From patchwork Fri Oct 18 16:57:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 3069031 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id ACC029F372 for ; Fri, 18 Oct 2013 16:58:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 842B7203B5 for ; Fri, 18 Oct 2013 16:58:16 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 23760204D3 for ; Fri, 18 Oct 2013 16:58:15 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VXDNM-0002Tz-AD; Fri, 18 Oct 2013 16:58:12 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VXDNJ-0001wH-Qt; Fri, 18 Oct 2013 16:58:09 +0000 Received: from mail-we0-f170.google.com ([74.125.82.170]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VXDNG-0001vE-UL for linux-arm-kernel@lists.infradead.org; Fri, 18 Oct 2013 16:58:07 +0000 Received: by mail-we0-f170.google.com with SMTP id u57so4084789wes.29 for ; Fri, 18 Oct 2013 09:57:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=uB5SEghR11MvFgLCe1WwhwFoHChit7AKvg1xqcvJlSM=; b=Ugduw8G+emdDKXcFloNkuvCWfs+XM9bklybxl87esTijnz2BFHYNNlV8dcLBnv2+cT KqubbCO1mIGOVX8R2db5a8mHh0vrlsAWnECv8o9BVYp//rtYAXNso2mcSaDi3MuDnx5P FBKYC1vmUMbYUsmfsOXkUoxKzoRIgqCyE48W2MUVqVZ06C4UrkGtdEb1wDiypvht5Ryr tyLER+dFgcWakKbBu/PN7adb4Zsg7tzRYx3luJCPoqM1MeNoyWTyZ5BWngx/oxWKOmyG HCIF89+Sk+bY7ZSEXwiSUNzr2KpUXAblilyPNwjTuJXfLNXTWvBs8bNhHX/95fP6JVRg wJpQ== X-Gm-Message-State: ALoCoQmt9Df5Q1UzFe9xomO8eQCOtb1I5t+kvO597dUGDzqZmDu7gZDFIvoBfen4VA91cNjjNQBW MIME-Version: 1.0 X-Received: by 10.180.72.148 with SMTP id d20mr150097wiv.21.1382115463665; Fri, 18 Oct 2013 09:57:43 -0700 (PDT) Received: by 10.180.198.51 with HTTP; Fri, 18 Oct 2013 09:57:43 -0700 (PDT) In-Reply-To: <20131011131138.3bc5b2acf60df3a5d79d0d24@linux-foundation.org> References: <1381296747.2040.17.camel@joe-AO722> <20131011131138.3bc5b2acf60df3a5d79d0d24@linux-foundation.org> Date: Fri, 18 Oct 2013 09:57:43 -0700 Message-ID: Subject: Re: [RFC PATCH] device: Add kernel standard devm_k.alloc functions From: Kevin Hilman To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131018_125807_108939_7F9FB857 X-CRM114-Status: GOOD ( 23.80 ) X-Spam-Score: -2.6 (--) Cc: Sangjung Woo , Greg KH , Olof Johansson , LKML , Tejun Heo , Thierry Reding , linux-arm-kernel , Joe Perches , Guenter Roeck X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Oct 11, 2013 at 1:11 PM, Andrew Morton wrote: > On Tue, 08 Oct 2013 22:32:27 -0700 Joe Perches wrote: > >> Currently, devm_ managed memory only supports kzalloc. >> >> Convert the devm_kzalloc implementation to devm_kmalloc >> and remove the complete memset to 0 but still set the >> initial struct devres header and whatever padding before >> data to 0. >> >> Add the other normal alloc variants as static inlines with >> __GFP_ZERO added to the gfp flag where appropriate: >> >> devm_kzalloc >> devm_kcalloc >> devm_kmalloc_array >> >> Add gfp.h to device.h for the newly added static inlines. >> >> ... >> >> --- a/drivers/base/devres.c >> +++ b/drivers/base/devres.c >> @@ -91,7 +91,8 @@ static __always_inline struct devres * alloc_dr(dr_release_t release, >> if (unlikely(!dr)) >> return NULL; >> >> - memset(dr, 0, tot_size); >> + memset(dr, 0, offsetof(struct devres, data)); > > Well, this does make some assumptions about devres layout. It would > have been cleaner to do > > memset(&dr.node, 0, sizeof(dr.node)); > > but whatever. > > I made some changelog changes. > > I agree that including devm_kmalloc_array() might be going a bit far > (it's the lack of devm_kmalloc which matters most). But > devm_kmalloc_array() is inlined and is hence basically cost-free until > someone actually uses it. A handful of boot panics on ARM platforms were bisected to point at the version of this commit that's in linux-next (commit 64c862a839a8db2c02bbaa88b923d13e1208919d). Reverting this commit makes things happy again. Upon further digging, it seems that users of devres_alloc() are relying on the previous behavior of having the memory zero'd which is no longer the case after $SUBJECT patch. The change below on top of -next makes these ARM boards happy again. Kevin [1] From 16489e16c8efdda791e96bd591e455e7c7739f98 Mon Sep 17 00:00:00 2001 From: Kevin Hilman Date: Fri, 18 Oct 2013 09:41:39 -0700 Subject: [PATCH] devres: restore zeroing behavior of devres_alloc() commit 64c862a8 (devres: add kernel standard devm_k.alloc functions) changed the default behavior of alloc_dr() to no longer zero the allocated memory. However, only the devm.k.alloc() function were modified to pass in __GFP_ZERO which leaves any users of devres_alloc() or __devres_alloc() with potentially wrong assumptions about memory being zero'd upon allocation. To fix, add __GFP_ZERO to devres_alloc() calls to preserve previous behavior of zero'ing memory upon allocation. Signed-off-by: Kevin Hilman --- drivers/base/devres.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) return dr->data; diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 37e67a2..e3fe8be 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -136,7 +136,7 @@ void * devres_alloc(dr_release_t release, size_t size, gfp_t gfp) { struct devres *dr; - dr = alloc_dr(release, size, gfp); + dr = alloc_dr(release, size, gfp | __GFP_ZERO); if (unlikely(!dr)) return NULL;