Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1017874imu; Fri, 9 Nov 2018 09:36:17 -0800 (PST) X-Google-Smtp-Source: AJdET5egUgUrh9hjPvMXKObKetI39XH5j3V9YGk1vJLrpHlAoYWk0r//Qr8mLFAw6s1mjHF3n7ut X-Received: by 2002:a17:902:274a:: with SMTP id j10-v6mr7868874plg.312.1541784977356; Fri, 09 Nov 2018 09:36:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541784977; cv=none; d=google.com; s=arc-20160816; b=hHJ10Wn3D92XWTauPK0JcI2nRFADJPzKUZzJi1w+q6fG2dk0EYSByGoLvx1d9c6GWQ 74fvcsKsIvg/tPyseC3qjtM2RuNX6HJk9ifWnykA7ubD194CsiH/6PHVdqsNu2RxiXGH d3D+mH8dVzJimBcI+vviIIchR77HA3sAWeaH+ISUk3dnbzjG/WhyUE1E4ku83llt2dvf B6l4slYHgbnP9lKbkr42oc+G1PmXOKMcBtN+63bmi/6KcLPuYMVlHq9AbmQ3zK+cr/N+ 0NQPbA80FAm9sSB+OZD5AHBbG1CXrSIdsNqJtO5a6LSgNfk4oBuvEgpQjCl9j9akoJuW YCPg== 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=Y0mTa6CzOgMxMA2AaM9ekXteSR4TlRcoRvvA0OlUSKg=; b=OGnbf0/RKCJh1UVp5zyu2TQm4qwJ2Heeo5Ft+uUgB3xxl/GePOUfQGpJOgMHEH2FiA iiZEw9c8RTk8m+Ptv69hNcNTe44EtTaoS/R+HMBVhKhfhBjh7sz9KeZ1y4kYfZXf9+QR rFR8StZ73tFSVibNQxlzFsJLfep8bltwkIJYbzbonq4l7qh4nMWdT8GMuU7JGeE3D6mQ u38b/1gZHIT1iEpHh5K2CS/KkUCViccXOtdbADIWi60nrxjI3sE3FcZVOPTifg9ZIFIt kUi4/0YC79lAeEArtZ6nHhM7WUamswYLT9Q+kfXONXJCF1d7vnzS4qu3UkuUHvo9ZK5u oVSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ctn1Om2t; 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 y15si6950903pgf.321.2018.11.09.09.36.00; Fri, 09 Nov 2018 09:36:17 -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=ctn1Om2t; 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 S1728668AbeKJDOi (ORCPT + 99 others); Fri, 9 Nov 2018 22:14:38 -0500 Received: from mail-it1-f193.google.com ([209.85.166.193]:33807 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727995AbeKJDOi (ORCPT ); Fri, 9 Nov 2018 22:14:38 -0500 Received: by mail-it1-f193.google.com with SMTP id t189-v6so4970490itf.1 for ; Fri, 09 Nov 2018 09:33:04 -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=Y0mTa6CzOgMxMA2AaM9ekXteSR4TlRcoRvvA0OlUSKg=; b=ctn1Om2tAQVvrSFuojnMqSLeKqgO1INaUf/p+u4/Uu6Qhy6BTVah5GPxKMTd/YhvST hZZqqZhSDYv1m1asSpn+xRLPyPXy4omcK5ZTH+nmqtxVe0P13OOuqFf1Ti6CTBhoyBdD R7LSIyL1ldFrHu1q6CIu8KclY8UvXYWgua/FY= 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=Y0mTa6CzOgMxMA2AaM9ekXteSR4TlRcoRvvA0OlUSKg=; b=bS6JXBtYadc7fYwlpmmPy2MhhMsvZvfKWK5l2gCKTdwS6f1rU9NuIkw+VYmhfTZMy0 OXRO4kOx1NldnfU4mpqUBBOIVUexyVqajOJDfuzwRAnfQ5DcWREBPROOvm+nWsTrCrOt oKiJLZzaa82ip56GmzW7zgq4Ztihy54aA6VbAa47nG2nx9fnac4Ee+K7MhbEWnmt4Dto u4+otGKO4Ei/7PeaRlZhjQG8eEu/gpIVKGB3SghlRe9Ehfa2wgdH8nfkgcO5DD+scraC QQq6tD1F39OPTNq4zPI0V/LQNxbjca32o3RHwpdWKdtzCIXOi0/UI46bWffdHaYUXFj2 Ws0g== X-Gm-Message-State: AGRZ1gI/AEs4rY9RYw5pvDp2N4CzTULZjRzOAWjcc4OBo30omFFLE+Ih tCmrbpvouzSm0iaAXKE3Qt3hdDPRZGR63TGuRDPV3Q== X-Received: by 2002:a24:8347:: with SMTP id d68-v6mr3232125ite.158.1541784783999; Fri, 09 Nov 2018 09:33:03 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a6b:4f16:0:0:0:0:0 with HTTP; Fri, 9 Nov 2018 09:33:03 -0800 (PST) In-Reply-To: <20181109173106.kbghzsdsu7oachl6@treble> References: <3cf04e113d71c9f8e4be95fb84a510f085aa4afa.1541711457.git.jpoimboe@redhat.com> <20181109151028.faifw66enzye32gg@treble> <20181109173106.kbghzsdsu7oachl6@treble> From: Ard Biesheuvel Date: Fri, 9 Nov 2018 18:33:03 +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 18:31, Josh Poimboeuf wrote: > On Fri, Nov 09, 2018 at 06:25:24PM +0100, Ard Biesheuvel wrote: >> 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. > > Ok, but doesn't that defeat the purpose of the inline approach? > It does. But this only occurs when a module is loaded far away, and this will only happen if you have 2 GB range KASLR enabled, or your 128 MB module region gets exhausted for some reason, so the majority of calls should use a single relative branch.