Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2154799imm; Thu, 11 Oct 2018 06:05:55 -0700 (PDT) X-Google-Smtp-Source: ACcGV60rjv1GasoiYLiDTp8Xe8HGoPuKoiqyyIDzdhFlTkyMyDfXx9U6hqDC4BqHcUd87U5FFTaJ X-Received: by 2002:a63:6d83:: with SMTP id i125-v6mr1316157pgc.215.1539263155719; Thu, 11 Oct 2018 06:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539263155; cv=none; d=google.com; s=arc-20160816; b=FW7wUTjlE9ZNxRGumDGNM6R+JqM0psRrF3UZkCdgvbs//ObWuKH2O1zIwZpX8xSY8D EIoK8n4Lbv9rTH3P+Tdu5i0IUFBJdo37g5cbdK+rvgl/3nComyOSjYPGIp0KZ2J78cfu 6tj1Ck1HpCqAv9kDEEmEkOe4LGJUU0hoMWmwyqGkoojnTvx9Eqsa/TKxs+2Cgqs15zFq VRAtl5V2fEzWm+1FScCUaiia4iCbGCP0xwz1HGtuZpPFAfTRv5UQ2ieqSFxTBhmK+GEr FpZqbqshCsD+Ud1KcFye7v5RORf/M2pwCQv2ZZZnAClPCg8gFtMVTQhaA/nYqPO7joRg lkYg== 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=TxVMWc6RyMv9OKXSzG3d//9cWtBpCPduDzAzJ33bdJw=; b=bQpsZVZFanQYeVZ5tAAFRpLWqyO4dQGCEckygtQvzBpd5Fwh7SADD+ZfKdmPwjS/nZ B+YTCuLFMVFm1JpQWw+sgi0c+FF2ub5HFX4N7CafKM3+6lwQNNw86kl1dHoEp62tVeAe yDrNvQOWtJv+ULJ/I3zH7p4WqZS7uepYWZXP5eztUbBt/e4iZhngHC24Hh8Pww/jMTlH eTNqy2DVNfrNRlApbVBZIJtfcR4+e9CqRSriKuAVZh8rm2KbB3Yf2shQRqIrCC2P5JJa 9vYnsm1725qrGPvDTzxDQDmKVDzigRXdaNm0aesLf1RD3Y/xcFKc/aTPq+Py9OP5BHF7 ntgg== 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 62-v6si2256335ply.163.2018.10.11.06.05.36; Thu, 11 Oct 2018 06:05:55 -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; 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 S1728323AbeJKUUL (ORCPT + 99 others); Thu, 11 Oct 2018 16:20:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36350 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726135AbeJKUUL (ORCPT ); Thu, 11 Oct 2018 16:20:11 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9752F5F724; Thu, 11 Oct 2018 12:53:06 +0000 (UTC) Received: from treble (ovpn-122-227.rdu2.redhat.com [10.10.122.227]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7F8BF7A536; Thu, 11 Oct 2018 12:53:01 +0000 (UTC) Date: Thu, 11 Oct 2018 07:52:58 -0500 From: Josh Poimboeuf To: Andy Lutomirski Cc: Steven Rostedt , Peter Zijlstra , LKML , Linus Torvalds , Ingo Molnar , Andrew Morton , Thomas Gleixner , Masami Hiramatsu , Mathieu Desnoyers , Matthew Helsley , "Rafael J. Wysocki" , David Woodhouse , Paolo Bonzini , Jason Baron , Jiri Kosina , Ard Biesheuvel , Andrew Lutomirski Subject: Re: [POC][RFC][PATCH 1/2] jump_function: Addition of new feature "jump_function" Message-ID: <20181011125258.ihsdmonepaoc5xtb@treble> References: <20181008155757.GC5663@hirez.programming.kicks-ass.net> <20181009021710.qwt5hpntyeps44h3@treble> <20181008235750.59da83ae@gandalf.local.home> <20181010175237.e7m3sldcu2maoqcq@treble> <20181010181605.arsyjxwdztztrjih@treble> <20181010181741.lc4l7kjvcmoxrw5b@treble> <20181011030738.wwy6grnss67txd2l@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20181011030738.wwy6grnss67txd2l@treble> User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 11 Oct 2018 12:53:07 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 10, 2018 at 10:07:38PM -0500, Josh Poimboeuf wrote: > On Wed, Oct 10, 2018 at 02:13:22PM -0700, Andy Lutomirski wrote: > > On Wed, Oct 10, 2018 at 11:17 AM Josh Poimboeuf wrote: > > > > > > On Wed, Oct 10, 2018 at 01:16:05PM -0500, Josh Poimboeuf wrote: > > > > On Wed, Oct 10, 2018 at 11:03:43AM -0700, Andy Lutomirski wrote: > > > > > > +#define DECLARE_STATIC_CALL(tramp, func) \ > > > > > > + extern typeof(func) tramp; \ > > > > > > + static void __used __section(.discard.static_call_tramps) \ > > > > > > + *__static_call_tramp_##tramp = tramp > > > > > > + > > > > > > > > > > Confused. What's the __static_call_tramp_##tramp variable for? And > > > > > why is a DECLARE_ macro defining a variable? > > > > > > > > This is the magic needed for objtool to find all the call sites. > > > > > > > > The variable itself isn't needed, but the .discard.static_call_tramps > > > > entry is. Objtool reads that section to find out which function call > > > > sites are targeted to a static call trampoline. > > > > > > To clarify: objtool reads that section to find out which functions are > > > really static call trampolines. Then it annotates all the instructions > > > which call/jmp to those trampolines. Those annotations are then read by > > > the kernel. > > > > > > > Ah, right, and objtool runs on a per-object basis so it has no other > > way to know what symbols are actually static calls. > > > > There's another way to skin this cat, though: > > > > extern typeof(func) __static_call_trampoline_##tramp; > > #define tramp __static_call_trampoline_##tramp > > > > And objtool could recognize it by name. But, of course, you can't put > > a #define in a macro. But maybe there's a way to hack it up with a > > static inline? I went with something similar in the latest version. It's less surprising in a couple of ways: - DECLARE_STATIC_CALL doesn't have the magic objtool definition. - Call sites use the static_call() wrapper, which makes static calls clearly visible. #define STATIC_CALL_TRAMP(key) ____static_call_tramp_##key #define STATIC_CALL_PTR(key) ____static_call_ptr_##key #define STATIC_CALL_TRAMP_STR(key) __stringify(STATIC_CALL_TRAMP(key)) #define STATIC_CALL_PTR_STR(key) __stringify(STATIC_CALL_PTR(key)) #define DECLARE_STATIC_CALL(key, func) \ extern typeof(func) STATIC_CALL_TRAMP(key); \ extern typeof(func) *STATIC_CALL_PTR(key) #define DEFINE_STATIC_CALL(key, func) \ typeof(func) *STATIC_CALL_PTR(key) = func; \ asm(".pushsection .text, \"ax\" \n" \ ".align 4 \n" \ ".globl " STATIC_CALL_TRAMP_STR(key) " \n" \ ".type " STATIC_CALL_TRAMP_STR(key) ", @function \n" \ STATIC_CALL_TRAMP_STR(key) ": \n" \ "jmpq *" STATIC_CALL_PTR_STR(key) "(%rip) \n" \ ".popsection \n") #define static_call(key, args...) STATIC_CALL_TRAMP(key)(args) #define static_call_update(key, func) \ ({ \ STATIC_CALL_PTR(key) = func; \ __static_call_update((void **)&STATIC_CALL_PTR(key)); \ }) -- Josh