From nobody Fri Apr 4 21:20:21 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1739379024; cv=none; d=zohomail.com; s=zohoarc; b=XmF10XLcSOmzjYLO6rax9RC0mgulirktCVtbJFRmCpz1+1MMOW/2XBH6ijULQfGlCsfsECGCcWqqmx5Xzmeh2vdxV6G8c/1PlSrm1CHhBo6lv4p8L5t+KiL0xEQNpscvUXUgFnlCPc2IYhQxCC8+U8LmbhfPYMZzwHLDHPHGfDM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739379024; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kAw+mTasQsiVtApU5TkW6YM2hvy+ebRCq1yUN4WdWL0=; b=j/+YLYpk3o9Ii5/j0k2y1m60nqo9mPoUncqwt4i0GPhzWpZo8hs07gpdj6vJjNgskgx3gh3KMyqMBVCFv5KhfHRqQv5wXbEot2lBoSUS//4fOpfOnI+WXHgtEh4GBY4qFg/s3sUqbm0N3Vqc3atbWUpx7FtGcF2pljned62QTU0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1739379024618827.5834986247288; Wed, 12 Feb 2025 08:50:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tiFvx-0004Of-DO; Wed, 12 Feb 2025 11:50:00 -0500 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 1tiFvr-0004NX-10 for qemu-devel@nongnu.org; Wed, 12 Feb 2025 11:49:51 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tiFvp-0004RD-7c for qemu-devel@nongnu.org; Wed, 12 Feb 2025 11:49:50 -0500 Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51CBQgH9013867; Wed, 12 Feb 2025 16:49:47 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 44rjfyv7ef-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2025 16:49:46 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 51CFi4FS000914; Wed, 12 Feb 2025 16:49:46 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([172.16.1.5]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 44pjkn9uhx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2025 16:49:46 +0000 Received: from smtpav02.dal12v.mail.ibm.com (smtpav02.dal12v.mail.ibm.com [10.241.53.101]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 51CGnjqq19071738 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Feb 2025 16:49:45 GMT Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F2B295805C; Wed, 12 Feb 2025 16:49:44 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BB9B35805E; Wed, 12 Feb 2025 16:49:44 +0000 (GMT) Received: from WIN-DU0DFC9G5VV.austin.ibm.com (unknown [9.41.104.243]) by smtpav02.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 12 Feb 2025 16:49:44 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pp1; bh=kAw+mTasQsiVtApU5TkW6YM2hvy+ebRCq1yUN4WdW L0=; b=KYQBIerQ6bieEUahh0QR7slOPZQXaE9b2QptOb0cEetDCOeCxwBuhm40a nASabAHxlMsfMg5eVk9PaT9OjKEvQzeNjr0aSzGj/oLA5VK+AOPTiHq89dk3qmi7 Of+spOZGyeSs3UNT5Lmitaut19gdwflE1AjMJJ1NcVcNQesKXpDeDNbt5VHYDqeO cNtqcs5iwyTWCc9xVB49v0VHYEA/M6YhdTgHCAzevHq5sRxW6FpJy9RqKIpOt5Mq rGAWhiZ0nX/A3B9SGLVeCUCoJetZ8ItAvLAwm6veufSrL7XJnJBSuLqWC2yRI0O7 jUEsRDohQNGwsvt807+ltWpHj63Xg== From: Konstantin Shkolnyy To: eperezma@redhat.com Cc: mst@redhat.com, sgarzare@redhat.com, mjrosato@linux.ibm.com, qemu-devel@nongnu.org, Konstantin Shkolnyy Subject: [PATCH v2] vdpa: Fix endian bugs in shadow virtqueue Date: Wed, 12 Feb 2025 10:49:23 -0600 Message-Id: <20250212164923.1971538-1-kshk@linux.ibm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: B2EIMEAPs2Bm85WTD_hNtlwtZ3JsZT-A X-Proofpoint-ORIG-GUID: B2EIMEAPs2Bm85WTD_hNtlwtZ3JsZT-A X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-12_05,2025-02-11_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 mlxscore=0 suspectscore=0 adultscore=0 clxscore=1015 mlxlogscore=574 lowpriorityscore=0 priorityscore=1501 phishscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2502120122 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=148.163.158.5; envelope-from=kshk@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, 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-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1739379027648019100 Content-Type: text/plain; charset="utf-8" VDPA didn't work on a big-endian machine due to missing/incorrect CPU<->LE data format conversions. Signed-off-by: Konstantin Shkolnyy Acked-by: Eugenio P=C3=A9rez Tested-by: Lei Yang --- Changes in v2: Change desc_next[] from LE format to "CPU". hw/virtio/vhost-shadow-virtqueue.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 37aca8b431..4af0d7c669 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; @@ -683,7 +685,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.34.1