From patchwork Tue Nov 5 16:55:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivank Garg X-Patchwork-Id: 13863232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55B33D31768 for ; Tue, 5 Nov 2024 16:56:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D85F86B0088; Tue, 5 Nov 2024 11:56:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D0FD26B0089; Tue, 5 Nov 2024 11:56:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B88B26B008A; Tue, 5 Nov 2024 11:56:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 93FEA6B0088 for ; Tue, 5 Nov 2024 11:56:11 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 417631C6E15 for ; Tue, 5 Nov 2024 16:56:11 +0000 (UTC) X-FDA: 82752641832.17.ECE5E17 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2083.outbound.protection.outlook.com [40.107.223.83]) by imf12.hostedemail.com (Postfix) with ESMTP id 2E4124001B for ; Tue, 5 Nov 2024 16:55:53 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=IlYPTqU0; spf=pass (imf12.hostedemail.com: domain of shivankg@amd.com designates 40.107.223.83 as permitted sender) smtp.mailfrom=shivankg@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730825584; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VYWSF/gUUp6fJckNhr9t7F7Ukp+JcQngNTbbZJ1S7CI=; b=seoMaG7WfkHqj5UOOklTU3M4Wd82Sn5KlGxcuTeUwwuaGKS6N73lgxj+glBRDLILHBunyr +OixOUd8QxRHXZYH8i4s/QRUJRRmFrDcFsu0+8IXfEL6Lc7v+giUATkiuPuaHZfRzGQnOF va52fGeXYy8Mcv/zYEim9gcAHKo6/5w= ARC-Authentication-Results: i=2; imf12.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=IlYPTqU0; spf=pass (imf12.hostedemail.com: domain of shivankg@amd.com designates 40.107.223.83 as permitted sender) smtp.mailfrom=shivankg@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730825584; a=rsa-sha256; cv=pass; b=1dh/gorCvkIf1bwl2Fp1dsFXptZjHDcrGomDVfmBmrruZhXIJeYELcLE1G2wWRvzZtrWbD QFAOm9L4zjSMtvMAAq+8g4UDSMT0oNjv+iwsHvK59S8IGqS9t6dJGaxRsIw7Va4ptF0fUa mOsw+3J6JnvJvvLvhd8eFQPPVixyb2U= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VQNqx5rfkrm0xspFXiRFCw3B3iZ4DSgHhAoD9r1uvmo/wmeW1OFahr0qh6TljCoY6JSD/apke9ye4EDV30RmAE/PDE3T7hsMtUd7IIMPh40CIBISgx9XAqsC4muoHyLxDGquqdW9aljdvTTzYFGpI0amj8wYlf/N3CWLhi5evJ7kWKHLg8BtZamJcRAWB74ChKFQr9OhMQ4B2IJFiSUSTqe39ZidnbV0tKaYqxdNfZAeGc2wU/h78OxlgBrH6kQFQHu11ELf761liu3wPQe7BsrRqXDLxX6e9qrimlyrSjsBrlmkMF3SLyhx01BVO3NseOsHMHGawtOh1+zEeWYqaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VYWSF/gUUp6fJckNhr9t7F7Ukp+JcQngNTbbZJ1S7CI=; b=qHJb8CGziQ2aeXFgkWYT38mnMrZTSaWRsqM9W74sRPAF/pXhxh30oPlsGt4w/ig84f9SUCDoAg0eZ2i9jdCcXol7m56DC1LLcDOEsCEsBwT2Jt3UIJERbGf7A6SyH9nKKiyoFFVqDdRkOmMNNfBxMYyjzELa/7bcZ8sEXppqh+GO2+W1VwFlyeWKpKNNk+Jt06lz1fehbbF71Ign10QJxj2nQtbffdxeAAnJ3KpagagxzKqErjI+2dD9pzfuvsh5HxrJxWU5E6ODcfiIo0S0mCzsLoivAswb9aE3oZJaRziGYeuRrruCFY21IPY2/PPgRDzFTd/K/xq+bTo1Wn8hAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VYWSF/gUUp6fJckNhr9t7F7Ukp+JcQngNTbbZJ1S7CI=; b=IlYPTqU0xLrL11gzMjByw9GvzskWtKb1K82/OcB11/CSOEbMDjGGT/pmq6hp/PE7Hko5A59NLzUuM4nelSBPToUnP1oiGm85KcOGCewyaAoblO4E4VGmNz/hX645zBSHGITq1yAKCO5B82hP8tqCRH3U1FieftDrUwFSc+am6i0= Received: from CY5PR18CA0023.namprd18.prod.outlook.com (2603:10b6:930:5::19) by DS0PR12MB7993.namprd12.prod.outlook.com (2603:10b6:8:14b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Tue, 5 Nov 2024 16:56:05 +0000 Received: from CY4PEPF0000E9D7.namprd05.prod.outlook.com (2603:10b6:930:5:cafe::4) by CY5PR18CA0023.outlook.office365.com (2603:10b6:930:5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.31 via Frontend Transport; Tue, 5 Nov 2024 16:56:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9D7.mail.protection.outlook.com (10.167.241.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8137.17 via Frontend Transport; Tue, 5 Nov 2024 16:56:05 +0000 Received: from kaveri.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 5 Nov 2024 10:55:56 -0600 From: Shivank Garg To: , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , Subject: [RFC PATCH 3/4] KVM: guest_memfd: Pass file pointer instead of inode in guest_memfd APIs Date: Tue, 5 Nov 2024 16:55:14 +0000 Message-ID: <20241105165515.154941-2-shivankg@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105165515.154941-1-shivankg@amd.com> References: <20241105164549.154700-1-shivankg@amd.com> <20241105165515.154941-1-shivankg@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D7:EE_|DS0PR12MB7993:EE_ X-MS-Office365-Filtering-Correlation-Id: 03792042-eef5-4eec-8dbb-08dcfdbabcdd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|36860700013|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: yWtUKC3+lYrQaPGckXHSaZZGA/1P/8AG+rQDXmYCIQtPHypCTizIy68gOl+/Sb9lO/JWITKK+pF+mTPdawJhvfjh4yubbxp7r8J9nV3YbVPICO/2YbcSw2Qa7fQFMwfcm9X/beYsr5VKQ04l4v1OlL7IuGbYy5V8CadVpzRD/D8qsRbm7fy4nn/TE+9yoGZh+9afGtgpS8gsAaZyM6uYH6A6vnc/r1VcVMdqKmFgAVqQ4VVwJEYO78PkQ77YDhNAtZUVrFVqKMG/b5mD+7uA6a5c1njDMfuz7U2yyEpwqayoltGlIow7czaqQERMsm23jh/w6pz9DUu522IA3QmJgVn14b1z9OKwnABQcJwNSfnVs/+SHaarTKUcMxCVqZx2EcizXZ7De1UwVcz07i9wgBSQDcyRR/3gQSEXDZOmVZFo4fQCF/IIexbUEehJNnkG6MBOV/MhF492Ld0ZyiAtHtQWKjDHsthvRHk8c3OihnOVu3TlBygX7SwtNwiVywG++Y4moLigQGBwDUtKYAZ4PrGutzyMrZalPhGiFRvdb+2fjIdhfQz+RFI3QBx7BlSsKaWQLpboZRMco7n5jZ4uyp/OvRIMvOVTqNW9NWOrAWKnRzdQscWHQq2T2D9+3oEAGrSfSi8b6Rl0OLg6wH2/Ab5gB8JE+NCjTc0cXeKU8DLjAOXnqucV/1dQ5QcYQhb0npRHiC76a5TL3CZt7st+4blSDOH0qHkzBucsaJVyd+4rQkzI4s9xbkpFsZxqLKuWlycY2LaP/wJ1YuGnSXEnP0VNDs/2pTF+XQydLyQlsCvksuEe5d47EMp/hGazFV+UR/RC+aapd4KXKowCmEfFieXXthnWvLSbH1EDwuh22xUDujSGAstc8iA6W50fDbUlB+5L332/NIEJeTDW11T4I+w6UOTwgFRZ7TxaqUQJ1AF81Nug6ohYFNSglTAsPqsE5pj4n1LphboDkpeqP6wH3idhOCjewLTiaMwcsatDvaGOKzW6p1BqTrM10iEZ6qL1wzbaI4Y87W40LaAQeKJHDhniw/KaN8PU3VgPmXlYePowTSx1992ijpOxg2VSyZYk02ikhC5j37pGjSF/itfHuBlNBqwM8VQTzD6YLZGFkMYx52kvML7I9i0x8DDCdiASdo7++ErLA8x5CIjGxSa3TdfuENqmOecemwokkA2bENRT6A+LgJuey9mBptoHXGCAi5QJX2p1Ttkh781/WwCmvQ180MNcemEk7bLwPtj19kM//S6LL8W5Y8dTHFfsdgwYxCDlGyp1CFRXRmmCm7dJcR6opKqtODHrtOinU6C7/QKI0d/eQG1P7A4EQbhR/Hl/IjTFFMsmhKiVzc8IUtJm1ORe03w56XA11Od67Moj57VgDxYKkc/IIoU1FrLzLWddb+WoYNKCERHfPL+SEcpq1g+2aGF5WjwPm6cl3CpAK1I= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(36860700013)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2024 16:56:05.2586 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 03792042-eef5-4eec-8dbb-08dcfdbabcdd X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9D7.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7993 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2E4124001B X-Stat-Signature: jejktwqfe1e6jmggemqpdygq83tnb9we X-Rspam-User: X-HE-Tag: 1730825753-105039 X-HE-Meta: U2FsdGVkX1+u6OzwMVKQhYUi+cY6T4YEXZP5uWSNHk12yWB73/vRY57UeYfeJEhduSQaHmxbcaC484pxBBVGAVCOE3jWaiRJfPx4M7s91MGazSJnFaLa+jPHk8KwzM7BoJJoog9tylYvqTIHhn9F3z7tR8XtSCJhya1vRDIXxTsXJFWXPLCLapVq8PotEB0Pb50ecW/PpHhPW9CEZP/WCUvg9HWOAJNmYM3lGxzAiYGPxiwHBLV+p9R2RzJPicNjeCq3BrcWaYF+me834UQjzodEFj0w3q152qotpwoJWNt31z6MJaw5QX0esVvRSr+G3u6KpYUPkc2hxGHDVwJ2avABqNZmg4jZCZb14rYflR0UOfx0v7TTvemDkGCccM4RnjgASMDxEleKhnIFsAez+YKPFLfzSeT7i451TzVa4JU3GI997yq/GqqQeABIEEXYnsS0lwt9w/HaojcOJoOp33EauFyvNCnIM03fPZoVs0+JpDmvDuD2Lv+6mbxLAvh5XV5HcJ0BNsywk8iPu4bT1LgENlJpK11ZNllMjnT9Zku/hAd6txdf83QKe1NFjLZVnf9HUbBwKYUwqTYaMrDaML//7/83dC2S98hZYIJ+KEi3fUC/N1RP0/EOHLZCoVxpkN2cshykk2jTczIwBkRvpm/bcdrSvwe5oRVZksRuZ9BFLnrY6WCGHiUP70vsbJJ5MgYSTBXtnmDqKUQN0EqhOca301Efib2aBmA3baXoXC2bQHmIYWAbvzPcK2/kJG2LHxtrX2X7Lt6J5XZ18iEq5tQDKd2tcvJ23tnrLdW6ijyscPLuBCMdeO95YrBYtRbB9a9me6kwnye0sbmzqlg30aoRWgpznRwu1RN9xt99N4omxZZ5aouv7NCJDesNcZlc6kvOalKTZhUkaaqj5QC6oNWMQlcaW0sPZA26/fl+LWZoKt043bHRrDQx+/9rTF2cSgEckxUDq2jD200DN91 MSh4WvSQ Za3DmbLlqaG49um4cn0SaY+tC3YFYJWLCeKwS+WeErBg1G2yfzR2YWb6RVGAs74rchCYvkotcyscSX8Z3DbWd+kjiNIAoZoF64JY9VE2RuyetDsOHN+9Gl4QG668cg7yV0BM8A2qCGPMY82C2SKv6xjEo0kB49PscsGdnJ8F3b7rjMqOjyh7nEAGFfYS/jVMC0303zc7YO+LtCdzKHRNceOMneCLszSPtb8cJWMOJgCKHWxZ2ZBV3hCk24c9H1mnBJ79CJW1BRmzHv/Xu59do9M4YHo3MNzH4BtlEvTU8bTXxAuEYKMC9+RmvXuGCdnCde4RzISoPycOXUN8bgmqreIfBKZFBKSpn09+CSJhQsQt4lYPskDMc+jWt1Lpqrwex+cundiY0TrrHr7DPmzTYWUhZ/5QvkKKqttxjqRN1PZWNFPeqhzwvpR04rWCJASFy8QbjIZsp+iwcHv7YWyHZMDev8rVpBctPI2dP32nmDYNs/+e3vVUd82Ufk3cpIRgMkSmy X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Change the KVM guest_memfd APIs to pass file pointers instead of inodes in the folio allocation functions. This is preparatory patch for adding NUMA support to guest memory allocations. The functional behavior remains unchanged. Signed-off-by: Shivank Garg --- virt/kvm/guest_memfd.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index e930014b4bdc..2c6fcf7c3ec9 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -91,7 +91,7 @@ static struct folio *kvm_gmem_get_huge_folio(struct inode *inode, pgoff_t index, { pgoff_t npages = 1UL << order; pgoff_t huge_index = round_down(index, npages); - struct address_space *mapping = inode->i_mapping; + struct address_space *mapping = inode->i_mapping; gfp_t gfp = mapping_gfp_mask(mapping) | __GFP_NOWARN; loff_t size = i_size_read(inode); struct folio *folio; @@ -125,16 +125,16 @@ static struct folio *kvm_gmem_get_huge_folio(struct inode *inode, pgoff_t index, * Ignore accessed, referenced, and dirty flags. The memory is * unevictable and there is no storage to write back to. */ -static struct folio *__kvm_gmem_get_folio(struct inode *inode, pgoff_t index, +static struct folio *__kvm_gmem_get_folio(struct file *file, pgoff_t index, bool allow_huge) { struct folio *folio = NULL; if (gmem_2m_enabled && allow_huge) - folio = kvm_gmem_get_huge_folio(inode, index, PMD_ORDER); + folio = kvm_gmem_get_huge_folio(file_inode(file), index, PMD_ORDER); if (!folio) - folio = filemap_grab_folio(inode->i_mapping, index); + folio = filemap_grab_folio(file_inode(file)->i_mapping, index); pr_debug("%s: allocate folio with PFN %lx order %d\n", __func__, folio_pfn(folio), folio_order(folio)); @@ -150,9 +150,9 @@ static struct folio *__kvm_gmem_get_folio(struct inode *inode, pgoff_t index, * Ignore accessed, referenced, and dirty flags. The memory is * unevictable and there is no storage to write back to. */ -static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index) +static struct folio *kvm_gmem_get_folio(struct file *file, pgoff_t index) { - return __kvm_gmem_get_folio(inode, index, true); + return __kvm_gmem_get_folio(file, index, true); } static void kvm_gmem_invalidate_begin(struct kvm_gmem *gmem, pgoff_t start, @@ -228,8 +228,9 @@ static long kvm_gmem_punch_hole(struct inode *inode, loff_t offset, loff_t len) return 0; } -static long kvm_gmem_allocate(struct inode *inode, loff_t offset, loff_t len) +static long kvm_gmem_allocate(struct file *file, loff_t offset, loff_t len) { + struct inode *inode = file_inode(file); struct address_space *mapping = inode->i_mapping; pgoff_t start, index, end; int r; @@ -252,7 +253,7 @@ static long kvm_gmem_allocate(struct inode *inode, loff_t offset, loff_t len) break; } - folio = kvm_gmem_get_folio(inode, index); + folio = kvm_gmem_get_folio(file, index); if (IS_ERR(folio)) { r = PTR_ERR(folio); break; @@ -292,7 +293,7 @@ static long kvm_gmem_fallocate(struct file *file, int mode, loff_t offset, if (mode & FALLOC_FL_PUNCH_HOLE) ret = kvm_gmem_punch_hole(file_inode(file), offset, len); else - ret = kvm_gmem_allocate(file_inode(file), offset, len); + ret = kvm_gmem_allocate(file, offset, len); if (!ret) file_modified(file); @@ -626,7 +627,7 @@ __kvm_gmem_get_pfn(struct file *file, struct kvm_memory_slot *slot, return ERR_PTR(-EIO); } - folio = __kvm_gmem_get_folio(file_inode(file), index, allow_huge); + folio = __kvm_gmem_get_folio(file, index, allow_huge); if (IS_ERR(folio)) return folio;