[PATCH v5 06/18] nvme: refactor nvme_addr_read

Klaus Jensen posted 18 patches 5 years, 9 months ago
Maintainers: Keith Busch <kbusch@kernel.org>, Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>
[PATCH v5 06/18] nvme: refactor nvme_addr_read
Posted by Klaus Jensen 5 years, 9 months ago
From: Klaus Jensen <k.jensen@samsung.com>

Pull the controller memory buffer check to its own function. The check
will be used on its own in later patches.

Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Maxim Levitsky <mlevitsky@redhat.com>
Reviewed-by: Keith Busch <kbusch@kernel.org>
---
 hw/block/nvme.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 4058f2c79796..623a88be93dc 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -66,14 +66,22 @@
 
 static void nvme_process_sq(void *opaque);
 
+static bool nvme_addr_is_cmb(NvmeCtrl *n, hwaddr addr)
+{
+    hwaddr low = n->ctrl_mem.addr;
+    hwaddr hi  = n->ctrl_mem.addr + int128_get64(n->ctrl_mem.size);
+
+    return addr >= low && addr < hi;
+}
+
 static void nvme_addr_read(NvmeCtrl *n, hwaddr addr, void *buf, int size)
 {
-    if (n->cmbsz && addr >= n->ctrl_mem.addr &&
-                addr < (n->ctrl_mem.addr + int128_get64(n->ctrl_mem.size))) {
+    if (n->cmbsz && nvme_addr_is_cmb(n, addr)) {
         memcpy(buf, (void *)&n->cmbuf[addr - n->ctrl_mem.addr], size);
-    } else {
-        pci_dma_read(&n->parent_obj, addr, buf, size);
+        return;
     }
+
+    pci_dma_read(&n->parent_obj, addr, buf, size);
 }
 
 static int nvme_check_sqid(NvmeCtrl *n, uint16_t sqid)
-- 
2.26.2


Re: [PATCH v5 06/18] nvme: refactor nvme_addr_read
Posted by Klaus Jensen 5 years, 9 months ago
On May  5 07:48, Klaus Jensen wrote:
> From: Klaus Jensen <k.jensen@samsung.com>
> 
> Pull the controller memory buffer check to its own function. The check
> will be used on its own in later patches.
> 
> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Reviewed-by: Maxim Levitsky <mlevitsky@redhat.com>
> Reviewed-by: Keith Busch <kbusch@kernel.org>
> ---
>  hw/block/nvme.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 

Woops, noticed that Maxim's R-b is wrong here, please update it to

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>

(without the 'y') when merging.

Re: [PATCH v5 06/18] nvme: refactor nvme_addr_read
Posted by Maxim Levitsky 5 years, 9 months ago
On Tue, 2020-05-05 at 07:52 +0200, Klaus Jensen wrote:
> On May  5 07:48, Klaus Jensen wrote:
> > From: Klaus Jensen <k.jensen@samsung.com>
> > 
> > Pull the controller memory buffer check to its own function. The check
> > will be used on its own in later patches.
> > 
> > Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
> > Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > Reviewed-by: Maxim Levitsky <mlevitsky@redhat.com>
> > Reviewed-by: Keith Busch <kbusch@kernel.org>
> > ---
> >  hw/block/nvme.c | 16 ++++++++++++----
> >  1 file changed, 12 insertions(+), 4 deletions(-)
> > 
> 
> Woops, noticed that Maxim's R-b is wrong here, please update it to
> 
> Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
> 
> (without the 'y') when merging.
> 
Well. When I worked for Intel, my email used to be mlevtsky@intel.com,
because I misspelled my private email (maximlevitsky@gmail.com) in my CV, and somehow this got
propagated to my username there.

Sure enough when I applied to work for Red Hat, I triple checked this to avoid such a mistake.
Well.... our usernames are limited to 8 characters.

Best regards,
	Maxim Levitsky