From nobody Wed Nov 27 13:05:34 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1698675072; cv=none; d=zohomail.com; s=zohoarc; b=QDJhFzF0Po81Ldm7DQFrbakfI4qSuaJp3BBlQpRGk2s5LQrqHmC8fTFua/by9IT0AUvluhjjigIQVslVnfXg2tEMCdPyXQRht7driv2QNzw5etW/mAhjrU2jdrLWkWRAl+Mk5LWOD6YVcCIMvQmQqMjm5uLCX5Es2Uuph74ABTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698675072; 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=4ej8HqBrqmqJvK47VR/LJCVQrkEeTKvpHVeo1Gm1RpM=; b=H6QhHgf4hP8JXg8pZv6n04CBy8HNfX8FTs5zhRfoCUNxeF22y3At4Rl+RQR/qdSP9FKHcCqlN/TLjpOd7awWkt2CXRVYszsB9XUy9eWEltsQLNWGbIphEmepE75ES904ByaUyeEc3+2irS47SN22XAcq5zo8fn/GCdfBaMnhOPo= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1698675072906528.082927995389; Mon, 30 Oct 2023 07:11:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxSyP-0006Or-Ba; Mon, 30 Oct 2023 10:10:34 -0400 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 1qxMs2-0002nP-Kx; Mon, 30 Oct 2023 03:39:34 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxMs1-0003Ub-03; Mon, 30 Oct 2023 03:39:34 -0400 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-280200949c3so1178187a91.0; Mon, 30 Oct 2023 00:39:31 -0700 (PDT) Received: from localhost (fp96936df3.ap.nuro.jp. [150.147.109.243]) by smtp.gmail.com with ESMTPSA id g23-20020a1709029f9700b001cc5225c220sm842969plq.15.2023.10.30.00.39.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 00:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698651570; x=1699256370; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4ej8HqBrqmqJvK47VR/LJCVQrkEeTKvpHVeo1Gm1RpM=; b=k7TJ3Q/gUfcPcdoh+/8v90PlsxDGQomvb1QLWWHGb/oOyOUmxFMQmYXq6CP6B1MIvU scYp7u9hKxLW18F7bx+eGKaBAWsDVSfvRMwH5n0sNzp7V0xzPO3tqluOG0JYmwLPMyWz 0CqP6zjEHK52lkX42U5TaT+ayVZgXvXdPhptk5Xuw8KEzpIvrqE0DqjErFQhZv1IiR9N zxO9K0P77xqVDQkjxZqjPajjfFMVWpGrn+pKuJQru66gm+j6lCVXOp+Uj82/uLYoDSPO APjH//lFn3qERiP/3ejs4Dpc0Po0w4K6YtztZOgAi+tyAt0hkvU//nwmFeXV4Z7eYYNq DiYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698651570; x=1699256370; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4ej8HqBrqmqJvK47VR/LJCVQrkEeTKvpHVeo1Gm1RpM=; b=wZWUs6FfLxTOFcC1u0RxNTSMpOW10Oy7cv9T9ePioVrMb9kVzKNUJYJYXpjpp3wo5l AnbEKpSUYPOnI8v4gywptNfJD20uB0q9mz09raVqE6sqH7aWAdO3QOCQtdw4aV9vc1Md Xzt9Hr3EFrmF9ZN7GdX3mgn7EmKv6HhO109zLZzXCffq8RXs25JzFzkdW5TKTlQr1N03 xSKxFbOax1PRLebvlYclCPmtzydMOkG4hPdY8N1SvPMPju7//+jJ55du+XdR6OyP0u1I w6031x3X8+yykTtukUhGBymasuQpsZ9g4ULKHab23XZEByQvRJOHEXfSuujqy33Ebl8l In0A== X-Gm-Message-State: AOJu0YyX8IMqEZ4d/mumKzPJdRGN41YcCy3sGqYnfyY3bLdiKIkx/oHE nyy5DT5yKTwjN8guLGk5qYOxkCFhWGEc4A== X-Google-Smtp-Source: AGHT+IFPR+ikqIofQWllgPafRWxqdmGhPJ9CkIkZu7GixloQ4YZH1CCa/10Urg+Eaq8IQbTg4pSjNg== X-Received: by 2002:a17:90a:3cc7:b0:27d:546b:4258 with SMTP id k7-20020a17090a3cc700b0027d546b4258mr6186199pjd.31.1698651570084; Mon, 30 Oct 2023 00:39:30 -0700 (PDT) From: Naohiro Aota X-Google-Original-From: Naohiro Aota To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Kevin Wolf , Hanna Reitz , Sam Li , Stefan Hajnoczi , Damien Le Moal , Naohiro Aota Subject: [PATCH] file-posix: fix over-writing of returning zone_append offset Date: Mon, 30 Oct 2023 16:38:53 +0900 Message-ID: <20231030073853.2601162-1-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::1035; envelope-from=nao.aota@gmail.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 30 Oct 2023 10:10:16 -0400 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 @gmail.com) X-ZM-MESSAGEID: 1698675073879100002 Content-Type: text/plain; charset="utf-8" raw_co_zone_append() sets "s->offset" where "BDRVRawState *s". This pointer is used later at raw_co_prw() to save the block address where the data is written. When multiple IOs are on-going at the same time, a later IO's raw_co_zone_append() call over-writes a former IO's offset address before raw_co_prw() completes. As a result, the former zone append IO returns the initial value (=3D the start address of the writing zone), instead of the proper address. Fix the issue by passing the offset pointer to raw_co_prw() instead of passing it through s->offset. Also, remove "offset" from BDRVRawState as there is no usage anymore. Fixes: 4751d09adcc3 ("block: introduce zone append write for zoned devices") Signed-off-by: Naohiro Aota Reviewed-by: Sam Li Reviewed-by: Stefan Hajnoczi --- block/file-posix.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 50e2b20d5c45..c39209358909 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -160,7 +160,6 @@ typedef struct BDRVRawState { bool has_write_zeroes:1; bool use_linux_aio:1; bool use_linux_io_uring:1; - int64_t *offset; /* offset of zone append operation */ int page_cache_inconsistent; /* errno from fdatasync failure */ bool has_fallocate; bool needs_alignment; @@ -2445,12 +2444,13 @@ static bool bdrv_qiov_is_aligned(BlockDriverState *= bs, QEMUIOVector *qiov) return true; } =20 -static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset, +static int coroutine_fn raw_co_prw(BlockDriverState *bs, int64_t *offset_p= tr, uint64_t bytes, QEMUIOVector *qiov, int= type) { BDRVRawState *s =3D bs->opaque; RawPosixAIOData acb; int ret; + uint64_t offset =3D *offset_ptr; =20 if (fd_open(bs) < 0) return -EIO; @@ -2513,8 +2513,8 @@ out: uint64_t *wp =3D &wps->wp[offset / bs->bl.zone_size]; if (!BDRV_ZT_IS_CONV(*wp)) { if (type & QEMU_AIO_ZONE_APPEND) { - *s->offset =3D *wp; - trace_zbd_zone_append_complete(bs, *s->offset + *offset_ptr =3D *wp; + trace_zbd_zone_append_complete(bs, *offset_ptr >> BDRV_SECTOR_BITS); } /* Advance the wp if needed */ @@ -2536,14 +2536,14 @@ static int coroutine_fn raw_co_preadv(BlockDriverSt= ate *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { - return raw_co_prw(bs, offset, bytes, qiov, QEMU_AIO_READ); + return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_READ); } =20 static int coroutine_fn raw_co_pwritev(BlockDriverState *bs, int64_t offse= t, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { - return raw_co_prw(bs, offset, bytes, qiov, QEMU_AIO_WRITE); + return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_WRITE); } =20 static int coroutine_fn raw_co_flush_to_disk(BlockDriverState *bs) @@ -3506,8 +3506,6 @@ static int coroutine_fn raw_co_zone_append(BlockDrive= rState *bs, int64_t zone_size_mask =3D bs->bl.zone_size - 1; int64_t iov_len =3D 0; int64_t len =3D 0; - BDRVRawState *s =3D bs->opaque; - s->offset =3D offset; =20 if (*offset & zone_size_mask) { error_report("sector offset %" PRId64 " is not aligned to zone siz= e " @@ -3528,7 +3526,7 @@ static int coroutine_fn raw_co_zone_append(BlockDrive= rState *bs, } =20 trace_zbd_zone_append(bs, *offset >> BDRV_SECTOR_BITS); - return raw_co_prw(bs, *offset, len, qiov, QEMU_AIO_ZONE_APPEND); + return raw_co_prw(bs, offset, len, qiov, QEMU_AIO_ZONE_APPEND); } #endif =20 --=20 2.42.0