From nobody Mon Nov 25 16:32:49 2024 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 E80A120F3C9; Fri, 25 Oct 2024 21:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=192.198.163.9 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729893096; cv=fail; b=gcd14rnRRaL4v/EaELv9uWLLNJo1nAWwTzJ8VBsaB4zhCnSEPYv35DvssEh+u+6nHkXV9SvpeIFuBtMImOowsjmV0H1lwhlz4fh+VC3+0p3fIy7na79Ug+QpZXbTp41byMom47bCz1EmUWA2IS/X52u5mxQfudYsXSNSehxLpv8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729893096; c=relaxed/simple; bh=Cb21LiisF8elRGSHW71OF80D2cdzyNx82WHuMbx7zMQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=B54xzmNlwDo1MO+9ugJFjJbiS0U9ruQjifxN+oBJSw5mGfR0zn5zpWqqfiIABmk0JaLsaNyixDTIE1iySJK3HBSJO9ZmGDgf3i/cnwnB9L7sORUT+4b9sAmxEgO230XEcpvm3tKUj/VaLvMQB9MYBIObzPN5gELUMEaxSeljsUc= 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=VUb3kU7q; arc=fail smtp.client-ip=192.198.163.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="VUb3kU7q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729893094; x=1761429094; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Cb21LiisF8elRGSHW71OF80D2cdzyNx82WHuMbx7zMQ=; b=VUb3kU7qZT0EbvnBaveU33qrqrX3EBi2OxBvMPCcB35X7W7blLcXz+2/ aWK615vrHyLc93Hmhp9TS0FRR6ySt3JSJfZM6oh1sxB9qTLMS/OeJMxFK vGYVCRWq4f1ovwP5Egr33qP8UYxr0M4wKg6vlfzUYGWQ4j9juMt/Daahm QWkb18SYuZbgBZeDL27fKiX9AU4SMusONV/16HKcLcfogYPd85EFM7kSO xT6KwxCXZyP0grQ9ZMjgR5bLyL40ABTBxNtoPCGMteni0Q90IYkf52/T2 m3JZ6laihH6BQUURLLFdxlkfHoDjWtkv30yqx+kDeBJQ60R5Nl/WZIkhy g==; X-CSE-ConnectionGUID: IWSPc1P6RUeYBoalVuqPaA== X-CSE-MsgGUID: ut6SNaExS+aHyogLdXQ8mg== X-IronPort-AV: E=McAfee;i="6700,10204,11236"; a="40192810" X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="40192810" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2024 14:51:33 -0700 X-CSE-ConnectionGUID: 0tKz9vp2T/6CtIaXQkIZeQ== X-CSE-MsgGUID: SRzMFBBBT+OWfwNpzaBQKA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="104358193" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmviesa002.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 25 Oct 2024 14:51:33 -0700 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 25 Oct 2024 14:51:32 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Fri, 25 Oct 2024 14:51:32 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.170) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 25 Oct 2024 14:51:32 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Tysue0GKSs8qWZ2J2pWbeGohRU3gzhCmexqocbxjhj/osK6VdZh104lLBnLiny1ITmXry7e0ij1GOOC9m2asb5ZOx+VLN5PyGvNePHA2/E5Dot86OroRQSFwUwwR8yFuxKtVSbKMzAqbhApDh2Si9Bi6ktoXmA44gyqkF1f+EJdERmccFJ0rOxLg7r7blG82Z8cenbGWDl+lRYSozTC14LSw2uH+2YMeG+OvuR6I9VgOHSW2iqnN7QI1XIOUIsxp60IlODyAalxr/mcUmKr4nWVPSw3VyJxe/3pV1t4ftml6WD6f1HNGRojs/d1UMs9ecrV1LXNFZKHjLbeFBSDfhw== 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=prUTcacmshz3WO2AIjl4k3nUwsfAHpTcDq5xf2IXaoM=; b=oSoSEWKNhJU6L9JExtrcc3IWMYKw8x4w3JVdNAvxOU9t0BkDp9LYrxqfA9L4cnF/3nhnXZxJnOu95hSrrssrK4jePZHhdyKQdcXCdQrbf6gAFjmKsrfodHIZ5pKnuFNUBFZLyT2NCfRnN2Uj1V4hAhRljYUkQjEkL+oTcyVydEC8paaiDXZL9icWetl9NYBUIsqOfS1hus/p6a894IGCgGigGQspO5QIvQUJxtwraQLQof/OLz290EQReBCiPnWuQ367Z558wt9oIvjgK1LNtyLRthuGr10tGNoIDx+IIiJTEZDT1hLfraqU1auPb9fYk+/QGeyvoGSCBGPgiNrzSw== 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 CY8PR11MB7745.namprd11.prod.outlook.com (2603:10b6:930:90::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Fri, 25 Oct 2024 21:51:25 +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.8093.018; Fri, 25 Oct 2024 21:51:25 +0000 From: =?UTF-8?q?Micha=C5=82=20Winiarski?= To: , , , , "Bjorn Helgaas" , =?UTF-8?q?Christian=20K=C3=B6nig?= , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= CC: Rodrigo Vivi , Michal Wajdeczko , Lucas De Marchi , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Matt Roper , =?UTF-8?q?Micha=C5=82=20Winiarski?= Subject: [PATCH v4 6/7] PCI: Allow drivers to control VF BAR size Date: Fri, 25 Oct 2024 23:50:37 +0200 Message-ID: <20241025215038.3125626-7-michal.winiarski@intel.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241025215038.3125626-1-michal.winiarski@intel.com> References: <20241025215038.3125626-1-michal.winiarski@intel.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: WA1P291CA0007.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::11) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|CY8PR11MB7745:EE_ X-MS-Office365-Filtering-Correlation-Id: f46ff9bf-6247-4a52-050f-08dcf53f2c21 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?bHN2NzltMkRaM0I2OS9XbEpBdEdzZWllc1JPUXNNcWdpcW0xYW8yZFl4NWIw?= =?utf-8?B?amFXalEwYXhIVWJKMHNtWFMxYlJaUEcxQW80N01zQmdOdzQzcC9oMElkTkRV?= =?utf-8?B?RkJtd00zWU41aDJCeGpzRjZuZWUvSWpkcGFyb09NUE9DSndkUTRkTFFqYSs2?= =?utf-8?B?aGlKR251VXN0RXovYW95a2RMcTV2ckc2YjNLNUZ6bzlMSzViL3JyR1FJWU9S?= =?utf-8?B?S3VVSTdoN1ZodVFvTnp6Rmp6NVNmRWczcEZ0TlpXVGFpZFZVaTRMTVRLVkVK?= =?utf-8?B?YVlJa3Y4Z1QxNGgxTUUwckYyWGFyQVlaM2w4UkRjaEVDRVNKazFjRmZqT2xF?= =?utf-8?B?a05venphRFBJc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m?= =?utf-8?B?VFliZ3JDMTBadCtqdjcraFZ4ZlFuQjVMdWUrMFIrUjRtRXdpemh3cjZiOHhT?= =?utf-8?B?RUNKZEM2eGlYV0hMT2RRdHB3OHhDWjJLYzJtS0tIeW5EaHdyMlJKeU9PM3Bx?= =?utf-8?B?Y2JuNkx4ZnYxNHhQRy8rOUIvODM0eEM5R2VJMlZmdmVjaGdnc3FGc3lqTTZL?= =?utf-8?B?Sno0VXlmYThuUnlQbW5RT2NMOTcyL01tRmR6WGlKTlhJSjIzU2tjT25DSzRU?= =?utf-8?B?YXVEZEJVMCtXVFhpWVRnaC9mQlE4ZmpwM25Sbm10Y0pHTXdTWmc3OGNsRUVE?= =?utf-8?B?V3laK0RLeWVjYjZmTVJjTW1ZaThmVFlaQTlSUy8wS2ZHUjZQRmg3TjQ0SC9W?= =?utf-8?B?dGdad3JJQzV2WHE5bFo4bVB1cC9UN216NWZQQXpLVno3VVZSQllBYUdOWjVh?= =?utf-8?B?SkZKYVFISDFRNHBZc29KKzhJVWxvZThiWkVtS2JHRVQ4OWdpVzFHdVRsTUpO?= =?utf-8?Q?kmWdH0dGYMvg2hMAEHPXDPx9U+fX9xHtmyZ7lr3?= 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)(7416014)(366016)(1800799024)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?K1V2THJ3S1VzUStsdEJMS2VmSlpyR21uZDdwcXMrdXI0M2t2TTlucG10T0VZ?= =?utf-8?B?ZEpIeFBoekVZU2lRUzRFbXNxN083RElOT21HS1R0QlR4TnZYR1lRSnRxVDhQ?= =?utf-8?B?TWxleHRuTmJkY09Nd1U1bTRnaGVPK3pLMW52WGFNbWJGOC9pK0lQeEJnL2d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sVkY0SnFFQTV6RFNCM3ZTNk13?= =?utf-8?B?SUdra3RzRjd3K0RscnBUYzVFckFJTmhZU0xQMTArcWd6cnk3aFJIQSs2aU55?= =?utf-8?B?SDY2c0lwTkRiMTFwYXpobWxvQjRpb1dsYlZxWGlyYkpuV3lzelVxdnBNMG8w?= =?utf-8?B?UllsRU9JcmpUTkt5TVdpM2hWQ2EyUTNlemFoNE1SQk1JeG5YUkZzTXlnbnpm?= =?utf-8?B?WUE9PQ==?= X-MS-Exchange-CrossTenant-Network-Message-Id: f46ff9bf-6247-4a52-050f-08dcf53f2c21 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 21:51:25.4462 (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: 4lpjpm+PrdnrSLgXcW4jGDb0w+DsQi3EgAsRb5u1vRJuEndwQGxDvdcDYaVjWSkRjNvPcctCIxHPjzPBcklHxE8iTTcqRY2+O9FG4uubvCg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR11MB7745 X-OriginatorOrg: intel.com Drivers could leverage the fact that the VF BAR MMIO reservation is created for total number of VFs supported by the device by resizing the BAR to larger size when smaller number of VFs is enabled. Add a pci_iov_vf_bar_set_size() function to control the size and a pci_iov_vf_bar_get_sizes() helper to get the VF BAR sizes that will allow up to num_vfs to be successfully enabled with the current underlying reservation size. Signed-off-by: Micha=C5=82 Winiarski --- drivers/pci/iov.c | 80 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 6 ++++ 2 files changed, 86 insertions(+) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 5de828e5a26ea..de8d473459440 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -1281,3 +1281,83 @@ int pci_sriov_configure_simple(struct pci_dev *dev, = int nr_virtfn) return nr_virtfn; } EXPORT_SYMBOL_GPL(pci_sriov_configure_simple); + +/** + * pci_iov_vf_bar_set_size - set a new size for a VF BAR + * @dev: the PCI device + * @resno: the resource number + * @size: new size as defined in the spec (0=3D1MB, 19=3D512GB) + * + * Set the new size of a VF BAR that supports VF resizable BAR capability. + * Unlike pci_resize_resource(), this does not cause the resource that + * reserves the MMIO space (originally up to total_VFs) to be resized, whi= ch + * means that following calls to pci_enable_sriov() can fail if the resour= ces + * no longer fit. + * + * Returns 0 on success, or negative on failure. + * + */ +int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size) +{ + int ret; + u32 sizes; + + if (!pci_resource_is_iov(resno)) + return -EINVAL; + + if (pci_iov_is_memory_decoding_enabled(dev)) + return -EBUSY; + + sizes =3D pci_rebar_get_possible_sizes(dev, resno); + if (!sizes) + return -ENOTSUPP; + + if (!(sizes & BIT(size))) + return -EINVAL; + + ret =3D pci_rebar_set_size(dev, resno, size); + if (ret) + return ret; + + pci_iov_resource_set_size(dev, resno, pci_rebar_size_to_bytes(size)); + + return 0; +} +EXPORT_SYMBOL_GPL(pci_iov_vf_bar_set_size); + +/** + * pci_iov_vf_bar_get_sizes - get VF BAR sizes that allow to create up to = num_vfs + * @dev: the PCI device + * @resno: the resource number + * @num_vfs: number of VFs + * + * Get the sizes of a VF resizable BAR that can fit up to num_vfs within t= he + * resource that reserves the MMIO space (originally up to total_VFs) the = as + * bitmask defined in the spec (bit 0=3D1MB, bit 19=3D512GB). + * + * Returns 0 if BAR isn't resizable. + * + */ +u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs) +{ + resource_size_t size; + u32 sizes; + int i; + + sizes =3D pci_rebar_get_possible_sizes(dev, resno); + if (!sizes) + return 0; + + while (sizes > 0) { + i =3D __fls(sizes); + size =3D pci_rebar_size_to_bytes(i); + + if (size * num_vfs <=3D pci_resource_len(dev, resno)) + break; + + sizes &=3D ~BIT(i); + } + + return sizes; +} +EXPORT_SYMBOL_GPL(pci_iov_vf_bar_get_sizes); diff --git a/include/linux/pci.h b/include/linux/pci.h index 573b4c4c2be61..1b9e7e3cab0ce 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2371,6 +2371,8 @@ int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 n= umvfs); 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_vf_bar_set_size(struct pci_dev *dev, int resno, int size); +u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs); void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe); =20 /* Arch may override these (weak) */ @@ -2423,6 +2425,10 @@ 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, i= nt resno) { return 0; } +static inline int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, = int size) +{ return -ENODEV; } +static inline u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno,= int num_vfs) +{ return 0; } static inline void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool prob= e) { } #endif =20 --=20 2.47.0