Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1539416ybx; Thu, 7 Nov 2019 13:20:54 -0800 (PST) X-Google-Smtp-Source: APXvYqzDwqeYfG95teE4v8+RuTNCGGOavMAIrYqxNZH4EQIrkLU/DjJP2/Tvp/TARuMwWV6qQadJ X-Received: by 2002:a50:fc1a:: with SMTP id i26mr6433122edr.9.1573161654103; Thu, 07 Nov 2019 13:20:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573161654; cv=none; d=google.com; s=arc-20160816; b=LBxkNv2n5wYH/T7TrzUGQyRWqIxVL+MV43E6YK8K3gZ8VQqHY/9jiIklqdg41mcqoN xTVirKXqyjqUqFuSybZm4+9mx4p42CEJv3qbKYJr192IUQ9BnpW2D2E9N0p8xnYv8RU7 nfvbJUD4tzWr7z2Sl0DKdw2Tuk/0GSzuLspnRy96w1a0JmSeDpIfeyMhgZob2kUNfEpX 29d30cC2g8wReLDCnF+nHgkpjTnN38u9GldRZHYxc3ppQoMeiKGZE9UPX9rrpC/t4zlq t8i1sgT0+paUDqZYsGkO02KiNUbLBxx6zagAdZKzfn7J8KB9g1dN8FZry5PgkTbPBxvf 485w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=viAE1CpzSxuRD/BH/MsOEcY+j2yNDU+1S4harELGxYA=; b=Yhqd84Oat55G+Jxl+eyH59zwJx8hudJIgrDLaEjGTzFU/dgEJ8ob8SX59pGy68vupE o742NdG/s5udkp9WjFxs0dFXzXtyskHMxyboGT1vmpATD51wu9dhhFbckG6uQQm5k7Mk 12UncPyl2KYXagx3jqdzS/r9ex6w7qMqCEhpLK26uCyVLxOZjmJEmHqtejXDWTU2r9qj 1l8x72Ko0eot5bS5keU2rFGUkHbW+/ngrK0iKS/IgyEfKJTmZsmYS5xsZanIds39jHNZ qvIA1ottIG2tjkLEMBnUT5SAOswc4cv7tIA2SuYRPUOgkVPBngtFN0GSgGTTN35WetWk DiGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=L7v0SvPM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c23si2416854ejk.143.2019.11.07.13.20.29; Thu, 07 Nov 2019 13:20:54 -0800 (PST) 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=pass header.i=@chromium.org header.s=google header.b=L7v0SvPM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726101AbfKGVTy (ORCPT + 99 others); Thu, 7 Nov 2019 16:19:54 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:42998 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725770AbfKGVTy (ORCPT ); Thu, 7 Nov 2019 16:19:54 -0500 Received: by mail-pg1-f195.google.com with SMTP id q17so2770415pgt.9 for ; Thu, 07 Nov 2019 13:19:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=viAE1CpzSxuRD/BH/MsOEcY+j2yNDU+1S4harELGxYA=; b=L7v0SvPM5wqtmIimdjoJlflFSCiarLVuMjw5tUDVJV49TBb/GIt3CUBOIRdHA3BebG Ve5aORzfLA3uMKYoSVZ1gtyANrv2YIhfT/YcS6c3Q8pkkKaEMXiPnQ6k95ZHy7YBdqKu wHLJLsaK2CXPSDDGzOxGxu8cIP/NX7P3BJYgA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=viAE1CpzSxuRD/BH/MsOEcY+j2yNDU+1S4harELGxYA=; b=uLGIB7ofLw5aBtkaT3vRYP0w/D72o/g63OkodR4uQrlXn80XC0uDO7aVztI8AphqH6 2PbPb35m8GRpsN9GdVCukxT3qjMbMDnB3a8Y+EoKD8X8DTlnpp/rKzOYg75WKYu3Td+7 Et2IBCLOz9mh2L2uiUHDYDprInWOX0+J4bXnZfRTaHvRt+6eRmQf95TgjY/N6dPzj1Wu LP7UcKwEe0NEFbPpUC6o+unCMxEq6HPCDSitJ6TBtwpmoqVL9soduvN24pjBXBTtUEqO BsCFEz4qoJmnzwczNJyDwCnYlADL69yRRmd3LT+2Hgr4VvJ2MStqDy8Zqr5uRSXCS1RU 4alw== X-Gm-Message-State: APjAAAWTFavl0CU0sptS/bOjFEfNXjHab1hZrIJ8jm1n6eM8JrUxun4y RZlgK3jv8K12pNCXiNaOMBoR1A== X-Received: by 2002:a63:5c21:: with SMTP id q33mr7533017pgb.61.1573161592677; Thu, 07 Nov 2019 13:19:52 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id r13sm3040014pgh.37.2019.11.07.13.19.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 13:19:51 -0800 (PST) Date: Thu, 7 Nov 2019 13:19:50 -0800 From: Kees Cook To: Laura Abbott Cc: Alexander Potapenko , Christoph Lameter , Nick Desaulniers , Kostya Serebryany , Dmitry Vyukov , Sandeep Patil , Jann Horn , Marco Elver , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Subject: Re: [PATCH] lib/test_meminit.c: Add bulk alloc/free tests Message-ID: <201911071318.A2FB7A9@keescook> References: <20191107191447.23058-1-labbott@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191107191447.23058-1-labbott@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 07, 2019 at 02:14:47PM -0500, Laura Abbott wrote: > > kmem_cache_alloc_bulk/kmem_cache_free_bulk are used to > make multiple allocations of the same size to avoid the > overhead of multiple kmalloc/kfree calls. Extend the kmem_cache > tests to make some calls to these APIs. > > Signed-off-by: Laura Abbott Thanks! Andrew, can you add this to -mm please? Reviewed-by: Kees Cook -Kees > --- > lib/test_meminit.c | 20 +++++++++++++++++++- > 1 file changed, 19 insertions(+), 1 deletion(-) > > diff --git a/lib/test_meminit.c b/lib/test_meminit.c > index 9729f271d150..20f330948b92 100644 > --- a/lib/test_meminit.c > +++ b/lib/test_meminit.c > @@ -183,6 +183,9 @@ static bool __init check_buf(void *buf, int size, bool want_ctor, > return fail; > } > > +#define BULK_SIZE 100 > +static void *bulk_array[BULK_SIZE]; > + > /* > * Test kmem_cache with given parameters: > * want_ctor - use a constructor; > @@ -203,9 +206,24 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor, > want_rcu ? SLAB_TYPESAFE_BY_RCU : 0, > want_ctor ? test_ctor : NULL); > for (iter = 0; iter < 10; iter++) { > + /* Do a test of bulk allocations */ > + if (!want_rcu && !want_ctor) { > + int ret; > + > + ret = kmem_cache_alloc_bulk(c, alloc_mask, BULK_SIZE, bulk_array); > + if (!ret) { > + fail = true; > + } else { > + int i; > + for (i = 0; i < ret; i++) > + fail |= check_buf(bulk_array[i], size, want_ctor, want_rcu, want_zero); > + kmem_cache_free_bulk(c, ret, bulk_array); > + } > + } > + > buf = kmem_cache_alloc(c, alloc_mask); > /* Check that buf is zeroed, if it must be. */ > - fail = check_buf(buf, size, want_ctor, want_rcu, want_zero); > + fail |= check_buf(buf, size, want_ctor, want_rcu, want_zero); > fill_with_garbage_skip(buf, size, want_ctor ? CTOR_BYTES : 0); > > if (!want_rcu) { > -- > 2.21.0 > -- Kees Cook