From patchwork Tue Jul 16 19:32:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Hildebrand X-Patchwork-Id: 13734852 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2086.outbound.protection.outlook.com [40.107.96.86]) (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 236111CD2C; Tue, 16 Jul 2024 19:33:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721158437; cv=fail; b=R6WW/NYMl9EP6j6Lq+SrULnsPU52GSVUEkdwjn5DrlL5e28y/WwVkhX1JDSW3JnqFXRbz8xsgoqCAPmiOKMt3VprM/dKttdCybltPsktUVIfwrLmL8nClCESk23j66nKM31abXrfz1+9knl/YjBWoil9T0J1KemWZfxw0GiKaNo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721158437; c=relaxed/simple; bh=UoAKZ7UG2gWc2C/jW6AOwIxbyjGeSk7Gg/uLJwFlP3k=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=JbnM2vjG+ymajSNyLewSlTEu/Gnn9lfuuE+NAvE89hoT6HGIqP/EQZ2meQ4xzS1MsiqM55qSyAMt7vAkxWkL+FxKFgqtcEJfTcI65UnMDqkpYs978pMsyjKpWZ2TcTZqtbGQ+2H7VxJ/vxkuQyJFIcfkvetKMjY66Y67eAZvNVs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=ULB5aMOy; arc=fail smtp.client-ip=40.107.96.86 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="ULB5aMOy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KcHPMn3pw340zMOb5OX/iwvzfyDQgoMIquMwBoIuIQTtxyxXL3YLrcqOSiSfPzi3ZMI85l0TeIZece7wln1ginxXH6NqdXUNetH5XEjCu9627KQDnYExlPhcUjlqTf0zLtnXw+P0L821r+iL5CJ+AvnA4Hm5kZc6mcEXqNkgqcm7L04T+2vHNp+xPCJD9k8OgKedW5iKQFRpkpcNJNdrvoTto/m2QtcAjNn5cwyh0yFUvXu6vWSnyH33wfKijPjdCj378MnTbNX4/h29hAy5ARwiMrsZQUohPXfaX1GmDI1qtP0bloglsPEYX0aJ6p9wV8WlJaSsod1u0yrkDsBvrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FUaZ2CCCwah1S2bUG1wuLlx9XA+UQHA5nrENPkn/Gb0=; b=Yn1dabyW8TDy6A/otBKBQTNt39fqQGqtFXsc229rBW2o5WHNU8fAC9O4wKbCTw5x6fX11NgpWQWyY4mlxBlThbvWFmB+afxain3vU3lFGtv1iuxox6svV7eECkGiKS8oZgAl01qUjXaBkk6mWoxdPZJWVvPxh8ZUjEHYzRmJcoBYYaq7EBe+FxXcvx0bSz1zSE7b+WlzITXp0hPxlHgoP9jF8DREQq0QWcqonznEpuu1OAV2/lehpQpMtmGdzXotuYUVMyD4ylJ0eZx3zS0ye7ogSvkpof343DA2ix1p+XiSUCfkhDKjyPC3+Np+YtezCKtduHNx80110vBOX2y6PA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FUaZ2CCCwah1S2bUG1wuLlx9XA+UQHA5nrENPkn/Gb0=; b=ULB5aMOycgpJlV5PgHbMZ5Hqnk6geQrG/Tt0l8KWpmbusv/w1YR2UF2GPxpWcxWxNu2fWuoZNq9OObmPqAmKkIfBxe2TvxhO+CxBstUaUejUrkLr4jdUW0X/1d4jywDiYqo7z1PPOD6mXJmTcys/D/ehHYaKVn9rYc1NoYwyXVg= Received: from MN0P220CA0024.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:52e::18) by DS0PR12MB8220.namprd12.prod.outlook.com (2603:10b6:8:f5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.15; Tue, 16 Jul 2024 19:33:52 +0000 Received: from BL6PEPF0001AB52.namprd02.prod.outlook.com (2603:10b6:208:52e:cafe::25) by MN0P220CA0024.outlook.office365.com (2603:10b6:208:52e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16 via Frontend Transport; Tue, 16 Jul 2024 19:33:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL6PEPF0001AB52.mail.protection.outlook.com (10.167.241.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.11 via Frontend Transport; Tue, 16 Jul 2024 19:33:50 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 16 Jul 2024 14:33:50 -0500 Received: from ubuntu.mshome.net (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Tue, 16 Jul 2024 14:33:48 -0500 From: Stewart Hildebrand To: Bjorn Helgaas , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , "Michael Ellerman" , Nicholas Piggin , Christophe Leroy , "Naveen N. Rao" , Thomas Zimmermann , "Arnd Bergmann" , Sam Ravnborg , Yongji Xie , =?utf-8?q?Ilpo_J=C3=A4rvinen?= CC: Stewart Hildebrand , , , , Subject: [PATCH v2 0/8] PCI: Align small (<4k) BARs Date: Tue, 16 Jul 2024 15:32:30 -0400 Message-ID: <20240716193246.1909697-1-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: stewart.hildebrand@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB52:EE_|DS0PR12MB8220:EE_ X-MS-Office365-Filtering-Correlation-Id: c6b27bc0-1815-4322-0773-08dca5ce384c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA: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V0rAVtiffE/BhQfbvLyqAV5GUunpduzH3jR+XPufQzFHs/G6L5/YQvIvU4O7xC+6kAXofrXF1I4MIuFg8b+ulmgzBpdNNF3qSbjMdqHCACqLfzwcb0O3P3HweNzMJLQpn6i6B7RAGnpBF71MRITHTv7FCLU5WzFtmam+t9Qzk9JMmp/zR3F/fRUbLHrYTGq9kEi2+DuWbHmSkaAb0mJnaOZyYNfcXZLrSQ6gT5t1alKKgts9eRNy1+T4C56HJ0oai2jbC3WTcNRR9frSci3saHYffhxhnXNBUX51A/2o62ivYuybuFdDHBomVUDGuvE8FtjjGV5C4USBbqHNswWFAac5J05t3TO+f+siquQcgJLM0F4iYRvjPoeGybXaursRHaWBAJSj4yq4iXTa3rlKxg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(36860700013)(1800799024)(82310400026)(7416014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2024 19:33:50.5495 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c6b27bc0-1815-4322-0773-08dca5ce384c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB52.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8220 This series sets the default minimum resource alignment to 4k for memory BARs. In preparation, it makes an optimization and addresses some corner cases observed when reallocating BARs. I consider the prepapatory patches to be prerequisites to changing the default BAR alignment. I considered introducing checks for the specific scenarios described, but chose not to pursue this. A check such as "if (xen_domain())" may be pretty simple, but that doesn't account for other hypervisors. If other hypervisors are to be considered, or if we try to dynamically reallocate BARs for devices being marked for passthrough, such a check may quickly grow unwieldy. Further, checking for the MSI-X tables residing in a small (<4k) BAR is unlikely to be a one-liner. Making 4k alignment the default seems more robust. Lastly, when using IORESOURCE_STARTALIGN, all resources in the system need to be aligned. I considered alternatively adding new functionality to the pci=resource_alignment= option, but that approach was already attempted and decided against [1]. [1] https://lore.kernel.org/linux-pci/1473757234-5284-4-git-send-email-xyjxie@linux.vnet.ibm.com/ v1->v2: * rename ("PCI: don't clear already cleared bit") to ("PCI: Don't unnecessarily disable memory decoding") * new patch: ("x86/PCI: Move some logic to new function") * new patch: ("powerpc/pci: Preserve IORESOURCE_STARTALIGN alignment") Stewart Hildebrand (8): x86/PCI: Move some logic to new function PCI: Don't unnecessarily disable memory decoding PCI: Restore resource alignment PCI: Restore memory decoding after reallocation x86/PCI: Preserve IORESOURCE_STARTALIGN alignment powerpc/pci: Preserve IORESOURCE_STARTALIGN alignment PCI: Don't reassign resources that are already aligned PCI: Align small (<4k) BARs arch/powerpc/kernel/pci-common.c | 6 +++-- arch/x86/pci/i386.c | 38 +++++++++++++++------------ drivers/pci/pci.c | 43 +++++++++++++++++++++++-------- drivers/pci/setup-bus.c | 44 ++++++++++++++++++++++++++++++++ include/linux/pci.h | 2 ++ 5 files changed, 103 insertions(+), 30 deletions(-)