Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1030988pxb; Fri, 15 Apr 2022 18:58:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKS6w52GGWJdHhp/tjpPZKGY5QM0NNnKpSGL77g/O1ZYAJRv1n8Q7bITkk+2B7hbmoQ8ac X-Received: by 2002:a17:902:c3c4:b0:158:85b8:1459 with SMTP id j4-20020a170902c3c400b0015885b81459mr1538426plj.10.1650074310087; Fri, 15 Apr 2022 18:58:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650074310; cv=none; d=google.com; s=arc-20160816; b=zhEtp7LbtcVCT9UQdYMlEuVTcstuTGxGSOrJIeBMV5/FYjrluNJ39suEk2Vzo6/elx BPB5/q4gqNJrCuKIHPzzZ+/mMmTCZOfJUvN6ysXZxwMFPe4dQG2luXlBE5XJRXiz+LyX Q8SSwieDPAz5/UW2McJYloPEVEvmSDJfvngSjfumrWlgRFDoWYVCxcjXBNaO0HEer3FD kcugs8tkbAW8+/q6ZykriHzyLi0DiVA++tzoqkOmJIYA7spLG40A3oXlshlQoFOw4XfC wXPsL7wqabm7+iU5TavBxFq5FWWyHKwN8rDtUeN4TjnpnAezLxXOLvmgu39Jbq9cDDPD +VcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=mMMKTkI1t74z457D3rwnXDbJeDE/63zmewzC5BANBFk=; b=CMhi+e4Ypzj3HvEMIVihO9Ro5a9b28api28bf2+OjB+0256aywG0nn1BfR2hynAVw2 41lMWLtTQkA9xT5EqL1lLu2iHQ5lOourJYqv5R8b725hS9uUw78dUzatnAQsZBRbk6ey zHtUJ3Ss/5Z30FH9l2bp5hgSpNJU53AWizQ1/nkeoo0++jQNjCjfc1KVcYgygbW7Mlf8 an1Pbu7L84zgNnT16VXQDcUGIc4WXhPa071QmbjYX491g/mzQLgvWGkqWCrPsfqpiKNC qZTtFWOHXppky4EsZqJboZIZpn6KLiuw+BMkmZuiwWYdC/D6UkWpdCTzGhp2NErE4GGF xakg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=g+3Y9bOl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g15-20020a63e60f000000b003a292529829si2761975pgh.603.2022.04.15.18.58.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 18:58:30 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=g+3Y9bOl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 423261AD1EF; Fri, 15 Apr 2022 18:19:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242045AbiDOMIl (ORCPT + 99 others); Fri, 15 Apr 2022 08:08:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353205AbiDOMID (ORCPT ); Fri, 15 Apr 2022 08:08:03 -0400 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBA54AD111; Fri, 15 Apr 2022 05:05:33 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 7B693240011; Fri, 15 Apr 2022 12:05:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1650024331; 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=mMMKTkI1t74z457D3rwnXDbJeDE/63zmewzC5BANBFk=; b=g+3Y9bOloddX2/b2HGfVlTPEpWZ68ZUGgetSueVe3wm8nyZ1jhl+j7fGPhOFtKPNiZxZnr R612kZmmwUw7Xqg+I9vYT6F27U3rZQTtiDYCZAW/cokGwdT4Hv/XWaKj2sExNp3+u0EWbY kQCEdZUplGQW1jWY3eoWjGttge76exXEw4Nv7Bz7ggutCJrisZrtWsid3Iz31TGD8FoJRW /AQetx8nkMRHniYA7ZtshW84j1lAfgX1mLbOyNp/GJ/lO3fQb087qPmJHc/dbBT4ooZB/I FH/OcCgaKpxgsw3HH7sUR360KZN2L6lwK386buhPttqL8+VGGNt4ri0YRAuH9A== Date: Fri, 15 Apr 2022 14:04:02 +0200 From: =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andrew Lunn Cc: Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S . Miller" , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Geert Uytterhoeven , Magnus Damm , Heiner Kallweit , Russell King , Thomas Petazzoni , Herve Codina , =?UTF-8?B?TWlxdcOobA==?= Raynal , Milan Stevanovic , Jimmy Lalande , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH net-next 07/12] net: dsa: rzn1-a5psw: add statistics support Message-ID: <20220415140402.76822543@fixe.home> In-Reply-To: References: <20220414122250.158113-1-clement.leger@bootlin.com> <20220414122250.158113-8-clement.leger@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le Fri, 15 Apr 2022 01:16:11 +0200, Andrew Lunn a =C3=A9crit : > On Thu, Apr 14, 2022 at 02:22:45PM +0200, Cl=C3=A9ment L=C3=A9ger wrote: > > Add per-port statistics. This support requries to add a stat lock since > > statistics are stored in two 32 bits registers, the hi part one being > > global and latched when accessing the lo part. > >=20 > > Signed-off-by: Cl=C3=A9ment L=C3=A9ger > > --- > > drivers/net/dsa/rzn1_a5psw.c | 101 +++++++++++++++++++++++++++++++++++ > > drivers/net/dsa/rzn1_a5psw.h | 2 + > > 2 files changed, 103 insertions(+) > >=20 > > diff --git a/drivers/net/dsa/rzn1_a5psw.c b/drivers/net/dsa/rzn1_a5psw.c > > index 5bee999f7050..7ab7d9054427 100644 > > --- a/drivers/net/dsa/rzn1_a5psw.c > > +++ b/drivers/net/dsa/rzn1_a5psw.c > > @@ -16,6 +16,59 @@ > > =20 > > #include "rzn1_a5psw.h" > > =20 > > +struct a5psw_stats { > > + u16 offset; > > + const char *name; > > +}; > > + > > +#define STAT_DESC(_offset, _name) {.offset =3D _offset, .name =3D _nam= e} > > + > > +static const struct a5psw_stats a5psw_stats[] =3D { > > + STAT_DESC(0x868, "aFrameTransmitted"), > > + STAT_DESC(0x86C, "aFrameReceived"), > > + STAT_DESC(0x8BC, "etherStatsetherStatsOversizePktsDropEvents"), =20 >=20 > > +}; =20 >=20 >=20 > > +static void a5psw_get_strings(struct dsa_switch *ds, int port, u32 str= ingset, > > + uint8_t *data) > > +{ > > + unsigned int u; > > + > > + if (stringset !=3D ETH_SS_STATS) > > + return; > > + > > + for (u =3D 0; u < ARRAY_SIZE(a5psw_stats); u++) { > > + strncpy(data + u * ETH_GSTRING_LEN, a5psw_stats[u].name, > > + ETH_GSTRING_LEN); > > + } =20 >=20 > The kernel strncpy() is like the user space one. It does not add a > NULL if the string is longer than ETH_GSTRING_LEN and it needs to > truncate. So there is a danger here. >=20 > What you find most drivers do is >=20 > struct a5psw_stats { > u16 offset; > const char name[ETH_GSTRING_LEN]; > }; >=20 > You should then get a compiler warning/error if you string is ever > longer than allowed. And use memcpy() rather than strcpy(), which is > faster anyway. But you do use up a bit more memory. Acked. >=20 > > +static void a5psw_get_ethtool_stats(struct dsa_switch *ds, int port, > > + uint64_t *data) > > +{ > > + struct a5psw *a5psw =3D ds->priv; > > + u32 reg_lo, reg_hi; > > + unsigned int u; > > + > > + for (u =3D 0; u < ARRAY_SIZE(a5psw_stats); u++) { > > + /* A5PSW_STATS_HIWORD is global and thus, access must be > > + * exclusive > > + */ =20 >=20 > Could you explain that a bit more. The RTNL lock will prevent two > parallel calls to this function. Ok, I wasn't sure of the locking applicable here. --=20 Cl=C3=A9ment L=C3=A9ger, Embedded Linux and Kernel engineer at Bootlin https://bootlin.com