Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp79944imu; Mon, 26 Nov 2018 08:11:21 -0800 (PST) X-Google-Smtp-Source: AFSGD/WWEsQpcsdipEkhxWSg5NHxWbChL36WbFHFWH9+X7dgwaSCPZF62FuIWOmKbOD5y9+I7AdC X-Received: by 2002:a17:902:8ec9:: with SMTP id x9mr28923935plo.27.1543248681138; Mon, 26 Nov 2018 08:11:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543248681; cv=none; d=google.com; s=arc-20160816; b=gPErpKNXtWz1aq1D+cGnMTZkCxfcX9kELAJUDl0bWbBZtGTVnvWwKq7kUCXgS8qMsx 48jkNslfia5z8jyL3um2CyGBY+ttLhcNNvvqzuPnWxlGXS+qCxEbk8HlSWB5k6VLpAbE ArgSZb2gR05Blj+Gihr98LrNowXX0uDsyu6TYQsal/lDrVExdJlGfDignRhmMeAsdt9S 5RIamkhlpBcYuijhoRJzWVsd4KzgQqoMRb5rFEMBfy4thdisE+5H8jYL7M2+psEJa/eu j1IXzjUSBdljljUi9RQ+sBMZp9KSaQcghQtaBffcUQsf1vS0lYu/K/2oZi5YFwq6C3lA JY0A== 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:dkim-signature; bh=VsTCm5zE3RpQJBZbC8onKGQcf6Oja50LKgsJ8cRfa9s=; b=hz7ePkpxaCj15K8qgCG94nooyeo1fqD3W2Qi8YUtqBoKkKU9Rtb7BidS9Hmo6rWfxB JJRW5mZjCP27o5FsuFG/HaNWLovEccao18+I8FExs483hxlUR26Aue1g36jH7Zt4sgA4 9lRl0qzczEa7Lx/fZ7FkSa43atKWpbHwqYyDNynQ8PBnEqmL4hJAmUEy46xe51pFK2t+ fyJFaOXY2os1bfYP5SVCP7J60DkLoNFUB5qxq5wsSXMZZdsp6V6fpRID5gu1kzYCY9Vi ylTAJrRJYTbo1gPnhsM+NvY8zIR02DpNQukW9eDZrGBzqr7grmc2HxnNh1EvrWgwenIb oeIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=dZBp+NIU; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g4si699876pfm.85.2018.11.26.08.10.11; Mon, 26 Nov 2018 08:11:21 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=dZBp+NIU; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726636AbeK0C5J (ORCPT + 99 others); Mon, 26 Nov 2018 21:57:09 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:57616 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726255AbeK0C5J (ORCPT ); Mon, 26 Nov 2018 21:57:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=VsTCm5zE3RpQJBZbC8onKGQcf6Oja50LKgsJ8cRfa9s=; b=dZBp+NIUabKA7+eVREo8mbGie YZXDDkAM1OLsO1qAjFuNocVVa1l/ZMwtxkplQo/veN3oucqB+igBpLrLuxcTH2nFKNAT7butgNutn vVV4db7HiKga9WvXF7VRQPQDRVckWbqk+6MaAuir5AfUG7krYaFYMnU0iJNCQeBiRbv6Zs4g1AshR oRCbcFtgJny2BR7rHoQLEsLFqTJDbqEYlaRGFAuBd41+WwtFbzwuvlwtqMsMr8fLqDQGEebgRL6qU V7Rwpb0pby4Til8m4wUgvkGwB/WKSuviN1vKwXoSWNptVEReuieYWkpxoxSy7jVTbK6PlBqeRcmaV V9gSOdFqw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gRJL0-0006LU-M8; Mon, 26 Nov 2018 16:02:18 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 12CFC2029F87F; Mon, 26 Nov 2018 17:02:17 +0100 (CET) Date: Mon, 26 Nov 2018 17:02:17 +0100 From: Peter Zijlstra To: Josh Poimboeuf Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Ard Biesheuvel , Andy Lutomirski , Steven Rostedt , Ingo Molnar , Thomas Gleixner , Linus Torvalds , Masami Hiramatsu , Jason Baron , Jiri Kosina , David Laight , Borislav Petkov , Julia Cartwright , Jessica Yu , "H. Peter Anvin" Subject: Re: [PATCH v2 4/4] x86/static_call: Add inline static call implementation for x86-64 Message-ID: <20181126160217.GR2113@hirez.programming.kicks-ass.net> References: <62188c62f6dda49ca2e20629ee8e5a62a6c0b500.1543200841.git.jpoimboe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <62188c62f6dda49ca2e20629ee8e5a62a6c0b500.1543200841.git.jpoimboe@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 26, 2018 at 07:55:00AM -0600, Josh Poimboeuf wrote: > diff --git a/arch/x86/kernel/static_call.c b/arch/x86/kernel/static_call.c > index 8026d176f25c..d3869295b88d 100644 > --- a/arch/x86/kernel/static_call.c > +++ b/arch/x86/kernel/static_call.c > @@ -9,13 +9,21 @@ > > void static_call_bp_handler(void); > void *bp_handler_dest; > +void *bp_handler_continue; > > asm(".pushsection .text, \"ax\" \n" > ".globl static_call_bp_handler \n" > ".type static_call_bp_handler, @function \n" > "static_call_bp_handler: \n" > - "ANNOTATE_RETPOLINE_SAFE \n" > +#ifdef CONFIG_HAVE_STATIC_CALL_INLINE > + ANNOTATE_RETPOLINE_SAFE > + "call *bp_handler_dest \n" > + ANNOTATE_RETPOLINE_SAFE > + "jmp *bp_handler_continue \n" > +#else /* !CONFIG_HAVE_STATIC_CALL_INLINE */ > + ANNOTATE_RETPOLINE_SAFE > "jmp *bp_handler_dest \n" > +#endif > ".popsection \n"); > > void arch_static_call_transform(void *site, void *tramp, void *func) > @@ -25,7 +33,10 @@ void arch_static_call_transform(void *site, void *tramp, void *func) > unsigned char insn_opcode; > unsigned char opcodes[CALL_INSN_SIZE]; > > - insn = (unsigned long)tramp; > + if (IS_ENABLED(CONFIG_HAVE_STATIC_CALL_INLINE)) > + insn = (unsigned long)site; > + else > + insn = (unsigned long)tramp; > > mutex_lock(&text_mutex); > > @@ -41,8 +52,10 @@ void arch_static_call_transform(void *site, void *tramp, void *func) > opcodes[0] = insn_opcode; > memcpy(&opcodes[1], &dest_relative, CALL_INSN_SIZE - 1); > > - /* Set up the variable for the breakpoint handler: */ > + /* Set up the variables for the breakpoint handler: */ > bp_handler_dest = func; > + if (IS_ENABLED(CONFIG_HAVE_STATIC_CALL_INLINE)) > + bp_handler_continue = (void *)(insn + CALL_INSN_SIZE); > > /* Patch the call site: */ > text_poke_bp((void *)insn, opcodes, CALL_INSN_SIZE, OK, so this is where that static_call_bp_handler comes from; you need that CALL to frob the stack. But I still think it is broken; consider: CPU0 CPU1 bp_handler = ponies; text_poke_bp(, &static_call_bp_handler) text_poke(&int3); on_each_cpu(sync) ... text_poke(/* all but first bytes */) on_each_cpu(sync) ... pt_regs->ip = &static_call_bp_handler // VCPU takes a nap... text_poke(/* first byte */) on_each_cpu(sync) ... // VCPU sleeps more bp_handler = unicorn; CALL unicorn *whoops* Now, granted, that is all rather 'unlikely', but that never stopped Murphy.