From patchwork Thu Feb 22 11:46:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 204769 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp262324dyb; Thu, 22 Feb 2024 05:50:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWQb8kWsXFK/TAM+FIvh2SwsfJ710DoNnOP4wn4eSI7Ut97UX8nxJUrfC0/C2kbFBn/UN6Ou/HboRzMN5b9ivGH4rgqGQ== X-Google-Smtp-Source: AGHT+IH03lGxNPZvec6zW3KjzM+RiJXI0jQt4lbYNQr3ZF/Yh85CRpxoAAQyZdcmrThmhNHcpF2S X-Received: by 2002:a05:6a00:1d10:b0:6e4:da27:785d with SMTP id a16-20020a056a001d1000b006e4da27785dmr104541pfx.8.1708609809110; Thu, 22 Feb 2024 05:50:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708609809; cv=pass; d=google.com; s=arc-20160816; b=DUCcq9CtxdMRDqUP0yrPVs963IHLNdhsDZ6Xp7uw5MQo/TYxGTTWHQiVMdQdkE1rNl 3uot/PZXF2Odq3Ogt+Gf7IgiSmbeMgvfF0n/EBb5SZn9JNC7CKjanD4Of521KVTF0UPY Ij9vvgxZjXto42UOiV2UdBsHDF0c1SaqcPSAvkkIUQ8L9eWmnLzbPQITo3L4o83Kbdau QPvLn+jhkgloIuURtJlaMuL+bwJqZC2cK70/dTug+whKf4MUsHNqs7VXqmWmd7xeGJdA K8HaEJkQQf8y/O7r+kuF4o4Uki9885ULw1pQ8ebsibsakPc5VihsoWSunYhG/kB77Tdp zM5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=GBPqS+eaexJ6/3PtVatezFSH27zdPSAYQbBkYHKLK9I=; fh=E3kzHqS1Jm88FpWLmLYVxK5f65z6O2nEEtILSQsq/7g=; b=Bg4zIv6gHMx9NeivhSZd+yVJ0BdjRu+QN3zKE6Yi/buQnrTz7yWsC0BZt2kIJLDBz7 /BOM05GiqXTeYF+CS/9+6ZJ72oGcaAuOWJr/5+70WWTsGiwoA0RdRNGZH47gWzPin14W nosacrnMsLkA2960rM632IpxDs2Guwnp1I+6Gy7Vr1C2JnkPvso7pOHU625vy8ocgLSS hHVJRaNi86rLJ43ZMwtzHbdYl9uWer0KJxp0zkypuYCtf/YKTTEvdUibeY/eerF0MROT r4ApkBFbneb2xstjsW9FZZ3JWGVwu2EztxLRcVhTWmTUZlP/H/uDHlGEx3tBLQZuhSRK H/dQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=i8KFdnaf; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76440-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76440-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b22-20020a639316000000b005d9b49b7ad6si10051223pge.775.2024.02.22.05.50.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:50:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76440-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=i8KFdnaf; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-76440-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76440-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 76F63B21BEC for ; Thu, 22 Feb 2024 11:46:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71B5D46448; Thu, 22 Feb 2024 11:46:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="i8KFdnaf" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 A891C208A2; Thu, 22 Feb 2024 11:46:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708602393; cv=none; b=AcrbAckKtc6W3Ma28JRncoWAIZhrrnt3USZohsVC0+vLraxhsYJYFO2xq9/eyj4I4QeLjzRvGvhldFTOEzR/vauwA5SvrQtMQFKL+pCf+aEvR9lU2H8ftyGWGbS2pgEwc8gncRyNaNCNw3W7cB8kKFKT6P19c29m55g+F4sUfs4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708602393; c=relaxed/simple; bh=U/ODfnHwPi5+9NrV+Ux+CV06sA5Ml+gF11lFUa0pFdY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=BME4IREv/Ap2gGCZQCw2pte4G6rXZqg3H2M2gojNFvqYOfTMyMN1lNs7ZebghPYvA9BOvoNgQQXgVn7dBsFIk2GfB/UMJTv6Z83ximOLfqpYhIwKExlEifYZaQV5amHXkKLxU83K4VbBk5y10QrVM5JJa2bLkppkbPVFWVmFdGI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=i8KFdnaf; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708602391; x=1740138391; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=U/ODfnHwPi5+9NrV+Ux+CV06sA5Ml+gF11lFUa0pFdY=; b=i8KFdnafKk0s0KRkmi87a2vigx642+bWfIXYLcUj3wl8Ue6ahv+ND/8y CO+qZtdAXyofUkr8bXMZPJoeBmh8Tq22p2rgY34ZuM73W201luFNQsS0e 6iZpoOgnCOfFAsGms64L6NmgEGwzN5xAZLUoQ+Za3/syh+RfiGKmqOHuS NLujUsrzpKxalbAOjalQw4bQGKp+AfSzcky9zlpMTsvZ6jDCku3YZjb8e hQA1NkT8AUH5VW1bcryO1n9PzTt0ytkDEk4Dn3sKDTi3KyJfjHbxFbaJ2 3dv2SgzL07RqMEZvgZPHkps6ZsKtIZhhx3uqLWroU4QyUNlNXyuPI51LW Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10991"; a="13522191" X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="13522191" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 03:46:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,177,1705392000"; d="scan'208";a="5436460" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.94.249.55]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 03:46:29 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 1/1] PCI/sysfs: Demacrofy pci_dev_resource_resize_attr(n) functions Date: Thu, 22 Feb 2024 13:46:06 +0200 Message-Id: <20240222114607.1837-1-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791607239114773309 X-GMAIL-MSGID: 1791607239114773309 pci_dev_resource_resize_attr(n) macro is invoked for six resources, creating a large footprint function for each resource. Rework the macro to only create a function that calls a helper function so the compiler can decide if it warrants to inline the function or not. With x86_64 defconfig, this saves roughly 2.5kB: $ scripts/bloat-o-meter drivers/pci/pci-sysfs.o{.old,.new} add/remove: 1/0 grow/shrink: 0/6 up/down: 512/-2934 (-2422) Function old new delta __resource_resize_store - 512 +512 resource5_resize_store 503 14 -489 resource4_resize_store 503 14 -489 resource3_resize_store 503 14 -489 resource2_resize_store 503 14 -489 resource1_resize_store 503 14 -489 resource0_resize_store 500 11 -489 Total: Before=13399, After=10977, chg -18.08% (The compiler seemingly chose to still inline __resource_resize_show() which is fine, those functions are not very complex/large.) Signed-off-by: Ilpo Järvinen --- drivers/pci/pci-sysfs.c | 138 +++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 64 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 2321fdfefd7d..613c5fc4f0a2 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1410,79 +1410,89 @@ static const struct attribute_group pci_dev_reset_attr_group = { .is_visible = pci_dev_reset_attr_is_visible, }; +static ssize_t __resource_resize_show(struct device *dev, int n, char *buf) +{ + struct pci_dev *pdev = to_pci_dev(dev); + ssize_t ret; + + pci_config_pm_runtime_get(pdev); + + ret = sysfs_emit(buf, "%016llx\n", + (u64)pci_rebar_get_possible_sizes(pdev, n)); + + pci_config_pm_runtime_put(pdev); + + return ret; +} + +static ssize_t __resource_resize_store(struct device *dev, int n, + const char *buf, size_t count) +{ + struct pci_dev *pdev = to_pci_dev(dev); + unsigned long size, flags; + int ret, i; + u16 cmd; + + if (kstrtoul(buf, 0, &size) < 0) + return -EINVAL; + + device_lock(dev); + if (dev->driver) { + ret = -EBUSY; + goto unlock; + } + + pci_config_pm_runtime_get(pdev); + + if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) { + ret = aperture_remove_conflicting_pci_devices(pdev, + "resourceN_resize"); + if (ret) + goto pm_put; + } + + pci_read_config_word(pdev, PCI_COMMAND, &cmd); + pci_write_config_word(pdev, PCI_COMMAND, + cmd & ~PCI_COMMAND_MEMORY); + + flags = pci_resource_flags(pdev, n); + + pci_remove_resource_files(pdev); + + for (i = 0; i < PCI_STD_NUM_BARS; i++) { + if (pci_resource_len(pdev, i) && + pci_resource_flags(pdev, i) == flags) + pci_release_resource(pdev, i); + } + + ret = pci_resize_resource(pdev, n, size); + + pci_assign_unassigned_bus_resources(pdev->bus); + + if (pci_create_resource_files(pdev)) + pci_warn(pdev, "Failed to recreate resource files after BAR resizing\n"); + + pci_write_config_word(pdev, PCI_COMMAND, cmd); +pm_put: + pci_config_pm_runtime_put(pdev); +unlock: + device_unlock(dev); + + return ret ? ret : count; +} + #define pci_dev_resource_resize_attr(n) \ static ssize_t resource##n##_resize_show(struct device *dev, \ struct device_attribute *attr, \ - char * buf) \ + char *buf) \ { \ - struct pci_dev *pdev = to_pci_dev(dev); \ - ssize_t ret; \ - \ - pci_config_pm_runtime_get(pdev); \ - \ - ret = sysfs_emit(buf, "%016llx\n", \ - (u64)pci_rebar_get_possible_sizes(pdev, n)); \ - \ - pci_config_pm_runtime_put(pdev); \ - \ - return ret; \ + return __resource_resize_show(dev, n, buf); \ } \ - \ static ssize_t resource##n##_resize_store(struct device *dev, \ struct device_attribute *attr,\ const char *buf, size_t count)\ { \ - struct pci_dev *pdev = to_pci_dev(dev); \ - unsigned long size, flags; \ - int ret, i; \ - u16 cmd; \ - \ - if (kstrtoul(buf, 0, &size) < 0) \ - return -EINVAL; \ - \ - device_lock(dev); \ - if (dev->driver) { \ - ret = -EBUSY; \ - goto unlock; \ - } \ - \ - pci_config_pm_runtime_get(pdev); \ - \ - if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) { \ - ret = aperture_remove_conflicting_pci_devices(pdev, \ - "resourceN_resize"); \ - if (ret) \ - goto pm_put; \ - } \ - \ - pci_read_config_word(pdev, PCI_COMMAND, &cmd); \ - pci_write_config_word(pdev, PCI_COMMAND, \ - cmd & ~PCI_COMMAND_MEMORY); \ - \ - flags = pci_resource_flags(pdev, n); \ - \ - pci_remove_resource_files(pdev); \ - \ - for (i = 0; i < PCI_STD_NUM_BARS; i++) { \ - if (pci_resource_len(pdev, i) && \ - pci_resource_flags(pdev, i) == flags) \ - pci_release_resource(pdev, i); \ - } \ - \ - ret = pci_resize_resource(pdev, n, size); \ - \ - pci_assign_unassigned_bus_resources(pdev->bus); \ - \ - if (pci_create_resource_files(pdev)) \ - pci_warn(pdev, "Failed to recreate resource files after BAR resizing\n");\ - \ - pci_write_config_word(pdev, PCI_COMMAND, cmd); \ -pm_put: \ - pci_config_pm_runtime_put(pdev); \ -unlock: \ - device_unlock(dev); \ - \ - return ret ? ret : count; \ + return __resource_resize_store(dev, n, buf, count); \ } \ static DEVICE_ATTR_RW(resource##n##_resize)