vkr: replace memory_region by vkr_region

The only functional difference should be that vkr_region_is_aligned
checks both begin and end.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
macos/master
Chia-I Wu 3 years ago
parent 81e081c6e3
commit 601d1afe72
  1. 10
      src/venus/vkr_ring.c
  2. 17
      src/venus/vkr_ring.h
  3. 52
      src/venus/vkr_transport.c

@ -68,7 +68,7 @@ vkr_ring_create(const struct vkr_ring_layout *layout,
return NULL; return NULL;
#define ring_attach_shared(member) \ #define ring_attach_shared(member) \
ring->shared.member = (void *)((uint8_t *)shared + layout->member.offset) ring->shared.member = (void *)((uint8_t *)shared + layout->member.begin)
ring_attach_shared(head); ring_attach_shared(head);
ring_attach_shared(tail); ring_attach_shared(tail);
ring_attach_shared(status); ring_attach_shared(status);
@ -76,10 +76,10 @@ vkr_ring_create(const struct vkr_ring_layout *layout,
ring_attach_shared(extra); ring_attach_shared(extra);
#undef ring_attach_shared #undef ring_attach_shared
assert(layout->buffer.size && util_is_power_of_two(layout->buffer.size)); ring->buffer_size = vkr_region_size(&layout->buffer);
ring->buffer_size = layout->buffer.size; assert(ring->buffer_size && util_is_power_of_two(ring->buffer_size));
ring->buffer_mask = layout->buffer.size - 1; ring->buffer_mask = ring->buffer_size - 1;
ring->extra_size = layout->extra.size; ring->extra_size = vkr_region_size(&layout->extra);
/* we will manage head and status, and we expect them to be 0 initially */ /* we will manage head and status, and we expect them to be 0 initially */
if (*ring->shared.head || *ring->shared.status) { if (*ring->shared.head || *ring->shared.status) {

@ -8,20 +8,13 @@
#include "vkr_common.h" #include "vkr_common.h"
struct virgl_context;
struct memory_region {
size_t offset;
size_t size;
};
/* the layout of a ring in a virgl_resource */ /* the layout of a ring in a virgl_resource */
struct vkr_ring_layout { struct vkr_ring_layout {
struct memory_region head; struct vkr_region head;
struct memory_region tail; struct vkr_region tail;
struct memory_region status; struct vkr_region status;
struct memory_region buffer; struct vkr_region buffer;
struct memory_region extra; struct vkr_region extra;
}; };
static_assert(ATOMIC_INT_LOCK_FREE == 2 && sizeof(atomic_uint) == 4, static_assert(ATOMIC_INT_LOCK_FREE == 2 && sizeof(atomic_uint) == 4,

@ -155,62 +155,62 @@ lookup_ring(struct vkr_context *ctx, uint64_t ring_id)
static bool static bool
vkr_ring_layout_init(struct vkr_ring_layout *layout, const VkRingCreateInfoMESA *info) vkr_ring_layout_init(struct vkr_ring_layout *layout, const VkRingCreateInfoMESA *info)
{ {
/* clang-format off */
*layout = (struct vkr_ring_layout){ *layout = (struct vkr_ring_layout){
.head = { info->headOffset, sizeof(uint32_t) }, .head = VKR_REGION_INIT(info->headOffset, sizeof(uint32_t)),
.tail = { info->tailOffset, sizeof(uint32_t) }, .tail = VKR_REGION_INIT(info->tailOffset, sizeof(uint32_t)),
.status = { info->statusOffset, sizeof(uint32_t) }, .status = VKR_REGION_INIT(info->statusOffset, sizeof(uint32_t)),
.buffer = { info->bufferOffset, info->bufferSize }, .buffer = VKR_REGION_INIT(info->bufferOffset, info->bufferSize),
.extra = { info->extraOffset, info->extraSize }, .extra = VKR_REGION_INIT(info->extraOffset, info->extraSize),
}; };
const struct memory_region *regions[] = { const struct vkr_region res_region = VKR_REGION_INIT(0, info->size);
const struct vkr_region *regions[] = {
&layout->head, &layout->head,
&layout->tail, &layout->tail,
&layout->status, &layout->status,
&layout->buffer, &layout->buffer,
&layout->extra, &layout->extra,
}; };
/* clang-format on */
for (size_t i = 0; i < ARRAY_SIZE(regions); i++) { for (size_t i = 0; i < ARRAY_SIZE(regions); i++) {
if (regions[i]->offset > info->size || const struct vkr_region *region = regions[i];
regions[i]->size > info->size - regions[i]->offset) {
vkr_log("ring buffer control variable (offset=%lu, size=%lu) placed" if (!vkr_region_is_valid(region) || !vkr_region_is_within(region, &res_region)) {
vkr_log("ring buffer control variable (begin=%lu, end=%lu) placed"
" out-of-bounds in shared memory layout", " out-of-bounds in shared memory layout",
regions[i]->offset, regions[i]->size); region->begin, region->end);
return false; return false;
} }
if (regions[i]->offset & 0x3) { if (!vkr_region_is_aligned(region, 4)) {
vkr_log("ring buffer control variable (offset=%lu, size=%lu) must be" vkr_log("ring buffer control variable (begin=%lu, end=%lu) must be"
" 32-bit aligned in shared memory layout", " 32-bit aligned in shared memory layout",
regions[i]->offset, regions[i]->size); region->begin, region->end);
return false; return false;
} }
} }
/* assumes region->size == 0 is valid */ /* assumes region->size == 0 is valid */
for (size_t i = 0; i < ARRAY_SIZE(regions); i++) { for (size_t i = 0; i < ARRAY_SIZE(regions); i++) {
if (!regions[i]->size) const struct vkr_region *region = regions[i];
continue;
for (size_t j = i + 1; j < ARRAY_SIZE(regions); j++) { for (size_t j = i + 1; j < ARRAY_SIZE(regions); j++) {
if (!regions[j]->size) const struct vkr_region *other = regions[j];
continue;
if (regions[i]->offset < regions[j]->offset + regions[j]->size && if (!vkr_region_is_disjoint(region, other)) {
regions[j]->offset < regions[i]->offset + regions[i]->size) { vkr_log("ring buffer control variable (begin=%lu, end=%lu)"
vkr_log("ring buffer control variable (offset=%lu, size=%lu)" " overlaps with control variable (begin=%lu, end=%lu)",
" overlaps with control variable (offset=%lu, size=%lu)", other->begin, other->end, region->begin, region->end);
regions[j]->offset, regions[j]->size, regions[i]->offset,
regions[i]->size);
return false; return false;
} }
} }
} }
if (!layout->buffer.size || !util_is_power_of_two(layout->buffer.size)) { const size_t buf_size = vkr_region_size(&layout->buffer);
vkr_log("ring buffer size (%lu) must be a power of two", if (!buf_size || !util_is_power_of_two(buf_size)) {
layout->buffer.size); vkr_log("ring buffer size (%lu) must be a power of two", buf_size);
return false; return false;
} }

Loading…
Cancel
Save