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 77CF145C00; Mon, 28 Oct 2024 20:03:18 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A70F3427D9; Mon, 28 Oct 2024 20:03:14 +0100 (CET) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id A2D46427A1 for ; Mon, 28 Oct 2024 20:03:12 +0100 (CET) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-71e4e481692so3790488b3a.1 for ; Mon, 28 Oct 2024 12:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1730142192; x=1730746992; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fcT6h0Cmu1o16DMiPUCTo8HZFP/Fzfoj4kP6JzB6Bew=; b=XhYwtlT/546OJoL0ZhRaiCjc/w3+mSygMXPYNMxleFf+MpztjbB4poN3PJOrLwU45i N1tIRqnuUmdHb7NgeBaKprvybTlYHHCJjuHFeII7eyGVT6JSVkKdliiTYratjoko5kWX w24d3tOAePECamp3NzezzANmS1HrTSPVIOmipIdc7XXytI5vOGKeIhibBzNYTtdye0e4 JGEOSlbkv78FQngA3oPnX3El/w3IP3QNOGVUKqMzGvhuXZAoInyy/MS6opVXedYPTQxG dIzRFd3TJcJHFb6SkI2bvC5pbpdlW40wENAX12sA6MaNLJ4SDkAk1BhKapzmd//LuPbA jq0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730142192; x=1730746992; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fcT6h0Cmu1o16DMiPUCTo8HZFP/Fzfoj4kP6JzB6Bew=; b=FZGSXRB5s0dYnRJMKnmpcJq15QVLyfik4PNPykLIP9DxttRwlfqTni8lKCWjc4K/vE i1205R+kUepKl57+grVVUJk7Obce1RftK9A5uWdtx/GyTsVw71qva/NJ6WXoyfFaFDen 4yVEawseR2MHRqLck9f1jUlDFUS3z7TW9fiAD/QzPCa8DvSnXx3gQq/agkuTuPGpOcb9 BvGVbolOXuUr4L5USSZbY7U9fF1L4AOle32WUy3RMSlQQjdkECRaV2UMXrs4REVbC9xd uXOVmJLnH0kIdHiuC53jDawIGbA8xpmW8rqnCro6nAxmaR94nEF+DWz+EnZq7GWcqMJW 9Zyw== X-Gm-Message-State: AOJu0YyK2lxduoL/zZdGTMpm0NU8mN0/RfPOOjV+JxElwbzL+bg31QGc NUnamK0RgbVuAbUZcJXHyEWq4qTK2rRs8V34z7xykm+kW3K1dH2jTucLH63yGIjySE3tErqwAk9 x X-Google-Smtp-Source: AGHT+IEZVMhIjyKhvib3SdANNAK/8V1VIHugoEA/NsPurNHxPB8bdb90sT5LqOegVWbCbc5qiOyO5Q== X-Received: by 2002:a05:6a00:194b:b0:71e:fb4:6c98 with SMTP id d2e1a72fcca58-7206308e56dmr13031674b3a.23.1730142191836; Mon, 28 Oct 2024 12:03:11 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72057939b82sm6152565b3a.81.2024.10.28.12.03.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 12:03:11 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Elena Agostini Subject: [PATCH v2 1/2] test-gpudev: avoid use-after-free and free-non-heap warnings Date: Mon, 28 Oct 2024 12:01:02 -0700 Message-ID: <20241028190301.264378-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241028190301.264378-1-stephen@networkplumber.org> References: <20241017225844.235401-1-stephen@networkplumber.org> <20241028190301.264378-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Remove the test intentionally frees a bad pointer in GPU memory, and GCC sees that at compile time now. Fix use after free in printf. Signed-off-by: Stephen Hemminger --- app/test-gpudev/main.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/app/test-gpudev/main.c b/app/test-gpudev/main.c index f065e6cd81..30fe573bf9 100644 --- a/app/test-gpudev/main.c +++ b/app/test-gpudev/main.c @@ -96,29 +96,19 @@ alloc_gpu_memory(uint16_t gpu_id) goto error; } - ret = rte_gpu_mem_free(gpu_id, (uint8_t *)(ptr_1)+0x700); - if (ret < 0) { - printf("GPU memory 0x%p NOT freed: GPU driver didn't find this memory address internally.\n", - (uint8_t *)(ptr_1)+0x700); - } else { - fprintf(stderr, "ERROR: rte_gpu_mem_free freed GPU memory 0x%p\n", - (uint8_t *)(ptr_1)+0x700); - goto error; - } - + printf("GPU memory 0x%p free\n", ptr_2); ret = rte_gpu_mem_free(gpu_id, ptr_2); if (ret < 0) { fprintf(stderr, "rte_gpu_mem_free returned error %d\n", ret); goto error; } - printf("GPU memory 0x%p freed\n", ptr_2); + printf("GPU memory 0x%p free\n", ptr_1); ret = rte_gpu_mem_free(gpu_id, ptr_1); if (ret < 0) { fprintf(stderr, "rte_gpu_mem_free returned error %d\n", ret); goto error; } - printf("GPU memory 0x%p freed\n", ptr_1); printf("\n=======> TEST: PASSED\n"); return 0; @@ -228,12 +218,12 @@ gpu_mem_cpu_map(uint16_t gpu_id) } printf("GPU memory CPU unmapped, 0x%p not valid anymore\n", ptr_cpu); + printf("GPU memory 0x%p freeing\n", ptr_gpu); ret = rte_gpu_mem_free(gpu_id, ptr_gpu); if (ret < 0) { fprintf(stderr, "rte_gpu_mem_free returned error %d\n", ret); goto error; } - printf("GPU memory 0x%p freed\n", ptr_gpu); printf("\n=======> TEST: PASSED\n"); return 0; -- 2.45.2