From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.200.43 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794608874; b=XWJVxoGOi5XDJULjhBwC13ZRD5Nby9UotqqLdD3bJq+cK/BrGRnAZQiPS/EJGXJaRCDs bp++maIE8Rup0WhuUScRmcuri6d1roaZ7Q6vzgpZiFdbTojKxfSqrvoTHqhJ3/RaF2di/ qMeWRNcAdKTTjeeYDpRuGzXhUVcKsCs+OSFnzJJ6fIiROrJY2Wimb1Es0cPBC1Qxb03Hb 60PiIwquaSAu1/V+fqpmdcpPmTvNx9Obo44AxjFm0mL3QoKg4lnw79Uq3UXo+Azp3FxXx mmnfti2cyB8Y9sGY+cnG0MEX46A7O7hk785zccoEkjUKbEIHw6VA0IWIUYV76wEyEWQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794608874; h=DMARC-Filter:DKIM-Signature:Received:Received:Message-ID:Date: User-Agent:Subject:To:Cc:References:Content-Language:From: Organization:In-Reply-To:Content-Type:Content-Transfer-Encoding: X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; bh=zbuPc0OoAZ7ponEmKQKwRM1Aj93AVVBpwHllhPZs6NY=; b=Y08YFm/+H3crfdnYU6CYkDiSvnuXvHRYl0cOTeh2WRRHSrTnLIVuZoScvcfyuAv3mDWg Ckc38P4ZMHV4iBMKcNurFpmYEpyXyLqu1CniTg+yb0ZDUXGHFYKM7wTPGfgIQjlvotjFl Zi8yJ3ebtxfiT1uJFBIr+SGCo7gF697tj4LCRwwNUZjvLHLbxbwPPTuIQuReFodRXgLGn lk4l4XVnIEHS+9UopnLtqS8u0oOteS6PRyvpdrAO2UhtnZFhtAu4KeLW8epHYTiAzunJE gRszjvTltoQgKl8CNXzm/O36gmfEe/orzmyiqe6i1ttPe13uuAb7AxtO7m6xIDTxL7w== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=ttGeHoyb; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.200.43 Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazon11012043.outbound.protection.outlook.com [40.107.200.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28175606A32E for ; Fri, 13 Nov 2026 22:27:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 28175606A32E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=ttGeHoyb ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YoCttBzSC9UB2A4w2UWpSN3x8/wz9KwrSU5rz2bWyUSRDhVEeLsthxw0ou9T1Qu1mH6dY9xCqVo5Fn0lngQSCIbaXucU4Vk+iNsd8hfy/oAS7RqofuateMdxAhydbnyCI0zycZ9gdCgWzr5lb4EMBJfqBEGjU6WgAgGyq8o83P9dP0wsfOuhqesdwS8OuRSt0PrRs+lXgM89kkH7GWbO4W69oUJv8W6JwZXz2dc8vdNaobMEW2MAuJvrnu7+2MRxS6pK17RwBx4K1I7He/CcDjtBBtYikCnsXhyu/JcS3X5rhGHtsFuwntggEnMkBtIOIHqVWJ+19dtwd9vcsTFuVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zbuPc0OoAZ7ponEmKQKwRM1Aj93AVVBpwHllhPZs6NY=; b=ilLH+GuxgGtC24sKToAKMyMqndZSvEdFsBrRHSD8tKTbwsYpkgxrPPAr3SIKFhyCgJP7gxrQOglPZv2q0oOiagEQhqi8Pfdt68VMDMrE5d7Hjc8mkNMARa7eSNKk2ewwIETAJMDtvu9XgUE1zBrAN287J8eA8QeFMipJbsKLmOb7eGMRjN3xBRBd1Lxk7qOi4lvW/agwpLx3t0fqYltutr0X4wUONngYbaQROM4now9U5jLySVyIvBEZkYtRWJEgklYXJdINLVOgjUvsb6K7LBEK+xqF/EvGtwgdHZwOLNEWyIfZsBD71QMSy29dV9R2eIaIa/ls9kn6eGN1wG6VaA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zbuPc0OoAZ7ponEmKQKwRM1Aj93AVVBpwHllhPZs6NY=; b=ttGeHoybh12BWixcAMXorFi3xkvpuv7qzQCOZhgPO7dnmsufA8E6B8frU7S66z+Tmq5PZXGXyBylJ1v0eRCV97VLoUaEZsewiKxFfu97NHRoahRd3gokFsFxlrh3VjbRSgQjBsz6TisTQzt9PP3FyUx7UlRzx/Z2nrAMcAiVrDw= Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DS5PPF18A985A10.namprd12.prod.outlook.com (2603:10b6:f:fc00::645) by PH7PR12MB8014.namprd12.prod.outlook.com (2603:10b6:510:27c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.615.10; Fri, 13 Nov 2026 22:27:40 +0000 Received: from DS5PPF18A985A10.namprd12.prod.outlook.com ([fe80::dd24:2a58:c0d0:b183]) by DS5PPF18A985A10.namprd12.prod.outlook.com ([fe80::dd24:2a58:c0d0:b183%6]) with mapi id 15.21.0615.007; Fri, 13 Nov 2026 22:27:38 +0000 Message-ID: <65222154-22bf-4f31-a050-b7c0f0c99284@amd.com> Date: Fri, 13 Nov 2026 17:27:36 -0500 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] drm/amd/display: Hold the VRR vblank reference only on active CRTCs To: Hugo Sales , harry.wentland@amd.com, sunpeng.li@amd.com, siqueira@igalia.com, alexander.deucher@amd.com, amd-gfx@lists.freedesktop.org Cc: alex.hung@amd.com, mario.kleiner.de@gmail.com, nicholas.kazlauskas@amd.com, ray.wu@amd.com, bhawanpreet.lakha@amd.com, chiahsuan.chung@amd.com, jerry.zuo@amd.com, Aric.Cyr@amd.com, christian.koenig@amd.com, airlied@gmail.com, simona@ffwll.ch, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <20261031143351.3222033-1-hugo@hsal.es> Content-Language: en-US From: Ivan Lipski Organization: AMD Inc. In-Reply-To: <20261031143351.3222033-1-hugo@hsal.es> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: YT3PR01CA0085.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:84::16) To DS5PPF18A985A10.namprd12.prod.outlook.com (2603:10b6:f:fc00::645) 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 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS5PPF18A985A10:EE_|PH7PR12MB8014:EE_ X-MS-Office365-Filtering-Correlation-Id: deb46995-8ef2-438a-079a-08df41d552f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|23010399003|10067099003|11063799006|56012099006|261021135927099003|261021123027099003|261021121427099003|261022105027099003|261009223027099003|261102123227099003|261026140227099003|261028144727099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: TI7l+EmD8eluMldjdwSbhWLPDbs+z6VvXnd7y/uObywkWkrZ/fIxhIY8C3QMFjlqYT0G3Fyl17OV3IGeYzNqkX+j6djbKHPEq55f1HzIh/y8SJxwnxfElQSrLdjDX0rgdSyHfepWneWnOu7LGQ7e4loVPk4ZL36sCfjFiGufCg17VBXDrhdHwMwn1QYbafPQ4RyXXVKzKpHcY1Uhos09z7ym5r6tU2gsOfVL4UtyIQeZasnBcwxp38EFZ65goSEFesEgeaBbG4Vgpn9WZu+3qzDU1fwPFrPwAAOggNMmOmgpqBIzHn+YO3iegByU9HxhhmHUqnwtTATg9jyOdw43c7EK9jEex/tDrY0jtYqdepHjVofRyHVvqDyBkLqL/EX8DXmyr2tL/DS3ePY1qmim/Tn0GheaBuFKYCn/lfqludu6+onG6h+/TJX5Lgg+BpqVnPRU9G+L7ov4Njk+OHys0PsdpZGstDfUjP3xBjYBJElhRrq+UM4LWrxLy+uHQvC6k9vjDWL6rTmiZedLyCpF4DJeJdREp8VF3cVVtAooyQa4bRJr0pt5sUDmLP0VwZR3vo/VtkjyWxTH3O/lu8WKd+AdelrH6wMTyzWgjGnxhbxmCuJKsxRqse55RS3XaYRDjXUW65IY6V0jZyhhjfGwRc0HD2fsQspKNgSd+0/m2ms= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS5PPF18A985A10.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016)(23010399003)(10067099003)(11063799006)(56012099006)(261021135927099003)(261021123027099003)(261021121427099003)(261022105027099003)(261009223027099003)(261102123227099003)(261026140227099003)(261028144727099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?cWlCdTZLSHF4bklDdGpIYm5Da2pxNEJzTmVHcDVIV1cxT1d2MWp3QW90WEFt?= =?utf-8?B?bTVOTUNBVmVwU2w4Rms4eU5lVG91THBvQ01kUGJwaTc2Rm9tL3pUUDRtam9N?= =?utf-8?B?WW1teVA1RHJ1NjZxRGlBTkd1a2k1TWJSMmhLYy9qR3pFQ2FkV0pNZ05XRjFu?= =?utf-8?B?dDZqd1VMdWIrNUZpdTJ0clRDaHlzMk54WGVzR3BtNlF1Y2N2NnFIbUlLdFBT?= =?utf-8?B?S3JXSjRyMVlXRWlhWjEyNjkvWFpnY2doNnpQU1h6Lys5Q3VRZllrRThhd2tp?= =?utf-8?B?MkpVR3BRaEhXS1N5R3k2K0YwM09lcjVHdmYyOEFZN2dnUU9tNzZiMFk0cjVq?= =?utf-8?B?V1BBWEg1NjdYNFRHa3VFRk1XeWgyZk5YaUVVOUZxMU5XU241RTNBNj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xWnFQVy9DM2li?= =?utf-8?B?cjI4UmNpb0U1dE5XbSttUjhPV3FSWVMyRW8wZUhyNnJIQjJHMjh5c3ZPbkth?= =?utf-8?B?blZ6cU16Y0xFb3N1QVh0QklkNTFkWTRuWVNlaUxKMkdNY0cvc3RLdz09?= X-MS-Exchange-CrossTenant-Network-Message-Id: deb46995-8ef2-438a-079a-08df41d552f3 X-MS-Exchange-CrossTenant-AuthSource: DS5PPF18A985A10.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2026 22:27:38.7258 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: I07yKZuM8IeBhDfGlbzjMhjId3CaU2BJOm9RE+3WuAFmRz1ITsC4uyju2v9L4YoomGJB7drFFrXQm9YpU6wpSw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8014 X-OriginatorOrg: amd.com On 10/31/26 10:33, Hugo Sales wrote: > amdgpu_dm_handle_vrr_transition() takes a vblank reference when a CRTC > state turns VRR on and drops it when a later state turns it off. It only > looks at freesync_config.state, and disabling a CRTC keeps that state, > so a suspend or DPMS off with VRR active keeps the reference > > On resume, drm_atomic_helper_resume() first calls drm_mode_config_reset(), > which swaps the CRTC state for a zeroed one. The restored state then goes > from VRR_STATE_UNSUPPORTED to active and takes a second reference, and > the first is never dropped. The vblank irq stays on for good, so the CRTC > never idles and PSR is never entered > > A VRR change on a disabled CRTC can't take the reference at all, since > vblank is off there and drm_crtc_vblank_get() fails with a WARN > > On a Cezanne laptop with VRR always on, each suspend added one to the > eDP CRTC's vblank refcount, and it stayed at 1 rather than 0 after VRR > was turned off again > > Treat VRR as active for the reference only while the CRTC is active too. > Disabling the CRTC then drops it and enabling it takes it again, which > balances suspend, resume and DPMS, and the get only happens once > manage_dm_interrupts() has turned vblank on > > Fixes: 66b0c973d7f7 ("drm/amd/display: Prevent vblank irq disable while VRR is active. (v3)") > Signed-off-by: Hugo Sales Reviewed-by: Ivan Lipski > --- > > Tested on an ASUS ROG Flow X13 (GV301QH, Cezanne, DCN 2.1) with VRR > set to always on in Hyprland. bpftrace on drm_handle_vblank showed the eDP > CRTC's vblank refcount go up by one on every suspend before this patch. > With it, the refcount reads the same before and after a systemctl > suspend, and drops to 0 once VRR is turned off > > dm_test_handle_vrr_transition_round_trip now sets base.active on both > states, since an inactive CRTC no longer takes the reference. The > three new cases cover the CRTC turning off and on with VRR left on > > amdgpu_dm KUnit on amd-staging-drm-next (ba496bb83788) passes apart > from dm_mst_test_dsc_link_bpp_between_limits and the two > dm_test_crtc_enable_vblank_ips_restore cases, which fail or panic in > drm_vblank_restore() without this patch as well > > .../display/amdgpu_dm/amdgpu_dm_freesync.c | 12 ++- > .../amdgpu_dm/tests/amdgpu_dm_freesync_test.c | 98 +++++++++++++++++++ > 2 files changed, 108 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c > index 386ba88c57c6a..ee8a11f62a0d3 100644 > --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c > +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_freesync.c > @@ -414,8 +414,16 @@ void amdgpu_dm_handle_vrr_transition(struct amdgpu_display_manager *dm, > struct dm_crtc_state *new_state) > { > struct amdgpu_device *adev = dm->adev; > - bool old_vrr_active = amdgpu_dm_crtc_vrr_active(old_state); > - bool new_vrr_active = amdgpu_dm_crtc_vrr_active(new_state); > + /* > + * A disabled CRTC keeps its freesync state, but drm_crtc_vblank_get() > + * fails there because vblank is off. Hold the reference only while > + * the CRTC is active as well, which also covers resume, where the > + * reset state lost track of the reference taken before suspend > + */ > + bool old_vrr_active = old_state->base.active && > + amdgpu_dm_crtc_vrr_active(old_state); > + bool new_vrr_active = new_state->base.active && > + amdgpu_dm_crtc_vrr_active(new_state); > > /* Only DCE gates vupdate on VRR, keep it enabled for DCN */ > bool vrr_gates_vupdate = amdgpu_ip_version(adev, DCE_HWIP, 0) == 0; > diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c > index 710cdc7f40bf8..3268bdb1043ba 100644 > --- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c > +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_freesync_test.c > @@ -855,8 +855,10 @@ static void dm_test_handle_vrr_transition_round_trip(struct kunit *test) > mutex_init(&adev->dm.dc_lock); > > old_state.base.crtc = &acrtc->base; > + old_state.base.active = true; > old_state.stream = stream; > new_state.base.crtc = &acrtc->base; > + new_state.base.active = true; > new_state.stream = stream; > new_state.freesync_config.state = VRR_STATE_ACTIVE_VARIABLE; > > @@ -867,6 +869,99 @@ static void dm_test_handle_vrr_transition_round_trip(struct kunit *test) > KUNIT_EXPECT_EQ(test, atomic_read(&vblank->refcount), 0); > } > > +/* > + * Runs a transition on a CRTC whose vblank is on with two references held, > + * so a get or put never has to enable or disable it, and returns the > + * refcount afterwards > + */ > +static int dm_test_vrr_transition_refcount(struct kunit *test, > + bool old_active, enum mod_vrr_state old_vrr, > + bool new_active, enum mod_vrr_state new_vrr) > +{ > + struct amdgpu_device *adev = dm_kunit_alloc_adev(test); > + struct amdgpu_display_manager *dm = dm_kunit_alloc_dm(test); > + struct dm_crtc_state *old_state, *new_state; > + struct drm_crtc *crtc; > + int refcount; > + > + KUNIT_ASSERT_EQ(test, drm_vblank_init(&adev->ddev, 1), 0); > + adev->ip_versions[DCE_HWIP][0] = IP_VERSION(2, 1, 0); > + dm->adev = adev; > + mutex_init(&dm->dc_lock); > + > + crtc = kunit_kzalloc(test, sizeof(*crtc), GFP_KERNEL); > + KUNIT_ASSERT_NOT_NULL(test, crtc); > + crtc->dev = &adev->ddev; > + > + old_state = kunit_kzalloc(test, sizeof(*old_state), GFP_KERNEL); > + new_state = kunit_kzalloc(test, sizeof(*new_state), GFP_KERNEL); > + KUNIT_ASSERT_NOT_NULL(test, old_state); > + KUNIT_ASSERT_NOT_NULL(test, new_state); > + old_state->base.crtc = crtc; > + old_state->base.active = old_active; > + old_state->freesync_config.state = old_vrr; > + new_state->base.crtc = crtc; > + new_state->base.active = new_active; > + new_state->freesync_config.state = new_vrr; > + > + adev->ddev.vblank[0].enabled = true; > + atomic_set(&adev->ddev.vblank[0].refcount, 2); > + > + amdgpu_dm_handle_vrr_transition(dm, old_state, new_state); > + refcount = atomic_read(&adev->ddev.vblank[0].refcount); > + > + /* drm_vblank_init_release() warns if vblank is still enabled */ > + adev->ddev.vblank[0].enabled = false; > + atomic_set(&adev->ddev.vblank[0].refcount, 0); > + > + return refcount; > +} > + > +/** > + * dm_test_vrr_transition_crtc_off_drops_ref - Test disabling the CRTC drops the ref > + * @test: The KUnit test context > + * > + * Disabling the CRTC keeps the freesync state, as on suspend or DPMS off. > + * The reference must still be dropped, since resume restores the state from > + * a reset one and takes a new reference > + */ > +static void dm_test_vrr_transition_crtc_off_drops_ref(struct kunit *test) > +{ > + KUNIT_EXPECT_EQ(test, > + dm_test_vrr_transition_refcount(test, true, VRR_STATE_ACTIVE_VARIABLE, > + false, VRR_STATE_ACTIVE_VARIABLE), > + 1); > +} > + > +/** > + * dm_test_vrr_transition_crtc_on_takes_ref - Test enabling the CRTC takes the ref > + * @test: The KUnit test context > + * > + * Covers resume, where the old state is a reset one, and DPMS on > + */ > +static void dm_test_vrr_transition_crtc_on_takes_ref(struct kunit *test) > +{ > + KUNIT_EXPECT_EQ(test, > + dm_test_vrr_transition_refcount(test, false, VRR_STATE_UNSUPPORTED, > + true, VRR_STATE_ACTIVE_VARIABLE), > + 3); > +} > + > +/** > + * dm_test_vrr_transition_crtc_off_keeps_ref - Test no ref change while off > + * @test: The KUnit test context > + * > + * A disabled CRTC has vblank off, so a VRR change there must neither take > + * nor drop a reference > + */ > +static void dm_test_vrr_transition_crtc_off_keeps_ref(struct kunit *test) > +{ > + KUNIT_EXPECT_EQ(test, > + dm_test_vrr_transition_refcount(test, false, VRR_STATE_UNSUPPORTED, > + false, VRR_STATE_ACTIVE_VARIABLE), > + 2); > +} > + > static struct kunit_case amdgpu_dm_freesync_tests[] = { > /* amdgpu_dm_is_timing_unchanged_for_freesync */ > KUNIT_CASE(dm_test_timing_unchanged_null_args), > @@ -910,6 +1005,9 @@ static struct kunit_case amdgpu_dm_freesync_tests[] = { > /* amdgpu_dm_handle_vrr_transition */ > KUNIT_CASE(dm_test_handle_vrr_transition_inactive), > KUNIT_CASE(dm_test_handle_vrr_transition_round_trip), > + KUNIT_CASE(dm_test_vrr_transition_crtc_off_drops_ref), > + KUNIT_CASE(dm_test_vrr_transition_crtc_on_takes_ref), > + KUNIT_CASE(dm_test_vrr_transition_crtc_off_keeps_ref), > {} > }; > -- Thanks, Ivan Lipski