Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp751457lqc; Fri, 8 Mar 2024 10:30:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW2X7aLVgLwdgV9Srw9x9Ab6ByGkKwKoX0W++z0LONoXcIfst+j2+4tA02l0De6S3FR02StnEiyyN31VggnXauszW6wIMgYVHTignFoHg== X-Google-Smtp-Source: AGHT+IHV4CY8CSrwJFXBquP3aaToy5wXFcjqZQJDEUGiFzxrac2F/yi6DN1bykoFUyciFNduxm3f X-Received: by 2002:a05:620a:471f:b0:788:5bc2:82bf with SMTP id bs31-20020a05620a471f00b007885bc282bfmr533297qkb.66.1709922615812; Fri, 08 Mar 2024 10:30:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709922615; cv=pass; d=google.com; s=arc-20160816; b=NwjVE2Mta3/POkkbo4kXxhlszq7er/VUvo28qnP+XICXte1PafEJF3won9IDr0ZDh/ 5aEJUJUMaPLD0nMu8DM47OfDG61D1aUnBrlshGE3MPWESs+bQOW/7C5PjXOHRoMG91o/ s4x2AsBYyO3ndkMCeWL2rlEHb3iFN5tV415vc/ZUYUrVSpJkb3wizzMxravf+uG0XcUp UpUeX7jhCZgA82tybDMkTCWhpfsJAcJrRmS5m16vkYZHqJovPgRzxhtgMVvaHCPMzsIc b7YzLi3weQ1+RWoptIa+pbxO7jRDlYXuKtsjajL3RCtT5xW9IpbMHeykyd6lX9DKRRVX IkBQ== 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=yFXpUhEJ/ItvZNUQqkXHwG73XavxT72enjAMgAKDLJc=; fh=k+XOIJNUsHzUJaDL15RNYqXCFhQXEIrRwBhvdxiqrXc=; b=DxOx9guLGrqv9MjS2zTj/yEWguL7hHt6KH4TDOzRcqV081fM6m4OgxFycwrHPmcorr 3amm9mWz4Ca5smBabcQJ9QoNMtVogSRfbAkhlRqVHz4tD8nqQ49mAMEkDPZHPWp90IC1 7wZqnHTrk+5esCZXiMUhl1gKttXnaho5txewotESz+RWjCwZ3COr6BSQuMTnrgmiHECV wDS/fJvzOTUKevjtr8a7o3qsM/wi39WV/d/xikTyk7CJax+A2YlbCTmSRzX2K8lwYppy 9Ry7cpwBNLOyu4aP22iYZE8pwJ04h8z3Kpk1LYGo9/cjiTL77MhqgFyvL1t7/tUZM9AR bqJQ==; 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-97457-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97457-linux.lists.archive=gmail.com@vger.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 p18-20020a05620a057200b007881a590422si5548qkp.15.2024.03.08.10.30.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 10:30:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97457-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; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-97457-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97457-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 88A621C21924 for ; Fri, 8 Mar 2024 18:30:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0302A56B7F; Fri, 8 Mar 2024 18:30:09 +0000 (UTC) Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 C9BE556776; Fri, 8 Mar 2024 18:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709922608; cv=none; b=tXSnIWatCB4MxAoridrLF5ZFK/AG1mHfOkwucQTMpzq8ZrOjT7tzwBtIioXMKJ5GTh8hkt+rALmTUHhpwF7b/2X8kHarU4I2Wz8nVpyaAcmGx60sJ0ownlt3ROpVMXfcJMp7jigBxhcmXYk2oZyi0qwzBkDhOYpO9c8eVAC+Mso= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709922608; c=relaxed/simple; bh=HFG1MynytzLWg0eicMZQdvo4JlKR6eu7Ns14s2RLGiw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=G79E92K/qwQn1BG4y/34ZivaBcXHvVy2QR0I3ru0sqwf7dYzjCMeGczVIWyQmAjATzbFN7Jl5yhOAKIkumnVMOvm3xbD7lPH3SMfLX+xvPsb1YyW9xRMuUU41g3DNfZvgdeMrqqGvl9l1bi90/2SIPUZjVBwpLyHKU9h00r6MI0= 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.51 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-f51.google.com with SMTP id a640c23a62f3a-a3ddc13bbb3so627851566b.0; Fri, 08 Mar 2024 10:30:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709922605; x=1710527405; 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=yFXpUhEJ/ItvZNUQqkXHwG73XavxT72enjAMgAKDLJc=; b=W2J3Hr4ZLBeGbd2wKMgm8PWzBdGJYzBeTcppGgrQnwi0oj9Sws+JoLCH9pibClQ+sq UXFOZazuvLLFs6F3L4Uo7/soYIgg8kuYw7ykQF38NTYRbRsFbMODo0FwJuB7+kSGt6It qf/KeUXxTR0KNF26DZtTljXYZQEcvp2RvzPPISK2g+hajfgGlVVvvLi4FRMT7z0hDypH fk15nOiU0TE+ptUeqp+L8tEu5bfTzrjj/DCg3ErYeMoLTZ7LYNLPzadr6BWzhzs9+PWz OSAQM+g6Sk/GDl5qc8szRDQdYHJpj9rSlfzEPU5MrWVoyx7YpgouMX3LWn1q2AU/gvKf 0aTg== X-Forwarded-Encrypted: i=1; AJvYcCVzKsfucWA0MC31hnKRuoZl5K6ilSjXGlp/ABmX3F5/1NlsY2Uq321SDbnylA4IgUfPDzQiUzq7wW74VhEf3oJGqST4fgC7WgfVHX/qPA6SSJRBOJk6Cimlc9fRjm+Ig4HdtYvGIs5hhA== X-Gm-Message-State: AOJu0Yz8+2gk0nv+WLYoCsQZ0oi34HTGJoghoxxbg6OrwJRUUvlaYcOa 0btXdnlnHveMM8T4bIpDKco7pXKrnd2NyBj6noprdg8itLBNBJIM X-Received: by 2002:a17:907:a08e:b0:a45:73b0:bcc3 with SMTP id hu14-20020a170907a08e00b00a4573b0bcc3mr801361ejc.34.1709922605113; Fri, 08 Mar 2024 10:30:05 -0800 (PST) Received: from localhost (fwdproxy-lla-111.fbsv.net. [2a03:2880:30ff:6f::face:b00c]) by smtp.gmail.com with ESMTPSA id l19-20020a170906231300b00a449d6184dasm54434eja.6.2024.03.08.10.30.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 10:30:04 -0800 (PST) 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 net-next] IB/hfi1: allocate dummy net_device dynamically Date: Fri, 8 Mar 2024 10:29:50 -0800 Message-ID: <20240308182951.2137779-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 iwl_trans_pcie by converting it into a pointer. Then use the leverage alloc_netdev() to allocate the net_device object at iwl_trans_pcie_alloc. The private data of net_device becomes a pointer for the struct iwl_trans_pcie, so, it is easy to get back to the iwl_trans_pcie parent given the net_device object. [1] https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ Signed-off-by: Breno Leitao --- drivers/infiniband/hw/hfi1/netdev.h | 2 +- drivers/infiniband/hw/hfi1/netdev_rx.c | 9 +++++++-- 2 files changed, 8 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..5c26a69fa2bb 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,11 @@ 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(sizeof(struct iwl_trans_pcie *), + "dummy", NET_NAME_UNKNOWN, + init_dummy_netdev); + if (!rx->rx_napi) + return -ENOMEM; xa_init(&rx->dev_tbl); atomic_set(&rx->enabled, 0); @@ -374,6 +378,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