From patchwork Thu Mar 2 05:25:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 63228 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp4063617wrd; Wed, 1 Mar 2023 21:53:39 -0800 (PST) X-Google-Smtp-Source: AK7set+W7Lzd5coPUWiQ3lyifHgTkfbRgwnME4ICYrqvbzLsga7R1w7LSXnKuiiu2oIKr9Sp3OD7 X-Received: by 2002:a17:907:8b17:b0:900:a150:cea5 with SMTP id sz23-20020a1709078b1700b00900a150cea5mr11734589ejc.54.1677736419077; Wed, 01 Mar 2023 21:53:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677736419; cv=none; d=google.com; s=arc-20160816; b=d6BP2J26D/7t2P0WMx7OdiGIK4Jr7nxzH/t/9aHyO+2MH7KmwXzMCIKLYVzgOfUVcS xTC5B0DAJKk24FjlZ1QybLjHy3YuFc4BX5MxSjRfYU7iMyUH5A7aanaaLFuGCHj+8MHE tkV/Q7P+q5S3iU8Sb+jcCbZTynQuneiNKYIZ0QCO14Y/ig4a0RX4qT3AdHkjuncRGd3T 6VCzbyG7Rro1GM7toylTIy4kIk6oP9o/l4m8sA7QIn1xuC5ZRb/5hMvkacsS9Wp86eOO Xf9OmuVEKVXJPROBaDYjFih7ld6EXJwA6HPV9+EBVvJYP5Cb75hx0VfLsFaaRrJfACPO DUQg== 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=o/s4OgoBvlYE/i/ueeuD809hBfxz0iI2J7KU1Tu8hr0=; b=aXCErqfpdFNbQsunmAHZ4Wlcakiu6yecLzESUZ2mUAG7JnEMrBYI55BvIcViJ7ABIv xJQM4dhV9hiJXlCABqIo8jQUdWd34fkG4cninrXuQ2+a8iKQ8BZTxmoPg8pDUqncrphN xTCQiHjrianxjfkplUf6zLpV0nyhaBwxuRjN3aug7Ew1NssUe0l7vHbYIPimdgkhKaNZ nnJfV3wrcF9qtO2klw28eTNipeyfYSV8BJIOfFuJ2nnR+wUDJss85dUd6xKZ1mu+4k9a PHSG+eMh39C/1FH5UHq1BO20vtbdZlttO0zY05l0uo20sniMJd0jFh3RPEZ3epFePH2P 47Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Zmw+nEZM; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a21-20020aa7d915000000b004ab1c20c759si5350620edr.543.2023.03.01.21.53.16; Wed, 01 Mar 2023 21:53:39 -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=@intel.com header.s=Intel header.b=Zmw+nEZM; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230048AbjCBFw2 (ORCPT + 99 others); Thu, 2 Mar 2023 00:52:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbjCBFvw (ORCPT ); Thu, 2 Mar 2023 00:51:52 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E1274DE12; Wed, 1 Mar 2023 21:51:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677736269; x=1709272269; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SfNRJW38HST/J2vYBy+d2Rz7YNwfS+VaJzsap6qMLmE=; b=Zmw+nEZMsh5OaGqBExIrVm8w3i4BOWz5VTMkQzlKk5rrPyEA7quVJvUD dtXVM4An7T+cNlpaVd2P3VavVdrLjrlkWoTQow5wXhagMHsehv3z2WjDr Y4RXvMWQDjPBCaiIyLDl+49sN9vh4eqNo7QYit27CqRIX09G3d2z3bjZs +CCR5Y4H0054iktjAWcRXOHg9Ukuy+x8/KlhHnk3OQaf6UmI4WNjpxVkq pc3+7w3/dKYovaVUaTLMoPCyZDx7LR+xsyMAxhK8wIC1eS4d0KPx0AIhF MzlqcqBhgEVwvEBSIsrPCIDzPQjlR8kpyw4jM+q9FkOFoqt7SE9d4t6v2 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10636"; a="420887232" X-IronPort-AV: E=Sophos;i="5.98,226,1673942400"; d="scan'208";a="420887232" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2023 21:50:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10636"; a="920530951" X-IronPort-AV: E=Sophos;i="5.98,226,1673942400"; d="scan'208";a="920530951" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga006.fm.intel.com with ESMTP; 01 Mar 2023 21:50:49 -0800 From: Xin Li To: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, peterz@infradead.org, andrew.cooper3@citrix.com, seanjc@google.com, pbonzini@redhat.com, ravi.v.shankar@intel.com Subject: [PATCH v4 23/34] x86/fred: update MSR_IA32_FRED_RSP0 during task switch Date: Wed, 1 Mar 2023 21:25:00 -0800 Message-Id: <20230302052511.1918-24-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230302052511.1918-1-xin3.li@intel.com> References: <20230302052511.1918-1-xin3.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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?1759234143127919678?= X-GMAIL-MSGID: =?utf-8?q?1759234143127919678?= From: "H. Peter Anvin (Intel)" MSR_IA32_FRED_RSP0 is used during ring 3 event delivery, and needs to be updated to point to the top of next task stack during task switch. Update MSR_IA32_FRED_RSP0 with WRMSR instruction for now, and will use WRMSRNS/WRMSRLIST for performance once it gets upstreamed. Signed-off-by: H. Peter Anvin (Intel) Tested-by: Shan Kang Signed-off-by: Xin Li --- arch/x86/include/asm/switch_to.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h index 5c91305d09d2..00fd85abc1d2 100644 --- a/arch/x86/include/asm/switch_to.h +++ b/arch/x86/include/asm/switch_to.h @@ -68,9 +68,16 @@ static inline void update_task_stack(struct task_struct *task) #ifdef CONFIG_X86_32 this_cpu_write(cpu_tss_rw.x86_tss.sp1, task->thread.sp0); #else - /* Xen PV enters the kernel on the thread stack. */ - if (cpu_feature_enabled(X86_FEATURE_XENPV)) + if (cpu_feature_enabled(X86_FEATURE_FRED)) { + /* + * Will use WRMSRNS/WRMSRLIST for performance once it's upstreamed. + */ + wrmsrl(MSR_IA32_FRED_RSP0, + task_top_of_stack(task) + TOP_OF_KERNEL_STACK_PADDING); + } else if (cpu_feature_enabled(X86_FEATURE_XENPV)) { + /* Xen PV enters the kernel on the thread stack. */ load_sp0(task_top_of_stack(task)); + } #endif }