Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp105724lqh; Wed, 27 Mar 2024 16:44:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX2Vr6vIo2m4aVAIofIqkvNpvO15891Bh0I3n73ntTjZamk8aCsQ7EufgEXXv5DSbGc9odMwujMKOYp9pC9v4U1CugljIhW1mOd3kiTGA== X-Google-Smtp-Source: AGHT+IGpPl4jETipIqyHtTiy5XEcYiXWMe8JeSMEb4YYlMmlUMFVQW1YHv54C7VK6bbF8kXbEZ91 X-Received: by 2002:a17:902:f64c:b0:1e0:2a5f:d1d6 with SMTP id m12-20020a170902f64c00b001e02a5fd1d6mr1465849plg.63.1711583080258; Wed, 27 Mar 2024 16:44:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711583080; cv=pass; d=google.com; s=arc-20160816; b=RqTN85xKJ2dzfBspKjNq0vq1mdO3uAk6ndkcMoeGp3mEsBwPc311NjaFZQybksllR+ 4xXgG/MeHSJ1TEX6nGnDc5piz34BZFj+vZZtToVgLIYIoLfH34YgZqZf/wA/50VWF9bG BrZ324bjBMG4+a6j0Wz4KLLBA/uU5EI8LTX4XdXl7HXbcdOwsMS4IZorqKadMFN1zAnm xQNrDDDIhJ6Nqj/rOUlbRy9eozGeol03dgucVku7KZbYzRz7BsGJjUQKaOCHu3gQLkOW JpoBotG8fliVrNp7VqtXqFmjbNs0MtqmJw72DZ1Hb9VeyrPCAzyM51C4G9GUP3EaRvYd 6SRA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=DsqU9PXjgnx5iMV4Gv2GAE/CJCMtgSBEOxF0nZeWP9w=; fh=+ddIPTcDWEUMsd6e8o6zR5UQyCHjVrnd3asiQzyhBGA=; b=Z9CZKe8/e+dWtPT12jGmeEDvIE8QhMfVEWpkneouioGwJjs3O/Wdd+B0kdwJ/nh5yF 5J22C/hQI8a9A4+/fUMHUQBRujYMg+fTZyHZRz5CU3D7WM8Bkl84hJ/8Z50yl2yVqStT fTqu3vyYquVzMqgrdGiXWvMcFiL4LJwT0Zdax4JuMc6qOzuuOrcjE4S6c5CvtH0vW9TC 9BpbnHhzF9KekY6MEDH9+hId5bAy4GLKMhKIBV/gkS4emT9BrPpu7jOWFiXKiUNCqupL 4fvWawloKcur5+ha8OX0oZeZhlLLlXfLEZLVDp8dngRkfgagr8MCEUV6Y/gasyk6gtfA e7uQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=DnKqWhRk; arc=pass (i=1 spf=pass spfdomain=paul-moore.com dkim=pass dkdomain=paul-moore.com dmarc=pass fromdomain=paul-moore.com); spf=pass (google.com: domain of linux-kernel+bounces-122193-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122193-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z12-20020a170902834c00b001dddd1df881si162688pln.295.2024.03.27.16.44.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 16:44:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122193-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=DnKqWhRk; arc=pass (i=1 spf=pass spfdomain=paul-moore.com dkim=pass dkdomain=paul-moore.com dmarc=pass fromdomain=paul-moore.com); spf=pass (google.com: domain of linux-kernel+bounces-122193-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122193-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 83C52295B22 for ; Wed, 27 Mar 2024 23:43:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3475C152E01; Wed, 27 Mar 2024 23:43:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b="DnKqWhRk" Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 926C01534EC for ; Wed, 27 Mar 2024 23:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711583030; cv=none; b=ug5S7dqE5aR00W7aZUjui4ngOx8qbNPMeoDFUCBCqMQHZDepxPvFbQvQpLvJMCvaiKksaz6VLumJyK9s2pCffjsWjyvho0ionCizx1Sl6mYAakA8J7CYMfiYiGlQvsBnLobdbBcx3ZcX+stspRJrwnDAougVYHVEEPhlI/EsR/Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711583030; c=relaxed/simple; bh=LHSTVg05tlSrlDZR4E07ykDqUEUkIg1dZ8Yhyx6TfZs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=VdXJeKIHo0R0IbV1N8FhGSe+TV/Ez6Era1hsUiHwfD62NMKmKFW53TbzEFitFkSQpOnLOQVzY2Q8jABw2YLNqqtsAdPXMTRBcEPTZQx4f24jIeG3SJk7k+K5JgIAQ7+PhT8CnDhNXZlxKRPGmDyDYriGyn0qJaeBxw+ivQApMR8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com; spf=pass smtp.mailfrom=paul-moore.com; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b=DnKqWhRk; arc=none smtp.client-ip=209.85.128.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paul-moore.com Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-609f060cbafso4789127b3.0 for ; Wed, 27 Mar 2024 16:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1711583027; x=1712187827; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DsqU9PXjgnx5iMV4Gv2GAE/CJCMtgSBEOxF0nZeWP9w=; b=DnKqWhRkNNFRkN868BBDfaaMasrOZKbpuo0lu9nfxAodgZgqnBd+dl11LpF4xphv/H zN+cKxH7oiigp9Fq4z5ZMIVFJBoHofUnUhX5nC4xNURk6LopWDajhp75pc9WfE6wEED1 OYLmuq5WPwu2ryBPp6X8IranWoHPIlEnh4xvx88swtCs1l/zg6KxTs9JRzMcg7+qrdiH v6uZjfSB6WrKiTvEgzbZP4QiZBRSMnv7ZWswLnGVLLblmVHidLOsoiH43bAmMMZhbGRb /Ket1pwRvZxsAeEEHHj6vyUlef2YMoi98HnZmnzPLGREBdbIPs6d5As52Upm8E0Oawq4 OA+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711583027; x=1712187827; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DsqU9PXjgnx5iMV4Gv2GAE/CJCMtgSBEOxF0nZeWP9w=; b=Hgu55rsz/A/RbvFAJaWtmQiIAbROm/RizcMl4L4Nts+KrxHg8e+wTWsnSPDZVkNaO/ NXcwcxUTcWSumktrHe/0JPVWA7spkBz0+Lenr2CPbwL1IERPHoulJ+CQrwInF4HYu94T 00635AT3pBppaZaPn9SLvxXGrrm6VEsLcMLij2JWhjoPSyiRWdOAjnWT6uw6Q4yAaEFS wJjhIujCw0AysyGicYwLsRQMhJ7W7jaKaHeSR4IDClC8o2WGMYag2ZIuLBjz9Z8NxdrA hj6ZpLUmvy9PBI8shbuOX4XoJy90YQJqraMMmJCrpVd0pYG2WfyCVM0SyuVz+Piho4Yd qIOw== X-Forwarded-Encrypted: i=1; AJvYcCUdA5JQyqVwrrJBs0RVY6TPn3sAQssV9hB9rjlmQJdrA2+bCgealOwtzsCrOnoPP2QuZ9BJQ0Z2vgTwpvKcoNW4mO8Z/RVyg2L+YADh X-Gm-Message-State: AOJu0Ywh0yKjzGP5zKqMN5dRuoMsCLhQ8b/3fkIepuOnuvjU9tqCzWoM xQtU2YQTA8fG8id8ji3XlTJPqFKjqB9yhrgPt3FNMCk2uuCx0whEPIIlG9u8rrsF1Rkq/o3epuM A3vglP2KBwwJXRCmSa0BgStM4/oQ9Oq8XQjgg X-Received: by 2002:a81:8397:0:b0:611:1eee:3af3 with SMTP id t145-20020a818397000000b006111eee3af3mr1296551ywf.7.1711583027605; Wed, 27 Mar 2024 16:43:47 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Paul Moore Date: Wed, 27 Mar 2024 19:43:36 -0400 Message-ID: Subject: Re: [PATCH] LANDLOCK: use kmem_cache for landlock_object To: Ayush Tiwari Cc: alison.schofield@intel.com, mic@digikod.net, fabio.maria.de.francesco@linux.intel.com, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, outreachy@lists.linux.dev, linux-security-module@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Mar 27, 2024 at 7:26=E2=80=AFPM Ayush Tiwari wrote: > > Use kmem_cache replace kzalloc() calls with kmem_cache_zalloc() for > struct landlock_object and update the related dependencies. > > Signed-off-by: Ayush Tiwari > --- > security/landlock/fs.c | 2 +- > security/landlock/object.c | 14 ++++++++++++-- > security/landlock/object.h | 4 ++++ > security/landlock/setup.c | 2 ++ > 4 files changed, 19 insertions(+), 3 deletions(-) Hi Ayush, Micka=C3=ABl has the final say on Landlock patches, but I had a few comments that I've included below ... > diff --git a/security/landlock/fs.c b/security/landlock/fs.c > index fc520a06f9af..227dd67dd902 100644 > --- a/security/landlock/fs.c > +++ b/security/landlock/fs.c > @@ -124,7 +124,7 @@ static struct landlock_object *get_inode_object(struc= t inode *const inode) > if (unlikely(rcu_access_pointer(inode_sec->object))) { > /* Someone else just created the object, bail out and ret= ry. */ > spin_unlock(&inode->i_lock); > - kfree(new_object); > + kmem_cache_free(landlock_object_cache, new_object); See my comment below, but you may want to wrap this in a Landlock object API function. > rcu_read_lock(); > goto retry; > diff --git a/security/landlock/object.c b/security/landlock/object.c > index 1f50612f0185..df1354215617 100644 > --- a/security/landlock/object.c > +++ b/security/landlock/object.c > @@ -17,6 +17,15 @@ > > #include "object.h" > > +struct kmem_cache *landlock_object_cache; > + > +void __init landlock_object_init(void) > +{ > + landlock_object_cache =3D kmem_cache_create( > + "landlock_object_cache", sizeof(struct landlock_object), = 0, > + SLAB_PANIC, NULL); The comments in include/linux/slab.h suggest using the KMEM_CACHE() macro, instead of kmem_cache_create(), as a best practice for creating slab caches. > +} > + > struct landlock_object * > landlock_create_object(const struct landlock_object_underops *const unde= rops, > void *const underobj) > @@ -25,7 +34,8 @@ landlock_create_object(const struct landlock_object_und= erops *const underops, > > if (WARN_ON_ONCE(!underops || !underobj)) > return ERR_PTR(-ENOENT); > - new_object =3D kzalloc(sizeof(*new_object), GFP_KERNEL_ACCOUNT); > + new_object =3D > + kmem_cache_zalloc(landlock_object_cache, GFP_KERNEL_ACCOU= NT); If the line is too long, you might want to consider splitting the function parameters like this: new_object =3D kmem_cache_zalloc(landlock_object_cache, GFP_KERNEL_ACCOUNT); > if (!new_object) > return ERR_PTR(-ENOMEM); > refcount_set(&new_object->usage, 1); > @@ -62,6 +72,6 @@ void landlock_put_object(struct landlock_object *const = object) > * @object->underobj to @object (if it still exists). > */ > object->underops->release(object); > - kfree_rcu(object, rcu_free); > + kmem_cache_free(landlock_object_cache, object); > } > } > diff --git a/security/landlock/object.h b/security/landlock/object.h > index 5f28c35e8aa8..8ba1af3ddc2e 100644 > --- a/security/landlock/object.h > +++ b/security/landlock/object.h > @@ -13,6 +13,10 @@ > #include > #include > > +extern struct kmem_cache *landlock_object_cache; This really is a decision for Micka=C3=ABl, but you may want to make @landlock_object_cache private to object.c and create functions to manage it as needed, e.g. put/free operations. > +void __init landlock_object_init(void); > + > struct landlock_object; > > /** > diff --git a/security/landlock/setup.c b/security/landlock/setup.c > index f6dd33143b7f..a5fca4582ee1 100644 --=20 paul-moore.com