From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 840361DB127 for ; Sat, 27 Sep 2025 13:52:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758981122; cv=none; b=o/YMf9ttlmlrsp1EzqiyENHV8ZzW5H0RisfKsP8Xfgqv6nJGpPTdWJeEFNdGCFW+Hpe4Wq2dUFnBMj2XXfHBlh7mUoEFj/Ner2qSTPBRVvwZaBG6vol+UJg37MKqwGR7hsoYShVksB6C3fwIE9t9haPR5oJPWNi2N2toum/XjGk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758981122; c=relaxed/simple; bh=Kq62syv+BVdCWbxNkz8T4gUKNI2B3eSz6nonthhXmLc=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jtgV6w1R3eqohdJ1qeOn7aykfBmb9meoRv16LBjFe/3WfvC1wLB/6Mn5oxlzMQyYML7O7CnnMhItroOkC2WTw2gSn2N6N6RGxAjkIyJB2ZyebJgsUx0gOgQaHbRg7k5KRnVqeMfdYEedhHSKivcrziZWQGe6TsPrMcXd1T9FW/Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ogjD8m0e; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ogjD8m0e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13B17C4CEE7; Sat, 27 Sep 2025 13:51:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758981121; bh=Kq62syv+BVdCWbxNkz8T4gUKNI2B3eSz6nonthhXmLc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ogjD8m0e4Fyn7U1/Z/MQBAA/bUbihSu8+xJtsZneVVBWTAzMXPjUsFFQ6QpR/It7g EbWC1VXapVQy5I4fojgd2c7zAnbSKkBwImHItek0Hs+xEONN/YhbSMdZwXnW7vVEzK kSXPEthoab4ngcOMebppio7sBiCYa1sXy+8UIhZhxiT/pHfYwjj2O6sNYWFVZrBOpT PUYVcXvZ7EijVgZ7DM1e3dnDc4LcqizQXD9hTW+ZxmctLh4CYqmmxA1kQjKL9Myir3 FNn8esrHexfqRqNbVrk8ZuXDjflEIMwHz52X2fRZmUMmEt0N8ZBSCX+DFwTLJsUT1y RNDUy1/8fXAdg== Date: Sat, 27 Sep 2025 14:51:52 +0100 From: Jonathan Cameron To: Andrej Valek Cc: Jonathan Cameron , linux-iio@vger.kernel.org, Lars-Peter Clausen , Michael Hennerich , Puranjay Mohan , Kessler Markus Subject: Re: [PATCH] drivers: iio: accel: fix ADX355 startup race condition Message-ID: <20250927145152.61c41a4f@jic23-huawei> In-Reply-To: <722b91bc-fce7-4e1f-811f-aea30e130f15@skyrain.eu> References: <20250909085528.68966-1-andrej.v@skyrain.eu> <20250910193049.145aa79e@jic23-huawei> <6ee57754-4fa0-4694-b997-5f4c627b567b@skyrain.eu> <20250912151259.00006fd5@huawei.com> <20250915165313.000041fa@huawei.com> <722b91bc-fce7-4e1f-811f-aea30e130f15@skyrain.eu> X-Mailer: Claws Mail 4.3.1 (GTK 3.24.50; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, 16 Sep 2025 09:07:18 +0200 Andrej Valek wrote: > On 15.09.2025 17:53, Jonathan Cameron wrote: > > On Mon, 15 Sep 2025 14:03:47 +0200 > > Andrej Valek wrote: > > =20 > >> Hi Jonathan, > >> > >> I submitted the version 2 with applied your suggestions. > >> > >> On 12.09.2025 16:12, Jonathan Cameron wrote: =20 > >>> On Thu, 11 Sep 2025 11:33:49 +0200 > >>> Andrej Valek wrote: > >>> =20 > >>>> Hi Jonathan, > >>>> > >>>> First, I would like to thanks for your feedback. > >>>> > >>>> On 10.09.2025 20:30, Jonathan Cameron wrote: =20 > >>>>> On Tue, 9 Sep 2025 10:55:28 +0200 > >>>>> Andrej Valek wrote: > >>>>> =20 > >>>>>> From: Valek Andrej =20 > >>>>> Hi Valek, > >>>>> > >>>>> Thanks for the patch. Small thing on patch title, don't include dri= vers. > >>>>> It's a pain but you need to look at other patches to a given subsys= tem > >>>>> to find out the preferred style. =20 > >>>> Valek is my surname =F0=9F=99=82. =20 > >>> Oops. Sorry! > >>> > >>> Hi Andrej, > >>> =20 > >>>>>> Signed-off-by: Valek Andrej > >>>>>> Signed-off-by: Kessler Markus > >>>>>> --- > >>>>>> drivers/iio/accel/adxl355_core.c | 48 ++++++++++++++++++++++++= ++++---- > >>>>>> 1 file changed, 43 insertions(+), 5 deletions(-) > >>>>>> > >>>>>> diff --git a/drivers/iio/accel/adxl355_core.c b/drivers/iio/accel/= adxl355_core.c > >>>>>> index 2e00fd51b4d51..5386cd4766def 100644 > >>>>>> --- a/drivers/iio/accel/adxl355_core.c > >>>>>> +++ b/drivers/iio/accel/adxl355_core.c > >>>>>> @@ -56,6 +56,8 @@ > >>>>>> #define ADXL355_POWER_CTL_DRDY_MSK BIT(2) > >>>>>> #define ADXL355_SELF_TEST_REG 0x2E > >>>>>> #define ADXL355_RESET_REG 0x2F > >>>>>> +#define ADXL355_BASE_ADDR_SHADOW_REG 0x50 > >>>>>> +#define ADXL355_SHADOW_REG_COUNT 5 > >>>>>> =20 > >>>>>> #define ADXL355_DEVID_AD_VAL 0xAD > >>>>>> #define ADXL355_DEVID_MST_VAL 0x1D > >>>>>> @@ -294,6 +296,9 @@ static void adxl355_fill_3db_frequency_table(s= truct adxl355_data *data) > >>>>>> static int adxl355_setup(struct adxl355_data *data) > >>>>>> { > >>>>>> unsigned int regval; > >>>>>> + u8 shadow_regs[ADXL355_SHADOW_REG_COUNT]; =20 > >>>>> Needs to be a DMA safe buffer. We can't assume that regmap will al= ways > >>>>> bounce the data through one before passing it to the SPI controllers > >>>>> that do sometimes require DMA safe buffers. Add a buffer to end = of > >>>>> struct adxl355_data where you can take advantage of the forcing of = appropriate > >>>>> padding that is already going on there. =20 > >>>> I see, but I don't like extending the adxl355_data just for one time > >>>> usage. The suggested approach is more similar to what is done with t= he > >>>> ID checking. > >>>> | if (regval !=3D ADXL355_DEVID_MST_VAL) { > >>>> |=C2=A0 dev_err(data->dev, "Invalid MEMS ID 0x%02x\n", regval); > >>>> |=C2=A0 return -ENODEV; > >>>> | } =20 > >>> That's a single read. Regmap always bounces those so a local variabl= e should > >>> be fine. Not so for a bulk read (or at least no one guarantees it) > >>> > >>> https://events19.linuxfoundation.org/wp-content/uploads/2017/12/20181= 023-Wolfram-Sang-ELCE18-safe_dma_buffers.pdf > >>> Slide 11 (in general this slide deck is a good introduction to the fu= n of DMA safety). > >>> > >>> The path for a single read goes through: > >>> https://elixir.bootlin.com/linux/v6.16.7/source/drivers/base/regmap/r= egmap.c#L2779 > >>> _regmap_bus_read() which uses map->work_buf which is DMA safe. =20 > >> regmap_bulk_read is using the same _regmap_read > >> https://elixir.bootlin.com/linux/v6.16.7/source/drivers/base/regmap/re= gmap.c#L3137 > >> so it should be safe, too I guess. =20 > > Whilst true, the repeated statement from the regmap maintainer that > > is mentioned in the talk is that there is no guarantee that will contin= ue > > to be the case :( Whereas the single reads are fine and will remain so. > > I guess one reason for that is that regmap_read() take an unsigned int = *val > > so the type is almost always going to be wrong and a copy necessary. > > > > Anyhow, the whole thing is a bit silly but upshot is dma safe buffers o= nly to bulk > > accessors unless the ABI is ever documented as not needing them. > > > > Jonathan =20 > Ok, I see. So can we live with the variant I did? > >>> Jonathan > >>> > >>> =20 > >> Andy > >> =20 > > =20 > In other words, is there anything pending from my side? Use a dma safe buffer for the bulk read. It's not a bug today but it is relying on undocumented behaviour of the regmap implementation that may change. Jonathan >=20 > Andy