From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E41F12BDC28 for ; Fri, 10 Jul 2026 14:43:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783694639; cv=none; b=GrNhMgFw1gZ2Ex/J5FJHBhSn7Hms032aZFnJjZ8W1yQFnY0dMS1e4PxaJnOGQLNd4AAzGPdUVDiL0OTr1IEx8xcCF9jiT358T+q9Iz9ktHJBDGc7qmpWjOvRgPf1RH7YLQ0v0+jQ8XWqWd0QRZSZlkOSXzVkAAUh0ZWCmgM8yi8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783694639; c=relaxed/simple; bh=pzRKBu3SXQKga3pYDi4SadmUoxVjMew/0Myz9yjAuGk=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=qu5ImFeVEuvI5L/H0XPvmZY53LlA0rj/z8njrn5EirK2AopDLw6q/K5Apzxu9p+9e6rx6uQQMA8GNoy9F6HOkwDKHWQ1VSGXxQVua0Lp5znZPM5hscGCRQ53rU3+SVD0ms7NohnAv4W9Sa2tYJbmfLd62EKD8/nCOJvBGcjvdZw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nWUH7GtH; arc=none smtp.client-ip=209.85.218.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nWUH7GtH" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-c15cec1ccb6so103909066b.1 for ; Fri, 10 Jul 2026 07:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783694636; x=1784299436; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=FxNlQqZ4nmCctseCgXDiOPH8Q0HV/V8Z2ffjauVlT1w=; b=nWUH7GtHUOYJahPfRcbr7b8NH2Iyxs01C1Jw/7EE1UNJXFY/JCZ6ynfnMalEdOvcah SZ0/naYBwoavZK7OvglK64D2BPOksMZr/Z22FUCbXIl/9ab0FUYQZGvFlULmSPMl4ewg 1FRhnckaS46dJceZ6akWR6/vFRoEHcz7EGn76qhdjaaHtfhRZq1pqwLJiPWYmfuLkGd/ /nfviMyyk5ZYEG0NAH/TfglzlOHQKbofQY3/slTfXDPswXxMceHyxzWVPB3ILTmxFQJa x5Mbc13Mzl7e3ln9pUxJKZV66nGmeoH5cSat+ZgxQoUjs5HeZi8BvhYh1d/RP0v17Rrj c74A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783694636; x=1784299436; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=FxNlQqZ4nmCctseCgXDiOPH8Q0HV/V8Z2ffjauVlT1w=; b=LFE4T3AdLTMUflUcOvMDUNg0ZgMD1FN2iZEpLFO2cd7TpNa5cYDgd8FUmyrLuT62uO fOp8aovO3DXm2SN5p2DK2RjWj2stRxPIa7ryHPKInl0uo/LTj1f993fEqlRF0qLu21hD 1vxrw2Zg3Ijz4XBJ/f4kzkU9Eq7MTORmkVOHMcIruigDLOWzez8AkvECuiDQdetjhwUy RH4CHjtDqo2qr3pVev5YbzXHR5TQfdOnOxMnyjipZLhITvmj4dUKJxq3NMqsiHVpAoOK sPiw61rp0Q9QGJUd2mEE57ZXch7vLk4xLYvOlvrvGe0+FNweIYuMPfH/i0G1uTfu8tB+ WRGQ== X-Gm-Message-State: AOJu0YyrttonCG6gRsJGqYk/7U+24y0CgaSh2YunjW0RAqAV1fw58VPC TErCEwi93eRsn7K7acoO8Yr1DcwU63ZCTzxaorBWSXCyoP66hdr31Ul1u2XjUZcBCH0doEsKKBj 6eMBDPRqRRoIgrg== X-Received: from ejbgw6.prod.google.com ([2002:a17:906:f146:b0:c12:549e:c2fd]) (user=jpiecuch job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:bd81:b0:c12:a469:c with SMTP id a640c23a62f3a-c15cded3365mr517601366b.9.1783694635943; Fri, 10 Jul 2026 07:43:55 -0700 (PDT) Date: Fri, 10 Jul 2026 14:43:41 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.795.g602f6c329a-goog Message-ID: <20260710144342.3802587-1-jpiecuch@google.com> Subject: [PATCH sched_ext/for-7.3] sched_ext: skip ops.set_weight() for disabled tasks From: Kuba Piecuch To: Tejun Heo , Andrea Righi , Changwoo Min , David Vernet Cc: linux-kernel@vger.kernel.org, sched-ext@lists.linux.dev, Kuba Piecuch Content-Type: text/plain; charset="UTF-8" When switching a task's sched_class away from sched_ext, we get the following sequence of events in __sched_setscheduler(): sched_change_begin() switched_from_scx() scx_disable_task(p) ops.disable(p) __setscheduler_params() set_load_weight() reweight_task_scx(p) ops.set_weight(p) p->sched_class = next_class; sched_change_end() ... Notably, ops.set_weight() is called _after_ ops.disable(). This violates the expected semantics of the callbacks, the expectation being that ops.disable() can only be followed by ops.exit_task() or ops.enable(). Skipping the weight adjustment for disabled tasks should be harmless since the weight will be recalculated in scx_enable_task() if the task ever rejoins SCX. Signed-off-by: Kuba Piecuch --- kernel/sched/ext/ext.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c index 5241b55a58ec..b75d8d71ef4d 100644 --- a/kernel/sched/ext/ext.c +++ b/kernel/sched/ext/ext.c @@ -3673,6 +3673,17 @@ static void reweight_task_scx(struct rq *rq, struct task_struct *p, if (task_dead_and_done(p)) return; + /* + * When switching sched_class away from SCX, reweight_task_scx() + * is called _after_ scx_disable_task(). Skip calling ops.set_weight() + * since the BPF scheduler may have already forgotten the task in + * ops.disable(). + * p->scx.weight will be recalculated in scx_enable_task() if the task + * ever returns to SCX class. + */ + if (scx_get_task_state(p) != SCX_TASK_ENABLED) + return; + p->scx.weight = sched_weight_to_cgroup(scale_load_down(lw->weight)); if (SCX_HAS_OP(sch, set_weight)) SCX_CALL_OP_TASK(sch, set_weight, rq, p, p->scx.weight); -- 2.55.0.795.g602f6c329a-goog