From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 82CBF385D7C for ; Fri, 7 Aug 2026 14:27:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786112853; cv=none; b=hgNt9dHqTu9YXndrUQLA6yDBJ/BLJFlGCwXAO745fpngCoAYjnCGvOQEV3FftFjMZe8HgvYujc7aCNiJLq6E1jIChzP5ITZ6OtOw8B7aaxziei1NSgQrS7OxpylYc8MkEViXsyU0xIxrhfbucMWNYCfoThOnY4LjlbyHjhkfILU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786112853; c=relaxed/simple; bh=tJ6YIoKNUDojeg86gqnCuw1WTPa7k4m9/MpBN2CPG+0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Doj4zaZSY61W7ky7dy7/2tC5eyybhjLz0MhRjQYX+tX94HY3jYQStjMyCQ80kLl5RZHQZKwTpwlP8+aZPgREiD5XQmUzCoBY5cg5ZModF/asVHAsL1xaFv6IuwElL+WcgL/v0n7z9ywnLM0siHNwBhEyNGxKc0hWLprzBdb0Vn0= 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=BQbqc2jZ; arc=none smtp.client-ip=209.85.215.180 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="BQbqc2jZ" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-c966b9ee9cbso2332353a12.1 for ; Fri, 07 Aug 2026 07:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786112850; x=1786717650; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=dY6T8KLKe7c50VCzbw04TgHR78SFTtnFy4T2vHFIKTs=; b=BQbqc2jZvfZL+tgjDrZGUNXRoSQDjlvLCKTmrNYmIPTIzs7SEuIxMINYi/dNAPagrh qwP5jS/UsbQyPCf6ocQ6TtTEwHQDo+YGagEJxvO6r0vy+UWHBFxoLG1ivYmkMOL69wXo BUsr6yrzdc5VPdDxtzYOf9jwcep9cNibfMw26Z6U0ypmMcbvI/FTk7RVRIdQOafX9CMD g5iiiPTU5xtz+cwbQ69oC+sW9lXMmingA94DguRfi0Um5YH12uQxu2wFNhX4ZUilWUzE QK+aNFtgkqifGFgd/TMmJnanV/km9nDQmJeb7Bg3ZMJU/dpyrr2U+VeqRzyvwhBbzEgb gFzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786112850; x=1786717650; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=dY6T8KLKe7c50VCzbw04TgHR78SFTtnFy4T2vHFIKTs=; b=rRb2Yokc5qd+cjWpiKQHQvtgCVajpvjYaXCBwSDwde/Qha3sVwi1uH9YU7UaeXVKqE bttSY32FUjet1ga/caciP8BqMMFnR9BjEhltiuYMSWgJAydIgxIv8YyrA+Pr3SBfYF4f rdV1in0uKy4DdLCQrB9GG/BtIuwwa5XyiRfFJFcbT80hS3jqtN7mReRDZlOwMSMbkSMF AsT9WIylIy/D9ENYGfr6ePj9Yq2FDD7jkqPPvLznDmkW53B1zfo/gVNKVr1CSToTEZ1j qsc2YX7OPg6j0CrDO8uvgQ5ZQ9G5YqWFMSKIWmkT7a5YT4APaqhZm+n4ApZVFhkxuBtq pDWQ== X-Forwarded-Encrypted: i=1; AHgh+RpV8L5wkKilmVN1aEcNUfgRaGC5QxWou48wjif1DEqzJn8yHrgDrbHwMSvlXS8LwqgSdlKEiIsPv2XL0Sc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+R1JtzDl0pF831vPqCj+VmOxYd3B1TRgrxXx3HGin1zXDu8vl j6/jw4j0AUrK/gwAoth5355Z9MJGmND4BmRTPMTdeOlIwRyvf9UdCRyy X-Gm-Gg: AR+sD10C4JCMDURFlROJLc1HQqjXPdDVMtn+fpqX021DT/6Y4ryJdL31f2UbksxFeXE ZsWIgyCG0oE9rwfrgDcg+ViGUiOwpA+Q+rbVYvpCBt6pziw4IbG6jBgDdlSKNkpwm8qNwB0irGb NM516dscHEK9hwtHQTW+dnvaPNG6ymkGRgiqURfRR7i7dJzCuJvVJTTLU7UYGjUSi/tLaMcK+7O Ckn0mBGpQOlUc03NkEqgAzMeiI/kfMWfgtyGjHqL86vAcPyrIkS3oVVwXiqLfPT/q/SaqWQI4sm RAgAG73hqVECuHdfNZGzrTMIz8HfbEnKbNY5AnIIi6GDjWvDHCvLnr9muf6+cq0N7cTgeSZPHth qYRqIZ7uuSQGS3IbD7+ke3sbadgYUAcK49qG/Pnp08n0jJHqSvFV3s/GfSWIghRh0ABhXJrt32f j3j8YoSN1yFG2fajZcwOfGYLsDHBh2+H4j1UJinLRoYlHsRp/Iba3W5Z0= X-Received: by 2002:a05:6a00:1705:b0:82f:38df:681c with SMTP id d2e1a72fcca58-84f2e0228e1mr21662231b3a.6.1786112849746; Fri, 07 Aug 2026 07:27:29 -0700 (PDT) Received: from fedora ([203.175.12.242]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84f5a553071sm1125866b3a.43.2026.08.07.07.27.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Aug 2026 07:27:28 -0700 (PDT) Date: Fri, 7 Aug 2026 22:27:19 +0800 From: Hangbin Liu To: Xin Xie Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, andrew+netdev@lunn.ch, shuah@kernel.org, kees@kernel.org, petr.wozniak@gmail.com, qingfang.deng@linux.dev, fmaurer@redhat.com, luka.gejak@linux.dev, bigeasy@linutronix.de, xiaoliang.yang_1@nxp.com, skhawaja@google.com, stable@vger.kernel.org, sdf.kernel@gmail.com Subject: Re: [PATCH net v4 2/4] net: hsr: shrink seqnr_lock to sequence counter updates Message-ID: References: <20260803222211.877-1-xiexinet@gmail.com> <20260803222211.877-3-xiexinet@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260803222211.877-3-xiexinet@gmail.com> Hi Xie Xin, On Tue, Aug 04, 2026 at 12:22:09AM +0200, Xin Xie wrote: > hsr->seqnr_lock is currently held across entire hsr_forward_skb() > calls: master TX (hsr_dev_xmit()), interlink RX (hsr_handle_frame()), > and both supervision frame builders hold it while frames are built, > classified, duplicated and forwarded on every port. The only state > that actually needs the lock is the sequence counters themselves > (hsr->sequence_nr / hsr->sup_sequence_nr). > > Shrink the locking to the individual counter updates: > handle_std_frame() now takes the lock around its sequence number > allocation (replacing the lockdep assertion), the master TX and > interlink RX paths drop their outer lock, and the supervision > builders release the lock right after updating their counter instead > of holding it across frame construction and forwarding. > > Statistics: the outer seqnr_lock also incidentally serialized the > tx_packets/tx_bytes/tx_dropped updates in hsr_forward_skb(), which are > reachable from the concurrently callable master-TX, supervision and > interlink-RX paths. Those updates now use DEV_STATS_INC()/ > DEV_STATS_ADD(), the atomic legacy-stat helpers, so narrowing the lock > does not turn them into lossy plain read-modify-writes. > > Ordering: with IFF_NO_QUEUE and dev->lltx, hsr_dev_xmit() is > concurrently callable, and this change removes the old > allocation-through-forward ordering guarantee there: master-TX frames > may now be emitted out of sequence-allocation order. On the current > tree this is safe because duplicate discard tracks individual > sequence numbers in sparse bitmaps (commit aae9d6b616b5 ("hsr: > Implement more robust duplicate discard for HSR") and > commit 415e6367512b ("hsr: Implement more robust duplicate discard > for PRP")) rather than requiring monotonic arrival. Sequence numbers > remain unique and monotonically allocated per counter. > > This is a latency/critical-section prerequisite for unfolding GSO > super-packets at the forward entry (not a functional prerequisite): > the segmentation work should not extend the global sequence lock's > critical section. Patch 3 depends on this change; their automatic > stable selection is limited to 7.0 and newer, where sparse-bitmap > duplicate discard accepts out-of-order arrival. Older stable branches > require an adapted backport. > > History of the lock being narrowed: it was introduced by > commit 06afd2c31d33 ("hsr: Synchronize sending frames to have always > incremented outgoing seq nr.") and briefly removed by > commit b3c9e65eb227 ("net: hsr: remove seqnr_lock") in net. Merge > commit 46ae4d0a4897 ("Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net") > reverted that removal because > commit 430d67bdcb04 ("net: hsr: Use the seqnr lock for frames > received via interlink port.") in net-next had already superseded it > by adding locking for the interlink RX path. All sequence counter > updates remain protected; only the forwarding work moves out of the > critical section. > > Cc: # 7.0.x > Signed-off-by: Xin Xie Maybe use a shorter commit description. [ ... ] > @@ -746,8 +747,8 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port) > * So check and increment stats for master port only here. > */ > if (port->type == HSR_PT_MASTER || port->type == HSR_PT_INTERLINK) { > - port->dev->stats.tx_packets++; > - port->dev->stats.tx_bytes += skb->len; > + DEV_STATS_INC(port->dev, tx_packets); > + DEV_STATS_ADD(port->dev, tx_bytes, skb->len); Note: Avoid these macros in fast path, prefer per-cpu or per-queue counters. And the counters in hsr_deliver_master() also need to protected. Especially multicast. Thanks Hangbin