Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp580973lqz; Sat, 30 Mar 2024 09:12:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU1hr9LRwOJtCBVkFgSaRxjpxxWehXXG+E1KGfcqGV5zz1vkZHIR//zIooqV3H50U512aCcpQewQKZ5Cv387JIOjry2As+TybYNkQrBvw== X-Google-Smtp-Source: AGHT+IHh2KV6Pr8fdwu/wsZm7wNETpEzMMlrVMEGZLjIZplx3fxpftcxWsslV8pKOr5ln3KazyXe X-Received: by 2002:a50:d4ca:0:b0:568:b95f:5398 with SMTP id e10-20020a50d4ca000000b00568b95f5398mr3482521edj.38.1711815152678; Sat, 30 Mar 2024 09:12:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711815152; cv=pass; d=google.com; s=arc-20160816; b=Gko7QC5lNuEcuSbWbMHFTZNLvf1Pp1P+Nu1EzD45f+fDo9HfizwUVX5HtYkE0qVJwd H0muFv68IWRo/7gbyI4qXMKDhQvG7/M4QiNsKX7+NEyNWc+/04Cb/4QgSVT3YwdH782G BN4ItG9VODxISXG8Ib0PTBY9FukSOC013lr2eWLhwW5nnsMb8jcEDnB/kNPtDCEwFDKA 1Y+FErGZ4gbxhuWBSOmCGk6IJcpLSGE3jJ3jaQRl6Ya4NvdzEvuJenTNcFamnCj9FWBn DeMLRPLDvSZOL9VTCUd4g+E6o26mD7OtZcqrgEPE8WGXxZ2KpxFJ08O0wqMGSRrNAYyu gQSw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=VuED0/sVIh8KQLjRLLbr/tL7jhlAbkA01H5Fl7DSpi0=; fh=OfVyiCjY6bx9rSHKxrFdMZFuyCzo+fCL/fafeaDkmBk=; b=s2l3gdGv+gp028IlKaCKfvx7NRSOl6vhc9JvyzLJPhqIqpzj94eQ56vSe0S1x3B9xt Ch3lq6s/kR9v+GpSgPdQZ3wCBGCDC9a9xdtTgIk4KZN6xmc9JgCnfDJW8oG/3EAfFHkN tCrDV09XWfQdEwYAKTM76n1RN+THDI8t6oGZ6ofuXck7ll5zHsj25iTAfkxkB5fUJSSX hQnk6GqTbmWgmAsr9Ty4rtDNid0JVq5TuWz4AAhIJ/bz3cuwEdBSP0wpL1vn/f2q9Eu/ pJgy5sVIdXIBBdx8rE3QZtBb3m4QzQTa+podycSmoiNPeNdJ26JiVUv8Eb8ocGot8z10 UIaQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=m5yyjZZx; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-125775-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125775-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u12-20020a50d50c000000b0056bea228099si2808784edi.174.2024.03.30.09.12.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:12:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-125775-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=m5yyjZZx; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-125775-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125775-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 79E631F21AD0 for ; Sat, 30 Mar 2024 16:12:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F3293BB2A; Sat, 30 Mar 2024 16:12:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="m5yyjZZx" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 632128467; Sat, 30 Mar 2024 16:12:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711815142; cv=none; b=Gtg6dPScUZXoP6ABT/VPJ9ZMj+42YNSdiWJpRD65Lv0Uv4af+0zziNhZKUVxqmi+H+I9j3JeLiITN/LUbaGIiKafYB2qs786NUD7Cjmma/MLItz7rGFTYVl3FDQZ88TybXpXy+WaFU060PAJn8yMmiuNDPNN/k1ypirzkbbSjhs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711815142; c=relaxed/simple; bh=7DJY80SqsN2zeO08mKaZocYC36hJgIIyI/nQTHv2yrU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eZ8dIDYk+3RGNmKnN0spStMzc4+ILXegENLk63pSOJOLI9TgKj3lX2yCGC6qiMw+1j4tS0CpkF2GaKFyt5lg1Z0QUbsdgNbGRVdqQhaU++4iWBBBVd5PWWigLaJAqB5CRAxPSukA/kHibpWvt2VNq1DcAA8PlYLRvKHuRT8bUIM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=m5yyjZZx; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76F7DC433F1; Sat, 30 Mar 2024 16:12:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1711815142; bh=7DJY80SqsN2zeO08mKaZocYC36hJgIIyI/nQTHv2yrU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=m5yyjZZxH/klvWCBqIoRuOHkVpGXYh6HA/sHEABnoAgryF8I8SAM+MGoRMAK/g3wa VWWANrzP0+SrtPxZLoSYHQv8bDh4Vrjh+L2kYzartfBynhg7AtgOr+N9D32OoW54PM 875jr+Sl46wU5PJ7IIT3IogAgVhpDkaHF968PPPo= Date: Sat, 30 Mar 2024 17:12:18 +0100 From: Greg KH To: Ayush Tiwari Cc: alison.schofield@intel.com, paul@paul-moore.com, mic@digikod.net, fabio.maria.de.francesco@linux.intel.com, linux-kernel@vger.kernel.org, outreachy@lists.linux.dev, linux-security-module@vger.kernel.org Subject: Re: [PATCH v2] landlock: Use kmem for landlock_object Message-ID: <2024033030-tutu-dynamite-47c9@gregkh> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Sat, Mar 30, 2024 at 07:24:19PM +0530, Ayush Tiwari wrote: > Use kmem_cache replace kzalloc() calls with kmem_cache_zalloc() for > struct landlock_object and update the related dependencies to improve > memory allocation and deallocation performance. So it's faster? Great, what are the measurements? > This patch does not > change kfree() and kfree_rcu() calls because according to kernel commit > ae65a5211d90("mm/slab: document kfree() as allowed for > kmem_cache_alloc() objects"), starting from kernel 6.4 with > CONFIG_SLOB, kfree() is safe to use for such objects. There is no CONFIG_SLOB anymore so why mention it? > > Signed-off-by: Ayush Tiwari > --- > > Changes in v2: Used clang-format and corrected the removal of kfree_rcu. > Tried to use KMEM macro but due to lack of cache pointer in that macro, > had to explicitly define landlock_object_cache, as done in security.c. > > security/landlock/object.c | 12 +++++++++++- > security/landlock/object.h | 2 ++ > security/landlock/setup.c | 1 + > 3 files changed, 14 insertions(+), 1 deletion(-) > > diff --git a/security/landlock/object.c b/security/landlock/object.c > index 1f50612f0185..cfc367725624 100644 > --- a/security/landlock/object.c > +++ b/security/landlock/object.c > @@ -17,6 +17,15 @@ > > #include "object.h" > > +static struct kmem_cache *landlock_object_cache; > + > +void __init landlock_object_cache_init(void) > +{ > + landlock_object_cache = kmem_cache_create( > + "landlock_object_cache", sizeof(struct landlock_object), 0, > + SLAB_PANIC, NULL); You really want SLAB_PANIC? Why? > +} > + > struct landlock_object * > landlock_create_object(const struct landlock_object_underops *const underops, > void *const underobj) > @@ -25,7 +34,8 @@ landlock_create_object(const struct landlock_object_underops *const underops, > > if (WARN_ON_ONCE(!underops || !underobj)) > return ERR_PTR(-ENOENT); > - new_object = kzalloc(sizeof(*new_object), GFP_KERNEL_ACCOUNT); > + new_object = > + kmem_cache_zalloc(landlock_object_cache, GFP_KERNEL_ACCOUNT); Odd indentation, why? thanks, greg k-h