Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1016084imu; Fri, 9 Nov 2018 09:34:32 -0800 (PST) X-Google-Smtp-Source: AJdET5f9W672L+g2I9/ksLk+oRRkvADsZQlzyAQnbx8EuR2bmLxyKt0OUDeHDa1DtqBAFvz9JWpJ X-Received: by 2002:a63:2643:: with SMTP id m64mr8113500pgm.35.1541784872740; Fri, 09 Nov 2018 09:34:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541784872; cv=none; d=google.com; s=arc-20160816; b=GunlbdGn6kh1gQC9Oh3/+SjirSIresJz4tjA/w6CvP+a7K81GcUmbkO6ebzvtPwZxt K1k4AZCzCU26rBmdacS0VM7Q8cgvF8kJoyftf5czP8SE3ZkD7wuk9LgW+6y664pNgf5r NkFSnuxKJQ6oKBGsFWocX+Hu30IcT9A37+JHCX2beoJh7wke358So0O8/tLGZn5xnOL0 WPQ/6IbDNNZfSNcCYUOdn3q5soksC3TKbGWuSZQR/6UJWsUU0uOyKmwOqxz6UXgDzG91 i8xIYYcTC64gjcqxi3oBLxZVuXnrpcKOqzUpwN8u+xlZqpTQjj3QlgZ9dxU/v9217w+y tzHw== 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=GaXKJda1a0HIIzDJ+oi8Grj4uH5//Rd/ViWjsrFZVW8=; b=gGBf/PuPoXrxKj2c/420zcRF8lAkvkPy13jb3zDr1QZdFL+4wSsO9yURzG5rJx2R7i EfTkI/lpdLbRcctPjhU3AEJ2vXJpPxfeeAeyIdSG1pERDds/FmrmQRj1oTH2rO/Qds1X I7gPVPMzm3kDQdTTPyeuVEVMIRXB9gQddlc+NifMcC2qSHmZEsOktpFqguWLxLhtMBuO A2mlQKEVyevKEQHlDr0e99uWP9ZiubcJppHAy43IpfVm0L33kcFKel6tJ1qrLqeNO4sF DVOTNxQMD0sp9GvM4iXk6jvkwXYDy4u4LSrvRJUF8S4GHr1TRj2fQ283PHBt48WESPjn MmMg== 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 r27si7053212pgl.494.2018.11.09.09.34.07; Fri, 09 Nov 2018 09:34: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; 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 S1728684AbeKJDOn (ORCPT + 99 others); Fri, 9 Nov 2018 22:14:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60898 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727995AbeKJDOm (ORCPT ); Fri, 9 Nov 2018 22:14:42 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 286147F3E7; Fri, 9 Nov 2018 17:33:09 +0000 (UTC) Received: from treble (ovpn-124-61.rdu2.redhat.com [10.10.124.61]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8FB1E600CD; Fri, 9 Nov 2018 17:33:07 +0000 (UTC) Date: Fri, 9 Nov 2018 11:33:05 -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: <20181109173305.2trzwl7ugczxf6rg@treble> References: <3cf04e113d71c9f8e4be95fb84a510f085aa4afa.1541711457.git.jpoimboe@redhat.com> <20181109151028.faifw66enzye32gg@treble> <20181109173106.kbghzsdsu7oachl6@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20181109173106.kbghzsdsu7oachl6@treble> User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 09 Nov 2018 17:33:09 +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 11:31:06AM -0600, 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? Or are you only going to use the trampoline for out-of-range calls, otherwise just do direct calls? -- Josh