From nobody Sun Feb 8 13:32:44 2026 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 759BB2147E0 for ; Fri, 4 Apr 2025 17:46:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743788797; cv=none; b=CARmCT0YN8R2YCquf6nleu+OVZfiX55NoOL0sSfhuF3tuhVO+fr+wTpgIvrHSEAjrr3uigCpJoMY+3oB0QwHpgU/pdYWmoL65vLcuwD1DR/WeX1gg478xRgRvW3n5LLb5unqVmkfOKFyA1uoDIoKYaUi8CUtq/4epNq2zqO4vck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743788797; c=relaxed/simple; bh=4uieBqT7gmN5Utt0O/2pT4/9I2ULrrNvfRrwQOFLCm4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UxpzLq+r7ehHmdCJ/4ecHuUHY2061vAa1Psu9/PmWu4zCtkYvITSAZ5UG/E9uYpGjgL+8lNnEWRW4xVHyr05i8SMQtymq3LKmsQGnSa4UfhhWOmrs35wvq5hdAKz1tg8QT2sQRPJ2d+NANICEKC4cX3tltc3uCvdqfVvy3Kjh6A= 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=WwYjcKWI; arc=none smtp.client-ip=209.85.221.45 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="WwYjcKWI" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-39ac8e7688aso1771161f8f.2 for ; Fri, 04 Apr 2025 10:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1743788794; x=1744393594; 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=60FugxO6v0YRFtzoey5lDeif30RhYzbYmC0Dvosg4Ck=; b=WwYjcKWIvim+3dQEEK2eQexu8qLbfCIezH3kWt7y2D4+Ym+ZUN2lfgVkMAXNQkx/yl 4CK1SUIZ5nOgcQ44vwALBidDSEiAwjtqxOFy46bdiewaqNOPZvuiWGioD1KLPwLD/Ehd j+XEAgx+Xascf8q5gi/kTErYOrHR8+NFK7hdRr15hyBOl+4mfr+EE5WKdGdtyGycZf2/ BnIIgSfNpuapCH/DxLhqtucpj50UE2RsV4eBtyRQnp4kazPUGDXd6IJeeDPzyNHu3LmJ BVWRWTF3TRVCF8XicO80ugwHOGyOh/fpmLvQiVueRePiWh8o47Y3G4PYah5cKerlGQ4Y Jq1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743788794; x=1744393594; 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=60FugxO6v0YRFtzoey5lDeif30RhYzbYmC0Dvosg4Ck=; b=AOebXB+Xo9vK1+6pHzn+a4i/uTO9AjSvOWvbi8rl6HuGyahnb4RlPY2nce3zio5iyQ E4AHuXFB1xVV3dgsdU4PpEkeXNRkWfND6NzO9TvPZ35dxzOD+Ljbzcv17Rz8abPIKutV JJe0MTkZMeTCwPLSzUaORPetMsdRWZriteRdme3611j/BO+3wo/+DhA0sVE2xk5ckVRS OX7LUZKMRBDPtsRfszOl5J3DfT+vgQ2G923Bq0WwAkRgajpIWOW3yb4OD4YO426JuyfD Ww7rr2izFLolwsN2ZsJU09zocDMIbZVd5wF9stHPIZFlxLlJMfSTdiqXVF9kIopQ/4FR zA3w== X-Forwarded-Encrypted: i=1; AJvYcCXHQeNK/BRAi3TiOI3MY918KAHDpe4FjoLzXUX9FonvB8RCMcqTilP/MCjO4J9gWMFb6beQMRKbu4824KM=@vger.kernel.org X-Gm-Message-State: AOJu0Yzv3+Njw8OEF2ijsWnvWomLfIhfgbmejxlly1iD4ivqA79hp/o0 Q7nrd9U6Sb7fiUp2cpMSSAGLJCXPbFKg5u1m8fvWyrcl7Z1vS6XDbi5VFy6+R28= X-Gm-Gg: ASbGncssPYAPwEB/SMxWwf/zhWl4T7dv6D7qlBdUr4KZjgd/ORoZgmnx6oCxmxXzRPQ DULVU5Col16L3BTzlkCer58JzyL2vjFLFprWF8ocFQDx4LhdT2jZexVRlAaD2tmG9mK/e0KMmGF FfsvNTxaIe0uvkKVc8tGvhAWX8/WqELV9A9PdraSAJa9e3eA87agn55tqftkxoAUYki4idy3uwg njE+kT9tedt0r8wfkLslTiZXi/LjCG1iSWBwSoOjX2+ZLUgiw0bx53rkdYbG127zwK7Qo60aqlI DHpXApal7rboNJtNyGOggCAneUUDr221uKHRuXICPNRIrWJDoJJ2XOR5rQ== X-Google-Smtp-Source: AGHT+IFceB1324JoXOWMIqxbwKQDL3IqddpAqcTL7wFdsVu4aneHN/xUo6VXTYzYA5DUcd8e7Y74kQ== X-Received: by 2002:a5d:5f8a:0:b0:399:7f2b:8531 with SMTP id ffacd0b85a97d-39d6fce113emr185504f8f.38.1743788793428; Fri, 04 Apr 2025 10:46:33 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:331:144d:74c3:a7a4]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-39c30226dfesm4939535f8f.97.2025.04.04.10.46.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Apr 2025 10:46:33 -0700 (PDT) From: Jerome Brunet Date: Fri, 04 Apr 2025 19:46:20 +0200 Subject: [PATCH v2 1/3] PCI: endpoint: add epc_feature argument for pci_epf_free_space() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250404-pci-ep-size-alignment-v2-1-c3a0db4cfc57@baylibre.com> References: <20250404-pci-ep-size-alignment-v2-0-c3a0db4cfc57@baylibre.com> In-Reply-To: <20250404-pci-ep-size-alignment-v2-0-c3a0db4cfc57@baylibre.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Lorenzo Pieralisi , Jon Mason , Dave Jiang , Allen Hubbe Cc: Marek Vasut , Yoshihiro Shimoda , Yuya Hamamachi , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, ntb@lists.linux.dev, Jerome Brunet X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5399; i=jbrunet@baylibre.com; h=from:subject:message-id; bh=4uieBqT7gmN5Utt0O/2pT4/9I2ULrrNvfRrwQOFLCm4=; b=owEBbQKS/ZANAwAKAeb8Dxw38tqFAcsmYgBn8Br1Q6kEuYoAQE/bmEcnQHkFE2CYtfsAuAcca fK2YBNaIfKJAjMEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZ/Aa9QAKCRDm/A8cN/La hYt9EACfZPJwbj3KH7gUvv+4V+47BZs/0lx6Idi+Pq0fdQy+NK0N16UVt3VfRIAeTxI9GAx99d9 dbZ0NR9HrfWiM31VeFXKUDGmT610XOmyc6uyR01lERr+6ubO09bNNf/k+6AT5i1wxDSS/jNAXCj Jc6ZsCfNNCzLjNpmTsb6HJx6WraeKMQTYmDx85FwC4ylh1tmw9Gsmfc8USnKvJAT0qeUcqLCDaf MIX8rm3pHX+94ugr2aNKNmRRhMnYXMJGkk8uzGVBdKgUt1pnz+VGjnsZKlVYcZj4iaQGLcrs7V6 aMVzJYhC+4JU1xhcSQTmHV4wZtf8UG4VR4NBNLJzJtvrdsyVMEm8WiDZvbABWygjh5sfKiHNhyZ Ah61cPG6xTfQvVC223MopGaXlaRTomeCr4asErOFDzedE2IMyIIlG2Kt7Lqe2u3dCNgOb6lUZaD ghUUXbmqJTGYiGzlOHaH6Wy3hhwwz3GSQS1TlHmAnDe3LaXxaM7gMqgekdUUbcQIVdqUJqZFnoL E6tKOYSn15e5XWs6wCtVDt+gxgCxixkB3CQPY8FLI5c0BeLIjAHPRKXavNEShvKtzg0XgfP6T3O GgeQck/qdD3auhtDM+mYZkB8unVYkPt0tBBlY96abvrHCxhBsdKc3Jkzje4vlw4gzhGcE+jCqyN 0GBxYDbFx6Wm4cA== 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/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 + 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-ntb.c b/drivers/pci/end= point/functions/pci-epf-ntb.c index e01a98e74d211174db3075c20457a3183f37e0a5..44775c41c10b90a56b1167f3f38= 69a60c686cf9e 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 =3D ntb->epc[type]; barno =3D 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); } } =20 diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/en= dpoint/functions/pci-epf-test.c index 50eb4106369f41afa00ed3ae58c84922e0a49e51..8d5df47967226e1f02444e8d45f= 7aad1394afd04 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] =3D 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; =20 pci_epf_free_space(epf, epf_test->reg[bar], bar, + epf_test->epc_features, PRIMARY_INTERFACE); epf_test->reg[bar] =3D NULL; } diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/en= dpoint/functions/pci-epf-vntb.c index 874cb097b093ae645bbc4bf3c9d28ca812d7689d..8f59a5b9b7adec2c05eebae71c6= a246bc5a8e88c 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_nt= b *ntb) */ static void epf_ntb_config_spad_bar_free(struct epf_ntb *ntb) { + const struct pci_epc_features *epc_features; enum pci_barno barno; =20 + epc_features =3D pci_epc_get_features(ntb->epf->epc, + ntb->epf->func_no, + ntb->epf->vfunc_no); + barno =3D 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); } =20 /** @@ -557,7 +562,7 @@ static int epf_ntb_db_bar_init(struct epf_ntb *ntb) return ret; =20 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; } =20 @@ -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; =20 + epc_features =3D pci_epc_get_features(ntb->epf->epc, + ntb->epf->func_no, + ntb->epf->vfunc_no); + barno =3D 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..b7deb0ee1760b23a24f49abf3ba= f53ea2f273476 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 secondar= y EPC * * Invoke to free the allocated PCI EPF register space. */ void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno ba= r, + 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..d2d1c60fd5e0487b25aad51fee1= b30554f630557 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 s= ize, 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 ba= r, + 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); --=20 2.47.2 From nobody Sun Feb 8 13:32:44 2026 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 22C211494A6 for ; Fri, 4 Apr 2025 17:46:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743788798; cv=none; b=KtwZLHLx8ejsUyPYnoGMXGJDaW37HNpWLiJi2xejTp2PEMNX1xjkrKzu28kgE4GF6uXLKyLs3BtezP5ausFa7qccehGfgNB8WwyVpBW10MEXlG1rXMn1LT1L6ivLThdLGRRgx/KSplN8VmXvKS1uM0Cuw0NpIiKxtTRSmwkIFt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743788798; c=relaxed/simple; bh=n0KkujYCmFsi6TCmOtVdMu0bbfrL6UkgnMn4aw3JxJA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RTeAxTMzSZ6n/mMSzen1ldygNLe97lq9YCcCwp58xQB6p6WxVHR0mXTlm5Jdz9e5gN5sz4tu2L9FGxXgmJy7uG/WI65QHos3yRLDIaLq969jIInDMZWuAHJppwKFUCUMwscUT5fW2mOBpuBUS7bK5BSs/Ofv/MJlK+BObh3dTqI= 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=BMoSoKJU; arc=none smtp.client-ip=209.85.221.44 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="BMoSoKJU" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-39c14016868so2020335f8f.1 for ; Fri, 04 Apr 2025 10:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1743788794; x=1744393594; 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=BMoSoKJUykjQ5WSRyzd8htirdiEK14dt3XvqFsw9KyimfGSvmKgWqZ/dkMJgt4Lsyd A1s5iKJxukguw43AmboqYamrmD9SL4KeHSoTpaMryww/opnqBrCmnghHjbsP+9vu1bhX jRlcGWIyRTon2LZifHqtWdWslKYw+UseBhNHteFZCnWs/56D/7Fwx+VguxUH3rUF03Fa IEL6sooOKYuiJtO13US4u9VJGc40yvHkgJ5jGWR3Ms2gtyknbCzVpGssZZ9kHlF1TyQu Dv6o2nFUFzcdabqZgxpNSzkU27fXrJH7d01kozqEI+cqMhmN/JXYKuh/mn1M509zS8+T QcRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743788794; x=1744393594; 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=UUH1YUe4PEtdSsDX1ICw5HtQ0Rq2qkp7Dlk6qIbzOneU7VwdjxRDf/plJpYsTwvMY9 zY0M/jIMkT37LlXzDI6MewfS4IiTwAiOLpJu9wBcNEk6ykpnclvzpXAkGIhtOX8y2Nri LixRFcsd59ZKQSrLV3XrXVVYnZzlcXMtLh2X6xrWKNY9bWY1V1VDWQ+U8CS4xiZyYw/S rZOc0oySgjUTFIt5jFN1EEl8rLICp/TPS7b1ApG3e02QjXGH7FM1dhD+RhxQFsHiRWVJ hew7kA8OFK3QGLZoqaPvqiZQW+TrRcbiQKxeK5GHoXUmLmWYECWa2thZ4b/FdwOrGsdr 0J/Q== X-Forwarded-Encrypted: i=1; AJvYcCVHsP0DlVQQ2xRbQh+fmxWwzckL/goEZ/kQfx0pZE6zBcOBoP49sYGn0mRfzTMbCfBkX72kWGNx6doClfU=@vger.kernel.org X-Gm-Message-State: AOJu0YxIttkAZkwAyALbHIdRvaB0gMSkELlbEamxIAJBEErQehG2sGKw SdINW/DGDcVyL/C7uMZSxdJrdVyQFRvAxY99nXgT4JhstsM1Lt80iyEmA9INZv0= X-Gm-Gg: ASbGncuNuWdvMziHv0nsp/pOz1IdTcIegedc2DSJTFKH/Hc28tAToeUiU8KjOLL7xVs tRfLw6hWPby99y7RPEzNFS2q/Qg5l5DDOUcaPyXoDxOUaOjWmD9M+sH0HRye8vd1eWn0zvShM0g Ii2fGIny8JOanmAb6Hm/GGiwtpCKv8WJNXAw/QVliEccHsdEOgpNEAI0ZwkY4n4EPPzTk1yr/NQ 2s/Zv5wB+9LKl5YSfkFNLTZFO4ePuSYwzfA9LdSB05qdqpjnxDiEQL6eHr/qwSKP4bQEa54Sow7 iABNBm1ZXxauPhqYtVF/hyn0D49iUrGL5a0JsXfdUWYmnZ3vcChQe1sAew== X-Google-Smtp-Source: AGHT+IEmApi11yA6tOT0eemVOGBTN2LnrWT3UdKLD1oWXnbRDDDJhQjzlClW4YROw282/g4Zg8Ot9A== X-Received: by 2002:a05:6000:290a:b0:391:41c9:7a87 with SMTP id ffacd0b85a97d-39d14662e92mr3389503f8f.51.1743788794420; Fri, 04 Apr 2025 10:46:34 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:331:144d:74c3:a7a4]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-39c30226dfesm4939535f8f.97.2025.04.04.10.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Apr 2025 10:46:34 -0700 (PDT) From: Jerome Brunet Date: Fri, 04 Apr 2025 19:46:21 +0200 Subject: [PATCH v2 2/3] PCI: endpoint: improve fixed_size bar handling when allocating space Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250404-pci-ep-size-alignment-v2-2-c3a0db4cfc57@baylibre.com> References: <20250404-pci-ep-size-alignment-v2-0-c3a0db4cfc57@baylibre.com> In-Reply-To: <20250404-pci-ep-size-alignment-v2-0-c3a0db4cfc57@baylibre.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Lorenzo Pieralisi , Jon Mason , Dave Jiang , Allen Hubbe Cc: Marek Vasut , Yoshihiro Shimoda , Yuya Hamamachi , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, ntb@lists.linux.dev, 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/ZANAwAKAeb8Dxw38tqFAcsmYgBn8Br1H2IfezMlXrBbIxRkNQ3j+kTXSTGIJoiCl BJLVqqhDXiJAjMEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZ/Aa9QAKCRDm/A8cN/La hbZnEACJzgxE9lKIX+NE+nV0iDTm/dKMyc9oMEMR7lXtubsne2ToqmweqeTyZ9sN7Ce+uRFA8SO b+32pA6IRIM3ZjjUcmYhG7ampJT3NowyeJUYVwHaAxUOuX3fPbPL5e28cRYLmMuucKj5O7QNwbI 4dsui7riQUQMOD+zEYSTK3q0HTOc/VVFqSiDosRLVFit8fLfj42jbslafJuqP5DW0514nU1T1b5 Z3fo4UB35RDZv3wRh3SzclMAzDs9cWD6XZSNOtctlN8uGx4wMMD1MD4R0Wnb+nqBlH04awxi4Xs j7PhQHtzCB38TvCJWiXb7BDHCg/H6stmAuTl4I7lmqUyI7YN71yC6kYD8UTpq3qPQl3GgEgChPN bdWlJQiid0+nH87x2lTEOeQWqI6pXFMyYu/Y/LiXLYNLxWcN/XxG6YvRy+y78TRY3XRzLHKkFw2 HbwUX4KhLgmgnLKZYK3jft6zqDJHvpX5Zc/rk73yCo2iPCSQNpM4FjQvJ5WhcHlbMwhCDP90I4/ HjFhT6t3ynCFcCfWG5h6xEILzloLvfAxALfIdT1u4YLGW+AVBbBYkfbhQUDXBKpJtVEbPKZVMPE DJnct5Ml6aKHyxZQA9+yw9e0nbae2XNd13vVFAQuByhwx/BLljKLlcTFp370RVzlcbC7DIbC9WG Q85YLg7u/YS3QiA== 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 b= uffers 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..fb902b751e1c965c902c5199d57= 969ae0a757c2e 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; =20 if (!addr) return; @@ -237,9 +238,12 @@ void pci_epf_free_space(struct pci_epf *epf, void *add= r, enum pci_barno bar, epf_bar =3D epf->sec_epc_bar; } =20 + size =3D epf_bar[bar].size; + if (epc_features->align) + size =3D ALIGN(size, epc_features->align); + dev =3D 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); =20 epf_bar[bar].phys_addr =3D 0; epf_bar[bar].addr =3D NULL; @@ -266,7 +270,7 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t s= ize, enum pci_barno bar, enum pci_epc_interface_type type) { u64 bar_fixed_size =3D epc_features->bar[bar].fixed_size; - size_t align =3D epc_features->align; + size_t aligned_size, align =3D 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 =3D bar_fixed_size; + } else { + /* BAR size must be power of two */ + size =3D roundup_pow_of_two(size); } =20 - if (align) - size =3D ALIGN(size, align); - else - size =3D 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 =3D align ? ALIGN(size, align) : size; =20 if (type =3D=3D PRIMARY_INTERFACE) { epc =3D epf->epc; @@ -303,7 +312,7 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t s= ize, enum pci_barno bar, } =20 dev =3D epc->dev.parent; - space =3D dma_alloc_coherent(dev, size, &phys_addr, GFP_KERNEL); + space =3D dma_alloc_coherent(dev, aligned_size, &phys_addr, GFP_KERNEL); if (!space) { dev_err(dev, "failed to allocate mem space\n"); return NULL; --=20 2.47.2 From nobody Sun Feb 8 13:32:44 2026 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 085562192F5 for ; Fri, 4 Apr 2025 17:46:36 +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=1743788799; cv=none; b=skUpavUv0hUJByvbReaJk4kT7MOwdLNEFcOnjcYKrWwarRpl/Y6mbJ3md4ncjcOvt9iqd8T01s6+6IZ67NbBsvf66hIxlFsgvUM8MC77Jt29b/UT8/Bc9CiVhKcRndc2JTibtY+VoXiNFui/zzF8KfBbW1ibIRpjzBUMhzqJdF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743788799; c=relaxed/simple; bh=VMQRvj8CO60hVIlMMgdkTE1dtBACF+fNeO1bhBVnQsU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WbcH1FS+Z+lX3r4pFoFfxKk0xj9vwhLXZOp1VEfBg+dtu1mTgdC8FUqqSVKagPlrtH1vBs1G5RHQzzqE2paj1L+jkOEIhRvOYIsl58dcSi9dK8zSlO946sAzlXOYKMnkUj7K8ks+F1BLqMoqESvKu1Z2m6Cn1MRktH0UbdyuyZ8= 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=ZP/p8dXw; 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="ZP/p8dXw" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-39c0dfba946so1509223f8f.3 for ; Fri, 04 Apr 2025 10:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1743788795; x=1744393595; 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=ZP/p8dXw58qJXYdRhzm8N6Jb+79SD6nldnsyJ5wM4600xOtsQPalyW6vUM4J/OEaBc THc74vAgMrPMznB0emXJID/aQSQJqHFVS1bKXRYVoYYW8sMrTa+mDB/2yEYstgrbgCpi R6dWtiWZbQvJzECr7GTFO+OqEX5914DzXg4tQdqQJGTLWrJYd8XzRHFZBegfDE972i9w ZIS0yYRyArZXneXT3UtjKK5UQFrCsSw0chmzSE8NLg6oa3ALBEgqjlEQO/K5nmANdZcZ V4yalWGyw4TtbcSdV/9+EcsrAFwjMSdI57xOw8c7lD3i3rNLplS9NQhWDfueL2XKZVvl EgWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743788795; x=1744393595; 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=Jpeg0AhCTxUdmEJTfjtvF2fLT4EIdq8+2JjzXlP85bXPonTaHYHCQAHSY4L7/sel8G 5exObBZxLCntmskAY0XA9RKnSxzC1MkwbDyakoUl/2P5SpH0qhTY9i6o0jSebS787UMa GVm8p+7Wsa+xsiNXl4sGAixez1n/GfbcxQwVpOa0IILpEKPUV6GW6ogKouykQFDPgDuG 9B1IgDFZyS71CSWFycsveaKcGm1jemQSzEJMSRByeumLyagZwm/oyhT5Ugo3EdT6lrPC hqOtzyQWLyaFxNE02s+4VnywYtqHlTsmKF94Y8WXy4OO6iSYuNqKr1iLwmZwmXcWCLOC uAqw== X-Forwarded-Encrypted: i=1; AJvYcCW4FXwUjzOZfGETKz2oczNcwq88biaJbqhtMyXT+/Mwt0+423/T4T4fSEmdShSOPDjYF2p+6K+wojSGlWY=@vger.kernel.org X-Gm-Message-State: AOJu0Ywvcz4tFwZb+UTzF0t5qlOUl3yB0CuAKEecR8cRjXJDACa2wdHL rkKELKpoOyFmLbanH+tMkkZ5h3+jmgX30vt/3yfuZk32pxLrk88bHYS+7Vi0B7Q= X-Gm-Gg: ASbGncu7JzSsrsfoG/gZe3xLz6et+3oZyJGjHv/jP4NqOM62xEXNhTGp6LUH18a2I6n KlMsbBJG5rc9eUZlRoMjf+k6VoMYKhZxqbSz/Hz9Nw14eIMfKQTTPHALblaXPyQhR3bj63LNyUp LVbeXQ1MYchaH/vgC09OHwLSYokInOBMtodrE4NXPDGXch/3pqPtwEICJiM2Yk4j88IeFiMiYp+ gtAh3nvLRF9PthmrzMd9QdSKhjEcoyZZMbfOn9y0YG4TndmXA65WpEKSSpTHHbC4kS4DCU7Kljo ApB/+MSNmvQ6mZfL4phPHjarrtOvJ8YeLZx6QuLX1P0ROzFjIdsP1vG92csBHY4QlBsL X-Google-Smtp-Source: AGHT+IGJK67GjTDKDpj5bH038uXsv6Y5SZCtrTzwfFsjB58QOdWQqxfjOKhYa5MkwP/MU+TWVGqe2w== X-Received: by 2002:a05:6000:270e:b0:39c:1257:c96c with SMTP id ffacd0b85a97d-39cba93f966mr3020079f8f.56.1743788795236; Fri, 04 Apr 2025 10:46:35 -0700 (PDT) Received: from toaster.baylibre.com ([2a01:e0a:3c5:5fb1:331:144d:74c3:a7a4]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-39c30226dfesm4939535f8f.97.2025.04.04.10.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Apr 2025 10:46:34 -0700 (PDT) From: Jerome Brunet Date: Fri, 04 Apr 2025 19:46:22 +0200 Subject: [PATCH v2 3/3] PCI: endpoint: pci-epf-vntb: simplify ctrl/spad space allocation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250404-pci-ep-size-alignment-v2-3-c3a0db4cfc57@baylibre.com> References: <20250404-pci-ep-size-alignment-v2-0-c3a0db4cfc57@baylibre.com> In-Reply-To: <20250404-pci-ep-size-alignment-v2-0-c3a0db4cfc57@baylibre.com> To: Manivannan Sadhasivam , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Lorenzo Pieralisi , Jon Mason , Dave Jiang , Allen Hubbe Cc: Marek Vasut , Yoshihiro Shimoda , Yuya Hamamachi , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, ntb@lists.linux.dev, 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/ZANAwAKAeb8Dxw38tqFAcsmYgBn8Br21+RpEyu7VflBJ+7DQPDTHDsNR/iu152/c AfIb7ODPZ2JAjMEAAEKAB0WIQT04VmuGPP1bV8btxvm/A8cN/LahQUCZ/Aa9gAKCRDm/A8cN/La haVOD/94gKh4Rwrb9XZS7wgvtm4xpuUyG+eCwYuUMEyNfOou0meG7+SOlSJhtvZ1NsV6kD7V4HB ngGvBJwsU0P8WC5cRU9CLVrc8i3A61jPsLvNnhVrJ77uvSg2C0HRqgHw15xyRsvIZArIb8CU040 A5JupzLwaZDYkREjQjLEBNqAuUVCwD1MT3sm61cZFKdXJoxqRr67QoUoZ10GzQTv/X28JQL5WeD 1IAy6A3fkHtphYdtl1vFCY5PDeijD0KzoIycqy3dDl0gFiMFKYCVBCIsOXI8ms25+GlwwlR7jmr KmXHh8zMIoCtoVTRXR5zeCq1lqvi/V4m7MFSpW7uC9iaTFfFYEmPDFxK2xDemp8L4++PHROmJ5u 7CPXSakNhZVd9WGCVQEZkifF5j1ciFeaeBmWbCoBFtVHjzioGu0Ss+9cTluMndT1YxZwhHJF9cr oHScr42ldiZkUIDW1DkshspaPEpv3+Y1TSIsPrvN+hztJzk+OcKTp9RlR3Y4X6f2JlAk7gBPUml wkrZh30XKCKDfZAQ8DYmIRGV34JTkX7GOPSSsQrfp5SOLZJ7XvcIEqTbdf+kX/GD6lHLtTfiTzN ZmBFc5ZcRokYQuO2ciUIO9fsoRZpg+CGU25E0E+08pGb9b45MlAvo8mc3JWcE6ql2TykQ9kl+PZ G6+yE31B/oorRXg== 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/en= dpoint/functions/pci-epf-vntb.c index 8f59a5b9b7adec2c05eebae71c6a246bc5a8e88c..bc4a9c7c4338db6cc89fa47de89= dc704d0a03806 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_nt= b *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 =3D ntb->epf; struct device *dev =3D &epf->dev; u32 spad_count; @@ -427,31 +425,13 @@ static int epf_ntb_config_spad_bar_alloc(struct epf_n= tb *ntb) epf->func_no, epf->vfunc_no); barno =3D ntb->epf_ntb_bar[BAR_CONFIG]; - size =3D epc_features->bar[barno].fixed_size; - align =3D epc_features->align; - - if ((!IS_ALIGNED(size, align))) - return -EINVAL; - spad_count =3D ntb->spad_count; =20 - ctrl_size =3D sizeof(struct epf_ntb_ctrl); + ctrl_size =3D ALIGN(sizeof(struct epf_ntb_ctrl), sizeof(u32)); spad_size =3D 2 * spad_count * sizeof(u32); =20 - if (!align) { - ctrl_size =3D roundup_pow_of_two(ctrl_size); - spad_size =3D roundup_pow_of_two(spad_size); - } else { - ctrl_size =3D ALIGN(ctrl_size, align); - spad_size =3D ALIGN(spad_size, align); - } - - if (!size) - size =3D ctrl_size + spad_size; - else if (size < ctrl_size + spad_size) - return -EINVAL; - - base =3D pci_epf_alloc_space(epf, size, barno, epc_features, 0); + base =3D 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; --=20 2.47.2