Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2866798lqt; Tue, 23 Apr 2024 04:16:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVJyi4zY9XAEsKPjnf6v6smfZhWAdoZV0Vul//i67dluAwsyKile6wUmyO6lUnCn9+LegktWstDy0efQ69b8ajYL7VN8qvZbeuCY1vqAw== X-Google-Smtp-Source: AGHT+IHN9IEv73pim4Yx59Db6KSE/D3UiOvA1fIGuPU83hAEfI/Y82uu57o/zBzz6T0abSq/icBC X-Received: by 2002:a05:6a00:b85:b0:6ec:d972:c3d3 with SMTP id g5-20020a056a000b8500b006ecd972c3d3mr14792957pfj.18.1713871010629; Tue, 23 Apr 2024 04:16:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713871010; cv=pass; d=google.com; s=arc-20160816; b=SH0kumMGZZIDdzED5ed97PmGopy7aeSCd0yYKQKj8FBezt++Pu3w0Tc6mLy0Phx8J5 5d23eBbEAQAU/qBW4dXdZ2rgocTTxE9zey4s+gD9+grctqk/brydNwO1xDvyBd+ANi0q TDtqvBD6GQ8h7gGhmCE6w7XzYkwXA+OvwVDiUYbs95tIKgAFoUhgskYfJ/xsBAE4iw99 vt9s8F4mP9vIkINdHtrgZSCMG/EMGIqDYx5Wr6csOkr0wODqAdEzx5U6y6KcmMOV3kZq qE7qBjdoHGJO7HCIkPaKqxh4S0ukteaFGbcUlxmdrSvYeyLwZNeMZAY6FSQrN8QJbM/U yWng== 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=cdL15pJ77Sj0Cva8ICRQ2JuwbtlCzNTOoIbNph6ObY8=; fh=kAKc6o0Qiff0GTTb9IIdBSgkMf9BPHc2vP3PAZSzHWA=; b=eddtjgQY83MkHKOTzInfxwOylqyBHOA+/gJNfFx3ZnQX3f/nKYULG08+PyP+ICdn2z QpJQRQ83b3YNL63+HS85LEDx/wLnjBvcAvfsOu4BQ55Hys87LABkd9NhsPezPkAJ4jP4 UXQtTJdEqRjMXrrggd57Y1KtxDA6LY6q45MAToUkVy4z769hc85PxirAcu1uZtVHwZsv XvrBqSH615E0v2IP/H4viaGY5MY4aqISlfgBT2akTF7z35uJFEtGksMzdFYwo/6mbbSX diQzytlgJMB7bdxzv3qT8yyPp7EA2Y7tySDypC0aHz4nKAsDqGNuRstFABTttZwIeFn6 aFVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@resnulli-us.20230601.gappssmtp.com header.s=20230601 header.b=wC8oKOk7; arc=pass (i=1 dkim=pass dkdomain=resnulli-us.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-154962-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154962-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y11-20020a056a00180b00b006e6b14382f5si6064089pfa.34.2024.04.23.04.16.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 04:16:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154962-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@resnulli-us.20230601.gappssmtp.com header.s=20230601 header.b=wC8oKOk7; arc=pass (i=1 dkim=pass dkdomain=resnulli-us.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-154962-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154962-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3EB0028296D for ; Tue, 23 Apr 2024 11:16:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 90DE07E58E; Tue, 23 Apr 2024 11:16:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b="wC8oKOk7" Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 E168B60279 for ; Tue, 23 Apr 2024 11:16:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713870998; cv=none; b=girEENuXPFbxa0uY/5Up/i3qOtxeaWPYKIiGXKtd8SKcdT+Ja2YTWSFVQDt7alNSXusvxEBYfNYvzlrgoGrfKXiJquy0y1N069DHGj/osVlXS73nPGFiYatCUVajUrLtTT3ek/bcbDYLPXPAd0twdwheaI/LUMAkg0VEpUPIEIE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713870998; c=relaxed/simple; bh=vJ7vKFjiwn65Rjcu8oRwURAmmYugDNrXhg2GErSucAc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YtlCtOkJtSHRJOREBHQEok4p0QueIA+iUDlkzBGWKYNDJArncxceQr6y1ZjU9iaUQPn5xpx4GnEC6MWQAjEBBVF0SDLDu/t0N/B0z+yR9VB67rmqolhAM4dTJhN91BPBYJdTGMvdHVmIHouAxNvzMfUg4P6jcSn6bj7otCwAJ3o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us; spf=none smtp.mailfrom=resnulli.us; dkim=pass (2048-bit key) header.d=resnulli-us.20230601.gappssmtp.com header.i=@resnulli-us.20230601.gappssmtp.com header.b=wC8oKOk7; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=resnulli.us Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-51abd9fcbf6so7484971e87.1 for ; Tue, 23 Apr 2024 04:16:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20230601.gappssmtp.com; s=20230601; t=1713870994; x=1714475794; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=cdL15pJ77Sj0Cva8ICRQ2JuwbtlCzNTOoIbNph6ObY8=; b=wC8oKOk7ZgiHqMWO6b5nkVAx+mkpNxz5AjXyGiMMXcfWZee4AXbUp1cqURMBOoUZGQ 9Lbp+cLpGPqPGxY7pvi/cw9So0Gbw/2U75spxFDcm366zZIAgtTqZpUxTh6DU7aUO+P/ yQQqm8Cl6D22lBDkPvwkL7s/2yYYxmSysl9XWhQvv2c5oB7DcMhxkfe9zcAOOJeyCIi3 4uO1T0Zwpriyni+xoHDbiSmNmY4o8UsUJZkfXoRxKBodTAmOZG1nXzkz8p+ynbjV5EwE Emmvj9l++ozi+hr55ancLGCkT5QVOPyd++Epse0cXTWDaweWsod0oneiVSR1MRRZ97Rd IbEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713870994; x=1714475794; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=cdL15pJ77Sj0Cva8ICRQ2JuwbtlCzNTOoIbNph6ObY8=; b=XDzqd+jz1C/Ci9o0x0Swfy5/V/Aw8vbnMfkmHW7cERmbcsGhuYSiAqU9rpA4TqjF4d sCXXf7z+KuxjpZpszav+MWeiEomtNVidAvFzvOq+2Q8h+nfSo+D+KC0lhtysUw3AlcNH +vuPxEbcwjm+yVPcKdnGOpM8dGJT5PJoIEo38ahv04inpi65CO7BSceUpVLASqPICocz jNM/VxmSXXBkuNQad9Rsobidffx4IFHuEAU2JpfZ045eXAdA7T2XGEOScuj11S424ad8 Z8fjz9YH5t50v40RUpORlFTj8DlSXrVnknpkWPMyhLS3r7Ae4JvssUtS1D6AfLpldgJw tnbg== X-Forwarded-Encrypted: i=1; AJvYcCUIt8nqpIrJWztfKFyiciAjMFMOFw1zloGyjCuzrXT8S6Z8YCNXiacKpBoJHn8zZV5BvAehP39I2fPX363v8jFfaNKnL1ot00tN9+pW X-Gm-Message-State: AOJu0YwebEKV5S84dPl8v0eT7aw3gwWT1yFCTbuf8L9CtQ4aQlod0HxT Rnxhs4alwdIxjNBC0Sf4BLSO/HX9T5OorRwcZyk3P8wZyuKcS+yNhv0QtXutKvM= X-Received: by 2002:a19:3855:0:b0:515:9d9e:7339 with SMTP id d21-20020a193855000000b005159d9e7339mr9434432lfj.20.1713870993542; Tue, 23 Apr 2024 04:16:33 -0700 (PDT) Received: from localhost (78-80-105-131.customers.tmcz.cz. [78.80.105.131]) by smtp.gmail.com with ESMTPSA id em3-20020a170907288300b00a5871e215c8sm1340551ejc.127.2024.04.23.04.16.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 04:16:32 -0700 (PDT) Date: Tue, 23 Apr 2024 13:16:30 +0200 From: Jiri Pirko To: "Kubalewski, Arkadiusz" Cc: "netdev@vger.kernel.org" , "vadim.fedorenko@linux.dev" , "davem@davemloft.net" , "rrameshbabu@nvidia.com" , "linux-kernel@vger.kernel.org" , "pabeni@redhat.com" , "kuba@kernel.org" , mschmidt , "Kitszel, Przemyslaw" Subject: Re: [PATCH net] dpll: fix dpll_pin_registration missing refcount Message-ID: References: <20240419194711.1075349-1-arkadiusz.kubalewski@intel.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: Tue, Apr 23, 2024 at 01:04:22PM CEST, arkadiusz.kubalewski@intel.com wrote: >>From: Jiri Pirko >>Sent: Monday, April 22, 2024 3:31 PM >> >>Fri, Apr 19, 2024 at 09:47:11PM CEST, arkadiusz.kubalewski@intel.com wrote: >>>In scenario where pin is registered with multiple parent pins via >>>dpll_pin_on_pin_register(..), belonging to the same dpll device, >>>and each time with the same set of ops/priv data, a reference >>>between a pin and dpll is created once and then refcounted, at the same >>>time the dpll_pin_registration is only checked for existence and created >>>if does not exist. This is wrong, as for the same ops/priv data a >>>registration shall be also refcounted, a child pin is also registered >>>with dpll device, until each child is unregistered the registration data >>>shall exist. >> >>I read this 3 time, don't undestand clearly the matter of the problem. >>Could you perhaps make it somehow visual? >> > >Many thanks for all your insights on this! > >Register child pin twice (via dpll_pin_on_pin_register(..)) with two different >parents but the same ops/priv. Then, a single dpll_pin_on_pin_unregister(..) will >cause below stack trace. > >It was good to add a fix in b446631f355e, but the fix did not cover a multi-parent >registration case, here I am fixing it. > >> >>> >>>Add refcount and check if all registrations are dropped before releasing >>>dpll_pin_registration resources. >>> >>>Currently, the following crash/call trace is produced when ice driver is >>>removed on the system with installed NIC which includes dpll device: >>> >>>WARNING: CPU: 51 PID: 9155 at drivers/dpll/dpll_core.c:809 dpll_pin_ops+0x20/0x30 >>>Call Trace: >>> dpll_msg_add_pin_freq+0x37/0x1d0 >>> dpll_cmd_pin_get_one+0x1c0/0x400 >>> ? __nlmsg_put+0x63/0x80 >>> dpll_pin_event_send+0x93/0x140 >>> dpll_pin_on_pin_unregister+0x3f/0x100 >>> ice_dpll_deinit_pins+0xa1/0x230 [ice] >>> ice_remove+0xf1/0x210 [ice] >>> >>>Fixes: b446631f355e ("dpll: fix dpll_xa_ref_*_del() for multiple registrations") >>>Reviewed-by: Przemek Kitszel >>>Signed-off-by: Arkadiusz Kubalewski >>>--- >>> drivers/dpll/dpll_core.c | 17 +++++++++++++---- >>> 1 file changed, 13 insertions(+), 4 deletions(-) >>> >>>diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c >>>index 64eaca80d736..7ababa327c0c 100644 >>>--- a/drivers/dpll/dpll_core.c >>>+++ b/drivers/dpll/dpll_core.c >>>@@ -40,6 +40,7 @@ struct dpll_device_registration { >>> >>> struct dpll_pin_registration { >>> struct list_head list; >>>+ refcount_t refcount; >>> const struct dpll_pin_ops *ops; >>> void *priv; >>> }; >>>@@ -81,6 +82,7 @@ dpll_xa_ref_pin_add(struct xarray *xa_pins, struct >>>dpll_pin *pin, >>> reg = dpll_pin_registration_find(ref, ops, priv); >>> if (reg) { >>> refcount_inc(&ref->refcount); >>>+ refcount_inc(®->refcount); >> >>I don't like this. Registration is supposed to be created for a single >>registration. Not you create one for many and refcount it. >> > >If register function is called with the same priv/ops, why to do all you >suggested below instead of just refcounting? > >>Instead of this, I suggest to extend __dpll_pin_register() for a >>"void *cookie" arg. That would be NULL for dpll_pin_register() caller. >>For dpll_pin_on_pin_register() caller, it would pass "parent" pointer. >> >>Than dpll_xa_ref_pin_add() can pass this cookie value to >>dpll_pin_registration_find(). The if case there would look like: >>if (reg->ops == ops && reg->priv == priv && reg->cookie == cookie) >> >>This way, we will create separate "sub-registration" for each parent. >> >>Makes sense? >> > >It would do, but only if the code would anyhow use that new parent >sub-registration explicitly for anything else later. > >Creating a sub-registration with additional parent cookie just to create a >second registration with only difference parent cookie and not using the >cookie even once after, seems overshot for a fix. Well, we have ref with multiple references and refcount, single registration instance per registration. Now you make that multiple references and refcounted as well, just because the parent is different. That is why I suggested to add the parent to the registration look-up if. Makes things a bit cleaner to read in already quite complex code. > >What you suggest is rather a refactor, but again needed only after we would >make use of the parent cooking somewhere else. >And such refactor shall target next-tree, right? Not sure what refactor you refer to. Couple of lines, similar to your version. > >Thank you! >Arkadiusz > >>> return 0; >>> } >>> ref_exists = true; >>>@@ -113,6 +115,7 @@ dpll_xa_ref_pin_add(struct xarray *xa_pins, struct >>>dpll_pin *pin, >>> reg->priv = priv; >>> if (ref_exists) >>> refcount_inc(&ref->refcount); >>>+ refcount_set(®->refcount, 1); >>> list_add_tail(®->list, &ref->registration_list); >>> >>> return 0; >>>@@ -131,8 +134,10 @@ static int dpll_xa_ref_pin_del(struct xarray >>>*xa_pins, struct dpll_pin *pin, >>> reg = dpll_pin_registration_find(ref, ops, priv); >>> if (WARN_ON(!reg)) >>> return -EINVAL; >>>- list_del(®->list); >>>- kfree(reg); >>>+ if (refcount_dec_and_test(®->refcount)) { >>>+ list_del(®->list); >>>+ kfree(reg); >>>+ } >>> if (refcount_dec_and_test(&ref->refcount)) { >>> xa_erase(xa_pins, i); >>> WARN_ON(!list_empty(&ref->registration_list)); >>>@@ -160,6 +165,7 @@ dpll_xa_ref_dpll_add(struct xarray *xa_dplls, struct >>>dpll_device *dpll, >>> reg = dpll_pin_registration_find(ref, ops, priv); >>> if (reg) { >>> refcount_inc(&ref->refcount); >>>+ refcount_inc(®->refcount); >>> return 0; >>> } >>> ref_exists = true; >>>@@ -192,6 +198,7 @@ dpll_xa_ref_dpll_add(struct xarray *xa_dplls, struct >>>dpll_device *dpll, >>> reg->priv = priv; >>> if (ref_exists) >>> refcount_inc(&ref->refcount); >>>+ refcount_set(®->refcount, 1); >>> list_add_tail(®->list, &ref->registration_list); >>> >>> return 0; >>>@@ -211,8 +218,10 @@ dpll_xa_ref_dpll_del(struct xarray *xa_dplls, struct >>>dpll_device *dpll, >>> reg = dpll_pin_registration_find(ref, ops, priv); >>> if (WARN_ON(!reg)) >>> return; >>>- list_del(®->list); >>>- kfree(reg); >>>+ if (refcount_dec_and_test(®->refcount)) { >>>+ list_del(®->list); >>>+ kfree(reg); >>>+ } >>> if (refcount_dec_and_test(&ref->refcount)) { >>> xa_erase(xa_dplls, i); >>> WARN_ON(!list_empty(&ref->registration_list)); >>> >>>base-commit: ac1a21db32eda8a09076bad025d7b848dd086d28 >>>-- >>>2.38.1 >>>