Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp41725pxf; Wed, 24 Mar 2021 20:21:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyx1n1/EC6iGfEZLc/7ZfIVDC3KSM9oOnRFW+fjGdH0CagDVn9p5kVj901mlPsI1YTsBQdv X-Received: by 2002:a17:906:8447:: with SMTP id e7mr7174292ejy.523.1616642460555; Wed, 24 Mar 2021 20:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616642460; cv=none; d=google.com; s=arc-20160816; b=utRjvUOS3y3xiFQEjzH0aBUno2LTDV2xCEca6T+5OdEpAaX79uu/30cB1jooG1+ucv ztow1r+RdmAgf25YW4XqHWfNOOTWFK7Qe3vqpgYh61+GiewnBs1D6TA/qbPk/T1At7KV YwKDxQp6j9k3lgvFNAKxS6B2k2WUMJPBorW0bG6BESOKwKKJEdnPoFSeF7myLh1vC1Y6 E7dfkqBhfGRkxNLeeN6eTKF6KZbzgV/psFR7Urd7g9bYcC/RmH3KHlhFy4keDkDh0OV1 tFCS+G3ps1c8p1+j80acX5RrbER0dtlp+kvqkEQZK74Ee2Myy1MWo3cH7PNBPWBgJSJI SUhA== 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=2NU6FPwrDnfXjj/zGjqnsj9oELpXyMIcySZnpRlsrj4=; b=xzbcd5khKtzQugenXCukmTKCTAMpFiEdb9eNTAtlu3ySKEW7xrA2QbO4dfEabLW98M JBl02ObdSaujNuu6A92o9+jlBjkCzXvRD/1SU97Q/hkug8oWMat7ncWVcoq8wQSfbMtl 6RR4u/f2oCieVkXxeOG2nmgGiA54AQ/mkJ1wqYmMyLaB5fgCeBMIyFW6i4HqJGIhFekH cVyYqBQVmAGOYccUohZos4UJWvkZjC1CzV2FhFDo0Rk/paVGkvyB21YgN7+u0qJkwQv7 qaU2A6z0kO/J86iy9iXGcXp2by5dl7OQNpJmzQCdbV0ka7uO/7OqzyP8cY0vJiS4SJjO DYkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=k6L2iCNM; 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 a3si3171187ejv.34.2021.03.24.20.20.38; Wed, 24 Mar 2021 20:21:00 -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=k6L2iCNM; 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 S237277AbhCXRgt (ORCPT + 99 others); Wed, 24 Mar 2021 13:36:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237109AbhCXRgm (ORCPT ); Wed, 24 Mar 2021 13:36:42 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ADBFC061763 for ; Wed, 24 Mar 2021 10:36:42 -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=2NU6FPwrDnfXjj/zGjqnsj9oELpXyMIcySZnpRlsrj4=; b=k6L2iCNMo7jtezpMv5NlRBf+Y/ SwfrqRu9UpWB7o0QL5C+od/Dum1FBItYKsfmmji7UbmCLN3zhP6vvMCt9xmiRtMmKmBSeI6+DSxce bLz+J633/2844gBO/knNa4/SsUZ7caQiQA9o/UAy4pN/lCiv8T5dvK/Bg+WlsPVHay0getESkacWd iHWn+72oc2JCJ7vw/NJZz2+5CcBoiyqWqAj4DwbsrFX/QrqIfwWNLYamIkawn/vPwksQoussAUEdc obKzcekmp7toQ7GUaVuGZSQLnIHMyO4V732Yj8NKs+4SIBY+pJYqKp6tAod6pjiM5ceVF3sauAxFK H0BwfBuw==; 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 1lP7O1-00BdaQ-08; Wed, 24 Mar 2021 17:34:21 +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 ACC72306099; Wed, 24 Mar 2021 18:33:39 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 8D3F22CB17AFA; Wed, 24 Mar 2021 18:33:39 +0100 (CET) Date: Wed, 24 Mar 2021 18:33:39 +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 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 return value is in a register. Per the first we can call a function that has a partial (empty per extremum) argument list. 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.