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: 13807614 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2044.outbound.protection.outlook.com [40.107.223.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CEB81A08CC; Thu, 19 Sep 2024 09:45:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726739126; cv=fail; b=fbW0Gu49yStn46FKiT8sJJ/f6iHQtSLK+fDHOjhc1vOUZ4V05YfXsXGSDRbh3+X1FAJfJBvAXJV5wI/lm/RXDoufZtFaTlHn82WRpFquf+eQG+IRo4RrGdIFIs6uaa+Ql/dVK3nVV0KwgfvHX4dTDrxc935Mzf64/9yipSN7K7s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726739126; c=relaxed/simple; bh=Ch/3BXRIDwXuwvGggJHTLNf/PCWdMgQZ54sRU6QlWZk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RSRBiaVIlht5Yrtmhb3T/ubz+nI0Ke+rB/OE74m4fbJUjzb19YP6aZFLzeKlB3mVzWmyUiwAhi6uXM76dt620DsKmiX/4vhT9paIZc+iqgdAj/WQ6qbSRzGSJ1XsYP1Ro0NkaL3NNSW3cZW8GXLT3ikjjxhTqq9GpwKT1rlOTE0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=AhlQYqts; arc=fail smtp.client-ip=40.107.223.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="AhlQYqts" 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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/VDU0xHwL4O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3iT86uXdlFL4//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 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));