[SeaBIOS] [PATCH] nvme: Only allocate one dma bounce buffer for all nvme drives

Kevin O'Connor posted 1 patch 2 years, 3 months ago
Failed in applying to current master (apply log)
src/hw/nvme-int.h |  3 ---
src/hw/nvme.c     | 14 +++++++++-----
2 files changed, 9 insertions(+), 8 deletions(-)
[SeaBIOS] [PATCH] nvme: Only allocate one dma bounce buffer for all nvme drives
Posted by Kevin O'Connor 2 years, 3 months ago
There is no need to create multiple dma bounce buffers as the BIOS
disk code isn't reentrant capable.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>

---

This is a minor cleanup on top of the previous nvme code series.

-Kevin

--- 
src/hw/nvme-int.h |  3 ---
 src/hw/nvme.c     | 14 +++++++++-----
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/hw/nvme-int.h b/src/hw/nvme-int.h
index f0d717d..f9c807e 100644
--- a/src/hw/nvme-int.h
+++ b/src/hw/nvme-int.h
@@ -117,9 +117,6 @@ struct nvme_namespace {
     u32 block_size;
     u32 metadata_size;
     u32 max_req_size;
-
-    /* Page aligned buffer of size NVME_PAGE_SIZE. */
-    char *dma_buffer;
 };
 
 /* Data structures for NVMe admin identify commands */
diff --git a/src/hw/nvme.c b/src/hw/nvme.c
index 39b9138..0ba981c 100644
--- a/src/hw/nvme.c
+++ b/src/hw/nvme.c
@@ -20,6 +20,9 @@
 #include "nvme.h"
 #include "nvme-int.h"
 
+// Page aligned "dma bounce buffer" of size NVME_PAGE_SIZE in high memory
+static void *nvme_dma_buffer;
+
 static void *
 zalloc_page_aligned(struct zone_s *zone, u32 size)
 {
@@ -294,7 +297,8 @@ nvme_probe_ns(struct nvme_ctrl *ctrl, u32 ns_idx, u8 mdts)
         ns->max_req_size = -1U;
     }
 
-    ns->dma_buffer = zalloc_page_aligned(&ZoneHigh, NVME_PAGE_SIZE);
+    if (!nvme_dma_buffer)
+        nvme_dma_buffer = zalloc_page_aligned(&ZoneHigh, NVME_PAGE_SIZE);
 
     char *desc = znprintf(MAXDESCSIZE, "NVMe NS %u: %llu MiB (%llu %u-byte "
                           "blocks + %u-byte metadata)",
@@ -460,12 +464,12 @@ nvme_bounce_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count,
     u16 blocks = count < max_blocks ? count : max_blocks;
 
     if (write)
-        memcpy(ns->dma_buffer, buf, blocks * ns->block_size);
+        memcpy(nvme_dma_buffer, buf, blocks * ns->block_size);
 
-    int res = nvme_io_xfer(ns, lba, ns->dma_buffer, NULL, blocks, write);
+    int res = nvme_io_xfer(ns, lba, nvme_dma_buffer, NULL, blocks, write);
 
     if (!write && res >= 0)
-        memcpy(buf, ns->dma_buffer, res * ns->block_size);
+        memcpy(buf, nvme_dma_buffer, res * ns->block_size);
 
     return res;
 }
@@ -499,7 +503,7 @@ nvme_prpl_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count,
     if ((ns->block_size * count) > (NVME_PAGE_SIZE * 2)) {
         /* We need to describe more than 2 pages, build PRP List */
         u32 prpl_len = 0;
-        u64 *prpl = (void*)ns->dma_buffer;
+        u64 *prpl = nvme_dma_buffer;
         int first_page = 1;
         for (; size > 0; base += NVME_PAGE_SIZE, size -= NVME_PAGE_SIZE) {
             if (first_page) {
-- 
2.31.1

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org
[SeaBIOS] Re: [PATCH] nvme: Only allocate one dma bounce buffer for all nvme drives
Posted by Alexander Graf via SeaBIOS 2 years, 2 months ago
On 19.01.22 20:11, Kevin O'Connor wrote:
> There is no need to create multiple dma bounce buffers as the BIOS
> disk code isn't reentrant capable.
>
> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>


Reviewed-by: Alexander Graf <graf@amazon.com>

Alex


>
> ---
>
> This is a minor cleanup on top of the previous nvme code series.
>
> -Kevin
>
> ---
> src/hw/nvme-int.h |  3 ---
>   src/hw/nvme.c     | 14 +++++++++-----
>   2 files changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/src/hw/nvme-int.h b/src/hw/nvme-int.h
> index f0d717d..f9c807e 100644
> --- a/src/hw/nvme-int.h
> +++ b/src/hw/nvme-int.h
> @@ -117,9 +117,6 @@ struct nvme_namespace {
>       u32 block_size;
>       u32 metadata_size;
>       u32 max_req_size;
> -
> -    /* Page aligned buffer of size NVME_PAGE_SIZE. */
> -    char *dma_buffer;
>   };
>
>   /* Data structures for NVMe admin identify commands */
> diff --git a/src/hw/nvme.c b/src/hw/nvme.c
> index 39b9138..0ba981c 100644
> --- a/src/hw/nvme.c
> +++ b/src/hw/nvme.c
> @@ -20,6 +20,9 @@
>   #include "nvme.h"
>   #include "nvme-int.h"
>
> +// Page aligned "dma bounce buffer" of size NVME_PAGE_SIZE in high memory
> +static void *nvme_dma_buffer;
> +
>   static void *
>   zalloc_page_aligned(struct zone_s *zone, u32 size)
>   {
> @@ -294,7 +297,8 @@ nvme_probe_ns(struct nvme_ctrl *ctrl, u32 ns_idx, u8 mdts)
>           ns->max_req_size = -1U;
>       }
>
> -    ns->dma_buffer = zalloc_page_aligned(&ZoneHigh, NVME_PAGE_SIZE);
> +    if (!nvme_dma_buffer)
> +        nvme_dma_buffer = zalloc_page_aligned(&ZoneHigh, NVME_PAGE_SIZE);
>
>       char *desc = znprintf(MAXDESCSIZE, "NVMe NS %u: %llu MiB (%llu %u-byte "
>                             "blocks + %u-byte metadata)",
> @@ -460,12 +464,12 @@ nvme_bounce_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count,
>       u16 blocks = count < max_blocks ? count : max_blocks;
>
>       if (write)
> -        memcpy(ns->dma_buffer, buf, blocks * ns->block_size);
> +        memcpy(nvme_dma_buffer, buf, blocks * ns->block_size);
>
> -    int res = nvme_io_xfer(ns, lba, ns->dma_buffer, NULL, blocks, write);
> +    int res = nvme_io_xfer(ns, lba, nvme_dma_buffer, NULL, blocks, write);
>
>       if (!write && res >= 0)
> -        memcpy(buf, ns->dma_buffer, res * ns->block_size);
> +        memcpy(buf, nvme_dma_buffer, res * ns->block_size);
>
>       return res;
>   }
> @@ -499,7 +503,7 @@ nvme_prpl_xfer(struct nvme_namespace *ns, u64 lba, void *buf, u16 count,
>       if ((ns->block_size * count) > (NVME_PAGE_SIZE * 2)) {
>           /* We need to describe more than 2 pages, build PRP List */
>           u32 prpl_len = 0;
> -        u64 *prpl = (void*)ns->dma_buffer;
> +        u64 *prpl = nvme_dma_buffer;
>           int first_page = 1;
>           for (; size > 0; base += NVME_PAGE_SIZE, size -= NVME_PAGE_SIZE) {
>               if (first_page) {
> --
> 2.31.1
>



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879


_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org