Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1613712pxb; Mon, 11 Oct 2021 09:30:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUkrF4ff7/Y7H2o1YzVbS7o6LEVGb7CXwzIajONMt8hdcGjeLfaxMxcQIhlml7SUhb0FGb X-Received: by 2002:a17:906:8d7:: with SMTP id o23mr26583515eje.193.1633969822915; Mon, 11 Oct 2021 09:30:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633969822; cv=none; d=google.com; s=arc-20160816; b=dj+mEB7OevCeh08k837RnWICCu/f+a5Zr6dWP2Cw7jDKDPyrA8Cv/s97qGg7F12TOa 2/hV+644JZcd/QuGgvFCto6vXeWAIPbdktOgNLFxAHgGi2UuC+mG8Io5K/fGtgZJhvSX vyMKhI8hrIPX2xybu2Ub3gJwIF9+C8xmUR7E2HpkKqGbO2hb7xi48jQLd5t0UYAAug4c IHneGsoiPDNC+wDcZMLVVNwxwep42LqEb3uqptKKTUF6k/iya0XBUm+pQgUfR0tXIWSX DABcP4d5gIwFcao9c1iaQxqLcgM0LkZUR8diTGb23hejGiepn/5VATqr/kHmPuUfwhQD ubhQ== 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=5trGNRug20ozcHQa6Sf3W0/gfyNltNe9TEtOXGSGh3Q=; b=oY87+e+WVBPCzJOg84oUPyOyx1D7YYxWvVDX4RDH/KnalMgLB5AY80PXpts0D7qIyy D5gnW1ILRZlH7uszgDkRutWaHt7Cb13s8VYrk8Flv83EkJ7qyNOClU92yh/c6gB+e0UB QiSZPW4cAePzHxsYxRwPBgWvxLMDszaHeH7ZZ2uKlYCuJzFPn3L+d5PNfI2d3Yr/cBaa 7qsWoStFdOkxOHimUXf5slQV9q+yMeVfh7GIb0JW3gc44k4VVh8nwCokGRkWGI1b657m eJHVksWVzyn+CLUXO5kUvz6o/uL/c6O/UImQyBUuNkth2SX7+NYXUZlYh5UkF5SjpAzd X7RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lW+em4Vt; 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 h12si18487331edb.85.2021.10.11.09.29.59; Mon, 11 Oct 2021 09:30:22 -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=lW+em4Vt; 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 S237552AbhJKNxr (ORCPT + 99 others); Mon, 11 Oct 2021 09:53:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:39696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237300AbhJKNwL (ORCPT ); Mon, 11 Oct 2021 09:52:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 583D360F4B; Mon, 11 Oct 2021 13:50:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633960211; bh=AuBVr87Shi6Tg3Fqh1mlcjMeh2zQRTw2nAlNt32fzdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lW+em4Vt/L4sbZRdPUFRusps2TXAJORS/Nm1K/AcvWtlKeSoPAhQWEf1EKLKiKpIu ttgWfYm9nZ1KHsG4Lep38lRArO48kxC5IjYmPEo5L50uKjiP6VEwjThLEKdM7tf2kc nxsnQJC/XMcSu8llKcRZdvJckw2uyHJduUrntWJE= 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.4 51/52] x86/hpet: Use another crystalball to evaluate HPET usability Date: Mon, 11 Oct 2021 15:46:20 +0200 Message-Id: <20211011134505.483011431@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134503.715740503@linuxfoundation.org> References: <20211011134503.715740503@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 @@ -710,12 +710,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 @@ -9,6 +9,7 @@ #include #include +#include #undef pr_fmt #define pr_fmt(fmt) "hpet: " fmt @@ -806,6 +807,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. */ @@ -819,6 +897,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;