Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3031230imu; Thu, 29 Nov 2018 14:19:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/UGlMUo0bogkhDJJ0QlPH2Ec5STVWGD1vnYrVe1Yl69qawc1iGXWO+mqyqhBJM3xQGYJC+9 X-Received: by 2002:a62:cd44:: with SMTP id o65mr3140618pfg.222.1543529986164; Thu, 29 Nov 2018 14:19:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543529986; cv=none; d=google.com; s=arc-20160816; b=mBeZoDD5g8ZhrrN4PRq4yIL1bfUHkJjq8djMwg8OgNcmIsqqvvEG1un/ZHJRD/hJj2 s0uVZR1JpQwKLZStf0MCvRhJPvhmuVWdGVeh8pEHJp8Fiv4wuY5BKB8DYu5ZVnLdRK+y C2+CXTm1i5zfALsjAxz7XUPTEAGLVrv+KG2PA1n2mW3WzZfj6uUj1q6iTiKtMUD/TAJe W0hniBQwqaSoB+Ab1rPnKUb+j4/uObglsoT+uAp6v6s7/lbxEdWzyvAgheJTYnshGKec dxwRWRSXOnvL7WPlKeIJ75GSHLkJuzOdc7gE8KRKZLFYjK0qy35/qQ2sRk+XOwPhqBYG MoNw== 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=ZjI/MuQU5wLahlpRAl/c44gWhdexPZd0T7TXNfN/N9U=; b=UY8NTYNXrdQxv+avuLI71mPPBy0rdVAnpgAsDU05J+w8ChDBOOaBrpKhPuBJ+edujM osuyxhMx7LpoYeYoAx9SKeOSuYKIG52e/kb+1yzv/qgYaTnLd65q6nj5qNYHoe08YSxF z703oyfj7uZ1kIpnIoFjoXucBpHW52z7kBdRiVCMrT+bpYgvSWhGGgjQFl+dBdDTlrtu mPsJq6qp4bMTDoFhPJzuFf/7+LdFttEDL2ptwA8L+04WcQovelQnywayu91zwX85eylO xNMDyWE0E5tFEBYWal+ignAFyN6Bf0FGtTJsMhftb3oIgECE56dYzDyP3VLyyQfLHo3Z 15MQ== 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 l6si2990676pgg.592.2018.11.29.14.19.31; Thu, 29 Nov 2018 14:19:46 -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 S1726674AbeK3JYu (ORCPT + 99 others); Fri, 30 Nov 2018 04:24:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59828 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726264AbeK3JYt (ORCPT ); Fri, 30 Nov 2018 04:24:49 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB6D1394D3C; Thu, 29 Nov 2018 22:17:49 +0000 (UTC) Received: from treble (ovpn-123-4.rdu2.redhat.com [10.10.123.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B557C17563; Thu, 29 Nov 2018 22:17:47 +0000 (UTC) Date: Thu, 29 Nov 2018 16:17:45 -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: <20181129221745.jxxqjsocergfzrb4@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: <20181129202452.56f4j2wdct6qbaqo@treble> User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 29 Nov 2018 22:17:50 +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 02:24:52PM -0600, Josh Poimboeuf wrote: > On Thu, Nov 29, 2018 at 11:27:00AM -0800, Andy Lutomirski wrote: > > On Thu, Nov 29, 2018 at 11:08 AM Linus Torvalds > > wrote: > > > > > > On Thu, Nov 29, 2018 at 10:58 AM Linus Torvalds > > > wrote: > > > > > > > > In contrast, if the call was wrapped in an inline asm, we'd *know* the > > > > compiler couldn't turn a "call wrapper(%rip)" into anything else. > > > > > > Actually, I think I have a better model - if the caller is done with inline asm. > > > > > > What you can do then is basically add a single-byte prefix to the > > > "call" instruction that does nothing (say, cs override), and then > > > replace *that* with a 'int3' instruction. > > > > > > Boom. Done. > > > > > > Now, the "int3" handler can just update the instruction in-place, but > > > leave the "int3" in place, and then return to the next instruction > > > byte (which is just the normal branch instruction without the prefix > > > byte). > > > > > > The cross-CPU case continues to work, because the 'int3' remains in > > > place until after the IPI. > > > > Hmm, cute. But then the calls are in inline asm, which results in > > giant turds like we have for the pvop vcalls. And, if they start > > being used more generally, we potentially have ABI issues where the > > calling convention isn't quite what the asm expects, and we explode. > > > > I propose a different solution: > > > > As in this patch set, we have a direct and an indirect version. The > > indirect version remains exactly the same as in this patch set. The > > direct version just only does the patching when all seems well: the > > call instruction needs to be 0xe8, and we only do it when the thing > > doesn't cross a cache line. Does that work? In the rare case where > > the compiler generates something other than 0xe8 or crosses a cache > > line, then the thing just remains as a call to the out of line jmp > > trampoline. Does that seem reasonable? It's a very minor change to > > the patch set. > > Maybe that would be ok. If my math is right, we would use the > out-of-line version almost 5% of the time due to cache misalignment of > the address. BTW, this means that if any of a trampoline's callers crosses cache boundaries then we won't be able to poison the trampoline. Which is kind of sad. -- Josh