Received: by 2002:ab2:5c0e:0:b0:1ef:a325:1205 with SMTP id i14csp8726lqk; Wed, 13 Mar 2024 14:37:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWi07aFz6JuoxiYUwW4zdYfwDYNmcjJtGKrSceqhW2pl1d8YyKnP7etEh4QClzMAeWBIDV9ovKH3pwzJ+58nO05qEmzTs3kWUxH9mSbuA== X-Google-Smtp-Source: AGHT+IHozc9Ttukp7T3vIlGgzZlYKoSNc5tSSRt/yq9/yyQeo97MOFWRx6apjwOeu1D3NiitlOHs X-Received: by 2002:a05:6122:3691:b0:4d4:ef9:71b0 with SMTP id ec17-20020a056122369100b004d40ef971b0mr147007vkb.7.1710365859225; Wed, 13 Mar 2024 14:37:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710365859; cv=pass; d=google.com; s=arc-20160816; b=0f2TOzyo73+bZ7kS8qw6WuMocu+qb61SQ37jgkUBuvRaFMeCLoN0ph+8wz9uZV9EvA m3yDQSEtcdVw4jQ0vvjG0BsuIkGXmRzmucoSl4Y0uj7zBCubHdjOiZMPSo5Zcl0d3Qzg gpnqBUBQ8rAaCsgwYra9cBkzsBEf4Smz7f1+EDQ+ushF6q0ADPSMXSEVVUpN8GxwMAlR jiYvBFMq24Y0m7DlnifeVAZLcT8N2aDVhaW/HXe9oSjqh2peatCYGqeqAnKJAWpDVKl9 JELh9g/k/grDwiIR7RvSaFXAkclfWTM6zsbnyiU0rliHYV4gJKMy1uFT5NPOpIEy5a0X EQRg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :mail-followup-to:message-id:subject:cc:to:from:date:dkim-signature; bh=oUWr+l/7P22mnFeHOehcZrsbMwGybiUWqyX8/H/bx60=; fh=80n+Zs2QVJZVfXI09hz+AE1IKzRoer0nUyeZgN/xx3g=; b=v6DAShY7HPaZZWBfyWoUwWYtTvbUovfMJMUAuVtkaMC6VNOWKnIhHzD4/mdbNMWnXp EreiACJj9JRY2cjVx2ix9df4sln2vmX8pDG6IoIaYElgSr9qMAWUMKbr0pFC0RgovLOF W1sI4D47eLG0/dc1iNe5F2dxe6H9y6vAsIpxJyoVNdrfBw9iJhGp5w0iuNoNVeN+GIF9 w1o+MsOXeLjduBKYFl1OdNyrsIxCbKCnFGOpgN0S7LZa7JDfg3WnOc67eHpIrgrbo6oK cMC1pGd36Y3S4xlfxXSbhR6lmaZKTHZb0GNbyaV/C1AI/EL46Smfnn+Z4NggMPtFWvGA pmDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=temperror (no key for signature) header.i=@infradead.org header.s=zeniv-20220401 header.b=GiBhUP0A; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-102539-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102539-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 14-20020a05621420ce00b006903c84591asi77754qve.491.2024.03.13.14.37.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 14:37:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102539-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=temperror (no key for signature) header.i=@infradead.org header.s=zeniv-20220401 header.b=GiBhUP0A; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-102539-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102539-linux.lists.archive=gmail.com@vger.kernel.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id DF88B1C2280D for ; Wed, 13 Mar 2024 21:37:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BE1253E2D; Wed, 13 Mar 2024 21:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=infradead.org header.i=@infradead.org header.b="GiBhUP0A" Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (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 5F3431A38DC for ; Wed, 13 Mar 2024 21:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710365853; cv=none; b=bR9RNNt4GLYqSuY07MmS6V3hL2pFLs2ROOmbPgA3l56fp93Mo9niBKQudKyI4SbPVYVXIhZbXY5Tv0J0sdP/UEnO6/4VNkHeGMYOhyq5uNjFvRrJ8gvUfNnbRH0ctU3ekKWoSIQJKqWulsZc9XGLoOE4nUeie9JCwV4cJlPucGE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710365853; c=relaxed/simple; bh=5yHraXVDQFk+w5OJkjMBnM5b16oeNXRmUoLOQD+vJ9c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OL1ESdMaWePcr/GNctIOs3irOxglz9T32p1ufRLsiX4Z2DS9Cy7bDAH/bBK1glCpvj/AnNk/fXuY1lE++lkQwnMphWDB0r6qtWR3E8+XhP7AwnsnG0sYjaPWlHxNj6YElS6ozAMtxjAZ8cluqLsK3k/HAOGa6Bhwt2n5qMnr6Dc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=evilplan.org; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=fail (0-bit key) header.d=infradead.org header.i=@infradead.org header.b=GiBhUP0A reason="key not found in DNS"; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=evilplan.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=oUWr+l/7P22mnFeHOehcZrsbMwGybiUWqyX8/H/bx60=; b=GiBhUP0AA7Oa7ZLMa+/XHji2jy N2Cy2rUYTUIS098VKTjXvdDuLmXt971V8YDd491TFNLqrnMpRHAIQFpSjhjORY0/wii5bRdTBPGWG c5ocTLE196iRz8lxnTWA5LkcoQ1J/fRY4IojUcnk9J2u5ajr2TrA3QZe0c/5dUDgSYKUMfo6+ceBd hV0Uy7JX3lkHYZGXdwXxF8EuU3wJkUULmV3hHMwx4XkfKS0zT6bc6nmXc/76Gx6e2B3OcsF5vP4Rp EzeuUp5+Z52RcIZQcgcOw4DnCThfddlBiV0q1vfopb49OmujSO84OHpSMy32fPqpB9tMOxAalk9Ax lP6zokOA==; Received: from jlbec by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1rkWHo-008ThA-2F; Wed, 13 Mar 2024 21:37:20 +0000 Date: Wed, 13 Mar 2024 14:37:17 -0700 From: Joel Becker To: Tom Lendacky Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Dan Williams , Michael Roth , Ashish Kalra , Christoph Hellwig Subject: Re: [PATCH v2 12/14] fs/configfs: Add a callback to determine attribute visibility Message-ID: Mail-Followup-To: Tom Lendacky , linux-kernel@vger.kernel.org, x86@kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Dan Williams , Michael Roth , Ashish Kalra , Christoph Hellwig 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: X-Burt-Line: Trees are cool. X-Red-Smith: Ninety feet between bases is perhaps as close as man has ever come to perfection. Sender: Joel Becker On Fri, Mar 08, 2024 at 12:35:27PM -0600, Tom Lendacky wrote: > In order to support dynamic decisions as to whether an attribute should be > created, add a callback that returns a bool to indicate whether the > attribute should be display. If no callback is registered, the attribute > is displayed by default. I'm curious what the strong value is in this extra callback. As opposed to not generating the attribute in the absence of a TPM (why create a config_item at all?), merely having an empty response from the attribute, or having `->show()` return -ENODEV or similar. > > Cc: Joel Becker > Cc: Christoph Hellwig > Signed-off-by: Tom Lendacky > --- > fs/configfs/file.c | 13 +++++ > include/linux/configfs.h | 114 +++++++++++++++++++++++++++------------ > 2 files changed, 93 insertions(+), 34 deletions(-) > > diff --git a/fs/configfs/file.c b/fs/configfs/file.c > index 0ad32150611e..c758bcc11235 100644 > --- a/fs/configfs/file.c > +++ b/fs/configfs/file.c > @@ -451,6 +451,12 @@ int configfs_create_file(struct config_item * item, const struct configfs_attrib > umode_t mode = (attr->ca_mode & S_IALLUGO) | S_IFREG; > int error = 0; > > + if (attr->ca_is_visible) { > + mode = attr->ca_is_visible(item, attr); > + if (!mode) > + return 0; What value do we get from carrying the mode through here? The API proposed is "visible or not", which is a boolean. Overloading that with "also set the mode" is confusing, and it also can lead to the divergent codepath problem you mentioned in your response, where `->ca_is_visible()` fails to return the mode correctly. If this was simpl a boolean hook, the code could read like so: ``` umode_t mode = (attr->ca_mode & S_IALLUGO) | S_IFREG; int error = 0; if (attr->ca_is_visible && !attr->ca_is_visible(item, attr)) return 0; ``` > diff --git a/include/linux/configfs.h b/include/linux/configfs.h > index 2606711adb18..18011f78ffde 100644 > --- a/include/linux/configfs.h > +++ b/include/linux/configfs.h > @@ -112,39 +112,64 @@ static inline void configfs_add_default_group(struct config_group *new_group, > list_add_tail(&new_group->group_entry, &group->default_groups); > } > > +typedef umode_t (*configfs_is_visible_t)(const struct config_item *item, > + const struct configfs_attribute *attr); > + We don't use typedefs of op functions anywhere else in configfs or frankly the entire filesystem API. Adding one here would just introduce confusion. > struct configfs_attribute { > const char *ca_name; > struct module *ca_owner; > umode_t ca_mode; > + configfs_is_visible_t ca_is_visible; > ssize_t (*show)(struct config_item *, char *); > ssize_t (*store)(struct config_item *, const char *, size_t); > }; > Thanks, Joel -- Life's Little Instruction Book #306 "Take a nap on Sunday afternoons." http://www.jlbec.org/ jlbec@evilplan.org