Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp242972pxb; Wed, 20 Apr 2022 21:28:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxqj4+68PsXaRNrAtiLJC/jqArH4k29A5IRf4GPHNeD7O319h5oXbw3Vr+nuw80TbWfBiR X-Received: by 2002:a17:902:d2d2:b0:159:118:e10e with SMTP id n18-20020a170902d2d200b001590118e10emr17016327plc.102.1650515303096; Wed, 20 Apr 2022 21:28:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650515303; cv=none; d=google.com; s=arc-20160816; b=iwonjD3ECm7JJdE1Zpx4FITdp1aHoxJk1XSEmfjhig+QqgZuPx+9O9oS4YN7vbpdF9 Qz2CVm0Jn1QrP76XHHxuKaw6B+LMvthZu/5QfTppW6N6aO2NKYZ5IzrH+BA1SrhRYiFs IChWdbsLMQz95lPzR5rx5pTvKUVZB9a684qdjAe/9H9SVkfjnxu8dUgJHzdlvE35zmVe CeRYTl2fxTPGshlymP6vUbSq2k7CgpVRO+wkjU3XXUR9id1EBXzlEFWfQB70H1cCaXB1 /XSbnJA8K60sePh7sAs+9RCVaVITn1XJJWGb3Qytn4r/xdR1iEUxxY0taEkYv7tbIz+P 0pqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:dkim-signature; bh=/YcLEeHXGnvW3CkeUBahwEkpTt5m20IOkz4c7VfxhOY=; b=E5MMCprKVfiN02AEUaxinnlNK6cEli9y2BFe6C4YNTyT3I0OxMvbzwPqBJ9ZwfQt+k SqmGsQGzZT1b9LeBr2IbCetjJa3K5DdXwBubMfcNxI2MAzDF8SWJLSesrMeUAWD+LuSV wv1I2jIqwm9159pyjc5b17cEuonllzrAnfsyP86uDYmkghauiqN4AE1Vn2ZDSAENO0oq uwaynltxW1soVwJ97qK9hGtWKLE5USqsG1aZk0A96CIutCrutIpz14SrOFjGXhgXSZgS FSCLNTH4n9she3VH2uIXYFNVICr1di+dJ1TqWLZepJ2768rJveNjCHISNtsZEQd+klA7 1s9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uVJ6QTXo; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020a056a00078500b005060ce352e8si3843944pfu.171.2022.04.20.21.27.36; Wed, 20 Apr 2022 21:28:23 -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=@kernel.org header.s=k20201202 header.b=uVJ6QTXo; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379668AbiDTOaJ (ORCPT + 99 others); Wed, 20 Apr 2022 10:30:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231538AbiDTOaH (ORCPT ); Wed, 20 Apr 2022 10:30:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8DA1443DC for ; Wed, 20 Apr 2022 07:27:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 12622B81EB2 for ; Wed, 20 Apr 2022 14:27:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E809C385A4; Wed, 20 Apr 2022 14:27:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650464837; bh=kRue8UYppimeZ4GCFiUVzoXvs5yFCMygQF0LIsQLeBU=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=uVJ6QTXoD8T0flzb1kO3j4UkGVDSwdkUWh7cNrIn8cqn9yPUcr/8XQRWNgAMocIHv GbAf8bRh2IZjeLBcivAV0WuC/L5cu1Yd2uksDlSN/T8LYzSQ4Q+tgcTX9cQx1jzmFS bsjs49RHMvtVg/OfWRzRXAYwx99RmzpNruwYpxk2fCWNU9+vVxPchX9XCOFliYTGEI JezZj4xDUqbgsIkYsaEbWu6Da9KMCjpe93Fofh1mrakoCGTEYEju5l9N7dZo2dKB2G wCidG2BcXqG+ieijRHbzWpWd6UbaeW1W2DnNLe3E5xWg/AvRli3QwEvfMd0nGXG+lH OJ0M8lnLKv4WQ== Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 25FC927C0054; Wed, 20 Apr 2022 10:27:16 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute2.internal (MEProxy); Wed, 20 Apr 2022 10:27:16 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrtddtgdehvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdetnhgu hicunfhuthhomhhirhhskhhifdcuoehluhhtoheskhgvrhhnvghlrdhorhhgqeenucggtf frrghtthgvrhhnpeffveffudegfeeguefgvdetteehfeekhedufefhveefhfehgeelffel gefhkeetkeenucffohhmrghinheptghomhhprghtrdhssgenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhguhidomhgvshhmthhprghuthhh phgvrhhsohhnrghlihhthidqudduiedukeehieefvddqvdeifeduieeitdekqdhluhhtoh eppehkvghrnhgvlhdrohhrgheslhhinhhugidrlhhuthhordhush X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 84B6321E0073; Wed, 20 Apr 2022 10:27:15 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-568-g521196dd5d-fm-20220414.001-g521196dd Mime-Version: 1.0 Message-Id: In-Reply-To: <20220419205241.339242797@infradead.org> References: <20220419204109.520779286@infradead.org> <20220419205241.339242797@infradead.org> Date: Wed, 20 Apr 2022 07:26:54 -0700 From: "Andy Lutomirski" To: "Peter Zijlstra (Intel)" , "the arch/x86 maintainers" , "Josh Poimboeuf" , "Brian Gerst" , "Lai Jiangshan" , "Andrew Cooper" Cc: "Linux Kernel Mailing List" Subject: Re: [PATCH 2/2] x86,entry: Use PUSH_AND_CLEAR_REGS for compat Content-Type: text/plain X-Spam-Status: No, score=-7.7 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_PASS 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 On Tue, Apr 19, 2022, at 1:41 PM, Peter Zijlstra wrote: > Since the upper regs don't exist for ia32 code, preserving them > doesn't hurt and it simplifies the code. They exist for compat code, though, and should be preserved for ABI purposes. Programs that do int $0x80 in 64-bit code do exist. > > Signed-off-by: Peter Zijlstra (Intel) > --- > arch/x86/entry/calling.h | 9 ++-- > arch/x86/entry/entry_64_compat.S | 87 +-------------------------------------- > 2 files changed, 8 insertions(+), 88 deletions(-) > > --- a/arch/x86/entry/calling.h > +++ b/arch/x86/entry/calling.h > @@ -63,13 +63,15 @@ For 32-bit we have the following convent > * for assembly code: > */ > > -.macro PUSH_REGS rdx=%rdx rax=%rax save_ret=0 > +.macro PUSH_REGS rdx=%rdx rax=%rax save_ret=0 save_rdi=1 > .if \save_ret > pushq %rsi /* pt_regs->si */ > movq 8(%rsp), %rsi /* temporarily store the return address in %rsi */ > movq %rdi, 8(%rsp) /* pt_regs->di (overwriting original return address) */ > .else > + .if \save_rdi > pushq %rdi /* pt_regs->di */ > + .endif > pushq %rsi /* pt_regs->si */ > .endif > pushq \rdx /* pt_regs->dx */ > @@ -111,11 +113,10 @@ For 32-bit we have the following convent > xorl %r13d, %r13d /* nospec r13 */ > xorl %r14d, %r14d /* nospec r14 */ > xorl %r15d, %r15d /* nospec r15 */ > - > .endm > > -.macro PUSH_AND_CLEAR_REGS rdx=%rdx rax=%rax save_ret=0 > - PUSH_REGS rdx=\rdx, rax=\rax, save_ret=\save_ret > +.macro PUSH_AND_CLEAR_REGS rdx=%rdx rax=%rax save_ret=0 save_rdi=1 > + PUSH_REGS rdx=\rdx, rax=\rax, save_ret=\save_ret save_rdi=\save_rdi > CLEAR_REGS > .endm > > --- a/arch/x86/entry/entry_64_compat.S > +++ b/arch/x86/entry/entry_64_compat.S > @@ -83,32 +83,7 @@ SYM_INNER_LABEL(entry_SYSENTER_compat_af > movl %eax, %eax > > pushq %rax /* pt_regs->orig_ax */ > - pushq %rdi /* pt_regs->di */ > - pushq %rsi /* pt_regs->si */ > - pushq %rdx /* pt_regs->dx */ > - pushq %rcx /* pt_regs->cx */ > - pushq $-ENOSYS /* pt_regs->ax */ > - pushq $0 /* pt_regs->r8 = 0 */ > - xorl %r8d, %r8d /* nospec r8 */ > - pushq $0 /* pt_regs->r9 = 0 */ > - xorl %r9d, %r9d /* nospec r9 */ > - pushq $0 /* pt_regs->r10 = 0 */ > - xorl %r10d, %r10d /* nospec r10 */ > - pushq $0 /* pt_regs->r11 = 0 */ > - xorl %r11d, %r11d /* nospec r11 */ > - pushq %rbx /* pt_regs->rbx */ > - xorl %ebx, %ebx /* nospec rbx */ > - pushq %rbp /* pt_regs->rbp (will be overwritten) */ > - xorl %ebp, %ebp /* nospec rbp */ > - pushq $0 /* pt_regs->r12 = 0 */ > - xorl %r12d, %r12d /* nospec r12 */ > - pushq $0 /* pt_regs->r13 = 0 */ > - xorl %r13d, %r13d /* nospec r13 */ > - pushq $0 /* pt_regs->r14 = 0 */ > - xorl %r14d, %r14d /* nospec r14 */ > - pushq $0 /* pt_regs->r15 = 0 */ > - xorl %r15d, %r15d /* nospec r15 */ > - > + PUSH_AND_CLEAR_REGS rax=$-ENOSYS > UNWIND_HINT_REGS > > cld > @@ -225,35 +200,7 @@ SYM_INNER_LABEL(entry_SYSCALL_compat_saf > SYM_INNER_LABEL(entry_SYSCALL_compat_after_hwframe, SYM_L_GLOBAL) > movl %eax, %eax /* discard orig_ax high bits */ > pushq %rax /* pt_regs->orig_ax */ > - pushq %rdi /* pt_regs->di */ > - pushq %rsi /* pt_regs->si */ > - xorl %esi, %esi /* nospec si */ > - pushq %rdx /* pt_regs->dx */ > - xorl %edx, %edx /* nospec dx */ > - pushq %rbp /* pt_regs->cx (stashed in bp) */ > - xorl %ecx, %ecx /* nospec cx */ > - pushq $-ENOSYS /* pt_regs->ax */ > - pushq $0 /* pt_regs->r8 = 0 */ > - xorl %r8d, %r8d /* nospec r8 */ > - pushq $0 /* pt_regs->r9 = 0 */ > - xorl %r9d, %r9d /* nospec r9 */ > - pushq $0 /* pt_regs->r10 = 0 */ > - xorl %r10d, %r10d /* nospec r10 */ > - pushq $0 /* pt_regs->r11 = 0 */ > - xorl %r11d, %r11d /* nospec r11 */ > - pushq %rbx /* pt_regs->rbx */ > - xorl %ebx, %ebx /* nospec rbx */ > - pushq %rbp /* pt_regs->rbp (will be overwritten) */ > - xorl %ebp, %ebp /* nospec rbp */ > - pushq $0 /* pt_regs->r12 = 0 */ > - xorl %r12d, %r12d /* nospec r12 */ > - pushq $0 /* pt_regs->r13 = 0 */ > - xorl %r13d, %r13d /* nospec r13 */ > - pushq $0 /* pt_regs->r14 = 0 */ > - xorl %r14d, %r14d /* nospec r14 */ > - pushq $0 /* pt_regs->r15 = 0 */ > - xorl %r15d, %r15d /* nospec r15 */ > - > + PUSH_AND_CLEAR_REGS rax=$-ENOSYS > UNWIND_HINT_REGS > > movq %rsp, %rdi > @@ -381,35 +328,7 @@ SYM_CODE_START(entry_INT80_compat) > pushq 1*8(%rdi) /* regs->orig_ax */ > pushq (%rdi) /* pt_regs->di */ > .Lint80_keep_stack: > - > - pushq %rsi /* pt_regs->si */ > - xorl %esi, %esi /* nospec si */ > - pushq %rdx /* pt_regs->dx */ > - xorl %edx, %edx /* nospec dx */ > - pushq %rcx /* pt_regs->cx */ > - xorl %ecx, %ecx /* nospec cx */ > - pushq $-ENOSYS /* pt_regs->ax */ > - pushq %r8 /* pt_regs->r8 */ > - xorl %r8d, %r8d /* nospec r8 */ > - pushq %r9 /* pt_regs->r9 */ > - xorl %r9d, %r9d /* nospec r9 */ > - pushq %r10 /* pt_regs->r10*/ > - xorl %r10d, %r10d /* nospec r10 */ > - pushq %r11 /* pt_regs->r11 */ > - xorl %r11d, %r11d /* nospec r11 */ > - pushq %rbx /* pt_regs->rbx */ > - xorl %ebx, %ebx /* nospec rbx */ > - pushq %rbp /* pt_regs->rbp */ > - xorl %ebp, %ebp /* nospec rbp */ > - pushq %r12 /* pt_regs->r12 */ > - xorl %r12d, %r12d /* nospec r12 */ > - pushq %r13 /* pt_regs->r13 */ > - xorl %r13d, %r13d /* nospec r13 */ > - pushq %r14 /* pt_regs->r14 */ > - xorl %r14d, %r14d /* nospec r14 */ > - pushq %r15 /* pt_regs->r15 */ > - xorl %r15d, %r15d /* nospec r15 */ > - > + PUSH_AND_CLEAR_REGS save_rdi=0 > UNWIND_HINT_REGS > > cld