lkml.org 
[lkml]   [2023]   [Sep]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [RFC PATCH v2 1/6] KVM: gmem: Truncate pages on punch hole
From
On Thu, Sep 21, 2023, Sean Christopherson wrote:
> On Thu, Sep 21, 2023, isaku.yamahata@intel.com wrote:
> > From: Isaku Yamahata <isaku.yamahata@intel.com>
> >
> > Although kvm_gmem_punch_hole() keeps all pages in mapping on punching hole,
> > it's common expectation that pages are truncated. Truncate pages on
> > punching hole. As page contents can be encrypted, avoid zeroing partial
> > folio by refusing partial punch hole.
> >
> > Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
> > ---
> > virt/kvm/guest_mem.c | 14 ++++++++++++--
> > 1 file changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/virt/kvm/guest_mem.c b/virt/kvm/guest_mem.c
> > index a819367434e9..01fb4ca861d0 100644
> > --- a/virt/kvm/guest_mem.c
> > +++ b/virt/kvm/guest_mem.c
> > @@ -130,22 +130,32 @@ static void kvm_gmem_invalidate_end(struct kvm_gmem *gmem, pgoff_t start,
> > static long kvm_gmem_punch_hole(struct inode *inode, loff_t offset, loff_t len)
> > {
> > struct list_head *gmem_list = &inode->i_mapping->private_list;
> > + struct address_space *mapping = inode->i_mapping;
> > pgoff_t start = offset >> PAGE_SHIFT;
> > pgoff_t end = (offset + len) >> PAGE_SHIFT;
> > struct kvm_gmem *gmem;
> >
> > + /*
> > + * punch hole may result in zeroing partial area. As pages can be
> > + * encrypted, prohibit zeroing partial area.
> > + */
> > + if (offset & ~PAGE_MASK || len & ~PAGE_MASK)
> > + return -EINVAL;
>
> This should be unnecessary, kvm_gmem_fallocate() does
>
> if (!PAGE_ALIGNED(offset) || !PAGE_ALIGNED(len))
> return -EINVAL;
>
> before invoking kvm_gmem_punch_hole(). If that's not working, i.e. your test
> fails, then that code needs to be fixed. I'll run your test to double-check,
> but AFAICT this is unnecesary.

I confirmed that the testcase passes without the extra checks. Just to close the
loop, what prompted adding more checks to kvm_gmem_punch_hole()?

\
 
 \ /
  Last update: 2023-09-21 23:48    [W:2.049 / U:0.000 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site