NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/57703: kernel panic in eventfd_fop_close()



The following reply was made to PR kern/57703; it has been noted by GNATS.

From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
To: thorpej%NetBSD.org@localhost
Cc: paul%whooppee.com@localhost, gnats-bugs%NetBSD.org@localhost
Subject: Re: kern/57703: kernel panic in eventfd_fop_close()
Date: Sat, 18 Nov 2023 22:56:58 +0000

 This is a multi-part message in MIME format.
 --=_ml7q+P8YFLTA7qSAPcDHHBHCSIXmg0yj
 
 Here's the test that crashed my laptop -- working on converting this
 to use rump instead.
 
 --=_ml7q+P8YFLTA7qSAPcDHHBHCSIXmg0yj
 Content-Type: text/plain; charset="ISO-8859-1"; name="pr57703-eventfdsignaltestwip"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment; filename="pr57703-eventfdsignaltestwip.patch"
 
 From f71c52d125f8376c3e99f1fda37f1f466c97e199 Mon Sep 17 00:00:00 2001
 From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
 Date: Sat, 18 Nov 2023 21:16:13 +0000
 Subject: [PATCH] WIP: add test for interrupting eventfd read/write by signal
 
 PR kern/57703
 ---
  tests/lib/libc/sys/t_eventfd.c | 71 +++++++++++++++++++++++++++++++++-
  1 file changed, 69 insertions(+), 2 deletions(-)
 
 diff --git a/tests/lib/libc/sys/t_eventfd.c b/tests/lib/libc/sys/t_eventfd.c
 index 4eaea2aff3ba..4dc2fe3e4baf 100644
 --- a/tests/lib/libc/sys/t_eventfd.c
 +++ b/tests/lib/libc/sys/t_eventfd.c
 @@ -31,23 +31,27 @@ __COPYRIGHT("@(#) Copyright (c) 2020\
   The NetBSD Foundation, inc. All rights reserved.");
  __RCSID("$NetBSD: t_eventfd.c,v 1.3 2022/02/20 15:21:14 thorpej Exp $");
 =20
 -#include <sys/types.h>
  #include <sys/event.h>
  #include <sys/eventfd.h>
  #include <sys/ioctl.h>
  #include <sys/select.h>
  #include <sys/stat.h>
  #include <sys/syscall.h>
 +#include <sys/types.h>
 +
  #include <errno.h>
  #include <poll.h>
  #include <pthread.h>
 -#include <stdlib.h>
 +#include <signal.h>
  #include <stdio.h>
 +#include <stdlib.h>
  #include <time.h>
  #include <unistd.h>
 =20
  #include <atf-c.h>
 =20
 +#include "h_macros.h"
 +
  struct helper_context {
  	int	efd;
 =20
 @@ -815,6 +819,67 @@ ATF_TC_BODY(eventfd_fcntl, tc)
 =20
  /*************************************************************************=
 ****/
 =20
 +static pthread_key_t eventfd_signal_key;
 +
 +static void
 +eventfd_read_signal_handler(int signo)
 +{
 +	volatile sig_atomic_t *const flag =3D
 +	    pthread_getspecific(eventfd_signal_key);
 +
 +	*flag =3D 1;
 +}
 +
 +static void *
 +eventfd_read_signal_helper(void * const v)
 +{
 +	struct helper_context * const ctx =3D v;
 +	eventfd_t efd_value;
 +	sig_atomic_t flag =3D 0;
 +	int error;
 +
 +	RZ(pthread_setspecific(eventfd_signal_key, &flag));
 +	if (signal(SIGUSR1, &eventfd_read_signal_handler) =3D=3D SIG_ERR)
 +		atf_tc_fail("signal(SIGUSR1): %s", strerror(errno));
 +
 +	ATF_REQUIRE(wait_barrier(ctx));
 +	ATF_REQUIRE(eventfd_read(ctx->efd, &efd_value) =3D=3D -1);
 +	error =3D errno;
 +	ATF_REQUIRE_MSG(error =3D=3D EINTR, "errno=3D%d (%s)", error,
 +	    strerror(error));
 +	ATF_REQUIRE_MSG(flag, "signal not delivered");
 +
 +	return NULL;
 +}
 +
 +ATF_TC(eventfd_read_signal);
 +ATF_TC_HEAD(eventfd_read_signal, tc)
 +{
 +	atf_tc_set_md_var(tc, "descr",
 +	    "Tests eventfd reads can be interrupted by signal");
 +}
 +ATF_TC_BODY(eventfd_read_signal, tc)
 +{
 +	struct helper_context ctx;
 +	pthread_t helper;
 +
 +	RZ(pthread_key_create(&eventfd_signal_key, NULL));
 +
 +	init_helper_context(&ctx);
 +
 +	RL(ctx.efd =3D eventfd(0, 0));
 +	RZ(pthread_create(&helper, NULL, &eventfd_read_signal_helper, &ctx));
 +
 +	ATF_REQUIRE(wait_barrier(&ctx)); /* wait for helper to start */
 +	(void)sleep(1);		/* wait for the read to block */
 +	(void)alarm(1);		/* set a deadline */
 +	RZ(pthread_kill(helper, SIGUSR1)); /* wake helper */
 +	RZ(pthread_join(helper, NULL)); /* wait for helper to wake and fail */
 +	(void)alarm(0);		/* clear deadline */
 +}
 +
 +/*************************************************************************=
 ****/
 +
  ATF_TP_ADD_TCS(tp)
  {
  	ATF_TP_ADD_TC(tp, eventfd_normal);
 @@ -825,6 +890,8 @@ ATF_TP_ADD_TCS(tp)
  	ATF_TP_ADD_TC(tp, eventfd_select_poll_kevent_block);
  	ATF_TP_ADD_TC(tp, eventfd_restart);
  	ATF_TP_ADD_TC(tp, eventfd_fcntl);
 +	ATF_TP_ADD_TC(tp, eventfd_read_signal);
 +//	ATF_TP_ADD_TC(tp, eventfd_write_signal);
 =20
  	return atf_no_error();
  }
 
 --=_ml7q+P8YFLTA7qSAPcDHHBHCSIXmg0yj--
 


Home | Main Index | Thread Index | Old Index