From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23C95C433DB for ; Sun, 14 Mar 2021 09:10:59 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8919264DD7 for ; Sun, 14 Mar 2021 09:10:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8919264DD7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=XJYdjWBZgGyQ48M/FfODw4piQhieCUdZsl6/S7f1p18=; b=UffaoofagGWXTdMDifUUfZkhA YvKWUJ7l5Re7uo6mn33nx3068WNHxl3+I9U4conLTnR/psQ275qn7/+7c3S3vfXEVFcM/MoRpOZSt bkj5y2vII99Ma68IdrjBq6kf0L8el+td4CKt252JVEO7d6iNwD9tVH2tm07wPQdrmzLxtq1uVaVOG CPfLe33GMaxzi1RAFM6c5+V+jbMgteaNJrvweB4KfZOlsOo9ZPygvhksQogUzuyzhEoEOpbxGe/hg BKqDGVL2Q9++fey0tjRbUfJxEIG5Q0oBTUwzbQChvpEWBsIm6CmbK1vQleS3/85XC9fn+Q3+Eyt/T zCEKyKbeg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lLMkM-00E3LH-Pi; Sun, 14 Mar 2021 09:09:15 +0000 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lLMkI-00E3Kv-5c for linux-arm-kernel@lists.infradead.org; Sun, 14 Mar 2021 09:09:12 +0000 Received: by mail-pg1-x531.google.com with SMTP id 16so12252674pgo.13 for ; Sun, 14 Mar 2021 01:09:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=tJrE5yB0s4MYuzTDxyIGPDzIPpwerkBrEWrfe5LUuh4=; b=ZiFf71vkGBezYsRPGDA4SNIhyJJ3fCxxhr48uBDiADsdJzUNqHGbZM/Ars500CoD/C U9V2gbxkBvym87OvrSjgpiC+STwtx5neNLII5Amq+ol1192XlqLfzPtS4kVgOaHmXPF7 SyluA3ztVHFoTiDAnM5Ly+s0P0jyi+EypmSPDhdNpL2vUqtn9ALvcvb6KuC5f22oLVQZ UcUiXgNJQBViTzk1g42zPk2RvKNynLC4iiSWwFt1lOadsS4Wd+n+7Wr//560Kevl6u/X CQDB0ks09jrP7tMDDcrJD1ztDwh7JZjwJpTkMJ0mSXkgdM9GJkC4cC0Ww8K5Ov01sCoD gMxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=tJrE5yB0s4MYuzTDxyIGPDzIPpwerkBrEWrfe5LUuh4=; b=c29S2Pc2Sqbrz1TLu/YCNcVYf+ZSUIia6iS0gpEQqDdY8tnSIhDjgd/HhqH2gNmpT8 4E0rOJaM2lvH1TjJKtwq9QCMS+q2B5LDQDpzB6R7CS1QYbVLBBXK5Ym+eTb80qvHX3dW rHq/n7BAoT1g60zcwvL1WknnoME0Y9Ou5QmEZcc3FAzmKEVisa+JHXQHcTHo3SIvoNnY UqUKEJrWhq1OVjF5d2xRCCl8Ly6J7WpS82EuEo6vbHDuFTr0XFU3WCoy1rV9xm9WQW3O WYPtH28hUAwoWB+nB9YH/327M1q3ycnk7h8lD2bS4ZQd/SWj346nODUT+FxoZi+eihKQ B5Vw== X-Gm-Message-State: AOAM532bX74dVbfU3Sfkpoic643agCeWJsGCEOJzBKix1VET7gTLQeiR 4UF/L7hjcTIGxl6KC9pfBh8= X-Google-Smtp-Source: ABdhPJyJ9RuW9uTpPw9TttzqomrqpE8AqLzOzb5l5qEfxF4ZFzs0Mn05ItcnoILUrl1g86roCc6rjg== X-Received: by 2002:a62:e404:0:b029:1f1:5cea:afbd with SMTP id r4-20020a62e4040000b02901f15ceaafbdmr5910905pfh.5.1615712944192; Sun, 14 Mar 2021 01:09:04 -0800 (PST) Received: from shinobu ([156.146.35.76]) by smtp.gmail.com with ESMTPSA id h186sm10242385pgc.38.2021.03.14.01.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 01:09:03 -0800 (PST) Date: Sun, 14 Mar 2021 18:08:56 +0900 From: William Breathitt Gray To: Fabrice Gasnier Cc: jic23@kernel.org, kamel.bouhara@bootlin.com, gwendal@chromium.org, david@lechnology.com, linux-iio@vger.kernel.org, patrick.havelange@essensium.com, alexandre.belloni@bootlin.com, mcoquelin.stm32@gmail.com, linux-kernel@vger.kernel.org, o.rempel@pengutronix.de, Dan Carpenter , kernel@pengutronix.de, fabrice.gasnier@st.com, syednwaris@gmail.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, alexandre.torgue@st.com Subject: Re: [Linux-stm32] [PATCH v9 22/33] counter: Internalize sysfs interface code Message-ID: References: <377a1552e7794ca4d998d840c06ba4a109214863.1615293276.git.vilhelm.gray@gmail.com> MIME-Version: 1.0 In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210314_090910_354612_C6B0F830 X-CRM114-Status: GOOD ( 37.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============7830575066735999721==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============7830575066735999721== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="EpN61qC1eJVFbM4k" Content-Disposition: inline --EpN61qC1eJVFbM4k Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Mar 14, 2021 at 04:56:44PM +0900, William Breathitt Gray wrote: > On Fri, Mar 12, 2021 at 04:02:42PM +0100, Fabrice Gasnier wrote: > > On 3/9/21 2:19 PM, William Breathitt Gray wrote: > > > +static ssize_t enums_available_show(const u32 *const enums, > > > + const size_t num_enums, > > > + const char *const strs[], char *buf) > > > +{ > > > + size_t len =3D 0; > > > + size_t index; > > > + > > > + for (index =3D 0; index < num_enums; index++) > > > + len +=3D sysfs_emit(buf + len, "%s\n", strs[enums[index]]); > > > + > > > + return len; > > > +} > > > + > > > +static ssize_t strs_available_show(const struct counter_available *c= onst avail, > > > + char *buf) > > > +{ > > > + size_t len =3D 0; > > > + size_t index; > > > + > > > + for (index =3D 0; index < avail->num_items; index++) > > > + len +=3D sysfs_emit(buf + len, "%s\n", avail->strs[index]); > > > + > > > + return len; > > > +} > >=20 > > Hi William, > >=20 > > I was willing to do some testing on this series, on the stm32 counter > > drivers, since we released few fixes around them. > >=20 > > I tried to apply this series against current testing branch, with few > > patches applied (so it applies cleanly): > > - dt-bindings: counter: add interrupt-counter binding > > - counter: add IRQ or GPIO based counter > > - counter: stm32-timer-cnt: fix ceiling miss-alignment with reload regi= ster > > - counter: stm32-timer-cnt: fix ceiling write max value > > counter: stm32-timer-cnt: Report count function when SLAVE_MODE_DISABL= ED > >=20 > >=20 > > For both the "stm32-lptimer-cnt" and "stm32-timer-cnt" drivers, I get a > > warning message and stack dump in "sysfs_emit" when reading the > > available functions from sysfs. > > I started to do some testing on v8 of this series last week. I didn't > > noticed that. > >=20 > > For both the "stm32-lptimer-cnt", there are 2 functions currently I get > > 1 stack dump. Only the "increase" function is printed correctly. > >=20 > > For the "stm32-timer-cnt", there are 4 functions currently, I get 3 > > stack dumps. Only the "increase" function is printed correctly > >=20 > > Sample log for "stm32-timer-cnt: > >=20 > > root@stm32mp1:/sys/devices/platform/soc/44000000.timer/44000000.timer:c= ounter/counter0# > > cat count0/function_available > > [ 4689.195506] ------------[ cut here ]------------ > > [ 4689.198747] WARNING: CPU: 1 PID: 5841 at fs/sysfs/file.c:737 > > sysfs_emit+0x88/0x94 > > [ 4689.206233] invalid sysfs_emit: buf:f4a66208 > > [ 4689.210553] Modules linked in: sha256_generic libsha256 sha256_arm > > cfg80211 panel_orisetech_otm8009a snd_soc_hdmi_codec > > snd_soc_stm32_sai_sub stm32_lptimers > > [ 4689.261444] CPU: 1 PID: 5841 Comm: cat Tainted: G W > > 5.12.0-rc1 #534 > > [ 4689.268999] Hardware name: STM32 (Device Tree Support) > > [ 4689.274166] [] (unwind_backtrace) from [] > > (show_stack+0x10/0x14) > > [ 4689.281942] [] (show_stack) from [] > > (dump_stack+0xc0/0xd4) > > [ 4689.289199] [] (dump_stack) from [] > > (__warn+0xec/0x148) > > [ 4689.296194] [] (__warn) from [] > > (warn_slowpath_fmt+0x98/0xbc) > > [ 4689.303714] [] (warn_slowpath_fmt) from [] > > (sysfs_emit+0x88/0x94) > > [ 4689.311586] [] (sysfs_emit) from [] > > (counter_comp_available_show+0x11c/0x1a4 [counter]) > > [ 4689.321382] [] (counter_comp_available_show [counter]) from > > [] (dev_attr_show+0x18/0x48) > > [ 4689.331263] [] (dev_attr_show) from [] > > (sysfs_kf_seq_show+0x88/0xf0) > > [ 4689.339394] [] (sysfs_kf_seq_show) from [] > > (seq_read_iter+0x1a4/0x554) > > [ 4689.347703] [] (seq_read_iter) from [] > > (vfs_read+0x1ac/0x2c4) > > [ 4689.355224] [] (vfs_read) from [] > > (ksys_read+0x64/0xdc) > > [ 4689.362219] [] (ksys_read) from [] > > (ret_fast_syscall+0x0/0x58) > > [ 4689.369827] Exception stack(0xc7261fa8 to 0xc7261ff0) > > [ 4689.374906] 1fa0: 00000000 00020000 00000003 > > b6f35000 00020000 00000000 > > [ 4689.383126] 1fc0: 00000000 00020000 b6f56ce0 00000003 00000003 > > 00000000 00020000 00000000 > > [ 4689.391344] 1fe0: 00000003 be8239a8 410bff27 4104c066 > > ... > > 2 more stack dumps follow > > ... > > [ 4689.810479] ---[ end trace 59ed79949efe984c ]--- > > increase > >=20 > > I get similar backtrace with other _available attributes: > > $ cat signal0_action_available > > $ cat signal1_action_available > >=20 > > Do you think I'm doing something wrong ? > >=20 > > I tested then "quadrature x4" on the timer driver... It seems all fine. > >=20 > > Best regards > > Fabrice > >=20 > > > + > > > +static ssize_t counter_comp_available_show(struct device *dev, > > > + struct device_attribute *attr, > > > + char *buf) > > > +{ > > > + const struct counter_attribute *const a =3D to_counter_attribute(at= tr); > > > + const struct counter_count *const count =3D a->parent; > > > + const struct counter_synapse *const synapse =3D a->comp.priv; > > > + const struct counter_available *const avail =3D a->comp.priv; > > > + > > > + switch (a->comp.type) { > > > + case COUNTER_COMP_FUNCTION: > > > + return enums_available_show(count->functions_list, > > > + count->num_functions, > > > + counter_function_str, buf); > > > + case COUNTER_COMP_SYNAPSE_ACTION: > > > + return enums_available_show(synapse->actions_list, > > > + synapse->num_actions, > > > + counter_synapse_action_str, buf); > > > + case COUNTER_COMP_ENUM: > > > + return strs_available_show(avail, buf); > > > + case COUNTER_COMP_COUNT_MODE: > > > + return enums_available_show(avail->enums, avail->num_items, > > > + counter_count_mode_str, buf); > > > + default: > > > + return -EINVAL; > > > + } > > > +} >=20 > Hi Fabrice, >=20 > I can confirm that I'm hitting this regression as well with the > 104-quad-8 driver. The warning seems to be caused by the > offset_in_page(buf) check in sysfs_emit(). It looks like the first loop > in enums_available_show() calls sysfs_emit() correctly, but subsequent > loops have an invalid buf offset. >=20 > The enums_available_show() callback is rather simple: call sysfs_emit() > for each enum string and increment buf by the length written each time. > I haven't modified this function since v8, so I am somewhat confused > about why the buf offset would be invalid here now. I wonder if there > has been a change somewhere else in the kernel that is causing > sysfs_emit() to now return an incorrect length. >=20 > William Breathitt Gray Fabrice, Would you be able to check the values of buf and len before they enter sysfs_emit()? I think redefining the enums_available_show() function like this should suffice: static ssize_t enums_available_show(const u32 *const enums, const size_t num_enums, const char *const strs[], char *buf) { size_t len =3D 0; size_t index; for (index =3D 0; index < num_enums; index++){ pr_info("buf: %p\tbuf+len: %p\tlen: %zu\n", buf, buf + len,= len); len +=3D sysfs_emit(buf + len, "%s\n", strs[enums[index]]); } return len; } I want to see whether the issue is due to the sysfs_emit() return value or the value of buf. Thank you, William Breathitt Gray --EpN61qC1eJVFbM4k Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAmBN0p4ACgkQhvpINdm7 VJK9cBAAysjrATgmOPhs5cHd6oWdl+vCffNIupxnwQ3TK49IsHq2wdrCtMduLQWC nbwPdNhce3+gwbsIZKKz8KTqVYyl+sELO9ee2MDQfJTsFw4XmHjjtGf2IPACCWP3 21QLF3zTaXQK6OmYpbloAZylB5VyDOf0HT5wSWIPQ9e9RbsoVXpSuMC1ovJgfS/R FPxTYsKfWF/+qFBU0fGIT3fkQJj4i3fucJ59u+vXJaTZjGIYcBxeYiVs0DM8YOMd ZlKl1S3zG1PCBCM7DhB0juI0NLp6sdIX9AxkfXTT3tiY8xiB6gVOXU+O+uhwFpl2 hvH9ZM10fl4RsbY3zbpTgLHs9dw7ZNe+DMHIqdIo4yAcvAt1mklFy8oANrcwAfGm JtwV3/sGl9FbO8zbKVbnRpRBP8gIUaSqgjUjALjfHQYkaaksy0tWNqI6E3bnFEia OczVrtskHunyXzRESCXwYce+2ChC43IJf86+XhLbILZ77WrpGRs0grTfITiLkh28 /ESikmU2orfONIIIENvAJG7ZLc8ACHhyQkR7ctE3rMBeK2DMss/Rm7JLKE9c+j7O RLZ661oUdskQfUXUlaVQxM1rAxTa1mn1kc9y0ZhMG1U5k2X1miHQYt8oI19Y/W3B pGbtr2ob0M8sHWPtBvnKAjQLfLdFgXD1VV8R1gs/NY+Bp6JIrrs= =oQxd -----END PGP SIGNATURE----- --EpN61qC1eJVFbM4k-- --===============7830575066735999721== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============7830575066735999721==--