Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5762226rwl; Tue, 11 Apr 2023 09:35:52 -0700 (PDT) X-Google-Smtp-Source: AKy350Z/Wn6YV4IDDbI4dvNxRjyeQ1wUhJ4/LzMXrZ/wtLVsbQQ8MHWkDJwC5uO27GHBnDpR0rp7 X-Received: by 2002:a62:61c4:0:b0:635:56c3:4bb0 with SMTP id v187-20020a6261c4000000b0063556c34bb0mr9179015pfb.27.1681230952603; Tue, 11 Apr 2023 09:35:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681230952; cv=none; d=google.com; s=arc-20160816; b=crKwWVd6zR1eDvh+BR/bQaT5WKl1xwvpm1tvdJsduVvZ6UHYBSdhkgR2VumqX/X0oX zphQj87G91IcDTY4Z+mbODcet0N7jWQU6Bx8Cb1cdBZCkNTvYnBCDcBFQUNzLDA8MJA6 I9Um4WCQf5ZLaevaVswCYC/eyN6Tcmg9a76gxjSwqmdhaXFEw+R5+g3by6z9thyqiug1 aZ7s7w3DaLQlrCXmwvLzeQTareCcoBqy9oysTyjpaBw7uXFlGi+rXoaeGpLy5g/LUxFR iaT04I87OHkXMTEnKoHI35qgG4vJS8eMGlBIS2l/JiyNMFZc7tKYIJ9loPF6zwaaSh4X bNgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=ALv++1lpafzbPYh+8H3mwX2MnrqW23j0lXWDGZQVNzQ=; b=UHqBZhm50XS8BSjDpC24ykSCl4SYoeU1WdB6ImEYWpqzw4GqmUpn7DIJ5QV+8wozVA 4On6znf+v1lP0GhIXyT55AFPHb7+MTKnJ1eUy6yf68jo6lcvwOs8my1l5KqQZCulKdmY OeZGGGx+bG1g17K1vmnuBvEdtNDAvgD5OCk4QervgSkfOUr55Y0MCS52BbICcMx8gTL3 jmnmHufX1Q4U7bUR/X9qrF0LWRQhGXzEHYLpN1sR9+BEQUllUb83cQSv0ia7BLILI8l8 aAg4EH0OSazqwfzA1DA5Hrzuli+AQ7V3QbzwgTdVJP5wJyHbPj0XkbFg3gWnqL0p9Rpz MKrg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g13-20020aa79dcd000000b005a8ac319433si13704913pfq.178.2023.04.11.09.35.39; Tue, 11 Apr 2023 09:35:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229778AbjDKQSR convert rfc822-to-8bit (ORCPT + 99 others); Tue, 11 Apr 2023 12:18:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229642AbjDKQRx (ORCPT ); Tue, 11 Apr 2023 12:17:53 -0400 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 689345251; Tue, 11 Apr 2023 09:16:57 -0700 (PDT) Received: by mail-ej1-f53.google.com with SMTP id gb34so21958028ejc.12; Tue, 11 Apr 2023 09:16:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681229816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z3ITv/vwrFDX7sYlzoF644RlJZcwlzODzuaMxOLuck8=; b=tKDdwxiVRX5/QTrfCpBOZ/KytM9uQqpvQ+U9NOj/iyfkPgmuLMfbXOyO+Sc9eGqpO1 3WdxNQgvlgJ8SGPF7/NOY5ABmxgYfxpYDKad0aXKoV7Agfr30uR8IZ5fnipZVRb1O/Db FlN0yrRvHQ/BG+xmj/gv5fVlCg2FJZirN33mPAgHTfOafSUM8AhylW9dwkxIVYhNmofh mY+DrVXPv3rqVcsIG844oDnMucgqUwCcVtk/2K4L7sMxYeGkyygR7tnmqXgSMd+sFMvN IkcbPCkTRmWFBQWMKBUzEQzi2ve0CdTXKhYzjuUQq1WO1Bb7AFGAknfx6XisNnm/wSf7 pagQ== X-Gm-Message-State: AAQBX9dzlE3zWLry+qtL2JqikvpsP1Br/EmbdVHi8JPg1FmEDOKyX7q3 sDyxTQzxB/j6bDgmQDNKLtLStmEUyjZhSokYJa4= X-Received: by 2002:a17:907:6287:b0:93e:c1ab:ae67 with SMTP id nd7-20020a170907628700b0093ec1abae67mr5882234ejc.2.1681229815612; Tue, 11 Apr 2023 09:16:55 -0700 (PDT) MIME-Version: 1.0 References: <20230410173501.3743570-1-srinivas.pandruvada@linux.intel.com> In-Reply-To: <20230410173501.3743570-1-srinivas.pandruvada@linux.intel.com> From: "Rafael J. Wysocki" Date: Tue, 11 Apr 2023 18:16:44 +0200 Message-ID: Subject: Re: [PATCH] thermal: intel: Fix unchecked MSR issue To: Srinivas Pandruvada Cc: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, bp@alien8.de, Rui Salvaterra , stable@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 10, 2023 at 7:35 PM Srinivas Pandruvada wrote: > > Some older processors don't allow BIT(13) and BIT(15) in the current > mask set by "THERM_STATUS_CLEAR_CORE_MASK". This results in: > > unchecked MSR access error: WRMSR to 0x19c (tried to > write 0x000000000000aaa8) at rIP: 0xffffffff816f66a6 > (throttle_active_work+0xa6/0x1d0) > > To avoid unchecked MSR issues, check cpuid for each feature and then > form core mask. Do the same for package mask set by > "THERM_STATUS_CLEAR_PKG_MASK". > > Introduce functions thermal_intr_core_clear_mask() and > thermal_intr_pkg_clear_mask() I've renamed these two functions to thermal_intr_init_core_clear_mask() and thermal_intr_init_pkg_clear_mask(), respectively. > to set core and package mask respectively. > These functions are called during initialization. > > Fixes: 6fe1e64b6026 ("thermal: intel: Prevent accidental clearing of HFI status") > Reported-by: Rui Salvaterra > Link: https://lore.kernel.org/lkml/cdf43fb423368ee3994124a9e8c9b4f8d00712c6.camel@linux.intel.com/T/ > Tested-by: Rui Salvaterra > Signed-off-by: Srinivas Pandruvada > Cc: stable@kernel.org # 6.2+ > --- > drivers/thermal/intel/therm_throt.c | 73 ++++++++++++++++++++++++++--- > 1 file changed, 66 insertions(+), 7 deletions(-) > > diff --git a/drivers/thermal/intel/therm_throt.c b/drivers/thermal/intel/therm_throt.c > index 2e22bb82b738..d5047676f3d2 100644 > --- a/drivers/thermal/intel/therm_throt.c > +++ b/drivers/thermal/intel/therm_throt.c > @@ -193,8 +193,67 @@ static const struct attribute_group thermal_attr_group = { > #define THERM_THROT_POLL_INTERVAL HZ > #define THERM_STATUS_PROCHOT_LOG BIT(1) > > -#define THERM_STATUS_CLEAR_CORE_MASK (BIT(1) | BIT(3) | BIT(5) | BIT(7) | BIT(9) | BIT(11) | BIT(13) | BIT(15)) > -#define THERM_STATUS_CLEAR_PKG_MASK (BIT(1) | BIT(3) | BIT(5) | BIT(7) | BIT(9) | BIT(11)) > +static u64 def_therm_core_clear_mask; > +static u64 def_therm_pkg_clear_mask; And I've renamed these two variables to therm_intr_core_clear_mask and therm_intr_pkg_clear_mask, respectively. Also I've changed the subject (to "thermal: intel: Avoid updating unsupported THERM_STATUS_CLEAR mask bits") and made some assorted changelog edits. With the above changes, the patch has been queued up for 6.3-rc7. > + > +static void thermal_intr_core_clear_mask(void) > +{ > + if (def_therm_core_clear_mask) > + return; > + > + /* > + * Reference: Intel SDM Volume 4 > + * "Table 2-2. IA-32 Architectural MSRs", MSR 0x19C > + * IA32_THERM_STATUS. > + */ > + > + /* > + * Bit 1, 3, 5: CPUID.01H:EDX[22] = 1. This driver will not > + * enable interrupts, when 0 as it checks for X86_FEATURE_ACPI. > + */ > + def_therm_core_clear_mask = (BIT(1) | BIT(3) | BIT(5)); > + > + /* > + * Bit 7 and 9: Thermal Threshold #1 and #2 log > + * If CPUID.01H:ECX[8] = 1 > + */ > + if (boot_cpu_has(X86_FEATURE_TM2)) > + def_therm_core_clear_mask |= (BIT(7) | BIT(9)); > + > + /* Bit 11: Power Limitation log (R/WC0) If CPUID.06H:EAX[4] = 1 */ > + if (boot_cpu_has(X86_FEATURE_PLN)) > + def_therm_core_clear_mask |= BIT(11); > + > + /* > + * Bit 13: Current Limit log (R/WC0) If CPUID.06H:EAX[7] = 1 > + * Bit 15: Cross Domain Limit log (R/WC0) If CPUID.06H:EAX[7] = 1 > + */ > + if (boot_cpu_has(X86_FEATURE_HWP)) > + def_therm_core_clear_mask |= (BIT(13) | BIT(15)); > +} > + > +static void thermal_intr_pkg_clear_mask(void) > +{ > + if (def_therm_pkg_clear_mask) > + return; > + > + /* > + * Reference: Intel SDM Volume 4 > + * "Table 2-2. IA-32 Architectural MSRs", MSR 0x1B1 > + * IA32_PACKAGE_THERM_STATUS. > + */ > + > + /* All bits except BIT 26 depends on CPUID.06H: EAX[6] = 1 */ > + if (boot_cpu_has(X86_FEATURE_PTS)) > + def_therm_pkg_clear_mask = (BIT(1) | BIT(3) | BIT(5) | BIT(7) | BIT(9) | BIT(11)); > + > + /* > + * Intel SDM Volume 2A: Thermal and Power Management Leaf > + * Bit 26: CPUID.06H: EAX[19] = 1 > + */ > + if (boot_cpu_has(X86_FEATURE_HFI)) > + def_therm_pkg_clear_mask |= BIT(26); > +} > > /* > * Clear the bits in package thermal status register for bit = 1 > @@ -207,13 +266,10 @@ void thermal_clear_package_intr_status(int level, u64 bit_mask) > > if (level == CORE_LEVEL) { > msr = MSR_IA32_THERM_STATUS; > - msr_val = THERM_STATUS_CLEAR_CORE_MASK; > + msr_val = def_therm_core_clear_mask; > } else { > msr = MSR_IA32_PACKAGE_THERM_STATUS; > - msr_val = THERM_STATUS_CLEAR_PKG_MASK; > - if (boot_cpu_has(X86_FEATURE_HFI)) > - msr_val |= BIT(26); > - > + msr_val = def_therm_pkg_clear_mask; > } > > msr_val &= ~bit_mask; > @@ -708,6 +764,9 @@ void intel_init_thermal(struct cpuinfo_x86 *c) > h = THERMAL_APIC_VECTOR | APIC_DM_FIXED | APIC_LVT_MASKED; > apic_write(APIC_LVTTHMR, h); > > + thermal_intr_core_clear_mask(); > + thermal_intr_pkg_clear_mask(); > + > rdmsr(MSR_IA32_THERM_INTERRUPT, l, h); > if (cpu_has(c, X86_FEATURE_PLN) && !int_pln_enable) > wrmsr(MSR_IA32_THERM_INTERRUPT, > -- > 2.39.1 >