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=-3.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,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 0AB81C352AA for ; Mon, 7 Oct 2019 11:24:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D008321655 for ; Mon, 7 Oct 2019 11:24:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="s/E/I2TN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727877AbfJGLXp (ORCPT ); Mon, 7 Oct 2019 07:23:45 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:50202 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727757AbfJGLXj (ORCPT ); Mon, 7 Oct 2019 07:23:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-Id:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=6ytk5toi7ed/P8/QssHvJfGQ5q0+1cUdkvB+sfDzJjE=; b=s/E/I2TNRa3DbCnecuOw5dQpVc pYhrewMij9MesigPP0Wkdd+cfkheGa0yVv1NDwT9ICCbkJqaHkSL117gxWdZsH9H6ijbJTOTIREQt N6FqTP2sFb1QvQ0e/2JLcKjzDPqI5BAtSCVTAmYBpsBY2R9EpxKOL7mH2D1ItkMjngUJQANPTATMC jUJ8IZ8pNjGk3dRYnAm+Jc6KEmZzMZk4lihf/K6ofraCfZKEF2mK9FSaI4Y+EyqbqHDiHLwvASvNV YtKorBQgdvHLjxn+RT0PO5jcUenrFEaL23wQb8W9hH39GgsEAUDV+J0dG5G3BAwj1qAo2bXP8bQi+ k7WVEdUw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.2 #3 (Red Hat Linux)) id 1iHR6w-0003GQ-Ek; Mon, 07 Oct 2019 11:23:30 +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 29A49307093; Mon, 7 Oct 2019 13:22:36 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id C87C220244E24; Mon, 7 Oct 2019 13:23:26 +0200 (CEST) Message-Id: <20191007083830.92867794.0@infradead.org> User-Agent: quilt/0.65 Date: Mon, 07 Oct 2019 10:27:15 +0200 From: Peter Zijlstra To: x86@kernel.org Cc: peterz@infradead.org, linux-kernel@vger.kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, bristot@redhat.com, jbaron@akamai.com, torvalds@linux-foundation.org, tglx@linutronix.de, mingo@kernel.org, namit@vmware.com, hpa@zytor.com, luto@kernel.org, ard.biesheuvel@linaro.org, jpoimboe@redhat.com Subject: [PATCH v2 07/13] static_call: Simple self-test References: <20191007082708.01393931.1@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Peter Zijlstra (Intel) --- arch/Kconfig | 6 ++++++ kernel/static_call.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) --- a/arch/Kconfig +++ b/arch/Kconfig @@ -103,6 +103,12 @@ config STATIC_KEYS_SELFTEST help Boot time self-test of the branch patching code. +config STATIC_CALL_SELFTEST + bool "Static call selftest" + depends on HAVE_STATIC_CALL + help + Boot time self-test of the call patching code. + config OPTPROBES def_bool y depends on KPROBES && HAVE_OPTPROBES --- a/kernel/static_call.c +++ b/kernel/static_call.c @@ -364,3 +364,31 @@ static void __init static_call_init(void #endif } early_initcall(static_call_init); + +#ifdef CONFIG_STATIC_CALL_SELFTEST + +static int func_a(int x) +{ + return x+1; +} + +static int func_b(int x) +{ + return x+2; +} + +DEFINE_STATIC_CALL(sc_selftest, func_a); + +static int __init test_static_call_init(void) +{ + WARN_ON(static_call(sc_selftest)(2) != 3); + static_call_update(sc_selftest, &func_b); + WARN_ON(static_call(sc_selftest)(2) != 4); + static_call_update(sc_selftest, &func_a); + WARN_ON(static_call(sc_selftest)(2) != 3); + + return 0; +} +early_initcall(test_static_call_init); + +#endif /* CONFIG_STATIC_CALL_SELFTEST */