Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp836695imu; Fri, 9 Nov 2018 06:56:43 -0800 (PST) X-Google-Smtp-Source: AJdET5eLY98h99ilKSLPMpIhRZpeXuYrYQC6jgwBfUo9XllucRKUN0hiuo57WdaTCy3BFqpEU2ew X-Received: by 2002:a63:1f1c:: with SMTP id f28mr7778018pgf.193.1541775403309; Fri, 09 Nov 2018 06:56:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541775403; cv=none; d=google.com; s=arc-20160816; b=kChXQHN8cO8qJJtVBXPecCWftd27Vrj5NHsSqW1qaSUlXpnF8xeZF6fpgxBndyHMWz kQM0voL9CGetguqz5JdrUecL3DeItbuS9qkqiuE3FYbgFfsl/Mu4/p112EA/PjdZMLv3 FQZySvwYLl3mT5Pe8/pF1NMB4qnBq0x65Py+sL+aFRQzbYJ7Ty06u1TfiCKcKr2tLeWR uSRp2XUdVU2MF7ObA9PkkvkLGb6z6t2yulQjDMP4y2VW3TWSZy2LrbTzIz3AvyvsOuva lGYSan4qpudN6+26L81D1CLgeAirGSnH2TEuk+yriJbKt6C0o2+2zOWhjI6XEufEEQdB ooqA== 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=+fHxnIepCY4Old2/fFEN6e8d/1AVU4dciiQ37zQIZXE=; b=YXIb/BJZNsHPSsazyEIYrnFJP4CDNAebYiaeatc38zJp9CUAPNyng/jQNKEswXsQaL Xnxhd3FwkaGCRA3Ak5f1opVOe47ddIe/flLATqIwku9O4mUIoI4ArooSdJWslPU8+6uC YB/yMslRpmn/FcKkw7jIMrenrLxcr+7YmBja99GDyrwSNmELWSZyKrsPcAHDbO69WpoJ MTLlxjfNru6N7NspVuAJbGJxoTNsUP9XVQ+zLran90NPtgREYHjmBOu6rD9IGXHwvhMb xJy8xrV1GiNbZ3hI/1sf4mReokjpUPCr9OOTf9bBAlJ4p+POGWHfnXUlWlzb391uP8A0 q9lQ== 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 i33-v6si1469569pld.185.2018.11.09.06.56.27; Fri, 09 Nov 2018 06:56:43 -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 S1728115AbeKJAgV (ORCPT + 99 others); Fri, 9 Nov 2018 19:36:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46518 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727784AbeKJAgV (ORCPT ); Fri, 9 Nov 2018 19:36:21 -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 61A2930820DF; Fri, 9 Nov 2018 14:55:25 +0000 (UTC) Received: from treble (ovpn-124-61.rdu2.redhat.com [10.10.124.61]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5DE1101960A; Fri, 9 Nov 2018 14:55:23 +0000 (UTC) Date: Fri, 9 Nov 2018 08:55:21 -0600 From: Josh Poimboeuf To: Ard Biesheuvel Cc: Linux Kernel Mailing List , the arch/x86 maintainers , Andy Lutomirski , Steven Rostedt , Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Linus Torvalds , Masami Hiramatsu , Jason Baron , Jiri Kosina , David Laight , Borislav Petkov Subject: Re: [RFC PATCH 1/3] static_call: Add static call infrastructure Message-ID: <20181109145521.2nfypucjsaq6bvxx@treble> References: <3cf04e113d71c9f8e4be95fb84a510f085aa4afa.1541711457.git.jpoimboe@redhat.com> 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.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.47]); Fri, 09 Nov 2018 14:55:25 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 09, 2018 at 10:51:16AM +0100, Ard Biesheuvel wrote: > Hi Josh, > > Thanks a lot for looking into this. > > On 8 November 2018 at 22:15, Josh Poimboeuf wrote: > > Add a static call infrastructure. Static calls use code patching to > > hard-code function pointers into direct branch instructions. They give > > the flexibility of function pointers, but with improved performance. > > This is especially important for cases where retpolines would otherwise > > be used, as retpolines can significantly impact performance. > > > > This code is heavily inspired by the jump label code (aka "static > > jumps"), as some of the concepts are very similar. > > > > There are three implementations, depending on arch support: > > > > 1) optimized: patched call sites (CONFIG_HAVE_STATIC_CALL_OPTIMIZED) > > 2) unoptimized: patched trampolines (CONFIG_HAVE_STATIC_CALL_UNOPTIMIZED) > > Could we move to an idiom like inline/out of line? The unoptimized > variant may be perfectly adequate for many arches, and 'unoptimized' > sounds like there is something wrong with it. Yeah, inline/out-of-line would be better. It's both more descriptive and less derogatory :-) > > + * Usage example: > > + * > > + * # Start with the following functions (with identical prototypes): > > + * int func_a(int arg1, int arg2); > > + * int func_b(int arg1, int arg2); > > + * > > + * # Define a 'my_key' reference, associated with func_a() by default > > + * DEFINE_STATIC_CALL(my_key, func_a); > > + * > > + * # Call func_a() > > + * static_call(my_key, arg1, arg2); > > + * > > + * # Update 'my_key' to point to func_b() > > + * static_call_update(my_key, func_b); > > + * > > + * # Call func_b() > > + * static_call(my_key, arg1, arg2); > > + * > > Any way we can revert to the default implementation? That would be > useful for, e.g., unloading modules that provide an alternative > implementation. I saw your original implementation had a "reset to default", but from what I can tell, most users wouldn't need that. Assuming the caller knows what the original dest function was, can't they just call static_call_update(my_key, orig_func) directly? > > diff --git a/include/linux/static_call_types.h b/include/linux/static_call_types.h > > new file mode 100644 > > index 000000000000..7dd4b3d7ec2b > > --- /dev/null > > +++ b/include/linux/static_call_types.h > > @@ -0,0 +1,19 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#ifndef _STATIC_CALL_TYPES_H > > +#define _STATIC_CALL_TYPES_H > > + > > +#include > > + > > +#define STATIC_CALL_TRAMP_PREFIX ____static_call_tramp_ > > +#define STATIC_CALL_TRAMP_PREFIX_STR __stringify(STATIC_CALL_TRAMP_PREFIX) > > + > > +#define STATIC_CALL_TRAMP(key) STATIC_CALL_TRAMP_PREFIX##key > > +#define STATIC_CALL_TRAMP_STR(key) __stringify(STATIC_CALL_TRAMP(key)) > > + > > I needed to apply > > diff --git a/include/linux/static_call_types.h > b/include/linux/static_call_types.h > index 7dd4b3d7ec2b..6859b208de6e 100644 > --- a/include/linux/static_call_types.h > +++ b/include/linux/static_call_types.h > @@ -7,7 +7,7 @@ > #define STATIC_CALL_TRAMP_PREFIX ____static_call_tramp_ > #define STATIC_CALL_TRAMP_PREFIX_STR __stringify(STATIC_CALL_TRAMP_PREFIX) > > -#define STATIC_CALL_TRAMP(key) STATIC_CALL_TRAMP_PREFIX##key > +#define STATIC_CALL_TRAMP(key) __PASTE(STATIC_CALL_TRAMP_PREFIX, key) > #define STATIC_CALL_TRAMP_STR(key) __stringify(STATIC_CALL_TRAMP(key)) > > /* The static call site table is created by objtool. */ > > or I end up with > > 0000000000000000 : > 0: 14000000 b a8 > 4: d503201f nop Ha, oops. That was part of a last minute cleanup to share the macros with objtool. -- Josh