Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp585214imm; Mon, 9 Jul 2018 07:12:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdnyJkDQ1wHPmCgRs3OW4W5NzeKI0PHyPxoLkkoAH1CBZBRebAMKKQYrcctHm/hOZa82aXF X-Received: by 2002:a63:d704:: with SMTP id d4-v6mr5471351pgg.312.1531145535706; Mon, 09 Jul 2018 07:12:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531145535; cv=none; d=google.com; s=arc-20160816; b=0KcvU+BfLof8mCK24syTHxNJdtE9xbG1A9uU5x5GK4xN0zltcdAXXKqwYb6DJqWiqr +KfIJVy46K+7DOf9cQd5b8Dd2kCODMhEp189JrqBpApSBFKZRY3FHIkAMGSzBpBWw3b4 sCLhW5LUrjdJrqrZ9HsyESmoPeUURPyjumv6YYJAyIte1/itlDgoQKsJWDmdcWxBr+bV tGTP1u8DkHnGw9UtxbOeg5GeSeSkZPoNr9AbRCd6WAAsaBF17YTBaSmgBU3uSTDclcmj CdKf/Lz0WfWrSrZZoUWG4sMO7RzKm205u+HMuMlHVTLqx8yuUk7QbEwluZW905518zud LE3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:arc-authentication-results; bh=DgMUvRX6XnBkbJUYmmZbc284DtxsmXgz0C/DdENXmok=; b=IbojxDD517eVpR3pMQih/GRq93Yy4JhoW5HBuMRbGCDnJX4Mrfw/DPeG6S2I+TXpRc CAlA4u87L9y4a2TKNTqLj6nnzGDorGUmYU+H/Jjspq7nhLiH+JwkrbNheXCqIHMISFEY rs8FaauP5MRRNoXNWrlo4sNVy8wYWoGnzyCfcQ4pFPMOXHkfwPnuJU5LoplKcEbZpl2V 85wEeqatGj4Bsdgmvp5YrUY8yONLUFoCKAYOlH+Dc92vx7Bi2rVulOEEbQJLkTU3hSme Ruqvfl1X3ZhQfOiLP1eBy0SyJGvntLmqY74piGrgDfaZZMwY1UTbQ3rTkWNM/4OrXHQ3 oN1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p5-v6si14277155pls.53.2018.07.09.07.12.00; Mon, 09 Jul 2018 07:12:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932903AbeGIOKj (ORCPT + 99 others); Mon, 9 Jul 2018 10:10:39 -0400 Received: from mail-ua0-f195.google.com ([209.85.217.195]:34237 "EHLO mail-ua0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932436AbeGIOKg (ORCPT ); Mon, 9 Jul 2018 10:10:36 -0400 Received: by mail-ua0-f195.google.com with SMTP id r10-v6so11791594uao.1; Mon, 09 Jul 2018 07:10:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DgMUvRX6XnBkbJUYmmZbc284DtxsmXgz0C/DdENXmok=; b=fMQSg6dHxyCWBCsoMdX78o+512GAD/Hm7AB0QjAdz9vcORODa3N2u8YNrFtmRfhC7v 7lAdpMm9oXAzneqkqrmMrfxhGBIrgbcCGR8kYmoAZ0rZOGSSqlBpwYb5l6UexeVGufGz 6SLGeGub2przVP8njbb6V+RY14URVcFoZlJjqgQ0l0ZcuY9bPFlEXIIRlUKecfMyKskg qrtyuZF515ZMfunAMFBxgbZ/1h49gKJAqRm7W9jO84T4rvptQNs0eDG/eDW67c7JKp1u MqhGvOuWsbas52gqAe5rXgdZWlK6eehMqfLv/rkWuJ9AAUs5pkXLcAIwwEv/jtlUnzQH fMhg== X-Gm-Message-State: APt69E1vmTRIE6JHUOWGU3g6u1zDRNVk1cix2W/4TRPHTcRp9mLUDqeK JxfOFPNmacmwK89cs4+gX7cuyLCot9kowbtPqcc= X-Received: by 2002:ab0:25d6:: with SMTP id y22-v6mr13834421uan.33.1531145435089; Mon, 09 Jul 2018 07:10:35 -0700 (PDT) MIME-Version: 1.0 References: <20180709134550.29541-1-abrodkin@synopsys.com> <20180709135409.GQ2476@hirez.programming.kicks-ass.net> <20180709140438.ashvw4otyusj3nfa@lakrids.cambridge.arm.com> In-Reply-To: <20180709140438.ashvw4otyusj3nfa@lakrids.cambridge.arm.com> From: Geert Uytterhoeven Date: Mon, 9 Jul 2018 16:10:23 +0200 Message-ID: Subject: Re: [PATCH v3] devres: Explicitly align datai[] to 64-bit To: Mark Rutland Cc: Peter Zijlstra , Alexey Brodkin , Linux Kernel Mailing List , arcml , Linux-Arch , Greg KH , David Laight , Thomas Gleixner , Will Deacon , Greg KH , stable Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 9, 2018 at 4:04 PM Mark Rutland 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