Re: [PATCH] device-dax: map dax memory as decrypted in CoCo guests

From: Kevin Loughlin
Date: Mon Aug 26 2024 - 17:35:47 EST


> 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@xxxxxxxxx > ---
> > 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;
> > }
> >
>