From patchwork Fri Apr 4 17:46:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 14038697 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 690DF20A5F1 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=1743788797; cv=none; b=mORd90UHFC+A6TPPLsPoEl9NK+skJy8VLFScAH4B6K0Gpp8AkFwV8J6A5yGHGmnQZ+lDJXednu4oTQvfrbmi2aCqfC/LptFu2N2xLJjAdIxAQjZi9gOZM7Zlhj2VMqB1ppkUa1mDPrDy85x+HXRPtblUDqYUix/TMSICa7NA2gQ= 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.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="WwYjcKWI" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-39ac8e7688aso1771159f8f.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=JGuUHRRWeJlCb4VdnmVCIhwsABd0oKnOnP8A2OeVeQdLqCwirUnaWs/Xm6eePU6iE9 5TqbgnacsoWVQjuQUwZhc/0gmm/0UYLsQeo5ZGGrXiOKQNRh3e/6IhswfvqYk0Pkuats XXDlgShrUb2cYcvbUtwYDC3RXpYwMpRTEu/7VCns4wc51zNbqstaJXiDY0fJcpxSSrVw JqqIqVfgkExX92YyAvADFFhzaR1pbvHvy90pm1KuAyxb1MDOCvD9cV68pVpqdRWAMw3y H3shxJ8ojyBR/W4jF7TCz47om9TR0OEv4hD5zPjQ954RIIF0Ob4rkkFH8TQNhtIDxQP2 KGQQ== X-Forwarded-Encrypted: i=1; AJvYcCUQF/P9lR4eQM5/8MWwV+nCLukFTsv2BjX04IbUJH5PZSknxJA0cqkNabE2FgYncbh2NvFOb1J7PqE=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8Ru0WeACIGnH1EJhU7I2jlSTeXAoLhnVEvbhP1enrH4udJTFv YqDTKYi/cdbs2l+ds0FKbgELeH6nf/CTYBwmMPDRLWZpuzeuqpgt9BmpY15nmb8= X-Gm-Gg: ASbGncsnfWfe+srERhsv6eXbcZRqfW1TbFCyVCB20RxcU4n8ALIKhmvRAhOV+/KPCNK McN4vPrxyc/wACjvukQ/10AdtTpXjPdsBEawvxD4emliW98dbrpDr+1j3QS8/eQzqVYNeu4sehU tawftNJWmDEuFlAt9kyWsMJ8kkSIaqRGP7JJOUPYY7EaJRynfbd5WHDSMHeEig43e5dkLZfko3V gpZtSG2SbL0n7EkSpoMcl3T8ZBimH1gWsKbNs7rCuDOhRl1mvY8a+oxAXx9fd6s2rKOKtqhEgyR 5sk/7EWoUE/r9yA1MiO2KxF0nuVSQcR7kwYdWfJDylCRWOeyORW/SQmLvg== 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-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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?Krzy?= =?utf-8?q?sztof_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/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 Fri Apr 4 17:46:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 14038698 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 5318B215040 for ; Fri, 4 Apr 2025 17:46:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743788798; cv=none; b=LZiROttsmKZupgmnYJ8Tt3jZZJbNUqzn7fbDd3kusDc5qL730+fQu+DdJH9TB3jAOEeWx8m45SJ5PUzm9KOiaOiW2PD5/i0VA20ZL+w4vtgfjFlfimguxZrvKDSusBIrV9oKtjst15zrMQoKcF9qsMlnvFvj8MmuNVqxIYtMsA4= 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.48 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-f48.google.com with SMTP id ffacd0b85a97d-39ac9aea656so2069115f8f.3 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=Ci/ndYxQRzeZJiFWDHm7PvzX1IBIlSXHZ0ao1UYz4gIZ7rDeRvkeKxifJ7Sksvw48e D0wvLP/KKYtkWa1ZxF0Q4ALBwxOaCEIq6a/ntWGBHj5hAvf9ZP1/N18cOKny6y/2CAph yVbobAqffpQW3qaRZGf9qYWfA1nl/xASpigOZ2DZe/9MHE9FJMR65B/Z1LgcTi1IopDD dQ1ZGJOSzliYtDlCe6axszZqBSjmtMsly/6dojXqSLMtQOI0nO9vjcy5t9dicDdE+8AL 8rOfLXziUEf/ifxIUh2Hv4IkIi3leissg+LdgHb9hftDs9Gpp6hFcvIh5J7LAJPAs8+j jALA== X-Forwarded-Encrypted: i=1; AJvYcCXSxhb+4+e9l4+AV5G5SSCJn5yVS+aZrNdoBERogtWxno3tSovhW93yFDEEyfXHzU+JirdgCWuJWK4=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5WssW86gAfXiII1+KOHPU9JDMCjVMNEPQf7ThE666IqNOz8Zm TD4hkBiVueUmtNaiJG8yCPfOm7gUYGaJptMISWDzhBivcawcNwNotv9XMuTP2Tk= X-Gm-Gg: ASbGncudCM3bDbVlu77gQSQngDBWmSLIVQ8Xh+A4JXa+ffA8iwhbQi2Ck0o162pzUbu 8Uk1slXnTQMVOyi8INDzLcWRS8R0GtuWVG/5wlsXg+vutx6z83wTSU1RjikKiS7ESwT8/9OqUY5 tuMvESDNLIyyhizG4lACLzhXBzobO6tJyF5wlNq2qqWKGdE1AquoWpjHcMJV9OvGf6JPRSQvBQq gm25UU74DMzJy5PX3Z3Yp6mEqwlbwD05TRBCMsOSrJMgjue1JDJdzaB1EKJcu5gvhE4QEBK9etM F6jKUgdhF3/YtxJhMflzedCWJ1Ab599rh+RG3LRpBVM1m62nfGMs0wbYhg== 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-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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?Krzy?= =?utf-8?q?sztof_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 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 Fri Apr 4 17:46:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 14038699 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 033E0215060 for ; Fri, 4 Apr 2025 17:46:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743788798; cv=none; b=RFJynsZ17rmVabOWpQ5tEZEmhjcC0EW++aZFgNwiFVouZJSqMZCWWz58m3Zh0dIXZ0Heb7DwzKJ2swPxfJtSfjgqWqS7TUrhCKb7vDjIqPukRwWmsJu8hjEpPSszEg12WWbgVnyadWS7Tws4QpEYrCADpfz7KXbVFko1gk0GFLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743788798; c=relaxed/simple; bh=VMQRvj8CO60hVIlMMgdkTE1dtBACF+fNeO1bhBVnQsU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VfjtQAnHEQAayfRhBymFicSXfjj3k5GlkRvphLWZFqey4oGDf6270rFvcOkFKHHXPpLBJ5HQPJe/Uzg8fcRUD33NMnEA1A1v3OesOIAR44wYXb30dm527eXnUpMyKST1PDXxrShS6iAyfLbx08KSQX4LplEO4gh+S8HbEve19rk= 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.50 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-f50.google.com with SMTP id ffacd0b85a97d-39c0dfba946so1509224f8f.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=j/gdOkE3AvIcxQF/T+dwMm/dSbIphQiX9lQxmlUeOlW4Zah0U2OXFpjmsFXE7XZai8 mg6D0nvE6XdZ5c59LrNAmrl8SFihM5Igz/K1cZbbm+8eemqpITksFDQtDwzFQ23Rhx9r 6o9igBxmPWaLEnXOpn1cStFfi+h58RFoFDkApGU/2k1mWWKKe4Eny39I7CuvwaLXdJkf A+9YT9r5hgNgpf/wuBe/1LAxUxJctMnViErXhDiKqp3SMpCVz5gnwzzEXUI7plGw58xu KjEYD8jADjCureJX5yGBHy9ImXM3GeJKWvgey5JQlD2S4fdbzLxCuJcfZGKoF0NOD9mA rVeQ== X-Forwarded-Encrypted: i=1; AJvYcCWUCg5YQBD/g6Gx0JOzukUDmz0c8r9pJRVjdFWA/reYZrVsk4TLKYgwit/gY+O9cKK47E/Jy4z1hhE=@vger.kernel.org X-Gm-Message-State: AOJu0YyC3PzDoaPKTkyhYKtnBeqC1LpxZxVQ1P/GePlqXeuLmVQybhgz Lr5p56YmYC9Q8V+aHoh2ZMJkzwt+H16cBMj6b4gvx1RvL0J9KeMstq6JgpMSH6k= X-Gm-Gg: ASbGnctzQKKOEmbHTVN5Rwi0Qa44lbe5DjprMB7v3d4fYOH8bSjgQp0DGNtroARRCtn PjtywyP9OywIrozRqJoEOovRS/+2f5qHLH1jl3bmQbMPDPZYhfvH989ItPhVlRUFax1US3jUum6 ePhTGlIhA1+J9SyWedyJUGbP9gyvq7CrBZhbaUE6mdYo+u5Al66OVoyy5mnO0HcwA63aIkSyb3O 658r1N9Z6LYiu0P1LcahjetAMOT7qJBZq4AaTELByOIJg38hmOgjsiHK2hvkA9jiRr7/YRfkkNY Ah23elNImkg+9pkNvHm+Gw6VIaPsm9LCZEU0XE9EUyuRzhsHw2EKTy9VpxV6bFH6Qn3t 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-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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?Krzy?= =?utf-8?q?sztof_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/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;