Skip to contentSkip to conversation

linux/blktap: fix racy memory refernce with ring_ok

PATCH New Isaku Yamahata 1 participant 1 message Apr 28, 2009 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 2/4 linux/blktap: fix racy memory refernce with ring_ok

blktap: fix race memory refernce with ring_ok.

fix race memory refernce with ring_ok.
ring_ok is shared by mmapping process and blktap kernel thread.

drivers/xen/blktap/blktap.c +5 -0
@@ -617,6 +617,9 @@ static int blktap_release(struct inode *
 	if (!info)
 		return 0;
 
+	info->ring_ok = 0;
+	smp_wmb();
+
 	info->dev_inuse = 0;
 	DPRINTK("Freeing device [/dev/xen/blktap%d]\n",info->minor);
 
@@ -717,6 +720,7 @@ static int blktap_mmap(struct file *filp
 #endif
 
 	info->vma = vma;
+	smp_wmb();
 	info->ring_ok = 1;
 	return 0;
  fail:
@@ -1390,6 +1394,7 @@ static void dispatch_rw_block_io(blkif_t
 		WPRINTK("blktap: ring not ready for requests!\n");
 		goto fail_response;
 	}
+	smp_rmb();
 
 	if (RING_FULL(&info->ufe_ring)) {
 		WPRINTK("blktap: fe_ring is full, can't add "

blktap: fix race memory refernce with ring_ok.

fix race memory refernce with ring_ok.
ring_ok is shared by mmapping process and blktap kernel thread.

drivers/xen/blktap/blktap.c +5 -0
@@ -617,6 +617,9 @@ static int blktap_release(struct inode *
 	if (!info)
 		return 0;
 
+	info->ring_ok = 0;
+	smp_wmb();
+
 	info->dev_inuse = 0;
 	DPRINTK("Freeing device [/dev/xen/blktap%d]\n",info->minor);
 
@@ -717,6 +720,7 @@ static int blktap_mmap(struct file *filp
 #endif
 
 	info->vma = vma;
+	smp_wmb();
 	info->ring_ok = 1;
 	return 0;
  fail:
@@ -1390,6 +1394,7 @@ static void dispatch_rw_block_io(blkif_t
 		WPRINTK("blktap: ring not ready for requests!\n");
 		goto fail_response;
 	}
+	smp_rmb();
 
 	if (RING_FULL(&info->ufe_ring)) {
 		WPRINTK("blktap: fe_ring is full, can't add "

_______________________________________________
Xen-ia64-devel mailing list
[email protected]
http://lists.xensource.com/xen-ia64-devel