Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1471299lqj; Tue, 4 Jun 2024 02:35:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXDhVi9hMCKO40IzzlFYHiecUq5d/VFc56Yq0XnKEI0EYyim8U486fklEgndvSiO21WOUV5d0nJR9+NvqYagSrDGarF92GXqRH2nvf/7w== X-Google-Smtp-Source: AGHT+IExWK0oPqF2A4cmGaGEMG60M4saZLT7r6Hrbf70MbiGQpG/8m6RSL0vj5FIu3Mk32D1pJeY X-Received: by 2002:a05:6214:398f:b0:6af:bd70:3653 with SMTP id 6a1803df08f44-6afbd703aeemr63537936d6.39.1717493711517; Tue, 04 Jun 2024 02:35:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717493711; cv=pass; d=google.com; s=arc-20160816; b=iqV7N/G/blZZDbAaim+wLHuXFs127mDfG4AooPdnOp6Oxgw5+ei/+8bgFJ/QA1X6FE jXPSXA0doW8JcTr/Mhf54vCCaCi62CviuTlY/zSFF9S7/5RdxjIr04YXeRwym/lKSrvJ q80S76KaE4lbDf2CFbCr22ILUuJcaFlMBr4p7Qx55TZZ1BJOxhLRi5+4T9Szk8EBtLxx sDNKyyr9LZwXuMC2DSbNeHULlBWPatSAj6tOG/Cifb3UR2rGzOZxWFJh3yqXWj2gr6lD BixPtRztIsYzxM9oT13PfyCgP+5L9M0gCrSQ9Vr3mnfvzxpn51Ae9o0dAUAUUnN+MqL5 F8Pg== 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=aNf1CwFxqtGvqsbh32RiPgc7qIjFIz6EHdx5qudJGKs=; fh=/1JAPC7lVXYtfk9mR2LIhOu8Jhc10giTT5yUf2Lr2wQ=; b=fgxfnCvvcSuoJdIJyX2P3EaprwiCc6PN6zEvfXyRDZgyTweu9j2NhpArTqkK3S5MZq iFvTwq5zlQsxcxwRbecX5u4YWUT13kf3A7I3QCk0TYW0ocLufzu4mU4H7HD3pZg6mTbj SdbWxJ1QsXy8d49ejSzSu3d8ZoayN8tku9aFnCKhqkTw2s/YzcoBohLIzFeg6mI4eFbs W/zHrWwp+4FdcSMY2+ohUXp/YjMCm8XVIYuRq+3C+Ds8H1OMJZsMRiuebldxoXRCF1kG HvjXd/+9qQUf1u7ABIsqMALY8kBWkGzPXf7AN2jIpZHc9VRCJ22WnpaAgD7fOWaIbTRf 99AQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tn7WkOYs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-200362-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200362-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6ae4b414887si105651136d6.338.2024.06.04.02.35.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 02:35:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200362-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tn7WkOYs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-200362-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200362-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8E03A1C220CD for ; Tue, 4 Jun 2024 09:34:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4C1E144306; Tue, 4 Jun 2024 09:33:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tn7WkOYs" 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 A9223823BC; Tue, 4 Jun 2024 09:33:56 +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=1717493636; cv=none; b=j0ZGI1AwfRjfRtSN9VZ3p3qVuzVGkrElYMbTH3rlPqQ/R0wPthh/cmwZ1bRmURuRp9y0ggT3Zg00Ba61nGc2KKOYpzcZ5Q6xf2k0WFQcjd8G0YUgwp4tvU78VTHTmopC7V6rr4lQ1yqRWQ2D4D8ELumXGKA3EuIipBVGsM3RC7A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717493636; c=relaxed/simple; bh=JaaBIIXHCbGmOzepuoBGmKbypMRkED1xayHQDMMQjEA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fH5+WqZEgPUPvtRrFeURfNYjy8BBzkfkvXLkJ1YIqyV8VQ3WpSWac8zlwOkPdSSzC4sG3oTa/FmC0J/fM17vlkX1WTarKdJRov3OBOIPJ4NC6zQve46UICJyHJD3w6jxTWQg7927PszVClhHo/ioBCP52YvMn+2KS0CILyXwIy8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tn7WkOYs; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88107C2BBFC; Tue, 4 Jun 2024 09:33:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717493636; bh=JaaBIIXHCbGmOzepuoBGmKbypMRkED1xayHQDMMQjEA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=tn7WkOYsrinLNfR1Du+opWfBFE7yf+/ugsZL2M5cccHBKPwCqejGEim1s4caAxbEn S0liFqOnftGDQmZfQQEggAZRVgKPq+hN9NQ2K20VuNln3Huid/Am6eDHY80NxSYF+Y RKwvO5HffShDqgg53uVB0aClx2p53l/w6k2exB3SLQH1aSjNRBk0xeG4R9+SAD3Rb/ p3of3H88+TFLAHUS2JXWM1XLHCwGK1OTa0OtPMogh66HmhOK0fUyal4a+qSHZPq77w cYoQdQv4lTIUxBJTEL6xELT6wXRJ5mcnraBoB+xG+anxvpSQKmhLxuom2hU/Y+Jw6M AwNU8QrQN45Kw== Date: Tue, 4 Jun 2024 10:33:49 +0100 From: Simon Horman To: Shradha Gupta Cc: linux-hardening@vger.kernel.org, netdev@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Colin Ian King , Ahmed Zaki , Pavan Chebbi , Souradeep Chakrabarti , Konstantin Taranov , Kees Cook , Paolo Abeni , Jakub Kicinski , Eric Dumazet , "David S. Miller" , Dexuan Cui , Wei Liu , Haiyang Zhang , "K. Y. Srinivasan" , Leon Romanovsky , Jason Gunthorpe , Long Li , Shradha Gupta Subject: Re: [PATCH net-next v3] net: mana: Allow variable size indirection table Message-ID: <20240604093349.GP491852@kernel.org> References: <1717169861-15825-1-git-send-email-shradhagupta@linux.microsoft.com> 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: <1717169861-15825-1-git-send-email-shradhagupta@linux.microsoft.com> On Fri, May 31, 2024 at 08:37:41AM -0700, Shradha Gupta wrote: > Allow variable size indirection table allocation in MANA instead > of using a constant value MANA_INDIRECT_TABLE_SIZE. > The size is now derived from the MANA_QUERY_VPORT_CONFIG and the > indirection table is allocated dynamically. > > Signed-off-by: Shradha Gupta > Reviewed-by: Dexuan Cui > Reviewed-by: Haiyang Zhang ... > diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c ... > @@ -2344,11 +2352,33 @@ static int mana_create_vport(struct mana_port_context *apc, > return mana_create_txq(apc, net); > } > > +static int mana_rss_table_alloc(struct mana_port_context *apc) > +{ > + if (!apc->indir_table_sz) { > + netdev_err(apc->ndev, > + "Indirection table size not set for vPort %d\n", > + apc->port_idx); > + return -EINVAL; > + } > + > + apc->indir_table = kcalloc(apc->indir_table_sz, sizeof(u32), GFP_KERNEL); > + if (!apc->indir_table) > + return -ENOMEM; > + > + apc->rxobj_table = kcalloc(apc->indir_table_sz, sizeof(mana_handle_t), GFP_KERNEL); > + if (!apc->rxobj_table) { > + kfree(apc->indir_table); Hi, Shradha Perhaps I am on the wrong track here, but I have some concerns about clean-up paths. Firstly. I think that apc->indir_table should be to NULL here for consistency with other clean-up paths. Or alternatively, fields of apc should not set to NULL elsewhere after being freed. In looking into this I noticed that mana_probe() does not call mana_remove() or return an error in the cases where mana_probe_port() or mana_attach() fail unless add_adev also fails. If so, is that intentional? In any case, I would suggest as a follow-up, arranging things so that when an error occurs in a function, anything that was allocated is unwound before returning an error. I think this would make allocation/deallocation easier to reason with. And I suspect it would avoid both the need for fields of structures to be zeroed after being freed, and the need to call mana_remove() from mana_probe(). > + return -ENOMEM; > + } > + > + return 0; > +} > + > static void mana_rss_table_init(struct mana_port_context *apc) > { > int i; > > - for (i = 0; i < MANA_INDIRECT_TABLE_SIZE; i++) > + for (i = 0; i < apc->indir_table_sz; i++) > apc->indir_table[i] = > ethtool_rxfh_indir_default(i, apc->num_queues); > } ... > @@ -2739,11 +2772,17 @@ static int mana_probe_port(struct mana_context *ac, int port_idx, > err = register_netdev(ndev); > if (err) { > netdev_err(ndev, "Unable to register netdev.\n"); > - goto reset_apc; > + goto free_indir; > } > > return 0; > > +free_indir: > + apc->indir_table_sz = 0; > + kfree(apc->indir_table); > + apc->indir_table = NULL; > + kfree(apc->rxobj_table); > + apc->rxobj_table = NULL; > reset_apc: > kfree(apc->rxqs); > apc->rxqs = NULL; nit: Not strictly related to this patch, but the reset_apc code should probably be a call to mana_cleanup_port_context() as it is the dual of mana_init_port_context() which is called earlier in mana_probe_port() ... > @@ -2931,6 +2972,11 @@ void mana_remove(struct gdma_dev *gd, bool suspending) > } > > unregister_netdevice(ndev); > + apc->indir_table_sz = 0; > + kfree(apc->indir_table); > + apc->indir_table = NULL; > + kfree(apc->rxobj_table); > + apc->rxobj_table = NULL; The code to free and zero indir_table_sz and indir_table appears twice in this patch. Perhaps a helper to do this, which would be the dual of mana_rss_table_alloc is in order. > > rtnl_unlock(); > ...