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 65C0343D6C; Thu, 28 Mar 2024 14:49:45 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 52BC341144; Thu, 28 Mar 2024 14:49:44 +0100 (CET) Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) by mails.dpdk.org (Postfix) with ESMTP id 06EC340FDE; Thu, 28 Mar 2024 14:49:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1711633783; x=1743169783; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=/22v47v434gCF1t4riF1UHRFc2F3R8yO+C1AAKS+wNA=; b=vpsICdItLovRyN8Z0Z5WL+kltiNEwPTYT/tzxkYE91azHgd6ZaP+1/9h smTrz8E3H9BkWkhWzfXg7OeneosLnVQ+XTA8E1YbyZwDK2n3uZQ3tAstt +BR7NNk3AbjjdcEDz1KrvbrT+yVJwfydu0VtqF4pwjIz/AsyFQKeEqT5e 4=; X-IronPort-AV: E=Sophos;i="6.07,162,1708387200"; d="scan'208";a="195061742" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2024 13:49:39 +0000 Received: from EX19MTAEUB002.ant.amazon.com [10.0.43.254:50833] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.40.37:2525] with esmtp (Farcaster) id 784c0c00-8ae7-437f-99f3-fb263e6d0a58; Thu, 28 Mar 2024 13:49:37 +0000 (UTC) X-Farcaster-Flow-ID: 784c0c00-8ae7-437f-99f3-fb263e6d0a58 Received: from EX19D007EUA001.ant.amazon.com (10.252.50.133) by EX19MTAEUB002.ant.amazon.com (10.252.51.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Thu, 28 Mar 2024 13:49:37 +0000 Received: from EX19MTAUWC001.ant.amazon.com (10.250.64.145) 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; Thu, 28 Mar 2024 13:49:36 +0000 Received: from HFA15-CG15235BS.amazon.com (10.85.143.172) by mail-relay.amazon.com (10.250.64.145) with Microsoft SMTP Server id 15.2.1258.28 via Frontend Transport; Thu, 28 Mar 2024 13:49:34 +0000 From: To: , , , , CC: , , Shai Brandes Subject: [PATCH 1/1] net/ena: fix metrics excessive memory consumption Date: Thu, 28 Mar 2024 15:49:25 +0200 Message-ID: <20240328134925.1150-2-shaibran@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240328134925.1150-1-shaibran@amazon.com> References: <20240328134925.1150-1-shaibran@amazon.com> MIME-Version: 1.0 Content-Type: text/plain 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 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: 14001 --- 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; } -- 2.17.1