From patchwork Thu Aug 17 23:58:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 13357109 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75762C7112F for ; Thu, 17 Aug 2023 23:59:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356206AbjHQX7C (ORCPT ); Thu, 17 Aug 2023 19:59:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356331AbjHQX6m (ORCPT ); Thu, 17 Aug 2023 19:58:42 -0400 Received: from mail-vs1-xe2f.google.com (mail-vs1-xe2f.google.com [IPv6:2607:f8b0:4864:20::e2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41E7826AA; Thu, 17 Aug 2023 16:58:40 -0700 (PDT) Received: by mail-vs1-xe2f.google.com with SMTP id ada2fe7eead31-44bf676a086so112449137.3; Thu, 17 Aug 2023 16:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692316719; x=1692921519; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IbxQJAuu/02g0YU9vrxi3SyQC4nxmr5UrgA6AsN18q8=; b=ZeJ60BzgGXd1SBSYMiwyHub3P6Rh+S9nGPGM8e/jAiCPC+0+3KqCr29x3LDNeS+Bwv uq/j5CapHUQHNMyMKsrxzjCfd3LVnaX2AN75H6Jz7smcBozlFy5A8nfNBHWbOm+p144Q UYfkIXz54exgW68FW4plva+rfrlWuxzlvpdfAdJctIGwmLxS1IH0gLIh8f2Y+ljTIG6Y R0U0rbT9SbecrwwFWJgbQv6RhJTGa4Fp25WGhaiy9/VuYHZsPkk/AfBgLJckS+v2E7ud C1iH4pgTpIVOrgSqTXjIPnqZU2MuvrvGPLE4MP42DZv2ASbrw1qdI/YdoXjmOuTsTSON narA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692316719; x=1692921519; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IbxQJAuu/02g0YU9vrxi3SyQC4nxmr5UrgA6AsN18q8=; b=dAKDllIIKN1X5dB+4WwkFh+ZBmI6jPeyXHXpbrInFuaYPdlIG40nvE/UfxADWFXMui zT9YLMwy9XSpSNgCrYkQPCjscA2zFVRIHoWB+7p5+vTNgq024v6GRWfw9zSSH3d6yh/c Pp13aX8lVI/oX1op2ftn6QLBNcMFO3dMqvhW6pxFg8KRMIaKPZKqrhuIunpPGUPH+XXA A58/J+WfhV8/8kEGu3vtR6BPfN3Yth/kJzXfcvp7YEFgN0HDjR23+ffXHU6eS4S11uTs uJKAYuxo3FrtgQf/5okoIYZDnsyM8iIL1+5+BjTmH+q6rD6nlLU7Yrw0zYtqzUW9Ym8/ 1dlg== X-Gm-Message-State: AOJu0Yw+huA4O9sB0Sed86trYM9WIKRxwJh2riN4nGPsgnYxHSht/APv FHl9DvbvZ4zxVgcDhQa+NTg= X-Google-Smtp-Source: AGHT+IHj0DF5V6UPufpc5XTF58aPL9ESo5WVhPIU6toUFTeRwwxX94nFJ8ulAI7qDfEceBcb7nbimQ== X-Received: by 2002:a05:6102:2858:b0:444:17aa:df60 with SMTP id az24-20020a056102285800b0044417aadf60mr1479117vsb.13.1692316719261; Thu, 17 Aug 2023 16:58:39 -0700 (PDT) Received: from localhost.localdomain ([146.70.187.10]) by smtp.gmail.com with ESMTPSA id k19-20020a67c293000000b0044bf2750d30sm135182vsj.10.2023.08.17.16.58.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 16:58:38 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: bhelgaas@google.com, linux-pci@vger.kernel.org, Jonathan.Cameron@huawei.com, lukas@wunner.de Cc: alex.williamson@redhat.com, christian.koenig@amd.com, kch@nvidia.com, gregkh@linuxfoundation.org, logang@deltatee.com, linux-kernel@vger.kernel.org, alistair23@gmail.com, chaitanyak@nvidia.com, rdunlap@infradead.org, Alistair Francis Subject: [PATCH v6 1/3] PCI/DOE: Expose the DOE features via sysfs Date: Thu, 17 Aug 2023 19:58:08 -0400 Message-ID: <20230817235810.596458-1-alistair.francis@wdc.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The PCIe 6 specification added support for the Data Object Exchange (DOE). When DOE is supported the Discovery Data Object Protocol must be implemented. The protocol allows a requester to obtain information about the other DOE features supported by the device. The kernel is already querying the DOE features supported and cacheing the values. This patch exposes the values via sysfs. This will allow userspace to determine which DOE features are supported by the PCIe device. By exposing the information to userspace tools like lspci can relay the information to users. By listing all of the supported features we can allow userspace to parse and support the list, which might include vendor specific features as well as yet to be supported features. Signed-off-by: Alistair Francis --- v6: - Use "feature" instead of protocol - Don't use any devm_* functions - Add two more patches to the series v5: - Return the file name as the file contents - Code cleanups and simplifications v4: - Fixup typos in the documentation - Make it clear that the file names contain the information - Small code cleanups - Remove most #ifdefs - Remove extra NULL assignment v3: - Expose each DOE feature as a separate file v2: - Add documentation - Code cleanups This patch will create a doe_features directory for all PCIe devices without the next two patches Documentation/ABI/testing/sysfs-bus-pci | 11 +++ drivers/pci/doe.c | 112 ++++++++++++++++++++++++ drivers/pci/pci-sysfs.c | 10 +++ drivers/pci/pci.h | 3 + include/linux/pci-doe.h | 1 + 5 files changed, 137 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci index ecf47559f495..199ee5d27d9d 100644 --- a/Documentation/ABI/testing/sysfs-bus-pci +++ b/Documentation/ABI/testing/sysfs-bus-pci @@ -500,3 +500,14 @@ Description: console drivers from the device. Raw users of pci-sysfs resourceN attributes must be terminated prior to resizing. Success of the resizing operation is not guaranteed. + +What: /sys/bus/pci/devices/.../doe_features +Date: August 2023 +Contact: Linux PCI developers +Description: + This directory contains a list of the supported + Data Object Exchange (DOE) features. The feature values are in the + file name. The contents of each file are the same as the name. + The value comes from the device and specifies the vendor and + data object type supported. The lower byte is the data object + type and the next two bytes are the vendor ID. diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c index 1b97a5ab71a9..316aac60ccd5 100644 --- a/drivers/pci/doe.c +++ b/drivers/pci/doe.c @@ -56,6 +56,8 @@ struct pci_doe_mb { wait_queue_head_t wq; struct workqueue_struct *work_queue; unsigned long flags; + + struct device_attribute *sysfs_attrs; }; struct pci_doe_protocol { @@ -92,6 +94,116 @@ struct pci_doe_task { struct pci_doe_mb *doe_mb; }; +#ifdef CONFIG_SYSFS +static umode_t pci_doe_sysfs_attr_is_visible(struct kobject *kobj, + struct attribute *a, int n) +{ + struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); + unsigned long total_features = 0; + struct pci_doe_mb *doe_mb; + unsigned long index, j; + void *entry; + + xa_for_each(&pdev->doe_mbs, index, doe_mb) { + xa_for_each(&doe_mb->prots, j, entry) + total_features++; + } + + if (total_features == 0) + return 0; + + return a->mode; +} + +static struct attribute *pci_dev_doe_feature_attrs[] = { + NULL, +}; + +const struct attribute_group pci_dev_doe_feature_group = { + .name = "doe_features", + .attrs = pci_dev_doe_feature_attrs, + .is_visible = pci_doe_sysfs_attr_is_visible, +}; + +static ssize_t pci_doe_sysfs_feature_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", attr->attr.name); +} + +static int pci_doe_sysfs_feature_supports(struct pci_dev *pdev, + struct pci_doe_mb *doe_mb) +{ + struct device *dev = &pdev->dev; + struct device_attribute *attrs; + unsigned long num_features = 0; + unsigned long vid, type; + unsigned long i; + void *entry; + int ret; + + xa_for_each(&doe_mb->prots, i, entry) + num_features++; + + attrs = kcalloc(num_features, sizeof(*attrs), GFP_KERNEL); + if (!attrs) + return -ENOMEM; + + doe_mb->sysfs_attrs = attrs; + xa_for_each(&doe_mb->prots, i, entry) { + sysfs_attr_init(&attrs[i].attr); + vid = xa_to_value(entry) >> 8; + type = xa_to_value(entry) & 0xFF; + attrs[i].attr.name = kasprintf(GFP_KERNEL, + "0x%04lX:%02lX", vid, type); + if (!attrs[i].attr.name) { + ret = -ENOMEM; + goto fail; + } + + attrs[i].attr.mode = 0444; + attrs[i].show = pci_doe_sysfs_feature_show; + + ret = sysfs_add_file_to_group(&dev->kobj, &attrs[i].attr, + pci_dev_doe_feature_group.name); + if (ret) + goto fail; + } + + return 0; + +fail: + doe_mb->sysfs_attrs = NULL; + xa_for_each(&doe_mb->prots, i, entry) { + if (attrs[i].show) + sysfs_remove_file_from_group(&dev->kobj, &attrs[i].attr, + pci_dev_doe_feature_group.name); + kfree(attrs[i].attr.name); + } + + kfree(attrs); + + return ret; +} + +int doe_sysfs_init(struct pci_dev *pdev) +{ + struct pci_doe_mb *doe_mb; + unsigned long index; + int ret; + + xa_for_each(&pdev->doe_mbs, index, doe_mb) { + ret = pci_doe_sysfs_feature_supports(pdev, doe_mb); + + if (ret) + return ret; + } + + return 0; +} +#endif + static int pci_doe_wait(struct pci_doe_mb *doe_mb, unsigned long timeout) { if (wait_event_timeout(doe_mb->wq, diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index ab32a91f287b..3f5104cf78b6 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -1226,6 +1227,12 @@ static int pci_create_resource_files(struct pci_dev *pdev) int i; int retval; + if (IS_ENABLED(CONFIG_PCI_DOE)) { + retval = doe_sysfs_init(pdev); + if (retval) + return retval; + } + /* Expose the PCI resources from this device as files */ for (i = 0; i < PCI_STD_NUM_BARS; i++) { @@ -1651,6 +1658,9 @@ static const struct attribute_group *pci_dev_attr_groups[] = { #endif #ifdef CONFIG_PCIEASPM &aspm_ctrl_attr_group, +#endif +#ifdef CONFIG_PCI_DOE + &pci_dev_doe_feature_group, #endif NULL, }; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index a4c397434057..139d37a0d4cd 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -180,6 +180,9 @@ extern const struct attribute_group *pci_dev_groups[]; extern const struct attribute_group *pcibus_groups[]; extern const struct device_type pci_dev_type; extern const struct attribute_group *pci_bus_groups[]; +#ifdef CONFIG_SYSFS +extern const struct attribute_group pci_dev_doe_feature_group; +#endif extern unsigned long pci_hotplug_io_size; extern unsigned long pci_hotplug_mmio_size; diff --git a/include/linux/pci-doe.h b/include/linux/pci-doe.h index 1f14aed4354b..4cc13d9ccb50 100644 --- a/include/linux/pci-doe.h +++ b/include/linux/pci-doe.h @@ -22,4 +22,5 @@ int pci_doe(struct pci_doe_mb *doe_mb, u16 vendor, u8 type, const void *request, size_t request_sz, void *response, size_t response_sz); +int doe_sysfs_init(struct pci_dev *pci_dev); #endif From patchwork Thu Aug 17 23:58:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 13357108 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20A62C678DC for ; Thu, 17 Aug 2023 23:59:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356262AbjHQX7D (ORCPT ); Thu, 17 Aug 2023 19:59:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356333AbjHQX6n (ORCPT ); Thu, 17 Aug 2023 19:58:43 -0400 Received: from mail-vk1-xa36.google.com (mail-vk1-xa36.google.com [IPv6:2607:f8b0:4864:20::a36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D71526B6; Thu, 17 Aug 2023 16:58:41 -0700 (PDT) Received: by mail-vk1-xa36.google.com with SMTP id 71dfb90a1353d-4881f8a6caeso115133e0c.0; Thu, 17 Aug 2023 16:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692316720; x=1692921520; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rhYFDJTt8t7W7/+Nj3izgy85+P+pn9Ak5WijxGq2p+Q=; b=hVRuVq4seOD0e1K0arobBgHBIAfpKu+qtKERCI7g+N3DYJyoGKBSC2Ph8sipI730vF 5VZ5WmFjmpXJLaqj/mFrKYMI4YDD4iycpT/MtlN9X0drTuJVIzYT1XSeDsC4jjV5PtJ3 qeCLIpTFyzAf0HizEeRSL3DLkmIMGRRsp3torg+2MYyQkdjnA7Fwpaq/5KAqdryxP/BC TeGc6bxzksuTx/B+EyRMkcCLX5z6LFxFzVv7GRFpgjudisP40FCSeP2xgTZ5zqT+eTJh FxIm7w5eTprCr3F6IcNQg8wLdlTT+XvozKKEJZMcPUL7HJDyeToC+c6n1dogU0LOCv5f gNOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692316720; x=1692921520; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rhYFDJTt8t7W7/+Nj3izgy85+P+pn9Ak5WijxGq2p+Q=; b=UVlOg0WcABjX6kWHmBX6Vv3oxuGAnD2whZ0eyS7F7HKmOa+1FWoG38QOTdzHVOaEsq rvRKhVtr0LtxWoB/TgRw1K5KHAd9okXXxxp+5dMI7ilmvIQv8RLpw20XllG6C34sm/re UQFDN3oN+WLTa+xcg5Y7LVsx4Zw7NZHHgMKEIpx+We6moJDWKy7MDHFgwZK+sThbIEoW HfMqEtF+UWohJUbFENrC6wTvOASBc9SoX4bn1E90d2hG6qsozS5iT3dqCQybU6uZBPWS 937iYyQaHeOc5yc51U7fetkMctkti9Gjm4AaphoxGTk6caGpGXqOLlgFJq8UBBUoci6q L9lA== X-Gm-Message-State: AOJu0YyCtyb6TlCMEfO4rAMOvc2JeqPio46noKoysDPZzo5hmcZfVCZr IRtmBJ9gJ4k8YJq/akaf5Nk= X-Google-Smtp-Source: AGHT+IFrrh7c2bJwTE+iNjf4C7BVmlGDz4CVfCvz9VQBas8wkdE9LzLBsN5ZlTbhSeyE5Yxj9smUpQ== X-Received: by 2002:a67:ffd5:0:b0:43d:6660:581b with SMTP id w21-20020a67ffd5000000b0043d6660581bmr1726767vsq.5.1692316720529; Thu, 17 Aug 2023 16:58:40 -0700 (PDT) Received: from localhost.localdomain ([146.70.187.10]) by smtp.gmail.com with ESMTPSA id k19-20020a67c293000000b0044bf2750d30sm135182vsj.10.2023.08.17.16.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 16:58:40 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: bhelgaas@google.com, linux-pci@vger.kernel.org, Jonathan.Cameron@huawei.com, lukas@wunner.de Cc: alex.williamson@redhat.com, christian.koenig@amd.com, kch@nvidia.com, gregkh@linuxfoundation.org, logang@deltatee.com, linux-kernel@vger.kernel.org, alistair23@gmail.com, chaitanyak@nvidia.com, rdunlap@infradead.org, Alistair Francis Subject: [PATCH v6 2/3] sysfs: Add a attr_is_visible function to attribute_group Date: Thu, 17 Aug 2023 19:58:09 -0400 Message-ID: <20230817235810.596458-2-alistair.francis@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230817235810.596458-1-alistair.francis@wdc.com> References: <20230817235810.596458-1-alistair.francis@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org When creating an attribute group, if it is named a subdirectory it is created and the sysfs files are placed into that subdirectory. If no files are created, normally the directory would still be present, but it would be empty. This can be confusing for users, as it appears the feature is avaliable as there is a directory, but it isn't supported by the hardware or the kernel. One way to fix this is to remove directories that don't contain any files, such as [1]. The problem with this is that there are currently lots of users in the kernel who expect the group to remain even if empty, as they dynamically add/merge properties later. The documentation for sysfs_merge_group() specifically says This function returns an error if the group doesn't exist or any of the files already exist in that group, in which case none of the new files are created. So just not adding the group if it's empty doesn't work, at least not with the code we currently have. The code can be changed to support this, but it is difficult to determine how this will affect existing use cases. This approach instead adds a new function pointer, attr_is_visible(), to `struct attribute_group` which can be set if the user wants to filter the avaliablility of the function. This matches the .is_visible() function pointer that already exists and is commonly used. This approach provides greater control over if the directory should be visible or not. This will be used by the PCIe DOE sysfs attributes to kind the directory on devices that don't support DOE. 1: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git/commit/?h=debugfs_cleanup&id=f670945dfbaf353fe068544c31e3fa45575da5b5 Signed-off-by: Alistair Francis Signed-off-by: Greg Kroah-Hartman Signed-off-by: Alistair Francis Signed-off-by: Greg Kroah-Hartman Signed-off-by: Alistair Francis Signed-off-by: Dan Williams Signed-off-by: Dan Williams Signed-off-by: Dan Williams --- v6: - Add patch fs/sysfs/group.c | 12 +++++++++++- include/linux/sysfs.h | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 138676463336..34afd5becdbe 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -111,6 +111,7 @@ static int internal_create_group(struct kobject *kobj, int update, kuid_t uid; kgid_t gid; int error; + umode_t mode; if (WARN_ON(!kobj || (!update && !kobj->sd))) return -EINVAL; @@ -125,6 +126,15 @@ static int internal_create_group(struct kobject *kobj, int update, return 0; } + if (grp->attr_is_visible) { + mode = grp->attr_is_visible(kobj); + + if (mode == 0) + return 0; + } else { + mode = S_IRWXU | S_IRUGO | S_IXUGO; + } + kobject_get_ownership(kobj, &uid, &gid); if (grp->name) { if (update) { @@ -136,7 +146,7 @@ static int internal_create_group(struct kobject *kobj, int update, } } else { kn = kernfs_create_dir_ns(kobj->sd, grp->name, - S_IRWXU | S_IRUGO | S_IXUGO, + mode, uid, gid, kobj, NULL); if (IS_ERR(kn)) { if (PTR_ERR(kn) == -EEXIST) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index fd3fe5c8c17f..808e7fc0ca57 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -63,6 +63,11 @@ do { \ * @name: Optional: Attribute group name * If specified, the attribute group will be created in * a new subdirectory with this name. + * @attr_is_visible: Optional: Function to return permissions + * associated with the attribute group. Only read/write + * permissions as well as SYSFS_PREALLOC are accepted. Must + * return 0 if an attribute is not visible. The returned value + * will replace static permissions defined in struct attribute. * @is_visible: Optional: Function to return permissions associated with an * attribute of the group. Will be called repeatedly for each * non-binary attribute in the group. Only read/write @@ -83,6 +88,7 @@ do { \ */ struct attribute_group { const char *name; + umode_t (*attr_is_visible)(struct kobject *); umode_t (*is_visible)(struct kobject *, struct attribute *, int); umode_t (*is_bin_visible)(struct kobject *, From patchwork Thu Aug 17 23:58:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 13357110 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA38DC71130 for ; Thu, 17 Aug 2023 23:59:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356312AbjHQX7D (ORCPT ); Thu, 17 Aug 2023 19:59:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356341AbjHQX6p (ORCPT ); Thu, 17 Aug 2023 19:58:45 -0400 Received: from mail-ua1-x934.google.com (mail-ua1-x934.google.com [IPv6:2607:f8b0:4864:20::934]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02E823A8C; Thu, 17 Aug 2023 16:58:43 -0700 (PDT) Received: by mail-ua1-x934.google.com with SMTP id a1e0cc1a2514c-79a31d66002so131075241.3; Thu, 17 Aug 2023 16:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692316722; x=1692921522; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=55+40jxtA3P6XkOphpXmjT7MqNRWcdiP6Y+qR2y2ujc=; b=qDn4+b0HNawkSs2NxxKkhIeOhkmvQxP9CAXvBXRjHkRvKRYOyRsASjvgVnEAGrrBq0 6S8y15U0msACFoEbuBSbnhxmbww7Vi3juvXZhbECHqC06aZn4SodAj/WvhbU0lJuCYQl hN2m6gk/egUW7lzy06FO2sBdODqnX3l4ltD/4ogHo0m+hw9QLwuS1/kOy8wSxNF3ps1T fJH81vQNi8Rb4MSWgu13lnEtQunOhr3t/5MVEnXRWD2KuWgVjFKZMw/0qdAaodKXQ9rX 1xqEYEG4O8EzeOQGyrlVtD91uE1Dpq9ZNx5+MPl2lMGf8mscPi0dhPXLT1iPO3Gf3IBi 94gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692316722; x=1692921522; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=55+40jxtA3P6XkOphpXmjT7MqNRWcdiP6Y+qR2y2ujc=; b=bZhMgOovec4YpIvm+XW3T3e+a1pe4dQBx4Cb71Rm0lrErWZCT7Sr2XMlUeQENrhQUS rF4DhL+jQ9pUJOkiLUaXo48Y0w8MfoWpi8TtLYLJvicB1mUnHn/7TzEFSAF9P50bfEiF 4EfhRXUKfC+lpnzUk32Rq3TEj5HjaMnfFbRy1K2ln/F85T+SRySahLS7smXVGqCzcgNm bo6WU6B7OqipKd90QGNWz+fXJPKuhZJuGg1SBR+pQ8GStR4ssVFMmcWDaEX9dvdNn7tc R5LRTWAU9Fk/XuUzw0qHhdH2UUeFIeEIUhos1Z94dmYS4wDQFh7gf3uSaE84hJFyAkW4 1OpA== X-Gm-Message-State: AOJu0Yzjo7pleFyQVKHtCM0MiOzNxMV3xnlx4vGkzZ8vZ42xjwJFhkTw ld8wwu5YRkFXs1yiyA/Ywok= X-Google-Smtp-Source: AGHT+IFsTd4DINM89FbHHi3BCycS0X3bSd402Jmg0SpgktNoFaAV3+CmOUS88KSP3qlykyzXCWIEIg== X-Received: by 2002:a67:e41a:0:b0:445:4996:1d27 with SMTP id d26-20020a67e41a000000b0044549961d27mr1612084vsf.3.1692316722052; Thu, 17 Aug 2023 16:58:42 -0700 (PDT) Received: from localhost.localdomain ([146.70.187.10]) by smtp.gmail.com with ESMTPSA id k19-20020a67c293000000b0044bf2750d30sm135182vsj.10.2023.08.17.16.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 16:58:41 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: bhelgaas@google.com, linux-pci@vger.kernel.org, Jonathan.Cameron@huawei.com, lukas@wunner.de Cc: alex.williamson@redhat.com, christian.koenig@amd.com, kch@nvidia.com, gregkh@linuxfoundation.org, logang@deltatee.com, linux-kernel@vger.kernel.org, alistair23@gmail.com, chaitanyak@nvidia.com, rdunlap@infradead.org, Alistair Francis Subject: [PATCH v6 3/3] PCI/DOE: Only expose the sysfs attribute group if DOE is supported Date: Thu, 17 Aug 2023 19:58:10 -0400 Message-ID: <20230817235810.596458-3-alistair.francis@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230817235810.596458-1-alistair.francis@wdc.com> References: <20230817235810.596458-1-alistair.francis@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Now that the new attr_is_visible() function is avaliable as part of `struct attribute_group` we can use that to hide the attribute group on devices that don't support DOE. Signed-off-by: Alistair Francis --- v6: - Add patch drivers/pci/doe.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c index 316aac60ccd5..1a021e8b3e0c 100644 --- a/drivers/pci/doe.c +++ b/drivers/pci/doe.c @@ -95,8 +95,7 @@ struct pci_doe_task { }; #ifdef CONFIG_SYSFS -static umode_t pci_doe_sysfs_attr_is_visible(struct kobject *kobj, - struct attribute *a, int n) +static umode_t pci_doe_sysfs_group_is_visible(struct kobject *kobj) { struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); unsigned long total_features = 0; @@ -112,7 +111,17 @@ static umode_t pci_doe_sysfs_attr_is_visible(struct kobject *kobj, if (total_features == 0) return 0; - return a->mode; + return S_IRWXU | S_IRUGO | S_IXUGO; +} + +static umode_t pci_doe_sysfs_attr_is_visible(struct kobject *kobj, + struct attribute *a, int n) +{ + if (pci_doe_sysfs_group_is_visible(kobj)) { + return a->mode; + } + + return 0; } static struct attribute *pci_dev_doe_feature_attrs[] = { @@ -122,6 +131,7 @@ static struct attribute *pci_dev_doe_feature_attrs[] = { const struct attribute_group pci_dev_doe_feature_group = { .name = "doe_features", .attrs = pci_dev_doe_feature_attrs, + .attr_is_visible = pci_doe_sysfs_group_is_visible, .is_visible = pci_doe_sysfs_attr_is_visible, };