Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4027207pxb; Tue, 26 Jan 2021 10:25:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxYN9il0BxShMMJxm9swJI6/7NqwaHwAXihB0y4nnLL1031PC5eILcFbDwqwFuTQbj6nBS X-Received: by 2002:a17:906:d8b4:: with SMTP id qc20mr4433360ejb.451.1611685524155; Tue, 26 Jan 2021 10:25:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611685524; cv=none; d=google.com; s=arc-20160816; b=rKu0jmKOD/WAvw/lqhM84cmoMuQVvbcWCiZRwoQ+rWT+DP66QoEo7MJ2dvMPFOoMmF GJK5Y9DhSOAZrNWTIiybN5Qi0y/veRwUPzkxIuzKkIzfasX1AkGk0MYTkoY+gy5Ur6Im 29iqvEBAPXyMK7JjJYCRf2UwyyjmV9gf8177VIB0lzGSQiBoD5mQzFbDTIxdnZKuOqAu xhAU4z6xAZwSgJ4u4RBeJKvFnqbplHocnSfiY4GWQRug+xFqgVR/jIldf4qGiR0eDfcG UssdA0hjcpX4141qwq/R3UoFRATeZ1jocGbG2VAP+RPHRwcS026UqQhvBVjtuo1w1s0f CeXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=TI7tBuRKs0bg8oWuQR5b13Rx640yWYP+vhA5wC5N43E=; b=k5+RcWN7tBWk+cSRpj9wMjrVv/VHq+fOnDhl4R/HB1rnuK5sM/Sv+3zh/CZSLchkCq Nl2/AfVudvRFxKINQeOCkzFPSs4OdakZ7qeU6pbCjhLA41bbF8SaYGV49oZ8rrR74WI/ ZZpMpllA1gKA6XtGKr0uQZf2NiAjyMXokc+axuFPP8mm1tEHVD5jpkoeZifVvu8Ruo1C UUGXF0eL+HDN816m/nfD5rfUbA3NB+aVoPaHj4Y/5lN7ISCLK+c2PP6znBvPQHUrJ1/3 z5lFzVIiryJXA5hG1+86VHHG8vB9sf0JIITJiqF14DDdsQ/uuRRqhTD6GmxjmqSUFaak ZZrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="WPte/Rxo"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o16si7328742ejr.715.2021.01.26.10.24.57; Tue, 26 Jan 2021 10:25:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="WPte/Rxo"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404966AbhAZLFD (ORCPT + 99 others); Tue, 26 Jan 2021 06:05:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727316AbhAZGFm (ORCPT ); Tue, 26 Jan 2021 01:05:42 -0500 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCE1EC061573 for ; Mon, 25 Jan 2021 22:05:00 -0800 (PST) Received: by mail-io1-xd2f.google.com with SMTP id y19so31515187iov.2 for ; Mon, 25 Jan 2021 22:05:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TI7tBuRKs0bg8oWuQR5b13Rx640yWYP+vhA5wC5N43E=; b=WPte/RxocovDgITuE7OvzROaSfhW2YqEZkaJJ4m3+e4JC9GHNG6hCh6kbEUL5J1qJQ 4SwXITpc+sInBlGgYDGPpfoURkYqd1TpenN/LVRO+mV1weSltrzCRiPS1vIbRHeSsHLy e25emuhUm0jRIglzmoSDagkprj9W3u/IZ9V349rCZvl24Wfl3Ax7xyjtYQUOzTe34lyq pMGdtzJckfe4eEYdSwY9utH/LuXmtFlcbRIZne1JjIXplYG0kwucnpgufsALUOuOBQWE SfxA/By6N1SYyLbYgJS0KQt+nhY0n/S0XYN8pJQwmOQOUmZK5PSUUAAe2OqqbKXE0Bzu 8QQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TI7tBuRKs0bg8oWuQR5b13Rx640yWYP+vhA5wC5N43E=; b=IflLmf14JYO2E1RElkjVMFKAG9Hlgm9cIC9/xuknGtu7/MdxFFKEnT+rGvHrsuXXEW s0jpjSKREjb2mUAugifXKcJAzhwI0RhC3SOQN7iWzaqytI4zzxcG9n9JX/FXRmPGe9Qk Egy+aYB1tfg2rxF45uE/EOvIHLXA6EU3wYO+F809r6++9VKllAloo0JJWhTzF4KyiFLX S8NLxpP/kYlUmY/PLIo9QJXFpBvreGmJiRlxQJordvy5fP0OtbC2hJnfXUMm2dro5iJX FRTp9cEpSb9QJPnvEPFqoedKokAYY7Q5qRRo3b/ibs6cSB2XBkdtPcLE3ygQEgPKdpBP 7WXA== X-Gm-Message-State: AOAM533HSSYCx+2p8giE86pAW8Ja5dCS8NvSfdgQHwzIVXKstxyoGcfp JlKUrphMUuykGrNmUFLSmigVqPoJJM0On2ivcQ== X-Received: by 2002:a05:6602:2dcd:: with SMTP id l13mr3030002iow.40.1611641100227; Mon, 25 Jan 2021 22:05:00 -0800 (PST) MIME-Version: 1.0 References: <20210125173444.22696-1-jiangshanlai@gmail.com> <20210125173444.22696-4-jiangshanlai@gmail.com> In-Reply-To: <20210125173444.22696-4-jiangshanlai@gmail.com> From: Brian Gerst Date: Tue, 26 Jan 2021 01:04:48 -0500 Message-ID: Subject: Re: [PATCH V2 3/6] x86_32/sysenter: switch to the task stack without emptying the entry stack To: Lai Jiangshan Cc: Linux Kernel Mailing List , Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "the arch/x86 maintainers" , "H. Peter Anvin" , Dave Hansen , Peter Zijlstra , Al Viro , Vincenzo Frascino , Joerg Roedel , Ricardo Neri , Reinette Chatre , Andrew Morton , Gabriel Krisman Bertazi , Kees Cook , Frederic Weisbecker , Jens Axboe , Arvind Sankar , Ard Biesheuvel , Andi Kleen , Mike Rapoport , Mike Hommey , Mark Gross , Fenghua Yu , Tony Luck , Anthony Steinhauser , Jay Lang , "Chang S. Bae" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 25, 2021 at 11:35 AM Lai Jiangshan wrote: > > From: Lai Jiangshan > > Like the way x86_64 uses the "old" stack, we can save the entry stack > pointer to a register and switch to the task stack. So that we have > space on the "old" stack to save more things or scratch registers. > > Signed-off-by: Lai Jiangshan > --- > arch/x86/entry/entry_32.S | 11 +++++------ > 1 file changed, 5 insertions(+), 6 deletions(-) > > diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S > index 3b4d1a63d1f0..4513702ba45d 100644 > --- a/arch/x86/entry/entry_32.S > +++ b/arch/x86/entry/entry_32.S > @@ -905,19 +905,18 @@ SYM_FUNC_START(entry_SYSENTER_32) > pushl %eax > BUG_IF_WRONG_CR3 no_user_check=1 > SWITCH_TO_KERNEL_CR3 scratch_reg=%eax > - popl %eax > - popfl > > - /* Stack empty again, switch to task stack */ > - movl TSS_entry2task_stack(%esp), %esp > + /* Switch to task stack */ > + movl %esp, %eax > + movl (2*4+TSS_entry2task_stack)(%esp), %esp > > .Lsysenter_past_esp: > pushl $__USER_DS /* pt_regs->ss */ > pushl $0 /* pt_regs->sp (placeholder) */ > - pushfl /* pt_regs->flags (except IF = 0) */ > + pushl 4(%eax) /* pt_regs->flags (except IF = 0) */ __KERNEL_DS isn't loaded at this point, so this needs an explicit %ss: override. You probably didn't catch this because the default __USER_DS was still loaded. > pushl $__USER_CS /* pt_regs->cs */ > pushl $0 /* pt_regs->ip = 0 (placeholder) */ > - pushl %eax /* pt_regs->orig_ax */ > + pushl (%eax) /* pt_regs->orig_ax */ Add an %ss: override here too. > SAVE_ALL pt_regs_ax=$-ENOSYS /* save rest, stack already switched */ > > /* > -- > 2.19.1.6.gb485710b > -- Brian Gerst