* [Qemu-devel] [RHEL-8.1 virt 0/2] Enable SEV VM to boot with assigned PCI device
@ 2019-04-10 0:08 ` Gary R Hook
0 siblings, 0 replies; 13+ messages in thread
From: Gary R Hook @ 2019-04-10 0:08 UTC (permalink / raw)
To: rhvirt-patches
Cc: ghook, Danilo C. L. de Paula, Eduardo Habkost, Paolo Bonzini,
qemu-devel, Richard Henderson
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
On an AMD SEV enabled host with an SEV enabled guest, attaching an
assigned device to the VM results in a failure to start the VM:
qemu-kvm: -device vfio-pci,host=01:00.0,id=hostdev0,bus=pci.2,addr=0x0: sev_ram_block_added: failed to register region (0x7fd96e6bb000+0x20000) error 'Cannot allocate memory'
In this example the assigned device is a simple Intel 82574L NIC:
01:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
Subsystem: Intel Corporation Gigabit CT Desktop Adapter
Flags: bus master, fast devsel, latency 0, IRQ 89, NUMA node 0
Memory at fb9c0000 (32-bit, non-prefetchable) [size=128K]
Memory at fb900000 (32-bit, non-prefetchable) [size=512K]
Note that the error indicates the region as (base+size) where a size
of 0x20000 is 128K, which matches that of BAR0 for the device.
dmesg on the host also reports:
SVM: SEV: Failure locking 32 pages.
SEV guests make use of the RAMBlock notifier in QEMU to add page
pinnings for SEV; the kernel side of the call only knows how to pin
pages with get_user_pages(), and this currently faults on non-page
backed mappings (e.g. the mmap of an MMIO BAR).
To resolve this failure, change the order of the memory region type
assignment and avoid pinning device memory regions.
Cc: "Danilo C. L. de Paula" <ddepaula@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Cc: Richard Henderson <rth@twiddle.net>
Danilo C. L. de Paula (2):
redhat: branching qemu-kvm to rhel-8.1.0
redhat: renaming branch to rhel-8.1.0
Gary R Hook (2):
Subject: memory: Fix the memory region type assignment order
Subject: target/i386: sev: Do not pin the ram device memory region
.gitpublish | 6 +++---
memory.c | 9 ++++++++-
target/i386/sev.c | 11 +++++++++++
3 files changed, 22 insertions(+), 4 deletions(-)
--
2.18.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Qemu-devel] [RHEL-8.1 virt 0/2] Enable SEV VM to boot with assigned PCI device
@ 2019-04-10 0:08 ` Gary R Hook
0 siblings, 0 replies; 13+ messages in thread
From: Gary R Hook @ 2019-04-10 0:08 UTC (permalink / raw)
To: rhvirt-patches
Cc: ghook, Eduardo Habkost, qemu-devel, Paolo Bonzini,
Danilo C. L. de Paula, Richard Henderson
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
On an AMD SEV enabled host with an SEV enabled guest, attaching an
assigned device to the VM results in a failure to start the VM:
qemu-kvm: -device vfio-pci,host=01:00.0,id=hostdev0,bus=pci.2,addr=0x0: sev_ram_block_added: failed to register region (0x7fd96e6bb000+0x20000) error 'Cannot allocate memory'
In this example the assigned device is a simple Intel 82574L NIC:
01:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
Subsystem: Intel Corporation Gigabit CT Desktop Adapter
Flags: bus master, fast devsel, latency 0, IRQ 89, NUMA node 0
Memory at fb9c0000 (32-bit, non-prefetchable) [size=128K]
Memory at fb900000 (32-bit, non-prefetchable) [size=512K]
Note that the error indicates the region as (base+size) where a size
of 0x20000 is 128K, which matches that of BAR0 for the device.
dmesg on the host also reports:
SVM: SEV: Failure locking 32 pages.
SEV guests make use of the RAMBlock notifier in QEMU to add page
pinnings for SEV; the kernel side of the call only knows how to pin
pages with get_user_pages(), and this currently faults on non-page
backed mappings (e.g. the mmap of an MMIO BAR).
To resolve this failure, change the order of the memory region type
assignment and avoid pinning device memory regions.
Cc: "Danilo C. L. de Paula" <ddepaula@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Cc: Richard Henderson <rth@twiddle.net>
Danilo C. L. de Paula (2):
redhat: branching qemu-kvm to rhel-8.1.0
redhat: renaming branch to rhel-8.1.0
Gary R Hook (2):
Subject: memory: Fix the memory region type assignment order
Subject: target/i386: sev: Do not pin the ram device memory region
.gitpublish | 6 +++---
memory.c | 9 ++++++++-
target/i386/sev.c | 11 +++++++++++
3 files changed, 22 insertions(+), 4 deletions(-)
--
2.18.1
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Qemu-devel] [RHEL-8.1 virt 1/2] memory: Fix the memory region type assignment order
@ 2019-04-10 0:08 ` Gary R Hook
0 siblings, 0 replies; 13+ messages in thread
From: Gary R Hook @ 2019-04-10 0:08 UTC (permalink / raw)
To: rhvirt-patches; +Cc: ghook, Paolo Bonzini, qemu-devel
BZ: 1667249
Branch: rhel-8.1.0
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
Upstream Status: 4.0.0-rc1
Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=20980582
Conflicts: None
commit 2ddb89b00f947f785c9ca6742f28f954e3b75e62
Author: Singh, Brijesh <brijesh.singh@amd.com>
Date: Mon Feb 4 22:23:39 2019 +0000
memory: Fix the memory region type assignment order
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>
Message-Id: <20190204222322.26766-2-brijesh.singh@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
---
memory.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/memory.c b/memory.c
index 4974f972d5..04ff5e9108 100644
--- a/memory.c
+++ b/memory.c
@@ -1631,10 +1631,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.18.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [RHEL-8.1 virt 1/2] memory: Fix the memory region type assignment order
@ 2019-04-10 0:08 ` Gary R Hook
0 siblings, 0 replies; 13+ messages in thread
From: Gary R Hook @ 2019-04-10 0:08 UTC (permalink / raw)
To: rhvirt-patches; +Cc: Paolo Bonzini, ghook, qemu-devel
BZ: 1667249
Branch: rhel-8.1.0
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
Upstream Status: 4.0.0-rc1
Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=20980582
Conflicts: None
commit 2ddb89b00f947f785c9ca6742f28f954e3b75e62
Author: Singh, Brijesh <brijesh.singh@amd.com>
Date: Mon Feb 4 22:23:39 2019 +0000
memory: Fix the memory region type assignment order
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>
Message-Id: <20190204222322.26766-2-brijesh.singh@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
---
memory.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/memory.c b/memory.c
index 4974f972d5..04ff5e9108 100644
--- a/memory.c
+++ b/memory.c
@@ -1631,10 +1631,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.18.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [RHEL-8.1 virt 2/2] target/i386: sev: Do not pin the ram device memory region
@ 2019-04-10 0:08 ` Gary R Hook
0 siblings, 0 replies; 13+ messages in thread
From: Gary R Hook @ 2019-04-10 0:08 UTC (permalink / raw)
To: rhvirt-patches
Cc: ghook, Paolo Bonzini, Richard Henderson, Eduardo Habkost, qemu-devel
BZ: 1667249
Branch: rhel-8.1.0
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
Upstream Status: 4.0.0-rc1
Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=20980582
Conflicts: None
commit cedc0ad539afbbb669dba9e73dfad2915bc1c25b
Author: Singh, Brijesh <brijesh.singh@amd.com>
Date: Mon Feb 4 22:23:40 2019 +0000
target/i386: sev: Do not pin the ram device memory region
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>
Message-Id: <20190204222322.26766-3-brijesh.singh@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
target/i386/sev.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/target/i386/sev.c b/target/i386/sev.c
index 2395171acf..b8009b001a 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -130,6 +130,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.18.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [RHEL-8.1 virt 2/2] target/i386: sev: Do not pin the ram device memory region
@ 2019-04-10 0:08 ` Gary R Hook
0 siblings, 0 replies; 13+ messages in thread
From: Gary R Hook @ 2019-04-10 0:08 UTC (permalink / raw)
To: rhvirt-patches
Cc: qemu-devel, Paolo Bonzini, ghook, Eduardo Habkost, Richard Henderson
BZ: 1667249
Branch: rhel-8.1.0
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
Upstream Status: 4.0.0-rc1
Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=20980582
Conflicts: None
commit cedc0ad539afbbb669dba9e73dfad2915bc1c25b
Author: Singh, Brijesh <brijesh.singh@amd.com>
Date: Mon Feb 4 22:23:40 2019 +0000
target/i386: sev: Do not pin the ram device memory region
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>
Message-Id: <20190204222322.26766-3-brijesh.singh@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
target/i386/sev.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/target/i386/sev.c b/target/i386/sev.c
index 2395171acf..b8009b001a 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -130,6 +130,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.18.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [RHEL-8.1 virt 1/2] memory: Fix the memory region type assignment order
@ 2019-04-22 21:26 ` Eduardo Habkost
0 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2019-04-22 21:26 UTC (permalink / raw)
To: Gary R Hook; +Cc: rhvirt-patches, Paolo Bonzini, qemu-devel
On Tue, Apr 09, 2019 at 08:08:02PM -0400, Gary R Hook wrote:
> BZ: 1667249
> Branch: rhel-8.1.0
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
> Upstream Status: 4.0.0-rc1
> Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=20980582
> Conflicts: None
>
> commit 2ddb89b00f947f785c9ca6742f28f954e3b75e62
> Author: Singh, Brijesh <brijesh.singh@amd.com>
> Date: Mon Feb 4 22:23:39 2019 +0000
>
> memory: Fix the memory region type assignment order
>
> 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>
> Message-Id: <20190204222322.26766-2-brijesh.singh@amd.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: qemu-devel@nongnu.org
Faithful backport.
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
--
Eduardo
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [RHEL-8.1 virt 1/2] memory: Fix the memory region type assignment order
@ 2019-04-22 21:26 ` Eduardo Habkost
0 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2019-04-22 21:26 UTC (permalink / raw)
To: Gary R Hook; +Cc: Paolo Bonzini, rhvirt-patches, qemu-devel
On Tue, Apr 09, 2019 at 08:08:02PM -0400, Gary R Hook wrote:
> BZ: 1667249
> Branch: rhel-8.1.0
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
> Upstream Status: 4.0.0-rc1
> Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=20980582
> Conflicts: None
>
> commit 2ddb89b00f947f785c9ca6742f28f954e3b75e62
> Author: Singh, Brijesh <brijesh.singh@amd.com>
> Date: Mon Feb 4 22:23:39 2019 +0000
>
> memory: Fix the memory region type assignment order
>
> 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>
> Message-Id: <20190204222322.26766-2-brijesh.singh@amd.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: qemu-devel@nongnu.org
Faithful backport.
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
--
Eduardo
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [RHEL-8.1 virt 2/2] target/i386: sev: Do not pin the ram device memory region
@ 2019-04-22 21:29 ` Eduardo Habkost
0 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2019-04-22 21:29 UTC (permalink / raw)
To: Gary R Hook; +Cc: rhvirt-patches, qemu-devel, Paolo Bonzini, Richard Henderson
On Tue, Apr 09, 2019 at 08:08:03PM -0400, Gary R Hook wrote:
> BZ: 1667249
> Branch: rhel-8.1.0
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
> Upstream Status: 4.0.0-rc1
> Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=20980582
> Conflicts: None
>
> commit cedc0ad539afbbb669dba9e73dfad2915bc1c25b
> Author: Singh, Brijesh <brijesh.singh@amd.com>
> Date: Mon Feb 4 22:23:40 2019 +0000
>
> target/i386: sev: Do not pin the ram device memory region
>
> 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>
> Message-Id: <20190204222322.26766-3-brijesh.singh@amd.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: qemu-devel@nongnu.org
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
--
Eduardo
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [RHEL-8.1 virt 2/2] target/i386: sev: Do not pin the ram device memory region
@ 2019-04-22 21:29 ` Eduardo Habkost
0 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2019-04-22 21:29 UTC (permalink / raw)
To: Gary R Hook; +Cc: Paolo Bonzini, rhvirt-patches, qemu-devel, Richard Henderson
On Tue, Apr 09, 2019 at 08:08:03PM -0400, Gary R Hook wrote:
> BZ: 1667249
> Branch: rhel-8.1.0
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
> Upstream Status: 4.0.0-rc1
> Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=20980582
> Conflicts: None
>
> commit cedc0ad539afbbb669dba9e73dfad2915bc1c25b
> Author: Singh, Brijesh <brijesh.singh@amd.com>
> Date: Mon Feb 4 22:23:40 2019 +0000
>
> target/i386: sev: Do not pin the ram device memory region
>
> 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>
> Message-Id: <20190204222322.26766-3-brijesh.singh@amd.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: qemu-devel@nongnu.org
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
--
Eduardo
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [RHEL-8.1 virt 0/2] Enable SEV VM to boot with assigned PCI device
@ 2019-04-26 8:10 ` Paolo Bonzini
0 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2019-04-26 8:10 UTC (permalink / raw)
To: Gary R Hook, rhvirt-patches
Cc: Danilo C. L. de Paula, Eduardo Habkost, qemu-devel, Richard Henderson
On 10/04/19 02:08, Gary R Hook wrote:
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
>
> On an AMD SEV enabled host with an SEV enabled guest, attaching an
> assigned device to the VM results in a failure to start the VM:
>
> qemu-kvm: -device vfio-pci,host=01:00.0,id=hostdev0,bus=pci.2,addr=0x0: sev_ram_block_added: failed to register region (0x7fd96e6bb000+0x20000) error 'Cannot allocate memory'
>
> In this example the assigned device is a simple Intel 82574L NIC:
>
> 01:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
> Subsystem: Intel Corporation Gigabit CT Desktop Adapter
> Flags: bus master, fast devsel, latency 0, IRQ 89, NUMA node 0
> Memory at fb9c0000 (32-bit, non-prefetchable) [size=128K]
> Memory at fb900000 (32-bit, non-prefetchable) [size=512K]
>
> Note that the error indicates the region as (base+size) where a size
> of 0x20000 is 128K, which matches that of BAR0 for the device.
> dmesg on the host also reports:
>
> SVM: SEV: Failure locking 32 pages.
>
> SEV guests make use of the RAMBlock notifier in QEMU to add page
> pinnings for SEV; the kernel side of the call only knows how to pin
> pages with get_user_pages(), and this currently faults on non-page
> backed mappings (e.g. the mmap of an MMIO BAR).
>
> To resolve this failure, change the order of the memory region type
> assignment and avoid pinning device memory regions.
>
> Cc: "Danilo C. L. de Paula" <ddepaula@redhat.com>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: qemu-devel@nongnu.org
> Cc: Richard Henderson <rth@twiddle.net>
>
> Danilo C. L. de Paula (2):
> redhat: branching qemu-kvm to rhel-8.1.0
> redhat: renaming branch to rhel-8.1.0
>
> Gary R Hook (2):
> Subject: memory: Fix the memory region type assignment order
> Subject: target/i386: sev: Do not pin the ram device memory region
>
> .gitpublish | 6 +++---
> memory.c | 9 ++++++++-
> target/i386/sev.c | 11 +++++++++++
> 3 files changed, 22 insertions(+), 4 deletions(-)
>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [RHEL-8.1 virt 0/2] Enable SEV VM to boot with assigned PCI device
@ 2019-04-26 8:10 ` Paolo Bonzini
0 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2019-04-26 8:10 UTC (permalink / raw)
To: Gary R Hook, rhvirt-patches
Cc: Richard Henderson, Eduardo Habkost, Danilo C. L. de Paula, qemu-devel
On 10/04/19 02:08, Gary R Hook wrote:
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
>
> On an AMD SEV enabled host with an SEV enabled guest, attaching an
> assigned device to the VM results in a failure to start the VM:
>
> qemu-kvm: -device vfio-pci,host=01:00.0,id=hostdev0,bus=pci.2,addr=0x0: sev_ram_block_added: failed to register region (0x7fd96e6bb000+0x20000) error 'Cannot allocate memory'
>
> In this example the assigned device is a simple Intel 82574L NIC:
>
> 01:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
> Subsystem: Intel Corporation Gigabit CT Desktop Adapter
> Flags: bus master, fast devsel, latency 0, IRQ 89, NUMA node 0
> Memory at fb9c0000 (32-bit, non-prefetchable) [size=128K]
> Memory at fb900000 (32-bit, non-prefetchable) [size=512K]
>
> Note that the error indicates the region as (base+size) where a size
> of 0x20000 is 128K, which matches that of BAR0 for the device.
> dmesg on the host also reports:
>
> SVM: SEV: Failure locking 32 pages.
>
> SEV guests make use of the RAMBlock notifier in QEMU to add page
> pinnings for SEV; the kernel side of the call only knows how to pin
> pages with get_user_pages(), and this currently faults on non-page
> backed mappings (e.g. the mmap of an MMIO BAR).
>
> To resolve this failure, change the order of the memory region type
> assignment and avoid pinning device memory regions.
>
> Cc: "Danilo C. L. de Paula" <ddepaula@redhat.com>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: qemu-devel@nongnu.org
> Cc: Richard Henderson <rth@twiddle.net>
>
> Danilo C. L. de Paula (2):
> redhat: branching qemu-kvm to rhel-8.1.0
> redhat: renaming branch to rhel-8.1.0
>
> Gary R Hook (2):
> Subject: memory: Fix the memory region type assignment order
> Subject: target/i386: sev: Do not pin the ram device memory region
>
> .gitpublish | 6 +++---
> memory.c | 9 ++++++++-
> target/i386/sev.c | 11 +++++++++++
> 3 files changed, 22 insertions(+), 4 deletions(-)
>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [RHEL-8.1 virt 2/2] target/i386: sev: Do not pin the ram device memory region
2019-04-10 0:08 ` Gary R Hook
(?)
(?)
@ 2019-11-06 20:04 ` Gary R Hook
-1 siblings, 0 replies; 13+ messages in thread
From: Gary R Hook @ 2019-11-06 20:04 UTC (permalink / raw)
To: rhvirt-patches
Cc: Paolo Bonzini, Richard Henderson, qemu-devel, Eduardo Habkost
----- Original Message -----
> From: "Gary R Hook" <ghook@redhat.com>
> To: rhvirt-patches@redhat.com
> Cc: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>, ghook@redhat.com, "Eduardo Habkost"
> <ehabkost@redhat.com>, "Richard Henderson" <rth@twiddle.net>
> Sent: Tuesday, April 9, 2019 7:08:03 PM
> Subject: [RHEL-8.1 virt 2/2] target/i386: sev: Do not pin the ram device memory region
>
> BZ: 1667249
> Branch: rhel-8.1.0
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
> Upstream Status: 4.0.0-rc1
> Build Info:
> https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=20980582
> Conflicts: None
>
> commit cedc0ad539afbbb669dba9e73dfad2915bc1c25b
> Author: Singh, Brijesh <brijesh.singh@amd.com>
> Date: Mon Feb 4 22:23:40 2019 +0000
>
> target/i386: sev: Do not pin the ram device memory region
>
> 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>
> Message-Id: <20190204222322.26766-3-brijesh.singh@amd.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: qemu-devel@nongnu.org
NACKed-by: Gary R Hook <ghook@redhat.com>
> ---
> target/i386/sev.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/target/i386/sev.c b/target/i386/sev.c
> index 2395171acf..b8009b001a 100644
> --- a/target/i386/sev.c
> +++ b/target/i386/sev.c
> @@ -130,6 +130,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.18.1
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2019-11-06 20:05 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-10 0:08 [Qemu-devel] [RHEL-8.1 virt 0/2] Enable SEV VM to boot with assigned PCI device Gary R Hook
2019-04-10 0:08 ` Gary R Hook
2019-04-10 0:08 ` [Qemu-devel] [RHEL-8.1 virt 1/2] memory: Fix the memory region type assignment order Gary R Hook
2019-04-10 0:08 ` Gary R Hook
2019-04-22 21:26 ` Eduardo Habkost
2019-04-22 21:26 ` Eduardo Habkost
2019-04-10 0:08 ` [Qemu-devel] [RHEL-8.1 virt 2/2] target/i386: sev: Do not pin the ram device memory region Gary R Hook
2019-04-10 0:08 ` Gary R Hook
2019-04-22 21:29 ` Eduardo Habkost
2019-04-22 21:29 ` Eduardo Habkost
2019-11-06 20:04 ` Gary R Hook
2019-04-26 8:10 ` [Qemu-devel] [RHEL-8.1 virt 0/2] Enable SEV VM to boot with assigned PCI device Paolo Bonzini
2019-04-26 8:10 ` Paolo Bonzini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.