Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp883172rdg; Fri, 13 Oct 2023 04:19:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/ZMG+5VCfzuIdCJsFQ6/Q3dQUZL0k/IQKJNOQACKhXjS0r5b0LfKJE7jTrP7S9nyRJAhI X-Received: by 2002:a17:90a:1c0f:b0:263:f521:da3e with SMTP id s15-20020a17090a1c0f00b00263f521da3emr36559146pjs.2.1697195941232; Fri, 13 Oct 2023 04:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697195941; cv=none; d=google.com; s=arc-20160816; b=Iam3MFtaw5zKhqBrwpaRbs2qLNPNGd4jlDHqWf52DwIjRscRtCSijx75q985MMVZyP 5CkZNARhwuGLAqqXwNAlSla5gKCnmdI8kkbJjQ1y/+Hcc+f1QwkPkET8b0J9Hz81PYQJ zbMp6s1mH4FZFsXS9zeH7b70IPIL6Gfjw3c5scSadpcPhpmi5y5IAkDmc0w90yP/awt/ /VMLW5PGFavB75QvHYtRekDvzELzKjsuUVMXkWsDp4fTIFnYDVHgk4d6974FKaQ95Dc9 IpulL4f8dqIaS38Hl3pbbV6GMoY4cb3MsuZQxWNO2pPW0hZWcY/kd/maacEAE4h88BbC jDaw== 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:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id k18-20020a170902c41200b001c9ca0167e2si4062181plk.420.2023.10.13.04.19.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:19:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; 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:6 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 pete.vger.email (Postfix) with ESMTP id F0D0483A0C23; Fri, 13 Oct 2023 04:18:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230486AbjJMLSd (ORCPT + 99 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 pete.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 (pete.vger.email [0.0.0.0]); Fri, 13 Oct 2023 04:18:58 -0700 (PDT) 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 */