From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 46B4E46011; Tue, 7 Jan 2025 20:03:02 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1797440150; Tue, 7 Jan 2025 20:03:02 +0100 (CET) Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by mails.dpdk.org (Postfix) with ESMTP id 8763C4014F for ; Tue, 7 Jan 2025 20:03:00 +0100 (CET) Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2efc3292021so36624080a91.1 for ; Tue, 07 Jan 2025 11:03:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736276579; x=1736881379; darn=dpdk.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zfl4W7R+UESN/US9I+xXZvYU3yC7qxAiaQMbODbbsbw=; b=b5y1qOaLjwr+HtVA8dkPGw1uUYW/bI9k5pjdE7hlDeha+SPUnsOQjR98+v5LYG86g+ eKP4MR0OraMErfMgwOdDiHzbW6Nv8t42xxCZFk7sulYaDwYv+RSNr2xZKXx3Lb51ayBu xVF1Pb/espXx2T52GZHiXgKKClqRxFtInWdbuwVu4d45BLII/6YvbrCsCMY4V5EhuZoL 6Lbr7ufuKkJXBcO+4Z6A6o0UfPzuid9Q22qWvK3RhEREJirDAflOUfk/RBNJ7Mg2Wzjj rXOqhfQYmM/5cQ2OU4YHs/codhozenrosWV21JdYg5Y8GqeKibl16sBLA4aBHI9zU+dT 0LiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736276579; x=1736881379; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zfl4W7R+UESN/US9I+xXZvYU3yC7qxAiaQMbODbbsbw=; b=Y4Kc+WrLLKuusF21KPGTJZZPoOSns94hXxrRkP98E7rAH6RSqaim+GQI3I9UIhxISw JCjTN1dj3GWNej3ugA/N+P1B2Jmn3gF6uGUzmcSX4H46pn6UW6B/MvlIjrEBaDd9LRFT 6/OWR5U9M2ro3xZkSMTN1oZxd+I4QPzioELFNNbaULiF38zTCm0lnBifHyC6ItSei0Oj MkpuYeVvi6FKSjiR+6e7Ic4yo0EKuAZqkPQTy9n9xMEFSTx5sFxUoiteJTGnHSRAggCr tQERjx7sBS/hyTb+J7YpWgCFqryoRjQQuGcXsGyobWF0fQCAdLsbErjUISD44bEoSYsw g4aQ== X-Gm-Message-State: AOJu0Yz4jAe+n4N2+QXFauJUegCIMWmr4n1aN6b9zkJHoJpLzI1kjSFM AOP9Pudt3u2c3VOG2gSawmGfNEbtvztC7LZ77taVsvzVstmWTOHieFL/qWlcm2fb2bxlK2nqkas hTTCP9umdVg== X-Google-Smtp-Source: AGHT+IFmUp/wTeqVs1b2N5gIJSA+z5L3iNDSFNrqPs8TYat+fCyrp9hdJUOCtXsKdKABtzGKrf/kB/tNmSRWVA== X-Received: from pjbqd7.prod.google.com ([2002:a17:90b:3cc7:b0:2e5:5ffc:1c36]) (user=joshwash job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2c84:b0:2ea:a25d:3baa with SMTP id 98e67ed59e1d1-2f452dfa40bmr97663981a91.5.1736276579601; Tue, 07 Jan 2025 11:02:59 -0800 (PST) Date: Tue, 7 Jan 2025 11:02:58 -0800 In-Reply-To: <20241223201623.5666-1-joshwash@google.com> Mime-Version: 1.0 References: <20241223201623.5666-1-joshwash@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250107190258.2107909-1-joshwash@google.com> Subject: [PATCH v3] net/gve: allocate RX QPL pages using malloc From: Joshua Washington To: Jeroen de Borst , Rushil Gupta , Joshua Washington Cc: dev@dpdk.org, Praveen Kaligineedi Content-Type: text/plain; charset="UTF-8" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Praveen Kaligineedi Allocating QPL for an RX queue might fail if enough contiguous IOVA memory cannot be allocated. This can commonly occur when using 2MB huge pages because the 1024 4K buffers are allocated for each RX ring by default, resulting in 4MB for each ring. However, the only requirement for RX QPLs is that each 4K buffer be IOVA contiguous, not the entire QPL. Therefore, malloc will be used to allocate RX QPLs instead. Note that TX queues require the entire QPL to be IOVA contiguous, so it will continue to use the memzone-based allocation. Signed-off-by: Praveen Kaligineedi Signed-off-by: Joshua Washington --- drivers/net/gve/gve_ethdev.c | 102 ++++++++++++++++++++++++++++------- drivers/net/gve/gve_ethdev.h | 5 +- drivers/net/gve/gve_rx.c | 2 +- 3 files changed, 89 insertions(+), 20 deletions(-) diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c index db4ebe7036..e471a34e61 100644 --- a/drivers/net/gve/gve_ethdev.c +++ b/drivers/net/gve/gve_ethdev.c @@ -22,42 +22,97 @@ gve_write_version(uint8_t *driver_version_register) writeb('\n', driver_version_register); } +static const struct rte_memzone * +gve_alloc_using_mz(const char *name, uint32_t num_pages) +{ + const struct rte_memzone *mz; + mz = rte_memzone_reserve_aligned(name, num_pages * PAGE_SIZE, + rte_socket_id(), + RTE_MEMZONE_IOVA_CONTIG, PAGE_SIZE); + if (mz == NULL) + PMD_DRV_LOG(ERR, "Failed to alloc memzone %s.", name); + return mz; +} + +static int +gve_alloc_using_malloc(void **bufs, uint32_t num_entries) +{ + uint32_t i; + + for (i = 0; i < num_entries; i++) { + bufs[i] = rte_malloc_socket(NULL, PAGE_SIZE, PAGE_SIZE, rte_socket_id()); + if (bufs[i] == NULL) { + PMD_DRV_LOG(ERR, "Failed to malloc"); + goto free_bufs; + } + } + return 0; + +free_bufs: + while (i > 0) + rte_free(bufs[--i]); + + return -ENOMEM; +} + static struct gve_queue_page_list * -gve_alloc_queue_page_list(const char *name, uint32_t num_pages) +gve_alloc_queue_page_list(const char *name, uint32_t num_pages, bool is_rx) { struct gve_queue_page_list *qpl; const struct rte_memzone *mz; - dma_addr_t page_bus; uint32_t i; qpl = rte_zmalloc("qpl struct", sizeof(struct gve_queue_page_list), 0); if (!qpl) return NULL; - mz = rte_memzone_reserve_aligned(name, num_pages * PAGE_SIZE, - rte_socket_id(), - RTE_MEMZONE_IOVA_CONTIG, PAGE_SIZE); - if (mz == NULL) { - PMD_DRV_LOG(ERR, "Failed to alloc %s.", name); - goto free_qpl_struct; - } qpl->page_buses = rte_zmalloc("qpl page buses", num_pages * sizeof(dma_addr_t), 0); if (qpl->page_buses == NULL) { PMD_DRV_LOG(ERR, "Failed to alloc qpl page buses"); - goto free_qpl_memzone; + goto free_qpl_struct; } - page_bus = mz->iova; - for (i = 0; i < num_pages; i++) { - qpl->page_buses[i] = page_bus; - page_bus += PAGE_SIZE; + + if (is_rx) { + /* RX QPL need not be IOVA contiguous. + * Allocate 4K size buffers using malloc + */ + qpl->qpl_bufs = rte_zmalloc("qpl bufs", + num_pages * sizeof(void *), 0); + if (qpl->qpl_bufs == NULL) { + PMD_DRV_LOG(ERR, "Failed to alloc qpl bufs"); + goto free_qpl_page_buses; + } + + if (gve_alloc_using_malloc(qpl->qpl_bufs, num_pages)) + goto free_qpl_page_bufs; + + /* Populate the IOVA addresses */ + for (i = 0; i < num_pages; i++) + qpl->page_buses[i] = + rte_malloc_virt2iova(qpl->qpl_bufs[i]); + } else { + /* TX QPL needs to be IOVA contiguous + * Allocate QPL using memzone + */ + mz = gve_alloc_using_mz(name, num_pages); + if (!mz) + goto free_qpl_page_buses; + + qpl->mz = mz; + + /* Populate the IOVA addresses */ + for (i = 0; i < num_pages; i++) + qpl->page_buses[i] = mz->iova + i * PAGE_SIZE; } - qpl->mz = mz; + qpl->num_entries = num_pages; return qpl; -free_qpl_memzone: - rte_memzone_free(qpl->mz); +free_qpl_page_bufs: + rte_free(qpl->qpl_bufs); +free_qpl_page_buses: + rte_free(qpl->page_buses); free_qpl_struct: rte_free(qpl); return NULL; @@ -69,7 +124,18 @@ gve_free_queue_page_list(struct gve_queue_page_list *qpl) if (qpl->mz) { rte_memzone_free(qpl->mz); qpl->mz = NULL; + } else if (qpl->qpl_bufs) { + uint32_t i; + + for (i = 0; i < qpl->num_entries; i++) + rte_free(qpl->qpl_bufs[i]); + } + + if (qpl->qpl_bufs) { + rte_free(qpl->qpl_bufs); + qpl->qpl_bufs = NULL; } + if (qpl->page_buses) { rte_free(qpl->page_buses); qpl->page_buses = NULL; @@ -89,7 +155,7 @@ gve_setup_queue_page_list(struct gve_priv *priv, uint16_t queue_id, bool is_rx, /* Allocate a new QPL. */ snprintf(qpl_name, sizeof(qpl_name), "gve_%s_%s_qpl%d", priv->pci_dev->device.name, queue_type_string, queue_id); - qpl = gve_alloc_queue_page_list(qpl_name, num_pages); + qpl = gve_alloc_queue_page_list(qpl_name, num_pages, is_rx); if (!qpl) { PMD_DRV_LOG(ERR, "Failed to alloc %s qpl for queue %hu.", diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h index c417a0b31c..35cb9062b1 100644 --- a/drivers/net/gve/gve_ethdev.h +++ b/drivers/net/gve/gve_ethdev.h @@ -62,7 +62,10 @@ struct gve_queue_page_list { uint32_t id; /* unique id */ uint32_t num_entries; dma_addr_t *page_buses; /* the dma addrs of the pages */ - const struct rte_memzone *mz; + union { + const struct rte_memzone *mz; /* memzone allocated for TX queue */ + void **qpl_bufs; /* RX qpl-buffer list allocated using malloc*/ + }; }; /* A TX desc ring entry */ diff --git a/drivers/net/gve/gve_rx.c b/drivers/net/gve/gve_rx.c index 1f5fa3f1da..7a91c31ad2 100644 --- a/drivers/net/gve/gve_rx.c +++ b/drivers/net/gve/gve_rx.c @@ -117,7 +117,7 @@ gve_rx_mbuf(struct gve_rx_queue *rxq, struct rte_mbuf *rxe, uint16_t len, rxq->ctx.mbuf_tail = rxe; } if (rxq->is_gqi_qpl) { - addr = (uint64_t)(rxq->qpl->mz->addr) + rx_id * PAGE_SIZE + padding; + addr = (uint64_t)rxq->qpl->qpl_bufs[rx_id] + padding; rte_memcpy((void *)((size_t)rxe->buf_addr + rxe->data_off), (void *)(size_t)addr, len); } -- 2.47.1.613.gc27f4b7a9f-goog