Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1007505imu; Fri, 9 Nov 2018 09:26:32 -0800 (PST) X-Google-Smtp-Source: AJdET5fe+pP7cikUfg+ma7TmG6w2QqA4HCfy+nteCevi6IjK+tSNKFBwjzukHlpyPLtaPykqdBFB X-Received: by 2002:a63:94:: with SMTP id 142mr8120903pga.74.1541784391955; Fri, 09 Nov 2018 09:26:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541784391; cv=none; d=google.com; s=arc-20160816; b=UFc8DG6Cy2NcH3WRYIMu1W+GHR4q2Ty7IcasIvUthKfA8HAIlLBDwX2Vdkzwf/BDTi aq5jRBX7yHZXWl7OrP0K4Rdz+3TW+WZLL78ONwadLMPSSXuYP0OGteFDO5qAxnRXnrhl tGArfBRC6nSjPNzlYqFW6SXzrjXkIXXTRKwaDtNktNpehmcSvkbU+fm1lBNxOXXtgp38 1ggE0JTD3mNzEKvIfT4kwV+X2h5DlzYjJ4MMvnhjsaA6VrmpAyj7B9oGqkn9miszoAFI 1aj8dM5iyjbFHHckZlS5UcFAXSSZ+oNtsARJyzHUp6oaeYFPMuG3CsqkM9cxsCKFuiAd zb0g== 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=9aGMBaqfHr5+oz0GStiUC20Z8K8nSZZh//9q/PC4HTY=; b=Pv/yF/nHbfylImhdCN20Nt2ZsUUg+mF1TDBaT531rbcaMYkPGI9kQSRm4fZ50GPnfL nlgbiFrKrJy2JdwSvWMk2yCVdY6LJlGliqofepagMEfVeicTolUSKD/Swv5WVqMpDeQO hv2PnDGcx28JryeSitEMCfLstQMdg4vAmB6QYu+hqq6XnaUDDVSUT+d75k0BSSZjBpaQ X9NWe8PU+TcJN2EGe3pBZQDPna3tYXR5j2HoSXbYUYZx0Zcllqioe/pfwSNsl/LlXPUQ 7XI/PVscFtJaJ3sc7/k5BQoEVE4TGcbLGuTvrnwfx/zXFsAs/5n3YbODma5RFWhErMK9 ZTZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GgWNlcXH; 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 73-v6si8343954pfs.7.2018.11.09.09.26.01; Fri, 09 Nov 2018 09:26:31 -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=GgWNlcXH; 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 S1728394AbeKJDG5 (ORCPT + 99 others); Fri, 9 Nov 2018 22:06:57 -0500 Received: from mail-it1-f193.google.com ([209.85.166.193]:36604 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728026AbeKJDG5 (ORCPT ); Fri, 9 Nov 2018 22:06:57 -0500 Received: by mail-it1-f193.google.com with SMTP id w7-v6so4410293itd.1 for ; Fri, 09 Nov 2018 09:25:25 -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=9aGMBaqfHr5+oz0GStiUC20Z8K8nSZZh//9q/PC4HTY=; b=GgWNlcXHDfun5IlXKHNJ/saWyUR3Wk61IZwk6LPbtCnrA0mHZEH4DkH/rp5dD4/FSY d5HPh5d+kbeSeS4GccboLBgegucqZwk2jBo1bMFO/wezkngg2km1l4muizNZEBf4lEiZ gNLkaVDMxgzhyVt8peKl1RO5nQ30RFw26qjPI= 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=9aGMBaqfHr5+oz0GStiUC20Z8K8nSZZh//9q/PC4HTY=; b=jLcwXvJcj97qGD3xezwARwaZtYrJO01u//zkXCbYjbXlh0hTfNJYZ9ce+o1Y8P6qXC QqSvJovQiwP31PbiKEgm4JHodsKjH84cdGiKESLuWv5MY/zUez5U0HNzXls+BUcUcSSL l+/MWwhLw4XJxI4HXTOlGLVR1nea5kL2ADiPAM6IdRaBWpKirB74/BJI3LLq4IPWh/EA qDIz6a+YF2CIuOJ0mtujtDfFWIpfN37gbUC70WQbTdoNAYk4ZYudN0ZtAko77eBSbsYr t5Im9WyPDUK9wW+9pON2PIaLJTsuJQkz0nEUhl56eoUzTB2/UN843izbzpSBNN7tX3hr MkTA== X-Gm-Message-State: AGRZ1gJQOr6CrW8TGd8jYZFCfwq6Wa+GhZS1ICRqM/Mte1Cus0HHSMPB zjsLYVZhWK2GdoypGRnvG35H6TTMDnITk+o3lm/atw== X-Received: by 2002:a02:9f85:: with SMTP id a5-v6mr8696367jam.2.1541784325233; Fri, 09 Nov 2018 09:25:25 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a6b:4f16:0:0:0:0:0 with HTTP; Fri, 9 Nov 2018 09:25:24 -0800 (PST) In-Reply-To: References: <3cf04e113d71c9f8e4be95fb84a510f085aa4afa.1541711457.git.jpoimboe@redhat.com> <20181109151028.faifw66enzye32gg@treble> From: Ard Biesheuvel Date: Fri, 9 Nov 2018 18:25:24 +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:14, Ard Biesheuvel wrote: > 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. > Could we call it 'defuse' rather than 'poision'? On arm64, we will need to keep it around to bounce function calls that are out of range, and replace it with a PLT sequence.