RSEQ updates for 6.12
Mathieu Desnoyers
maintainercover RSEQ updates for 6.12
Hi Peter,
This series contains my rseq updates for 6.12.
It is based on tag v6.12-rc1.
Can you pick it up through the tip tree ?
Thanks,
Mathieu
Mathieu Desnoyers (2):
sched: Improve cache locality of RSEQ concurrency IDs for intermittent
workloads
selftests/rseq: Adapt to glibc __rseq_size feature detection
fs/exec.c | 2 +- include/linux/mm_types.h | 72 +++++++++++++++--- kernel/fork.c | 2 +- kernel/sched/core.c | 22 +++--- kernel/sched/sched.h | 47 ++++++++---- tools/testing/selftests/rseq/rseq.c | 109 +++++++++++++++++++--------- tools/testing/selftests/rseq/rseq.h | 10 +-- 7 files changed, 187 insertions(+), 77 deletions(-)
Signature · 1 line
2.39.2
Mathieu Desnoyers
maintainerPATCH 1/2 sched: Improve cache locality of RSEQ concurrency IDs for intermittent workloads
commit 223baf9d17f25 ("sched: Fix performance regression introduced by mm_cid") introduced a per-mm/cpu current concurrency id (mm_cid), which keeps a reference to the concurrency id allocated for each CPU. This reference expires shortly after a 100ms delay.
These per-CPU references keep the per-mm-cid data cache-local in situations where threads are running at least once on each CPU within each 100ms window, thus keeping the per-cpu reference alive.
However, intermittent workloads behaving in bursts spaced by more than 100ms on each CPU exhibit bad cache locality and degraded performance compared to purely per-cpu data indexing, because concurrency IDs are allocated over various CPUs and cores, therefore losing cache locality of the associated data.
Introduce the following changes to improve per-mm-cid cache locality:
- Add a "recent_cid" field to the per-mm/cpu mm_cid structure to keep track of which mm_cid value was last used, and use it as a hint to attempt re-allocating the same concurrency ID the next time this mm/cpu needs to allocate a concurrency ID,
- Add a per-mm CPUs allowed mask, which keeps track of the union of CPUs allowed for all threads belonging to this mm. This cpumask is only set during the lifetime of the mm, never cleared, so it represents the union of all the CPUs allowed since the beginning of the mm lifetime. (note that the mm_cpumask() is really arch-specific and tailored to the TLB flush needs, and is thus _not_ a viable approach for this)
- Add a per-mm nr_cpus_allowed to keep track of the weight of the per-mm CPUs allowed mask (for fast access),
- Add a per-mm nr_cids_used to keep track of the highest concurrency ID allocated for the mm. This is used for expanding the concurrency ID allocation within the upper bound defined by:
min(mm->nr_cpus_allowed, mm->mm_users)
When the next unused CID value reaches this threshold, stop trying to expand the cid allocation and use the first available cid value instead.
Spreading allocation to use all the cid values within the range
[ 0, min(mm->nr_cpus_allowed, mm->mm_users) - 1 ]
improves cache locality while preserving mm_cid compactness within the expected user limits.
- In __mm_cid_try_get, only return cid values within the range [ 0, mm->nr_cpus_allowed ] rather than [ 0, nr_cpu_ids ]. This prevents allocating cids above the number of allowed cpus in rare scenarios where cid allocation races with a concurrent remote-clear of the per-mm/cpu cid. This improvement is made possible by the addition of the per-mm CPUs allowed mask.
- In sched_mm_cid_migrate_to, use mm->nr_cpus_allowed rather than t->nr_cpus_allowed. This criterion was really meant to compare the number of mm->mm_users to the number of CPUs allowed for the entire mm. Therefore, the prior comparison worked fine when all threads shared the same CPUs allowed mask, but not so much in scenarios where those threads have different masks (e.g. each thread pinned to a single CPU). This improvement is made possible by the addition of the per-mm CPUs allowed mask.
* Benchmarks
Each thread increments 16kB worth of 8-bit integers in bursts, with a configurable delay between each thread's execution. Each thread run one after the other (no threads run concurrently). The order of thread execution in the sequence is random. The thread execution sequence begins again after all threads have executed. The 16kB areas are allocated with rseq_mempool and indexed by either cpu_id, mm_cid (not cache-local), or cache-local mm_cid. Each thread is pinned to its own core.
Testing configurations:
8-core/1-L3: Use 8 cores within a single L3 24-core/24-L3: Use 24 cores, 1 core per L3 192-core/24-L3: Use 192 cores (all cores in the system) 384-thread/24-L3: Use 384 HW threads (all HW threads in the system)
Intermittent workload delays between threads: 200ms, 10ms.
Hardware:
CPU(s): 384
On-line CPU(s) list: 0-383
Vendor ID: AuthenticAMD
Model name: AMD EPYC 9654 96-Core Processor
Thread(s) per core: 2
Core(s) per socket: 96
Socket(s): 2
Caches (sum of all):
L1d: 6 MiB (192 instances)
L1i: 6 MiB (192 instances)
L2: 192 MiB (192 instances)
L3: 768 MiB (24 instances)Each result is an average of 5 test runs. The cache-local speedup is calculated as: (cache-local mm_cid) / (mm_cid).
Intermittent workload delay: 200ms
per-cpu mm_cid cache-local mm_cid cache-local speedup
(ns) (ns) (ns)
8-core/1-L3 1374 19289 1336 14.4x 24-core/24-L3 2423 26721 1594 16.7x 192-core/24-L3 2291 15826 2153 7.3x 384-thread/24-L3 1874 13234 1907 6.9x
Intermittent workload delay: 10ms
per-cpu mm_cid cache-local mm_cid cache-local speedup
(ns) (ns) (ns)
8-core/1-L3 662 756 686 1.1x 24-core/24-L3 1378 3648 1035 3.5x 192-core/24-L3 1439 10833 1482 7.3x 384-thread/24-L3 1503 10570 1556 6.8x
[ This deprecates the prior "sched: NUMA-aware per-memory-map concurrency IDs"
patch series with a simpler and more general approach. ]
--- fs/exec.c | 2 +- include/linux/mm_types.h | 72 +++++++++++++++++++++++++++++++++++----- kernel/fork.c | 2 +- kernel/sched/core.c | 22 +++++++----- kernel/sched/sched.h | 47 ++++++++++++++++++-------- 5 files changed, 111 insertions(+), 34 deletions(-)
fs/exec.c +1 -1
@@ -990,7 +990,7 @@ static int exec_mmap(struct mm_struct *mm) active_mm = tsk->active_mm; tsk->active_mm = mm; tsk->mm = mm; -mm_init_cid (mm); +mm_init_cid (mm, tsk);/* * This prevents preemption while active_mm is being loaded and * it and mm are being updated, which could cause problems for
include/linux/mm_types.h +63 -9
126 lines not on this page · raw message
kernel/fork.c +1 -1
@@ -1298,7 +1298,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,if (init_new_context (p, mm)) goto fail_nocontext; -if (mm_alloc_cid (mm)) +if (mm_alloc_cid (mm, p)) goto fail_cid; if (percpu_counter_init_many(mm->rss_stat, 0, GFP_KERNEL_ACCOUNT,
kernel/sched/core.c +13 -9
@@ -2691,6 +2691,7 @@ __do_set_cpus_allowed(struct task_struct *p, struct affinity_context *ctx)put_prev_task (rq, p); p->sched_class->set_cpus_allowed (p, ctx); +mm_set_cpus_allowed (p->mm, ctx->new_mask);if (queued)enqueue_task (rq, p,ENQUEUE_RESTORE |ENQUEUE_NOCLOCK );
@@ -10228,6 +10229,7 @@ int __sched_mm_cid_migrate_from_try_steal_cid(struct rq *src_rq,*/ if (!try_cmpxchg (&src_pcpu_cid->cid, &lazy_cid,MM_CID_UNSET ))return -1 ; +WRITE_ONCE (src_pcpu_cid->recent_cid,MM_CID_UNSET );return src_cid; }
@@ -10240,7 +10242,8 @@ void sched_mm_cid_migrate_to(struct rq *dst_rq, struct task_struct *t) {struct mm_cid *src_pcpu_cid, *dst_pcpu_cid;struct mm_struct *mm = t->mm; -int src_cid, dst_cid, src_cpu; +int src_cid, src_cpu; +bool dst_cid_is_set;struct rq *src_rq;lockdep_assert_rq_held (dst_rq);
@@ -10257,9 +10260,9 @@ void sched_mm_cid_migrate_to(struct rq *dst_rq, struct task_struct *t)* allocation closest to 0 in cases where few threads migrate around * many CPUs. * -* If destination cid is already set, we may have to just clear -* the src cid to ensure compactness in frequent migrations -* scenarios. +* If destination cid or recent cid is already set, we may have +* to just clear the src cid to ensure compactness in frequent +* migrations scenarios. * * It is not useful to clear the src cid when the number of threads is * greater or equal to the number of allowed CPUs, because user-space
@@ -10267,9 +10270,9 @@ void sched_mm_cid_migrate_to(struct rq *dst_rq, struct task_struct *t)* allowed CPUs. */ dst_pcpu_cid =per_cpu_ptr (mm->pcpu_cid,cpu_of (dst_rq)); - dst_cid =READ_ONCE (dst_pcpu_cid->cid); -if (!mm_cid_is_unset (dst_cid) && -atomic_read (&mm->mm_users) >= t->nr_cpus_allowed) + dst_cid_is_set = !mm_cid_is_unset (READ_ONCE (dst_pcpu_cid->cid)) || + !mm_cid_is_unset (READ_ONCE (dst_pcpu_cid->recent_cid)); +if (dst_cid_is_set &&atomic_read (&mm->mm_users) >=atomic_read (&mm->nr_cpus_allowed))return ; src_pcpu_cid =per_cpu_ptr (mm->pcpu_cid, src_cpu); src_rq =cpu_rq (src_cpu);
@@ -10280,13 +10283,14 @@ void sched_mm_cid_migrate_to(struct rq *dst_rq, struct task_struct *t) src_cid);if (src_cid ==-1 )return ; -if (!mm_cid_is_unset (dst_cid)) { +if (dst_cid_is_set) {__mm_cid_put (mm, src_cid);return ; }/* Move src_cid to dst cpu. */ mm_cid_snapshot_time (dst_rq, mm);WRITE_ONCE (dst_pcpu_cid->cid, src_cid); +WRITE_ONCE (dst_pcpu_cid->recent_cid, src_cid); } static void sched_mm_cid_remote_clear(struct mm_struct *mm, struct mm_cid *pcpu_cid,
@@ -10523,7 +10527,7 @@ void sched_mm_cid_after_execve(struct task_struct *t)* Matches barrier in sched_mm_cid_remote_clear_old(). */ smp_mb (); - t->last_mm_cid = t->mm_cid =mm_cid_get (rq, mm); + t->last_mm_cid = t->mm_cid =mm_cid_get (rq, t, mm); }rseq_set_notify_resume (t); }
kernel/sched/sched.h +33 -14
106 lines not on this page · raw message
Signature · 1 line
2.39.2
Mathieu Desnoyers
maintainerPATCH 2/2 selftests/rseq: Adapt to glibc __rseq_size feature detection
In reply to Mathieu DesnoyersAdapt the rseq.c/rseq.h code to follow GNU C library changes introduced by:
commit 2e456ccf0c34 ("Linux: Make __rseq_size useful for feature detection (bug 31965)")
Wihout this fix, rseq selftests for mm_cid fail:
./run_param_test.sh
Default parameters
Running test spinlock
Running compare-twice test spinlock
Running mm_cid test spinlock
Error: cpu id getter unavailable
--- tools/testing/selftests/rseq/rseq.c | 109 +++++++++++++++++++--------- tools/testing/selftests/rseq/rseq.h | 10 +-- 2 files changed, 76 insertions(+), 43 deletions(-)
tools/testing/selftests/rseq/rseq.c +74 -35
@@ -60,12 +60,6 @@ unsigned int rseq_size = -1U;/* Flags used during rseq registration. */ unsigned int rseq_flags; -/* -* rseq feature size supported by the kernel. 0 if the registration was -* unsuccessful. -*/ -unsigned int rseq_feature_size =-1U ; -static int rseq_ownership;static int rseq_reg_success;/* At least one rseq registration has succeded. */
@@ -111,6 +105,43 @@ int rseq_available(void) } } +/* The rseq areas need to be at least 32 bytes. */ +static +unsigned get_rseq_min_alloc_size (void ) +{ +unsigned int alloc_size = rseq_size; + +if (alloc_size <ORIG_RSEQ_ALLOC_SIZE ) + alloc_size =ORIG_RSEQ_ALLOC_SIZE ; +return alloc_size; +} + +/* +* Return the feature size supported by the kernel. +* +* Depending on the value returned by getauxval(AT_RSEQ_FEATURE_SIZE): +* +* 0: Return ORIG_RSEQ_FEATURE_SIZE (20) +* > 0: Return the value from getauxval(AT_RSEQ_FEATURE_SIZE). +* +* It should never return a value below ORIG_RSEQ_FEATURE_SIZE. +*/ +static +unsigned int get_rseq_kernel_feature_size (void ) +{ +unsigned long auxv_rseq_feature_size, auxv_rseq_align; + + auxv_rseq_align =getauxval (AT_RSEQ_ALIGN ); +assert (!auxv_rseq_align || auxv_rseq_align <=RSEQ_THREAD_AREA_ALLOC_SIZE ); + + auxv_rseq_feature_size =getauxval (AT_RSEQ_FEATURE_SIZE ); +assert (!auxv_rseq_feature_size || auxv_rseq_feature_size <=RSEQ_THREAD_AREA_ALLOC_SIZE ); +if (auxv_rseq_feature_size) +return auxv_rseq_feature_size; +else +return ORIG_RSEQ_FEATURE_SIZE ; +} +int rseq_register_current_thread (void ) {int rc;
@@ -119,7 +150,7 @@ int rseq_register_current_thread(void)/* Treat libc's ownership as a successful registration. */ return 0 ; } - rc =sys_rseq (&__rseq_abi, rseq_size,0 ,RSEQ_SIG ); + rc =sys_rseq (&__rseq_abi,get_rseq_min_alloc_size (),0 ,RSEQ_SIG );if (rc) {if (RSEQ_READ_ONCE (rseq_reg_success)) {/* Incoherent success/failure within process. */
@@ -140,28 +171,12 @@ int rseq_unregister_current_thread(void)/* Treat libc's ownership as a successful unregistration. */ return 0 ; } - rc =sys_rseq (&__rseq_abi, rseq_size,RSEQ_ABI_FLAG_UNREGISTER ,RSEQ_SIG ); + rc =sys_rseq (&__rseq_abi,get_rseq_min_alloc_size (),RSEQ_ABI_FLAG_UNREGISTER ,RSEQ_SIG );if (rc)return -1 ;return 0 ; } -static -unsigned int get_rseq_feature_size (void ) -{ -unsigned long auxv_rseq_feature_size, auxv_rseq_align; - - auxv_rseq_align =getauxval (AT_RSEQ_ALIGN ); -assert (!auxv_rseq_align || auxv_rseq_align <=RSEQ_THREAD_AREA_ALLOC_SIZE ); - - auxv_rseq_feature_size =getauxval (AT_RSEQ_FEATURE_SIZE ); -assert (!auxv_rseq_feature_size || auxv_rseq_feature_size <=RSEQ_THREAD_AREA_ALLOC_SIZE ); -if (auxv_rseq_feature_size) -return auxv_rseq_feature_size; -else -return ORIG_RSEQ_FEATURE_SIZE ; -} -static __attribute__((constructor))void rseq_init (void ) {
@@ -178,28 +193,53 @@ void rseq_init(void) }if (libc_rseq_size_p && libc_rseq_offset_p && libc_rseq_flags_p && *libc_rseq_size_p !=0 ) { +unsigned int libc_rseq_size; +/* rseq registration owned by glibc */ rseq_offset = *libc_rseq_offset_p; - rseq_size = *libc_rseq_size_p; + libc_rseq_size = *libc_rseq_size_p; rseq_flags = *libc_rseq_flags_p; - rseq_feature_size =get_rseq_feature_size (); -if (rseq_feature_size > rseq_size) - rseq_feature_size = rseq_size; + +/* +* Previous versions of glibc expose the value +* 32 even though the kernel only supported 20 +* bytes initially. Therefore treat 32 as a +* special-case. glibc 2.40 exposes a 20 bytes +* __rseq_size without using getauxval(3) to +* query the supported size, while still allocating a 32 +* bytes area. Also treat 20 as a special-case. +* +* Special-cases are handled by using the following +* value as active feature set size: +* +* rseq_size = min(32, get_rseq_kernel_feature_size()) +*/ +switch (libc_rseq_size) { +case ORIG_RSEQ_FEATURE_SIZE :/* Fallthrough. */ +case ORIG_RSEQ_ALLOC_SIZE : + { +unsigned int rseq_kernel_feature_size =get_rseq_kernel_feature_size (); + +if (rseq_kernel_feature_size <ORIG_RSEQ_ALLOC_SIZE ) + rseq_size = rseq_kernel_feature_size; +else + rseq_size =ORIG_RSEQ_ALLOC_SIZE ; +break ; + } +default : +/* Otherwise just use the __rseq_size from libc as rseq_size. */ + rseq_size = libc_rseq_size; +break ; + }return ; } rseq_ownership =1 ;if (!rseq_available ()) { rseq_size =0 ; - rseq_feature_size =0 ;return ; } rseq_offset = (void *)&__rseq_abi -rseq_thread_pointer (); rseq_flags =0 ; - rseq_feature_size =get_rseq_feature_size (); -if (rseq_feature_size ==ORIG_RSEQ_FEATURE_SIZE ) - rseq_size =ORIG_RSEQ_ALLOC_SIZE ; -else - rseq_size =RSEQ_THREAD_AREA_ALLOC_SIZE ; } static __attribute__((destructor))
@@ -209,7 +249,6 @@ void rseq_exit(void)return ; rseq_offset =0 ; rseq_size =-1U ; - rseq_feature_size =-1U ; rseq_ownership =0 ; }
tools/testing/selftests/rseq/rseq.h +2 -8
@@ -68,12 +68,6 @@ extern unsigned int rseq_size;/* Flags used during rseq registration. */ extern unsigned int rseq_flags; -/* -* rseq feature size supported by the kernel. 0 if the registration was -* unsuccessful. -*/ -extern unsigned int rseq_feature_size; -enum rseq_mo {RSEQ_MO_RELAXED =0 ,RSEQ_MO_CONSUME =1 ,/* Unused */
@@ -193,7 +187,7 @@ static inline uint32_t rseq_current_cpu(void)static inline bool rseq_node_id_available (void ) { - return (int) rseq_feature_size >= rseq_offsetofend(struct rseq_abi, node_id); + return (int) rseq_size >= rseq_offsetofend(struct rseq_abi, node_id); }/*
@@ -207,7 +201,7 @@ static inline uint32_t rseq_current_node_id(void)static inline bool rseq_mm_cid_available (void ) { - return (int) rseq_feature_size >= rseq_offsetofend(struct rseq_abi, mm_cid); + return (int) rseq_size >= rseq_offsetofend(struct rseq_abi, mm_cid); }static inline uint32_t rseq_current_mm_cid (void )
Signature · 1 line
2.39.2
Shuah Khan
maintainerRe: [PATCH 2/2] selftests/rseq: Adapt to glibc __rseq_size feature detection
Quoted 5 lines · Mathieu Desnoyers
Adapt the
rseq.c/rseq.hcode to follow GNU C library changes introduced by:commit
2e456ccf0c34("Linux: Make__rseq_sizeuseful for feature detection (bug 31965)")Wihout this fix, rseq selftests for
mm_cidfail:
Without
Can you change the short log to say "Fix mm_cid test failure"
This way it is clear that this fixes a test failure. You can add "Adapt to glibc __rseq_size feature detection: in the chabeg log for context.
Quoted 219 lines
./run_param_test.sh
Default parameters
Running test spinlock
Running compare-twice test spinlock
Runningmm_cidtest spinlock
Error: cpu id getter unavailableSigned-off-by Mathieu Desnoyers <[email protected]>Cc Peter Zijlstra <[email protected]>CC Boqun Feng <[email protected]>CC "Paul E. McKenney" <[email protected]>Cc Shuah Khan <[email protected]>CC Carlos O'Donell <[email protected]>CC Florian Weimer <[email protected]>--- tools/testing/selftests/rseq/rseq.c | 109 +++++++++++++++++++--------- tools/testing/selftests/rseq/rseq.h | 10 +-- 2 files changed, 76 insertions(+), 43 deletions(-)tools/testing/selftests/rseq/rseq.c +74
-35@@ -60,12 +60,6 @@ unsigned int rseq_size = -1U;/* Flags used during rseq registration. */ unsigned int rseq_flags; -/* -* rseq feature size supported by the kernel. 0 if the registration was -* unsuccessful. -*/ -unsigned int rseq_feature_size =-1U ; -static int rseq_ownership;static int rseq_reg_success;/* At least one rseq registration has succeded. */ @@ -111,6 +105,43 @@ int rseq_available(void) } } +/* The rseq areas need to be at least 32 bytes. */ +static +unsigned get_rseq_min_alloc_size (void ) +{ +unsigned int alloc_size = rseq_size; + +if (alloc_size <ORIG_RSEQ_ALLOC_SIZE ) + alloc_size =ORIG_RSEQ_ALLOC_SIZE ; +return alloc_size; +} + +/* +* Return the feature size supported by the kernel. +* +* Depending on the value returned by getauxval(AT_RSEQ_FEATURE_SIZE): +* +* 0: Return ORIG_RSEQ_FEATURE_SIZE (20) +* > 0: Return the value from getauxval(AT_RSEQ_FEATURE_SIZE). +* +* It should never return a value below ORIG_RSEQ_FEATURE_SIZE. +*/ +static +unsigned int get_rseq_kernel_feature_size (void ) +{ +unsigned long auxv_rseq_feature_size, auxv_rseq_align; + + auxv_rseq_align =getauxval (AT_RSEQ_ALIGN ); +assert (!auxv_rseq_align || auxv_rseq_align <=RSEQ_THREAD_AREA_ALLOC_SIZE ); + + auxv_rseq_feature_size =getauxval (AT_RSEQ_FEATURE_SIZE ); +assert (!auxv_rseq_feature_size || auxv_rseq_feature_size <=RSEQ_THREAD_AREA_ALLOC_SIZE ); +if (auxv_rseq_feature_size) +return auxv_rseq_feature_size; +else +return ORIG_RSEQ_FEATURE_SIZE ; +} +int rseq_register_current_thread (void ) {int rc;@@ -119,7 +150,7 @@ int rseq_register_current_thread(void)/* Treat libc's ownership as a successful registration. */ return 0 ; } - rc =sys_rseq (&__rseq_abi, rseq_size,0 ,RSEQ_SIG ); + rc =sys_rseq (&__rseq_abi,get_rseq_min_alloc_size (),0 ,RSEQ_SIG );if (rc) {if (RSEQ_READ_ONCE (rseq_reg_success)) {/* Incoherent success/failure within process. */ @@ -140,28 +171,12 @@ int rseq_unregister_current_thread(void)/* Treat libc's ownership as a successful unregistration. */ return 0 ; } - rc =sys_rseq (&__rseq_abi, rseq_size,RSEQ_ABI_FLAG_UNREGISTER ,RSEQ_SIG ); + rc =sys_rseq (&__rseq_abi,get_rseq_min_alloc_size (),RSEQ_ABI_FLAG_UNREGISTER ,RSEQ_SIG );if (rc)return -1 ;return 0 ; } -static -unsigned int get_rseq_feature_size (void ) -{ -unsigned long auxv_rseq_feature_size, auxv_rseq_align; - - auxv_rseq_align =getauxval (AT_RSEQ_ALIGN ); -assert (!auxv_rseq_align || auxv_rseq_align <=RSEQ_THREAD_AREA_ALLOC_SIZE ); - - auxv_rseq_feature_size =getauxval (AT_RSEQ_FEATURE_SIZE ); -assert (!auxv_rseq_feature_size || auxv_rseq_feature_size <=RSEQ_THREAD_AREA_ALLOC_SIZE ); -if (auxv_rseq_feature_size) -return auxv_rseq_feature_size; -else -return ORIG_RSEQ_FEATURE_SIZE ; -} -static __attribute__((constructor))void rseq_init (void ) {@@ -178,28 +193,53 @@ void rseq_init(void) }if (libc_rseq_size_p && libc_rseq_offset_p && libc_rseq_flags_p && *libc_rseq_size_p !=0 ) { +unsigned int libc_rseq_size; +/* rseq registration owned by glibc */ rseq_offset = *libc_rseq_offset_p; - rseq_size = *libc_rseq_size_p; + libc_rseq_size = *libc_rseq_size_p; rseq_flags = *libc_rseq_flags_p; - rseq_feature_size =get_rseq_feature_size (); -if (rseq_feature_size > rseq_size) - rseq_feature_size = rseq_size; + +/* +* Previous versions of glibc expose the value +* 32 even though the kernel only supported 20 +* bytes initially. Therefore treat 32 as a +* special-case. glibc 2.40 exposes a 20 bytes +* __rseq_size without using getauxval(3) to +* query the supported size, while still allocating a 32 +* bytes area. Also treat 20 as a special-case. +* +* Special-cases are handled by using the following +* value as active feature set size: +* +* rseq_size = min(32, get_rseq_kernel_feature_size()) +*/ +switch (libc_rseq_size) { +case ORIG_RSEQ_FEATURE_SIZE :/* Fallthrough. */ +case ORIG_RSEQ_ALLOC_SIZE : + { +unsigned int rseq_kernel_feature_size =get_rseq_kernel_feature_size (); + +if (rseq_kernel_feature_size <ORIG_RSEQ_ALLOC_SIZE ) + rseq_size = rseq_kernel_feature_size; +else + rseq_size =ORIG_RSEQ_ALLOC_SIZE ; +break ; + } +default : +/* Otherwise just use the __rseq_size from libc as rseq_size. */ + rseq_size = libc_rseq_size; +break ; + }return ; } rseq_ownership =1 ;if (!rseq_available ()) { rseq_size =0 ; - rseq_feature_size =0 ;return ; } rseq_offset = (void *)&__rseq_abi -rseq_thread_pointer (); rseq_flags =0 ; - rseq_feature_size =get_rseq_feature_size (); -if (rseq_feature_size ==ORIG_RSEQ_FEATURE_SIZE ) - rseq_size =ORIG_RSEQ_ALLOC_SIZE ; -else - rseq_size =RSEQ_THREAD_AREA_ALLOC_SIZE ; } static __attribute__((destructor))@@ -209,7 +249,6 @@ void rseq_exit(void)return ; rseq_offset =0 ; rseq_size =-1U ; - rseq_feature_size =-1U ; rseq_ownership =0 ; }tools/testing/selftests/rseq/rseq.h +1
-7@@ -68,12 +68,6 @@ extern unsigned int rseq_size;/* Flags used during rseq registration. */ extern unsigned int rseq_flags; -/* -* rseq feature size supported by the kernel. 0 if the registration was -* unsuccessful. -*/ -extern unsigned int rseq_feature_size; -enum rseq_mo {RSEQ_MO_RELAXED =0 ,RSEQ_MO_CONSUME =1 ,/* Unused */ @@ -193,7 +187,7 @@ static inline uint32_t rseq_current_cpu(void)static inline bool rseq_node_id_available (void ) { - return (int) rseq_feature_size >= rseq_offsetofend(struct rseq_abi, node_id); + return (int) rseq_size >= rseq_offsetofend(struct rseq_abi, node_id); }/*
tools/testing/selftests/rseq/rseq.h static inline uint32_t rseq_current_node_id(void) · line 207
Quoted 8 lines
tools/testing/selftests/rseq/rseq.h +1
-1@@ -207,7 +201,7 @@ static inline uint32_t rseq_current_node_id(void)static inline bool rseq_mm_cid_available (void ) { - return (int) rseq_feature_size >= rseq_offsetofend(struct rseq_abi, mm_cid); + return (int) rseq_size >= rseq_offsetofend(struct rseq_abi, mm_cid); }static inline uint32_t rseq_current_mm_cid (void )
thanks,
-- Shuah
Mathieu Desnoyers
maintainerRe: [PATCH 2/2] selftests/rseq: Adapt to glibc __rseq_size feature detection
Quoted 7 lines · Shuah Khan
Quoted 5 lines · Mathieu Desnoyers
Adapt the
rseq.c/rseq.hcode to follow GNU C library changes introduced by:commit
2e456ccf0c34("Linux: Make__rseq_sizeuseful for feature detection (bug 31965)")Wihout this fix, rseq selftests for
mm_cidfail:
Quoted 7 lines
Without
Can you change the short log to say "Fix
mm_cidtest failure"This way it is clear that this fixes a test failure. You can add "Adapt to glibc
__rseq_sizefeature detection: in the chabeg log for context.
Yes, I will update it and re-send the series.
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com