ia64/xen-unstable

changeset 7366:af38c6b205f6

Keir moved barriers,
Competence questions are raised:
Correctness withers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
author kaf24@firebug.cl.cam.ac.uk
date Wed Oct 12 17:00:29 2005 +0100 (2005-10-12)
parents 9d47f70345a4
children d6e99066959a
files linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Wed Oct 12 16:42:35 2005 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Wed Oct 12 17:00:29 2005 +0100
     1.3 @@ -130,7 +130,7 @@ int xb_write(const void *data, unsigned 
     1.4  
     1.5  		wait_event_interruptible(xb_waitq, output_avail(out));
     1.6  
     1.7 -		mb();
     1.8 +		/* Make local copy of header to check for sanity. */
     1.9  		h = *out;
    1.10  		if (!check_buffer(&h))
    1.11  			return -EIO;
    1.12 @@ -140,10 +140,20 @@ int xb_write(const void *data, unsigned 
    1.13  			continue;
    1.14  		if (avail > len)
    1.15  			avail = len;
    1.16 +
    1.17 +		/* Make sure we read header before we write data
    1.18 +		 * (implied by data-dependency, but let's play safe). */
    1.19 +		mb();
    1.20 +
    1.21  		memcpy(dst, data, avail);
    1.22  		data += avail;
    1.23  		len -= avail;
    1.24 +
    1.25 +		/* Other side must not see new header until data is there. */
    1.26 +		wmb();
    1.27  		update_output_chunk(out, avail);
    1.28 +
    1.29 +		/* This implies mb() before other side sees interrupt. */
    1.30  		notify_remote_via_evtchn(xen_start_info->store_evtchn);
    1.31  	} while (len != 0);
    1.32  
    1.33 @@ -171,7 +181,6 @@ int xb_read(void *data, unsigned len)
    1.34  
    1.35  		wait_event_interruptible(xb_waitq, xs_input_avail());
    1.36  
    1.37 -		mb();
    1.38  		h = *in;
    1.39  		if (!check_buffer(&h))
    1.40  			return -EIO;
    1.41 @@ -183,13 +192,21 @@ int xb_read(void *data, unsigned len)
    1.42  			avail = len;
    1.43  		was_full = !output_avail(&h);
    1.44  
    1.45 +		/* We must read header before we read data. */
    1.46 +		rmb();
    1.47 +
    1.48  		memcpy(data, src, avail);
    1.49  		data += avail;
    1.50  		len -= avail;
    1.51 +
    1.52 +		/* Other side must not see free space until we've copied out */
    1.53 +		mb();
    1.54 +
    1.55  		update_input_chunk(in, avail);
    1.56  		pr_debug("Finished read of %i bytes (%i to go)\n", avail, len);
    1.57  		/* If it was full, tell them we've taken some. */
    1.58  		if (was_full)
    1.59 +			/* Implies mb(): they will see new header. */
    1.60  			notify_remote_via_evtchn(xen_start_info->store_evtchn);
    1.61  	}
    1.62