Received: by 10.213.65.68 with SMTP id h4csp3867337imn; Tue, 10 Apr 2018 06:00:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+/fhSizgmvYwb4k4QQ8nll2npt9fYDyfA5carhE7rHZtSieO5KbwYdPn3zvexun/t3GjxL X-Received: by 10.99.151.74 with SMTP id d10mr215867pgo.171.1523365242034; Tue, 10 Apr 2018 06:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523365241; cv=none; d=google.com; s=arc-20160816; b=r9OdXInaknvwLi8dDG10A5v8aUT46VfS6upuqE75FtQnx+NAlxsw6CM61C9zCYf4yS TmFCiAKXR1uHGcoX7cSmUcSEOJt+r17LuDmb9s3U41wqqTwjPkp/HY/W1GQ042Q18qHY fUGvRdUeArl1igWDD39siizu036uLEGuVKvnjoIOlQDpydFx3+efI49ONdrSNWC5VWTJ nA7FEtty7vcUwz3drJvlW3H3w4IrZBWuSzauh1fHddM99rxifB/V7VqDQjXBMFx+lOuU ijkvObxFk2GWUZwWMxHZd7O91hItslQ4/KKpUGU9A9oIcIZ7+esaMpVMPh1n03LO4UdN MDdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=eac1jG3rZJD0f9lmeuIAxoQk6lfNG9tLn8arejvI09k=; b=RTEfPe+QRFzZADEmm9+Q5289q9Q3V3x4fPOruwqF2gllqC5xVmha3RZ0sM/9Gau0iX QFy4gpJtgkMLm/AnOOF5LHYQgoF2REjzw92p1VszhORIFcGP3lbymuCkjdwrgG5C3/ja VnS/UKxMukZJvNhVO93mbrSM7eQoi9OJiwcx+uX2ot1I5tgxirdaIfCUMcB2XeoeusdU gKMCPBbEYZgekVqRr+g95AYbLX4nNxpoF434ZSrS6dT8XyBxts0Wh8sYYsLzE4nDTWWY TNjsxWkNwjmlG1abN8SnOnus+PcxucyvQcBa9sA2DF7shPn23HK3ssPi56lmlfwasjWg 4New== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=s1iOtu9N; 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 d15-v6si2644711pls.232.2018.04.10.06.00.05; Tue, 10 Apr 2018 06:00:41 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=s1iOtu9N; 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 S1753314AbeDJMyB (ORCPT + 99 others); Tue, 10 Apr 2018 08:54:01 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:37194 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753164AbeDJMx6 (ORCPT ); Tue, 10 Apr 2018 08:53:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=eac1jG3rZJD0f9lmeuIAxoQk6lfNG9tLn8arejvI09k=; b=s1iOtu9NhSsPYpEYVXepA0iDU fl/0LNsjQe71K5jBSoSTd0Rg1/V17DaDidluJ3WAtYB+dV6UbOWyPwFBwSUILxrDqvuoHczHliwTC jHkH449Zs7tK4Mn/Zyv7TNuGGZGuf+2fjymBnqniz1s12nO+dexLMYlcGaf7hG0NSnSHbUVtqVa6q fa/O8FutB9yQAgSs+EBQSWJa9qX4hbZEghj+tV2r9rxpaLCEn52H/ueEfv1DrmxItpDD4+ZS4tt6p ZE8KV8IRuxWfbiu8UWcyJnL9gj6PfJbiuSUKf6cllqHcMRu5u8F8wLVgr5ParvtVubw3VBTcrU0Sa 4zcCIDDaQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5smX-0004BT-I1; Tue, 10 Apr 2018 12:53:53 +0000 From: Matthew Wilcox To: linux-mm@kvack.org Cc: Matthew Wilcox , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , linux-kernel@vger.kernel.org, Jan Kara , Jeff Layton , Mel Gorman , stable@vger.kernel.org Subject: [PATCH 1/2] slab: __GFP_ZERO is incompatible with a constructor Date: Tue, 10 Apr 2018 05:53:50 -0700 Message-Id: <20180410125351.15837-1-willy@infradead.org> X-Mailer: git-send-email 2.14.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox __GFP_ZERO requests that the object be initialised to all-zeroes, while the purpose of a constructor is to initialise an object to a particular pattern. We cannot do both. Add a warning to catch any users who mistakenly pass a __GFP_ZERO flag when allocating a slab with a constructor. Fixes: d07dbea46405 ("Slab allocators: support __GFP_ZERO in all allocators") Signed-off-by: Matthew Wilcox Cc: stable@vger.kernel.org --- mm/slab.c | 6 ++++-- mm/slob.c | 4 +++- mm/slub.c | 6 ++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index 38d3f4fd17d7..8b2cb7db85db 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3313,8 +3313,10 @@ slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, local_irq_restore(save_flags); ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller); - if (unlikely(flags & __GFP_ZERO) && ptr) - memset(ptr, 0, cachep->object_size); + if (unlikely(flags & __GFP_ZERO) && ptr) { + if (!WARN_ON_ONCE(cachep->ctor)) + memset(ptr, 0, cachep->object_size); + } slab_post_alloc_hook(cachep, flags, 1, &ptr); return ptr; diff --git a/mm/slob.c b/mm/slob.c index 1a46181b675c..958173fd7c24 100644 --- a/mm/slob.c +++ b/mm/slob.c @@ -556,8 +556,10 @@ static void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node) flags, node); } - if (b && c->ctor) + if (b && c->ctor) { + WARN_ON_ONCE(flags & __GFP_ZERO); c->ctor(b); + } kmemleak_alloc_recursive(b, c->size, 1, c->flags, flags); return b; diff --git a/mm/slub.c b/mm/slub.c index 9e1100f9298f..0f55f0a0dcaa 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2714,8 +2714,10 @@ static __always_inline void *slab_alloc_node(struct kmem_cache *s, stat(s, ALLOC_FASTPATH); } - if (unlikely(gfpflags & __GFP_ZERO) && object) - memset(object, 0, s->object_size); + if (unlikely(gfpflags & __GFP_ZERO) && object) { + if (!WARN_ON_ONCE(s->ctor)) + memset(object, 0, s->object_size); + } slab_post_alloc_hook(s, gfpflags, 1, &object); -- 2.16.3