Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1120466ybj; Tue, 5 May 2020 13:30:20 -0700 (PDT) X-Google-Smtp-Source: APiQypI8e+CeL1nD9tb9pmjwk+ZmiyOBXyDbw3azu7Dw6CnAUMfaO45r0XeOqNjVMNfzSgCk9/mY X-Received: by 2002:a50:a0c7:: with SMTP id 65mr4349936edo.7.1588710620392; Tue, 05 May 2020 13:30:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588710620; cv=none; d=google.com; s=arc-20160816; b=v6/NfQIgHMDpprxmZ/PlvwWTeHMxTr7nluvRZ9JsR2oby5J7npU7AEtKC24S7spp8m 4KxbSjLialXmVd4FcINulty3Klc31ZG+jgv4e50jirkjAZdojAfhyuC9ruyIQfMeqRuQ AEUsf+cH/meH+STFv5iY25abJDV8U6mARHT77NG3wlZbktT3cPudGmC5pKUxWYsESdNY o/OBIJm/tUWwEAZ/4Sp7S76c05Ot9eLXn4AJl7bdBwGB9SSAzqDsu+kH5kHp+LX6afjJ tu1WQhfWsWmf2PV5CG7DryakrBVSa2sPDbY4v3T9mjXqQsvBszkjfH2Va3s4rr0mpSFa +bTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=GrEmWaFbMd1zFTo9Cuyp79HV+BYqRIRTCdvEBTTf208=; b=dxBbyNwWlA2tQE4eEUT1p4ROMuIBpFiHk7DgDQUrULw8LiGqrilpHAzqn7y5PsfxI3 nZrRt5eEaNDLWxhDa+jiPmFDq4i0ijYes9Ae/rTfMivwWE70MsGGo6NClfA2sLWk8K61 6AUmtmuKOETVEBBzS5ZOdZXG5+uw5h8G53I2Z60Ew8hj74SJJfVBzHsqLvD6WHFttCoR aA53GL4HIkAJ0JIBKYFNZ2JdNUu14xedYmC791Z7hPA5wuc2VtPfc/97U/5Nhx3y+el7 /31Jx5smijokC7CVRQ5XmL+nw5f/4KAmqFlkjeaO3XBc0NoBXnGA57PBwlfzqBPq5NdV o1uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=Lp4rHoS4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b21si1871713edr.47.2020.05.05.13.29.55; Tue, 05 May 2020 13:30:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=Lp4rHoS4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729229AbgEEU1t (ORCPT + 99 others); Tue, 5 May 2020 16:27:49 -0400 Received: from mail.efficios.com ([167.114.26.124]:49728 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729205AbgEEU1r (ORCPT ); Tue, 5 May 2020 16:27:47 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id C60762A228A; Tue, 5 May 2020 16:27:44 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 4EYqnJQ3nAPy; Tue, 5 May 2020 16:27:44 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 508502A2289; Tue, 5 May 2020 16:27:44 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 508502A2289 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1588710464; bh=GrEmWaFbMd1zFTo9Cuyp79HV+BYqRIRTCdvEBTTf208=; h=Date:From:To:Message-ID:MIME-Version; b=Lp4rHoS48kj8kZbeFHUHJBl80koszFDldwF0bz+C5sOrRkWG5tI0InMDDHd6YbqZN +7gZEeRoz3HXDyRf+xZedU44s8slQZluNIcJCvV53YlTX/fNniT6soWk32/RRjNmRK 6+zuHPP/9O+8ujpiyryj9GNIoW8YHhvSv5WnRVdQ4UMZoN+czKCZswfoLWgsfT+QM1 SvKMmWFRZ1KnFtss9Mkv+kx5SskHPnm8vkhGNJ2NXctPkp/waG/D8bAx86QicIrmvJ +kuixQJ1j+7laaMv6pHo/6inHLzyKn+twGlTUvnNU5ZK7ldaXPEPSCB7aIfFz8bXAq FTHEEiT3azbUg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id cCHThXy3vm1O; Tue, 5 May 2020 16:27:44 -0400 (EDT) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id 3CBD72A213F; Tue, 5 May 2020 16:27:44 -0400 (EDT) Date: Tue, 5 May 2020 16:27:44 -0400 (EDT) From: Mathieu Desnoyers To: ndesaulniers Cc: Linus Torvalds , Peter Zijlstra , Rasmus Villemoes , x86 , linux-kernel , rostedt , Masami Hiramatsu , bristot , jbaron , Thomas Gleixner , Ingo Molnar , Nadav Amit , "H. Peter Anvin" , Andy Lutomirski , Ard Biesheuvel , Josh Poimboeuf , Paolo Bonzini , "H.J. Lu" , clang-built-linux Message-ID: <470458191.1021.1588710464160.JavaMail.zimbra@efficios.com> In-Reply-To: References: <20200501202849.647891881@infradead.org> <20200504201445.GQ3762@hirez.programming.kicks-ass.net> <20200505093625.GE5298@hirez.programming.kicks-ass.net> <656098739.766.1588705237442.JavaMail.zimbra@efficios.com> Subject: Re: [PATCH v4 14/18] static_call: Add static_cond_call() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_3928 (ZimbraWebClient - FF75 (Linux)/8.8.15_GA_3928) Thread-Topic: static_call: Add static_cond_call() Thread-Index: LKX/yK89nuESaon3x7N5kSfc1EEjRQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On May 5, 2020, at 3:57 PM, ndesaulniers ndesaulniers@google.com wrote: > On Tue, May 5, 2020 at 12:00 PM Mathieu Desnoyers > wrote: >> >> ----- On May 5, 2020, at 2:48 PM, Linus Torvalds torvalds@linux-foundation.org >> wrote: >> [...] >> > >> > Your initial reaction that "you can't compile away the read and the >> > test of NULL" was correct, I think. >> >> I suspect this pattern of "if (func != NULL) func(...)" could be semantically >> changed to just invoking an empty function which effectively does nothing. >> This would remove the need to do a pointer check in the first place. But maybe >> I'm missing something subtle about why it has not been done in this context. > > Good idea, this eliminates the check: https://godbolt.org/z/Xugo9w > but you still have an indirect tail call (I think a direct tail call > is the desired solution?) Actually, if the goal is to do code patching of the call, I wonder what makes it OK to "guess" all the call patterns generated by the compiler ? AFAIU this is not an ABI in any way. For instance, a new compiler version could choose to add some no-op instructions within this pattern just because it feels like it. For static jumps, we worked with the compiler people to add "asm goto ()" so we could express a jump in assembly which would branch outside of the asm. Emitting the jump in assembly allows us to control the exact code pattern, which can then be patched, and the asm goto operands allow the compiler to be in control of all the allowed branch targets. I'm again possibly missing something, but it looks like this proposal of static_call() (especially the static_cond_call part) is trying to just assume the common call patterns generated by the compilers, and patch those. What is the expected behavior if a compiler ends up generating unknown code patterns in future versions ? I would think a more robust approach would be to, again, work with the compiler people and introduce something like: asm call ("asm goes here" : : : funcA, funcB, funcC ) which would allow patching the call emitted _in assembly_ between the various available targets. Bonus points if the compiler can let the asm know whether it's a standard call or tail-call. Then once we have that, we can start doing fun stuff like adding a conditional within the assembly, but I don't see why the conditional should be the same variable as the actual function pointer: each can be changed independently as long as the function pointer always points to a "valid" function (not NULL). Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com