diff mbox series

device-dax: map dax memory as decrypted in CoCo guests

Message ID 20240814205303.2619373-1-kevinloughlin@google.com
State New
Headers show
Series device-dax: map dax memory as decrypted in CoCo guests | expand

Commit Message

Kevin Loughlin Aug. 14, 2024, 8:53 p.m. UTC
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.

Signed-off-by: Kevin Loughlin <kevinloughlin@google.com>
---
 drivers/dax/device.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Gupta, Pankaj Aug. 23, 2024, 12:09 p.m. UTC | #1
> 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.

Overall patch seems OK to me.

How can I test this? Can I test it with virtio-pmem device?

Thanks,
Pankaj
> 
> Signed-off-by: Kevin Loughlin <kevinloughlin@google.co > ---
>   drivers/dax/device.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/dax/device.c b/drivers/dax/device.c
> index 2051e4f73c8a..a284442d7ecc 100644
> --- a/drivers/dax/device.c
> +++ b/drivers/dax/device.c
> @@ -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;
>   }
>
Kevin Loughlin Aug. 26, 2024, 9:35 p.m. UTC | #2
> 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.



>
> Thanks,
> Pankaj
> >
> > Signed-off-by: Kevin Loughlin <kevinloughlin@google.co > ---
> >   drivers/dax/device.c | 3 +++
> >   1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/dax/device.c b/drivers/dax/device.c
> > index 2051e4f73c8a..a284442d7ecc 100644
> > --- a/drivers/dax/device.c
> > +++ b/drivers/dax/device.c
> > @@ -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;
> >   }
> >
>
Gupta, Pankaj Sept. 10, 2024, 1 p.m. UTC | #3
On 8/26/2024 11:35 PM, Kevin Loughlin wrote:
>> 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
Gupta, Pankaj Sept. 10, 2024, 1:07 p.m. UTC | #4
On 9/10/2024 3:00 PM, Gupta, Pankaj wrote:
> On 8/26/2024 11:35 PM, Kevin Loughlin wrote:
>>> 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.

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
diff mbox series

Patch

diff --git a/drivers/dax/device.c b/drivers/dax/device.c
index 2051e4f73c8a..a284442d7ecc 100644
--- a/drivers/dax/device.c
+++ b/drivers/dax/device.c
@@ -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;
 }