From patchwork Fri Oct 13 11:18:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 152503 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1815165vqb; Fri, 13 Oct 2023 04:18:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErpaMRBeDoLip4ng7fwNkoPOPk6y5MGjZeBn4mgn5QRtA7nLll3git8tiHtFobqHvHfo+h X-Received: by 2002:a17:90b:3b50:b0:27d:1593:2b0b with SMTP id ot16-20020a17090b3b5000b0027d15932b0bmr5704648pjb.0.1697195936723; Fri, 13 Oct 2023 04:18:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697195936; cv=none; d=google.com; s=arc-20160816; b=oPrIA9pTyQsg0PGOGFTiasFGpllh6PDgrtJkNFKRnGJU68aruGMuZQGyHbziRl5J0z rs/ruHYPnzd29E5JNon9o5fOWlpesYt6RFh0LXQcEnDXif13hrrpJbEx6xaFpvSrArd5 M4+Xqfw2bQbeGQSMTrK/Sblsm6wbgkQnojB2xGUAShbIEl5I6db98rN1apVmtW7jkt/G 87XLyCmugXgoypaPHR+PZdlj2t0cjrLehs0VmgqyGWwfqw85Fl0S90wnB4Z8vUIwQxaZ RYPSlG56fX+zeBMQoLddgpAOBjtuQyMBGDvsTRuCftiUsb7EacdHnVUn+LMJb7/x5rbs SQ4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=ubTp/0jO7M8gTlbN18aXMtPlK8oLH70xqfq1ZuyfzV0=; fh=rgFuo364X/bMod36etsfjmew4T/qgY2GNOeHFq2LY2k=; b=Sk/zbPFeb8d5mRNZ9OajhUu0PCpRTfNnEVA3Ghpvfux6HkCNGdSquKugII4Dc3gWxB VtIIwulhioHiyg/cTOL3i9OxGubpkriYfpkulE/mAZc/QC8a4xjrmI1UKNlG+4SkD7Tj qADuli4RKjuP7ivifrjrDZKxNemqkLHcfIciwTwQ88zcIn1tHGhUuSwDGGvXnp5vIwE2 PkaNDOi1aKPGriNNLR1mQkA+BlpLrg52iP/uZe6zWXSPXJqV3p4hrcdtjOqyhCqAoJmh nERS29tdG7TKyT7NvfXwEP/E7l47G4eHaFYzcgeE4bWiA8qnefuCtYBHyD586G9tTlSr T44g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pJfk1kwC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=QXu+iRrS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id i62-20020a638741000000b005638dc9751csi1381952pge.0.2023.10.13.04.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:18:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=pJfk1kwC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=QXu+iRrS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 091B48242F69; Fri, 13 Oct 2023 04:18:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230515AbjJMLSd (ORCPT + 19 others); Fri, 13 Oct 2023 07:18:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230441AbjJMLSc (ORCPT ); Fri, 13 Oct 2023 07:18:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BCE3B7; Fri, 13 Oct 2023 04:18:29 -0700 (PDT) Date: Fri, 13 Oct 2023 11:18:26 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697195907; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ubTp/0jO7M8gTlbN18aXMtPlK8oLH70xqfq1ZuyfzV0=; b=pJfk1kwCXhmY/6CLtV4kbtgrs8nBymXpcmBimvVYVwoNgrYQyzJjEq0DGs4EnPdjBkSMRT 3N64rBsd7kwUyygrhM0x1cbZbo6m2FivDYAwRkx4xyAwUHZxekTzs1TloKNTmit95ztfg9 E0HVH88wibWqH3w41pL9UDA/WaggpQh0B4+x3pg40mHWW6lhUOgiiy/sjJ2nd2/bGww6wI mibgRAD+fWLVmlhPTSA7a9vHwaaWdFDI69vcQ5MvMWT46At8C7z24Dudre3UhKiKsyXMeQ gzoKw38CHUXOT6EP98Iy7eIW2wk+UusXIUI8mXqxv6olAOzVCdTsq8HI2dlEdg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697195907; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ubTp/0jO7M8gTlbN18aXMtPlK8oLH70xqfq1ZuyfzV0=; b=QXu+iRrSRdi8ennv6D94GeiGdaq5KC/H7eAK48l7ElfTM2HpFH+t9sCPugC7OLiHVb1Ylj RhVgNa7jI82/DqDg== From: "tip-bot2 for Brian Gerst" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/entry] x86/entry/32: Clean up syscall fast exit tests Cc: Brian Gerst , Ingo Molnar , Andy Lutomirski , Borislav Petkov , Denys Vlasenko , "H. Peter Anvin" , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Josh Poimboeuf , Uros Bizjak , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231011224351.130935-4-brgerst@gmail.com> References: <20231011224351.130935-4-brgerst@gmail.com> MIME-Version: 1.0 Message-ID: <169719590633.3135.1644131863421264861.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 13 Oct 2023 04:18:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779500862552049100 X-GMAIL-MSGID: 1779638926474111078 The following commit has been merged into the x86/entry branch of tip: Commit-ID: 1a09a27153f91cd7676b2d4ca574577572a8c999 Gitweb: https://git.kernel.org/tip/1a09a27153f91cd7676b2d4ca574577572a8c999 Author: Brian Gerst AuthorDate: Wed, 11 Oct 2023 18:43:51 -04:00 Committer: Ingo Molnar CommitterDate: Fri, 13 Oct 2023 13:05:28 +02:00 x86/entry/32: Clean up syscall fast exit tests Merge compat and native code and clarify comments. No change in functionality expected. Signed-off-by: Brian Gerst Signed-off-by: Ingo Molnar Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Josh Poimboeuf Cc: Uros Bizjak Link: https://lore.kernel.org/r/20231011224351.130935-4-brgerst@gmail.com --- arch/x86/entry/common.c | 48 ++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 4c7154d..d813160 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -255,34 +255,30 @@ __visible noinstr bool do_fast_syscall_32(struct pt_regs *regs) if (!__do_fast_syscall_32(regs)) return false; -#ifdef CONFIG_X86_64 /* - * Opportunistic SYSRETL: if possible, try to return using SYSRETL. - * SYSRETL is available on all 64-bit CPUs, so we don't need to - * bother with SYSEXIT. - * - * Unlike 64-bit opportunistic SYSRET, we can't check that CX == IP, - * because the ECX fixup above will ensure that this is essentially - * never the case. + * Check that the register state is valid for using SYSRETL/SYSEXIT + * to exit to userspace. Otherwise use the slower but fully capable + * IRET exit path. */ - return regs->cs == __USER32_CS && regs->ss == __USER_DS && - regs->ip == landing_pad && - (regs->flags & (X86_EFLAGS_RF | X86_EFLAGS_TF)) == 0; -#else - /* - * Opportunistic SYSEXIT: if possible, try to return using SYSEXIT. - * - * Unlike 64-bit opportunistic SYSRET, we can't check that CX == IP, - * because the ECX fixup above will ensure that this is essentially - * never the case. - * - * We don't allow syscalls at all from VM86 mode, but we still - * need to check VM, because we might be returning from sys_vm86. - */ - return regs->cs == __USER_CS && regs->ss == __USER_DS && - regs->ip == landing_pad && - (regs->flags & (X86_EFLAGS_RF | X86_EFLAGS_TF | X86_EFLAGS_VM)) == 0; -#endif + + /* XEN PV guests always use the IRET path */ + if (cpu_feature_enabled(X86_FEATURE_XENPV)) + return false; + + /* EIP must point to the VDSO landing pad */ + if (unlikely(regs->ip != landing_pad)) + return false; + + /* CS and SS must match the values set in MSR_STAR */ + if (unlikely(regs->cs != __USER32_CS || regs->ss != __USER_DS)) + return false; + + /* If the TF, RF, or VM flags are set, use IRET */ + if (unlikely(regs->flags & (X86_EFLAGS_RF | X86_EFLAGS_TF | X86_EFLAGS_VM))) + return false; + + /* Use SYSRETL/SYSEXIT to exit to userspace */ + return true; } /* Returns true to return using SYSEXIT/SYSRETL, or false to use IRET */