From owner-svn-src-all@freebsd.org Thu Jun 1 16:49:49 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B409AB7A426; Thu, 1 Jun 2017 16:49:49 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 842A3822AC; Thu, 1 Jun 2017 16:49:49 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v51GnmkW029672; Thu, 1 Jun 2017 16:49:48 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v51GnmT5029670; Thu, 1 Jun 2017 16:49:48 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201706011649.v51GnmT5029670@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 1 Jun 2017 16:49:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319444 - in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jun 2017 16:49:49 -0000 Author: hselasky Date: Thu Jun 1 16:49:48 2017 New Revision: 319444 URL: https://svnweb.freebsd.org/changeset/base/319444 Log: Make sure the selrecord() function is only called from within system polling contexts in the LinuxKPI. After the kqueue() support was added to the LinuxKPI in r319409 the Linux poll file operation will be used outside the system file polling callback function, which can cause a NULL-pointer panic inside selrecord() because curthread->td_sel is set to NULL. This patch moves the selrecord() call away from poll_wait() and to the system file poll callback function in the LinuxKPI, which essentially wraps the Linux one. This is similar to what the cuse(3) module is currently doing. Refer to sys/fs/cuse/*.[ch] for more details. MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/compat/linuxkpi/common/include/linux/poll.h head/sys/compat/linuxkpi/common/src/linux_compat.c Modified: head/sys/compat/linuxkpi/common/include/linux/poll.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/poll.h Thu Jun 1 16:44:39 2017 (r319443) +++ head/sys/compat/linuxkpi/common/include/linux/poll.h Thu Jun 1 16:49:48 2017 (r319444) @@ -43,7 +43,7 @@ typedef struct poll_table_struct { static inline void poll_wait(struct linux_file *filp, wait_queue_head_t *wait_address, poll_table *p) { - selrecord(curthread, &filp->f_selinfo); + /* NOP */ } extern void linux_poll_wakeup(struct linux_file *); Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_compat.c Thu Jun 1 16:44:39 2017 (r319443) +++ head/sys/compat/linuxkpi/common/src/linux_compat.c Thu Jun 1 16:49:48 2017 (r319444) @@ -956,9 +956,10 @@ linux_dev_poll(struct cdev *dev, int events, struct th file = td->td_fpop; filp->f_flags = file->f_flag; linux_set_current(td); - if (filp->f_op->poll) + if (filp->f_op->poll != NULL) { + selrecord(td, &filp->f_selinfo); revents = filp->f_op->poll(filp, NULL) & events; - else + } else revents = 0; return (revents); @@ -1263,9 +1264,10 @@ linux_file_poll(struct file *file, int events, struct filp = (struct linux_file *)file->f_data; filp->f_flags = file->f_flag; linux_set_current(td); - if (filp->f_op->poll) + if (filp->f_op->poll != NULL) { + selrecord(td, &filp->f_selinfo); revents = filp->f_op->poll(filp, NULL) & events; - else + } else revents = 0; return (revents);