* [PATCH] KVM: selftests: Increase 'maxnode' for guest_memfd tests
@ 2026-03-02 9:07 Kai Huang
2026-03-02 15:57 ` Sean Christopherson
0 siblings, 1 reply; 3+ messages in thread
From: Kai Huang @ 2026-03-02 9:07 UTC (permalink / raw)
To: seanjc, pbonzini
Cc: shuah, shivankg, kvm, linux-kselftest, linux-kernel, Kai Huang
Increase 'maxnode' when using 'get_mempolicy' syscall in guest_memfd
mmap and NUMA policy tests to fix a failure on one Intel GNR platform.
On a CXL-capable platform, the memory affinity of CXL memory regions may
not be covered by the SRAT. Since each CXL memory region is enumerated
via a CFMWS table, at early boot the kernel parses all CFMWS tables to
detect all CXL memory regions and assigns a 'faked' NUMA node for each
of them, starting from the highest NUMA node ID enumerated via the SRAT.
This increases the 'nr_node_ids'. E.g., on the aforementioned Intel GNR
platform which has 4 NUMA nodes and 18 CFMWS tables, it increases to 22.
This results in the 'get_mempolicy' syscall failure on that platform,
because currently 'maxnode' is hard-coded to 8 but the 'get_mempolicy'
syscall requires the 'maxnode' to be not smaller than the 'nr_node_ids'.
Increase the 'maxnode' to the number of bits of 'unsigned long' (i.e.,
64 on 64-bit systems) to fix this. Note the 'nodemask' is 'unsigned
long', so it makes sense to set 'maxnode' to bits of 'unsigned long'
anyway.
This may not cover all systems. Perhaps a better way is to always set
the 'nodemask' and 'maxnode' based on the actual maximum NUMA node ID on
the system, but for now just do the simple way.
Signed-off-by: Kai Huang <kai.huang@intel.com>
---
tools/testing/selftests/kvm/guest_memfd_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c
index 618c937f3c90..b434612bc3ec 100644
--- a/tools/testing/selftests/kvm/guest_memfd_test.c
+++ b/tools/testing/selftests/kvm/guest_memfd_test.c
@@ -80,7 +80,7 @@ static void test_mbind(int fd, size_t total_size)
{
const unsigned long nodemask_0 = 1; /* nid: 0 */
unsigned long nodemask = 0;
- unsigned long maxnode = 8;
+ unsigned long maxnode = sizeof(nodemask) * 8;
int policy;
char *mem;
int ret;
base-commit: a91cc48246605af9aeef1edd32232976d74d9502
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: selftests: Increase 'maxnode' for guest_memfd tests
2026-03-02 9:07 [PATCH] KVM: selftests: Increase 'maxnode' for guest_memfd tests Kai Huang
@ 2026-03-02 15:57 ` Sean Christopherson
2026-03-02 20:29 ` Huang, Kai
0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2026-03-02 15:57 UTC (permalink / raw)
To: Kai Huang; +Cc: pbonzini, shuah, shivankg, kvm, linux-kselftest, linux-kernel
On Mon, Mar 02, 2026, Kai Huang wrote:
> Increase 'maxnode' when using 'get_mempolicy' syscall in guest_memfd
> mmap and NUMA policy tests to fix a failure on one Intel GNR platform.
>
> On a CXL-capable platform, the memory affinity of CXL memory regions may
> not be covered by the SRAT. Since each CXL memory region is enumerated
> via a CFMWS table, at early boot the kernel parses all CFMWS tables to
> detect all CXL memory regions and assigns a 'faked' NUMA node for each
> of them, starting from the highest NUMA node ID enumerated via the SRAT.
>
> This increases the 'nr_node_ids'. E.g., on the aforementioned Intel GNR
> platform which has 4 NUMA nodes and 18 CFMWS tables, it increases to 22.
>
> This results in the 'get_mempolicy' syscall failure on that platform,
> because currently 'maxnode' is hard-coded to 8 but the 'get_mempolicy'
> syscall requires the 'maxnode' to be not smaller than the 'nr_node_ids'.
>
> Increase the 'maxnode' to the number of bits of 'unsigned long' (i.e.,
> 64 on 64-bit systems) to fix this. Note the 'nodemask' is 'unsigned
> long', so it makes sense to set 'maxnode' to bits of 'unsigned long'
> anyway.
>
> This may not cover all systems. Perhaps a better way is to always set
> the 'nodemask' and 'maxnode' based on the actual maximum NUMA node ID on
> the system, but for now just do the simple way.
>
Can you add:
Reported-by: Yi Lai <yi1.lai@intel.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221014
Closes: https://lore.kernel.org/all/bug-221014-28872@https.bugzilla.kernel.org%2F
> Signed-off-by: Kai Huang <kai.huang@intel.com>
> ---
> tools/testing/selftests/kvm/guest_memfd_test.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c
> index 618c937f3c90..b434612bc3ec 100644
> --- a/tools/testing/selftests/kvm/guest_memfd_test.c
> +++ b/tools/testing/selftests/kvm/guest_memfd_test.c
> @@ -80,7 +80,7 @@ static void test_mbind(int fd, size_t total_size)
> {
> const unsigned long nodemask_0 = 1; /* nid: 0 */
> unsigned long nodemask = 0;
> - unsigned long maxnode = 8;
> + unsigned long maxnode = sizeof(nodemask) * 8;
Pretty sure this can be:
unsigned long maxnode = BITS_PER_TYPE(nodemask)
> int policy;
> char *mem;
> int ret;
>
> base-commit: a91cc48246605af9aeef1edd32232976d74d9502
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: selftests: Increase 'maxnode' for guest_memfd tests
2026-03-02 15:57 ` Sean Christopherson
@ 2026-03-02 20:29 ` Huang, Kai
0 siblings, 0 replies; 3+ messages in thread
From: Huang, Kai @ 2026-03-02 20:29 UTC (permalink / raw)
To: seanjc@google.com
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, shuah@kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
shivankg@amd.com
On Mon, 2026-03-02 at 07:57 -0800, Sean Christopherson wrote:
> On Mon, Mar 02, 2026, Kai Huang wrote:
> > Increase 'maxnode' when using 'get_mempolicy' syscall in guest_memfd
> > mmap and NUMA policy tests to fix a failure on one Intel GNR platform.
> >
> > On a CXL-capable platform, the memory affinity of CXL memory regions may
> > not be covered by the SRAT. Since each CXL memory region is enumerated
> > via a CFMWS table, at early boot the kernel parses all CFMWS tables to
> > detect all CXL memory regions and assigns a 'faked' NUMA node for each
> > of them, starting from the highest NUMA node ID enumerated via the SRAT.
> >
> > This increases the 'nr_node_ids'. E.g., on the aforementioned Intel GNR
> > platform which has 4 NUMA nodes and 18 CFMWS tables, it increases to 22.
> >
> > This results in the 'get_mempolicy' syscall failure on that platform,
> > because currently 'maxnode' is hard-coded to 8 but the 'get_mempolicy'
> > syscall requires the 'maxnode' to be not smaller than the 'nr_node_ids'.
> >
> > Increase the 'maxnode' to the number of bits of 'unsigned long' (i.e.,
> > 64 on 64-bit systems) to fix this. Note the 'nodemask' is 'unsigned
> > long', so it makes sense to set 'maxnode' to bits of 'unsigned long'
> > anyway.
> >
> > This may not cover all systems. Perhaps a better way is to always set
> > the 'nodemask' and 'maxnode' based on the actual maximum NUMA node ID on
> > the system, but for now just do the simple way.
> >
>
> Can you add:
>
> Reported-by: Yi Lai <yi1.lai@intel.com>
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221014
> Closes: https://lore.kernel.org/all/bug-221014-28872@https.bugzilla.kernel.org%2F
Oh I didn't know this was already reported. Will do.
>
> > Signed-off-by: Kai Huang <kai.huang@intel.com>
> > ---
> > tools/testing/selftests/kvm/guest_memfd_test.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c
> > index 618c937f3c90..b434612bc3ec 100644
> > --- a/tools/testing/selftests/kvm/guest_memfd_test.c
> > +++ b/tools/testing/selftests/kvm/guest_memfd_test.c
> > @@ -80,7 +80,7 @@ static void test_mbind(int fd, size_t total_size)
> > {
> > const unsigned long nodemask_0 = 1; /* nid: 0 */
> > unsigned long nodemask = 0;
> > - unsigned long maxnode = 8;
> > + unsigned long maxnode = sizeof(nodemask) * 8;
>
> Pretty sure this can be:
>
> unsigned long maxnode = BITS_PER_TYPE(nodemask)
Yeah.
Will update and send out v2 soon since this is a simple patch.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-02 20:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-02 9:07 [PATCH] KVM: selftests: Increase 'maxnode' for guest_memfd tests Kai Huang
2026-03-02 15:57 ` Sean Christopherson
2026-03-02 20:29 ` Huang, Kai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox