Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp520740lqz; Sat, 30 Mar 2024 06:54:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXvp0EEriP3TiSKylbopNgjiqyALI97+AtCa6lpBA88oQASxbVEqSx1RqL3WD6b3p3+mj45KSQRVz9oiRHgy1yRRrtT9vFNlI6kW8JD3w== X-Google-Smtp-Source: AGHT+IHeRO3XrkYrfbwheeBdRTQrEier5tn/eahUvQOqkUrecJ5rxCrd1ARYAakPDJ3uDd4Aw9r6 X-Received: by 2002:a05:6830:14d6:b0:6e5:2c78:49e3 with SMTP id t22-20020a05683014d600b006e52c7849e3mr4890778otq.31.1711806880999; Sat, 30 Mar 2024 06:54:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711806880; cv=pass; d=google.com; s=arc-20160816; b=r1PGNSVlpndx67PXEKDvirXeH2stSp3cAJImkw5grmSpkslvsVj9zTySHYA58y1ez9 eur9nf0WnqCVmv+U4xE5w5xZiHepvcSSjzMfgcr6IGSS62rEdQ70rVAgQxxFCue5QZjR a6IBUBaC2eXtO8tni2s8aas4ZeHewvEV2PE0bHhUCQmsJv9QVrVTNd3hNhoHLPxhUN9s EdtZSu1ospf9j8BWdu2P01Kj+Dp5IdGPwR4HT5M3M+1mtRzcFacUeV5xoA/J0XAuvDAJ SqMyK23AA01JcsoLQ7UbL0pI27dSEYOnisdYOmWpOrSCIm0DE1Rx+HpOezsTeYGZFDSy 3ulA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=Oqh2nZliN5w5CydPn9rkbQtrtD4gRqfg8XL3I/NhjWQ=; fh=86U2S1Qf6k28wek1Lb3CxhoRsCAwG8l0vk8yN9CsL4E=; b=HXXhvy5TXIFHNcvyfQ0LF6G/4fLdzZ278/rn5NFn62duOp5fjbGtqqgWTuqhaubNQO RpVYV0ajtB5I0d8hDQDxL9nFfs4DRast8acKIl02rv1t/InEJeEHeKxjdtk9Xc6rzS9F APAXgidk0H5gI28SgabMC6GtYQ7fp11ZYWPy5DdIMn2J7RP65FxJW6qOjtccYHHOIxgt wbx3e3XUIqEMpynnfRlA/a6L1IjfHJF3gfyrYWKONBR8n7yVa6pXZ8/NKjnPGVeGv9aw aF8qN4pNRyxmK5IArv++vwNnaKPJtityTWfL7E4cIAwTcZxzSyk6CE+tCEb1hkLPaId4 JVXw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=d0GrYD4m; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-125740-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125740-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d16-20020a0ce450000000b00696852c3cfdsi5348549qvm.613.2024.03.30.06.54.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 06:54:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-125740-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=d0GrYD4m; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-125740-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125740-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 71F7F1C21100 for ; Sat, 30 Mar 2024 13:54:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB4A92E3F7; Sat, 30 Mar 2024 13:54:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d0GrYD4m" Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 924C18BFC; Sat, 30 Mar 2024 13:54:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711806872; cv=none; b=fJd19SYNO8WavivY/PzYWyuS1WwlMsaPqasDgFn0ewFLyx39wGlVef0JQlZlchBFxgeYmSV5hIqKyHCWhhPFUgv+gROriKoz10E3LcpgW5J6S3Oufa6vyRx4przrniZrkvWMa+HEXPL6nDNSh4nV/y/O6m0lmvAbsfa80oSopKQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711806872; c=relaxed/simple; bh=fedmjVSg0DUkzLNTvNvlEWO9S467LP+p2s3GtiDdmBQ=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=Xq/GvcNR9dq1CV119upPag2xC1cQctcgFGoYldctQeepxQlzJnv5MI5DIRTHtYKxMRGAgTGKOqx6+OV2IkU0VMgsiBpwpOxUi0p5+hBlE13D+3mgXElzN/Ll2Kj4Llzut/0J6suUr3fK6rOR39foCmJmotQxH+8G2sEOGSf7M3g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d0GrYD4m; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1e00d1e13a2so19697255ad.0; Sat, 30 Mar 2024 06:54:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711806870; x=1712411670; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=Oqh2nZliN5w5CydPn9rkbQtrtD4gRqfg8XL3I/NhjWQ=; b=d0GrYD4mJVJyY8ZJf/2cTDD2DRfW506BtcfkC0czCrldLBLrn/L6xZ1pRoG73h1GiX QL8LT6QTMtGUl49Pd4VxEz3wnqQaxkcnekW3FGYBmSqUT9xsx77njHcoQiPF5QCQr4Pz o4OR65bhHJw/iKL+AjmXrggze+6W80ewo6BFu4m7qiW4/vVLJYafpwY+lEt4tjRExiXp 26tnQ5nmQXkPpQs/MogVwfPS/i0r0vbWCDyvam0qDGakGiM3xLJ7wokkK1ondHQNvaYc 6ryNjuPnLZebi5vrYDstC1WWajptgC17Ar5He2t3Icr1CqYUlycHn/Dp4TT3r4dlnFMI y3Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711806870; x=1712411670; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Oqh2nZliN5w5CydPn9rkbQtrtD4gRqfg8XL3I/NhjWQ=; b=B/GN7R8YfUa6HcxJypUysCORQXtjOSWZQV/NUAV89BAWFmhUMmcHiwx+Is7KPvetiF B7Vl6q3tZVxT5BbTVyie/3eprgxucsC9BGvzZMxIk82QYLijjY9/l87bQLjdkJNYQZVn b9FqGtnxDxWnAoYQAhAQR1M+393l/Mzj2z+jQGmLKJlkvjcRqanoxc7Hzq7TPVDay00L iYd4q44rW7pRIpXVagCAgZkpWSs3FFY9RIHkTFGpAYlnflCAS3TQDp/t4H33WDUnB5iv V30Fyb/KeRv7l5/50Za+sVP8bFd7QcmOrfgoK8y/Ox4E6CoYqfjn7tmS1XX+Oa0vHBEA ihRg== X-Forwarded-Encrypted: i=1; AJvYcCX00c6PlGBy0RyLuPLoKIp6JMyRbysefUoOB+gIEj5NqrzLyQsY4bk1pg4jdQsxrDlax+X4T+lJVkjvtYgyzkVrZA52owVIeJTTLJI7gSKThKYeh+IJYHLQH/x7aeHRea89r8VYEXOIUnJ1r00mfosfOj67 X-Gm-Message-State: AOJu0YxkCVm+yssR8y/RP4nY3Lc5PKG1zrZOwnQYgMEiuuGeabvhzm4q x1+ZDihCtPQC0ToRtM/WAnIBv6GPlKQCSFq1HB3dT2ojVTieGZz779T3webNz3A= X-Received: by 2002:a17:902:d4c3:b0:1e0:b5e8:7467 with SMTP id o3-20020a170902d4c300b001e0b5e87467mr5920862plg.3.1711806869527; Sat, 30 Mar 2024 06:54:29 -0700 (PDT) Received: from ayush-HP-Pavilion-Gaming-Laptop-15-ec0xxx ([2409:40e3:103e:d98f:6ff5:fd6a:83ef:b115]) by smtp.gmail.com with ESMTPSA id b3-20020a170902d50300b001dcb654d1a5sm5249616plg.21.2024.03.30.06.54.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 06:54:29 -0700 (PDT) Date: Sat, 30 Mar 2024 19:24:19 +0530 From: Ayush Tiwari To: alison.schofield@intel.com, paul@paul-moore.com, mic@digikod.net, fabio.maria.de.francesco@linux.intel.com, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org Cc: outreachy@lists.linux.dev, linux-security-module@vger.kernel.org Subject: [PATCH v2] landlock: Use kmem for landlock_object Message-ID: 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 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. 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. 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); +} + 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); if (!new_object) return ERR_PTR(-ENOMEM); refcount_set(&new_object->usage, 1); diff --git a/security/landlock/object.h b/security/landlock/object.h index 5f28c35e8aa8..d9967ef16ec1 100644 --- a/security/landlock/object.h +++ b/security/landlock/object.h @@ -15,6 +15,8 @@ struct landlock_object; +void __init landlock_object_cache_init(void); + /** * struct landlock_object_underops - Operations on an underlying object */ diff --git a/security/landlock/setup.c b/security/landlock/setup.c index f6dd33143b7f..525820fc03ec 100644 --- a/security/landlock/setup.c +++ b/security/landlock/setup.c @@ -33,6 +33,7 @@ const struct lsm_id landlock_lsmid = { static int __init landlock_init(void) { + landlock_object_cache_init(); landlock_add_cred_hooks(); landlock_add_ptrace_hooks(); landlock_add_fs_hooks(); -- 2.40.1