From nobody Thu Mar 28 23:22:51 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=1555336818; cv=none; d=zoho.com; s=zohoarc; b=F++fdmNLMvA3cHdx7Yxi4U0k0rQP97Hl8aV7njjP+nv+SioG/7qWl0EkpdddjrMP1CpJu+6m5MAcBSF93a66irMGO4SpCiodfKbrlqXTrn68WuYfZNQn+dSiv+iQSvXFWeZ2R7HOuTSYajUH9f7GWhm+LtJf8A1azW/zhb7ddbg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555336818; 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:ARC-Authentication-Results; bh=kEM8cNQ+D6ok3rH1/UGlLSe9D0SHJxUm8cy6yRvajYA=; b=nb0BT+k/vsKRJ0e5Rrite8ht0qL9W8r0/4YsMTGzgGVTloH1zUmXONMsu1uMv3G2clzYlCylSNFcI0oTXv5kG/cTnvPi81F75ifW69tlg+xZCt7AxqpPVfElxEy2ujaQOXai8DFiCjo1DPCjyNOJ8QInucm6atnXq8VHLdYcaDk= 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 155533681870952.218255685446934; Mon, 15 Apr 2019 07:00:18 -0700 (PDT) Received: from localhost ([127.0.0.1]:50626 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hG29f-0006Z4-44 for importer@patchew.org; Mon, 15 Apr 2019 10:00:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hG27T-00055h-Vd for qemu-devel@nongnu.org; Mon, 15 Apr 2019 09:58:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hG27T-0007xV-38 for qemu-devel@nongnu.org; Mon, 15 Apr 2019 09:57:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51936) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hG27P-0007tR-9A; Mon, 15 Apr 2019 09:57:55 -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 C817D3082E1F; Mon, 15 Apr 2019 13:57:52 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D12A1001DE8; Mon, 15 Apr 2019 13:57:50 +0000 (UTC) From: Maxim Levitsky To: qemu-block@nongnu.org Date: Mon, 15 Apr 2019 16:57:42 +0300 Message-Id: <20190415135746.7571-2-mlevitsk@redhat.com> In-Reply-To: <20190415135746.7571-1-mlevitsk@redhat.com> References: <20190415135746.7571-1-mlevitsk@redhat.com> 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.46]); Mon, 15 Apr 2019 13:57:52 +0000 (UTC) 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] [PATCH 1/5] block/nvme: don't flip CQ phase bits 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: Fam Zheng , Kevin Wolf , Max Reitz , qemu-devel@nongnu.org, Maxim Levitsky Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Phase bits are only set by the hardware to indicate new completions and not by the device driver. Signed-off-by: Maxim Levitsky --- block/nvme.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 0684bbd077..2d208000df 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -340,8 +340,6 @@ static bool nvme_process_completion(BDRVNVMeState *s, N= VMeQueuePair *q) 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.17.2 From nobody Thu Mar 28 23:22:51 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=1555336794; cv=none; d=zoho.com; s=zohoarc; b=LKLywwMjkhtMo/lmtArSWbZlfbxX1G+bjmLTVW0sTjCmz5hDdDdvycjaiFmnyQothhci4aVycTGxS0Na9Z/Qq/Z+II6jYlKQq7S55DR1gTkrIJVx0khqTL7JGniQBbdy1TGKe1K4R4iDFeJIHxXb7NpFJ8qqWqN4ZJAoE+WWg5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555336794; 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:ARC-Authentication-Results; bh=48PRL0uDcAkPlo9Zgc+lEMs3oanqMBSqMsPCzze73xY=; b=V98vWvFDww0V8CbIB6eMoCNczmsqYYz2UOj985f8zLLdhwT4zYUZ59DNWRYqShp//jS5Th5Fgk5EstvVCIkz+/y8TejpXcpGQLfmpgZBN/V0xA7+freAIuW7yYguv8Auube00BoqZahpDAimrvNC0bAM96ZrUZqpmIMYO1v7DbU= 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 1555336794974197.91494568171288; Mon, 15 Apr 2019 06:59:54 -0700 (PDT) Received: from localhost ([127.0.0.1]:50621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hG29E-0006Bw-Kg for importer@patchew.org; Mon, 15 Apr 2019 09:59:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hG27U-00055s-84 for qemu-devel@nongnu.org; Mon, 15 Apr 2019 09:58:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hG27T-0007xl-D3 for qemu-devel@nongnu.org; Mon, 15 Apr 2019 09:58:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40458) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hG27R-0007uV-B3; Mon, 15 Apr 2019 09:57:57 -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 C8D94308FC4D; Mon, 15 Apr 2019 13:57:54 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EEB81001DE8; Mon, 15 Apr 2019 13:57:52 +0000 (UTC) From: Maxim Levitsky To: qemu-block@nongnu.org Date: Mon, 15 Apr 2019 16:57:43 +0300 Message-Id: <20190415135746.7571-3-mlevitsk@redhat.com> In-Reply-To: <20190415135746.7571-1-mlevitsk@redhat.com> References: <20190415135746.7571-1-mlevitsk@redhat.com> 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.43]); Mon, 15 Apr 2019 13:57:54 +0000 (UTC) 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] [PATCH 2/5] block/nvme: fix doorbell stride 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: Fam Zheng , Kevin Wolf , Max Reitz , qemu-devel@nongnu.org, Maxim Levitsky Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Fix the math involving non standard doorbell stride Signed-off-by: Maxim Levitsky --- block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/nvme.c b/block/nvme.c index 2d208000df..208242cf1f 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -216,7 +216,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.17.2 From nobody Thu Mar 28 23:22:51 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=1555337000; cv=none; d=zoho.com; s=zohoarc; b=Nc0JyiKNwBXrDis80QFnsqA89X8Re2aEeeBksmaUwZWOc0MSDM+o4/9IaR/eD8xMmmGQPhyknbcNJ6emlzhHgAWNsKzgwNaICZK5dV4ssV/n85qzCFiIcBLBpCv66gxVq4exHbnH30RZQzgTep/rInnRSMdmMNEn+jAiiwjetMw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555337000; 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:ARC-Authentication-Results; bh=rfCD1ofiLj+l5pZpEN0VQJN0SUR9YSPXDtFQ8GcjgIk=; b=XTYwrQUqIil68YAPF7/8lRge6xjrIjOEu+T8IuQ6ExHvlRqMHszbQVvJU6pw26vWSICWcvyL5TTQbEH3VO5J6SF1/BSQS/1No6zr9KPbtRLpU41yAWWjhkTCccSEOGIv5ioBtfEbue+S5ZIXRdbCbyzuwnR/JvKhUBM/HZysI8Q= 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 1555337000315827.2813504359149; Mon, 15 Apr 2019 07:03:20 -0700 (PDT) Received: from localhost ([127.0.0.1]:50690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hG2Ca-0000CA-Cr for importer@patchew.org; Mon, 15 Apr 2019 10:03:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hG27U-00056R-V4 for qemu-devel@nongnu.org; Mon, 15 Apr 2019 09:58:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hG27T-0007yH-V7 for qemu-devel@nongnu.org; Mon, 15 Apr 2019 09:58:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40486) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hG27R-0007vX-HG; Mon, 15 Apr 2019 09:57:57 -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 CB7A53092645; Mon, 15 Apr 2019 13:57:56 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 301311001DE8; Mon, 15 Apr 2019 13:57:54 +0000 (UTC) From: Maxim Levitsky To: qemu-block@nongnu.org Date: Mon, 15 Apr 2019 16:57:44 +0300 Message-Id: <20190415135746.7571-4-mlevitsk@redhat.com> In-Reply-To: <20190415135746.7571-1-mlevitsk@redhat.com> References: <20190415135746.7571-1-mlevitsk@redhat.com> 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.43]); Mon, 15 Apr 2019 13:57:56 +0000 (UTC) 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] [PATCH 3/5] block/nvme: support larger that 512 bytes sector devices 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: Fam Zheng , Kevin Wolf , Max Reitz , qemu-devel@nongnu.org, Maxim Levitsky Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently the driver hardcodes the sector size to 512, and doesn't check the underlying device Signed-off-by: Maxim Levitsky --- block/nvme.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 208242cf1f..0d9b521760 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -101,8 +101,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 @@ -415,8 +418,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, @@ -463,7 +467,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[idns->flbas & 0x0f]; + + 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_BITS || 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); @@ -782,8 +801,17 @@ 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 int nvme_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz) +{ + BDRVNVMeState *s =3D bs->opaque; + assert(s->blkshift >=3D 9); + bsz->phys =3D 1 << s->blkshift; + bsz->log =3D 1 << s->blkshift; + return 0; } =20 /* Called with s->dma_map_lock */ @@ -914,13 +942,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 { @@ -1151,6 +1180,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.17.2 From nobody Thu Mar 28 23:22:51 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=1555337071; cv=none; d=zoho.com; s=zohoarc; b=OHueEVz9EHtv/igdXlbUK7EcrFxM3BwmQa4E5Hrup8NxBrU7P702dBBbRrDiFih0RWEMoxwAm+iMQp+i+iwO8Jwdy6yiHdUt5dVXEr22u1SB9ZQFg0TkovnXDE6YnDsl4CNNn8jjL5NBRBuNMEtK+9DacOnVIFy1mxewtEUBufk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555337071; 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:ARC-Authentication-Results; bh=jt6zLgJvoiXvECJUfknIDBIi7tihjB4rqfBKu8EPVUM=; b=JdyUvtO+OGtzfSziV6afGKWySaoElRwo5Tdbleh46TJRUBY3JkrX+3cn+BQyggU6nsHRmnRx20ZC13rPDvLg754NWMqn/GBPuQNWLfZ46iuNvOPc673DbLprnVXj4HlbYNm+72u9E8oBsmlg8rgQg3qYLH/onExcUMLynlCb6Fo= 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 1555337071634205.40989793517122; Mon, 15 Apr 2019 07:04:31 -0700 (PDT) Received: from localhost ([127.0.0.1]:50698 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hG2Dm-0000qK-NB for importer@patchew.org; Mon, 15 Apr 2019 10:04:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hG27X-0005A9-S2 for qemu-devel@nongnu.org; Mon, 15 Apr 2019 09:58:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hG27W-0007zw-Ku for qemu-devel@nongnu.org; Mon, 15 Apr 2019 09:58:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52022) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hG27T-0007xQ-Jg; Mon, 15 Apr 2019 09:57:59 -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 CD4C1307D869; Mon, 15 Apr 2019 13:57:58 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 311ED108F83F; Mon, 15 Apr 2019 13:57:57 +0000 (UTC) From: Maxim Levitsky To: qemu-block@nongnu.org Date: Mon, 15 Apr 2019 16:57:45 +0300 Message-Id: <20190415135746.7571-5-mlevitsk@redhat.com> In-Reply-To: <20190415135746.7571-1-mlevitsk@redhat.com> References: <20190415135746.7571-1-mlevitsk@redhat.com> 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.48]); Mon, 15 Apr 2019 13:57:58 +0000 (UTC) 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] [PATCH 4/5] block/nvme: add support for write zeros 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: Fam Zheng , Kevin Wolf , Max Reitz , qemu-devel@nongnu.org, Maxim Levitsky Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Maxim Levitsky --- block/nvme.c | 69 +++++++++++++++++++++++++++++++++++++++++++- block/trace-events | 1 + include/block/nvme.h | 17 ++++++++++- 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 0d9b521760..5121e809f0 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -109,6 +109,8 @@ typedef struct { uint64_t max_transfer; bool plugged; =20 + bool supports_write_zeros; + CoMutex dma_map_lock; CoQueue dma_flush_queue; =20 @@ -457,6 +459,10 @@ static void nvme_identify(BlockDriverState *bs, int na= mespace, Error **errp) s->max_transfer =3D MIN_NON_ZERO(s->max_transfer, s->page_size / sizeof(uint64_t) * s->page_size); =20 + + + s->supports_write_zeros =3D (idctrl->oncs & NVME_ONCS_WRITE_ZEROS) != =3D 0; + memset(resp, 0, 4096); =20 cmd.cdw10 =3D 0; @@ -469,6 +475,11 @@ static void nvme_identify(BlockDriverState *bs, int na= mespace, Error **errp) s->nsze =3D le64_to_cpu(idns->nsze); lbaf =3D &idns->lbaf[idns->flbas & 0x0f]; =20 + if (NVME_ID_NS_DLFEAT_DALLOC_WZEROS(idns->dlfeat) && + NVME_ID_NS_DLFEAT_READ_BEHAVIER(idns->dlfeat) =3D=3D + NVME_ID_NS_DLFEAT_READ_BEHAVIER_ZEROS) + bs->supported_write_flags |=3D BDRV_REQ_MAY_UNMAP; + if (lbaf->ms) { error_setg(errp, "Namespaces with metadata are not yet supported"); goto out; @@ -763,6 +774,8 @@ static int nvme_file_open(BlockDriverState *bs, QDict *= options, int flags, int ret; BDRVNVMeState *s =3D bs->opaque; =20 + bs->supported_write_flags =3D BDRV_REQ_FUA; + opts =3D qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &error_abort); device =3D qemu_opt_get(opts, NVME_BLOCK_OPT_DEVICE); @@ -791,7 +804,6 @@ static int nvme_file_open(BlockDriverState *bs, QDict *= options, int flags, goto fail; } } - bs->supported_write_flags =3D BDRV_REQ_FUA; return 0; fail: nvme_close(bs); @@ -1080,6 +1092,58 @@ static coroutine_fn int nvme_co_flush(BlockDriverSta= te *bs) } =20 =20 +static coroutine_fn int nvme_co_pwrite_zeroes(BlockDriverState *bs, + int64_t offset, int bytes, BdrvRequestFlags flags) +{ + BDRVNVMeState *s =3D bs->opaque; + NVMeQueuePair *ioq =3D s->queues[1]; + NVMeRequest *req; + + if (!s->supports_write_zeros) { + return -ENOTSUP; + } + + uint32_t cdw12 =3D ((bytes >> s->blkshift) - 1) & 0xFFFF; + + NvmeCmd cmd =3D { + .opcode =3D NVME_CMD_WRITE_ZEROS, + .nsid =3D cpu_to_le32(s->nsid), + .cdw10 =3D cpu_to_le32((offset >> s->blkshift) & 0xFFFFFFFF), + .cdw11 =3D cpu_to_le32(((offset >> s->blkshift) >> 32) & 0xFFFFFFF= F), + }; + + NVMeCoData data =3D { + .ctx =3D bdrv_get_aio_context(bs), + .ret =3D -EINPROGRESS, + }; + + if (flags & BDRV_REQ_MAY_UNMAP) { + cdw12 |=3D (1 << 25); + } + + if (flags & BDRV_REQ_FUA) { + cdw12 |=3D (1 << 30); + } + + cmd.cdw12 =3D cpu_to_le32(cdw12); + + trace_nvme_write_zeros(s, offset, bytes, flags); + assert(s->nr_queues > 1); + req =3D nvme_get_free_req(ioq); + assert(req); + + nvme_submit_command(s, ioq, req, &cmd, nvme_rw_cb, &data); + + data.co =3D qemu_coroutine_self(); + while (data.ret =3D=3D -EINPROGRESS) { + qemu_coroutine_yield(); + } + + trace_nvme_rw_done(s, true, offset, bytes, data.ret); + return data.ret; +} + + static int nvme_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp) { @@ -1184,6 +1248,9 @@ static BlockDriver bdrv_nvme =3D { =20 .bdrv_co_preadv =3D nvme_co_preadv, .bdrv_co_pwritev =3D nvme_co_pwritev, + + .bdrv_co_pwrite_zeroes =3D nvme_co_pwrite_zeroes, + .bdrv_co_flush_to_disk =3D nvme_co_flush, .bdrv_reopen_prepare =3D nvme_reopen_prepare, =20 diff --git a/block/trace-events b/block/trace-events index 7335a42540..943a58569f 100644 --- a/block/trace-events +++ b/block/trace-events @@ -144,6 +144,7 @@ nvme_submit_command_raw(int c0, int c1, int c2, int c3,= int c4, int c5, int c6, nvme_handle_event(void *s) "s %p" nvme_poll_cb(void *s) "s %p" nvme_prw_aligned(void *s, int is_write, uint64_t offset, uint64_t bytes, i= nt flags, int niov) "s %p is_write %d offset %"PRId64" bytes %"PRId64" flag= s %d niov %d" +nvme_write_zeros(void *s, uint64_t offset, uint64_t bytes, int flags) "s %= p offset %"PRId64" bytes %"PRId64" flags %d" nvme_qiov_unaligned(const void *qiov, int n, void *base, size_t size, int = align) "qiov %p n %d base %p size 0x%zx align 0x%x" nvme_prw_buffered(void *s, uint64_t offset, uint64_t bytes, int niov, int = is_write) "s %p offset %"PRId64" bytes %"PRId64" niov %d is_write %d" nvme_rw_done(void *s, int is_write, uint64_t offset, uint64_t bytes, int r= et) "s %p is_write %d offset %"PRId64" bytes %"PRId64" ret %d" diff --git a/include/block/nvme.h b/include/block/nvme.h index 0eae6f9f15..f625aefd3b 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -653,12 +653,27 @@ typedef struct NvmeIdNs { uint8_t mc; uint8_t dpc; uint8_t dps; - uint8_t res30[98]; + + uint8_t nmic; + uint8_t rescap; + uint8_t fpi; + uint8_t dlfeat; + + uint8_t res30[94]; NvmeLBAF lbaf[16]; uint8_t res192[192]; uint8_t vs[3712]; } NvmeIdNs; =20 +#define NVME_ID_NS_DLFEAT_GUARD_CRC(dlfeat) ((dlfeat) & 0x10) +#define NVME_ID_NS_DLFEAT_DALLOC_WZEROS(dlfeat) ((dlfeat) & 0x04) + +#define NVME_ID_NS_DLFEAT_READ_BEHAVIER(dlfeat) ((dlfeat) & 0x3) +#define NVME_ID_NS_DLFEAT_READ_BEHAVIER_UNDEFINED 0 +#define NVME_ID_NS_DLFEAT_READ_BEHAVIER_ZEROS 1 +#define NVME_ID_NS_DLFEAT_READ_BEHAVIER_ONES 2 + + #define NVME_ID_NS_NSFEAT_THIN(nsfeat) ((nsfeat & 0x1)) #define NVME_ID_NS_FLBAS_EXTENDED(flbas) ((flbas >> 4) & 0x1) #define NVME_ID_NS_FLBAS_INDEX(flbas) ((flbas & 0xf)) --=20 2.17.2 From nobody Thu Mar 28 23:22:51 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=1555336817; cv=none; d=zoho.com; s=zohoarc; b=YveYVftVITRUV4B/lDqWrqEeDjYPISKbNS2aHuSjV1yTPSsRjCYi/3FiQs7Hscqel5rXnZYgWvi6pbxia/r+VFzj+jJmjdKlVGYDhGBYTUUTOmiGKJZOYXlfJ1CeHtC07xTso+hIHdEgwm595f5AJWmbEwmrGXdGEgF79elPLsg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555336817; 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:ARC-Authentication-Results; bh=pP5Xe7qowmxX5op+mJSQkl5vLLwmp0FtmYXLvH9SIo4=; b=SeZS7/Fwg7Xj51c69nHhEy2FeAogWfmrCj0afb3d15WgHCIVt2ecnjnYhp7lYURwQyamge5MDKXqGI7nh4RXEDsMmQ/VbB3/dO5EI3Ti+CDc8XY/H6Vc4JDRxBbvYhW5zNrJk57gdRN0P0ZEqOR6AWbqbo6yvAQHjgsn2CxmClI= 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 1555336817553734.2891008915293; Mon, 15 Apr 2019 07:00:17 -0700 (PDT) Received: from localhost ([127.0.0.1]:50624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hG29V-0006QY-GW for importer@patchew.org; Mon, 15 Apr 2019 10:00:05 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hG27e-0005EY-1q for qemu-devel@nongnu.org; Mon, 15 Apr 2019 09:58:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hG27c-00082H-Ua for qemu-devel@nongnu.org; Mon, 15 Apr 2019 09:58:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59416) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hG27a-00081B-E4; Mon, 15 Apr 2019 09:58:06 -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 A56AE19CBF7; Mon, 15 Apr 2019 13:58:05 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 323701001E85; Mon, 15 Apr 2019 13:57:59 +0000 (UTC) From: Maxim Levitsky To: qemu-block@nongnu.org Date: Mon, 15 Apr 2019 16:57:46 +0300 Message-Id: <20190415135746.7571-6-mlevitsk@redhat.com> In-Reply-To: <20190415135746.7571-1-mlevitsk@redhat.com> References: <20190415135746.7571-1-mlevitsk@redhat.com> 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.29]); Mon, 15 Apr 2019 13:58:05 +0000 (UTC) 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] [PATCH 5/5] block/nvme: add support for discard 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: Fam Zheng , Kevin Wolf , Max Reitz , qemu-devel@nongnu.org, Maxim Levitsky Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Maxim Levitsky --- block/nvme.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ block/trace-events | 2 ++ 2 files changed, 83 insertions(+) diff --git a/block/nvme.c b/block/nvme.c index 5121e809f0..386c2508b7 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -110,6 +110,7 @@ typedef struct { bool plugged; =20 bool supports_write_zeros; + bool supports_discard; =20 CoMutex dma_map_lock; CoQueue dma_flush_queue; @@ -462,6 +463,7 @@ static void nvme_identify(BlockDriverState *bs, int nam= espace, Error **errp) =20 =20 s->supports_write_zeros =3D (idctrl->oncs & NVME_ONCS_WRITE_ZEROS) != =3D 0; + s->supports_discard =3D (idctrl->oncs & NVME_ONCS_DSM) !=3D 0; =20 memset(resp, 0, 4096); =20 @@ -1144,6 +1146,83 @@ static coroutine_fn int nvme_co_pwrite_zeroes(BlockD= riverState *bs, } =20 =20 +static int coroutine_fn nvme_co_pdiscard(BlockDriverState *bs, + int64_t offset, int bytes) +{ + BDRVNVMeState *s =3D bs->opaque; + NVMeQueuePair *ioq =3D s->queues[1]; + NVMeRequest *req; + NvmeDsmRange *buf; + QEMUIOVector local_qiov; + int r; + + NvmeCmd cmd =3D { + .opcode =3D NVME_CMD_DSM, + .nsid =3D cpu_to_le32(s->nsid), + .cdw10 =3D 0, /*number of ranges - 0 based*/ + .cdw11 =3D cpu_to_le32(1 << 2), /*deallocate bit*/ + }; + + NVMeCoData data =3D { + .ctx =3D bdrv_get_aio_context(bs), + .ret =3D -EINPROGRESS, + }; + + if (!s->supports_discard) { + return -ENOTSUP; + } + + assert(s->nr_queues > 1); + + buf =3D qemu_try_blockalign0(bs, 4096); + if (!buf) { + return -ENOMEM; + } + + buf->nlb =3D bytes >> s->blkshift; + buf->slba =3D offset >> s->blkshift; + buf->cattr =3D 0; + + qemu_iovec_init(&local_qiov, 1); + qemu_iovec_add(&local_qiov, buf, 4096); + + req =3D nvme_get_free_req(ioq); + assert(req); + + qemu_co_mutex_lock(&s->dma_map_lock); + r =3D nvme_cmd_map_qiov(bs, &cmd, req, &local_qiov); + qemu_co_mutex_unlock(&s->dma_map_lock); + + if (r) { + req->busy =3D false; + return r; + } + + trace_nvme_dsm(s, offset, bytes); + + nvme_submit_command(s, ioq, req, &cmd, nvme_rw_cb, &data); + + data.co =3D qemu_coroutine_self(); + while (data.ret =3D=3D -EINPROGRESS) { + qemu_coroutine_yield(); + } + + qemu_co_mutex_lock(&s->dma_map_lock); + r =3D nvme_cmd_unmap_qiov(bs, &local_qiov); + qemu_co_mutex_unlock(&s->dma_map_lock); + if (r) { + return r; + } + + trace_nvme_dsm_done(s, offset, bytes, data.ret); + + qemu_iovec_destroy(&local_qiov); + qemu_vfree(buf); + return data.ret; + +} + + static int nvme_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp) { @@ -1250,6 +1329,8 @@ static BlockDriver bdrv_nvme =3D { .bdrv_co_pwritev =3D nvme_co_pwritev, =20 .bdrv_co_pwrite_zeroes =3D nvme_co_pwrite_zeroes, + .bdrv_co_pdiscard =3D nvme_co_pdiscard, + =20 .bdrv_co_flush_to_disk =3D nvme_co_flush, .bdrv_reopen_prepare =3D nvme_reopen_prepare, diff --git a/block/trace-events b/block/trace-events index 943a58569f..e55ac5c40b 100644 --- a/block/trace-events +++ b/block/trace-events @@ -148,6 +148,8 @@ nvme_write_zeros(void *s, uint64_t offset, uint64_t byt= es, int flags) "s %p offs nvme_qiov_unaligned(const void *qiov, int n, void *base, size_t size, int = align) "qiov %p n %d base %p size 0x%zx align 0x%x" nvme_prw_buffered(void *s, uint64_t offset, uint64_t bytes, int niov, int = is_write) "s %p offset %"PRId64" bytes %"PRId64" niov %d is_write %d" nvme_rw_done(void *s, int is_write, uint64_t offset, uint64_t bytes, int r= et) "s %p is_write %d offset %"PRId64" bytes %"PRId64" ret %d" +nvme_dsm(void *s, uint64_t offset, uint64_t bytes) "s %p offset %"PRId64" = bytes %"PRId64"" +nvme_dsm_done(void *s, uint64_t offset, uint64_t bytes, int ret) "s %p off= set %"PRId64" bytes %"PRId64" ret %d" nvme_dma_map_flush(void *s) "s %p" nvme_free_req_queue_wait(void *q) "q %p" nvme_cmd_map_qiov(void *s, void *cmd, void *req, void *qiov, int entries) = "s %p cmd %p req %p qiov %p entries %d" --=20 2.17.2