From mboxrd@z Thu Jan 1 00:00:00 1970 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 17A3AC433F5 for ; Fri, 14 Jan 2022 00:28:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238372AbiANA2N (ORCPT ); Thu, 13 Jan 2022 19:28:13 -0500 Received: from mga04.intel.com ([192.55.52.120]:24454 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230165AbiANA2N (ORCPT ); Thu, 13 Jan 2022 19:28:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642120093; x=1673656093; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=RRSc0fCF2gQ58MCLYJ6EBu3GpIJNYU365XBPjiNmmwU=; b=aH2hmOTwwfKK+7xqAT3xwiRYnJPanp28ULfpIXa3JM2OtWPTBLRoceFs EFYyGpJ5d6Mzc7XZ0yZW3h3RtCSdFsXlKFE6OcHnoHFlniUbU8dHct2z2 AKNVo+Hoih3KkW+Ub0sQ8kG+LtLGSiHERbH/pWmvojpRYPasSHOIxKuwC 5pXglXux9y+c80/thexk8jwphMFvCaEN3+lJMdUPP6vuJdsFm+aCubBmq MjLJ5y9GiPyp4NbL27W9wrML9nmVSmKkJlTPk5+cn6Qh76DtNrD5FWeSf BE7tby8VpvLxrfkx+FGiJg3+b4vFXwZH0pkdcj6Q6bQ9gER0YjkUxhxkj Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10226"; a="242964235" X-IronPort-AV: E=Sophos;i="5.88,287,1635231600"; d="scan'208";a="242964235" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2022 16:28:12 -0800 X-IronPort-AV: E=Sophos;i="5.88,287,1635231600"; d="scan'208";a="491317600" Received: from lucas-s2600cw.jf.intel.com ([10.165.21.202]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2022 16:28:12 -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?q?Ville=20Syrj=C3=A4l=C3=A4?= , Matt Roper , Rodrigo Vivi , stable@vger.kernel.org Subject: [PATCH v5 1/5] x86/quirks: Fix stolen detection with integrated + discrete GPU Date: Thu, 13 Jan 2022 16:28:39 -0800 Message-Id: <20220114002843.2083382-1-lucas.demarchi@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@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 So, stop using the QFLAG_APPLY_ONCE flag, replacing it with a static local variable. We can set this variable in the right place, inside intel_graphics_quirks(), only when the quirk was actually applied, i.e. when we find the integrated GPU based on the intel_early_ids table. Cc: stable@vger.kernel.org Signed-off-by: Lucas De Marchi --- v5: apply fix before the refactor arch/x86/kernel/early-quirks.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c index 1ca3a56fdc2d..de9a76eb544e 100644 --- a/arch/x86/kernel/early-quirks.c +++ b/arch/x86/kernel/early-quirks.c @@ -589,10 +589,14 @@ 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; + device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID); for (i = 0; i < ARRAY_SIZE(intel_early_ids); i++) { @@ -605,6 +609,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; } } @@ -705,7 +711,7 @@ static struct chipset early_qrk[] __initdata = { { PCI_VENDOR_ID_INTEL, 0x3406, PCI_CLASS_BRIDGE_HOST, PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check }, { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA, PCI_ANY_ID, - QFLAG_APPLY_ONCE, intel_graphics_quirks }, + 0, 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. -- 2.34.1 From mboxrd@z Thu Jan 1 00:00:00 1970 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 576D9C433F5 for ; Fri, 14 Jan 2022 00:28:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8ACD110E86E; Fri, 14 Jan 2022 00:28:14 +0000 (UTC) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id DC65210E86E for ; Fri, 14 Jan 2022 00:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642120092; x=1673656092; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=RRSc0fCF2gQ58MCLYJ6EBu3GpIJNYU365XBPjiNmmwU=; b=Is5UVV4j5ALLxSvgsaGN1ThpGSaZ7vbmEkcEe2/n2gaXUfItQikjoWFo 0/0JTxA4AkPRYbVycIapwTBFePKTcqjKAtkUImClpe/gMWNmESM+0+5cN 6RHyqbrmHgoTbAmB8yz9ZYJFQVlI6Xr8AhEL4v+x7JaDfcGdsAhfc/8hA oi2/SGSrSiuBebmDjSqF+scmnIvSWTRhZDEOVJnGIiZ/T2OTw0BDuVXz7 5vdyjOL441ZCBDuDugQctSdaINSNGOasp20LHaiTt7waz4+KzSn0ZsK+h 7i/GW9T6Fr3XgCJ7SGL3sXoty9jdh4vAZwtTcgXKMUA/mV/i8y1+/yEoc w==; X-IronPort-AV: E=McAfee;i="6200,9189,10226"; a="244103839" X-IronPort-AV: E=Sophos;i="5.88,287,1635231600"; d="scan'208";a="244103839" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2022 16:28:12 -0800 X-IronPort-AV: E=Sophos;i="5.88,287,1635231600"; d="scan'208";a="491317600" Received: from lucas-s2600cw.jf.intel.com ([10.165.21.202]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2022 16:28:12 -0800 From: Lucas De Marchi To: x86@kernel.org Date: Thu, 13 Jan 2022 16:28:39 -0800 Message-Id: <20220114002843.2083382-1-lucas.demarchi@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Intel-gfx] [PATCH v5 1/5] x86/quirks: Fix stolen detection with integrated + discrete GPU X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pci@vger.kernel.org, intel-gfx@lists.freedesktop.org, Dave Hansen , stable@vger.kernel.org, Ingo Molnar , Bjorn Helgaas , Thomas Gleixner Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 So, stop using the QFLAG_APPLY_ONCE flag, replacing it with a static local variable. We can set this variable in the right place, inside intel_graphics_quirks(), only when the quirk was actually applied, i.e. when we find the integrated GPU based on the intel_early_ids table. Cc: stable@vger.kernel.org Signed-off-by: Lucas De Marchi --- v5: apply fix before the refactor arch/x86/kernel/early-quirks.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c index 1ca3a56fdc2d..de9a76eb544e 100644 --- a/arch/x86/kernel/early-quirks.c +++ b/arch/x86/kernel/early-quirks.c @@ -589,10 +589,14 @@ 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; + device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID); for (i = 0; i < ARRAY_SIZE(intel_early_ids); i++) { @@ -605,6 +609,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; } } @@ -705,7 +711,7 @@ static struct chipset early_qrk[] __initdata = { { PCI_VENDOR_ID_INTEL, 0x3406, PCI_CLASS_BRIDGE_HOST, PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check }, { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA, PCI_ANY_ID, - QFLAG_APPLY_ONCE, intel_graphics_quirks }, + 0, 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. -- 2.34.1