Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2294131rdb; Thu, 21 Sep 2023 14:24:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFiQa3Si9ilnTdhKTBK9oXKbNkGff0heHuXza0Wx1iYJEAmqhfQK+UmK4A/PuCv5cLV0BCo X-Received: by 2002:a05:6358:9185:b0:13a:9d5:356a with SMTP id j5-20020a056358918500b0013a09d5356amr8475244rwa.21.1695331472268; Thu, 21 Sep 2023 14:24:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695331472; cv=none; d=google.com; s=arc-20160816; b=c0wD/fAz5VQpWZKuyVWuyDgn5Au8aJiCpwRZKY5Mlj0eyxLWWEtv8Jtp0jR9dW6Uzb exjV46WMOy6c5rymuEhnBe6w2X3XLEUE8D4IP+2Fz4vQsAdhRbcUF/ds/+XpK3Fove1c m9dl0eQKsLBHT8NWfu1hRVAkMDTPvRfwE0jC9wW71g8y2WK1mSoHYYNPzKDIvTHgUCgu SLD4H7XBO82J7isHsyDQUluX1DirhAreskhMUy4P20TkFXqJWTRlviBSr7HKoqFAj4y8 cp8BiFLQIG4Wk31yoozR28MbkMt9dlHl0LsAlh3Spq73RaWsLa8nwxgY5Nsk9nRBRapG 4jDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=aP7hpifj13TY/cmxy/VtYAtAKQo7n6lxac2QUYqGXnE=; fh=4zSMCzNb7rJrUGZtbNPceVM+tszI9ngqwF5WBZpI8NM=; b=LcfbneKIVnzHsR8nn/Nmhs5QiI2GWl42tv8pcFeF8Z1LDMzgUgRBmBLUcR91sluajR gsScOCNixJ6rrHBVQ0AYkgT8rzQCV+WddW4PSkE3korjHVh2HgGiyG7EPHuaaqN1RPHx /c7khcK3eGi73xd1Cf2pHwhb8DMhUO7dslzrZnhsBEgoMm+naAVHa0CoJ6Q3zAZoe65M UBd5XXY4Mu7WU62IL+RHktxbr/QwmYnP7/oHpe7/tuuNSfbEqGmB2DwJoeFyHgR+qxmV cE//QcGhi6iEB8VNDZ2L9dUVuPYLKLLCJqE6OW04jRU/xRC92j0EyJj/jiOJ5magK+3F BSiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=aCsMPYSr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id g7-20020a636b07000000b005637962e15esi2205427pgc.603.2023.09.21.14.24.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 14:24:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=aCsMPYSr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E025482CD6E8; Thu, 21 Sep 2023 14:12:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230390AbjIUVJ3 (ORCPT + 99 others); Thu, 21 Sep 2023 17:09:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231802AbjIUVJP (ORCPT ); Thu, 21 Sep 2023 17:09:15 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42844CDBE6 for ; Thu, 21 Sep 2023 13:37:03 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1c448ba292dso11513395ad.3 for ; Thu, 21 Sep 2023 13:37:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695328622; x=1695933422; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=aP7hpifj13TY/cmxy/VtYAtAKQo7n6lxac2QUYqGXnE=; b=aCsMPYSruNk/9yL3kVNkQ67ftw0JWLNZ8Ei5Se2KTIg1H7jjRUX8tAcarx71wgV4rV CenTLjy5vBKKNjV9P5bNNTnh9mjsay+f6OqT/Q+zYJApi0UEV/WySiVMfXEJQREQ8zuU 7RHX7Pk/c5pUD3oTAAvaG8+elXyX1j5ckWUOXLOkxGYf7owt5uRSY4L9zDaydEsT19NZ pPaKAZiwOjyww1gX5GeGEJn3s1zBcUep+Qn3T0S0AMYZFHc/aI0vOG/EySkgNkQnBqu4 BgQPy7AlJg+zQiaNx1gFJf/SFWCfZnrnH9J3+5kTRmGIahPoQ5ZDY0A2je7Kw9p0rV1x HOdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695328622; x=1695933422; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aP7hpifj13TY/cmxy/VtYAtAKQo7n6lxac2QUYqGXnE=; b=Ou0VWoQ67OOJFCkpWS+l5OL5C+HZe/wV1fzsyeVVUEfKc4mlW1W29SsOgawK5CUPw9 lJO1fblOJLypRU90I3EF2ZVKPN/08DA5hSC1yxWlW5fuHm1h6UAVISk+4gfkhEUXB7o9 vtaKVwuNlLI6ozGadtEm4MRGZP0tmotPuEvq8VJtJpH4KSvy1/VZpKfYeBdghuFq4MZH JEbKbKXcDVbn83C8EWLo/9NJcHCUyup/0EeLQWSzQWBUQcG3gamdMvGi2HjrdhHCKnUu F4cislTAavIl5Ca2Ls9qCOggYN/deP1m1ut/DH8rkHZPRDSVkJIUSXK93S1+HRKlQa86 6DDQ== X-Gm-Message-State: AOJu0YxB+191LXPoeMYABFkT8Di8uIeINlJQqKkb5ZUExoX7wlc7iF1P LsTiHBvn1ihYf+SdgMzpAl9ctlLCaac= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:1c7:b0:1b8:3c5e:2289 with SMTP id e7-20020a17090301c700b001b83c5e2289mr84379plh.2.1695328622355; Thu, 21 Sep 2023 13:37:02 -0700 (PDT) Date: Thu, 21 Sep 2023 13:37:01 -0700 In-Reply-To: Mime-Version: 1.0 References: Message-ID: Subject: Re: [RFC PATCH v2 1/6] KVM: gmem: Truncate pages on punch hole From: Sean Christopherson To: isaku.yamahata@intel.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Michael Roth , Paolo Bonzini , erdemaktas@google.com, Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, linux-coco@lists.linux.dev, Chao Peng , Ackerley Tng , Vishal Annapurve , Yuan Yao , Jarkko Sakkinen , Xu Yilun , Quentin Perret , wei.w.wang@intel.com, Fuad Tabba Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:12:35 -0700 (PDT) On Thu, Sep 21, 2023, isaku.yamahata@intel.com wrote: > From: Isaku Yamahata > > 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 > --- > 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. > + > /* > * Bindings must stable across invalidation to ensure the start+end > * are balanced. > */ > - filemap_invalidate_lock(inode->i_mapping); > + filemap_invalidate_lock(mapping); > > list_for_each_entry(gmem, gmem_list, entry) { > kvm_gmem_invalidate_begin(gmem, start, end); > kvm_gmem_invalidate_end(gmem, start, end); > } > > - filemap_invalidate_unlock(inode->i_mapping); > + truncate_inode_pages_range(mapping, offset, offset + len - 1); The truncate needs to happen between begin() and end(), otherwise KVM can create mappings to the memory between end() and truncate(). > + > + filemap_invalidate_unlock(mapping); > > return 0; > } > -- > 2.25.1 >