From nobody Fri Oct 2 10:06:53 2026 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (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 25C033264CE for ; Sun, 2 Aug 2026 18:43:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785696214; cv=none; b=U8UzJ9bNaQ7F5DKlvREvhxGN1RW5UlbpVo13VFyYCNn7qIrtoPFEjVc5sO+0/82MxsqQOYpraUzjMOxUZlNMFYp0S0/9NFTW0lzt31UlKV8dtK0z4SgPdIfsLu14XPyGVdohHrqnvxPoW3Xtx6bt7iLTxaWLqmN/8Vr5txs3Ohw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785696214; c=relaxed/simple; bh=TxRBgbTF3yjk8RfdptAdirInkEmw8cmqXAbU2gNLvSU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=oova4aJxPZjP8NJ4PN/bFmy/zAlFlrKR0Z8Qp7ZtRZJsSUEUolDO5U6OYEw0Vw2fdHdeMI8jzd6BNwH6glNhciBnk6q5//Pj7mQWNx5Ii2j5fuSUzoYnej7gMgarnNDl7KFC2ebiOR8Q3+BtE8GCdkEvQLV26M1ORIqVOhxWdcY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=chipe/nk; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="chipe/nk" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1785696210; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xfGZ5mxxGbASPb597QUgHIhYoVOQiaIlYyKMsccGqd4=; b=chipe/nkubhALK+0VxDuFC/AmMUifQNxMB9sj4VcIlaDoqiiBEqTYRc+D9hCATpRdAJMyO ama+D0FOwIyAaK3FXF9ac8QzkeneGJsegTc/UawI3KmAhzAiZEl2nXhv1fuQxO0Wq0pETw 6eRX3niEtaZQjdLG4833uuhg/b9WI1Q= From: wen.yang@linux.dev To: Gabriele Monaco Cc: Nam Cao , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, Wen Yang , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Subject: [PATCH v2 1/4] rv/reactors: use context-sensitive lockdep wait type in rv_react() Date: Mon, 3 Aug 2026 02:43:02 +0800 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT From: Wen Yang The single DEFINE_WAIT_OVERRIDE_MAP(rv_react_map, LD_WAIT_FREE) in rv_react() declares wait_type_inner =3D LD_WAIT_FREE for every execution context. In a preemptible context (e.g. CONFIG_PREEMPT_RT or a KUnit test running on a task), a timer interrupt can fire during a reactor callback; the interrupt exit path then schedules and acquires rq->__lock (LD_WAIT_SPIN) while the override map is still held. Since the map declares the context to be wait-free, lockdep reports a spurious "Invalid wait context" warning: [ BUG: Invalid wait context ] context-{5:5} 1 lock held by kunit_try_catch/209: #0: (rv_react_map-wait-type-override){+.+.}-{1:1} kunit_try_catch/209 is trying to lock: ffff8a743ed3e8a0 (&rq->__lock){-...}-{2:2} Use two lockdep override maps, selected by execution context: - Preemptible context (task, softirq, PREEMPT_RT irq thread): the scheduler may preempt, so use LD_WAIT_SPIN, the tightest wait type the scheduler itself uses, to suppress the spurious warning. - NMI/hardirq context: preemption is disabled and the scheduler cannot run, so the false positive cannot arise. Keep LD_WAIT_FREE here to preserve the original constraint that reactors must not take raw spinlocks in atomic context. Fixes: 69d8895cb9a9 ("rv: Add explicit lockdep context for reactors") Signed-off-by: Wen Yang Cc: Thomas Wei=C3=9Fschuh --- kernel/trace/rv/rv_reactors.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/kernel/trace/rv/rv_reactors.c b/kernel/trace/rv/rv_reactors.c index 2f5fc8d18dea..cd571b1649f5 100644 --- a/kernel/trace/rv/rv_reactors.c +++ b/kernel/trace/rv/rv_reactors.c @@ -465,18 +465,25 @@ int init_rv_reactors(struct dentry *root_dir) =20 void rv_react(struct rv_monitor *monitor, const char *msg, ...) { - static DEFINE_WAIT_OVERRIDE_MAP(rv_react_map, LD_WAIT_FREE); + /* + * A reactor callback can be preempted; the scheduler then takes + * rq->__lock (LD_WAIT_SPIN). Advertise that in preemptible contexts + * to avoid a spurious lockdep report, and keep LD_WAIT_FREE in atomic + * ones where the scheduler cannot run. + */ + static DEFINE_WAIT_OVERRIDE_MAP(rv_react_map, LD_WAIT_SPIN); + static DEFINE_WAIT_OVERRIDE_MAP(rv_react_map_atomic, LD_WAIT_FREE); + struct lockdep_map * __maybe_unused map; va_list args; =20 if (!rv_reacting_on() || !monitor->react) return; =20 + map =3D (in_nmi() || in_hardirq()) ? &rv_react_map_atomic : &rv_react_map; va_start(args, msg); - - lock_map_acquire_try(&rv_react_map); + lock_map_acquire_try(map); monitor->react(msg, args); - lock_map_release(&rv_react_map); - + lock_map_release(map); va_end(args); } EXPORT_SYMBOL_GPL(rv_react); --=20 2.25.1 From nobody Fri Oct 2 10:06:53 2026 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 C84763264C2 for ; Sun, 2 Aug 2026 18:43:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785696216; cv=none; b=ZtN4UD3mmHjT1nl6QcmuveVWZY0iNbxmtiFsGYcz84J4rZoaBCCi3KLG9X/w0SVkXLvb3JGqn9wgq6UOVcALpxH290SW+fb6IXZxPyLkZBuUPTUu0arKcE722IhexXXkuJYPejOou8Rm9L2MTja6obYdn+QFaxe+Hal9P2JlgjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785696216; c=relaxed/simple; bh=Ecq2RJ7y2VSTOYugocYRX9djwXgqRWBviiGZWfMVbn0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZWgJmqo/5x21xMHgPzlbWiMRFt6oatqFkZ0jZVqEbbGSV/Fn9Ujh+AXRkhR6ev3xNaDoIBkxS9Pk2nhfhqDCZ0DCvAV9QHIWkzA2nFCvDoIMIoMwijWPafY9upvPU2kqQ9Ui4utP9Zr95/q7ZGuk8PpRjR0karc2rQ4Fdm1Mo7k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=c4HQ2wAS; arc=none smtp.client-ip=91.218.175.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="c4HQ2wAS" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1785696213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fdKr1DAddybaNOWyLxb0IMTWhsKJKuUiULfAzBO1VQ8=; b=c4HQ2wASqDl4n4uKe3Zr6vVSgylO+IaqfEPm+ZYVYchdhCJKXGEZjVS4fDLrbj9PcRfj/P wmRZEbszT5mlfPfTXis7u6Vj3PAFJnB+Bsl7Le2TFxwjdP64VWEV2zoShn/oaNXmbM6m4z m7tkHEEkda2d2zAqZttPU9be9SQvDzc= From: wen.yang@linux.dev To: Gabriele Monaco Cc: Nam Cao , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, Wen Yang Subject: [PATCH v2 2/4] rv/reactors: propagate rv_register_reactor() error from reactor init Date: Mon, 3 Aug 2026 02:43:03 +0800 Message-Id: <76b672af7c3eed78582ae90fcbf4736a76783df5.1785695669.git.wen.yang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Wen Yang Both register_react_printk() and register_react_panic() ignore the return value of rv_register_reactor() and always return 0. If the registration fails (e.g. a duplicate reactor name), the init functions silently report success even though the reactor was not registered. Propagate the error from rv_register_reactor() so a failed registration is reported instead of being silently ignored. Suggested-by: Gabriele Monaco Signed-off-by: Wen Yang Reviewed-by: Gabriele Monaco --- kernel/trace/rv/reactor_panic.c | 3 +-- kernel/trace/rv/reactor_printk.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/trace/rv/reactor_panic.c b/kernel/trace/rv/reactor_pani= c.c index 76537b8a4343..db7116ceafff 100644 --- a/kernel/trace/rv/reactor_panic.c +++ b/kernel/trace/rv/reactor_panic.c @@ -26,8 +26,7 @@ static struct rv_reactor rv_panic =3D { =20 static int __init register_react_panic(void) { - rv_register_reactor(&rv_panic); - return 0; + return rv_register_reactor(&rv_panic); } =20 static void __exit unregister_react_panic(void) diff --git a/kernel/trace/rv/reactor_printk.c b/kernel/trace/rv/reactor_pri= ntk.c index 48c934e315b3..002a10f6aa7b 100644 --- a/kernel/trace/rv/reactor_printk.c +++ b/kernel/trace/rv/reactor_printk.c @@ -25,8 +25,7 @@ static struct rv_reactor rv_printk =3D { =20 static int __init register_react_printk(void) { - rv_register_reactor(&rv_printk); - return 0; + return rv_register_reactor(&rv_printk); } =20 static void __exit unregister_react_printk(void) --=20 2.25.1 From nobody Fri Oct 2 10:06:53 2026 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 712443264F4 for ; Sun, 2 Aug 2026 18:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785696219; cv=none; b=nAKoRyOJ9bONDilmPvaX5inBPo90fvrUHQXMeY7j03VuvHhgU4MYN1IbY6sxUFnLyMyPGjtxz10aehOcrPgMpzCZ3qoRrr4JjHAbZi9Hyu0AioiOuJ/Bb4dU5Q7XumMzqlAgg+erWXAiPXirOw1m/lfGHpExkZfXt01we30V5G8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785696219; c=relaxed/simple; bh=ZIuhFCaqOxV6wf9wRCdEeM/YUvZJrMgP4lMgUvgAZCw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iXINZMynvH8jjZMFhAw9DL+4OaOhVlx+pbdNoW4AZ3OUPqg6E5hsAuuCqWHftK8bpk3OKTa2JV54nvdJIBsOO2awiPLLf6u7a+jVvQK5hj7jXkCnWqyzhRUkyebPCUdI6E+jpN2uBmdlFPecsHCW/90WiGLwFDI3BgrZvWcp6+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cySl5Ofa; arc=none smtp.client-ip=91.218.175.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cySl5Ofa" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1785696216; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uV2s8PsuJocgqni44DIMvUciMbVy/lKZUSh93ut9JnY=; b=cySl5OfaXtMQYT0y8wUMg8Vsz2hVLNg+dsOdyLBJTJnPerY9ONeiQ6+o1PcmfcYzRXGOjj bBPYxe39VHXyRhdfdYD4X+HBfc+FHFiZqwXAmKIE5ywj9g9mDe+1TnZelsBh9kdFGDjTFk hxqwhhBPiAxwJb6ezEvoXejTN1RYYuo= From: wen.yang@linux.dev To: Gabriele Monaco Cc: Nam Cao , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, Wen Yang Subject: [PATCH v2 3/4] rv/reactors: export rv_register_reactor() and rv_unregister_reactor() Date: Mon, 3 Aug 2026 02:43:04 +0800 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Wen Yang rv_react() is exported to modules, but the reactor registration helpers are not. Export them with EXPORT_SYMBOL_GPL() so reactor modules and the tristate KUnit test module can register and unregister reactors without hitting undefined symbol errors at load time. Signed-off-by: Wen Yang Reviewed-by: Gabriele Monaco --- kernel/trace/rv/rv_reactors.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/trace/rv/rv_reactors.c b/kernel/trace/rv/rv_reactors.c index cd571b1649f5..228ed043bd73 100644 --- a/kernel/trace/rv/rv_reactors.c +++ b/kernel/trace/rv/rv_reactors.c @@ -314,6 +314,7 @@ int rv_register_reactor(struct rv_reactor *reactor) guard(mutex)(&rv_interface_lock); return __rv_register_reactor(reactor); } +EXPORT_SYMBOL_GPL(rv_register_reactor); =20 /** * rv_unregister_reactor - unregister a rv reactor. @@ -327,6 +328,7 @@ int rv_unregister_reactor(struct rv_reactor *reactor) list_del(&reactor->list); return 0; } +EXPORT_SYMBOL_GPL(rv_unregister_reactor); =20 /* * reacting_on interface. --=20 2.25.1 From nobody Fri Oct 2 10:06:53 2026 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (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 4D8A9327C08 for ; Sun, 2 Aug 2026 18:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785696222; cv=none; b=bBafkKP1+aO56HS7B6R2vrNRPrl95XQ/LTKXMIBAtaPTFi3RlmpFQJjOz4h/XNRIOIx79lpnqvkR/Ks1dPvVFut411HQaYKoZXx1NI4VwST95AuDHMImK7cjws/tZIC7pzXPzpNBUkXu2LPhSnmOgIe9ptLcOtyJanwdbboPB6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785696222; c=relaxed/simple; bh=tFnmduTwKi8rKfeOua0RpyVuiF3l2Poer9y6mqarLng=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UQoeFHUsW6H4qDqKrK/dXn7Rfsj/kDEZ+0K9oNA3LP8TpZQdpyMTQMLyV+TMj0f2d//xq7y3XMs+VgFFpq7qDYUAwh9ItnQvMtXnCmpdiOTmD3rPESI8da6SMrkIQb9l3EXSF0o+2yU9+/p6o6KLloQ7dWmidfsGmgS3YpHlzNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=N8YADW4I; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="N8YADW4I" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1785696219; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P3ZsGVsjxs1arltMdkzF3yJ+/NF4RzrrXWmF0vxUiwo=; b=N8YADW4I+Rd3ESZoGCQnCn9dymAsAJa+KhJSoMYjq1od2Q6u0AHL1BlHA+W5TZ5SEqF+nY /fKR00ojvgJ8fJD076FMixaftu07uvBW9gbj76AoGOseMzgYdZ2TGN1tSvBKi0Kmb8MaiO lWaa+uhJ0N8TcgvFk+Rmc+xjDY5nZoc= From: wen.yang@linux.dev To: Gabriele Monaco Cc: Nam Cao , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, Wen Yang Subject: [PATCH v2 4/4] rv/reactors: add KUnit tests for reactor registration and dispatch Date: Mon, 3 Aug 2026 02:43:05 +0800 Message-Id: <55a167aacaf1497fafbbe9fd578ffe14cbee368f.1785695669.git.wen.yang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Wen Yang Add KUnit tests covering the reactor register/unregister lifecycle (including duplicate and name-length rejection) and rv_react() dispatch (a no-op without a callback, exactly one invocation with one; the mdelay callback keeps the CPU busy so a timer interrupt exercises the LD_WAIT_SPIN lockdep context). The Kconfig entry is tristate so the tests can be built as a module when CONFIG_KUNIT=3Dm; only RV_REACTORS is required. Signed-off-by: Wen Yang --- kernel/trace/rv/Kconfig | 12 +++ kernel/trace/rv/Makefile | 1 + kernel/trace/rv/rv_reactors_kunit.c | 143 ++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 kernel/trace/rv/rv_reactors_kunit.c diff --git a/kernel/trace/rv/Kconfig b/kernel/trace/rv/Kconfig index efa930f94ea4..9bfd429ffdea 100644 --- a/kernel/trace/rv/Kconfig +++ b/kernel/trace/rv/Kconfig @@ -113,6 +113,18 @@ config RV_REACT_PANIC Enables the panic reactor. The panic reactor emits a printk() message if an exception is found and panic()s the system. =20 +config RV_REACTORS_KUNIT + tristate "KUnit tests for RV reactors" if !KUNIT_ALL_TESTS + depends on KUNIT + depends on RV_REACTORS + default KUNIT_ALL_TESTS + help + Enable KUnit tests for RV reactor registration and dispatch. + These tests verify the register/unregister lifecycle, duplicate + rejection, and that rv_react() correctly invokes callbacks. + + If unsure, say N. + config RV_MONITORS_KUNIT_TEST tristate "KUnit tests for RV monitors" if !KUNIT_ALL_TESTS depends on KUNIT && RV && RV_REACTORS diff --git a/kernel/trace/rv/Makefile b/kernel/trace/rv/Makefile index cdbf68c84f5a..c895d81dfdad 100644 --- a/kernel/trace/rv/Makefile +++ b/kernel/trace/rv/Makefile @@ -25,4 +25,5 @@ obj-$(CONFIG_RV_MON_WAKEUP) +=3D monitors/wakeup/wakeup.o obj-$(CONFIG_RV_REACTORS) +=3D rv_reactors.o obj-$(CONFIG_RV_REACT_PRINTK) +=3D reactor_printk.o obj-$(CONFIG_RV_REACT_PANIC) +=3D reactor_panic.o +obj-$(CONFIG_RV_REACTORS_KUNIT) +=3D rv_reactors_kunit.o obj-$(CONFIG_RV_MONITORS_KUNIT_TEST) +=3D rv_monitors_test.o diff --git a/kernel/trace/rv/rv_reactors_kunit.c b/kernel/trace/rv/rv_react= ors_kunit.c new file mode 100644 index 000000000000..32c25dcf0cb6 --- /dev/null +++ b/kernel/trace/rv/rv_reactors_kunit.c @@ -0,0 +1,143 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit tests for RV reactor registration and dispatch. + */ + +#include +#include +#include +#include +#include "rv.h" + +static struct rv_reactor test_reactor =3D { + .name =3D "kunit_test_reactor", + .description =3D "KUnit test reactor", +}; + +/* + * rv_unregister_reactor() on a reactor that was never registered would + * list_del() an uninitialized list_head, so track registration and only + * unregister in the teardown if it is still on the list. + */ +static bool test_reactor_registered; + +static int unregister_test_reactor(void) +{ + int ret =3D 0; + + if (test_reactor_registered) { + ret =3D rv_unregister_reactor(&test_reactor); + test_reactor_registered =3D false; + } + + return ret; +} + +/* + * The teardown action guarantees the reactor is unregistered even if a + * test fails mid-way, so a leftover entry cannot corrupt later tests. + */ +static void reactor_teardown(void *arg) +{ + unregister_test_reactor(); +} + +static void register_test_reactor(struct kunit *test) +{ + KUNIT_ASSERT_EQ(test, rv_register_reactor(&test_reactor), 0); + test_reactor_registered =3D true; + KUNIT_ASSERT_EQ(test, + kunit_add_action_or_reset(test, reactor_teardown, NULL), 0); +} + +static void test_register_unregister(struct kunit *test) +{ + register_test_reactor(test); + + KUNIT_EXPECT_EQ(test, unregister_test_reactor(), 0); +} + +static void test_double_register(struct kunit *test) +{ + register_test_reactor(test); + + KUNIT_EXPECT_EQ(test, rv_register_reactor(&test_reactor), -EINVAL); + + KUNIT_EXPECT_EQ(test, unregister_test_reactor(), 0); +} + +static void test_name_too_long(struct kunit *test) +{ + /* Name length of MAX_RV_REACTOR_NAME_SIZE (32) must be rejected. */ + static struct rv_reactor long_reactor =3D { + .name =3D "kunit_reactor_name_too_long_xxx_", + }; + + KUNIT_ASSERT_EQ(test, (int)strlen(long_reactor.name), + MAX_RV_REACTOR_NAME_SIZE); + KUNIT_EXPECT_EQ(test, rv_register_reactor(&long_reactor), -EINVAL); +} + +static struct kunit_case rv_reactor_registration_cases[] =3D { + KUNIT_CASE(test_register_unregister), + KUNIT_CASE(test_double_register), + KUNIT_CASE(test_name_too_long), + {} +}; + +static struct kunit_suite rv_reactor_registration_suite =3D { + .name =3D "rv_reactor_registration", + .test_cases =3D rv_reactor_registration_cases, +}; + +static atomic_t react_call_count; + +__printf(1, 0) static void mock_react(const char *msg, va_list args) +{ + atomic_inc(&react_call_count); + /* + * Hold the CPU for 5 ms so a timer interrupt is likely to fire + * inside rv_react()'s lockdep context, exercising the LD_WAIT_SPIN + * constraint. mdelay() is a calibrated busy-wait with no scheduler + * interaction. + */ + mdelay(5); +} + +static void test_react_no_callback(struct kunit *test) +{ + struct rv_monitor monitor =3D { + .name =3D "kunit_null_react", + }; + + /* rv_react() must silently return when monitor->react is NULL. */ + rv_react(&monitor, "no callback"); +} + +static void test_react_callback_invoked(struct kunit *test) +{ + struct rv_monitor monitor =3D { + .name =3D "kunit_dispatch_monitor", + .react =3D mock_react, + }; + + atomic_set(&react_call_count, 0); + rv_react(&monitor, "callback invocation test"); + KUNIT_EXPECT_EQ(test, atomic_read(&react_call_count), 1); +} + +static struct kunit_case rv_react_dispatch_cases[] =3D { + KUNIT_CASE(test_react_no_callback), + KUNIT_CASE(test_react_callback_invoked), + {} +}; + +static struct kunit_suite rv_react_dispatch_suite =3D { + .name =3D "rv_react_dispatch", + .test_cases =3D rv_react_dispatch_cases, +}; + +kunit_test_suites(&rv_reactor_registration_suite, &rv_react_dispatch_suite= ); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("KUnit tests for RV reactor registration and dispatch"); --=20 2.25.1