Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp866150lqt; Fri, 19 Apr 2024 12:51:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX74NeOr0ovz5OVou8jTex5IayrVVYCHHKlRhOK5eacOzjMUm4qF/RWEsTw3UXLhm118jeNp9MHWvohwbSQW7ikdB/0+Q+nTK4WxYLyNQ== X-Google-Smtp-Source: AGHT+IEz25UX2ue6scmBdTXZ7kPN6wicLZ4eynJQRUTUSc5XfZIXImK71pfh2r8EE5j5wed7JwwZ X-Received: by 2002:a05:6a20:1054:b0:1a8:2cd1:e493 with SMTP id gt20-20020a056a20105400b001a82cd1e493mr4131202pzc.29.1713556279814; Fri, 19 Apr 2024 12:51:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713556279; cv=pass; d=google.com; s=arc-20160816; b=N1DGEc2Ix4XieyvqEkKfYaTEMqEAcYF+2hQ1CJgBeTxm7o3RMxzombF2GXWVzTi4vQ EvpNjeAGWblyDaqSsy6TEAAw7hydkV6tM8USV552osr3TWA6GaDQfl199ONAIjghh6tJ 9+7EgYvFyBcX8GvaEV3SZbdzZwWmCK8+apHFoJoby6Q40pHg/ic2Y4tFmbCV+ssNLB9w foBGMrwhu+gSoGDtW5lay6NPJuB/Bf68nIJ1iUpgjBeKTcD3LBSPt4BxfXQr+Z7cbkmH 5J88kHtrQKKCIr35gmFK5e8ZX9zIu/+73bD3lXRUj54bBb3lgqgYfc1RkRg1MWFBHhxe 7ZwQ== 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:dkim-signature; bh=B1xBUz11i30jS97UV3Sia0rJkeny8VCCULV+O0gy+8w=; fh=HZenDJqmB/wyaTddb+IguMvTfSkWs+otIRqrVwWqb+c=; b=USELvzRox/xJH6k01egHaIo+hessWeUcEG8ew/LiDdOkDJY90Vd1xjPYHHNhXZWRZu wGcI/kt4BcUvm6ZKslw6+6xBBJL9EJn2W0tbnLtC7o5636+7MTein/PnMcubA9O/jn1z Ympm5HlJ1wt/oJqHvFY20eeOrf61fWGIPdnGmW+/lsNwecYXudI+QZ4f+IbBks9ttxWv Opl2rvvpWhI0fPAc2T8aL+1cV6bdSNxhWm4wZ3bVF5gFrp3bQ0rG1lEt9+lpdANF7Hqn wYFftbM462o8gTszWQzaMzJ73uMLgw4IF+U04wbl8Ufq8THtRIPLC+TQE7t8LWEmlVZW VkLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="no/tkbmQ"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-151919-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151919-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q5-20020a63d605000000b005dc894ea130si3747835pgg.384.2024.04.19.12.51.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 12:51:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151919-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="no/tkbmQ"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-151919-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151919-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 7156D28405A for ; Fri, 19 Apr 2024 19:51:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B338813C9C4; Fri, 19 Apr 2024 19:51:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="no/tkbmQ" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 AB5BA131188; Fri, 19 Apr 2024 19:51:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713556270; cv=none; b=f6CbEJRv5DfKmFu0RDLmMRSCKw6UyHw3woocBuT5XpbpcyQQVZWLSxtyW9lpC1Gv6zdwAMg3BRhs/Rijo4qEnlWOttegtFMWw6WCPtjQuinAEqz6tVedEExKoZ2JlJlPcnTIwiXVthzvu/uol37Pw1mMwtUYqs7XpqJg/qXfDrs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713556270; c=relaxed/simple; bh=I+KaRSuYYHq33wzOX7I6A8aqVWCW9ldBZFg7/uknzuA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=gwBkPmT/+2hAlzX5xkp342kY4qMHWrA4v0VtYNGrJYjrbhjUWfQjt4VJlarW6++7DNwrols26Tk+dcCE+N6tfJCJHTS2djnfnQjsxEjqSsN/VCZfcmQC6Bq9YSbEfE49C9iLqEk2oIvB/WD5ZGEo64i9bzNZB3cGnuL9YqrfclU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=no/tkbmQ; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713556269; x=1745092269; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=I+KaRSuYYHq33wzOX7I6A8aqVWCW9ldBZFg7/uknzuA=; b=no/tkbmQhuHqWNGiTmyi1SeRcFY3VOVMhTwqXLiUNIxwi7NY62vpYhpb HOJ16Y8tK4HqzBMocFVcL5W4UmK+liUgWdlmy8yjBNuzmM3oZ0lOdHPsp MMWi9vvYCwmdi9TIIg4dqwNNaUnHmPVkgdczf51J7kajz/hLF03K1ux2R KdisCNMRJXHDRJ1HktA7w4lnCOZB0YeHkH8r4ChVScU2jHtNpDjxxpDOZ a5pC6BjJ9qGMXg8Hjsv1DeTTzWRyIMLOWZ6Y0bzfXizQ1Dnd6P4RRzRId 8FRI36yfeAO4RXpMmJSQchIUXva3n+FpsIvjw+5yR/gfe7JgOo6pnfJba Q==; X-CSE-ConnectionGUID: ClTWVIqbQ7KhaG7fr6gd8g== X-CSE-MsgGUID: GSGavcpDTxaDsROCsUY8wg== X-IronPort-AV: E=McAfee;i="6600,9927,11049"; a="9046272" X-IronPort-AV: E=Sophos;i="6.07,214,1708416000"; d="scan'208";a="9046272" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2024 12:51:08 -0700 X-CSE-ConnectionGUID: Xe14cQuhRnyFFqD/ir7/JA== X-CSE-MsgGUID: lljCEdhZS5OOh17gqeJo+w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,214,1708416000"; d="scan'208";a="46723350" Received: from amlin-018-114.igk.intel.com ([10.102.18.114]) by fmviesa002.fm.intel.com with ESMTP; 19 Apr 2024 12:51:05 -0700 From: Arkadiusz Kubalewski To: netdev@vger.kernel.org Cc: vadim.fedorenko@linux.dev, jiri@resnulli.us, davem@davemloft.net, rrameshbabu@nvidia.com, linux-kernel@vger.kernel.org, pabeni@redhat.com, kuba@kernel.org, mschmidt@redhat.com, Arkadiusz Kubalewski , Przemek Kitszel Subject: [PATCH net] dpll: fix dpll_pin_registration missing refcount Date: Fri, 19 Apr 2024 21:47:11 +0200 Message-Id: <20240419194711.1075349-1-arkadiusz.kubalewski@intel.com> X-Mailer: git-send-email 2.38.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. 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); 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