From patchwork Fri Oct 25 21:50:36 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: 13851877 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1AB47D149F3 for ; Fri, 25 Oct 2024 21:51:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8859E10EB93; Fri, 25 Oct 2024 21:51:28 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Kh7GiJBt"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8044110EB94; Fri, 25 Oct 2024 21:51:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729893085; x=1761429085; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=+6kX+PN8G7ONn69IurZXEHL7OKrxjzVRleyDPT0EP3I=; b=Kh7GiJBtgsuD9yFaaWJDUF67Wfw5pLut5WyAYuUl6hse8OP7hh15J98i xF336LPCLv3jxK8oaPtqbzQQmvE29Ic5LBNOk4538atBLEgNVydHjIXG+ Omxiz+QarHeocDdYWmh10BhVr8gpTcBllNWo6BbFe6bNXyMyDutAS5ELI MXyZipkKJmr8iiNdOir/m8oAzR2x3hpkv4D27Ci/IFgdPKWIoAWFPEb2m 4TW1bcuaoq6Tbe82YYti3Jq3rgyMhzjE2suL1bK07oiY2XWBzcsqEgHuS 8Tfb8OGFTKv9V7e/mTfn0syTp04thsCUTnRawmAlg7PjdHgrEMonmePJg Q==; X-CSE-ConnectionGUID: yS/M8t+ZTyu3ploeeH8I9g== X-CSE-MsgGUID: fOW8yV4/SD+SHIOBvtgsHw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="29704511" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="29704511" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2024 14:51:24 -0700 X-CSE-ConnectionGUID: fVOU1lOORGShgQld12K5tw== X-CSE-MsgGUID: KjNzKySLTx+EEDqUT3X9cg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="111854145" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmviesa001.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 25 Oct 2024 14:51:23 -0700 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX602.amr.corp.intel.com (10.22.229.15) 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:23 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx603.amr.corp.intel.com (10.22.229.16) 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:23 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.177) by edgegateway.intel.com (134.134.137.103) 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:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=t61H16/QvbYc7XiVxmQ2qeypXB3lixCgRenTVrw5kMtrQNfIhfVToy7lY+e8oT4QsUskzTRWPUeZBhqPCUuS1frnTBez33SXPWC2sRABs3/8z0HAB4VlQ4U2hl0Ys+mcjvDR6LlpOICtNx4D4KLroeyhT3tKoMRCE+3NcEnWMykgBCQ3YSR26EviT8gQi0zxHJWUArKdNZKFU4KMkKTmMEK6GZbKMSFr9Y7cFdWFiD2JXsPcb+GsUWuHRK8i1iKjhfej7XIJE9y8nsCTN1/PKfV3TQz9kuptYvz9BVIzYlX/EgCUnrD8cVAo8CQ+4Qtfqvd91XR/gxdFkbv3rGcg3g== 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=+QmHvi2kGNZ/R3MXys/d+yl7CPR0MJOK4uWFtGOMqxM=; b=c9D9WMMnAdSSbZivka/R6iIInAF2+Xlujo9d9xolefwgiCTjM5nfIushDoInXn+oNUIF3qgiplIWWlh9IwJqnOVCwGrJNmxJ66DHdgwhqVPm7QFTCM6EDoCIDho/DScN4sgrCOoodu0soDq1E7UmJlw9k375jd5uSsVTn2/Bkpvv1kGhQI4RF8aOQQVGZT764q4K7rtTQx28cAAZsu/lAetexg4fUDl6amNrUA8YzEAiG4Aa5tYysDFPPenmTuHDCMVY8lZFYEAxVsKAstLeSDuC4IDH3+7WKoxJ/jS+W+UJcm+FuJeif6GGTch2LX5+C7uhJ76H4Zqy3lGNF8kVVw== 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:21 +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:21 +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 v4 5/7] PCI/IOV: Check that VF BAR fits within the reservation Date: Fri, 25 Oct 2024 23:50:36 +0200 Message-ID: <20241025215038.3125626-6-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> X-ClientProxiedBy: WA2P291CA0018.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:1e::13) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|CY8PR11MB7745:EE_ X-MS-Office365-Filtering-Correlation-Id: ca155235-7f3f-41fa-1ddb-08dcf53f29c4 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?q?WFD5tRRa95ebfw9CzLQ4ZdCWsvITKan?= =?utf-8?q?Gpf39+MCJXz7DX79u8fhY1UMHcXb/5wjBXHbtx10reLc5BlHF7H7mcyX4IRuRa+1i?= =?utf-8?q?/kezRVhhi1gqhwbOy+zEfj7Bjuz3Cl2+Ti/qI5gnaEMPbp/uPYPnV9AOkTnIOhQ2q?= =?utf-8?q?9bAK8MPZCA/VmU+Vr6NsZ0ZauEeRU6yPMdR/fOX+BD2fg20Wwc17Oe7P+Nid8e6aB?= =?utf-8?q?DNidA3Ecu0pQVF3dvwlownkCmrI4DWWGMo7anr5+S2cdK8PG7SIKQkCXnXBwoB+Es?= =?utf-8?q?MX1lrdlFzE3vuvusKdszLFbOKYNp2DmdbYdD9zOdO11nhwGxr3JXHukbwSBGmsozu?= =?utf-8?q?yrV12ccaTdNqUyOU9NTlGZlsLAESIEFztmUdgaHS2QxKtkwHWVG9tVzU1Arn9+E9e?= =?utf-8?q?McLb7go617yg3sf12/URnAk83ezI0YDs4kmE2qU9Jb8wNPt06f2xHk/AxFydKMDUG?= =?utf-8?q?vfZVQZb091aCMRWbIueKTfWGiNOOSWtp+qAvUwPc8w+Jb+nPdplF/siERh/cZrtvC?= =?utf-8?q?ZNAVQy36grHe7YtagJ7qqPf+EPzQC35XKA7Iev2ZSr+0Yu8mbuWVsxHpNOXzTKZaF?= =?utf-8?q?xqpC4YUC+Mlxkgsii6lB7mND/fEJjlZ4lAH7BuVzft1zBsL4lSJUAO7UUpjugYNrX?= =?utf-8?q?SP4ShG+o7KzWPAa0u5jpiCxvzIWoa+Al47oUgU/3xb80R1k6hPyxlNDm/3E6bCM81?= =?utf-8?q?L3ksnIOurJGELfRqG3WF7e4LYp8nY7+6OkvXLCg93nwvysxT2WuqMKYi2Jk0ulR3A?= =?utf-8?q?xvCJZNZ6zBdAqz2Aj7ZIJfWe2jg0uCZ1nawdJyhwI/wRzZs8EhySNgcj9039Pez8N?= =?utf-8?q?S+mzCaXnBptdGHw0Pg+f3ODVyiFSnjZA8sjbNaGmqZzmRQ2PvQc66IIhUdM0I2Tn+?= =?utf-8?q?z6+F7U02yb4i/ayS4C3hsI2QAPJT4BhvjoOUF0bCR0hAjGSYy1Mq5DuNakiEv/bFH?= =?utf-8?q?CX1LiFJRfC1RrCpUULViyzrduKBg7BW1fJ500ifsPpcmF81mQWw7GNogJMdSDVxx0?= =?utf-8?q?MirBPtS7PwdCaagXHDWfrVsTK7rpX4ivx2Hy3smsg7lTFvoMwmOVhNhN4P4XvAHZB?= =?utf-8?q?nD+xXH2kGokbo9ZQauDKtKCOlWpMRRM3GZEPEHT5Ui1tUshp1PHKFxmiEq+jfvSr5?= =?utf-8?q?EzNrTCnVJkk66ut6/PGEtpsy8N1u4on7v9HisR+6IcIApOe1P55suQmOaSPxIXTg3?= =?utf-8?q?aiijWwkZi5ovlmn3Vkqet0dVDItU2oV8b6dmq1eioaVvkMZrV9D78LVbnLmIXcEUa?= =?utf-8?q?W8MCTX7epDxLx?= 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?q?xddZdIRgFEJsh2mb0k2jl6hzV2zK?= =?utf-8?q?gbkEhZAdw9nCe2zZK29LtiGKNoD4haJF+kbi4LelDx7ldQUWiI2dUXooku0a+C1ZX?= =?utf-8?q?/wvtr3xgbtRhpSihDmPEEWn9xEuprFFsy+wPQF+brRkc9lKqtHm6uE0M5T0BKXI3h?= =?utf-8?q?OjpbVvWxZCZg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j41JUxF/vTmVhca8iG9NLHe1NIsYU8L+5qwgpPq9KUmDWeLSWed2Kjdr19r3?= =?utf-8?q?RdxJI7u8nprcT8KPbKan/abZau5GtOSZsl9RMsBw6/9kuo/CcyJU4pfzQXBXn7MlN?= =?utf-8?q?OCD3hLEI7ZmXNgK7vBCT0nE94wJCkUeLNCFmiJdqsXVNVvtkfPlH/UR69GjzXg64n?= =?utf-8?q?+khLrTqVOr4orFGm4qFRmhcWiK5LfNQ/HeRX8umSlfHPb/HMrH1JC8eGpHZ192gDQ?= =?utf-8?q?Z1OmVSRA53sCmXRIcHVWddqKELG8OzVDrr7Z9OfJLTv2cPldKkGhUTS70jdSlDIZQ?= =?utf-8?q?PuurzklZQib2kq6PVBL2MmTk0WhIhoZvyDnGMODQCt602XkSPhoZlCvryq5juAIkU?= =?utf-8?q?Krh9oFBfFi27kvkb3f6SUWFojryP5He8wa43GUWSAIwPqJrlirmf43GTy+VZS8sNx?= =?utf-8?q?btaIyMt6bCmVzAlMVsfHHBJnKqd6lbto8RAtk43On/qGBwnV8+csGQp4K2DrcyGOv?= =?utf-8?q?9XAlMNldl19UTttyPPfLMpCjYWs2PRoLsw=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: ca155235-7f3f-41fa-1ddb-08dcf53f29c4 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:21.3542 (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: 9XgPgUJNOFCIDFEH3Fo/lHsn9Q+NGbgHujLlu+gf3xOdD2MhI4McvcoU5hX4vsWGTbRdzrXCeAW1E9ev9JtOfaRta/VOjhB4TWROpvXHyr4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR11MB7745 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" VF MMIO resource reservation, either created by system firmware and inherited by Linux PCI subsystem or created by the subsystem itself, should contain enough space to fit the BAR of all SR-IOV Virtual Functions that can potentially be created (total VFs supported by the device). However, that assumption only holds in an environment where VF BAR size can't be modified. 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 79143c1bc7bb4..5de828e5a26ea 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -645,10 +645,14 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) nres = 0; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { + int vf_bar_sz = pci_iov_resource_size(dev, + pci_resource_to_iov(i)); bars |= (1 << pci_resource_to_iov(i)); res = &dev->resource[pci_resource_to_iov(i)]; - if (res->parent) - nres++; + if (!res->parent || vf_bar_sz * nr_virtfn > resource_size(res)) + continue; + + nres++; } if (nres != iov->nres) { pci_err(dev, "not enough MMIO resources for SR-IOV\n");