From patchwork Thu Mar 20 11:08:52 2025 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: 14023709 X-Patchwork-Delegate: bhelgaas@google.com Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 432AE221556; Thu, 20 Mar 2025 11:09:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=192.198.163.10 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742468997; cv=fail; b=h2W38sUb1R8qieh+F0DaT/EzXwY1g0zkv5IGVt7E4DPsteEB0vvHhPfePLOENmdka1a0vNsFFpp1XUZPfwraJpwlgshhj806iu+9NxipdE/QwjUWjIhqp8FJqrIN33scx7E5YOnG2otVG2awXVmtLwFIi7NcrTKCsobrnHDYqTA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742468997; c=relaxed/simple; bh=L0gnhAy12+pBA8N7aVrR1ppPMpMddCZ1SRv+i8EY6PE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=onc9FguFI5hTeiJjSH1e5l5k+CIMNvDnWfPabc8aqAwHv8T3ikzD54MEYQUlE9nyd70jfyeK/AFycPz9jt8hWnr0ep+K0ieTLI7333+BHyVa1E5hgnuhhiwsTOLQJO+FSuEdo79B7+ZdYdkilFCs4DC4Et11+0y87wfmYi0CsR4= 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=be00nlNl; arc=fail smtp.client-ip=192.198.163.10 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="be00nlNl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742468996; x=1774004996; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=L0gnhAy12+pBA8N7aVrR1ppPMpMddCZ1SRv+i8EY6PE=; b=be00nlNlpCasOl4ujq21+XDtIUzITljfMRQDiBcnuo4fM/GJZaryDggy RaH072z8byVPkAqkOmg2oigghNlH2vlzx6NbIMuPs5evcT19M/IDnJBCC J4/aohRFdfbrcROLRfz8U40oU8QSQUE0Q8vouxEze1iWw8lQ8sfe11Yki p3W4iazxef+WLEn4DxJeBkzESHSeNeboazUnTrlGx/WKZPNS+YjRDyfxn hHODY/J68QP02cJhgUvJ6iE35ffI7ISJFbw5M6YDq+Kk0on17q65pDlM/ nn5pJBb8WtEdYOXxnAdgUA4JNmKNxNKUgxVpKU106muV4jRruHeAdLcYp w==; X-CSE-ConnectionGUID: EcT/LtrDQNmR796FVsKrWg== X-CSE-MsgGUID: AJ2biF7ETsugprFccR3j6Q== X-IronPort-AV: E=McAfee;i="6700,10204,11378"; a="55070861" X-IronPort-AV: E=Sophos;i="6.14,261,1736841600"; d="scan'208";a="55070861" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Mar 2025 04:09:56 -0700 X-CSE-ConnectionGUID: VGLe8Q3NTYuf6JlmfIiCLA== X-CSE-MsgGUID: kwZv40D5RVOWPAgtjfBM2A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,261,1736841600"; d="scan'208";a="146265569" Received: from orsmsx901.amr.corp.intel.com ([10.22.229.23]) by fmviesa002.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Mar 2025 04:09:55 -0700 Received: from ORSMSX901.amr.corp.intel.com (10.22.229.23) by ORSMSX901.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Thu, 20 Mar 2025 04:09:55 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by ORSMSX901.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14 via Frontend Transport; Thu, 20 Mar 2025 04:09:55 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.49) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.44; Thu, 20 Mar 2025 04:09:54 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=d5M5o3qP/1eJsiM54j8efN2kLOncb1WQMJD/7Pdo+kouEHPDvL3yT2RNdpMsuRLQO9vjqf0YyWV56mWYpa7d7s67OQNoDy+GXBnXedG+5XttkHxnkyajTNQWC/Ho9ENpfZb7F+HL9dM7rl//ySIQxYB7R1KZ8vAsbLaTmnrShsg0OF4aojRLs8O0h3LGiAUzAR/m3QmgHgbRuhL/yHp4boNYNftLJFjlMHMEBI0E0yY3uKU8R9WhC5mPunV0uU0AEdbfLCzWgjdktMuDbJ02HN3yWIW/PEUdyLjsQnxxubYSybkZ9ZW1nZL0jC8YHTYE40nw3/PzNGVFlIKgmVfF8g== 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=fkh+RjKXYZuPmliaIxzvKlbcAJ3OTsmXJEDPgMuDqNI=; b=iwclHgYoXSPXjgTr6WzQFKewMhFelKJtyyU9i2/gqyACCkeMK+5BkTQm/fQfKbfCQ2aCuzf1N67ZmVBIxIkmAIrTvUta9E8UZhpHai7Bb5aSQiEPDQ/WEYJWKp1w+qqcqCRmiEgHp0kXRjTt9+wxVTa+LiBCNp51tEkTptVaKBbxxEj/3uWfBTqh9ZnI/sbMfrAaDfI8H4rDMMkwmReQvIUUzAGN4toSaF0s6buRsXprxHB4sWLuiKpF1hz+QLlaE0kaYpVRHFdVwjfztH/b2hXZ4sZdtS03ps/Vo3DH4tN4ykjAgfdzdHnA+X3uPEPltBqa8Rr/YEAgCz5sE9uVcg== 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 SN7PR11MB6875.namprd11.prod.outlook.com (2603:10b6:806:2a6::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.34; Thu, 20 Mar 2025 11:09:53 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39%7]) with mapi id 15.20.8534.036; Thu, 20 Mar 2025 11:09:53 +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?= , =?utf-8?q?Ilpo_J=C3=A4rvi?= =?utf-8?q?nen?= 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 v6 4/6] PCI/IOV: Check that VF BAR fits within the reservation Date: Thu, 20 Mar 2025 12:08:52 +0100 Message-ID: <20250320110854.3866284-5-michal.winiarski@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250320110854.3866284-1-michal.winiarski@intel.com> References: <20250320110854.3866284-1-michal.winiarski@intel.com> X-ClientProxiedBy: VI1PR06CA0178.eurprd06.prod.outlook.com (2603:10a6:803:c8::35) 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_|SN7PR11MB6875:EE_ X-MS-Office365-Filtering-Correlation-Id: 00f7e26c-30fb-4e4f-23b9-08dd679fbd3d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?utf-8?q?hymEBP/qR/zH4iCA3AcYZVyc/hGFkvu?= =?utf-8?q?KodE2fYTBMIyeJRuq8nW+QhiSSwdFI3hLveIvaoLlLDU2oTbQLtWTYyf+i8K8Nv28?= =?utf-8?q?6P2ruI/s/tu1Vd71VlJtb//Zu0pMOaCIlViktoUcQUw7uLdykJ5kUN6cbx1w6pwNm?= =?utf-8?q?NKDyWC87LrJDFBMyqxOBKARxmU97FJjia3OaTcgr8Q5fYXOquB+RVWzXKSkgXpF7x?= =?utf-8?q?ejy70VP/Zsk+q+nxo2TTX05lpmrUDarSTGC46w6qWAEtfybW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EUHEzgIWAIC5/I588vU2T?= =?utf-8?q?AraBMixofjkl9r0h+huWLGea0s5NFIk2lIOxmry9suaqMkRQFuGME6b/T/LBQh7ij?= =?utf-8?q?+clgBGVrBJv+zgaqlS99QgP9jO9N+e4W1QRfWhiR1no8syOU/wr2j+ZnC5Of4Vend?= =?utf-8?q?NV7CtDSVcDaiPIzN9iaqq0DfrKP+bChR9P1dC6nQYDb7JHPaxIyW4GUl99PiAIjz8?= =?utf-8?q?h89TmnRzXMN2?= 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)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?zQ/2cRiWx/g7f3owia6ovvMxqIJp?= =?utf-8?q?UL4A5ilTRpFLNFT+BXZh1Bqt4MDpld+nf5yxujYR80gArtekpLg1nHrNv6tTjFx3f?= =?utf-8?q?EcdcP1UCv/5Le203hogdaDi2eEafy7uhx+D0Qz4s7/wEkNWqQziBMZVMoCV/xVCaa?= =?utf-8?q?ruLj3z+56ZSsr5VKVXqSjZHwwvBe5a84U6RgqDrhFBcGbG+lv02PJDB9lxrtlTmk+?= =?utf-8?q?Ta3/cJ1mxdgF0zI6JgrQv7b22TlnVuxSBErXod7DYrNcSWdFAI8fAGUy0GfANcV3q?= =?utf-8?q?rgwao/ROxLdVTJjxqDgEEm16swzEHLOCR9Q3kSjXS+UDQIGPdDfZTyzgOD+SH/msn?= =?utf-8?q?fq2hzm1yE1Z+4KDb/+DCerhHgMw5cuAPSpSweoFX111Huiahj/RsMJ7LTd6i2LGha?= =?utf-8?q?whGsOdrqaioVSXW8nqERC7PvMVGrcJHSE6X1q3pZTu/jiQdtAyPNDmExo1yKURd6I?= =?utf-8?q?PnBfiE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XV/+lnar1+/zKPTPKz8DfiS1c/1mDQd8?= =?utf-8?q?LOyMmgLIzzWeMD7LR0wHph0y+xsdb3N4GRfa/JJjKtgAwbetLBwut4ogw+3ClLHo5?= =?utf-8?q?oPh9qDNHiP+huWmrRQ0rHgQcnOjUp5rDiqG8+5FEF2Utn9DDLUh1irDMYmtWxZRAi?= =?utf-8?q?iaediNyKzyvWQS+72fTMbARWe5fswD2YNQ=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 00f7e26c-30fb-4e4f-23b9-08dd679fbd3d X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Mar 2025 11:09:52.9937 (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: OXiyvWT3hufNEGwzikadGM+8V2nDqa6pf3AbN1ef7fouTkKDyeO4I3RTpjNqniGsIkE2uTj8RjiGuaNu4d4gAGEYfo4kBXMUvGunt0UVJIQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR11MB6875 X-OriginatorOrg: intel.com When the resource representing VF MMIO BAR reservation is created, its size is always large enough to accommodate the BAR of all SR-IOV Virtual Functions that can potentially be created (total VFs). If for whatever reason it's not possible to accommodate all VFs - the resource is not assigned and no VFs can be created. The following patch will allow VF BAR size to be modified by drivers at a later point in time, which means that the check for resource assignment is no longer sufficient. Add an additional check that verifies that VF BAR for all enabled VFs fits within the underlying reservation resource. Signed-off-by: MichaƂ Winiarski --- drivers/pci/iov.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index cbf335725d4fb..861273ad9a580 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -646,8 +646,13 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) nres = 0; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { + resource_size_t vf_bar_sz = + pci_iov_resource_size(dev, + pci_resource_num_from_vf_bar(i)); bars |= (1 << pci_resource_num_from_vf_bar(i)); res = &dev->resource[pci_resource_num_from_vf_bar(i)]; + if (vf_bar_sz * nr_virtfn > resource_size(res)) + continue; if (res->parent) nres++; }