* [Qemu-devel] [PATCH v2 1/2] memory: Fix the memory region type assignment order
2019-02-04 22:23 [Qemu-devel] [PATCH v2 0/2] Fix SEV VM device assignment Singh, Brijesh
@ 2019-02-04 22:23 ` Singh, Brijesh
2019-02-04 22:23 ` [Qemu-devel] [PATCH v2 2/2] target/i386: sev: Do not pin the ram device memory region Singh, Brijesh
2019-03-01 15:09 ` [Qemu-devel] [PATCH v2 0/2] Fix SEV VM device assignment Singh, Brijesh
2 siblings, 0 replies; 5+ messages in thread
From: Singh, Brijesh @ 2019-02-04 22:23 UTC (permalink / raw)
To: qemu-devel@nongnu.org
Cc: alex.williamson@redhat.com, Singh, Brijesh, Paolo Bonzini
Currently, a callback registered through the RAMBlock notifier
is not able to get the memory region type (i.e callback is not
able to use memory_region_is_ram_device function). This is
because mr->ram assignment happens _after_ the memory is allocated
whereas the callback is executed during allocation.
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
Suggested-by: Alex Williamson <alex.williamson@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
---
memory.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/memory.c b/memory.c
index 61d66e4441..9ec15349dd 100644
--- a/memory.c
+++ b/memory.c
@@ -1652,10 +1652,17 @@ void memory_region_init_ram_device_ptr(MemoryRegion *mr,
uint64_t size,
void *ptr)
{
- memory_region_init_ram_ptr(mr, owner, name, size, ptr);
+ memory_region_init(mr, owner, name, size);
+ mr->ram = true;
+ mr->terminates = true;
mr->ram_device = true;
mr->ops = &ram_device_mem_ops;
mr->opaque = mr;
+ mr->destructor = memory_region_destructor_ram;
+ mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
+ /* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */
+ assert(ptr != NULL);
+ mr->ram_block = qemu_ram_alloc_from_ptr(size, ptr, mr, &error_fatal);
}
void memory_region_init_alias(MemoryRegion *mr,
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH v2 2/2] target/i386: sev: Do not pin the ram device memory region
2019-02-04 22:23 [Qemu-devel] [PATCH v2 0/2] Fix SEV VM device assignment Singh, Brijesh
2019-02-04 22:23 ` [Qemu-devel] [PATCH v2 1/2] memory: Fix the memory region type assignment order Singh, Brijesh
@ 2019-02-04 22:23 ` Singh, Brijesh
2019-02-04 22:29 ` Alex Williamson
2019-03-01 15:09 ` [Qemu-devel] [PATCH v2 0/2] Fix SEV VM device assignment Singh, Brijesh
2 siblings, 1 reply; 5+ messages in thread
From: Singh, Brijesh @ 2019-02-04 22:23 UTC (permalink / raw)
To: qemu-devel@nongnu.org
Cc: alex.williamson@redhat.com, Singh, Brijesh, Paolo Bonzini
The RAM device presents a memory region that should be handled
as an IO region and should not be pinned.
In the case of the vfio-pci, RAM device represents a MMIO BAR
and the memory region is not backed by pages hence
KVM_MEMORY_ENCRYPT_REG_REGION fails to lock the memory range.
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
---
target/i386/sev.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/target/i386/sev.c b/target/i386/sev.c
index 20b2d325d8..cd77f6b5d4 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -131,6 +131,17 @@ sev_ram_block_added(RAMBlockNotifier *n, void *host, size_t size)
{
int r;
struct kvm_enc_region range;
+ ram_addr_t offset;
+ MemoryRegion *mr;
+
+ /*
+ * The RAM device presents a memory region that should be treated
+ * as IO region and should not be pinned.
+ */
+ mr = memory_region_from_host(host, &offset);
+ if (mr && memory_region_is_ram_device(mr)) {
+ return;
+ }
range.addr = (__u64)(unsigned long)host;
range.size = size;
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2 2/2] target/i386: sev: Do not pin the ram device memory region
2019-02-04 22:23 ` [Qemu-devel] [PATCH v2 2/2] target/i386: sev: Do not pin the ram device memory region Singh, Brijesh
@ 2019-02-04 22:29 ` Alex Williamson
0 siblings, 0 replies; 5+ messages in thread
From: Alex Williamson @ 2019-02-04 22:29 UTC (permalink / raw)
To: Singh, Brijesh; +Cc: qemu-devel@nongnu.org, Paolo Bonzini
On Mon, 4 Feb 2019 22:23:40 +0000
"Singh, Brijesh" <brijesh.singh@amd.com> wrote:
> The RAM device presents a memory region that should be handled
> as an IO region and should not be pinned.
>
> In the case of the vfio-pci, RAM device represents a MMIO BAR
> and the memory region is not backed by pages hence
> KVM_MEMORY_ENCRYPT_REG_REGION fails to lock the memory range.
>
> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
> Cc: Alex Williamson <alex.williamson@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
> ---
> target/i386/sev.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/target/i386/sev.c b/target/i386/sev.c
> index 20b2d325d8..cd77f6b5d4 100644
> --- a/target/i386/sev.c
> +++ b/target/i386/sev.c
> @@ -131,6 +131,17 @@ sev_ram_block_added(RAMBlockNotifier *n, void *host, size_t size)
> {
> int r;
> struct kvm_enc_region range;
> + ram_addr_t offset;
> + MemoryRegion *mr;
> +
> + /*
> + * The RAM device presents a memory region that should be treated
> + * as IO region and should not be pinned.
> + */
> + mr = memory_region_from_host(host, &offset);
> + if (mr && memory_region_is_ram_device(mr)) {
> + return;
> + }
>
> range.addr = (__u64)(unsigned long)host;
> range.size = size;
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/2] Fix SEV VM device assignment
2019-02-04 22:23 [Qemu-devel] [PATCH v2 0/2] Fix SEV VM device assignment Singh, Brijesh
2019-02-04 22:23 ` [Qemu-devel] [PATCH v2 1/2] memory: Fix the memory region type assignment order Singh, Brijesh
2019-02-04 22:23 ` [Qemu-devel] [PATCH v2 2/2] target/i386: sev: Do not pin the ram device memory region Singh, Brijesh
@ 2019-03-01 15:09 ` Singh, Brijesh
2 siblings, 0 replies; 5+ messages in thread
From: Singh, Brijesh @ 2019-03-01 15:09 UTC (permalink / raw)
To: qemu-devel@nongnu.org; +Cc: Singh, Brijesh, alex.williamson@redhat.com
Hi Paolo,
Any comment on this series. Currently, device pass-through is
broken for the SEV guests. I am wondering if we can queue the
patches.
thanks
Brijesh
On 2/4/19 4:23 PM, Singh, Brijesh wrote:
> Fix: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
>
> Since v1:
> * check the error code from memory_region_from_host() before
> accessing the mr.
>
> Brijesh Singh (2):
> memory: Fix the memory region type assignment order
> target/i386: sev: Do not pin the ram device memory region
>
> memory.c | 9 ++++++++-
> target/i386/sev.c | 11 +++++++++++
> 2 files changed, 19 insertions(+), 1 deletion(-)
>
^ permalink raw reply [flat|nested] 5+ messages in thread