From patchwork Thu Sep 19 09:44:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shivank Garg X-Patchwork-Id: 13807606 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 769F9CE8D66 for ; Thu, 19 Sep 2024 09:45:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BADD86B0089; Thu, 19 Sep 2024 05:45:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5DC56B008A; Thu, 19 Sep 2024 05:45:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FE386B008C; Thu, 19 Sep 2024 05:45:07 -0400 (EDT) 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 7E7526B0089 for ; Thu, 19 Sep 2024 05:45:07 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1FF8E1C5311 for ; Thu, 19 Sep 2024 09:45:07 +0000 (UTC) X-FDA: 82581004254.18.318DB17 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2071.outbound.protection.outlook.com [40.107.237.71]) by imf04.hostedemail.com (Postfix) with ESMTP id 37F854000C for ; Thu, 19 Sep 2024 09:45:04 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=w5PJOmyn; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf04.hostedemail.com: domain of shivankg@amd.com designates 40.107.237.71 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=1726738979; 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: references:dkim-signature; bh=RX70B6oiVsdzGQ5F/xs6/PIPqNSP+XkdXHUH5Mi+Lic=; b=7patccMNp1SRmNByHhkpdgfUF0XmWGv8o+hdGK/SLJ3DMGH8X0NPiuZkWrrUVZRSAjfGm1 jPC6xaPwGafu+eMxAaeCc3HMw7nf6Y9IpmK6bbz/NwzryUfl065MwNWqNSWe8niIwTTCyN LJndmpTdJee5/ic/ARnrYNfeYT3WQPo= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1726738979; a=rsa-sha256; cv=pass; b=wdTqw+Ac+fs3gA85J5nP3ZHY4O2aMGSU5D4fWsxmrWvJq8vkYl+TsaRNziv1ZD8re5evMi ioZi3RXNVKfkbbTbeAbcvPvMpLHk1ck6qrwYznNq7uL8lfflUwfXB6sKREC3UqTSkWwasL XgTBuO5nG10M8Alec+nQefiU2Dg/x5Y= ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=w5PJOmyn; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf04.hostedemail.com: domain of shivankg@amd.com designates 40.107.237.71 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=YdAD7ZMqPMRfMymCYhosJN3gcVuaXbpoLwroZWun+15h2veJkyS945KYF3uiXhZWEJrWRHRER9tUc4JgC8qjPjMd6NNWEioh4mTEDrVEYoLaw3MzWkm2+WZAQxYk1cuYV86kIjtmqzihADT4nLS6S2POwZcVLTQ/VoUO8pdVdtGvPEzkhCxhhHljQGcdkdFhvNiAhSYBYHBkIsCkZEovWh7x7xOxP7VBrLD82fU//1cmaaGzGSPBMfupX/T0bFtbHYFk2gc4mCM74HvX4lug/T5p3BJq1VI1I2GR5Xj5G9scTmU+ey/bRfXGCl2JPNoIiv3sY3tWTYLPoOuodJ/9Yg== 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=RX70B6oiVsdzGQ5F/xs6/PIPqNSP+XkdXHUH5Mi+Lic=; b=lPIGTr2Pe/XXFoQYZAvqKxLmRd5gvY72ZEAltmSudVftrg/wEZG+0IEhb4ISAZDSUjFzzO1yvieslIxBvQb5j9137ApLcILGTgcsojeCEuERY5/DSpxVRnuog1mAZS0a6RBmv9Gga8L176v9CbGUMwOAP6tIJtYWqtWjSaZVXUfsUtnOlaAzQQ9qnKvTb3ICcaxsbUVovBFNy0sXc7uBpOexNVoefu0jNsZ1WWnvR2EmcFyJE6UhxY73LhE+S2hyLHPmMnBTdwN+eUZGt5Gl3uPLpshEmymFrvMhjsKNlXOTJSz5gWDbWWJB92QrIsdGXKN2YTq+yupNQ87cvr2hUw== 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=RX70B6oiVsdzGQ5F/xs6/PIPqNSP+XkdXHUH5Mi+Lic=; b=w5PJOmynk241d1sRaT0dp2cWcFUoc5vjxmTM09WJeJOUqwfHWIpdCoa9qlPhRHw+qGBDa8CdCm6APNg6v8+ub3vd0TX+vQHIjcEItklUgkMizQeCjhtlaudVLBaroDfDtJLT4xc4+tPUpxqjg8OaLa7eWGiahul7ARGhioYHgak= Received: from DS7PR05CA0044.namprd05.prod.outlook.com (2603:10b6:8:2f::10) by LV3PR12MB9167.namprd12.prod.outlook.com (2603:10b6:408:196::19) 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:00 +0000 Received: from DS1PEPF00017090.namprd03.prod.outlook.com (2603:10b6:8:2f:cafe::29) by DS7PR05CA0044.outlook.office365.com (2603:10b6:8:2f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.14 via Frontend Transport; Thu, 19 Sep 2024 09:44:59 +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 DS1PEPF00017090.mail.protection.outlook.com (10.167.17.132) 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:44:59 +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:44:54 -0500 From: Shivank Garg To: , , , CC: , , , , , , , , , , , , Subject: [RFC PATCH V2 0/3] Add NUMA mempolicy support for KVM guest_memfd Date: Thu, 19 Sep 2024 09:44:35 +0000 Message-ID: <20240919094438.10987-1-shivankg@amd.com> X-Mailer: git-send-email 2.34.1 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: DS1PEPF00017090:EE_|LV3PR12MB9167:EE_ X-MS-Office365-Filtering-Correlation-Id: c8321190-3553-4775-2a41-08dcd88fba45 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014|7416014; X-Microsoft-Antispam-Message-Info: ZIXI3q1MW5JVr7P99zA2ej//YmX42SKQAurzNt1xej8w48NX3UfaJeLb66wn+xahlKAkot7PEukmTGpMvHKF1dFsvFXqb7xDYbS+d0hh81LBf3uX1YApz3xl4+MBV9I95RI+M3u/QoEWAGA3sQRWJYJ6FczVHw2Xb9/SRbOYib/qLY79640ddHiPlLTq8IHRE5ATrYKS3yOAB/T2CN46Du4oG/sA42XjL0kIfS1tQwyEgqMRKh8coYVyLj/TFewPXbaK/8POBCB8ZclbHNmlXBttQVCle2+LE+zSnr8HmeCQmdHaphUN6ny6O+nXiSyvLYh/KBL39+rlnRKUVKnvYBFcEupmdfU+z7hrqrjL5sklSSw1wHXkrC555Ddv+DENE6L3nOFbVh9/X3UAeN3+0Wgxvp0uYlAOZs8183vMy76TQ+UZ7uSSUJu2aoqDpF3/LZtzHgnpDBpPVSzE6wIhOFvcy0MFWVGdasOhBx2ljFEt/ThlNwm8xxzqRE23FBQkCTJbVgs1Qn/vgcp9dGhIityE4zh4BiUmDJ53+4N9Qsk3jXrmhB2VeXQ6Fpxrwnt5h6xtEUjDy/oaLtyxPxCACsZl/3Fg+ABVWKnOadQWfk6EXzEiz0n4XE1PMjmz4wUta+vhWnDTVSAwBEcqcRnBxFeQ2Lp7Nm3JEw9q1qzISMmMUs+zp38xA6pD3CZ6JiFUrIc6jUccYyzNhibpFcrYcVa17y4hIZN8z7dZ+nHLHPm7dkLZS3YV8jS7ENUN9f7J4r/bNxy0Cp+ALNYahzJIQdajncD1nPYu7AwnLiO47qyqVo2l2kffGvBubyTAiIAiRVjTf59XQl4kzTJryBptwy9siNCfMINP5T0ZJgVtJHYyb1gZpLs8FxG1B2F2pJwEBobPQIHyf7qEGImG1X+wFZAY7XW71tluTf8evD/7IXIV6lASAcK2L2QQ9ycjLZO1JWR0rOdJ4+CTz1xrj7g8Pmzzz4nIXhwZiq8jsbipZmE6XrqBFFQ20S4tEIbvvMegB8Vl0ySvWlDGoMvuZYaCzmsb63LiEtd0sJMv0qxMJ/roPD32p9jjHcYvovauxDV1ES5Kptot1me+v7E2fGBol17msID2/Br0lKyMpZR6SYRAJLhu2JWQDafM6VKao029bkCwMEgVG1GKNEATmyav9w7q3CG8KG0++j9bxtDEv98ig+oS/9OvieCxkAHZKncs02J2euJtDFqyITgfX8V5hsCcBW9aAzN5kFcXFQUuwkZv/Vo+4n1phwVO1AtVofhhvjelt2uweYroMB2cWd5h+je8ZeDkfUGznSxD2XjFMtcHOjkQNxWBs8WeiXGi7J1r4O721niweXJZADmAe1WNsJTRwOPDGDlrK/K1IkdW5RcTIDGi/FJIS6/eJoMz5ANisc/83nRb3eWDuvw1D1maenbXyfTJnRisR2Q0DBjmOPMGtUOnxIXxF/hM4w4mRw3fXkcJUSunquiw3o45QFTOxg== 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)(36860700013)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2024 09:44:59.5690 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8321190-3553-4775-2a41-08dcd88fba45 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: DS1PEPF00017090.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9167 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 37F854000C X-Stat-Signature: 7zpcjnoisjomw8gkgp7anfu8hbe894wz X-Rspam-User: X-HE-Tag: 1726739104-232901 X-HE-Meta: U2FsdGVkX1/YMY7OKydHdUIrVcZ31AkpCTywqZWLYjtd9NoQ/PbI9j0XYGaMpmD0DHKfQ8NPmoONPwp0IFzEfxM2/16H5qRIKjvkA1/WtmUXZwa4DXSY3WbBYMqmh83K61CXjwBB8E09PS9Usne8udJ3NlFqf0dmRITuuC6P9+THd3pt/QBaca+S6Qk9reu7WfZ2DegqEfNyQ8zaVVyaE3iuN7y6zAfrUDXBCmEOjzcxZ+l6MZxB8Bm9iwq8c/wDHOOLnF1WOqEZ+c9jGhKfPmxjBHb08kOaBcpvZmX8sRX2X522AIG4DDfBLMr1ZZf16UI24yKOeWYNaHUS12m4Imhxkv7Q6XI55TKcREt/rBsKwIjZm9Sd6Pr0ieS/oHeG4BH6SR/dcntpsetCvXwsKS+Jc+BchDXUkmv1cfRbPqsw8JGpcz2HdAD70kSa5rUjpv4Wy/kdb3sFH2Q6VSK7Un7lS1c3zTPpq3hx50FSK6ueGwNE/+HLduac14J24QHoJnbJCBtlxnx5iBq7UkxQ9t+R7Z7PcqZtjxGt7hrAQYJNYFQLR3c3egT68Gipy/UY8puYHzOCEqRFVLg2/ahroKZxeu1JrVjhOD1p+R7bdbf1p18awvJB1tFwiWRpJfsZJn9rWR++gCADGBsKm+c8CBoCHFt54IJkzb12DiLd2sBmgYepHtKj6vDbrNEPMd+gC44Y9i3Es2boTE1xyLFl0i7aGk9jrkLFhhYLhmIwjNdIZSdEOGeASawVGfkDUOYdJ9dtMkWEcH1fp87LGY8Ybx/qzHXNnJfe6re5TikdDmAUAe33CA1Nf7y+jKwyqY0nhA1teoTdEDrfzo+YHTs7IH1qRsSWV/Luj6Eliwp8QZCX0Z+JVZhvrscqytyDUAcsasAxrlJTth0fD/JWKoo8586oAIF+/G+bbcCC+FoOggZbfEGS4m5hYrf/mVlXOAAQYZsXP3AF0tz7dSg457x DnoIbzo2 KEskfSs6Hd+tZ/N8OvEBdN8yCfPlJfQhkJ7+jaSo9ONq99a7IeRf99GKU5g+z8x0VvJLG86NWfQ1DrUriJ13eRy5wAKJ1I1RfDkFK6v0MV3hbVRi4DQCAoaLPDU6/Yy6fvtzqg/7+FSMdv6EEF/hQioMCZ1qK94g+G07udDxYbNjvFLEMIX1QIT1uh/OK2F+ePIMuB/lBLHyhi9k/DVSuzbYFFPg2MQ14chkwABg2YI+1b8ZmOpIvM2njyKct5th/mtn5QNYk9aBShhcj3/e8QpaQwS6Y3hV1Sfeqi0DGQ4Pwelwik1CVH5xTefLadSYVgx0Ap1tey/uGaV6PVDOnzmBfkdwBXSBK2oVe28NFhv78Y9gkfbwh75hBA3BHFRJE1GHOaI/+xWwFCe9kYC9A9qmXFRktWgt8um/VLGxOYc3Z+/SEUWH6Iupn8NrJqxjuxCPzmSFhG6RiMSiYdKS38cFwPRI3OEU/fWpVhXHdRcjK53dPdGPkBQrkwg== 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: 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. This patch-series adds support to specify NUMA memory policy for guests with private guest-memfd memory backend. KVM guest-memfd support for memory backend is already available in QEMU RAMBlock. However, the NUMA support was missing. This cause memory allocation from guest to randomly allocate on host NUMA nodes even when passing policy and host-nodes in the QEMU command. It ensures that VMM provided NUMA policy is adhered. This feature is particularly useful for SEV-SNP guests as they require guest_memfd memory backend for allocations. Workloads with high memory- locality are likely to benefit with this change. Users can provide a policy mode such as default, bind, interleave, or preferred along with a list of node IDs from the host machine. To try this patch-series, build the custom QEMU with NUMA supported KVM guest-memfd: QEMU tree- https://github.com/AMDESE/qemu/tree/NUMA_guest_memfd For instance, to run a SEV-SNP guest bound to NUMA Node 0 of the host, the corresponding QEMU command would be: $ qemu-system-x86_64 \ -enable-kvm \ ... -machine memory-encryption=sev0,vmport=off \ -object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1 \ -numa node,nodeid=0,memdev=ram0,cpus=0-15 \ -object memory-backend-memfd,id=ram0,policy=bind,host-nodes=0,size=1024M,share=true,prealloc=false v2: - Add fixes suggested by Matthew Wilcox v1: https://lore.kernel.org/linux-mm/20240916165743.201087-1-shivankg@amd.com Shivansh Dhiman (3): KVM: guest_memfd: Extend creation API to support NUMA mempolicy mm: Add mempolicy support to the filemap layer KVM: guest_memfd: Enforce NUMA mempolicy if available Documentation/virt/kvm/api.rst | 13 ++++++++- include/linux/mempolicy.h | 4 +++ include/linux/pagemap.h | 40 ++++++++++++++++++++++++++ include/uapi/linux/kvm.h | 5 +++- mm/filemap.c | 30 ++++++++++++++++---- mm/mempolicy.c | 52 ++++++++++++++++++++++++++++++++++ tools/include/uapi/linux/kvm.h | 5 +++- virt/kvm/guest_memfd.c | 28 ++++++++++++++---- virt/kvm/kvm_mm.h | 3 ++ 9 files changed, 167 insertions(+), 13 deletions(-)