From patchwork Mon Sep 16 16:57:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivank Garg X-Patchwork-Id: 13805653 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 2917EC3ABB2 for ; Mon, 16 Sep 2024 16:58:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B00326B0096; Mon, 16 Sep 2024 12:58:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB0276B0098; Mon, 16 Sep 2024 12:58:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 929B16B0099; Mon, 16 Sep 2024 12:58:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7535B6B0096 for ; Mon, 16 Sep 2024 12:58:50 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id ECF27A0638 for ; Mon, 16 Sep 2024 16:58:49 +0000 (UTC) X-FDA: 82571210778.15.05759FC Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2079.outbound.protection.outlook.com [40.107.94.79]) by imf13.hostedemail.com (Postfix) with ESMTP id ED86620009 for ; Mon, 16 Sep 2024 16:58:46 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=QoxQZ1hH; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf13.hostedemail.com: domain of shivankg@amd.com designates 40.107.94.79 as permitted sender) smtp.mailfrom=shivankg@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1726505846; a=rsa-sha256; cv=pass; b=EwcpbnXrSXFsw8t0Sl2fkILztjZVuvIoiE+2TiR5hSlUY226jP+5kaYcKA5YMQFDJz5/DJ FO0PmmepgFfM76Bu85PX8DhGLo/GfEiEful7rRv7Dn77STdIPB+DrciCo0zWai1I/drLZk HUcdYc5VR6MArGw6TTTN3IKF0nbntUs= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=QoxQZ1hH; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf13.hostedemail.com: domain of shivankg@amd.com designates 40.107.94.79 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=1726505846; 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=OOf4NdlXsWVep6Tn+sZd2i4ctWjT8joLeneT+6HEDKKVvJcAftqXx0sya/Va5Wi3AIuOBl 64abwJQ2I7CoNqbi+/WKhX4chOH8y5v2nm+5iAH5/KYF/eoXixrecPJHHEf2xYg/1LXtkd 6xXOtPlx7R+tCi9khcJkiFnYR6/VIag= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=u5jIR95Kx2fG4Svhmo/jZ57vDaiWopGt1NRUJkPLZ1sr5b6OpvCqNr/b8CLLouCg6/Ngb0hKhGRQkiSXWwe0UFzWbpqitC4nHQwxmvvbeByxzrRP+FS4Ot6p4XD6P9+lfvlJefnGeGnquJ78iCNW4o95u3Xlgje7u+YDEjLEq0USwpyelgfggPN9PPY771lbLnTEcKz33L5GFinI1mlp+CkjODf4u6H+n8kmiDEjVa3VRk7ms1ev/BjBgwigcC65HD1lkXHz9gxg+/a8lk9pMMGlwBM/zGO+NkbsJ5PGbzZNVMsv4ZUs05RQNNqx718ilLeD+tX9ptC5z/XtcOlc7g== 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=zVJUD3LRylBHVZOH55tgjhN85vVulCoRXyuavhDntkWsEc8fo6yvE561c0aCcbjMkhXDawJAbeptmeXSzbOdIu+EW9hYrEUynwNWGFreUKqHm6JhUF53uW7xG5WEbR5K60exlvXW+K7aaf7p/+RZjDeftDKgfqUG5dQ94DUtOWBTyqitEGSRNEdodY8iWCS574kNKZsGVFNrIzL2aO54JtEFJalLLRGEKtbsL+BY4ybbAULwoN3PP1w2awqE//ygoEgHZu6t+i4pWIgTU/xHd5h2GCLo0GRKcJoJ4r28e2yWZGBnJ1jV677KZVZnm2RkB2uNuX9/owVQmf1QFXkCPw== 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=QoxQZ1hHyr14fQxR3BKCC715xWenv4az8sx9Mrzu2+etVof4p+8WXwI4VqWHS0/l4tvjQGubQJvwBJW5UTJjJH81sABWMYbXEgUIpnzXgNOYr0PqZCveenYyXsmahFspj1rAidfg0cunaKZl31ujzyrUgAKS+bJT2pBgwScFflg= Received: from SA0PR11CA0114.namprd11.prod.outlook.com (2603:10b6:806:d1::29) by DM4PR12MB5796.namprd12.prod.outlook.com (2603:10b6:8:63::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.24; Mon, 16 Sep 2024 16:58:40 +0000 Received: from SN1PEPF000252A1.namprd05.prod.outlook.com (2603:10b6:806:d1:cafe::40) by SA0PR11CA0114.outlook.office365.com (2603:10b6:806:d1::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.30 via Frontend Transport; Mon, 16 Sep 2024 16:58:39 +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 SN1PEPF000252A1.mail.protection.outlook.com (10.167.242.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Mon, 16 Sep 2024 16:58:39 +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; Mon, 16 Sep 2024 11:58:32 -0500 From: Shivank Garg To: , , , CC: , , , , , , , , , , , , , Subject: [PATCH RFC 3/3] KVM: guest_memfd: Enforce NUMA mempolicy if available Date: Mon, 16 Sep 2024 16:57:43 +0000 Message-ID: <20240916165743.201087-4-shivankg@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240916165743.201087-1-shivankg@amd.com> References: <20240916165743.201087-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: SN1PEPF000252A1:EE_|DM4PR12MB5796:EE_ X-MS-Office365-Filtering-Correlation-Id: f9f75e68-0ee6-488e-5b0f-08dcd670d051 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: +bwEEvAnMVEBX6U9xmGh4Fmg6LC4oZNUd5RW1KE4MImQuwJvVVQSmJStxXfbMohnRy3/t1VO8Xcpk3Yaxrqyk3/FIKBISMYPjLVxVotgX73pFAReY+qKp/lRPMbX8+g1t69fhT1ENYvWZXJrFuAJZFial2bSuH1GFWfmvdT6reG3l1r/8C86beh4BpqRERejjZCAzmy76eh6jVf5JJY5OP5serfVMGlWDwskLYzPbb2pijQCzyZjUfvqrZ/n4IUiVVvGLLCEZ3i5MgiwUf85ekM4mm9rSfLW0hBdstWQXTbUXv0UjIZw98ORE4sn+WWkhZGvgSYZMtvVQMAQIIrUvyfiZZWFub+q4ufUTtcyN32ah2Aq3AUmt4OvhO9yrMvPLZ46IAoMdOECuKgLNlyjGm7xOMfjiA7yu9v8XxDVzPPr1QtTyJQrDbLShEw3opunnNunwkKJPLOO0nsdJD4nPFOKyhnfSS1bGUtHnoah7bteYw5Lf4VEUvo8GY9lXNwSSuEgUywBeR3SJF951SeAspf99ZwZXs2xAh0jJg4Z8/B19pRtbFnemq338Swl1J4t/NMYsVOzvVZ0vYdOZG1oXikA3pmAI85+FYwXiL5uqDbtOVsZpOEKNrepGr7n0kjnJMlZ9R/ugm/OGkfKJPr0NzXDP4X5mIe81zSZxha+sAIhcMAuObmx17m/G3ofWcZr3+lKomLOT4XHDvqPvE8SugY3F9CbUQld1T50ascSTyKCNUIjhfs4CTO/IhSRDgaCHqWyC0zozg7Inmpp16cCuhLGJRi8obLqPt1GmR/DJ0J4AeJl2zui2xcAkf1OFdu2u2wZ6pZI2IC/O3yyuAW1LVm91LSn8KQCsSDzVgpdREu/uWXQJ2sbuqMWEBttO/j3TWJXuCtQ4/Yl9Gnqnl+WjQQC4duXcQpuQnftWPHqt7pZ1tfmrdAuRtrBG5r5Q+uQ6yNzfTYLF0xTemHHzf2XvcwyOzi/UvOGKEUyu+WfyVCx5iV+Hbpl/B5zUaYGDz8sqQgN+25UB3krLmimbG1R8vvDskhXJfNBjx3epTwmG8DpayqXuGccKl0eJDDYAvFxL7YPnD3d5v2+qr+6XL01qmAAqiofjIuByusr/h0fvTIOdhZj9EkdYEVEF95WlgeVsmruzVR05ZYmpRY+ryuAqaSzWGCCmnNe/ICdWHDK9vLUQXXV/Rn+MHYGtpzWgLgp95OPAiVeS7cQ59UOHNzQ9m3URx+7psav6nX9bBm4k0WIxNVfTXKtl1tadZpvMRkvS9+P778cE4NF4yzuQKdH4MScvoH+zHwlJ7tgA1az2Jl1InxY6VnXjkITcGlcRpxSEC1L6ZtpX+4Gp5e0of2ipbDh6RWwTQyebuSz6wYGPlM4NnhsFaffVjUEDbFYie95EVhCtKmjfpO4U0r8qXWsiMEViJAbZEqbhzJCG1kDYfgUKguGmoa7RR/2DKZEydZb 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)(376014)(7416014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2024 16:58:39.8660 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f9f75e68-0ee6-488e-5b0f-08dcd670d051 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: SN1PEPF000252A1.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5796 X-Rspamd-Queue-Id: ED86620009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: snydgt5kuboonns1q8mwe16k8ip6ceoi X-HE-Tag: 1726505926-566734 X-HE-Meta: U2FsdGVkX1/+hUWVQmWifU7giQU9J1m/OtYxze1JSnMYtEVMYHs0SEkBAqVN6UcLDoToYVqKWqrHovCEAR00IwcUI49fMbhP/yYgor7oQyAHXH1Bq+gveWpFPSBXTrUiKk7bSsy0mBIvUBnk4Mv26/gUIffoTuqETxDzm7Vc7yxbfspo9zXE7UvMGXydS+HoimDmTLHKENdhqwgJyOyiseUMJRVqmJJQjeaV5xsRhZ7b1JDoWNaqSqhNZV1qWUHRUMnfZkA8qXhqoKq/FnywIwTBym4LikQAJCGRBB1b+q14nFFbe0Sf8/24k+ylj8Dui/6g9s+X7L/0Y47ExeSppsw+MUUb5lGbiWlxYKi/iJEq/kksiO4sf4wTPESR3QeMXp4bllwZrayMVkXobeUA1fJSt/UlmvtWgJCTVPD0rlGtyyQOFJgw/LmWUA+gBK3QlG9ExELjdVqxsm8NiB65J4RcEmDT8/+oBCZMrNo0hvB+w6nHBAIB0kYo0tIoX//+KHANvQsw+U2/cPD+FovaNDHE881gQLmrZaM8CzJrKKOUqk7D83wJ5rydtislosZIlcXZcd77H4azpHIBN12H73UBVsnAMOZi3/s2evrqWtfNMGJMN1ESBCz0wU1LfALQYvTzShXPhT44118cVNCawYrGj7vwIQhPvYrjUNzo7LsvIyoPANaIEB3DVmd14t2ta15O6HZ52DgTmzIqs23DZq2comlxDZ7h44qUpXicStyQlrAXbJZN1neefC11w2G97ds4Wizquff5tcyqsgS4TnIzNBFvUIgS3Hi1/Sq/55EV+awrresICWjuOIMk+Sc08c4iytN14CzCZoIsG2CFPG53GbsSDLu8ODquR5QZBuqNy+h2rM3hjqldho2aOvUotf9O3iwTBNkmKCcR0UtJN8/p1a64/Z7fM1NhLL6IAYyYMOukADZfOB4LvkBTWe+PzLxF9qT7pYabLfnI59x YWKZaWOg X/e4ubEKC0tEXko8FEBQ6VD7tEvIAJ7EFoxZ7BoLQfhHyJA6jCcePNAa2AtloozwPKOOfIUw4ObmCSNCw3U/QSpjSYXasLMRe+XoT2fPUma52BjW0ueroEskblhMuUEkQdgUO1esw9VR6Fs/fmDLDJv2el92NLlyE4uqgpRXiPl6cyCj5iXIC2SRyKFrX8DQ9LDBEzYfdYnyEXRpPmzIBpmcCam+gGuSYrf8nHmlVEOlGXM/k4+X8PXSe4fSAMK0KiATGvuNJQ+6v7aIX9xR6GGUg2bSEUpych3w6E2sxdgIA4X3Vv1F6K22t0KeygGsUG3uDSpysK9+LW7Ar6OxsSGcvsKM9HzFwkEOTiMKpQr8hGXwlia1pfiqidaOSYvjIwLCy 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));