From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 B9B5B2E6114 for ; Fri, 22 Aug 2025 07:26:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755847607; cv=none; b=WMzyC1AEYQCpEYbAHyz3s8hGX2VGopW2NY8plQlhBBXVyKdLLNT3H+Oh2S2wdfZEN/POJvFu9E345NU2w94eVh7XmvXOvVPSGujEt0Lykj+DnIzjv0RJSy/2Yds4TCxqokjMDwInHZ9BDnO3S3a797uax8L5ZIZj+v2YMLUqNW0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755847607; c=relaxed/simple; bh=/YzDiNUs0MNdPN24taJl6Bj7ZP9vE4B0C45SZtCHV7E=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Rlucnemk21Wpy5Wh2QeaSI4Cp6KxyIqVps7D4CSKkSTlV/JCyFQmZnCNBKaZDH9AkuD0KxMKbnVHETdQ7AfbpBKqnfyxnY90IDdYffLtFk74PpujuY4+x8xF02knBwDgjNiWgP+X3kdHaEk1U6VGWKBdV7gMCXqhPk3x5LK4m3U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=blackwall.org; spf=none smtp.mailfrom=blackwall.org; dkim=pass (2048-bit key) header.d=blackwall.org header.i=@blackwall.org header.b=O8Y5inc9; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=blackwall.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=blackwall.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blackwall.org header.i=@blackwall.org header.b="O8Y5inc9" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-619487c8865so4999550a12.1 for ; Fri, 22 Aug 2025 00:26:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall.org; s=google; t=1755847604; x=1756452404; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=YkCBHqC6hkeu3pks9cF863PKhddTjTOP8QecN7y7a1I=; b=O8Y5inc9Y9Cufnp7ah9Sg8j3JzztwhZkgo9DrNv/QEJyuTk4wnSsmQEhaqyXMe2waY Eww4ycA47p981fUoegZCkbifj9u96SFO2H/HumZxtIw8PVHNjMhh1jukzHg/weteyoCr lgOj8YoKNqrTxGWFfEO4yQqTxAtsx5z6wsS8yXOpQl1KV7jlXxrxpFsG/TLjCB1kyusi coRN+AGXwUatmUJWEvsA7Brt4hVm6FStahek97zhy1/OO6/oG+n6FU8YplB6ReDSirGA xF2KCiufZtrQMsD5UtOnEj9kHkwzVEajVre9M9CpspvYr3QHYPOY/I3YY9/pFEwiUvVe YxKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755847604; x=1756452404; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YkCBHqC6hkeu3pks9cF863PKhddTjTOP8QecN7y7a1I=; b=ewC7sXSMbQekihGJRjhwfCKFUn+x4fyfiEj2Zyw6WeA+BMKXDAUsVjVZzaajHeSVjK ITH5XHbLBEZHyvkvRAnkniITNAqXuVRipy+99vDVk5zlHen4pXtPvNGrTlptbLPiKsdT MteWI/AOcTyxTuh/0rn4wETVAMWUEFVXS/2cnmiOtr4ccp2VqvgsUDPqRVMJtN53TYWk arSqUCkM9prRUTsuD4SZUMBrx6u6rEvYz1FavK62dFXWmjF/njtXzQ32Ula6crp4rI81 w8x1x7elxt9nkR/be43P90LuITNDD3ewzfOgl6SEtdQg8DyusDbdrilSV3NtC6je41lE bpyg== X-Gm-Message-State: AOJu0YymNFaftQ/SE5qJsaGH0gHVmWxVTgMip2KJOYcZUmXOMUnrfhFv icis7IRSFFK+8FSfjI0eM6n1MWV96VWzGWkIxcxxNooMYkfRwduFZWDwuHq4xrgRWas= X-Gm-Gg: ASbGnctXah9qbPe9H8J1ZTefSWKoAsHW8EpPS7TG4wIkwAANqi08AhaAmTiU86yrTQA GeycBi+jXKsj84wlRut9rXIF1DILKQBaSlDxwz/HQWM058akR19GXQAXpaAmHIyY+2i+LgJHVq1 /auM6BO2yinteKl7dOZSKZN4mGItNVnApKNkOEFuHAV12p0wGPEifeeqLXAw4brPOQ5ow+nkQDo Zhu/X3ytT4DXKbNNjYu6G5IBtKkqKI4kRCdDyZqJqkr9PQNHWwQ3X0DAn+C2kkdtkQnXH1LMvQX pcu+Wp3UOEIzaZf8HUufQ8+xKbB0cMA5In/gf3IpOKsg3NmqxRFYTUYxC9Vv8kadbuMJLEOgt5q klmyq1pZypwr6/eJqxU2j73OnLlhZALmrpnp5Rc/c3zPhaPVXZhXYJQ== X-Google-Smtp-Source: AGHT+IHGfZ8P7tgu80xMWCg8ePf2z7xgt63VR2ssnLjdHjM9Fx5i6pO37IMRM0WOjccKlN04n6re1A== X-Received: by 2002:a17:906:3689:b0:afe:2ef3:8358 with SMTP id a640c23a62f3a-afe2ef387eemr107664466b.22.1755847603725; Fri, 22 Aug 2025 00:26:43 -0700 (PDT) Received: from [192.168.0.205] (78-154-15-142.ip.btc-net.bg. [78.154.15.142]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-afded5353cdsm550935966b.106.2025.08.22.00.26.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Aug 2025 00:26:43 -0700 (PDT) Message-ID: <87303e90-3c74-4e4f-8fac-2001d82b90d8@blackwall.org> Date: Fri, 22 Aug 2025 10:26:41 +0300 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] 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, daniel@iogearbox.net, bigeasy@linutronix.de, tgraf@suug.ch, paulmck@kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org References: <20250822064200.38149-1-laoar.shao@gmail.com> Content-Language: en-US From: Nikolay Aleksandrov In-Reply-To: <20250822064200.38149-1-laoar.shao@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 8/22/25 09:42, 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. > nit: you are no longer using in_softirq() in v2, you should update the commit message as well. [snip] Cheers, Nik