From patchwork Mon Nov 21 13:07:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 23731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1575855wrr; Mon, 21 Nov 2022 05:09:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf7uJ9jOM91q0b84BD+TpqTjzcifkZWJiV24RqaMD0D3SGVhL+U+hurodSTaOCBMgv5ar++M X-Received: by 2002:a17:902:6b07:b0:186:df61:4693 with SMTP id o7-20020a1709026b0700b00186df614693mr839391plk.173.1669036162127; Mon, 21 Nov 2022 05:09:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669036162; cv=none; d=google.com; s=arc-20160816; b=BaCdbLzQrS3Olf4FL6GyWrEfDTKndQLlch5LXj9nMkqjQzK0Xe2shX+77j+g59AZtz 6kPu/2IYJmICyQUkjbcgR5rFFrm4pbyuOo0kynIVi5OIwZZhVdnK1QoDb5xXRXUPZ7SI OY6iP+5sg4EjGxrQADpMzukS18Bj5fGaCS3NoOM8Gwt3I7JKFz/Qzje/b7x0SlFZsTPg Z8ZmxSEDQpoTzs6VMSZSXvsXZKqy89BecjkR3nvmOMmYZLvr/cPATpArBnEopTVXJNRY xpLHjkuzMxCyUBTCXCkJnGCMPq1MkmiXHVG1qW2a+jDmZRicHBuL8+mtLXKhLYrvdy5Q NLWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=0LTsNOnWcLQkZ4pXm46KIGH1m+Af+UxpALo5i3IMh+c=; b=tJmh69jhuDYuj2Ooz4OyVIsf4D7a7/uDbcav7KdNq+EBRlPXXsC8Z2UonzTasaGMln aOjCV6zHD6d8Rtx84TJYuZyG7SyoTUhQdvrWc5JgbNoLsQAGSuWIPvPzEwaj93q8+G/M TeS0H556MX2vCZhLXhZ9r8jPjWSUbNy+NL76uHSbKgFyEydVoYDN8+333bJx/F+DdwtB iLXBS8MiF6R4jbq8TBVGNteTsIYkwFE2U+2hrwsNgqyIRsLg03FLla/ZNamP6kqmSPsb qlXC/VfWJOYlKUYFJKiL1+Ps+4Bln3dzYH5/N569LZs9AzLwXuU4ytAIP5cJJgdt4VMg MIcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=W31slvMK; dkim=neutral (no key) header.i=@linutronix.de header.b=7mvL8o5S; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d4-20020a056a0010c400b00565ba4c501asi12078274pfu.276.2022.11.21.05.09.06; Mon, 21 Nov 2022 05:09:22 -0800 (PST) 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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=W31slvMK; dkim=neutral (no key) header.i=@linutronix.de header.b=7mvL8o5S; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229628AbiKUNIK (ORCPT + 99 others); Mon, 21 Nov 2022 08:08:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229639AbiKUNIE (ORCPT ); Mon, 21 Nov 2022 08:08:04 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 768AFB949F; Mon, 21 Nov 2022 05:07:59 -0800 (PST) Date: Mon, 21 Nov 2022 13:07:55 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669036077; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0LTsNOnWcLQkZ4pXm46KIGH1m+Af+UxpALo5i3IMh+c=; b=W31slvMKB5yU2W/QrFVDFx+b51GO08sTGTex5EELWpSSfQiTlPkT+KYBEr+UtEiZaFyWbT zYeIvaci18mj7QJfDuwVdPXTV5ZupiSW2kreY9ZroTIZB2KqriNjbXr0R47ZAK9IyoAcrG 277370bvXMFCR1QTUPWyUY30As94OFPq0k3OpxIBYXZqYhVehJTJxxaKsmi23KJ1b5NIbp WE85ihMByxfBQuZhbzZp14cAcr012N9smSLtggMagWIm1lR3hQYrppZDY4/pBzUNUU8jaz xk1DX3PX1d2eKVIbL5zOq6i1jp8rQPs2iIfAA2VndaSbZ6da0MZrbuy2VbH8XA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669036077; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0LTsNOnWcLQkZ4pXm46KIGH1m+Af+UxpALo5i3IMh+c=; b=7mvL8o5Sa9uaTAMAS5J3N8VW6cQW6ZA45ZpOu82XbANj8A+/5Ct2zyUal1JrdbxFUKtN1M aHoSfqQ+r/SXG8DQ== From: "tip-bot2 for Pawan Gupta" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/pm: Add enumeration check before spec MSRs save/restore setup Cc: Hans de Goede , Pawan Gupta , Borislav Petkov , Dave Hansen , "Rafael J. Wysocki" , , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: =?utf-8?q?=3Cc24db75d69df6e66c0465e13676ad3f2837a2ed8=2E1668539?= =?utf-8?q?735=2Egit=2Epawan=2Ekumar=2Egupta=40linux=2Eintel=2Ecom=3E?= References: =?utf-8?q?=3Cc24db75d69df6e66c0465e13676ad3f2837a2ed8=2E16685397?= =?utf-8?q?35=2Egit=2Epawan=2Ekumar=2Egupta=40linux=2Eintel=2Ecom=3E?= MIME-Version: 1.0 Message-ID: <166903607515.4906.17081515597820913083.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749591264149330149?= X-GMAIL-MSGID: =?utf-8?q?1750111262832623824?= The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 44bf877180388ea23d689edd5e7dd7ca828f64ce Gitweb: https://git.kernel.org/tip/44bf877180388ea23d689edd5e7dd7ca828f64ce Author: Pawan Gupta AuthorDate: Tue, 15 Nov 2022 11:17:06 -08:00 Committer: Borislav Petkov CommitterDate: Mon, 21 Nov 2022 13:32:27 +01:00 x86/pm: Add enumeration check before spec MSRs save/restore setup pm_save_spec_msr() keeps a list of all the MSRs which _might_ need to be saved and restored at hibernate and resume. However, it has zero awareness of CPU support for these MSRs. It mostly works by unconditionally attempting to manipulate these MSRs and relying on rdmsrl_safe() being able to handle a #GP on CPUs where the support is unavailable. However, it's possible for reads (RDMSR) to be supported for a given MSR while writes (WRMSR) are not. In this case, msr_build_context() sees a successful read (RDMSR) and marks the MSR as valid. Then, later, a write (WRMSR) fails, producing a nasty (but harmless) error message. This causes restore_processor_state() to try and restore it, but writing this MSR is not allowed on the Intel Atom N2600 leading to: unchecked MSR access error: WRMSR to 0x122 (tried to write 0x0000000000000002) \ at rIP: 0xffffffff8b07a574 (native_write_msr+0x4/0x20) Call Trace: restore_processor_state x86_acpi_suspend_lowlevel acpi_suspend_enter suspend_devices_and_enter pm_suspend.cold state_store kernfs_fop_write_iter vfs_write ksys_write do_syscall_64 ? do_syscall_64 ? up_read ? lock_is_held_type ? asm_exc_page_fault ? lockdep_hardirqs_on entry_SYSCALL_64_after_hwframe To fix this, add the corresponding X86_FEATURE bit for each MSR. Avoid trying to manipulate the MSR when the feature bit is clear. This required adding a X86_FEATURE bit for MSRs that do not have one already, but it's a small price to pay. [ bp: Move struct msr_enumeration inside the only function that uses it. ] Fixes: 73924ec4d560 ("x86/pm: Save the MSR validity status at context setup") Reported-by: Hans de Goede Signed-off-by: Pawan Gupta Signed-off-by: Borislav Petkov Reviewed-by: Dave Hansen Acked-by: Rafael J. Wysocki Cc: Link: https://lore.kernel.org/r/c24db75d69df6e66c0465e13676ad3f2837a2ed8.1668539735.git.pawan.kumar.gupta@linux.intel.com --- arch/x86/power/cpu.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c index 4cd39f3..93ae332 100644 --- a/arch/x86/power/cpu.c +++ b/arch/x86/power/cpu.c @@ -513,16 +513,23 @@ static int pm_cpu_check(const struct x86_cpu_id *c) static void pm_save_spec_msr(void) { - u32 spec_msr_id[] = { - MSR_IA32_SPEC_CTRL, - MSR_IA32_TSX_CTRL, - MSR_TSX_FORCE_ABORT, - MSR_IA32_MCU_OPT_CTRL, - MSR_AMD64_LS_CFG, - MSR_AMD64_DE_CFG, + struct msr_enumeration { + u32 msr_no; + u32 feature; + } msr_enum[] = { + { MSR_IA32_SPEC_CTRL, X86_FEATURE_MSR_SPEC_CTRL }, + { MSR_IA32_TSX_CTRL, X86_FEATURE_MSR_TSX_CTRL }, + { MSR_TSX_FORCE_ABORT, X86_FEATURE_TSX_FORCE_ABORT }, + { MSR_IA32_MCU_OPT_CTRL, X86_FEATURE_SRBDS_CTRL }, + { MSR_AMD64_LS_CFG, X86_FEATURE_LS_CFG_SSBD }, + { MSR_AMD64_DE_CFG, X86_FEATURE_LFENCE_RDTSC }, }; + int i; - msr_build_context(spec_msr_id, ARRAY_SIZE(spec_msr_id)); + for (i = 0; i < ARRAY_SIZE(msr_enum); i++) { + if (boot_cpu_has(msr_enum[i].feature)) + msr_build_context(&msr_enum[i].msr_no, 1); + } } static int pm_check_save_msr(void)