linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rt-tests: cyclictest: Fix -a option fail when max_cpus is more
@ 2020-04-22  2:19 Yunfeng Ye
  2020-04-24 20:59 ` John Kacur
  0 siblings, 1 reply; 2+ messages in thread
From: Yunfeng Ye @ 2020-04-22  2:19 UTC (permalink / raw)
  To: linux-rt-users, williams, jkacur; +Cc: hushiyuan, hewenliang4

An Error occurs when run: ./cyclictest -v -t 5 -p 80 -i 1000 -a 3

  parse_cpumask: Using 0 cpus.
  Max CPUs = 96
  WARN: Couldn't setaffinity in main thread: Invalid argument
  # /dev/cpu_dma_latency set to 0us
  FATAL: No allowable cpus to run on

We find that numa_bitmask_alloc() is used incorrectly in
use_current_cpuset(), it should pass the number of cpus as parameters,
not the sizeof(struct bitmask), which is only 8 bytes.

The syscall sched_getaffinity will check the parameters, if using
sizeof(struct bitmask), it will fail when cpus is more:

  SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len,
                unsigned long __user *, user_mask_ptr)
  {
        int ret;
        cpumask_var_t mask;

        if ((len * BITS_PER_BYTE) < nr_cpu_ids)
                return -EINVAL;

Fix it by passing max_cpus as parameters to numa_bitmask_alloc().

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
---
 src/cyclictest/cyclictest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index c5f1fd46567a..989113fb3483 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -1135,7 +1135,7 @@ static void use_current_cpuset(const int max_cpus)

 	pid = getpid();

-	curmask = numa_bitmask_alloc(sizeof(struct bitmask));
+	curmask = numa_bitmask_alloc(max_cpus);
 	numa_sched_getaffinity(pid, curmask);

 	/* Clear bits that are not set in both the cpuset from the environment,
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rt-tests: cyclictest: Fix -a option fail when max_cpus is more
  2020-04-22  2:19 [PATCH] rt-tests: cyclictest: Fix -a option fail when max_cpus is more Yunfeng Ye
@ 2020-04-24 20:59 ` John Kacur
  0 siblings, 0 replies; 2+ messages in thread
From: John Kacur @ 2020-04-24 20:59 UTC (permalink / raw)
  To: Yunfeng Ye; +Cc: linux-rt-users, williams, hushiyuan, hewenliang4



On Wed, 22 Apr 2020, Yunfeng Ye wrote:

> An Error occurs when run: ./cyclictest -v -t 5 -p 80 -i 1000 -a 3
> 
>   parse_cpumask: Using 0 cpus.
>   Max CPUs = 96
>   WARN: Couldn't setaffinity in main thread: Invalid argument
>   # /dev/cpu_dma_latency set to 0us
>   FATAL: No allowable cpus to run on
> 
> We find that numa_bitmask_alloc() is used incorrectly in
> use_current_cpuset(), it should pass the number of cpus as parameters,
> not the sizeof(struct bitmask), which is only 8 bytes.
> 
> The syscall sched_getaffinity will check the parameters, if using
> sizeof(struct bitmask), it will fail when cpus is more:
> 
>   SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len,
>                 unsigned long __user *, user_mask_ptr)
>   {
>         int ret;
>         cpumask_var_t mask;
> 
>         if ((len * BITS_PER_BYTE) < nr_cpu_ids)
>                 return -EINVAL;
> 
> Fix it by passing max_cpus as parameters to numa_bitmask_alloc().
> 
> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
> ---
>  src/cyclictest/cyclictest.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
> index c5f1fd46567a..989113fb3483 100644
> --- a/src/cyclictest/cyclictest.c
> +++ b/src/cyclictest/cyclictest.c
> @@ -1135,7 +1135,7 @@ static void use_current_cpuset(const int max_cpus)
> 
>  	pid = getpid();
> 
> -	curmask = numa_bitmask_alloc(sizeof(struct bitmask));
> +	curmask = numa_bitmask_alloc(max_cpus);
>  	numa_sched_getaffinity(pid, curmask);
> 
>  	/* Clear bits that are not set in both the cpuset from the environment,
> -- 
> 1.8.3.1
> 
> 
> 
Signed-off-by: John Kacur <jkacur@redhat.com>

Thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-24 21:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-22  2:19 [PATCH] rt-tests: cyclictest: Fix -a option fail when max_cpus is more Yunfeng Ye
2020-04-24 20:59 ` John Kacur

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).