Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3197132rdb; Wed, 13 Sep 2023 05:19:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHoMLI/9Z7penisyzBB1H+1VqRQUqby9u3MESw2TBkiaJlQahJ3GyiliYjG3eoiHuMPeMn X-Received: by 2002:a05:6870:548d:b0:1ba:2c95:a168 with SMTP id f13-20020a056870548d00b001ba2c95a168mr2681529oan.35.1694607592672; Wed, 13 Sep 2023 05:19:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694607592; cv=none; d=google.com; s=arc-20160816; b=lSnVZzWP+q2kZIIsGGXYZ3BzsaWuR1+qZ5e9fVG+hL8j+lX2/BAlWUC6i38Vv/zj9d V5mPlcYJKA1WPRmACN0IhXg5p1jtXLLa1hjJdqGhBmprPE/VkkvlOpAcTx7i7SJn2rF1 RVu0Vm25VRtw20FT/MegdWajGheFsUHhMmv4h7bk43sO6v6gp1tp1neBsYFvQ9D7muMJ 3VpXbA7UzeDgfv58Za1/9mF9PQUfUCRGDj6NLyNLqHIZmpngcoTrKGwZzGmSLBtBaqmf AX+kDDM8kXHRhCEUZbxXCdfryDGfGk2P+vrkyB69zAFN7bKEjavROX1iZJxHh1hsreBz AADw== 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=SdlGs3oVAiEG9eIM5fX2og2cE0CrKRnZQIn08nfAR2A=; fh=ANS6iRpdj3ntKSmwSzT4LEHUH9ZAudCj9zvP8/EeThQ=; b=PQ0JHf4xgPesq1dVi9WFCwIv4/TBay1Wa/esdt+y4uYnW7Ai2gJlWVQ71/xbfNvPqj Fm5ZWa9emSVx3wChY6NjQkyT91iGxwfJKzA41stNUiBjKoA042sJZ0CZeeHcmSD4Z4sA DKq2MLsBWqeE3D5g6wGIUmse+W8sZgQne/Zc7NoLNyRVs7z2OTf2yjfnJNq4xJujAdrG Rgg8Kkh9o+UxE5vKoD1zWZkbn8r4CrPE4LQciIu4WlmfvNt4Df3OznImAA7+2TEtIpSY g8QIYT+xDTsKmzuuNOs2eO0EpaVoOEq0agKgQ2td1PlMuNxECs/lEMxF5Z7wjabjw+5V AufQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="EP/O/eLj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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. [23.128.96.31]) by mx.google.com with ESMTPS id bv127-20020a632e85000000b00577a51961eesi3070733pgb.357.2023.09.13.05.19.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 05:19:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="EP/O/eLj"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 C0F59826E8B6; Wed, 13 Sep 2023 03:49:29 -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 S239795AbjIMKt0 (ORCPT + 99 others); Wed, 13 Sep 2023 06:49:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239733AbjIMKtQ (ORCPT ); Wed, 13 Sep 2023 06:49:16 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75C2219AD; Wed, 13 Sep 2023 03:49:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694602152; x=1726138152; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w56T0yhNaiatkjqh/uT3sOfSvQs6+aSo/JfJQY17ObY=; b=EP/O/eLjvuNw4Uv064A4PCcDZxXG0cU0p6wORSOn9BW0u/11kcZY9kbl QIFx36GGwXQSq6+7B4oBcBtLPv5+RNTINTX+/+w4VwROPr3QV3hubvMPr mNEagD2dt60pmKDhXmOXZZK59B8Okv2jKMw6TnMuieoejL7NxPyxuF38G 1n1TN5LDyORle/KSl80c5lw8MTqsYC9toVX2e8lQRZkgbL4yUkuA5fPk8 5uDgCalUVpKafz9iMXcvF5SHkfTUHadMdfRxkSqTavmwX+qSca03lPo0a URalsr8/2Gbm2pcpG00Sfl82i9IONrdm3iEQsg6V9d3r4xLrfRnpAHQMN g==; X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="377537889" X-IronPort-AV: E=Sophos;i="6.02,143,1688454000"; d="scan'208";a="377537889" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 03:49:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="809635592" X-IronPort-AV: E=Sophos;i="6.02,143,1688454000"; d="scan'208";a="809635592" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 03:49:11 -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 4/6] KVM: guest_memfd: Implemnet bmap inode operation Date: Wed, 13 Sep 2023 03:48:53 -0700 Message-Id: <852b6fa117bf3767a99353d908bc566a5dd9c61a.1694599703.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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]); Wed, 13 Sep 2023 03:49:29 -0700 (PDT) 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email From: Isaku Yamahata To inject memory failure, physical address of the page is needed. Implement bmap() method to convert the file offset into physical address. Signed-off-by: Isaku Yamahata --- virt/kvm/Kconfig | 4 ++++ virt/kvm/guest_mem.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig index 624df45baff0..eb008f0e7cc3 100644 --- a/virt/kvm/Kconfig +++ b/virt/kvm/Kconfig @@ -115,3 +115,7 @@ config KVM_GENERIC_PRIVATE_MEM config HAVE_GENERIC_PRIVATE_MEM_HANDLE_ERROR bool + +config KVM_GENERIC_PRIVATE_MEM_BMAP + depends on KVM_GENERIC_PRIVATE_MEM + bool diff --git a/virt/kvm/guest_mem.c b/virt/kvm/guest_mem.c index 3678287d7c9d..90dfdfab1f8c 100644 --- a/virt/kvm/guest_mem.c +++ b/virt/kvm/guest_mem.c @@ -355,12 +355,40 @@ static int kvm_gmem_error_page(struct address_space *mapping, struct page *page) return MF_DELAYED; } +#ifdef CONFIG_KVM_GENERIC_PRIVATE_MEM_BMAP +static sector_t kvm_gmem_bmap(struct address_space *mapping, sector_t block) +{ + struct folio *folio; + sector_t pfn = 0; + + filemap_invalidate_lock_shared(mapping); + + if (block << PAGE_SHIFT > i_size_read(mapping->host)) + goto out; + + folio = filemap_get_folio(mapping, block); + if (IS_ERR_OR_NULL(folio)) + goto out; + + pfn = folio_pfn(folio) + (block - folio->index); + folio_put(folio); + +out: + filemap_invalidate_unlock_shared(mapping); + return pfn; + +} +#endif + static const struct address_space_operations kvm_gmem_aops = { .dirty_folio = noop_dirty_folio, #ifdef CONFIG_MIGRATION .migrate_folio = kvm_gmem_migrate_folio, #endif .error_remove_page = kvm_gmem_error_page, +#ifdef CONFIG_KVM_GENERIC_PRIVATE_MEM_BMAP + .bmap = kvm_gmem_bmap, +#endif }; static int kvm_gmem_getattr(struct mnt_idmap *idmap, -- 2.25.1