linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Alexey Brodkin <Alexey.Brodkin@synopsys.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	arcml <linux-snps-arc@lists.infradead.org>,
	Linux-Arch <linux-arch@vger.kernel.org>,
	Greg KH <gregkh@linuxfoundation.org>,
	David Laight <David.Laight@aculab.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Will Deacon <will.deacon@arm.com>, Greg KH <greg@kroah.com>,
	stable <stable@vger.kernel.org>
Subject: Re: [PATCH v3] devres: Explicitly align datai[] to 64-bit
Date: Mon, 9 Jul 2018 16:10:23 +0200	[thread overview]
Message-ID: <CAMuHMdUS1QXuV8L1zadJ4XP=2g4pfoXgKByZ7Yg9PEbXOT_KVw@mail.gmail.com> (raw)
Message-ID: <20180709141023.LXemXzZ-859U1bEpE7S0WiKsHrfkWmwPOZxnAzAnCXs@z> (raw)
In-Reply-To: <20180709140438.ashvw4otyusj3nfa@lakrids.cambridge.arm.com>

On Mon, Jul 9, 2018 at 4:04 PM Mark Rutland <mark.rutland@arm.com> wrote:
> On Mon, Jul 09, 2018 at 03:54:09PM +0200, Peter Zijlstra wrote:
> > On Mon, Jul 09, 2018 at 04:45:50PM +0300, Alexey Brodkin wrote:
> > > diff --git a/drivers/base/devres.c b/drivers/base/devres.c
> > > index f98a097e73f2..d65327cb83c9 100644
> > > --- a/drivers/base/devres.c
> > > +++ b/drivers/base/devres.c
> > > @@ -24,8 +24,12 @@ struct devres_node {
> > >
> > >  struct devres {
> > >     struct devres_node              node;
> > > -   /* -- 3 pointers */
> > > -   unsigned long long              data[]; /* guarantee ull alignment */
> > > +   /*
> > > +    * data[] must be 64 bit aligned even on 32 bit architectures
> > > +    * because it might be accessed by instructions that require
> > > +    * aligned memory arguments such as atomic64_t.
> > > +    */
> > > +   u8 __aligned(8)                 data[];
> > >  };
> >
> > From a quick reading in Documentation/driver-model/devres.txt this
> > devres muck is supposed to be device memory, right?
>
> It's for associating resources (e.g. memory allocations) with a struct
> device.
>
> e.g. you do:
>
>         devm_kmalloc(dev, size, GFP_KERNEL);
>
> ... and that allocates sizeof(struct devres) + size, putting some
> accounting data into that devres, and returning a pointer to the
> remaining size bytes.
>
> The data[] thing is a hack to ensure that the structure is padded to
> 64-bit alignment, in case you'd done:
>
> struct foo {
>         atomic64_t counter;
> }
>
> struct foo *f = devm_kmalloc(dev, sizeof(*f), GFP_KERNEL);

So the big issue is that the minimum alignment of a buffer allocated with
devm_kmalloc() and friends is different (lower) than when allocated with
kmalloc().

On 32-bit, it's only aligned to 4 bytes. Ugh.
I wouldn't be surprised if some callers assume it to be cacheline-aligned...

Which means blind conversions to the devm_*() versions can be dangerous.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

  parent reply	other threads:[~2018-07-09 14:10 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-09 13:45 [PATCH v3] devres: Explicitly align datai[] to 64-bit Alexey Brodkin
2018-07-09 13:45 ` Alexey Brodkin
2018-07-09 13:54 ` Peter Zijlstra
2018-07-09 13:54   ` Peter Zijlstra
2018-07-09 14:04   ` Mark Rutland
2018-07-09 14:04     ` Mark Rutland
2018-07-09 14:10     ` Geert Uytterhoeven [this message]
2018-07-09 14:10       ` Geert Uytterhoeven
2018-07-09 14:07   ` Alexey Brodkin
2018-07-09 14:07     ` Alexey Brodkin
2018-07-09 14:07 ` Peter Zijlstra
2018-07-09 14:07   ` Peter Zijlstra
2018-07-09 14:10   ` Peter Zijlstra
2018-07-09 14:10     ` Peter Zijlstra
2018-07-09 14:33     ` Alexey Brodkin
2018-07-09 14:33       ` Alexey Brodkin
2018-07-09 14:49       ` Peter Zijlstra
2018-07-09 14:49         ` Peter Zijlstra
2018-07-09 14:53         ` Alexey Brodkin
2018-07-09 14:53           ` Alexey Brodkin
2018-10-04 16:19           ` Alexey Brodkin
2018-10-04 16:19             ` Alexey Brodkin
2018-07-09 15:02         ` David Laight
2018-07-09 15:02           ` David Laight
2018-07-09 15:14           ` Peter Zijlstra
2018-07-09 15:14             ` Peter Zijlstra
2018-07-09 15:29         ` Mark Rutland
2018-07-09 15:29           ` Mark Rutland
2018-07-09 15:34           ` Peter Zijlstra
2018-07-09 15:34             ` Peter Zijlstra
2018-07-09 15:45             ` Peter Zijlstra
2018-07-09 15:45               ` Peter Zijlstra
2018-07-09 15:48               ` Mark Rutland
2018-07-09 15:48                 ` Mark Rutland
2018-07-09 16:10                 ` David Laight
2018-07-09 16:10                   ` David Laight
2018-07-09 20:28                   ` Vineet Gupta
2018-07-09 20:28                     ` Vineet Gupta

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='CAMuHMdUS1QXuV8L1zadJ4XP=2g4pfoXgKByZ7Yg9PEbXOT_KVw@mail.gmail.com' \
    --to=geert@linux-m68k.org \
    --cc=Alexey.Brodkin@synopsys.com \
    --cc=David.Laight@aculab.com \
    --cc=greg@kroah.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-snps-arc@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=will.deacon@arm.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;
as well as URLs for NNTP newsgroup(s).