Message ID | b1f490b450b14dd754a45f91bb1abd622ce8d4f7.1695935486.git.christophe.jaillet@wanadoo.fr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3779864vqu; Thu, 28 Sep 2023 21:43:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMZqYiw9p8qH/pAUeYbCo2NvRj0fW2bcKxkePOCjo4iPJ5KUvEnT+gBlhHm5ZMM6gnr/40 X-Received: by 2002:a05:6358:7e92:b0:139:e7db:3f3f with SMTP id o18-20020a0563587e9200b00139e7db3f3fmr3591561rwn.10.1695962596701; Thu, 28 Sep 2023 21:43:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695962596; cv=none; d=google.com; s=arc-20160816; b=lrZnHDQHKAF180xMbtx2YitQmi2GJdZqNNlF/w8gmeERvcQyDLtKlyXurkb/M7hdVC 5xX/4FoaLp+BV2SDLdaQOt+KCndXGI8joR5JP57Iupk7kUQSdmzsE8bX/tMHTacgddKW eHF0R5UDw2by+q0Akkzjm5lhW3qZtThfp/WgeaRIFc+MwjL5u40zvJEnZSP5aM+YHBXV JULsvCvCOp0ibka8rrGZZ+VpDFG4lpNYb2HDu0a3tCXM9n7tCkEgDyWJW4qo9vaFlKZk lzmCzaHdSSSeoglIpBOTBdBe86al3bOZvnJJap48rqfLTvaOoWv/3NxWDs5bxzGNtiWn XVNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=CT0rFoQj+YDKwuwWbEo3e5SQCHTQDs01F+cu4QFHXgE=; fh=MFhZbGUUoVYiNzHAuFIsirbI3IhzhFf1PPducs4mZAM=; b=gqupByW8tfEwINpu166VEr/9uun+2ULPNkkI1GJBMAG9+kfYbyRfLAHCJms95vhx7/ e1ADY6MldMjpd6o+ocBEExLWR6BiVjpMKIs78IJ0USuEqxo1QeJXRlU5h/z78Fa0qvK1 rz4XNyKSZnIC3n2tInbqzeCZBvJhYW3O9BVOfEyCFxKPxuzfDJomnMX3DaYINnc9PNBM U+6szOccJ2P5EY91PhhnNrsvfQJOTDM6ClMyU/RFBy/PvMTjhv2r5UZT3jgXdCTM9ViP 2qezWJz/M3ukidhLvR1HBce/LCeHuYM4Hzr8PomgUmPoEHC5eE8vJC6QngAn4nhMtNZ3 xNAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=GKDTgvqa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id bg26-20020a056a02011a00b00578c4d1f530si19589491pgb.728.2023.09.28.21.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 21:43:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=GKDTgvqa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 6CC8F835C214; Thu, 28 Sep 2023 14:12:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232527AbjI1VMF (ORCPT <rfc822;pwkd43@gmail.com> + 22 others); Thu, 28 Sep 2023 17:12:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232482AbjI1VMC (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 28 Sep 2023 17:12:02 -0400 Received: from smtp.smtpout.orange.fr (smtp-15.smtpout.orange.fr [80.12.242.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26C291B9 for <linux-kernel@vger.kernel.org>; Thu, 28 Sep 2023 14:11:51 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id lyIVqxYRoFUAIlyIVqcqAN; Thu, 28 Sep 2023 23:11:50 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1695935510; bh=CT0rFoQj+YDKwuwWbEo3e5SQCHTQDs01F+cu4QFHXgE=; h=From:To:Cc:Subject:Date; b=GKDTgvqa9RYXrDd7JRIRmjq5ZV7qkctMPq1hXE3q0NsVLQwHqbGamk6UI1d2nPUpt wmUHjQPqpiZSvfFThnPHZQ2OsNfff/EifuIlFkkCm4pxAgDynuyUt10RDW0/PDJ/aT UPvUPd+uHpExnaTjcnrfd/tYK46sKW2p98W/51Fz1R9mWWGcR56KziyEuF2+VLXSIx x2k+9Ab7Qqdyrc34Tu/2AY4DWIj8qCuvaBo7SBAEZBcTRIkJjOanuxFrmrAjQBGHDf 6F4KAUSeyAOuIB+DMWS8I1GmEtE34dvPw1W+jfFqPlRRlsQO+Mh3i1Z3wEOm/fA+hQ aj0DiKIrWPF5A== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Thu, 28 Sep 2023 23:11:50 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: Matthew Wilcox <willy@infradead.org>, Andrew Morton <akpm@linux-foundation.org>, "Liam R. Howlett" <Liam.Howlett@Oracle.com> Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, linux-fsdevel@vger.kernel.org Subject: [PATCH] radix tree test suite: Fix a memory initialization issue Date: Thu, 28 Sep 2023 23:11:45 +0200 Message-Id: <b1f490b450b14dd754a45f91bb1abd622ce8d4f7.1695935486.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 28 Sep 2023 14:12:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778345675939563481 X-GMAIL-MSGID: 1778345675939563481 |
Series |
radix tree test suite: Fix a memory initialization issue
|
|
Commit Message
Christophe JAILLET
Sept. 28, 2023, 9:11 p.m. UTC
If __GFP_ZERO is used, the whole allocated memory should be cleared, not
the first part of it only.
Fixes: cc86e0c2f306 ("radix tree test suite: add support for slab bulk APIs")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
tools/testing/radix-tree/linux.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
* Christophe JAILLET <christophe.jaillet@wanadoo.fr> [230928 17:11]: > If __GFP_ZERO is used, the whole allocated memory should be cleared, not > the first part of it only. > > Fixes: cc86e0c2f306 ("radix tree test suite: add support for slab bulk APIs") > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > --- > tools/testing/radix-tree/linux.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/linux.c > index d587a558997f..8ab162c48629 100644 > --- a/tools/testing/radix-tree/linux.c > +++ b/tools/testing/radix-tree/linux.c > @@ -172,7 +172,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t size, > if (cachep->ctor) > cachep->ctor(p[i]); > else if (gfp & __GFP_ZERO) > - memset(p[i], 0, cachep->size); > + memset(p[i], 0, cachep->size * size); > } > } This doesn't look right. In fact, I think you have taken a bug and extended it to clear the bugs over-allocation worth of memory. The bulk allocator allocates to the array (here it's p) of a given size (size). Each kmem_cache has a size pre-set, that is, each allocation from that cache is of size cachep->size. What you are doing is zeroing each pointer for the entire size of the allocation for the entire range, and not just one elements worth. This isn't crashing because we are allocating too much memory to begin with. Note that this zeroing is in a for loop: for (i = 0; i < size; i++) { ... } So, really the bug is that we are over-allocating and not that we aren't zeroing the entire thing. If you drop size from these arguments and use LSAN to check that things are not overrun, then you will see that we can reduce the allocation by a lot and still run correctly. Thanks, Liam
diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/linux.c index d587a558997f..8ab162c48629 100644 --- a/tools/testing/radix-tree/linux.c +++ b/tools/testing/radix-tree/linux.c @@ -172,7 +172,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t size, if (cachep->ctor) cachep->ctor(p[i]); else if (gfp & __GFP_ZERO) - memset(p[i], 0, cachep->size); + memset(p[i], 0, cachep->size * size); } }