From nobody Fri Apr 26 16:14:51 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=intel.com Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1638843474258141.15562223382483; Mon, 6 Dec 2021 18:17:54 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 83B5D16E3D78; Tue, 7 Dec 2021 02:17:47 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 90D0816E3D70 for ; Tue, 7 Dec 2021 02:16:25 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2021 18:16:25 -0800 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by orsmga001.jf.intel.com with ESMTP; 06 Dec 2021 18:16:23 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10190"; a="236205220" X-IronPort-AV: E=Sophos;i="5.87,293,1631602800"; d="scan'208";a="236205220" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,293,1631602800"; d="scan'208";a="542632716" From: Andy Pei To: seabios@seabios.org Date: Tue, 7 Dec 2021 09:31:08 +0800 Message-Id: <1638840668-165774-4-git-send-email-andy.pei@intel.com> In-Reply-To: <1638840668-165774-1-git-send-email-andy.pei@intel.com> References: <1638840668-165774-1-git-send-email-andy.pei@intel.com> Message-ID-Hash: 5KH4W4T3FUQGYACQSYXRLO57YIDVK3JY X-Message-ID-Hash: 5KH4W4T3FUQGYACQSYXRLO57YIDVK3JY X-MailFrom: andy.pei@intel.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: kraxel@redhat.com, andy.pei@intel.com, Ding Limin X-Mailman-Version: 3.3.5rc1 Precedence: list Subject: [SeaBIOS] [PATCH v4 3/3] virtio-blk.: split large IO according to size_max List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1638843475075100001 Content-Type: text/plain; charset="utf-8" if driver reads data larger than VIRTIO_BLK_F_SIZE_MAX, it will cause some issue to the DMA engine. So when upper software wants to read data larger than VIRTIO_BLK_F_SIZE_MAX, virtio-blk driver split one large request into multiple smaller ones. Signed-off-by: Andy Pei Signed-off-by: Ding Limin Reviewed-by: Gerd Hoffmann --- src/hw/virtio-blk.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 82b1d2a..929ba88 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -24,6 +24,11 @@ #include "virtio-ring.h" #include "virtio-blk.h" =20 +#define min(a, b) ({\ + typeof(a) _a =3D a;\ + typeof(b) _b =3D b;\ + _a < _b ? _a : _b; }) + struct virtiodrive_s { struct drive_s drive; struct vring_virtqueue *vq; @@ -82,8 +87,36 @@ virtio_blk_op(struct disk_op_s *op, int write) .length =3D sizeof(status), }, }; + u32 max_io_size =3D + vdrive->drive.max_segment_size * vdrive->drive.max_segments; + u16 blk_num_max; + + if (vdrive->drive.blksize !=3D 0 && max_io_size !=3D 0) + blk_num_max =3D (u16)max_io_size / vdrive->drive.blksize; + else + /* default blk_num_max if hardware doesnot advise a proper value */ + blk_num_max =3D 8; =20 - virtio_blk_op_one_segment(vdrive, write, sg); + if (op->count <=3D blk_num_max) { + virtio_blk_op_one_segment(vdrive, write, sg); + } else { + void *p =3D op->buf_fl; + u16 count =3D op->count; + + while (count > 0) { + u16 blk_num =3D min(count, blk_num_max); + sg[1].length =3D vdrive->drive.blksize * blk_num; + sg[1].addr =3D p; + virtio_blk_op_one_segment(vdrive, write, sg); + if (status =3D=3D VIRTIO_BLK_S_OK) { + hdr.sector +=3D blk_num; + p +=3D sg[1].length; + count -=3D blk_num; + } else { + break; + } + } + } return status =3D=3D VIRTIO_BLK_S_OK ? DISK_RET_SUCCESS : DISK_RET_EBA= DTRACK; } =20 --=20 1.8.3.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org