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 CDD8345A48; Fri, 27 Sep 2024 22:50:03 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 372C040B97; Fri, 27 Sep 2024 22:48:22 +0200 (CEST) Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by mails.dpdk.org (Postfix) with ESMTP id 42DFB4068A for ; Fri, 27 Sep 2024 22:48:11 +0200 (CEST) Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-71979bf5e7aso1991682b3a.1 for ; Fri, 27 Sep 2024 13:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1727470090; x=1728074890; 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=Ng3ui7F82ZyOLA2TqbcN38mJTXs+gNIZoGOuUVuhB5E=; b=ApWHwRKmIaM0rU/avoEEGy8c8NDnXDD8GohvZcVIPwAi/OV90OiprWyPPxgxRuDvLh wVqikdFeSZ2Gr+joY8FQAGceR0riDq2T/20LMI5Cqog7m0E050fWsAgHV1I5tXiywk3Y jAkVJud1cmoi9rC+/o5M+uEDiL6pdCdudPMzYQ/Hwwvhrm0wWwqpc4h8UuGnVW+E4JC1 YaDmouSqy2/lkXb7jIpupjw1tZmtuQynR53OjG+gxuCU1FDDRks1flI3z+EGDpGT1tN8 YXRBGRU96Wut4ki12tVmRj3K537mIc01Rz5pl79K8wRw61T7lswxSK3ocwZxnN84uQhl sG/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727470090; x=1728074890; 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=Ng3ui7F82ZyOLA2TqbcN38mJTXs+gNIZoGOuUVuhB5E=; b=R62f/XyJY4wnwEq4ISRtF1Aut1OCXPLbzDPizRr0YfPaVv+KBZMZpyybPlIEB5X9Cc vFZoIYNZykep+aXFIwrOxrtaiQ8KS/O/EaJw9SWqon4nKC07VN+kEul5AjB3btfdI6TG hoywsfDLC3oRsh028Hd7th1hXt38AD4B4nhiTwZkMz+VXa55CPiyl82Pg99fUa9HBkR6 JkDVsEkBDGkzI0i+zq8Wp8nK/tbfj5pj2evnDFmcGEjj9iePJI1KWAVciNvFSwWn/0BB JqHMvOS0nvUrERP8cAneNuzWVMCKjx78vt2QdYAmb9Fpj2HGGbE89g6kM8to38fwOjG2 TU5g== X-Gm-Message-State: AOJu0YznlBfqgL2MWVo1oup3DEUlv6Nquze5xYZzPWFX7tStALoAlMqK +XcgXLzf+FAv7US9reWDiqjYokrZCSvoD/xk2Ot+vcZxZzc/oPcJzdZ1DRqWn2FBurNRnwF+2Z8 l X-Google-Smtp-Source: AGHT+IEBx0VNCUGvcJgkZug/zfUX26KI9joJEiELV4qVsrkCU2O5JKNIoMKPTgsGs6+pwYyWQghdHw== X-Received: by 2002:a05:6a00:2e18:b0:710:5825:5ba0 with SMTP id d2e1a72fcca58-71b25f27c3emr6367639b3a.3.1727470090365; Fri, 27 Sep 2024 13:48:10 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e6db294533sm2036531a12.12.2024.09.27.13.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2024 13:48:10 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Anatoly Burakov , Tyler Retzlaff Subject: [PATCH 15/16] eal: add alloc_function attribute to rte_malloc Date: Fri, 27 Sep 2024 13:45:51 -0700 Message-ID: <20240927204742.546164-16-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240927204742.546164-1-stephen@networkplumber.org> References: <20240927204742.546164-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 Use the GCC function attribute to detect cases where memory is allocated with rte_malloc and freed incorrectly with libc version of free (and vice versa). Also will detect some other pointer mismatches. Signed-off-by: Stephen Hemminger --- lib/eal/include/rte_malloc.h | 55 +++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/lib/eal/include/rte_malloc.h b/lib/eal/include/rte_malloc.h index cf3c174022..9e60a36476 100644 --- a/lib/eal/include/rte_malloc.h +++ b/lib/eal/include/rte_malloc.h @@ -31,6 +31,22 @@ struct rte_malloc_socket_stats { size_t heap_allocsz_bytes; /**< Total allocated bytes on heap */ }; + +/** + * Frees the memory space pointed to by the provided pointer. + * + * This pointer must have been returned by a previous call to + * rte_malloc(), rte_zmalloc(), rte_calloc() or rte_realloc(). The behaviour of + * rte_free() is undefined if the pointer does not match this requirement. + * + * If the pointer is NULL, the function does nothing. + * + * @param ptr + * The pointer to memory to be freed. + */ +void +rte_free(void *ptr); + /** * This function allocates memory from the huge-page area of memory. The memory * is not cleared. In NUMA systems, the memory allocated resides on the same @@ -55,7 +71,8 @@ struct rte_malloc_socket_stats { void * rte_malloc(const char *type, size_t size, unsigned align) __rte_alloc_size(2) - __rte_alloc_align(3); + __rte_alloc_align(3) + __rte_alloc_func(rte_free); /** * Allocate zeroed memory from the heap. @@ -83,7 +100,8 @@ rte_malloc(const char *type, size_t size, unsigned align) void * rte_zmalloc(const char *type, size_t size, unsigned align) __rte_alloc_size(2) - __rte_alloc_align(3); + __rte_alloc_align(3) + __rte_alloc_func(rte_free); /** * Replacement function for calloc(), using huge-page memory. Memory area is @@ -111,7 +129,8 @@ rte_zmalloc(const char *type, size_t size, unsigned align) void * rte_calloc(const char *type, size_t num, size_t size, unsigned align) __rte_alloc_size(2, 3) - __rte_alloc_align(4); + __rte_alloc_align(4) + __rte_alloc_func(rte_free); /** * Replacement function for realloc(), using huge-page memory. Reserved area @@ -136,7 +155,8 @@ rte_calloc(const char *type, size_t num, size_t size, unsigned align) void * rte_realloc(void *ptr, size_t size, unsigned int align) __rte_alloc_size(2) - __rte_alloc_align(3); + __rte_alloc_align(3) + __rte_alloc_func(rte_free); /** * Replacement function for realloc(), using huge-page memory. Reserved area @@ -163,7 +183,8 @@ rte_realloc(void *ptr, size_t size, unsigned int align) void * rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket) __rte_alloc_size(2) - __rte_alloc_align(3); + __rte_alloc_align(3) + __rte_alloc_func(rte_free); /** * This function allocates memory from the huge-page area of memory. The memory @@ -191,7 +212,8 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket) void * rte_malloc_socket(const char *type, size_t size, unsigned align, int socket) __rte_alloc_size(2) - __rte_alloc_align(3); + __rte_alloc_align(3) + __rte_alloc_func(rte_free); /** * Allocate zeroed memory from the heap. @@ -221,7 +243,8 @@ rte_malloc_socket(const char *type, size_t size, unsigned align, int socket) void * rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket) __rte_alloc_size(2) - __rte_alloc_align(3); + __rte_alloc_align(3) + __rte_alloc_func(rte_free); /** * Replacement function for calloc(), using huge-page memory. Memory area is @@ -251,22 +274,8 @@ rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket) void * rte_calloc_socket(const char *type, size_t num, size_t size, unsigned align, int socket) __rte_alloc_size(2, 3) - __rte_alloc_align(4); - -/** - * Frees the memory space pointed to by the provided pointer. - * - * This pointer must have been returned by a previous call to - * rte_malloc(), rte_zmalloc(), rte_calloc() or rte_realloc(). The behaviour of - * rte_free() is undefined if the pointer does not match this requirement. - * - * If the pointer is NULL, the function does nothing. - * - * @param ptr - * The pointer to memory to be freed. - */ -void -rte_free(void *ptr); + __rte_alloc_align(4) + __rte_alloc_func(rte_free); /** * If malloc debug is enabled, check a memory block for header -- 2.45.2