Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7903017rwd; Tue, 20 Jun 2023 07:42:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Kh6h8cIS7AxTbJGOAetoPh1pDlNpSVI/iAR4GqX1GeYo4ZJQ/K5xKNwM6uqCO8NBisAAX X-Received: by 2002:a05:6a00:1483:b0:65d:d5cd:6f17 with SMTP id v3-20020a056a00148300b0065dd5cd6f17mr14040118pfu.24.1687272154952; Tue, 20 Jun 2023 07:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687272154; cv=none; d=google.com; s=arc-20160816; b=TeqZJo7EJ8oK+DQQ2+QlhYs0igLr6x5yrrhUgXP7OKaEbV/Y8sfoJp5HLGgR6CUt/s PNzhHr59KhG5OzdvstEfgQpQXcsTscyHmsKtcs5H5BRjv9nTmz48rjawfx9GlZlQLCE6 SjTY/UP38stpT6U+m5ykdHufc+otkgcBd4r2NBEc2u0WoMl1O4FrsyaziUDmzNoOwUqM Ab+KQORVrSEaixaA/iVjmTlWTGdXAVXerxH4381u20XoWoqJwD4vXHU/PVUQUVZguczY 30XXSM5XHRpFT88NsDK4iWURingoZF4XCK4SvKlII5OMpUHdn3Q5UMrdRL7JeubANOsb ryGA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+DkmE6hETltBu3bPa+S3gxCm/8V55tvpJfZg0jQ8Gvw=; b=Gfyx48uLkxrr2et8AmfQoSHl5NIl15hdAonvX98kcZ/3tcrTcgLcSYvmtXcR6F4GZe 2eG+fqTnKK5YRxIG3cRAPI9eSglsFwuRuFkV/K8NbB/9VkZQUV/+yvePZ9vppYDYYNeA HaL8bIgexsbyWkeAY01KBJy3F/E7yrDI1Drfekt6dg5nZPEbqmtbJA9cs5/tQRWOpIDY XqppAECdzOF17bnHv8nhkGSW9c5L8uQGRAX9MYQW0wmF7pV8ixXsPaLpn3ze/V2b53fW eLiEfZ1wtzCdEiUBuLlDZ+oyr+74FXlebtEnRHZzlWttC9EQrTpcDkT6syJLc3iU6pj3 xVIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E7kQT7cL; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d3-20020aa797a3000000b0062565210347si1777489pfq.275.2023.06.20.07.41.57; Tue, 20 Jun 2023 07:42:34 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=E7kQT7cL; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232731AbjFTOJf (ORCPT + 99 others); Tue, 20 Jun 2023 10:09:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231528AbjFTOJd (ORCPT ); Tue, 20 Jun 2023 10:09:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25A51B1 for ; Tue, 20 Jun 2023 07:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687270133; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+DkmE6hETltBu3bPa+S3gxCm/8V55tvpJfZg0jQ8Gvw=; b=E7kQT7cLKuX9taJLlnGUXwiQHr9nrHKUW8X5S2HRmDgrl5Ms/UQyBAqb8URY4KRbGhzLlp +Qyk5X/2F4QPRmcEgT37msx0WIFboSIMrpNtu5lCCGI7RjHdnPrXavX5sSF2QZZLYrZVRS MAVKQhAhILSnJL6962oKRHw+2K4/z6U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-37-2A_wpEtmMHKKyXq6jJXqlg-1; Tue, 20 Jun 2023 10:08:34 -0400 X-MC-Unique: 2A_wpEtmMHKKyXq6jJXqlg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5130888711B; Tue, 20 Jun 2023 14:06:33 +0000 (UTC) Received: from llong.com (unknown [10.22.34.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91537425356; Tue, 20 Jun 2023 14:06:32 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Josh Poimboeuf , Pawan Gupta , Jacob Pan , Len Brown Cc: linux-kernel@vger.kernel.org, x86@kernel.org, linux-pm@vger.kernel.org, Robin Jarry , Joe Mario , Waiman Long Subject: [PATCH v2 2/5] x86/idle: Disable IBRS when cpu is offline Date: Tue, 20 Jun 2023 10:06:22 -0400 Message-Id: <20230620140625.1001886-3-longman@redhat.com> In-Reply-To: <20230620140625.1001886-1-longman@redhat.com> References: <20230620140625.1001886-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Commit bf5835bcdb96 ("intel_idle: Disable IBRS during long idle") disables IBRS when the CPU enters long idle. However, when a CPU becomes offline, the IBRS bit is still set when X86_FEATURE_KERNEL_IBRS is enabled. That will impact the performance of a sibling CPU. Mitigate this performance impact by clearing all the mitigation bits in SPEC_CTRL MSR when offline and restoring the value of the MSR when it becomes online again. Signed-off-by: Waiman Long --- arch/x86/kernel/smpboot.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 352f0ce1ece4..5ff82fef413c 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -84,6 +84,7 @@ #include #include #include +#include /* representing HT siblings of each logical CPU */ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map); @@ -1838,12 +1839,24 @@ void __noreturn hlt_play_dead(void) void native_play_dead(void) { + u64 spec_ctrl = spec_ctrl_current(); + + if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS)) { + this_cpu_write(x86_spec_ctrl_current, 0); + native_wrmsrl(MSR_IA32_SPEC_CTRL, 0); + } + play_dead_common(); tboot_shutdown(TB_SHUTDOWN_WFS); mwait_play_dead(); if (cpuidle_play_dead()) hlt_play_dead(); + + if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS)) { + native_wrmsrl(MSR_IA32_SPEC_CTRL, spec_ctrl); + this_cpu_write(x86_spec_ctrl_current, spec_ctrl); + } } #else /* ... !CONFIG_HOTPLUG_CPU */ -- 2.31.1