From nobody Mon Dec 8 01:12:29 2025 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 1638511700173755.4869277565414; Thu, 2 Dec 2021 22:08:20 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 8826216E3DB9; Fri, 3 Dec 2021 06:08:16 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 6111916E3D9C for ; Fri, 3 Dec 2021 06:07:36 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2021 22:07:35 -0800 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by orsmga008.jf.intel.com with ESMTP; 02 Dec 2021 22:07:34 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10186"; a="323170597" X-IronPort-AV: E=Sophos;i="5.87,283,1631602800"; d="scan'208";a="323170597" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,283,1631602800"; d="scan'208";a="513576837" From: Andy Pei To: seabios@seabios.org Date: Fri, 3 Dec 2021 13:22:44 +0800 Message-Id: <1638508964-115451-4-git-send-email-andy.pei@intel.com> In-Reply-To: <1638508964-115451-1-git-send-email-andy.pei@intel.com> References: <1638508964-115451-1-git-send-email-andy.pei@intel.com> Message-ID-Hash: NAZT35TYBNS6ME6OZ2GPRJO56JFL2JXN X-Message-ID-Hash: NAZT35TYBNS6ME6OZ2GPRJO56JFL2JXN 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 v3 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: 1638511700700100001 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 --- src/hw/virtio-blk.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 0bc8743..664396c 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -82,8 +82,46 @@ 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; =20 - virtio_blk_op_one_segment(vdrive, write, sg); + 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; + + if (op->count <=3D blk_num_max) { + virtio_blk_op_one_segment(vdrive, write, sg); + } else { + struct vring_list *p_sg =3D &sg[1]; + void *p =3D op->buf_fl; + u16 count =3D op->count; + + while (count > blk_num_max) { + p_sg->addr =3D p; + p_sg->length =3D vdrive->drive.blksize * blk_num_max; + virtio_blk_op_one_segment(vdrive, write, sg); + if (status =3D=3D VIRTIO_BLK_S_OK) { + hdr.sector +=3D blk_num_max; + p +=3D p_sg->length; + count -=3D blk_num_max; + } else { + break; + } + } + + if (status !=3D VIRTIO_BLK_S_OK) + return DISK_RET_EBADTRACK; + + if (count > 0) { + p_sg->addr =3D p; + p_sg->length =3D vdrive->drive.blksize * count; + virtio_blk_op_one_segment(vdrive, write, sg); + } + + } 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