Commit 6f960fe4 authored by Keir Fraser's avatar Keir Fraser

libxenctrl headers should not pollute macro namespace with

mb/rmb/wmb. Instead add a xen_ prefix. Modify Xen's public headers to
expect the prefixed names instead of bare mb/rmb/wmb, but gate this
expectation on a bump of __XEN_INTERFACE_VERSION__.
Signed-off-by: default avatarKeir Fraser <keir.fraser@citrix.com>
parent bbb71aa2
...@@ -641,7 +641,7 @@ static void get_io_request(struct td_state *s) ...@@ -641,7 +641,7 @@ static void get_io_request(struct td_state *s)
if (!run) return; /*We have received signal to close*/ if (!run) return; /*We have received signal to close*/
rp = info->fe_ring.sring->req_prod; rp = info->fe_ring.sring->req_prod;
rmb(); xen_rmb();
for (j = info->fe_ring.req_cons; j != rp; j++) for (j = info->fe_ring.req_cons; j != rp; j++)
{ {
int done = 0, start_seg = 0; int done = 0, start_seg = 0;
......
...@@ -153,7 +153,7 @@ static void buffer_append(struct domain *dom) ...@@ -153,7 +153,7 @@ static void buffer_append(struct domain *dom)
cons = intf->out_cons; cons = intf->out_cons;
prod = intf->out_prod; prod = intf->out_prod;
mb(); xen_mb();
size = prod - cons; size = prod - cons;
if ((size == 0) || (size > sizeof(intf->out))) if ((size == 0) || (size > sizeof(intf->out)))
...@@ -172,7 +172,7 @@ static void buffer_append(struct domain *dom) ...@@ -172,7 +172,7 @@ static void buffer_append(struct domain *dom)
buffer->data[buffer->size++] = intf->out[ buffer->data[buffer->size++] = intf->out[
MASK_XENCONS_IDX(cons++, intf->out)]; MASK_XENCONS_IDX(cons++, intf->out)];
mb(); xen_mb();
intf->out_cons = cons; intf->out_cons = cons;
xc_evtchn_notify(dom->xce_handle, dom->local_port); xc_evtchn_notify(dom->xce_handle, dom->local_port);
...@@ -750,7 +750,7 @@ static int ring_free_bytes(struct domain *dom) ...@@ -750,7 +750,7 @@ static int ring_free_bytes(struct domain *dom)
cons = intf->in_cons; cons = intf->in_cons;
prod = intf->in_prod; prod = intf->in_prod;
mb(); xen_mb();
space = prod - cons; space = prod - cons;
if (space > sizeof(intf->in)) if (space > sizeof(intf->in))
...@@ -797,7 +797,7 @@ static void handle_tty_read(struct domain *dom) ...@@ -797,7 +797,7 @@ static void handle_tty_read(struct domain *dom)
intf->in[MASK_XENCONS_IDX(prod++, intf->in)] = intf->in[MASK_XENCONS_IDX(prod++, intf->in)] =
msg[i]; msg[i];
} }
wmb(); xen_wmb();
intf->in_prod = prod; intf->in_prod = prod;
xc_evtchn_notify(dom->xce_handle, dom->local_port); xc_evtchn_notify(dom->xce_handle, dom->local_port);
} else { } else {
......
...@@ -140,8 +140,8 @@ void* handle_mount(void *data) ...@@ -140,8 +140,8 @@ void* handle_mount(void *data)
handle_aio_events(mount); handle_aio_events(mount);
moretodo: moretodo:
rp = mount->ring.sring->req_prod; rp = mount->ring.sring->req_prod;
rmb(); /* Ensure we see queued requests up to 'rp'. */ xen_rmb(); /* Ensure we see queued requests up to 'rp'. */
while ((cons = mount->ring.req_cons) != rp) while ((cons = mount->ring.req_cons) != rp)
{ {
int i; int i;
......
...@@ -75,7 +75,7 @@ static void buffer_append(struct domain *dom) ...@@ -75,7 +75,7 @@ static void buffer_append(struct domain *dom)
cons = intf->out_cons; cons = intf->out_cons;
prod = intf->out_prod; prod = intf->out_prod;
mb(); xen_mb();
size = prod - cons; size = prod - cons;
if ((size == 0) || (size > sizeof(intf->out))) if ((size == 0) || (size > sizeof(intf->out)))
...@@ -94,7 +94,7 @@ static void buffer_append(struct domain *dom) ...@@ -94,7 +94,7 @@ static void buffer_append(struct domain *dom)
buffer->data[buffer->size++] = intf->out[ buffer->data[buffer->size++] = intf->out[
MASK_XENCONS_IDX(cons++, intf->out)]; MASK_XENCONS_IDX(cons++, intf->out)];
mb(); xen_mb();
intf->out_cons = cons; intf->out_cons = cons;
xc_evtchn_notify(dom->xce_handle, dom->local_port); xc_evtchn_notify(dom->xce_handle, dom->local_port);
...@@ -289,7 +289,7 @@ static int ring_free_bytes(struct domain *dom) ...@@ -289,7 +289,7 @@ static int ring_free_bytes(struct domain *dom)
cons = intf->in_cons; cons = intf->in_cons;
prod = intf->in_prod; prod = intf->in_prod;
mb(); xen_mb();
space = prod - cons; space = prod - cons;
if (space > sizeof(intf->in)) if (space > sizeof(intf->in))
...@@ -322,7 +322,7 @@ static void xencons_receive(void *opaque, const uint8_t *buf, int len) ...@@ -322,7 +322,7 @@ static void xencons_receive(void *opaque, const uint8_t *buf, int len)
intf->in[MASK_XENCONS_IDX(prod++, intf->in)] = intf->in[MASK_XENCONS_IDX(prod++, intf->in)] =
buf[i]; buf[i];
} }
wmb(); xen_wmb();
intf->in_prod = prod; intf->in_prod = prod;
xc_evtchn_notify(dom->xce_handle, dom->local_port); xc_evtchn_notify(dom->xce_handle, dom->local_port);
} }
......
...@@ -485,7 +485,7 @@ static void xenfb_on_fb_event(struct xenfb *xenfb) ...@@ -485,7 +485,7 @@ static void xenfb_on_fb_event(struct xenfb *xenfb)
prod = page->out_prod; prod = page->out_prod;
if (prod == page->out_cons) if (prod == page->out_cons)
return; return;
rmb(); /* ensure we see ring contents up to prod */ xen_rmb(); /* ensure we see ring contents up to prod */
for (cons = page->out_cons; cons != prod; cons++) { for (cons = page->out_cons; cons != prod; cons++) {
union xenfb_out_event *event = &XENFB_OUT_RING_REF(page, cons); union xenfb_out_event *event = &XENFB_OUT_RING_REF(page, cons);
int x, y, w, h; int x, y, w, h;
...@@ -512,7 +512,7 @@ static void xenfb_on_fb_event(struct xenfb *xenfb) ...@@ -512,7 +512,7 @@ static void xenfb_on_fb_event(struct xenfb *xenfb)
break; break;
} }
} }
mb(); /* ensure we're done with ring contents */ xen_mb(); /* ensure we're done with ring contents */
page->out_cons = cons; page->out_cons = cons;
xc_evtchn_notify(xenfb->evt_xch, xenfb->fb.port); xc_evtchn_notify(xenfb->evt_xch, xenfb->fb.port);
} }
...@@ -571,9 +571,9 @@ static int xenfb_kbd_event(struct xenfb *xenfb, ...@@ -571,9 +571,9 @@ static int xenfb_kbd_event(struct xenfb *xenfb,
return -1; return -1;
} }
mb(); /* ensure ring space available */ xen_mb(); /* ensure ring space available */
XENKBD_IN_RING_REF(page, prod) = *event; XENKBD_IN_RING_REF(page, prod) = *event;
wmb(); /* ensure ring contents visible */ xen_wmb(); /* ensure ring contents visible */
page->in_prod = prod + 1; page->in_prod = prod + 1;
return xc_evtchn_notify(xenfb->evt_xch, xenfb->kbd.port); return xc_evtchn_notify(xenfb->evt_xch, xenfb->kbd.port);
} }
......
...@@ -218,7 +218,7 @@ static ioreq_t *__cpu_get_ioreq(int vcpu) ...@@ -218,7 +218,7 @@ static ioreq_t *__cpu_get_ioreq(int vcpu)
return NULL; return NULL;
} }
rmb(); /* see IOREQ_READY /then/ read contents of ioreq */ xen_rmb(); /* see IOREQ_READY /then/ read contents of ioreq */
req->state = STATE_IOREQ_INPROCESS; req->state = STATE_IOREQ_INPROCESS;
return req; return req;
...@@ -568,7 +568,7 @@ void __handle_buffered_iopage(CPUState *env) ...@@ -568,7 +568,7 @@ void __handle_buffered_iopage(CPUState *env)
__handle_ioreq(env, &req); __handle_ioreq(env, &req);
mb(); xen_mb();
buffered_io_page->read_pointer += qw ? 2 : 1; buffered_io_page->read_pointer += qw ? 2 : 1;
} }
} }
...@@ -603,7 +603,7 @@ void cpu_handle_ioreq(void *opaque) ...@@ -603,7 +603,7 @@ void cpu_handle_ioreq(void *opaque)
return; return;
} }
wmb(); /* Update ioreq contents /then/ update state. */ xen_wmb(); /* Update ioreq contents /then/ update state. */
/* /*
* We do this before we send the response so that the tools * We do this before we send the response so that the tools
......
...@@ -43,22 +43,21 @@ ...@@ -43,22 +43,21 @@
*/ */
#if defined(__i386__) #if defined(__i386__)
#define mb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" ) #define xen_mb() asm volatile ( "lock; addl $0,0(%%esp)" : : : "memory" )
#define rmb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" ) #define xen_rmb() asm volatile ( "lock; addl $0,0(%%esp)" : : : "memory" )
#define wmb() __asm__ __volatile__ ( "" : : : "memory") #define xen_wmb() asm volatile ( "" : : : "memory")
#elif defined(__x86_64__) #elif defined(__x86_64__)
#define mb() __asm__ __volatile__ ( "mfence" : : : "memory") #define xen_mb() asm volatile ( "mfence" : : : "memory")
#define rmb() __asm__ __volatile__ ( "lfence" : : : "memory") #define xen_rmb() asm volatile ( "lfence" : : : "memory")
#define wmb() __asm__ __volatile__ ( "" : : : "memory") #define xen_wmb() asm volatile ( "" : : : "memory")
#elif defined(__ia64__) #elif defined(__ia64__)
#define mb() __asm__ __volatile__ ("mf" ::: "memory") #define xen_mb() asm volatile ("mf" ::: "memory")
#define rmb() __asm__ __volatile__ ("mf" ::: "memory") #define xen_rmb() asm volatile ("mf" ::: "memory")
#define wmb() __asm__ __volatile__ ("mf" ::: "memory") #define xen_wmb() asm volatile ("mf" ::: "memory")
#elif defined(__powerpc__) #elif defined(__powerpc__)
/* XXX loosen these up later */ #define xen_mb() asm volatile ("sync" : : : "memory")
#define mb() __asm__ __volatile__ ("sync" : : : "memory") #define xen_rmb() asm volatile ("sync" : : : "memory") /* lwsync? */
#define rmb() __asm__ __volatile__ ("sync" : : : "memory") /* lwsync? */ #define xen_wmb() asm volatile ("sync" : : : "memory") /* eieio? */
#define wmb() __asm__ __volatile__ ("sync" : : : "memory") /* eieio? */
#else #else
#error "Define barriers" #error "Define barriers"
#endif #endif
......
...@@ -511,10 +511,10 @@ int monitor_tbufs(void) ...@@ -511,10 +511,10 @@ int monitor_tbufs(void)
{ {
while ( meta[i]->cons != meta[i]->prod ) while ( meta[i]->cons != meta[i]->prod )
{ {
rmb(); /* read prod, then read item. */ xen_rmb(); /* read prod, then read item. */
rec_size = process_record( rec_size = process_record(
i, (struct t_rec *)(data[i] + meta[i]->cons % data_size)); i, (struct t_rec *)(data[i] + meta[i]->cons % data_size));
mb(); /* read item, then update cons. */ xen_mb(); /* read item, then update cons. */
meta[i]->cons += rec_size; meta[i]->cons += rec_size;
} }
} }
......
...@@ -112,7 +112,7 @@ static int writechn(struct connection *conn, ...@@ -112,7 +112,7 @@ static int writechn(struct connection *conn,
/* Must read indexes once, and before anything else, and verified. */ /* Must read indexes once, and before anything else, and verified. */
cons = intf->rsp_cons; cons = intf->rsp_cons;
prod = intf->rsp_prod; prod = intf->rsp_prod;
mb(); xen_mb();
if (!check_indexes(cons, prod)) { if (!check_indexes(cons, prod)) {
errno = EIO; errno = EIO;
...@@ -124,7 +124,7 @@ static int writechn(struct connection *conn, ...@@ -124,7 +124,7 @@ static int writechn(struct connection *conn,
len = avail; len = avail;
memcpy(dest, data, len); memcpy(dest, data, len);
mb(); xen_mb();
intf->rsp_prod += len; intf->rsp_prod += len;
xc_evtchn_notify(xce_handle, conn->domain->port); xc_evtchn_notify(xce_handle, conn->domain->port);
...@@ -142,7 +142,7 @@ static int readchn(struct connection *conn, void *data, unsigned int len) ...@@ -142,7 +142,7 @@ static int readchn(struct connection *conn, void *data, unsigned int len)
/* Must read indexes once, and before anything else, and verified. */ /* Must read indexes once, and before anything else, and verified. */
cons = intf->req_cons; cons = intf->req_cons;
prod = intf->req_prod; prod = intf->req_prod;
mb(); xen_mb();
if (!check_indexes(cons, prod)) { if (!check_indexes(cons, prod)) {
errno = EIO; errno = EIO;
...@@ -154,7 +154,7 @@ static int readchn(struct connection *conn, void *data, unsigned int len) ...@@ -154,7 +154,7 @@ static int readchn(struct connection *conn, void *data, unsigned int len)
len = avail; len = avail;
memcpy(data, src, len); memcpy(data, src, len);
mb(); xen_mb();
intf->req_cons += len; intf->req_cons += len;
xc_evtchn_notify(xce_handle, conn->domain->port); xc_evtchn_notify(xce_handle, conn->domain->port);
......
...@@ -384,8 +384,8 @@ int monitor_tbufs(int outfd) ...@@ -384,8 +384,8 @@ int monitor_tbufs(int outfd)
/* Read window information only once. */ /* Read window information only once. */
cons = meta[i]->cons; cons = meta[i]->cons;
prod = meta[i]->prod; prod = meta[i]->prod;
rmb(); /* read prod, then read item. */ xen_rmb(); /* read prod, then read item. */
if ( cons == prod ) if ( cons == prod )
continue; continue;
...@@ -428,7 +428,7 @@ int monitor_tbufs(int outfd) ...@@ -428,7 +428,7 @@ int monitor_tbufs(int outfd)
outfd); outfd);
} }
mb(); /* read buffer, then update cons. */ xen_mb(); /* read buffer, then update cons. */
meta[i]->cons = prod; meta[i]->cons = prod;
} }
......
...@@ -27,6 +27,14 @@ ...@@ -27,6 +27,14 @@
#ifndef __XEN_PUBLIC_IO_RING_H__ #ifndef __XEN_PUBLIC_IO_RING_H__
#define __XEN_PUBLIC_IO_RING_H__ #define __XEN_PUBLIC_IO_RING_H__
#include "../xen-compat.h"
#if __XEN_INTERFACE_VERSION__ < 0x00030208
#define xen_mb() mb()
#define xen_rmb() rmb()
#define xen_wmb() wmb()
#endif
typedef unsigned int RING_IDX; typedef unsigned int RING_IDX;
/* Round a 32-bit unsigned constant down to the nearest power of two. */ /* Round a 32-bit unsigned constant down to the nearest power of two. */
...@@ -211,12 +219,12 @@ typedef struct __name##_back_ring __name##_back_ring_t ...@@ -211,12 +219,12 @@ typedef struct __name##_back_ring __name##_back_ring_t
(((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r)) (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
#define RING_PUSH_REQUESTS(_r) do { \ #define RING_PUSH_REQUESTS(_r) do { \
wmb(); /* back sees requests /before/ updated producer index */ \ xen_wmb(); /* back sees requests /before/ updated producer index */ \
(_r)->sring->req_prod = (_r)->req_prod_pvt; \ (_r)->sring->req_prod = (_r)->req_prod_pvt; \
} while (0) } while (0)
#define RING_PUSH_RESPONSES(_r) do { \ #define RING_PUSH_RESPONSES(_r) do { \
wmb(); /* front sees responses /before/ updated producer index */ \ xen_wmb(); /* front sees resps /before/ updated producer index */ \
(_r)->sring->rsp_prod = (_r)->rsp_prod_pvt; \ (_r)->sring->rsp_prod = (_r)->rsp_prod_pvt; \
} while (0) } while (0)
...@@ -253,9 +261,9 @@ typedef struct __name##_back_ring __name##_back_ring_t ...@@ -253,9 +261,9 @@ typedef struct __name##_back_ring __name##_back_ring_t
#define RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(_r, _notify) do { \ #define RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(_r, _notify) do { \
RING_IDX __old = (_r)->sring->req_prod; \ RING_IDX __old = (_r)->sring->req_prod; \
RING_IDX __new = (_r)->req_prod_pvt; \ RING_IDX __new = (_r)->req_prod_pvt; \
wmb(); /* back sees requests /before/ updated producer index */ \ xen_wmb(); /* back sees requests /before/ updated producer index */ \
(_r)->sring->req_prod = __new; \ (_r)->sring->req_prod = __new; \
mb(); /* back sees new requests /before/ we check req_event */ \ xen_mb(); /* back sees new requests /before/ we check req_event */ \
(_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) < \ (_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) < \
(RING_IDX)(__new - __old)); \ (RING_IDX)(__new - __old)); \
} while (0) } while (0)
...@@ -263,9 +271,9 @@ typedef struct __name##_back_ring __name##_back_ring_t ...@@ -263,9 +271,9 @@ typedef struct __name##_back_ring __name##_back_ring_t
#define RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(_r, _notify) do { \ #define RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(_r, _notify) do { \
RING_IDX __old = (_r)->sring->rsp_prod; \ RING_IDX __old = (_r)->sring->rsp_prod; \
RING_IDX __new = (_r)->rsp_prod_pvt; \ RING_IDX __new = (_r)->rsp_prod_pvt; \
wmb(); /* front sees responses /before/ updated producer index */ \ xen_wmb(); /* front sees resps /before/ updated producer index */ \
(_r)->sring->rsp_prod = __new; \ (_r)->sring->rsp_prod = __new; \
mb(); /* front sees new responses /before/ we check rsp_event */ \ xen_mb(); /* front sees new resps /before/ we check rsp_event */ \
(_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) < \ (_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) < \
(RING_IDX)(__new - __old)); \ (RING_IDX)(__new - __old)); \
} while (0) } while (0)
...@@ -274,7 +282,7 @@ typedef struct __name##_back_ring __name##_back_ring_t ...@@ -274,7 +282,7 @@ typedef struct __name##_back_ring __name##_back_ring_t
(_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \ (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \
if (_work_to_do) break; \ if (_work_to_do) break; \
(_r)->sring->req_event = (_r)->req_cons + 1; \ (_r)->sring->req_event = (_r)->req_cons + 1; \
mb(); \ xen_mb(); \
(_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \ (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \
} while (0) } while (0)
...@@ -282,7 +290,7 @@ typedef struct __name##_back_ring __name##_back_ring_t ...@@ -282,7 +290,7 @@ typedef struct __name##_back_ring __name##_back_ring_t
(_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \ (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \
if (_work_to_do) break; \ if (_work_to_do) break; \
(_r)->sring->rsp_event = (_r)->rsp_cons + 1; \ (_r)->sring->rsp_event = (_r)->rsp_cons + 1; \
mb(); \ xen_mb(); \
(_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \ (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \
} while (0) } while (0)
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#ifndef __XEN_PUBLIC_XEN_COMPAT_H__ #ifndef __XEN_PUBLIC_XEN_COMPAT_H__
#define __XEN_PUBLIC_XEN_COMPAT_H__ #define __XEN_PUBLIC_XEN_COMPAT_H__
#define __XEN_LATEST_INTERFACE_VERSION__ 0x00030207 #define __XEN_LATEST_INTERFACE_VERSION__ 0x00030208
#if defined(__XEN__) || defined(__XEN_TOOLS__) #if defined(__XEN__) || defined(__XEN_TOOLS__)
/* Xen is built with matching headers and implements the latest interface. */ /* Xen is built with matching headers and implements the latest interface. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment