NetBSD Problem Report #42685

From www@NetBSD.org  Thu Jan 28 16:38:36 2010
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id A9C2463C449
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 28 Jan 2010 16:38:36 +0000 (UTC)
Message-Id: <20100128163836.7B4D863C441@www.NetBSD.org>
Date: Thu, 28 Jan 2010 16:38:36 +0000 (UTC)
From: baiyang@gmail.com
Reply-To: baiyang@gmail.com
To: gnats-bugs@NetBSD.org
Subject: waiting a kqueue concurrently may cause kernel panic
X-Send-Pr-Version: www-1.0

>Number:         42685
>Category:       kern
>Synopsis:       waiting a kqueue concurrently may cause kernel panic
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 28 16:40:00 +0000 2010
>Closed-Date:    Thu Jan 07 15:13:54 +0000 2021
>Last-Modified:  Thu Jan 07 15:13:54 +0000 2021
>Originator:     BaiYang
>Release:        5.0.1 / i386
>Organization:
>Environment:
>Description:
If we are using the kevent api to waiting a kqueue on multi-threads concurrently like this: 

// ...
int r = kevent(sg_kqfd, NULL, 0, &evt, 1, &m_tspTMOUT);
// ...

Two situations may be ocurred:
1. When an event is raised, more than one kevent will return the same (which was just raised) event.
2. When an event is raised, a kernel panic may occured with the "fatal page fault" error.

On the other hand, the same code works very well on FreeBSD. 

We can simply accept the situation 1 as a different behaviour from FreeBSD and other systems. But the situation 2 is obviously a system bug because in any case, a user mode process should not cause a kernel panic.
>How-To-Repeat:
Just wait a kqueue concurrently in a thread pool.
>Fix:
Include the code segment with a critical section could resolve the problem:

// ...
pthread_mutex_lock(&mutex);
int r = kevent(sg_kqfd, NULL, 0, &evt, 1, &m_tspTMOUT);
pthread_mutex_unlock(&mutex);
// ...

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->feedback
State-Changed-By: maya@NetBSD.org
State-Changed-When: Mon, 28 Oct 2019 07:32:36 +0000
State-Changed-Why:
kevent locking was likely fixed. Are you still having issues?


State-Changed-From-To: feedback->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Thu, 07 Jan 2021 15:13:54 +0000
State-Changed-Why:
Feedback timeout. Assuming fixed. Let me know if you are still having problems.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: gnats-precook-prs,v 1.4 2018/12/21 14:20:20 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.