Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

virtio_ring: factor out core logic for updating last_used_idx

Factor out the core logic for updating last_used_idx to be reused by
the packed in order implementation.

Acked-by: Eugenio Pérez <eperezma@redhat.com>
Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Tested-by: Lei Yang <leiyang@redhat.com>
Reviewed-by: Eugenio Pérez <eperezma@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20251230064649.55597-17-jasowang@redhat.com>

authored by

Jason Wang and committed by
Michael S. Tsirkin
fa56d17b c623106c

+25 -18
+25 -18
drivers/virtio/virtio_ring.c
··· 1754 1754 return virtqueue_poll_packed(vq, READ_ONCE(vq->last_used_idx)); 1755 1755 } 1756 1756 1757 + static void update_last_used_idx_packed(struct vring_virtqueue *vq, 1758 + u16 id, u16 last_used, 1759 + u16 used_wrap_counter) 1760 + { 1761 + last_used += vq->packed.desc_state[id].num; 1762 + if (unlikely(last_used >= vq->packed.vring.num)) { 1763 + last_used -= vq->packed.vring.num; 1764 + used_wrap_counter ^= 1; 1765 + } 1766 + 1767 + last_used = (last_used | (used_wrap_counter << VRING_PACKED_EVENT_F_WRAP_CTR)); 1768 + WRITE_ONCE(vq->last_used_idx, last_used); 1769 + 1770 + /* 1771 + * If we expect an interrupt for the next entry, tell host 1772 + * by writing event index and flush out the write before 1773 + * the read in the next get_buf call. 1774 + */ 1775 + if (vq->packed.event_flags_shadow == VRING_PACKED_EVENT_FLAG_DESC) 1776 + virtio_store_mb(vq->weak_barriers, 1777 + &vq->packed.vring.driver->off_wrap, 1778 + cpu_to_le16(vq->last_used_idx)); 1779 + } 1780 + 1757 1781 static void *virtqueue_get_buf_ctx_packed(struct vring_virtqueue *vq, 1758 1782 unsigned int *len, 1759 1783 void **ctx) ··· 1821 1797 ret = vq->packed.desc_state[id].data; 1822 1798 detach_buf_packed(vq, id, ctx); 1823 1799 1824 - last_used += vq->packed.desc_state[id].num; 1825 - if (unlikely(last_used >= vq->packed.vring.num)) { 1826 - last_used -= vq->packed.vring.num; 1827 - used_wrap_counter ^= 1; 1828 - } 1829 - 1830 - last_used = (last_used | (used_wrap_counter << VRING_PACKED_EVENT_F_WRAP_CTR)); 1831 - WRITE_ONCE(vq->last_used_idx, last_used); 1832 - 1833 - /* 1834 - * If we expect an interrupt for the next entry, tell host 1835 - * by writing event index and flush out the write before 1836 - * the read in the next get_buf call. 1837 - */ 1838 - if (vq->packed.event_flags_shadow == VRING_PACKED_EVENT_FLAG_DESC) 1839 - virtio_store_mb(vq->weak_barriers, 1840 - &vq->packed.vring.driver->off_wrap, 1841 - cpu_to_le16(vq->last_used_idx)); 1800 + update_last_used_idx_packed(vq, id, last_used, used_wrap_counter); 1842 1801 1843 1802 LAST_ADD_TIME_INVALID(vq); 1844 1803