Bug 206368

Summary: [PATCH] kevent doesn't notify EV_ENABLE-ed events
Product: Base System Reporter: taketsuru11
Component: kernAssignee: Mark Johnston <markj>
Status: Closed FIXED    
Severity: Affects Some People CC: hiren, jmg, markj, ngie
Priority: --- Keywords: patch
Version: CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
reproduce none

Description taketsuru11 2016-01-18 13:52:14 UTC
Created attachment 165759 [details]
reproduce

Kevent() doesn't notify an EV_ENABLE-ed event even though the notification condition of the event is satisfied.  R274560 introduced this bug.

The following patch solves the issue.

diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index d41ac96..6584294 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -1284,7 +1284,8 @@ done_ev_add:
                kn->kn_status |= KN_DISABLED;
        }

-       if ((kn->kn_status & KN_DISABLED) == 0)
+       if ((kev->flags & EV_ENABLE) ||
+           (kn->kn_status & KN_DISABLED) == 0)
                event = kn->kn_fop->f_event(kn, 0);
        else
                event = 0;
Comment 1 taketsuru11 2016-01-18 13:56:06 UTC
Comment on attachment 165759 [details]
reproduce

This program is expected to exit silently, but it prints 'what?!'.
Comment 2 Hiren Panchasara freebsd_committer freebsd_triage 2016-01-20 07:50:03 UTC
jmg@, can you please take a look to see if this indeed is a regression caused by r274560?
Comment 3 Enji Cooper freebsd_committer freebsd_triage 2016-02-17 01:21:19 UTC
We believe we're run in to similar issues internally..
Comment 4 Mark Johnston freebsd_committer freebsd_triage 2016-02-17 04:31:12 UTC
(In reply to Ngie Cooper from comment #3)
Indeed. See: https://reviews.freebsd.org/D5307
Comment 5 commit-hook freebsd_committer freebsd_triage 2016-02-19 01:50:19 UTC
A commit references this bug:

Author: markj
Date: Fri Feb 19 01:49:33 UTC 2016
New revision: 295786
URL: https://svnweb.freebsd.org/changeset/base/295786

Log:
  Ensure that we test the event condition when a disabled kevent is enabled.

  r274560 modified kqueue_register() to only test the event condition if the
  corresponding knote is not disabled. However, this check takes place before
  the EV_ENABLE flag is used to clear the KN_DISABLED flag on the knote, so
  enabling a previously-disabled kevent would not result in a notification for
  a triggered event. This change fixes the problem by testing for EV_ENABLED
  before possibly checking the event condition.

  This change also updates a kqueue regression test to exercise this case.

  PR:		206368
  Reviewed by:	kib
  Sponsored by:	EMC / Isilon Storage Division
  Differential Revision:	https://reviews.freebsd.org/D5307

Changes:
  head/sys/kern/kern_event.c
  head/tests/sys/kqueue/read.c