From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08934C433E3 for ; Wed, 24 Mar 2021 19:21:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C42F461984 for ; Wed, 24 Mar 2021 19:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237659AbhCXTUd (ORCPT ); Wed, 24 Mar 2021 15:20:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237803AbhCXTT6 (ORCPT ); Wed, 24 Mar 2021 15:19:58 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BCA9C061763 for ; Wed, 24 Mar 2021 12:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=8kgmSg2ylYXDNqcwANjFrVhrVwVzypEMPaaOndJGkCk=; b=BCtxHDwdxKWOhsxmruZlJyx6te 39ldE0kuQTepQHtPTtDie7WFVMFAkNUY1taLDkcT6BEVORC6AcXimYfeeo3qmP9flKW8Ww6j2by9C pzoBPs7jM+DWDTTfdTQB231ncFIotdUYmManYwlYO6ovrX49ivrdyNJJygaRYRamIE0rzLCuZm0mJ 1unkJWlzLw+iTJPxdVJLZv+2mPGrYaZOd72DMiIJRmFINNE9/4z+OOlus1ah8B9+iD52kuSeXIh0j 01O2RfFZW/yobHjl0RqdMqLgQGfAoA0AIS4xbvPgLRkshpWBEMZzd5g2jG4YENTRcEI2ldkARxQpb c1Dq5C6g==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lP8zA-00Bkwf-M9; Wed, 24 Mar 2021 19:16:24 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 2F6173062BA; Wed, 24 Mar 2021 20:16:07 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 093DA203D944F; Wed, 24 Mar 2021 20:16:07 +0100 (CET) Date: Wed, 24 Mar 2021 20:16:06 +0100 From: Peter Zijlstra To: Rasmus Villemoes Cc: Sami Tolvanen , Rasmus Villemoes , Steven Rostedt , Arnd Bergmann , Josh Poimboeuf , Jason Baron , Ingo Molnar , Juri Lelli , Vincent Guittot , Ard Biesheuvel , Dietmar Eggemann , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Frederic Weisbecker , Linux Kernel Mailing List Subject: Re: [PATCH] static_call: fix function type mismatch Message-ID: References: <20210322170711.1855115-1-arnd@kernel.org> <20210322153214.25d869b1@gandalf.local.home> <20210322172921.56350a69@gandalf.local.home> <0f4679d6-44a4-d045-f249-a9cffb126fd4@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 24, 2021 at 06:33:39PM +0100, Peter Zijlstra wrote: > On Wed, Mar 24, 2021 at 05:45:52PM +0100, Rasmus Villemoes wrote: > > Sorry, I think I misread the code. The static calls are indeed > > initialized with a function with the right prototype. Try adding > > "preempt=full" on the command line so that we exercise these lines > > > > static_call_update(cond_resched, > > (typeof(&__cond_resched)) __static_call_return0); > > static_call_update(might_resched, > > (typeof(&__cond_resched)) __static_call_return0); > > > > I would expect that to blow up, since we end up calling a long (*)(void) > > function using a function pointer of type int (*)(void). > > Note that on x86 there won't actually be any calling of function > pointers. See what arch/x86/kernel/static_call.c does :-) > > But I think some of this code might need some __va_function() love when > combined with CFI. > > But yes, this is why I think something like -fcdecl might be a good > idea, that ought to tell the compiler about the calling convention, > which ought to be enough for the compiler to figure out that this magic > really is ok. > > Notable things we rely on: > > - caller cleanup of stack; the function caller sets up any stack > arguments and is also responsible for cleanin up the stack once the > function returns. - the arguments are pushed on stack right to left; > - the return value is in a register. > > Per the first we can call a function that has a partial (empty per > extremum) argument list. That extra constraint is required to make partial args work; as it happens we only use empty args, and as such don't really care about this atm. > Per the second we can call a function with a > different return type as long as they all fit in the same register. > > The calling of a 'long (*)()' function for a 'int (*)()' type then > becomes idential to something like: 'int x = (long)y', and that is > something C is perfectly fine with. > > We then slightly push things with the other __static_call_return0() > usage in the kernel, where we basically end up with: 'void *x = > (long)y', which is something C really rather would have a cast on.