Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2443380imu; Thu, 29 Nov 2018 05:13:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/V55mS1Yhj6EF0HjuHlpWubuUyDjMOHj1YexEF2z+31EfEu5cC7CVLxtZtBD/ChJQ/morau X-Received: by 2002:a63:f811:: with SMTP id n17mr1231978pgh.23.1543497206736; Thu, 29 Nov 2018 05:13:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543497206; cv=none; d=google.com; s=arc-20160816; b=dMBw1+mb95JZtDbEW2GxZ5sb+XUCmZOAcH8o9Fx7c9RdltfoSCgqZsjHmvixED4rzJ 4ipvIs2yD2rOtOEy+r4djHPWx+alK1eLcbxYiqj1suUkNmExRg5c+epfkfKHSl7q4/hR 789FLoGu1cBQMxw/xco+damN58xoQZHnO6vOni3oVMbgLREVU08y+qLWQrL7XwFg/SJ3 ufKWuOZgxoXzcuigOVEX7RyUBnxEXe0NYs/QHmcJEJ6s+FbRYOlmAZDQCr9GkP9BXSfh xTK8VbvWpotrj9r6z1WCzEhIoDdQtbxz3Oqe6H1d1e6hh2h4dan4DAVRXvdKxWoK2CZ7 /vcA== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=rQKS5/3PvJHImw7TSb15LvjeCuxuy8Zftg7XGaT2YQM=; b=cStI6LWPmvT8RIEmEih1asLC1so9S2kXO0itPYMpDbm+wO4rD5OlHDrzKHJW83vUNq 20V/CRvRGsnV1FSgQUSA6Sn/MMPmDdEK0YYqRols8HX+mWavVE9vqjpCqYAbFGLXNy4D TqbCqMb3hO9GIaJFwycDnhbBi16bzW2/bq/Mev+gpDMGTrK3MlAbQFggDHq7yorc4ESZ SnXOVq/U+S4OKVZNSXU9TDKgzt/tl5zGWHa+CW7GTnEq9Ut4xgRCJonwh++HL26VsBaJ s4IXNK9WlDanl1MGq9KHfrGb6ghAkhqfSzE4lGY3Zu0WFgs5RZ3cxDU0IJb/YwBq8D6j +DBQ== 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 w7si2170714pfw.200.2018.11.29.05.13.00; Thu, 29 Nov 2018 05:13:26 -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 S1728454AbeK3AQr (ORCPT + 99 others); Thu, 29 Nov 2018 19:16:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40952 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728414AbeK3AQr (ORCPT ); Thu, 29 Nov 2018 19:16:47 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68B9813AA2; Thu, 29 Nov 2018 13:11:28 +0000 (UTC) Received: from treble (ovpn-123-4.rdu2.redhat.com [10.10.123.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 71D07101962B; Thu, 29 Nov 2018 13:11:24 +0000 (UTC) Date: Thu, 29 Nov 2018 07:11:22 -0600 From: Josh Poimboeuf To: Peter Zijlstra Cc: Andy Lutomirski , X86 ML , LKML , Ard Biesheuvel , Steven Rostedt , Ingo Molnar , Thomas Gleixner , Linus Torvalds , 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: <20181129131122.wfceiqlnklruas6g@treble> References: <62188c62f6dda49ca2e20629ee8e5a62a6c0b500.1543200841.git.jpoimboe@redhat.com> <20181126160217.GR2113@hirez.programming.kicks-ass.net> <20181126171036.chcbmb35ygpxziub@treble> <20181126175624.bruqfbkngbucpvxr@treble> <20181126200801.GW2113@hirez.programming.kicks-ass.net> <20181126212628.4apztfazichxnt7r@treble> <20181127084330.GX2113@hirez.programming.kicks-ass.net> <20181129094210.GC2131@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20181129094210.GC2131@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 29 Nov 2018 13:11:28 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 29, 2018 at 10:42:10AM +0100, Peter Zijlstra wrote: > On Wed, Nov 28, 2018 at 10:05:54PM -0800, Andy Lutomirski wrote: > > > >> +static void static_call_bp_handler(struct pt_regs *regs, void *_data) > > >> +{ > > >> + struct static_call_bp_data *data = _data; > > >> + > > >> + /* > > >> + * For inline static calls, push the return address on the stack so the > > >> + * "called" function will return to the location immediately after the > > >> + * call site. > > >> + * > > >> + * NOTE: This code will need to be revisited when kernel CET gets > > >> + * implemented. > > >> + */ > > >> + if (data->ret) { > > >> + regs->sp -= sizeof(long); > > >> + *(unsigned long *)regs->sp = data->ret; > > >> + } > > > > You can’t do this. Depending on the alignment of the old RSP, which > > is not guaranteed, this overwrites regs->cs. IRET goes boom. > > I don't get it; can you spell that out? I don't quite follow that either. Maybe Andy is referring to x86-32, for which regs->sp isn't actually saved: see kernel_stack_pointer(). This code is 64-bit only so that's not a concern. > The way I understand it is that we're at a location where a "E8 - Near > CALL" instruction should be, and thus RSP should be the regular kernel > stack, and the above simply does "PUSH ret", which is what that CALL > would've done too. Right. -- Josh