Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1163375rwb; Thu, 6 Oct 2022 09:11:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5FMMMMlb9ojZogfRZHiN7YbiEr7LIWd5//pmMpRBGDZSg1fh7E2UhSLMKjb+oB9xf/Z3nc X-Received: by 2002:a17:907:ea6:b0:782:1ace:9d5b with SMTP id ho38-20020a1709070ea600b007821ace9d5bmr481489ejc.770.1665072716863; Thu, 06 Oct 2022 09:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665072716; cv=none; d=google.com; s=arc-20160816; b=k2BgOlFd1j3g15YmxSI38IMhSX3Z7e0HEXnjf1QOiIbVXMg1siMWBLp9Dlbe2Oq52e +GuSf/vjyTZcYD7X+65QtGidrRQYPpj9ro6EPffgYOftef04Pa/tZpaMI1+X/9wlHwVy EVpe01MErTNNxXUfK5qxTBnvXDcwD5vbS7YU1KDwEMrN9qpUjo3DMOo6CZCZpeqZHoLH nxAzdMUrb50UNlbSeoKW45viNhK5CkVQu3Je3drM2DC2lCH4R5QWOGYBGExiGrcBas/9 BrOu0CDN8Og8yar7Dp5bUzJU4Gyu+XkhBqltujN1irhAzHhL+AvARC3lN3174U0g6BEn PHKg== 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=Mwx0bmL/iflkPSrLZX+z7nHqjep5uXu6l2HfgDQDt2o=; b=k0h3q2TYxIZzvUKDR7r/9LHoA5rq6Bg+7h/arDci/dCU6ZltHstG+Am4NgT5rvE095 Mw/qqTAzx8ipxNkbl+/65JoVP35CpPss2QTKMhikgPrQrofKKm+RLTWJeD1epTBqEGCo FIvaxoBevwOgna5+2WVL6dIl2wOjGLM4Ea00qhCppklKQFOdgQ+2pu5DrgEnSL91JSZ8 rf1t4i9JYjqg0hTKlOJbpNmJEqVT+fmPFg+JobAA0crpdOQ1if5haH8dxZiS9m5RON2Z lgR/J64lNv8uk/87YFj9N+AzWnCZTHbqujbaVeaXYsb/bfha0zRKl2s/6jVKNTqOQaHt qAzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jxKw+8UV; 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 e5-20020a170906314500b0077b6ecac099si5392160eje.287.2022.10.06.09.11.29; Thu, 06 Oct 2022 09:11:56 -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=jxKw+8UV; 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 S231558AbiJFQEE (ORCPT + 99 others); Thu, 6 Oct 2022 12:04:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231792AbiJFQDr (ORCPT ); Thu, 6 Oct 2022 12:03:47 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38009B2745 for ; Thu, 6 Oct 2022 09:03:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665072227; x=1696608227; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UaC8ceQnideTemOSR0AnD9gGv296yv6KtEQKYgHeIg4=; b=jxKw+8UVS/xHiX5TS3LjHyJCmJTJs9BXkzfcPSg0mOfbZazHa1KbiOT1 hCrFLfpv3R+8jlxSGN11DE5wM+AYbSti8w555KqJp7IZ1PckRNuUArTz6 w0F9JSk98HwVkqPE5ch0MJJ8cj6aRPbtEu4uiJy95dm6ENsVamTahiSPA AfJwjjsXUJE2VRg+gHjTajBVOpn6DzaF93CbvertipTVbCw2Ac0pWVtH4 BqYis5aZBtze0i2mx2MGpm5EQWtqC63ogvJaAcosqSNwww4mpBXzBNcwI kqYLbyMWIGFSrqt4xrcrRmofaqNCHvAyy+0ySq05pHCKLtrySdie5Br86 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10492"; a="304480712" X-IronPort-AV: E=Sophos;i="5.95,164,1661842800"; d="scan'208";a="304480712" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2022 09:02:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10491"; a="687486230" X-IronPort-AV: E=Sophos;i="5.95,164,1661842800"; d="scan'208";a="687486230" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga008.fm.intel.com with ESMTP; 06 Oct 2022 09:02:36 -0700 From: Xin Li To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com Subject: [PATCH 4/6] x86/gsseg: move local_irq_save/restore() into asm_load_gs_index() Date: Thu, 6 Oct 2022 08:40:39 -0700 Message-Id: <20221006154041.13001-5-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221006154041.13001-1-xin3.li@intel.com> References: <20221006154041.13001-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 From: "H. Peter Anvin (Intel)" The need to disable/enable interrupts around asm_load_gs_index() is a consequence of the implementation. Prepare for using the LKGS instruction, which is locally atomic and therefore doesn't need interrupts disabled. Signed-off-by: H. Peter Anvin (Intel) Signed-off-by: Xin Li --- arch/x86/entry/entry_64.S | 26 +++++++++++++++++++++----- arch/x86/include/asm/special_insns.h | 4 ---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index e0c48998d2fb..cc6ba6672418 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -778,19 +778,35 @@ SYM_CODE_END(common_interrupt_return) _ASM_NOKPROBE(common_interrupt_return) /* - * Reload gs selector with exception handling + * Reload gs selector with exception handling. This is used only on + * native, so using swapgs, pushf, popf, cli, sti, ... directly is fine. + * * di: new selector + * rax: scratch register * * Is in entry.text as it shouldn't be instrumented. + * + * Note: popf is slow, so use pushf to read IF and then execute cli/sti + * if necessary. */ SYM_FUNC_START(asm_load_gs_index) FRAME_BEGIN + pushf + pop %rax + andl $X86_EFLAGS_IF, %eax /* Interrupts enabled? */ + jz 1f + cli +1: swapgs .Lgs_change: ANNOTATE_NOENDBR // error_entry movl %edi, %gs 2: ALTERNATIVE "", "mfence", X86_BUG_SWAPGS_FENCE swapgs + testl %eax, %eax + jz 3f + sti +3: FRAME_END RET @@ -799,12 +815,12 @@ SYM_FUNC_START(asm_load_gs_index) swapgs /* switch back to user gs */ .macro ZAP_GS /* This can't be a string because the preprocessor needs to see it. */ - movl $__USER_DS, %eax - movl %eax, %gs + movl $__USER_DS, %edi + movl %edi, %gs .endm ALTERNATIVE "", "ZAP_GS", X86_BUG_NULL_SEG - xorl %eax, %eax - movl %eax, %gs + xorl %edi, %edi + movl %edi, %gs jmp 2b _ASM_EXTABLE(.Lgs_change, .Lbad_gs) diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h index a71d0e8d4684..6de00dec6564 100644 --- a/arch/x86/include/asm/special_insns.h +++ b/arch/x86/include/asm/special_insns.h @@ -124,11 +124,7 @@ extern asmlinkage void asm_load_gs_index(u16 selector); static inline void native_load_gs_index(unsigned int selector) { - unsigned long flags; - - local_irq_save(flags); asm_load_gs_index(selector); - local_irq_restore(flags); } static inline unsigned long __read_cr4(void) -- 2.34.1