From nobody Fri Dec 19 19:17:43 2025 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EA581A0BE0 for ; Wed, 8 Jan 2025 08:33:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736325208; cv=none; b=F8sNOK7lf+fywsqSQ7Fa1tBNmqG1KepZfLgEAkkbguBsH0jhh2FztnKhgNi+Tbcg2IQ3AIhenga/B0VNOfNTyQXD/NUxWz5Ofp2xVJ6GeKUEiDZmL+L2S+/PLOgtAwhYky8EEro1rTkSf/L752pYek5S+M6HuPggUtASbbZmoH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736325208; c=relaxed/simple; bh=iirM0NasIYzjQrdmz/tXpf6l1cO4qDifM38gdGoqe5k=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=nDJEBUoY1eZVjPmcdfIir+cB3UwXuJqq5E2BsE5RlTZ+2wEuoR8DvjQg5WMjMNXGhk7jfKhtM5hhclR/rYMUnkDN1PFFSZbz7zu6fSow0oWzuBq9OXz5QZ3v/9n06eKEGjwCXmglbHLYsqMjXL3S9qMHzdpUwPXVOrz0HUfRimM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=lWcdtGgI; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="lWcdtGgI" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Vp8LGSCadpXk37ONZPISrlYudNE5rvfNtsIU+pxh1WQ=; b=lWcdtGgIkJItEb6415HYP8Cc0m ooBAIMVDNNHVcecW4Jk/flOwYo2AOhwO2VLcqj4VuE6WlG1ruG6cA0cSFZjOiA2PecMaEoHIxSyon 1ewfscyKryeZGh0074CJ+h5quOUY5JhsUyJ8kq/oy2fNaFsU2ztBkdCBwuSvvDHkAszUDbG8RikYX LUoRfqQgJufT7ti3EBnwsHUQdYsKwzZEksP8FypStraLe/whms0jorB3EOPVroSlnHccxfpbgt2z7 JkXPL+BRGUBAZnwyoRQaeFigzewsnQtQgqCjlpk2md7A471SjwhKUMlAri31TDa3HYBz/3kZzm/EJ mpojIJtw==; Received: from [58.29.143.236] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1tVRV6-00D3Tv-Pw; Wed, 08 Jan 2025 09:33:17 +0100 From: Changwoo Min To: tj@kernel.org, void@manifault.com, arighi@nvidia.com Cc: kernel-dev@igalia.com, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH v2] sched_ext: Replace rq_lock() to raw_spin_rq_lock() in scx_ops_bypass() Date: Wed, 8 Jan 2025 17:33:07 +0900 Message-ID: <20250108083307.74220-1-changwoo@igalia.com> X-Mailer: git-send-email 2.47.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" scx_ops_bypass() iterates all CPUs to re-enqueue all the scx tasks. For each CPU, it acquires a lock using rq_lock() regardless of whether a CPU is offline or the CPU is currently running a task in a higher scheduler class (e.g., deadline). The rq_lock() is supposed to be used for online CPUs, and the use of rq_lock() may trigger an unnecessary warning in rq_pin_lock(). Therefore, replace rq_lock() to raw_spin_rq_lock() in scx_ops_bypass(). This change fixes: 0e7ffff1b811 ("scx: Fix raciness in scx_ops_bypass()") Without this change, we observe the following warnings: =3D=3D=3D=3D=3D START =3D=3D=3D=3D=3D [ 6.615204] ------------[ cut here ]------------ [ 6.615205] rq->balance_callback && rq->balance_callback !=3D &balance_p= ush_callback [ 6.615208] WARNING: CPU: 2 PID: 0 at kernel/sched/sched.h:1730 __schedu= le+0x1130/0x1c90 [ 6.615214] Modules linked in: nf_tables vfat fat intel_rapl_msr amd_atl= intel_rapl_common kvm_amd snd_hda_codec_realtek snd_hda_scodec_component k= vm snd_hda_codec_generic crct10dif_pclmul crc32_pclmul polyval_clmulni snd_= hda_intel polyval_generic ghash_clmulni_intel snd_intel_dspcfg eeepc_wmi sn= d_usb_audio snd_intel_sdw_acpi sha512_ssse3 sha1_ssse3 asus_wmi snd_hda_cod= ec aesni_intel snd_usbmidi_lib ee1004 platform_profile gf128mul snd_ump asu= s_ec_sensors snd_hda_core i8042 crypto_simd snd_rawmidi sparse_keymap snd_h= wdep snd_seq_device cryptd serio rapl rfkill snd_pcm wmi_bmof pcspkr k10tem= p snd_timer i2c_piix4 snd i2c_smbus soundcore ccp mc igc mousedev ptp joyde= v pps_core leetmouse(OE) mac_hid tcp_bbr pkcs8_key_parser ntsync(OE) i2c_de= v crypto_user dm_mod loop nfnetlink lz4 zram 842_decompress 842_compress lz= 4hc_compress lz4_compress ip_tables x_tables btrfs libcrc32c crc32c_generic= raid6_pq xor crc32c_intel nvme sha256_ssse3 nvme_core nvme_auth nvidia_drm= (OE) drm_ttm_helper ttm hid_cmedia nvidia_uvm(OE) [ 6.615294] nvidia_modeset(OE) hid_generic mxm_wmi video wmi usbhid nvi= dia(OE) [ 6.615302] CPU: 2 UID: 0 PID: 0 Comm: swapper/2 Tainted: G OE= 6.12.6-2-cachyos #1 c963cd2b82aa9cdd05160d5f7838a69b51110706 [ 6.615307] Tainted: [O]=3DOOT_MODULE, [E]=3DUNSIGNED_MODULE [ 6.615308] Hardware name: System manufacturer System Product Name/ROG S= TRIX X570-E GAMING, BIOS 5013 03/18/2024 [ 6.615310] Sched_ext: lavd (enabling+all) [ 6.615311] RIP: 0010:__schedule+0x1130/0x1c90 [ 6.615314] Code: 90 56 65 94 0f 84 e1 ef ff ff f6 05 4a 78 3d 01 01 0f = 85 d4 ef ff ff c6 05 3d 78 3d 01 01 48 c7 c7 8b a3 cd 93 e8 90 24 0e ff <0f= > 0b 41 8b 86 38 0c 00 00 e9 b3 ef ff ff e8 bd 8c ff ff 65 ff 0d [ 6.615316] RSP: 0018:ffffb23e4019fe28 EFLAGS: 00010046 [ 6.615319] RAX: e9cdb54dc06b0200 RBX: ffffa02e00a93680 RCX: 00000000000= 00027 [ 6.615320] RDX: ffffb23e4019fc90 RSI: 00000000ffffefff RDI: ffffa0350eb= 21948 [ 6.615322] RBP: ffffb23e4019fee0 R08: 0000000000000000 R09: ffffffff946= 5a840 [ 6.615323] R10: 0000000000002ffd R11: 0000000000000004 R12: 00000000000= 00000 [ 6.615325] R13: ffffa02e00a93680 R14: ffffa0350eb366c0 R15: 00000000fff= fffff [ 6.615327] FS: 0000000000000000(0000) GS:ffffa0350eb00000(0000) knlGS:= 0000000000000000 [ 6.615329] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 6.615331] CR2: 00007cb2b7100008 CR3: 000000012222a000 CR4: 0000000000f= 50ef0 [ 6.615333] PKRU: 55555554 [ 6.615334] Call Trace: [ 6.615336] [ 6.615338] ? __warn+0xd5/0x1d0 [ 6.615341] ? __schedule+0x1130/0x1c90 [ 6.615345] ? report_bug+0x144/0x1f0 [ 6.615348] ? __schedule+0x1130/0x1c90 [ 6.615350] ? handle_bug+0x6a/0x90 [ 6.615353] ? exc_invalid_op+0x1a/0x50 [ 6.615356] ? asm_exc_invalid_op+0x1a/0x20 [ 6.615361] ? __schedule+0x1130/0x1c90 [ 6.615363] ? __schedule+0x1130/0x1c90 [ 6.615366] ? pv_native_safe_halt+0x13/0x20 [ 6.615369] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615372] ? ct_kernel_enter+0x2e/0x90 [ 6.615374] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615376] ? local_clock_noinstr+0xc/0xc0 [ 6.615380] schedule_idle+0x23/0x40 [ 6.615382] cpu_startup_entry+0x1c2/0x250 [ 6.615386] start_secondary+0x9e/0xa0 [ 6.615389] common_startup_64+0x13e/0x140 [ 6.615395] [ 6.615396] ---[ end trace 0000000000000000 ]--- [ 6.615398] ------------[ cut here ]------------ [ 6.615401] rq->balance_callback && rq->balance_callback !=3D &balance_p= ush_callback [ 6.615403] WARNING: CPU: 6 PID: 2269 at kernel/sched/sched.h:1730 scx_o= ps_bypass+0x178/0x240 [ 6.615408] Modules linked in: nf_tables vfat fat intel_rapl_msr amd_atl= intel_rapl_common kvm_amd snd_hda_codec_realtek snd_hda_scodec_component k= vm snd_hda_codec_generic crct10dif_pclmul crc32_pclmul polyval_clmulni snd_= hda_intel polyval_generic ghash_clmulni_intel snd_intel_dspcfg eeepc_wmi sn= d_usb_audio snd_intel_sdw_acpi sha512_ssse3 sha1_ssse3 asus_wmi snd_hda_cod= ec aesni_intel snd_usbmidi_lib ee1004 platform_profile gf128mul snd_ump asu= s_ec_sensors snd_hda_core i8042 crypto_simd snd_rawmidi sparse_keymap snd_h= wdep snd_seq_device cryptd serio rapl rfkill snd_pcm wmi_bmof pcspkr k10tem= p snd_timer i2c_piix4 snd i2c_smbus soundcore ccp mc igc mousedev ptp joyde= v pps_core leetmouse(OE) mac_hid tcp_bbr pkcs8_key_parser ntsync(OE) i2c_de= v crypto_user dm_mod loop nfnetlink lz4 zram 842_decompress 842_compress lz= 4hc_compress lz4_compress ip_tables x_tables btrfs libcrc32c crc32c_generic= raid6_pq xor crc32c_intel nvme sha256_ssse3 nvme_core nvme_auth nvidia_drm= (OE) drm_ttm_helper ttm hid_cmedia nvidia_uvm(OE) [ 6.615482] nvidia_modeset(OE) hid_generic mxm_wmi video wmi usbhid nvi= dia(OE) [ 6.615490] CPU: 6 UID: 0 PID: 2269 Comm: scx_lavd Tainted: G W = OE 6.12.6-2-cachyos #1 c963cd2b82aa9cdd05160d5f7838a69b51110706 [ 6.615494] Tainted: [W]=3DWARN, [O]=3DOOT_MODULE, [E]=3DUNSIGNED_MODULE [ 6.615495] Hardware name: System manufacturer System Product Name/ROG S= TRIX X570-E GAMING, BIOS 5013 03/18/2024 [ 6.615497] Sched_ext: lavd (enabling+all), task: runnable_at=3D+0ms [ 6.615498] RIP: 0010:scx_ops_bypass+0x178/0x240 [ 6.615501] Code: eb 42 0f 1f 44 00 00 4c 89 ef e8 c3 fd d1 00 49 ff c4 = e9 5b ff ff ff c6 05 9d dc 0e 02 01 48 c7 c7 8b a3 cd 93 e8 b8 88 df ff <0f= > 0b eb a5 0f 0b 41 8b 85 6c 0a 00 00 eb a9 0f 0b 41 8b 85 6c 0a [ 6.615503] RSP: 0018:ffffb23e619479e8 EFLAGS: 00010046 [ 6.615506] RAX: 3730614603e1d700 RBX: 0000000000000000 RCX: 00000000000= 00027 [ 6.615507] RDX: ffffb23e61947850 RSI: 00000000ffffefff RDI: ffffa0350ed= 21948 [ 6.615509] RBP: ffffa0350eb00000 R08: 0000000000000000 R09: ffffffff946= 5a840 [ 6.615511] R10: 0000000000002ffd R11: 0000000000000004 R12: 00000000000= 00002 [ 6.615512] R13: ffffa0350eb366c0 R14: 0000000000000286 R15: ffffb23e619= 479f0 [ 6.615514] FS: 0000703f64c53880(0000) GS:ffffa0350ed00000(0000) knlGS:= 0000000000000000 [ 6.615516] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 6.615517] CR2: 00005b2a1d0d23d0 CR3: 000000011089a000 CR4: 0000000000f= 50ef0 [ 6.615519] PKRU: 55555554 [ 6.615520] Call Trace: [ 6.615522] [ 6.615524] ? __warn+0xd5/0x1d0 [ 6.615527] ? scx_ops_bypass+0x178/0x240 [ 6.615530] ? report_bug+0x144/0x1f0 [ 6.615533] ? scx_ops_bypass+0x178/0x240 [ 6.615536] ? handle_bug+0x6a/0x90 [ 6.615538] ? exc_invalid_op+0x1a/0x50 [ 6.615541] ? asm_exc_invalid_op+0x1a/0x20 [ 6.615545] ? scx_ops_bypass+0x178/0x240 [ 6.615548] ? scx_ops_bypass+0x178/0x240 [ 6.615551] bpf_scx_reg+0xfb5/0x1380 [ 6.615559] bpf_struct_ops_link_create+0x13c/0x190 [ 6.615563] __sys_bpf+0x765/0x6080 [ 6.615567] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615570] ? syscall_exit_to_user_mode+0x38/0xc0 [ 6.615573] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615578] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615580] ? arch_exit_to_user_mode_prepare.cold+0x5/0x5c [ 6.615583] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615585] ? syscall_exit_to_user_mode+0x38/0xc0 [ 6.615587] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615589] ? do_syscall_64+0x9b/0x170 [ 6.615592] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615594] ? syscall_exit_to_user_mode+0x38/0xc0 [ 6.615596] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615598] ? do_syscall_64+0x9b/0x170 [ 6.615601] ? __se_sys_close.llvm.4416965578177173658+0x6d/0xa0 [ 6.615604] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615606] ? kmem_cache_free.cold+0x138/0x32a [ 6.615610] __x64_sys_bpf+0x1c/0x30 [ 6.615613] do_syscall_64+0x8f/0x170 [ 6.615615] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615617] ? do_syscall_64+0x9b/0x170 [ 6.615621] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615624] ? arch_exit_to_user_mode_prepare.cold+0x5/0x5c [ 6.615626] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615628] ? syscall_exit_to_user_mode+0x38/0xc0 [ 6.615631] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615633] ? do_syscall_64+0x9b/0x170 [ 6.615635] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615637] ? arch_exit_to_user_mode_prepare.cold+0x5/0x5c [ 6.615640] ? srso_alias_return_thunk+0x5/0xfbef5 [ 6.615643] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 6.615645] RIP: 0033:0x703f64e8315d [ 6.615656] Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 = 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48= > 3d 01 f0 ff ff 73 01 c3 48 8b 0d 9b 6b 0d 00 f7 d8 64 89 01 48 [ 6.615658] RSP: 002b:00007ffebaea0a38 EFLAGS: 00000246 ORIG_RAX: 000000= 0000000141 [ 6.615661] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 0000703f64e= 8315d [ 6.615662] RDX: 0000000000000040 RSI: 00007ffebaea0a70 RDI: 00000000000= 0001c [ 6.615664] RBP: 00007ffebaea0b40 R08: 000000000000000f R09: 00000000000= 00000 [ 6.615665] R10: 000000000000000f R11: 0000000000000246 R12: 00000000000= 0000f [ 6.615667] R13: 000000000000002c R14: 0000000000000010 R15: 0000703f650= d8000 [ 6.615671] [ 6.615673] ---[ end trace 0000000000000000 ]--- [ 6.615712] sched_ext: BPF scheduler "lavd" enabled [ 6.623157] sched_ext: kworker/1:0[29] has zero slice in pick_task_scx() =3D=3D=3D=3D=3D END =3D=3D=3D=3D=3D Signed-off-by: Changwoo Min --- kernel/sched/ext.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 8fe64c27004e..cb6eb49d16be 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -4803,10 +4803,9 @@ static void scx_ops_bypass(bool bypass) */ for_each_possible_cpu(cpu) { struct rq *rq =3D cpu_rq(cpu); - struct rq_flags rf; struct task_struct *p, *n; =20 - rq_lock(rq, &rf); + raw_spin_rq_lock(rq); =20 if (bypass) { WARN_ON_ONCE(rq->scx.flags & SCX_RQ_BYPASSING); @@ -4822,7 +4821,7 @@ static void scx_ops_bypass(bool bypass) * sees scx_rq_bypassing() before moving tasks to SCX. */ if (!scx_enabled()) { - rq_unlock(rq, &rf); + raw_spin_rq_unlock(rq); continue; } =20 @@ -4842,10 +4841,11 @@ static void scx_ops_bypass(bool bypass) sched_enq_and_set_task(&ctx); } =20 - rq_unlock(rq, &rf); - /* resched to restore ticks and idle state */ - resched_cpu(cpu); + if (cpu_online(cpu) || cpu =3D=3D smp_processor_id()) + resched_curr(rq); + + raw_spin_rq_unlock(rq); } =20 atomic_dec(&scx_ops_breather_depth); --=20 2.47.1