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.129.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 8C54A386C0F for ; Thu, 7 May 2026 14:09:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778162956; cv=none; b=r3TfSTA3zEupppZQNt7OTlDpl7OMQboEhfcVTG9/oYTDNcx+ylk7A8ApomnGN0XJT08QJLtmsyOkNgtt4Bodcy8eFGjTJ6Y+y76o4pDYgHMIk+Tyg5xTdIOuF3HuqSxMgTk2rDnmS3uKT+4lSuhgRuTLGjBJ2sy4mgdf+zltYA4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778162956; c=relaxed/simple; bh=V0H+uFjPvZq71PDhJj6Mg13maJnYoEVsPn9f5ZUOJ8w=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=KjH1TXW+DlGqEEQkDTdbuxXz9iLcnbNSYMX/Gbiva6O7K5YkE7mgiFppwvu39bs+HEXDm3wCDJRWMdwDJqb7LJVvhuc0IZ8q5wBeZRa23hEu5xCFRxutNro4wUNSH1RCMFUKLAqDy7O+yEQHRR9B8EBWb5Fwyj4fyfqo+XkM3f8= 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=U/H1K2W+; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=jZvhCvgw; arc=none smtp.client-ip=170.10.129.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="U/H1K2W+"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="jZvhCvgw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778162953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w2nhovRvFw1+XQcDcRJ+2hvlsNXDoa4sYKL7qfbTHmc=; b=U/H1K2W+K4vpF3S+C2HtMZdv1ayGKhEEAMsb7pgJN7PU/qbBGqkkZLqyWy5bNCfjR1ux5j 63bOKXfnuB5XXJCepB8nRgeF+wryuuVDFQx+FbiFiz7Yj2PcNQ57uEIvcsz5qtNP/afm3+ yA7A1he7idE7oTERmlkIigdKzX1rlSA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-127-tpz7l0jyO4O7msl2MX2GbA-1; Thu, 07 May 2026 10:08:42 -0400 X-MC-Unique: tpz7l0jyO4O7msl2MX2GbA-1 X-Mimecast-MFC-AGG-ID: tpz7l0jyO4O7msl2MX2GbA_1778162919 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-44d83e45febso1692731f8f.0 for ; Thu, 07 May 2026 07:08:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778162919; x=1778767719; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=w2nhovRvFw1+XQcDcRJ+2hvlsNXDoa4sYKL7qfbTHmc=; b=jZvhCvgw2H9F591bEDoKNQ+lHBu41wFBvJS7JIXu+bum4Sk8wyr9tIK/VqvsmaTuws GHyJ4w4HRh+isLc3NVYIETOn7Hzuz/i42ivTPcHKmdJdWddBDiRhs9GEPAJOrJ/U98Op YUsGdAe75O2U5VSamzawPhkVk971rVeeE0o4tw8OdpjbfOaBhcP06RT32GyILc8Y+9rU HSOGjh9heO4byR0Def+g5DM/Je0GGJjxEylXXAae1l5Yu7lgQWrMg5GCQBkx7wXttCx6 KfPatBYFKq3XhrS4pFvG7vEV6USU+cOmaEj7eSHuDuEqe5zZ/uaeDRieqxuu0Xwl4PZ7 lvmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778162919; x=1778767719; h=content-transfer-encoding:in-reply-to:from:content-language :references: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=w2nhovRvFw1+XQcDcRJ+2hvlsNXDoa4sYKL7qfbTHmc=; b=a+EThCGhJYW6yz64On45VvuQuOXjrhPySmcGiRfwUgf9fjrejxUjNo6wkqm6DzWdGp 140aWOe9G7+U7UWIR6u71f6BM9nnP3qELu2q8otWenatyRmoY/E4/9zUTAz31khO4254 EfhYhCbMN7hba36uh6hGmfZPK7ics2HTV5BjvjIIZmLALNM7YYCDWSGUPuQ8+vKe6xJh efnROVrSrUMNnNc3lDeYcmL60JCuHjDdFgIjcpbhBNlbzp3wvgNquBQtxPgMXiM3cRiQ QaewvyUGHOQeug2fSaJfZ1XTyZdgHUwV4hOEOen72tQZeTaleZPACHm9Z9T4/7JglzLq kuew== X-Forwarded-Encrypted: i=1; AFNElJ8l+PbGWdASYW9VsRs2ESBX/yntBo3VImYVi7E0gk886duXNiRAQlIVZL9NSTDucV4zmuFKF7aBdU9V6d8=@vger.kernel.org X-Gm-Message-State: AOJu0YypdHrFdeb8+/sIVy+tZZjfvdQmAVg9K+NeqwjOyuuNbZSslo4o QcjU6SR68FjO1iQFp4VHQTLtkYQ6IZ9QKi6N2Yw9eJBeAECC/j3Es0JHnRRNgekY/FsY7DjHj+7 /a5QC0tTpTtZzt6TADa+nacLVQUS3Yq/1aBuSZn7qEYqYYWgXGsQvf2/lRHC5MC1VyA== X-Gm-Gg: AeBDieubh/Xpbu7zjDSt/iuyXjTzGrCStWygldxnnrXeWDyOuzWGKdEzGZtHPo17lDQ C5dw5BG5tPhwW4p704kEYZXkulgXxm1YAk98fX9/Wb2YF5yELSs7YOdMAT7Bp/oXnMLbxGMSciM KpSD4thFEsrF2XE6zmB/tbgUnfriOuUtHp+BqiwJkLqpAgnLhbgMZGIZ2WDJ6zWWulpRZxQaEGu gdMwRFQg0OHECoCghkj4cvbU2/nm0Dd+6Ro2suRlXonVpSHmvYef0mjOxsTvxt2QaKRUx4NZKKT whaSopZuyTckeB/+NPAb4oi9a2UrrsC6bMxl5Vs4r0DIChQX5EzZxm+8xlhODJPVPmjODwsTTtJ I74lDq5l8ANOfKoAk20vhrevYr+WWKbUwl2vNoYq17jZ7e/O4edtbovyncHb6xlEhskqOyu8fya yA X-Received: by 2002:a05:600c:3e86:b0:48a:5339:a46 with SMTP id 5b1f17b1804b1-48e5dffabcamr46917665e9.9.1778162918796; Thu, 07 May 2026 07:08:38 -0700 (PDT) X-Received: by 2002:a05:600c:3e86:b0:48a:5339:a46 with SMTP id 5b1f17b1804b1-48e5dffabcamr46917155e9.9.1778162918260; Thu, 07 May 2026 07:08:38 -0700 (PDT) Received: from [192.168.88.32] ([150.228.93.82]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e530d8691sm91116195e9.2.2026.05.07.07.08.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 May 2026 07:08:37 -0700 (PDT) Message-ID: Date: Thu, 7 May 2026 16:08:35 +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 1/5] net: dsa: mt7530: fix FDB entries not aging out with short timeout To: Daniel Golle , "Chester A. Unal" , Andrew Lunn , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Matthias Brugger , AngeloGioacchino Del Regno , DENG Qingfang , Florian Fainelli , =?UTF-8?B?QXLEsW7DpyDDnE5BTA==?= , Sean Wang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org References: Content-Language: en-US From: Paolo Abeni In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/5/26 4:16 PM, Daniel Golle wrote: > When setting a low ageing time such as 10 seconds, the algorithm in > mt7530_set_ageing_time() finds AGE_CNT=0 and AGE_UNIT=9 as the first > exact match (starting the search from tmp_age_count=0). > > On the MT7530/MT7531 hardware, the per-entry aging counter is > initialized to AGE_CNT when a MAC address is learned. With AGE_CNT=0, > new entries start with a counter value of 0, which the hardware treats > as "already aged" and never removes, effectively disabling aging. > > Fix this by starting the search from tmp_age_count=1 to ensure entries > always have a non-zero initial aging counter. For a 10-second ageing > time this yields AGE_CNT=1 and AGE_UNIT=4 instead: the timer ticks > every 5 seconds and entries are removed after 2 ticks. > > Fixes: ea6d5c924e39 ("net: dsa: mt7530: support setting ageing time") > Signed-off-by: Daniel Golle > --- > drivers/net/dsa/mt7530.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c > index 44d670904ad8..b1903da7d500 100644 > --- a/drivers/net/dsa/mt7530.c > +++ b/drivers/net/dsa/mt7530.c > @@ -1027,8 +1027,12 @@ mt7530_set_ageing_time(struct dsa_switch *ds, unsigned int msecs) > if (secs < 1 || secs > (AGE_CNT_MAX + 1) * (AGE_UNIT_MAX + 1)) > return -ERANGE; > > - /* iterate through all possible age_count to find the closest pair */ > - for (tmp_age_count = 0; tmp_age_count <= AGE_CNT_MAX; ++tmp_age_count) { > + /* Iterate through all possible age_count values to find the closest > + * pair. Start from 1 because the per-entry aging counter is > + * initialized to AGE_CNT and a value of 0 means the entry will > + * never be aged out. > + */ > + for (tmp_age_count = 1; tmp_age_count <= AGE_CNT_MAX; ++tmp_age_count) { > unsigned int tmp_age_unit = secs / (tmp_age_count + 1) - 1; > > if (tmp_age_unit <= AGE_UNIT_MAX) { Sashiko noted that the above will have problem with secs == 1: What happens here if secs is 1? Since the bounds check at the start of the function allows secs == 1, tmp_age_unit would be calculated as 1 / (1 + 1) - 1, which evaluates to 0 - 1, resulting in an unsigned underflow to UINT_MAX. > if (tmp_age_unit <= AGE_UNIT_MAX) { Because UINT_MAX is greater than AGE_UNIT_MAX, this condition will fail for all iterations of the loop. [ ... ] > mt7530_write(priv, MT7530_AAC, AGE_CNT(age_count) | AGE_UNIT(age_unit)); If the loop exits without ever finding a match and entering the if block, age_count and age_unit will remain uninitialized. Could this result in uninitialized stack variables being written to the MT7530_AAC hardware register? /P