diff options
author | royger <royger@FreeBSD.org> | 2015-12-15 11:20:20 +0000 |
---|---|---|
committer | royger <royger@FreeBSD.org> | 2015-12-15 11:20:20 +0000 |
commit | 7330ea873340f2c45f4ce57a83881226f441e142 (patch) | |
tree | cf27e87af29518c3dd199b71f6e735fd3cb274d8 /sys/dev/hyperv/utilities | |
parent | 33a03a57b123cb0e01504766b1fc73b8acc27868 (diff) | |
download | FreeBSD-src-7330ea873340f2c45f4ce57a83881226f441e142.zip FreeBSD-src-7330ea873340f2c45f4ce57a83881226f441e142.tar.gz |
hyperv/kvp: wake up the daemon if it's sleeping due to poll()
Without the patch, there is a race condition: when poll() is invoked(),
if kvp_globals.daemon_busy is false, the daemon won't be timely
woke up, because hv_kvp_send_msg_to_daemon() can't wake up the daemon
in this case.
Submitted by: Dexuan Cui <decui@microsoft.com>
Sponsored by: Microsoft OSTC
Reviewed by: delphij, royger
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D4258
Diffstat (limited to 'sys/dev/hyperv/utilities')
-rw-r--r-- | sys/dev/hyperv/utilities/hv_kvp.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/sys/dev/hyperv/utilities/hv_kvp.c b/sys/dev/hyperv/utilities/hv_kvp.c index 4598510..58d565c4 100644 --- a/sys/dev/hyperv/utilities/hv_kvp.c +++ b/sys/dev/hyperv/utilities/hv_kvp.c @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include <sys/reboot.h> #include <sys/lock.h> #include <sys/taskqueue.h> +#include <sys/selinfo.h> #include <sys/sysctl.h> #include <sys/poll.h> #include <sys/proc.h> @@ -114,6 +115,8 @@ static struct cdev *hv_kvp_dev; static struct hv_kvp_msg *hv_kvp_dev_buf; struct proc *daemon_task; +static struct selinfo hv_kvp_selinfo; + /* * Global state to track and synchronize multiple * KVP transaction requests from the host. @@ -628,6 +631,9 @@ hv_kvp_send_msg_to_daemon(void) /* Send the msg to user via function deamon_read - setting sema */ sema_post(&kvp_globals.dev_sema); + + /* We should wake up the daemon, in case it's doing poll() */ + selwakeup(&hv_kvp_selinfo); } @@ -940,7 +946,7 @@ hv_kvp_dev_daemon_write(struct cdev *dev __unused, struct uio *uio, int ioflag _ * for daemon to read. */ static int -hv_kvp_dev_daemon_poll(struct cdev *dev __unused, int events, struct thread *td __unused) +hv_kvp_dev_daemon_poll(struct cdev *dev __unused, int events, struct thread *td) { int revents = 0; @@ -953,6 +959,9 @@ hv_kvp_dev_daemon_poll(struct cdev *dev __unused, int events, struct thread *td */ if (kvp_globals.daemon_busy == true) revents = POLLIN; + else + selrecord(td, &hv_kvp_selinfo); + mtx_unlock(&kvp_globals.pending_mutex); return (revents); |