From nobody Fri Apr 26 04:16:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=linux.alibaba.com Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1668398342704636.9219797097556; Sun, 13 Nov 2022 19:59:02 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id EABF022852; Mon, 14 Nov 2022 03:58:55 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id D29C52208B for ; Mon, 14 Nov 2022 03:58:31 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.aliyun-inc.com; Mon, 14 Nov 2022 11:58:21 +0800 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R831e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VUgGmq7_1668398300; From: Xuan Zhuo To: seabios@seabios.org Date: Mon, 14 Nov 2022 11:58:17 +0800 Message-Id: <20221114035818.109511-2-xuanzhuo@linux.alibaba.com> In-Reply-To: <20221114035818.109511-1-xuanzhuo@linux.alibaba.com> References: <20221114035818.109511-1-xuanzhuo@linux.alibaba.com> MIME-Version: 1.0 X-Git-Hash: 73ebbf4 Message-ID-Hash: BYOCH5VIV5R26FXCQSPVRRPFF33F7MBI X-Message-ID-Hash: BYOCH5VIV5R26FXCQSPVRRPFF33F7MBI X-MailFrom: xuanzhuo@linux.alibaba.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: lersek@redhat.com, jasowang@redhat.com, peter.maydell@linaro.org, kraxel@redhat.com, "Michael S. Tsirkin" X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [SeaBIOS] [PATCH v1 1/2] virtio-mmio: read/write the hi 32 features for mmio List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: --- X-ZM-MESSAGEID: 1668398342946100001 Content-Type: text/plain; charset="utf-8" Under mmio, when we read the feature from the device, we should read the high 32-bit part. Similarly, when writing the feature back, we should also write back the high 32-bit feature. Signed-off-by: Xuan Zhuo Acked-by: Michael S. Tsirkin --- src/hw/virtio-pci.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hw/virtio-pci.c b/src/hw/virtio-pci.c index 213c497..89a4f50 100644 --- a/src/hw/virtio-pci.c +++ b/src/hw/virtio-pci.c @@ -193,7 +193,8 @@ u64 vp_get_features(struct vp_device *vp) if (vp->use_mmio) { vp_write(&vp->common, virtio_mmio_cfg, device_feature_select, 0); f0 =3D vp_read(&vp->common, virtio_mmio_cfg, device_feature); - f1 =3D 0; + vp_write(&vp->common, virtio_mmio_cfg, device_feature_select, 1); + f1 =3D vp_read(&vp->common, virtio_mmio_cfg, device_feature); } else if (vp->use_modern) { vp_write(&vp->common, virtio_pci_common_cfg, device_feature_select= , 0); f0 =3D vp_read(&vp->common, virtio_pci_common_cfg, device_feature); @@ -214,8 +215,10 @@ void vp_set_features(struct vp_device *vp, u64 feature= s) f1 =3D features >> 32; =20 if (vp->use_mmio) { - vp_write(&vp->common, virtio_mmio_cfg, guest_feature_select, f0); + vp_write(&vp->common, virtio_mmio_cfg, guest_feature_select, 0); vp_write(&vp->common, virtio_mmio_cfg, guest_feature, f0); + vp_write(&vp->common, virtio_mmio_cfg, guest_feature_select, 1); + vp_write(&vp->common, virtio_mmio_cfg, guest_feature, f1); } else if (vp->use_modern) { vp_write(&vp->common, virtio_pci_common_cfg, guest_feature_select,= 0); vp_write(&vp->common, virtio_pci_common_cfg, guest_feature, f0); --=20 2.32.0.3.g01195cf9f _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Fri Apr 26 04:16:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=linux.alibaba.com Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1668398355923661.2427445926811; Sun, 13 Nov 2022 19:59:15 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id C323322BD9; Mon, 14 Nov 2022 03:59:10 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 579222208B for ; Mon, 14 Nov 2022 03:58:33 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.aliyun-inc.com; Mon, 14 Nov 2022 11:58:22 +0800 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R281e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VUgGmqw_1668398301; From: Xuan Zhuo To: seabios@seabios.org Date: Mon, 14 Nov 2022 11:58:18 +0800 Message-Id: <20221114035818.109511-3-xuanzhuo@linux.alibaba.com> In-Reply-To: <20221114035818.109511-1-xuanzhuo@linux.alibaba.com> References: <20221114035818.109511-1-xuanzhuo@linux.alibaba.com> MIME-Version: 1.0 X-Git-Hash: 73ebbf4 Message-ID-Hash: RHPETJ5V3B6D2YYH3MAW2FOKAGU777GW X-Message-ID-Hash: RHPETJ5V3B6D2YYH3MAW2FOKAGU777GW X-MailFrom: xuanzhuo@linux.alibaba.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: lersek@redhat.com, jasowang@redhat.com, peter.maydell@linaro.org, kraxel@redhat.com, "Michael S. Tsirkin" X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [SeaBIOS] [PATCH v1 2/2] virtio: finalize features before using device List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: --- X-ZM-MESSAGEID: 1668398356940100001 Content-Type: text/plain; charset="utf-8" Under the standard of Virtio 1.0, the initialization process of the device must first write sub-features back to device before using device, such as finding vqs. There are four places using vp_find_vq(). 1. virtio-blk.pci: put the code of finalizing features in front of using= device 2. virtio-blk.mmio: put the code of finalizing features in front of using= device 3. virtio-scsi.pci: is ok 4. virtio-scsi.mmio: add the code of finalizing features before vp_find_vq= () Link: https://www.mail-archive.com/qemu-devel@nongnu.org/msg920776.html Signed-off-by: Xuan Zhuo Acked-by: Michael S. Tsirkin Reviewed-by: Gerd Hoffmann --- src/hw/virtio-blk.c | 22 +++++++++++++--------- src/hw/virtio-scsi.c | 13 +++++++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 9b4a05a..ab6e79b 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -151,10 +151,6 @@ init_virtio_blk(void *data) vdrive->drive.cntl_id =3D pci->bdf; =20 vp_init_simple(&vdrive->vp, pci); - if (vp_find_vq(&vdrive->vp, 0, &vdrive->vq) < 0 ) { - dprintf(1, "fail to find vq for virtio-blk %pP\n", pci); - goto fail; - } =20 if (vdrive->vp.use_modern) { struct vp_device *vp =3D &vdrive->vp; @@ -212,7 +208,14 @@ init_virtio_blk(void *data) vp_read(&vp->device, struct virtio_blk_config, heads); vdrive->drive.pchs.sector =3D vp_read(&vp->device, struct virtio_blk_config, sectors); - } else { + } + + if (vp_find_vq(&vdrive->vp, 0, &vdrive->vq) < 0 ) { + dprintf(1, "fail to find vq for virtio-blk %pP\n", pci); + goto fail; + } + + if (!vdrive->vp.use_modern) { struct virtio_blk_config cfg; vp_get_legacy(&vdrive->vp, 0, &cfg, sizeof(cfg)); =20 @@ -272,10 +275,6 @@ init_virtio_blk_mmio(void *mmio) vdrive->drive.cntl_id =3D (u32)mmio; =20 vp_init_mmio(&vdrive->vp, mmio); - if (vp_find_vq(&vdrive->vp, 0, &vdrive->vq) < 0 ) { - dprintf(1, "fail to find vq for virtio-blk-mmio %p\n", mmio); - goto fail; - } =20 struct vp_device *vp =3D &vdrive->vp; u64 features =3D vp_get_features(vp); @@ -294,6 +293,11 @@ init_virtio_blk_mmio(void *mmio) goto fail; } =20 + if (vp_find_vq(&vdrive->vp, 0, &vdrive->vq) < 0 ) { + dprintf(1, "fail to find vq for virtio-blk-mmio %p\n", mmio); + goto fail; + } + if (features & max_segment_size) vdrive->drive.max_segment_size =3D vp_read(&vp->device, struct virtio_blk_config, size_max); diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index 369c981..79bda0b 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -239,6 +239,19 @@ init_virtio_scsi_mmio(void *mmio) vp_init_mmio(vp, mmio); u8 status =3D VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER; =20 + u64 features =3D vp_get_features(vp); + u64 version1 =3D 1ull << VIRTIO_F_VERSION_1; + if (features & version1) { + u64 iommu_platform =3D 1ull << VIRTIO_F_IOMMU_PLATFORM; + + vp_set_features(vp, features & (version1 | iommu_platform)); + vp_set_status(vp, VIRTIO_CONFIG_S_FEATURES_OK); + if (!(vp_get_status(vp) & VIRTIO_CONFIG_S_FEATURES_OK)) { + dprintf(1, "device didn't accept features: %pP\n", mmio); + goto fail; + } + } + if (vp_find_vq(vp, 2, &vq) < 0 ) { dprintf(1, "fail to find vq for virtio-scsi-mmio %p\n", mmio); goto fail; --=20 2.32.0.3.g01195cf9f _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org