From patchwork Wed Apr 2 14:11:19 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: 14036084 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (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 39E6723AE8D; Wed, 2 Apr 2025 14:12:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=198.175.65.20 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743603131; cv=fail; b=MhKJFOH9qpkW/cMyugBYhw0MOqjybZTjsXw7mR2h9gW5XK+7MjJ6NBqVbWqETLrU+uCj+XDJiwv/z4cUaqhCScUqMmkWYcS6du52mQ+m34QyQDZ87TwGb4ao6DwZ61zxkv73OIBi6m34Gm6wjkhXiHx4IjOydjI2axHBbjnQFrg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743603131; c=relaxed/simple; bh=S1jC0Lmjg22Iq2xHGaQKQ4cSnZc+qzdwjPAR/8Q3DCI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=C4lScvXl7VoNv+IHCBHVQHQJaiVoEy5ySlozXEZN8n4uAtsasykSS7wA/oxMzuABiTgGluvzWF0/L9NFhqTxSyXelCLYdcBgTUjUsXeW64y1/g2PcVjiRlotTebk+QlILiVNiVtYrxRvjrVGEvvhdbU7KIjKTglixrtcFALBIFE= 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=YIcH1sqa; arc=fail smtp.client-ip=198.175.65.20 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="YIcH1sqa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1743603130; x=1775139130; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=S1jC0Lmjg22Iq2xHGaQKQ4cSnZc+qzdwjPAR/8Q3DCI=; b=YIcH1sqaaeR7GtHvbu/8bIJtCIpfz1pxe/beKq0PjNdb1Gy+wzwoLweL JnyQ2hdlvop6uquvksgQG74fWYeUZxwNU5hw28KAqzEcGSr2NL87Cjuu/ ooJ7IW+c0EWvLqFsxR923gXLR15XpYIaPpTouHC5eUVG/sv2F+IOhmj2n 2kqHnmgIWR/53oh8pgtzSYNBOfVYuPy7XRvf0fV1Ms8CSV+YUdsWRt3gy CCv9S75d0VkYzryJ/tF7UUPGe/fZsYunJYduGToXFBiMb/d6bRIj+GGZJ zBu4PahSoCDeUwKmu7lC+eupH5//mw4u7DDPe+BljA0Purd9jTvPE9R1v g==; X-CSE-ConnectionGUID: JTZZ4RowR6q34yR0wqSZ4g== X-CSE-MsgGUID: LsVew3NCTOat+P35mtjtPQ== X-IronPort-AV: E=McAfee;i="6700,10204,11392"; a="44677148" X-IronPort-AV: E=Sophos;i="6.15,182,1739865600"; d="scan'208";a="44677148" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2025 07:12:05 -0700 X-CSE-ConnectionGUID: zzfVS+2TQtyBUfGYpDrAOA== X-CSE-MsgGUID: P54R2dcwQDOWJqrTeTylJg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,182,1739865600"; d="scan'208";a="127620420" Received: from orsmsx902.amr.corp.intel.com ([10.22.229.24]) by orviesa008.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2025 07:12:05 -0700 Received: from ORSMSX901.amr.corp.intel.com (10.22.229.23) by ORSMSX902.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Wed, 2 Apr 2025 07:12:04 -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; Wed, 2 Apr 2025 07:12:04 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.169) 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; Wed, 2 Apr 2025 07:12:03 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TWVLmBO7Zxc3537vFpbGF6abXutVoev5o6+8SuyANV3dt1mQlnp4Rxucz+XqwX4kV9kEHccTTEYgc7zcKUXgbuDbCACJmCC11RJ+XAwcicV9g9G0nzYvvNLGp8F/sjIgZUBKD6dflexMQgrKuoZusparE1cojG3G6PrGphuyXUFUDGWY2SASd2T2YJRqE45glMc8M7ySVxJpCFm8W3/HhUbwrz1fvcaXvwrKIHYBf6t9dbo9BIawE/KpCA4jVQJjWahwtKOY4zRmMud+ny8Lr6bF5WOPN9o2h76T5s6VxC+551cHvzO9ZcStODAz/BbMSny1wChctd+JVkf5FkInFw== 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=1+WX4f30IsXc1peH/jKONYDsfguRJ8HmiN0jcQiIz+s=; b=LemrCJWmKKatigUFTseV4XU7jwgxu9gPfPJlAaNge6lI11Rxjh8Vd8fkMKS+L68KTLq5BcisRXuJjjqh5fsqRYx+7mjW4YoRhhoXa7rC5pSrnuY/6eJzfTCQ+g03ASnRs+u9mZqabmPeGPkwEX3kdKY2Xt3rkcU9/cmVgWgClTPqGxwNKNhNT/6Qhldj8/bygPeysyuqqZ5Sb4/gldULpLpWElJAUDa1ADn8CwDpmOHyPDPeyz+6f3CdcYNg700R4FFOdojMBvSZuU+fFIKeogciBJlxmKYAUHrEOIjDWwHJdrOxkYWESEIVDx6GpLyhS7SRjnWtTT6AMqVsDE3aiQ== 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 SJ0PR11MB5213.namprd11.prod.outlook.com (2603:10b6:a03:2da::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.48; Wed, 2 Apr 2025 14:11:50 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39%4]) with mapi id 15.20.8583.041; Wed, 2 Apr 2025 14:11:50 +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 v7 3/6] PCI: Allow IOV resources to be resized in pci_resize_resource() Date: Wed, 2 Apr 2025 16:11:19 +0200 Message-ID: <20250402141122.2818478-4-michal.winiarski@intel.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402141122.2818478-1-michal.winiarski@intel.com> References: <20250402141122.2818478-1-michal.winiarski@intel.com> X-ClientProxiedBy: VI1PR0102CA0021.eurprd01.prod.exchangelabs.com (2603:10a6:802::34) 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_|SJ0PR11MB5213:EE_ X-MS-Office365-Filtering-Correlation-Id: f9c2cc56-f4d2-45f7-6978-08dd71f04e5f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?WXGLrP1Y88YNhIw0uXBNxm6jDG/0Jns?= =?utf-8?q?1ENEcoMBFyeiNA/tndj4h31SMal4Y0Pkq0DoRJ3devQrsGUGJYuTPsBX3cET61f+J?= =?utf-8?q?/q0KZTdE5bNFGr/k67NGyxjq7jTMJkQB7fVGH5g+BvM6noNfofBf7mtfFFNsdlzJi?= =?utf-8?q?bBAFMw4XyEsE+OxjY/dfV4jmA3g0c72P7D6/Cm+UQKItLPI5O4NdEKEXzIez3H/KN?= =?utf-8?q?vxZybZmpyrZ7W3zG/7E1D5K3SMdA0skX425QsRqcOYlHeLZWrTbCw6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AEG+bOE7fadWO?= =?utf-8?q?O1vesyZ3azXQsPUwPp64VOvMm0UrkumOPHJYUi+ona/idiV0+/ogRZc0+okNpbs9C?= =?utf-8?q?rxukpfiDeQ8NgG4tiWd1GT17nqh3HPUiIavun7B/9ttyWhRi2PCrMhC8Wh/4MVh1W?= =?utf-8?q?rQb4KDcFtWJFpqBgyPV+TkY3EJ8EzEYCnSPZ/Y4q03ManlRZGYoGQwLFHcTBtEkYX?= =?utf-8?q?llnRNPinNsCa?= 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)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?ue6q6n1PnTJdI0PG0wPwXIQ4QzV7?= =?utf-8?q?HmhkONTVdb58DyFufNz86TGSxrSV4q0IQ+JXVP5W8plsrWI7L8d08tIV01Iyczd68?= =?utf-8?q?86onDygRPqoxN/bda2UyvZFtKwL/ldWqpHJINmLLYMgFHuC25gcZs7BKH066zrkbQ?= =?utf-8?q?O9IP1lCfiQ0hlYNxw/TGq4tp5heGrQkcSEAKY6nRC6mqeyj1NKam4MGD3Z+qQJoXZ?= =?utf-8?q?YhWpx5iO5KSjPaW34oSAEYSCvSBllVEVRFqUSXWRQuw6HNxnTA5T0+b5pqwSemODQ?= =?utf-8?q?KhetAaleRXpXr+BBLr6QlCwDpdHkuzLf/gSy2oKP193srE3eiRM/iZNyhIbARD+JP?= =?utf-8?q?UCn/WdatPSZcTORamTpQjxjgKzn3g6ptPs7TDruT1czBv1Mf0O1bpUqednpuAbhkO?= =?utf-8?q?FRUuy+TkcvTD9LQlQ5lNk9dtD0vCtRqgCb3NFAgZANRmEUkOyaBZhR6vxKtiwiGiq?= =?utf-8?q?LvArWTDhbH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f-8?q?FuvtOV15rdHdEuqChar4YfQHZW4y6jAQcTinBqunylVueaUe3XctOScXLF3a0GNwV?= =?utf-8?q?Ncj3jkRZ0slp/Xwfb1GcXmO/OSxZWSJxqFYRhP2WXYUWctnhjSi56vZzzfY4FHvfh?= =?utf-8?q?cQ2avf2pdTUUgijcHjOkM1rwmCNn+1Vi4msAIDc0ybZgOAiAvpaPOr6/mNIs9RCKP?= =?utf-8?q?fo1Us3hOc/luESIrgu/WnjLEKzoy7r4Tjw=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: f9c2cc56-f4d2-45f7-6978-08dd71f04e5f X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2025 14:11:50.5394 (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: D4oprYbjuKh1g4ocI4O7Qm1Jn0sbYmCAdOPQ/rrpVA+jmLz/KiACx1ndeikADeP0kH+eaitKpAew4PpQsK0CvZT5knH6KsWDG0RdqCJuzDA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB5213 X-OriginatorOrg: intel.com Similar to regular resizable BAR, VF BAR can also be resized. The capability layout is the same as PCI_EXT_CAP_ID_REBAR, which means we can reuse most of the implementation, the only difference being resource size calculation (which is multiplied by total VFs) and memory decoding (which is controlled by a separate VF MSE field in SR-IOV cap). Extend the pci_resize_resource() function to accept IOV resources. See PCIe r6.2, sec 7.8.7. Signed-off-by: Michał Winiarski Reviewed-by: Ilpo Järvinen --- drivers/pci/iov.c | 21 +++++++++++++++++++++ drivers/pci/pci.c | 10 +++++++++- drivers/pci/pci.h | 9 +++++++++ drivers/pci/setup-res.c | 35 ++++++++++++++++++++++++++++++----- 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 3d5da055c3dc1..fee99e15a943f 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -154,6 +154,27 @@ resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno) return dev->sriov->barsz[pci_resource_num_to_vf_bar(resno)]; } +void pci_iov_resource_set_size(struct pci_dev *dev, int resno, + resource_size_t size) +{ + if (!pci_resource_is_iov(resno)) { + pci_warn(dev, "%s is not an IOV resource\n", + pci_resource_name(dev, resno)); + return; + } + + dev->sriov->barsz[pci_resource_num_to_vf_bar(resno)] = size; +} + +bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev) +{ + u16 cmd; + + pci_read_config_word(dev, dev->sriov->pos + PCI_SRIOV_CTRL, &cmd); + + return cmd & PCI_SRIOV_CTRL_MSE; +} + static void pci_read_vf_config_common(struct pci_dev *virtfn) { struct pci_dev *physfn = virtfn->physfn; diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 4d7c9f64ea24e..6878e3b1e3fcf 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3745,7 +3745,15 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar) unsigned int pos, nbars, i; u32 ctrl; - pos = pdev->rebar_cap; + if (pci_resource_is_iov(bar)) { + if (!pdev->physfn) + return -ENOTSUPP; + pos = pdev->sriov->vf_rebar_cap; + bar = pci_resource_num_to_vf_bar(bar); + } else { + pos = pdev->rebar_cap; + } + if (!pos) return -ENOTSUPP; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index f44840ee3c327..643cd8c737f66 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -689,6 +689,9 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno); resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno); void pci_restore_iov_state(struct pci_dev *dev); int pci_iov_bus_range(struct pci_bus *bus); +void pci_iov_resource_set_size(struct pci_dev *dev, int resno, + resource_size_t size); +bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev); static inline bool pci_resource_is_iov(int resno) { return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END; @@ -722,6 +725,12 @@ static inline int pci_iov_bus_range(struct pci_bus *bus) { return 0; } +static inline void pci_iov_resource_set_size(struct pci_dev *dev, int resno, + resource_size_t size) { } +static inline bool pci_iov_is_memory_decoding_enabled(struct pci_dev *dev) +{ + return false; +} static inline bool pci_resource_is_iov(int resno) { return false; diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index c6657cdd06f67..d2b3ed51e8804 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -423,13 +423,39 @@ void pci_release_resource(struct pci_dev *dev, int resno) } EXPORT_SYMBOL(pci_release_resource); +static bool pci_resize_is_memory_decoding_enabled(struct pci_dev *dev, + int resno) +{ + u16 cmd; + + if (pci_resource_is_iov(resno)) + return pci_iov_is_memory_decoding_enabled(dev); + + pci_read_config_word(dev, PCI_COMMAND, &cmd); + + return cmd & PCI_COMMAND_MEMORY; +} + +static void pci_resize_resource_set_size(struct pci_dev *dev, int resno, + int size) +{ + resource_size_t res_size = pci_rebar_size_to_bytes(size); + struct resource *res = pci_resource_n(dev, resno); + + if (!pci_resource_is_iov(resno)) { + resource_set_size(res, res_size); + } else { + resource_set_size(res, res_size * pci_sriov_get_totalvfs(dev)); + pci_iov_resource_set_size(dev, resno, res_size); + } +} + int pci_resize_resource(struct pci_dev *dev, int resno, int size) { struct resource *res = pci_resource_n(dev, resno); struct pci_host_bridge *host; int old, ret; u32 sizes; - u16 cmd; /* Check if we must preserve the firmware's resource assignment */ host = pci_find_host_bridge(dev->bus); @@ -440,8 +466,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size) if (!(res->flags & IORESOURCE_UNSET)) return -EBUSY; - pci_read_config_word(dev, PCI_COMMAND, &cmd); - if (cmd & PCI_COMMAND_MEMORY) + if (pci_resize_is_memory_decoding_enabled(dev, resno)) return -EBUSY; sizes = pci_rebar_get_possible_sizes(dev, resno); @@ -459,7 +484,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size) if (ret) return ret; - resource_set_size(res, pci_rebar_size_to_bytes(size)); + pci_resize_resource_set_size(dev, resno, size); /* Check if the new config works by trying to assign everything. */ if (dev->bus->self) { @@ -471,7 +496,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size) error_resize: pci_rebar_set_size(dev, resno, old); - resource_set_size(res, pci_rebar_size_to_bytes(old)); + pci_resize_resource_set_size(dev, resno, old); return ret; } EXPORT_SYMBOL(pci_resize_resource);