From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from www62.your-server.de (www62.your-server.de [213.133.104.62]) (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 6E844305053; Tue, 19 Aug 2025 12:42:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.133.104.62 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755607335; cv=none; b=fHNHbMYv9vgr3wS1R8ydgOll8c2B1bj+wrBdU3TJwYFueP42bMUdA2Drx0V2K1dTKNGvIoJfAa2J0vy2CE17FUgS3O3C7s/r55ix/1wUChAaZImjcjrq/3DJzQ2aHS/DaR31QOf0pYmr+CcynSoSvqPObAM+NPCpAbsoIS+qig4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755607335; c=relaxed/simple; bh=5YmId6TaJSXxbQAcmBKh+QzUHZdg3v1E8gFElkn2tlc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=oRdf+EwA4i4wUZCQ1KL5BM3NZet0tCTSBwjMagEjEKF0FSraS5vfw1deSowoB0Uu70wncKvoP4iG4W3BFQiOogeGuor8dcW5cxgWa9w2vSZV+EWBMCsjClto8qgR9307FMhKRmrZ7jUBRqKLBcuOAuH9GIlWNCSN/DilYpVI9yU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iogearbox.net; spf=pass smtp.mailfrom=iogearbox.net; dkim=pass (2048-bit key) header.d=iogearbox.net header.i=@iogearbox.net header.b=gDEdXieo; arc=none smtp.client-ip=213.133.104.62 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=iogearbox.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iogearbox.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iogearbox.net header.i=@iogearbox.net header.b="gDEdXieo" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=iogearbox.net; s=default2302; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=mQNnN16mIYhaXp4sreQmcdqv7Ohu0QtrzdbShxrwIUE=; b=gDEdXieo2XHmZfvDDMXPiJzmO8 se3oLVyBUlfyC40YGD5hE7JPOA+9nlwDd/AdA7ugCZK1h87RLw4yoXiPhFT+2x5eVMC0UB038ZgSo q4BLS1komBZdCEISFDsOPxh81J6ASvsAlskPq1zFnLpNQv+iHdBydJvgntohpMnaz50E4GEJJnoam WXmHYKJ9m2MJK2SnW0tKUilQykbLACJKKOiC654Ck2YFY25iv/WykgXE1xLqKokClBxYS/puuokXC zthd87qoD8miGYBA+HIY5gKqQK5RtOnTlxZgLtKrtF8Aasor40N1COFNk7QPAlI/q/VmnfAYKgcOz GT73mfWA==; Received: from sslproxy06.your-server.de ([78.46.172.3]) by www62.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1uoLfF-0009Xt-10; Tue, 19 Aug 2025 14:42:09 +0200 Received: from localhost ([127.0.0.1]) by sslproxy06.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uoLfE-000KJH-14; Tue, 19 Aug 2025 14:42:08 +0200 Message-ID: <7d2f3767-64c5-4efa-862b-f463751a03bb@iogearbox.net> Date: Tue, 19 Aug 2025 14:42:07 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] net/cls_cgroup: Fix task_get_classid() during qdisc run To: Yafang Shao , davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Graf , Paul McKenney , Sebastian Andrzej Siewior , "open list:BPF [RINGBUF]" , Willem de Bruijn References: <20250819093737.60688-1-laoar.shao@gmail.com> Content-Language: en-US From: Daniel Borkmann Autocrypt: addr=daniel@iogearbox.net; keydata= xsFNBGNAkI0BEADiPFmKwpD3+vG5nsOznvJgrxUPJhFE46hARXWYbCxLxpbf2nehmtgnYpAN 2HY+OJmdspBntWzGX8lnXF6eFUYLOoQpugoJHbehn9c0Dcictj8tc28MGMzxh4aK02H99KA8 VaRBIDhmR7NJxLWAg9PgneTFzl2lRnycv8vSzj35L+W6XT7wDKoV4KtMr3Szu3g68OBbp1TV HbJH8qe2rl2QKOkysTFRXgpu/haWGs1BPpzKH/ua59+lVQt3ZupePpmzBEkevJK3iwR95TYF 06Ltpw9ArW/g3KF0kFUQkGXYXe/icyzHrH1Yxqar/hsJhYImqoGRSKs1VLA5WkRI6KebfpJ+ RK7Jxrt02AxZkivjAdIifFvarPPu0ydxxDAmgCq5mYJ5I/+BY0DdCAaZezKQvKw+RUEvXmbL 94IfAwTFA1RAAuZw3Rz5SNVz7p4FzD54G4pWr3mUv7l6dV7W5DnnuohG1x6qCp+/3O619R26 1a7Zh2HlrcNZfUmUUcpaRPP7sPkBBLhJfqjUzc2oHRNpK/1mQ/+mD9CjVFNz9OAGD0xFzNUo yOFu/N8EQfYD9lwntxM0dl+QPjYsH81H6zw6ofq+jVKcEMI/JAgFMU0EnxrtQKH7WXxhO4hx 3DFM7Ui90hbExlFrXELyl/ahlll8gfrXY2cevtQsoJDvQLbv7QARAQABzSZEYW5pZWwgQm9y a21hbm4gPGRhbmllbEBpb2dlYXJib3gubmV0PsLBkQQTAQoAOxYhBCrUdtCTcZyapV2h+93z cY/jfzlXBQJjQJCNAhsDBQkHhM4ACAsJ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GL9YyEHpS7MGPb3jSLzucMAFXgoI8rVqoq6si2sxr2l0VsNH5o3NgoAgJNIg= In-Reply-To: <20250819093737.60688-1-laoar.shao@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Clear (ClamAV 1.0.7/27737/Tue Aug 19 10:27:27 2025) On 8/19/25 11:37 AM, Yafang Shao wrote: > During recent testing with the netem qdisc to inject delays into TCP > traffic, we observed that our CLS BPF program failed to function correctly > due to incorrect classid retrieval from task_get_classid(). The issue > manifests in the following call stack: > > bpf_get_cgroup_classid+5 > cls_bpf_classify+507 > __tcf_classify+90 > tcf_classify+217 > __dev_queue_xmit+798 > bond_dev_queue_xmit+43 > __bond_start_xmit+211 > bond_start_xmit+70 > dev_hard_start_xmit+142 > sch_direct_xmit+161 > __qdisc_run+102 <<<<< Issue location > __dev_xmit_skb+1015 > __dev_queue_xmit+637 > neigh_hh_output+159 > ip_finish_output2+461 > __ip_finish_output+183 > ip_finish_output+41 > ip_output+120 > ip_local_out+94 > __ip_queue_xmit+394 > ip_queue_xmit+21 > __tcp_transmit_skb+2169 > tcp_write_xmit+959 > __tcp_push_pending_frames+55 > tcp_push+264 > tcp_sendmsg_locked+661 > tcp_sendmsg+45 > inet_sendmsg+67 > sock_sendmsg+98 > sock_write_iter+147 > vfs_write+786 > ksys_write+181 > __x64_sys_write+25 > do_syscall_64+56 > entry_SYSCALL_64_after_hwframe+100 > > The problem occurs when multiple tasks share a single qdisc. In such cases, > __qdisc_run() may transmit skbs created by different tasks. Consequently, > task_get_classid() retrieves an incorrect classid since it references the > current task's context rather than the skb's originating task. > > Given that dev_queue_xmit() always executes with bh disabled, we can safely > use in_softirq() instead of in_serving_softirq() to properly identify the > softirq context and obtain the correct classid. > > Signed-off-by: Yafang Shao > Cc: Daniel Borkmann > Cc: Thomas Graf > --- > include/net/cls_cgroup.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/net/cls_cgroup.h b/include/net/cls_cgroup.h > index 7e78e7d6f015..fc9e0617a73c 100644 > --- a/include/net/cls_cgroup.h > +++ b/include/net/cls_cgroup.h > @@ -63,7 +63,7 @@ static inline u32 task_get_classid(const struct sk_buff *skb) > * calls by looking at the number of nested bh disable calls because > * softirqs always disables bh. > */ > - if (in_serving_softirq()) { > + if (in_softirq()) { > struct sock *sk = skb_to_full_sk(skb); > > /* If there is an sock_cgroup_classid we'll use that. */ Hm, essentially you only want to use the fallback method of retrieving cgroup from the socket when the dev_queue_xmit() was triggered via ksoftirqd, rather than from a process via syscall all the way into dev_queue_xmit(). It gets more fuzzy presumably when skbs are queued somewhere and then some other kthread calls the dev_queue_xmit(). Looking at in_softirq(), the comment says "the following macros are deprecated and should not be used in new code", see commit 15115830c887 ("preempt: Cleanup the macro maze a bit"). Maybe Sebastian or Paul has input on whether in_softirq() is still supposed to be used. Side question, did you investigate where the skb->sk association got orphaned somewhere along the way? Thanks, Daniel