From patchwork Mon Apr 7 14:39:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 14040878 X-Patchwork-Delegate: kw@linux.com Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D50611F8BC5 for ; Mon, 7 Apr 2025 14:39:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744036772; cv=none; b=WzgB5xDeKkf+tIWsBIzPUSpqHZuw+M+7+kievDz09fsRfdUOpl9DxL8Qb8qvi0xCn2DaFiX3a1bB8DSr+4RSZxQSzUd2Cha+q9S4+S7J4oUj2EkZn4ZQZsobte0lT0yCXEKHKQTJvsSB+MfErMO44Vn8pa2d+gYkDK1MMVuqg+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744036772; c=relaxed/simple; bh=gpdenQ1KTwrhqtRAGsdUtxPDX/0ZTIXJDe/D+TKenF4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nMs+p9QSSCtwI6U8T+FPZ5Q4v3X5zQVcG7VM/vUFQw75oMO8JC5ai9nEbRAdWJ+DTUAH2Q5+QNR+WP09yZf5MdkxAuQ8wNGY/OTP0Wv6MegBS+73YjAVA0By4+TYzvcZYMOpYRdcjyT/ccpeepjpeCWmMDb7I3Kye9mHerrsgU4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=USH96wTo; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="USH96wTo" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3995ff6b066so2403639f8f.3 for ; Mon, 07 Apr 2025 07:39:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1744036767; x=1744641567; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=CAkSoBab2mcjkSikNieA7Mms82PLhiuTw+xHOZIjvOM=; b=USH96wToS2QK+WUQ3EfwESMwcLSpjohUHVu21tPQ5903L0huSambSn7v+1hm0dIZl2 0KabSrMQjz3Iq9Yl1Zrae0Czg2hzUB/FyrB0pap8ODLucPF/cax6t7Y5d5uhF25Nzycf eTey/FgWUW0knZOxoSc022qieeo/gJ+Os6njEir0NkRYPq4f5hopRN5e1oTjp6SrqrD8 /XoY5gxzz/p12NycwA9x1CDC+1LEAIMZUHUVTTjd9Mf8Suir/VMRK1TQdgtch5J1BWR9 7Bkv1LapLTx1qXS2XNL78fZOc1txGoCO9+eBh1LXBs0YaSU75t1ZWM5+es4SZX5RiHIQ 9r6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744036767; x=1744641567; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CAkSoBab2mcjkSikNieA7Mms82PLhiuTw+xHOZIjvOM=; b=KP7NXdowvruOpUIYS/nkH3R2N8Fo9qfq10O61WXKeT0hlSw9cEoOZFWjx6MHRSUk5U PGt0UctK+hXT1F2IckdIhI07Dizp97nltGVnHSTKUu5vKjrWPA+x5YDl/+iB/41H0YVX xaCJl6BmYiLyVu2RJZpRBKvDsB9NB5NGvg+66KHczRuZfH5YAiRJ+sDpIx8w3xLl9hXp RPHj1yegNYArWiIlci5h44loG4ZJvgnHxK1A0RjzK9tdLtrz24tHVJMdNlcHHK2yMVHJ IIeVOl03uZJBZvnlB5cu/4eIhBL8IYNTnwyw32jqi/OngoPFK0LSk0Z6Hym63i0n6BOy aOwg== X-Forwarded-Encrypted: i=1; AJvYcCVwGUa2pg97znZJqcaSAI4hyDMaKcJELPbolULA++tXZ/NXpcZa2I0dbppgeQAaaYyXAsz8T8p755I=@vger.kernel.org X-Gm-Message-State: AOJu0YxfEZjMEi37hYvP+o19xdfM2+uKkJVoNewmNMUigzAzNuq3g7IF pEOk9gJ39JjIqNnxFv6VgJyE6J5UCmf1gIOHM2bS0U6ZkgkO6+dnde5h+swJESteXeK/ncL5Itw o X-Gm-Gg: ASbGncu0GfIXqT0lx1lvVzONtVCcG7xHuFQa4RkeTKDPOS5SP4LoIanlXfuaGSXtCqL 1k7mjrLgWgE8xRUX7EQEnGfRxEi7mBqUejEDO3HllXbTshO+JB0JOfrovxdVHCWxlz32ynSEcSg ExWPQVB5cUPFpDy/Bwu0+mn9fcWvajgYz6XwxfbOg9iCq8ZoX5rjidPK4mgJT2H8vyrcw+4NAxf LWUyBBzCMUQuN7Tf7b+2lnBC04pM9/CGGwZ/eTIExrfcgPoTjbiy1/QzNKbxMxCVv9ve8M1DqVX OYBKYseYYmKge2pCN3XPeZZjgEVcLPsX11GCKaREEpDn69OUfUuiqSKZmvY= X-Google-Smtp-Source: AGHT+IHYNuBw7pt0b3N9Uj+WvpJtruSG0l3vb5tTFAlq3DYP7AsQp5Q6OxMd7vtr6bLEUuW77X9vqQ== X-Received: by 2002:a05:6000:2509:b0:390:d6ab:6c49 with SMTP id ffacd0b85a97d-39cb35b1a8cmr12446064f8f.35.1744036766921; Mon, 07 Apr 2025 07:39:26 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:1122:cb29:d776:d906]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43ec16602bbsm135003705e9.9.2025.04.07.07.39.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 07:39:26 -0700 (PDT) From: Jerome Brunet Date: Mon, 07 Apr 2025 16:39:07 +0200 Subject: [PATCH v3 1/3] PCI: endpoint: add epc_feature argument for pci_epf_free_space() Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-pci-ep-size-alignment-v3-1-865878e68cc8@baylibre.com> References: <20250407-pci-ep-size-alignment-v3-0-865878e68cc8@baylibre.com> In-Reply-To: <20250407-pci-ep-size-alignment-v3-0-865878e68cc8@baylibre.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Lorenzo Pieralisi , Jon Mason , Dave Jiang , Allen Hubbe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni Cc: Marek Vasut , Yoshihiro Shimoda , Yuya Hamamachi , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, ntb@lists.linux.dev, linux-nvme@lists.infradead.org, Jerome Brunet X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6049; i=jbrunet@baylibre.com; h=from:subject:message-id; bh=gpdenQ1KTwrhqtRAGsdUtxPDX/0ZTIXJDe/D+TKenF4=; b=owEBbQKS/ZANAwAKAeb8Dxw38tqFAcsmYgBn8+OauAXNd7kCvh8ELhw9UoQ+j9kAT8RJ+NjMp oe5ssp0vg+JAjMEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZ/PjmgAKCRDm/A8cN/La hX83D/sHZNFS59gQ+4tjHanyRU0075HG7FzCjsrOpcn4tmq1hn+jgn6dhWO8oxjMBDCbTextQIf XRhqEc8ne7LwhSCmO6VJffo+woIG1kNyvVmHcnUoacePg95tTePNuTrs9K2dLUe9JTvZwwJiKuc zvQCcBgslxS3wyCeZrO57mYiNHr5R/6kNvQ2G7t/to2FiXiQTduj+CVkiKvG+7JX/W7FA8C9MtU mj61PY4DqWpdNGt5ssMYq3mkwbLpEdWoOdgz/h9iLLqHyUeLv3So091p137zgvTx7BbPm2ePh0P QRfjqrhJFfkGb9453ayLp+zPjxUKwAkA653DtSQJTz6pp7FTYJnHYVWqjk/lM6cEci3zKZfgU2j p5BMXYjoL0kO5A6/nhlMm11Qatd1scLJloJBeYmShCQSaglvY9XXMSqtsI1Xe35rklbdDlL+a2M 7yJSGuy/qDj1MhcMcX2lM0ac4KdD40GfPY5AcwzRhZCo2eNxIRAmn/s9g0DvK05fdaBxRtjHNxC ouUQ9p2HWbLG+c52gHmU5kfTqYipAZMdnsN1+i9UJVyADq9UGL4MRiL4KdwEn96dANHkP/ObHKU I4Wj+6VnOjKQQM2sun9xo8gAfcAW3nFfH9w7cCMkhAdraLlVc5tl87BfSr5Vm5UFBY6H4qpdAAF c3hpgbSWFd/jwTA== X-Developer-Key: i=jbrunet@baylibre.com; a=openpgp; fpr=F29F26CF27BAE1A9719AE6BDC3C92AAF3E60AED9 Add epc_feature argument for pci_epf_free_space(), same as pci_epf_alloc_space(). Doing so will allow to better handle the iATU alignment requirements. Signed-off-by: Jerome Brunet --- drivers/nvme/target/pci-epf.c | 3 ++- drivers/pci/endpoint/functions/pci-epf-ntb.c | 3 ++- drivers/pci/endpoint/functions/pci-epf-test.c | 2 ++ drivers/pci/endpoint/functions/pci-epf-vntb.c | 16 +++++++++++++--- drivers/pci/endpoint/pci-epf-core.c | 2 ++ include/linux/pci-epf.h | 1 + 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/target/pci-epf.c b/drivers/nvme/target/pci-epf.c index 51c27b32248d0137fd3a557728eaab72fc7fca0c..2bbc41f8400837bcb83463b436598b16070e11f5 100644 --- a/drivers/nvme/target/pci-epf.c +++ b/drivers/nvme/target/pci-epf.c @@ -2174,7 +2174,8 @@ static void nvmet_pci_epf_free_bar(struct nvmet_pci_epf *nvme_epf) if (!nvme_epf->reg_bar) return; - pci_epf_free_space(epf, nvme_epf->reg_bar, BAR_0, PRIMARY_INTERFACE); + pci_epf_free_space(epf, nvme_epf->reg_bar, BAR_0, + nvme_epf->epc_features, PRIMARY_INTERFACE); nvme_epf->reg_bar = NULL; } diff --git a/drivers/pci/endpoint/functions/pci-epf-ntb.c b/drivers/pci/endpoint/functions/pci-epf-ntb.c index e01a98e74d211174db3075c20457a3183f37e0a5..44775c41c10b90a56b1167f3f3869a60c686cf9e 100644 --- a/drivers/pci/endpoint/functions/pci-epf-ntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-ntb.c @@ -957,7 +957,8 @@ static void epf_ntb_config_spad_bar_free(struct epf_ntb *ntb) ntb_epc = ntb->epc[type]; barno = ntb_epc->epf_ntb_bar[BAR_CONFIG]; if (ntb_epc->reg) - pci_epf_free_space(epf, ntb_epc->reg, barno, type); + pci_epf_free_space(epf, ntb_epc->reg, barno, + ntb_epc->epc_features, type); } } diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 50eb4106369f41afa00ed3ae58c84922e0a49e51..8d5df47967226e1f02444e8d45f7aad1394afd04 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -740,6 +740,7 @@ static int pci_epf_test_set_bar(struct pci_epf *epf) &epf->bar[bar]); if (ret) { pci_epf_free_space(epf, epf_test->reg[bar], bar, + epf_test->epc_features, PRIMARY_INTERFACE); epf_test->reg[bar] = NULL; dev_err(dev, "Failed to set BAR%d\n", bar); @@ -941,6 +942,7 @@ static void pci_epf_test_free_space(struct pci_epf *epf) continue; pci_epf_free_space(epf, epf_test->reg[bar], bar, + epf_test->epc_features, PRIMARY_INTERFACE); epf_test->reg[bar] = NULL; } diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c index 874cb097b093ae645bbc4bf3c9d28ca812d7689d..8f59a5b9b7adec2c05eebae71c6a246bc5a8e88c 100644 --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c @@ -389,10 +389,15 @@ static int epf_ntb_config_sspad_bar_set(struct epf_ntb *ntb) */ static void epf_ntb_config_spad_bar_free(struct epf_ntb *ntb) { + const struct pci_epc_features *epc_features; enum pci_barno barno; + epc_features = pci_epc_get_features(ntb->epf->epc, + ntb->epf->func_no, + ntb->epf->vfunc_no); + barno = ntb->epf_ntb_bar[BAR_CONFIG]; - pci_epf_free_space(ntb->epf, ntb->reg, barno, 0); + pci_epf_free_space(ntb->epf, ntb->reg, barno, epc_features, 0); } /** @@ -557,7 +562,7 @@ static int epf_ntb_db_bar_init(struct epf_ntb *ntb) return ret; err_alloc_peer_mem: - pci_epf_free_space(ntb->epf, mw_addr, barno, 0); + pci_epf_free_space(ntb->epf, mw_addr, barno, epc_features, 0); return -1; } @@ -570,10 +575,15 @@ static void epf_ntb_mw_bar_clear(struct epf_ntb *ntb, int num_mws); */ static void epf_ntb_db_bar_clear(struct epf_ntb *ntb) { + const struct pci_epc_features *epc_features; enum pci_barno barno; + epc_features = pci_epc_get_features(ntb->epf->epc, + ntb->epf->func_no, + ntb->epf->vfunc_no); + barno = ntb->epf_ntb_bar[BAR_DB]; - pci_epf_free_space(ntb->epf, ntb->epf_db, barno, 0); + pci_epf_free_space(ntb->epf, ntb->epf_db, barno, epc_features, 0); pci_epc_clear_bar(ntb->epf->epc, ntb->epf->func_no, ntb->epf->vfunc_no, diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 394395c7f8decfa2010469655a4bd58a002993fd..b7deb0ee1760b23a24f49abf3baf53ea2f273476 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -213,11 +213,13 @@ EXPORT_SYMBOL_GPL(pci_epf_remove_vepf); * @epf: the EPF device from whom to free the memory * @addr: the virtual address of the PCI EPF register space * @bar: the BAR number corresponding to the register space + * @epc_features: the features provided by the EPC specific to this EPF * @type: Identifies if the allocated space is for primary EPC or secondary EPC * * Invoke to free the allocated PCI EPF register space. */ void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar, + const struct pci_epc_features *epc_features, enum pci_epc_interface_type type) { struct device *dev; diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 879d19cebd4fc6d8df9d724e3a52fa7fbd61e535..d2d1c60fd5e0487b25aad51fee1b30554f630557 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -222,6 +222,7 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, const struct pci_epc_features *epc_features, enum pci_epc_interface_type type); void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar, + const struct pci_epc_features *epc_features, enum pci_epc_interface_type type); int pci_epf_bind(struct pci_epf *epf); void pci_epf_unbind(struct pci_epf *epf); From patchwork Mon Apr 7 14:39:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 14040877 X-Patchwork-Delegate: kw@linux.com Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 948BC1F8BD0 for ; Mon, 7 Apr 2025 14:39:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744036772; cv=none; b=UTRV+/DTz2N1YzKaVdM+bc+S9+UuwUV3paOvxiyZOn25A10T7sCCEXk1JRQEPqLuAsrpuM9v4km1/cOz5Fm1P2P4lDkViBR5rKIf4OtCizs+hLG9y//PujwhbzV75GxrPfnYnvOIjwTxPqU1WHEnOuxznw9g39Bd2y/zfNRFk6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744036772; c=relaxed/simple; bh=n0KkujYCmFsi6TCmOtVdMu0bbfrL6UkgnMn4aw3JxJA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tDg2SvmCXMAcUTWlxBzftFrIGbO2wnj+RrTmD/wwxHrARvTYGxVX9OHcGgeocfPC2AqFvwpzoxbvbZcTUh97Uhc7hcNlkm24oB9YYU2jB2BUcxupSl3CiKfoKEq3GOccSOofIRzYFHqfCl9J7nCTIxq+ok3A6PyeheMybZChSLM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=K+nvT7YF; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="K+nvT7YF" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-39c31e4c3e5so2756698f8f.0 for ; Mon, 07 Apr 2025 07:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1744036768; x=1744641568; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Y7eFcTw1BBmLsXfJBPUwIPNdKPEmqoZIDDhrBsVYvns=; b=K+nvT7YFxhEAhsSYsMdvO9GRgyH7rBqMQ3xOKZV9jFqd0LBiY/L0JMW92qZ68suQtM qTjupBjdTsxlDuI3rf9UgXMHIFWtPPrj1r8Vj20fB3Qvn25O0ARjab2I2U7Sal7RjDwj 5HOOi68tysp3Cjz/mAFriRCRWYxlYQcIAWJd7p8+vNXT3kKZcNolpNw18BfUucLARM71 mkWv5N2qEwC3qd+Ww0NzdP2w5546S4ocQMpQWmlaGvT30DWhlk9lTYLiJysJUGXLEwtL CYVDSHrtHM4voY6J2+HICdzCj4g+0BB8/HaJ+epbJZNmfIxLrdVXH2crLKWt5LOkkJCX 68lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744036768; x=1744641568; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y7eFcTw1BBmLsXfJBPUwIPNdKPEmqoZIDDhrBsVYvns=; b=RWAG/4pt4Lxv2YCIBFuFhja7bvYL3ScQTUfgx/5aikiGsAJzCmQyJincoAaSPFor+f xQhKd+1OBlo/k7VgBiX48gUofljx23eVYto7g2YMuT5A8fPKVg9xqBUlmdiSpip6LJJO XR6aGJxzGsWI4sFpY4+5bQ9gL32hCCbQ5rdpPw3v1rLWU1pXLw9LhD81OX6jKXtEcT0h kWFj6nbEyRURdJ+qjsnITqNwg3OXznsI0cEXlFCvLGeDeCn8AIltHdcUzbsZ42ThcHdA QvYFhce5Md7i0D7Xod8KcRgQHlO9mYlNdX9f4aBcI+IgNXgOvImm4RnhJ6XNCWvu8I9+ OMBA== X-Forwarded-Encrypted: i=1; AJvYcCVFyUYb+HBw4941gdf5WCYU4d5MVCsBY/UoVa4XWVydExubz7bG0Q2gEB0EdVGepig7R6hgFXX/06A=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/sX8013irI2zj8kMcxPKML5kb1HFBFIv1jva7gpDI9Qb/sFsp 9W+b3YvqeHO3sPoEEeQUfVw/HgaPwSltaOrMIuVyUwC9RzMgZmngjADTSomz+Pvhf3VDcWBP0o3 v X-Gm-Gg: ASbGncvpqLJskd+OR39s80dSw9g1V4HdyomFMpwpnzEJo26WSj71P/xxgOvjmqTkl3E yz4AMCyDku5S2YPXx9Wzw4lMkRG1uLo5g115QHJaQmhYCGi4bxw6AOhQGpVQNvGJxl8vF+a8F5Y k6vlSERKCfZzUp+FlG0qKA1Tm/ev8ljkKrJltg1WHRjdVouS0mAHqBpVladCWSDacNQl73ubGxT fli/AjCw5EwT5elYXmVe1ZI/4SfGYUufzmFkKmOGZlH2wu8zjtTB/DL1gPAG4VIteLQ5mjHAcuU Xlvdt8Y8cqndVyp9e24ka3A2gOjQxnM4jgFaqLiwPMx/fFKWpNOA7/VBDz4= X-Google-Smtp-Source: AGHT+IHz+UHcCsUtEEJhgEfJlAKbScYm9TcMULxn6JxZWVz6GKeQRERIZCltbN3u7HtrlOzoRjNl/A== X-Received: by 2002:a05:6000:188f:b0:391:3915:cfea with SMTP id ffacd0b85a97d-39cba93329amr10771859f8f.38.1744036767753; Mon, 07 Apr 2025 07:39:27 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:1122:cb29:d776:d906]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43ec16602bbsm135003705e9.9.2025.04.07.07.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 07:39:27 -0700 (PDT) From: Jerome Brunet Date: Mon, 07 Apr 2025 16:39:08 +0200 Subject: [PATCH v3 2/3] PCI: endpoint: improve fixed_size bar handling when allocating space Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-pci-ep-size-alignment-v3-2-865878e68cc8@baylibre.com> References: <20250407-pci-ep-size-alignment-v3-0-865878e68cc8@baylibre.com> In-Reply-To: <20250407-pci-ep-size-alignment-v3-0-865878e68cc8@baylibre.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Lorenzo Pieralisi , Jon Mason , Dave Jiang , Allen Hubbe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni Cc: Marek Vasut , Yoshihiro Shimoda , Yuya Hamamachi , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, ntb@lists.linux.dev, linux-nvme@lists.infradead.org, Jerome Brunet X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3212; i=jbrunet@baylibre.com; h=from:subject:message-id; bh=n0KkujYCmFsi6TCmOtVdMu0bbfrL6UkgnMn4aw3JxJA=; b=owEBbQKS/ZANAwAKAeb8Dxw38tqFAcsmYgBn8+ObiJpvdYB8bsZnZVvwp+QDS1VlGg2pjvZVF AG6RByUfqeJAjMEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZ/PjmwAKCRDm/A8cN/La hb2MD/0YQhJLrOZ76T9VTuUia/wCoGBX5EMJnYssupmfuh6Sv5QSaTs5/1bOLyHR64hwp4rgcm+ NQQxKNgHWHakJNxR5lQGikqtiYKuaVwsAaso6mWmgNsIhumgjAeOhSfpL/arH0zfBIImA/h5Orf 0YlfqljnT1Ap7yO6n+CLEUK1KkeH0fsk3Hs2O/AD9gtT+ZAMceneheK4VD64dcSWLNU+tT12nX2 3WcV+F8Oe6eRpjIsyIF56/yFrgAkzM1B/k8ZFqOXDgFqb0aDMH6COVKwSGkdbMyZ1wV/e3mvI6c 1kZUS1LgH3ESB5Cak1EG+0JZehGnJsbAecqLXxhYNYfyctcDx7cKjk16L+8z3G53VdIHWuTjP8s ZxV9TLG9f2U1DZqtudDIwqXX61MNL9Igqvv3co8jizpNIcjM0kTjdFDUas0OZ+nWL9bWtwkohu0 sXb7xs1tIVyZQ6O3YD22HbpKfpVknQ81WZ3KicMRZOfJ22FHxHxF/alKA0DaNVFBu8efVH6S18/ pB9RFpc7R8STCGyUpw5u/7UTiXBftL8XarGnrqvwWJ2B8OBg+te82ctgTKFJGGlrBMRHSnnpIY0 szjPrQuaWsLGEXgGozut/BhnEuMKPPETZnH0PUVrGeGY2cezR2MemHr/dQmI15mSXO7s0iEihfB NCY/lGk981j6SYA== X-Developer-Key: i=jbrunet@baylibre.com; a=openpgp; fpr=F29F26CF27BAE1A9719AE6BDC3C92AAF3E60AED9 When trying to allocate space for an endpoint function on a BAR with a fixed size, the size saved in the 'struct pci_epf_bar' should be the fixed size. This is expected by pci_epc_set_bar(). However, if the fixed_size is smaller that the alignment, the size saved in the 'struct pci_epf_bar' matches the alignment and it is a problem for pci_epc_set_bar(). To solve this, continue to allocate space that match the iATU alignment requirement but save the size that matches what is present in the BAR. Fixes: 2a9a801620ef ("PCI: endpoint: Add support to specify alignment for buffers allocated to BARs") Signed-off-by: Jerome Brunet --- drivers/pci/endpoint/pci-epf-core.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index b7deb0ee1760b23a24f49abf3baf53ea2f273476..fb902b751e1c965c902c5199d57969ae0a757c2e 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -225,6 +225,7 @@ void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar, struct device *dev; struct pci_epf_bar *epf_bar; struct pci_epc *epc; + size_t size; if (!addr) return; @@ -237,9 +238,12 @@ void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar, epf_bar = epf->sec_epc_bar; } + size = epf_bar[bar].size; + if (epc_features->align) + size = ALIGN(size, epc_features->align); + dev = epc->dev.parent; - dma_free_coherent(dev, epf_bar[bar].size, addr, - epf_bar[bar].phys_addr); + dma_free_coherent(dev, size, addr, epf_bar[bar].phys_addr); epf_bar[bar].phys_addr = 0; epf_bar[bar].addr = NULL; @@ -266,7 +270,7 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, enum pci_epc_interface_type type) { u64 bar_fixed_size = epc_features->bar[bar].fixed_size; - size_t align = epc_features->align; + size_t aligned_size, align = epc_features->align; struct pci_epf_bar *epf_bar; dma_addr_t phys_addr; struct pci_epc *epc; @@ -287,12 +291,17 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, return NULL; } size = bar_fixed_size; + } else { + /* BAR size must be power of two */ + size = roundup_pow_of_two(size); } - if (align) - size = ALIGN(size, align); - else - size = roundup_pow_of_two(size); + /* + * Allocate enough memory to accommodate the iATU alignment requirement. + * In most cases, this will be the same as .size but it might be different + * if, for example, the fixed size of a BAR is smaller than align + */ + aligned_size = align ? ALIGN(size, align) : size; if (type == PRIMARY_INTERFACE) { epc = epf->epc; @@ -303,7 +312,7 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, } dev = epc->dev.parent; - space = dma_alloc_coherent(dev, size, &phys_addr, GFP_KERNEL); + space = dma_alloc_coherent(dev, aligned_size, &phys_addr, GFP_KERNEL); if (!space) { dev_err(dev, "failed to allocate mem space\n"); return NULL; From patchwork Mon Apr 7 14:39:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 14040879 X-Patchwork-Delegate: kw@linux.com Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E00F1F91E3 for ; Mon, 7 Apr 2025 14:39:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744036774; cv=none; b=sw1TMSUK3Y7FIKQCPjOos2De/rWrqpx0DtphD3biDDODGUIhnTCcm0bvdRnyrNhROca1ybSHhOdmbJf445UIUyEroKvSxRuvm3HSI/PyP+HYg9arzMx87QYyNYCm1A/PHPYSKLXTIaO+ZUQ5DUm2N3WcxorhAjGN++trfg6YmWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744036774; c=relaxed/simple; bh=VMQRvj8CO60hVIlMMgdkTE1dtBACF+fNeO1bhBVnQsU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ux2WhftdPuLdUFtvbXVABVwB+aHQdi+REgqxdjXMr3leb7Lfr0aZrcfnoXtmHeu24FSLSKdp4IglV5DPHZfwDMZCG/yHpuVaNo/xxd2WgXr+mEhytSfM6/Wr2XjEVSg4wICPkunjHTtrSRqR0TYuCjgwH+ihbJ6Xwk0aHUodL0E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=sY/Qfux4; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="sY/Qfux4" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-43cf257158fso31067525e9.2 for ; Mon, 07 Apr 2025 07:39:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1744036769; x=1744641569; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=pxPRinaB0R9MRMHkqtzs6Jksu6ZEexxFz8Cu5WJ1Zw0=; b=sY/Qfux4gitYxD5bucZHE8bB/tfelW6IUCOG3P7D9JjYSzaY9fDYxELg8SExkl0M+6 otmXZyt/vOe+peWCEZtiyCU9ws6wT4sdPK2xVOtggUlWx/F56zfgkQL9Ddf9Ck0x93bs tvGU+B4q8jKflaOvzGQWnB+8dzXFGaGbDKMWqhiQhvjlhid5sN1N+Tm/QsUxOBvuvhdl xSKY6Kd77Sog4KaMfoGuYgsFeVfQ/Y7dhJ05jVYo45O6pPppg89xyKtwko0n7MK4HF8X O4ZXK6huc0nk+WNqDq8NEHNXIPmOWp5H6l/Yj9q3Wrjokc0No9ZnY0lMJfKlMxtZkjQV RWVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744036769; x=1744641569; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pxPRinaB0R9MRMHkqtzs6Jksu6ZEexxFz8Cu5WJ1Zw0=; b=sibwIZSB6H+rymMRWeLNfVBGVrlLCNXkpa33cBvNHoMTjMeBoD4xVYylW8RwhhfWhm e12BWL0MrzZNzKgnO/1LYoptkDT1hqwrMylzievi76z4cyamy+cAepLMNQSxAD5uWFfv TPGr7MXjrS29UDJjMHjEfVyE5ODjsTg53pmg87AkIEArqYsj0mFRqWMlh158skrARgCS RzA0wz/svdGbwSb3z3lUNG2/or9UHrd5Qpo9C3BJQE/Dyn1jEbuVnflJtYMHM9CVVThZ 53S2y0ys/b2NScnVJZ0vk75ExhWfafrqWVmJQy8nmbq+OLLNNywv3VnRzXCob0SgXFi4 T6/w== X-Forwarded-Encrypted: i=1; AJvYcCUS3xAEB1arx1C4y+foglZBa//r/L2hdrJDqKGURqOPs6j0TXWpSBVBp3gMtMnXqjZ6asWGOL0DGAc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8XOkTq0hFj85ap0H7fyWABV8Ru0rU3jt2SuANB3YY8ox2LKiB iHQWCfEaZQVy4BClnKHhzgT6Y63CW0kIHeamFkTPUg27ZONjDPmUO3PiVmcwcipyRAIRmbwreH5 2 X-Gm-Gg: ASbGncsdwJn4LF3wkX1MDeUz4EGHIkmQz8+C+tHZW/mi49l8WKtMAsxsFnfOfiZe/oz rMfiykD1bTYfG1enT9Uj5sir/U3f3vA3wSFRn9oZf4qhllTOqwHxvkNp+WmaT6rU79/CoNZQ2ed Ky7pEUXwtWsWFfK+aZhuODWw8x5QN06+V+noDvMM/tyEnrMdqqQo013845mTnxA2vL0T4ldxoD1 c5zlWf/iJEp/6wKpXwbU3rsB2iWT757cEVngjQX2wdXcEYDIC9POVjXjzQYwBBmC+6uImpHqG3K gGN1jCP7ikgtIYXNEU57Unzf/uoqtmrEZIn3DI3ROi08Wbj5Qe2XZC0a3Fg= X-Google-Smtp-Source: AGHT+IEubbxZPgQUSRZzvvQhBmDtFalBkcWkhDKsJzJ20didIoJnFHLspvjPaPuLm6u+H9tSSj/f+Q== X-Received: by 2002:a05:600c:1382:b0:43c:f8fc:f69a with SMTP id 5b1f17b1804b1-43ecf8231a8mr126309295e9.4.1744036769270; Mon, 07 Apr 2025 07:39:29 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:1122:cb29:d776:d906]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43ec16602bbsm135003705e9.9.2025.04.07.07.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 07:39:28 -0700 (PDT) From: Jerome Brunet Date: Mon, 07 Apr 2025 16:39:09 +0200 Subject: [PATCH v3 3/3] PCI: endpoint: pci-epf-vntb: simplify ctrl/spad space allocation Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-pci-ep-size-alignment-v3-3-865878e68cc8@baylibre.com> References: <20250407-pci-ep-size-alignment-v3-0-865878e68cc8@baylibre.com> In-Reply-To: <20250407-pci-ep-size-alignment-v3-0-865878e68cc8@baylibre.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Lorenzo Pieralisi , Jon Mason , Dave Jiang , Allen Hubbe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni Cc: Marek Vasut , Yoshihiro Shimoda , Yuya Hamamachi , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, ntb@lists.linux.dev, linux-nvme@lists.infradead.org, Jerome Brunet X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2649; i=jbrunet@baylibre.com; h=from:subject:message-id; bh=VMQRvj8CO60hVIlMMgdkTE1dtBACF+fNeO1bhBVnQsU=; b=owEBbQKS/ZANAwAKAeb8Dxw38tqFAcsmYgBn8+Ocp5qrU6t7BkdRqC40BGTRhG7GQXtWTrTgD yIlZpB1YGOJAjMEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZ/PjnAAKCRDm/A8cN/La hWRHD/9g//XvxSZqH7CmO0Os/k5ApJ/k9nXjmH7ZssT55T/YPBza5Ck1OyaluYJjja7C9k1gitK Wjln7OTMRKwA0VzH1g1UDleQkt+jb1NBdtHlx8jupKsX8zyjnDaZmZwl7jjNpRxaFw+Wjq8MUg1 TjpNZssf3Q4kG3iqg+sqziIgeUCk6Xi4WHBlqNolxkkqUSsSRf2KWk8tUBDA+EBPv+/psSmdfFC dBIjEtm7dsQoXpApCzIV1+myZh939mnlIPuh/trWJ3dIglJrl6XT5x9tBm6+Nq/cPRfLXHseEIP ncliq6apj8jXQMgKFD99eYT8ARDSrJoXhbXhHoHRMrZxmCCHCcsgFXcgovDYLsQWXQRwT7gO3mH wGW3a4D+6XUxWihlx8J7UJ2xthK8ZAstsSOdJUXwBkXui6lHUOr+euZFVK43ymcFqfxtqQT2hjR nOljtrKlt8MLWFPLORpH9PcYcdzp2lTTRgA3GBzMg9f4tB40N3x0oEUUXpRfWWMDLQFYzQ4J0ay hfC7zFLsq/XX6YZbAZwG30s+lL+dkmODzrVaBXC6o//nyL/U0ho7u26khB//KhdPuSPeohl/NZS YK2cDoltbNR4i94PvtU86XBOfMK+F2OsqAlsMja7w1OfMEgkZijdiePOiY9asNzKvoKZptEVXPc Anao+OnAuOocI/A== X-Developer-Key: i=jbrunet@baylibre.com; a=openpgp; fpr=F29F26CF27BAE1A9719AE6BDC3C92AAF3E60AED9 When allocating the shared ctrl/spad space, epf_ntb_config_spad_bar_alloc() should not try to handle the size quirks for underlying BAR, whether it is fixed size or alignment. This is already handled by pci_epf_alloc_space(). Also, when handling the alignment, this allocate more space than necessary. For example, with a spad size of 1024B and a ctrl size of 308B, the space necessary is 1332B. If the alignment is 1MB, epf_ntb_config_spad_bar_alloc() tries to allocate 2MB where 1MB would have been more than enough. Drop the handling of the BAR size quirks and let pci_epf_alloc_space() handle that. Just make sure the 32bits SPAD register are aligned on 32bits. Signed-off-by: Jerome Brunet --- drivers/pci/endpoint/functions/pci-epf-vntb.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c index 8f59a5b9b7adec2c05eebae71c6a246bc5a8e88c..bc4a9c7c4338db6cc89fa47de89dc704d0a03806 100644 --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c @@ -413,11 +413,9 @@ static void epf_ntb_config_spad_bar_free(struct epf_ntb *ntb) */ static int epf_ntb_config_spad_bar_alloc(struct epf_ntb *ntb) { - size_t align; enum pci_barno barno; struct epf_ntb_ctrl *ctrl; u32 spad_size, ctrl_size; - u64 size; struct pci_epf *epf = ntb->epf; struct device *dev = &epf->dev; u32 spad_count; @@ -427,31 +425,13 @@ static int epf_ntb_config_spad_bar_alloc(struct epf_ntb *ntb) epf->func_no, epf->vfunc_no); barno = ntb->epf_ntb_bar[BAR_CONFIG]; - size = epc_features->bar[barno].fixed_size; - align = epc_features->align; - - if ((!IS_ALIGNED(size, align))) - return -EINVAL; - spad_count = ntb->spad_count; - ctrl_size = sizeof(struct epf_ntb_ctrl); + ctrl_size = ALIGN(sizeof(struct epf_ntb_ctrl), sizeof(u32)); spad_size = 2 * spad_count * sizeof(u32); - if (!align) { - ctrl_size = roundup_pow_of_two(ctrl_size); - spad_size = roundup_pow_of_two(spad_size); - } else { - ctrl_size = ALIGN(ctrl_size, align); - spad_size = ALIGN(spad_size, align); - } - - if (!size) - size = ctrl_size + spad_size; - else if (size < ctrl_size + spad_size) - return -EINVAL; - - base = pci_epf_alloc_space(epf, size, barno, epc_features, 0); + base = pci_epf_alloc_space(epf, ctrl_size + spad_size, + barno, epc_features, 0); if (!base) { dev_err(dev, "Config/Status/SPAD alloc region fail\n"); return -ENOMEM;