From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794415246; b=1V7FVmXk6IREf6Lky4dbn/iIIwDBWXAmj8/YipJMi8dAMVbyOaxz4bocELxCCAaJY/g+ li89v+qvSf8qAyV2gIW5kN12XqWFrj+tp5h88fzsiah/KT9LbBiOROeLWFd4Jo1AmUD8o Lm+nuiO7Vvqo2R/RzMbsbRld8Vn4JBkxxnHRRFv9cNW7vhOjbYuOme9udI0467rf3Ka/f Wh01X9c3iV2gR8+FhvyDaK/FogZDJkBzviTdlgXeTCA+KO79WbK/7X5b/DNZERMh7ceUw SSrZG1/8Dyr4F+nonX2uguBSjDaefmXcfAoNuAYW3Gkii4a9vhTCykOTPahv2wWFi5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794415246; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=4UXdJhb2DeSA3nX65h3c9Ro7JbdiHIOP89nBTrO6qaY=; b=npwxMA4sJaoX0x4Hoogn4AT7YwG6HZdDrukQkqQwLSwHsZs3xh4Rn3GBjkXjP19JwrJa RbZ6Xdx6KGjTcmyH2Mjg+76qvmDVvIfzHfSrCJ8vAx01Py0JPXa6W61h+d8F91K4gFmAj dWfKEvZUycHXUgRXZpsYqKuxaVU5yyZkIwU8G2CNAokJIr2hN8nIEjOCZ2WaD09OPQcK3 PeD0HFGKQb6Vjp9ZoIFhM7RX2md9JFxZcs3qi9Tp6cbO1EZkE0WNh7JM+JoMnzdUobXCy Lx9kQB7sHid28rzChWh94RPhan1x785e3lQgrfhfxehKvX8AlpJHycbx66hxGF7ubyA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b="Q/WfYdTS"; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97580606A31C for ; Wed, 11 Nov 2026 16:40:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 97580606A31C 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.a=rsa-sha256 header.s=mimecast20190719 header.b=Q/WfYdTS DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794415244; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4UXdJhb2DeSA3nX65h3c9Ro7JbdiHIOP89nBTrO6qaY=; b=Q/WfYdTS4bdVLnmjBMGy1O9Lfxw9eni8J+OxeqnuVT1I5MIa8yiLZcN6x7QsstCNRcViJG UtEqhDh6NrblEs/JFndoEhmYRcMvx4StVaZoKXf+aN8il7BGDe6buWJ+Ik8ek3NmTkzSr/ SJugt4vwEYnoogDlebdp2dxBbA8RTZU= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-202-8oyxtDaRMGC08USG0k2hVg-1; Wed, 11 Nov 2026 11:40:38 -0500 X-MC-Unique: 8oyxtDaRMGC08USG0k2hVg-1 X-Mimecast-MFC-AGG-ID: 8oyxtDaRMGC08USG0k2hVg_1794415235 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0ABF4180061D; Wed, 11 Nov 2026 16:40:35 +0000 (UTC) Received: from ivecera-thinkpadp16vgen1.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 15DB3410; Wed, 11 Nov 2026 16:40:28 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Vadim Fedorenko , Arkadiusz Kubalewski , Jiri Pirko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Min Li , Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, Grzegorz Nitka , Karol Kolacinski , Saeed Mahameed , Tariq Toukan , Petr Oros Subject: [PATCH net-next v2 1/9] ice: dpll: notify TSPLL lock status from the periodic work only Date: Wed, 11 Nov 2026 17:40:12 +0100 Message-ID: <20261111164021.273409-2-ivecera@redhat.com> In-Reply-To: <20261111164021.273409-1-ivecera@redhat.com> References: <20261111164021.273409-1-ivecera@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Content-Type: text/plain; charset="utf-8" ice_dpll_tspll_state_on_dpll_set() notifies the TSPLL device from a callback of the TIME_REF pin. This pin belongs to an external DPLL and the DPLL core is going to run its callbacks under a lock of the pin's owner, which does not cover the TSPLL device. Only update dpll_state in the callback, so a device get reports the new state right away, and leave prev_dpll_state to ice_dpll_periodic_work_e825(), which then sends the notification. It now arrives up to 500 ms later and after the reply to the request. Refresh dpll_state on every run of the work, as the state written by the callback can be transient and the lock status can return to prev_dpll_state before the next run. No notification is sent in this case. Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera --- Changes in v2: - Merged the two comments in ice_dpll_tspll_state_on_dpll_set() (Sashiko) --- drivers/net/ethernet/intel/ice/ice_dpll.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.c b/drivers/net/ethern= et/intel/ice/ice_dpll.c index ade1fb3dd06743..0877827a6521cc 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.c +++ b/drivers/net/ethernet/intel/ice/ice_dpll.c @@ -2914,7 +2914,6 @@ ice_dpll_tspll_state_on_dpll_set(const struct dpll_pi= n *pin, void *pin_priv, struct ice_dpll_pin *p =3D pin_priv; struct ice_pf *pf =3D p->pf; enum ice_clk_src clk_src; - bool changed =3D false; struct ice_dpll *tp; int ret; =20 @@ -2939,23 +2938,16 @@ ice_dpll_tspll_state_on_dpll_set(const struct dpll_= pin *pin, void *pin_priv, =20 new_state =3D ice_dpll_tspll_lock_status_get(pf, false); =20 - /* Sync the cached lock state to what we just observed from HW - * so ice_dpll_periodic_work_e825() (cached path) does not emit - * a spurious UNLOCKED notification between now and the next - * PTP monitor tick. + /* Sync the cached lock state to what we just observed from HW. + * ice_dpll_periodic_work_e825() reads it (cached path), + * compares it with prev_dpll_state and sends the notification. + * dpll_state lets a device get report it right away. */ WRITE_ONCE(pf->ptp.tspll_locked, new_state =3D=3D DPLL_LOCK_STATUS_LOCKED); - - if (tp->prev_dpll_state !=3D new_state) { - tp->dpll_state =3D new_state; - tp->prev_dpll_state =3D new_state; - changed =3D true; - } + tp->dpll_state =3D new_state; } mutex_unlock(&pf->dplls.lock); - if (changed) - __dpll_device_change_ntf(tp->dpll); /* TSPLL reconfiguration may complete before lock is reacquired. * PTP periodic monitoring tracks and restores the final lock state. */ @@ -3372,8 +3364,8 @@ static void ice_dpll_periodic_work_e825(struct ice_pf= *pf) mutex_lock(&pf->dplls.lock); new_state =3D ice_dpll_tspll_lock_status_get(pf, true); =20 + tp->dpll_state =3D new_state; if (tp->prev_dpll_state !=3D new_state) { - tp->dpll_state =3D new_state; tp->prev_dpll_state =3D new_state; changed =3D true; } --=20 2.56.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794415249; b=aE94bA60LZSYtuJaBAihLrA9g2H4gxGQnpmiBB46Xrk4fcACODHECxM7dngnmSNwjqeT 7v9rsiRy8lpa/MpQEoM1VpdkQGP+JeNwtfJ08/7HhjgF7bPRhZqNuurdG//Pyn9qTcOzp Z/hrafpX4OYiGHE6Ixsh1CkPvByrXMZfi7s+Q5Vg03Dv+ReLtJtkfJoMkqDC88NL11jQm 5nLe8u6DcfzwM4ZVHr2C9AYUj7B6IpTDKo9QoiTER++7SKak2+4wmzeJqcBm0ZjgifO9S 7PTWpHuW+qnc3YIJ+CAe8dUCdnNNj+MFW00af/Y/oSGTIvrc+3lBukga9KI9kdBwj2A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794415249; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=GVpqEQdeZ6Xl2N3ggskm2E4WT2d/uk/VeOOShN/bjqU=; b=JGFNZ5K1UKUoCgotnxX0iGkF50d/XHmyUngv9JvxbrHmcWgfBsdKpO2+jmWKlhHXWEHu Ds2/a0Otoe9ApV4+RhMmfbQjJQW5WbRFs4Md1afMWLnoo+O0yrpPIE5OLVC7s0TTFtdGV 4zENwWDGhxTxL40+XkXpgJ2gK7P0z6cvPVju1aI96gVgTXg6dmG5lhGivhkJacJnsfurx BKdP7TAxQkUdohPhQ5JcJZt8K3b6YB2NLytnb5Z5je+/XCSYfvUxs3uRZu3mtJ0X0hxVw LqlfbwD8ZyXv4Wr6OIvCIEtcW8shmd2CpDcaph982w8dHzw0YZXw05Mv5rCQ7G7osgA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gq2lLa7d; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 204C2606A88D for ; Wed, 11 Nov 2026 16:40:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 204C2606A88D 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.a=rsa-sha256 header.s=mimecast20190719 header.b=gq2lLa7d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794415248; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GVpqEQdeZ6Xl2N3ggskm2E4WT2d/uk/VeOOShN/bjqU=; b=gq2lLa7dH2QHSvyzW3DhkAd3gijo0XncG0xLePfclmT8zqPNvZ21JGtxvA8qwjInHkCOxK X63aAruqYAzabGlzRhRSiA+joNuWTIY1OOwGkEh691pQo87mbjuLs/sxlI81NQAgVUHQeX VHhM+6cfMn0HO4iJOZFkdqnfceG7mEU= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-262-DB1KiW41P76NTV8Fl0A1NA-1; Wed, 11 Nov 2026 11:40:44 -0500 X-MC-Unique: DB1KiW41P76NTV8Fl0A1NA-1 X-Mimecast-MFC-AGG-ID: DB1KiW41P76NTV8Fl0A1NA_1794415242 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9EDF0180054D; Wed, 11 Nov 2026 16:40:41 +0000 (UTC) Received: from ivecera-thinkpadp16vgen1.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6E68B428; Wed, 11 Nov 2026 16:40:35 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Vadim Fedorenko , Arkadiusz Kubalewski , Jiri Pirko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Min Li , Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, Grzegorz Nitka , Karol Kolacinski , Saeed Mahameed , Tariq Toukan , Petr Oros Subject: [PATCH net-next v2 2/9] dpll: add domain object Date: Wed, 11 Nov 2026 17:40:13 +0100 Message-ID: <20261111164021.273409-3-ivecera@redhat.com> In-Reply-To: <20261111164021.273409-1-ivecera@redhat.com> References: <20261111164021.273409-1-ivecera@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Content-Type: text/plain; charset="utf-8" All dpll device and pin callbacks are serialized by the global dpll_lock, so a slow device stalls all others, whichever driver they belong to. Add struct dpll_domain as a preparation for serializing callbacks per driver instance. A domain groups all devices and pins created with the same (module, clock_id) pair, which is in practice one chip or card. The same pair already identifies the owner of a pin in dpll_pin_own_dpll_ref_first(), which now compares the domains instead. Domains are kept in an xarray, like devices and pins, and they live only as long as their objects. No functional change. Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera --- Changes in v2: - Moved the mutex to the next patch, which first takes it (Sashiko) - dpll_pin_own_dpll_ref_first() compares the domains --- drivers/dpll/dpll_core.c | 71 ++++++++++++++++++++++++++++++++++++---- drivers/dpll/dpll_core.h | 21 ++++++++++++ 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index 8389983f425695..c1b54e6ba430bf 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -24,6 +24,7 @@ DEFINE_MUTEX(dpll_lock); =20 DEFINE_XARRAY_FLAGS(dpll_device_xa, XA_FLAGS_ALLOC); DEFINE_XARRAY_FLAGS(dpll_pin_xa, XA_FLAGS_ALLOC); +static DEFINE_XARRAY_FLAGS(dpll_domain_xa, XA_FLAGS_ALLOC); =20 static RAW_NOTIFIER_HEAD(dpll_notifier_chain); static DEFINE_IDA(dpll_pin_idx_ida); @@ -88,6 +89,47 @@ void dpll_pin_notify(struct dpll_pin *pin, u64 src_clock= _id, call_dpll_notifiers(action, &info); } =20 +static struct dpll_domain *dpll_domain_get(u64 clock_id, struct module *mo= dule) +{ + struct dpll_domain *domain; + unsigned long i; + int ret; + + lockdep_assert_held(&dpll_lock); + + xa_for_each(&dpll_domain_xa, i, domain) { + if (domain->clock_id =3D=3D clock_id && domain->module =3D=3D module) { + refcount_inc(&domain->refcount); + return domain; + } + } + + domain =3D kzalloc_obj(*domain); + if (!domain) + return ERR_PTR(-ENOMEM); + domain->clock_id =3D clock_id; + domain->module =3D module; + refcount_set(&domain->refcount, 1); + ret =3D xa_alloc(&dpll_domain_xa, &domain->id, domain, xa_limit_32b, + GFP_KERNEL); + if (ret) { + kfree(domain); + return ERR_PTR(ret); + } + + return domain; +} + +static void dpll_domain_put(struct dpll_domain *domain) +{ + lockdep_assert_held(&dpll_lock); + + if (refcount_dec_and_test(&domain->refcount)) { + xa_erase(&dpll_domain_xa, domain->id); + kfree(domain); + } +} + static void dpll_device_tracker_alloc(struct dpll_device *dpll, dpll_tracker *tracker) { @@ -120,6 +162,7 @@ static void __dpll_device_put(struct dpll_device *dpll,= dpll_tracker *tracker) xa_erase(&dpll_device_xa, dpll->id); WARN_ON(!list_empty(&dpll->registration_list)); ref_tracker_dir_exit(&dpll->refcnt_tracker); + dpll_domain_put(dpll->domain); kfree(dpll); } } @@ -159,6 +202,7 @@ static void __dpll_pin_put(struct dpll_pin *pin, dpll_t= racker *tracker) fwnode_handle_put(pin->fwnode); dpll_pin_idx_free(pin->pin_idx); ref_tracker_dir_exit(&pin->refcnt_tracker); + dpll_domain_put(pin->domain); kfree_rcu(pin, rcu); } } @@ -366,6 +410,12 @@ dpll_device_alloc(const u64 clock_id, u32 device_idx, = struct module *module) dpll =3D kzalloc_obj(*dpll); if (!dpll) return ERR_PTR(-ENOMEM); + dpll->domain =3D dpll_domain_get(clock_id, module); + if (IS_ERR(dpll->domain)) { + ret =3D PTR_ERR(dpll->domain); + kfree(dpll); + return ERR_PTR(ret); + } refcount_set(&dpll->refcount, 1); INIT_LIST_HEAD(&dpll->registration_list); dpll->device_idx =3D device_idx; @@ -374,6 +424,7 @@ dpll_device_alloc(const u64 clock_id, u32 device_idx, s= truct module *module) ret =3D xa_alloc_cyclic(&dpll_device_xa, &dpll->id, dpll, xa_limit_32b, &dpll_device_xa_id, GFP_KERNEL); if (ret < 0) { + dpll_domain_put(dpll->domain); kfree(dpll); return ERR_PTR(ret); } @@ -664,6 +715,11 @@ dpll_pin_alloc(u64 clock_id, u32 pin_idx, struct modul= e *module, ret =3D dpll_pin_prop_dup(prop, &pin->prop); if (ret) goto err_pin_prop; + pin->domain =3D dpll_domain_get(clock_id, module); + if (IS_ERR(pin->domain)) { + ret =3D PTR_ERR(pin->domain); + goto err_domain; + } refcount_set(&pin->refcount, 1); xa_init_flags(&pin->dpll_refs, XA_FLAGS_ALLOC); xa_init_flags(&pin->parent_refs, XA_FLAGS_ALLOC); @@ -678,6 +734,8 @@ dpll_pin_alloc(u64 clock_id, u32 pin_idx, struct module= *module, xa_destroy(&pin->dpll_refs); xa_destroy(&pin->parent_refs); xa_destroy(&pin->ref_sync_pins); + dpll_domain_put(pin->domain); +err_domain: dpll_pin_prop_free(&pin->prop); err_pin_prop: kfree(pin); @@ -1156,11 +1214,11 @@ void *dpll_pin_on_pin_priv(struct dpll_pin *parent, * dpll_pin_own_dpll_ref_first - find the first owner dpll ref of a pin * @pin: pointer to a dpll pin * - * Search pin's dpll_refs for a ref whose dpll matches the pin's - * (module, clock_id) tuple, i.e. the dpll registered by the driver - * that created the pin. This ensures pin-level attributes are - * reported and modified using the owner's ops even when the pin is - * also registered with dplls from other drivers. + * Search pin's dpll_refs for a ref whose dpll belongs to the domain of + * the pin, i.e. the dpll registered by the driver that created the pin. + * This ensures pin-level attributes are reported and modified using the + * owner's ops even when the pin is also registered with dplls from other + * drivers. * * Return: pointer to the owner's dpll_pin_ref, or NULL if no * owner ref is found. @@ -1171,8 +1229,7 @@ struct dpll_pin_ref *dpll_pin_own_dpll_ref_first(stru= ct dpll_pin *pin) unsigned long i; =20 xa_for_each(&pin->dpll_refs, i, ref) { - if (ref->dpll->module =3D=3D pin->module && - ref->dpll->clock_id =3D=3D pin->clock_id) + if (ref->dpll->domain =3D=3D pin->domain) return ref; } =20 diff --git a/drivers/dpll/dpll_core.h b/drivers/dpll/dpll_core.h index da8a369556ed11..6edf7edf7a9539 100644 --- a/drivers/dpll/dpll_core.h +++ b/drivers/dpll/dpll_core.h @@ -15,12 +15,30 @@ =20 #define DPLL_REGISTERED XA_MARK_1 =20 +/** + * struct dpll_domain - group of dpll objects + * @id: index of the domain in dpll_domain_xa + * @clock_id: clock_id of the objects in the domain + * @module: module of the objects in the domain + * @refcount: number of dpll devices and pins in the domain + * + * All dpll devices and pins created with the same (module, clock_id) pair + * belong to one domain, in practice to one chip or card. + **/ +struct dpll_domain { + u32 id; + u64 clock_id; + struct module *module; + refcount_t refcount; +}; + /** * struct dpll_device - stores DPLL device internal data * @id: unique id number for device given by dpll subsystem * @device_idx: id given by dev driver * @clock_id: unique identifier (clock_id) of a dpll * @module: module of creator + * @domain: domain the device belongs to * @type: type of a dpll * @pin_refs: stores pins registered within a dpll * @refcount: refcount @@ -32,6 +50,7 @@ struct dpll_device { u32 device_idx; u64 clock_id; struct module *module; + struct dpll_domain *domain; enum dpll_type type; struct xarray pin_refs; refcount_t refcount; @@ -46,6 +65,7 @@ struct dpll_device { * @clock_id: clock_id of creator * @module: module of creator * @module_name: module name of creator + * @domain: domain the pin belongs to * @fwnode: optional reference to firmware node * @dpll_refs: hold referencees to dplls pin was registered with * @parent_refs: hold references to parent pins pin was registered with @@ -61,6 +81,7 @@ struct dpll_pin { u64 clock_id; struct module *module; char module_name[MODULE_NAME_LEN]; + struct dpll_domain *domain; struct fwnode_handle *fwnode; struct xarray dpll_refs; struct xarray parent_refs; --=20 2.56.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794415259; b=OsSQ8fHQqqbrDNmsFP43uFIqcNq1SGMwb9/Ddx0lMjiuEe9AbX3GCPEoDXWoXoHnT/Yw j7SmbFJdr/BgkJP1GKiyw4/Vt9e5RQd9hY82805xuszMEa+aCyDgVEfqSYl0tRUVe5U5D gY4JeRl3ExNde+uEGRqJirjaVZh1i1r/m87PtSCCNUuEHesne8sDJ56NrqEXKlrNg51Db EWQRR34o9bdQHurpYINJOI2xhq2d5NM5DmMePiyksFtDMKPFWe68F88nJ+Uhex2F2kh3i fnbV5OuTL4qrpkAGw0BdNrwKgItQlBhezADti5v+5SH82V1YVT/OOPze8AoMhEmR6Eg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794415259; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=umDKtDCFGzYxk2dEeezIHi8PxghDJPE6q5xyw+RAb64=; b=5iS/uJZfqZ3PKotSl3OR3DslpwFIwcmj69ywh+It3u+q2VafBssEJb5YfaNhvUwAMCgH FqU+KYlO5AWmPDrzL5gbaHtAlbyeOHLmRcI6nfPp81MLo+OZlSlrxiXx+371G/jC1e1Wk ZnVNeyXPFLMbnZwAWmQlxG6BCXar0dCJSDU2NphGDt4RsKCsFcn3SYERVV0dH34b1uNXp g+EhI7o+CIG4cwV1kFA3AbYgdcYDkJ7JbWNnsaLbJgfk4inLMEUlPNVvIHcJiMSq8mwie c1L2sv/l7WqiGio6nBcm3/L1/pk44Wu7g+uZ0pV2U0EEnzVoaVOAP4GQlDfpLtUvZaA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bEgvf4im; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2646606A33E for ; Wed, 11 Nov 2026 16:40:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B2646606A33E 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.a=rsa-sha256 header.s=mimecast20190719 header.b=bEgvf4im DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794415257; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=umDKtDCFGzYxk2dEeezIHi8PxghDJPE6q5xyw+RAb64=; b=bEgvf4im1ZLOhdbeOKAeMtFPckt99F6H2h3LZXSI9cknQZSVPCXyajhGsk8BKSdF0w/o1M RRPOE7Pz58AJUUpubEeJMlYdFWCLAuOApK4BZMvuFCRvzrhFub3frg6cQFiB5E9W68Mlgu HF0W4Ta8T/Bup02hwZxY9McnKlzvUdg= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-492-1Ws9ZcBfNfGujCZvMzrUiw-1; Wed, 11 Nov 2026 11:40:50 -0500 X-MC-Unique: 1Ws9ZcBfNfGujCZvMzrUiw-1 X-Mimecast-MFC-AGG-ID: 1Ws9ZcBfNfGujCZvMzrUiw_1794415247 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A167A1954B12; Wed, 11 Nov 2026 16:40:47 +0000 (UTC) Received: from ivecera-thinkpadp16vgen1.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0F4BE421; Wed, 11 Nov 2026 16:40:41 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Vadim Fedorenko , Arkadiusz Kubalewski , Jiri Pirko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Min Li , Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, Grzegorz Nitka , Karol Kolacinski , Saeed Mahameed , Tariq Toukan , Petr Oros Subject: [PATCH net-next v2 3/9] dpll: take domain locks around driver callbacks Date: Wed, 11 Nov 2026 17:40:14 +0100 Message-ID: <20261111164021.273409-4-ivecera@redhat.com> In-Reply-To: <20261111164021.273409-1-ivecera@redhat.com> References: <20261111164021.273409-1-ivecera@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Content-Type: text/plain; charset="utf-8" Add a mutex to struct dpll_domain. Hold the domain lock of the addressed object wherever driver callbacks can run: - netlink requests addressing a device or a pin, from pre_doit to post_doit - dumps, for each object - notifications, while the message is being built and sent Callbacks of a device run under the domain of the device. Callbacks of a pin run under the domain of the pin, also when another driver registered the pin with its dpll or under its parent pin. All callbacks a message about a pin needs are thus covered by one lock, and only one domain lock is ever held. Domains have no lock order, so registrations can connect them in any way. A request is atomic against other requests addressing objects of that domain, and messages of one object are sent in the order they were built. Requests resolving an id run no callbacks, so they do not take the lock. __dpll_{device,pin}_change_ntf() now also require the domain lock of the object. A callback can therefore only notify objects of the domain it runs under. Callbacks stay serialized by dpll_lock for now. Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera --- Changes in v2: - Added the domain mutex here, moved from the previous patch (Sashiko) --- drivers/dpll/dpll_core.c | 21 ++++++---- drivers/dpll/dpll_core.h | 12 +++++- drivers/dpll/dpll_netlink.c | 78 ++++++++++++++++++++++++++++--------- 3 files changed, 85 insertions(+), 26 deletions(-) diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index c1b54e6ba430bf..b4b2b2dc449aec 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -110,9 +110,11 @@ static struct dpll_domain *dpll_domain_get(u64 clock_i= d, struct module *module) domain->clock_id =3D clock_id; domain->module =3D module; refcount_set(&domain->refcount, 1); + mutex_init(&domain->lock); ret =3D xa_alloc(&dpll_domain_xa, &domain->id, domain, xa_limit_32b, GFP_KERNEL); if (ret) { + mutex_destroy(&domain->lock); kfree(domain); return ERR_PTR(ret); } @@ -126,6 +128,7 @@ static void dpll_domain_put(struct dpll_domain *domain) =20 if (refcount_dec_and_test(&domain->refcount)) { xa_erase(&dpll_domain_xa, domain->id); + mutex_destroy(&domain->lock); kfree(domain); } } @@ -517,7 +520,7 @@ dpll_device_registration_find(struct dpll_device *dpll, * * Make dpll device available for user space. * - * Context: Acquires a lock (dpll_lock) + * Context: Acquires dpll_lock and the domain lock of @dpll * Return: * * 0 on success * * negative - error value @@ -576,7 +579,7 @@ EXPORT_SYMBOL_GPL(dpll_device_register); * * Unregister device, make it unavailable for userspace. * Note: It does not free the memory - * Context: Acquires a lock (dpll_lock) + * Context: Acquires dpll_lock and the domain lock of @dpll */ void dpll_device_unregister(struct dpll_device *dpll, const struct dpll_device_ops *ops, void *priv) @@ -925,7 +928,7 @@ __dpll_pin_register(struct dpll_device *dpll, struct dp= ll_pin *pin, * @ops: ops for a dpll pin ops * @priv: pointer to private information of owner * - * Context: Acquires a lock (dpll_lock) + * Context: Acquires dpll_lock and domain locks * Return: * * 0 on success * * negative - error value @@ -986,7 +989,9 @@ static void dpll_pin_ref_sync_pair_del(u32 ref_sync_pin= _id) ref_sync_pin =3D xa_load(&pin->ref_sync_pins, ref_sync_pin_id); if (ref_sync_pin) { xa_erase(&pin->ref_sync_pins, ref_sync_pin_id); + mutex_lock(&pin->domain->lock); __dpll_pin_change_ntf(pin); + mutex_unlock(&pin->domain->lock); } } } @@ -1013,7 +1018,7 @@ __dpll_pin_unregister(struct dpll_device *dpll, struc= t dpll_pin *pin, * @priv: pointer to private information of owner * * Note: It does not free the memory - * Context: Acquires a lock (dpll_lock) + * Context: Acquires dpll_lock and domain locks */ void dpll_pin_unregister(struct dpll_device *dpll, struct dpll_pin *pin, const struct dpll_pin_ops *ops, void *priv) @@ -1039,7 +1044,7 @@ EXPORT_SYMBOL_GPL(dpll_pin_unregister); * Register a pin with a parent pin, create references between them and * between newly registered pin and dplls connected with a parent pin. * - * Context: Acquires a lock (dpll_lock) + * Context: Acquires dpll_lock and domain locks * Return: * * 0 on success * * negative - error value @@ -1096,7 +1101,7 @@ EXPORT_SYMBOL_GPL(dpll_pin_on_pin_register); * @ops: ops for a dpll pin * @priv: pointer to private information of owner * - * Context: Acquires a lock (dpll_lock) + * Context: Acquires dpll_lock and domain locks * Note: It does not free the memory */ void dpll_pin_on_pin_unregister(struct dpll_pin *parent, struct dpll_pin *= pin, @@ -1126,7 +1131,7 @@ EXPORT_SYMBOL_GPL(dpll_pin_on_pin_unregister); * * Once pins are paired, the user-space configuration of reference sync pa= ir * is possible. - * Context: Acquires a lock (dpll_lock) + * Context: Acquires dpll_lock and domain locks * Return: * * 0 on success * * negative - error value @@ -1139,7 +1144,9 @@ int dpll_pin_ref_sync_pair_add(struct dpll_pin *pin, mutex_lock(&dpll_lock); ret =3D xa_insert(&pin->ref_sync_pins, ref_sync_pin->id, ref_sync_pin, GFP_KERNEL); + mutex_lock(&pin->domain->lock); __dpll_pin_change_ntf(pin); + mutex_unlock(&pin->domain->lock); mutex_unlock(&dpll_lock); =20 return ret; diff --git a/drivers/dpll/dpll_core.h b/drivers/dpll/dpll_core.h index 6edf7edf7a9539..630c5a1ca572c2 100644 --- a/drivers/dpll/dpll_core.h +++ b/drivers/dpll/dpll_core.h @@ -9,6 +9,7 @@ =20 #include #include +#include #include #include #include "dpll_nl.h" @@ -16,20 +17,29 @@ #define DPLL_REGISTERED XA_MARK_1 =20 /** - * struct dpll_domain - group of dpll objects + * struct dpll_domain - group of dpll objects sharing a lock * @id: index of the domain in dpll_domain_xa * @clock_id: clock_id of the objects in the domain * @module: module of the objects in the domain * @refcount: number of dpll devices and pins in the domain + * @lock: serializes driver callbacks of the domain * * All dpll devices and pins created with the same (module, clock_id) pair * belong to one domain, in practice to one chip or card. + * + * Callbacks of a device run under the domain of the device and callbacks = of a + * pin under the domain of the pin, whichever driver registered them. Only= one + * domain lock is held at a time, so domains have no lock order. **/ struct dpll_domain { u32 id; u64 clock_id; struct module *module; refcount_t refcount; + /* Serializes the driver callbacks of all DPLL devices and pins + * that share one (module, clock_id) pair. + */ + struct mutex lock; }; =20 /** diff --git a/drivers/dpll/dpll_netlink.c b/drivers/dpll/dpll_netlink.c index e5380d95f238b3..1b4e3a0166a744 100644 --- a/drivers/dpll/dpll_netlink.c +++ b/drivers/dpll/dpll_netlink.c @@ -861,27 +861,39 @@ dpll_device_event_send(enum dpll_cmd event, struct dp= ll_device *dpll) =20 int dpll_device_create_ntf(struct dpll_device *dpll) { + int ret; + + mutex_lock(&dpll->domain->lock); dpll_device_notify(dpll, DPLL_DEVICE_CREATED); - return dpll_device_event_send(DPLL_CMD_DEVICE_CREATE_NTF, dpll); + ret =3D dpll_device_event_send(DPLL_CMD_DEVICE_CREATE_NTF, dpll); + mutex_unlock(&dpll->domain->lock); + + return ret; } =20 int dpll_device_delete_ntf(struct dpll_device *dpll) { + int ret; + + mutex_lock(&dpll->domain->lock); dpll_device_notify(dpll, DPLL_DEVICE_DELETED); - return dpll_device_event_send(DPLL_CMD_DEVICE_DELETE_NTF, dpll); + ret =3D dpll_device_event_send(DPLL_CMD_DEVICE_DELETE_NTF, dpll); + mutex_unlock(&dpll->domain->lock); + + return ret; } =20 /** * __dpll_device_change_ntf - notify that the dpll device has been changed * @dpll: registered dpll pointer * - * Context: caller must hold dpll_lock. Suitable for use inside device - * callbacks which are already invoked under dpll_lock. + * Context: caller must hold dpll_lock and the domain lock of @dpll. + * Suitable for use inside callbacks running under these locks. * Return: 0 if succeeds, error code otherwise. */ int __dpll_device_change_ntf(struct dpll_device *dpll) { - lockdep_assert_held(&dpll_lock); + lockdep_assert_held(&dpll->domain->lock); dpll_device_notify(dpll, DPLL_DEVICE_CHANGED); return dpll_device_event_send(DPLL_CMD_DEVICE_CHANGE_NTF, dpll); } @@ -891,7 +903,7 @@ EXPORT_SYMBOL_GPL(__dpll_device_change_ntf); * dpll_device_change_ntf - notify that the dpll device has been changed * @dpll: registered dpll pointer * - * Context: acquires and holds a dpll_lock. + * Context: acquires and holds dpll_lock and the domain lock of @dpll. * Return: 0 if succeeds, error code otherwise. */ int dpll_device_change_ntf(struct dpll_device *dpll) @@ -899,7 +911,9 @@ int dpll_device_change_ntf(struct dpll_device *dpll) int ret; =20 mutex_lock(&dpll_lock); + mutex_lock(&dpll->domain->lock); ret =3D __dpll_device_change_ntf(dpll); + mutex_unlock(&dpll->domain->lock); mutex_unlock(&dpll_lock); =20 return ret; @@ -941,27 +955,39 @@ dpll_pin_event_send(enum dpll_cmd event, struct dpll_= pin *pin) =20 int dpll_pin_create_ntf(struct dpll_pin *pin, u64 src_clock_id) { + int ret; + + mutex_lock(&pin->domain->lock); dpll_pin_notify(pin, src_clock_id, DPLL_PIN_CREATED); - return dpll_pin_event_send(DPLL_CMD_PIN_CREATE_NTF, pin); + ret =3D dpll_pin_event_send(DPLL_CMD_PIN_CREATE_NTF, pin); + mutex_unlock(&pin->domain->lock); + + return ret; } =20 int dpll_pin_delete_ntf(struct dpll_pin *pin, u64 src_clock_id) { + int ret; + + mutex_lock(&pin->domain->lock); dpll_pin_notify(pin, src_clock_id, DPLL_PIN_DELETED); - return dpll_pin_event_send(DPLL_CMD_PIN_DELETE_NTF, pin); + ret =3D dpll_pin_event_send(DPLL_CMD_PIN_DELETE_NTF, pin); + mutex_unlock(&pin->domain->lock); + + return ret; } =20 /** * __dpll_pin_change_ntf - notify that the pin has been changed * @pin: registered pin pointer * - * Context: caller must hold dpll_lock. Suitable for use inside pin - * callbacks which are already invoked under dpll_lock. + * Context: caller must hold dpll_lock and the domain lock of @pin. + * Suitable for use inside callbacks running under these locks. * Return: 0 if succeeds, error code otherwise. */ int __dpll_pin_change_ntf(struct dpll_pin *pin) { - lockdep_assert_held(&dpll_lock); + lockdep_assert_held(&pin->domain->lock); dpll_pin_notify(pin, pin->clock_id, DPLL_PIN_CHANGED); return dpll_pin_event_send(DPLL_CMD_PIN_CHANGE_NTF, pin); } @@ -971,7 +997,7 @@ EXPORT_SYMBOL_GPL(__dpll_pin_change_ntf); * dpll_pin_change_ntf - notify that the pin has been changed * @pin: registered pin pointer * - * Context: acquires and holds a dpll_lock. + * Context: acquires and holds dpll_lock and the domain lock of @pin. * Return: 0 if succeeds, error code otherwise. */ int dpll_pin_change_ntf(struct dpll_pin *pin) @@ -979,7 +1005,9 @@ int dpll_pin_change_ntf(struct dpll_pin *pin) int ret; =20 mutex_lock(&dpll_lock); + mutex_lock(&pin->domain->lock); ret =3D __dpll_pin_change_ntf(pin); + mutex_unlock(&pin->domain->lock); mutex_unlock(&dpll_lock); =20 return ret; @@ -1780,7 +1808,9 @@ int dpll_nl_pin_get_dumpit(struct sk_buff *skb, struc= t netlink_callback *cb) ret =3D -EMSGSIZE; break; } + mutex_lock(&pin->domain->lock); ret =3D dpll_cmd_pin_get_one(skb, pin, cb->extack); + mutex_unlock(&pin->domain->lock); if (ret) { genlmsg_cancel(skb, hdr); if (ret =3D=3D -ENODEV) { @@ -1999,7 +2029,9 @@ int dpll_nl_device_get_dumpit(struct sk_buff *skb, st= ruct netlink_callback *cb) ret =3D -EMSGSIZE; break; } + mutex_lock(&dpll->domain->lock); ret =3D dpll_device_get_one(dpll, skb, cb->extack); + mutex_unlock(&dpll->domain->lock); if (ret) { genlmsg_cancel(skb, hdr); break; @@ -2018,6 +2050,7 @@ int dpll_nl_device_get_dumpit(struct sk_buff *skb, st= ruct netlink_callback *cb) int dpll_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) { + struct dpll_device *dpll; u32 id; =20 if (GENL_REQ_ATTR_CHECK(info, DPLL_A_ID)) @@ -2025,11 +2058,13 @@ int dpll_pre_doit(const struct genl_split_ops *ops,= struct sk_buff *skb, =20 mutex_lock(&dpll_lock); id =3D nla_get_u32(info->attrs[DPLL_A_ID]); - info->user_ptr[0] =3D dpll_device_get_by_id(id); - if (!info->user_ptr[0]) { + dpll =3D dpll_device_get_by_id(id); + if (!dpll) { NL_SET_ERR_MSG(info->extack, "device not found"); goto unlock; } + info->user_ptr[0] =3D dpll; + mutex_lock(&dpll->domain->lock); return 0; unlock: mutex_unlock(&dpll_lock); @@ -2039,6 +2074,9 @@ int dpll_pre_doit(const struct genl_split_ops *ops, s= truct sk_buff *skb, void dpll_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) { + struct dpll_device *dpll =3D info->user_ptr[0]; + + mutex_unlock(&dpll->domain->lock); mutex_unlock(&dpll_lock); } =20 @@ -2061,6 +2099,7 @@ dpll_unlock_doit(const struct genl_split_ops *ops, st= ruct sk_buff *skb, int dpll_pin_pre_doit(const struct genl_split_ops *ops, struct sk_buff *sk= b, struct genl_info *info) { + struct dpll_pin *pin; int ret; =20 mutex_lock(&dpll_lock); @@ -2068,14 +2107,14 @@ int dpll_pin_pre_doit(const struct genl_split_ops *= ops, struct sk_buff *skb, ret =3D -EINVAL; goto unlock_dev; } - info->user_ptr[0] =3D xa_load(&dpll_pin_xa, - nla_get_u32(info->attrs[DPLL_A_PIN_ID])); - if (!info->user_ptr[0] || - !dpll_pin_available(info->user_ptr[0])) { + pin =3D xa_load(&dpll_pin_xa, nla_get_u32(info->attrs[DPLL_A_PIN_ID])); + if (!pin || !dpll_pin_available(pin)) { NL_SET_ERR_MSG(info->extack, "pin not found"); ret =3D -ENODEV; goto unlock_dev; } + info->user_ptr[0] =3D pin; + mutex_lock(&pin->domain->lock); =20 return 0; =20 @@ -2087,5 +2126,8 @@ int dpll_pin_pre_doit(const struct genl_split_ops *op= s, struct sk_buff *skb, void dpll_pin_post_doit(const struct genl_split_ops *ops, struct sk_buff *= skb, struct genl_info *info) { + struct dpll_pin *pin =3D info->user_ptr[0]; + + mutex_unlock(&pin->domain->lock); mutex_unlock(&dpll_lock); } --=20 2.56.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794415263; b=Qzw5AtdfzHMRDW3HUiKKjXesybjDfft8aNxvPvH9oOS98Q2LY99UDLD7DX1ubgQhN30k NIBbbEMKADcgsWIwV5aWL+2e37Xs1+13ZxLHguajVdmuDt2thkDa85kenhepR/VCxsiIf QAhzA5iMBG1sfgDPA6W50Sy5SRg1oJad4QviMoefQY2umiP+2df4YPKlMMDsCz08ZSyp5 XkxpxBQtRfnFY8n+g1OpmrVkChQohJx5hxFaxndgB5EJm5etlhp/xw9Rq2NQAIjKmv2+o ybSRBQBOQ4wtD6aBETMrhI2lf2F44Nl+L0z904z+H4Xn5K8UwQvT2aH9+J/zn1GjLrg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794415263; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=lRqsjk0A3D+1SinYrhqnbnjoAOHbhQtms1itlFQ68EE=; b=GKqBseTzt1W9VayxxSCVvv+AvUu1OEBNqA9/1O7VSZSEhYFXQD9X+LvGY2gaq6g3FUn+ h+vbpwoVI9Pqj9fIzbgZrLfRorM5m3Q3JHWNSm8FcDBrBkxUT4+oFv4kkkUhe/4sI8hp1 nIZSRc+Fvy4EG0NfjbbMbl5wbrCKpXkli7Bo/PYY/I3CYtC6IGYNScdAM2L+MG+rC1MP0 h/La1qRcObzNZNVYLj237sw3Sg+K1IgwvR99n9OhjXvcIOn9fds8oCv6sj7i/bc0A72Su RdrJ0V7v3h1c+W55CuS4SOr9BvCUR8BzhBf5+uZf0bgpaXae1zwLPDyb6zzmWGNayXg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=V16GpfYA; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5C13606A31C for ; Wed, 11 Nov 2026 16:41:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C5C13606A31C 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.a=rsa-sha256 header.s=mimecast20190719 header.b=V16GpfYA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794415261; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lRqsjk0A3D+1SinYrhqnbnjoAOHbhQtms1itlFQ68EE=; b=V16GpfYAMRD5uUwRm+oZqf5mNS+0iPDzKDkYIW9AueSqEuWwUfi4x3+8T88HIQJofsXsLc +oYhA5v7y+BRm6MtjRre5ChCUel+CNEQ6/n3bIa8Bu7GWPOx82OVkrH41ALA8kkZ2v2dXt ju3qGm4GjAhLXEXLBNqIoNm7+93/F3Y= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-126-BkJZ6L9CMAijsIC7z7N7qg-1; Wed, 11 Nov 2026 11:40:57 -0500 X-MC-Unique: BkJZ6L9CMAijsIC7z7N7qg-1 X-Mimecast-MFC-AGG-ID: BkJZ6L9CMAijsIC7z7N7qg_1794415254 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DCD8319540F2; Wed, 11 Nov 2026 16:40:53 +0000 (UTC) Received: from ivecera-thinkpadp16vgen1.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0BD0E421; Wed, 11 Nov 2026 16:40:47 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Vadim Fedorenko , Arkadiusz Kubalewski , Jiri Pirko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Min Li , Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, Grzegorz Nitka , Karol Kolacinski , Saeed Mahameed , Tariq Toukan , Petr Oros Subject: [PATCH net-next v2 4/9] dpll: convert dpll_lock to rwsem Date: Wed, 11 Nov 2026 17:40:15 +0100 Message-ID: <20261111164021.273409-5-ivecera@redhat.com> In-Reply-To: <20261111164021.273409-1-ivecera@redhat.com> References: <20261111164021.273409-1-ivecera@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Content-Type: text/plain; charset="utf-8" Driver callbacks are now serialized by domain locks, so dpll_lock only has to protect the topology and lifetime of devices and pins. Convert it to an rwsem. Core functions changing the topology take it for write. Netlink requests, each part of a dump and change notifications take it for read, for their whole duration, so objects found by a lookup stay valid. This is the patch that lets callbacks of different domains run concurrently. A callback running for long still blocks topology changes, and a waiting writer blocks new readers, so a stuck callback stalls the subsystem while a device is being probed or removed. This is no worse than the global serialization it replaces. Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera --- Changes in v2: - lockdep_assert_held_write() in dpll_domain_get() and dpll_domain_put() (Sashiko) --- drivers/dpll/dpll_core.c | 97 +++++++++++++++++-------------------- drivers/dpll/dpll_core.h | 3 +- drivers/dpll/dpll_netlink.c | 32 ++++++------ 3 files changed, 63 insertions(+), 69 deletions(-) diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index b4b2b2dc449aec..2b1dfe2929647e 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -19,8 +19,12 @@ #include "dpll_core.h" #include "dpll_netlink.h" =20 -/* Mutex lock to protect DPLL subsystem devices and pins */ -DEFINE_MUTEX(dpll_lock); +/* Protects the topology and lifetime of DPLL devices and pins. Taken for = write + * to change them and for read for the whole netlink request, part of a du= mp or + * change notification that uses them. Driver callbacks are serialized by = domain + * locks, which are only taken under this lock. + */ +DECLARE_RWSEM(dpll_lock); =20 DEFINE_XARRAY_FLAGS(dpll_device_xa, XA_FLAGS_ALLOC); DEFINE_XARRAY_FLAGS(dpll_pin_xa, XA_FLAGS_ALLOC); @@ -95,7 +99,7 @@ static struct dpll_domain *dpll_domain_get(u64 clock_id, = struct module *module) unsigned long i; int ret; =20 - lockdep_assert_held(&dpll_lock); + lockdep_assert_held_write(&dpll_lock); =20 xa_for_each(&dpll_domain_xa, i, domain) { if (domain->clock_id =3D=3D clock_id && domain->module =3D=3D module) { @@ -124,7 +128,7 @@ static struct dpll_domain *dpll_domain_get(u64 clock_id= , struct module *module) =20 static void dpll_domain_put(struct dpll_domain *domain) { - lockdep_assert_held(&dpll_lock); + lockdep_assert_held_write(&dpll_lock); =20 if (refcount_dec_and_test(&domain->refcount)) { xa_erase(&dpll_domain_xa, domain->id); @@ -459,7 +463,7 @@ dpll_device_get(u64 clock_id, u32 device_idx, struct mo= dule *module, struct dpll_device *dpll, *ret =3D NULL; unsigned long index; =20 - mutex_lock(&dpll_lock); + down_write(&dpll_lock); xa_for_each(&dpll_device_xa, index, dpll) { if (dpll->clock_id =3D=3D clock_id && dpll->device_idx =3D=3D device_idx && @@ -475,7 +479,7 @@ dpll_device_get(u64 clock_id, u32 device_idx, struct mo= dule *module, dpll_device_tracker_alloc(ret, tracker); } =20 - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); =20 return ret; } @@ -492,9 +496,9 @@ EXPORT_SYMBOL_GPL(dpll_device_get); */ void dpll_device_put(struct dpll_device *dpll, dpll_tracker *tracker) { - mutex_lock(&dpll_lock); + down_write(&dpll_lock); __dpll_device_put(dpll, tracker); - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); } EXPORT_SYMBOL_GPL(dpll_device_put); =20 @@ -540,16 +544,16 @@ int dpll_device_register(struct dpll_device *dpll, en= um dpll_type type, if (WARN_ON(type < DPLL_TYPE_PPS || type > DPLL_TYPE_MAX)) return -EINVAL; =20 - mutex_lock(&dpll_lock); + down_write(&dpll_lock); reg =3D dpll_device_registration_find(dpll, ops, priv); if (reg) { - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); return -EEXIST; } =20 reg =3D kzalloc_obj(*reg); if (!reg) { - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); return -ENOMEM; } reg->ops =3D ops; @@ -559,13 +563,13 @@ int dpll_device_register(struct dpll_device *dpll, en= um dpll_type type, first_registration =3D list_empty(&dpll->registration_list); list_add_tail(®->list, &dpll->registration_list); if (!first_registration) { - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); return 0; } =20 xa_set_mark(&dpll_device_xa, dpll->id, DPLL_REGISTERED); dpll_device_create_ntf(dpll); - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); =20 return 0; } @@ -586,12 +590,12 @@ void dpll_device_unregister(struct dpll_device *dpll, { struct dpll_device_registration *reg; =20 - mutex_lock(&dpll_lock); + down_write(&dpll_lock); ASSERT_DPLL_REGISTERED(dpll); dpll_device_delete_ntf(dpll); reg =3D dpll_device_registration_find(dpll, ops, priv); if (WARN_ON(!reg)) { - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); return; } list_del(®->list); @@ -599,11 +603,11 @@ void dpll_device_unregister(struct dpll_device *dpll, kfree(reg); =20 if (!list_empty(&dpll->registration_list)) { - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); return; } xa_clear_mark(&dpll_device_xa, dpll->id, DPLL_REGISTERED); - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); } EXPORT_SYMBOL_GPL(dpll_device_unregister); =20 @@ -771,9 +775,9 @@ int register_dpll_notifier(struct notifier_block *nb) { int ret; =20 - mutex_lock(&dpll_lock); + down_write(&dpll_lock); ret =3D raw_notifier_chain_register(&dpll_notifier_chain, nb); - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); return ret; } EXPORT_SYMBOL_GPL(register_dpll_notifier); @@ -782,9 +786,9 @@ int unregister_dpll_notifier(struct notifier_block *nb) { int ret; =20 - mutex_lock(&dpll_lock); + down_write(&dpll_lock); ret =3D raw_notifier_chain_unregister(&dpll_notifier_chain, nb); - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); return ret; } EXPORT_SYMBOL_GPL(unregister_dpll_notifier); @@ -812,7 +816,7 @@ dpll_pin_get(u64 clock_id, u32 pin_idx, struct module *= module, struct dpll_pin *pos, *ret =3D NULL; unsigned long i; =20 - mutex_lock(&dpll_lock); + down_write(&dpll_lock); xa_for_each(&dpll_pin_xa, i, pos) { if (pos->clock_id =3D=3D clock_id && pos->pin_idx =3D=3D pin_idx && @@ -827,7 +831,7 @@ dpll_pin_get(u64 clock_id, u32 pin_idx, struct module *= module, if (!IS_ERR(ret)) dpll_pin_tracker_alloc(ret, tracker); } - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); =20 return ret; } @@ -844,9 +848,9 @@ EXPORT_SYMBOL_GPL(dpll_pin_get); */ void dpll_pin_put(struct dpll_pin *pin, dpll_tracker *tracker) { - mutex_lock(&dpll_lock); + down_write(&dpll_lock); __dpll_pin_put(pin, tracker); - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); } EXPORT_SYMBOL_GPL(dpll_pin_put); =20 @@ -859,10 +863,10 @@ EXPORT_SYMBOL_GPL(dpll_pin_put); */ void dpll_pin_fwnode_set(struct dpll_pin *pin, struct fwnode_handle *fwnod= e) { - mutex_lock(&dpll_lock); + down_write(&dpll_lock); fwnode_handle_put(pin->fwnode); /* Drop fwnode previously set */ pin->fwnode =3D fwnode_handle_get(fwnode); - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); } EXPORT_SYMBOL_GPL(dpll_pin_fwnode_set); =20 @@ -885,7 +889,7 @@ struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_han= dle *fwnode, struct dpll_pin *pin, *ret =3D NULL; unsigned long index; =20 - mutex_lock(&dpll_lock); + down_write(&dpll_lock); xa_for_each(&dpll_pin_xa, index, pin) { if (pin->fwnode =3D=3D fwnode) { __dpll_pin_hold(pin, tracker); @@ -893,7 +897,7 @@ struct dpll_pin *fwnode_dpll_pin_find(struct fwnode_han= dle *fwnode, break; } } - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); =20 return ret; } @@ -950,7 +954,7 @@ dpll_pin_register(struct dpll_device *dpll, struct dpll= _pin *pin, DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE))) return -EINVAL; =20 - mutex_lock(&dpll_lock); + down_write(&dpll_lock); =20 dev_ops =3D dpll_device_ops(dpll); if (WARN_ON(ops->measured_freq_get && @@ -974,7 +978,7 @@ dpll_pin_register(struct dpll_device *dpll, struct dpll= _pin *pin, =20 ret =3D __dpll_pin_register(dpll, pin, ops, priv, NULL); out_unlock: - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); =20 return ret; } @@ -1028,9 +1032,9 @@ void dpll_pin_unregister(struct dpll_device *dpll, st= ruct dpll_pin *pin, if (WARN_ON(!xa_empty(&pin->parent_refs))) return; =20 - mutex_lock(&dpll_lock); + down_write(&dpll_lock); __dpll_pin_unregister(dpll, pin, ops, priv, NULL); - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); } EXPORT_SYMBOL_GPL(dpll_pin_unregister); =20 @@ -1064,7 +1068,7 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent,= struct dpll_pin *pin, WARN_ON(!ops->direction_get)) return -EINVAL; =20 - mutex_lock(&dpll_lock); + down_write(&dpll_lock); ret =3D dpll_xa_ref_pin_add(&pin->parent_refs, parent, ops, priv, pin); if (ret) goto unlock; @@ -1076,7 +1080,7 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent,= struct dpll_pin *pin, } dpll_pin_create_ntf(pin, parent->clock_id); } - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); =20 return ret; =20 @@ -1089,7 +1093,7 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent,= struct dpll_pin *pin, } dpll_xa_ref_pin_del(&pin->parent_refs, parent, ops, priv, pin); unlock: - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); return ret; } EXPORT_SYMBOL_GPL(dpll_pin_on_pin_register); @@ -1111,7 +1115,7 @@ void dpll_pin_on_pin_unregister(struct dpll_pin *pare= nt, struct dpll_pin *pin, struct dpll_pin_ref *ref; unsigned long i; =20 - mutex_lock(&dpll_lock); + down_write(&dpll_lock); xa_for_each(&pin->dpll_refs, i, ref) { reg =3D dpll_pin_registration_find(ref, ops, priv, parent); if (!reg) @@ -1120,7 +1124,7 @@ void dpll_pin_on_pin_unregister(struct dpll_pin *pare= nt, struct dpll_pin *pin, __dpll_pin_unregister(ref->dpll, pin, ops, priv, parent); } dpll_xa_ref_pin_del(&pin->parent_refs, parent, ops, priv, pin); - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); } EXPORT_SYMBOL_GPL(dpll_pin_on_pin_unregister); =20 @@ -1141,13 +1145,13 @@ int dpll_pin_ref_sync_pair_add(struct dpll_pin *pin, { int ret; =20 - mutex_lock(&dpll_lock); + down_write(&dpll_lock); ret =3D xa_insert(&pin->ref_sync_pins, ref_sync_pin->id, ref_sync_pin, GFP_KERNEL); mutex_lock(&pin->domain->lock); __dpll_pin_change_ntf(pin); mutex_unlock(&pin->domain->lock); - mutex_unlock(&dpll_lock); + up_write(&dpll_lock); =20 return ret; } @@ -1253,23 +1257,12 @@ const struct dpll_pin_ops *dpll_pin_ops(struct dpll= _pin_ref *ref) =20 static int __init dpll_init(void) { - int ret; - - ret =3D genl_register_family(&dpll_nl_family); - if (ret) - goto error; - - return 0; - -error: - mutex_destroy(&dpll_lock); - return ret; + return genl_register_family(&dpll_nl_family); } =20 static void __exit dpll_exit(void) { genl_unregister_family(&dpll_nl_family); - mutex_destroy(&dpll_lock); } =20 subsys_initcall(dpll_init); diff --git a/drivers/dpll/dpll_core.h b/drivers/dpll/dpll_core.h index 630c5a1ca572c2..e212e53528e33b 100644 --- a/drivers/dpll/dpll_core.h +++ b/drivers/dpll/dpll_core.h @@ -12,6 +12,7 @@ #include #include #include +#include #include "dpll_nl.h" =20 #define DPLL_REGISTERED XA_MARK_1 @@ -129,7 +130,7 @@ const struct dpll_pin_ops *dpll_pin_ops(struct dpll_pin= _ref *ref); struct dpll_pin_ref *dpll_xa_ref_dpll_first(struct xarray *xa_refs); extern struct xarray dpll_device_xa; extern struct xarray dpll_pin_xa; -extern struct mutex dpll_lock; +extern struct rw_semaphore dpll_lock; =20 void dpll_device_notify(struct dpll_device *dpll, unsigned long action); void dpll_pin_notify(struct dpll_pin *pin, u64 src_clock_id, diff --git a/drivers/dpll/dpll_netlink.c b/drivers/dpll/dpll_netlink.c index 1b4e3a0166a744..9d8f5d1ce97248 100644 --- a/drivers/dpll/dpll_netlink.c +++ b/drivers/dpll/dpll_netlink.c @@ -910,11 +910,11 @@ int dpll_device_change_ntf(struct dpll_device *dpll) { int ret; =20 - mutex_lock(&dpll_lock); + down_read(&dpll_lock); mutex_lock(&dpll->domain->lock); ret =3D __dpll_device_change_ntf(dpll); mutex_unlock(&dpll->domain->lock); - mutex_unlock(&dpll_lock); + up_read(&dpll_lock); =20 return ret; } @@ -1004,11 +1004,11 @@ int dpll_pin_change_ntf(struct dpll_pin *pin) { int ret; =20 - mutex_lock(&dpll_lock); + down_read(&dpll_lock); mutex_lock(&pin->domain->lock); ret =3D __dpll_pin_change_ntf(pin); mutex_unlock(&pin->domain->lock); - mutex_unlock(&dpll_lock); + up_read(&dpll_lock); =20 return ret; } @@ -1795,7 +1795,7 @@ int dpll_nl_pin_get_dumpit(struct sk_buff *skb, struc= t netlink_callback *cb) unsigned long i; int ret =3D 0; =20 - mutex_lock(&dpll_lock); + down_read(&dpll_lock); xa_for_each_marked_start(&dpll_pin_xa, i, pin, DPLL_REGISTERED, ctx->idx) { if (!dpll_pin_available(pin)) @@ -1821,7 +1821,7 @@ int dpll_nl_pin_get_dumpit(struct sk_buff *skb, struc= t netlink_callback *cb) } genlmsg_end(skb, hdr); } - mutex_unlock(&dpll_lock); + up_read(&dpll_lock); =20 if (ret =3D=3D -EMSGSIZE) { ctx->idx =3D i; @@ -2019,7 +2019,7 @@ int dpll_nl_device_get_dumpit(struct sk_buff *skb, st= ruct netlink_callback *cb) unsigned long i; int ret =3D 0; =20 - mutex_lock(&dpll_lock); + down_read(&dpll_lock); xa_for_each_marked_start(&dpll_device_xa, i, dpll, DPLL_REGISTERED, ctx->idx) { hdr =3D genlmsg_put(skb, NETLINK_CB(cb->skb).portid, @@ -2038,7 +2038,7 @@ int dpll_nl_device_get_dumpit(struct sk_buff *skb, st= ruct netlink_callback *cb) } genlmsg_end(skb, hdr); } - mutex_unlock(&dpll_lock); + up_read(&dpll_lock); =20 if (ret =3D=3D -EMSGSIZE) { ctx->idx =3D i; @@ -2056,7 +2056,7 @@ int dpll_pre_doit(const struct genl_split_ops *ops, s= truct sk_buff *skb, if (GENL_REQ_ATTR_CHECK(info, DPLL_A_ID)) return -EINVAL; =20 - mutex_lock(&dpll_lock); + down_read(&dpll_lock); id =3D nla_get_u32(info->attrs[DPLL_A_ID]); dpll =3D dpll_device_get_by_id(id); if (!dpll) { @@ -2067,7 +2067,7 @@ int dpll_pre_doit(const struct genl_split_ops *ops, s= truct sk_buff *skb, mutex_lock(&dpll->domain->lock); return 0; unlock: - mutex_unlock(&dpll_lock); + up_read(&dpll_lock); return -ENODEV; } =20 @@ -2077,14 +2077,14 @@ void dpll_post_doit(const struct genl_split_ops *op= s, struct sk_buff *skb, struct dpll_device *dpll =3D info->user_ptr[0]; =20 mutex_unlock(&dpll->domain->lock); - mutex_unlock(&dpll_lock); + up_read(&dpll_lock); } =20 int dpll_lock_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) { - mutex_lock(&dpll_lock); + down_read(&dpll_lock); =20 return 0; } @@ -2093,7 +2093,7 @@ void dpll_unlock_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) { - mutex_unlock(&dpll_lock); + up_read(&dpll_lock); } =20 int dpll_pin_pre_doit(const struct genl_split_ops *ops, struct sk_buff *sk= b, @@ -2102,7 +2102,7 @@ int dpll_pin_pre_doit(const struct genl_split_ops *op= s, struct sk_buff *skb, struct dpll_pin *pin; int ret; =20 - mutex_lock(&dpll_lock); + down_read(&dpll_lock); if (GENL_REQ_ATTR_CHECK(info, DPLL_A_PIN_ID)) { ret =3D -EINVAL; goto unlock_dev; @@ -2119,7 +2119,7 @@ int dpll_pin_pre_doit(const struct genl_split_ops *op= s, struct sk_buff *skb, return 0; =20 unlock_dev: - mutex_unlock(&dpll_lock); + up_read(&dpll_lock); return ret; } =20 @@ -2129,5 +2129,5 @@ void dpll_pin_post_doit(const struct genl_split_ops *= ops, struct sk_buff *skb, struct dpll_pin *pin =3D info->user_ptr[0]; =20 mutex_unlock(&pin->domain->lock); - mutex_unlock(&dpll_lock); + up_read(&dpll_lock); } --=20 2.56.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794415270; b=ncnnhwmb7gBOesJ3vmMI/a8+5rja4MkFkfEmFuWiDmaBiYTEkdSuUUCpKkIOqhVRQgXc J0Bc7/qnJ3Msg7aLTxyQMLKG+VzpGuCSK95/oQ+a3wvezaAdygOT4zrSBGpX+lz+t18ST u/HOFlMgM7wEnfhTpwJGhSTD6ek3D4/+sGWpUQtTne6/Eo+4C51SX0DFg7QNbjRvuTLYk jZOXK3Visv5mJrN46BD9BISpD0MCKKD6ZjGtYIgAGUSVCgp4S7cB184sFlSNnvZfkuPMA m267FHHQbXLCJFGxC+SyCET5NbxhCu43cqfGqgcJaXrD3guVYUFftgNcaKPhU2t7Kbg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794415270; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=3dFQpE5deOHYWMMC5WmaVQGd/dNSozo5sXvLAdvloVc=; b=R4ew7i0c318dFVL0F/hkb3Zbr4yxHStniyqL9p4eXk60EwRK1dWQTifv9udRAmH9W0iX SRuMIXVRKx/utHnkVd1MtDoYlI9bcHjekdsQ7Ti8mCv6ip0lf2JJQBYO/NNiqpu8edkfJ oO5Wn02QLhdvAJn2gPr9ksr5tN6CkD3zPZOqzQuJYI8569GXpZWR+qLFuW97O0sdtVvM4 ovSQ7VHNQkIJ0w5ovO7AR4wyRAMP4aoyMp7YualGexkENrvWNcoKrAQPFGAXKzOhHmymE +/6qUVnFSoMNvDmNwN5LBK+HcRIy4HbexY7ots8y3S4lJPfCSR9I++VM5dFP/39o94Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DUY33cQE; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F4AA60A261E for ; Wed, 11 Nov 2026 16:41:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7F4AA60A261E 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.a=rsa-sha256 header.s=mimecast20190719 header.b=DUY33cQE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794415268; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3dFQpE5deOHYWMMC5WmaVQGd/dNSozo5sXvLAdvloVc=; b=DUY33cQEe2l8ux9wi6ccraQfTsgFvKVBl0IZNek3BM2b1DbqDEjDNQ44LLy7wAjL72qN4U r/95uQUGLrgmcaJeXcuTiKIHROihy8UeOO/4IvZ3msP1Vds8cfCXETUC3mynh1o5FyzI8n iGSIfq2iV7hF1WvdtJho12AwVVOOUds= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-572-FxrrKEJlOEWWY6lcF3oCBg-1; Wed, 11 Nov 2026 11:41:02 -0500 X-MC-Unique: FxrrKEJlOEWWY6lcF3oCBg-1 X-Mimecast-MFC-AGG-ID: FxrrKEJlOEWWY6lcF3oCBg_1794415260 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 102E71955F24; Wed, 11 Nov 2026 16:41:00 +0000 (UTC) Received: from ivecera-thinkpadp16vgen1.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4C536421; Wed, 11 Nov 2026 16:40:54 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Vadim Fedorenko , Arkadiusz Kubalewski , Jiri Pirko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Min Li , Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, Grzegorz Nitka , Karol Kolacinski , Saeed Mahameed , Tariq Toukan , Petr Oros Subject: [PATCH net-next v2 5/9] dpll: add KUnit tests for core locking Date: Wed, 11 Nov 2026 17:40:16 +0100 Message-ID: <20261111164021.273409-6-ivecera@redhat.com> In-Reply-To: <20261111164021.273409-1-ivecera@redhat.com> References: <20261111164021.273409-1-ivecera@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Content-Type: text/plain; charset="utf-8" Add KUnit tests using a mock driver with unrelated domains, a pin of one domain registered with a dpll of another and a pin of one domain under a MUX pin of another. They check that: - objects with the same (module, clock_id) share a refcounted domain - callbacks of a device run under its domain and callbacks of a pin under the domain of the pin alone, whichever driver registered them - a callback blocked in one domain does not stop unrelated domains - callbacks of one domain are serialized, also across its devices - a stuck callback of a foreign registration stops only the domain of the pin, and a stuck foreign device or domain of the pin does not stop the other side - a pin and its parent pin of another domain do not block each other - registrations can connect two domains in both directions - a topology change waits until running requests finish - a request setting several attributes of a pin is atomic against other requests about the pin, also when it spans two domains - notifications from callbacks keep their order, also when a callback fails Requests that can block run in kthreads, so a test can report a locking bug instead of blocking itself. A real deadlock cannot be undone, the stuck request keeps its locks, so the teardown then hangs until the run times out. The handlers are called directly with a hand-built message, so they are exported for KUnit. Only lockdep can tell which locks a callback holds. Without it the checks of held locks cannot fail, so the test that checks nothing else is skipped. The tests of what blocks what do not depend on it. The tests do not cover what needs a netlink socket, for example the order of notifications against the ACK or the content of messages. Run them with: tools/testing/kunit/kunit.py run --kunitconfig=3Ddrivers/dpll Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera --- Changes in v2: - Used kunit_fwnode_create_software_node() (Sashiko) - Released blocked callbacks in the exit callback of the suite, so a test aborted before its request is set up cannot hang the teardown (Sashiko) --- drivers/dpll/.kunitconfig | 5 + drivers/dpll/Kconfig | 13 + drivers/dpll/Makefile | 1 + drivers/dpll/dpll_core_kunit.c | 1478 ++++++++++++++++++++++++++++++++ drivers/dpll/dpll_netlink.c | 7 + 5 files changed, 1504 insertions(+) create mode 100644 drivers/dpll/.kunitconfig create mode 100644 drivers/dpll/dpll_core_kunit.c diff --git a/drivers/dpll/.kunitconfig b/drivers/dpll/.kunitconfig new file mode 100644 index 00000000000000..017c9d5b593a4f --- /dev/null +++ b/drivers/dpll/.kunitconfig @@ -0,0 +1,5 @@ +CONFIG_KUNIT=3Dy +CONFIG_NET=3Dy +CONFIG_DPLL_KUNIT_TEST=3Dy +CONFIG_DEBUG_KERNEL=3Dy +CONFIG_PROVE_LOCKING=3Dy diff --git a/drivers/dpll/Kconfig b/drivers/dpll/Kconfig index be98969f040ab6..12bcf706a15e14 100644 --- a/drivers/dpll/Kconfig +++ b/drivers/dpll/Kconfig @@ -23,6 +23,19 @@ config DPLL_REFCNT_TRACKER =20 If unsure, say N. =20 +config DPLL_KUNIT_TEST + tristate "KUnit tests for DPLL core" if !KUNIT_ALL_TESTS + depends on KUNIT && NET + select DPLL + default KUNIT_ALL_TESTS + help + KUnit tests for locking in the DPLL core. They use a mock driver + to check that callbacks run under the locks of their domains and + that unrelated domains do not block each other. The checks of held + locks need PROVE_LOCKING. + + If unsure, say N. + source "drivers/dpll/zl3073x/Kconfig" =20 endmenu diff --git a/drivers/dpll/Makefile b/drivers/dpll/Makefile index 9e7a3a3e592e81..75ee1608c76a93 100644 --- a/drivers/dpll/Makefile +++ b/drivers/dpll/Makefile @@ -8,4 +8,5 @@ dpll-y +=3D dpll_core.o dpll-y +=3D dpll_netlink.o dpll-y +=3D dpll_nl.o =20 +obj-$(CONFIG_DPLL_KUNIT_TEST) +=3D dpll_core_kunit.o obj-$(CONFIG_ZL3073X) +=3D zl3073x/ diff --git a/drivers/dpll/dpll_core_kunit.c b/drivers/dpll/dpll_core_kunit.c new file mode 100644 index 00000000000000..21f941a5fdec4e --- /dev/null +++ b/drivers/dpll/dpll_core_kunit.c @@ -0,0 +1,1478 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit tests for locking in the DPLL core. + * + * Each test starts with two unrelated domains: + * + * Domain A: devices A0 and A1 + * pin P on A0 and A1, setting its state on A0 notifies pin S + * pin S on A0 and A1 + * Domain B: device B0 + * pin BP on B0 + * + * Tests of objects connected by a pin add these domains: + * + * Domain E: device E0, pin X on E0 (the owner), pin M (MUX) on E0 + * Domain F: device F0, pin X from E is also registered with F0 + * Domain G: pin C registered under pin M from E + * + * Requests that can block run in kthreads, so a test can report a locking= bug + * instead of blocking itself. A real deadlock cannot be undone, the stuck + * request keeps its locks, so the teardown then hangs until the run times= out. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dpll_core.h" + +MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); + +#define DT_CLOCK_ID_A 0xd0110a +#define DT_CLOCK_ID_B 0xd0110b +#define DT_CLOCK_ID_E 0xd0110e +#define DT_CLOCK_ID_F 0xd0110f +#define DT_CLOCK_ID_G 0xd01107 + +#define DT_PIN_IDX_P 0 +#define DT_PIN_IDX_S 1 +#define DT_PIN_IDX_BP 2 +#define DT_PIN_IDX_M 3 +#define DT_PIN_IDX_X 4 +#define DT_PIN_IDX_C 5 +#define DT_PIN_IDX_Y 6 +#define DT_PIN_IDX_EXTRA 7 + +#define DT_MAX_EVENTS 8 +#define DT_TIMEOUT msecs_to_jiffies(5000) +#define DT_SHORT_TIMEOUT msecs_to_jiffies(100) + +struct dt_ctx; + +/* Counters and blocking of the callbacks of one driver instance */ +struct dt_dom { + struct dt_ctx *ctx; + struct completion entered; + atomic_t cur; + atomic_t peak; + bool block; +}; + +struct dt_dev { + struct dt_dom *dom; + struct dpll_device *dpll; + dpll_tracker tracker; + struct dt_dev *notify; + enum dpll_mode mode; + bool block; +}; + +struct dt_pin { + struct dpll_pin *pin; + dpll_tracker tracker; +}; + +struct dt_reg { + struct dt_dom *dom; + struct dt_pin *pin; + struct dt_dev *dev; + struct dt_pin *parent; + struct dt_pin *notify; + struct dpll_domain *forbid; + enum dpll_pin_state state; + enum dpll_pin_direction direction; + atomic_t freq_gets; + u32 prio; + bool block_prio_set; +}; + +struct dt_ctx { + struct kunit *test; + struct dt_dom dom_a, dom_b, dom_e, dom_f, dom_g; + struct dt_dev a0, a1, b0, e0, f0; + struct dt_pin p, s, bp, x, y, m, c, extra; + struct dt_reg reg_p_a0, reg_p_a1, reg_s_a0, reg_s_a1, reg_bp_b0; + struct dt_reg reg_x_e0, reg_x_f0, reg_y_e0, reg_y_f0, reg_m_e0, reg_c_m; + struct dt_reg *atomic_regs[2]; + struct notifier_block nb; + wait_queue_head_t wq; + atomic_t cur_total; + atomic_t peak_total; + atomic_t wrong_lock; + atomic_t bad_ntf; + atomic_t torn; + struct task_struct *set_task; + void *events[DT_MAX_EVENTS]; + int num_events; + bool record; + bool fail_after_ntf; + bool debug_locks_at_start; +}; + +struct dt_req { + struct dt_ctx *ctx; + int (*fn)(void *arg); + void *arg; + int ret; + struct completion done; + bool finished; +}; + +/* A nested attribute of a pin set request */ +struct dt_nest { + int type; + u32 parent_id; + int attr; + u32 val; +}; + +/* Allocated with kunit_kzalloc(), a failed assertion must not free them */ +struct dt_pin_set_args { + struct dt_ctx *ctx; + struct dpll_pin *pin; + struct dt_nest nests[2]; + int num; +}; + +struct dt_mode_set_args { + struct dpll_device *dpll; + enum dpll_mode mode; +}; + +/* + * The lock may be held by another task, so mutex_is_locked() is not enoug= h. + * Without lockdep no check of a held lock can fail. + */ +static bool dt_held(struct dpll_domain *domain) +{ +#ifdef CONFIG_LOCKDEP + return lockdep_is_held(&domain->lock) !=3D 0; +#else + return true; +#endif +} + +static bool dt_surely_held(struct dpll_domain *domain) +{ +#ifdef CONFIG_LOCKDEP + return lockdep_is_held(&domain->lock) > 0; +#else + return false; +#endif +} + +static void dt_peak(atomic_t *peak, int val) +{ + int old =3D atomic_read(peak); + + while (val > old && !atomic_try_cmpxchg(peak, &old, val)) + ; +} + +static void dt_block(struct dt_dom *dom, bool *block) +{ + complete(&dom->entered); + wait_event(dom->ctx->wq, !READ_ONCE(*block)); +} + +static void dt_enter(struct dt_dom *dom) +{ + struct dt_ctx *ctx =3D dom->ctx; + + dt_peak(&ctx->peak_total, atomic_inc_return(&ctx->cur_total)); + dt_peak(&dom->peak, atomic_inc_return(&dom->cur)); + + if (READ_ONCE(dom->block)) + dt_block(dom, &dom->block); +} + +static void dt_leave(struct dt_dom *dom) +{ + atomic_dec(&dom->cur); + atomic_dec(&dom->ctx->cur_total); +} + +static void dt_dev_enter(struct dt_dev *dev, const struct dpll_device *dpl= l) +{ + if (!dt_held(dpll->domain)) + atomic_inc(&dev->dom->ctx->wrong_lock); + dt_enter(dev->dom); + if (READ_ONCE(dev->block)) + dt_block(dev->dom, &dev->block); +} + +/* A callback of a pin runs under the domain of the pin alone */ +static void dt_pin_enter(struct dt_reg *reg, const struct dpll_pin *pin) +{ + struct dt_ctx *ctx =3D reg->dom->ctx; + + if (!dt_held(pin->domain) || + (reg->forbid && dt_surely_held(reg->forbid))) + atomic_inc(&ctx->wrong_lock); + dt_enter(reg->dom); +} + +static int dt_mode_get(const struct dpll_device *dpll, void *priv, + enum dpll_mode *mode, struct netlink_ext_ack *extack) +{ + struct dt_dev *dev =3D priv; + + dt_dev_enter(dev, dpll); + *mode =3D dev->mode; + dt_leave(dev->dom); + + return 0; +} + +static int dt_mode_set(const struct dpll_device *dpll, void *priv, + enum dpll_mode mode, struct netlink_ext_ack *extack) +{ + struct dt_dev *dev =3D priv; + + dt_dev_enter(dev, dpll); + dev->mode =3D mode; + dt_leave(dev->dom); + + if (dev->notify) + __dpll_device_change_ntf(dev->notify->dpll); + + return 0; +} + +static int dt_supported_modes_get(const struct dpll_device *dpll, void *pr= iv, + unsigned long *modes, + struct netlink_ext_ack *extack) +{ + struct dt_dev *dev =3D priv; + + dt_dev_enter(dev, dpll); + __set_bit(DPLL_MODE_AUTOMATIC, modes); + __set_bit(DPLL_MODE_MANUAL, modes); + dt_leave(dev->dom); + + return 0; +} + +static int dt_lock_status_get(const struct dpll_device *dpll, void *priv, + enum dpll_lock_status *status, + enum dpll_lock_status_error *status_error, + struct netlink_ext_ack *extack) +{ + struct dt_dev *dev =3D priv; + + dt_dev_enter(dev, dpll); + *status =3D DPLL_LOCK_STATUS_LOCKED; + dt_leave(dev->dom); + + return 0; +} + +static const struct dpll_device_ops dt_dev_ops =3D { + .mode_get =3D dt_mode_get, + .mode_set =3D dt_mode_set, + .supported_modes_get =3D dt_supported_modes_get, + .lock_status_get =3D dt_lock_status_get, +}; + +static int dt_frequency_get(const struct dpll_pin *pin, void *pin_priv, + const struct dpll_device *dpll, void *dpll_priv, + u64 *frequency, struct netlink_ext_ack *extack) +{ + struct dt_reg *reg =3D pin_priv; + + dt_pin_enter(reg, pin); + atomic_inc(®->freq_gets); + *frequency =3D 1; + dt_leave(reg->dom); + + return 0; +} + +static int dt_state_on_dpll_get(const struct dpll_pin *pin, void *pin_priv, + const struct dpll_device *dpll, void *dpll_priv, + enum dpll_pin_state *state, + struct netlink_ext_ack *extack) +{ + struct dt_reg *reg =3D pin_priv; + + dt_pin_enter(reg, pin); + *state =3D reg->state; + dt_leave(reg->dom); + + return 0; +} + +static int dt_state_on_dpll_set(const struct dpll_pin *pin, void *pin_priv, + const struct dpll_device *dpll, void *dpll_priv, + const enum dpll_pin_state state, + struct netlink_ext_ack *extack) +{ + struct dt_reg *reg =3D pin_priv; + + dt_pin_enter(reg, pin); + reg->state =3D state; + dt_leave(reg->dom); + + if (reg->notify) + __dpll_pin_change_ntf(reg->notify->pin); + + return reg->dom->ctx->fail_after_ntf ? -EIO : 0; +} + +static int dt_state_on_pin_get(const struct dpll_pin *pin, void *pin_priv, + const struct dpll_pin *parent_pin, + void *parent_pin_priv, + enum dpll_pin_state *state, + struct netlink_ext_ack *extack) +{ + struct dt_reg *reg =3D pin_priv; + + dt_pin_enter(reg, pin); + *state =3D reg->state; + dt_leave(reg->dom); + + return 0; +} + +static int dt_state_on_pin_set(const struct dpll_pin *pin, void *pin_priv, + const struct dpll_pin *parent_pin, + void *parent_pin_priv, + const enum dpll_pin_state state, + struct netlink_ext_ack *extack) +{ + struct dt_reg *reg =3D pin_priv; + + dt_pin_enter(reg, pin); + reg->state =3D state; + dt_leave(reg->dom); + + return 0; +} + +static int dt_prio_get(const struct dpll_pin *pin, void *pin_priv, + const struct dpll_device *dpll, void *dpll_priv, + u32 *prio, struct netlink_ext_ack *extack) +{ + struct dt_reg *reg =3D pin_priv; + struct dt_ctx *ctx =3D reg->dom->ctx; + + dt_pin_enter(reg, pin); + /* Only the request doing the set may see it half done */ + if (READ_ONCE(ctx->set_task) && current !=3D ctx->set_task && + ctx->atomic_regs[0]->prio !=3D ctx->atomic_regs[1]->prio) + atomic_inc(&ctx->torn); + *prio =3D reg->prio; + dt_leave(reg->dom); + + return 0; +} + +static int dt_prio_set(const struct dpll_pin *pin, void *pin_priv, + const struct dpll_device *dpll, void *dpll_priv, + const u32 prio, struct netlink_ext_ack *extack) +{ + struct dt_reg *reg =3D pin_priv; + + dt_pin_enter(reg, pin); + if (READ_ONCE(reg->block_prio_set)) + dt_block(reg->dom, ®->block_prio_set); + reg->prio =3D prio; + dt_leave(reg->dom); + + return 0; +} + +static int dt_direction_get(const struct dpll_pin *pin, void *pin_priv, + const struct dpll_device *dpll, void *dpll_priv, + enum dpll_pin_direction *direction, + struct netlink_ext_ack *extack) +{ + struct dt_reg *reg =3D pin_priv; + + dt_pin_enter(reg, pin); + *direction =3D reg->direction; + dt_leave(reg->dom); + + return 0; +} + +static int dt_direction_set(const struct dpll_pin *pin, void *pin_priv, + const struct dpll_device *dpll, void *dpll_priv, + const enum dpll_pin_direction direction, + struct netlink_ext_ack *extack) +{ + struct dt_reg *reg =3D pin_priv; + + dt_pin_enter(reg, pin); + reg->direction =3D direction; + dt_leave(reg->dom); + + return 0; +} + +static int dt_ref_sync_get(const struct dpll_pin *pin, void *pin_priv, + const struct dpll_pin *ref_sync_pin, + void *ref_sync_pin_priv, enum dpll_pin_state *state, + struct netlink_ext_ack *extack) +{ + struct dt_reg *reg =3D pin_priv; + + dt_pin_enter(reg, pin); + *state =3D DPLL_PIN_STATE_DISCONNECTED; + dt_leave(reg->dom); + + return 0; +} + +static const struct dpll_pin_ops dt_pin_ops =3D { + .frequency_get =3D dt_frequency_get, + .state_on_dpll_get =3D dt_state_on_dpll_get, + .state_on_dpll_set =3D dt_state_on_dpll_set, + .state_on_pin_get =3D dt_state_on_pin_get, + .state_on_pin_set =3D dt_state_on_pin_set, + .prio_get =3D dt_prio_get, + .prio_set =3D dt_prio_set, + .direction_get =3D dt_direction_get, + .direction_set =3D dt_direction_set, + .ref_sync_get =3D dt_ref_sync_get, +}; + +static const struct dpll_pin_properties dt_prop =3D { + .type =3D DPLL_PIN_TYPE_EXT, + .capabilities =3D DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE | + DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE | + DPLL_PIN_CAPABILITIES_DIRECTION_CAN_CHANGE, +}; + +static const struct dpll_pin_properties dt_prop_mux =3D { + .type =3D DPLL_PIN_TYPE_MUX, + .capabilities =3D DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE, +}; + +/* Other dpll drivers in the system can send notifications at any time */ +static bool dt_own_clock_id(u64 clock_id) +{ + switch (clock_id) { + case DT_CLOCK_ID_A: + case DT_CLOCK_ID_B: + case DT_CLOCK_ID_E: + case DT_CLOCK_ID_F: + case DT_CLOCK_ID_G: + return true; + default: + return false; + } +} + +static int dt_notifier(struct notifier_block *nb, unsigned long action, + void *data) +{ + struct dt_ctx *ctx =3D container_of(nb, struct dt_ctx, nb); + struct dpll_device_notifier_info *dev_info =3D data; + struct dpll_pin_notifier_info *pin_info =3D data; + struct dpll_domain *domain; + u64 clock_id; + void *obj; + + switch (action) { + case DPLL_DEVICE_CHANGED: + clock_id =3D dev_info->clock_id; + obj =3D dev_info->dpll; + domain =3D dev_info->dpll->domain; + break; + case DPLL_PIN_CHANGED: + clock_id =3D pin_info->clock_id; + obj =3D pin_info->pin; + domain =3D pin_info->pin->domain; + break; + default: + return NOTIFY_DONE; + } + + if (!dt_own_clock_id(clock_id) || !ctx->record) + return NOTIFY_DONE; + + if (!dt_held(domain)) + atomic_inc(&ctx->bad_ntf); + if (ctx->num_events < DT_MAX_EVENTS) + ctx->events[ctx->num_events] =3D obj; + ctx->num_events++; + + return NOTIFY_OK; +} + +static void dt_final_check(void *data) +{ + struct dt_ctx *ctx =3D data; + + KUNIT_EXPECT_EQ(ctx->test, atomic_read(&ctx->wrong_lock), 0); + if (ctx->debug_locks_at_start) + KUNIT_EXPECT_TRUE(ctx->test, debug_locks); +} + +static void dt_dev_release(void *data) +{ + struct dt_dev *dev =3D data; + + dpll_device_unregister(dev->dpll, &dt_dev_ops, dev); + dpll_device_put(dev->dpll, &dev->tracker); +} + +static void dt_dev_add(struct kunit *test, struct dt_dev *dev, + struct dt_dom *dom, u64 clock_id, u32 idx, + enum dpll_type type) +{ + int ret; + + dev->dom =3D dom; + dev->mode =3D DPLL_MODE_AUTOMATIC; + dev->dpll =3D dpll_device_get(clock_id, idx, THIS_MODULE, &dev->tracker); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev->dpll); + + ret =3D dpll_device_register(dev->dpll, type, &dt_dev_ops, dev); + if (ret) + dpll_device_put(dev->dpll, &dev->tracker); + KUNIT_ASSERT_EQ(test, ret, 0); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, dt_dev_release, + dev), 0); +} + +static void dt_pin_release(void *data) +{ + struct dt_pin *pin =3D data; + + if (!IS_ERR_OR_NULL(pin->pin)) + dpll_pin_put(pin->pin, &pin->tracker); +} + +static void dt_pin_add(struct kunit *test, struct dt_pin *pin, u64 clock_i= d, + u32 idx, const struct dpll_pin_properties *prop) +{ + pin->pin =3D dpll_pin_get(clock_id, idx, THIS_MODULE, prop, + &pin->tracker); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pin->pin); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, dt_pin_release, + pin), 0); +} + +static void dt_reg_release(void *data) +{ + struct dt_reg *reg =3D data; + + if (reg->parent) + dpll_pin_on_pin_unregister(reg->parent->pin, reg->pin->pin, + &dt_pin_ops, reg); + else + dpll_pin_unregister(reg->dev->dpll, reg->pin->pin, &dt_pin_ops, + reg); +} + +static void dt_reg_add(struct kunit *test, struct dt_reg *reg, + struct dt_dom *dom, struct dt_pin *pin, + struct dt_dev *dev, struct dt_pin *parent) +{ + int ret; + + reg->dom =3D dom; + reg->pin =3D pin; + reg->dev =3D dev; + reg->parent =3D parent; + reg->state =3D DPLL_PIN_STATE_SELECTABLE; + reg->direction =3D DPLL_PIN_DIRECTION_INPUT; + + if (parent) + ret =3D dpll_pin_on_pin_register(parent->pin, pin->pin, + &dt_pin_ops, reg); + else + ret =3D dpll_pin_register(dev->dpll, pin->pin, &dt_pin_ops, reg); + KUNIT_ASSERT_EQ(test, ret, 0); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, dt_reg_release, + reg), 0); +} + +/* Creates a pin with a fwnode so that it can be registered with another d= pll */ +static void dt_fwnode_pin_add(struct kunit *test, struct dt_pin *pin, + u64 clock_id, u32 idx) +{ + struct fwnode_handle *fwnode; + + fwnode =3D kunit_fwnode_create_software_node(test, NULL, NULL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, fwnode); + dt_pin_add(test, pin, clock_id, idx, &dt_prop); + dpll_pin_fwnode_set(pin->pin, fwnode); +} + +/* Builds domains E and F connected by pin X */ +static void dt_foreign_pin_add(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + + dt_dev_add(test, &ctx->e0, &ctx->dom_e, DT_CLOCK_ID_E, 0, + DPLL_TYPE_PPS); + dt_dev_add(test, &ctx->f0, &ctx->dom_f, DT_CLOCK_ID_F, 0, + DPLL_TYPE_PPS); + dt_fwnode_pin_add(test, &ctx->x, DT_CLOCK_ID_E, DT_PIN_IDX_X); + dt_reg_add(test, &ctx->reg_x_e0, &ctx->dom_e, &ctx->x, &ctx->e0, NULL); + dt_reg_add(test, &ctx->reg_x_f0, &ctx->dom_f, &ctx->x, &ctx->f0, NULL); + + /* No callback of the pin takes the lock of the other domain */ + ctx->reg_x_e0.forbid =3D ctx->f0.dpll->domain; + ctx->reg_x_f0.forbid =3D ctx->f0.dpll->domain; +} + +/* + * Builds domains E and G connected by pin C under pin M. The pins are add= ed + * first, so that domain G is freed only after the registrations are gone. + */ +static void dt_on_pin_add(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + + dt_dev_add(test, &ctx->e0, &ctx->dom_e, DT_CLOCK_ID_E, 0, + DPLL_TYPE_PPS); + dt_pin_add(test, &ctx->m, DT_CLOCK_ID_E, DT_PIN_IDX_M, &dt_prop_mux); + dt_pin_add(test, &ctx->c, DT_CLOCK_ID_G, DT_PIN_IDX_C, &dt_prop); + dt_reg_add(test, &ctx->reg_m_e0, &ctx->dom_e, &ctx->m, &ctx->e0, NULL); + dt_reg_add(test, &ctx->reg_c_m, &ctx->dom_g, &ctx->c, NULL, &ctx->m); + + ctx->reg_c_m.forbid =3D ctx->e0.dpll->domain; + ctx->reg_m_e0.forbid =3D ctx->c.pin->domain; +} + +static void dt_notifier_release(void *data) +{ + struct dt_ctx *ctx =3D data; + + unregister_dpll_notifier(&ctx->nb); +} + +static void dt_dom_init(struct dt_dom *dom, struct dt_ctx *ctx) +{ + dom->ctx =3D ctx; + init_completion(&dom->entered); +} + +static int dt_init(struct kunit *test) +{ + struct dt_ctx *ctx; + + ctx =3D kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, ctx); + test->priv =3D ctx; + + ctx->test =3D test; + dt_dom_init(&ctx->dom_a, ctx); + dt_dom_init(&ctx->dom_b, ctx); + dt_dom_init(&ctx->dom_e, ctx); + dt_dom_init(&ctx->dom_f, ctx); + dt_dom_init(&ctx->dom_g, ctx); + init_waitqueue_head(&ctx->wq); + ctx->debug_locks_at_start =3D debug_locks; + + /* Runs last, after the deletion of all objects */ + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, dt_final_check, + ctx), 0); + + dt_dev_add(test, &ctx->a0, &ctx->dom_a, DT_CLOCK_ID_A, 0, + DPLL_TYPE_PPS); + dt_dev_add(test, &ctx->a1, &ctx->dom_a, DT_CLOCK_ID_A, 1, + DPLL_TYPE_EEC); + dt_dev_add(test, &ctx->b0, &ctx->dom_b, DT_CLOCK_ID_B, 0, + DPLL_TYPE_PPS); + ctx->a0.notify =3D &ctx->a1; + + dt_pin_add(test, &ctx->p, DT_CLOCK_ID_A, DT_PIN_IDX_P, &dt_prop); + dt_reg_add(test, &ctx->reg_p_a0, &ctx->dom_a, &ctx->p, &ctx->a0, NULL); + dt_reg_add(test, &ctx->reg_p_a1, &ctx->dom_a, &ctx->p, &ctx->a1, NULL); + ctx->reg_p_a0.notify =3D &ctx->s; + + dt_pin_add(test, &ctx->s, DT_CLOCK_ID_A, DT_PIN_IDX_S, &dt_prop); + dt_reg_add(test, &ctx->reg_s_a0, &ctx->dom_a, &ctx->s, &ctx->a0, NULL); + dt_reg_add(test, &ctx->reg_s_a1, &ctx->dom_a, &ctx->s, &ctx->a1, NULL); + + dt_pin_add(test, &ctx->bp, DT_CLOCK_ID_B, DT_PIN_IDX_BP, &dt_prop); + dt_reg_add(test, &ctx->reg_bp_b0, &ctx->dom_b, &ctx->bp, &ctx->b0, + NULL); + + ctx->nb.notifier_call =3D dt_notifier; + KUNIT_ASSERT_EQ(test, register_dpll_notifier(&ctx->nb), 0); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, + dt_notifier_release, + ctx), 0); + + atomic_set(&ctx->peak_total, 0); + atomic_set(&ctx->dom_a.peak, 0); + atomic_set(&ctx->dom_b.peak, 0); + + return 0; +} + +static int dt_device_ntf(void *arg) +{ + struct dt_dev *dev =3D arg; + + return dpll_device_change_ntf(dev->dpll); +} + +static int dt_pin_ntf(void *arg) +{ + struct dt_pin *pin =3D arg; + + return dpll_pin_change_ntf(pin->pin); +} + +static int dt_extra_pin_get(void *arg) +{ + struct dt_pin *pin =3D arg; + + pin->pin =3D dpll_pin_get(DT_CLOCK_ID_B, DT_PIN_IDX_EXTRA, THIS_MODULE, + &dt_prop, &pin->tracker); + + return PTR_ERR_OR_ZERO(pin->pin); +} + +static void dt_unblock(struct dt_ctx *ctx) +{ + WRITE_ONCE(ctx->dom_a.block, false); + WRITE_ONCE(ctx->dom_b.block, false); + WRITE_ONCE(ctx->dom_e.block, false); + WRITE_ONCE(ctx->dom_f.block, false); + WRITE_ONCE(ctx->dom_g.block, false); + WRITE_ONCE(ctx->f0.block, false); + WRITE_ONCE(ctx->reg_p_a0.block_prio_set, false); + WRITE_ONCE(ctx->reg_x_e0.block_prio_set, false); + WRITE_ONCE(ctx->reg_x_f0.block_prio_set, false); + wake_up_all(&ctx->wq); +} + +/* + * Runs before the cleanup actions, also when a test aborts, so that no re= lease + * of an object waits for a blocked callback. test->priv is NULL if dt_ini= t() + * failed to allocate the context. + */ +static void dt_exit(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + + if (ctx) + dt_unblock(ctx); +} + +static int dt_req_thread(void *data) +{ + struct dt_req *req =3D data; + + req->ret =3D req->fn(req->arg); + kthread_complete_and_exit(&req->done, 0); +} + +/* Runs before the objects used by the request are released */ +static void dt_req_release(void *data) +{ + struct dt_req *req =3D data; + + dt_unblock(req->ctx); + if (!req->finished) + wait_for_completion(&req->done); +} + +static struct dt_req *dt_req_start(struct kunit *test, int (*fn)(void *arg= ), + void *arg) +{ + struct task_struct *task; + struct dt_req *req; + + req =3D kunit_kzalloc(test, sizeof(*req), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, req); + + req->ctx =3D test->priv; + req->fn =3D fn; + req->arg =3D arg; + init_completion(&req->done); + + task =3D kthread_run(dt_req_thread, req, "dpll-test"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, task); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, dt_req_release, + req), 0); + + return req; +} + +/* + * Consumes the completion, so it must not be waited for again. Assert it = before + * reading what the request wrote. + */ +static bool dt_done(struct dt_req *req, unsigned long timeout) +{ + if (!req->finished && wait_for_completion_timeout(&req->done, timeout)) + req->finished =3D true; + + return req->finished; +} + +/* Blocks a request of @dom in a callback, which holds the domain lock */ +static struct dt_req *dt_block_in(struct kunit *test, struct dt_dom *dom, + int (*fn)(void *arg), void *arg) +{ + struct dt_req *req; + + WRITE_ONCE(dom->block, true); + req =3D dt_req_start(test, fn, arg); + KUNIT_ASSERT_TRUE(test, wait_for_completion_timeout(&dom->entered, + DT_TIMEOUT)); + + return req; +} + +/* Build a set request and pass it to the handlers genetlink would call */ +static int dt_pin_set_fn(void *arg) +{ + struct dt_pin_set_args *args =3D arg; + struct nlattr *attrs[DPLL_A_PIN_MAX + 1] =3D {}; + struct genl_info info =3D {}; + struct nlmsghdr *nlh; + struct sk_buff *skb; + struct nlattr *nest; + int i, ret; + + if (args->ctx) + WRITE_ONCE(args->ctx->set_task, current); + + skb =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!skb) + return -ENOMEM; + ret =3D -EMSGSIZE; + nlh =3D nlmsg_put(skb, 0, 0, NLMSG_MIN_TYPE, GENL_HDRLEN, 0); + if (!nlh || nla_put_u32(skb, DPLL_A_PIN_ID, args->pin->id)) + goto out; + for (i =3D 0; i < args->num; i++) { + const struct dt_nest *n =3D &args->nests[i]; + + nest =3D nla_nest_start(skb, n->type); + if (!nest || + nla_put_u32(skb, DPLL_A_PIN_PARENT_ID, n->parent_id) || + nla_put_u32(skb, n->attr, n->val)) + goto out; + nla_nest_end(skb, nest); + } + nlmsg_end(skb, nlh); + + info.genlhdr =3D nlmsg_data(nlh); + info.attrs =3D attrs; + attrs[DPLL_A_PIN_ID] =3D nla_find(genlmsg_data(info.genlhdr), + genlmsg_len(info.genlhdr), + DPLL_A_PIN_ID); + + ret =3D dpll_pin_pre_doit(NULL, skb, &info); + if (!ret) { + ret =3D dpll_nl_pin_set_doit(skb, &info); + dpll_pin_post_doit(NULL, skb, &info); + } +out: + nlmsg_free(skb); + + return ret; +} + +static int dt_mode_set_fn(void *arg) +{ + struct dt_mode_set_args *args =3D arg; + struct nlattr *attrs[DPLL_A_MAX + 1] =3D {}; + struct genl_info info =3D {}; + struct nlmsghdr *nlh; + struct sk_buff *skb; + int ret; + + skb =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!skb) + return -ENOMEM; + ret =3D -EMSGSIZE; + nlh =3D nlmsg_put(skb, 0, 0, NLMSG_MIN_TYPE, GENL_HDRLEN, 0); + if (!nlh || nla_put_u32(skb, DPLL_A_ID, args->dpll->id) || + nla_put_u32(skb, DPLL_A_MODE, args->mode)) + goto out; + nlmsg_end(skb, nlh); + + info.genlhdr =3D nlmsg_data(nlh); + info.attrs =3D attrs; + attrs[DPLL_A_ID] =3D nla_find(genlmsg_data(info.genlhdr), + genlmsg_len(info.genlhdr), DPLL_A_ID); + + ret =3D dpll_pre_doit(NULL, skb, &info); + if (!ret) { + ret =3D dpll_nl_device_set_doit(skb, &info); + dpll_post_doit(NULL, skb, &info); + } +out: + nlmsg_free(skb); + + return ret; +} + +/* Runs a request that should not block in a kthread and returns its resul= t */ +static int dt_run(struct kunit *test, int (*fn)(void *arg), void *arg) +{ + struct dt_req *req =3D dt_req_start(test, fn, arg); + + KUNIT_ASSERT_TRUE(test, dt_done(req, DT_TIMEOUT)); + + return req->ret; +} + +static struct dt_pin_set_args *dt_pin_set_args_alloc(struct kunit *test, + struct dpll_pin *pin, + int num) +{ + struct dt_pin_set_args *args; + + args =3D kunit_kzalloc(test, sizeof(*args), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, args); + args->pin =3D pin; + args->num =3D num; + + return args; +} + +static struct dt_pin_set_args *dt_pin_set_args_one(struct kunit *test, + struct dpll_pin *pin, + int type, u32 parent_id, + int attr, u32 val) +{ + struct dt_pin_set_args *args =3D dt_pin_set_args_alloc(test, pin, 1); + + args->nests[0].type =3D type; + args->nests[0].parent_id =3D parent_id; + args->nests[0].attr =3D attr; + args->nests[0].val =3D val; + + return args; +} + +static int dt_pin_set_one(struct kunit *test, struct dpll_pin *pin, int ty= pe, + u32 parent_id, int attr, u32 val) +{ + return dt_run(test, dt_pin_set_fn, + dt_pin_set_args_one(test, pin, type, parent_id, attr, + val)); +} + +static void dt_expect_events(struct kunit *test, void * const *expected, + int num) +{ + struct dt_ctx *ctx =3D test->priv; + int i; + + KUNIT_ASSERT_EQ(test, ctx->num_events, num); + for (i =3D 0; i < num; i++) + KUNIT_EXPECT_PTR_EQ(test, ctx->events[i], expected[i]); + KUNIT_EXPECT_EQ(test, atomic_read(&ctx->bad_ntf), 0); +} + +/* Objects with the same (module, clock_id) share a refcounted domain */ +static void dt_test_domain_sharing(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + struct dpll_domain *a =3D ctx->a0.dpll->domain; + struct dpll_domain *b =3D ctx->b0.dpll->domain; + + KUNIT_EXPECT_PTR_EQ(test, ctx->a1.dpll->domain, a); + KUNIT_EXPECT_PTR_EQ(test, ctx->p.pin->domain, a); + KUNIT_EXPECT_PTR_EQ(test, ctx->bp.pin->domain, b); + KUNIT_EXPECT_PTR_NE(test, a, b); + + KUNIT_EXPECT_EQ(test, refcount_read(&a->refcount), 4); + KUNIT_EXPECT_EQ(test, refcount_read(&b->refcount), 2); + + KUNIT_ASSERT_EQ(test, dt_extra_pin_get(&ctx->extra), 0); + KUNIT_EXPECT_PTR_EQ(test, ctx->extra.pin->domain, b); + KUNIT_EXPECT_EQ(test, refcount_read(&b->refcount), 3); + dpll_pin_put(ctx->extra.pin, &ctx->extra.tracker); + KUNIT_EXPECT_EQ(test, refcount_read(&b->refcount), 2); +} + +/* The same clock_id used by another module means another domain */ +static void dt_test_domain_per_module(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + static char other_module; + struct dpll_device *dpll; + dpll_tracker tracker; + + /* Never registered, so the core does not dereference the module */ + dpll =3D dpll_device_get(DT_CLOCK_ID_A, 0, (struct module *)&other_module, + &tracker); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dpll); + KUNIT_EXPECT_PTR_NE(test, dpll, ctx->a0.dpll); + KUNIT_EXPECT_PTR_NE(test, dpll->domain, ctx->a0.dpll->domain); + dpll_device_put(dpll, &tracker); +} + +/* A pin on a dpll of another domain stays in its domain */ +static void dt_test_foreign_registration_domain(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + struct dpll_domain *e, *f; + + dt_foreign_pin_add(test); + e =3D ctx->e0.dpll->domain; + f =3D ctx->f0.dpll->domain; + + KUNIT_EXPECT_PTR_NE(test, e, f); + KUNIT_EXPECT_PTR_EQ(test, ctx->x.pin->domain, e); + KUNIT_EXPECT_EQ(test, refcount_read(&e->refcount), 2); + KUNIT_EXPECT_EQ(test, refcount_read(&f->refcount), 1); +} + +/* A pin under a parent pin of another domain stays in its domain */ +static void dt_test_on_pin_registration_domain(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + struct dpll_domain *e, *g; + + dt_on_pin_add(test); + e =3D ctx->e0.dpll->domain; + g =3D ctx->c.pin->domain; + + KUNIT_EXPECT_PTR_NE(test, e, g); + KUNIT_EXPECT_PTR_EQ(test, ctx->m.pin->domain, e); + KUNIT_EXPECT_EQ(test, refcount_read(&e->refcount), 2); + KUNIT_EXPECT_EQ(test, refcount_read(&g->refcount), 1); +} + +/* A callback blocked in one domain does not stop other domains */ +static void dt_test_domains_run_in_parallel(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + struct dt_req *blocked, *other; + + blocked =3D dt_block_in(test, &ctx->dom_a, dt_device_ntf, &ctx->a0); + + other =3D dt_req_start(test, dt_device_ntf, &ctx->b0); + KUNIT_EXPECT_TRUE(test, dt_done(other, DT_TIMEOUT)); + KUNIT_EXPECT_FALSE(test, completion_done(&blocked->done)); + KUNIT_EXPECT_EQ(test, atomic_read(&ctx->peak_total), 2); + + dt_unblock(ctx); + KUNIT_EXPECT_TRUE(test, dt_done(blocked, DT_TIMEOUT)); +} + +/* Callbacks of one domain are serialized, across its devices too */ +static void dt_test_domain_is_serialized(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + struct dt_req *first, *second; + + first =3D dt_block_in(test, &ctx->dom_a, dt_device_ntf, &ctx->a0); + + second =3D dt_req_start(test, dt_device_ntf, &ctx->a1); + KUNIT_EXPECT_FALSE(test, dt_done(second, DT_SHORT_TIMEOUT)); + + dt_unblock(ctx); + KUNIT_EXPECT_TRUE(test, dt_done(first, DT_TIMEOUT)); + KUNIT_EXPECT_TRUE(test, dt_done(second, DT_TIMEOUT)); + KUNIT_EXPECT_EQ(test, atomic_read(&ctx->dom_a.peak), 1); +} + +/* Callbacks of all refs of a pin run under the domain of the pin alone */ +static void dt_test_foreign_get_locks(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + + if (!IS_ENABLED(CONFIG_LOCKDEP) || !debug_locks) + kunit_skip(test, "needs lockdep"); + + dt_foreign_pin_add(test); + + KUNIT_EXPECT_EQ(test, dt_run(test, dt_pin_ntf, &ctx->x), 0); + KUNIT_EXPECT_EQ(test, atomic_read(&ctx->wrong_lock), 0); +} + +/* Setters of a foreign ref run under the domain of the pin alone */ +static void dt_test_foreign_set_locks(struct kunit *test) +{ + static const struct { + int attr; + u32 val; + } sets[] =3D { + { DPLL_A_PIN_STATE, DPLL_PIN_STATE_CONNECTED }, + { DPLL_A_PIN_PRIO, 7 }, + { DPLL_A_PIN_DIRECTION, DPLL_PIN_DIRECTION_OUTPUT }, + }; + struct dt_ctx *ctx =3D test->priv; + int i; + + dt_foreign_pin_add(test); + + for (i =3D 0; i < ARRAY_SIZE(sets); i++) { + int ret; + + ctx->num_events =3D 0; + ctx->record =3D true; + ret =3D dt_pin_set_one(test, ctx->x.pin, DPLL_A_PIN_PARENT_DEVICE, + ctx->f0.dpll->id, sets[i].attr, + sets[i].val); + ctx->record =3D false; + + KUNIT_EXPECT_EQ(test, ret, 0); + dt_expect_events(test, (void *[]){ ctx->x.pin }, 1); + } + KUNIT_EXPECT_EQ(test, ctx->reg_x_f0.state, DPLL_PIN_STATE_CONNECTED); + KUNIT_EXPECT_EQ(test, ctx->reg_x_f0.prio, 7); + KUNIT_EXPECT_EQ(test, ctx->reg_x_f0.direction, + DPLL_PIN_DIRECTION_OUTPUT); + KUNIT_EXPECT_EQ(test, ctx->reg_x_e0.prio, 0); +} + +/* The callback of a foreign ref can notify objects of the domain of the p= in */ +static void dt_test_foreign_callback_notifies_pin(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + int ret; + + dt_foreign_pin_add(test); + ctx->reg_x_f0.notify =3D &ctx->x; + + ctx->record =3D true; + ret =3D dt_pin_set_one(test, ctx->x.pin, DPLL_A_PIN_PARENT_DEVICE, + ctx->f0.dpll->id, DPLL_A_PIN_STATE, + DPLL_PIN_STATE_CONNECTED); + ctx->record =3D false; + + KUNIT_EXPECT_EQ(test, ret, 0); + dt_expect_events(test, (void *[]){ ctx->x.pin, ctx->x.pin }, 2); +} + +/* Without an owner the pin-level attributes come from the foreign ref */ +static void dt_test_pin_without_owner(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + + dt_dev_add(test, &ctx->f0, &ctx->dom_f, DT_CLOCK_ID_F, 0, + DPLL_TYPE_PPS); + dt_fwnode_pin_add(test, &ctx->x, DT_CLOCK_ID_E, DT_PIN_IDX_X); + dt_reg_add(test, &ctx->reg_x_f0, &ctx->dom_f, &ctx->x, &ctx->f0, NULL); + KUNIT_ASSERT_PTR_NE(test, ctx->x.pin->domain, ctx->f0.dpll->domain); + ctx->reg_x_f0.forbid =3D ctx->f0.dpll->domain; + + atomic_set(&ctx->reg_x_f0.freq_gets, 0); + KUNIT_EXPECT_EQ(test, dt_run(test, dt_pin_ntf, &ctx->x), 0); + KUNIT_EXPECT_GT(test, atomic_read(&ctx->reg_x_f0.freq_gets), 0); + KUNIT_EXPECT_EQ(test, atomic_read(&ctx->wrong_lock), 0); +} + +/* A stuck callback of a foreign ref stops only the domain of the pin */ +static void dt_test_stuck_foreign_callback(struct kunit *test) +{ + struct dt_req *blocked, *owner, *foreign, *other; + struct dt_ctx *ctx =3D test->priv; + + dt_foreign_pin_add(test); + + WRITE_ONCE(ctx->reg_x_f0.block_prio_set, true); + blocked =3D dt_req_start(test, dt_pin_set_fn, + dt_pin_set_args_one(test, ctx->x.pin, + DPLL_A_PIN_PARENT_DEVICE, + ctx->f0.dpll->id, + DPLL_A_PIN_PRIO, 7)); + KUNIT_ASSERT_TRUE(test, wait_for_completion_timeout(&ctx->dom_f.entered, + DT_TIMEOUT)); + + owner =3D dt_req_start(test, dt_device_ntf, &ctx->e0); + KUNIT_EXPECT_FALSE(test, dt_done(owner, DT_SHORT_TIMEOUT)); + foreign =3D dt_req_start(test, dt_device_ntf, &ctx->f0); + KUNIT_EXPECT_TRUE(test, dt_done(foreign, DT_TIMEOUT)); + other =3D dt_req_start(test, dt_device_ntf, &ctx->b0); + KUNIT_EXPECT_TRUE(test, dt_done(other, DT_TIMEOUT)); + + dt_unblock(ctx); + KUNIT_EXPECT_TRUE(test, dt_done(blocked, DT_TIMEOUT)); + KUNIT_EXPECT_TRUE(test, dt_done(owner, DT_TIMEOUT)); +} + +/* A stuck device callback does not stop a foreign pin registered with it = */ +static void dt_test_stuck_foreign_device(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + struct dt_req *blocked, *pin; + + dt_foreign_pin_add(test); + + WRITE_ONCE(ctx->f0.block, true); + blocked =3D dt_req_start(test, dt_device_ntf, &ctx->f0); + KUNIT_ASSERT_TRUE(test, wait_for_completion_timeout(&ctx->dom_f.entered, + DT_TIMEOUT)); + + pin =3D dt_req_start(test, dt_pin_ntf, &ctx->x); + KUNIT_EXPECT_TRUE(test, dt_done(pin, DT_TIMEOUT)); + + dt_unblock(ctx); + KUNIT_EXPECT_TRUE(test, dt_done(blocked, DT_TIMEOUT)); +} + +/* A stuck owner stops requests for its pins, but not the foreign device */ +static void dt_test_stuck_owner_domain(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + struct dt_req *blocked, *foreign, *pin; + + dt_foreign_pin_add(test); + + blocked =3D dt_block_in(test, &ctx->dom_e, dt_device_ntf, &ctx->e0); + + foreign =3D dt_req_start(test, dt_device_ntf, &ctx->f0); + KUNIT_EXPECT_TRUE(test, dt_done(foreign, DT_TIMEOUT)); + pin =3D dt_req_start(test, dt_pin_ntf, &ctx->x); + KUNIT_EXPECT_FALSE(test, dt_done(pin, DT_SHORT_TIMEOUT)); + + dt_unblock(ctx); + KUNIT_EXPECT_TRUE(test, dt_done(blocked, DT_TIMEOUT)); + KUNIT_EXPECT_TRUE(test, dt_done(pin, DT_TIMEOUT)); +} + +/* A pin and its parent pin of another domain do not block each other */ +static void dt_test_on_pin_domains_are_independent(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + struct dt_req *blocked, *other; + + dt_on_pin_add(test); + + blocked =3D dt_block_in(test, &ctx->dom_e, dt_device_ntf, &ctx->e0); + other =3D dt_req_start(test, dt_pin_ntf, &ctx->c); + KUNIT_EXPECT_TRUE(test, dt_done(other, DT_TIMEOUT)); + dt_unblock(ctx); + KUNIT_EXPECT_TRUE(test, dt_done(blocked, DT_TIMEOUT)); + + blocked =3D dt_block_in(test, &ctx->dom_g, dt_pin_ntf, &ctx->c); + other =3D dt_req_start(test, dt_pin_ntf, &ctx->m); + KUNIT_EXPECT_TRUE(test, dt_done(other, DT_TIMEOUT)); + dt_unblock(ctx); + KUNIT_EXPECT_TRUE(test, dt_done(blocked, DT_TIMEOUT)); +} + +/* Registrations in both directions between two domains are fine */ +static void dt_test_registrations_both_directions(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + + dt_foreign_pin_add(test); + dt_fwnode_pin_add(test, &ctx->y, DT_CLOCK_ID_F, DT_PIN_IDX_Y); + dt_reg_add(test, &ctx->reg_y_f0, &ctx->dom_f, &ctx->y, &ctx->f0, NULL); + dt_reg_add(test, &ctx->reg_y_e0, &ctx->dom_e, &ctx->y, &ctx->e0, NULL); + ctx->reg_y_f0.forbid =3D ctx->e0.dpll->domain; + ctx->reg_y_e0.forbid =3D ctx->e0.dpll->domain; + + KUNIT_EXPECT_EQ(test, dt_run(test, dt_pin_ntf, &ctx->x), 0); + KUNIT_EXPECT_EQ(test, dt_run(test, dt_pin_ntf, &ctx->y), 0); +} + +/* A topology change waits until running requests finish */ +static void dt_test_topology_change_waits(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + struct dt_req *blocked, *writer; + + blocked =3D dt_block_in(test, &ctx->dom_a, dt_device_ntf, &ctx->a0); + + /* Added before the request starts, so it runs after waiting for it */ + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, dt_pin_release, + &ctx->extra), 0); + writer =3D dt_req_start(test, dt_extra_pin_get, &ctx->extra); + KUNIT_EXPECT_FALSE(test, dt_done(writer, DT_SHORT_TIMEOUT)); + + dt_unblock(ctx); + KUNIT_EXPECT_TRUE(test, dt_done(blocked, DT_TIMEOUT)); + KUNIT_ASSERT_TRUE(test, dt_done(writer, DT_TIMEOUT)); + KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ctx->extra.pin); +} + +/* Other requests about a pin cannot see a set of two attributes half done= */ +static void dt_check_request_atomic(struct kunit *test, struct dt_pin *pin, + struct dt_dev *dev0, struct dt_reg *reg0, + struct dt_dev *dev1, struct dt_reg *reg1) +{ + struct dt_pin_set_args *args =3D dt_pin_set_args_alloc(test, pin->pin, 2); + struct dt_ctx *ctx =3D test->priv; + struct dt_req *set, *other; + int i; + + args->ctx =3D ctx; + for (i =3D 0; i < args->num; i++) { + args->nests[i].type =3D DPLL_A_PIN_PARENT_DEVICE; + args->nests[i].parent_id =3D i ? dev1->dpll->id : dev0->dpll->id; + args->nests[i].attr =3D DPLL_A_PIN_PRIO; + args->nests[i].val =3D 11; + } + + ctx->atomic_regs[0] =3D reg0; + ctx->atomic_regs[1] =3D reg1; + + /* The other request starts to wait before the first attribute is set */ + WRITE_ONCE(reg0->block_prio_set, true); + set =3D dt_req_start(test, dt_pin_set_fn, args); + KUNIT_ASSERT_TRUE(test, wait_for_completion_timeout(®0->dom->entered, + DT_TIMEOUT)); + other =3D dt_req_start(test, dt_pin_ntf, pin); + KUNIT_EXPECT_FALSE(test, dt_done(other, DT_SHORT_TIMEOUT)); + + dt_unblock(ctx); + KUNIT_ASSERT_TRUE(test, dt_done(set, DT_TIMEOUT)); + KUNIT_ASSERT_TRUE(test, dt_done(other, DT_TIMEOUT)); + KUNIT_EXPECT_EQ(test, set->ret, 0); + KUNIT_EXPECT_EQ(test, reg0->prio, 11); + KUNIT_EXPECT_EQ(test, reg1->prio, 11); + KUNIT_EXPECT_EQ(test, atomic_read(&ctx->torn), 0); +} + +static void dt_test_request_is_atomic(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + + dt_check_request_atomic(test, &ctx->p, &ctx->a0, &ctx->reg_p_a0, + &ctx->a1, &ctx->reg_p_a1); +} + +static void dt_test_spanning_request_is_atomic(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + + dt_foreign_pin_add(test); + dt_check_request_atomic(test, &ctx->x, &ctx->e0, &ctx->reg_x_e0, + &ctx->f0, &ctx->reg_x_f0); +} + +/* Notifications from a callback come first, under the domain lock */ +static void dt_test_ntf_order(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + int ret; + + ctx->record =3D true; + ret =3D dt_pin_set_one(test, ctx->p.pin, DPLL_A_PIN_PARENT_DEVICE, + ctx->a0.dpll->id, DPLL_A_PIN_STATE, + DPLL_PIN_STATE_CONNECTED); + ctx->record =3D false; + + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, ctx->reg_p_a0.state, DPLL_PIN_STATE_CONNECTED); + dt_expect_events(test, (void *[]){ ctx->s.pin, ctx->p.pin }, 2); +} + +/* A notification from a callback that fails is still sent */ +static void dt_test_ntf_on_failure(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + int ret; + + ctx->fail_after_ntf =3D true; + ctx->record =3D true; + ret =3D dt_pin_set_one(test, ctx->p.pin, DPLL_A_PIN_PARENT_DEVICE, + ctx->a0.dpll->id, DPLL_A_PIN_STATE, + DPLL_PIN_STATE_CONNECTED); + ctx->record =3D false; + + KUNIT_EXPECT_EQ(test, ret, -EIO); + dt_expect_events(test, (void *[]){ ctx->s.pin }, 1); +} + +/* A set on a pin under a parent of another domain needs only its domain */ +static void dt_test_set_on_pin(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + int ret; + + dt_on_pin_add(test); + + ctx->record =3D true; + ret =3D dt_pin_set_one(test, ctx->c.pin, DPLL_A_PIN_PARENT_PIN, + ctx->m.pin->id, DPLL_A_PIN_STATE, + DPLL_PIN_STATE_CONNECTED); + ctx->record =3D false; + + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, ctx->reg_c_m.state, DPLL_PIN_STATE_CONNECTED); + dt_expect_events(test, (void *[]){ ctx->c.pin }, 1); +} + +/* A device callback notifies a sibling device of its domain */ +static void dt_test_device_set_ntf(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + struct dt_mode_set_args *args; + int ret; + + args =3D kunit_kzalloc(test, sizeof(*args), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, args); + args->dpll =3D ctx->a0.dpll; + args->mode =3D DPLL_MODE_MANUAL; + + ctx->record =3D true; + ret =3D dt_run(test, dt_mode_set_fn, args); + ctx->record =3D false; + + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, ctx->a0.mode, DPLL_MODE_MANUAL); + dt_expect_events(test, (void *[]){ ctx->a1.dpll }, 1); +} + +/* A change of a reference sync pair notifies under the domain of the pin = */ +static void dt_test_ref_sync_pair(struct kunit *test) +{ + struct dt_ctx *ctx =3D test->priv; + int ret; + + ctx->record =3D true; + ret =3D dpll_pin_ref_sync_pair_add(ctx->p.pin, ctx->s.pin); + ctx->record =3D false; + + KUNIT_EXPECT_EQ(test, ret, 0); + dt_expect_events(test, (void *[]){ ctx->p.pin }, 1); +} + +static struct kunit_case dt_cases[] =3D { + KUNIT_CASE(dt_test_domain_sharing), + KUNIT_CASE(dt_test_domain_per_module), + KUNIT_CASE(dt_test_foreign_registration_domain), + KUNIT_CASE(dt_test_on_pin_registration_domain), + KUNIT_CASE(dt_test_domains_run_in_parallel), + KUNIT_CASE(dt_test_domain_is_serialized), + KUNIT_CASE(dt_test_foreign_get_locks), + KUNIT_CASE(dt_test_foreign_set_locks), + KUNIT_CASE(dt_test_foreign_callback_notifies_pin), + KUNIT_CASE(dt_test_pin_without_owner), + KUNIT_CASE(dt_test_stuck_foreign_callback), + KUNIT_CASE(dt_test_stuck_foreign_device), + KUNIT_CASE(dt_test_stuck_owner_domain), + KUNIT_CASE(dt_test_on_pin_domains_are_independent), + KUNIT_CASE(dt_test_registrations_both_directions), + KUNIT_CASE(dt_test_topology_change_waits), + KUNIT_CASE(dt_test_request_is_atomic), + KUNIT_CASE(dt_test_spanning_request_is_atomic), + KUNIT_CASE(dt_test_ntf_order), + KUNIT_CASE(dt_test_ntf_on_failure), + KUNIT_CASE(dt_test_set_on_pin), + KUNIT_CASE(dt_test_device_set_ntf), + KUNIT_CASE(dt_test_ref_sync_pair), + {} +}; + +static struct kunit_suite dt_suite =3D { + .name =3D "dpll_core", + .init =3D dt_init, + .exit =3D dt_exit, + .test_cases =3D dt_cases, +}; + +kunit_test_suite(dt_suite); + +MODULE_DESCRIPTION("KUnit tests for locking in the DPLL core"); +MODULE_LICENSE("GPL"); diff --git a/drivers/dpll/dpll_netlink.c b/drivers/dpll/dpll_netlink.c index 9d8f5d1ce97248..223cd1de905c1a 100644 --- a/drivers/dpll/dpll_netlink.c +++ b/drivers/dpll/dpll_netlink.c @@ -6,6 +6,7 @@ * Copyright (c) 2023 Intel and affiliates * */ +#include #include #include #include @@ -1836,6 +1837,7 @@ int dpll_nl_pin_set_doit(struct sk_buff *skb, struct = genl_info *info) =20 return dpll_pin_set_from_nlattr(pin, info); } +EXPORT_SYMBOL_IF_KUNIT(dpll_nl_pin_set_doit); =20 static struct dpll_device * dpll_device_find(u64 clock_id, struct nlattr *mod_name_attr, @@ -2010,6 +2012,7 @@ int dpll_nl_device_set_doit(struct sk_buff *skb, stru= ct genl_info *info) =20 return dpll_set_from_nlattr(dpll, info); } +EXPORT_SYMBOL_IF_KUNIT(dpll_nl_device_set_doit); =20 int dpll_nl_device_get_dumpit(struct sk_buff *skb, struct netlink_callback= *cb) { @@ -2070,6 +2073,7 @@ int dpll_pre_doit(const struct genl_split_ops *ops, s= truct sk_buff *skb, up_read(&dpll_lock); return -ENODEV; } +EXPORT_SYMBOL_IF_KUNIT(dpll_pre_doit); =20 void dpll_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) @@ -2079,6 +2083,7 @@ void dpll_post_doit(const struct genl_split_ops *ops,= struct sk_buff *skb, mutex_unlock(&dpll->domain->lock); up_read(&dpll_lock); } +EXPORT_SYMBOL_IF_KUNIT(dpll_post_doit); =20 int dpll_lock_doit(const struct genl_split_ops *ops, struct sk_buff *skb, @@ -2122,6 +2127,7 @@ int dpll_pin_pre_doit(const struct genl_split_ops *op= s, struct sk_buff *skb, up_read(&dpll_lock); return ret; } +EXPORT_SYMBOL_IF_KUNIT(dpll_pin_pre_doit); =20 void dpll_pin_post_doit(const struct genl_split_ops *ops, struct sk_buff *= skb, struct genl_info *info) @@ -2131,3 +2137,4 @@ void dpll_pin_post_doit(const struct genl_split_ops *= ops, struct sk_buff *skb, mutex_unlock(&pin->domain->lock); up_read(&dpll_lock); } +EXPORT_SYMBOL_IF_KUNIT(dpll_pin_post_doit); --=20 2.56.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794415274; b=r1M1NJusvYr/+TRehWuIvtBrqTK05Lfl7ebFyZIWR0UqYREnXJSU6VQhpfOIt8df9LWl qKXfckenU01bsRXpTKfL8p8x0/axmhWZPGH9yIMvHpo5z+4VQZoieaPnV+CMhBsA/4YUE cnrJMZ2b+JoGCOKoTnQy4Mn6rrdV+K1igR3Rqwx0eakVCZqzBFheZJQ02k5fVrHKF5q45 rGpBimBVp1jkT3b+cpuxHInsVEjNHgxyUXwvXn4ixN8bxFSuXvxw/UP+dDES5WWtIUZXK 1qSrQ9LI160kBiuRb52tFN16nO4hmGc81QP/vtYRljyb+8gbuyQ0buIRB+2pbR/IRxw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794415274; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=YVBnk+tKGuQmlOeutGxL0dvsVwIL5GEniKA9KvwsYEE=; b=5pz2CXMwE/B88NezH2fVM0AI8tqk7NvhAzYhI0mW0958fV7FXSHTY9KoZzSjv5Hf/bjr fdegQ4SL0DhCdQXSj7N+J9mMy8j9KzT+Bg4xmVVdfGdflEAF0q/ceW0yFfVI6BrEn6xeD sUdR4TbaFgA1j3xlaBylTPckSyzxmhRRQ1UwPFyf/OLO/xRT3jvQ8+RbydaJCrLn4wPmg j0MpmYwyPlJzG9PLyzBoQMk3GZQMFunhKBkBA4JLtc60BiZbcFZf5FN6nahrCKeKvdifE TKan07OZrPEhIdjd5Y9XS5WcRU/S5MOOdj3Qb80njSJLoOxYFRpdi8gDyKcaabpGTyg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=emY4mXzh; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 528AF60A3817 for ; Wed, 11 Nov 2026 16:41:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 528AF60A3817 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.a=rsa-sha256 header.s=mimecast20190719 header.b=emY4mXzh DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794415273; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YVBnk+tKGuQmlOeutGxL0dvsVwIL5GEniKA9KvwsYEE=; b=emY4mXzhG2OAdqZ+B7RZ9GNL7K5CWDFqoykOQlSYY3aSITh+NB+Mp4PQHEHWcvfZ2H2kFp FFImHhitg5PR75AV2tOPZ38qoqx0VYPJA4KdQikdl/YGMVoyoGm0OxfLVHClWgtXCzMPom 73fmoKVa+Gh6Hu/hZlA0eU0JO93QMeA= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-674-vuk2LXO-MVGBwJ0yhq-E7g-1; Wed, 11 Nov 2026 11:41:09 -0500 X-MC-Unique: vuk2LXO-MVGBwJ0yhq-E7g-1 X-Mimecast-MFC-AGG-ID: vuk2LXO-MVGBwJ0yhq-E7g_1794415266 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 00C711955E7E; Wed, 11 Nov 2026 16:41:06 +0000 (UTC) Received: from ivecera-thinkpadp16vgen1.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 731AB421; Wed, 11 Nov 2026 16:41:00 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Vadim Fedorenko , Arkadiusz Kubalewski , Jiri Pirko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Min Li , Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, Grzegorz Nitka , Karol Kolacinski , Saeed Mahameed , Tariq Toukan , Petr Oros Subject: [PATCH net-next v2 6/9] dpll: reject measured_freq_get for foreign and on-pin registrations Date: Wed, 11 Nov 2026 17:40:17 +0100 Message-ID: <20261111164021.273409-7-ivecera@redhat.com> In-Reply-To: <20261111164021.273409-1-ivecera@redhat.com> References: <20261111164021.273409-1-ivecera@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Content-Type: text/plain; charset="utf-8" A message about a pin with .measured_freq_get calls .freq_monitor_get of a dpll of the pin. For a pin of another domain, this device callback would run outside the domain of the dpll, so dpll_pin_register() now rejects such ops. dpll_pin_on_pin_register() checks nothing about them. The message would call .freq_monitor_get with no NULL check, on a dpll of the parent pin that can belong to another driver, so reject them there as well. No in-tree driver passes such ops. Add KUnit tests: the ops work on a dpll of the domain of the pin, and are rejected on a dpll of another domain and under a parent pin. Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera --- No changes since v1 --- drivers/dpll/dpll_core.c | 6 +- drivers/dpll/dpll_core_kunit.c | 112 +++++++++++++++++++++++++++++++-- 2 files changed, 111 insertions(+), 7 deletions(-) diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index 2b1dfe2929647e..a73abb0772cc6b 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -958,7 +958,8 @@ dpll_pin_register(struct dpll_device *dpll, struct dpll= _pin *pin, =20 dev_ops =3D dpll_device_ops(dpll); if (WARN_ON(ops->measured_freq_get && - (!dev_ops || !dev_ops->freq_monitor_get || + (pin->domain !=3D dpll->domain || !dev_ops || + !dev_ops->freq_monitor_get || !dev_ops->freq_monitor_set))) { ret =3D -EINVAL; goto out_unlock; @@ -1065,7 +1066,8 @@ int dpll_pin_on_pin_register(struct dpll_pin *parent,= struct dpll_pin *pin, =20 if (WARN_ON(!ops) || WARN_ON(!ops->state_on_pin_get) || - WARN_ON(!ops->direction_get)) + WARN_ON(!ops->direction_get) || + WARN_ON(ops->measured_freq_get)) return -EINVAL; =20 down_write(&dpll_lock); diff --git a/drivers/dpll/dpll_core_kunit.c b/drivers/dpll/dpll_core_kunit.c index 21f941a5fdec4e..d575eed160700f 100644 --- a/drivers/dpll/dpll_core_kunit.c +++ b/drivers/dpll/dpll_core_kunit.c @@ -87,6 +87,7 @@ struct dt_reg { struct dt_dev *dev; struct dt_pin *parent; struct dt_pin *notify; + const struct dpll_pin_ops *ops; struct dpll_domain *forbid; enum dpll_pin_state state; enum dpll_pin_direction direction; @@ -276,11 +277,33 @@ static int dt_lock_status_get(const struct dpll_devic= e *dpll, void *priv, return 0; } =20 +static int dt_freq_monitor_set(const struct dpll_device *dpll, void *priv, + enum dpll_feature_state state, + struct netlink_ext_ack *extack) +{ + return 0; +} + +static int dt_freq_monitor_get(const struct dpll_device *dpll, void *priv, + enum dpll_feature_state *state, + struct netlink_ext_ack *extack) +{ + struct dt_dev *dev =3D priv; + + dt_dev_enter(dev, dpll); + *state =3D DPLL_FEATURE_STATE_ENABLE; + dt_leave(dev->dom); + + return 0; +} + static const struct dpll_device_ops dt_dev_ops =3D { .mode_get =3D dt_mode_get, .mode_set =3D dt_mode_set, .supported_modes_get =3D dt_supported_modes_get, .lock_status_get =3D dt_lock_status_get, + .freq_monitor_set =3D dt_freq_monitor_set, + .freq_monitor_get =3D dt_freq_monitor_get, }; =20 static int dt_frequency_get(const struct dpll_pin *pin, void *pin_priv, @@ -433,6 +456,21 @@ static int dt_ref_sync_get(const struct dpll_pin *pin,= void *pin_priv, return 0; } =20 +static int dt_measured_freq_get(const struct dpll_pin *pin, void *pin_priv, + const struct dpll_device *dpll, void *dpll_priv, + u64 *measured_freq, + struct netlink_ext_ack *extack) +{ + struct dt_reg *reg =3D pin_priv; + + dt_pin_enter(reg, pin); + atomic_inc(®->freq_gets); + *measured_freq =3D 1; + dt_leave(reg->dom); + + return 0; +} + static const struct dpll_pin_ops dt_pin_ops =3D { .frequency_get =3D dt_frequency_get, .state_on_dpll_get =3D dt_state_on_dpll_get, @@ -446,6 +484,13 @@ static const struct dpll_pin_ops dt_pin_ops =3D { .ref_sync_get =3D dt_ref_sync_get, }; =20 +static const struct dpll_pin_ops dt_pin_ops_measured =3D { + .measured_freq_get =3D dt_measured_freq_get, + .state_on_dpll_get =3D dt_state_on_dpll_get, + .state_on_pin_get =3D dt_state_on_pin_get, + .direction_get =3D dt_direction_get, +}; + static const struct dpll_pin_properties dt_prop =3D { .type =3D DPLL_PIN_TYPE_EXT, .capabilities =3D DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE | @@ -570,9 +615,9 @@ static void dt_reg_release(void *data) =20 if (reg->parent) dpll_pin_on_pin_unregister(reg->parent->pin, reg->pin->pin, - &dt_pin_ops, reg); + reg->ops, reg); else - dpll_pin_unregister(reg->dev->dpll, reg->pin->pin, &dt_pin_ops, + dpll_pin_unregister(reg->dev->dpll, reg->pin->pin, reg->ops, reg); } =20 @@ -588,12 +633,14 @@ static void dt_reg_add(struct kunit *test, struct dt_= reg *reg, reg->parent =3D parent; reg->state =3D DPLL_PIN_STATE_SELECTABLE; reg->direction =3D DPLL_PIN_DIRECTION_INPUT; + if (!reg->ops) + reg->ops =3D &dt_pin_ops; =20 if (parent) - ret =3D dpll_pin_on_pin_register(parent->pin, pin->pin, - &dt_pin_ops, reg); + ret =3D dpll_pin_on_pin_register(parent->pin, pin->pin, reg->ops, + reg); else - ret =3D dpll_pin_register(dev->dpll, pin->pin, &dt_pin_ops, reg); + ret =3D dpll_pin_register(dev->dpll, pin->pin, reg->ops, reg); KUNIT_ASSERT_EQ(test, ret, 0); KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, dt_reg_release, reg), 0); @@ -1438,6 +1485,59 @@ static void dt_test_ref_sync_pair(struct kunit *test) dt_expect_events(test, (void *[]){ ctx->p.pin }, 1); } =20 +/* A pin with a measured frequency must be in the domain of its dpll */ +static void dt_test_measured_freq_foreign(struct kunit *test) +{ + struct kunit_suppressed_warning *w; + struct dt_ctx *ctx =3D test->priv; + struct dt_reg *reg; + int ret; + + dt_dev_add(test, &ctx->e0, &ctx->dom_e, DT_CLOCK_ID_E, 0, + DPLL_TYPE_PPS); + dt_dev_add(test, &ctx->f0, &ctx->dom_f, DT_CLOCK_ID_F, 0, + DPLL_TYPE_PPS); + dt_fwnode_pin_add(test, &ctx->x, DT_CLOCK_ID_E, DT_PIN_IDX_X); + + reg =3D &ctx->reg_x_e0; + reg->ops =3D &dt_pin_ops_measured; + dt_reg_add(test, reg, &ctx->dom_e, &ctx->x, &ctx->e0, NULL); + atomic_set(®->freq_gets, 0); + KUNIT_EXPECT_EQ(test, dt_run(test, dt_pin_ntf, &ctx->x), 0); + KUNIT_EXPECT_GT(test, atomic_read(®->freq_gets), 0); + + w =3D kunit_start_suppress_warning(test); + ret =3D dpll_pin_register(ctx->f0.dpll, ctx->x.pin, reg->ops, reg); + kunit_end_suppress_warning(test, w); + + KUNIT_EXPECT_EQ(test, ret, -EINVAL); + if (!ret) + dpll_pin_unregister(ctx->f0.dpll, ctx->x.pin, reg->ops, reg); +} + +/* A pin under a parent pin cannot have a measured frequency */ +static void dt_test_measured_freq_on_pin(struct kunit *test) +{ + struct kunit_suppressed_warning *w; + struct dt_ctx *ctx =3D test->priv; + struct dt_reg *reg; + int ret; + + dt_on_pin_add(test); + dt_pin_add(test, &ctx->y, DT_CLOCK_ID_G, DT_PIN_IDX_Y, &dt_prop); + reg =3D &ctx->reg_c_m; + + w =3D kunit_start_suppress_warning(test); + ret =3D dpll_pin_on_pin_register(ctx->m.pin, ctx->y.pin, + &dt_pin_ops_measured, reg); + kunit_end_suppress_warning(test, w); + + KUNIT_EXPECT_EQ(test, ret, -EINVAL); + if (!ret) + dpll_pin_on_pin_unregister(ctx->m.pin, ctx->y.pin, + &dt_pin_ops_measured, reg); +} + static struct kunit_case dt_cases[] =3D { KUNIT_CASE(dt_test_domain_sharing), KUNIT_CASE(dt_test_domain_per_module), @@ -1462,6 +1562,8 @@ static struct kunit_case dt_cases[] =3D { KUNIT_CASE(dt_test_set_on_pin), KUNIT_CASE(dt_test_device_set_ntf), KUNIT_CASE(dt_test_ref_sync_pair), + KUNIT_CASE(dt_test_measured_freq_foreign), + KUNIT_CASE(dt_test_measured_freq_on_pin), {} }; =20 --=20 2.56.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794415280; b=IlnXBhbmV/vHupJUwnuPq5kCY1JLQt5t2mwvEiJxqwqcv+noSTLfOvdIrl88FRWSuh8l k14GzL7zKG0oCpSbyhpzxJmhSUk75l257YZ4TKYDZIAXS0dAe3qM7gdqA6Vwq7Cyb4i3K geTNBrWZ7mpfOiqXiGvV1ADaZ1RTJ01k1i6/W/MGfOZmF5M5aJ9QVoPqANsyDqQz6XjDH FjhhOqWQPAgV+KAsoB60010POSdnz3NGEBU18Ub9xMTR7CAkZl0xv1AWEu/2dl9f4kq8w wvDmOVWTw5nNc2B5/BjEvGyN7amcOVN+FQN1KyMgbe9gA/avD53om/MutyzyiBMEi/A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794415280; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=jOxpAWZEDjh6YuLzUFmhUB+/S4//KD7ZYS5impIWXLs=; b=U7EKnqwqdLG86zOuOBziJVQQZ8AyULNNgheXk6JTjmGLlOQU4Z0lUJw1dxGXz6Cqg1SC Opn6KtDog6JxUDenEL9LxTiiYg/+BNYIEY7g757SBw7F0woRjsPhFs/CfmlOIdrDtZIaN wZytragizChc16XnDb5cdj7MX3Vp+gbL9HHTIHk+VAqJnf2CPWSONOaA3qSFDxM8qzhok unfiMa61I6UEVOtidGlgjTOPKbCPnMYJe4KKOMiyles8QdO3TfnbZg25SAC38O5YI3tXg SROf/G/wixwaBDN5a4uspXbmMhTI/fR4ymPJdphlr4+Kqcdlouf/pZ4J3gS4rdm3H9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=eE7GAG+a; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D40760A5BC1 for ; Wed, 11 Nov 2026 16:41:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3D40760A5BC1 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.a=rsa-sha256 header.s=mimecast20190719 header.b=eE7GAG+a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794415279; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jOxpAWZEDjh6YuLzUFmhUB+/S4//KD7ZYS5impIWXLs=; b=eE7GAG+aogJ2GKHh7u3B0AsNTkXKAS+Plg2IGWYo1lyxNU/cJiY7pYE6fEnO1hXBLMC3mU FMVOC2R58LZD0vz6TOBJoH+4RpYG9reCs68aDTgnkoHQow8bEGRspSvur+NCOKZt5RR8K0 xzV/YkSWFfJzMc57UApHBpTx2CmFb5A= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-388-jlDh60aTO8q3L_Wbnk2pqg-1; Wed, 11 Nov 2026 11:41:14 -0500 X-MC-Unique: jlDh60aTO8q3L_Wbnk2pqg-1 X-Mimecast-MFC-AGG-ID: jlDh60aTO8q3L_Wbnk2pqg_1794415272 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EAA7A1955DC5; Wed, 11 Nov 2026 16:41:11 +0000 (UTC) Received: from ivecera-thinkpadp16vgen1.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 61D1D410; Wed, 11 Nov 2026 16:41:06 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Vadim Fedorenko , Arkadiusz Kubalewski , Jiri Pirko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Min Li , Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, Grzegorz Nitka , Karol Kolacinski , Saeed Mahameed , Tariq Toukan , Petr Oros Subject: [PATCH net-next v2 7/9] dpll: zl3073x: update locking comments Date: Wed, 11 Nov 2026 17:40:18 +0100 Message-ID: <20261111164021.273409-8-ivecera@redhat.com> In-Reply-To: <20261111164021.273409-1-ivecera@redhat.com> References: <20261111164021.273409-1-ivecera@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Content-Type: text/plain; charset="utf-8" Callbacks are serialized by the DPLL core domain lock instead of dpll_lock. All channels of a chip belong to one domain, so what the comments rely on still holds. Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera --- No changes since v1 --- drivers/dpll/zl3073x/dpll.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/dpll/zl3073x/dpll.c b/drivers/dpll/zl3073x/dpll.c index 1cdadb8e46fb2d..6e5e2bb41f55d6 100644 --- a/drivers/dpll/zl3073x/dpll.c +++ b/drivers/dpll/zl3073x/dpll.c @@ -349,9 +349,10 @@ zl3073x_dpll_input_pin_ref_sync_set(const struct dpll_= pin *dpll_pin, if (rc) goto unlock; =20 - /* All code paths accessing per-channel reference priorities are - * serialized by the subsystem dpll_lock, so it is safe to release - * our lock here before iterating over the other channels. + /* All callbacks accessing per-channel reference priorities are + * serialized by the DPLL core domain lock shared by all channels of + * the chip, so it is safe to release our lock here before iterating + * over the other channels. */ mutex_unlock(&zldpll->lock); =20 @@ -2401,7 +2402,7 @@ zl3073x_dpll_changes_check(struct zl3073x_dpll *zldpl= l) mutex_unlock(&zldpll->lock); =20 /* Send notifications outside the lock to avoid ABBA deadlock - * with dpll_lock taken by notification functions. + * with the DPLL core domain lock taken by notification functions. */ if (dev_changed) dpll_device_change_ntf(zldpll->dpll_dev); --=20 2.56.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794415287; b=4pc7biwXmwGB0aWiBncENcFx3aHWDDjj2ozU0aKOO0FyDXIFq7mqpR6W0bKNQRxLDST8 ivBhoTP/HoxVOrElUd30aCMbImmnoSQXg+47PNeRehM/HKs1ZFOVby/PkOOVwVT5PvFEm PJ1TxUR2LjV7LweU9mlJjbQm82gxPFAYpDaeIkowOYOfOBVEKzZn9MEM6zA8VcE4T8iEd mwjINOj+6XTWWwgP86SRATeUaLtTDigX5cPn5sNE9AcvprPS/Oce8oDw4/5dfYt/rQVv6 rt1MdBB9fcxVirfY0+9YiP8gsLLvEP84UR2SzGk7XGZeFJE57jqGzjfDJAAfACL7N4g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794415287; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=NX9FKH6K+UEomRB8px05FQHC/CI9W13+rfvS8/4IDW0=; b=CX4S4sJMhDnFyalflkR9ljh3TmT1V+dMmWJu+xH0tJjXeb4hw+6UH88vQgnjvIKAvz03 xdIZGVGhP4JMS2Usq8Bar/+bB64SBYrhrsOWu3nelpRm9g+wFmF1YSrN2MgFF2fZxhG+8 p+6I2CztrzMcEaZ8wgpzLCBggmXzGGVRpzd8DkwbhPen7cvZ3IwIsmyPikDbdDZbYO9ZQ wnu/j22PxPqtbSQUhGcLho/708VRlmAEii1SVDZSs9pPz/zvxqxf9MmIFp9l/RZFofshE kQbJpsZfpcOax0pEARrcDAkckxewEtnV4S+cbTMm2gYPef77zkJCTLkeGK6Oj6iWKBg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TGBoC6iw; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35000606A8BB for ; Wed, 11 Nov 2026 16:41:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 35000606A8BB 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.a=rsa-sha256 header.s=mimecast20190719 header.b=TGBoC6iw DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794415286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NX9FKH6K+UEomRB8px05FQHC/CI9W13+rfvS8/4IDW0=; b=TGBoC6iwOAkKml+s4xqozq20tujaNzLZqazVIqqKMDGMQVZZxczmVAzZm7sHwS2lI4yN32 reY7QIPdvZ7VrPWpP64CvPy2Mi+ijC9vXAsa9HgJb71+x1Nl4KVLxKCtGqhGSMfILN1DTp 41hjtq8/c/PAWlG67wN5314j7dyBJT4= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-478-udOd2yd0Nz--KgahitOCoA-1; Wed, 11 Nov 2026 11:41:20 -0500 X-MC-Unique: udOd2yd0Nz--KgahitOCoA-1 X-Mimecast-MFC-AGG-ID: udOd2yd0Nz--KgahitOCoA_1794415278 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D9C981955E7E; Wed, 11 Nov 2026 16:41:17 +0000 (UTC) Received: from ivecera-thinkpadp16vgen1.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 593AD410; Wed, 11 Nov 2026 16:41:12 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Vadim Fedorenko , Arkadiusz Kubalewski , Jiri Pirko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Min Li , Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, Grzegorz Nitka , Karol Kolacinski , Saeed Mahameed , Tariq Toukan , Petr Oros Subject: [PATCH net-next v2 8/9] ice: dpll: update locking comments Date: Wed, 11 Nov 2026 17:40:19 +0100 Message-ID: <20261111164021.273409-9-ivecera@redhat.com> In-Reply-To: <20261111164021.273409-1-ivecera@redhat.com> References: <20261111164021.273409-1-ivecera@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Content-Type: text/plain; charset="utf-8" Callbacks run under the DPLL core domain locks instead of dpll_lock. On E825 the TXC DPLL, the TSPLL DPLL and the other objects of a PF are in three domains, and callbacks of pins of an external DPLL run under the domain of that DPLL, so only pf->dplls.lock serializes them with each other. Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera --- Changes in v2: - Described the three domains of an E825 PF (Sashiko) --- drivers/net/ethernet/intel/ice/ice_dpll.c | 4 ++-- drivers/net/ethernet/intel/ice/ice_dpll.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.c b/drivers/net/ethern= et/intel/ice/ice_dpll.c index 0877827a6521cc..5d0a52d86f03e8 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.c +++ b/drivers/net/ethernet/intel/ice/ice_dpll.c @@ -1178,8 +1178,8 @@ ice_dpll_input_state_get(const struct dpll_pin *pin, = void *pin_priv, * peer via dpll netlink learn about the update. * * Context: Called from dpll_pin_ops callbacks after pf->dplls.lock is - * released. Uses __dpll_pin_change_ntf() because dpll_lock is - * still held by the dpll netlink layer. + * released. Uses __dpll_pin_change_ntf() because the domain lock + * is still held by the dpll core. */ static void ice_dpll_sw_pin_notify_peer(struct ice_dplls *d, struct ice_dpll_pin *changed) diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.h b/drivers/net/ethern= et/intel/ice/ice_dpll.h index bce0bea9a664bc..c522c5fcbcce52 100644 --- a/drivers/net/ethernet/intel/ice/ice_dpll.h +++ b/drivers/net/ethernet/intel/ice/ice_dpll.h @@ -164,6 +164,11 @@ struct ice_dpll { * tx_refclks usage map), acquire pf->dplls.lock first, then * ctrl_pf->dplls.lock. Skip the second acquire when pf =3D=3D ctrl_pf * to avoid recursive locking. + * - The DPLL core serializes callbacks per (module, clock_id) domain. On + * E825 the TXC DPLL, the TSPLL DPLL and the other objects of a PF, su= ch + * as the RCLK pin, use three different clock_ids, and callbacks of the + * SYNCE and TIME_REF pins of an external DPLL run under the domain of + * that DPLL, so only @lock serializes all of them with each other. * - @txclk_notify_rwsem is held for read across * ice_txclk_update_and_notify(), including the out-of-lock * dpll_*_change_ntf() calls. ice_dpll_deinit() takes the write side --=20 2.56.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794415292; b=ixVH6IO9yw5PhM0DhpsYS+5gQi4K8CD2YQwVI8ceseP20+PlpeEf6FlI+LUm3E7/p5i2 7HUIa/KZS1BhE4szmp7pmhuSmXz+bv7GthmP+Jv6SZqBJz8XTOYPBwvXJ/R95iGhuv0Nz ivq4+nGHyXGRR4Dg6DN3bJP7Fhm8K+kTtCH9bXaI4l9Qe1tKaAFpwhPg82znHEpxihLqR BZ3u9++6b62xZ4wn+MKvdOTIU2V1oRWbTukpTuvommtgzzBHQs4BVPCNq0yZk3xtnKo/I kvt9do7tQiYbWDwbwOnrhK165iDKoCK5pdQwwz6QqGrRsTph3ek6regV+xP1+yS/m/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794415292; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=TC/qzi0GwbwJRPe4iytsw8ARC/xSRyQXvSanD2vms5g=; b=jeTra4VhpLRW0JzpIsbMSNh+goqaxq4krKOipRms4WqGTsCnIfhURhIalXiViNH0s+7w 5lv9vPyUCknU4HBDPiWeVKbf8rh1EMri9f98PxTOA9Pq8KBjMCWP9Wv7cEPM9wRrVd1et KG52C3TvG4FqFPI+X4v15MjT1DW74l3jWfUbgMBeb67acCFNgCZHUQ82UNIZyKVsRVpch lqmQF4ngHCRGmQYOaGZRoEhdXgWqxLqR8Olq4cHeDL2wZF8HWTrSe6mDk8bn7+f3GnAPF QJVYV6O0qzm3cksQ94d5ExvTYY+cMp7hvAnqYGRqoM6F89vrHCUswukUG08sBlytD3w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ViYp3FRw; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8047E60A2606 for ; Wed, 11 Nov 2026 16:41:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8047E60A2606 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.a=rsa-sha256 header.s=mimecast20190719 header.b=ViYp3FRw DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794415290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TC/qzi0GwbwJRPe4iytsw8ARC/xSRyQXvSanD2vms5g=; b=ViYp3FRwmH1jz3kkbUNp8AiQMotf/rta8pnIwVaEXdEZNlb7394jAEOjDWP/1mdT29Vxa7 6r81+yNdDajcd+MDBxeRZwOnHvk4gr6SvljEM+ev2kwU87exvPdXaN9RkipbRS2X6yf5S3 Vu88h4Jc9QZy6RZQSKUkt28W+il1Bfc= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-652-QeALwB0-N6OvZSh1l3qmTg-1; Wed, 11 Nov 2026 11:41:27 -0500 X-MC-Unique: QeALwB0-N6OvZSh1l3qmTg-1 X-Mimecast-MFC-AGG-ID: QeALwB0-N6OvZSh1l3qmTg_1794415284 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 337721955DE4; Wed, 11 Nov 2026 16:41:24 +0000 (UTC) Received: from ivecera-thinkpadp16vgen1.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 47E5A410; Wed, 11 Nov 2026 16:41:18 +0000 (UTC) From: Ivan Vecera To: netdev@vger.kernel.org Cc: Vadim Fedorenko , Arkadiusz Kubalewski , Jiri Pirko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Min Li , Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, Grzegorz Nitka , Karol Kolacinski , Saeed Mahameed , Tariq Toukan , Petr Oros Subject: [PATCH net-next v2 9/9] dpll: document locking rules Date: Wed, 11 Nov 2026 17:40:20 +0100 Message-ID: <20261111164021.273409-10-ivecera@redhat.com> In-Reply-To: <20261111164021.273409-1-ivecera@redhat.com> References: <20261111164021.273409-1-ivecera@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Content-Type: text/plain; charset="utf-8" Describe the lock levels of the subsystem, which domain a callback runs under and the rules device drivers have to follow. Reviewed-by: Petr Oros Signed-off-by: Ivan Vecera --- Changes in v2: - Added a rule for reference sync pairs (Sashiko) - Rules 1 and 3 also forbid waiting for a work item that notifies (Sashiko) --- Documentation/driver-api/dpll.rst | 48 +++++++++++++++++++++++++++++++ drivers/dpll/dpll_core.c | 13 +++++++++ 2 files changed, 61 insertions(+) diff --git a/Documentation/driver-api/dpll.rst b/Documentation/driver-api/d= pll.rst index 7c117ae37cc1bc..9cc6a912c58913 100644 --- a/Documentation/driver-api/dpll.rst +++ b/Documentation/driver-api/dpll.rst @@ -675,6 +675,54 @@ In the error path we have to rewind every allocation i= n the reverse order: =20 More complex example can be found in Intel's ICE driver or nVidia's mlx5 d= river. =20 +Locking +=3D=3D=3D=3D=3D=3D=3D + +The subsystem uses two levels of locks, always taken in this order: + +- ``dpll_lock`` protects the topology of dpll devices and pins and their + lifetime. Functions changing the topology, for example dpll_pin_register= (), + take it for write and send the create and delete notifications under it. + Netlink requests, each part of a dump and change notifications take it f= or + read for their whole duration. +- A domain lock serializes driver callbacks. All dpll devices and pins cre= ated + with the same module and ``clock_id`` belong to one domain, in practice = to + one chip or card. + +A netlink request addressing a device or a pin by its ID holds the domain = lock +of that object from start to end. A notification holds it while its messag= e is +built and sent, so messages of one object are sent in the order they were +built. Only one domain lock is held at a time, so domains have no lock ord= er, +and callbacks of different domains can run concurrently. + +Callbacks of a dpll device run under the domain of the device. Callbacks o= f a +pin run under the domain of the pin, whichever driver registered them: + +- A driver registering a pin of another driver with its dpll device has th= ese + callbacks serialized with the driver that created the pin, not with the = other + callbacks of its device, so it has to protect the state they share by it= self. + A callback stuck in such a registration stops the domain of the pin. +- The parent pin of a pin registered with dpll_pin_on_pin_register() and i= ts + dpll devices can belong to another driver, so the callback must not + dereference their private data. +- The frequency monitor belongs to the dpll device, so only callbacks of a= pin + of the same domain registered with dpll_pin_register() can include + ``.measured_freq_get``. +- The reference sync callbacks of a pin get the private data of the other = pin + of the pair, so both pins of a pair added by dpll_pin_ref_sync_pair_add() + have to belong to one domain. + +Device drivers have to follow these rules: + +- A callback must not call dpll_device_change_ntf(), dpll_pin_change_ntf()= or + any function changing the topology, nor wait for a work item that calls = them. +- A callback notifies about objects of the domain it runs under with + __dpll_device_change_ntf() or __dpll_pin_change_ntf(). Other objects hav= e to + be notified from a context that holds no domain lock, for example a work= item. +- A driver must not call dpll_device_change_ntf(), dpll_pin_change_ntf() o= r any + function changing the topology, nor wait for a work item that calls them, + while holding a lock that its callbacks take. + SyncE enablement =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D For SyncE enablement it is required to allow control over dpll device diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index a73abb0772cc6b..9a0843bba184af 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -932,6 +932,10 @@ __dpll_pin_register(struct dpll_device *dpll, struct d= pll_pin *pin, * @ops: ops for a dpll pin ops * @priv: pointer to private information of owner * + * The callbacks run under the domain of @pin. If @pin belongs to another = domain + * than @dpll, they are not serialized with the callbacks of @dpll and @op= s must + * not include .measured_freq_get. + * * Context: Acquires dpll_lock and domain locks * Return: * * 0 on success @@ -1049,6 +1053,11 @@ EXPORT_SYMBOL_GPL(dpll_pin_unregister); * Register a pin with a parent pin, create references between them and * between newly registered pin and dplls connected with a parent pin. * + * The callbacks run under the domain of @pin. The parent pin and its dpll= s can + * belong to another driver, so @ops must not dereference their private da= ta. + * The frequency monitor belongs to a dpll, so @ops must not include + * .measured_freq_get. + * * Context: Acquires dpll_lock and domain locks * Return: * * 0 on success @@ -1137,6 +1146,10 @@ EXPORT_SYMBOL_GPL(dpll_pin_on_pin_unregister); * * Once pins are paired, the user-space configuration of reference sync pa= ir * is possible. + * + * The reference sync callbacks of each pin get the private data of the ot= her + * one, so both pins must belong to one domain. + * * Context: Acquires dpll_lock and domain locks * Return: * * 0 on success --=20 2.56.0