]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commitdiff
libvchan: Read prod/cons only once.
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Fri, 20 Nov 2015 17:22:14 +0000 (12:22 -0500)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Fri, 18 Dec 2015 14:50:02 +0000 (09:50 -0500)
We must ensure that the prod/cons are only read once and that
the compiler won't try to optimize the reads. That is split
the read of these in multiple instructions influencing later
branch code. As such insert barriers when fetching the cons
and prod index.

This is part of XSA155.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
tools/libvchan/io.c

index 8a9629ba88c0c8c7d5477e2dae03ef204a04881f..381cc051723cbcd595955bfd1cce50b92ded65c4 100644 (file)
@@ -117,6 +117,7 @@ static inline int send_notify(struct libxenvchan *ctrl, uint8_t bit)
 static inline int raw_get_data_ready(struct libxenvchan *ctrl)
 {
        uint32_t ready = rd_prod(ctrl) - rd_cons(ctrl);
+       xen_mb(); /* Ensure 'ready' is read only once. */
        if (ready > rd_ring_size(ctrl))
                /* We have no way to return errors.  Locking up the ring is
                 * better than the alternatives. */
@@ -158,6 +159,7 @@ int libxenvchan_data_ready(struct libxenvchan *ctrl)
 static inline int raw_get_buffer_space(struct libxenvchan *ctrl)
 {
        uint32_t ready = wr_ring_size(ctrl) - (wr_prod(ctrl) - wr_cons(ctrl));
+       xen_mb(); /* Ensure 'ready' is read only once. */
        if (ready > wr_ring_size(ctrl))
                /* We have no way to return errors.  Locking up the ring is
                 * better than the alternatives. */