From patchwork Fri Sep 10 20:26:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12485993 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 X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75E7CC433F5 for ; Fri, 10 Sep 2021 20:26:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D0BE60E76 for ; Fri, 10 Sep 2021 20:26:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233397AbhIJU1m (ORCPT ); Fri, 10 Sep 2021 16:27:42 -0400 Received: from mail-lj1-f169.google.com ([209.85.208.169]:45755 "EHLO mail-lj1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233498AbhIJU1j (ORCPT ); Fri, 10 Sep 2021 16:27:39 -0400 Received: by mail-lj1-f169.google.com with SMTP id l18so5095135lji.12 for ; Fri, 10 Sep 2021 13:26:27 -0700 (PDT) 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=yBAyHIZsVPEUTgzr43vz1L6tRP5OB5mLLXAzlt1cbVI=; b=OItH+sHk8KZHF5encWNOFkwJ9hQLRdN0/Owg+439opEC6Z01YjyJMNJwSNGfb6NhhX 4prTMvK0IRum27dg9W8HamWtLxKfPMByrA/xcsjX2+ct3B3Yh4lofCHofjOXO8ITmL6t mCXgScBo7RXbA4tIl1AuoNiISdpdHJfFABZFRxxF0TRTi8dhTcW57vvJCW9Bhs7HxWFq 6X5JDUknVc+9ryDvi0jQ+HU9sZQTVIN2U/y4/kH8czzUNd2yQZYNgoh/tS9Dm+D8KOnu Vt/iZV3OvO8FpThXcwPFr2rZ00wmosIftp0bX2iTFOEU7+s/4wMy4epIeyWLQJMtvf0W b2oQ== X-Gm-Message-State: AOAM530/ZD0mCwFSN2najzH3XQVnMQvs4yH+TnEG0BgiP54AJd+s/tfF A9VGakZb4un3OreScNF09x8= X-Google-Smtp-Source: ABdhPJzl6A/kZjHACv3IpELTvOwRu2PLN+PtgjP26ULTvHT+/o8IMy2sm3FyJLI8NVcS+AkdsvSdFw== X-Received: by 2002:a2e:7814:: with SMTP id t20mr5604852ljc.13.1631305586626; Fri, 10 Sep 2021 13:26:26 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id a22sm657667lfb.17.2021.09.10.13.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 13:26:26 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Greg Kroah-Hartman , =?utf-8?q?Pali_Roh?= =?utf-8?q?=C3=A1r?= , "Oliver O'Halloran" , =?utf-8?q?Krzysztof_Ha=C5=82asa?= , linux-pci@vger.kernel.org Subject: [PATCH v2 1/7] PCI/sysfs: Add pci_dev_resource_attr_is_visible() helper Date: Fri, 10 Sep 2021 20:26:17 +0000 Message-Id: <20210910202623.2293708-2-kw@linux.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210910202623.2293708-1-kw@linux.com> References: <20210910202623.2293708-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This helper controls how a static sysfs attribute is exposed, where depending on whether a particular resource is available (the BAR address space requested has non-zero size) or whether the write-combine feature is supported, the sysfs attribute will be made either visible or hidden. After the conversion to use static sysfs objects when exposing each PCI BAR address space this helper is to be called from the .is_bin_visible() callback for each of the PCI resources attributes groups. A single BAR will have a dedicated attribute group with two attributes in it - one normal resource and one that can potentially support the write-combine feature. Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-sysfs.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 7fb5cd17cc98..4272d1aba205 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1237,6 +1237,30 @@ static int pci_create_resource_files(struct pci_dev *pdev) } return 0; } + +static umode_t pci_dev_resource_attr_is_visible(struct kobject *kobj, + struct bin_attribute *a, + int bar, bool write_combine) +{ + struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); + resource_size_t resource_size = pci_resource_len(pdev, bar); + bool prefetch; + + if (!resource_size) + return 0; + + prefetch = (pci_resource_flags(pdev, bar) & + (IORESOURCE_MEM | IORESOURCE_PREFETCH)) == + (IORESOURCE_MEM | IORESOURCE_PREFETCH); + + if (write_combine && !(prefetch && arch_can_pci_mmap_wc())) + return 0; + + a->size = resource_size; + + return a->attr.mode; +}; + #else /* !(defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)) */ int __weak pci_create_resource_files(struct pci_dev *dev) { return 0; } void __weak pci_remove_resource_files(struct pci_dev *dev) { return; } From patchwork Fri Sep 10 20:26:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12486001 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 X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE4ADC433FE for ; Fri, 10 Sep 2021 20:26:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DDAF60E76 for ; Fri, 10 Sep 2021 20:26:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233498AbhIJU1o (ORCPT ); Fri, 10 Sep 2021 16:27:44 -0400 Received: from mail-lf1-f46.google.com ([209.85.167.46]:38875 "EHLO mail-lf1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233635AbhIJU1k (ORCPT ); Fri, 10 Sep 2021 16:27:40 -0400 Received: by mail-lf1-f46.google.com with SMTP id x27so6449105lfu.5 for ; Fri, 10 Sep 2021 13:26:28 -0700 (PDT) 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=BSY0I3VKOsoIdgVYMSbo9+/e6WBendyy8et/oBmrSfE=; b=3dXauB0pGk7oc74a9u20zxUTovDXKzHFfmEIJ95H3JyxAFCy4qIN6gpS11iafoJRKp umarcnW1AdnYKZkrVMVjsfYSetxh0TzYWK+D6TTAiKUwcxs54ZdKlCmBW8K4T4znoLcx RVdqY+3OFwsiinZ4/Ir83Cek1RdXk37vhxPjrzLPqhd2+f3z8gznXg048bjguOzIa19j /tLBNN/Yyyr1vnaFyzYJnAlF0bOyj1GitdIKNdcCFW3k4e27KFveZKoJTvbV2y/YddjN 0Aczu/flVvhxxI3UcXa51fhfUEu4FDyXDpGtvpbzX65fmeQQPyd0U8VeauJX5nWbeon3 /1Ig== X-Gm-Message-State: AOAM532/v5urqms0bz4VcxeAKbkpWr5cyWvtDBE/KXXTXFtKQQo7JDO3 og2rDqtk0sayw9H6bCG7AHE= X-Google-Smtp-Source: ABdhPJwDU4Ymo5vqpvVCIIQ5vZ25wcRBW4sQUKjpF12x1V/GrJS+e72UkFcDrGuy/uIZewSwWB1wwg== X-Received: by 2002:a05:6512:32c9:: with SMTP id f9mr5189742lfg.249.1631305587678; Fri, 10 Sep 2021 13:26:27 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id a22sm657667lfb.17.2021.09.10.13.26.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 13:26:27 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Greg Kroah-Hartman , =?utf-8?q?Pali_Roh?= =?utf-8?q?=C3=A1r?= , "Oliver O'Halloran" , =?utf-8?q?Krzysztof_Ha=C5=82asa?= , linux-pci@vger.kernel.org Subject: [PATCH v2 2/7] PCI/sysfs: Add pci_dev_resource_attr() macro Date: Fri, 10 Sep 2021 20:26:18 +0000 Message-Id: <20210910202623.2293708-3-kw@linux.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210910202623.2293708-1-kw@linux.com> References: <20210910202623.2293708-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The pci_dev_resource_attr() macro will be used to declare and define each of the PCI resource sysfs objects statically while also reducing unnecessary code repetition. This macro aims to also replace functions pci_create_resource_files() and pci_create_attr() that are currently involved in the PCI resource sysfs objects dynamic creation and set up once the. Internally this macro relies on the pci_dev_resource_attr_is_visible() helper which should correctly handle creating either normal and/or write-combine attributes as required. Two other macros were also added to help reduce code duplication, the pci_dev_bin_attribute() and pci_dev_resource_group(). The pci_dev_bin_attribute() macro abstracts the declaration and definition of a binary attribute with all the required fields from struct bin_attribute set as needed for a given PCI resource sysfs attribute. The pci_dev_resource_group() macro will be used to reduce unnecessary code repetition following the use of the pci_dev_resource_attr() macro when adding each of the many newly created resource groups to the list of other PCI sysfs objects stored in the pci_dev_groups array. The conversion to static sysfs objects will result in two sysfs attributes to be created for each PCI resource (the underlying BAR) independently, one for a normal resource, and one for a resource that is write-combine capable, should this feature be supported. Each such resource will be then placed in a dedicated attribute resource group so that access to it can be controlled using a dedicated .is_bin_visible() callback where depending on what the underlying resource (a given BAR) supports will be either made visible or hidden. Therefore, for six standard PCI BARs, a total of twelve attribute groups will be thus created per device. Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-sysfs.c | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 4272d1aba205..ccdd1e34aeee 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1261,6 +1261,67 @@ static umode_t pci_dev_resource_attr_is_visible(struct kobject *kobj, return a->attr.mode; }; +#define pci_dev_bin_attribute(_name, _mmap, _bar) \ +struct bin_attribute pci_dev_##_name##_attr = { \ + .attr = { .name = __stringify(_name), .mode = 0600 }, \ + .read = pci_read_resource_io, \ + .write = pci_write_resource_io, \ + .mmap = _mmap, \ + .private = (void *)(unsigned long)_bar, \ + .f_mapping = iomem_get_mapping, \ +} + +#define pci_dev_resource_attr(_bar) \ +static pci_dev_bin_attribute(resource##_bar, \ + pci_mmap_resource_uc, \ + _bar); \ + \ +static struct bin_attribute *pci_dev_resource##_bar##_attrs[] = { \ + &pci_dev_resource##_bar##_attr, \ + NULL, \ +}; \ + \ +static umode_t \ +pci_dev_resource##_bar##_attr_is_visible(struct kobject *kobj, \ + struct bin_attribute *a, \ + int n) \ +{ \ + return pci_dev_resource_attr_is_visible(kobj, a, _bar, false); \ +}; \ + \ +static const struct \ +attribute_group pci_dev_resource##_bar##_attr_group = { \ + .bin_attrs = pci_dev_resource##_bar##_attrs, \ + .is_bin_visible = pci_dev_resource##_bar##_attr_is_visible, \ +}; \ + \ +static pci_dev_bin_attribute(resource##_bar##_wc, \ + pci_mmap_resource_wc, \ + _bar); \ + \ +static struct bin_attribute *pci_dev_resource##_bar##_wc_attrs[] = { \ + &pci_dev_resource##_bar##_wc_attr, \ + NULL, \ +}; \ + \ +static umode_t \ +pci_dev_resource##_bar##_wc_attr_is_visible(struct kobject *kobj, \ + struct bin_attribute *a, \ + int n) \ +{ \ + return pci_dev_resource_attr_is_visible(kobj, a, _bar, true); \ +}; \ + \ +static const struct \ +attribute_group pci_dev_resource##_bar##_wc_attr_group = { \ + .bin_attrs = pci_dev_resource##_bar##_wc_attrs, \ + .is_bin_visible = pci_dev_resource##_bar##_wc_attr_is_visible, \ +} + +#define pci_dev_resource_group(_bar) \ + &pci_dev_resource##_bar##_attr_group, \ + &pci_dev_resource##_bar##_wc_attr_group + #else /* !(defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)) */ int __weak pci_create_resource_files(struct pci_dev *dev) { return 0; } void __weak pci_remove_resource_files(struct pci_dev *dev) { return; } From patchwork Fri Sep 10 20:26:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12485997 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 X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F6EBC4332F for ; Fri, 10 Sep 2021 20:26:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DADDD60E0B for ; Fri, 10 Sep 2021 20:26:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233635AbhIJU1o (ORCPT ); Fri, 10 Sep 2021 16:27:44 -0400 Received: from mail-lj1-f169.google.com ([209.85.208.169]:33349 "EHLO mail-lj1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233715AbhIJU1l (ORCPT ); Fri, 10 Sep 2021 16:27:41 -0400 Received: by mail-lj1-f169.google.com with SMTP id s12so5189731ljg.0 for ; Fri, 10 Sep 2021 13:26:29 -0700 (PDT) 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=uqfQt5c1SW21pKtEyRPySF5oZi27MiZQXZzAu2FFZCs=; b=xf+GSJ+U+cJsVHC77uoxMRPbt3m7F3hSN6i3zGJ64sa7gFTUWOCaMucdHiB0aSf8Tx 7ovu/dC4YbIoh0Turx9zqCmoQDJdUbCogHLmtZRJRrr/3BvaU8yOMmudoUW5XAh5y2yT C3Lyx1ezAlOhHZLQbBeGuPkTU9DFOpfC/9O49B6K1s37zO9EddoE5lL9mqUjSt8T6CSJ aRzJulg/uoZOMrMw6j3rqCZrsF6GoGDoZzOBEPHTBPjrj+kb79sqxZXz9SiqzV2Wp2q0 NzqM+iQ6YCNKW/hLbS1+voVzeFj8h1P7sL9ZNHFD4NA6CnRCtTvpF0FSvFyfMJp2m37a nhcg== X-Gm-Message-State: AOAM532AE2ofiJ1lHIQQ76WZY5FOtaRU7z9GzfLXxc7KZ4K2sAPuJ5QQ wey/7NjkHaOb+O/Xj8TJ0ZQ= X-Google-Smtp-Source: ABdhPJyHb9iCBzQqvKdtEMAbq6f5qnyv+c6gxyOPfoA9wMsYxylQ9/BVkcdEgT1Gw/hYO4dd/R2LXw== X-Received: by 2002:a2e:6c05:: with SMTP id h5mr5771787ljc.42.1631305588678; Fri, 10 Sep 2021 13:26:28 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id a22sm657667lfb.17.2021.09.10.13.26.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 13:26:28 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Greg Kroah-Hartman , =?utf-8?q?Pali_Roh?= =?utf-8?q?=C3=A1r?= , "Oliver O'Halloran" , =?utf-8?q?Krzysztof_Ha=C5=82asa?= , linux-pci@vger.kernel.org Subject: [PATCH v2 3/7] PCI/sysfs: Only allow IORESOURCE_IO in pci_resource_io() Date: Fri, 10 Sep 2021 20:26:19 +0000 Message-Id: <20210910202623.2293708-4-kw@linux.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210910202623.2293708-1-kw@linux.com> References: <20210910202623.2293708-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Currently, when the sysfs attributes for PCI resources are added dynamically, the read() and write() callbacks will only ever be set when the underlying resource (a given BAR) has the IORESOURCE_IO flag set, otherwise the callbacks will be NULL and any attempt to read from such sysfs attribute will inherently fail. After the conversion to the static sysfs objects, the read() and write() callbacks will be always set for a given binary attribute (a particular sysfs object). Thus, a check is added to the pci_resource_io() function to ensure that a read against the underlying resource is supported and that the IORESOURCE_IO flag is set. Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-sysfs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index ccdd1e34aeee..e151d635fe04 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1084,6 +1084,9 @@ static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj, int bar = (unsigned long)attr->private; unsigned long port = off; + if (!(pci_resource_flags(pdev, bar) & IORESOURCE_IO)) + return -EIO; + port += pci_resource_start(pdev, bar); if (port > pci_resource_end(pdev, bar)) From patchwork Fri Sep 10 20:26:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12485995 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 X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78941C43217 for ; Fri, 10 Sep 2021 20:26:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5377D60F45 for ; Fri, 10 Sep 2021 20:26:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233715AbhIJU1o (ORCPT ); Fri, 10 Sep 2021 16:27:44 -0400 Received: from mail-lf1-f47.google.com ([209.85.167.47]:46599 "EHLO mail-lf1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233733AbhIJU1m (ORCPT ); Fri, 10 Sep 2021 16:27:42 -0400 Received: by mail-lf1-f47.google.com with SMTP id t19so6390861lfe.13 for ; Fri, 10 Sep 2021 13:26:30 -0700 (PDT) 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=SCWGEafDm9+a2Gvdto/l8SUM0CdXaX/vrNhpnx0tOGg=; b=oiLg2BBp8CeqstP4eRMYLD73yQK8nbprLpEXvxroqiuPr4kfCzYtGuJxGdvVkoZYw0 YNwQTEoH8HP9LmjdYuHPL6xtXXWucRop7De/DeevzxfsnEngseN7EwVlFSrGYsT5BgfT j5XXtW//hB5ZrqgPRCocT4yYxup9n2UdVQnuOkzgFN0jhDjBAQDT/PZcBJnENlTLvVt3 e/sG+pmDRXHJ7G5FhexJP6P0qc4C5/4eu3euQ8JK5+1r922/4Npz3ax1e5FSFta2f4vC yu967JpR4wPBDU9WZNJKUCX6Ux6plvQOUWtdUJQV0T1xgqlvJDucH2Kkvz3ZTZSGwsNV oaFA== X-Gm-Message-State: AOAM531AyDJ8O+NSfY9xDvlihQYWWNN/efhTPbraXSeDOOqksOpZwDJH +it9zdXqtp1jgJ5CsWC4/Rs= X-Google-Smtp-Source: ABdhPJw9PsY3v1dNQCjFlM2XHn3SHsklA6wQYVyWe/n3qp0lbcsdZdAb2gHMJc/v6w/NIxZjjdMZIg== X-Received: by 2002:a05:6512:96f:: with SMTP id v15mr5083269lft.455.1631305589686; Fri, 10 Sep 2021 13:26:29 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id a22sm657667lfb.17.2021.09.10.13.26.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 13:26:29 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Greg Kroah-Hartman , =?utf-8?q?Pali_Roh?= =?utf-8?q?=C3=A1r?= , "Oliver O'Halloran" , =?utf-8?q?Krzysztof_Ha=C5=82asa?= , linux-pci@vger.kernel.org Subject: [PATCH v2 4/7] PCI/sysfs: Only allow supported resource type in pci_mmap_resource() Date: Fri, 10 Sep 2021 20:26:20 +0000 Message-Id: <20210910202623.2293708-5-kw@linux.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210910202623.2293708-1-kw@linux.com> References: <20210910202623.2293708-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Currently, when the sysfs attributes for PCI resources are added dynamically, the mmap() callback will only ever be set when the underlying resource (a given BAR) has either the IORESOURCE_MEM (which currently is implied) or IORESOURCE_IO flag set and where the latter requires that the underlying architecture supports mmap() for I/O BARs, otherwise the callbacks are set to NULL and any attempt to read from such sysfs attribute will inherently fail. Following the conversion to the static sysfs objects, the mmap() callbacks will be always set for a given binary attribute (a particular sysfs object). Thus, a check is added to the pci_mmap_resource() function to ensure that a read against the underlying resource is supported and that either the IORESOURCE_MEM or IORESOURCE_IO flag is set with the platform supporting mmap() for I/O BARs as required. Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-sysfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index e151d635fe04..2031b5da6bcf 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1051,6 +1051,10 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr, if (ret) return ret; + if (!(res->flags & IORESOURCE_MEM || + ((res->flags & IORESOURCE_IO) && arch_can_pci_mmap_io()))) + return -EIO; + if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(res->start)) return -EINVAL; From patchwork Fri Sep 10 20:26:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12486003 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 X-Spam-Level: X-Spam-Status: No, score=-21.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9908C4321E for ; Fri, 10 Sep 2021 20:26:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9171A61059 for ; Fri, 10 Sep 2021 20:26:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233733AbhIJU1p (ORCPT ); Fri, 10 Sep 2021 16:27:45 -0400 Received: from mail-lf1-f49.google.com ([209.85.167.49]:33716 "EHLO mail-lf1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233742AbhIJU1n (ORCPT ); Fri, 10 Sep 2021 16:27:43 -0400 Received: by mail-lf1-f49.google.com with SMTP id n2so6537183lfk.0 for ; Fri, 10 Sep 2021 13:26:31 -0700 (PDT) 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=DiOpE3WyY4/ZpnwxyMCEu2mtrwH7ajbKZ/RguIir4mo=; b=aHSO3/erFGZQci+jdq3IaYEJf/mT7qzogSsasMstiSd4LEK+kcamq9rU4gxOSskpOC R2cmzJC36k2G3YPMltOCBIHL86T2u28FmaEoBYVNmWkPgZcNhV8xcrOTIJMjN36A/fWo /6OoLREaOoJ46MLgOcv0UQyi3cJrXKlLwxz1dysvG6xS8iJ7EjEAkCuhFSBYBr8++CSb bjDytiNrhLGhP6Uk/vAgXpF2NRwQwIS65Q+kFM78XMCM840hnJ+nVhbqQ5IX+gkZio/A USfnZBdmcHBpGl8PUvyqi8UNfgCt5V2qVt8M6ataZX723UwQyYvN3fRFz9iW7oRh9MwC 73LA== X-Gm-Message-State: AOAM532Q11gGsyObs/sXx0ZY4Cj5OzoczZjSFfcoGOuZTt4TK+TyBF/c UydglNPv/5I6T22YKDGhP2A= X-Google-Smtp-Source: ABdhPJxJfkyu33jxnUZklxnt02d2H3BlVWwnctdbhxrj3QR2ai2JYqm2BBLIwK7BkY3rwzQMLBJvBg== X-Received: by 2002:ac2:4e90:: with SMTP id o16mr5161328lfr.473.1631305590743; Fri, 10 Sep 2021 13:26:30 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id a22sm657667lfb.17.2021.09.10.13.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 13:26:30 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Greg Kroah-Hartman , =?utf-8?q?Pali_Roh?= =?utf-8?q?=C3=A1r?= , "Oliver O'Halloran" , =?utf-8?q?Krzysztof_Ha=C5=82asa?= , linux-pci@vger.kernel.org Subject: [PATCH v2 5/7] PCI/sysfs: Convert PCI resource files to static attributes Date: Fri, 10 Sep 2021 20:26:21 +0000 Message-Id: <20210910202623.2293708-6-kw@linux.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210910202623.2293708-1-kw@linux.com> References: <20210910202623.2293708-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The PCI resource files are a series of sysfs objects that allow for access to the PCI BAR address space. Previously, the PCI resource files for platforms that provide either the HAVE_PCI_MMAP or ARCH_GENERIC_PCI_MMAP_RESOURCE definitions were dynamically created by pci_bus_add_device() or the pci_sysfs_init() late_initcall, but since these objects do not need to be created or removed dynamically, we can use static attributes so the device model takes care of addition and removal automatically. Thus, convert the PCI resources files to static attributes on supported platforms using the pci_dev_resource_attr() macro. This macro makes use of the .is_bin_visible() callback to support creating either normal or write-combine attributes as required. Platforms that do currently do not define either the HAVE_PCI_MMAP or ARCH_GENERIC_PCI_MMAP_RESOURCE such as the Alpha platform can keep using their platform-specific methods for adding PCI resources files. Also remove pci_create_resource_files(), pci_remove_resource_files() and pci_create_attr() functions, which are no longer needed. The PCI resource files were first added in the pre-Git era: https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/drivers/pci/pci-sysfs.c?id=42298be0eeb5ae98453b3374c36161b05a46c5dc Support for write-combine resources was added in commit 45aec1a ("x86: PAT export resource_wc in pci sysfs"). Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-sysfs.c | 129 ++++++++-------------------------------- include/linux/pci.h | 2 + 2 files changed, 28 insertions(+), 103 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 2031b5da6bcf..084c386c94c4 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1142,109 +1142,6 @@ static ssize_t pci_write_resource_io(struct file *filp, struct kobject *kobj, return pci_resource_io(filp, kobj, attr, buf, off, count, true); } -/** - * pci_remove_resource_files - cleanup resource files - * @pdev: dev to cleanup - * - * If we created resource files for @pdev, remove them from sysfs and - * free their resources. - */ -static void pci_remove_resource_files(struct pci_dev *pdev) -{ - int i; - - for (i = 0; i < PCI_STD_NUM_BARS; i++) { - struct bin_attribute *res_attr; - - res_attr = pdev->res_attr[i]; - if (res_attr) { - sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); - kfree(res_attr); - } - - res_attr = pdev->res_attr_wc[i]; - if (res_attr) { - sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); - kfree(res_attr); - } - } -} - -static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine) -{ - /* allocate attribute structure, piggyback attribute name */ - int name_len = write_combine ? 13 : 10; - struct bin_attribute *res_attr; - char *res_attr_name; - int retval; - - res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC); - if (!res_attr) - return -ENOMEM; - - res_attr_name = (char *)(res_attr + 1); - - sysfs_bin_attr_init(res_attr); - if (write_combine) { - pdev->res_attr_wc[num] = res_attr; - sprintf(res_attr_name, "resource%d_wc", num); - res_attr->mmap = pci_mmap_resource_wc; - } else { - pdev->res_attr[num] = res_attr; - sprintf(res_attr_name, "resource%d", num); - if (pci_resource_flags(pdev, num) & IORESOURCE_IO) { - res_attr->read = pci_read_resource_io; - res_attr->write = pci_write_resource_io; - if (arch_can_pci_mmap_io()) - res_attr->mmap = pci_mmap_resource_uc; - } else { - res_attr->mmap = pci_mmap_resource_uc; - } - } - if (res_attr->mmap) - res_attr->f_mapping = iomem_get_mapping; - res_attr->attr.name = res_attr_name; - res_attr->attr.mode = 0600; - res_attr->size = pci_resource_len(pdev, num); - res_attr->private = (void *)(unsigned long)num; - retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr); - if (retval) - kfree(res_attr); - - return retval; -} - -/** - * pci_create_resource_files - create resource files in sysfs for @dev - * @pdev: dev in question - * - * Walk the resources in @pdev creating files for each resource available. - */ -static int pci_create_resource_files(struct pci_dev *pdev) -{ - int i; - int retval; - - /* Expose the PCI resources from this device as files */ - for (i = 0; i < PCI_STD_NUM_BARS; i++) { - - /* skip empty resources */ - if (!pci_resource_len(pdev, i)) - continue; - - retval = pci_create_attr(pdev, i, 0); - /* for prefetchable resources, create a WC mappable file */ - if (!retval && arch_can_pci_mmap_wc() && - pdev->resource[i].flags & IORESOURCE_PREFETCH) - retval = pci_create_attr(pdev, i, 1); - if (retval) { - pci_remove_resource_files(pdev); - return retval; - } - } - return 0; -} - static umode_t pci_dev_resource_attr_is_visible(struct kobject *kobj, struct bin_attribute *a, int bar, bool write_combine) @@ -1329,6 +1226,13 @@ attribute_group pci_dev_resource##_bar##_wc_attr_group = { \ &pci_dev_resource##_bar##_attr_group, \ &pci_dev_resource##_bar##_wc_attr_group +pci_dev_resource_attr(0); +pci_dev_resource_attr(1); +pci_dev_resource_attr(2); +pci_dev_resource_attr(3); +pci_dev_resource_attr(4); +pci_dev_resource_attr(5); + #else /* !(defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)) */ int __weak pci_create_resource_files(struct pci_dev *dev) { return 0; } void __weak pci_remove_resource_files(struct pci_dev *dev) { return; } @@ -1470,6 +1374,10 @@ static const struct attribute_group pci_dev_reset_attr_group = { .is_visible = pci_dev_reset_attr_is_visible, }; +#if defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE) +int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev) { return 0; } +void pci_remove_sysfs_dev_files(struct pci_dev *pdev) { } +#else /* !(defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)) */ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev) { if (!sysfs_initialized) @@ -1491,9 +1399,15 @@ void pci_remove_sysfs_dev_files(struct pci_dev *pdev) pci_remove_resource_files(pdev); } +#endif static int __init pci_sysfs_init(void) { +#if defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE) + struct pci_bus *pbus = NULL; + + sysfs_initialized = 1; +#else /* !(defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)) */ struct pci_dev *pdev = NULL; struct pci_bus *pbus = NULL; int retval; @@ -1507,6 +1421,7 @@ static int __init pci_sysfs_init(void) } } +#endif while ((pbus = pci_find_next_bus(pbus))) pci_create_legacy_files(pbus); @@ -1580,6 +1495,14 @@ static const struct attribute_group pci_dev_group = { const struct attribute_group *pci_dev_groups[] = { &pci_dev_group, +#if defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE) + pci_dev_resource_group(0), + pci_dev_resource_group(1), + pci_dev_resource_group(2), + pci_dev_resource_group(3), + pci_dev_resource_group(4), + pci_dev_resource_group(5), +#endif &pci_dev_config_attr_group, &pci_dev_rom_attr_group, &pci_dev_reset_attr_group, diff --git a/include/linux/pci.h b/include/linux/pci.h index cd8aa6fce204..51c632e5d0f7 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -459,8 +459,10 @@ struct pci_dev { u32 saved_config_space[16]; /* Config space saved at suspend time */ struct hlist_head saved_cap_space; int rom_attr_enabled; /* Display of ROM attribute enabled? */ +#if !(defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)) struct bin_attribute *res_attr[DEVICE_COUNT_RESOURCE]; /* sysfs file for resources */ struct bin_attribute *res_attr_wc[DEVICE_COUNT_RESOURCE]; /* sysfs file for WC mapping of resources */ +#endif #ifdef CONFIG_HOTPLUG_PCI_PCIE unsigned int broken_cmd_compl:1; /* No compl for some cmds */ From patchwork Fri Sep 10 20:26:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12485999 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 X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 194A4C433EF for ; Fri, 10 Sep 2021 20:26:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F38DE60E76 for ; Fri, 10 Sep 2021 20:26:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233742AbhIJU1p (ORCPT ); Fri, 10 Sep 2021 16:27:45 -0400 Received: from mail-lj1-f170.google.com ([209.85.208.170]:44964 "EHLO mail-lj1-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233767AbhIJU1o (ORCPT ); Fri, 10 Sep 2021 16:27:44 -0400 Received: by mail-lj1-f170.google.com with SMTP id s3so5088390ljp.11 for ; Fri, 10 Sep 2021 13:26:32 -0700 (PDT) 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=4ZuH0jzBV51o66YWzpZ25xw+RCnaMfe3266VXxf4r4w=; b=ZRs+rgqBMsVB6eJCgFhqgoDeBthnH0I7I6z/ZjyxU1zzeO9kiKnD8G4GdTvixSOMdb II6ndVxjUXpGH57jXK1x9aYj1xnFoBrtNBQo9cAZ9b4X+igHxcY4Nlo5jyY/fHEOPWpn 6UjrL1kabxMrv763Z+gNBqeRhbg0pwLrb7GrzJ0BtRr493JiMHLPhHUUxKA/IgiYEBcK Ky/iEwTrhEoHfJJAnsQmMvMqCH5p/t4Zje+9gIuLLu0Fj5QTaL6tcAHr6Up2X453S7+g mx1TXylcHoFRq0GbXmZ1aAm79posNA51xwePy+Q2pIHJUNaN2wn949fNykQhfp+2Uzpq GnNQ== X-Gm-Message-State: AOAM53375Zb3PghAb08d8d3yyBQMHWeTLk4tBnxnlX1MgksYeafmhHEi LHehg4Vy/V1kKMsuzIODpEHCJmP5Mk0= X-Google-Smtp-Source: ABdhPJyJ5nQ0M2joP/C5/jOXMjoCLgrgemyY8etqh7DkT9YVvc48+FNnDrdXGPlVtFUajovrqxyJWg== X-Received: by 2002:a05:651c:310:: with SMTP id a16mr5596080ljp.492.1631305591818; Fri, 10 Sep 2021 13:26:31 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id a22sm657667lfb.17.2021.09.10.13.26.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 13:26:31 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Greg Kroah-Hartman , =?utf-8?q?Pali_Roh?= =?utf-8?q?=C3=A1r?= , "Oliver O'Halloran" , =?utf-8?q?Krzysztof_Ha=C5=82asa?= , linux-pci@vger.kernel.org Subject: [PATCH v2 6/7] PCI/sysfs: Rename pci_read_resource_io() and pci_write_resource_io() Date: Fri, 10 Sep 2021 20:26:22 +0000 Message-Id: <20210910202623.2293708-7-kw@linux.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210910202623.2293708-1-kw@linux.com> References: <20210910202623.2293708-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The pci_read_resource_io() and pci_write_resource_io() functions are used for the corresponding read() and write() callbacks when declaring and defining a static sysfs object for a given PCI resource. Currently, only reading and writing against an I/O BARs is supported, but we might change this in the future to also include memory-mapped resources. Thus, rename to read() and write() callbacks to be more generic and drop the I/O BARs-specific suffix from them. Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-sysfs.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 084c386c94c4..17535f4028af 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1122,16 +1122,16 @@ static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj, return -EINVAL; } -static ssize_t pci_read_resource_io(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count) +static ssize_t pci_read_resource(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, char *buf, + loff_t off, size_t count) { return pci_resource_io(filp, kobj, attr, buf, off, count, false); } -static ssize_t pci_write_resource_io(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count) +static ssize_t pci_write_resource(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, char *buf, + loff_t off, size_t count) { int ret; @@ -1168,8 +1168,8 @@ static umode_t pci_dev_resource_attr_is_visible(struct kobject *kobj, #define pci_dev_bin_attribute(_name, _mmap, _bar) \ struct bin_attribute pci_dev_##_name##_attr = { \ .attr = { .name = __stringify(_name), .mode = 0600 }, \ - .read = pci_read_resource_io, \ - .write = pci_write_resource_io, \ + .read = pci_read_resource, \ + .write = pci_write_resource, \ .mmap = _mmap, \ .private = (void *)(unsigned long)_bar, \ .f_mapping = iomem_get_mapping, \ From patchwork Fri Sep 10 20:26:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12486005 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 X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 691ADC43219 for ; Fri, 10 Sep 2021 20:26:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A5A260FC2 for ; Fri, 10 Sep 2021 20:26:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233767AbhIJU1p (ORCPT ); Fri, 10 Sep 2021 16:27:45 -0400 Received: from mail-lf1-f42.google.com ([209.85.167.42]:36684 "EHLO mail-lf1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233783AbhIJU1p (ORCPT ); Fri, 10 Sep 2021 16:27:45 -0400 Received: by mail-lf1-f42.google.com with SMTP id c8so6470639lfi.3 for ; Fri, 10 Sep 2021 13:26:33 -0700 (PDT) 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=Ci/PBCckgs64eaxt+gMPCPMWq/pAK0//yJPrgBnmYXs=; b=sBshwizvs8kBobki3x+rXy+x0hI47t3PQHBvN5GQrFf/dzNtCg/EDkzGqsP5TMW0ap Z1hqZZO+KrcRhN0kiPMQ/5vrZtg+uT1je0dDkQ7VXqeGcPARWD0kYy+ooWlumOdGoelH 3Ixqua0E3JNo/eWmRsDOkZYdUlVjPqE7mlS13hrkY7DiqyMLyHOFG3URUSgwZcDm1eCv V4tsgWlyNAHiCoArssG8GBXjIjbakJRuQA37LSd0stSrXF88rrA8GDQU66MUjTabSXCv 2oS3PHWcnu9GikmZ09FXXip7qVMk+QlTDNAFxSMVILn+z6RNgVnkcO3ha14+4CqX/Kty EluQ== X-Gm-Message-State: AOAM533KJBIhCu4TEYoZzf+zJo4jCx/LupQ1p3mFFgQXSHWxOYOA809W NEKBma3BKDvt9DYRKgTSTN4= X-Google-Smtp-Source: ABdhPJxUMPMgd5IGic50hPkJc6HTX7z7vXTq2n5XmwHoFBGY3T9iGmchNvVbjDu6tzTHsluMwwdh6Q== X-Received: by 2002:a19:c757:: with SMTP id x84mr5122051lff.134.1631305592836; Fri, 10 Sep 2021 13:26:32 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id a22sm657667lfb.17.2021.09.10.13.26.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 13:26:32 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Greg Kroah-Hartman , =?utf-8?q?Pali_Roh?= =?utf-8?q?=C3=A1r?= , "Oliver O'Halloran" , =?utf-8?q?Krzysztof_Ha=C5=82asa?= , linux-pci@vger.kernel.org Subject: [PATCH v2 7/7] PCI/sysfs: Update code to match the preferred style Date: Fri, 10 Sep 2021 20:26:23 +0000 Message-Id: <20210910202623.2293708-8-kw@linux.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210910202623.2293708-1-kw@linux.com> References: <20210910202623.2293708-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Update code to match the preferred style while making the bitwise operations less ambiguous with added extra parentheses surrounding the expression. Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-sysfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 17535f4028af..fdfe4aa70875 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1013,7 +1013,7 @@ int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma, unsigned long nr, start, size; resource_size_t pci_start = 0, pci_end; - if (pci_resource_len(pdev, resno) == 0) + if (!pci_resource_len(pdev, resno)) return 0; nr = vma_pages(vma); start = vma->vm_pgoff; @@ -1055,13 +1055,13 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr, ((res->flags & IORESOURCE_IO) && arch_can_pci_mmap_io()))) return -EIO; - if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(res->start)) + if ((res->flags & IORESOURCE_MEM) && iomem_is_exclusive(res->start)) return -EINVAL; if (!pci_mmap_fits(pdev, bar, vma, PCI_MMAP_SYSFS)) return -EINVAL; - mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io; + mmap_type = (res->flags & IORESOURCE_MEM) ? pci_mmap_mem : pci_mmap_io; return pci_mmap_resource_range(pdev, bar, vma, mmap_type, write_combine); }