From nobody Sun May 19 06:23:13 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=1563294662; cv=none; d=zoho.com; s=zohoarc; b=fgd7sWSqEuRs1fyaVoerqI2x6mgZsQs2gZVXZJzqeFFIVdfV837LzzSMMwqmIWJpXgHoffIUjYWmrR/awHSkmB7y7dofRIGdEiTvkvoc2xuGNobgWGSPX59ybcxczkGpIU/pVkZ66yOiSk/XI+5pMFuSWAj19NHPlIgr1bwbZ5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563294662; 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=sPMYa6LhDIOo83oZeZiikAfg2eaIQfK6iiVo3NY93oU=; b=gzCqmA1oZfA1VrdsqJ7WAMbcBlcwr6XIjXygNomQBrauh460o/vogHGvhw/36D2YRHOC6HYAzYmJtknbuhtpmaZHVuB9irHCmbpCYzwEOhhaPqrtrLZ5bzPEFGvMnVeXJwdulOfX7ausvVlbjCfAefdZ9xw0F/GK1lnVmZW01VE= 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 1563294662108559.1273986873647; Tue, 16 Jul 2019 09:31:02 -0700 (PDT) Received: from localhost ([::1]:51048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnQM0-0005H1-P6 for importer@patchew.org; Tue, 16 Jul 2019 12:31:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52872) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnQLa-0003uk-35 for qemu-devel@nongnu.org; Tue, 16 Jul 2019 12:30:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnQLZ-0001z5-5t for qemu-devel@nongnu.org; Tue, 16 Jul 2019 12:30:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36366) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnQLW-0001w4-Qa; Tue, 16 Jul 2019 12:30:30 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 183F1307D847; Tue, 16 Jul 2019 16:30:30 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4791C61781; Tue, 16 Jul 2019 16:30:26 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Date: Tue, 16 Jul 2019 19:30:18 +0300 Message-Id: <20190716163020.13383-2-mlevitsk@redhat.com> In-Reply-To: <20190716163020.13383-1-mlevitsk@redhat.com> References: <20190716163020.13383-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 16 Jul 2019 16:30:30 +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 v4 1/3] 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: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Max Reitz , Paolo Bonzini , Maxim Levitsky , John Snow 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 Reviewed-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.17.2 From nobody Sun May 19 06:23:13 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=1563294695; cv=none; d=zoho.com; s=zohoarc; b=DQ/n1wAGCh2+RPQqZnRypZ7VMgeTY9r4ak3+BAUOPY2x/SoOk/jJd10KQVsbXPjwMQ7ksMBI2RxblbciBsFXClmR6dhOqNg91efHDC+NiL4xtfDCdA9iSi2EZY5RJciJf9hVy/1qC2lRelvGwznKhc+NM6BT5nO9BXHJmC06n8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563294695; 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=W4nJIZ7lQfZ0SQBwbUVyLXIhAKMusnCyQ5MkDypFLas=; b=iS/HIXSkRywrDxunTTtiSmTgrE+R6eVYYRMe5HPReDt+npaMfZkd4d4TWJ2opJyNnyC0y0GcHF39dAkEk0rdrepJAdcTclOlDf30tlYnTrz4cvukyaVaWI/N1WNTPHtocJvUr9b0JBcZ743RUx/MC8WN97JTL/Y4hO7CbEaJEFE= 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 1563294695925675.4198312760977; Tue, 16 Jul 2019 09:31:35 -0700 (PDT) Received: from localhost ([::1]:51068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnQMX-0007SP-ST for importer@patchew.org; Tue, 16 Jul 2019 12:31:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52904) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnQLd-00047V-2Y for qemu-devel@nongnu.org; Tue, 16 Jul 2019 12:30:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnQLb-00020V-UC for qemu-devel@nongnu.org; Tue, 16 Jul 2019 12:30:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59418) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnQLZ-0001yo-55; Tue, 16 Jul 2019 12:30:33 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74FE53082129; Tue, 16 Jul 2019 16:30:32 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C8AF5C28D; Tue, 16 Jul 2019 16:30:30 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Date: Tue, 16 Jul 2019 19:30:19 +0300 Message-Id: <20190716163020.13383-3-mlevitsk@redhat.com> In-Reply-To: <20190716163020.13383-1-mlevitsk@redhat.com> References: <20190716163020.13383-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 16 Jul 2019 16:30:32 +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 v4 2/3] 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: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Max Reitz , Paolo Bonzini , Maxim Levitsky , John Snow 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. Fix that. Also fail if underlying nvme device is formatted with metadata as this needs special support. Signed-off-by: Maxim Levitsky --- 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.17.2 From nobody Sun May 19 06:23:13 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=1563294689; cv=none; d=zoho.com; s=zohoarc; b=juOpU6d3oaCyW/gUw8cv1invYbEGpPOmxoIvn8g0uPiP4JmSIpQodaik60y1B0URDU6OEdPvG8DJK95DBHa3rAb+d8LKFF6xW9o0CxFAR8RuogyZxfhzZpsLhxfb7iZyJCcyqGDfP9iTcGQyRioXlVexZmylrgtn3Yk8AMXgwUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563294689; 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=OLSdDY0qjjz2XBnF4YS5kEiDn2hDZSUXn6Em4DQ7YRI=; b=VpqkHew62S7L6bpBwE7gayl7Ck3Iqk03Eq/0nl8wXSY3rBfMtcg82QSxW8ufU/39/5XaxQcViMHW9nzNLVj4jiTbvApMkqrPSJwrZKTyrLTC31Ch8Wmt3x/DZU2zeDRAen9gKi6GXDjrV7b6eQ/vZF0MfSp5ysrjn1TLLnm4B+w= 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 15632946891270.7809518771807689; Tue, 16 Jul 2019 09:31:29 -0700 (PDT) Received: from localhost ([::1]:51066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnQMR-000743-SH for importer@patchew.org; Tue, 16 Jul 2019 12:31:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52936) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnQLg-0004JA-2q for qemu-devel@nongnu.org; Tue, 16 Jul 2019 12:30:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnQLf-00021f-2S for qemu-devel@nongnu.org; Tue, 16 Jul 2019 12:30:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52842) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnQLc-00020b-KG; Tue, 16 Jul 2019 12:30:36 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7556285AE; Tue, 16 Jul 2019 16:30:35 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC65C5C28D; Tue, 16 Jul 2019 16:30:32 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Date: Tue, 16 Jul 2019 19:30:20 +0300 Message-Id: <20190716163020.13383-4-mlevitsk@redhat.com> In-Reply-To: <20190716163020.13383-1-mlevitsk@redhat.com> References: <20190716163020.13383-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 16 Jul 2019 16:30:35 +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 v4 3/3] 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: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Max Reitz , Paolo Bonzini , Maxim Levitsky , John Snow 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" 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 --- 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.17.2