From patchwork Sun Apr 7 11:45:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Brandes, Shai" X-Patchwork-Id: 139180 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4C96543E21; Sun, 7 Apr 2024 13:46:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1218440647; Sun, 7 Apr 2024 13:46:09 +0200 (CEST) Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by mails.dpdk.org (Postfix) with ESMTP id 1D174402E0; Sun, 7 Apr 2024 13:46:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1712490367; x=1744026367; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=Xr8WbupP/zd70vJ3kwbdxVVSwUsJ9ukayozEoO36Q2Q=; b=Mx8oL72sCobjFmstRqFjeowkjk49gHJ2Gczh7ehWfwILTutm/QLq35uO vo/dvjqZgdhCS0v7dLeAut87yl781I6zcfoFzTpzFkPnVAUIWQeBQXkhw HxsCwEV3wwRSM6HA6X5eDnpx9OMKO4W47uMkU5ydzdlug3zY99Y5Af8p0 U=; X-IronPort-AV: E=Sophos;i="6.07,185,1708387200"; d="scan'208";a="393121239" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2024 11:46:04 +0000 Received: from EX19MTAEUC002.ant.amazon.com [10.0.17.79:13065] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.20.190:2525] with esmtp (Farcaster) id d288f403-a6ec-4442-8f08-7d294bf74375; Sun, 7 Apr 2024 11:46:01 +0000 (UTC) X-Farcaster-Flow-ID: d288f403-a6ec-4442-8f08-7d294bf74375 Received: from EX19D007EUA001.ant.amazon.com (10.252.50.133) by EX19MTAEUC002.ant.amazon.com (10.252.51.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Sun, 7 Apr 2024 11:46:01 +0000 Received: from EX19MTAUEC001.ant.amazon.com (10.252.135.222) by EX19D007EUA001.ant.amazon.com (10.252.50.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Sun, 7 Apr 2024 11:46:01 +0000 Received: from HFA15-CG15235BS.amazon.com (10.1.212.12) by mail-relay.amazon.com (10.252.135.200) with Microsoft SMTP Server id 15.2.1258.28 via Frontend Transport; Sun, 7 Apr 2024 11:45:59 +0000 From: To: , , , , CC: , , Shai Brandes Subject: [PATCH 1/1] net/ena/base: fix metrics excessive memory consumption Date: Sun, 7 Apr 2024 14:45:54 +0300 Message-ID: <20240407114554.1789-2-shaibran@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240407114554.1789-1-shaibran@amazon.com> References: <20240407114554.1789-1-shaibran@amazon.com> MIME-Version: 1.0 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 From: Shai Brandes [ upstream commit c8a1898f82f8c04cbe1d3e2d0eec0705386c23f7 ] The driver accidentally allocates a huge memory buffer for the customer metrics because it uses an uninitialized variable for the buffer length. This can lead to excessive memory footprint for the driver which can even fail to initialize in case of insufficient memory. Signed-off-by: Shai Brandes Reviewed-by: Amit Bernstein Fixes: f73f53f7dc7a ("net/ena: upgrade HAL") Bugzilla ID: 1400 Cc: stable@dpdk.org --- drivers/net/ena/base/ena_com.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/ena/base/ena_com.c b/drivers/net/ena/base/ena_com.c index 6953a1fa33..8ae7dcf48e 100644 --- a/drivers/net/ena/base/ena_com.c +++ b/drivers/net/ena/base/ena_com.c @@ -3134,16 +3134,18 @@ int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev, int ena_com_allocate_customer_metrics_buffer(struct ena_com_dev *ena_dev) { struct ena_customer_metrics *customer_metrics = &ena_dev->customer_metrics; + customer_metrics->buffer_len = ENA_CUSTOMER_METRICS_BUFFER_SIZE; + customer_metrics->buffer_virt_addr = NULL; ENA_MEM_ALLOC_COHERENT(ena_dev->dmadev, customer_metrics->buffer_len, customer_metrics->buffer_virt_addr, customer_metrics->buffer_dma_addr, customer_metrics->buffer_dma_handle); - if (unlikely(customer_metrics->buffer_virt_addr == NULL)) + if (unlikely(customer_metrics->buffer_virt_addr == NULL)) { + customer_metrics->buffer_len = 0; return ENA_COM_NO_MEM; - - customer_metrics->buffer_len = ENA_CUSTOMER_METRICS_BUFFER_SIZE; + } return 0; }