Received: by 10.192.165.156 with SMTP id m28csp2391796imm; Thu, 12 Apr 2018 13:32:20 -0700 (PDT) X-Google-Smtp-Source: AIpwx49y6ILT1Wgr21flu6sUcdELZe9hbUZvXAnZpx2xog4WX4EoFbSMGzgQR8+lXhepQG+gxi+N X-Received: by 10.101.69.198 with SMTP id m6mr1815962pgr.244.1523565140581; Thu, 12 Apr 2018 13:32:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523565140; cv=none; d=google.com; s=arc-20160816; b=DxDHfY78TMl+4U9iGa9htvI+aSzqxQKEig8vgHoja8T+YSH2c2Z40nuRdlVgSAlOCL S3FGKfP4X17GMRuUmutD9IAnEZ5DDLkivAjVU+25ZxALXphGfMJ2mQkLESIAn13o8wpw kWJDWr3PqWB9/6HsuouUxlcFgODHE/3B7dcEpnLHwZ1q791C6BxTxxZnERf++zAcsPwo xkkhZp7PHD4yY6Iy9Ub1Xz6EuhMBMs8zJJamny1TaLbfBiv5LH0AVcFCvzcIv+PWvHgu 87fmwVF6+AFrQriiFWUHJ/v7j6UrmoFZcjETmfq02lgybRP28o1MvsPbrA9I6bKC13Yj goLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=utwqfw/txclHz4VYI/i9MqnvzjW2HnUJJYX25lUDR8g=; b=bqYXo5+iNg3+S7R9+UkrhTOxOBbVBIIKjg2MqMRzWgGMOll/FgnH48/nOwOwu5Z7/k GsPziEqainGWjbBAXfIqyb9ZFSUjZ4ki901dw3WwzfXF1YV3BcqzHinjVoDxT9yly7UN hCddVsCw79nE3UYEwIFOaVbzdC4UKlAtExkpGqMUnhCE6AionwotaO8U9tO83u2RKIYL JLLMB3NfiQt9611RJA2GqYXNK7B6GUnKInI06sEZoVxZOECwDmRDBDX1j/L1RYfMVOeH 4Vhp6uzDBCsLlNtSM2t8YPD/Yw+cH7tu/S7HcIUg22f08fYBfPCn0NV4bgiRexKW6IdF N3aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=kz9B3KcW; 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 g92-v6si4014517plg.256.2018.04.12.13.32.06; Thu, 12 Apr 2018 13:32:20 -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=kz9B3KcW; 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 S1753551AbeDLTN3 (ORCPT + 99 others); Thu, 12 Apr 2018 15:13:29 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:39806 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753058AbeDLTN2 (ORCPT ); Thu, 12 Apr 2018 15:13:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=utwqfw/txclHz4VYI/i9MqnvzjW2HnUJJYX25lUDR8g=; b=kz9B3KcWzF18FGMDeIhCEcJCy cpVBLrorJGxMyAduTtAmFx0wfjoD/FBed0X+4l/2tCqbdjV4jPwffhuWTx4KRuxp/UBwLWulTGlYR k5pxPItI8hWih/fJePVbiMZy8SYMjWT8Dg8Gmcq1uI1Y84g9Hu5qKbjhCZVtK1T+YaqiiQmaRGehz wjr2snIIBd+cbTGCLXMtbzSDmnoDJfSR634UamvlXi9bqqSWZKsMqf1EYriykNccOnxOL7yaPP2pk lF2n7+cFQgMKCxthJQ4JW3R1qWzPWRXuw+sI2IgCuEVHudPDT/t2LihuehtbNLW07ZP0A5zJMNxc1 Yfx6i5L8A==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6hes-0004bY-LO; Thu, 12 Apr 2018 19:13:22 +0000 Date: Thu, 12 Apr 2018 12:13:22 -0700 From: Matthew Wilcox To: Christopher Lameter Cc: linux-mm@kvack.org, Matthew Wilcox , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , linux-kernel@vger.kernel.org, Jan Kara , Jeff Layton , Mel Gorman Subject: [PATCH v3 2/2] slab: __GFP_ZERO is incompatible with a constructor Message-ID: <20180412191322.GA21205@bombadil.infradead.org> References: <20180411060320.14458-1-willy@infradead.org> <20180411060320.14458-3-willy@infradead.org> <20180411192448.GD22494@bombadil.infradead.org> <20180411235652.GA28279@bombadil.infradead.org> <20180412142718.GA20398@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180412142718.GA20398@bombadil.infradead.org> User-Agent: Mutt/1.9.2 (2017-12-15) 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 Acked-by: Johannes Weiner Acked-by: Vlastimil Babka Acked-by: Michal Hocko --- mm/slab.c | 2 ++ mm/slob.c | 4 +++- mm/slub.c | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/slab.c b/mm/slab.c index 58c8cecc26ab..aca63d49b270 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -2661,6 +2661,7 @@ static struct page *cache_grow_begin(struct kmem_cache *cachep, invalid_mask, &invalid_mask, flags, &flags); dump_stack(); } + WARN_ON_ONCE(cachep->ctor && (flags & __GFP_ZERO)); local_flags = flags & (GFP_CONSTRAINT_MASK|GFP_RECLAIM_MASK); check_irq_off(); @@ -3067,6 +3068,7 @@ static inline void cache_alloc_debugcheck_before(struct kmem_cache *cachep, static void *cache_alloc_debugcheck_after(struct kmem_cache *cachep, gfp_t flags, void *objp, unsigned long caller) { + WARN_ON_ONCE(cachep->ctor && (flags & __GFP_ZERO)); if (!objp) return objp; if (cachep->flags & SLAB_POISON) { 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 a28488643603..0487d316a665 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2434,6 +2434,8 @@ static inline void *new_slab_objects(struct kmem_cache *s, gfp_t flags, struct kmem_cache_cpu *c = *pc; struct page *page; + WARN_ON_ONCE(s->ctor && (flags & __GFP_ZERO)); + freelist = get_partial(s, flags, node, c); if (freelist) -- 2.16.3