From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 4282838F629 for ; Mon, 2 Mar 2026 09:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772442892; cv=none; b=MUWpiP1mHnQXena120hGBIgaxRVJa/LQmCi1BdDDPEuz47bW094arlpx8v9dhswoMpapGuXhKxXoVVMV+hdXN5ANcHY57GXEY+JgYUhqLTHuYPgR434fkNlDu7E6UbriyN+t4ComB4NBYvDpOwcCjKJRiVJwEiicbydZK1pheDE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772442892; c=relaxed/simple; bh=mqQ1xqyijcFk6G2ohzrkaC2WIRmYTASGG+OJDAiXtEY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=INdY5JNx8bPqjIJduNhktMAAlwV5OVhe/xOPhSeTZWXeZliXM+cqnDS5pl+YWVIvdSoF8lVjzF3kuEU24bILj2SoYj5r0RJ76/FCygyscelOsf9UYtoUyOguXneryfBmMbIAALeSVFOUXQnxekA/+Tt9uFFHG9ovEn4xhu9nAu8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UnrdQVQ0; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UnrdQVQ0" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2ae50a33ff8so5120805ad.3 for ; Mon, 02 Mar 2026 01:14:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772442889; x=1773047689; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xp4h+20tE5YCAazww+ZGLMD2jeF+NfRy9eju/1nS0pk=; b=UnrdQVQ0P8AhkMCuUj5K6sW6bVSq01yNIUr5fpidWgyaUxMInqc14/AhIDuyZ87npp +dFf3swcA4x3L5GpTNJnBmvtyMB9x9k5FsV0QrjiOnPZXDKJrAQhewUdC5Vyq1ISf4F7 ov2RYe26X7oKXIa6ekFijozM/QL0Whpy2GJCENkTiYt1cjRKRLOv+lN2ekk0sW3BJJcL Q1Kfr/sXta5GXu0FdII2sk+gKjl9M59DJ+ZzEg29gKTo/uNM+MG4QILJ0lMljP8BNcVy il6lHCd+COlgn9VurHXQQkaBmbVgV8saZvRxpHaqhZwN9F1MSzn+MRgEoQv/EXkuvDmi DB0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772442889; x=1773047689; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xp4h+20tE5YCAazww+ZGLMD2jeF+NfRy9eju/1nS0pk=; b=Ouxcm87/G2eclag7AivKg4Lwh0fPZ5/CzOL/4L1WVoq+ttNWeDi5XqjVNSvmIkIaT5 AuKr1C3F+xruM+CVOZn6OcBQZxEA6Wv8Lm3jAoL1n5Qd1u41gxIqm31cx51vtVfnRrAJ D6NA231F3WZgu5Jtk+mzsSr48uSGtq4hkPc5oJSLXk1N1bPCLFA4Z22f3ROLu+8MbWBR yAmyipLnb+uKL4RQZcJzjeoWc2fEjAi6dzjAb9aNwIrswHmlq0263FxTdyQsEh55oGxu pkAXWEfNhGKQg3cZgoe7gqHKLgdCMyb7CIvQjXSYkezD2PiC3vUPz2kzmZypwT5SzHHA lElw== X-Gm-Message-State: AOJu0YyWH6i5Y9DtN9tjjHit+gRFwweX3pXfU6IQpZSyohWJm0VZ9pAY 9eNvfTxOsLKLC11yVLNrf/JiPw8YSmSOqWtsz8CZf41keKfrjGHwZ+MGixLrKKV1 X-Gm-Gg: ATEYQzx4T/POeRtA67Zks7qwGiKfeEkBaU9LeoBT4jAe4DOjVOBJXBxPZpMqq5PD4nx pAUWanZ8i0LbdDVbPT/NGqIeRWnCaHH2SHrPOd8pfEUR7PjqE3h5xerQTV2pbvBYqictSjBFG0S Q+c94FYZCFDzktQ49ZgFUSF4YvfSFTAi7RPTVMBVKcUnYXnzYkueJ+btYX1MgUTnPNbDG7i9pJM 8X/UCxCejFrDSR8wqkMFQ3LyYAUF1tOO31DH9ayrRk7vcPeWoDjFLOzR/KdT0IfZlroJtI0kn1D i224VWjglQgAGc9o9ycarCTlPRrDD7s6bl1mqzzxzHSYqAmmKLqo+JxEFtyGlamuvLVOkvd7fmG VI0GQEqdypGmtXP4TmlwrPIfCjtapHuU8R+s44WEnkNEjM6Vp8x2MjEbdgvw0giP9rPDYkWYra1 ej4PALiQz87rPX0SgPbpvnqPS03s/trG8thnvriCs7pkd3dviIYmsfg0XAlD91k/UP4qKzVlMV5 4ZkD1xG+bbFSzs= X-Received: by 2002:a17:902:ea02:b0:2ad:c527:e9fd with SMTP id d9443c01a7336-2ae2e4b5a34mr130433495ad.41.1772442889308; Mon, 02 Mar 2026 01:14:49 -0800 (PST) Received: from mi-HP-ProDesk-680-G6-PCI-Microtower-PC.mioffice.cn ([43.224.245.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ae496470d3sm39729525ad.15.2026.03.02.01.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 01:14:49 -0800 (PST) From: zhidao su To: sched-ext@lists.linux.dev Cc: linux-kernel@vger.kernel.org, tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com, peterz@infradead.org, mingo@redhat.com, zhidao su Subject: [PATCH 2/2] sched_ext: Replace naked scx_root dereferences in kobject callbacks Date: Mon, 2 Mar 2026 17:14:40 +0800 Message-ID: <20260302091440.3973220-2-soolaugust@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260302091440.3973220-1-soolaugust@gmail.com> References: <20260302091440.3973220-1-soolaugust@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: zhidao su scx_attr_ops_show() and scx_uevent() access scx_root->ops.name directly. This is problematic for two reasons: 1. The file-level comment explicitly identifies naked scx_root dereferences as a temporary measure that needs to be replaced with proper per-instance access. 2. scx_attr_events_show(), the neighboring sysfs show function in the same group, already uses the correct pattern: struct scx_sched *sch = container_of(kobj, struct scx_sched, kobj); Having inconsistent access patterns in the same sysfs/uevent group is error-prone. The kobject embedded in struct scx_sched is initialized as: kobject_init_and_add(&sch->kobj, &scx_ktype, NULL, "root"); so container_of(kobj, struct scx_sched, kobj) correctly retrieves the owning scx_sched instance in both callbacks. Replace the naked scx_root dereferences with container_of()-based access, consistent with scx_attr_events_show() and in preparation for proper multi-instance scx_sched support. Signed-off-by: zhidao su --- kernel/sched/ext.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 718401f4ff2a..f25340ac044a 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -3631,7 +3631,9 @@ static void scx_kobj_release(struct kobject *kobj) static ssize_t scx_attr_ops_show(struct kobject *kobj, struct kobj_attribute *ka, char *buf) { - return sysfs_emit(buf, "%s\n", scx_root->ops.name); + struct scx_sched *sch = container_of(kobj, struct scx_sched, kobj); + + return sysfs_emit(buf, "%s\n", sch->ops.name); } SCX_ATTR(ops); @@ -3675,7 +3677,9 @@ static const struct kobj_type scx_ktype = { static int scx_uevent(const struct kobject *kobj, struct kobj_uevent_env *env) { - return add_uevent_var(env, "SCXOPS=%s", scx_root->ops.name); + const struct scx_sched *sch = container_of(kobj, struct scx_sched, kobj); + + return add_uevent_var(env, "SCXOPS=%s", sch->ops.name); } static const struct kset_uevent_ops scx_uevent_ops = { -- 2.43.0