Message ID | 20230307023946.14516-24-xin3.li@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2212761wrd; Mon, 6 Mar 2023 19:16:49 -0800 (PST) X-Google-Smtp-Source: AK7set+RAb3bAbgT0e0ksTCN0ml3l0Bz6vCLdiC3QWf27E78VyK0d8uoflC4EVukmVAlk/GwE14j X-Received: by 2002:a17:907:7212:b0:8b1:75c4:abd with SMTP id dr18-20020a170907721200b008b175c40abdmr15688198ejc.15.1678159009124; Mon, 06 Mar 2023 19:16:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678159009; cv=none; d=google.com; s=arc-20160816; b=Y3YkIbvk1gYUDmQnJIUOlL+MH7XV3OjkUa/LCnsxhW3WRQnv/cVBxGFWqXCm/QBLvt YwbMwtFkhFPYT+pByN3TUI9uHPbonG+I5ybbMH/ORESy9B92grTB2ZT2NtNUgNJYdLoH jFKXz9XiWRAuPyKZUbMAdrldibT/PITlDB2PGuekaPiEaf5/qsNe48iEmYomeOXxP4ou 9clxSwWbEmjjZfUhIqLGBbWcZ2bJwQyGtqhCTScLkdJQDEZkrXyCgB7A7z/Troytyyaf +WDSnP9PMePLvBkGWgdq9/iBRt53o/CTuhejwL4cRdD1O/ZtX6XNaAViJNbadsW/YpD+ d0wA== 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=C+Tb5gVYlfLxnXvDX3oFUuZBxv+nSe+GDL2CvvmE6Mm3pjIpcH7ubcbG/uvDTC9iwN S9LKGkw12qAX4WON4zcPkw87WVZ/4CEa3WEj5mwTFrgMT9T8UeCNDoiQbUs0CWtUL36+ B9LUqbYuHpv6uuRT6QAIoAumumEuh9RdLh8kO+ghQZanLeZC0H/VxEYWykNFA62L+0x6 VvAH/2azBQyW+qbIII70PHlVKFdXkAFDGLsmZh8tn4dT+sBaCg0Sy2q9/pAiytsKXtiz WojtC2EaegIPVFYKpfLwZZQGv1g4z88fgIS0lm7jWhUT99XNxIk9xDv9tB8WsN2OGEVu WqJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MF0uuArZ; 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 o2-20020aa7c502000000b004af625a0f8esi1968445edq.395.2023.03.06.19.16.24; Mon, 06 Mar 2023 19:16:49 -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=MF0uuArZ; 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 S230495AbjCGDHL (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Mon, 6 Mar 2023 22:07:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230388AbjCGDGR (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 6 Mar 2023 22:06:17 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A6E880E2F; Mon, 6 Mar 2023 19:05:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678158334; x=1709694334; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SfNRJW38HST/J2vYBy+d2Rz7YNwfS+VaJzsap6qMLmE=; b=MF0uuArZWwfm3DmkD3oV0y1fD+aU668AvfN97PduzuSJ44neyMyEpIGa p+mRaPiAxlhgwKok3y48eE0+aLuT6ROvDyc6Aq2AUCiMkphBYxBOqSZQY Ei7nBJpuA4LCoug2NvTs0iBD4rsY8qw5a+rLCvJxdgnARpkJItPMNajz/ WIOgn3Luq3al2F3GbUb8Swj6akDox75SB1FZJnNc7BpiFmeCuuVDbOAwc mve6cjDP13r0KgWnW2y5LR5PFVzawTY/EBLLvZUFSK1s8snRuXGt+L0Ct 8Yw0CSLrSN0I5WrDryCkVxMP9Sxf6Ltc4G8k/cFHedWLDBRPAHpSdZ5RN A==; X-IronPort-AV: E=McAfee;i="6500,9779,10641"; a="338072527" X-IronPort-AV: E=Sophos;i="5.98,238,1673942400"; d="scan'208";a="338072527" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2023 19:05:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10641"; a="676409874" X-IronPort-AV: E=Sophos;i="5.98,238,1673942400"; d="scan'208";a="676409874" Received: from unknown (HELO fred..) ([172.25.112.68]) by orsmga002.jf.intel.com with ESMTP; 06 Mar 2023 19:05:19 -0800 From: Xin Li <xin3.li@intel.com> 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 v5 23/34] x86/fred: update MSR_IA32_FRED_RSP0 during task switch Date: Mon, 6 Mar 2023 18:39:35 -0800 Message-Id: <20230307023946.14516-24-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307023946.14516-1-xin3.li@intel.com> References: <20230307023946.14516-1-xin3.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759677260990002659?= X-GMAIL-MSGID: =?utf-8?q?1759677260990002659?= |
Series |
x86: enable FRED for x86-64
|
|
Commit Message
Li, Xin3
March 7, 2023, 2:39 a.m. UTC
From: "H. Peter Anvin (Intel)" <hpa@zytor.com> 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) <hpa@zytor.com> Tested-by: Shan Kang <shan.kang@intel.com> Signed-off-by: Xin Li <xin3.li@intel.com> --- arch/x86/include/asm/switch_to.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
Comments
On Mon, Mar 06, 2023 at 06:39:35PM -0800, Xin Li wrote: > From: "H. Peter Anvin (Intel)" <hpa@zytor.com> > > 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) <hpa@zytor.com> > Tested-by: Shan Kang <shan.kang@intel.com> > Signed-off-by: Xin Li <xin3.li@intel.com> > --- > 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)) { Whee, so hardware will really only ever look at this when RSP0? I don't need to worry about exceptions during context switch?
> > - 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)) { > > Whee, so hardware will really only ever look at this when RSP0? I don't need to > worry about exceptions during context switch? You're right, we don't. RSP0 is only used in ring3. Exceptions from ring0 just keep using the current kernel stack unless a higher stack level needs to be used, e.g., RSP3 for #DF. Thanks! Xin
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 }