Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp545415imm; Fri, 5 Oct 2018 07:58:45 -0700 (PDT) X-Google-Smtp-Source: ACcGV601NabIBq8BUKa3fMe/7YClLT8XUdpzDAU0I+WZfd5D2RMYVV9+GW0sPUm2hlIYApRn8JQk X-Received: by 2002:a62:8559:: with SMTP id u86-v6mr12401359pfd.32.1538751525726; Fri, 05 Oct 2018 07:58:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538751525; cv=none; d=google.com; s=arc-20160816; b=nUi0QJLsJ/VAm37HyT73MPmB46nIhQQtteRQ9nXhcAdJkQLS0Ouz9dCK5Z3kmIx/Ek 9N9ooNtSKYc1r0AH2WbQxsCnB0MejI6nVEzOChpvQ2VCE6cDLnp7IjB6wNZR8foLv/vz 8SM6Pl94ATf2AF2jBfovJKXPiwQFZcVmc1S5z4wuqKRDstiiAO0+poNKopK3PZHdjfs9 tZTY1DOxjWBYN47LyQYCiQKSRff3/0hfPRoU0uNbP2u9vFz5iQtbtrmaTSjLmov+F6KI HHZ6EZ+4GD/ko8tTyw3ngyZGZx5cwJsgb6Ss90he+3RZlM2LweN3oV3j0p3FnK/aqFyz 7d5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=V4YLpmN1ofx8DjUCcCAnT+gAIrUFV0ZMrcyHc8ddDec=; b=iQLfAme0YvwtbLHt/mRJjmrerOGSjhf3xeTsIK9EbUVDJ6a8IsKGScb6ir3UeXZr66 5T85k0ZT0maIJLDiBL8Iy3UMLxU4wVpRSc1vu9TPMI4/jRrHPd1+QAeeqq9YbNEnu0ys rkw0kkrtznNpsDUV9x3rrBqt5FM1jXdYHo95etsjqzfiS57ScX8nc2w1WuephBtUj2Ke Lvv+ueTCd+AskxbEMVnUOaQIZ/CajZajZIeXeOjcr3wH6E8CF5JemXRPxOUBhoINX7VC fXO/vqJq++lUzm0xYpbmbnYFdoVgfRAbcUVrTkGYr1KKV3mlb60VPJRhSCf26CGMKPeE nHUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZXgn7fuE; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o9-v6si8393891plk.4.2018.10.05.07.58.29; Fri, 05 Oct 2018 07:58:45 -0700 (PDT) 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=pass header.i=@linaro.org header.s=google header.b=ZXgn7fuE; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728954AbeJEV5E (ORCPT + 99 others); Fri, 5 Oct 2018 17:57:04 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:38635 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728139AbeJEV5E (ORCPT ); Fri, 5 Oct 2018 17:57:04 -0400 Received: by mail-it1-f195.google.com with SMTP id i76-v6so3118859ita.3 for ; Fri, 05 Oct 2018 07:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=V4YLpmN1ofx8DjUCcCAnT+gAIrUFV0ZMrcyHc8ddDec=; b=ZXgn7fuEJtYwPH0irwGdjeVH05CiPo8ulTk2CpFffZxoOIsiGslSYaA7PpIIFhUGdF M07qXl6lHhIkN/cVH6/sdTd6llU96GiOj55w6YAkiSqRve2u8yyYXWbgOtpHrCX/rx8q ObqL3Le6C7+F3y7Btb8vgiZVFtBKuAM1QRPrE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=V4YLpmN1ofx8DjUCcCAnT+gAIrUFV0ZMrcyHc8ddDec=; b=abpJH94H41p+1McWn9xMwfrp5nhEqS1w3KUnmbcsBxMMzTeQrfqmaFpc7clspkqpJI pjQM06aa8BhVdF1WOiAzd7tk5cIVMaz/cC3atfesaCpvddiDj8J1BUimqjGYAbJ0KRHu AKCcCVtOKUpHFvGaqhb5jbqOTmi+9CBX0l3CzUX+j3Uki2NMSAEFTP26wPkxRrsOODql olS3533EYwwTfwyO/80dFGxN2Htj42aWJW5ANo9ZlhT9Gj/J/Gpr5GxhS9Lt2+QdxVPF OJnJkYQD7xUeWnTTFkK6wzJII/vVUnXLDqvQOUqFj7X/WxffxjmWyHp/BFbQrWStwwUz Vo2A== X-Gm-Message-State: ABuFfojVtFXEAQMIy4SeS9vHReM/yy2yPzDWdSzdWflN1JJnMJtIW6c9 z7xtQ3omD9rVQzuT35+EKnqDOJN0rycZ9FUnboHmcw== X-Received: by 2002:a24:a10b:: with SMTP id y11-v6mr4679847ite.148.1538751479033; Fri, 05 Oct 2018 07:57:59 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:5910:0:0:0:0:0 with HTTP; Fri, 5 Oct 2018 07:57:57 -0700 (PDT) In-Reply-To: <20181005141433.GS19272@hirez.programming.kicks-ass.net> References: <20181005081333.15018-1-ard.biesheuvel@linaro.org> <20181005081333.15018-2-ard.biesheuvel@linaro.org> <20181005141433.GS19272@hirez.programming.kicks-ass.net> From: Ard Biesheuvel Date: Fri, 5 Oct 2018 16:57:57 +0200 Message-ID: Subject: Re: [RFC PATCH 1/9] kernel: add support for patchable function pointers To: Peter Zijlstra Cc: Linux Kernel Mailing List , "Jason A . Donenfeld" , Eric Biggers , Samuel Neves , Andy Lutomirski , Arnd Bergmann , Herbert Xu , "David S. Miller" , Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Thomas Gleixner , Ingo Molnar , Kees Cook , "Martin K. Petersen" , Greg Kroah-Hartman , Andrew Morton , Richard Weinberger , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , linux-arm-kernel , linuxppc-dev Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5 October 2018 at 16:14, Peter Zijlstra wrote: > On Fri, Oct 05, 2018 at 10:13:25AM +0200, Ard Biesheuvel wrote: >> diff --git a/include/linux/ffp.h b/include/linux/ffp.h >> new file mode 100644 >> index 000000000000..8fc3b4c9b38f >> --- /dev/null >> +++ b/include/linux/ffp.h >> @@ -0,0 +1,43 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> + >> +#ifndef __LINUX_FFP_H >> +#define __LINUX_FFP_H >> + >> +#include >> +#include >> + >> +#ifdef CONFIG_HAVE_ARCH_FFP >> +#include >> +#else >> + >> +struct ffp { >> + void (**fn)(void); >> + void (*default_fn)(void); >> +}; >> + >> +#define DECLARE_FFP(_fn, _def) \ >> + extern typeof(_def) *_fn; \ >> + extern struct ffp const __ffp_ ## _fn >> + >> +#define DEFINE_FFP(_fn, _def) \ >> + typeof(_def) *_fn = &_def; \ >> + struct ffp const __ffp_ ## _fn \ >> + = { (void(**)(void))&_fn, (void(*)(void))&_def }; \ >> + EXPORT_SYMBOL(__ffp_ ## _fn) >> + >> +static inline void ffp_set_target(const struct ffp *m, void *new_fn) >> +{ >> + WRITE_ONCE(*m->fn, new_fn); >> +} >> + >> +static inline void ffp_reset_target(const struct ffp *m) >> +{ >> + WRITE_ONCE(*m->fn, m->default_fn); >> +} >> + >> +#endif >> + >> +#define SET_FFP(_fn, _new) ffp_set_target(&__ffp_ ## _fn, _new) >> +#define RESET_FFP(_fn) ffp_reset_target(&__ffp_ ## _fn) >> + >> +#endif > > I don't understand this interface. There is no wrapper for the call > site, so how are we going to patch all call-sites when you update the > target? This is the generic implementation, and in this case, it is just a function pointer which gets dereferenced and called indirectly at each call site. In the arch specific implementations (for ones where it matters, see 2/9), it is more like a PLT entry, which gets called from each call site, and which can be patched to point to another function. So we replace a single indirect call with a direct call plus a direct jump.