From patchwork Fri Jan 7 21:05:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas De Marchi X-Patchwork-Id: 12707057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F35A3C433F5 for ; Fri, 7 Jan 2022 21:05:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229697AbiAGVFL (ORCPT ); Fri, 7 Jan 2022 16:05:11 -0500 Received: from mga11.intel.com ([192.55.52.93]:64400 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229663AbiAGVFK (ORCPT ); Fri, 7 Jan 2022 16:05:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641589510; x=1673125510; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=aKLYYSDTkBTTSsRb9jl0RQrFl9gvKzgSUDHiY2KjVNY=; b=YuKDUlqM81M6giio/ndqDGiUblxn+ST4bLiOJ/sOagREHG5yodbc7TB0 n9IbBfV1DBVMP7CdZXAgdcJRQmwY3IRmF0VcK52OQFFmxym5pD1wh2mnM IWFdq5C+DVXwuGJk7F4U9+42PZd//GBDny4ee74pGCGYpz4Da4IiQ9kIv dGnpjVcadxrAgFZVAMQ4o3GNr6ztRe7sM7jbAaOoK7l7n8WZ/MB5HYAHh KeajPNgauW1iyJRyYEgEyxjskAQwjNbM5GlPtmPaRMzkh+2l31+fjP5yS w36oidCBYZIA0aXDuglxvuPaugLpIN0bhGwDYDPdgonwPjg4S+cVpzoPi A==; X-IronPort-AV: E=McAfee;i="6200,9189,10220"; a="240493442" X-IronPort-AV: E=Sophos;i="5.88,271,1635231600"; d="scan'208";a="240493442" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jan 2022 13:04:51 -0800 X-IronPort-AV: E=Sophos;i="5.88,271,1635231600"; d="scan'208";a="527506812" Received: from lucas-s2600cw.jf.intel.com ([10.165.21.202]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jan 2022 13:04:51 -0800 From: Lucas De Marchi To: x86@kernel.org Cc: Dave Hansen , Ingo Molnar , Thomas Gleixner , Bjorn Helgaas , linux-pci@vger.kernel.org, intel-gfx@lists.freedesktop.org, =?utf-8?b?Vmls?= =?utf-8?b?bGUgU3lyasOkbMOk?= , Matt Roper Subject: [PATCH v3 1/3] x86/quirks: Replace QFLAG_APPLY_ONCE with static locals Date: Fri, 7 Jan 2022 13:05:14 -0800 Message-Id: <20220107210516.907834-1-lucas.demarchi@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The flags are only used to mark a quirk to be called once and nothing else. Also, that logic may not be appropriate if the quirk wants to do additional filtering and set quirk ass applied by itself. So replace the uses of QFLAG_APPLY_ONCE with static local variables in the few quirks that use this logic and remove all the flags logic. Signed-off-by: Lucas De Marchi Reviewed-by: Bjorn Helgaas --- v3: Keep in this patch only the mechanical change to move from QFLAG_APPLY_ONCE to static locals. Differently than v2, we don't try to set quirk_applied in nvidia_bugs() and via_bugs() only when the global resource is set - this patch is a mechanical move only and shouldn't change any behavior. For intel_graphics_quirks(), we will move it to the right place in a subsequent patch. arch/x86/kernel/early-quirks.c | 55 +++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c index 391a4e2b8604..8b689c2b8cc7 100644 --- a/arch/x86/kernel/early-quirks.c +++ b/arch/x86/kernel/early-quirks.c @@ -57,6 +57,13 @@ static void __init fix_hypertransport_config(int num, int slot, int func) static void __init via_bugs(int num, int slot, int func) { #ifdef CONFIG_GART_IOMMU + static bool quirk_applied __initdata; + + if (quirk_applied) + return; + + quirk_applied = true; + if ((max_pfn > MAX_DMA32_PFN || force_iommu) && !gart_iommu_aperture_allowed) { printk(KERN_INFO @@ -81,6 +88,13 @@ static void __init nvidia_bugs(int num, int slot, int func) { #ifdef CONFIG_ACPI #ifdef CONFIG_X86_IO_APIC + static bool quirk_applied __initdata; + + if (quirk_applied) + return; + + quirk_applied = true; + /* * Only applies to Nvidia root ports (bus 0) and not to * Nvidia graphics cards with PCI ports on secondary buses. @@ -587,10 +601,16 @@ intel_graphics_stolen(int num, int slot, int func, static void __init intel_graphics_quirks(int num, int slot, int func) { + static bool quirk_applied __initdata; const struct intel_early_ops *early_ops; u16 device; int i; + if (quirk_applied) + return; + + quirk_applied = true; + device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID); for (i = 0; i < ARRAY_SIZE(intel_early_ids); i++) { @@ -673,37 +693,33 @@ static void __init apple_airport_reset(int bus, int slot, int func) early_iounmap(mmio, BCM4331_MMIO_SIZE); } -#define QFLAG_APPLY_ONCE 0x1 -#define QFLAG_APPLIED 0x2 -#define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED) struct chipset { u32 vendor; u32 device; u32 class; u32 class_mask; - u32 flags; void (*f)(int num, int slot, int func); }; static struct chipset early_qrk[] __initdata = { { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, - PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, nvidia_bugs }, + PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, nvidia_bugs }, { PCI_VENDOR_ID_VIA, PCI_ANY_ID, - PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, via_bugs }, + PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, via_bugs }, { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB, - PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config }, + PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, fix_hypertransport_config }, { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS, - PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs }, + PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, ati_bugs }, { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS, - PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs_contd }, + PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, ati_bugs_contd }, { PCI_VENDOR_ID_INTEL, 0x3403, PCI_CLASS_BRIDGE_HOST, - PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check }, + PCI_BASE_CLASS_BRIDGE, intel_remapping_check }, { PCI_VENDOR_ID_INTEL, 0x3405, PCI_CLASS_BRIDGE_HOST, - PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check }, + PCI_BASE_CLASS_BRIDGE, intel_remapping_check }, { PCI_VENDOR_ID_INTEL, 0x3406, PCI_CLASS_BRIDGE_HOST, - PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check }, + PCI_BASE_CLASS_BRIDGE, intel_remapping_check }, { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA, PCI_ANY_ID, - QFLAG_APPLY_ONCE, intel_graphics_quirks }, + intel_graphics_quirks }, /* * HPET on the current version of the Baytrail platform has accuracy * problems: it will halt in deep idle state - so we disable it. @@ -713,9 +729,9 @@ static struct chipset early_qrk[] __initdata = { * http://www.intel.com/content/dam/www/public/us/en/documents/datasheets/atom-z8000-datasheet-vol-1.pdf */ { PCI_VENDOR_ID_INTEL, 0x0f00, - PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, force_disable_hpet}, + PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, force_disable_hpet}, { PCI_VENDOR_ID_BROADCOM, 0x4331, - PCI_CLASS_NETWORK_OTHER, PCI_ANY_ID, 0, apple_airport_reset}, + PCI_CLASS_NETWORK_OTHER, PCI_ANY_ID, apple_airport_reset}, {} }; @@ -756,12 +772,9 @@ static int __init check_dev_quirk(int num, int slot, int func) ((early_qrk[i].device == PCI_ANY_ID) || (early_qrk[i].device == device)) && (!((early_qrk[i].class ^ class) & - early_qrk[i].class_mask))) { - if ((early_qrk[i].flags & - QFLAG_DONE) != QFLAG_DONE) - early_qrk[i].f(num, slot, func); - early_qrk[i].flags |= QFLAG_APPLIED; - } + early_qrk[i].class_mask))) + early_qrk[i].f(num, slot, func); + } type = read_pci_config_byte(num, slot, func, From patchwork Fri Jan 7 21:05:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas De Marchi X-Patchwork-Id: 12707058 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BBC9C433EF for ; Fri, 7 Jan 2022 21:05:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229663AbiAGVFL (ORCPT ); Fri, 7 Jan 2022 16:05:11 -0500 Received: from mga11.intel.com ([192.55.52.93]:64400 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229695AbiAGVFL (ORCPT ); Fri, 7 Jan 2022 16:05:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641589511; x=1673125511; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vFLYInGUJc6hUal4AED9pTD9I7tbEWM8G9wbErgC8p0=; b=CZ9mUna1G/TP27ATou7jxGmnuV3iTs/yxSF7BcSukLXGnpxRP60nWSwa bWVQ/n6vWbxbkaRKYdSJ0RtiPjYdBNBT6bko93fEE6amd+vrD2GB+xCaE 3rhnhF/8Y9UMdMuqSfdNBB1HcOXHqSbEe0C8MpX+9J9Ughm2Lpvg0sBJK CA+3xc/3r/uH7cbBvek65FKpvFFTbYd9KPc/5YsoyZ6cV60qpjIWfJjPh XGm0VdDKTL/lJZYLSErQ+ltD1XEePapupitbEJ8anjn7m5ubve3o9afFa +GMOm3l+IAfASZbxj8Fr5PEtrE3/X5DJ62C7wpaV1OKEsPYbmOUcPiXlG Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10220"; a="240493446" X-IronPort-AV: E=Sophos;i="5.88,271,1635231600"; d="scan'208";a="240493446" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jan 2022 13:04:51 -0800 X-IronPort-AV: E=Sophos;i="5.88,271,1635231600"; d="scan'208";a="527506815" Received: from lucas-s2600cw.jf.intel.com ([10.165.21.202]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jan 2022 13:04:51 -0800 From: Lucas De Marchi To: x86@kernel.org Cc: Dave Hansen , Ingo Molnar , Thomas Gleixner , Bjorn Helgaas , linux-pci@vger.kernel.org, intel-gfx@lists.freedesktop.org, =?utf-8?b?Vmls?= =?utf-8?b?bGUgU3lyasOkbMOk?= , Matt Roper Subject: [PATCH v3 2/3] x86/quirks: Improve line wrap on quirk conditions Date: Fri, 7 Jan 2022 13:05:15 -0800 Message-Id: <20220107210516.907834-2-lucas.demarchi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220107210516.907834-1-lucas.demarchi@intel.com> References: <20220107210516.907834-1-lucas.demarchi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Remove extra parenthesis and wrap lines so it's easier to read what are the conditions being checked. The call to the hook also had an extra indentation: remove here to conform to coding style. Signed-off-by: Lucas De Marchi Reviewed-by: Rodrigo Vivi --- arch/x86/kernel/early-quirks.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c index 8b689c2b8cc7..df34963e23bf 100644 --- a/arch/x86/kernel/early-quirks.c +++ b/arch/x86/kernel/early-quirks.c @@ -767,14 +767,12 @@ static int __init check_dev_quirk(int num, int slot, int func) device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID); for (i = 0; early_qrk[i].f != NULL; i++) { - if (((early_qrk[i].vendor == PCI_ANY_ID) || - (early_qrk[i].vendor == vendor)) && - ((early_qrk[i].device == PCI_ANY_ID) || - (early_qrk[i].device == device)) && - (!((early_qrk[i].class ^ class) & - early_qrk[i].class_mask))) - early_qrk[i].f(num, slot, func); - + if ((early_qrk[i].vendor == PCI_ANY_ID || + early_qrk[i].vendor == vendor) && + (early_qrk[i].device == PCI_ANY_ID || + early_qrk[i].device == device) && + !((early_qrk[i].class ^ class) & early_qrk[i].class_mask)) + early_qrk[i].f(num, slot, func); } type = read_pci_config_byte(num, slot, func, From patchwork Fri Jan 7 21:05:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas De Marchi X-Patchwork-Id: 12707059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EFBDC433FE for ; Fri, 7 Jan 2022 21:05:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229695AbiAGVFM (ORCPT ); Fri, 7 Jan 2022 16:05:12 -0500 Received: from mga11.intel.com ([192.55.52.93]:64400 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229712AbiAGVFL (ORCPT ); Fri, 7 Jan 2022 16:05:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641589511; x=1673125511; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BGkQZ9wJjtm6Ly24SCm04Vr1byx/zgNEgihwQDGEf9k=; b=S4eo3903rALxYm3/ehF6XcM4FVYnz2NLYZ0UED4SqOTIzo8HcoKlLHLs pQenFHnpE5gtTksv+Eml1Q4omYLhqVCwSWRy6dKLVOXp8rVxdwWv15itg QyQR90BE6/ERhgH5O4JSRfoAqLvDgzVyQOCdPcR5IiXVS/l/SuI5V6sy5 R33BoAaNuem5xcApAyLErJOvgagJPhMpOgLlRiys2M+9MkJkX6n9AMa5L OtTSRhYsUD+oX9fXNJoGSgUjvQ3bUz8XACza+/MgJJ0J1BewNwVCfvg/e 4OW/w0EsTvtS5o0Fluw+kjpx8lSKeInHB2P0o5S8U1CXE2InqrszIs58l w==; X-IronPort-AV: E=McAfee;i="6200,9189,10220"; a="240493450" X-IronPort-AV: E=Sophos;i="5.88,271,1635231600"; d="scan'208";a="240493450" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jan 2022 13:04:51 -0800 X-IronPort-AV: E=Sophos;i="5.88,271,1635231600"; d="scan'208";a="527506817" Received: from lucas-s2600cw.jf.intel.com ([10.165.21.202]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jan 2022 13:04:51 -0800 From: Lucas De Marchi To: x86@kernel.org Cc: Dave Hansen , Ingo Molnar , Thomas Gleixner , Bjorn Helgaas , linux-pci@vger.kernel.org, intel-gfx@lists.freedesktop.org, =?utf-8?b?Vmls?= =?utf-8?b?bGUgU3lyasOkbMOk?= , Matt Roper Subject: [PATCH v3 3/3] x86/quirks: Fix stolen detection with integrated + discrete GPU Date: Fri, 7 Jan 2022 13:05:16 -0800 Message-Id: <20220107210516.907834-3-lucas.demarchi@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220107210516.907834-1-lucas.demarchi@intel.com> References: <20220107210516.907834-1-lucas.demarchi@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org early_pci_scan_bus() does a depth-first traversal, possibly calling the quirk functions for each device based on vendor, device and class from early_qrk table. intel_graphics_quirks() however uses PCI_ANY_ID and does additional filtering in the quirk. If there is an Intel integrated + discrete GPU the quirk may be called first for the discrete GPU based on the PCI topology. Then we will fail to reserve the system stolen memory for the integrated GPU, because we will already have marked the quirk as "applied". This was reproduced in a setup with Alderlake-P (integrated) + DG2 (discrete), with the following PCI topology: - 00:01.0 Bridge `- 03:00.0 DG2 - 00:02.0 Integrated GPU Move the setting of quirk_applied in intel_graphics_quirks() so it's mark as applied only when we find the integrated GPU based on the intel_early_ids table. Signed-off-by: Lucas De Marchi Reviewed-by: Rodrigo Vivi Acked-by: Bjorn Helgaas --- v3: now that we do the refactor before the fix, we can do a single line change to fix intel_graphics_quirks(). Also, we don't change intel_graphics_stolen() anymore as we did in v2: we don't have to check other devices anymore if there was a previous match causing intel_graphics_stolen() to be called (there can only be one integrated GPU reserving the stolen memory). arch/x86/kernel/early-quirks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c index df34963e23bf..932f9087c324 100644 --- a/arch/x86/kernel/early-quirks.c +++ b/arch/x86/kernel/early-quirks.c @@ -609,8 +609,6 @@ static void __init intel_graphics_quirks(int num, int slot, int func) if (quirk_applied) return; - quirk_applied = true; - device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID); for (i = 0; i < ARRAY_SIZE(intel_early_ids); i++) { @@ -623,6 +621,8 @@ static void __init intel_graphics_quirks(int num, int slot, int func) intel_graphics_stolen(num, slot, func, early_ops); + quirk_applied = true; + return; } }