From patchwork Thu Oct 13 20:01:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 2356 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp465466wrs; Thu, 13 Oct 2022 13:25:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5SMM2hTzQi6gbG0+xpoxtW2OO+yNd1wHYymWeJ5mvzI9bTpZ/xgGUwUT208V32jdlnOr0A X-Received: by 2002:a17:902:b942:b0:178:be25:203f with SMTP id h2-20020a170902b94200b00178be25203fmr1750786pls.101.1665692730549; Thu, 13 Oct 2022 13:25:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665692730; cv=none; d=google.com; s=arc-20160816; b=YVnmAlN+ZmYy+9xdmyj2DSODWMUa1faohKzPfuguEUz7Vce6N+2MINpWXEgoLobjPG 96hy8M/PDdUEVEexn25yh84/KYZKWjap+muJWL1jJxAqS2QvrL7SR+l1oB2BRNqRGzXA O5QcYtznmowlrGhWw/B7r4oM4xxnkexynHNN0t2U3ka+UXOH71tmxRt1nNeCQ5IGeuBS pK0Euehwkp1+DLlyLuykNKiV5VfswPsTZ7l8LSdbXB3QbaozVMua2qkGHdhiSQxXXVHj TsTWREHACJQRkPa7yO66jQKk6LA6xFXU1C7WkNwiYiFVhXRd78trq3RS0svKMJLQQ10M gjqA== 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=sY1XVGgLxxl9SntezX7l2CICivZnP5hseGipSGLmjmjO9t52VWRMUHrOlbelgmicMe qNseo0l7m5q/Nb052Zl1BmS4QUoqUu4un5KQ2oQf0GHiyrYZqWlK/Dz4etmHv8gmg/Oo AUe0vlqdxYto2+eXqEq4lvcOtGrV4TP/r4lJPArMDBuJylKyQQhTDHUJxN1C8E5/Spai csl9Cll9IvTNXQynAULvsLwY9TbaIDKAfc8azT6zOksX5TTK6ssCbbmIddtSDrfK+SNZ /qMQtt88ywIgqVUbW6Q4bqk4onfXJlAHA1wlMPnqXrZmhZM9GwFPbeqIIckfGJEPVihU pjWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JXX3Y2FF; 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 b10-20020a170902d88a00b00174e6274906si711444plz.236.2022.10.13.13.25.14; Thu, 13 Oct 2022 13:25:30 -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=JXX3Y2FF; 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 S229925AbiJMUX6 (ORCPT + 99 others); Thu, 13 Oct 2022 16:23:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbiJMUXc (ORCPT ); Thu, 13 Oct 2022 16:23:32 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 875C4159D56 for ; Thu, 13 Oct 2022 13:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665692611; x=1697228611; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UaC8ceQnideTemOSR0AnD9gGv296yv6KtEQKYgHeIg4=; b=JXX3Y2FFoP7rZrS57moacsUWRCz3WxJ7dE23q0R56fqYpT9jGyGh+udN wKz60Q3om83n0nhW1FGu1qG5PyIDiq5r1B8yH17zb9WCoKMZdwEugDKQp 9swTWY7eDf3u8tHNzTGNbWVqLHLrMkKJ3xbhuxaXyu/WhjeFw1sS1WAVm +NY+eoPI2Z8QhSyAWDj0mSyXpyMB2TGUN5EI8ysjlPkLqzMTqHw9Ww66O ulDbfyQc12nUhf0/N0vBilzzretaj+eFFGd3zHb0Bc9PXgikH7qS4ndML i5kaYoTJiNgbzGmvGzYhGOWMlsMgNShiY12U9tefnNouA4EuADT7j8etR g==; X-IronPort-AV: E=McAfee;i="6500,9779,10499"; a="302808968" X-IronPort-AV: E=Sophos;i="5.95,182,1661842800"; d="scan'208";a="302808968" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2022 13:23:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10499"; a="690271049" X-IronPort-AV: E=Sophos;i="5.95,182,1661842800"; d="scan'208";a="690271049" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga008.fm.intel.com with ESMTP; 13 Oct 2022 13:23:27 -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, peterz@infradead.org, brgerst@gmail.com, chang.seok.bae@intel.com Subject: [PATCH v3 4/6] x86/gsseg: move local_irq_save/restore() into asm_load_gs_index() Date: Thu, 13 Oct 2022 13:01:32 -0700 Message-Id: <20221013200134.1487-5-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013200134.1487-1-xin3.li@intel.com> References: <20221013200134.1487-1-xin3.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1746605420715235638?= X-GMAIL-MSGID: =?utf-8?q?1746605420715235638?= 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)