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 9D0CB45B61; Fri, 18 Oct 2024 00:59:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 33DAC40664; Fri, 18 Oct 2024 00:59:00 +0200 (CEST) Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by mails.dpdk.org (Postfix) with ESMTP id C6DE4402AC for ; Fri, 18 Oct 2024 00:58:56 +0200 (CEST) Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-20c70abba48so13062125ad.0 for ; Thu, 17 Oct 2024 15:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1729205936; x=1729810736; 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=if/rB9KBLROqzwzMcjDBaKqnaPjNWu2ATzpaO5IWUPNrc26xSQOdsvu9O7l9lXSnhA OwwBupe7jUunebE6JWFQolYUfe8Is2ttwwq3VfSWHJE3jHHO0oNXcRG4CeYOZODDIlvW lMcM0DK+bULWlTz6SAF0HYMladgZ96vf4r1fZsYacrVMdLqCpofjqb61jPOgx5yVK2nB 2gnFBG/0L/gnZ0p3SmuFr+iRzJkQnlvJsy/0Ma21oeluss2IKg9mKjFbVtQcOUpMbWfB GGq1D7Oxu8nvi01zBGuvCh3qsMk6jCgISibaD+iYix1Oc/Rt47JfzQi+utPyyxRFmDru dmIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729205936; x=1729810736; 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=jSA7LLMRxax/lCA+UbyWKpA/PsJLMXpVtx6ob6Rzf8sWAX8BsJ6PelGqwuTlU9h7nM cOum0bS50U+ORWaY5FjBmJcQacuxY3muuj9+QISPRx+DqbOSrGMq9yCfUsuhc57qiyvW 5ty+t9yidxnqQKqd2ZR79Yp+3IpGqP1UpC/8v00PW8rTOk7fMMboy90ykuuQAYktRwit WenTCzhRwsKMk9gsyTITzypTaSV2aisM1GjxuJhDjsvfloVL+5E/QObd9j191S8KDkqX IPDgSFlBX0vy2Pbn4Q9O2wbeMH/GSJGpq2jIkyl/U4drZ6svnuT00RJcR7/l2KQQwVT3 nT2g== X-Gm-Message-State: AOJu0YyGWDmwxToHX3nPiNyCduBYx9MB3n9I3DHrrgGAfUBX32HZ0FO/ xIkiUUpbP5/BuZpt+eYGLzkrzE866QRay90T+rzJgx5i9bXSo0jZDp8lRtOGYSOiUdfbAgrBivh B X-Google-Smtp-Source: AGHT+IHy6ZBZfsJaEQ8mJ2vBUKwN/Sd+7QPL52/SPMmjQxpe4DJlLS2kuW6ozy/fv91Rql1Skvrcxw== X-Received: by 2002:a17:902:ecce:b0:20c:771c:b5fd with SMTP id d9443c01a7336-20e5a95a7cfmr4138465ad.60.1729205935956; Thu, 17 Oct 2024 15:58:55 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e5a71ee35sm1544685ad.17.2024.10.17.15.58.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 15:58:55 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Elena Agostini Subject: [PATCH 2/2] gpudev: add malloc annotations to rte_gpu_mem_alloc Date: Thu, 17 Oct 2024 15:58:04 -0700 Message-ID: <20241017225844.235401-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241017225844.235401-1-stephen@networkplumber.org> References: <20241017225844.235401-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