Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2541374rwl; Mon, 27 Mar 2023 01:27:07 -0700 (PDT) X-Google-Smtp-Source: AK7set+UO7Cta8tYI4X2sviq69nl3wmFbcwUbzrr3ek/+M7Q5T6LdzWAFxHAaXihzqTy9LDF/g1r X-Received: by 2002:a05:6a20:a110:b0:d9:27f7:8c52 with SMTP id q16-20020a056a20a11000b000d927f78c52mr14141796pzk.16.1679905626935; Mon, 27 Mar 2023 01:27:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679905626; cv=none; d=google.com; s=arc-20160816; b=zfi0eW+dUvbVPYibpsyDfL9S7Ad8G+6S2/PMIVIpjxxErTC7ZxNiq5X/XW0qIRnPGz /0DNoXpD53nlSG3eSlHVq2CfSrsCajABxrmqepKcC3xjWFzKDJgkFSjloCl04Cdk+Ssh y5KUy6LdsmYnhnCVul5wGvxdQi7s11wwCa9kFenIPg35m7oC4h8u42MpiCrU9FGsRg02 o2Fm4Jc/lujjXvn9bEWaiD+z6/sopsgSLD3U/nvvBIOULJq2ioiFYwxengmXRPXhCXtD u/Ry98Xxdckfg3nZb3sEIKQYMtB/EKZWuMCIm3QfXc41mqqDprE9/UlVDFbuWc/bwQv2 alBA== 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=Ool6u7C42MhchPvr819R7TbWs/e3O6GlIF8ddTZZoJKRi/YztPwgy0c/14NBBl/WtQ PPJuuIVhuQBsh4g68PK99p9aDgdekXMd/FDecVRnP6Dy91AZGCM+tP5xS4F5K2obOGy/ 3lEsw3T1QEhXhz3HkilOhYUR6GhfmWcHBn0spM+Fnus6lBQ8u7izWkwIxV9nenvuNN4m Gn6juA69zrlU72/2bP5jbYyGrwwCiBLoChPxTiDqZdqWQ5SPEbdC6IP+KimnumjneEw9 7LVirKklXJy6ppUb/SurLunbVE76sqFEWiTrVORLoAk1dhTQcqFoQxQmQxgUdHxZbdCZ qghw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fvgsSzQg; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 3-20020a631743000000b005134ad7aeccsi3611400pgx.812.2023.03.27.01.26.55; Mon, 27 Mar 2023 01:27:06 -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=@intel.com header.s=Intel header.b=fvgsSzQg; 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 S233191AbjC0I0F (ORCPT + 99 others); Mon, 27 Mar 2023 04:26:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233120AbjC0IYz (ORCPT ); Mon, 27 Mar 2023 04:24:55 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 317E2559F; Mon, 27 Mar 2023 01:24:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679905479; x=1711441479; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SfNRJW38HST/J2vYBy+d2Rz7YNwfS+VaJzsap6qMLmE=; b=fvgsSzQg2y5+8N4JOrf6ltJVVeIToOnneOUJoxpYYCCUW5KZkhkG9Ocb K7ehhSjB6sbKJqxXc3ZicSKnM4AL9q4QJzgnXMN/DKGZFJULH14eaJqA7 cBDoxuxTgizgE0ywkJJXIMj5494rMjDnshr/E5x14nMgIgeKCMCkQeT1z Y+JZtpPfzNO1v5zYCjHw5SpUrBb3lEHSXWRha0+VEZnqpiRsXGV6/xp8F nECDULAFymj8ZqOn/GW9UXGZNZuwIY1c8UMf5DBX3y3kYH6dMOgIzw6aG vjlzfmtWk4PXfjh3k6lm4VEWzgbc9eU9H2D728oJQ8xjnwr0buOOEO906 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10661"; a="338930315" X-IronPort-AV: E=Sophos;i="5.98,294,1673942400"; d="scan'208";a="338930315" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 01:24:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10661"; a="713787115" X-IronPort-AV: E=Sophos;i="5.98,294,1673942400"; d="scan'208";a="713787115" Received: from unknown (HELO fred..) ([172.25.112.68]) by orsmga008.jf.intel.com with ESMTP; 27 Mar 2023 01:24:37 -0700 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, jiangshanlai@gmail.com, shan.kang@intel.com Subject: [PATCH v6 22/33] x86/fred: update MSR_IA32_FRED_RSP0 during task switch Date: Mon, 27 Mar 2023 00:58:27 -0700 Message-Id: <20230327075838.5403-23-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230327075838.5403-1-xin3.li@intel.com> References: <20230327075838.5403-1-xin3.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=unavailable 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 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 } -- 2.34.1