Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp1251432lqs; Sat, 15 Jun 2024 00:33:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXY4UscIJdsHzZiiUrXiuOzDCPlaTpWyuSe/37RXi87Hbi79TV+svbAXKR9zV6okFpcOGNx9i8G+g6JeWBEIzsSK5GJKt9wy11OW8AeTw== X-Google-Smtp-Source: AGHT+IH+zFaIVGlsZC2I22moDrR9zQIbbE5ZelwxgsQhTynophCq/QYhssyn1QjWwmk4+lEDT1Jd X-Received: by 2002:a05:6602:168d:b0:7de:c720:ab1f with SMTP id ca18e2360f4ac-7ebeb66e75amr440430839f.20.1718436795067; Sat, 15 Jun 2024 00:33:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718436795; cv=pass; d=google.com; s=arc-20160816; b=qBJ9bDTp5ARvvu6Yp74AX7Zz8nv9gPQNK+KQTxqOJxL6uAPRkMKdbw+q4GHD9f5Vcq UWWewkyhqxNt31vlxrcZ6xaUJbD4IEErmxbCW4zlK0vtfUy+/b8imH15oWo1bYVlDnNi Vh3VWKpcxur3hoTz/6t5XtWdqMWRtqmDtFjoybVXWW6pY+Git8whbCFXH5RMyvzkrM7h V9g+RyX87hpSbGMoAWJ1SOzpegPzl3ls+Yl6LrBNlEL8oTQlWt/l7IBU+91RpRRvx7f0 uFd3V4XtsYiTWjWXjpF1gMLW//A+yAxP9MpXfa6Vf4qkMs9RQc1PHTtiJo7Sk556TgTi 6EKw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=tBEghfvq+5z54ZV4jIHPr7X9Oi4D60ClW3wodM8SoZ0=; fh=Zn1gQ4/ukZGPQ3sTJkY2mZRk8lbM5WlekZfZxg4iXXU=; b=VMjpU+A6GP6YlXSNeZIALHxCm6gnnUbNrG1FNXdW0/fEJVBxhJdJymL+pvVPijVXZx AzYux556O0nNXechMUPT3gODzkR5oPrdCAUSzkKuwcmCMbd9J8nO7/I090VrxX/ZSf8n sMXC8E1l3tGHLBnpR9HT0lHD/+Hk1ay7UZxbM75F+4C4TlD7ju4NOeHwD10gB3BVArq2 qeJTJs7sS9baxt0siT5EuyOVXbvykv2PINsUOnabMVxTN4fBOOjsuTxu1r0wCn9dxwoi rBmDf8PQCy+Wih+N5j0tRi1MZp5hkA/5FQwQTapG6JIVbeN56XlpL+RV9VUyv6FmPapE foEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S1ReQlZU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-215743-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215743-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6fedd4f403dsi4904022a12.160.2024.06.15.00.33.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 00:33:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215743-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S1ReQlZU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-215743-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215743-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9FF56285198 for ; Sat, 15 Jun 2024 07:33:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18A0D17BCA; Sat, 15 Jun 2024 07:33:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S1ReQlZU" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2095B524C; Sat, 15 Jun 2024 07:33:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718436782; cv=none; b=jyOUOtSWq+gaFl74uBaCC0iRwwpyU1kuKgA7RjDhXqhSERwbnK5s1n9ih+/wxHYPZjEl/QRPgGwjB/rSDnUXyqLee9eGyFMWTt60xPDhrg1RKfhH3GGncWcMjgDOw4lThvGNz53JE78BSCSxLNyRZYwoh687bMVTl4gmDtZYBHI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718436782; c=relaxed/simple; bh=wgIviLql9xjHQhQaoRPN2xsCGK+9G4KbVXYZmBVurK0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JyXu/K9PoTzGj59JQnKZmerSsGWIDo7fA6iB/HlZs2ycZyPt5JA/xWs9MvZJlXjSPUoARrogjCx9nS9npUCntkBZRmy+PdDAUnuUIkFyRMMT8/hgPAD4xN/q0fc7CTUPYx5hrpExdCkiaY4+CpzjfujNKvfmjQqARQg200DPqto= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S1ReQlZU; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 268FDC116B1; Sat, 15 Jun 2024 07:32:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718436781; bh=wgIviLql9xjHQhQaoRPN2xsCGK+9G4KbVXYZmBVurK0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S1ReQlZUGPjAAQriVbxXOTkLhtymELA+gVt31Q7ViXw4uqbhYT7LF+xjWLw8Sm17j 6p/Q7kijNVAdhdikXbvQtHZMSgemf8BIQJcjLvaqup19NUJvL8PaekpFiRcAF817F6 Cycg6cJnxY2fyhUYINrh8dGoKTzJ62jbn3C511CG6ENMahJF5ppBFTYygkfqPLwDBn ZaxcJ1SzaW5TrjWnV1M9Tkl8BYlMYlTr39AGcI3/qhQlbyfcqh6zfvBI0jWmX9Zj+y bBWRyqAk9RZbXCkfhFrtKL6Gmapm7JAkSziXZgtMsxQTvUF3cvD15UMT1Uih+j3BLl IY81STomopRzw== Date: Sat, 15 Jun 2024 08:32:56 +0100 From: Simon Horman To: Alexander Lobakin Cc: intel-wired-lan@lists.osuosl.org, Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Mina Almasry , nex.sw.ncis.osdt.itp.upstreaming@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH iwl-next 03/12] idpf: split &idpf_queue into 4 strictly-typed queue structures Message-ID: <20240615073256.GZ8447@kernel.org> References: <20240528134846.148890-1-aleksander.lobakin@intel.com> <20240528134846.148890-4-aleksander.lobakin@intel.com> <20240601085308.GY491852@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Jun 13, 2024 at 01:03:00PM +0200, Alexander Lobakin wrote: > From: Simon Horman > Date: Sat, 1 Jun 2024 09:53:08 +0100 > > > On Tue, May 28, 2024 at 03:48:37PM +0200, Alexander Lobakin wrote: > >> Currently, sizeof(struct idpf_queue) is 32 Kb. > >> This is due to the 12-bit hashtable declaration at the end of the queue. > >> This HT is needed only for Tx queues when the flow scheduling mode is > >> enabled. But &idpf_queue is unified for all of the queue types, > >> provoking excessive memory usage. > >> The unified structure in general makes the code less effective via > >> suboptimal fields placement. You can't avoid that unless you make unions > >> each 2 fields. Even then, different field alignment etc., doesn't allow > >> you to optimize things to the limit. > >> Split &idpf_queue into 4 structures corresponding to the queue types: > >> RQ (Rx queue), SQ (Tx queue), FQ (buffer queue), and CQ (completion > >> queue). Place only needed fields there and shortcuts handy for hotpath. > >> Allocate the abovementioned hashtable dynamically and only when needed, > >> keeping &idpf_tx_queue relatively short (192 bytes, same as Rx). This HT > >> is used only for OOO completions, which aren't really hotpath anyway. > >> Note that this change must be done atomically, otherwise it's really > >> easy to get lost and miss something. > >> > >> Signed-off-by: Alexander Lobakin > > > > ... > > > >> diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c > > > > ... > > > >> @@ -1158,20 +1325,22 @@ static void idpf_rxq_set_descids(struct idpf_vport *vport, struct idpf_queue *q) > >> */ > >> static int idpf_txq_group_alloc(struct idpf_vport *vport, u16 num_txq) > >> { > >> - bool flow_sch_en; > >> - int err, i; > >> + bool split, flow_sch_en; > >> + int i; > >> > >> vport->txq_grps = kcalloc(vport->num_txq_grp, > >> sizeof(*vport->txq_grps), GFP_KERNEL); > >> if (!vport->txq_grps) > >> return -ENOMEM; > >> > >> + split = idpf_is_queue_model_split(vport->txq_model); > >> flow_sch_en = !idpf_is_cap_ena(vport->adapter, IDPF_OTHER_CAPS, > >> VIRTCHNL2_CAP_SPLITQ_QSCHED); > >> > >> for (i = 0; i < vport->num_txq_grp; i++) { > >> struct idpf_txq_group *tx_qgrp = &vport->txq_grps[i]; > >> struct idpf_adapter *adapter = vport->adapter; > >> + struct idpf_txq_stash *stashes; > >> int j; > >> > >> tx_qgrp->vport = vport; > >> @@ -1180,45 +1349,62 @@ static int idpf_txq_group_alloc(struct idpf_vport *vport, u16 num_txq) > >> for (j = 0; j < tx_qgrp->num_txq; j++) { > >> tx_qgrp->txqs[j] = kzalloc(sizeof(*tx_qgrp->txqs[j]), > >> GFP_KERNEL); > >> - if (!tx_qgrp->txqs[j]) { > >> - err = -ENOMEM; > >> + if (!tx_qgrp->txqs[j]) > >> goto err_alloc; > >> - } > >> + } > >> + > >> + if (split && flow_sch_en) { > >> + stashes = kcalloc(num_txq, sizeof(*stashes), > >> + GFP_KERNEL); > > > > Hi Alexander, > > > > Here stashes is assigned a memory allocation and > > then then assigned to tx_qgrp->stashes a few lines below... > > > >> + if (!stashes) > >> + goto err_alloc; > >> + > >> + tx_qgrp->stashes = stashes; > >> } > >> > >> for (j = 0; j < tx_qgrp->num_txq; j++) { > >> - struct idpf_queue *q = tx_qgrp->txqs[j]; > >> + struct idpf_tx_queue *q = tx_qgrp->txqs[j]; > >> > >> q->dev = &adapter->pdev->dev; > >> q->desc_count = vport->txq_desc_count; > >> q->tx_max_bufs = idpf_get_max_tx_bufs(adapter); > >> q->tx_min_pkt_len = idpf_get_min_tx_pkt_len(adapter); > >> - q->vport = vport; > >> + q->netdev = vport->netdev; > >> q->txq_grp = tx_qgrp; > >> - hash_init(q->sched_buf_hash); > >> > >> - if (flow_sch_en) > >> - set_bit(__IDPF_Q_FLOW_SCH_EN, q->flags); > >> + if (!split) { > >> + q->clean_budget = vport->compln_clean_budget; > >> + idpf_queue_assign(CRC_EN, q, > >> + vport->crc_enable); > >> + } > >> + > >> + if (!flow_sch_en) > >> + continue; > >> + > >> + if (split) { > > > > ... but here elements of stashes seem to be assigned to q->stash > > without stashes having being initialised. > > > > Flagged by Smatch > > Hi! Yes, I saw the report, but isn't it a false positive? > > Allocation happens when `split && flow_sch_en`, and here we have > > if (!flow_sch_en) > continue; > > if (split) > // assign > > IOW the assignment can't happen without the allocation? Thanks, and sorry for missing the points you highlight above. I agree that this is a false positive. > > > > >> + q->stash = &stashes[j]; > >> + hash_init(q->stash->sched_buf_hash); > >> + } > >> + > >> + idpf_queue_set(FLOW_SCH_EN, q); > > Thanks, > Olek >