From ee8383c2b139f32512f13209c100c4c3252ed914 Mon Sep 17 00:00:00 2001 From: Bill Nguyen Date: Wed, 30 Oct 2024 17:02:26 +1100 Subject: [PATCH] fix a memory issue with UIO Signed-off-by: Bill Nguyen --- tools/linux/uio_drivers/net/main.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tools/linux/uio_drivers/net/main.c b/tools/linux/uio_drivers/net/main.c index d80b1797..6ccf9c03 100644 --- a/tools/linux/uio_drivers/net/main.c +++ b/tools/linux/uio_drivers/net/main.c @@ -27,6 +27,7 @@ /* Change this if you want to bind to a different interface make sure it is brought up first by the init script */ #define NET_INTERFACE "eth0" +char frame[ETH_FRAME_LEN]; /* Event queue for polling */ #define MAX_EVENTS 20 @@ -229,18 +230,21 @@ void rx_process(void) { exit(EXIT_FAILURE); } - // Convert DMA addr from virtualiser to offset - uintptr_t offset = buffer.io_or_offset - vmm_info_passing->rx_paddr; - char *buf_in_sddf_rx_data = (char *) ((uintptr_t) rx_data_drv + offset); - - // Write to the data buffer - int num_bytes = recv(sock_fd, buf_in_sddf_rx_data, ETH_FRAME_LEN, 0); + // Write frame out to temp buffer + int num_bytes = recv(sock_fd, &frame[0], ETH_FRAME_LEN, 0); if (num_bytes < 0) { perror("rx_process(): recv()"); - LOG_NET_ERR("couldnt recv from raw sock, offset is %p, buf_in_sddf_rx_data is %p\n", offset, buf_in_sddf_rx_data); + LOG_NET_ERR("couldnt recv from raw sock\n"); exit(EXIT_FAILURE); } + // Convert DMA addr from virtualiser to offset then mem copy + uintptr_t offset = buffer.io_or_offset - vmm_info_passing->rx_paddr; + char *buf_in_sddf_rx_data = (char *) ((uintptr_t) rx_data_drv + offset); + for (uint64_t i = 0; i < num_bytes; i++) { + buf_in_sddf_rx_data[i] = frame[i]; + } + // Enqueue it to the active queue buffer.len = num_bytes; if (net_enqueue_active(&rx_queue, buffer) != 0) { @@ -269,6 +273,8 @@ int main(int argc, char **argv) uint64_t sddf_net_control_and_data_size = (NET_DATA_REGION_CAPACITY * 4) + (NET_DATA_REGION_CAPACITY * (1 + NUM_NETWORK_CLIENTS)); sddf_net_queues_vaddr = map_uio(sddf_net_control_and_data_size, uio_sddf_net_queues_fd); + printf("total size is %p\n", sddf_net_control_and_data_size); + LOG_NET("*** Setting up sDDF control and data queues\n"); rx_free_drv = sddf_net_queues_vaddr; rx_active_drv = (char *) ((uint64_t) rx_free_drv + NET_DATA_REGION_CAPACITY); @@ -321,7 +327,7 @@ int main(int argc, char **argv) LOG_NET("*** All initialisation successful, now sending all pending TX active before we block on events\n"); net_request_signal_active(&tx_queue); - // tx_process(); + tx_process(); LOG_NET("*** All pending TX active have been sent thru the raw sock, entering event loop now.\n"); LOG_NET("*** You won't see any output from UIO Net anymore. Unless there is a warning or error.\n");