diff mbox series

[v2,1/5] lib/test_cpumask: drop cpu_possible_mask full test

Message ID 6dfd4d3a4d77f97f13ab3f22bc53c96c38ba908e.1661007339.git.sander@svanheule.net (mailing list archive)
State Superseded
Headers show
Series cpumask: KUnit test suite fixes and improvements | expand

Commit Message

Sander Vanheule Aug. 20, 2022, 3:03 p.m. UTC
When the number of CPUs that can possibly be brought online is known at
boot time, e.g. when HOTPLUG is disabled, nr_cpu_ids may be smaller than
NR_CPUS. In that case, cpu_possible_mask would not be completely filled,
and cpumask_full(cpu_possible_mask) can return false for valid system
configurations.

Fixes: c41e8866c28c ("lib/test: introduce cpumask KUnit test suite")
Link: https://lore.kernel.org/lkml/346cb279-8e75-24b0-7d12-9803f2b41c73@riseup.net/
Reported-by: Maíra Canal <mairacanal@riseup.net>
Signed-off-by: Sander Vanheule <sander@svanheule.net>
Tested-by: Maíra Canal <mairacanal@riseup.net>
Reviewed-by: David Gow <davidgow@google.com>
---
Changes in v2:
Rewrite commit message to explain why this test is wrong

 lib/test_cpumask.c | 1 -
 1 file changed, 1 deletion(-)

Comments

Yury Norov Aug. 20, 2022, 9:35 p.m. UTC | #1
On Sat, Aug 20, 2022 at 05:03:09PM +0200, Sander Vanheule wrote:
> When the number of CPUs that can possibly be brought online is known at
> boot time, e.g. when HOTPLUG is disabled, nr_cpu_ids may be smaller than
> NR_CPUS. In that case, cpu_possible_mask would not be completely filled,
> and cpumask_full(cpu_possible_mask) can return false for valid system
> configurations.

It doesn't mean we can just give up. You can check validity of possible
cpumask like this: 
        KUNIT_EXPECT_EQ(test, nr_cpu_ids, cpumask_first_zero(&mask_all))
        KUNIT_EXPECT_EQ(test, NR_CPUS, cpumask_first(&mask_all))
 
> Fixes: c41e8866c28c ("lib/test: introduce cpumask KUnit test suite")
> Link: https://lore.kernel.org/lkml/346cb279-8e75-24b0-7d12-9803f2b41c73@riseup.net/
> Reported-by: Maíra Canal <mairacanal@riseup.net>
> Signed-off-by: Sander Vanheule <sander@svanheule.net>
> Tested-by: Maíra Canal <mairacanal@riseup.net>
> Reviewed-by: David Gow <davidgow@google.com>
> ---
> Changes in v2:
> Rewrite commit message to explain why this test is wrong
> 
>  lib/test_cpumask.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/lib/test_cpumask.c b/lib/test_cpumask.c
> index a31a1622f1f6..4ebf9f5805f3 100644
> --- a/lib/test_cpumask.c
> +++ b/lib/test_cpumask.c
> @@ -54,7 +54,6 @@ static cpumask_t mask_all;
>  static void test_cpumask_weight(struct kunit *test)
>  {
>  	KUNIT_EXPECT_TRUE(test, cpumask_empty(&mask_empty));
> -	KUNIT_EXPECT_TRUE(test, cpumask_full(cpu_possible_mask));
>  	KUNIT_EXPECT_TRUE(test, cpumask_full(&mask_all));
>  
>  	KUNIT_EXPECT_EQ(test, 0, cpumask_weight(&mask_empty));
> -- 
> 2.37.2
Sander Vanheule Aug. 21, 2022, 1:08 p.m. UTC | #2
Hi Yury,

On Sat, 2022-08-20 at 14:35 -0700, Yury Norov wrote:
> On Sat, Aug 20, 2022 at 05:03:09PM +0200, Sander Vanheule wrote:
> > When the number of CPUs that can possibly be brought online is known at
> > boot time, e.g. when HOTPLUG is disabled, nr_cpu_ids may be smaller than
> > NR_CPUS. In that case, cpu_possible_mask would not be completely filled,
> > and cpumask_full(cpu_possible_mask) can return false for valid system
> > configurations.
> 
> It doesn't mean we can just give up. You can check validity of possible
> cpumask like this: 
>         KUNIT_EXPECT_EQ(test, nr_cpu_ids, cpumask_first_zero(&mask_all))
>         KUNIT_EXPECT_EQ(test, NR_CPUS, cpumask_first(&mask_all))

Did you mean cpu_possible_mask, or mask_all?

For cpu_possible_mask, these tests are in test_cpumask_first(), albeit under a
slightly different form. Together with the tests in test_cpumask_weight() and
test_cpumask_last(), cpu_possible_mask is already one of the more constrained
masks.

For mask_all, the mask is filled up with nr_cpumask_bits <= NR_CPUS. I could add
cpumask_first(), cpumask_first_zero(), and cpumask_last() tests though.

More tests could be also added for cpu_all_mask, since this does have all
NR_CPUS bits set, but I think that belongs in a separate patch.

I think the extra mask_all and cpu_all_mask test are out of scope for this
patch, but they could be added in another patch (for 6.1).

Best,
Sander

>  
> > Fixes: c41e8866c28c ("lib/test: introduce cpumask KUnit test suite")
> > Link:
> > https://lore.kernel.org/lkml/346cb279-8e75-24b0-7d12-9803f2b41c73@riseup.net/
> > Reported-by: Maíra Canal <mairacanal@riseup.net>
> > Signed-off-by: Sander Vanheule <sander@svanheule.net>
> > Tested-by: Maíra Canal <mairacanal@riseup.net>
> > Reviewed-by: David Gow <davidgow@google.com>
> > ---
> > Changes in v2:
> > Rewrite commit message to explain why this test is wrong
> > 
> >  lib/test_cpumask.c | 1 -
> >  1 file changed, 1 deletion(-)
> > 
> > diff --git a/lib/test_cpumask.c b/lib/test_cpumask.c
> > index a31a1622f1f6..4ebf9f5805f3 100644
> > --- a/lib/test_cpumask.c
> > +++ b/lib/test_cpumask.c
> > @@ -54,7 +54,6 @@ static cpumask_t mask_all;
> >  static void test_cpumask_weight(struct kunit *test)
> >  {
> >         KUNIT_EXPECT_TRUE(test, cpumask_empty(&mask_empty));
> > -       KUNIT_EXPECT_TRUE(test, cpumask_full(cpu_possible_mask));
> >         KUNIT_EXPECT_TRUE(test, cpumask_full(&mask_all));
> >  
> >         KUNIT_EXPECT_EQ(test, 0, cpumask_weight(&mask_empty));
> > -- 
> > 2.37.2
Sander Vanheule Aug. 21, 2022, 1:27 p.m. UTC | #3
Hi Yury,

Replying back in plaintext, as you sent an HTML message.

On Sun, 2022-08-21 at 09:18 -0400, Yury Norov wrote:
> 
> 
> On Sun, Aug 21, 2022, 09:08 Sander Vanheule <sander@svanheule.net> wrote:
> > Hi Yury,
> > 
> > On Sat, 2022-08-20 at 14:35 -0700, Yury Norov wrote:
> > > On Sat, Aug 20, 2022 at 05:03:09PM +0200, Sander Vanheule wrote:
> > > > When the number of CPUs that can possibly be brought online is known at
> > > > boot time, e.g. when HOTPLUG is disabled, nr_cpu_ids may be smaller than
> > > > NR_CPUS. In that case, cpu_possible_mask would not be completely filled,
> > > > and cpumask_full(cpu_possible_mask) can return false for valid system
> > > > configurations.
> > > 
> > > It doesn't mean we can just give up. You can check validity of possible
> > > cpumask like this: 
> > >         KUNIT_EXPECT_EQ(test, nr_cpu_ids, cpumask_first_zero(&mask_all))
> > >         KUNIT_EXPECT_EQ(test, NR_CPUS, cpumask_first(&mask_all))
> > 
> > Did you mean cpu_possible_mask, or mask_all?
> 
> cpu_possble_as of curse.
> 
> > For cpu_possible_mask, these tests are in test_cpumask_first(), albeit under
> > a
> > slightly different form. Together with the tests in test_cpumask_weight()
> > and
> > test_cpumask_last(), cpu_possible_mask is already one of the more
> > constrained
> > masks.
> > 
> > 
> > For mask_all, the mask is filled up with nr_cpumask_bits <= NR_CPUS. I could
> > add
> > cpumask_first(), cpumask_first_zero(), and cpumask_last() tests though.
> > 
> > More tests could be also added for cpu_all_mask, since this does have all
> > NR_CPUS bits set, but I think that belongs in a separate patch.
> > 
> > I think the extra mask_all and cpu_all_mask test are out of scope for this
> > patch, but they could be added in another patch (for 6.1).
> 
> If you think that possible mask is tested by other parts, then can you notice
> that in comments?

Sure, I'll update the commit message to note the other constraints on
cpu_possible_mask.

Best,
Sander
diff mbox series

Patch

diff --git a/lib/test_cpumask.c b/lib/test_cpumask.c
index a31a1622f1f6..4ebf9f5805f3 100644
--- a/lib/test_cpumask.c
+++ b/lib/test_cpumask.c
@@ -54,7 +54,6 @@  static cpumask_t mask_all;
 static void test_cpumask_weight(struct kunit *test)
 {
 	KUNIT_EXPECT_TRUE(test, cpumask_empty(&mask_empty));
-	KUNIT_EXPECT_TRUE(test, cpumask_full(cpu_possible_mask));
 	KUNIT_EXPECT_TRUE(test, cpumask_full(&mask_all));
 
 	KUNIT_EXPECT_EQ(test, 0, cpumask_weight(&mask_empty));