From patchwork Wed Jan 10 10:48:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 186787 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp709340dyi; Wed, 10 Jan 2024 02:51:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrNBE4004NZ5f3dV4eVt8wwrcHid4vtI8OoDYyl+Dcj2dZ/9wSjhHQUwzlyL8oMvxzXrUh X-Received: by 2002:a17:907:9195:b0:a27:941f:32a1 with SMTP id bp21-20020a170907919500b00a27941f32a1mr391840ejb.58.1704883874611; Wed, 10 Jan 2024 02:51:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704883874; cv=none; d=google.com; s=arc-20160816; b=as0cc0pDgiq0QUB4BLx7WdT/oPnxRp6jb0UrEHftdEi2P2TugTdihmYHTWKwJnLUVD dZAdAgLS2BAoux5q4RiD5uTdcG1qytixk/jtWk2SBHUwOCmS+br6crv7u+AjLrS1p+OK PHgav2+EPG61PZmc9+zf6esU3NrijCN+DyXfhpH4aeQMrTa0I49x2Cah11fYOCP/yRfk QpnFbT79hjgieHGJrXJpp3F2YHGdFXzdeYQ8lTRkEVf2E4Q7Iv+sCA+sDFR8hxteBEKJ 721cvJ+lAFSzlss+gPJ6mHg2YXh7kZzwohv/uFyl3+ezPwz3QyAdwH0a4EuQwU8prgTC 0emA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=feedback-id:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=01XDLaUcBT2RQ9V7wGx1eLRm4Rge4cU3oPm+Kmesajw=; fh=wt9W4g6arwYNy+xc95k5dGrNePOTFQIHPt2Vnmtg5SU=; b=PE9+nJ92OfYyEr6o5JTWHHGXmCnkA0MHUYPJ/LKnwtYtQN2KXArGKBkA4PZKelPg3g BhlWw+4TGdcuc/kr9AOErlArHuVyFEVWrS3FUM1bFJAWAjq1ghfN3XnKw3XGYi7anW0M NCq8BA34Vpznwp0xmpMsF/h0G1OQjNkCiH+NIi9ZFYbO45HlzPCAimkf3x36VNZOPzFI K5HU1mT6ZA9PkiyZcbiupfowwUzx+72y2jIeS9luwOosaHEK8j53YGqFYiyYMb18PqOv tX/qxORUi/XTMnTSBjJ2SmTFVtN9P6H5Y5BUOHjhq2V40mACfLmfb7HIk01yenwMBGBC hJSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-22019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22019-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id c10-20020a170906170a00b00a26aa16625csi1675576eje.187.2024.01.10.02.51.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 02:51:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-22019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22019-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3B7D91F24E9E for ; Wed, 10 Jan 2024 10:51:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A2CC47F64; Wed, 10 Jan 2024 10:49:54 +0000 (UTC) Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3084047A6F for ; Wed, 10 Jan 2024 10:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tinylab.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tinylab.org X-QQ-mid: bizesmtp72t1704883746tldabub3 Received: from ubuntu1.. ( [221.226.144.218]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 10 Jan 2024 18:49:04 +0800 (CST) X-QQ-SSF: 01200000000000B0B000000A0000000 X-QQ-FEAT: U4uNK7LTfdqXYB2ToMtJLJ8+FJ8X+0ubq/JvtvJPoyrv7YmBWN6qqiKxSdBXd IT2aGPQ5BL4kdR8KXdvkjNASv50uYGfhnhM/7oqOondEo7XPMWdwg2Arx3WCFheQWfv+RUA y+mFM28hPPNoDB/Y4OB8TpJ8Es6huXwhlG+IxT0TSgfzYDx9fzfX5j3JI3Kq61XeAKkfKDb ND4xTPAfCuZWEjwYSJmUdz8v8pszn2pq9u96/8z+qIk47qwZ2nhcOPMpDgfnFA8ebQCQO0E AUIYbkNQNeYgslkv7qTDVR7DSAb+G+9ct9w4lUAdASph8Y+tYisM2O0LwONCX3MHaItcRmT wuCyFd5h26gwQADdgjob610BDTWBjQzTh6PNbEM X-QQ-GoodBg: 0 X-BIZMAIL-ID: 13203849688828320885 From: Song Shuai To: peterz@infradead.org, jpoimboe@kernel.org, jbaron@akamai.com, rostedt@goodmis.org, ardb@kernel.org, songshuaishuai@tinylab.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] static_call: make selftest available for out-of-line SC Date: Wed, 10 Jan 2024 18:48:54 +0800 Message-Id: <20240110104854.292752-1-songshuaishuai@tinylab.org> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz4a-2 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787700313573211490 X-GMAIL-MSGID: 1787700313573211490 Static call selftest should be built once HAVE_STATIC_CALL is configured. but it's now bonded with HAVE_STATIC_CALL_INLINE. Move selftest to static_call.c making it available for out-of-line SC. Signed-off-by: Song Shuai --- kernel/static_call.c | 44 +++++++++++++++++++++++++++++++++++++ kernel/static_call_inline.c | 42 ----------------------------------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/kernel/static_call.c b/kernel/static_call.c index e9c3e69f3837..b1e1b4573201 100644 --- a/kernel/static_call.c +++ b/kernel/static_call.c @@ -1,8 +1,52 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include long __static_call_return0(void) { return 0; } EXPORT_SYMBOL_GPL(__static_call_return0); + +#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 struct static_call_data { + int (*func)(int); + int val; + int expect; +} static_call_data [] __initdata = { + { NULL, 2, 3 }, + { func_b, 2, 4 }, + { func_a, 2, 3 } +}; + +static int __init test_static_call_init(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(static_call_data); i++ ) { + struct static_call_data *scd = &static_call_data[i]; + + if (scd->func) + static_call_update(sc_selftest, scd->func); + + WARN_ON(static_call(sc_selftest)(scd->val) != scd->expect); + } + + return 0; +} +early_initcall(test_static_call_init); + +#endif /* CONFIG_STATIC_CALL_SELFTEST */ diff --git a/kernel/static_call_inline.c b/kernel/static_call_inline.c index 639397b5491c..3e65bfafe559 100644 --- a/kernel/static_call_inline.c +++ b/kernel/static_call_inline.c @@ -512,45 +512,3 @@ int __init static_call_init(void) } 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 struct static_call_data { - int (*func)(int); - int val; - int expect; -} static_call_data [] __initdata = { - { NULL, 2, 3 }, - { func_b, 2, 4 }, - { func_a, 2, 3 } -}; - -static int __init test_static_call_init(void) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(static_call_data); i++ ) { - struct static_call_data *scd = &static_call_data[i]; - - if (scd->func) - static_call_update(sc_selftest, scd->func); - - WARN_ON(static_call(sc_selftest)(scd->val) != scd->expect); - } - - return 0; -} -early_initcall(test_static_call_init); - -#endif /* CONFIG_STATIC_CALL_SELFTEST */