From nobody Wed Dec 17 19:22:44 2025 Received: from pdx-out-006.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-006.esa.us-west-2.outbound.mail-perimeter.amazon.com [52.26.1.71]) (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 A35FD1F63CD; Fri, 3 Oct 2025 09:05:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.26.1.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759482339; cv=none; b=tIO3MRCpgJeeZn2LmN4j0cyOUr2CvbpOmFjVgojqvbJpum/GmlhXIiS5u0spFyAmzP6IOGoARRt+96U6Tt69HVSOCE8Q76HmnfSKJIxsuCNAZgEStDHACKinx67c2KglOSlTZFNV3hjnY0DOiLuAz3Zd1dAOyGWy38OgJthn4m8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759482339; c=relaxed/simple; bh=slLWGxQfls1x1S/FVs4FN7heJzZTdg6FH91JCzX11E8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ee91qfiJ7HxeN1QYWHY7tfWwR2B6/6NnHKWOgzA4dGiZuxBhq7K4uaD2EXUlZJZxIsk9hX7PHDUOiz0BBi3RbLaipXvfLB00+1g+R5P1Uc0aN7PH6Xn+pOxVRSJZ3+nk4JUN533oiTOsneDoh2zNmU63W83pAucMbBl8+MyKYac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b=qOKnudwI; arc=none smtp.client-ip=52.26.1.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b="qOKnudwI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1759482337; x=1791018337; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tn0GQRVzT5fKEu1tgXMFMDyjYjbCRfljUqvSP9velpg=; b=qOKnudwIPrdDIUOAh5v4VWsBOS4Hj/o4HIZYD2ZwvvRlHVteHuaimq7Y ymaJ6Ryra6kk5FPwOwcEHSpwL2orjKA3i8364sEa1au7k3JdPl+VYXX9k 6INyBrT2OsYafJ1kbMO+sS4+outWCuLplZHV/6xNXILPcw1yuPm8OLD9j jRvDCAkpSCxT1WFs4rCdM1PeKqWF50PLtYp1GHeg8tkFc/PU2ouKkJMJR Rm9fUjPPmj3rPrVSFPq4jxFcY+M6N28YrTlHYqLR6FrQhY9q+mNa6cfq7 UCmRVBLB3HNQwvvUdWX2odTyKPoeGaNrjw/WX/C+Wrn8NCjHholGIVWbS A==; X-CSE-ConnectionGUID: Dtu+UvqTT5SZjS6EPSHS9g== X-CSE-MsgGUID: zmyYvmr+Q7KbR3Erf9NvWw== X-IronPort-AV: E=Sophos;i="6.18,281,1751241600"; d="scan'208";a="4212893" Received: from ip-10-5-9-48.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.9.48]) by internal-pdx-out-006.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2025 09:05:37 +0000 Received: from EX19MTAUWC002.ant.amazon.com [10.0.7.35:44698] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.25.156:2525] with esmtp (Farcaster) id 9215df3b-2cb7-42da-a9b3-e947d8efb987; Fri, 3 Oct 2025 09:05:37 +0000 (UTC) X-Farcaster-Flow-ID: 9215df3b-2cb7-42da-a9b3-e947d8efb987 Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Fri, 3 Oct 2025 09:05:36 +0000 Received: from dev-dsk-epetron-1c-1d4d9719.eu-west-1.amazon.com (10.253.109.105) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Fri, 3 Oct 2025 09:05:33 +0000 From: Evangelos Petrongonas To: Bjorn Helgaas , Alex Williamson , "Rafael J . Wysocki" , "Len Brown" CC: Evangelos Petrongonas , Pasha Tatashin , David Matlack , "Vipin Sharma" , Chris Li , Jason Miu , Pratyush Yadav , "Stanislav Spassov" , , , , Subject: [RFC PATCH 10/13] pci: pcsc: Use contiguous pages for the cache data Date: Fri, 3 Oct 2025 09:00:46 +0000 Message-ID: <914285f708739992f14c16fb3be336c6e8afed52.1759312886.git.epetron@amazon.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D039UWB001.ant.amazon.com (10.13.138.119) To EX19D001UWA001.ant.amazon.com (10.13.138.214) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch refactors PCSC to use a single contiguous memory block for all per-device data. This improves memory allocation efficiency. This is a preparatory step for KHO persistence support, as it is easier to manipulate physically continuous pages. Signed-off-by: Evangelos Petrongonas --- drivers/pci/pcsc.c | 28 ++++++++++++++++++++++++---- include/linux/pcsc.h | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pcsc.c b/drivers/pci/pcsc.c index 304239b7ff8a..18d508f76649 100644 --- a/drivers/pci/pcsc.c +++ b/drivers/pci/pcsc.c @@ -725,6 +725,7 @@ int pcsc_add_device(struct pci_dev *dev) { struct pcsc_node *node; struct pci_bus *bus; + size_t data_size; =20 if (WARN_ON(!dev)) return -EINVAL; @@ -741,12 +742,27 @@ int pcsc_add_device(struct pci_dev *dev) * nodes for these devices, as it simplifies the code flow */ if (dev->hdr_type =3D=3D PCI_HEADER_TYPE_NORMAL) { - dev->pcsc->cfg_space =3D kzalloc(PCSC_CFG_SPC_SIZE, GFP_KERNEL); - if (!dev->pcsc->cfg_space) + /* Allocate contiguous, page aligned data block. This will be + * needed for persisting the data with KHO. + */ + data_size =3D sizeof(struct pcsc_data); + + dev->pcsc->data =3D + (struct pcsc_data *)__get_free_pages( + GFP_KERNEL | __GFP_ZERO, get_order(data_size)); + if (!dev->pcsc->data) + goto err_free_node; =20 + dev->pcsc->cachable_bitmask =3D dev->pcsc->data->cachable_bitmask; + dev->pcsc->cached_bitmask =3D dev->pcsc->data->cached_bitmask; + dev->pcsc->cfg_space =3D dev->pcsc->data->cfg_space; + infer_cacheability(dev); } else { + dev->pcsc->data =3D NULL; + dev->pcsc->cachable_bitmask =3D NULL; + dev->pcsc->cached_bitmask =3D NULL; dev->pcsc->cfg_space =3D NULL; } =20 @@ -771,8 +787,12 @@ int pcsc_remove_device(struct pci_dev *dev) =20 atomic_dec(&num_nodes); =20 - if (dev->pcsc && dev->pcsc->cfg_space) { - kfree(dev->pcsc->cfg_space); + if (dev->pcsc && dev->pcsc->data) { + size_t data_size =3D sizeof(struct pcsc_data); + size_t total_size =3D PAGE_ALIGN(data_size); + + free_pages((unsigned long)dev->pcsc->data, + get_order(total_size)); kfree(dev->pcsc); } dev->pcsc =3D NULL; diff --git a/include/linux/pcsc.h b/include/linux/pcsc.h index 85471273c0a9..88894f641257 100644 --- a/include/linux/pcsc.h +++ b/include/linux/pcsc.h @@ -18,12 +18,40 @@ #define PCSC_CFG_SPC_SIZE 256 #endif =20 -struct pcsc_node { - u8 *cfg_space; +/* + * struct pcsc__data - Continuous data block for PCSC + * + * This structure contains all the PCSC data in a single continuous + * memory block. + * + * @cfg_space: Configuration space cache + * @cachable_bitmask: Bitmap of cacheable configuration space offsets + * @cached_bitmask: Bitmap of cached configuration space offsets + */ +struct pcsc_data { + u8 cfg_space[PCSC_CFG_SPC_SIZE]; DECLARE_BITMAP(cachable_bitmask, PCSC_CFG_SPC_SIZE); DECLARE_BITMAP(cached_bitmask, PCSC_CFG_SPC_SIZE); }; =20 +/* + * struct pcsc_node - PCSC node structure + * + * This structure represents a PCSC node for a PCI device. + * It contains pointers into the data block for convenient access. + * + * @data: Pointer to the continuous data block + * @cachable_bitmask: Pointer to cachable_bitmask in data + * @cached_bitmask: Pointer to cached_bitmask in data + * @cfg_space: Pointer to cfg_space in data + */ +struct pcsc_node { + struct pcsc_data *data; /* Pointer to continuous data block */ + unsigned long *cachable_bitmask; /* Convenience pointer into data */ + unsigned long *cached_bitmask; /* Convenience pointer into data */ + u8 *cfg_space; /* Convenience pointer into data */ +}; + /** * pcsc_hw_config_read - Direct hardware PCI config space read * @bus: PCI bus --=20 2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597