Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp863485imu; Fri, 9 Nov 2018 07:18:33 -0800 (PST) X-Google-Smtp-Source: AJdET5fN5/nToDrgLQ80EDx/1wkYl1le7f0dtXIAPpt6wvOITxMXEMLQHnLlYCIUH8g3/kIWHRuo X-Received: by 2002:a63:990a:: with SMTP id d10mr7860069pge.279.1541776712960; Fri, 09 Nov 2018 07:18:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541776712; cv=none; d=google.com; s=arc-20160816; b=aI6imBnLuF3E80VIjt7P9FdwPkYD5SzhOMEB9WnvuQiFS3icHVllcYTX3hRYm878Mb 7By1hNSVt67q1r5T/k7VtdX+PqJ+Pbpg711bFib6DQECm3hdfXzmCIAJhJqTUJlVLktP WBhHg9wrO4SWyzHaWQMRJHsSKNEsS69UyyK9JAPU/g3maz6OmE63WGKwWAdnBu+wd/pc AH0t14QWys0425Ykmh+skNPkN9RdLvbj9IZuJNuQR1yycPWCDgaJZOiBWiT2tK1iwR7U wxVk9MxNyWK2GCjhNusBseu5ecZ/PczQ0/BXMklhGOI04Z9o3/NV7TbZOLNqrX2Q3kcd 6MdQ== 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=QmEOCZhKoy4tMYvrz4DsulhuUxwi7kZKfWHrSbAKPsY=; b=ouaxViCm6TvjmsZVnDrghezHAxVp7rs3P/EKCGfSngOzHhONUxqrlxCkLZr7f43dwp FLrzo3SZXifhP1NjZnpkUaLZL1x48cKkxYk28a9HyUvJwX5p+D2jCbXiurse2pvdlFIL RlDSwKDO+FRANzMbW2VcA8suqsIWgJdgsK7nO6Df/4K3fRMjPQs583CMUZ6+i1WgYw9f 1DXdNigWmVGtg2bOkJ3XPcdneaz49Q+tB2bI28Ly3872VFeLCNe8Olv3d+8iweoca3e6 h+cMv1Ee0GHhQTXDyPQ2VWyYI4r1tScFhRvI4y5kYrvRDPMNNa9KYHib0GtkRZbnV/l4 MAiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h6PkiK7u; 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 m8-v6si6750472pgk.424.2018.11.09.07.17.32; Fri, 09 Nov 2018 07:18:32 -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; dkim=pass header.i=@linaro.org header.s=google header.b=h6PkiK7u; 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 S1728238AbeKJAzq (ORCPT + 99 others); Fri, 9 Nov 2018 19:55:46 -0500 Received: from mail-it1-f193.google.com ([209.85.166.193]:36543 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727735AbeKJAzq (ORCPT ); Fri, 9 Nov 2018 19:55:46 -0500 Received: by mail-it1-f193.google.com with SMTP id w7-v6so3715941itd.1 for ; Fri, 09 Nov 2018 07:14:46 -0800 (PST) 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=QmEOCZhKoy4tMYvrz4DsulhuUxwi7kZKfWHrSbAKPsY=; b=h6PkiK7uJATjFMAioiq1SOdVFad8kUSj7BiEsR5IOgT/GlVzhm7NbSlFLNBmePuckV R5Iq7/W+UPfV6M0RKNpSHQdg+nh6Y8QaYu7e0G+mSRPYJQGTSKFvnxarwb2bnEZvuxpC XcTdtdgq476dsCYw2fYLwV3BIc3TR2nAjoJSM= 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=QmEOCZhKoy4tMYvrz4DsulhuUxwi7kZKfWHrSbAKPsY=; b=ZVelGXAwO6aiIktaSF3LpTd7X3rICog1Fr+15FM1MCkGno90mFmIqACpZ05KH49pXE DbCnI+D0hRvebEQ92K5HZ839QSk0RXbRomN3IlyQirryFHEi2Z76OthO7f1Qrq4MMIb+ Dd5Wf/uEdzUA9NmxEmRfQEtL7kudgYLTrn6XTgSpRw2Puk7oGZeL86HBQx8Zk9wNl90Q Pqmn/mg543IQx84IVL3SOU9ZA+N7p6YA2Ymj/guwA2XWl1U0+AY1X9miavYpCe5Cf6SA am2CstC137adPd8G8k6TOPwLOfrnwicm1r6sAa9C+jkpN16o39COIvRAwdNaECaYfE2+ jujQ== X-Gm-Message-State: AGRZ1gKq41+6cTWjm84D+qGEp5X7ALBA7FrWH+Es9pV881JDEO/smWqW b0qRxXVK6YCFoFrsqDWOHCsY84diNiPAhrn6dQ5NOg== X-Received: by 2002:a02:8449:: with SMTP id l9-v6mr8480077jah.130.1541776486303; Fri, 09 Nov 2018 07:14:46 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a6b:4f16:0:0:0:0:0 with HTTP; Fri, 9 Nov 2018 07:14:45 -0800 (PST) In-Reply-To: <20181109151028.faifw66enzye32gg@treble> References: <3cf04e113d71c9f8e4be95fb84a510f085aa4afa.1541711457.git.jpoimboe@redhat.com> <20181109151028.faifw66enzye32gg@treble> From: Ard Biesheuvel Date: Fri, 9 Nov 2018 16:14:45 +0100 Message-ID: Subject: Re: [RFC PATCH 1/3] static_call: Add static call infrastructure To: Josh Poimboeuf 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 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 9 November 2018 at 16:10, Josh Poimboeuf wrote: > 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(). > Ah right, so I am basically missing a dereference in my arch_static_call_poison_tramp() code if this breaks. >> 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. > And kmalloc(GFP_KERNEL) itself could cascade into lots of other code as well.