Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1015414imu; Fri, 9 Nov 2018 09:33:54 -0800 (PST) X-Google-Smtp-Source: AJdET5eVjX0MV86nxgt0lL08tCnkp3/Alq0JHAPsI9J9KR3Yw8ThdgLeSBYA0/n3U4K96YbQZMkX X-Received: by 2002:a63:5a08:: with SMTP id o8mr8138548pgb.185.1541784834171; Fri, 09 Nov 2018 09:33:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541784834; cv=none; d=google.com; s=arc-20160816; b=DluCIAFk/ObiwpHAlHOPRbzcFFhDrMcaIrloLqWyCjoi5ImEgUv3+9FLSEgvpjaGR4 /0fXhBB2+EIpXlZ41/uD55KmrLWMVjwtF+s7hP2tbOJqw7XbHDSeqDRW0MSxLZaMFYdm Iwjpas9nATQCYve/MJdgGNugfUa73mlB8RZzZNa0oDhnbeftPVInFY5KPWc4h6sJDDT7 VXS/r5msWPhlZMTJ8G5/t9yndFOpmSt4LGw//fk4B8SCfRHCfqgTWo0I61Xl77eHc23h LakSWCvjuuN6DjPx4OMnG9fNbkwAbSD0yGUsvWj0yMhBShDKoDOE7Eq+MuS671LCW2Nk o9Hw== 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=ppVReJBmjdlTPmTn8NVww7VmSSW+FEaRCLk4/51wfkw=; b=cQp5UvEmNM4W9T/TOV+qeDlgM/PzEq3ZT23y3ziDCraIRzbYPg7ryNxCUJL+xJX6nf FpXTqb6ZrtGqaI3uJkaXsvzinFWK8kAAxiOwleEvak/YyAX6SumbHDP+/e3t9bCEGgJF 8/6v1TBkFzmOUd3vy3zczj7vKQXXisQVk38AAEs9OkKidRR5Vr1OH3umcfAARK7o1OK6 pFFeZfyIzk3McSUNGlfk8xF9IzoUUFHEVO6ckjTGr1nIS0VJ9s5w2YLNWAxfoLsH8YXP OGgBjV193t6MxcYEL92eK2/hsut+EtpBQTBhS/tDyWa6rGkm5tNfNf8AGizIrObsPkVV 284w== 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 27si7133020pgp.135.2018.11.09.09.33.25; Fri, 09 Nov 2018 09:33:54 -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 S1728496AbeKJDMo (ORCPT + 99 others); Fri, 9 Nov 2018 22:12:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44376 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728108AbeKJDMn (ORCPT ); Fri, 9 Nov 2018 22:12:43 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8ED1308ED4B; Fri, 9 Nov 2018 17:31:10 +0000 (UTC) Received: from treble (ovpn-124-61.rdu2.redhat.com [10.10.124.61]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ADDF560A9C; Fri, 9 Nov 2018 17:31:08 +0000 (UTC) Date: Fri, 9 Nov 2018 11:31:06 -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: <20181109173106.kbghzsdsu7oachl6@treble> References: <3cf04e113d71c9f8e4be95fb84a510f085aa4afa.1541711457.git.jpoimboe@redhat.com> <20181109151028.faifw66enzye32gg@treble> 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 09 Nov 2018 17:31:11 +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 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? -- Josh