Received: by 2002:a05:6520:1682:b0:147:d1a0:b502 with SMTP id ck2csp5596297lkb; Mon, 11 Oct 2021 09:38:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRU6W3V9/ZFyhQC92+sQQv2rGw+7nH3+5/jrtl4hZJAEgzh4SxSMQj9YsjzPZS7uRBbeuW X-Received: by 2002:a05:6a00:234f:b0:3eb:3ffd:6da2 with SMTP id j15-20020a056a00234f00b003eb3ffd6da2mr26759734pfj.15.1633970322612; Mon, 11 Oct 2021 09:38:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633970322; cv=none; d=google.com; s=arc-20160816; b=fpZG9ujc9bAJiAMZUuLthzWjmtjtm31LojkcZI2hZmPP0ULBM697TXHxjbMDkjcWeX /NvC+81FVceDJdZTsZg0IQ6WgTuDb673SfDD59dgVBClPU8naS+VTVvlgawvivrmkA9Z 5AodC0Z19zl8PSrvRdiy64jADg3jHn0GYrmreOtmpmiWmDwA1O+1W6CmQbcEvUVTLUYX ueGpJRN9YA/ee9N3Ca+8VwULNJ2Alrl/c1+NWGGdhGKi6hDG8nZBbq7trd+uArsFbXDu qoq0n2xnVa3SXzK8y2/bDm5qIWx+Jc2WO2VjXtW8lUpmPKKZiJQrWt2tlFe2eZ8N7Riw VWuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2WmQWgvsMJ/DrkDJuz6VqPBvx5Ecy9pSzZWYWfNVocA=; b=dCswO2XPsTGcgsynzKHoCsm+VXWhRWpc9tYfvZBDqXtiwAfNYCZtIThTNG6JkPrqbc ImLDHj2kan/6iG5qVm72jrsy757r1p+hhk4/7H2CyRAUqB2UBXHb9ZWAHi3gZQ/QnQPs Ts8DN3nUKeDSX0LUShuaR173teIkJ/9YJMoJUcKuWmKAobIxWwbPdA6f5GOke4psaZLO 2IcJpa+DDtC6HuKPRaGCqPPsu2a4o8IQhf17kRtI5/zPdA0QDq09dPPWxDbvFrnT8vvB mhe2SxhoEpQHm2D3X7DViNP+J5YxzqYCCf9PJCMWnQ53mxSB+bfLrCVT6KydwtWAjrVG MgMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i8vk2CYy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f2si14464950pfe.179.2021.10.11.09.38.29; Mon, 11 Oct 2021 09:38:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i8vk2CYy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243063AbhJKOPy (ORCPT + 99 others); Mon, 11 Oct 2021 10:15:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:34050 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244036AbhJKONd (ORCPT ); Mon, 11 Oct 2021 10:13:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4855860EDF; Mon, 11 Oct 2021 14:04:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633961070; bh=zqndhYKowbWUCONueoEbL925Z+Em9LuWtqNphI/M9iM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i8vk2CYylm7Ur9MgJJ2394/ifozF4xDfIfP4uI9ZMgaKH6/xrpalYrghfKEQDFD38 2mW1yluUQ78OlCSkODPj7CzVbNe9IhYuKgRJl1z3uIGmP+CQW9RS9bWGQU4CAjlTVn 3IoBb2iFKBUS6xkFk3dL/m9wmiGtUXSliOKOSgUU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jakub Kicinski , Thomas Gleixner , "Rafael J. Wysocki" , Kai-Heng Feng , Bjorn Helgaas Subject: [PATCH 5.14 150/151] x86/hpet: Use another crystalball to evaluate HPET usability Date: Mon, 11 Oct 2021 15:47:02 +0200 Message-Id: <20211011134522.684528124@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134517.833565002@linuxfoundation.org> References: <20211011134517.833565002@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner commit 6e3cd95234dc1eda488f4f487c281bac8fef4d9b upstream. On recent Intel systems the HPET stops working when the system reaches PC10 idle state. The approach of adding PCI ids to the early quirks to disable HPET on these systems is a whack a mole game which makes no sense. Check for PC10 instead and force disable HPET if supported. The check is overbroad as it does not take ACPI, intel_idle enablement and command line parameters into account. That's fine as long as there is at least PMTIMER available to calibrate the TSC frequency. The decision can be overruled by adding "hpet=force" on the kernel command line. Remove the related early PCI quirks for affected Ice Cake and Coffin Lake systems as they are not longer required. That should also cover all other systems, i.e. Tiger Rag and newer generations, which are most likely affected by this as well. Fixes: Yet another hardware trainwreck Reported-by: Jakub Kicinski Signed-off-by: Thomas Gleixner Tested-by: Jakub Kicinski Reviewed-by: Rafael J. Wysocki Cc: stable@vger.kernel.org Cc: Kai-Heng Feng Cc: Bjorn Helgaas Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/early-quirks.c | 6 --- arch/x86/kernel/hpet.c | 81 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 6 deletions(-) --- a/arch/x86/kernel/early-quirks.c +++ b/arch/x86/kernel/early-quirks.c @@ -714,12 +714,6 @@ static struct chipset early_qrk[] __init */ { PCI_VENDOR_ID_INTEL, 0x0f00, PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, force_disable_hpet}, - { PCI_VENDOR_ID_INTEL, 0x3e20, - PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, force_disable_hpet}, - { PCI_VENDOR_ID_INTEL, 0x3ec4, - PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, force_disable_hpet}, - { PCI_VENDOR_ID_INTEL, 0x8a12, - PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, force_disable_hpet}, { PCI_VENDOR_ID_BROADCOM, 0x4331, PCI_CLASS_NETWORK_OTHER, PCI_ANY_ID, 0, apple_airport_reset}, {} --- a/arch/x86/kernel/hpet.c +++ b/arch/x86/kernel/hpet.c @@ -10,6 +10,7 @@ #include #include #include +#include #undef pr_fmt #define pr_fmt(fmt) "hpet: " fmt @@ -916,6 +917,83 @@ static bool __init hpet_counting(void) return false; } +static bool __init mwait_pc10_supported(void) +{ + unsigned int eax, ebx, ecx, mwait_substates; + + if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) + return false; + + if (!cpu_feature_enabled(X86_FEATURE_MWAIT)) + return false; + + if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF) + return false; + + cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates); + + return (ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) && + (ecx & CPUID5_ECX_INTERRUPT_BREAK) && + (mwait_substates & (0xF << 28)); +} + +/* + * Check whether the system supports PC10. If so force disable HPET as that + * stops counting in PC10. This check is overbroad as it does not take any + * of the following into account: + * + * - ACPI tables + * - Enablement of intel_idle + * - Command line arguments which limit intel_idle C-state support + * + * That's perfectly fine. HPET is a piece of hardware designed by committee + * and the only reasons why it is still in use on modern systems is the + * fact that it is impossible to reliably query TSC and CPU frequency via + * CPUID or firmware. + * + * If HPET is functional it is useful for calibrating TSC, but this can be + * done via PMTIMER as well which seems to be the last remaining timer on + * X86/INTEL platforms that has not been completely wreckaged by feature + * creep. + * + * In theory HPET support should be removed altogether, but there are older + * systems out there which depend on it because TSC and APIC timer are + * dysfunctional in deeper C-states. + * + * It's only 20 years now that hardware people have been asked to provide + * reliable and discoverable facilities which can be used for timekeeping + * and per CPU timer interrupts. + * + * The probability that this problem is going to be solved in the + * forseeable future is close to zero, so the kernel has to be cluttered + * with heuristics to keep up with the ever growing amount of hardware and + * firmware trainwrecks. Hopefully some day hardware people will understand + * that the approach of "This can be fixed in software" is not sustainable. + * Hope dies last... + */ +static bool __init hpet_is_pc10_damaged(void) +{ + unsigned long long pcfg; + + /* Check whether PC10 substates are supported */ + if (!mwait_pc10_supported()) + return false; + + /* Check whether PC10 is enabled in PKG C-state limit */ + rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, pcfg); + if ((pcfg & 0xF) < 8) + return false; + + if (hpet_force_user) { + pr_warn("HPET force enabled via command line, but dysfunctional in PC10.\n"); + return false; + } + + pr_info("HPET dysfunctional in PC10. Force disabled.\n"); + boot_hpet_disable = true; + return true; +} + /** * hpet_enable - Try to setup the HPET timer. Returns 1 on success. */ @@ -929,6 +1007,9 @@ int __init hpet_enable(void) if (!is_hpet_capable()) return 0; + if (hpet_is_pc10_damaged()) + return 0; + hpet_set_mapping(); if (!hpet_virt_address) return 0;