From patchwork Thu Sep 19 22:35:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 13808028 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 4768C1B2EFD; Thu, 19 Sep 2024 22:38:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=198.175.65.9 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726785517; cv=fail; b=MkAC3Nfzc4oE97qdL1BbBBdXK4rMRMo8ahiYHmoW/0AzYlpfAFww8zMSgLyBXHlGakN6W1VZJkl+Avp41rsSmHKK/A3y1IjnOT/EGcihdSoPznqyqhk4rNQ+AVbgSt8BQ55SUvQz48onG68+Ivb+sQ+BEGFyMtNyDJN0jixByHI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726785517; c=relaxed/simple; bh=eS0E31whnXBKSFMFJ0GVHUtUktaU8XpFULlAzs0+1qs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Fc3ctcuBYSMYK2FKvVzEyLG+aIEarrfo4Znd+IcZRSb0os3Y38M+yaETwcj6RtLfqyD5asvzx8nAi54oWJn7+AKcWrvuluTlqPerA4arObHS3Sz3olj07APhiu47B0JYSxmm0t7fsyHaWtytPFWh0h4DfuBEGZYpe1TxSBcszps= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=TS/bhKeo; arc=fail smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TS/bhKeo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726785515; x=1758321515; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=eS0E31whnXBKSFMFJ0GVHUtUktaU8XpFULlAzs0+1qs=; b=TS/bhKeoeUVNxukKbIk5xM0qEOrUS7qgOruiovNQXKo37zdRzypdNt1f 3KmwVvZmTW3mhTiSY56rjVsyD74yAJRcSPQfFHixhPxQblpmBvlkg+mwH 9tJQf3FI4kU8cVhtkOvTbYiHFb82PGyFPjOwuHWZGJCQkEAYG9RfqXnbU 4Tui6h3oCnz0FofTk9xuE0T9680crVy58BpG6mIe4B6wxMNucu/DiHWDf FF8J1avV//kQ6BStPpyHmGClKHUQxid3h0OYxK63GsBu/0qAkpBxDu82X WY2Akef6hHers+iNovgchEURVtYabqcydyE/5xbajARysZmAivd5guz2u w==; X-CSE-ConnectionGUID: EKWn2BubRGyhlPqbkLqxFw== X-CSE-MsgGUID: rMi/076mR0qHAkTQ/YUYyw== X-IronPort-AV: E=McAfee;i="6700,10204,11200"; a="48309527" X-IronPort-AV: E=Sophos;i="6.10,243,1719903600"; d="scan'208";a="48309527" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2024 15:38:34 -0700 X-CSE-ConnectionGUID: qcem5oLwTEmbzkSEh7/y0Q== X-CSE-MsgGUID: stq0zOzkRlmHJO3pxXanxQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,243,1719903600"; d="scan'208";a="70334048" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmviesa010.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 19 Sep 2024 15:38:35 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 19 Sep 2024 15:38:34 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Thu, 19 Sep 2024 15:38:34 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.48) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 19 Sep 2024 15:38:34 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xJ5Olot3dg8zmkzdnhJkMwWCwnqGvnmPKgbc8uy12jnqtarRUQVyMDawVxLo3D9zMiV5SWeZI9w+xoubLCKCcPVjZVEZTpyJwhW2ALDM0bhH8m5QVoBKo+4RAJaI5wqWuToWq4CH1OibwiMBuyEM2qKWgPpId5na3wmF+zeuasN8nqPG+sGmYg/uqf/XlddsdrgaarL+cRs+BqU0pm4ITa0yc9si2Nw2ohh4iAb+a2H53TxM0tImaDdkbydGjOYvjc47ykf2gxtqJyJDO43oAQ2u2/eSeVN57V5P8eMuIeuNy3rNqWNGFLv1vv8Ww7SkNH0K/qGzFGVuojy1sNNp0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TJfy8lBMZwBLNA92nEEFy/avPdhG6w929Ib94qVf9QE=; b=I546VOKCIAyv50qQv6i4zik8cJqz70wxaAFA2iHa6U2W9UUCKMTPvL6sSDXHz+uLyMBjVgQNe+EVrHMhg4ru1YcwP7Bcqxm0frNQ5wNLWvzGy6kabAvIjFNrd1wT+TCF+XuJkaK2vdSsSDdzqFA/OGxV9/A/JpNUnDZEE1UVyQGMH4u9kDBZIlAdC0p0eWlcN6KDC0NYrcwVxc3tyQp2iuDHUGVTcuOHEOgvlpECyWDY3ymG3ziYBROouuDU76lmIaNI/pmpYTiEXQzaciuFJngOdNlmLQorRqfVKh8Pi8SuB4gfuB70j5jnOuappp+E2DFHRceVAr7/AUp+EX9S5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by MW4PR11MB5824.namprd11.prod.outlook.com (2603:10b6:303:187::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.26; Thu, 19 Sep 2024 22:38:31 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39%5]) with mapi id 15.20.7982.018; Thu, 19 Sep 2024 22:38:31 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , , , , "Bjorn Helgaas" , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= CC: Rodrigo Vivi , Michal Wajdeczko , Lucas De Marchi , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Matt Roper , =?utf-8?q?Micha=C5=82_Winiarski?= Subject: [PATCH v2 2/3] PCI: Allow extending VF BAR within original resource boundary Date: Fri, 20 Sep 2024 00:35:56 +0200 Message-ID: <20240919223557.1897608-3-michal.winiarski@intel.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240919223557.1897608-1-michal.winiarski@intel.com> References: <20240919223557.1897608-1-michal.winiarski@intel.com> X-ClientProxiedBy: WA1P291CA0003.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::6) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|MW4PR11MB5824:EE_ X-MS-Office365-Filtering-Correlation-Id: 86993122-d4e1-46ea-e425-08dcd8fbc9dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?q1LOytLE0CiXcuRs+LdpY24Y/sxfMv1?= =?utf-8?q?9/r5XYNblpUgbUq5KOFjK79Nx1z9ayGgiiQL2lfrybmHAROLzHdB5T6Jnb067emxJ?= =?utf-8?q?jpmJ4MFVavZ6G/+EuXiBBo3okHdcbFvqbLT3kxguQXe7X1fI711/wEZVqLB+Qnj7t?= =?utf-8?q?ipSLLq3Mjz72qoXaApbowmrx//f7kowyoxEexIno83loUm4oWmAAThi3bjnjW1V+8?= =?utf-8?q?pZJTJYjoJ0IDZY2fY14r+ArwEhUDbpK5+fe7owdHjTYBKwBjoAuyLQ3sWE3D8co4c?= =?utf-8?q?cMk8uAQxQwoI6fUUxzyzWeGNtoBkTkd29WvKvb238Z0DE9bkU5xh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uq?= =?utf-8?q?0VEQK6uD8VJ2CEksuBFwkYUOoAVFnxZlzhBj4ZqR//MDSxtqMZwxIb6mIAtyYvNox?= =?utf-8?q?PZH0Dijds+H4avnNn/GjVdsdBZUMgr3FvXg=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR11MB5373.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(7416014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?hp0/NeXEl4pRAgZj+IwaxD85fpsn?= =?utf-8?q?Md1VBLQrs7Xfc2wXi/jM4VJ1me5u9yGPjG2xf6TQzkiYrH4uQWOce68CyWhtUCMuT?= =?utf-8?q?jCD9UpVgQP4shSCnMX+WSlY5K3jiyF0NZl5XkpcmPWtY4iKf1/Olx5zCvODkJEiB8?= =?utf-8?q?ELQGg+YT1Xmt9vOhIibylyYHPyI9g36I062jSmIruSAVzZNyw3g4qYqYqXIIovIj7?= =?utf-8?q?vBAwDAIiDwuK+P3j9UbusHvhAfT838LXi/T3Y91JCqUHCYam2Y8B14gnQEQ2R511H?= =?utf-8?q?2v6bS2KrCFzjKiHC9FAbNhzWZtNI7lDV1lXFoxwsS0EOktgiiRf5cK29x9mBK3sEs?= =?utf-8?q?aMv3eHGU7Qm58hCZtAzXdBG2AU4dIQnQWhCmx8hkKh950f8eQekz8/xV0nTkQxWI7?= =?utf-8?q?hFggLJDHEjJiWc3dADVvBze00UREL5YJieVRjwvS0JI4UR3els3fGCKxwDpAWsmJz?= =?utf-8?q?gclqvZ8K91B738F/2YTAzj9Le65WYeGPgOC5CNU7JquUyBxfciVPx6IiN4/TkqY7L?= =?utf-8?q?36cuGp1FI/gkUAgW3MyVud7NIz/ipTV7E2pTEEgV2nqKRzgTbvVN2jn0hVqW6rH4B?= =?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Z3WfnfL2?= =?utf-8?q?HQoznfJlwDZOApM6bz+x3Ip4xNbaHky9hMxQoWWj/+DAkYBXNJ2noVfva7ErScIWt?= =?utf-8?q?xDRfphUx9ArCfljNYCFtxb1OL9XbsSYXpQ=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 86993122-d4e1-46ea-e425-08dcd8fbc9dc X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2024 22:38:31.5983 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: n3Wp5liD2i8R32ApDb99e3sRLSB6qxSrZc2OQYwamFNNwsiY93RONpHg7OGp5MB62Pye+Q52bB+LngG8FNAa8xIVi8cNLcSledAn0lQi1RY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR11MB5824 X-OriginatorOrg: intel.com VF MMIO resource reservation, either created by system firmware and inherited by Linux PCI subsystem or created by the subsystem itself, contains enough space to fit the BAR of all SR-IOV Virtual Functions that can potentially be created (total VFs supported by the device). This can be leveraged when the device is exposing lower than optimal BAR size as a default, allowing access to the entire resource when lower number of VFs are created. It is achieved by dynamically resizing the BAR to largest possible value that allows to fit all newly created VFs within the original resource boundary. Signed-off-by: MichaƂ Winiarski --- drivers/pci/iov.c | 92 ++++++++++++++++++++++++++++++++++++++++++++- drivers/pci/pci.h | 1 + include/linux/pci.h | 3 ++ 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index e8ccd2ae0f024..d88efbfa70e42 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -181,6 +181,86 @@ bool pci_iov_memory_decoding_enabled(struct pci_dev *dev) return cmd & PCI_SRIOV_CTRL_MSE; } +static void pci_iov_resource_do_extend(struct pci_dev *dev, int resno, u16 num_vfs) +{ + resource_size_t size; + int ret, old, i; + u32 sizes; + + pci_config_pm_runtime_get(dev); + + if (pci_iov_memory_decoding_enabled(dev)) { + ret = -EBUSY; + goto err; + } + + sizes = pci_rebar_get_possible_sizes(dev, resno); + if (!sizes) { + ret = -ENOTSUPP; + goto err; + } + + old = pci_rebar_get_current_size(dev, resno); + if (old < 0) { + ret = old; + goto err; + } + + while (sizes > 0) { + i = __fls(sizes); + size = pci_rebar_size_to_bytes(i); + if (size * num_vfs <= pci_resource_len(dev, resno)) { + if (i != old) { + ret = pci_rebar_set_size(dev, resno, size); + if (ret) + goto err; + + pci_iov_resource_set_size(dev, resno, size); + pci_iov_update_resource(dev, resno); + } + break; + } + sizes &= ~BIT(i); + } + + pci_config_pm_runtime_put(dev); + + return; + +err: + dev_WARN(&dev->dev, "Failed to extend %s: %d\n", + pci_resource_name(dev, resno), ret); + + pci_config_pm_runtime_put(dev); +} + +static void pci_iov_resource_do_restore(struct pci_dev *dev, int resno) +{ + if (dev->sriov->rebar_extend[resno - PCI_IOV_RESOURCES]) + pci_iov_resource_do_extend(dev, resno, dev->sriov->total_VFs); +} + +int pci_iov_resource_extend(struct pci_dev *dev, int resno, bool enable) +{ + if (!pci_resource_is_iov(dev, resno)) { + dev_WARN(&dev->dev, "%s is not an IOV resource\n", + pci_resource_name(dev, resno)); + + return -ENODEV; + } + + if (!pci_rebar_get_possible_sizes(dev, resno)) + return -ENOTSUPP; + + if (!enable) + pci_iov_resource_do_restore(dev, resno); + + dev->sriov->rebar_extend[resno - PCI_IOV_RESOURCES] = enable; + + return 0; +} +EXPORT_SYMBOL_GPL(pci_iov_resource_extend); + static void pci_read_vf_config_common(struct pci_dev *virtfn) { struct pci_dev *physfn = virtfn->physfn; @@ -445,7 +525,7 @@ static ssize_t sriov_numvfs_store(struct device *dev, const char *buf, size_t count) { struct pci_dev *pdev = to_pci_dev(dev); - int ret = 0; + int i, ret = 0; u16 num_vfs; if (kstrtou16(buf, 0, &num_vfs) < 0) @@ -487,6 +567,11 @@ static ssize_t sriov_numvfs_store(struct device *dev, goto exit; } + for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { + if (pdev->sriov->rebar_extend[i]) + pci_iov_resource_do_extend(pdev, i + PCI_IOV_RESOURCES, num_vfs); + } + ret = pdev->driver->sriov_configure(pdev, num_vfs); if (ret < 0) goto exit; @@ -881,8 +966,13 @@ static int sriov_init(struct pci_dev *dev, int pos) static void sriov_release(struct pci_dev *dev) { + int i; + BUG_ON(dev->sriov->num_VFs); + for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) + pci_iov_resource_do_restore(dev, i + PCI_IOV_RESOURCES); + if (dev != dev->sriov->dev) pci_dev_put(dev->sriov->dev); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index e763b3fd4c7a2..47ed2633232aa 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -385,6 +385,7 @@ struct pci_sriov { u16 subsystem_vendor; /* VF subsystem vendor */ u16 subsystem_device; /* VF subsystem device */ resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */ + bool rebar_extend[PCI_SRIOV_NUM_BARS]; /* Resize VF BAR */ bool drivers_autoprobe; /* Auto probing of VFs by driver */ }; diff --git a/include/linux/pci.h b/include/linux/pci.h index 4cf89a4b4cbcf..c007119da7b3d 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2364,6 +2364,7 @@ int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs); int pci_sriov_get_totalvfs(struct pci_dev *dev); int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn); resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno); +int pci_iov_resource_extend(struct pci_dev *dev, int resno, bool enable); void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe); /* Arch may override these (weak) */ @@ -2416,6 +2417,8 @@ static inline int pci_sriov_get_totalvfs(struct pci_dev *dev) #define pci_sriov_configure_simple NULL static inline resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno) { return 0; } +static inline void pci_iov_resource_extend(struct pci_dev *dev, int resno, bool enable) +{ return -ENODEV; } static inline void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe) { } #endif