Skip to content

Commit 8fd08d8

Browse files
isilenceaxboe
authored andcommitted
io_uring/zcrx: introduce io_parse_rqe()
Add a helper for verifying a rqe and extracting a niov out of it. It'll be reused in following patches. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 5a8b6e7 commit 8fd08d8

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

io_uring/zcrx.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,28 @@ static struct io_uring_zcrx_rqe *io_zcrx_get_rqe(struct io_zcrx_ifq *ifq,
750750
return &ifq->rqes[idx];
751751
}
752752

753+
static inline bool io_parse_rqe(struct io_uring_zcrx_rqe *rqe,
754+
struct io_zcrx_ifq *ifq,
755+
struct net_iov **ret_niov)
756+
{
757+
unsigned niov_idx, area_idx;
758+
struct io_zcrx_area *area;
759+
760+
area_idx = rqe->off >> IORING_ZCRX_AREA_SHIFT;
761+
niov_idx = (rqe->off & ~IORING_ZCRX_AREA_MASK) >> ifq->niov_shift;
762+
763+
if (unlikely(rqe->__pad || area_idx))
764+
return false;
765+
area = ifq->area;
766+
767+
if (unlikely(niov_idx >= area->nia.num_niovs))
768+
return false;
769+
niov_idx = array_index_nospec(niov_idx, area->nia.num_niovs);
770+
771+
*ret_niov = &area->nia.niovs[niov_idx];
772+
return true;
773+
}
774+
753775
static void io_zcrx_ring_refill(struct page_pool *pp,
754776
struct io_zcrx_ifq *ifq)
755777
{
@@ -765,23 +787,11 @@ static void io_zcrx_ring_refill(struct page_pool *pp,
765787

766788
do {
767789
struct io_uring_zcrx_rqe *rqe = io_zcrx_get_rqe(ifq, mask);
768-
struct io_zcrx_area *area;
769790
struct net_iov *niov;
770-
unsigned niov_idx, area_idx;
771791
netmem_ref netmem;
772792

773-
area_idx = rqe->off >> IORING_ZCRX_AREA_SHIFT;
774-
niov_idx = (rqe->off & ~IORING_ZCRX_AREA_MASK) >> ifq->niov_shift;
775-
776-
if (unlikely(rqe->__pad || area_idx))
793+
if (!io_parse_rqe(rqe, ifq, &niov))
777794
continue;
778-
area = ifq->area;
779-
780-
if (unlikely(niov_idx >= area->nia.num_niovs))
781-
continue;
782-
niov_idx = array_index_nospec(niov_idx, area->nia.num_niovs);
783-
784-
niov = &area->nia.niovs[niov_idx];
785795
if (!io_zcrx_put_niov_uref(niov))
786796
continue;
787797

0 commit comments

Comments
 (0)