@samitouri / QOSamiQemu / commits / c12bb74fd5

pc-bios/s390-ccw: Refactor byte swapping

Introduce local variables to cache the byte-swapped values eliminating some redundant byte swap operations. Additionally, do byte swap when polling to avoid a special case where endianness is preserved. Reviewed-by: Eric Farman <farman@linux.ibm.com> Signed-off-by: Zhuoying Cai <zycai@linux.ibm.com> Signed-off-by: Jared Rossi <jrossi@linux.ibm.com> Tested-by: Matthew Rosato <mjrosato@linux.ibm.com> Message-ID: <20260630141917.673995-2-jrossi@linux.ibm.com> Signed-off-by: Cornelia Huck <cohuck@redhat.com>

Zhuoying Cai committed Jun 30, 2026 at 10:19 UTC c12bb74fd57f9ec9a90887a79282c24f17690183
1 file changed +12 -12
pc-bios/s390-ccw/virtio.c
+12 -12
@@ -153,14 +153,14 @@ static void vr_bswap_descriptor(VRingDesc *desc)
153
154 void vring_send_buf(VRing *vr, void *p, int len, int flags)
155 {
156 - if (!be_ipl()) {
157 - vr->avail->idx = bswap16(vr->avail->idx);
158 - }
156 + uint16_t avail_idx;
157 +
158 + avail_idx = be_ipl() ? vr->avail->idx : bswap16(vr->avail->idx);
159
160 /* For follow-up chains we need to keep the first entry point */
161 if (!(flags & VRING_HIDDEN_IS_CHAIN)) {
162 - vr->avail->ring[vr->avail->idx % vr->num] = be_ipl() ? vr->next_idx :
163 - bswap16(vr->next_idx);
162 + vr->avail->ring[avail_idx % vr->num] = be_ipl() ? vr->next_idx :
163 + bswap16(vr->next_idx);
164 }
165
166 vr->desc[vr->next_idx].addr = (unsigned long)p;
@@ -177,23 +177,23 @@ void vring_send_buf(VRing *vr, void *p, int len, int flags)
177
178 /* Chains only have a single ID */
179 if (!(flags & VRING_DESC_F_NEXT)) {
180 - vr->avail->idx++;
181 - }
182 -
183 - if (!be_ipl()) {
184 - vr->avail->idx = bswap16(vr->avail->idx);
180 + avail_idx++;
181 + vr->avail->idx = be_ipl() ? avail_idx : bswap16(avail_idx);
182 }
183 }
184
185 int vr_poll(VRing *vr)
186 {
190 - if (vr->used->idx == vr->used_idx) {
187 + uint16_t used_idx;
188 +
189 + used_idx = be_ipl() ? vr->used->idx : bswap16(vr->used->idx);
190 + if (used_idx == vr->used_idx) {
191 vring_notify(vr);
192 yield();
193 return 0;
194 }
195
196 - vr->used_idx = vr->used->idx; /* Endianness is preserved */
196 + vr->used_idx = used_idx;
197 vr->next_idx = 0;
198 vr->desc[0].len = 0;
199 vr->desc[0].flags = 0;