Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4083909imu; Fri, 30 Nov 2018 10:41:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/VMhOK/Wy+EN6Qphw2JDJk7KdeGD8VrXBBv0WdbjNR799kLSMBfDPwM7iZgcmcV3VchRZkL X-Received: by 2002:a62:6385:: with SMTP id x127mr6750567pfb.15.1543603288446; Fri, 30 Nov 2018 10:41:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543603288; cv=none; d=google.com; s=arc-20160816; b=k3lNTjLWRlM4pZbEcLJHn6lcXuJtXTmw5j3QCTkTDyf/MLljEh9t1DXsbZGrn8ZLkN UryflopmjpHCDeor9TrI/kJSiEb8ZqwdUDYLevP/lT8zdWIEf3adJg3zS/LOMLBeh21q as0V87Sw5zruvi8eZBUp3lyi23AN1PRzi215Gsllu2iOI2GvELrJTMbyhgtrPR20ooo2 iwEDnVEuUv7FCTivTrmm6a7TaNnKRZMYRDOON0ec5ahzK4ieC4nqo7EaZVzEJvGkomY+ 3+wzGip4/vkP2NG4V5JFdpHxFOSglB9us0IaImiIbZ83Yaszy2QJjh0Vxtl9M9ygmFEV RGrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=z/P9HsG5yiYhmV38r5eyZNeFW4LJlDL/npTTmGlFtxg=; b=PH85gHAfR1O72gQt8pSGFMOp7/K3AdOglZbprLHJ/JL/mESQxaZFTjLMUe/rLX6YiI EerR7Lr0vTJ0Imaq792eEKVo/M1hhaGWN/dbNiMcoP+gulnKN1lnGg0JF/K5/do3qib4 9ZdlT4gwlZXeueAwLmsKSssx3Ak77KeVWpimb4k1sRsrGt63Xxi5tofRJSnL4WYmV4iV 4H/yJ45Jo1Cn/FotcnoZJ7XPmY9wrKvwKfVxyMAUW8k6uRjns0b/PNhr/NnOae+fZjnO 2/h1Ll2PnWo5ZjKHMKg4YVCiZ4Xcd6GH/Zq9JBcVG2t6LFg2V5ncQJf8ucxD/l+cH8I1 1V1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 41si5853993plf.347.2018.11.30.10.41.13; Fri, 30 Nov 2018 10:41:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726564AbeLAFtc (ORCPT + 99 others); Sat, 1 Dec 2018 00:49:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45250 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725817AbeLAFtc (ORCPT ); Sat, 1 Dec 2018 00:49:32 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 202AA3086268; Fri, 30 Nov 2018 18:39:21 +0000 (UTC) Received: from treble (ovpn-121-129.rdu2.redhat.com [10.10.121.129]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02FE1600C9; Fri, 30 Nov 2018 18:39:18 +0000 (UTC) Date: Fri, 30 Nov 2018 12:39:17 -0600 From: Josh Poimboeuf To: Andy Lutomirski Cc: Linus Torvalds , Steven Rostedt , Peter Zijlstra , X86 ML , LKML , Ard Biesheuvel , Ingo Molnar , Thomas Gleixner , Masami Hiramatsu , Jason Baron , Jiri Kosina , David Laight , Borislav Petkov , julia@ni.com, jeyu@kernel.org, "H. Peter Anvin" Subject: Re: [PATCH v2 4/4] x86/static_call: Add inline static call implementation for x86-64 Message-ID: <20181130183917.hxmti5josgq4clti@treble> References: <20181129124404.2fe55dd0@gandalf.local.home> <20181129125857.75c55b96@gandalf.local.home> <20181129134725.6d86ade6@gandalf.local.home> <20181129202452.56f4j2wdct6qbaqo@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 30 Nov 2018 18:39:21 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 30, 2018 at 08:42:26AM -0800, Andy Lutomirski wrote: > On Thu, Nov 29, 2018 at 12:24 PM Josh Poimboeuf wrote: > > > > > Alternatively, we could actually emulate call instructions like this: > > > > > > void __noreturn jump_to_kernel_pt_regs(struct pt_regs *regs, ...) > > > { > > > struct pt_regs ptregs_copy = *regs; > > > barrier(); > > > *(unsigned long *)(regs->sp - 8) = whatever; /* may clobber old > > > regs, but so what? */ > > > asm volatile ("jmp return_to_alternate_ptregs"); > > > } > > > > > > where return_to_alternate_ptregs points rsp to the ptregs and goes > > > through the normal return path. It's ugly, but we could have a test > > > case for it, and it should work fine. > > > > Is that really any better than my patch to create a gap in the stack > > (modified for kernel space #BP only)? > > > > I tend to prefer a nice local hack like mine over a hack that further > complicates the entry in general. This is not to say I'm thrilled by > my idea either. They're both mucking with the location of the pt_regs. The above code just takes that fact and hides it in the corner and hopes that there are no bugs lurking there. Even with the CPL check, the "gap" code is simple and self-contained (see below). The kernel pt_regs can already be anywhere on the stack so there should be no harm in moving them. AFAICT, all the other proposed options seem to have major issues. diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index ce25d84023c0..f487f7daed6c 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -876,7 +876,7 @@ apicinterrupt IRQ_WORK_VECTOR irq_work_interrupt smp_irq_work_interrupt * @paranoid == 2 is special: the stub will never switch stacks. This is for * #DF: if the thread stack is somehow unusable, we'll still get a useful OOPS. */ -.macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1 +.macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1 create_gap=1 ENTRY(\sym) UNWIND_HINT_IRET_REGS offset=\has_error_code*8 @@ -896,6 +896,18 @@ ENTRY(\sym) jnz .Lfrom_usermode_switch_stack_\@ .endif +#ifdef CONFIG_HAVE_STATIC_CALL_INLINE + .if \create_gap == 1 + testb $3, CS-ORIG_RAX(%rsp) + jnz .Lfrom_usermode_no_gap_\@ + .rept 6 + pushq 5*8(%rsp) + .endr + UNWIND_HINT_IRET_REGS offset=8 +.Lfrom_usermode_no_gap_\@: + .endif +#endif + .if \paranoid call paranoid_entry .else @@ -1126,7 +1138,7 @@ apicinterrupt3 HYPERV_STIMER0_VECTOR \ #endif /* CONFIG_HYPERV */ idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK -idtentry int3 do_int3 has_error_code=0 +idtentry int3 do_int3 has_error_code=0 create_gap=1 idtentry stack_segment do_stack_segment has_error_code=1 #ifdef CONFIG_XEN_PV