device-dax: map dax memory as decrypted in CoCo guests
PATCH 1/1 device-dax: map dax memory as decrypted in CoCo guests
Confidential Computing (CoCo) guests encrypt private memory by default. DAX memory regions allow a guest to bypass its own (private) page cache and instead use host memory, which is not private to the guest.
Commit 867400af90f1 ("mm/memremap.c: map FS_DAX device memory as decrypted") only ensures that FS_DAX memory is appropriately marked as decrypted. As such, also mark device-dax memory as decrypted.
--- drivers/dax/device.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/dax/device.c +3 -0
@@ -11,6 +11,7 @@#include <linux/fs.h> #include <linux/mm.h> #include <linux/mman.h> +#include <linux/cc_platform.h> #include "dax-private.h" #include "bus.h"
@@ -303,6 +304,8 @@ static int dax_mmap(struct file *filp, struct vm_area_struct *vma) vma->vm_ops = &dax_vm_ops;vm_flags_set (vma,VM_HUGEPAGE ); +if (cc_platform_has (CC_ATTR_MEM_ENCRYPT )) + vma->vm_page_prot =pgprot_decrypted (vma->vm_page_prot);return 0 ; }
Signature · 1 line
2.46.0.76.ge559c4bf1a-goog
Quoted 7 lines
Confidential Computing (CoCo) guests encrypt private memory by default. DAX memory regions allow a guest to bypass its own (private) page cache and instead use host memory, which is not private to the guest.
Commit
867400af90f1("mm/memremap.c: mapFS_DAXdevice memory as decrypted") only ensures thatFS_DAXmemory is appropriately marked as decrypted. As such, also mark device-dax memory as decrypted.
Overall patch seems OK to me.
How can I test this? Can I test it with virtio-pmem device?
Thanks,
Pankaj
Quoted 26 lines
Signed-off-by Kevin Loughlin <[email protected] > ---drivers/dax/device.c | 3 +++ 1 file changed, 3 insertions(+)drivers/dax/device.c +3
-0@@ -11,6 +11,7 @@#include <linux/fs.h> #include <linux/mm.h> #include <linux/mman.h> +#include <linux/cc_platform.h> #include "dax-private.h" #include "bus.h" @@ -303,6 +304,8 @@ static int dax_mmap(struct file *filp, struct vm_area_struct *vma) vma->vm_ops = &dax_vm_ops;vm_flags_set (vma,VM_HUGEPAGE ); +if (cc_platform_has (CC_ATTR_MEM_ENCRYPT )) + vma->vm_page_prot =pgprot_decrypted (vma->vm_page_prot);return 0 ; }
Quoted 1 line
How can I test this? Can I test it with virtio-pmem device?
Correct. Assuming the CoCo guest accesses some virtio-pmem device in devdax mode, mmapping() this virtio-pmem device's memory region results in the guest and host reading the same (plaintext) values from the region.
Quoted 30 lines
Thanks,
PankajQuoted 26 lines
Signed-off-by Kevin Loughlin <[email protected] > ---drivers/dax/device.c | 3 +++ 1 file changed, 3 insertions(+)drivers/dax/device.c +3
-0@@ -11,6 +11,7 @@#include <linux/fs.h> #include <linux/mm.h> #include <linux/mman.h> +#include <linux/cc_platform.h> #include "dax-private.h" #include "bus.h" @@ -303,6 +304,8 @@ static int dax_mmap(struct file *filp, struct vm_area_struct *vma) vma->vm_ops = &dax_vm_ops;vm_flags_set (vma,VM_HUGEPAGE ); +if (cc_platform_has (CC_ATTR_MEM_ENCRYPT )) + vma->vm_page_prot =pgprot_decrypted (vma->vm_page_prot);return 0 ; }
Quoted 6 lines · Kevin Loughlin
Quoted 1 line
How can I test this? Can I test it with virtio-pmem device?
Correct. Assuming the CoCo guest accesses some virtio-pmem device in devdax mode,
mmapping()this virtio-pmem device's memory region results in the guest and host reading the same (plaintext) values from the region.
I tried to test the daxdev with virtio-pmem but getting the below error (just tried without this patch)
root@ubuntu:/home/amd# ndctl list -N
{
"dev":"namespace0.0",
"mode":"devdax",
"map":"dev",
"size":1054867456,
"uuid":"c8b15ce6-0c8f-4a1a-ada6-b19a90bdf1bb",
"numa_node":0
}root@ubuntu:cat /dev/zero | daxio --output=/dev/namespace0.0
daxio: neither input or output is device dax
Could you please share the instructions (to test with virtio-pmem or Qemu). If not, still okay.
Thanks,
Pankaj
Best regards,
Pankaj
Quoted 20 lines · Pankaj
Quoted 6 lines · Kevin Loughlin
Quoted 1 line
How can I test this? Can I test it with virtio-pmem device?
Correct. Assuming the CoCo guest accesses some virtio-pmem device in devdax mode,
mmapping()this virtio-pmem device's memory region results in the guest and host reading the same (plaintext) values from the region.I tried to test the daxdev with virtio-pmem but getting the below error (just tried without this patch)
root@ubuntu:/home/amd# ndctl list -N { "dev":"namespace0.0", "mode":"devdax", "map":"dev", "size":1054867456, "uuid":"c8b15ce6-0c8f-4a1a-ada6-b19a90bdf1bb", "numa_node":0 }
Quoted 4 lines
root@ubuntu:cat
/dev/zero| daxio --output=/dev/namespace0.0
daxio: neither input or output is device daxCould you please share the instructions (to test with virtio-pmem or Qemu). If not, still okay.
Ah by mistake pressed entered early.
Just want to see the behavior on a SEV system with daxdev (maybe above virtio-pmem or other emulated device) and see how this patch helps.
Best regards,
Pankaj