Skip to content

Commit

Permalink
zephyr: Switch to new barrier API
Browse files Browse the repository at this point in the history
Calling dmb() and dsb() directly is no longer supported. Use the new
barrier API instead.

Signed-off-by: Mykyta Poturai <[email protected]>
  • Loading branch information
Deedone committed Feb 28, 2024
1 parent 14ceb8a commit f9aba2d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
17 changes: 9 additions & 8 deletions vch/src/vch.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <zephyr/xen/events.h>
#include <zephyr/xen/gnttab.h>
#include <zephyr/sys/barrier.h>

#include "vch.h"

Expand Down Expand Up @@ -56,7 +57,7 @@ static int _vch_notify(struct vch_handle *h, int rw)
return -EINVAL;
}

dmb();
z_barrier_dmem_fence_full();
if (h->is_server) {
target = &h->ring->srv_notify;
} else {
Expand Down Expand Up @@ -92,15 +93,15 @@ static void _vch_unmask_notify(struct vch_handle *h, int bit)
}

__atomic_fetch_or(target, bit, __ATOMIC_SEQ_CST);
dmb();
z_barrier_dmem_fence_full();
}

static inline size_t _vch_get_rd_avail(struct vch_handle *h, size_t req)
{

size_t avail = RD_PROD(h) - RD_CONS(h);

dmb();
z_barrier_dmem_fence_full();

return avail;
}
Expand All @@ -110,7 +111,7 @@ static inline size_t _vch_get_wr_avail(struct vch_handle *h, size_t req)

size_t avail = WR_RING_SZ(h) - (WR_PROD(h) - WR_CONS(h));

dmb();
z_barrier_dmem_fence_full();

return avail;
}
Expand Down Expand Up @@ -381,13 +382,13 @@ int vch_read(struct vch_handle *h, void *buf, size_t size)
}

/* ensure indexes are read before data access */
dmb();
z_barrier_dmem_fence_full();
size = MIN(size, avail);
chunk = MIN(chunk, size);
memcpy((uint8_t *)buf, h->read_cbuf + idx, chunk);
memcpy((uint8_t *)buf + chunk, h->read_cbuf,
size - chunk);
dmb();
z_barrier_dmem_fence_full();
RD_CONS(h) += size;
if (_vch_notify(h, VCHAN_NOTIFY_READ)) {
return -EFAULT;
Expand Down Expand Up @@ -426,13 +427,13 @@ int vch_write(struct vch_handle *h, const void *buf, size_t size)
}

/* ensure indexes are read before buffer fill */
dmb();
z_barrier_dmem_fence_full();
size = MIN(size, avail);
chunk = MIN(chunk, size);
memcpy(h->write_cbuf + idx, buf, chunk);
memcpy(h->write_cbuf, (uint8_t *)buf + chunk,
size - chunk);
dmb();
z_barrier_dmem_fence_full();
WR_PROD(h) += size;
if (_vch_notify(h, VCHAN_NOTIFY_WRITE)) {
return -EFAULT;
Expand Down
9 changes: 5 additions & 4 deletions xen-console-srv/src/xen_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <zephyr/xen/public/memory.h>
#include <zephyr/xen/public/xen.h>
#include <zephyr/xen/hvm.h>
#include <zephyr/sys/barrier.h>

#include <zephyr/init.h>
#include <zephyr/kernel.h>
Expand Down Expand Up @@ -112,7 +113,7 @@ static void write_to_ext_ring(struct xencons_interface *intf,
XENCONS_RING_IDX idx = 0;
size_t free_space;

__DSB(); /* Read counters, then write data */
z_barrier_dsync_fence_full(); /* Read counters, then write data */
if ((prod - cons) > sizeof(intf->in)) {
LOG_WRN("Invalid state of console input ring. Resetting.");
intf->in_prod = cons;
Expand All @@ -132,7 +133,7 @@ static void write_to_ext_ring(struct xencons_interface *intf,
len--;
}

__DSB(); /* Write data, then update counter */
z_barrier_dsync_fence_full(); /* Write data, then update counter */
intf->in_prod = prod;
}

Expand All @@ -149,7 +150,7 @@ static int read_from_ext_ring(struct xencons_interface *intf,
XENCONS_RING_IDX prod = intf->out_prod;
XENCONS_RING_IDX out_idx = 0;

__DSB(); /* Read counters, then data */
z_barrier_dsync_fence_full(); /* Read counters, then data */
if ((prod - cons) > sizeof(intf->out)) {
LOG_WRN("Invalid state of console output ring. Resetting.");
intf->out_cons = prod;
Expand All @@ -163,7 +164,7 @@ static int read_from_ext_ring(struct xencons_interface *intf,
cons++;
}

__DSB(); /* Read data then update counter */
z_barrier_dsync_fence_full(); /* Read data then update counter */
intf->out_cons = cons;

return recv;
Expand Down
9 changes: 5 additions & 4 deletions xenstore-srv/src/xenstore_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <zephyr/xen/public/hvm/params.h>
#include <zephyr/xen/hvm.h>
#include <zephyr/logging/log.h>
#include <zephyr/sys/barrier.h>

#include <mem-mgmt.h>
#include "domain.h"
Expand Down Expand Up @@ -354,7 +355,7 @@ static int ring_write(struct xenstore *xenstore, const void *data, size_t len)

cons = intf->rsp_cons;
prod = intf->rsp_prod;
dmb();
z_barrier_dmem_fence_full();

if (check_indexes(cons, prod)) {
return -EINVAL;
Expand All @@ -366,7 +367,7 @@ static int ring_write(struct xenstore *xenstore, const void *data, size_t len)
}

memcpy(dest, data, len);
dmb();
z_barrier_dmem_fence_full();
intf->rsp_prod += len;

notify_evtchn(xenstore->local_evtchn);
Expand Down Expand Up @@ -1742,7 +1743,7 @@ static int ring_read(struct xenstore *xenstore, void *data, size_t len)

cons = intf->req_cons;
prod = intf->req_prod;
dmb();
z_barrier_dmem_fence_full();

if (check_indexes(cons, prod)) {
return -EIO;
Expand All @@ -1754,7 +1755,7 @@ static int ring_read(struct xenstore *xenstore, void *data, size_t len)
}

memcpy(data, src, len);
dmb();
z_barrier_dmem_fence_full();
intf->req_cons += len;

notify_evtchn(xenstore->local_evtchn);
Expand Down

0 comments on commit f9aba2d

Please sign in to comment.