From patchwork Mon Nov 29 14:31:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1561222 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=YPhM37gc; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J2nqL4HCLz9sVc for ; Tue, 30 Nov 2021 01:31:58 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1mrhh8-0001oJ-L9; Mon, 29 Nov 2021 14:31:50 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1mrhh6-0001nr-R7 for kernel-team@lists.ubuntu.com; Mon, 29 Nov 2021 14:31:48 +0000 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id A814E3F1B7 for ; Mon, 29 Nov 2021 14:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1638196308; bh=/DPyVUWjeDyrhwTp9p86rRF5OMPJQnuPwtijCa4V0d0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=YPhM37gcs7SbiXNY8lsgQKxxNLwy+YYrBB1Irbxnt77yzt/OHXMnPCpd+rgJVrPvH HbELMmWAxGQGToCHaBdUdIqUMPW9WfEII/RTmUrwU+JZcCXUxG1u8VmQIrjkgqCNa0 F0YgNDLZiZFaUEqRQa4zMxDfTN+i992rlRPVjHbdYcBi+pLIMy94NLiYkafayfvM0k it9XBTtqHlGnrZMKSUmtgDz4R/aT5UpTzc7j5mwaeKXlCWTUV6j5fHH1u/Gzk0TUKJ c4dP8GyODn59DdpyAM1BcxxZBGIgDcFBbze3TWiRrLWZU65H375Blg9O4m/oHN2hYT 6qljWj/c1TOGQ== Received: by mail-pj1-f70.google.com with SMTP id jx2-20020a17090b46c200b001a62e9db321so8026888pjb.7 for ; Mon, 29 Nov 2021 06:31:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/DPyVUWjeDyrhwTp9p86rRF5OMPJQnuPwtijCa4V0d0=; b=Y075H3cEJyQIlQVeS+odXic7NTCguquBk5bKRfMlGUVmJHdWy4d8YWxo0RdbV25tMX /Tweo3//VbntXd3vH3rEyqxyvwLZ/cFxbEwDwJM9aGOnxzFs8RJ+kGsNJwVpzK8A7R/B mpWTIMhi/Y1GWneAEgJUPmutwom70MrFsDALjIOYZIdEQYfrfniuMMbds2HnUErYheZS AuUNMIwqB+qQ6KrSxwqaUntT8CNDQWzUqNT00gM+hehJM9HYdFomHgKg2zNWSjVOhtlg 2ktedYb3vy4W0Ude6CVQzUvLuhAR5ymBUMfJo9tTEfcg9rU7uYWgBkxLe1u7wEfRjfyg yaOA== X-Gm-Message-State: AOAM532YGfMCT/PGwcPbAV9y02eQ2QKlbBkuHHZzL3URsTHP6k3hw7YF 7VeCY0G6YetGAB5yn5KVC9tcGH1VhlOC0nDEuPns1lf2OdwWc7Dg4gY6GmnSiOy+gmR9khTLqTK W9/eO2iUt15KDCrLft2zg85ife15bhrmyOZ800+QNrQ== X-Received: by 2002:a65:5aca:: with SMTP id d10mr27113837pgt.278.1638196306969; Mon, 29 Nov 2021 06:31:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/tyWTB26q08FV/O6+O3O46reERGGM38zhCmnAlX6Ezy9rpRNczaMLhDELiFC9Z4v+9IGyjw== X-Received: by 2002:a65:5aca:: with SMTP id d10mr27113812pgt.278.1638196306659; Mon, 29 Nov 2021 06:31:46 -0800 (PST) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id w20sm19559542pfu.146.2021.11.29.06.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 06:31:46 -0800 (PST) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH][focal/linux-azure] PCI/sysfs: Convert "config" to static attribute Date: Mon, 29 Nov 2021 07:31:38 -0700 Message-Id: <20211129143138.19190-2-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211129143138.19190-1-tim.gardner@canonical.com> References: <20211129143138.19190-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Krzysztof Wilczyński BugLink: https://bugs.launchpad.net/bugs/1952621 The "config" sysfs attribute allows access to either the legacy (PCI and PCI-X Mode 1) or the extended (PCI-X Mode 2 and PCIe) device configuration space. Previously it was dynamically created either when a device was added (for hot-added devices) or via a late_initcall (for devices present at boot): pci_bus_add_devices pci_bus_add_device pci_create_sysfs_dev_files if (!sysfs_initialized) return sysfs_create_bin_file # for hot-added devices pci_sysfs_init # late_initcall sysfs_initialized = 1 for_each_pci_dev(pdev) pci_create_sysfs_dev_files(pdev) # for devices present at boot And dynamically removed when the PCI device is stopped and removed: pci_stop_bus_device pci_stop_dev pci_remove_sysfs_dev_files sysfs_remove_bin_file This attribute does not need to be created or removed dynamically, so we can use a static attribute so the device model takes care of addition and removal automatically. Convert "config" to a static attribute and use the .is_bin_visible() callback to set the correct object size (either 256 bytes or 4 KiB) at runtime. The pci_sysfs_init() scheme was added in the pre-git era by https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/drivers/pci/pci-sysfs.c?id=f6d553444da2 [bhelgaas: commit log] Suggested-by: Oliver O'Halloran Link: https://lore.kernel.org/r/CAOSf1CHss03DBSDO4PmTtMp0tCEu5kScn704ZEwLKGXQzBfqaA@mail.gmail.com Link: https://lore.kernel.org/r/20210416205856.3234481-2-kw@linux.com Signed-off-by: Krzysztof Wilczyński Signed-off-by: Bjorn Helgaas (cherry picked from commit e1d3f3268b0e512ceb811dd4765e476626bde71c) Signed-off-by: Tim Gardner --- drivers/pci/pci-sysfs.c | 64 ++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 39 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index b78835742526b..399f441e81a4c 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -814,6 +814,29 @@ static ssize_t pci_write_config(struct file *filp, struct kobject *kobj, return count; } +static BIN_ATTR(config, 0644, pci_read_config, pci_write_config, 0); + +static struct bin_attribute *pci_dev_config_attrs[] = { + &bin_attr_config, + NULL, +}; + +static umode_t pci_dev_config_attr_is_visible(struct kobject *kobj, + struct bin_attribute *a, int n) +{ + struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); + + a->size = PCI_CFG_SPACE_SIZE; + if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) + a->size = PCI_CFG_SPACE_EXP_SIZE; + + return a->attr.mode; +} + +static const struct attribute_group pci_dev_config_attr_group = { + .bin_attrs = pci_dev_config_attrs, + .is_bin_visible = pci_dev_config_attr_is_visible, +}; #ifdef HAVE_PCI_LEGACY /** @@ -1283,26 +1306,6 @@ static ssize_t pci_read_rom(struct file *filp, struct kobject *kobj, return count; } -static const struct bin_attribute pci_config_attr = { - .attr = { - .name = "config", - .mode = 0644, - }, - .size = PCI_CFG_SPACE_SIZE, - .read = pci_read_config, - .write = pci_write_config, -}; - -static const struct bin_attribute pcie_config_attr = { - .attr = { - .name = "config", - .mode = 0644, - }, - .size = PCI_CFG_SPACE_EXP_SIZE, - .read = pci_read_config, - .write = pci_write_config, -}; - static ssize_t reset_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -1354,16 +1357,9 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev) if (!sysfs_initialized) return -EACCES; - if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) - retval = sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr); - else - retval = sysfs_create_bin_file(&pdev->dev.kobj, &pci_config_attr); - if (retval) - goto err; - retval = pci_create_resource_files(pdev); if (retval) - goto err_config_file; + goto err; /* If the device has a ROM, try to expose it in sysfs. */ rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE); @@ -1404,11 +1400,6 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev) } err_resource_files: pci_remove_resource_files(pdev); -err_config_file: - if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) - sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr); - else - sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr); err: return retval; } @@ -1434,12 +1425,6 @@ void pci_remove_sysfs_dev_files(struct pci_dev *pdev) return; pci_remove_capabilities_sysfs(pdev); - - if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) - sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr); - else - sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr); - pci_remove_resource_files(pdev); if (pdev->rom_attr) { @@ -1535,6 +1520,7 @@ static const struct attribute_group pci_dev_group = { const struct attribute_group *pci_dev_groups[] = { &pci_dev_group, + &pci_dev_config_attr_group, NULL, };