From nobody Sat May 18 07:31:19 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563816421; cv=none; d=zoho.com; s=zohoarc; b=A6haMb2MHgPZ5sihMDDtzQzhO/VHY2f2I4Rr4+NSULr3bmVybCwhL/oF6eePXPJulLrbKAhri1ac4SpVGdHj0kO00mFC76L3DmksXpLpWYtuqS/osz0pB0M4muQr1+Hg3wQsMqAO7yi8th1Ru+sEzEyNFIyYS4JWL6PNYC4smJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563816421; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7uexuCQpAP2eWtv9kfn8gaSDz3+8dB87iFzZSyM8+Nc=; b=ERw5Vv9Uh6ZDlT7s/F6Yg16a1bwz5YuM9RGAYI//2iEIBxhArHyWS0IZKgXtKZ8PLXDp82qotL4dK4piWT6Bx8u89qik5GxYM5yHCng5ZUPNq7U3Ru2U9z03hUf3n55D60z+EHielgYMYpekyRc672Z0GeXKhVTAaq59Ye37mnc= ARC-Authentication-Results: i=1; mx.zoho.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; 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 1563816421951647.8388406293395; Mon, 22 Jul 2019 10:27:01 -0700 (PDT) Received: from localhost ([::1]:36282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpc5U-0001Yz-VK for importer@patchew.org; Mon, 22 Jul 2019 13:27:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51082) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpc5K-0001AW-7X for qemu-devel@nongnu.org; Mon, 22 Jul 2019 13:26:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hpc5D-0004Lu-Vw for qemu-devel@nongnu.org; Mon, 22 Jul 2019 13:26:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37744) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hpc5B-0004Js-D2; Mon, 22 Jul 2019 13:26:41 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA23785376; Mon, 22 Jul 2019 17:26:40 +0000 (UTC) Received: from localhost (unknown [10.40.205.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D63A71001DE1; Mon, 22 Jul 2019 17:26:37 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 22 Jul 2019 19:26:12 +0200 Message-Id: <20190722172616.28797-2-mreitz@redhat.com> In-Reply-To: <20190722172616.28797-1-mreitz@redhat.com> References: <20190722172616.28797-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 22 Jul 2019 17:26:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/5] block/nvme: fix doorbell stride 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky Fix the math involving non standard doorbell stride Signed-off-by: Maxim Levitsky Reviewed-by: Max Reitz Message-id: 20190716163020.13383-2-mlevitsk@redhat.com Signed-off-by: Max Reitz --- block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/nvme.c b/block/nvme.c index 9896b7f7c6..82fdefccd6 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -217,7 +217,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDrive= rState *bs, error_propagate(errp, local_err); goto fail; } - q->cq.doorbell =3D &s->regs->doorbells[idx * 2 * s->doorbell_scale + 1= ]; + q->cq.doorbell =3D &s->regs->doorbells[(idx * 2 + 1) * s->doorbell_sca= le]; =20 return q; fail: --=20 2.21.0 From nobody Sat May 18 07:31:19 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563816448; cv=none; d=zoho.com; s=zohoarc; b=bTctIv2yCEW6K9wil8ipZ5vHqG6LJ3jxqZYWXOWr/BpMWS3TSk79EFMvo3648Bu2D1gAkkWOAzDmO88oC9RTzBkCHZziRGLgmwYwgQOFh64Chos/qORpjOzoqbEy7cm/BhMCJpL8/8PoLgy03rfgFEKzxPA9w82vBaXevHTvRrY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563816448; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=t8RjRLdQ8MSvtaIIJNBplXgCeX3+RWsWjw3GTTrEAfA=; b=HFkbWeD8sxcQj8Q0Rt+E+jYjbMRokImYze+eN0izc4z0aFSgFksML8hvI6hUpDvXUh0TSVGabdpb6YL0K9vka2UPoy6rtkovVjOqq85d6C2h1Z4bHu7fONkJ7u/SwPGIIfCJvx4ZSTz86I9W9UBUgHCRqomcACC/NEnOk4bMvE4= ARC-Authentication-Results: i=1; mx.zoho.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; 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 1563816448150609.4325291240328; Mon, 22 Jul 2019 10:27:28 -0700 (PDT) Received: from localhost ([::1]:36298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpc5u-0002zU-Qw for importer@patchew.org; Mon, 22 Jul 2019 13:27:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51191) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpc5Z-00020b-5y for qemu-devel@nongnu.org; Mon, 22 Jul 2019 13:27:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hpc5Y-0004W6-0q for qemu-devel@nongnu.org; Mon, 22 Jul 2019 13:27:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58658) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hpc5N-0004Mh-Q8; Mon, 22 Jul 2019 13:26:55 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B644985538; Mon, 22 Jul 2019 17:26:45 +0000 (UTC) Received: from localhost (unknown [10.40.205.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CC75B61377; Mon, 22 Jul 2019 17:26:44 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 22 Jul 2019 19:26:13 +0200 Message-Id: <20190722172616.28797-3-mreitz@redhat.com> In-Reply-To: <20190722172616.28797-1-mreitz@redhat.com> References: <20190722172616.28797-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 22 Jul 2019 17:26:45 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/5] block/nvme: support larger that 512 bytes sector devices 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky Currently the driver hardcodes the sector size to 512, and doesn't check the underlying device. Fix that. Also fail if underlying nvme device is formatted with metadata as this needs special support. Signed-off-by: Maxim Levitsky Message-id: 20190716163020.13383-3-mlevitsk@redhat.com Signed-off-by: Max Reitz --- block/nvme.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 82fdefccd6..35ce10dc79 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -102,8 +102,11 @@ typedef struct { size_t doorbell_scale; bool write_cache_supported; EventNotifier irq_notifier; + uint64_t nsze; /* Namespace size reported by identify command */ int nsid; /* The namespace id to read/write data. */ + size_t blkshift; + uint64_t max_transfer; bool plugged; =20 @@ -418,8 +421,9 @@ static void nvme_identify(BlockDriverState *bs, int nam= espace, Error **errp) BDRVNVMeState *s =3D bs->opaque; NvmeIdCtrl *idctrl; NvmeIdNs *idns; + NvmeLBAF *lbaf; uint8_t *resp; - int r; + int r, hwsect_size; uint64_t iova; NvmeCmd cmd =3D { .opcode =3D NVME_ADM_CMD_IDENTIFY, @@ -466,7 +470,22 @@ static void nvme_identify(BlockDriverState *bs, int na= mespace, Error **errp) } =20 s->nsze =3D le64_to_cpu(idns->nsze); + lbaf =3D &idns->lbaf[NVME_ID_NS_FLBAS_INDEX(idns->flbas)]; + + if (lbaf->ms) { + error_setg(errp, "Namespaces with metadata are not yet supported"); + goto out; + } + + hwsect_size =3D 1 << lbaf->ds; + + if (hwsect_size < BDRV_SECTOR_SIZE || hwsect_size > s->page_size) { + error_setg(errp, "Namespace has unsupported block size (%d)", + hwsect_size); + goto out; + } =20 + s->blkshift =3D lbaf->ds; out: qemu_vfio_dma_unmap(s->vfio, resp); qemu_vfree(resp); @@ -785,8 +804,22 @@ fail: static int64_t nvme_getlength(BlockDriverState *bs) { BDRVNVMeState *s =3D bs->opaque; + return s->nsze << s->blkshift; +} =20 - return s->nsze << BDRV_SECTOR_BITS; +static int64_t nvme_get_blocksize(BlockDriverState *bs) +{ + BDRVNVMeState *s =3D bs->opaque; + assert(s->blkshift >=3D BDRV_SECTOR_BITS); + return 1 << s->blkshift; +} + +static int nvme_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz) +{ + int64_t blocksize =3D nvme_get_blocksize(bs); + bsz->phys =3D blocksize; + bsz->log =3D blocksize; + return 0; } =20 /* Called with s->dma_map_lock */ @@ -917,13 +950,14 @@ static coroutine_fn int nvme_co_prw_aligned(BlockDriv= erState *bs, BDRVNVMeState *s =3D bs->opaque; NVMeQueuePair *ioq =3D s->queues[1]; NVMeRequest *req; - uint32_t cdw12 =3D (((bytes >> BDRV_SECTOR_BITS) - 1) & 0xFFFF) | + + uint32_t cdw12 =3D (((bytes >> s->blkshift) - 1) & 0xFFFF) | (flags & BDRV_REQ_FUA ? 1 << 30 : 0); NvmeCmd cmd =3D { .opcode =3D is_write ? NVME_CMD_WRITE : NVME_CMD_READ, .nsid =3D cpu_to_le32(s->nsid), - .cdw10 =3D cpu_to_le32((offset >> BDRV_SECTOR_BITS) & 0xFFFFFFFF), - .cdw11 =3D cpu_to_le32(((offset >> BDRV_SECTOR_BITS) >> 32) & 0xFF= FFFFFF), + .cdw10 =3D cpu_to_le32((offset >> s->blkshift) & 0xFFFFFFFF), + .cdw11 =3D cpu_to_le32(((offset >> s->blkshift) >> 32) & 0xFFFFFFF= F), .cdw12 =3D cpu_to_le32(cdw12), }; NVMeCoData data =3D { @@ -1154,6 +1188,7 @@ static BlockDriver bdrv_nvme =3D { .bdrv_file_open =3D nvme_file_open, .bdrv_close =3D nvme_close, .bdrv_getlength =3D nvme_getlength, + .bdrv_probe_blocksizes =3D nvme_probe_blocksizes, =20 .bdrv_co_preadv =3D nvme_co_preadv, .bdrv_co_pwritev =3D nvme_co_pwritev, --=20 2.21.0 From nobody Sat May 18 07:31:19 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563816450; cv=none; d=zoho.com; s=zohoarc; b=DvO3W8qYlnRSJwMBiPgKDqiXFvBxE+e+XcOC60V5F6F46MBKx+/+iWEqhMqiOcCK+Q5Zmkrq9SbPmLr8OnUJgAlRuKdm3bFtFewxZNgV+U+U85/fibnVXZrkbJPfYt6jFJMPX9JQLzaVyyVowHJJo5MR6tuNorSxvnCNJVzaZEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563816450; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=WTQM9OrKKEKUGrhmxLvJaYH78UZUyvo+pjSZUByOKPA=; b=DYyCtUb+2oMK8EnHs3jok6W7tXKBxIUPJVE3IB2OOFA3B2IG1Jh2McEM727Lq4ehrSMZm6JOzdlAZKTuz2LfqTxTFcPB1CfEv8aCpAuz4CPIhNXUZ+KDigvPb+tRnVA/966Er6FQy3eTZcAbO71BIOETwhSWCxbe9NZz8CDyXow= ARC-Authentication-Results: i=1; mx.zoho.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; 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 1563816450889641.8126099456141; Mon, 22 Jul 2019 10:27:30 -0700 (PDT) Received: from localhost ([::1]:36300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpc5x-0003DP-Lf for importer@patchew.org; Mon, 22 Jul 2019 13:27:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51301) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpc5b-00025R-IL for qemu-devel@nongnu.org; Mon, 22 Jul 2019 13:27:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hpc5a-0004Yh-By for qemu-devel@nongnu.org; Mon, 22 Jul 2019 13:27:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41774) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hpc5Y-0004PY-6G; Mon, 22 Jul 2019 13:27:04 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B53893082126; Mon, 22 Jul 2019 17:26:51 +0000 (UTC) Received: from localhost (unknown [10.40.205.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A039760BFB; Mon, 22 Jul 2019 17:26:50 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 22 Jul 2019 19:26:14 +0200 Message-Id: <20190722172616.28797-4-mreitz@redhat.com> In-Reply-To: <20190722172616.28797-1-mreitz@redhat.com> References: <20190722172616.28797-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 22 Jul 2019 17:26:51 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/5] block/nvme: don't touch the completion entries 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky Completion entries are meant to be only read by the host and written by the= device. The driver is supposed to scan the completions from the last point where it= left, and until it sees a completion with non flipped phase bit. Signed-off-by: Maxim Levitsky Reviewed-by: Max Reitz Message-id: 20190716163020.13383-4-mlevitsk@redhat.com Signed-off-by: Max Reitz --- block/nvme.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 35ce10dc79..c28755cc31 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -318,7 +318,7 @@ static bool nvme_process_completion(BDRVNVMeState *s, N= VMeQueuePair *q) while (q->inflight) { int16_t cid; c =3D (NvmeCqe *)&q->cq.queue[q->cq.head * NVME_CQ_ENTRY_BYTES]; - if (!c->cid || (le16_to_cpu(c->status) & 0x1) =3D=3D q->cq_phase) { + if ((le16_to_cpu(c->status) & 0x1) =3D=3D q->cq_phase) { break; } q->cq.head =3D (q->cq.head + 1) % NVME_QUEUE_SIZE; @@ -342,10 +342,7 @@ static bool nvme_process_completion(BDRVNVMeState *s, = NVMeQueuePair *q) qemu_mutex_unlock(&q->lock); req.cb(req.opaque, nvme_translate_error(c)); qemu_mutex_lock(&q->lock); - c->cid =3D cpu_to_le16(0); q->inflight--; - /* Flip Phase Tag bit. */ - c->status =3D cpu_to_le16(le16_to_cpu(c->status) ^ 0x1); progress =3D true; } if (progress) { --=20 2.21.0 From nobody Sat May 18 07:31:19 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563816461; cv=none; d=zoho.com; s=zohoarc; b=Wpo07c3Nhfvs5SVALrPS0yxc/1EWjESMF5bGHre7tbPMdHc3nbrbIiNXqyRZTP2WKOmbct+Kg4b9apsZwTcZfZq6J4qVcMNoDab7RFQYGV5g6ULXLqrQhJQ8mOr0tD8VevX/hz1xwbg2zbRcLLC4HH2eER2TumF4rJSLTiNbWcI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563816461; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=5DO3DwjbxKnCYcAOQEdijPCZ/6tO9KuVheFPZQbTSoo=; b=lS3wrhK8U29S8z+9VnQrMHo8NYrc/dNpcUuPyRnADwmpsZrNep6cISpG41L8MxlnXtebKuqSUzDJGmvN6qc4+daerqYIwYB0MmaVqIjo9Lyd/jDhdSIUHUYrnskLHOGLUJsLD1tSPQRwJN7LSXjzjLOLRK4vsrXXASOB/tET1GY= ARC-Authentication-Results: i=1; mx.zoho.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; 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 156381646124697.331077588227; Mon, 22 Jul 2019 10:27:41 -0700 (PDT) Received: from localhost ([::1]:36302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpc68-00045X-AA for importer@patchew.org; Mon, 22 Jul 2019 13:27:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51350) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpc5i-0002d1-Ok for qemu-devel@nongnu.org; Mon, 22 Jul 2019 13:27:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hpc5h-0004e9-P6 for qemu-devel@nongnu.org; Mon, 22 Jul 2019 13:27:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38420) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hpc5f-0004ce-JX; Mon, 22 Jul 2019 13:27:11 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7B1D87638; Mon, 22 Jul 2019 17:27:10 +0000 (UTC) Received: from localhost (unknown [10.40.205.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4BE1960148; Mon, 22 Jul 2019 17:27:10 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 22 Jul 2019 19:26:15 +0200 Message-Id: <20190722172616.28797-5-mreitz@redhat.com> In-Reply-To: <20190722172616.28797-1-mreitz@redhat.com> References: <20190722172616.28797-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 22 Jul 2019 17:27:10 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/5] block: Dec. drained_end_counter before bdrv_wakeup 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Decrementing drained_end_counter after bdrv_dec_in_flight() (which in turn invokes bdrv_wakeup() and thus aio_wait_kick()) is not very clever. We should decrement it beforehand, so that any waiting aio_poll() that is woken by bdrv_dec_in_flight() sees the decremented drained_end_counter. Because the time window between decrementing drained_end_counter and aio_wait_kick() is very small, I cannot supply a reliable regression test. However, running e.g. the /bdrv-drain/blockjob/iothread/drain_all test in test-bdrv-drain has a small chance of hanging without this patch (about 1/200 or so; it gets to nearly 100 % if you add e.g. an fputc(' ', stderr); after the bdrv_dec_in_flight()). Fixes: e037c09c78520cbdb6da7cfc6ad0256d5870b814 Signed-off-by: Max Reitz Message-id: 20190722133054.21781-2-mreitz@redhat.com Signed-off-by: Max Reitz --- block/io.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index b89e155d21..06305c6ea6 100644 --- a/block/io.c +++ b/block/io.c @@ -217,13 +217,12 @@ static void coroutine_fn bdrv_drain_invoke_entry(void= *opaque) bs->drv->bdrv_co_drain_end(bs); } =20 - /* Set data->done before reading bs->wakeup. */ + /* Set data->done and decrement drained_end_counter before bdrv_wakeup= () */ atomic_mb_set(&data->done, true); - bdrv_dec_in_flight(bs); - if (!data->begin) { atomic_dec(data->drained_end_counter); } + bdrv_dec_in_flight(bs); =20 g_free(data); } --=20 2.21.0 From nobody Sat May 18 07:31:19 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563816473; cv=none; d=zoho.com; s=zohoarc; b=k8KE/waevjyPmIZHfrZp9j12o/Si2aJTok5MHdjLEm/iufi3wP/hYHVT/ef0caUq4j8Uyo3FJHJ1J8PfTVlnA0p+3DTTrOiYJyAxnLcqXgzAINT2LDAal7E374ovnvkVzTkfaJmyB9wPJs+8tEg+19PeBJSkNe5AzrCkaYKsOMg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563816473; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=HiVChfhSsN3mmpin/V/PImnfxtKRsaSvgE9eOuTheD4=; b=eTHeyGHXgvxj3ROaWOorrsuujJ9SELdpbPZyW/9T8jMrXbvsDHCITua2ladwmtTwXIclJJ68wupN90DOPMwI2fro4cu57ADrtvbfzALLcBVejEQZzm9cWA0UnF3GsXHeJKv5JvnOda9KSMvCIP26m+pcfioIHpRWVBZY3c4CwXI= ARC-Authentication-Results: i=1; mx.zoho.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; 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 1563816473812765.349145141671; Mon, 22 Jul 2019 10:27:53 -0700 (PDT) Received: from localhost ([::1]:36322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpc6K-0005DE-Mt for importer@patchew.org; Mon, 22 Jul 2019 13:27:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51470) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpc66-0004LE-AD for qemu-devel@nongnu.org; Mon, 22 Jul 2019 13:27:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hpc63-0004nf-Gl for qemu-devel@nongnu.org; Mon, 22 Jul 2019 13:27:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43788) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hpc60-0004mF-Cx; Mon, 22 Jul 2019 13:27:32 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AE8B63082201; Mon, 22 Jul 2019 17:27:31 +0000 (UTC) Received: from localhost (unknown [10.40.205.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A7A451024802; Mon, 22 Jul 2019 17:27:30 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 22 Jul 2019 19:26:16 +0200 Message-Id: <20190722172616.28797-6-mreitz@redhat.com> In-Reply-To: <20190722172616.28797-1-mreitz@redhat.com> References: <20190722172616.28797-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 22 Jul 2019 17:27:31 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/5] block: Only the main loop can change AioContexts 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_set_aio_context_ignore() can only work in the main loop: bdrv_drained_begin() only works in the main loop and the node's (old) AioContext; and bdrv_drained_end() really only works in the main loop and the node's (new) AioContext (contrary to its current comment, which is just wrong). Consequentially, bdrv_set_aio_context_ignore() must be called from the main loop. Luckily, assuming that we can make block graph changes only from the main loop as well, all its callers do that already. Note that changing a node's context in a sense is an operation that changes the block graph, so it actually makes sense to require this function to be called from the main loop. Also, fix bdrv_drained_end()'s description. You can only use it from the main loop or the node's AioContext, and in the latter case, the whole subtree must be in the same context. Fixes: e037c09c78520cbdb6da7cfc6ad0256d5870b814 Signed-off-by: Max Reitz Message-id: 20190722133054.21781-3-mreitz@redhat.com Signed-off-by: Max Reitz --- include/block/block.h | 8 +++----- block.c | 13 ++++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 60f00479e0..50a07c1c33 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -667,11 +667,9 @@ void bdrv_subtree_drained_begin(BlockDriverState *bs); * * This polls @bs's AioContext until all scheduled sub-drained_ends * have settled. On one hand, that may result in graph changes. On - * the other, this requires that all involved nodes (@bs and all of - * its parents) are in the same AioContext, and that the caller has - * acquired it. - * If there are any nodes that are in different contexts from @bs, - * these contexts must not be acquired. + * the other, this requires that the caller either runs in the main + * loop; or that all involved nodes (@bs and all of its parents) are + * in the caller's AioContext. */ void bdrv_drained_end(BlockDriverState *bs); =20 diff --git a/block.c b/block.c index 9c94f7f28a..cbd8da5f3b 100644 --- a/block.c +++ b/block.c @@ -5914,6 +5914,8 @@ static void bdrv_attach_aio_context(BlockDriverState = *bs, * Changes the AioContext used for fd handlers, timers, and BHs by this * BlockDriverState and all its children and parents. * + * Must be called from the main AioContext. + * * The caller must own the AioContext lock for the old AioContext of bs, b= ut it * must not own the AioContext lock for new_context (unless new_context is= the * same as the current context of bs). @@ -5925,9 +5927,10 @@ void bdrv_set_aio_context_ignore(BlockDriverState *b= s, AioContext *new_context, GSList **ignore) { AioContext *old_context =3D bdrv_get_aio_context(bs); - AioContext *current_context =3D qemu_get_current_aio_context(); BdrvChild *child; =20 + g_assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context()); + if (old_context =3D=3D new_context) { return; } @@ -5953,7 +5956,7 @@ void bdrv_set_aio_context_ignore(BlockDriverState *bs, bdrv_detach_aio_context(bs); =20 /* Acquire the new context, if necessary */ - if (current_context !=3D new_context) { + if (qemu_get_aio_context() !=3D new_context) { aio_context_acquire(new_context); } =20 @@ -5965,16 +5968,16 @@ void bdrv_set_aio_context_ignore(BlockDriverState *= bs, * subtree that have not yet been moved to the new AioContext. * Release the old one so bdrv_drained_end() can poll them. */ - if (current_context !=3D old_context) { + if (qemu_get_aio_context() !=3D old_context) { aio_context_release(old_context); } =20 bdrv_drained_end(bs); =20 - if (current_context !=3D old_context) { + if (qemu_get_aio_context() !=3D old_context) { aio_context_acquire(old_context); } - if (current_context !=3D new_context) { + if (qemu_get_aio_context() !=3D new_context) { aio_context_release(new_context); } } --=20 2.21.0