From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 A7C47318EFA for ; Tue, 3 Feb 2026 11:41:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770118893; cv=none; b=s2V3j5TiG0VVn1o62Q5XQa2u0JQMSOfgZXfIsaIdQB5Czi58xhlHVeVl9NrAv5QibObT8HjoUj9pS2dQQB0i3QRCnptkwgCAdZ5Xu71AsyFTPixaw8Qzy9go6V7tqExTRavpFehHY/30ISMf3z88sVnC2LbrYsDKfaufD6JmzIY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770118893; c=relaxed/simple; bh=OnOqQ7zGtU1F8PYO5hDacXXOIbXvG8vx3iFiBcA6zPM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=GVkCIlYnjs55R0BdlyCDm82DFTj/NFkiT312b+gDliMjYBa0SOppPxgxqhNGPGIlqbD+/ad8pSNIlBYhAnqqFykX7Sx00mtN7pViJh8RERZ0RisaTLRvqNkJeJuruL7yhCDZ5nvXvB9WBmUjgoKXCPaESZ3Tfxq4iWpLm68EjLs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=UPFLi+XQ; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=bwLzhcDa; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UPFLi+XQ"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="bwLzhcDa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770118890; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7LSei9XQMCIZvXF7U7iOMHf2h9cD0XujsB63tiFmLxs=; b=UPFLi+XQlCCeUjY/FP/SY9T+wggV8igxr4ledstWpKr9p0Iic8jsrz6YDUnqBZtZqdoFkU maiYZBpOTMTqBkiXFAOyW2HvBrrwHulQ5V4gV5/GvwewKSFJXuvYJ7ThSJVH+d6uuz6u43 JqUtF3wl4Ol40CloPnusuMIdxDuxPJk= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-534-F810rcgGP3qonLIEDWLDGw-1; Tue, 03 Feb 2026 06:41:29 -0500 X-MC-Unique: F810rcgGP3qonLIEDWLDGw-1 X-Mimecast-MFC-AGG-ID: F810rcgGP3qonLIEDWLDGw_1770118888 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-65932e533daso833580a12.3 for ; Tue, 03 Feb 2026 03:41:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770118888; x=1770723688; 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=7LSei9XQMCIZvXF7U7iOMHf2h9cD0XujsB63tiFmLxs=; b=bwLzhcDaegAdHlHMddcLaUKCbhwWuFVYyzu2424LkGDRaQ2FYuRPJ67nUBPBESP1w/ zaah0huj2ad7G38WldxuA9RASTB6FnD+dj+qQoUr2Zubuj89Taa4/Kf1R4o06i9PU3p7 7ZLugiwxusn5zGQOogvl08kHQmL9u8IwdLB4gxpP4PKZAOBK88gaPomtrA93dMT+lrSU G5FR0mRjvtodzyvMZ3yLiG9fC3uT2tl+2MnypHOVvQP29t+jMIYNtV3MFoCHDs6DgO07 VmVYOZIu+FcTtyFbk+piOoThv7FIQ8xj7EOMQTwrm0DUzK8Lm9PGXo1CyulEANQ352tW xsZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770118888; x=1770723688; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7LSei9XQMCIZvXF7U7iOMHf2h9cD0XujsB63tiFmLxs=; b=rfWzscR6KM0d45MgqwOaxfGUs5svNU6JNxk0cPlZ/EzfomBbRjgKLk5A34oLPGiXx/ St7alrrn8sRyxRMs8t9UZLZqWEo33VZ0oL+kJfdsHPuEfdPyChjxjir5K0AYhU0FXH4p Unx0fmnHGrWqv2UmE3z2RtSwcgnTv6n2zqQ6aJeVjYKRqfWf3yqfvBxxLG5yYZ9pTTH9 FvP76NaVPrUYmLgVUIJKhUQjNaEhQ+AH+qTm36bA5k8tJnWAVrzUOHP1C8NZdO9tlfeu /8qA/PUMR2zwKOfPZVTgC/Bs3cQFdD3d9es2lC1mNnHV68pGfhA8UvCWl+aDT6DIUSvH TTPA== X-Forwarded-Encrypted: i=1; AJvYcCXRwlERzVjViC4P4vWFbZDdCa5UmkKjhrXGRU+9GRVLwo5gqEBzbQCbeWuPu8zONOliZuoaFm5ya7jCp3o=@vger.kernel.org X-Gm-Message-State: AOJu0YzIvWLbxSyPmV1WY7qssx+tI5lsGYjwDAWIIIRqJ3ZDURRIkhvV XiSkJ9WEp/t2pk9QaUsAVPPTb0CmvwEkSKtL/a91/hsupcDdQ3DsA+Lmt6qAwrnghsYLRwstRiH SivuZz1GgzrqxeQcBZcyCHHi4H05gJ9S2eGdOlxsR2qUI3LcIVuHaACXugox+7mUe+w== X-Gm-Gg: AZuq6aLv0d/DBHPDJgB2bBUmVIYQzfSvwm6wgVkDUe65Pxvf/Zn4iYXP6AGuUu9Nm0f yw39+9IFtC9NsElw0vt+l5MI2QopsrbeaDQYbxwCzRj/QY9Z11BsIX53LFk4xdtGPYrynezIT/d nnoZ9pjkQyV3Ube/uML8DVhdGvq4sanUC48ma0edDriMw8TjN5OgBzhCQ4rtdsY9Gh+l6I6MrOF BJqgsfc98vWI3262IB1CDwVhEHfruaMbBl3S8f924BhkM5fjWU4Oth+KLu5sBcIC3PpUVLJlSW5 yIvXQXxxmr24hHxXm2PE20sYi0xEG8ZpzcpuXTnZ4NBB046G75Lr2aMxryvVU1kw1vAXWyYzKaO Dm/kfiaoMlW8= X-Received: by 2002:a05:6402:42c9:b0:649:64d3:1554 with SMTP id 4fb4d7f45d1cf-658de57433emr9791563a12.15.1770118888082; Tue, 03 Feb 2026 03:41:28 -0800 (PST) X-Received: by 2002:a05:6402:42c9:b0:649:64d3:1554 with SMTP id 4fb4d7f45d1cf-658de57433emr9791546a12.15.1770118887634; Tue, 03 Feb 2026 03:41:27 -0800 (PST) Received: from [192.168.88.32] ([150.228.93.21]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-658b44527eesm9043949a12.9.2026.02.03.03.41.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Feb 2026 03:41:26 -0800 (PST) Message-ID: Date: Tue, 3 Feb 2026 12:41:21 +0100 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 v2] net: mscc: ocelot: add missing lock protection in ocelot_port_xmit() To: Ziyi Guo , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com Cc: Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260131044911.2257072-1-n7l8m4@u.northwestern.edu> Content-Language: en-US From: Paolo Abeni In-Reply-To: <20260131044911.2257072-1-n7l8m4@u.northwestern.edu> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 1/31/26 5:49 AM, Ziyi Guo wrote: > ocelot_port_xmit() calls ocelot_can_inject() and ocelot_port_inject_frame() > without holding ocelot->inj_lock. However, both functions have > lockdep_assert_held(&ocelot->inj_lock) indicating that callers must hold > this lock. > > The correct caller felix_port_deferred_xmit() properly acquires the lock > using ocelot_lock_inj_grp() before calling these functions. > > Add ocelot_lock_inj_grp()/ocelot_unlock_inj_grp() around the injection > code path in ocelot_port_xmit() to fix the missing lock protection. > > Fixes: c5e12ac3beb0 ("net: mscc: ocelot: serialize access to the injection/extraction groups") > Signed-off-by: Ziyi Guo > --- > v2: > - Add missing Fixes tag > > drivers/net/ethernet/mscc/ocelot_net.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c > index 469784d3a1a6..da8579abea1e 100644 > --- a/drivers/net/ethernet/mscc/ocelot_net.c > +++ b/drivers/net/ethernet/mscc/ocelot_net.c > @@ -559,15 +559,22 @@ static netdev_tx_t ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev) > int port = priv->port.index; > u32 rew_op = 0; > > - if (!static_branch_unlikely(&ocelot_fdma_enabled) && > - !ocelot_can_inject(ocelot, 0)) > - return NETDEV_TX_BUSY; > + if (!static_branch_unlikely(&ocelot_fdma_enabled)) { > + ocelot_lock_inj_grp(ocelot, 0); > + > + if (!ocelot_can_inject(ocelot, 0)) { > + ocelot_unlock_inj_grp(ocelot, 0); > + return NETDEV_TX_BUSY; > + } > + } > > /* Check if timestamping is needed */ > if (ocelot->ptp && (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) { > struct sk_buff *clone = NULL; > > if (ocelot_port_txtstamp_request(ocelot, port, skb, &clone)) { > + if (!static_branch_unlikely(&ocelot_fdma_enabled)) > + ocelot_unlock_inj_grp(ocelot, 0); I'm under the impression this static_branch_unlikely() usage is racy, i.e. on CONFIG_PREEMPT kernel execution could enter this branch but not the paired lock. What about moving the 'Check timestamp' block in a separate helper and use a single static_branch_unlikely() branch? something alike the following, completely untested and unfinished: if (!static_branch_unlikely(&ocelot_fdma_enabled)) { int ret = NETDEV_TX_OK; ocelot_lock_inj_grp(ocelot, 0); if (!ocelot_can_inject(ocelot, 0)) { ret = NETDEV_TX_BUSY; goto unlock; } if (!ocelot_timestamp_check()) goto unlock; ocelot_port_inject_frame(ocelot, port, 0, rew_op, skb); consume_skb(skb); unlock: ocelot_unlock_inj_grp(ocelot, 0); return ret; } if (!ocelot_timestamp_check()) return NETDEV_TX_OK; ocelot_fdma_inject_frame(ocelot, port, rew_op, skb, dev); return NETDEV_TX_OK; Well, after scratching the above, I noted it would probably better to invert the two branches... /P