Re: [patch v2 08/11] futex: Add robust futex unlock IP range
From: Sebastian Andrzej Siewior
Date: Fri Mar 27 2026 - 09:26:37 EST
On 2026-03-20 00:24:46 [+0100], Thomas Gleixner wrote:
> --- a/include/linux/futex_types.h
> +++ b/include/linux/futex_types.h
> @@ -31,6 +31,20 @@ struct futex_sched_data {
…
>
> +struct futex_unlock_cs_range {
> + unsigned long start_ip;
> + unsigned long end_ip;
> + unsigned int pop_size32;
> +};
> +
> +#define FUTEX_ROBUST_MAX_CS_RANGES 2
…
> @@ -50,6 +68,10 @@ struct futex_mm_data {
> atomic_long_t phash_atomic;
> unsigned int __percpu *phash_ref;
> #endif
> +#ifdef CONFIG_FUTEX_ROBUST_UNLOCK
> + unsigned int unlock_cs_num_ranges;
> + struct futex_unlock_cs_range unlock_cs_ranges[FUTEX_ROBUST_MAX_CS_RANGES];
> +#endif
> };
While looking at this from an economic point of view, we get:
| unsigned int * phash_ref; /* 80 8 */
| unsigned int unlock_cs_num_ranges; /* 88 4 */
|
| /* XXX 4 bytes hole, try to pack */
|
| struct futex_unlock_cs_range unlock_cs_ranges[2]; /* 96 48 */
|}
|struct futex_unlock_cs_range {
| long unsigned int start_ip; /* 0 8 */
| long unsigned int end_ip; /* 8 8 */
| unsigned int pop_size32; /* 16 4 */
|
| /* size: 24, cachelines: 1, members: 3 */
| /* padding: 4 */
| /* last cacheline: 24 bytes */
|};
end_ip could be replaced with a u16 size. There is no need to have
pop_size32 as u32, it could be a u16 filling the gap.
On the other hand, pop_size32 could be passed by the caller since it is
known if it is the first or the second member / the 64bit or 32bit case.
unlock_cs_num_ranges could probably go because if start_ip == NULL then
there is no mapping since it can't be mapped at 0x0. Worst case would be
to check two variables vs NULL.
And if we replace end_ip with size then we could remove it because vdso
is known at compile so we should know the size at compile time.
Sebastian