From nobody Thu May 16 14:35:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600705800; cv=none; d=zohomail.com; s=zohoarc; b=B7VaLyGb8khrN09t/2Jdpi8EpdO9AMd/U7wqx6zmeg6FEsBYtWfRaH2AYZmtwdYhEqBPNtIiBCbP2j5/U9uLjtTuAnhaaf/TeZceB0mXymEtXdO2QS8lSZNNSBpS69J+vPd+tkSvbSJajsbpJFnZcnRwAJss/LaAUyIqTFFA5xk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600705800; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=xGl0Wf6pnfWpWYSfHB9A49lGc8kjUq8riXJkPMG2AM8=; b=mMpgzqE5+A9J5FnKoa9D+Mnjk1TG6yAbQRsJuXw1fpv/ec1WoaBKMkhcbdn6M/kv8ug+IOhRVGKLWQsONEcxA2pmj/LgNbHEy0LawNlmzS6l0qcLE4aIRLAJ7MT1DKlyHKSmiNSyCH5J/jOApgXxtnNUdgUWZP8NuMN3CWjU2P0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1600705800953741.5059483020715; Mon, 21 Sep 2020 09:30:00 -0700 (PDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-374-Z-_8AZHFPduyy37KoFClLg-1; Mon, 21 Sep 2020 12:29:57 -0400 Received: by mail-wr1-f70.google.com with SMTP id g6so6109850wrv.3 for ; Mon, 21 Sep 2020 09:29:57 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id a10sm121077wmj.38.2020.09.21.09.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 09:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600705799; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xGl0Wf6pnfWpWYSfHB9A49lGc8kjUq8riXJkPMG2AM8=; b=c6U15YCzw7EoctljkEbFDKfmX2sU02VuIQ6Vvqs8E3wu09JNr1R1LB9xXO0fwPfwSbph3/ oKst1jU9TXT/JmOkFyzYNVCemaOAsiy9Fb5y3igY2f9begFS+4G7yJYCR6u7NrKdks6Zx0 DS4ItitR1pYBmxx0myFuWvULhZ0JfUg= X-MC-Unique: Z-_8AZHFPduyy37KoFClLg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xGl0Wf6pnfWpWYSfHB9A49lGc8kjUq8riXJkPMG2AM8=; b=GjTaAdIdHxEUcWdPUZuqmLp1v615IoutVmdY7jkck1TykcNiy40I+cxNHvpQYzS5fR EtHyYS8hvNt6NBnywocqcnPpDLFqTRS5UQ3fwcXy0UGg72CmX24gvmtdm0HKx8y46yZm 8abl+NEz3FpUCmZGxDUaXC6MBU0PgtVfC/8sK69S47h/2WCsVsuO/+5eW7hvrZaG3/1W Z8rBH+3Oxvsi697wqBo/4ShXF6MsQs3BXwx19Eb7lrZD1p4qDm9M5ycNuzt+n25nG1o0 VViwyjIPrRZvDZooLDIgqm2QB9tb6N1Xdyq5MRxA6EzRWffCUHTqgjES3dkVp+nh9JO8 wPsg== X-Gm-Message-State: AOAM533Ftctku0HMFgkp/Slwe7KXOFxmkYtT6Rw7Fp/JJbkRN2O1ldh7 LkB4Ggv72H2Lkla1ByQY4koLp9TU5hBpcvEQVJStjP8yhPxlFCVl0G0AdYKLfFIPvlXbmj83nlH fUB3ceXgz6vWqPQ== X-Received: by 2002:a1c:4455:: with SMTP id r82mr228886wma.60.1600705796043; Mon, 21 Sep 2020 09:29:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+X4qczrV8ZTksRXbP87bPX8afhBXnDWPugb4xP9pK2qLFT5NFEKPwXpKjD/aYHZSvXphTvw== X-Received: by 2002:a1c:4455:: with SMTP id r82mr228868wma.60.1600705795863; Mon, 21 Sep 2020 09:29:55 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Kevin Wolf , Max Reitz , qemu-block@nongnu.org, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 1/6] util/vfio-helpers: Pass page protections to qemu_vfio_pci_map_bar() Date: Mon, 21 Sep 2020 18:29:44 +0200 Message-Id: <20200921162949.553863-2-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200921162949.553863-1-philmd@redhat.com> References: <20200921162949.553863-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Pages are currently mapped READ/WRITE. To be able to use different protections, add a new argument to qemu_vfio_pci_map_bar(). Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/vfio-helpers.h | 2 +- block/nvme.c | 3 ++- util/vfio-helpers.c | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/qemu/vfio-helpers.h b/include/qemu/vfio-helpers.h index 1f057c2b9e4..4491c8e1a6e 100644 --- a/include/qemu/vfio-helpers.h +++ b/include/qemu/vfio-helpers.h @@ -22,7 +22,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_= t size, int qemu_vfio_dma_reset_temporary(QEMUVFIOState *s); void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host); void *qemu_vfio_pci_map_bar(QEMUVFIOState *s, int index, - uint64_t offset, uint64_t size, + uint64_t offset, uint64_t size, int prot, Error **errp); void qemu_vfio_pci_unmap_bar(QEMUVFIOState *s, int index, void *bar, uint64_t offset, uint64_t size); diff --git a/block/nvme.c b/block/nvme.c index f4f27b6da7d..5a4dc6a722a 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -712,7 +712,8 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, goto out; } =20 - s->regs =3D qemu_vfio_pci_map_bar(s->vfio, 0, 0, NVME_BAR_SIZE, errp); + s->regs =3D qemu_vfio_pci_map_bar(s->vfio, 0, 0, NVME_BAR_SIZE, + PROT_READ | PROT_WRITE, errp); if (!s->regs) { ret =3D -EINVAL; goto out; diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 583bdfb36fc..9ac307e3d42 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -146,13 +146,13 @@ static int qemu_vfio_pci_init_bar(QEMUVFIOState *s, i= nt index, Error **errp) * Map a PCI bar area. */ void *qemu_vfio_pci_map_bar(QEMUVFIOState *s, int index, - uint64_t offset, uint64_t size, + uint64_t offset, uint64_t size, int prot, Error **errp) { void *p; assert_bar_index_valid(s, index); p =3D mmap(NULL, MIN(size, s->bar_region_info[index].size - offset), - PROT_READ | PROT_WRITE, MAP_SHARED, + prot, MAP_SHARED, s->device, s->bar_region_info[index].offset + offset); if (p =3D=3D MAP_FAILED) { error_setg_errno(errp, errno, "Failed to map BAR region"); --=20 2.26.2 From nobody Thu May 16 14:35:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600705807; cv=none; d=zohomail.com; s=zohoarc; b=FdKFDQIeqFcA8apac0Xhwjmi73iLjyy5sdbKqOWk9bDqtlqDYa8K4V4GF0jqtU6lUv2Z2iAd44Jc9JrUMvDla+81b+XMRdPRMVPzNTijb3UwYbkO0Y+6N8XUdhqXvT7i3XXQm70f5MdMby2Aux9d6P7VVeuAOD5NKUvktIPBp10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600705807; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=sZC6xa6hR7fJNx1ScYKH1kNh8OmwESP7iiqvw8pbcT0=; b=R8XtKUpnyYRYSRxaVefllcB9VMMlz7KDdSiKdT6XZtcBzvnTRjS36GHDmMQ8Cb7oxAWHcPQkDG0XQRk24O/x2FfafiBwNCvt6/486t6NitqqySvZwcP3PrUyT8BzGc8owtHuEDySTehFVfTI2qrh+bpqaiGA08S2SpAEMTXGqlg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1600705807710257.6546690378659; Mon, 21 Sep 2020 09:30:07 -0700 (PDT) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-242-Z8PO-zUAMlSNQkO52tp0Sw-1; Mon, 21 Sep 2020 12:30:02 -0400 Received: by mail-wr1-f72.google.com with SMTP id 33so6069646wrk.12 for ; Mon, 21 Sep 2020 09:30:02 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id y1sm127613wma.36.2020.09.21.09.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 09:30:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600705806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sZC6xa6hR7fJNx1ScYKH1kNh8OmwESP7iiqvw8pbcT0=; b=ZscTVDyJeCns2gjiTv5GJqZbeGLAK5fLqAlo3xxmcnV6cCMiSUQs2qKmd1cIBNjcUkSnza 6ifI3TiPYcztj5rWKc7giTcwg3JzACJzRYjRtIeclbwqX4BkE6r3jp/otsKzJNFzDT/sEz PtNwbogGQ/Niz2IqL/eiIboFYzWrDMY= X-MC-Unique: Z8PO-zUAMlSNQkO52tp0Sw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sZC6xa6hR7fJNx1ScYKH1kNh8OmwESP7iiqvw8pbcT0=; b=taRlAV0Owma1lwKUofMfsJVMQi5jsfosvyMOjyocdhNPM5zRxTGNlfp91oO9szsqeN i57+Xx5x+ht9RchL9REy54s7CKTpfmJpceJxh5LH1M7jUmORTsctqfGv99QkkS41jMJN 644u/SSybL4XmiR4nTL0bw2pacycKO4VCsvPRW9GIGPi/dSnhyl7dD/bS+HKEKBFplZS /doz4CydXZ4TIL3BD18ipV5f/Qv+tNvBC/qIMlqnK8Eyt1sEP6Kw35+y82B7FzSGmgJw 6H5etV9VA4I+VzQDmjJg1dh78RGydUjMBN6m/nO3y5r9cGK+Gt0Vd7n4ATYe3flp/mej R2SQ== X-Gm-Message-State: AOAM531hTsJ450pxRhqfLuxVNL+AvI2NBER3LSDGy1R4mk9BVMY3mABp w/kvk+yqxgHxA2SHOwV31ucKyVT/djRzBSvbrUA9kl9JaenOFhi80KFA2C9je2A04TmTORUhipC 4qtBpJkr56SFi0A== X-Received: by 2002:a7b:c959:: with SMTP id i25mr197185wml.39.1600705801474; Mon, 21 Sep 2020 09:30:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNS1UUWMCMi5dN+C53zPVnHzJVRbDkldI4yGh41Hj0IqRxHo0OfxT7hN44z4Ta/Ssr8zP9Zg== X-Received: by 2002:a7b:c959:: with SMTP id i25mr197162wml.39.1600705801250; Mon, 21 Sep 2020 09:30:01 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Kevin Wolf , Max Reitz , qemu-block@nongnu.org, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 2/6] block/nvme: Map doorbells pages write-only Date: Mon, 21 Sep 2020 18:29:45 +0200 Message-Id: <20200921162949.553863-3-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200921162949.553863-1-philmd@redhat.com> References: <20200921162949.553863-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Per the datasheet sections 3.1.13/3.1.14: "The host should not read the doorbell registers." As we don't need read access, map the doorbells with write-only permission. We keep a reference to this mapped address in the BDRVNVMeState structure. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 5a4dc6a722a..3c834da8fec 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -31,7 +31,7 @@ #define NVME_SQ_ENTRY_BYTES 64 #define NVME_CQ_ENTRY_BYTES 16 #define NVME_QUEUE_SIZE 128 -#define NVME_BAR_SIZE 8192 +#define NVME_DOORBELL_SIZE 4096 =20 /* * We have to leave one slot empty as that is the full queue case where @@ -84,10 +84,6 @@ typedef struct { /* Memory mapped registers */ typedef volatile struct { NvmeBar ctrl; - struct { - uint32_t sq_tail; - uint32_t cq_head; - } doorbells[]; } NVMeRegs; =20 #define INDEX_ADMIN 0 @@ -103,6 +99,11 @@ struct BDRVNVMeState { AioContext *aio_context; QEMUVFIOState *vfio; NVMeRegs *regs; + /* Memory mapped registers */ + volatile struct { + uint32_t sq_tail; + uint32_t cq_head; + } *doorbells; /* The submission/completion queue pairs. * [0]: admin queue. * [1..]: io queues. @@ -247,14 +248,14 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMe= State *s, error_propagate(errp, local_err); goto fail; } - q->sq.doorbell =3D &s->regs->doorbells[idx * s->doorbell_scale].sq_tai= l; + q->sq.doorbell =3D &s->doorbells[idx * s->doorbell_scale].sq_tail; =20 nvme_init_queue(s, &q->cq, size, NVME_CQ_ENTRY_BYTES, &local_err); if (local_err) { error_propagate(errp, local_err); goto fail; } - q->cq.doorbell =3D &s->regs->doorbells[idx * s->doorbell_scale].cq_hea= d; + q->cq.doorbell =3D &s->doorbells[idx * s->doorbell_scale].cq_head; =20 return q; fail: @@ -712,13 +713,12 @@ static int nvme_init(BlockDriverState *bs, const char= *device, int namespace, goto out; } =20 - s->regs =3D qemu_vfio_pci_map_bar(s->vfio, 0, 0, NVME_BAR_SIZE, + s->regs =3D qemu_vfio_pci_map_bar(s->vfio, 0, 0, sizeof(NvmeBar), PROT_READ | PROT_WRITE, errp); if (!s->regs) { ret =3D -EINVAL; goto out; } - /* Perform initialize sequence as described in NVMe spec "7.6.1 * Initialization". */ =20 @@ -748,6 +748,13 @@ static int nvme_init(BlockDriverState *bs, const char = *device, int namespace, } } =20 + s->doorbells =3D qemu_vfio_pci_map_bar(s->vfio, 0, sizeof(NvmeBar), + NVME_DOORBELL_SIZE, PROT_WRITE, e= rrp); + if (!s->doorbells) { + ret =3D -EINVAL; + goto out; + } + /* Set up admin queue. */ s->queues =3D g_new(NVMeQueuePair *, 1); s->queues[INDEX_ADMIN] =3D nvme_create_queue_pair(s, aio_context, 0, @@ -873,7 +880,9 @@ static void nvme_close(BlockDriverState *bs) &s->irq_notifier[MSIX_SHARED_IRQ_IDX], false, NULL, NULL); event_notifier_cleanup(&s->irq_notifier[MSIX_SHARED_IRQ_IDX]); - qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE); + qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->doorbells, + sizeof(NvmeBar), NVME_DOORBELL_SIZE); + qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, sizeof(NvmeBar= )); qemu_vfio_close(s->vfio); =20 g_free(s->device); --=20 2.26.2 From nobody Thu May 16 14:35:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600705812; cv=none; d=zohomail.com; s=zohoarc; b=CjROPpX3H3dfYijheqaToRnynVKXF5wCFaUKFAAjYoJkGP8gh246pKy2s4OmDtaXdXan9OiNJUjxbEf93Z7rha0EZy8xlVRUejmiCZY6dkzyVma7y+pFNS153iq/+oFRli3xGKC8G2suNiuqry6GMksAuN3X3/JLQzitfaXn140= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600705812; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=w3VSohO81qj1Qy9GMUYU8rCdXvyUaEcpLhj6tPxRG5I=; b=W6PtDR7KEWFx6vuAxb4wGVlmsYpN+nM0sb5APfM0PWIj6rUnfFdQW22wVS2dSsChZPCsBrpVDGqUJDvOExXW3gqLp54DJs7Mw3x21ljcDt+HjkT7wwJbr9Tm47k1N6+ZEciaJNF6sZnlHCsBCMWCGjZGAkc+D6DjYzJ565iKHx8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1600705812745241.37082740418327; Mon, 21 Sep 2020 09:30:12 -0700 (PDT) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-373-QTFAsNPcNravg2qHlIzAEA-1; Mon, 21 Sep 2020 12:30:07 -0400 Received: by mail-wm1-f72.google.com with SMTP id r10so172212wmh.0 for ; Mon, 21 Sep 2020 09:30:07 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id c4sm22477296wrp.85.2020.09.21.09.30.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 09:30:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600705811; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w3VSohO81qj1Qy9GMUYU8rCdXvyUaEcpLhj6tPxRG5I=; b=FEfiBlN+hmGU9ysVWNegYuWrvEmJ23wMUtkZ7OOQTLU0oa/ghSu1GKE+oOUt9tnpeDQvxF ujGGXdtYBE6tmpUO5DUFSPAks832ErtUEV03o8kPgIFHIDcLnv0Mcpb+C7Gfw2hd64z2/E ncPrVjRJnmtfXk3tbCOheHYO4V3i4Qw= X-MC-Unique: QTFAsNPcNravg2qHlIzAEA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w3VSohO81qj1Qy9GMUYU8rCdXvyUaEcpLhj6tPxRG5I=; b=njyYYkzCIVvJGiRKyHGAVdmkv3LdPKWYcYVqghWfSFHbFV0HrCKg5mxcA3xAG0p5ZK rdlR9uwUOqljJYsZeBMr6sgn5BIIL/N+QY2ovcWo6Keq78R5aScvuT4sidrrRAQGFhP8 X0DcYMYKvJjz8W5pPRmxTDbkwpj0RNc79RvuFGbnCSneFTkycdNDDynEksusahKzItaO Ohn4vgXP73pLQmLzdCT2NZsg69YIGAHSOEARvgd5ADI9isvuGwsztH6bGolGaZymTBCG VEeG1mAbKxFeXNXT23Mcd9QW+JfFt8uyaMakmurLClqZsCOUkOcuSDZTnA4ff082bmvr zkDg== X-Gm-Message-State: AOAM533F9o4xl4QPVtJCmBiDRDWkOOTT9TWGjtHAnyGEKBEGDYLw5APP SCoLxHbWiCx3Ys9s2y3QLnibnupFDEZ2VpKhmhritZM2kX0CxTFbyuvj0Qe4Onpvjyn+XbHNKPo XBAXv1fNIk1Mb3w== X-Received: by 2002:adf:fa02:: with SMTP id m2mr563555wrr.273.1600705806549; Mon, 21 Sep 2020 09:30:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuDGMPIjXlDaa/Q2cAnMtwWTcDs/LdCrlPAtloxT7TwCerzSsyfhCE1mhYxu9hvZLyV2rIhw== X-Received: by 2002:adf:fa02:: with SMTP id m2mr563529wrr.273.1600705806306; Mon, 21 Sep 2020 09:30:06 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Kevin Wolf , Max Reitz , qemu-block@nongnu.org, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 3/6] block/nvme: Reduce I/O registers scope Date: Mon, 21 Sep 2020 18:29:46 +0200 Message-Id: <20200921162949.553863-4-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200921162949.553863-1-philmd@redhat.com> References: <20200921162949.553863-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) We only access the I/O register in nvme_init(). Remove the reference in BDRVNVMeState and reduce its scope. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 3c834da8fec..e517c7539ff 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -98,7 +98,6 @@ enum { struct BDRVNVMeState { AioContext *aio_context; QEMUVFIOState *vfio; - NVMeRegs *regs; /* Memory mapped registers */ volatile struct { uint32_t sq_tail; @@ -695,6 +694,7 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, uint64_t timeout_ms; uint64_t deadline, now; Error *local_err =3D NULL; + NVMeRegs *regs; =20 qemu_co_mutex_init(&s->dma_map_lock); qemu_co_queue_init(&s->dma_flush_queue); @@ -713,16 +713,16 @@ static int nvme_init(BlockDriverState *bs, const char= *device, int namespace, goto out; } =20 - s->regs =3D qemu_vfio_pci_map_bar(s->vfio, 0, 0, sizeof(NvmeBar), - PROT_READ | PROT_WRITE, errp); - if (!s->regs) { + regs =3D qemu_vfio_pci_map_bar(s->vfio, 0, 0, sizeof(NvmeBar), + PROT_READ | PROT_WRITE, errp); + if (!regs) { ret =3D -EINVAL; goto out; } /* Perform initialize sequence as described in NVMe spec "7.6.1 * Initialization". */ =20 - cap =3D le64_to_cpu(s->regs->ctrl.cap); + cap =3D le64_to_cpu(regs->ctrl.cap); if (!(cap & (1ULL << 37))) { error_setg(errp, "Device doesn't support NVMe command set"); ret =3D -EINVAL; @@ -735,10 +735,10 @@ static int nvme_init(BlockDriverState *bs, const char= *device, int namespace, timeout_ms =3D MIN(500 * ((cap >> 24) & 0xFF), 30000); =20 /* Reset device to get a clean state. */ - s->regs->ctrl.cc =3D cpu_to_le32(le32_to_cpu(s->regs->ctrl.cc) & 0xFE); + regs->ctrl.cc =3D cpu_to_le32(le32_to_cpu(regs->ctrl.cc) & 0xFE); /* Wait for CSTS.RDY =3D 0. */ deadline =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + timeout_ms * SCA= LE_MS; - while (le32_to_cpu(s->regs->ctrl.csts) & 0x1) { + while (le32_to_cpu(regs->ctrl.csts) & 0x1) { if (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) > deadline) { error_setg(errp, "Timeout while waiting for device to reset (%" PRId64 " ms)", @@ -766,18 +766,18 @@ static int nvme_init(BlockDriverState *bs, const char= *device, int namespace, } s->nr_queues =3D 1; QEMU_BUILD_BUG_ON(NVME_QUEUE_SIZE & 0xF000); - s->regs->ctrl.aqa =3D cpu_to_le32((NVME_QUEUE_SIZE << 16) | NVME_QUEUE= _SIZE); - s->regs->ctrl.asq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->sq.iova); - s->regs->ctrl.acq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->cq.iova); + regs->ctrl.aqa =3D cpu_to_le32((NVME_QUEUE_SIZE << 16) | NVME_QUEUE_SI= ZE); + regs->ctrl.asq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->sq.iova); + regs->ctrl.acq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->cq.iova); =20 /* After setting up all control registers we can enable device now. */ - s->regs->ctrl.cc =3D cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << 20) | + regs->ctrl.cc =3D cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << 20) | (ctz32(NVME_SQ_ENTRY_BYTES) << 16) | 0x1); /* Wait for CSTS.RDY =3D 1. */ now =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); deadline =3D now + timeout_ms * 1000000; - while (!(le32_to_cpu(s->regs->ctrl.csts) & 0x1)) { + while (!(le32_to_cpu(regs->ctrl.csts) & 0x1)) { if (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) > deadline) { error_setg(errp, "Timeout while waiting for device to start (%" PRId64 " ms)", @@ -808,6 +808,10 @@ static int nvme_init(BlockDriverState *bs, const char = *device, int namespace, ret =3D -EIO; } out: + if (regs) { + qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)regs, 0, sizeof(NvmeBa= r)); + } + /* Cleaning up is done in nvme_file_open() upon error. */ return ret; } @@ -882,7 +886,6 @@ static void nvme_close(BlockDriverState *bs) event_notifier_cleanup(&s->irq_notifier[MSIX_SHARED_IRQ_IDX]); qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->doorbells, sizeof(NvmeBar), NVME_DOORBELL_SIZE); - qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, sizeof(NvmeBar= )); qemu_vfio_close(s->vfio); =20 g_free(s->device); --=20 2.26.2 From nobody Thu May 16 14:35:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600705818; cv=none; d=zohomail.com; s=zohoarc; b=WH4QczbgSok2exGZM1kH+03Ogq0AgIW0sWH9AFFk4oHa78DNWh+55UqV8R5Qut4yUfu1MP8WJddjxErAmwUjjfeRmtMjst6hXjGZ7nf0z0LkCIR/DOhZ0Bj0P+XZEZ0aKmtWDSNBdZaNhO9/5ytlMgpOYTN07D0lDUrDKFxqLG4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600705818; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=FMAxBBU4xA4hxywxEtXVcIMFGGDQnTZkLrdHa6P7weY=; b=bSchPBJi/fb7Z/BMIqGOAUKbQQqS9HYTx5zeHsBpRI6trasphkJgF0E6n/hpB1STB98WlKM3+wYt5mTRCyZ1KF4/z57l+LtJW1DJj2zB7NaqTTcRoWY8JQJB95eSt+gOztKBjNEQ4uDo/cVUJHC9869sIC9RjsTwqhiFK48wtUc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1600705818730420.92376274578; Mon, 21 Sep 2020 09:30:18 -0700 (PDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-500-w1s0jctVP_qbr8tjSIlQkA-1; Mon, 21 Sep 2020 12:30:13 -0400 Received: by mail-wr1-f69.google.com with SMTP id a10so6045479wrw.22 for ; Mon, 21 Sep 2020 09:30:12 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id m10sm177258wmi.9.2020.09.21.09.30.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 09:30:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600705817; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FMAxBBU4xA4hxywxEtXVcIMFGGDQnTZkLrdHa6P7weY=; b=TPJ+yNxcXWcIJj6yPOqphztaNwk6gZKB4yIjXjgKidZZf2gO555PD9wzsjJ4Xlx+hhvEVy glw7LUOj8wAWkTN7mVk64tJRkFaC6f5VjgG1UBli+lrmCRJjU3GB6Z5G6XAcP3UG29SkQN e3FpWK+DDCHht6GAy55Bg9P17Wkq0KM= X-MC-Unique: w1s0jctVP_qbr8tjSIlQkA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FMAxBBU4xA4hxywxEtXVcIMFGGDQnTZkLrdHa6P7weY=; b=pb2DOpWzNLGKZPPCAjM7VI4AEOGoPmY/gS2cUH/jYOk9UgM7uYGLTQOIwSNfrWhQGU sO3DD9i4dG+Y6xQC8DpQiZZ6c0JHyQh0Sle4yBL1D9R8K6bZGsOfBIWpHpL0/gijVVWw uw36Ka+qIGVbMYkQit16oPIQLont9ck6LQY8RlGRN4YaG7DBWATnSRyen7Q+dy19dYge qzfSFjGtAtVagMw9bKESWfcNISp57N7ByCbb+94KLoE6MpPPQqsHCX5a0XAC2kG7WC8x pVRGL+ock+KxWPcwzbpa6U/eWzJkMX3sNWXIo4Sb6NAr1nUd9D2sjXyw0LiewWQ7QoXz 8I8A== X-Gm-Message-State: AOAM53150vhhOnoalYizWOXySHUbfAeAPYqoE4c43VCH40VROX6pBMW5 9IcqS+adfojt3SIs+6I9T5MIVYmCC0f25PfxSlWLkczYOrPQL/5A18r3LOkxJ//Wb7FLo+vrKyJ 0fIxzIr/nwDC6uw== X-Received: by 2002:a7b:cf1a:: with SMTP id l26mr201510wmg.164.1600705811740; Mon, 21 Sep 2020 09:30:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKHKSmbEWFYlkMpEA9JJFVzHCJ6N5zFm4+VCgrxwIR4eGdI5IH/F1V3OEA/63qAmkNBHfM2w== X-Received: by 2002:a7b:cf1a:: with SMTP id l26mr201487wmg.164.1600705811494; Mon, 21 Sep 2020 09:30:11 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Kevin Wolf , Max Reitz , qemu-block@nongnu.org, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 4/6] block/nvme: Drop NVMeRegs structure, directly use NvmeBar Date: Mon, 21 Sep 2020 18:29:47 +0200 Message-Id: <20200921162949.553863-5-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200921162949.553863-1-philmd@redhat.com> References: <20200921162949.553863-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) NVMeRegs only contains NvmeBar. Simplify the code by using NvmeBar directly. This triggers a checkpatch.pl error: ERROR: Use of volatile is usually wrong, please add a comment #30: FILE: block/nvme.c:691: + volatile NvmeBar *regs; This is a false positive as in our case we are using I/O registers, so the 'volatile' use is justified. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index e517c7539ff..83bae6b2f13 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -81,11 +81,6 @@ typedef struct { QEMUBH *completion_bh; } NVMeQueuePair; =20 -/* Memory mapped registers */ -typedef volatile struct { - NvmeBar ctrl; -} NVMeRegs; - #define INDEX_ADMIN 0 #define INDEX_IO(n) (1 + n) =20 @@ -694,7 +689,7 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, uint64_t timeout_ms; uint64_t deadline, now; Error *local_err =3D NULL; - NVMeRegs *regs; + volatile NvmeBar *regs; =20 qemu_co_mutex_init(&s->dma_map_lock); qemu_co_queue_init(&s->dma_flush_queue); @@ -722,7 +717,7 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, /* Perform initialize sequence as described in NVMe spec "7.6.1 * Initialization". */ =20 - cap =3D le64_to_cpu(regs->ctrl.cap); + cap =3D le64_to_cpu(regs->cap); if (!(cap & (1ULL << 37))) { error_setg(errp, "Device doesn't support NVMe command set"); ret =3D -EINVAL; @@ -735,10 +730,10 @@ static int nvme_init(BlockDriverState *bs, const char= *device, int namespace, timeout_ms =3D MIN(500 * ((cap >> 24) & 0xFF), 30000); =20 /* Reset device to get a clean state. */ - regs->ctrl.cc =3D cpu_to_le32(le32_to_cpu(regs->ctrl.cc) & 0xFE); + regs->cc =3D cpu_to_le32(le32_to_cpu(regs->cc) & 0xFE); /* Wait for CSTS.RDY =3D 0. */ deadline =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + timeout_ms * SCA= LE_MS; - while (le32_to_cpu(regs->ctrl.csts) & 0x1) { + while (le32_to_cpu(regs->csts) & 0x1) { if (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) > deadline) { error_setg(errp, "Timeout while waiting for device to reset (%" PRId64 " ms)", @@ -766,18 +761,18 @@ static int nvme_init(BlockDriverState *bs, const char= *device, int namespace, } s->nr_queues =3D 1; QEMU_BUILD_BUG_ON(NVME_QUEUE_SIZE & 0xF000); - regs->ctrl.aqa =3D cpu_to_le32((NVME_QUEUE_SIZE << 16) | NVME_QUEUE_SI= ZE); - regs->ctrl.asq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->sq.iova); - regs->ctrl.acq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->cq.iova); + regs->aqa =3D cpu_to_le32((NVME_QUEUE_SIZE << 16) | NVME_QUEUE_SIZE); + regs->asq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->sq.iova); + regs->acq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->cq.iova); =20 /* After setting up all control registers we can enable device now. */ - regs->ctrl.cc =3D cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << 20) | + regs->cc =3D cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << 20) | (ctz32(NVME_SQ_ENTRY_BYTES) << 16) | 0x1); /* Wait for CSTS.RDY =3D 1. */ now =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); deadline =3D now + timeout_ms * 1000000; - while (!(le32_to_cpu(regs->ctrl.csts) & 0x1)) { + while (!(le32_to_cpu(regs->csts) & 0x1)) { if (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) > deadline) { error_setg(errp, "Timeout while waiting for device to start (%" PRId64 " ms)", --=20 2.26.2 From nobody Thu May 16 14:35:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600705821; cv=none; d=zohomail.com; s=zohoarc; b=l56nPvplXDmIAEl2PSTOU9Zfw1x66DH7UghGSdPnNMRFknlZi+4GGlMz44V0//V4wTqCFWPaNYv5MxQ8SZTIX8xB6ySlL8g1oZouYbgYFRznJOrg7B/5hODc8m24rfuL8jrI8WZNd2sKMtJRONjCRgPuWxvgjCxj2fKQg2MbSS0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600705821; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=+vspmClAclQUpTq3+aAb1q9Vz9LFQ93oZxnmdQ7/mR4=; b=OGQYptPohTywLejfB06rMwKenrQq/mTg3Zyvv8UVDcK7BcDbqOOHAi0midMPR41ktS2Boos9T7GS14WNqE5rOT3ox7OyqNQboexLbfx18XF94CA8M+1aC/IRBuPnu7Okk35HaG/b9MZ14qeFVaAmK/SsEZ8FwZn2lJAJ/1ORbY8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1600705821977771.3774806098858; Mon, 21 Sep 2020 09:30:21 -0700 (PDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-150-2bsRrTjcPgK26qhRz1YGRA-1; Mon, 21 Sep 2020 12:30:18 -0400 Received: by mail-wr1-f70.google.com with SMTP id a10so6045587wrw.22 for ; Mon, 21 Sep 2020 09:30:18 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id i26sm176802wmb.17.2020.09.21.09.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 09:30:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600705820; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+vspmClAclQUpTq3+aAb1q9Vz9LFQ93oZxnmdQ7/mR4=; b=LXj0i4P5qS2x4ZilSEXFT1yLpxZpIU1Rm+RMXNvAy3soDioEBlb5oyHWCuruNMRZK6Lb0p MQ6zZtZjiqa4idM8UXh8vNXGhkm6i5fxQ/rtSxCYeNgdJqU7YPmH8IKZO1q/gbykNOJ9/S Odo0+jhMVAxu9qaXbFPJ8xYve/lwduo= X-MC-Unique: 2bsRrTjcPgK26qhRz1YGRA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+vspmClAclQUpTq3+aAb1q9Vz9LFQ93oZxnmdQ7/mR4=; b=MvUTQHTIIApaT9SBgJFZJ/TQKXMqvNDGY8cmDnp/oMyePd9IlO1S/9WTPBGHHnB35m jO4YOlOAeCxHh3eb2eTALPIGobmVCDl017aArtmwjBSbvGwZuWRoMfY8JtB16en6TekZ 0CEIRaTdJdF8IGfqV632/C2JSWv3ES4BS+CnXnR5mkQvLdkrMHc4Po9dJbNUV3xdjcj+ SkHICzj6LbWHvhVAruVhUrxxQRwt8nT0Jq1QCcFHSCJvIe5Ap8kAmTV3HvU4nyKHFUP7 JCNszQljQAI5x290Gx7F0Chf1ggDD9wf/Xafh5Gl44FelilXIIbRmatNW4Ti7A8ukULe 4nAA== X-Gm-Message-State: AOAM531FFTTQU74M3ZXZcMtqDF0dVA+syr5dsbuurCPjY2zMU6Le6eJR zBPUl2ybhUel4nkFkAHxvx4EeZ+pWEw1m7UUC4QRZLKwH1OehFD2RKngwT4EhsnjVCLg1geVdRX FB6+mr3W/o2/VBw== X-Received: by 2002:adf:dfc3:: with SMTP id q3mr593402wrn.238.1600705816978; Mon, 21 Sep 2020 09:30:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBe1lBO1v5Fdq7q+orSp7/mnoAJSOSkMPj14A7yw18rRjFNDh6xsmA4Sgc37fKjk3U9q2nbw== X-Received: by 2002:adf:dfc3:: with SMTP id q3mr593379wrn.238.1600705816798; Mon, 21 Sep 2020 09:30:16 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Kevin Wolf , Max Reitz , qemu-block@nongnu.org, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 5/6] block/nvme: Use register definitions from 'block/nvme.h' Date: Mon, 21 Sep 2020 18:29:48 +0200 Message-Id: <20200921162949.553863-6-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200921162949.553863-1-philmd@redhat.com> References: <20200921162949.553863-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Use the NVMe register definitions from "block/nvme.h" which ease a bit reviewing the code while matching the datasheet. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 83bae6b2f13..d18e897c7c9 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -718,22 +718,22 @@ static int nvme_init(BlockDriverState *bs, const char= *device, int namespace, * Initialization". */ =20 cap =3D le64_to_cpu(regs->cap); - if (!(cap & (1ULL << 37))) { + if (!NVME_CAP_CSS(cap)) { error_setg(errp, "Device doesn't support NVMe command set"); ret =3D -EINVAL; goto out; } =20 - s->page_size =3D MAX(4096, 1 << (12 + ((cap >> 48) & 0xF))); - s->doorbell_scale =3D (4 << (((cap >> 32) & 0xF))) / sizeof(uint32_t); + s->page_size =3D MAX(4096, 1 << NVME_CAP_MPSMIN(cap)); + s->doorbell_scale =3D (4 << NVME_CAP_DSTRD(cap)) / sizeof(uint32_t); bs->bl.opt_mem_alignment =3D s->page_size; - timeout_ms =3D MIN(500 * ((cap >> 24) & 0xFF), 30000); + timeout_ms =3D MIN(500 * NVME_CAP_TO(cap), 30000); =20 /* Reset device to get a clean state. */ regs->cc =3D cpu_to_le32(le32_to_cpu(regs->cc) & 0xFE); /* Wait for CSTS.RDY =3D 0. */ deadline =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + timeout_ms * SCA= LE_MS; - while (le32_to_cpu(regs->csts) & 0x1) { + while (NVME_CSTS_RDY(le32_to_cpu(regs->csts))) { if (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) > deadline) { error_setg(errp, "Timeout while waiting for device to reset (%" PRId64 " ms)", @@ -761,18 +761,19 @@ static int nvme_init(BlockDriverState *bs, const char= *device, int namespace, } s->nr_queues =3D 1; QEMU_BUILD_BUG_ON(NVME_QUEUE_SIZE & 0xF000); - regs->aqa =3D cpu_to_le32((NVME_QUEUE_SIZE << 16) | NVME_QUEUE_SIZE); + regs->aqa =3D cpu_to_le32((NVME_QUEUE_SIZE << AQA_ACQS_SHIFT) | + (NVME_QUEUE_SIZE << AQA_ASQS_SHIFT)); regs->asq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->sq.iova); regs->acq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->cq.iova); =20 /* After setting up all control registers we can enable device now. */ - regs->cc =3D cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << 20) | - (ctz32(NVME_SQ_ENTRY_BYTES) << 16) | - 0x1); + regs->cc =3D cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << CC_IOCQES_SHIF= T) | + (ctz32(NVME_SQ_ENTRY_BYTES) << CC_IOSQES_SHIFT)= | + CC_EN_MASK); /* Wait for CSTS.RDY =3D 1. */ now =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); deadline =3D now + timeout_ms * 1000000; - while (!(le32_to_cpu(regs->csts) & 0x1)) { + while (!NVME_CSTS_RDY(le32_to_cpu(regs->csts))) { if (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) > deadline) { error_setg(errp, "Timeout while waiting for device to start (%" PRId64 " ms)", --=20 2.26.2 From nobody Thu May 16 14:35:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600705828; cv=none; d=zohomail.com; s=zohoarc; b=V8ZE8Yw7+ArpCJYqm6ftip3b8tU7Svw4vXoHWSDIc8obukC9+BKHxCl4oXHdZ6K3fJxBlObuRbb44rObZi4yHm91L5DFnohCXs9EjqOSsSM9xaNq71v6qHeohR+pJTI+BUFf5AZsPxg8FT5uRahczTwEgxmr21AnN6BbVlRSnuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600705828; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=VFUnGI39xPjzTrYSbqi9ooQfeOOci8dGNYXdLQ1TjBg=; b=Kfun3NU6mjSOOow4v0kdQ9NzzHM+Yl0B8xuoFP9AQMGkxhjjqenNUMch2YLEagI+MQ3kCqegsPbqY4qtWBwxzebJN4oKOk5pCQHidpihVMDdsXgQU1u11AuQIILbE0cqR/J9YNTR8ifvAuEzHVPiwzQUpsbMuxK2gGK+RhxYxys= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1600705828800956.364893678713; Mon, 21 Sep 2020 09:30:28 -0700 (PDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-553-VcOrPvdHP6WoATq1oeR3Wg-1; Mon, 21 Sep 2020 12:30:23 -0400 Received: by mail-wr1-f70.google.com with SMTP id x15so6047955wrm.7 for ; Mon, 21 Sep 2020 09:30:23 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id f12sm148215wmf.26.2020.09.21.09.30.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 09:30:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600705827; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VFUnGI39xPjzTrYSbqi9ooQfeOOci8dGNYXdLQ1TjBg=; b=DrhBdkI1nYZcLgyzpIkfAwV/zlK45I1yBRxDhg8TKRxgaKQlQGBP+mymptMtCYflkd7gZE 5SZDl8bcOtTTPgR9HPfd/7dEaQtILtuRIaZQEskEfabHXy5j7moXDk5tepx8c1Om/zN9la kjXNG6jpKkc9914x8dynXiQEEyykUyU= X-MC-Unique: VcOrPvdHP6WoATq1oeR3Wg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VFUnGI39xPjzTrYSbqi9ooQfeOOci8dGNYXdLQ1TjBg=; b=mGmNAcQAhu1sjLgEfah+g430Iv7TLTN6fGHpkWy6P6faQQD435irF49u1RpaabT0vJ U+egd5K8sbE9X7x+pTwE5pqtnL7XChHmCXY7eLdb/t3MLpQ7K9ty6iCXb825qfOxYV8z wFOPHB7NRCHpY6qWz6d3E2zyy4LRY7t3/zeh05VDJZvIr8fb/XGLG8dIEOGLxYdfRfAD Mnv/uFxPX3+LDRHchyU/6gWPkEszeVOYptvbwWuXkh4Nac/lznn+LT6eXfm0UvR5HZu8 ah3yrMwzUg23S2bhNQSeRo1etZnol07FmevQ9+3+hoUcy313H9mulpMtw9xp1CLhrWCC NSWQ== X-Gm-Message-State: AOAM532Hz2HSxqfr0fgND6PLhXDUGuhUDcQg+FQuX3lO4ygERKEHvvbX bSgE0G5AwLkmPp8EqzYOZhpAYBMRXwzUbEtjhq+AW4jD0ZnWf/YGXASRDpcxDUd9OXRcjXaY+EQ odg028puGhknglA== X-Received: by 2002:a1c:6484:: with SMTP id y126mr167561wmb.177.1600705822499; Mon, 21 Sep 2020 09:30:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqAMnvvzX7KRFUB9AMMq50VEuwDyDmX1j4JarJc9ypAQHEYr/rthZ9b2cqS3DipFFGazQQIA== X-Received: by 2002:a1c:6484:: with SMTP id y126mr167544wmb.177.1600705822362; Mon, 21 Sep 2020 09:30:22 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Kevin Wolf , Max Reitz , qemu-block@nongnu.org, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 6/6] block/nvme: Replace magic value by SCALE_MS definition Date: Mon, 21 Sep 2020 18:29:49 +0200 Message-Id: <20200921162949.553863-7-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200921162949.553863-1-philmd@redhat.com> References: <20200921162949.553863-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Use self-explicit SCALE_MS definition instead of magic value (missed in similar commit e4f310fe7f5). Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/nvme.c b/block/nvme.c index d18e897c7c9..b3dab1c4610 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -772,7 +772,7 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, CC_EN_MASK); /* Wait for CSTS.RDY =3D 1. */ now =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); - deadline =3D now + timeout_ms * 1000000; + deadline =3D now + timeout_ms * SCALE_MS; while (!NVME_CSTS_RDY(le32_to_cpu(regs->csts))) { if (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) > deadline) { error_setg(errp, "Timeout while waiting for device to start (%" --=20 2.26.2