[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMuHMdXm1Zg=Wm-=tn5jUJwqVGUvCi5yDaW0PXWC2DEDYGcy5A@mail.gmail.com>
Date: Tue, 20 Apr 2021 09:39:54 +0200
From: Geert Uytterhoeven <geert@...ux-m68k.org>
To: Matthew Wilcox <willy@...radead.org>
Cc: Jesper Dangaard Brouer <brouer@...hat.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Linux MM <linux-mm@...ck.org>, netdev <netdev@...r.kernel.org>,
linuxppc-dev <linuxppc-dev@...ts.ozlabs.org>,
Linux ARM <linux-arm-kernel@...ts.infradead.org>,
"open list:BROADCOM NVRAM DRIVER" <linux-mips@...r.kernel.org>,
Ilias Apalodimas <ilias.apalodimas@...aro.org>,
mcroce@...ux.microsoft.com,
Grygorii Strashko <grygorii.strashko@...com>,
Arnd Bergmann <arnd@...nel.org>,
Christoph Hellwig <hch@....de>,
arcml <linux-snps-arc@...ts.infradead.org>,
Michal Hocko <mhocko@...nel.org>, Mel Gorman <mgorman@...e.de>
Subject: Re: [PATCH 1/2] mm: Fix struct page layout on 32-bit systems
Hi Willy,
On Sat, Apr 17, 2021 at 4:49 AM Matthew Wilcox <willy@...radead.org> wrote:
> Replacement patch to fix compiler warning.
>
> From: "Matthew Wilcox (Oracle)" <willy@...radead.org>
> Date: Fri, 16 Apr 2021 16:34:55 -0400
> Subject: [PATCH 1/2] mm: Fix struct page layout on 32-bit systems
> To: brouer@...hat.com
> Cc: linux-kernel@...r.kernel.org,
> linux-mm@...ck.org,
> netdev@...r.kernel.org,
> linuxppc-dev@...ts.ozlabs.org,
> linux-arm-kernel@...ts.infradead.org,
> linux-mips@...r.kernel.org,
> ilias.apalodimas@...aro.org,
> mcroce@...ux.microsoft.com,
> grygorii.strashko@...com,
> arnd@...nel.org,
> hch@....de,
> linux-snps-arc@...ts.infradead.org,
> mhocko@...nel.org,
> mgorman@...e.de
>
> 32-bit architectures which expect 8-byte alignment for 8-byte integers
> and need 64-bit DMA addresses (arc, arm, mips, ppc) had their struct
> page inadvertently expanded in 2019. When the dma_addr_t was added,
> it forced the alignment of the union to 8 bytes, which inserted a 4 byte
> gap between 'flags' and the union.
>
> Fix this by storing the dma_addr_t in one or two adjacent unsigned longs.
> This restores the alignment to that of an unsigned long, and also fixes a
> potential problem where (on a big endian platform), the bit used to denote
> PageTail could inadvertently get set, and a racing get_user_pages_fast()
> could dereference a bogus compound_head().
>
> Fixes: c25fff7171be ("mm: add dma_addr_t to struct page")
> Signed-off-by: Matthew Wilcox (Oracle) <willy@...radead.org>
Thanks for your patch!
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -97,10 +97,10 @@ struct page {
> };
> struct { /* page_pool used by netstack */
> /**
> - * @dma_addr: might require a 64-bit value even on
> + * @dma_addr: might require a 64-bit value on
> * 32-bit architectures.
> */
> - dma_addr_t dma_addr;
> + unsigned long dma_addr[2];
So we get two 64-bit words on 64-bit platforms, while only one is
needed?
Would
unsigned long _dma_addr[sizeof(dma_addr_t) / sizeof(unsigned long)];
work?
Or will the compiler become too overzealous, and warn about the use
of ...[1] below, even when unreachable?
I wouldn't mind an #ifdef instead of an if () in the code below, though.
> };
> struct { /* slab, slob and slub */
> union {
> diff --git a/include/net/page_pool.h b/include/net/page_pool.h
> index b5b195305346..ad6154dc206c 100644
> --- a/include/net/page_pool.h
> +++ b/include/net/page_pool.h
> @@ -198,7 +198,17 @@ static inline void page_pool_recycle_direct(struct page_pool *pool,
>
> static inline dma_addr_t page_pool_get_dma_addr(struct page *page)
> {
> - return page->dma_addr;
> + dma_addr_t ret = page->dma_addr[0];
> + if (sizeof(dma_addr_t) > sizeof(unsigned long))
> + ret |= (dma_addr_t)page->dma_addr[1] << 16 << 16;
We don't seem to have a handy macro for a 32-bit left shift yet...
But you can also avoid the warning using
ret |= (u64)page->dma_addr[1] << 32;
> + return ret;
> +}
> +
> +static inline void page_pool_set_dma_addr(struct page *page, dma_addr_t addr)
> +{
> + page->dma_addr[0] = addr;
> + if (sizeof(dma_addr_t) > sizeof(unsigned long))
> + page->dma_addr[1] = addr >> 16 >> 16;
... but we do have upper_32_bits() for a 32-bit right shift.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-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
Powered by blists - more mailing lists