Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1619242lql; Wed, 13 Mar 2024 03:33:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVZMhr3eTbuv8YTpkgfasx1I8LthMAjH0pKgsIA2M3j38lGukTGPXlzmEK7uNNRy/0PpofErCvxR7bc+wEkhY/8BZVufINhLClyb9l1Gw== X-Google-Smtp-Source: AGHT+IE3iuwhnNiHOOqBX8OGSS+SCycbo7ZhUOMzMPxBAwZNkwQVHzKjlrZLTZXhEGQKEecwggtC X-Received: by 2002:a17:903:189:b0:1dd:88b6:ce0d with SMTP id z9-20020a170903018900b001dd88b6ce0dmr3268521plg.25.1710326037000; Wed, 13 Mar 2024 03:33:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710326036; cv=pass; d=google.com; s=arc-20160816; b=cVlfzbUyxPSEwKC/xRgSbFjKeSzHr7o8be+J3uYEO15Be6jMCH8+6aF8jHfhk1q9dl E1i9jM65flYhZs7zDQwvAY8u68NncJ/+5Qbh0BBiOCJlPZX8SAb3t4wcXjVvugfl4cyY n7E/ZFj+QFOPBHpXh5xVPf9nEzDTgJdS0nxRiTaGbK13S41iSlTIt4hemrbPUax3BJZy ebgmlskPFbmxWXT+F5AjLfVRh4us65+dunasIDxh8jHGt1c3gmwpSevq/1L2CB/EUl8R RtojROazJSGJXuPtsI56jnBXVxpQoSXUCoKLsJ6dsDKVkpbd/Y6h1atrH0Y9T348Zt0H pmPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=GT/cBgEGxXDwixV9KHDr6cWxeKznP/hAu4LpEwm6W0o=; fh=Mv3XY7FZITbDn994KxmPXN5Kg3lIhfl94wq5c17n8/Q=; b=It+Svn4Lz4SNAXnVRN9LDG7X5fXcC9Js8rVj4JePD7ER/H7h2163C2+cHxs1PCcUeT OxVJiXUw+PJE6FcoUsWBU9fmLt6JNiZqD5BcVlkqq3gh+cVdLx5ZJ3KSRmCzi0rbZEQd vNWn1DUxYoXWSSL9JAynBNJD9vuXoV7EakF2zW1Co7XRYN26ObD9JjExzY4TuXLA1km+ ariMUcK1xts/9ccPfp8TGXHinnUQxB79OLxQkVYUdnQxhmbzTlj8Sfaz6LaN/NMcUWVP 3Raeg6LYkYiuDsn/kdR9a2dbsHQMF15bl9FVa99VXNgJ8viAZk70vLCcjSZRb1wkV4ip fbuw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-101360-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101360-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d3-20020a170902cec300b001dd88b6ce07si7673830plg.172.2024.03.13.03.33.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 03:33:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101360-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-101360-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101360-linux.lists.archive=gmail.com@vger.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 99D7AB21B43 for ; Wed, 13 Mar 2024 10:33:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2CA1F3D3A0; Wed, 13 Mar 2024 10:33:44 +0000 (UTC) Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 009963CF72; Wed, 13 Mar 2024 10:33:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710326023; cv=none; b=fUBJJx9j6D8fT43c6gVJkN8kSSzdNKboJ/7tuujSAV/UIoW6Uy2JUfVchSO1ryD3ofmWEyOJQzHUgOBR/TRY0/JxFXzqVOzpi/IjLsPTsysTjSGEQKtgQoybMOPemtH03JOZNgPIa6kVeNngVvdsYtmGP2ArgbJnGcVyRPTp/qE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710326023; c=relaxed/simple; bh=YDBW7/p00YRMTMiZhCKdU1bl/6JNfj9O0y4oHAIAFY4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=tR9G0EAKOXYfUNUWnHwuNnQvMc3sk6ihZOxkpa8P2L+qsJZhndl4s/TCbWv93nMysJS6zAvLh/+A1ctPZs0v8LjAEKSLPH2xrzx36UCdnTobFj99XT0wjJTQlmpEF2mzA+iIJ6OYh18jN5wzGcgVx0SQ9le6M4BVSg0l47bG1fQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a45c006ab82so111895366b.3; Wed, 13 Mar 2024 03:33:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710326020; x=1710930820; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GT/cBgEGxXDwixV9KHDr6cWxeKznP/hAu4LpEwm6W0o=; b=IbwvPqQ2mkEz2xRLnZGwSThj6ihg0lAoyg0fh54zjIJgBhVdOEhQd7PILy/fUdBm+2 DzpFIyHRjzCfnSNZKBFn9o89Q5TN33wscR22LhlVVwdN0Z7zB/0syM9htY4VomP8Jvmv DVFdU+Ny5Z8g+US41zZ1HTkOoH0mMxw0zcgXYr0uD0LQ/8H2nBaiWdZKDQN5tPo4BeDB 54jEBo1se/dTc2ojdoDXZygWA5reuvFhJCZltEsrb+P8KXSyk4r9UPUa+UCftRWFjagb 1QIeXABA4r2DPwefiQlNom9IJK44kqxNDdGLKb6HYIEfC0KGloivBRHHoK3fqiLyWJxi oZ1Q== X-Forwarded-Encrypted: i=1; AJvYcCWbEdM6YYBYv/iCV1jVyOJsgtfD5w/xGj7/sq6Vu4VCmbLv7f8MY25AsE5JsSzxr7P1v/iBoaEzLYlBMrOKK/6LuDVgg48nOZsM6rfcGOyiv/iGclTpJaqO9t9rUvSF5xmmiy+QZaO6sQ== X-Gm-Message-State: AOJu0YxyQ8rMP4rATiN+Y5KRUokqncSfbPUMtT7qk1hVuDDV1QdbEZ8V fLWKriIvLP5bnMc0wB5NMadQTWW7/OW0oB8ZE7RZ6tPqdoH1Y4uN X-Received: by 2002:a17:906:68c9:b0:a45:ab8d:726a with SMTP id y9-20020a17090668c900b00a45ab8d726amr4247699ejr.26.1710326020155; Wed, 13 Mar 2024 03:33:40 -0700 (PDT) Received: from localhost (fwdproxy-lla-009.fbsv.net. [2a03:2880:30ff:9::face:b00c]) by smtp.gmail.com with ESMTPSA id jw18-20020a170906e95200b00a462520d561sm3028548ejb.54.2024.03.13.03.33.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 03:33:39 -0700 (PDT) From: Breno Leitao To: Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky Cc: kuba@kernel.org, keescook@chromium.org, linux-rdma@vger.kernel.org (open list:HFI1 DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2] IB/hfi1: allocate dummy net_device dynamically Date: Wed, 13 Mar 2024 03:33:10 -0700 Message-ID: <20240313103311.2926567-1-leitao@debian.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit struct net_device shouldn't be embedded into any structure, instead, the owner should use the priv space to embed their state into net_device. Embedding net_device into structures prohibits the usage of flexible arrays in the net_device structure. For more details, see the discussion at [1]. Un-embed the net_device from struct hfi1_netdev_rx by converting it into a pointer. Then use the leverage alloc_netdev() to allocate the net_device object at hfi1_alloc_rx(). [1] https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ Signed-off-by: Breno Leitao ---- PS: this diff needs d160c66cda0ac8614 ("net: Do not return value from init_dummy_netdev()") in order to apply and build cleanly. --- Changelog: v2: * Free struct hfi1_netdev_rx allocation if alloc_netdev() fails * Pass zero as the private size for alloc_netdev(). * Remove wrong reference for iwl in the comments --- drivers/infiniband/hw/hfi1/netdev.h | 2 +- drivers/infiniband/hw/hfi1/netdev_rx.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/netdev.h b/drivers/infiniband/hw/hfi1/netdev.h index 8aa074670a9c..07c8f77c9181 100644 --- a/drivers/infiniband/hw/hfi1/netdev.h +++ b/drivers/infiniband/hw/hfi1/netdev.h @@ -49,7 +49,7 @@ struct hfi1_netdev_rxq { * When 0 receive queues will be freed. */ struct hfi1_netdev_rx { - struct net_device rx_napi; + struct net_device *rx_napi; struct hfi1_devdata *dd; struct hfi1_netdev_rxq *rxq; int num_rx_q; diff --git a/drivers/infiniband/hw/hfi1/netdev_rx.c b/drivers/infiniband/hw/hfi1/netdev_rx.c index 720d4c85c9c9..cd6e78e257ef 100644 --- a/drivers/infiniband/hw/hfi1/netdev_rx.c +++ b/drivers/infiniband/hw/hfi1/netdev_rx.c @@ -188,7 +188,7 @@ static int hfi1_netdev_rxq_init(struct hfi1_netdev_rx *rx) int i; int rc; struct hfi1_devdata *dd = rx->dd; - struct net_device *dev = &rx->rx_napi; + struct net_device *dev = rx->rx_napi; rx->num_rx_q = dd->num_netdev_contexts; rx->rxq = kcalloc_node(rx->num_rx_q, sizeof(*rx->rxq), @@ -360,7 +360,12 @@ int hfi1_alloc_rx(struct hfi1_devdata *dd) if (!rx) return -ENOMEM; rx->dd = dd; - init_dummy_netdev(&rx->rx_napi); + rx->rx_napi = alloc_netdev(0, "dummy", NET_NAME_UNKNOWN, + init_dummy_netdev); + if (!rx->rx_napi) { + kfree(rx); + return -ENOMEM; + } xa_init(&rx->dev_tbl); atomic_set(&rx->enabled, 0); @@ -374,6 +379,7 @@ void hfi1_free_rx(struct hfi1_devdata *dd) { if (dd->netdev_rx) { dd_dev_info(dd, "hfi1 rx freed\n"); + free_netdev(dd->netdev_rx->rx_napi); kfree(dd->netdev_rx); dd->netdev_rx = NULL; } -- 2.43.0