From owner-freebsd-current@FreeBSD.ORG Fri Aug 26 15:42:09 2011 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D959E106564A for ; Fri, 26 Aug 2011 15:42:09 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.59.238]) by mx1.freebsd.org (Postfix) with ESMTP id 9BB008FC0C for ; Fri, 26 Aug 2011 15:42:09 +0000 (UTC) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id 9964E7302B; Fri, 26 Aug 2011 17:39:40 +0200 (CEST) Date: Fri, 26 Aug 2011 17:39:40 +0200 From: Luigi Rizzo To: current@freebsd.org Message-ID: <20110826153940.GA3800@onelab2.iet.unipi.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.3i Cc: Subject: kqueue and device driver experience anyone ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Aug 2011 15:42:09 -0000 a question for the kqueue experts out there: I am trying to add kqueue support to a device driver, and am puzzled on what the .f_event() function may assume. I see that some of the examples (e.g. bpf, audit_pipe.c) expect that the function is called with the device lock held (and even have a LOCK_ASSERT). Others (if_tap, cam/scsi/scsi_target.c) either do not use the lock or explicitly acquire it. As far as i can tell the .f_event() function is called in two places: - within knote() which in turn (through KNOTE_*() ) is called by the driver itself near selrecord() . So it is up to the device driver to call it with the device lock held; - within kqueue_scan(), which instead is called from the upper half of the kernel as part of kern_kevent(). Here there seems to be no way that the device lock is acquired when .f_event() is called. Unless, of course, the knote's on which these .f_event() are called are not the same ones attached to devices -- so there is a different .f_event() function called ? So, is there a bug in the kqueue support for bpf.c and audit_pipe.c, or i am missing something important ? cheers luigi