From nobody Thu May 2 02:39:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 1553708095861247.51626045946614; Wed, 27 Mar 2019 10:34:55 -0700 (PDT) Received: from localhost ([127.0.0.1]:51332 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9CRv-0003VG-KI for importer@patchew.org; Wed, 27 Mar 2019 13:34:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47276) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9CPV-0001so-2z for qemu-devel@nongnu.org; Wed, 27 Mar 2019 13:32:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9CPT-0000Fo-Ow for qemu-devel@nongnu.org; Wed, 27 Mar 2019 13:32:21 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:52218) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9CPQ-00007j-IV; Wed, 27 Mar 2019 13:32:16 -0400 X-IronPort-AV: E=Sophos;i="5.60,277,1549929600"; d="scan'208";a="81999350" From: Paul Durrant To: , , Date: Wed, 27 Mar 2019 17:32:05 +0000 Message-ID: <20190327173206.9065-2-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb6 In-Reply-To: <20190327173206.9065-1-paul.durrant@citrix.com> References: <20190327173206.9065-1-paul.durrant@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PATCH v2 1/2] xen-block: scale sector based quantities correctly X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefano Stabellini , Max Reitz , Paul Durrant , Stefan Hajnoczi , Anthony Perard Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The Xen blkif protocol requires that sector based quantities should be interpreted strictly as multiples of 512 bytes. Specifically: "first_sect and last_sect in blkif_request_segment, as well as sector_number in blkif_request, are always expressed in 512-byte units." This patch modifies the xen-block code accordingly. Signed-off-by: Paul Durrant --- Cc: Stefan Hajnoczi Cc: Stefano Stabellini Cc: Anthony Perard Cc: Kevin Wolf Cc: Max Reitz --- hw/block/dataplane/xen-block.c | 28 +++++++++++++--------------- hw/block/xen_blkif.h | 2 ++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index f1523c5b45..bb8f1186e4 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -49,7 +49,6 @@ struct XenBlockDataPlane { unsigned int *ring_ref; unsigned int nr_ring_ref; void *sring; - int64_t file_blk; int protocol; blkif_back_rings_t rings; int more_work; @@ -168,7 +167,7 @@ static int xen_block_parse_request(XenBlockRequest *req= uest) goto err; } =20 - request->start =3D request->req.sector_number * dataplane->file_blk; + request->start =3D request->req.sector_number * XEN_BLKIF_SECTOR_SIZE; for (i =3D 0; i < request->req.nr_segments; i++) { if (i =3D=3D BLKIF_MAX_SEGMENTS_PER_REQUEST) { error_report("error: nr_segments too big"); @@ -178,14 +177,14 @@ static int xen_block_parse_request(XenBlockRequest *r= equest) error_report("error: first > last sector"); goto err; } - if (request->req.seg[i].last_sect * dataplane->file_blk >=3D + if (request->req.seg[i].last_sect * XEN_BLKIF_SECTOR_SIZE >=3D XC_PAGE_SIZE) { error_report("error: page crossing"); goto err; } =20 len =3D (request->req.seg[i].last_sect - - request->req.seg[i].first_sect + 1) * dataplane->file_blk; + request->req.seg[i].first_sect + 1) * XEN_BLKIF_SECTOR_SIZE; request->size +=3D len; } if (request->start + request->size > blk_getlength(dataplane->blk)) { @@ -205,7 +204,6 @@ static int xen_block_copy_request(XenBlockRequest *requ= est) XenDevice *xendev =3D dataplane->xendev; XenDeviceGrantCopySegment segs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; int i, count; - int64_t file_blk =3D dataplane->file_blk; bool to_domain =3D (request->req.operation =3D=3D BLKIF_OP_READ); void *virt =3D request->buf; Error *local_err =3D NULL; @@ -220,16 +218,17 @@ static int xen_block_copy_request(XenBlockRequest *re= quest) if (to_domain) { segs[i].dest.foreign.ref =3D request->req.seg[i].gref; segs[i].dest.foreign.offset =3D request->req.seg[i].first_sect= * - file_blk; + XEN_BLKIF_SECTOR_SIZE; segs[i].source.virt =3D virt; } else { segs[i].source.foreign.ref =3D request->req.seg[i].gref; segs[i].source.foreign.offset =3D request->req.seg[i].first_se= ct * - file_blk; + XEN_BLKIF_SECTOR_SIZE; segs[i].dest.virt =3D virt; } segs[i].len =3D (request->req.seg[i].last_sect - - request->req.seg[i].first_sect + 1) * file_blk; + request->req.seg[i].first_sect + 1) * + XEN_BLKIF_SECTOR_SIZE; virt +=3D segs[i].len; } =20 @@ -331,22 +330,22 @@ static bool xen_block_split_discard(XenBlockRequest *= request, XenBlockDataPlane *dataplane =3D request->dataplane; int64_t byte_offset; int byte_chunk; - uint64_t byte_remaining, limit; + uint64_t byte_remaining; uint64_t sec_start =3D sector_number; uint64_t sec_count =3D nr_sectors; =20 /* Wrap around, or overflowing byte limit? */ if (sec_start + sec_count < sec_count || - sec_start + sec_count > INT64_MAX / dataplane->file_blk) { + sec_start + sec_count > INT64_MAX / XEN_BLKIF_SECTOR_SIZE) { return false; } =20 - limit =3D BDRV_REQUEST_MAX_SECTORS * dataplane->file_blk; - byte_offset =3D sec_start * dataplane->file_blk; - byte_remaining =3D sec_count * dataplane->file_blk; + byte_offset =3D sec_start * XEN_BLKIF_SECTOR_SIZE; + byte_remaining =3D sec_count * XEN_BLKIF_SECTOR_SIZE; =20 do { - byte_chunk =3D byte_remaining > limit ? limit : byte_remaining; + byte_chunk =3D byte_remaining > BDRV_REQUEST_MAX_BYTES ? + BDRV_REQUEST_MAX_BYTES : byte_remaining; request->aio_inflight++; blk_aio_pdiscard(dataplane->blk, byte_offset, byte_chunk, xen_block_complete_aio, request); @@ -632,7 +631,6 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevice= *xendev, XenBlockDataPlane *dataplane =3D g_new0(XenBlockDataPlane, 1); =20 dataplane->xendev =3D xendev; - dataplane->file_blk =3D conf->logical_block_size; dataplane->blk =3D conf->blk; =20 QLIST_INIT(&dataplane->inflight); diff --git a/hw/block/xen_blkif.h b/hw/block/xen_blkif.h index 3e6e1ea365..a353693ea0 100644 --- a/hw/block/xen_blkif.h +++ b/hw/block/xen_blkif.h @@ -143,4 +143,6 @@ static inline void blkif_get_x86_64_req(blkif_request_t= *dst, } } =20 +#define XEN_BLKIF_SECTOR_SIZE 512 + #endif /* XEN_BLKIF_H */ --=20 2.20.1.2.gb21ebb6 From nobody Thu May 2 02:39:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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 1553708085609260.13032184314864; Wed, 27 Mar 2019 10:34:45 -0700 (PDT) Received: from localhost ([127.0.0.1]:51330 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9CRf-0003DZ-CK for importer@patchew.org; Wed, 27 Mar 2019 13:34:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47273) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9CPU-0001sV-QA for qemu-devel@nongnu.org; Wed, 27 Mar 2019 13:32:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9CPT-0000Fe-MS for qemu-devel@nongnu.org; Wed, 27 Mar 2019 13:32:20 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:52218) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9CPP-00007j-KX; Wed, 27 Mar 2019 13:32:15 -0400 X-IronPort-AV: E=Sophos;i="5.60,277,1549929600"; d="scan'208";a="81999313" From: Paul Durrant To: , , Date: Wed, 27 Mar 2019 17:32:06 +0000 Message-ID: <20190327173206.9065-3-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb6 In-Reply-To: <20190327173206.9065-1-paul.durrant@citrix.com> References: <20190327173206.9065-1-paul.durrant@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PATCH v2 2/2] xen-block: always report 'sectors' in terms of 512-byte units X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anthony Perard , Kevin Wolf , Paul Durrant , Stefano Stabellini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The mail thread at [1] clarifies that the Xen blkif protocol requires that 'sectors' value reported in xenstore is strictly in terms of 512-byte units and is not dependent on the logical sector size reported in 'sector-size'. [1] https://lists.xenproject.org/archives/html/xen-devel/2019-03/msg01600.h= tml Signed-off-by: Paul Durrant --- Cc: Stefano Stabellini Cc: Anthony Perard Cc: Kevin Wolf Cc: Max Reitz --- hw/block/xen-block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index a848849f48..57e9da7e1c 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -149,7 +149,7 @@ static void xen_block_set_size(XenBlockDevice *blockdev) const char *type =3D object_get_typename(OBJECT(blockdev)); XenBlockVdev *vdev =3D &blockdev->props.vdev; BlockConf *conf =3D &blockdev->props.conf; - int64_t sectors =3D blk_getlength(conf->blk) / conf->logical_block_siz= e; + int64_t sectors =3D blk_getlength(conf->blk) / XEN_BLKIF_SECTOR_SIZE; XenDevice *xendev =3D XEN_DEVICE(blockdev); =20 trace_xen_block_size(type, vdev->disk, vdev->partition, sectors); --=20 2.20.1.2.gb21ebb6