lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240919094438.10987-4-shivankg@amd.com>
Date: Thu, 19 Sep 2024 09:44:38 +0000
From: Shivank Garg <shivankg@....com>
To: <pbonzini@...hat.com>, <corbet@....net>, <akpm@...ux-foundation.org>,
	<willy@...radead.org>
CC: <acme@...hat.com>, <namhyung@...nel.org>, <mpe@...erman.id.au>,
	<isaku.yamahata@...el.com>, <joel@....id.au>, <kvm@...r.kernel.org>,
	<linux-doc@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
	<linux-mm@...ck.org>, <linux-fsdevel@...r.kernel.org>, <shivankg@....com>,
	<bharata@....com>, <nikunj@....com>, Shivansh Dhiman
	<shivansh.dhiman@....com>
Subject: [RFC PATCH V2 3/3] KVM: guest_memfd: Enforce NUMA mempolicy if available

From: Shivansh Dhiman <shivansh.dhiman@....com>

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 <shivansh.dhiman@....com>
Signed-off-by: Shivank Garg <shivankg@....com>
---
 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));
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ