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 E48DF45C00; Mon, 28 Oct 2024 20:03:24 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D3A7E427DE; Mon, 28 Oct 2024 20:03:24 +0100 (CET) Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by mails.dpdk.org (Postfix) with ESMTP id 02202427DB for ; Mon, 28 Oct 2024 20:03:14 +0100 (CET) Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-7eab7622b61so3216924a12.1 for ; Mon, 28 Oct 2024 12:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1730142194; x=1730746994; 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=/4h4uUqnihK/jxcF8R0proGKOTyctRUvYT6JUVYNlHE=; b=I4FCsAOsPWTbcVCP0DGclOrrdlf3HkbMY0Gw4LAaFrv0Lt0+/OJB+bE8Jd5vFjw+EA d5aLHM0mbep5yMG1IOza1Uws3Muu30f8QU9WySnU8lCm8c/eMJYJyPzgQZIH95h+tFfF kL+rp5UeKhukWS+zn9RIiJ6zKe/r57UWI5xTGWdMZxJDIMrGzIlNfRwkGEeHmTbTNSgE rVK7VQ6fS8DOI9fWa2toAgk9sgaAKH5Baq+ioCeut6v5iNSz30erIVxLUML/V2hg8/Oq Oi2XcINxPi/tX32KOMP0/S7KA4jjCea/Ku10sMIl4BoQrJ2UIgrRjoi9kR+ImkLeXQ8o 0PXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730142194; x=1730746994; 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=/4h4uUqnihK/jxcF8R0proGKOTyctRUvYT6JUVYNlHE=; b=qdMlqpIdfpJ78dmkOdM/H8Cy8QFa1WftfXXltfyoYcZI0ALsMxA15sinoc6S5cUbRK LFfpZSvvjrm7NrodtHuRIFkedqmuJ4np4FuBn/KawPVyZfez6QS2Cytfbn84Kf4Kfr1j EAnt7c6BEbSUJQ/AeMPxN4eqcCWeq1PX7BtCYOw0QyoQujuk0Cmo1DkQMM03rTGH5E6T YGTeFVwU3Ckp8dw8vE/F34i0eaKDjNvmcGH+Xp+pnr4UqVKpOrfWCHyxmqBxDOaYcLET AtG5nMwvz04VMoAevnv0liIMAL7Zo089Q5LiTP/aEGipFZWucGVjkhCGdHxAfIVYbVk8 1FeA== X-Gm-Message-State: AOJu0YwLH/DwEa5UE4uUxWXO3o2Z3R9afqLTio21rlmRi+PipFRyNPZi Sans8TIt4xgqgWmnIfmCtMPPzrE9+eLG3zZhUpkZePNDnTLwSG3qWOQsgPKKFa2FES0c+kNw0dK 2 X-Google-Smtp-Source: AGHT+IHLY+xgTWvJ0IIp13TyY3oT+tig46l9u1Rwy+EIpTBa95buaZtc6pppIJnk6Nkl3oquIti6AA== X-Received: by 2002:a05:6a20:c6ce:b0:1d8:a3ab:7228 with SMTP id adf61e73a8af0-1d9a81c3febmr11856691637.0.1730142192564; Mon, 28 Oct 2024 12:03:12 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 12:03:12 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Elena Agostini Subject: [PATCH v2 2/2] gpudev: add malloc annotations to rte_gpu_mem_alloc Date: Mon, 28 Oct 2024 12:01:03 -0700 Message-ID: <20241028190301.264378-3-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 Add function attributes that allow detecting use after free, and calling free on bad pointer at compile time. Signed-off-by: Stephen Hemminger --- lib/gpudev/rte_gpudev.h | 46 +++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/lib/gpudev/rte_gpudev.h b/lib/gpudev/rte_gpudev.h index 0a94a6abc4..7a35cf85d1 100644 --- a/lib/gpudev/rte_gpudev.h +++ b/lib/gpudev/rte_gpudev.h @@ -357,6 +357,28 @@ int rte_gpu_callback_unregister(int16_t dev_id, enum rte_gpu_event event, __rte_experimental int rte_gpu_info_get(int16_t dev_id, struct rte_gpu_info *info); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Deallocate a chunk of memory allocated with rte_gpu_mem_alloc(). + * + * @param dev_id + * Reference device ID. + * @param ptr + * Pointer to the memory area to be deallocated. + * NULL is a no-op accepted value. + * + * @return + * 0 on success, -rte_errno otherwise: + * - ENODEV if invalid dev_id + * - ENOTSUP if operation not supported by the driver + * - EPERM if driver error + */ +__rte_experimental +int rte_gpu_mem_free(int16_t dev_id, void *ptr); + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice. @@ -385,28 +407,8 @@ int rte_gpu_info_get(int16_t dev_id, struct rte_gpu_info *info); */ __rte_experimental void *rte_gpu_mem_alloc(int16_t dev_id, size_t size, unsigned int align) -__rte_alloc_size(2); - -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice. - * - * Deallocate a chunk of memory allocated with rte_gpu_mem_alloc(). - * - * @param dev_id - * Reference device ID. - * @param ptr - * Pointer to the memory area to be deallocated. - * NULL is a no-op accepted value. - * - * @return - * 0 on success, -rte_errno otherwise: - * - ENODEV if invalid dev_id - * - ENOTSUP if operation not supported by the driver - * - EPERM if driver error - */ -__rte_experimental -int rte_gpu_mem_free(int16_t dev_id, void *ptr); + __rte_alloc_size(2) __rte_alloc_align(3) + __rte_malloc __rte_dealloc(rte_gpu_mem_free, 2); /** * @warning -- 2.45.2