From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41CD6C43460 for ; Sat, 10 Apr 2021 19:11:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B8D576113A for ; Sat, 10 Apr 2021 19:11:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8D576113A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 48ED98E0002; Sat, 10 Apr 2021 15:11:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 416518E0001; Sat, 10 Apr 2021 15:11:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28FF48E0002; Sat, 10 Apr 2021 15:11:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0132.hostedemail.com [216.40.44.132]) by kanga.kvack.org (Postfix) with ESMTP id 0A6828E0001 for ; Sat, 10 Apr 2021 15:11:07 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id BBD6240D7 for ; Sat, 10 Apr 2021 19:11:06 +0000 (UTC) X-FDA: 78017400132.38.6F7DE04 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf29.hostedemail.com (Postfix) with ESMTP id 8FCDDE8 for ; Sat, 10 Apr 2021 19:11:04 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id C8318611C1 for ; Sat, 10 Apr 2021 19:11:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618081863; bh=rBfw+r2um68UpFbzVkxVlHHyJ+hgFPf/zBrFYQw7TNI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=CIhhz328zzet5a/BvXZzSs9qZeOvsRmdTIQX8oHvPt4oPq31f6SdMiRQlV3wwxeNa GmirfKbnBbXy13rC5mPC5X4IYTxOrbfSp201pVc2ivwXNFWXhMjpUUd6Z3P6GdAypc hXQbk3jNgzXE4abVKr5LlTbMx3yus3tJYykOkPF4g5QUy/4sEmN3QnSl1XUTyImSG8 +nrIDp4z3hEGajjGuvQYOwmAvld9GZf6ZqRXKlZ6kJNOxc2eYZ8HIjAVZ3TijeONug 5j3gyVLCEPaB6nGAjThA9V1IH5nKdc2cpKmOF0OJJIEPxgrvw2FaG4CSqtEAVnEU7R BXNDi+Akq/Lhw== Received: by mail-ot1-f48.google.com with SMTP id t23-20020a0568301e37b02901b65ab30024so8965198otr.4 for ; Sat, 10 Apr 2021 12:11:03 -0700 (PDT) X-Gm-Message-State: AOAM530Xv8Lh98+a5Cr4jXSCwgIlIdaggmF+LiARL65pnWNWbK1CM12W fHrNLIdnHeJmETkLS09vXZOva+iiYxCZkRiZBHg= X-Google-Smtp-Source: ABdhPJy5fKRN+b0N+vdm7HuaN0voD9Ksx0FbjR4NiXXEFlqO3Rbtb6TftW/JNl1MSl+hXOUABL/gf3HkAiDbD0wFK7g= X-Received: by 2002:a05:6830:148c:: with SMTP id s12mr17843523otq.251.1618081863076; Sat, 10 Apr 2021 12:11:03 -0700 (PDT) MIME-Version: 1.0 References: <20210409185105.188284-3-willy@infradead.org> <202104100656.N7EVvkNZ-lkp@intel.com> <20210410024313.GX2531743@casper.infradead.org> In-Reply-To: <20210410024313.GX2531743@casper.infradead.org> From: Arnd Bergmann Date: Sat, 10 Apr 2021 21:10:47 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Bogus struct page layout on 32-bit To: Matthew Wilcox 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" Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 8FCDDE8 X-Stat-Signature: qka8oh8t5yax7o7xxisjmk97n3jef38t Received-SPF: none (kernel.org>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=mail.kernel.org; client-ip=198.145.29.99 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618081864-789221 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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). Arnd