Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp648015pxf; Wed, 24 Mar 2021 12:22:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymslM31HwagKamhCfKYY6C0RNDuvPFU0YbU+oLCP0rLcTE1gcbGo0zFk0msdUI00LFqiPH X-Received: by 2002:a17:906:27c7:: with SMTP id k7mr5528425ejc.13.1616613752718; Wed, 24 Mar 2021 12:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616613752; cv=none; d=google.com; s=arc-20160816; b=b0yEvZP8MEzl9U1KqGBA6oA/ca4INtYsQB5Yi1QfFO/anSlRzz2UEaM1jYoSkq/9Z4 blqgrY4SNHJMb+HM/UAe68sq7U2Qb+ymzdx+ktWbsIBzYRNv+RkZdPqUb/XwcCu0bctZ peYO+zLCWGIxCxknYlFfvCuN2ani1mL0iHq+hdmUhy7WiNdbumzKt2i+sBjx45RUX19q uw/Qgnsv5txiqzSbqT8bfHRCTX4CSVy8J/cBGpJX70Rt9hJzVo85rl3XwaupNzwyf5g8 HjJEbu6GBIs2KvFOt1SbPWM3J/XRGIgNaS9G5dkA79jAnM8QJjgLrSnUq85DJklmaxn8 e5eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8kgmSg2ylYXDNqcwANjFrVhrVwVzypEMPaaOndJGkCk=; b=kUCjOOmBWiqToP1O2TPdf/tCFOW83OPwZ7XsoZSPHvREdQfNUUiaQVXl8Re+aFvg0G Ti371Aw8iaZsnuQvojEeDgaNEotdMedQ+7cyGPuIeiMx4e+kTakiaPlxRk0m96QJeuem wHk1U8DrCG2lnq0ZO3f04B2Cfkigpfr+4cKeJMBv6wz2OmtRldrUppxI4TRZZxtNNfjM 9Blp71ndXcgB5s5KUOUVnR5Yl94g/Nqn6f/7prvB+96Tv75ODBk9BC3jj7MvdzfjOJBJ XJOPQw6XMLSUZ5tpYzh9uwYzCh9H+bxhYkVl93VUTNAhDr/tsPcGy34IGln76djGJLZR i+bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=BCtxHDwd; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b14si2416582eju.424.2021.03.24.12.22.07; Wed, 24 Mar 2021 12:22:32 -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=@infradead.org header.s=casper.20170209 header.b=BCtxHDwd; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237780AbhCXTUb (ORCPT + 99 others); Wed, 24 Mar 2021 15:20:31 -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.