Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1203097imu; Fri, 9 Nov 2018 12:35:45 -0800 (PST) X-Google-Smtp-Source: AJdET5cRCzuvx90Jv93mcxYWy5jxZayY86iSHrpBB9Pux44AgI3eiOrU+Wfxu3Yk1ko2clmC5KQQ X-Received: by 2002:a17:902:780f:: with SMTP id p15-v6mr10101073pll.197.1541795745463; Fri, 09 Nov 2018 12:35:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541795745; cv=none; d=google.com; s=arc-20160816; b=YEzmIeus2vINWpyBQDpTpBAvdMNZrUSAUSi0Rap+df3yWAI+ElQbYP11+OS6y9+gIu cieJc1Dw0V2tm5/3+EOn6xVSimbPFX/ay3SaP5bLI6D5OrpiVIGzuZGNnqfJNnDXCBkM Xys7kca+FurEzGvaF1BjxGtVwDxPY/79PzSTET6/skO53/VtpmCD6Qlmc/J8B7P3Kp69 saVeFAwtGZZ9j6UGVWb10dDNByqLZfcuaO6v8wV5B7wgbR6vXuVOdKd+1m7BmvkSFquk 9DUxiRLaku86PzJglmKXZj6HaMZXNL3zril7p2FfQxq+LdzIlLHXlcNC6CstDG6KrbNq DpxQ== 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=WHSV9gN1ZOM3SYAG7BEl8M3D/v15/PwW35s1tx/omrc=; b=TPUFwf+CkKWeXhns9/4SwB2QmF0M6XI7WkMFyeHIvHDAWDFq1fkGuFYUaB47Dgr/3i M29s6jTl0oMQik97IeCKvcHBvB0w1LnHtpsoYWx5yfAvUEN0KKhTxeOaLo5wSAkuwCqV SwY1IngFIJ0AnupEglSVQrsp+tzo1VIAFZHewxSU7t0ztpiUUrvyFXjA0GWdXm8MkI5i GdrAroLBxQ6Uh51PNNFz7llXpODzntxjoY5oielEW13DEGdlOqGbfezUtA/ko9CoO4Jg L1Qz/HmU+2CF4OBhhWuNem1cHwHuQYtSLDH8pE3EPUG5WFaq0UaFQbZj7lfcxhkKwQPG FPGw== 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 f3-v6si7047544pgq.536.2018.11.09.12.35.28; Fri, 09 Nov 2018 12:35:45 -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 S1728263AbeKJGRQ (ORCPT + 99 others); Sat, 10 Nov 2018 01:17:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50500 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726110AbeKJGRP (ORCPT ); Sat, 10 Nov 2018 01:17:15 -0500 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 297CC3DE04; Fri, 9 Nov 2018 20:35:03 +0000 (UTC) Received: from treble (ovpn-124-61.rdu2.redhat.com [10.10.124.61]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 723F75D9CA; Fri, 9 Nov 2018 20:35:01 +0000 (UTC) Date: Fri, 9 Nov 2018 14:34:59 -0600 From: Josh Poimboeuf To: Steven Rostedt Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Ard Biesheuvel , Andy Lutomirski , 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: <20181109203459.wbftlkxcvfnwo2bm@treble> References: <3cf04e113d71c9f8e4be95fb84a510f085aa4afa.1541711457.git.jpoimboe@redhat.com> <20181109133337.63487e3a@gandalf.local.home> <20181109193505.5p5iddrtgpk2cpb4@treble> <20181109145746.0037da3f@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20181109145746.0037da3f@gandalf.local.home> 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.29]); Fri, 09 Nov 2018 20:35:03 +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 02:57:46PM -0500, Steven Rostedt wrote: > On Fri, 9 Nov 2018 13:35:05 -0600 > Josh Poimboeuf wrote: > > > > > > +#define DECLARE_STATIC_CALL(key, func) \ > > > > + extern struct static_call_key key; \ > > > > + extern typeof(func) STATIC_CALL_TRAMP(key); \ > > > > + /* Preserve the ELF symbol so objtool can access it: */ \ > > > > + __ADDRESSABLE(key) > > > > > > Does the __ADDRESSABLE(key) need to be in the DECLARE part? > > > If so, there needs to be more explanation than just the comment above > > > it. > > > > For each call site, objtool creates a struct in .static_call_sites: > > > > struct static_call_site { > > s32 addr; > > s32 key; > > }; > > > > In order to do that, it needs to create a relocation which references > > the key symbol. If the key is defined in another .o file, then the > > current .o will not have an ELF symbol associated with the key. The > > __ADDRESSABLE(key) thing tells GCC to leave the key symbol in the .o > > file, even though it's not referenced anywhere. That makes objtool's > > job easier, so it doesn't have to edit the symbol table. > > > > I could add a comment saying as much, though it's hard to explain it in > > fewer words than I just did :-) > > Does this have to do with adding the references by relative address? > > In record_mcount, I just picked an existing symbol and referenced that.. > But perhaps this is a cleaner way. I think recordmcount is different. It creates references (in __mcount_loc) to functions which are already in the object file, so they already have symbols associated with them. But in this case, when objtool is creating references, the symbol it needs to reference is outside the .o file, so there's no symbol to associate it with. > Adding a more in depth comment wont hurt. > > > > > > > + /* > > > > + * If called before init, leave the call sites unpatched for now. > > > > + * In the meantime they'll continue to call the temporary trampoline. > > > > + */ > > > > + if (!static_call_initialized) > > > > + goto done; > > > > + > > > > + list_for_each_entry(mod, &key->site_mods, list) { > > > > > > Since I'm expecting a lot of sites, I'm wondering if we should just do > > > this as an array, like I do with the ftrace call sites. > > > > > > But this can be an enhancement for later. Let's focus on getting this > > > working first. > > > > But it's not a static list. It can grow/shrink as modules are > > loaded/unload. > > Neither is ftrace :-) What I did was make one array for the core kernel > code, and an array for each module, and link list those (single link, > although double link may not be hard either). That will save a lot of > memory than having each instance have a link pointer, as it only grows > or shrinks in chunks. That sounds exactly like what I did :-) The site_mods list is a list of static_call_mods. Each static_call_mod has a pointer to an array (which is that module/vmlinux's .static_call_site section). > > > So what's the reason for skipping init calls? > > > > This is the runtime changing code (static_call_update). Presumably the > > init sections no longer exist and we shouldn't write to any (former) > > call sites there. > > > > That's probably a dangerous assumption though... If > > static_call_update() were called early, some init code might not get > > patched and then call into the wrong function. > > > > I'm thinking we should just disallow static call sites in init sections. > > I can't think of a good reason why they would be needed in init code. > > We can WARN when detecting them during boot / module init. > > > > What I would do is to allow init (like ftrace now does). I have > ftrace_free_init_mem() that removes all the mcount references for init > calls from its list. You could add a static_call_free_init() to > kernel_init() in init/main.c too. That makes sense for ftrace, but I don't see much point in allowing it for static calls. Maybe we could just add support for it later if it turns out to be useful. -- Josh