Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp856580imu; Fri, 9 Nov 2018 07:12:37 -0800 (PST) X-Google-Smtp-Source: AJdET5eMezaX9izwLqwbNN7U1/Dk7z+VtA5RTxPmymKKmhiPK1V/y7Vr/mVNyedsKcWEnMSjIciU X-Received: by 2002:a63:1c1b:: with SMTP id c27-v6mr7907887pgc.351.1541776357273; Fri, 09 Nov 2018 07:12:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541776357; cv=none; d=google.com; s=arc-20160816; b=hWMqe0ECapiChoinKnFPmoFGJM8v5H97ZQIxqsnsBrVnZVw5Ria/+FbqliXuUCyn3p 0CxjC2rcNUkZkOoPX9Qm0g0ZNPtEJK+vPfkcYQLiMKYjCPN55/63ftfYzU5C6kbiZNyy 4S1qYsJCFG6IT3N2gvrXfI8daOBwJT/rsXHZG0MA+dNIHpAmqbG/STSa1ZjtbD4iDUtk Vm4KhgJWm3tdQw0yrdp0hjhu4nxxbknkaubUwM8lTUizQ0hy0sa9zESzTGhId8G/iKN8 p5zAdVImEPk1nMWUXM5aNOpgKeihkbXIoi6P06240PkFaKvRkevUXyAf4bI/fvxljuRD 6Qvw== 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=aZHrJxDp+3Vn+e+W2Y3/6YnK97gdpBOhAmETpCYqHvw=; b=o6a0Noghk2sJJz586kK6rs749/oDDLc9MwEh/8iGIeJbCdrZbxNMDvpoBE197VH4eC 2rJBzwM1+zF0ak+5yXeJHYu8DtPc6B8qeMfhaJOwUQAq+ztwzvF0OT59Ur3kjh++jbvG m3i2gVELg/RmkmGsXDN/REcWsvRz24WZA6KmtLL6hUruEq6TYkhGVJHf78m7vmMri5ad HhkW4ZU42cQDiZ2nPF+YsNNMvaqufUoEP0fus7aTj5LIi7XS9cYHAeyX3xi5AEylUx8h KKLow0ENbJ05bbqb5BOWLNTwLnUPQDTSAa1TOf5zcn8Z91rKE0s2h1xUJkc/Ckmt3mSk KY/g== 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 i136-v6si8659111pfe.224.2018.11.09.07.12.03; Fri, 09 Nov 2018 07:12:37 -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 S1728026AbeKJAvb (ORCPT + 99 others); Fri, 9 Nov 2018 19:51:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58964 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727735AbeKJAvb (ORCPT ); Fri, 9 Nov 2018 19:51:31 -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 DF6663082DDB; Fri, 9 Nov 2018 15:10:31 +0000 (UTC) Received: from treble (ovpn-124-61.rdu2.redhat.com [10.10.124.61]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F4265C219; Fri, 9 Nov 2018 15:10:29 +0000 (UTC) Date: Fri, 9 Nov 2018 09:10:28 -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: <20181109151028.faifw66enzye32gg@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.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.46]); Fri, 09 Nov 2018 15:10:32 +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:39:17PM +0100, Ard Biesheuvel wrote: > > + for (site = start; site < stop; site++) { > > + struct static_call_key *key = static_call_key(site); > > + unsigned long addr = static_call_addr(site); > > + > > + if (list_empty(&key->site_mods)) { > > + struct static_call_mod *mod; > > + > > + mod = kzalloc(sizeof(*mod), GFP_KERNEL); > > + if (!mod) { > > + WARN(1, "Failed to allocate memory for static calls"); > > + return; > > + } > > + > > + mod->sites = site; > > + list_add_tail(&mod->list, &key->site_mods); > > + > > + /* > > + * The trampoline should no longer be used. Poison it > > + * it with a BUG() to catch any stray callers. > > + */ > > + arch_static_call_poison_tramp(addr); > > This patches the wrong thing: the trampoline is at key->func not addr. If you look at the x86 implementation, it actually does poison the trampoline. The address of the trampoline isn't actually known here. key->func isn't the trampoline address; it's the destination func address. So instead I passed the address of the call instruction. The arch code then reads the instruction to find the callee (the trampoline). The code is a bit confusing. To make it more obvious, maybe we should add another arch function to read the call destination. Then this code can pass that into arch_static_call_poison_tramp(). > However, patching it here means we poison it before all users are > patched. I added this on top > > diff --git a/kernel/static_call.c b/kernel/static_call.c > index 599ebc6fc4f1..d9562329bec6 100644 > --- a/kernel/static_call.c > +++ b/kernel/static_call.c > @@ -248,6 +248,7 @@ static void __init static_call_init(void) > struct static_call_site *start = __start_static_call_sites; > struct static_call_site *stop = __stop_static_call_sites; > struct static_call_site *site; > + struct static_call_key *prev_key = NULL; > > if (start == stop) { > pr_warn("WARNING: empty static call table\n"); > @@ -279,7 +280,9 @@ static void __init static_call_init(void) > * The trampoline should no longer be used. Poison it > * it with a BUG() to catch any stray callers. > */ > - arch_static_call_poison_tramp(addr); > + if (prev_key) > + > arch_static_call_poison_tramp((unsigned long)prev_key->func); > + prev_key = key; > } > > arch_static_call_transform(addr, key->func); While it does indeed poison the trampoline before all users are patched, I had been thinking that it didn't really matter because this is before the other CPUs have been booted. But I believe interrupts are enabled at this point during the boot, so it would indeed be wise to poison it afterwards, in case an irq handler makes a static call. -- Josh