Merge branch 'for-7.1-fixes' into for-7.2

Pull to receive:

 05909810a9 ("tools/sched_ext: scx_qmap: Silence task_ctx lookup miss")

which conflicts with the cid-form qmap rework on for-7.2. Resolved
by applying the same silence-on-NULL semantics to the arena-backed
lookup_task_ctx() and qmap_select_cpu() on for-7.2.

Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
Tejun Heo 2026-04-21 06:30:11 -10:00
commit 9af5d67065
4 changed files with 35 additions and 8 deletions

View File

@ -12,6 +12,7 @@
#include <linux/alloc_tag.h>
#include <linux/atomic.h>
#include <linux/compiler.h>
#include <linux/irq_work_types.h>
#include <linux/mutex.h>
#include <linux/workqueue_types.h>
@ -77,6 +78,7 @@ struct rhashtable_params {
* @p: Configuration parameters
* @rhlist: True if this is an rhltable
* @run_work: Deferred worker to expand/shrink asynchronously
* @run_irq_work: Bounces the @run_work kick through hard IRQ context.
* @mutex: Mutex to protect current/future table swapping
* @lock: Spin lock to protect walker list
* @nelems: Number of elements in table
@ -88,6 +90,7 @@ struct rhashtable {
struct rhashtable_params p;
bool rhlist;
struct work_struct run_work;
struct irq_work run_irq_work;
struct mutex mutex;
spinlock_t lock;
atomic_t nelems;

View File

@ -20,6 +20,7 @@
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/irq_work.h>
#include <linux/jhash.h>
#include <linux/list_nulls.h>
#include <linux/workqueue.h>
@ -847,7 +848,7 @@ static __always_inline void *__rhashtable_insert_fast(
rht_assign_unlock(tbl, bkt, obj, flags);
if (rht_grow_above_75(ht, tbl))
schedule_work(&ht->run_work);
irq_work_queue(&ht->run_irq_work);
data = NULL;
out:

View File

@ -441,10 +441,33 @@ static void rht_deferred_worker(struct work_struct *work)
mutex_unlock(&ht->mutex);
/*
* Re-arm via @run_work, not @run_irq_work.
* rhashtable_free_and_destroy() drains async work as irq_work_sync()
* followed by cancel_work_sync(). If this site queued irq_work while
* cancel_work_sync() was waiting for us, irq_work_sync() would already
* have returned and the stale irq_work could fire post-teardown.
* cancel_work_sync() natively handles self-requeue on @run_work.
*/
if (err)
schedule_work(&ht->run_work);
}
/*
* Insert-path callers can run under a raw spinlock (e.g. an insecure_elasticity
* user). Calling schedule_work() under that lock records caller_lock ->
* pool->lock -> pi_lock -> rq->__lock, closing a locking cycle if any of
* these is acquired in the reverse direction elsewhere. Bounce through
* irq_work so the schedule_work() runs with the caller's lock no longer held.
*/
static void rht_deferred_irq_work(struct irq_work *irq_work)
{
struct rhashtable *ht = container_of(irq_work, struct rhashtable,
run_irq_work);
schedule_work(&ht->run_work);
}
static int rhashtable_insert_rehash(struct rhashtable *ht,
struct bucket_table *tbl)
{
@ -477,7 +500,7 @@ static int rhashtable_insert_rehash(struct rhashtable *ht,
if (err == -EEXIST)
err = 0;
} else
schedule_work(&ht->run_work);
irq_work_queue(&ht->run_irq_work);
return err;
@ -488,7 +511,7 @@ static int rhashtable_insert_rehash(struct rhashtable *ht,
/* Schedule async rehash to retry allocation in process context. */
if (err == -ENOMEM)
schedule_work(&ht->run_work);
irq_work_queue(&ht->run_irq_work);
return err;
}
@ -630,7 +653,7 @@ static void *rhashtable_try_insert(struct rhashtable *ht, const void *key,
rht_unlock(tbl, bkt, flags);
if (inserted && rht_grow_above_75(ht, tbl))
schedule_work(&ht->run_work);
irq_work_queue(&ht->run_irq_work);
}
} while (!IS_ERR_OR_NULL(new_tbl));
@ -1085,6 +1108,7 @@ int rhashtable_init_noprof(struct rhashtable *ht,
RCU_INIT_POINTER(ht->tbl, tbl);
INIT_WORK(&ht->run_work, rht_deferred_worker);
init_irq_work(&ht->run_irq_work, rht_deferred_irq_work);
return 0;
}
@ -1150,6 +1174,7 @@ void rhashtable_free_and_destroy(struct rhashtable *ht,
struct bucket_table *tbl, *next_tbl;
unsigned int i;
irq_work_sync(&ht->run_irq_work);
cancel_work_sync(&ht->run_work);
mutex_lock(&ht->mutex);

View File

@ -195,10 +195,8 @@ static task_ctx_t *lookup_task_ctx(struct task_struct *p)
QMAP_TOUCH_ARENA();
v = bpf_task_storage_get(&task_ctx_stor, p, 0, 0);
if (!v || !v->taskc) {
scx_bpf_error("task_ctx lookup failed");
if (!v || !v->taskc)
return NULL;
}
return v->taskc;
}
@ -283,7 +281,7 @@ s32 BPF_STRUCT_OPS(qmap_select_cpu, struct task_struct *p,
s32 cpu;
if (!(taskc = lookup_task_ctx(p)))
return -ESRCH;
return prev_cpu;
if (p->scx.weight < 2 && !(p->flags & PF_KTHREAD))
return prev_cpu;