Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2531776rdb; Fri, 22 Sep 2023 01:00:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGzQoGaugD9psx1Bg1WcKngafRUH6nkmFd1eH3yyP6qOG/aB/gT429l/vtFqaMksQdE4rrt X-Received: by 2002:a05:6a00:2389:b0:68a:59c6:c0a6 with SMTP id f9-20020a056a00238900b0068a59c6c0a6mr9252371pfc.24.1695369648164; Fri, 22 Sep 2023 01:00:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695369648; cv=none; d=google.com; s=arc-20160816; b=Ic+tMTu8FBi/39ROZtCZU7bWGPTxmJWzO+uSqpHSAwX4v2Ik5ed74lLwG0lcIm0MNA Txy2Bocd06NIR6OhXsef4M499rqcz3FYnf4O0J33NfF6RpI3f5ACKm491M/uZfy3pUx0 9bvhCtd0gKREJc7pW5+89m0ux8I2MDcYXk+FSI2qg35sY7bU0I4TQ382kH04/AkqO8bn ucpWPS8XoCVU37x5MlWJZPlHEViITvcOuZ9I85Libb4rYRO/FCCa5ylklYfndkodNfAj G97TszcNmso5Pk/Ft7raiHfTmijkJqDG478VPUkRMO21KT/yJCalwtf9saJy80iGXarN GLfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5ekKqDMutZT1+p/OAIwqT2gdhXe11P27k2HwXiyP8Yw=; fh=ANS6iRpdj3ntKSmwSzT4LEHUH9ZAudCj9zvP8/EeThQ=; b=MKVdQEGTQMSUDYJsSxhkZP6xCANfXQLwTpoHMoPN3BXokLHBLFXDYffJH/I+wDhV9S mEFpOV6h/74LsJDn8iFzAngr8XjyCp3BFhdqT3PXkDVXtViEY54SXbY036Od/PevbmIV qdJ8VtjiXs5Ce7QtgvDZZ0Tq7fXfQq3dMDeWcvU9a1bRUmNPiqA54uDkMYpEA0CbIq7h 6FzriRi1vdNG1NuOeG93Ey9vNPZYnxn0UQCllGXcIs36bMcCU8iRVJnOZIaATwnEHEhe Nv43gtRkNSh+NOtvLflGAY87Lx1RODM5DRapxW0zShRpd17zQGvuJ9+aUuqe7KYqyG7Y nHow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VIaZlZxC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id d7-20020a056a0024c700b0068ffd96e1d4si3471616pfv.165.2023.09.22.01.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 01:00:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VIaZlZxC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id D67C581DE6B2; Thu, 21 Sep 2023 13:41:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232080AbjIUUlQ (ORCPT + 99 others); Thu, 21 Sep 2023 16:41:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232226AbjIUUlE (ORCPT ); Thu, 21 Sep 2023 16:41:04 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9A775B422; Thu, 21 Sep 2023 13:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695327287; x=1726863287; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LZO5yjdBhkI2eq5MmnoYAkLMHFYrLWe3TrIyqhKkZPU=; b=VIaZlZxCI1JQuQnDmTFFVbkdoT8u44sVkbHmvQJ8KgQBTIfAcrRsWts+ sv0b8WMqv/QmWZWSeID/QEL1b3TdATpnP6ccQERE5oUeV5xNyRuykX2VQ NHbEYCbr3nnyy4Xo/yYkDoNx/wHUHgEE8NQyIJ6uXRS4ch4ptscYql9te ADPmcTXxHJYtsXr7/OwLheGVdLFezRhxdiznRgpqFH+mKhuRaLtKNaFjF IRiYz2mV7oxrZywnz3O4MGqlWFXzRf2GPb0Df0nUiJV5up98zVbsfq1uQ nfNYDgIshJJ3/9GQgjG6KC6UioQB6efvScUXlt2ke8TTiySpPrW5jVMjj Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10840"; a="383401590" X-IronPort-AV: E=Sophos;i="6.03,166,1694761200"; d="scan'208";a="383401590" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 13:14:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10840"; a="696897783" X-IronPort-AV: E=Sophos;i="6.03,166,1694761200"; d="scan'208";a="696897783" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 13:14:45 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Michael Roth , Paolo Bonzini , Sean Christopherson , 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 Subject: [RFC PATCH v2 1/6] KVM: gmem: Truncate pages on punch hole Date: Thu, 21 Sep 2023 13:14:34 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:41:23 -0700 (PDT) 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; + /* * 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); + + filemap_invalidate_unlock(mapping); return 0; } -- 2.25.1