Skip to contentSkip to conversation

xenbus: fix deadlock on writes to /proc/xen/xenbus

PATCH In review David Vrabel 2 participants 3 messages Dec 9, 2016 – Dec 12, 2016 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 xenbus: fix deadlock on writes to /proc/xen/xenbus

/proc/xen/xenbus does not work correctly. A read blocked waiting for a xenstore message holds the mutex needed for atomic file position updates. This blocks any writes on the same file handle, which can deadlock if the write is needed to unblock the read.

Clear FMODE_ATOMIC_POS when opening this device to always get character device like sematics.

---
v6:
- clear flag after calling nonseekable_open().

---
 drivers/xen/xenbus/xenbus_dev_frontend.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/xen/xenbus/xenbus_dev_frontend.c +2 -0
index 1e8be12..6c0ead4 100644
@@ -538,6 +538,8 @@ static int xenbus_file_open(struct inode *inode, struct file *filp)
 
 	nonseekable_open(inode, filp);
 
+	filp->f_mode &= ~FMODE_ATOMIC_POS; /* cdev-style semantics */
+
 	u = kzalloc(sizeof(*u), GFP_KERNEL);
 	if (u == NULL)
 		return -ENOMEM;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
maintainer Reviewed-by on v6 1/1
#1 lore raw
Quoted 7 lines · David Vrabel

/proc/xen/xenbus does not work correctly. A read blocked waiting for a xenstore message holds the mutex needed for atomic file position updates. This blocks any writes on the same file handle, which can deadlock if the write is needed to unblock the read.

Clear FMODE_ATOMIC_POS when opening this device to always get character device like sematics.

"semantics". I can fix this when committing.

Quoted 2 lines

Juergen

Quoted 13 lines

---
v6:
- clear flag after calling nonseekable_open().

---
 drivers/xen/xenbus/xenbus_dev_frontend.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/xen/xenbus/xenbus_dev_frontend.c +0 -0
index 1e8be12..6c0ead4 100644

drivers/xen/xenbus/xenbus_dev_frontend.c static int xenbus_file_open(struct inode *inode, struct file *filp) · line 545

Quoted 8 lines
drivers/xen/xenbus/xenbus_dev_frontend.c +2 -0
@@ -538,6 +538,8 @@ static int xenbus_file_open(struct inode *inode, struct file *filp)
 
 	nonseekable_open(inode, filp);
 
+	filp->f_mode &= ~FMODE_ATOMIC_POS; /* cdev-style semantics */
+
 	u = kzalloc(sizeof(*u), GFP_KERNEL);
 	if (u == NULL)
 		return -ENOMEM;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

maintainer
#2 lore raw
In reply to David Vrabel
Quoted 9 lines · David Vrabel

/proc/xen/xenbus does not work correctly. A read blocked waiting for a xenstore message holds the mutex needed for atomic file position updates. This blocks any writes on the same file handle, which can deadlock if the write is needed to unblock the read.

Clear FMODE_ATOMIC_POS when opening this device to always get character device like sematics.

Committed to xen/tip.git for-linus-4.10

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel