From nobody Tue May 21 02:46:43 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578495479; cv=none; d=zohomail.com; s=zohoarc; b=Wune9lcRvwqpmg4HZvUF+o3Nj/SOKWiIjW9hSN/5SvZKbnf/k7HqYo1au6dvHvzbCB6cWzjtrJh0ZcjwNTgXQvaHCflkJdCyH7bzRaAb6/rRGsk2RuAMwSIdRCnGVKw2EYp/q4txq02pOSQuPYZgsUlKmtxi2IJET8HZBbw9aiA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578495479; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=thqT8r9CcCG0T97Pz3DNSEuib2QMsHHphXqr+0a7uqc=; b=S6Vyw0dkLS6wNhBEh8GjOv66gcMv2NPk8Orxze58vgs/99xz0sCQJAxfrtJsYn1Yv3KdCeDuXBl/Nyy2eKEHXWSyTUrxPVnNpeZEAODSu/hCfk8/X0IruBzdu3YszbfIGIrWsE+eQ2wQ1lSlEznhHcn2yXi+fxuPRFVi1Kr6ooE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157849547944221.503787395830614; Wed, 8 Jan 2020 06:57:59 -0800 (PST) Received: from localhost ([::1]:45138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCmT-0006if-Ii for importer@patchew.org; Wed, 08 Jan 2020 09:57:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40338) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCkc-0004an-7t for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:56:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipCkb-0005QA-0D for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:56:02 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36028) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ipCka-0005Oy-PS; Wed, 08 Jan 2020 09:56:00 -0500 Received: by mail-wr1-x443.google.com with SMTP id z3so3726941wru.3; Wed, 08 Jan 2020 06:56:00 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id g21sm4703529wrb.48.2020.01.08.06.55.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jan 2020 06:55:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=thqT8r9CcCG0T97Pz3DNSEuib2QMsHHphXqr+0a7uqc=; b=sbzQRY0KNmus5MMY6Rfoc+hLGOKn833YTEy+YoktzfgkZO5UnD8l0Yor8M0/rmjd9U F3apNtOHlaLPeTStQ8kwJyp7/UB25W0CI3nxeQLAbSc/87zY5j8dVjXPwgATwK4BuH4O G9hgtGDtylzSq3WdIMzaXnwgQ1DUcugsvhpQtzclJCtRscr2G+xgsySuC7sw3b+mDKIo 1pvX/hN/csYFhp/EvvVo9yQWgbRpdc2jiVbunYMK5LoTndQk7tvsBtG7ja+Y2FLWrPDB sIxedMpp/BxeJZvRwTg4miqrfhwhaqfghaW9OEBmMjns+MpFZ217U514oSPcrwvTHvln RNGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=thqT8r9CcCG0T97Pz3DNSEuib2QMsHHphXqr+0a7uqc=; b=ZFgi0cvHGXwd/hUhM3UZiKbciyvxjJu0u9erGceTzwdAMQk1yNkbVLPDURVYnV6u9D +55TVjnfdHGol8bh37YtJ0V5TH5R0x7lzRrHW8lBywuXk7pCaSLmAHr90WOsOQt8kOIl QfacNqD7UNr85NAjZBfEjsR9nwR2H98nsV3iOYL7Xy9Ut9oTOs5ddc94DkGK2lZSSCKz z+5UVmjRiSArrQwh5idXxBfiTGxKZHfYzpawHFnbHaSiMVmfMn/MPAwJjXzA1xR8XPEO p4YLYEorMYua5YvocX3ce4xz0XzZF3g21/eSidRxp0mb7WZ6n/PDECasxHQ4F+27AkGF AObg== X-Gm-Message-State: APjAAAWJpV0iubizuWQDcH03i6K6g9KCTTzVGTOsgIb6lMpU4QR0TaZN Cd2OATzRyQYK4A7FhaptCw+W5LFj X-Google-Smtp-Source: APXvYqwYg19dCC2FKaE1SnWdS2WrqK/9J5So61rrvTzpqM6ZguMFTANHBLVeA/UUrEFxVS/Zgo06Hw== X-Received: by 2002:adf:e609:: with SMTP id p9mr4800868wrm.397.1578495359357; Wed, 08 Jan 2020 06:55:59 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 1/3] block: eliminate BDRV_REQ_NO_SERIALISING Date: Wed, 8 Jan 2020 15:55:54 +0100 Message-Id: <1578495356-46219-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1578495356-46219-1-git-send-email-pbonzini@redhat.com> References: <1578495356-46219-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It is unused since commit 00e30f0 ("block/backup: use backup-top instead of write notifiers", 2019-10-01), drop it to simplify the code. While at it, drop redundant assertions on flags. Signed-off-by: Paolo Bonzini --- block/io.c | 18 ++++-------------- include/block/block.h | 12 ------------ 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/block/io.c b/block/io.c index f75777f..b3a67fe 100644 --- a/block/io.c +++ b/block/io.c @@ -1445,8 +1445,7 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild= *child, * potential fallback support, if we ever implement any read flags * to pass through to drivers. For now, there aren't any * passthrough flags. */ - assert(!(flags & ~(BDRV_REQ_NO_SERIALISING | BDRV_REQ_COPY_ON_READ | - BDRV_REQ_PREFETCH))); + assert(!(flags & ~(BDRV_REQ_COPY_ON_READ | BDRV_REQ_PREFETCH))); =20 /* Handle Copy on Read and associated serialisation */ if (flags & BDRV_REQ_COPY_ON_READ) { @@ -1458,12 +1457,7 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChil= d *child, bdrv_mark_request_serialising(req, bdrv_get_cluster_size(bs)); } =20 - /* BDRV_REQ_SERIALISING is only for write operation */ - assert(!(flags & BDRV_REQ_SERIALISING)); - - if (!(flags & BDRV_REQ_NO_SERIALISING)) { - bdrv_wait_serialising_requests(req); - } + bdrv_wait_serialising_requests(req); =20 if (flags & BDRV_REQ_COPY_ON_READ) { int64_t pnum; @@ -1711,7 +1705,7 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, bdrv_inc_in_flight(bs); =20 /* Don't do copy-on-read if we read data before write operation */ - if (atomic_read(&bs->copy_on_read) && !(flags & BDRV_REQ_NO_SERIALISIN= G)) { + if (atomic_read(&bs->copy_on_read)) { flags |=3D BDRV_REQ_COPY_ON_READ; } =20 @@ -1852,8 +1846,6 @@ bdrv_co_write_req_prepare(BdrvChild *child, int64_t o= ffset, uint64_t bytes, return -EPERM; } =20 - /* BDRV_REQ_NO_SERIALISING is only for read operation */ - assert(!(flags & BDRV_REQ_NO_SERIALISING)); assert(!(bs->open_flags & BDRV_O_INACTIVE)); assert((bs->open_flags & BDRV_O_NO_IO) =3D=3D 0); assert(!(flags & ~BDRV_REQ_MASK)); @@ -3222,9 +3214,7 @@ static int coroutine_fn bdrv_co_copy_range_internal( =20 /* BDRV_REQ_SERIALISING is only for write operation */ assert(!(read_flags & BDRV_REQ_SERIALISING)); - if (!(read_flags & BDRV_REQ_NO_SERIALISING)) { - bdrv_wait_serialising_requests(&req); - } + bdrv_wait_serialising_requests(&req); =20 ret =3D src->bs->drv->bdrv_co_copy_range_from(src->bs, src, src_offset, diff --git a/include/block/block.h b/include/block/block.h index e9dcfef..23c7642 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -51,18 +51,6 @@ typedef enum { */ BDRV_REQ_MAY_UNMAP =3D 0x4, =20 - /* - * The BDRV_REQ_NO_SERIALISING flag is only valid for reads and means = that - * we don't want wait_serialising_requests() during the read operation. - * - * This flag is used for backup copy-on-write operations, when we need= to - * read old data before write (write notifier triggered). It is okay s= ince - * we already waited for other serializing requests in the initiating = write - * (see bdrv_aligned_pwritev), and it is necessary if the initiating w= rite - * is already serializing (without the flag, the read would deadlock - * waiting for the serialising write to complete). - */ - BDRV_REQ_NO_SERIALISING =3D 0x8, BDRV_REQ_FUA =3D 0x10, BDRV_REQ_WRITE_COMPRESSED =3D 0x20, =20 --=20 1.8.3.1 From nobody Tue May 21 02:46:43 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578495489; cv=none; d=zohomail.com; s=zohoarc; b=UhURKrc+9QTdG4YStKJxOawERodCWo8PRgPNNWrfbBNOL5xmH3EqcjHI2GTXuPmTfqpwi2M0G1hjgV7RHoJjVosEtht5cTqWEaz5L9MVP5KdGZYLmqr590j2CknrOouJIBeTgV/CDLsJcx1J40gpEpQYKmo0ALSvHvxV+r51D9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578495489; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=55yi1vJuIPc6uvcE+4FM+S7vWH9/hsBz/Hp/0qkGAcQ=; b=L8a/dqni9dyzw9qKehampIH4OHB5Cbwqq5foHH9aolc8/T/Y0pmS9xBf91f5NB/FACrXKqD7YaQ3kM4NZhjC7zUBORjfzhAnb1IDxiIgWl1WYqVZACJarIB4DpEIeNQGkxvrUZ/u+NhdgsTTHIy7RuaQmVEk3KyEsxSOw6eOSBc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1578495489733401.2666053155913; Wed, 8 Jan 2020 06:58:09 -0800 (PST) Received: from localhost ([::1]:45142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCme-00070s-64 for importer@patchew.org; Wed, 08 Jan 2020 09:58:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40360) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCkd-0004bk-4G for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:56:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipCkb-0005Qe-Oq for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:56:03 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:38950) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ipCkb-0005Q6-Hc; Wed, 08 Jan 2020 09:56:01 -0500 Received: by mail-wm1-x343.google.com with SMTP id 20so2812622wmj.4; Wed, 08 Jan 2020 06:56:01 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id g21sm4703529wrb.48.2020.01.08.06.55.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jan 2020 06:55:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=55yi1vJuIPc6uvcE+4FM+S7vWH9/hsBz/Hp/0qkGAcQ=; b=CnoUn7FgkPHdQcIV91sThsYdyY2OwOXjVAf7x7fp3H5AIJcr+HrENJ9Fkc+1FD2tKO D20lOcZiol5DXp/LDMHcENRJa4ITJ1g3VZWS0DLSoU29WHD4FoKN4FvMGX5zR0+Z28Mh S9Fve0u+FAKZmmuVJB93+FCCuHutBYFEyEcj024Baaoxk/O/9dTCozRyTTZmLLfkEb24 ViaNbnHMRWakS0+D+UV/eNG4xQLP+Z08looFW+9UDyVqtpMm9T5z+jCgLHtjRzjGGBj3 hwTQC6gAgA0aFxg0WARs5RpKO2C5isAeS7JzNWJto888L4FkwyzOJKWq2FP0OeQFbCCV wyTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=55yi1vJuIPc6uvcE+4FM+S7vWH9/hsBz/Hp/0qkGAcQ=; b=fWuDle6ln1u+1w3a5JEQnVXBDKpRZj7WcZORqnVCfjq/kmj+drl57Wsxqtd7pfBv8I hER2JZjtnjLU0ItK0VbOdtfGAZKZPiRLLW0zgC2LuZCg4HuQsBs6/sd5/YJmrCLg5Lu5 AN0Q2wOiYOoRGOTGuNm2x/pCBmoQBD9aymU7a85q8LPFKnxIzgLncPpfH4ZLmQV3HYle YDx5uplER2LunD7OiooSziljXRQHoCfET5WMbh2XOL6+2DEICFB8z0VlMljjNFie1o0t HrsU8mmQKTKryLIuLvRR/IRQS9pgZq+DK3228IInc1xJK40QV0/uEM9ePcaKcvW1X7aR 5T/Q== X-Gm-Message-State: APjAAAXxjZ/r+sp9Nf1aN4js1T+afo3f2aVmYfyzE4yJKGn+i1toJQqY uj8rjz8nqhkk6cCiZRQjthvtQWC9 X-Google-Smtp-Source: APXvYqyWg27U+eNw3TbGnM+Z1vCCIukWhA2gslQAkdwDorUxEx3CQOmWqSIAPNocQfnk8An88rOFRQ== X-Received: by 2002:a1c:23d7:: with SMTP id j206mr4198369wmj.39.1578495360251; Wed, 08 Jan 2020 06:56:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 2/3] block/io: wait for serialising requests when a request becomes serialising Date: Wed, 8 Jan 2020 15:55:55 +0100 Message-Id: <1578495356-46219-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1578495356-46219-1-git-send-email-pbonzini@redhat.com> References: <1578495356-46219-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Marking without waiting would not result in actual serialising behavior. Thus, make a call bdrv_mark_request_serialising sufficient for serialisation to happen. Signed-off-by: Paolo Bonzini --- block/file-posix.c | 1 - block/io.c | 40 +++++++++++++++++----------------------- include/block/block_int.h | 3 +-- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 1b805bd..2b08b02 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2753,7 +2753,6 @@ raw_do_pwrite_zeroes(BlockDriverState *bs, int64_t of= fset, int bytes, req->overlap_bytes =3D req->bytes; =20 bdrv_mark_request_serialising(req, bs->bl.request_alignment); - bdrv_wait_serialising_requests(req); } #endif =20 diff --git a/block/io.c b/block/io.c index b3a67fe..c466df8 100644 --- a/block/io.c +++ b/block/io.c @@ -41,6 +41,7 @@ #define MAX_BOUNCE_BUFFER (32768 << BDRV_SECTOR_BITS) =20 static void bdrv_parent_cb_resize(BlockDriverState *bs); +static bool coroutine_fn bdrv_wait_serialising_requests(BdrvTrackedRequest= *self); static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags); =20 @@ -715,7 +716,7 @@ static void tracked_request_begin(BdrvTrackedRequest *r= eq, qemu_co_mutex_unlock(&bs->reqs_lock); } =20 -void bdrv_mark_request_serialising(BdrvTrackedRequest *req, uint64_t align) +bool bdrv_mark_request_serialising(BdrvTrackedRequest *req, uint64_t align) { int64_t overlap_offset =3D req->offset & ~(align - 1); uint64_t overlap_bytes =3D ROUND_UP(req->offset + req->bytes, align) @@ -728,18 +729,7 @@ void bdrv_mark_request_serialising(BdrvTrackedRequest = *req, uint64_t align) =20 req->overlap_offset =3D MIN(req->overlap_offset, overlap_offset); req->overlap_bytes =3D MAX(req->overlap_bytes, overlap_bytes); -} - -static bool is_request_serialising_and_aligned(BdrvTrackedRequest *req) -{ - /* - * If the request is serialising, overlap_offset and overlap_bytes are= set, - * so we can check if the request is aligned. Otherwise, don't care and - * return false. - */ - - return req->serialising && (req->offset =3D=3D req->overlap_offset) && - (req->bytes =3D=3D req->overlap_bytes); + return bdrv_wait_serialising_requests(req); } =20 /** @@ -823,7 +813,7 @@ void bdrv_dec_in_flight(BlockDriverState *bs) bdrv_wakeup(bs); } =20 -bool coroutine_fn bdrv_wait_serialising_requests(BdrvTrackedRequest *self) +static bool coroutine_fn bdrv_wait_serialising_requests(BdrvTrackedRequest= *self) { BlockDriverState *bs =3D self->bs; BdrvTrackedRequest *req; @@ -1455,10 +1445,10 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChi= ld *child, * it ensures that the CoR read and write operations are atomic and * guest writes cannot interleave between them. */ bdrv_mark_request_serialising(req, bdrv_get_cluster_size(bs)); + } else { + bdrv_wait_serialising_requests(req); } =20 - bdrv_wait_serialising_requests(req); - if (flags & BDRV_REQ_COPY_ON_READ) { int64_t pnum; =20 @@ -1851,13 +1841,19 @@ bdrv_co_write_req_prepare(BdrvChild *child, int64_t= offset, uint64_t bytes, assert(!(flags & ~BDRV_REQ_MASK)); =20 if (flags & BDRV_REQ_SERIALISING) { - bdrv_mark_request_serialising(req, bdrv_get_cluster_size(bs)); + waited =3D bdrv_mark_request_serialising(req, bdrv_get_cluster_siz= e(bs)); + /* + * For a misaligned request we should have already waited earlier, + * because we come after bdrv_padding_rmw_read which must be called + * with the request already marked as serialising. + */ + assert(!waited || + (req->offset =3D=3D req->overlap_offset && + req->bytes =3D=3D req->overlap_bytes)); + } else { + bdrv_wait_serialising_requests(req); } =20 - waited =3D bdrv_wait_serialising_requests(req); - - assert(!waited || !req->serialising || - is_request_serialising_and_aligned(req)); assert(req->overlap_offset <=3D offset); assert(offset + bytes <=3D req->overlap_offset + req->overlap_bytes); assert(end_sector <=3D bs->total_sectors || child->perm & BLK_PERM_RES= IZE); @@ -2019,7 +2015,6 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvC= hild *child, padding =3D bdrv_init_padding(bs, offset, bytes, &pad); if (padding) { bdrv_mark_request_serialising(req, align); - bdrv_wait_serialising_requests(req); =20 bdrv_padding_rmw_read(child, req, &pad, true); =20 @@ -2122,7 +2117,6 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *chil= d, =20 if (bdrv_pad_request(bs, &qiov, &qiov_offset, &offset, &bytes, &pad)) { bdrv_mark_request_serialising(&req, align); - bdrv_wait_serialising_requests(&req); bdrv_padding_rmw_read(child, &req, &pad, false); } =20 diff --git a/include/block/block_int.h b/include/block/block_int.h index dd033d0..640fb82 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -999,8 +999,7 @@ extern unsigned int bdrv_drain_all_count; void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_pare= nt); void bdrv_unapply_subtree_drain(BdrvChild *child, BlockDriverState *old_pa= rent); =20 -bool coroutine_fn bdrv_wait_serialising_requests(BdrvTrackedRequest *self); -void bdrv_mark_request_serialising(BdrvTrackedRequest *req, uint64_t align= ); +bool coroutine_fn bdrv_mark_request_serialising(BdrvTrackedRequest *req, u= int64_t align); BdrvTrackedRequest *coroutine_fn bdrv_co_get_self_request(BlockDriverState= *bs); =20 int get_tmp_filename(char *filename, int size); --=20 1.8.3.1 From nobody Tue May 21 02:46:43 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578495480; cv=none; d=zohomail.com; s=zohoarc; b=NyhSQocYkwFB3u7b7AyOCsLE4j5XBQrHW/U1N3Geh4peVgZ4w9WXOI6hn2Asp9BAE9psyOis0LPYPkJ8vuiJfxjBhELuQfXdsD1CwYRUKHALQ3LDx9jty/o6gqTAiybdrffQIcdPmGLbYR7u/4VIgALWthY3QDRmE6QqoUKUUJE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578495480; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=qcVr5U+PaE347gU6Z5SP9PViHvCgA8hEGQiX601oVC8=; b=FyqJ6Nge/+5wIozjtw9tnQzmCRiwhpUcEEBz3SiZyPjGFlgWibue/7c/OFwVE0QBfdKj3by+ImEIQqXpeF5eeyEDkjP4zTiwka293SwtrCWXsWLZy6zTEoFHneRW9PRdrI26nK8K/5/7qK90NkVWgOlY3Z4CVwce6X5GxP3mccY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1578495480353912.459761046774; Wed, 8 Jan 2020 06:58:00 -0800 (PST) Received: from localhost ([::1]:45140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCmU-0006m1-Pf for importer@patchew.org; Wed, 08 Jan 2020 09:57:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40382) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ipCkd-0004dF-V6 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:56:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ipCkc-0005Re-H8 for qemu-devel@nongnu.org; Wed, 08 Jan 2020 09:56:03 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:36827) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ipCkc-0005QY-An; Wed, 08 Jan 2020 09:56:02 -0500 Received: by mail-wm1-x342.google.com with SMTP id p17so2827647wma.1; Wed, 08 Jan 2020 06:56:02 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id g21sm4703529wrb.48.2020.01.08.06.56.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jan 2020 06:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=qcVr5U+PaE347gU6Z5SP9PViHvCgA8hEGQiX601oVC8=; b=GsVjHs8GQ9BFdj0BD4UH6PXJzPqpOpQy0oD86GYjJIoJO9fhIQMnIiLlC9+hNMBWD4 LCkvohBVeH1BJxdcYwq80OouFOjcYmp46f2VZUX0G1WValDd1sfkIWRbwAbtNX8zriio fKa7OqIHAy1w0Htsa0MU+GMj6aTi0gXnwrgHG7lLU6IQ2Jemo+txGNnYTWB4Z6Z3Gkuz ab77vCtmZKIrAghMBDvwqidWvw7YoGE+IrvERy6OGDEVc8qN1dpRABxIzm1/30U7dEHK zzbuowZvpizq3tiN0/X/9Ldj5MEXCrwwEQua8R8Tv9qMNQyVinmXfzMbkL8w5AMiCa3t irDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=qcVr5U+PaE347gU6Z5SP9PViHvCgA8hEGQiX601oVC8=; b=ra8o7X8tSjYiqSbKor4uV1p48BW7gb+U0XW1D4fp3augptq26CuNkilWdfJQLm3cRY FOGr0D/k7MqgF0tzzSn/qxRZ09LkAPQImkz7U4/2CJQZGQ25ED6w5fug4/JN6w4vdhIY 2HbAAeqEkMB8Awsusm7u208GWlxDTsYK8QCSyJV8Yt3c6duuCwJqvZjsiDws0t3Py2Et 9GkLSB3kucLYxpoLuwK9NQ7uZevUBstheTPR1AWP5yJtW6PD3aNRlUHWYyut+bVuyqBf DCRD+wYkIW4OZHp9o4xKAvDl7MFGisWy2NbFVIaGgARafxEasNQgFEcUD79m1flEh05b 8kcQ== X-Gm-Message-State: APjAAAVcxAOaLB6HzLsllYgT4tibBpWqW7va3ODOAiXb+2YUgiXN6qcD SCdlNAKXe+jxMMQN0SvFOKl9whub X-Google-Smtp-Source: APXvYqyRPzdKIqXLdODIjRSCE1iCy+FJqVlNe/v3O1ohKV6TeM+bYkfXAt3JJo8hoaCpCKtmKXjlwA== X-Received: by 2002:a1c:407:: with SMTP id 7mr4208946wme.29.1578495361111; Wed, 08 Jan 2020 06:56:01 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 3/3] block/io: take bs->reqs_lock in bdrv_mark_request_serialising Date: Wed, 8 Jan 2020 15:55:56 +0100 Message-Id: <1578495356-46219-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1578495356-46219-1-git-send-email-pbonzini@redhat.com> References: <1578495356-46219-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" bdrv_mark_request_serialising is writing the overlap_offset and overlap_bytes fields of BdrvTrackedRequest. Take bs->reqs_lock for the whole duration of it, and not just when waiting for serialising requests, so that tracked_request_overlaps does not look at a half-updated request. The new code does not unlock/relock around retries. This is unnecessary because a retry is always preceded by a CoQueue wait, which already releases and reacquires bs->reqs_lock. Reported-by: Peter Lieven Signed-off-by: Paolo Bonzini --- block/io.c | 112 ++++++++++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 63 insertions(+), 49 deletions(-) diff --git a/block/io.c b/block/io.c index c466df8..1eb2b2b 100644 --- a/block/io.c +++ b/block/io.c @@ -41,7 +41,6 @@ #define MAX_BOUNCE_BUFFER (32768 << BDRV_SECTOR_BITS) =20 static void bdrv_parent_cb_resize(BlockDriverState *bs); -static bool coroutine_fn bdrv_wait_serialising_requests(BdrvTrackedRequest= *self); static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags); =20 @@ -716,12 +715,69 @@ static void tracked_request_begin(BdrvTrackedRequest = *req, qemu_co_mutex_unlock(&bs->reqs_lock); } =20 +static bool tracked_request_overlaps(BdrvTrackedRequest *req, + int64_t offset, uint64_t bytes) +{ + /* aaaa bbbb */ + if (offset >=3D req->overlap_offset + req->overlap_bytes) { + return false; + } + /* bbbb aaaa */ + if (req->overlap_offset >=3D offset + bytes) { + return false; + } + return true; +} + +static bool coroutine_fn +bdrv_wait_serialising_requests_locked(BlockDriverState *bs, + BdrvTrackedRequest *self) +{ + BdrvTrackedRequest *req; + bool retry; + bool waited =3D false; + + do { + retry =3D false; + QLIST_FOREACH(req, &bs->tracked_requests, list) { + if (req =3D=3D self || (!req->serialising && !self->serialisin= g)) { + continue; + } + if (tracked_request_overlaps(req, self->overlap_offset, + self->overlap_bytes)) + { + /* Hitting this means there was a reentrant request, for + * example, a block driver issuing nested requests. This = must + * never happen since it means deadlock. + */ + assert(qemu_coroutine_self() !=3D req->co); + + /* If the request is already (indirectly) waiting for us, = or + * will wait for us as soon as it wakes up, then just go on + * (instead of producing a deadlock in the former case). */ + if (!req->waiting_for) { + self->waiting_for =3D req; + qemu_co_queue_wait(&req->wait_queue, &bs->reqs_lock); + self->waiting_for =3D NULL; + retry =3D true; + waited =3D true; + break; + } + } + } + } while (retry); + return waited; +} + bool bdrv_mark_request_serialising(BdrvTrackedRequest *req, uint64_t align) { + BlockDriverState *bs =3D req->bs; int64_t overlap_offset =3D req->offset & ~(align - 1); uint64_t overlap_bytes =3D ROUND_UP(req->offset + req->bytes, align) - overlap_offset; + bool waited; =20 + qemu_co_mutex_lock(&bs->reqs_lock); if (!req->serialising) { atomic_inc(&req->bs->serialising_in_flight); req->serialising =3D true; @@ -729,7 +785,9 @@ bool bdrv_mark_request_serialising(BdrvTrackedRequest *= req, uint64_t align) =20 req->overlap_offset =3D MIN(req->overlap_offset, overlap_offset); req->overlap_bytes =3D MAX(req->overlap_bytes, overlap_bytes); - return bdrv_wait_serialising_requests(req); + waited =3D bdrv_wait_serialising_requests_locked(bs, req); + qemu_co_mutex_unlock(&bs->reqs_lock); + return waited; } =20 /** @@ -783,20 +841,6 @@ static int bdrv_get_cluster_size(BlockDriverState *bs) } } =20 -static bool tracked_request_overlaps(BdrvTrackedRequest *req, - int64_t offset, uint64_t bytes) -{ - /* aaaa bbbb */ - if (offset >=3D req->overlap_offset + req->overlap_bytes) { - return false; - } - /* bbbb aaaa */ - if (req->overlap_offset >=3D offset + bytes) { - return false; - } - return true; -} - void bdrv_inc_in_flight(BlockDriverState *bs) { atomic_inc(&bs->in_flight); @@ -816,45 +860,15 @@ void bdrv_dec_in_flight(BlockDriverState *bs) static bool coroutine_fn bdrv_wait_serialising_requests(BdrvTrackedRequest= *self) { BlockDriverState *bs =3D self->bs; - BdrvTrackedRequest *req; - bool retry; bool waited =3D false; =20 if (!atomic_read(&bs->serialising_in_flight)) { return false; } =20 - do { - retry =3D false; - qemu_co_mutex_lock(&bs->reqs_lock); - QLIST_FOREACH(req, &bs->tracked_requests, list) { - if (req =3D=3D self || (!req->serialising && !self->serialisin= g)) { - continue; - } - if (tracked_request_overlaps(req, self->overlap_offset, - self->overlap_bytes)) - { - /* Hitting this means there was a reentrant request, for - * example, a block driver issuing nested requests. This = must - * never happen since it means deadlock. - */ - assert(qemu_coroutine_self() !=3D req->co); - - /* If the request is already (indirectly) waiting for us, = or - * will wait for us as soon as it wakes up, then just go on - * (instead of producing a deadlock in the former case). */ - if (!req->waiting_for) { - self->waiting_for =3D req; - qemu_co_queue_wait(&req->wait_queue, &bs->reqs_lock); - self->waiting_for =3D NULL; - retry =3D true; - waited =3D true; - break; - } - } - } - qemu_co_mutex_unlock(&bs->reqs_lock); - } while (retry); + qemu_co_mutex_lock(&bs->reqs_lock); + waited =3D bdrv_wait_serialising_requests_locked(bs, self); + qemu_co_mutex_unlock(&bs->reqs_lock); =20 return waited; } --=20 1.8.3.1