public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
Cc: "Andy Shevchenko" <andy.shevchenko@gmail.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Eugen Hristev" <eugen.hristev@linaro.org>,
	"Nicolas Ferre" <nicolas.ferre@microchip.com>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v4 1/7] iio: introduce IIO_DECLARE_BUFFER_WITH_TS macros
Date: Sun, 4 May 2025 18:17:49 +0100	[thread overview]
Message-ID: <20250504181749.67d0d92e@jic23-huawei> (raw)
In-Reply-To: <38e243b0-e81b-4d4d-97fe-91ea2bec6270@baylibre.com>

On Tue, 29 Apr 2025 14:47:41 -0500
David Lechner <dlechner@baylibre.com> wrote:

> On 4/29/25 2:36 PM, Andy Shevchenko wrote:
> > On Tue, Apr 29, 2025 at 10:31 PM David Lechner <dlechner@baylibre.com> wrote:  
> >> On 4/28/25 9:12 PM, David Lechner wrote:  
> >>> On 4/28/25 3:23 PM, David Lechner wrote:  
> >>>> Add new macros to help with the common case of declaring a buffer that
> >>>> is safe to use with iio_push_to_buffers_with_ts(). This is not trivial
> >>>> to do correctly because of the alignment requirements of the timestamp.
> >>>> This will make it easier for both authors and reviewers.
> >>>>
> >>>> To avoid double __align() attributes in cases where we also need DMA
> >>>> alignment, add a 2nd variant IIO_DECLARE_DMA_BUFFER_WITH_TS().  
> > 
> > ...
> >   
> >>>> +/**
> >>>> + * IIO_DECLARE_DMA_BUFFER_WITH_TS() - Declare a DMA-aligned buffer with timestamp
> >>>> + * @type: element type of the buffer
> >>>> + * @name: identifier name of the buffer
> >>>> + * @count: number of elements in the buffer
> >>>> + *
> >>>> + * Same as IIO_DECLARE_BUFFER_WITH_TS(), but is uses __aligned(IIO_DMA_MINALIGN)
> >>>> + * to ensure that the buffer doesn't share cachelines with anything that comes
> >>>> + * before it in a struct. This should not be used for stack-allocated buffers
> >>>> + * as stack memory cannot generally be used for DMA.
> >>>> + */
> >>>> +#define IIO_DECLARE_DMA_BUFFER_WITH_TS(type, name, count)   \
> >>>> +    __IIO_DECLARE_BUFFER_WITH_TS(type, name, count)         \
> >>>> +    /* IIO_DMA_MINALIGN may be 4 on some 32-bit arches. */  \
> >>>> +    __aligned(MAX(IIO_DMA_MINALIGN, sizeof(s64)))  
> >>>
> >>> I just realized my logic behind this is faulty. It assumes sizeof(s64) ==
> >>> __alignof__(s64), but that isn't always true and that is what caused the builds
> >>> to hit the static_assert() on v3.
> >>>
> >>> We should be able to leave this as __aligned(IIO_DMA_MINALIGN)
> >>>
> >>> And have this (with better error message):
> >>>
> >>> static assert(IIO_DMA_MINALIGN % __alignof__(s64) == 0);  
> >>
> >> I was working late yesterday and should have saved that reply until morning
> >> to think about it more!
> >>
> >> We do want to align to to sizeof(s64) instead of __alignof__(s64) to avoid
> >> issues with, e.g. 32-bit kernel and 64-bit userspace (same reason that
> >> aligned_s64 exists and always uses 8-byte alignment).
> >>
> >> So I think this patch is correct as-is after all.  
> > 
> > I'm wondering, shouldn't it be better just to make sure that
> > IIO_DMA_MINALIGN is always bigger or equal to sizeof(s64)?
> >   
> 
> Sounds reasonable to me. From what I have seen while working on this is that
> there are quite a few drivers using IIO_DMA_MINALIGN expecting it to be
> sufficient for timestamp alignment, which as it seems is not always the case.
> 
> I'll wait for Jonathan to weigh in though before spinning up a new patch.
> 
It would be very odd if we ever see a platform with a DMA alignment requirement
that is not a multiple of sizeof(s64) just forcing IIO_DMA_MINALIGN to max
of the arch constraint and sizeof(s64) seems fine to me and fixes up
all those other drivers that were assuming this was true already...
I thought it was and only got fussy for this macro :(


Jonathan




  reply	other threads:[~2025-05-04 17:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-28 20:23 [PATCH v4 0/7] iio: introduce IIO_DECLARE_BUFFER_WITH_TS David Lechner
2025-04-28 20:23 ` [PATCH v4 1/7] iio: introduce IIO_DECLARE_BUFFER_WITH_TS macros David Lechner
2025-04-29  2:12   ` David Lechner
2025-04-29 19:31     ` David Lechner
2025-04-29 19:36       ` Andy Shevchenko
2025-04-29 19:47         ` David Lechner
2025-05-04 17:17           ` Jonathan Cameron [this message]
2025-04-30 16:05       ` Nuno Sá
2025-04-28 20:23 ` [PATCH v4 2/7] iio: adc: ad4695: use u16 for buffer elements David Lechner
2025-04-28 20:33   ` Trevor Gamblin
2025-05-04 17:19     ` Jonathan Cameron
2025-04-28 20:23 ` [PATCH v4 3/7] iio: adc: ad4695: use IIO_DECLARE_DMA_BUFFER_WITH_TS David Lechner
2025-04-28 20:33   ` Trevor Gamblin
2025-04-28 20:23 ` [PATCH v4 4/7] iio: adc: ad4695: rename AD4695_MAX_VIN_CHANNELS David Lechner
2025-04-28 20:37   ` Trevor Gamblin
2025-05-04 17:22     ` Jonathan Cameron
2025-04-28 20:23 ` [PATCH v4 5/7] iio: adc: ad7380: use IIO_DECLARE_DMA_BUFFER_WITH_TS David Lechner
2025-04-28 20:23 ` [PATCH v4 6/7] iio: accel: sca3300: use IIO_DECLARE_BUFFER_WITH_TS David Lechner
2025-04-28 20:23 ` [PATCH v4 7/7] iio: adc: at91-sama5d2: " David Lechner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250504181749.67d0d92e@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=dlechner@baylibre.com \
    --cc=eugen.hristev@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox