Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1355045pxb; Sun, 11 Apr 2021 16:58:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwifYeQcaom2VD/tD5/tIJlwFnfwgXb+S4JR/KEQt85ihVWsm/E3Sw1U5ZosAGlUwb/e2W9 X-Received: by 2002:a17:906:c010:: with SMTP id e16mr25199758ejz.214.1618185513918; Sun, 11 Apr 2021 16:58:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618185513; cv=none; d=google.com; s=arc-20160816; b=xx9vnlyEt+3BAZwA8X0Y3wx7dEJ3RpV21rQQxiuBHsEj6UngGUdxs8IGSgZbb5LDjs 7RT0aWIp2t1dhY4H5p5smAW8YXV0KMu6tYoumGAo/lK+/YZRrjIJKyg1S8nGKv7Ut+vx 34AfwY0AHAAJTfl9IUD5KJDY3H4/+ew8zyWj5c5rAMIxMpbX6ghQ+NYcehVePkAYc60E FAHuHF4yZfxqVFTA6DrxeKToihAkGsnBNfKTw5geI31h56ilfDYvRdahxB6U9WGT6JUM NUn+xc8po3p9pLpZovq24aspi1i/Pfjweousn8metUxFhyHm96frjfFCGGwCxu49rA0V D3bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=lvW0/1imLWgxPdvw89GQU7hXjnk5amCWvOf6j0ZGMxs=; b=KF3G1XIYdMPInLLyT0F8DYTIHyjoEtE8VlanbZZYfQBid589KxAohEJJifXQ0nVS36 ZXM1GLTxJkUJ3cgGkD7Lsm7DQn1r58pM7RFKa/mAMu8oLivjWMhtkUvcKy6ftpvLYMaK cTAcgtldzztYo0DKdr0rEL3ZNmb8+8pC58MhYIB+ZaTA5xnxOWgZ7+6D44t2zLAIeByR XkY+jCXDbvWNMe7qiRVQHZcS6Y6lORCWzDpnu22cOHj3c0oev22Uiu6y/2Na3APjUXCb pf44VidJLok8Hwg4p9t9vQb/9yr64VmFzthiqRw82GqOImyzVAEeJB4lQEzZi/Xy0PqG o+/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ciV9TA9s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt15si6667309ejc.504.2021.04.11.16.58.11; Sun, 11 Apr 2021 16:58:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ciV9TA9s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236069AbhDKWgU (ORCPT + 99 others); Sun, 11 Apr 2021 18:36:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235229AbhDKWgU (ORCPT ); Sun, 11 Apr 2021 18:36:20 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 342B8C061574; Sun, 11 Apr 2021 15:36:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lvW0/1imLWgxPdvw89GQU7hXjnk5amCWvOf6j0ZGMxs=; b=ciV9TA9sI2hcmMk+5mvn6+GMnQ NVm1V6dO3xEncplJkkDlPA7TgOj6ULsrH2ZS8g/+oRMVmxes2/l/PJUJomi09t748PLbrirAblFzt 9+iYMHD4kchH5/T/s2uhJzpGrDIP0bzFwXjxq8K7Inz0QPgN16EnsQlshWENlti99ULd0pPPgC9Vj MRC1FJZvgC1UEgNB5/X3wMh72XySjbvejFh2JgxyYnO2+gc/910Fy1f/DUK/AnFxSRP2HkYKAi5Ay A1nkFFPlVvLZHDJQxw4PZDVM6/IWhLdR10szkk3VpbK2rFhz+VFvaptbayoyArEpMhzHHNLX4tSok 49f9Ab7A==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lVig5-003WFx-6L; Sun, 11 Apr 2021 22:35:44 +0000 Date: Sun, 11 Apr 2021 23:35:37 +0100 From: Matthew Wilcox To: Arnd Bergmann Cc: kernel test robot , Linux-MM , kbuild-all@lists.01.org, clang-built-linux , Linux Kernel Mailing List , Linux FS-devel Mailing List , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , linuxppc-dev , Linux ARM , Jesper Dangaard Brouer , "David S. Miller" Subject: Re: Bogus struct page layout on 32-bit Message-ID: <20210411223537.GF2531743@casper.infradead.org> References: <20210409185105.188284-3-willy@infradead.org> <202104100656.N7EVvkNZ-lkp@intel.com> <20210410024313.GX2531743@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 10, 2021 at 09:10:47PM +0200, Arnd Bergmann wrote: > On Sat, Apr 10, 2021 at 4:44 AM Matthew Wilcox wrote: > > + dma_addr_t dma_addr __packed; > > }; > > struct { /* slab, slob and slub */ > > union { > > > > but I don't know if GCC is smart enough to realise that dma_addr is now > > on an 8 byte boundary and it can use a normal instruction to access it, > > or whether it'll do something daft like use byte loads to access it. > > > > We could also do: > > > > + dma_addr_t dma_addr __packed __aligned(sizeof(void *)); > > > > and I see pahole, at least sees this correctly: > > > > struct { > > long unsigned int _page_pool_pad; /* 4 4 */ > > dma_addr_t dma_addr __attribute__((__aligned__(4))); /* 8 8 */ > > } __attribute__((__packed__)) __attribute__((__aligned__(4))); > > > > This presumably affects any 32-bit architecture with a 64-bit phys_addr_t > > / dma_addr_t. Advice, please? > > I've tried out what gcc would make of this: https://godbolt.org/z/aTEbxxbG3 > > struct page { > short a; > struct { > short b; > long long c __attribute__((packed, aligned(2))); > } __attribute__((packed)); > } __attribute__((aligned(8))); > > In this structure, 'c' is clearly aligned to eight bytes, and gcc does > realize that > it is safe to use the 'ldrd' instruction for 32-bit arm, which is forbidden on > struct members with less than 4 byte alignment. However, it also complains > that passing a pointer to 'c' into a function that expects a 'long long' is not > allowed because alignof(c) is only '2' here. > > (I used 'short' here because I having a 64-bit member misaligned by four > bytes wouldn't make a difference to the instructions on Arm, or any other > 32-bit architecture I can think of, regardless of the ABI requirements). So ... we could do this: +++ b/include/linux/types.h @@ -140,7 +140,7 @@ typedef u64 blkcnt_t; * so they don't care about the size of the actual bus addresses. */ #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT -typedef u64 dma_addr_t; +typedef u64 __attribute__((aligned(sizeof(void *)))) dma_addr_t; #else typedef u32 dma_addr_t; #endif but I'm a little scared that this might have unintended consequences. And Jesper points out that a big-endian 64-bit dma_addr_t can impersonate a PageTail page, and we should solve that problem while we're at it. So I don't think we should do this, but thought I should mention it as a possibility.