From nobody Sun May 5 19:55:35 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=1600763913; cv=none; d=zohomail.com; s=zohoarc; b=lHWy1pSAT7IXo8f83HdpyPVasLEbEKPwxi46zuqb7Y3wrODJinxjAXmVngS09KZuh8m8kOfym/OutpPobLiX7FV1KmX4QIiAFETmUqFq7vwDTDBkRym4vRPpJzKnruANGucq3ljuTbqNyrah9r/h4vTGa8diAoaR+ixtKgkE+pU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600763913; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=xGl0Wf6pnfWpWYSfHB9A49lGc8kjUq8riXJkPMG2AM8=; b=EmydSoOsNcEIcH0XiKfXw2wJrW/fGNq2PPKGy1G4VvxLo6ROUkP0kCZubSVvBtUpOq9GGfsbhs33aqbF5pysTsR86vJD9n0bYfnVgO/PM37KfyRI8p0SztReQyrqsQIjXiH0C7HyoLrgUB/1jDzU4CLgCNyjK9lH7RRkUjRDO4E= 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 1600763913204898.1296163559388; Tue, 22 Sep 2020 01:38:33 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-561-pys2GlcKPyy9ElQBYWqKzA-1; Tue, 22 Sep 2020 04:38:30 -0400 Received: by mail-wm1-f70.google.com with SMTP id t10so382963wmi.9 for ; Tue, 22 Sep 2020 01:38:30 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id i83sm3541626wma.22.2020.09.22.01.38.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 01:38:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600763912; 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=dQaptuIU0GNJ65rR2chV9Z9R4c4kaCFVQexLeTJhTJJlJC21reUrnGW5yMmQZjJ+OyIFZV b/rJEEz944r1j+J/J7DheRatRUZyKQpnylrTAdphNTiZshjplRXaHzgPDONJ26od2Eqq8o rCoT67OrJvBXbcN/5rL8MsqPYwYsUlw= X-MC-Unique: pys2GlcKPyy9ElQBYWqKzA-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=NuuxnbJsQwvmERYExcMrFKoqttV1bcaVOYwxKqM+geT3e4fyRXYdTjlRGFJnykGQ6Y gXkomTBEhjYU1wMIIIa5rf1zkV7+oJXYiwtr1W8q3MzXqhBI/IhqJEPX2pAIvSevBmpD 57mvR/+50MsuViwWjTHRzqU5MY2YdvP2R2wS94duObEk34ZNV3r+0cNVp79JeyFw2942 C9OkiPBGFNyMdKCdK+rVCiqKmerH0Biz53bMR98VPKvT2Qo8MHUCWMl0nZWYKeMBI6ei +RIHoBZbElsEhEawaNxx2u1HtqQj+bgcvaSVgAdxvLbC/WTXhgPmzlg5t4BiZAKmMnG6 nzLg== X-Gm-Message-State: AOAM530UM6MAqZ6nnz0LucRTRHPICxjgT7sePXm3cP/z4wSry1ltBlAa ugk8oUi1eHv2KNFs6ddgkEm8a2VlWy2gLHbYdfBf8MOekoviPaoebVYpQL7U6TUowJNRcLrhKcg 0a065zgS5Wa9RPQ== X-Received: by 2002:a05:600c:4149:: with SMTP id h9mr3316538wmm.86.1600763909478; Tue, 22 Sep 2020 01:38:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQLofMZAoDPTa2aZvcFu29fhUcwukrKKrzgPM8+1ptGSVoTwwZnHD0D9289WJpCJRdzF5n3g== X-Received: by 2002:a05:600c:4149:: with SMTP id h9mr3316519wmm.86.1600763909260; Tue, 22 Sep 2020 01:38:29 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stefan Hajnoczi Cc: Fam Zheng , Max Reitz , qemu-block@nongnu.org, Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 1/6] util/vfio-helpers: Pass page protections to qemu_vfio_pci_map_bar() Date: Tue, 22 Sep 2020 10:38:16 +0200 Message-Id: <20200922083821.578519-2-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200922083821.578519-1-philmd@redhat.com> References: <20200922083821.578519-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 Reviewed-by: Fam Zheng --- 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 Sun May 5 19:55:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1600763918; cv=none; d=zohomail.com; s=zohoarc; b=lZd1QCp7IF7DvOgQLLGNAXsJs6TcE16yzmJUAxbpnaRaMrEpTEdtovrDsVYhzC5qiIv39oXjL0/wmLk8l38tivj6eHLvPer5ttKqTulzTvKzw+aaE/K4jujel3ZZYDou8px1Gxt6VxdbDpkUh/3v7BjeCjgXLzeAT7SCMD94110= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600763918; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=sZC6xa6hR7fJNx1ScYKH1kNh8OmwESP7iiqvw8pbcT0=; b=Rt/j90Mo48EvjQbq005YnGcCpQg9I5ATdNa2TMS4xBp/Hc9mA3Waht63UspAwCf/XQ+5apo/NBzxzhVwNfkFtd7Op7/m+wyuCgBGXlL8hQ9GkpznsBo5NsxTsOzzRKd3w1c2cF1EftFobOilzWfd0MZUZhTQlD+tcYtT/fZnLgk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1600763918711930.0025674240587; Tue, 22 Sep 2020 01:38:38 -0700 (PDT) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-177-vpywCAq7OS-f5Gy9p7dSWQ-1; Tue, 22 Sep 2020 04:38:35 -0400 Received: by mail-wm1-f69.google.com with SMTP id m19so622388wmg.6 for ; Tue, 22 Sep 2020 01:38:35 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id a81sm3632300wmf.32.2020.09.22.01.38.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 01:38:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600763917; 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=bQyl4px+ZbSm+U0BWxogLbdPLeJUB8NVvYQccAL5s9iieYZUKasg0gwUEn7JPWXL0V72W4 xWqaBM/hlicd2g+90WwIIzwMTXQW70eCHaKKdEEbCfiFhiTQknQHS6Rd+pWSx08TReQp+y 4lsvfgbmw+jGow0VTPznb3xTJzpkBUM= X-MC-Unique: vpywCAq7OS-f5Gy9p7dSWQ-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=XukdGIKlaMnBdHvj4MWjkfyxuc4l33CbXi+TxyV5sFdLFnrkcFrHP4U+EMnE0614nc X1NJoyLkg+eiXsEtDuCjK8WAuj7EH7uiZDGiR7cXSqUrTyIMLuqwCax2BaaXVrIq/rqH ri+Z58T9Ku/lGYt1v4fNAfbLrs6NbKmWsYjVgbCh8jG8FPpN8l1YPz1Vtu30MUCy3XaQ Y3c0HJKUOq7Kf4525Yq2fCctCalJB91xLFBKG5yvvhoE+xbAqoaTk4gMWuvgcb1+VVOg fIZ5L28wz3hedz/bSzDdxGmWmLxTFA+6knP1RRg2r2w7ioiHgvWjZ/kR2DCwJ2Jytdsq 2WkQ== X-Gm-Message-State: AOAM530GLijgCQfZILuakiaIU1OWHlO3vDC40MvZQWhIA9qbBT682+CM GTV2nKQHi4AnXtAPHs0cabZikMvKhYM34h7tlvW0JcbGlNJ6aGjl7QHcwiR8VZBfN9nu2Hbkahn U0wOi/Cauq0fuNQ== X-Received: by 2002:adf:c404:: with SMTP id v4mr3945419wrf.17.1600763914461; Tue, 22 Sep 2020 01:38:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxF+UhqcZjJhKCOx+Q+BQywL0fXH3wc58iclR4SZ3UwB3K+7NSbyy3ViBSWSzy1/bWyUBH3EA== X-Received: by 2002:adf:c404:: with SMTP id v4mr3945400wrf.17.1600763914258; Tue, 22 Sep 2020 01:38:34 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stefan Hajnoczi Cc: Fam Zheng , Max Reitz , qemu-block@nongnu.org, Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 2/6] block/nvme: Map doorbells pages write-only Date: Tue, 22 Sep 2020 10:38:17 +0200 Message-Id: <20200922083821.578519-3-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200922083821.578519-1-philmd@redhat.com> References: <20200922083821.578519-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 Reviewed-by: Fam Zheng --- 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 Sun May 5 19:55:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1600763925; cv=none; d=zohomail.com; s=zohoarc; b=ZD2397rgT5OqR/BgMZaSJMWeYcR+Zr/k70PL7NdspqOFPjwS5sewTDb0/V1EOpm2ZqtPp6TlH5v4h1uce5QvzzDth6CVZc3Mm/XOxEMXROPrDega5d0AwOjdi9t2keVV5+LoLQ1KJ4RNT59LF0ncmYIMtR9c1XWLZh+LmHiglSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600763925; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=w3VSohO81qj1Qy9GMUYU8rCdXvyUaEcpLhj6tPxRG5I=; b=IVSJGwl6pxxVKYaQytN2PGvkdpeYSw6kyImsDRzoZZ8ZRCzMZMLYZ1lJyOHTk4jax4bFsMinJB/2EAvCGgtngDJ1A0BPfYFI+wzJ4Do17kJvDYJs6Md4kffYGlUgHUN0Qh3e+etqseFLoMqn1KPpqb8igq6Y/BGJ+vcQWmtd4MM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1600763925525515.083382832958; Tue, 22 Sep 2020 01:38:45 -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-162-ws-JtVhTN5-H5U7GP8g5Pg-1; Tue, 22 Sep 2020 04:38:40 -0400 Received: by mail-wr1-f70.google.com with SMTP id y3so7100583wrl.21 for ; Tue, 22 Sep 2020 01:38:40 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id s26sm3574656wmh.44.2020.09.22.01.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 01:38:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600763924; 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=EpGpm+SCxxWJzE91pK13CuCAnlojcSK0VSaug29WfeU0VKKpY/WLZc/2StAXK4lz1k/Xls ykduUkTJ1xbSaF0ApYqtG+1NMrqCCGPFg0+iZmQ0y4f2Ht6FtqBbx70whBRx0WImXhUgen CdViaUl/CV9q8khwZIthAhZgYmdhzrQ= X-MC-Unique: ws-JtVhTN5-H5U7GP8g5Pg-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=qEIoGP7mVRosqicmw77l0Lk899KNLBRiEoxpRXi+QBjeD6LmXoNLWuFw5fkCyMEzlV uXIG+jXhTA3ahjMhEB+knvDTLXQEoSb/ihS5DV6OJLutpaehM7EoP9wx7nT4VhwZbWUK LqX8diYEFmochZrbr6h6tyzUjLNPuSTtKh11Eh8jwOdvo1naBLtP24VRfp2qaHj35ewu jkPH+s5ct6ScvrNjQbsfgWwgu5PVrdK9uJr6jxKyDFRZAisBM0tLac69h57YtOqKQAXv emdeYGlHlhnx5PqzZ5PfILEFKUuVbvMq7KmnmxT98FAo0UsH/3dhXcPFCQ54kR3QZEM5 BkwA== X-Gm-Message-State: AOAM532Mj91cN7jwwavollWV8uky3TyG9NlOSebLcZF/Tx6KoMJ7dzuJ Dv9fyKOvNJ9Jwn6QOU1zpNRcp/0g2Vee+4xwE0oXr7qJNVuPaPDdmMolF8AinpYls3pPuPUcs+L Cn8igUX71wXR5NQ== X-Received: by 2002:a7b:c1d9:: with SMTP id a25mr3485424wmj.4.1600763919434; Tue, 22 Sep 2020 01:38:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2A4AufQUmQ8oJDjFckC5bFktT4P9aa0D8sACtAvyc6hGPchj31267DKfeserMAUz86zQKPg== X-Received: by 2002:a7b:c1d9:: with SMTP id a25mr3485400wmj.4.1600763919174; Tue, 22 Sep 2020 01:38:39 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stefan Hajnoczi Cc: Fam Zheng , Max Reitz , qemu-block@nongnu.org, Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 3/6] block/nvme: Reduce I/O registers scope Date: Tue, 22 Sep 2020 10:38:18 +0200 Message-Id: <20200922083821.578519-4-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200922083821.578519-1-philmd@redhat.com> References: <20200922083821.578519-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 Reviewed-by: Fam Zheng --- 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 Sun May 5 19:55:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1600763932; cv=none; d=zohomail.com; s=zohoarc; b=nTYAMZ0bRub+5rIpGmqZittqLZT8qcwJGeIQ6aas7m9MHWJ7vhm7Qa6hzeWrevX+KQJF7YXeyQV19QntqrDgh5WnhmED4BetjvXyah+i5vF10kybVbL1j/LB24Xbee3eFmbiVpBIm7+WpOf2wr2cSh454FKMsQrs517IaWDD6Uc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600763932; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=0oUMbvSMybNmnNxDNxqBQV+vJ3XelXwsh3Q4bryO1QA=; b=k6cl6Y4vGlBaFuBNxCq0qSGcgC49Q2Ixp9BLZPnjMp/81vqoXyucBBWLzwBiTtHPxhB/sQhNSlsJm8kvT4OLIG0pmUEU/y1+g3uND6qxDNpL/IK4qQfmB+sLSNfHS3x20Uj7Z09SMUDjZmj7wF240PNJV9rvi83EUNLIjyDC6c4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1600763932525129.54551419131474; Tue, 22 Sep 2020 01:38:52 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-330-QlI0hzYyN3WmP-6OxjQbig-1; Tue, 22 Sep 2020 04:38:45 -0400 Received: by mail-wr1-f71.google.com with SMTP id a10so7049462wrw.22 for ; Tue, 22 Sep 2020 01:38:45 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u66sm3634947wme.12.2020.09.22.01.38.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 01:38:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600763931; 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=0oUMbvSMybNmnNxDNxqBQV+vJ3XelXwsh3Q4bryO1QA=; b=PuBkZnwEOtIC54iGOkWVdyelIkw6aSd92x2vEKSv5TVoA78SUdKVHJ1eOOzaqIcVmwoeea yX8OYtHVBKDvDL7Jp/hNkGGrlFFINCyKHy36OgpVbXEIvNF7FqNfOC/giw+JmRphmEnA3/ sTBL7Qj1weaBGvVxQJd44vYG1X/Rh/M= X-MC-Unique: QlI0hzYyN3WmP-6OxjQbig-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=0oUMbvSMybNmnNxDNxqBQV+vJ3XelXwsh3Q4bryO1QA=; b=fRY3dvqp2DgWbs9GJJTknNYGT5iGvVmqBsRPpp9LiqQkNpsuSoIsMwOxNUgHRydVV/ G810nOH+s7JpcCtOHmKuQqFLwCOmk5iBuTgOYhrMbGBMXQ/cxhIJr94Ieh6ZzfkTZbcJ pjI4lUPk4rVtxDVrqCyPVOgedhhRt4oeJQtGS4xPCS28MQcZ4CGjRMhqdk9Cky15i3GU pK3NAn0ZPzc/3SIG1BVmogcb7VIcTwYVR3mS5teqztBJqWC0rzQdFvlDAbo91xi7H8Gs cNVzGwjOI/vkXQGkr0yM9hMF6QYNh8Tf3cg9WwT+0la4qPPW1qvJ3rOfKxAl7D+QyNQF URZg== X-Gm-Message-State: AOAM53189AfoTNrs+t7tQIKiqEXZb/Eha4J/WB6AC0Rb1ekygB8+6+fG auDGVZRnLz4kWGFovf4N/0jNL9EaHaHQT3UNAymUPsXatnJ452vYWYw1qUbJRUZKhJvwuRag5jl Wsm5PBmwJ8RClBA== X-Received: by 2002:a5d:4d51:: with SMTP id a17mr4037242wru.248.1600763924457; Tue, 22 Sep 2020 01:38:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoT63a4O62yTIZCWlOOnvcKmJ+6l9YijfzUd62oqIbvbXG5RnJkhxDcC4oNk4iulDEYZn9Hg== X-Received: by 2002:a5d:4d51:: with SMTP id a17mr4037224wru.248.1600763924289; Tue, 22 Sep 2020 01:38:44 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stefan Hajnoczi Cc: Fam Zheng , Max Reitz , qemu-block@nongnu.org, Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 4/6] block/nvme: Drop NVMeRegs structure, directly use NvmeBar Date: Tue, 22 Sep 2020 10:38:19 +0200 Message-Id: <20200922083821.578519-5-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200922083821.578519-1-philmd@redhat.com> References: <20200922083821.578519-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 Reviewed-by: Fam Zheng --- block/nvme.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index e517c7539ff..bd82990b66c 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 =3D NULL; =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 Sun May 5 19:55:35 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=1600763934; cv=none; d=zohomail.com; s=zohoarc; b=kk5bjYFMGjX6H1QKqFQ100yYBDwV5VLrwEatBOkzxXByHWVGGtEyd5NRv+FwgtfEGELNxdA85qPAytQdKL+5iDYquTFEMrczyU1B6teKqvNyjo2Bg1IWyp7A7QrGQuLdWbrVIg0ZULIfb4bya8OZliPJjV6YacYa50QHiDugh8E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600763934; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=ZtGoZwu6xHPSB07J+UgiWcxCLBb0xpG4Cx8oWnT4spA=; b=gJhnZLRcCGrAcsPeijdru/dU4MQabYz6WQsqXTgGjEkkHxASsyFx/Jy8Znzh5YzzJCJ7C9LXm1nAG1kBsuNqPTzwkv2ryRH3MfGprvwTBGFzaGf7J9kVcs/zEdSy8985gGB1BrAZUYIZjbzPbw79mzZ2TdsuXItvBs4ApwvbSiw= 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 1600763934513727.2311434208269; Tue, 22 Sep 2020 01:38:54 -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-171-4DmaYnMiP_CSiQ1hEIa7RA-1; Tue, 22 Sep 2020 04:38:50 -0400 Received: by mail-wm1-f72.google.com with SMTP id t10so383201wmi.9 for ; Tue, 22 Sep 2020 01:38:50 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id p9sm3285820wma.42.2020.09.22.01.38.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 01:38:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600763933; 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=ZtGoZwu6xHPSB07J+UgiWcxCLBb0xpG4Cx8oWnT4spA=; b=IKGW3DAINRGrPM1X9AMJYizxa5LND0UMNwfiOw0UVe++7ZbMVY8uLzdUSifTQCNazJRYRr W2tbODi1YzXP+Fooss3DOEqht/fBLJYGX+noI93ZyiWzoPnDF9NN1TV8aXPjLu6JNIMkaP WsBKjXL6t2CJUnNvqB9rbi93uFBV9os= X-MC-Unique: 4DmaYnMiP_CSiQ1hEIa7RA-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=ZtGoZwu6xHPSB07J+UgiWcxCLBb0xpG4Cx8oWnT4spA=; b=dgrcUaCezOXPyaLn7s9oq0A3XBCrK62EcmP6v5zsq3WbkknwMZGUDo9ffh5wlTectU E6q/QV8m+WMWcSHLTggj00iQa9F/6ov0zvpmSKcCSVGOUxrOiOiiTKaYjpKDhoh0bKZU lPYLkPA0RGt9KSns52mEEhBXcyAAYgR+8ZOytmlgmUO6f68WunHMC6kN3aMm4mUi04t5 QGPLezRAz8dX86FfL9QZaIupCHOBvGwLJcaELn1gEqpaPeJ5iJ65ePz/2xfQGtMRiYgm lLQY+RA+JiYsCKlegXh62x+yKYkOvvh1a7/U9hwmAUKKzs39FyB3m+setfRCtQ8CkZvx xAdA== X-Gm-Message-State: AOAM530rZRB+M0Q64lWVKfi8MBbKiy6/mSbo7DpZTLLulXcgmuzHfSfz 8sylYiGGta76UfzdMqUDKnX9wu9W1gePEvUvD6W6HAUBbXOnlyzw/Y1GFWA03/2fe3iYdPJAvlt tA1RwSkaT9ZbZrA== X-Received: by 2002:a7b:cf30:: with SMTP id m16mr3359099wmg.0.1600763929344; Tue, 22 Sep 2020 01:38:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHegFdYPfsW2i5m9hJm5ucXISWGJOPhDFbqGTGXl2p02X58+aF0aDkwwZM56BfE3ksAhuz0w== X-Received: by 2002:a7b:cf30:: with SMTP id m16mr3359083wmg.0.1600763929158; Tue, 22 Sep 2020 01:38:49 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stefan Hajnoczi Cc: Fam Zheng , Max Reitz , qemu-block@nongnu.org, Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 5/6] block/nvme: Use register definitions from 'block/nvme.h' Date: Tue, 22 Sep 2020 10:38:20 +0200 Message-Id: <20200922083821.578519-6-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200922083821.578519-1-philmd@redhat.com> References: <20200922083821.578519-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 Reviewed-by: Fam Zheng --- block/nvme.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index bd82990b66c..959569d262f 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 Sun May 5 19:55:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1600763938; cv=none; d=zohomail.com; s=zohoarc; b=f9P9PmjudatI0rWiNf/AFNkZuHChIaNRvZ6HMmnN5+WyFkuWC76FOZ4vFd05z5BROmPUmy4girkXzrra8dqJmfdsosKkF64hU/arj2rTfW61hMkzCmdOQsW5myNOpBgiBIoH/lWWkeDm8d5DKJAlslYFzJ3BTHK1wQgr30413+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600763938; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=eUWquMJ0RxAYROBHIyitnnUFXZeARp+T5e38sU6nK2Y=; b=VjCXoBbPtuB5mVHMPUUFGpwW/MWZ9Gn9fuThwvbBPXkTdJMxUSZq9AUW/4QRIQVTT4cs3Ivbe/Uf68iVY2ZVRFov9/cNGDBdfshuU2GGDuCbnm7otpfZeIe2nRgUk97fKjK7fuq9pG4lOCnnH9disaqfeSXdYfKctHxd4heBLtM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1600763938514296.73677644751854; Tue, 22 Sep 2020 01:38:58 -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-353-y4JiukvsMQu3lE6RboBzIA-1; Tue, 22 Sep 2020 04:38:55 -0400 Received: by mail-wr1-f69.google.com with SMTP id d13so691699wrr.23 for ; Tue, 22 Sep 2020 01:38:55 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id w14sm25632237wrk.95.2020.09.22.01.38.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 01:38:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600763937; 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=eUWquMJ0RxAYROBHIyitnnUFXZeARp+T5e38sU6nK2Y=; b=Ds9l+8kty5UKKfcl6CQSbpiEdeRPK2ZUPDXwVrPknncJhQ+iIz2DFeNcNcb3xZqTRzvVrC 8pciUJJHPph7+3au/ZDW4lzdhOSO8cdLOiGgzCRhuXOZUMhhocrMX5iYVQvQ4umuDVls+9 HKN3V6M9smr5mNbe47Lta+sTbN7xpeU= X-MC-Unique: y4JiukvsMQu3lE6RboBzIA-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=eUWquMJ0RxAYROBHIyitnnUFXZeARp+T5e38sU6nK2Y=; b=HOjYg8N166ldREePiIG9RvSKntWGmx0lDLu7/F1RQabPRhEbjj5lACN82QF1Dvbryg sxQxadg+Z1Kw3YpDc7Z4kCKSMA6uIHr8zSCNpJTXlC7o/37p7JXw4vT0T6H0THD2p+KB qxttIddlB0B1XMDy+ljqBrr/R6NhU/mNDciiCRAKt8zRCuEQsi+L5cIe1DxjJsjgoYxY OpjzVsAgMk1YYjukvy2rPcaHt4t3PM48lPQPps0hnPG4qw09nURqeySL65dVQ8o87+k3 lBX4hhzU+9goqVL8VNnwoBIrsESWW47kQQ5FBbISRFvNgvZ1+w8HvOeHf5ZyN3nu58iy cJEw== X-Gm-Message-State: AOAM533vpvVZCBMUD6Zd885ULJa9bg3XYUL4jabzQMyWFK2+DA5BK5zN 7oJWPqmjysSLZPskyRHUN7JxpAzfuTEmiVy+CNAclRk77yXkgxrAZVnCAOAYKzmjqcTew1k6aAY eJr35zsr27RBCMQ== X-Received: by 2002:adf:cd05:: with SMTP id w5mr4092689wrm.62.1600763934261; Tue, 22 Sep 2020 01:38:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMDy41vws801DLin8/B/65FrcxeUVg0Q3hoNAdcILiV+NbPlRKhPJ/VGhaIGTAI4a2GVAMjw== X-Received: by 2002:adf:cd05:: with SMTP id w5mr4092671wrm.62.1600763934098; Tue, 22 Sep 2020 01:38:54 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Stefan Hajnoczi Cc: Fam Zheng , Max Reitz , qemu-block@nongnu.org, Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 6/6] block/nvme: Replace magic value by SCALE_MS definition Date: Tue, 22 Sep 2020 10:38:21 +0200 Message-Id: <20200922083821.578519-7-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200922083821.578519-1-philmd@redhat.com> References: <20200922083821.578519-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 Reviewed-by: Fam Zheng --- block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/nvme.c b/block/nvme.c index 959569d262f..b48f6f25881 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