From nobody Fri Apr 4 06:42:23 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1742030553766474.9271644893706; Sat, 15 Mar 2025 02:22:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ttNcQ-0003DD-W5; Sat, 15 Mar 2025 05:15:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ttNcJ-00031a-M4; Sat, 15 Mar 2025 05:15:39 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ttNcH-00080Z-Nx; Sat, 15 Mar 2025 05:15:39 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id DA114FFBC0; Sat, 15 Mar 2025 12:13:45 +0300 (MSK) Received: from gandalf.tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with ESMTP id E26F41CAD59; Sat, 15 Mar 2025 12:14:39 +0300 (MSK) Received: by gandalf.tls.msk.ru (Postfix, from userid 1000) id B710755A48; Sat, 15 Mar 2025 12:14:39 +0300 (MSK) From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Konstantin Shkolnyy , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Lei Yang , "Michael S . Tsirkin" , Michael Tokarev Subject: [Stable-7.2.17 15/27] vdpa: Fix endian bugs in shadow virtqueue Date: Sat, 15 Mar 2025 12:14:26 +0300 Message-Id: <20250315091439.657371-15-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1742030555263019100 From: Konstantin Shkolnyy VDPA didn't work on a big-endian machine due to missing/incorrect CPU<->LE data format conversions. Signed-off-by: Konstantin Shkolnyy Message-Id: <20250212164923.1971538-1-kshk@linux.ibm.com> Fixes: 10857ec0ad ("vhost: Add VhostShadowVirtqueue") Acked-by: Eugenio P=C3=A9rez Tested-by: Lei Yang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin (cherry picked from commit 50e9754149066dc91f58405d3378b589098cb408) Signed-off-by: Michael Tokarev diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index d422418f2d..20dcc7d2a0 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -165,10 +165,10 @@ static bool vhost_svq_vring_write_descs(VhostShadowVi= rtqueue *svq, hwaddr *sg, descs[i].len =3D cpu_to_le32(iovec[n].iov_len); =20 last =3D i; - i =3D cpu_to_le16(svq->desc_next[i]); + i =3D svq->desc_next[i]; } =20 - svq->free_head =3D le16_to_cpu(svq->desc_next[last]); + svq->free_head =3D svq->desc_next[last]; return true; } =20 @@ -228,10 +228,12 @@ static void vhost_svq_kick(VhostShadowVirtqueue *svq) smp_mb(); =20 if (virtio_vdev_has_feature(svq->vdev, VIRTIO_RING_F_EVENT_IDX)) { - uint16_t avail_event =3D *(uint16_t *)(&svq->vring.used->ring[svq-= >vring.num]); + uint16_t avail_event =3D le16_to_cpu( + *(uint16_t *)(&svq->vring.used->ring[svq->vring.num])); needs_kick =3D vring_need_event(avail_event, svq->shadow_avail_idx= , svq->shadow_avail_idx - 1); } else { - needs_kick =3D !(svq->vring.used->flags & VRING_USED_F_NO_NOTIFY); + needs_kick =3D + !(svq->vring.used->flags & cpu_to_le16(VRING_USED_F_NO_NOT= IFY)); } =20 if (!needs_kick) { @@ -365,7 +367,7 @@ static bool vhost_svq_more_used(VhostShadowVirtqueue *s= vq) return true; } =20 - svq->shadow_used_idx =3D cpu_to_le16(*(volatile uint16_t *)used_idx); + svq->shadow_used_idx =3D le16_to_cpu(*(volatile uint16_t *)used_idx); =20 return svq->last_used_idx !=3D svq->shadow_used_idx; } @@ -383,7 +385,7 @@ static bool vhost_svq_enable_notification(VhostShadowVi= rtqueue *svq) { if (virtio_vdev_has_feature(svq->vdev, VIRTIO_RING_F_EVENT_IDX)) { uint16_t *used_event =3D (uint16_t *)&svq->vring.avail->ring[svq->= vring.num]; - *used_event =3D svq->shadow_used_idx; + *used_event =3D cpu_to_le16(svq->shadow_used_idx); } else { svq->vring.avail->flags &=3D ~cpu_to_le16(VRING_AVAIL_F_NO_INTERRU= PT); } @@ -408,7 +410,7 @@ static uint16_t vhost_svq_last_desc_of_chain(const Vhos= tShadowVirtqueue *svq, uint16_t num, uint16_t i) { for (uint16_t j =3D 0; j < (num - 1); ++j) { - i =3D le16_to_cpu(svq->desc_next[i]); + i =3D svq->desc_next[i]; } =20 return i; @@ -670,7 +672,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, svq->desc_state =3D g_new0(SVQDescState, svq->vring.num); svq->desc_next =3D g_new0(uint16_t, svq->vring.num); for (unsigned i =3D 0; i < svq->vring.num - 1; i++) { - svq->desc_next[i] =3D cpu_to_le16(i + 1); + svq->desc_next[i] =3D i + 1; } } =20 --=20 2.39.5