From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 DFD8E3B3891 for ; Tue, 19 May 2026 09:13:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779182031; cv=none; b=oWtNifjRQBJLJqm8yDaCvAfO/nztrJHgkJxN47uV5DvkkSSaKoWQA3R0gzrCywcsNQnrop0hxjeDF5gASTCb06yGjvaNvwmFI65n5726VZEkiiPY+9FGOdOyE8YlGZLOI3NwEyaeZ7GdZ31B7/YYLbDpAT7f12naaEmwmOPk1fM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779182031; c=relaxed/simple; bh=Yr1naL0WjdE/A41/zRFmRBexEGZFRcqrl24tfALYhsE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jEXO+sexmaioyLSN++gAIKdflSQF+GUuipFevliOeHGRmuEzQ3c39DRIMNwqWT7yEMYWcoYGlQdb0A5ZHkbOrqkFxaduMlHQxjH0b/TsKYtuVyEi4IcywsWYPco74aFANGkl2g7F/AHcstzhlY6TakQNKBYXvTfZwIU7WfwBdgs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NN0sjwDX; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=kzS8TZ9P; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NN0sjwDX"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="kzS8TZ9P" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779182028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ay6gidP+I0vDJI41cdYOxuCXaLwaNuaZ5No08B1GxG8=; b=NN0sjwDXcgY4HF5JLeJlrysrsqLwZvl1folirl1Xsz1OkPtSFX2THtRZZdbdWWeIHmJmnP 8LWKTXqVQ3bMRz6zOmLIT1/GapdFBV22d34CS4P5grln/bIHqEjxMt9Q0C448y/wTC4FdP 86HxbYuffSxtYZ18X1Bp6URPz8DIS98= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-619-iOaSZEA7O3isMvZPYSR_xA-1; Tue, 19 May 2026 05:13:47 -0400 X-MC-Unique: iOaSZEA7O3isMvZPYSR_xA-1 X-Mimecast-MFC-AGG-ID: iOaSZEA7O3isMvZPYSR_xA_1779182027 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-44b186b715aso2018931f8f.0 for ; Tue, 19 May 2026 02:13:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1779182026; x=1779786826; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Ay6gidP+I0vDJI41cdYOxuCXaLwaNuaZ5No08B1GxG8=; b=kzS8TZ9PwmvjiUtfteHUSRJQXMamRtUNezZie+71KLNVxleIJdZXqNtys/tI7nuUMB ftGq+H/WNYCV9wtKNapLA4Rns/q8Mrf+BuFOlNtukCyfgPw5e+xebopmWAmFdsHJTi0a ptrBv1eMqjLsznhxwxk5o29EJBMQUs1ImeaWQP4HpyOSWGOSGu/IJTqr8A5xPF+mM0cp OrZzxS92VSZSLiipmFDDBFxIu/yGJrsctC1JL3R6ZKZZtUJS5ogIaXS6F566e5ubIH5T UqRSTmfGFwSREVcoatJ1i9t/fzT4HY4+Gbop2J+lQ6Au2K7fAbo/UYKd9rbAfC2zM6/E VIyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779182026; x=1779786826; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Ay6gidP+I0vDJI41cdYOxuCXaLwaNuaZ5No08B1GxG8=; b=cbUgWGOLHQ5SoNrJdP+BHz+NAHA4GZph/qKpQh+taU2MmG1ZfzX5WOEX2+8REhqrv+ mAIZFVhdaqew93PxtLQenBcBn9T8oWNKAseMPeKfIhwgI7b/mbrewVcg8+CnQvL8axNj 2LcOHyU+yTpH8jBiHnoS21BMALK9cjmRzMV54IYQKNwyHaFZsglx5LqAuvDnYqtB+dkG DnefnZf/HykIq6kllA4g2eGBzST4qRUm1z7ZfjaZ/K6AHqA7aLFrS/t54+1Q/yMbxSW4 vWsw2VTMI3UeMepQ51E2x8ZcTY1uft0vugZ8hin2QFHqq8HkwcgWVAAlDT16jatYERVM soGg== X-Forwarded-Encrypted: i=1; AFNElJ/jlQXrm1zTaj+k14hhO8d6fb74PJ7CWzxcaSjkdfHjVtsoioFbD4j8djbzmmGZGvHb5b97j14Zm3Saepc=@vger.kernel.org X-Gm-Message-State: AOJu0YyI0gn5+Wc5mOI+zj9EKNRiWHN+YLVTBx3cN+iMFYqY9NTEKTBo LQlp+z0HKG3ZSToH1D8qsyhNtmSU7roA11Uy4eSaz8ubG/JD769/ExqwkZg4TWXrbYeK3z5DCTR NdibImas48Mv0I2GtaQTpKmuzPIYyNAQ74h9zRE7RNr6MxMBGkSaSIPhBQpcnRfXtD+RFVQcocg == X-Gm-Gg: Acq92OFbI/CAL7OOh8QQx9izMS9KTE6Q0etpGkDyaHTASo1g2FPPy7UsYfRKQyg9s7L OZrEjfZJejQS0KNMOgYuQyG75uyqKG9gVdb+wi7QXGofiQ9KnSYMN4ifGSTEyR1akJRWprNh+cB YuA2cM2QacAVnBEcZPejFUMvT7pWdzTKiPN9+cbzBjQwX4susl+ft2a3+TufGIszOXVat2bZIcS 2CJaGgeY4YoQ5l+IzGzhS2GKs4tMJtPfb9ZTLj0wf03/NpMd3yt+SJYPSXOoHbYs2pcoUL2h6up ym9L951lwXzteOIVuMIyT0pJhT/N0UuK7JqfdgkUEjXG0XqdFM3H+SOGk0g2hFD1qudndD7x3WI 3ORL1QUZHGLhmqEz+RDOMXEELY0uvBPfBk8b5LmeFmmz0YcxmhiHgfA456k9uSJCKLw== X-Received: by 2002:a5d:64e4:0:b0:43e:b0f8:66f1 with SMTP id ffacd0b85a97d-45e5c5aebdcmr30874760f8f.43.1779182026475; Tue, 19 May 2026 02:13:46 -0700 (PDT) X-Received: by 2002:a5d:64e4:0:b0:43e:b0f8:66f1 with SMTP id ffacd0b85a97d-45e5c5aebdcmr30874709f8f.43.1779182026043; Tue, 19 May 2026 02:13:46 -0700 (PDT) Received: from [192.168.88.32] ([150.228.25.33]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45da0a1aeafsm46379303f8f.23.2026.05.19.02.13.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 May 2026 02:13:45 -0700 (PDT) Message-ID: Date: Tue, 19 May 2026 11:13:43 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v14 net-next 9/9] octeontx2-af: npc: cn20k: Allocate npc_priv and dstats dynamically. To: Ratheesh Kannoth , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, oss-drivers@corigine.com Cc: akiyano@amazon.com, andrew+netdev@lunn.ch, anthony.l.nguyen@intel.com, arkadiusz.kubalewski@intel.com, brett.creeley@amd.com, darinzon@amazon.com, davem@davemloft.net, donald.hunter@gmail.com, edumazet@google.com, horms@kernel.org, idosch@nvidia.com, ivecera@redhat.com, jiri@resnulli.us, kuba@kernel.org, leon@kernel.org, mbloch@nvidia.com, michael.chan@broadcom.com, pavan.chebbi@broadcom.com, petrm@nvidia.com, Prathosh.Satish@microchip.com, przemyslaw.kitszel@intel.com, saeedm@nvidia.com, sgoutham@marvell.com, tariqt@nvidia.com, vadim.fedorenko@linux.dev References: <20260514062537.3813802-1-rkannoth@marvell.com> <20260514062537.3813802-10-rkannoth@marvell.com> From: Paolo Abeni Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/15/26 9:30 AM, Ratheesh Kannoth wrote: > On 2026-05-14 at 11:55:37, Ratheesh Kannoth (rkannoth@marvell.com) wrote: >> Replace the file-scope static npc_priv with a kcalloc'd struct filled >> from hardware bank/subbank geometry at init (num_banks is no longer a >> const compile-time constant; drop init_done and use a non-NULL >> npc_priv pointer for liveness). Thread npc_priv_get() / pointer access >> through the CN20K NPC code paths, extend teardown to kfree the root >> struct on failure and in npc_cn20k_deinit, and adjust MCAM section >> setup to use the discovered subbank count. >> > >>> #include "cn20k/reg.h" >>> #include "rvu_npc_fs.h" >>> >>> -static struct npc_priv_t npc_priv = { >>> - .num_banks = MAX_NUM_BANKS, >>> -}; >>> +static struct npc_priv_t *npc_priv; >> Since npc_priv and dstats are still declared as global file-scope variables, >> won't probing multiple RVU devices cause these pointers to be overwritten? >> If a second device is probed, the allocations for the first device would be >> leaked and both devices would end up sharing the second device's state. >> On device unbind, devres will automatically free dstats, leaving a dangling >> global pointer. Additionally, npc_cn20k_deinit() explicitly frees npc_priv >> and sets it to NULL. >> If a userspace process reads a debugfs file after device unbind, could it >> cause a NULL pointer dereference on npc_priv or a use-after-free when >> accessing the dstats array? > While a global file-scope pointer introduces a shared-state risk in > drivers that support multiple instances, the structural design and > physical topology of the OcteonTX2 platform eliminate this hazard. > > First, the system architecture dictates that exactly one physical RVU > Admin Function (AF) hardware block exists per SoC layout. Because the > hardware platform cannot expose multiple active AF instances, there is > no parallel or sequential device probing sequence to trigger a race > condition, overwrite existing allocations, or cause memory leaks between distinct devices. Since at least another revision of this series is needed (see my previous email), and the code depends on the above H/W constraints, please document it explicitly somewhere inside the code. A build time or run time check would possibly be even better. >> for (int bank = npc_priv->num_banks - 1; bank >= 0; bank--) { >> for (int idx = npc_priv->bank_depth - 1; idx >= 0; idx--) { >> ... >> if (stats < dstats[0][bank][idx]) >> dstats[0][bank][idx] = 0; >> ... >> } >> Since dstats is still statically sized using MAX_NUM_BANKS and related >> macros, will this result in out-of-bounds accesses if the hardware returns >> larger values? >> Similarly, the en_map bitmap is sized using these same static constants. >> Could operations like set_bit(index, npc_priv->en_map) in >> npc_cn20k_enable_mcam_entry() corrupt the npc_priv_t structure if the >> hardware dimensions exceed the static bitmap size? > > The static definitions for the tracking arrays and bitmaps are based > strictly on the silicon's hard limits, preventing any possibility of > out-of-bounds corruption. > > The compile-time constants (MAX_NUM_BANKS, MAX_NUM_SUB_BANKS, and > MAX_SUBBANK_DEPTH) do not represent arbitrary bounds; they define the > absolute, physical maximum limits across all existing and planned SoC > variants for the CN20K hardware profile. The hardware registers cannot > expose configuration dimensions that exceed these maximum architectural limits > because the underlying silicon layout lacks the physical lines or registers > to support larger structures. A similar remark here. /P