From patchwork Thu Sep 19 09:44:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivank Garg X-Patchwork-Id: 13807607 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 B5D1FCE8D64 for ; Thu, 19 Sep 2024 09:45:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D1216B008C; Thu, 19 Sep 2024 05:45:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 480CF6B0092; Thu, 19 Sep 2024 05:45:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 321296B0093; Thu, 19 Sep 2024 05:45:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0E6AA6B008C for ; Thu, 19 Sep 2024 05:45:17 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BD7F6AAFF2 for ; Thu, 19 Sep 2024 09:45:16 +0000 (UTC) X-FDA: 82581004632.16.65CF822 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2046.outbound.protection.outlook.com [40.107.237.46]) by imf03.hostedemail.com (Postfix) with ESMTP id ACB092001D for ; Thu, 19 Sep 2024 09:45:13 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=H3POO4VL; spf=pass (imf03.hostedemail.com: domain of shivankg@amd.com designates 40.107.237.46 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=1726739056; a=rsa-sha256; cv=pass; b=rfPzou6gOyBP5vIAjAdzJWtwyE29VQbIbIN0JBbAtU72r4hFEfXourfVyIVOri4mTcEE6w 7JcNLh14zKROQepyedAtwxdGKoxjLfPzWt3aglRt3Kj+1eGLbZo6AYmzfv8c7V9GNxXXVr yXqVwKnD/ifA7RzXvOQ6KWGcqEaAYwA= ARC-Authentication-Results: i=2; imf03.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=H3POO4VL; spf=pass (imf03.hostedemail.com: domain of shivankg@amd.com designates 40.107.237.46 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=1726739056; 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=5wOCBU41KU/9jYAjuxEnaob8uAuZTVT2xJKX1zAfNJ4=; b=bmDN1PD6A7LPULxjktd3LchhT8h9LVt4CCdRNV0JvK25r/oaAXU2hWHGs5zBJzOKvv1tlW KskD0TrwuQy7PC23J+Wm261o00EC3PkQvtcJypUHxHzlj3dldqkQnAHeWVDh089ChWg8P1 wHHOYsKSGcpt7LAzJh7jMKem+SY/OEw= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Vv98mZ055XpIpRH7oeVcm2n29qWOKhwYeS8+YQYXVOQ66lLuGFfsx4ot0T+Q//v63o5Wwdi5AQOD4y6VAd6bL1u0cHOdRxGsd+2Ex7ihwNCIHG1pvrHYLUjCifFke8HUw7hSBdRLxh8/CQX8O4gwdUYOFSfv6IKX3mpyxvOIh/u/YTw1OCW9hjgTbqfenhEvb4syQtj+3z8+fuTKSIQS3WZro4Vl41ilIfNz4w6L/YBdTQ9JJCXW8CUb7WT8qsyK1NDwBI1tz9/22EYMsWkDX0dFaO0gkRAsxbeVDTIDqs/vQJPc8TfrkM5sBstTwBgoaIcSb9uHWxDzQpeks4WuQQ== 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=5wOCBU41KU/9jYAjuxEnaob8uAuZTVT2xJKX1zAfNJ4=; b=nFSDLYXIWGcYyXuv4R4ct1ERo1/R1bd0X5z314kli9YEdy5nDgMbaolyGD3QNACkRxhUjZG2yCqlMoGt52L4u5lv5aOV+vXSd+lGLRXhZjHVClsRqTYM99U0Oe9TMgspC63zeqQPJddMhzfPxu/oYTVbKDe5bwgUrZFrw+f36V8DEfYehdWqjuaY5nJvH7hBteOPNLVaWo2nqTcyJ8c93Q+RdFVhe0EP+A1h+4aGEwLSY24/EdBPrObQkFWUkQxK/eyBCQTgaVVLwPNqXo5AY5G5/VOodWQ4/OsHnCavL8BCheNzE4JwDkEWV7H/Kx1fc3MWnSwMr0PzFgz6NEUXrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com 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=5wOCBU41KU/9jYAjuxEnaob8uAuZTVT2xJKX1zAfNJ4=; b=H3POO4VLjrtWTRSVMGOiZ6zqWp1sSOpudJburHalHlF79Upd3tLNM3spgt2H3EXZnb9UH+4uvQA3Kc0bQ91lKLSQXV1yBtW+0aGmxxnkFWAf/AhXbJceRNvRv/+2XKGX+FKp5isY9/z5CN0DlF7XmNQPS3qBaqzu5Aq4Xq9m4Hc= Received: from DM5PR07CA0098.namprd07.prod.outlook.com (2603:10b6:4:ae::27) by DS7PR12MB6216.namprd12.prod.outlook.com (2603:10b6:8:94::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.17; Thu, 19 Sep 2024 09:45:09 +0000 Received: from DS1PEPF00017092.namprd03.prod.outlook.com (2603:10b6:4:ae:cafe::a2) by DM5PR07CA0098.outlook.office365.com (2603:10b6:4:ae::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.27 via Frontend Transport; Thu, 19 Sep 2024 09:45:09 +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 DS1PEPF00017092.mail.protection.outlook.com (10.167.17.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Thu, 19 Sep 2024 09:45:09 +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; Thu, 19 Sep 2024 04:45:01 -0500 From: Shivank Garg To: , , , CC: , , , , , , , , , , , , , Shivansh Dhiman Subject: [RFC PATCH V2 1/3] KVM: guest_memfd: Extend creation API to support NUMA mempolicy Date: Thu, 19 Sep 2024 09:44:36 +0000 Message-ID: <20240919094438.10987-2-shivankg@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240919094438.10987-1-shivankg@amd.com> References: <20240919094438.10987-1-shivankg@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017092:EE_|DS7PR12MB6216:EE_ X-MS-Office365-Filtering-Correlation-Id: 58805957-a8ea-462c-956b-08dcd88fc019 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700013|7416014|1800799024; X-Microsoft-Antispam-Message-Info: Rv8E5uecIgabxP5ll8kOmFJCjFHgm1nd/NbLTRCoeB6GJIKxcfS97sWMS7/N4BSU2qRf8b82hH2hG+vJPMqHwViciAIvDFJodMeh+H/5aeQQZoEv+Y0argQG5jCPSXW9Hz5hRANf0fh0NFmP1BuJDkIoeriIWUC/SjRZiIdALsROaZkxXdFAkqSGuN2vcdLGc+4dOV3muJ9eXPen2/rI/fuYMaJB34G9ihI24L26uCXwmY9M9HLNX46UxS6iCR78gBmYgzTm04Fb55Bbs4wDnIUKR4dilds8rd8Ms9R3BFM3nwqqtCcU899fByw8VgmHkQYJWLYK5z7lMe0cHWVYUtv2rGz7vq4qgHnMDdP26Vzzxjrt811baWe+wRlsVetb0WkbwSSMm9O9WVArk6kXpRTO87u66php6sGbZs3yKXF/GwpOlNzUhPrrWan9Waa+FKUP9+QvSOPIkTTAdoBsgy3yzTdfrZi5aCzINm7wLiWGVexDQfMol0fedvfpEV5g8ba003JVaDyxIQCtfojuOpSCvi8wIA6x1b8Ai7U8C2m777aGD2g9VDZYoVh55e21A/NFZhuq4P8wDEd5GQf+OBm9fSKnWsvXfxTMNWvUTHeK7Wk/EO7KNcNNYhZHmWOZ1YQyguDdlEoU0BJTYBFEAziu/dovUHC9Hujei3is6oU7k6Mn2EDov7GliO9ZplWmrSkzSGeYOEkSmcNoRDMEr+R9B/2F/EBfkm1CSeOLbT3txJEsSLVEka5UBb5djJwFi7PxjtdhUx87JssnQ9d5NHh9CJwJfSC/QnEKqhgl8u25CO1sNie2j70vOqFiDuS6HeNww1j/2lPm1VfjS1X3DAdfjQk0BImq2oqbTdtiRSRZRiB9cQ7XRqwZKBn1eAg5tZbTk/lvvnnhXd3N7c4EjuqyVo+1NCBdGRDXz0N2vqsAZXe475LoPLSrs13VBuE42hkO4UCXRknjhu2ldwDAbUwFcdBSi3FYPX/DCOUikkSEuekFDlMaOa8OntFisybaRoLI6yf4VdvgT1+2MxbCHbYkbG6Je8L7XSOIJ8z6x3KghhtMkoWOBaRKVEKP1OHGCb63Jv4G8XsniIEJpo4N6ot1B5u3fxRj7y79VAh/dHupl1bIJ15j8hMM8PMvMxLiesjyoEn7Uzoz2vTNTIM+64ncfjMfuluu1ZRF3Q8plTZGZjprVBNxp6Mm1kxzqZDjTpWqyZw/PHwRs7eQbPqt5GpK+BE4suGiPj7sK6x2rByQrvIb7Y+vuKeOZlcN9l1kWTouRXwdmlnkIuNwrB2+nUCrCGfwn1vGl9q+3lW60RhdPexdV2vNjp+mXHJpHIg2xj8MVY3SSQVqM++o4cyiHTHqa+qcTnjE0JqED0m+9qg59GpWl6Qd4/BRJl2rDQibFBmjkbQhiVV+1Er9wXf+vmg1aJ+GAbxwtzqeULvC7jj6hT1ZORHJC9I4rBuU10ha 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)(82310400026)(376014)(36860700013)(7416014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2024 09:45:09.3655 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 58805957-a8ea-462c-956b-08dcd88fc019 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: DS1PEPF00017092.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6216 X-Stat-Signature: d1tygea1kehdqo1hnotg3my1b9hserci X-Rspamd-Queue-Id: ACB092001D X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1726739113-135794 X-HE-Meta: U2FsdGVkX1/0q2+60HbK5kahDB8wBfiuPALs/wqz+4OlrUIKU0jBnroBbrCD5uMXpXDAzAN1j2j2CDVzsmn7+Gz4L0k3FttAMSS4LZRWX17456RTSlo8nveYCeCbBlu1DpfNX9v04/Nzus8S36T3PEZMQJS/RmXf0YeSD/d6KBeAoSQ1dzJFr1QG9YGWDYlJqWvdg0DZerWE+TUiqG62zqrZ7ukNDF3OGg4TKhHmaw9rZUPe95G3uLmnnuTeLcaqjM7qnGh633pRSAbwj+0YuiwgBkAGIni8+ogxJl6bYAW2paJMZcAqk6iegRwA3sbjDihVjFOMTI4mkVoofnGWPvMV6RFavSu7UPxH+Q60eobGk4tbxCGNB0OfBKvMsY5jjrWaDj/W52hd6/D3vXleKtFfqXyhwH+ZsUY1qqvVm4cltBgYe/7vAvtFwuk3uNUF9eolA04IT1LWt852HSgbwo7fhCde80dAagPMN0kjMOg/PNMkkLAj5pQ33AIrFam8+l01pc4deBS0ipAfqH6EXbjudRVOGyrQ7inlWS1WgrA3mTgyk2OI/MzE6rNGhdF7hMELKdjPgsDXokfWfS0MkEvhQOZMmX3FU9ePp9S4jnnFGWkJEz0QDS/f4rSUtJKDIOqITWuceBe4r4KGvEmpwUrVb4L86WwbrSL6i0XsNjk9yRi2sjJv/fplLhCP/OFS3wIAceZy77CL6ko2ojmP4EI6I7DtQqVJq8sbLIz/xil0SsBGk2LJRknmVpAmT/8ysYKQd+6Jax19EnLLzI61lGVdiQVfNTIMONqwLTWI+8vDwphuxRIw4bDJ0ZB95gUu+hj1UbAev5yjR8KDyak++T2MkLLPx1DMQ4g1sm3fvi01hp4SS+qppLryAH1u66WtLGWWORw7sTNj+6nncqArO8uTNK6B9ClsQpPccvvCGn78Wv+Mr53oVdnK9vPMgZGTRo4PgFJKMrBrF1EUbaa Dj3eOTz/ GBlyiOKJH4Z3+MSC4zh32DOQgr7FpNqA9uq3eHBhmgs0PvePUndLS96m1EVonVrOqZrIcBqsM8SxFQhQH5LhSN42NN36tYTToUvL7iLO26oSpmmdUugr4KoGlhZ38pyFxPbfoiiq1j9wRO/QPI9JeNxzfsETrbRa8G8pH6Pu109izKJE49/A/+Z1zyTcUsMTH0OYlXwCEs0ig7eT6BNX2OjSgOaTs9iVZfrhJarWSkKtfVCROExV71fTD2d2p8f6hQlKSA9YF7JQHTj0k+HtIJl77FA0ySqdX/O/bRInYDGITYM1a5Ij7WdFUKazAU/YhxV4IDQinqTyxB3kFMWsQG7kPZ5/arvFTnkBhgZEdKmG2BEORsn955ieFKMqmljhzP9kjovwHYB2jVD9HJwwDAgczI1anj04bEt3ItsQGGeEUUrllY49jqICNVUAvyRPnywA/M+vdTDYy8iA= 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: From: Shivansh Dhiman Extend the API of creating guest-memfd to introduce proper NUMA support, allowing VMM to set memory policies effectively. The memory policy defines from which node memory is allocated. The current implementation of KVM guest-memfd does not honor the settings provided by VMM. While mbind() can be used for NUMA policy support in userspace applications, it is not functional for guest-memfd as the memory is not mapped to userspace. Currently, SEV-SNP guest use guest-memfd as a memory backend and would benefit from NUMA support. It enables fine-grained control over memory allocation, optimizing performance for specific workload requirements. To apply memory policy on a guest-memfd, extend the KVM_CREATE_GUEST_MEMFD IOCTL with additional fields related to mempolicy. - mpol_mode represents the policy mode (default, bind, interleave, or preferred). - host_nodes_addr denotes the userspace address of the nodemask, a bit mask of nodes containing up to maxnode bits. - First bit of flags must be set to use mempolicy. Store the mempolicy struct in i_private_data of the memfd's inode, which is currently unused in the context of guest-memfd. Signed-off-by: Shivansh Dhiman Signed-off-by: Shivank Garg --- Documentation/virt/kvm/api.rst | 13 ++++++++- include/linux/mempolicy.h | 4 +++ include/uapi/linux/kvm.h | 5 +++- mm/mempolicy.c | 52 ++++++++++++++++++++++++++++++++++ tools/include/uapi/linux/kvm.h | 5 +++- virt/kvm/guest_memfd.c | 21 ++++++++++++-- virt/kvm/kvm_mm.h | 3 ++ 7 files changed, 97 insertions(+), 6 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index b3be87489108..dcb61282c773 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -6346,7 +6346,10 @@ and cannot be resized (guest_memfd files do however support PUNCH_HOLE). struct kvm_create_guest_memfd { __u64 size; __u64 flags; - __u64 reserved[6]; + __u64 host_nodes_addr; + __u16 maxnode; + __u8 mpol_mode; + __u8 reserved[37]; }; Conceptually, the inode backing a guest_memfd file represents physical memory, @@ -6367,6 +6370,14 @@ a single guest_memfd file, but the bound ranges must not overlap). See KVM_SET_USER_MEMORY_REGION2 for additional details. +NUMA memory policy support for KVM guest_memfd allows the host to specify +memory allocation behavior for guest NUMA nodes, similar to mbind(). If +KVM_GUEST_MEMFD_NUMA_ENABLE flag is set, memory allocations from the guest +will use the specified policy and host-nodes for physical memory. +- mpol_mode refers to the policy mode: default, preferred, bind, interleave, or + preferred. +- host_nodes_addr points to bitmask of nodes containing up to maxnode bits. + 4.143 KVM_PRE_FAULT_MEMORY --------------------------- diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h index 1add16f21612..468eeda2ec2f 100644 --- a/include/linux/mempolicy.h +++ b/include/linux/mempolicy.h @@ -299,4 +299,8 @@ static inline bool mpol_is_preferred_many(struct mempolicy *pol) } #endif /* CONFIG_NUMA */ + +struct mempolicy *create_mpol_from_args(unsigned char mode, + const unsigned long __user *nmask, + unsigned short maxnode); #endif diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 637efc055145..fda6cbef0a1d 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1561,7 +1561,10 @@ struct kvm_memory_attributes { struct kvm_create_guest_memfd { __u64 size; __u64 flags; - __u64 reserved[6]; + __u64 host_nodes_addr; + __u16 maxnode; + __u8 mpol_mode; + __u8 reserved[37]; }; #define KVM_PRE_FAULT_MEMORY _IOWR(KVMIO, 0xd5, struct kvm_pre_fault_memory) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index b858e22b259d..9e9450433fcc 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -3557,3 +3557,55 @@ static int __init mempolicy_sysfs_init(void) late_initcall(mempolicy_sysfs_init); #endif /* CONFIG_SYSFS */ + +#ifdef CONFIG_KVM_PRIVATE_MEM +/** + * create_mpol_from_args - create a mempolicy structure from args + * @mode: NUMA memory policy mode + * @nmask: bitmask of NUMA nodes + * @maxnode: number of bits in the nodes bitmask + * + * Create a mempolicy from given nodemask and memory policy such as + * default, preferred, interleave or bind. + * + * Return: error encoded in a pointer or memory policy on success. + */ +struct mempolicy *create_mpol_from_args(unsigned char mode, + const unsigned long __user *nmask, + unsigned short maxnode) +{ + struct mm_struct *mm = current->mm; + unsigned short mode_flags; + struct mempolicy *mpol; + nodemask_t nodes; + int lmode = mode; + int err = -ENOMEM; + + err = sanitize_mpol_flags(&lmode, &mode_flags); + if (err) + return ERR_PTR(err); + + err = get_nodes(&nodes, nmask, maxnode); + if (err) + return ERR_PTR(err); + + mpol = mpol_new(mode, mode_flags, &nodes); + if (IS_ERR_OR_NULL(mpol)) + return mpol; + + NODEMASK_SCRATCH(scratch); + if (!scratch) + return ERR_PTR(-ENOMEM); + + mmap_write_lock(mm); + err = mpol_set_nodemask(mpol, &nodes, scratch); + mmap_write_unlock(mm); + NODEMASK_SCRATCH_FREE(scratch); + + if (err) + return ERR_PTR(err); + + return mpol; +} +EXPORT_SYMBOL(create_mpol_from_args); +#endif diff --git a/tools/include/uapi/linux/kvm.h b/tools/include/uapi/linux/kvm.h index e5af8c692dc0..e3effcd1e358 100644 --- a/tools/include/uapi/linux/kvm.h +++ b/tools/include/uapi/linux/kvm.h @@ -1546,7 +1546,10 @@ struct kvm_memory_attributes { struct kvm_create_guest_memfd { __u64 size; __u64 flags; - __u64 reserved[6]; + __u64 host_nodes_addr; + __u16 maxnode; + __u8 mpol_mode; + __u8 reserved[37]; }; #define KVM_PRE_FAULT_MEMORY _IOWR(KVMIO, 0xd5, struct kvm_pre_fault_memory) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index e930014b4bdc..8f1877be4976 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "kvm_mm.h" @@ -445,7 +446,8 @@ static const struct inode_operations kvm_gmem_iops = { .setattr = kvm_gmem_setattr, }; -static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags) +static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags, + struct mempolicy *pol) { const char *anon_name = "[kvm-gmem]"; struct kvm_gmem *gmem; @@ -478,6 +480,7 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags) inode->i_private = (void *)(unsigned long)flags; inode->i_op = &kvm_gmem_iops; inode->i_mapping->a_ops = &kvm_gmem_aops; + inode->i_mapping->i_private_data = (void *)pol; inode->i_mode |= S_IFREG; inode->i_size = size; mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER); @@ -505,7 +508,8 @@ int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args) { loff_t size = args->size; u64 flags = args->flags; - u64 valid_flags = 0; + u64 valid_flags = GUEST_MEMFD_NUMA_ENABLE; + struct mempolicy *mpol = NULL; if (flags & ~valid_flags) return -EINVAL; @@ -513,7 +517,18 @@ int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args) if (size <= 0 || !PAGE_ALIGNED(size)) return -EINVAL; - return __kvm_gmem_create(kvm, size, flags); + if (flags & GUEST_MEMFD_NUMA_ENABLE) { + unsigned char mode = args->mpol_mode; + unsigned short maxnode = args->maxnode; + const unsigned long __user *user_nmask = + (const unsigned long *)args->host_nodes_addr; + + mpol = create_mpol_from_args(mode, user_nmask, maxnode); + if (IS_ERR_OR_NULL(mpol)) + return PTR_ERR(mpol); + } + + return __kvm_gmem_create(kvm, size, flags, mpol); } int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot, diff --git a/virt/kvm/kvm_mm.h b/virt/kvm/kvm_mm.h index 715f19669d01..3dd8495ae03d 100644 --- a/virt/kvm/kvm_mm.h +++ b/virt/kvm/kvm_mm.h @@ -36,6 +36,9 @@ static inline void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm, #endif /* HAVE_KVM_PFNCACHE */ #ifdef CONFIG_KVM_PRIVATE_MEM +/* Flag to check NUMA policy while creating KVM guest-memfd. */ +#define GUEST_MEMFD_NUMA_ENABLE BIT_ULL(0) + void kvm_gmem_init(struct module *module); int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args); int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot, From patchwork Thu Sep 19 09:44:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivank Garg X-Patchwork-Id: 13807608 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 52469CE8D66 for ; Thu, 19 Sep 2024 09:45:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5EAA6B0093; Thu, 19 Sep 2024 05:45:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0B366B0095; Thu, 19 Sep 2024 05:45:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5E526B0096; Thu, 19 Sep 2024 05:45:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 96B766B0093 for ; Thu, 19 Sep 2024 05:45:24 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0F6AA1C297E for ; Thu, 19 Sep 2024 09:45:24 +0000 (UTC) X-FDA: 82581004968.10.7A3456C Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2075.outbound.protection.outlook.com [40.107.92.75]) by imf17.hostedemail.com (Postfix) with ESMTP id 1DA2440006 for ; Thu, 19 Sep 2024 09:45:20 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=lANo6acv; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf17.hostedemail.com: domain of shivankg@amd.com designates 40.107.92.75 as permitted sender) smtp.mailfrom=shivankg@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1726739110; a=rsa-sha256; cv=pass; b=XE4ZpfVSukKgcul/z5fO3MhgNPelWRmgCkvtVZE4XeCyRkv3g7svnejBoKOvGJ0F6IwuVx wQ9lzL3Nu2aXqxu9wIJWuIiLttJH1BLijaUo5aa2zacVJn8TkAbpe6NPYw5BevTJlsYYly BPLgPQ1fCNv5TyIp+lxoRaCWEGh4UeI= ARC-Authentication-Results: i=2; imf17.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=lANo6acv; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf17.hostedemail.com: domain of shivankg@amd.com designates 40.107.92.75 as permitted sender) smtp.mailfrom=shivankg@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726739110; 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=9SNmEP9ffiNaTSzFYP+hIwyVz5gMf9kYO9erAqnd/kk=; b=3syulSoGCa96OCJOrANKr9FiwLEmnZXuAKreiWnZnlB9MAdLp8ySP7hZszLjbTnnPVUkd0 UFqUua0rpqBV8qPwgB6OkgMd4gAL368tHbon2VkFOSZ0Pwu+HVkMmU2nM1AubTT5EWNQ90 WqzwuKLuEG2iJMuC3s6gx1NdPUXOUMY= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LRqUZ6BrEe7UY/a1P8pmGcdvkoxt1WvbAyl3/t974e2bQtwVgS3ZuslsjPsb3Wh9BVBciwqzEcfsCViRjRUzQCE1HHumiqmpU6zg/GhduRKV5gsaNn2pcNXlhTKSPI2D4nzHjvRsywQ9oYMmGlOOAieeWZGz+Teu1/tDdH1gCk9do/zgg8n5JRcFdw8CrBlXWqrl/yCyICSCzo4/17RSMrrgdC5skcLhQVs/xrU2ZFCRPUQaVl5o1aU+H0R24ng0hQo5qdpJ6eKDMTQbDJUsp06ehDakb3DYMFtgP/gn+IVVoL5HRYPnjwMGOQZxGe+qUGTz+rHgbUrCQWEDEKJ7Ig== 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=9SNmEP9ffiNaTSzFYP+hIwyVz5gMf9kYO9erAqnd/kk=; b=dmitq/5JsDFYxtcyAbtQNBUxLBWC/t6zGV3CQieTAMg4sk4n4w1p6DyTk/nlx/bXQhcf/SIMnOAhkPsP8X5okvk0T/Yn0vLo4zeAQDOnetmH5D1PWt9bNEXMbpPxA0ZI9G/YZkuTVFNVjM1SnnA8omZkSrRHk4dNCxbIOROK1ePNHlIvAI6tz6yFbqqZfavci09A/Q8dk6j/P4EJOPODkWyrswYZbyq3CS6GHN6NZLMmvstq4mFKAVlWrQpcYaGs52SxZ/IZD8oOXssAIaqPNmrLsKa1zCbpZwamo0v4Pj9PpN68WQjhkAng5tYxQ9J+aat6CElKlnBqzDbzyeG06A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com 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=9SNmEP9ffiNaTSzFYP+hIwyVz5gMf9kYO9erAqnd/kk=; b=lANo6acvFf3wQAq+d1mNdnxs/jVhMSKkQceJknALt8OpdBodY9kxGUOGk5Ix0srL+t2L09RhF59IzkzN+XHgLqkvnZDM+7VMs+pse78kqeNKGbTdlpsIVhDsV2shxd6DRxMEka1sWjSRiksIzuXnBqjMshxzYiT85EIV+60wl0U= Received: from BL1PR13CA0400.namprd13.prod.outlook.com (2603:10b6:208:2c2::15) by MN2PR12MB4287.namprd12.prod.outlook.com (2603:10b6:208:1dd::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.21; Thu, 19 Sep 2024 09:45:16 +0000 Received: from BN1PEPF00004682.namprd03.prod.outlook.com (2603:10b6:208:2c2:cafe::af) by BL1PR13CA0400.outlook.office365.com (2603:10b6:208:2c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.7 via Frontend Transport; Thu, 19 Sep 2024 09:45:16 +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 BN1PEPF00004682.mail.protection.outlook.com (10.167.243.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Thu, 19 Sep 2024 09:45:15 +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; Thu, 19 Sep 2024 04:45:07 -0500 From: Shivank Garg To: , , , CC: , , , , , , , , , , , , , Shivansh Dhiman Subject: [RFC PATCH V2 2/3] mm: Add mempolicy support to the filemap layer Date: Thu, 19 Sep 2024 09:44:37 +0000 Message-ID: <20240919094438.10987-3-shivankg@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240919094438.10987-1-shivankg@amd.com> References: <20240919094438.10987-1-shivankg@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004682:EE_|MN2PR12MB4287:EE_ X-MS-Office365-Filtering-Correlation-Id: 34a31009-748e-4b5b-42ee-08dcd88fc3f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|376014|7416014|36860700013; X-Microsoft-Antispam-Message-Info: HfzqPEcjGx5qNfopDq3cPnfkIhBoSu0aHEKP1GZL0xL9i3LqSE0Opc9+J80KJjffM+BbuhebIjKR/UrghO7aiY8i7vfTORKWW+rrW/Q4hiBEr9cpxLzUTVM2/h6mZks7zTGnWDxftTnlP1/eBhnkinOXAOWABRfzx8Iv7oJdbDDDJpbVG0RhNMRFPGCRRkb5UY1sAJyBW8dXA4AhcZ65iuuCCcbFCBb90qucx5jlGTN3x5ATSuthEx0Gt2nO2a4K6wYwh0Ze4yN+icatQGBtOrO2Z58oroqEwgHDBtRBRjq/6GaW1/cfCK48kRAhnEovofbv4j1baO/7sQynazojpzWVm3XKf6JcDxb11K4rkLzvF/H9nNehvz2pwesPiZvaJ4RCBVxt0933TI88XMbZrLgeI/Ag2LnwmH9qN+mIctWCBrrQfwYsptO6BV2cP4Rv8waJhsS9/FtSQYanbyAehy1CleMGsniTVCretlYb3zn+ME02mEVnfoBP2U5/8mhIxYbjtqArKhKiMIDiRcplE/xWo7FkMuh1ip8pHFdR4VnyjSmflQg1eiDotiqAZxI8D4Jro1/R+JTBxr4bhInE7lSp2fKrcBN0ipw6gNewvUO0rO5cAM5F6iRuqQ1lNHzp319gwyu7n2oyqrCKGdpBHZlsdrifOxD33Q4NH0NqFEQ0hL4MDeihfY/mGQ+IsQvu9Gd6A0bF1MdHnzJ5iHE11ZBJe7EIZcK20DywZqdDsc7VNHW3BDtg0ZTtAh4oV/VrqLhQCZVpeMuDIVz5xEqrx4fUAR4Q68HSUtb+SzES94EPgJP1zftKLM5zhzGbf/h5MflQZe3C9Zw0FiikpC4dOkbuxd8ylpH1Wxl/hCxLcEn2Tm7Dtyrv1vetQZB0XKKAWdBm4Y19+GDbCgGhigWWm84jebVckwZKs+gyHdlTk3E0GOq/GzcxLbqibKm2o+zwNlKv6a7AYyUq+FhyGOfpp112/dhY6eeYaLxPRK4tlinc48l01UGrwJnaURcukae45PFp200CWiADR7XoYzNH6GXUKFIOEr06/jbl4rluf5zvnoom+WfUBmtHsAIJZnL6mCrBzhcRt8bOHtYXYj+aloucy4VzmOtWP2T6/yNGmqr/T/CXggfPujYFbmUdATzrwFfJyuOY9alTDiIPhQrB5htM5Kst83RP+Enp11cgWpkUE35OfVmXgY/HLryMNFaUUO+cw/j0jOCjMPMQ3I6DX7jb5HjEzzl9DoOpdRNfxT3T/ML1DSvoaq+rhdHFaqRO29CvL30nw/DTG/GEZT47eRnqWKVPpziq7yPU+ednwnRHiBsPV+Ocy7HVZPDRQag25pi2mz9fQ+CQEPlnmrOCdhx+0H6C1+QNmEk0eQIe8vqgjCjHnPvwkzPSO17x+hYaTfaGlwBNX2q0jCyJtO+fWPUpxjDNskMemA0dBKrFVTayo2Yj8Kz/NW0zeWv7xfrh 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)(1800799024)(82310400026)(376014)(7416014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2024 09:45:15.8736 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 34a31009-748e-4b5b-42ee-08dcd88fc3f8 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: BN1PEPF00004682.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4287 X-Rspam-User: X-Stat-Signature: c5oynfsx8cx1cwqsxstcdyjpgx7fksnp X-Rspamd-Queue-Id: 1DA2440006 X-Rspamd-Server: rspam02 X-HE-Tag: 1726739120-178289 X-HE-Meta: U2FsdGVkX1/LtM9vw1ApHB1yRIXuyByPCd0fI3FoZJltfRJd3tuHcobM9vDnArPPGpOI2mrzWAe9DGc5S2BXFbgg5rNNx+GEDZVAuBSP++3V5l7zi4gyXtES8K2qUnYmoKDOwKQ5YGJRzahWnTpYDW0M3aWibKX6eliFkCvcTetfWViQYxtPeS8/3R49gOs7BPosmn6mRSwsqTBnXM/6GQe9TStd+/Yy/DYlmgfRGxqA9RPJ07u+lxiKP0leUo/TAm9RH3tGQxrCBbD4x8PNmFVcgu9qj9RBoKHfJNEbE6rIJXZD9zR4eWiMOACLP0POlVQehmcrHkH+QoGDRQvuDYC1Ftv19bvkO0lRrVhNI3eg/X1bPLF+Vr8+sS+Q8SCB2R1k1NjGPON0cgyrrFw7+ahY1862yowZgi3OPqVdNoCY3L2W5iYSRsVzMn7bUVaUuknjcMt2AeR+fQljwDk6jM7Uc6slBxoRw2bWfiyqajDPTw1HenE7wIYfK/SQB1PnKoI3XNFfvC6wJ0SmWHRX4haxAAzxiBapRjhHdgcrfJGgNM3I2qk1y9xqyClbZFhp456s27mCH42J2byyGoFeS5/kyf6xVsCNM2twWpvR5HS0EWOCoY8KeTz/VeMbSmKhhWjcamsbkuSgFKnBWUK/vNCVWn638eFqT36YOfqxur9KlgnUKPaiuwAmPXghtf4Rr1tPWs5wIv4KurRT9PCuorR/g8vKJCJIv+1imQ5UJ3u5AgfyCqw3F3NZs680RQS7epL4jefepfln3klQmih88kcDXWfFrZno2azF0FXRqNfDuH/BgIq23UeM82pu5gb2WR5aK77FNpMeCrQrsMQ/noYRHnpehh/zv+fpbpd3Hn+RXi3BPnXwRFq3Z1ZMxkIQrK6z6RGpguDVhRViBLM/bJrNscGHoEQ/SRcyB825YhXgolo/j9TUi+4FKgXoyhdpfvV+zoDJC/5DQ7Ltdz1 K0Azh+u4 ekWYKFSX6r8OKTTg7zLxE2xDL+a/vQe5GRVDog+w31UA3rRll2ssJTB7v/kUteQddbKm/lewhT5nV58SlvCpVFk8i0hw4KFNTUkVvpdVq9nmfarT/mA5+9VtP7nlwHjw+Rhp4zEI8DX4v1WDAvI4ro27jW+BVqW7JP37/OPyGOw9NWgLtc9nJ3YM7xPUyl/WdUnZdzZ7TFHJ62oEkV2VGEMu54fRRmRI8T0PckvXIgj49ptnZw2+ks81EtgLHAP/b325aayg4pnnA87LxKyNvMzSxMvf3H5Cb6DIXduIlVaI9L8xdlmjtlSW2aPLqQ9FZnHPgwMRcHJtR6ruAXCBfwSkgEqLiZ0p6dn0muUVNYN80lmwW7FkBCmSQJyZ8atd5hj14739jdc4qMdm6ocmkhgtTigQLFh/Jw59t 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: From: Shivansh Dhiman Introduce mempolicy support to the filemap. Add filemap_grab_folio_mpol, filemap_alloc_folio_mpol_noprof() and __filemap_get_folio_mpol() APIs that take mempolicy struct as an argument. The API is required by VMs using KVM guest-memfd memory backends for NUMA mempolicy aware allocations. Signed-off-by: Shivansh Dhiman Signed-off-by: Shivank Garg --- include/linux/pagemap.h | 40 ++++++++++++++++++++++++++++++++++++++++ mm/filemap.c | 30 +++++++++++++++++++++++++----- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index d9c7edb6422b..b05b696f310b 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -564,15 +564,25 @@ static inline void *detach_page_private(struct page *page) #ifdef CONFIG_NUMA struct folio *filemap_alloc_folio_noprof(gfp_t gfp, unsigned int order); +struct folio *filemap_alloc_folio_mpol_noprof(gfp_t gfp, unsigned int order, + struct mempolicy *mpol); #else static inline struct folio *filemap_alloc_folio_noprof(gfp_t gfp, unsigned int order) { return folio_alloc_noprof(gfp, order); } +static inline struct folio *filemap_alloc_folio_mpol_noprof(gfp_t gfp, + unsigned int order, + struct mempolicy *mpol) +{ + return filemap_alloc_folio_noprof(gfp, order); +} #endif #define filemap_alloc_folio(...) \ alloc_hooks(filemap_alloc_folio_noprof(__VA_ARGS__)) +#define filemap_alloc_folio_mpol(...) \ + alloc_hooks(filemap_alloc_folio_mpol_noprof(__VA_ARGS__)) static inline struct page *__page_cache_alloc(gfp_t gfp) { @@ -652,6 +662,8 @@ static inline fgf_t fgf_set_order(size_t size) void *filemap_get_entry(struct address_space *mapping, pgoff_t index); struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, fgf_t fgp_flags, gfp_t gfp); +struct folio *__filemap_get_folio_mpol(struct address_space *mapping, + pgoff_t index, fgf_t fgp_flags, gfp_t gfp, struct mempolicy *mpol); struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index, fgf_t fgp_flags, gfp_t gfp); @@ -710,6 +722,34 @@ static inline struct folio *filemap_grab_folio(struct address_space *mapping, mapping_gfp_mask(mapping)); } +/** + * filemap_grab_folio_mpol - grab a folio from the page cache + * @mapping: The address space to search + * @index: The page index + * @mpol: The mempolicy to apply + * + * Same as filemap_grab_folio(), except that it allocates the folio using + * given memory policy. + * + * Return: A found or created folio. ERR_PTR(-ENOMEM) if no folio is found + * and failed to create a folio. + */ +#ifdef CONFIG_NUMA +static inline struct folio *filemap_grab_folio_mpol(struct address_space *mapping, + pgoff_t index, struct mempolicy *mpol) +{ + return __filemap_get_folio_mpol(mapping, index, + FGP_LOCK | FGP_ACCESSED | FGP_CREAT, + mapping_gfp_mask(mapping), mpol); +} +#else +static inline struct folio *filemap_grab_folio_mpol(struct address_space *mapping, + pgoff_t index, struct mempolicy *mpol) +{ + return filemap_grab_folio(mapping, index); +} +#endif /* CONFIG_NUMA */ + /** * find_get_page - find and get a page reference * @mapping: the address_space to search diff --git a/mm/filemap.c b/mm/filemap.c index d62150418b91..a870a05296c8 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -990,8 +990,13 @@ int filemap_add_folio(struct address_space *mapping, struct folio *folio, EXPORT_SYMBOL_GPL(filemap_add_folio); #ifdef CONFIG_NUMA -struct folio *filemap_alloc_folio_noprof(gfp_t gfp, unsigned int order) +struct folio *filemap_alloc_folio_mpol_noprof(gfp_t gfp, unsigned int order, + struct mempolicy *mpol) { + if (mpol) + return folio_alloc_mpol_noprof(gfp, order, mpol, + NO_INTERLEAVE_INDEX, numa_node_id()); + int n; struct folio *folio; @@ -1007,6 +1012,12 @@ struct folio *filemap_alloc_folio_noprof(gfp_t gfp, unsigned int order) } return folio_alloc_noprof(gfp, order); } +EXPORT_SYMBOL(filemap_alloc_folio_mpol_noprof); + +struct folio *filemap_alloc_folio_noprof(gfp_t gfp, unsigned int order) +{ + return filemap_alloc_folio_mpol_noprof(gfp, order, NULL); +} EXPORT_SYMBOL(filemap_alloc_folio_noprof); #endif @@ -1861,11 +1872,12 @@ void *filemap_get_entry(struct address_space *mapping, pgoff_t index) } /** - * __filemap_get_folio - Find and get a reference to a folio. + * __filemap_get_folio_mpol - Find and get a reference to a folio. * @mapping: The address_space to search. * @index: The page index. * @fgp_flags: %FGP flags modify how the folio is returned. * @gfp: Memory allocation flags to use if %FGP_CREAT is specified. + * @mpol: The mempolicy to apply. * * Looks up the page cache entry at @mapping & @index. * @@ -1876,8 +1888,8 @@ void *filemap_get_entry(struct address_space *mapping, pgoff_t index) * * Return: The found folio or an ERR_PTR() otherwise. */ -struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, - fgf_t fgp_flags, gfp_t gfp) +struct folio *__filemap_get_folio_mpol(struct address_space *mapping, pgoff_t index, + fgf_t fgp_flags, gfp_t gfp, struct mempolicy *mpol) { struct folio *folio; @@ -1947,7 +1959,7 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, err = -ENOMEM; if (order > 0) alloc_gfp |= __GFP_NORETRY | __GFP_NOWARN; - folio = filemap_alloc_folio(alloc_gfp, order); + folio = filemap_alloc_folio_mpol(alloc_gfp, order, mpol); if (!folio) continue; @@ -1978,6 +1990,14 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, return ERR_PTR(-ENOENT); return folio; } +EXPORT_SYMBOL(__filemap_get_folio_mpol); + +struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, + fgf_t fgp_flags, gfp_t gfp) +{ + return __filemap_get_folio_mpol(mapping, index, + fgp_flags, gfp, NULL); +} EXPORT_SYMBOL(__filemap_get_folio); static inline struct folio *find_get_entry(struct xa_state *xas, pgoff_t max, From patchwork Thu Sep 19 09:44:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivank Garg X-Patchwork-Id: 13807609 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 86B15CE8D64 for ; Thu, 19 Sep 2024 09:45:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14FD56B0096; Thu, 19 Sep 2024 05:45:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D7126B0098; Thu, 19 Sep 2024 05:45:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBB0C6B0099; Thu, 19 Sep 2024 05:45:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C746B6B0096 for ; Thu, 19 Sep 2024 05:45:28 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 84B3BA0B93 for ; Thu, 19 Sep 2024 09:45:28 +0000 (UTC) X-FDA: 82581005136.21.729DFC6 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by imf16.hostedemail.com (Postfix) with ESMTP id 9087B180007 for ; Thu, 19 Sep 2024 09:45:25 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=AhlQYqts; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf16.hostedemail.com: domain of shivankg@amd.com designates 40.107.236.41 as permitted sender) smtp.mailfrom=shivankg@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=1726739000; 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=t3TqfD3ymF6eqT4nlqJNmccBGoGKxBelhDPWPHnJ0q8=; b=IjB6eGHBgdp3sh3OQ4PmpM28dwyi1F2rn6Qs/gKqxKW7dHBodQeQyo+jtEWR03E0QlzU+t RYsvuOfAt8AMMABizkZ09w4AS1J7CQQqTS9LUzpp0L4NFl7NrIwqHeFK7cwPAUFu1X/a+f 0yEQ7N5oWH2Kp+77R+gxEQSbYk4Nf5w= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1726739000; a=rsa-sha256; cv=pass; b=ENjN7Kl5muOFynnHlBsOqp5YKwvcanz8fGMdT+nhVO2zwn3+yK975r+oRNctFWImdl/IV9 E+YoorVF5PBfqbhIh+R9AgCouzKXFGRx8xopBF+l12cA01lSKP8Yvar2ZowP9BrdCDddIU Ucnj5qYVNbsAUu8phqRyJGv8CO5vNDU= ARC-Authentication-Results: i=2; imf16.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=AhlQYqts; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf16.hostedemail.com: domain of shivankg@amd.com designates 40.107.236.41 as permitted sender) smtp.mailfrom=shivankg@amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=T+/r3YmQNREDWg3zA3VcBAHmLBjLCq6NPvLuqy7k/3WY7TY3jYq3LLXCxwQh1QucbXr6/ZUbgTOrPZN+gJWHptiIqyz2hkqNAOvfRsh9QLpxer9LHX4vV0ErUQpcOUwn8FEM7Ag/ugqeZ7uORi/TxY6ZuugGfkX8SO37Vt5AEKDrBBxkbKIjzh+4xao8O5CMMIjij1z6/WrXQn33FC8wG7au9EISBlHE6qg48MU51jaNz2oVn+DOL0A9gbCJJ/85mzBdekwRFo3zCAx7iX75uxfiYkmv/rpBhzZH2mfKyFtiRo8TaAG2RbpZg95j2+HY0zZ08KAbi1OwvR85p+SKWg== 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=t3TqfD3ymF6eqT4nlqJNmccBGoGKxBelhDPWPHnJ0q8=; b=SOCsn7rRaYO6k4af9vn/53JJEZi7H1/WUP4n4otLqOQOaEYm/Yatm38fJQvkKFiiYfO1r6kUQsJmxWskLX7seXdcoo95YmqqdvKk3SuKAdNnllcc0/kRXcb8Y3uBCcWwZxi3biyvG1S0NcH8uFQ2Me01LcEW+diJMYMaOlS4aIWqKuJ+3NGG/tV703IaGIzuLxFuq5AXQduvC2kLyxqB0SotxQi9raIkTHV9iw4XYHsaurkpvqhTyUaCWQBuhtqmtJDx6jp5Kc0VEc80T1NqBr7oHpxQ2SEJ0+OQfK+/JlajGWW0Hzen5lnUlKE196QW7MSatj2dEyAD2MwgsHoeYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com 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=t3TqfD3ymF6eqT4nlqJNmccBGoGKxBelhDPWPHnJ0q8=; b=AhlQYqtsfKDtZkZO2ypK528CjR61zshfcssxtXD2+6GT06xahb9TIt76EEXVEG1pDrdMQj+/+OD/a1OJe7WQeBXV1qYeCi0bBcFulbABHZWdoM92CxQ7/HrQewPKqNDFLDh2ve1q5ETPYWm/GZvPxaCKLkErzPMgs5W2zRNQ5bQ= Received: from BL1PR13CA0402.namprd13.prod.outlook.com (2603:10b6:208:2c2::17) by BY5PR12MB4307.namprd12.prod.outlook.com (2603:10b6:a03:20c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.21; Thu, 19 Sep 2024 09:45:20 +0000 Received: from BN1PEPF00004682.namprd03.prod.outlook.com (2603:10b6:208:2c2:cafe::20) by BL1PR13CA0402.outlook.office365.com (2603:10b6:208:2c2::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.25 via Frontend Transport; Thu, 19 Sep 2024 09:45:19 +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 BN1PEPF00004682.mail.protection.outlook.com (10.167.243.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Thu, 19 Sep 2024 09:45:19 +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; Thu, 19 Sep 2024 04:45:13 -0500 From: Shivank Garg To: , , , CC: , , , , , , , , , , , , , Shivansh Dhiman Subject: [RFC PATCH V2 3/3] KVM: guest_memfd: Enforce NUMA mempolicy if available Date: Thu, 19 Sep 2024 09:44:38 +0000 Message-ID: <20240919094438.10987-4-shivankg@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240919094438.10987-1-shivankg@amd.com> References: <20240919094438.10987-1-shivankg@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004682:EE_|BY5PR12MB4307:EE_ X-MS-Office365-Filtering-Correlation-Id: f510be3e-3ae5-4432-9f83-08dcd88fc63b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: CoH8PVwrVkFFuaqmWMh6HEMGGRoj7DTRG/ngW4R1N99ShmV/HedSKzqdxRwyYZbIX1jXfipv9L5/gEtxGGMxV+M205EkJTM0VOtzKZGKZbgmoUNV3wJr8A63IwCuw/VDU0xHwL4OdUM6XkuI3V5RxxAjxmM5UpBt5eUdAzGyYyqfGHaXQAEvaT5kUpqfO47hK52JCTtRsRHo/GBGlF76Bz3GNWxkS2s9hVvIB/e8uddp2Im7UOnBG12XEn7r2Ghq0qq6eS9l5o6hG6LXROfperp3ZlnR+pFFx+kcscYcXwc/PkMK2qeUhxtJfUM9uuJxvFlksuA95M/XbFGx3+yv2XJQaT2jg+LbQk/Nep80g7xX0jzZp+kymH05ig3runSHC7u7gtJiA+jND6tNDEndp6k7NW2ZU5a3sxkyjQl3h19h7pAumKVvt8QnAUgbj3E5nDTroDJSZ7xjK1kY0GrPplDEpIfIWZ7vzbYzfCAwpd+rT2oghREkCX3/vm3LVPbJQqPvFVt8zdLjlJ+QqCXth3XSzBOJNjtlUKNBC/eH4sSRCqrPUgru3N4p8oIqSCX4ZzlCRXwzdloswjLFfIyJSeHUVy9AY7pNQK90lrURWk5egt6ssbxtobPyUq3ngVr6ygyWCMrYwuz1Qn9hAm5mKi6W97/zJLkWghaF6zPyV8Ou9uA/d+yy4azqEh+mn6FUTwpdt+sYVmvooi9x70M+DsMAsU0a6dll3utSeVl8j1IKGz43r2x+dW6tlc/r6nCvGsw9i2iWXgkIHJr1J7VOuTMKQpe9EMzZKTF5ht9nCsaLz8QVisl5ziJnSNVVfoN5rJVrN2ENemo0PJxomt5KogA5rBGqAChjoqzsgHg2Rxyfmq9W1dA8BGOcp85iTSWAdjTxG5HT7Id2D30L9Of9Xtne17aKwqVW5YUcL/Vlil6bNGfg6qt1SpIH6eUoHh+huo5kxQ2zo3mpr3OoeXA6npOGMgMPuzRlgtT6YP7NsftMoU/z4woGm/CmPqf8mfcrVyh5+SFHtto4dwwCkfV8RtwvsTuh1dTQ/xGG2vWRbiC11NqqWHmQ/+mN3S3piAO6m+47hYpKkeyJfOOpK8LHkj2n8j8B03RFoP1EM61eZju1Z3PyC5IiU9sPe/2wyL+e42KZZ2EGbcVwcp56AngHkCUSocDlZ6PNfYKs+utak3UNBAqBqxp6/+4O3iT86uXdlFL4//iM3tZmbZ+VztKZ0VX6Pq1K6ZbfVZy5xBWqlTaYmXXYIJfjCHgSLmtnc6YDz2N7VC62bW1WKFUF72dzLD0DSrr94CS1kYZkV6ElYuBG3wORTnl+c+tJWj10rX9ypzRdg7vGagZ/iwDM0yb1n60iteGMmESC2bxGh9YvjqcNq5LV5VKvt8TtaoVWUSiuVZTAKlOg2XLoyNGPzlXiWhWCBvLaYD31SIGGkQP105iPgiR1Ob21VlwNAvD9+33V 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)(36860700013)(82310400026)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2024 09:45:19.6861 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f510be3e-3ae5-4432-9f83-08dcd88fc63b 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: BN1PEPF00004682.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4307 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9087B180007 X-Stat-Signature: 1e8uhiyzmhzhugatkdciapnqmim56ox3 X-Rspam-User: X-HE-Tag: 1726739125-495163 X-HE-Meta: U2FsdGVkX1/uHI3KJjSyKnBfCde+EuuSAiPklD4Y2HRf5xlELYiGFfsOf4Z3MLU1JrpPPiL/ID/RBR+gfZnlt4hxhhk8pAfBDtkikmcQD2HxWPsaRksWDBCJpXnhgnSoJbvlxIGmm2uasCebsddQbdyLlg624MsnfUY4ZmoXiDzDpJVi93RBpvSInzBKh5hcbX0j6f/ZmfNhNGedHztJOWx77HUdvCy7SvReARu912dNBnMzj/pQAnJIxa/qnxEY4LZH/ojg+bab6324s0NU+NvaYa/Azyhns3hR+tTXx8A1KaEbmS3kwtKN2HYdz4OvRgiY5q40TetHCA8fXre4ruu9Xv1ZaIj7Tb3EqKjwAYYPn/1IFuAhG5VeHArfOVSf8ciqHS56w8azbGGKljYdUCt4MmNd0n/dzvHwGgAhLipYk1bvFAnsHU+eZvTUPtt7qru3CA5Lb+38g1vpzCslfcToU4AF96higdpyAQmjlCHuYj7JPw3Ksg2G0VkxwQOXmsiztB6nSm/d2IwW3vhCGhTvxOht3vGv43COCxdvFPVmyRJdzPChNW7Uap8EZy2rIWK500j9ODVQV0FT8oqoOG2pjl6SX+hTbPFwKAjMXHxDP79NoaQLqC29a71nVTbRFBuuJPu8vCh5xidYf+QQkgCTXyrIOPd2zjYVBdqvMiBQPh6SKWRLhRNv7oWVH6OtywBXpt9rSeNhvKlnPw13M6WZ51DJD5QWc5UG+132gjhK9aUPNidzDYhgQN0yFLHAYTYRyfenuxNPU3zjiVzXM0fhNTI6lI2bM/5B7ZQHeMapMJafcy0xiz7MsokWD4qhKcKBrBTF5ti/k9rqfLZUToot/qFF0nk/izx8M8fgmy8y+BPFpVYhPNhUBsNZIUOWpMoLzTd7mODB0Jen86QSEHHVA/naJx1/Whr0KIiNVyRGhOh8xF2ViSmXTSgnoCQygEoVmjh4S2IiMNxSOrO uZeiRVZQ 4g26/iV/LIzXR/TKm1oHvL0zqezOBJmMQvUAuly9UxKlS4HQ6/9URnf3G51ampr1oDiCMK41SHthSmYJhRwc8maPuLY8fqAkqyu0CeYzzDbuUYXScbWp0RapLOW+S8QRGtYaMXai+QpXRE0QaOkWTCIGzuK8vMSK01WtHAWkHjUKyMqlv7JDmiWpuph8SuoKIrQsqXjvp9QiDeLhHMWgMhLJ15RL1qLekwvQsJYDw4Lst2NpAnuAJonPb70ReNJgQ4oqLymN4c7ckYNlPENt3slmw0jDnapvcwVjWsATXxTfpXqz1quXHyOxuN2DKGjKlB1Q1GPIoal7vuSKBs6/2UMOM8q6/HIL+E5s3V3PTAvtf9pTgqzfMRz2NV3z/HZ40egV6wvx0o7M504QmIT38Kbae23wtsTZ6qK5ulvYP8WKvgK4j7bValaDVSrt+iVuyBwENgheipbgIoA4= 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: From: Shivansh Dhiman Enforce memory policy on guest-memfd to provide proper NUMA support. Previously, guest-memfd allocations were following local NUMA node id in absence of process mempolicy, resulting in random memory allocation. Moreover, it cannot use mbind() since memory isn't mapped to userspace. To support NUMA policies, retrieve the mempolicy struct from i_private_data part of memfd's inode. Use filemap_grab_folio_mpol() to ensure that allocations follow the specified memory policy. Signed-off-by: Shivansh Dhiman Signed-off-by: Shivank Garg --- virt/kvm/guest_memfd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 8f1877be4976..8553d7069ba8 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -130,12 +130,15 @@ static struct folio *__kvm_gmem_get_folio(struct inode *inode, pgoff_t index, bool allow_huge) { struct folio *folio = NULL; + struct mempolicy *mpol; if (gmem_2m_enabled && allow_huge) folio = kvm_gmem_get_huge_folio(inode, index, PMD_ORDER); - if (!folio) - folio = filemap_grab_folio(inode->i_mapping, index); + if (!folio) { + mpol = (struct mempolicy *)(inode->i_mapping->i_private_data); + folio = filemap_grab_folio_mpol(inode->i_mapping, index, mpol); + } pr_debug("%s: allocate folio with PFN %lx order %d\n", __func__, folio_pfn(folio), folio_order(folio));