Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp585118pxb; Sat, 10 Apr 2021 12:12:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywTSbGFXmQlntn/UgC4qS/tAyakWsiVmWK3LzD++p+FphVr2Aa9Eku6n+D8tmZtAYzHrre X-Received: by 2002:a05:6402:31b2:: with SMTP id dj18mr21571821edb.104.1618081969607; Sat, 10 Apr 2021 12:12:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618081969; cv=none; d=google.com; s=arc-20160816; b=Lpw+kBMSaWdkK74F29xOtG8WT1DTFHncGVDKydg3XLAvcCqTg6v/6zjZQJlTbic/wr JAP4m+c4Ekfe6n/drQKyKIZql+lDxWgzs/sXzG0jGT4aZZPZ5p6AXDiNDcxYLHCItHJe YV3NaMDplstFilyrWvIibuWJ9CJ7N9Fgswfy+KxDre1nojKDinJH/ydJ5ZiLYW/z15jO vlRC89Rrrzw929lt3/aam60rqJKWVbp4BwLHroBIkTQ3JISxa6FoaSinqDi4tbRIOzPw wff5iE3bA/0FWh5o6Jxd8n5qrm3oIvSeTAV3aMireM5Jc8PgND+wC9IiUUVpwGUiHcqv ngaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=fqNinNAhhPaTU2cij2p+HaHNg/J69IJOBSNDmdxs+TY=; b=WLTl0mlMYti6zCK6rVkamyB1GwamgueH/rM7Vi/YZ56498B5Ul1eWPALF+PpZTyacp ERS0ZacTi2V20NrzdewNzdydM5GYqFsUU0hksaGFP1vVtlw2fRfPF/y/CVld9GoXFf1e oXT1uqPIlqjebOtV3gMpVUCLtb4W20VPCQF44nKKR2/ZsZEuXb8HSbGiWHBGe0yMyhrS PrAkYVMqfrmWvf7DUniNF2H1qb5mizi8S4EgmLo/qbxvV4jSEZ1MCj1e9BBdKujddLDX 9xI0EBnFKFGsgtrno8dxeKBZ6cBuQ2Kb7+voA/r/McR/FbEKL031KziwH82634dKQ69C Dzbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CIhhz328; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk18si4593097edb.570.2021.04.10.12.12.15; Sat, 10 Apr 2021 12:12:49 -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=@kernel.org header.s=k20201202 header.b=CIhhz328; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234928AbhDJTLU (ORCPT + 99 others); Sat, 10 Apr 2021 15:11:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:45068 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234768AbhDJTLS (ORCPT ); Sat, 10 Apr 2021 15:11:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BC6966113A; 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-f47.google.com with SMTP id k14-20020a9d7dce0000b02901b866632f29so8973160otn.1; Sat, 10 Apr 2021 12:11:03 -0700 (PDT) X-Gm-Message-State: AOAM531Gu7ZroMfzZPVK+zswSeVKSRAt6gNScNWY7toYwzv0pgTbqngs YoYRoVagkOv02V8N9BihJZYRoDdswmEDZttOAdg= 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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