From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796047219; b=Tu3FNa3ZaC3sr0fmxb2Wi3ed5EEwhYAFR0V3aAp5Y20mi4wz3uO1/w3M2YgNii4Tb1Ms XvswI8/Ti6EkdYq0QKEXDK15pKOA/8EVXL3t6n0cQlq1Ivs3nmlwM5PX4BTEun+dHODh5 L19dUGle2fZO4xdWe49jKRHCcLyYbQiRs6ob8C6lHSQhEfLOa16fbX7T9Pfa4vl39wz3P 3pbLDlIi0SMFG0l26TwFb/aNNdvuVt9A6yewCynZ3HEL7n5AHxBXm37R2u+IC74HDAext o9sbZPAjfh5IbCcEvZ9mZvA+BBpAdOBEUffMENsa3auOOsEjCIKgKCwuOPInawvv0UQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796047219; h=Received:DKIM-Signature:Received:Message-ID:User-Agent:Date:From:To: Cc:Subject:References:MIME-Version:Content-Type; bh=plhRM+FkgTYXLfpnzQqlGnSmev8kWTgza6yP/JcpasI=; b=ui4u6A+PQn6NwOIyJu7QygGGCQTqfZaouIHMAyjceiUV/rx5sg9qpPEAHZiLDpidPqxy eZ63PVA95ESN+9W32mLgjwFXYdJLTjxaNxPyyuyJ8D1LrHL3E1A4A5qy10r5TIp2WhhA7 QkeoLjrWU4voqa1ViPAGW1uI+EVwR+800XJkNFHfGdCOGiY9T8k0sWibJTmgM9ixMxOh1 PLdfcLOBVv2kp6BMUcQYiyOuxyz0CmZGWf6wu7yeaaXYNWzLJf5CHZmnnlo2wiXYuISNK yzix71imoRPAiPPCgDoIv1j26ipqdvAjhlJw88yunC8SqKc+Wugoc7sVxiXfEOizMtg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FICtftKU; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBC23606A68F for ; Mon, 30 Nov 2026 14:00:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FICtftKU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 937F51F00939; Mon, 30 Nov 2026 14:00:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796047219; bh=plhRM+FkgTYXLfpnzQqlGnSmev8kWTgza6yP/JcpasI=; h=Date:From:To:Cc:Subject:References; b=FICtftKUcPL9jB1vEGgNLRc5b1pM/8S49UMGbJEbJKfD/BVs2/c2a2GUCemJYqrBl gMs1BdJAicN/vJ0txwR/cdHusTrkOWs8li5cP7NuqCYthiGnMARzo8UqlFZKD8vUSx KtCpC0png8zPJ0BhOTRSw9e5zKgIQwTXrKeThqktJvOOc/kwp6GTOUS8Jce85GnmUR uBUNRH0qs/moi2DaXKvQEk4z+cURUe4u3L+wUWpjFBdWW9fMptuRX+9f1EqbPqdAgp 0/db5UrOpZRkZOb4ubDH7qxf3bgjUz5a2Un0CBqVuFOmcx+muB2l4N00DD1hJRby4b mgJxwyU6r9aXw== Received: from rostedt by gandalf with local (Exim 4.100.1) (envelope-from ) id 1xY1vW-00000009Id6-3jP1; Mon, 30 Nov 2026 09:00:18 -0500 Message-ID: <20261130140018.710833301@kernel.org> User-Agent: quilt/0.69 Date: Mon, 30 Nov 2026 08:59:54 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mathieu Desnoyers , Beau Belgrave , Jeff Barnes Subject: [for-next][PATCH 5/5] selftests/user_events: Test registration from existing threads References: <20261130135949.755499997@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 From: Jeff Barnes Create two threads before either registers a user event. Have the first thread register an event using a shared enable address and bit while it remains alive, then have the second thread register a different event using the same address and bit. The second registration should fail with EADDRINUSE because both threads share the same address space. This test fails without the accompanying kernel fix because each thread can create a separate user_event_mm with an independent enabler list. Link: https://patch.msgid.link/20261006164720.3940272-4-jeffbarnes@linux.microsoft.com Reviewed-by: Beau Belgrave Signed-off-by: Jeff Barnes Signed-off-by: Steven Rostedt --- .../testing/selftests/user_events/abi_test.c | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/tools/testing/selftests/user_events/abi_test.c b/tools/testing/selftests/user_events/abi_test.c index 21e1e3cca197..79bb6f2fcb8f 100644 --- a/tools/testing/selftests/user_events/abi_test.c +++ b/tools/testing/selftests/user_events/abi_test.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -258,6 +259,130 @@ FIXTURE_TEARDOWN(user) { USER_EVENT_FIXTURE_TEARDOWN(self->umount); } +struct thread_registration { + pthread_mutex_t lock; + pthread_cond_t cond; + __u32 enable; + bool start; + bool first_done; + bool second_done; + int first_ret; + int first_errno; + int first_unreg_ret; + int second_ret; + int second_errno; +}; + +static int reg_enable_name(void *enable, const char *name, int *saved_errno) +{ + struct user_reg reg = {0}; + int fd = open(data_file, O_RDWR); + int ret; + + if (fd < 0) { + *saved_errno = errno; + return -1; + } + + reg.size = sizeof(reg); + reg.name_args = (__u64)name; + reg.enable_bit = 0; + reg.enable_addr = (__u64)enable; + reg.enable_size = sizeof(__u32); + + errno = 0; + ret = ioctl(fd, DIAG_IOCSREG, ®); + *saved_errno = errno; + + close(fd); + + return ret; +} + +static void *register_first(void *arg) +{ + struct thread_registration *registration = arg; + + pthread_mutex_lock(®istration->lock); + while (!registration->start) + pthread_cond_wait(®istration->cond, ®istration->lock); + pthread_mutex_unlock(®istration->lock); + + registration->first_ret = reg_enable_name(®istration->enable, + "__abi_event_thread_a", + ®istration->first_errno); + + pthread_mutex_lock(®istration->lock); + registration->first_done = true; + pthread_cond_broadcast(®istration->cond); + + while (!registration->second_done) + pthread_cond_wait(®istration->cond, ®istration->lock); + pthread_mutex_unlock(®istration->lock); + + if (!registration->first_ret) + registration->first_unreg_ret = + reg_disable(®istration->enable, 0); + + return NULL; +} + +static void *register_second(void *arg) +{ + struct thread_registration *registration = arg; + + pthread_mutex_lock(®istration->lock); + while (!registration->start) + pthread_cond_wait(®istration->cond, ®istration->lock); + while (!registration->first_done) + pthread_cond_wait(®istration->cond, ®istration->lock); + pthread_mutex_unlock(®istration->lock); + + registration->second_ret = reg_enable_name(®istration->enable, + "__abi_event_thread_b", + ®istration->second_errno); + + pthread_mutex_lock(®istration->lock); + registration->second_done = true; + pthread_cond_broadcast(®istration->cond); + pthread_mutex_unlock(®istration->lock); + + if (!registration->second_ret) + reg_disable(®istration->enable, 0); + + return NULL; +} + +TEST_F(user, preexisting_threads_same_address) { + struct thread_registration registration = { + .lock = PTHREAD_MUTEX_INITIALIZER, + .cond = PTHREAD_COND_INITIALIZER, + }; + pthread_t first; + pthread_t second; + + ASSERT_EQ(0, pthread_create(&first, NULL, register_first, ®istration)); + ASSERT_EQ(0, pthread_create(&second, NULL, register_second, ®istration)); + + pthread_mutex_lock(®istration.lock); + registration.start = true; + pthread_cond_broadcast(®istration.cond); + pthread_mutex_unlock(®istration.lock); + + ASSERT_EQ(0, pthread_join(first, NULL)); + ASSERT_EQ(0, pthread_join(second, NULL)); + + pthread_cond_destroy(®istration.cond); + pthread_mutex_destroy(®istration.lock); + + ASSERT_EQ(0, registration.first_ret); + ASSERT_EQ(0, registration.first_errno); + ASSERT_EQ(0, registration.first_unreg_ret); + + ASSERT_EQ(-1, registration.second_ret); + ASSERT_EQ(EADDRINUSE, registration.second_errno); +} + TEST_F(user, enablement) { /* Changes should be reflected immediately */ ASSERT_EQ(0, self->check); -- 2.53.0