Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp585933pxb; Tue, 15 Feb 2022 22:57:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnTe53Bn71VxR8OBIITfjQeJEocMeGC7EMdbmyMFIugyOic1U8GIaF6vhZXDYXVt2HsLxy X-Received: by 2002:a05:6a00:13a4:b0:4ce:118f:a822 with SMTP id t36-20020a056a0013a400b004ce118fa822mr1815367pfg.33.1644994656570; Tue, 15 Feb 2022 22:57:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644994656; cv=none; d=google.com; s=arc-20160816; b=jfH4WzgsfDuASNuF4Zf06puFV52uPMphacYrqEFaBHTQl7vy+X0L0xUUD6uN7/iZ3P e+9jbF4afousCyOBPhxs4T5g+kyNmp4RP8eF9kOncaPYhGNTS3nepcPR1P2PmeLP+wXe pHTn169b3k7oqH7qrh9lCkKGW4W5UWLFHLkDD1jWkDHynlyLhVB9tBHBXuSKEcPFTmEk JSRGxQf9f4fjjFMLMM+N9eXfIVpx9uh8Oq6+LU70iXY8arw2Kl3Pl1zza0J0IgHyMxaz 3k6aXKqs2UvEaVwYg1PfaqykU6XkGqezbhwQOROKS16IypRS1MxZTjZTebD8SmekiwO1 qX6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:subject:cc:to :from:date:dkim-signature; bh=5xiy4gjlnWsBiQJMqEm1TTJriU9KvCPe8neiGLCZ+9Q=; b=hirN+JdzZfvqCXzYSONWKn34AxNJGKO70avEHUB2pRHsX+GfFkBAwVjtMOBhP3vMgF GAk1LTtR6l6Y/U5M/AqVkEJeWTjI3cJLHOnAZ65D783hz8sI+Q7FHqbO4SR25cX1Izky +njGC/qEo4ZBEUXGyF5+8k64gKM/pAjsFCjI8KPaxaHlLjYs69PSpMm6oaxsn5ZbUIx1 O9KmfHRnz9k6fhpmTFEfzuTshTLDJXtPVOadCp3PXKPMc6s7EbOnrHGejDMNIT4/ythy xF4lW3BlrpfntDGCTV6OVKsMIyBa7MQdpvaiMbWM8o8S/BhewesUB80Z+zmzvD5SNFSF XT+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fNOn8vAL; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x66si4912791pgx.114.2022.02.15.22.57.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 22:57:36 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fNOn8vAL; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7F3C922ED6D; Tue, 15 Feb 2022 22:39:45 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233939AbiBOPqp (ORCPT + 99 others); Tue, 15 Feb 2022 10:46:45 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241171AbiBOPqQ (ORCPT ); Tue, 15 Feb 2022 10:46:16 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 905FDF11A4 for ; Tue, 15 Feb 2022 07:43:14 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1E0C8B81AFB for ; Tue, 15 Feb 2022 15:43:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2B52C340EB; Tue, 15 Feb 2022 15:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644939791; bh=SKGn7wND7KsEt36XShzXq7j0Folx5a1fiX2ekqpJ1GI=; h=Date:From:To:cc:Subject:From; b=fNOn8vALJVmXGzrsUX16C3s9cuKmdnX0wryuVtmQkiLH1ftCdRaHdgu22H+w9XMvK 0Mbyn1H9RHQQ0r91MwaVV7f30yl+XkCR/FAUufv9VZDr+daiQNlo5m7DmN4x5tvDth 0KEKd0160VQny9iNZkiF4gtaZ/ei6RVSeeZeUPeysacJQI1bptdzIgzCn5USOSJPvJ 8yZz364boDacSkjWahmjLbyTrVQ54ubVtZ/6U/TbAMhniGDX9eZjf2SnYSIjeZXz4o r7qnOGi+WQq8EgHM2cARhgS8g/J7NryPHpYm0G0o4JNoDRbkxMULPi+zzgFXvhihDu 0zBy5sr4uK2YA== Date: Tue, 15 Feb 2022 16:43:08 +0100 (CET) From: Jiri Kosina To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Sebastian Siewior cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm: fb-helper: Avoid nesting spinlock_t into raw_spinlock_t Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Kosina drm_fb_helper_damage() is acquiring spinlock_t (helper->damage_lock), while it can be called from contexts where raw_spinlock_t is held (e.g. console_owner lock obtained on vprintk_emit() codepath). As the critical sections protected by damage_lock are super-tiny, let's fix this by converting it to raw_spinlock_t in order not to violate PREEMPT_RT-imposed lock nesting rules. This fixes the splat below. ============================= [ BUG: Invalid wait context ] 5.17.0-rc4-00002-gd567f5db412e #1 Not tainted ----------------------------- swapper/0/0 is trying to lock: ffff8c5687cc4158 (&helper->damage_lock){....}-{3:3}, at: drm_fb_helper_damage.isra.22+0x4a/0xf0 other info that might help us debug this: context-{2:2} 3 locks held by swapper/0/0: #0: ffffffffad776520 (console_lock){+.+.}-{0:0}, at: vprintk_emit+0xb8/0x2a0 #1: ffffffffad696120 (console_owner){-...}-{0:0}, at: console_unlock+0x17f/0x550 #2: ffffffffad926a58 (printing_lock){....}-{3:3}, at: vt_console_print+0x7d/0x3e0 stack backtrace: CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.17.0-rc4-00002-gd567f5db412e #1 bed1d5e19e0e7e8c9d97fd8afa1322f7f47a4f38 Hardware name: LENOVO 20UJS2B905/20UJS2B905, BIOS R1CET63W(1.32 ) 04/09/2021 Call Trace: dump_stack_lvl+0x58/0x71 __lock_acquire+0x165b/0x1780 ? secondary_startup_64_no_verify+0xd5/0xdb lock_acquire+0x278/0x300 ? drm_fb_helper_damage.isra.22+0x4a/0xf0 ? save_trace+0x3e/0x340 ? __bfs+0x10f/0x240 _raw_spin_lock_irqsave+0x48/0x60 ? drm_fb_helper_damage.isra.22+0x4a/0xf0 drm_fb_helper_damage.isra.22+0x4a/0xf0 soft_cursor+0x194/0x240 bit_cursor+0x386/0x630 ? get_color+0x29/0x120 ? bit_putcs+0x4b0/0x4b0 ? console_unlock+0x17f/0x550 hide_cursor+0x2f/0x90 vt_console_print+0x3c5/0x3e0 ? console_unlock+0x17f/0x550 console_unlock+0x515/0x550 vprintk_emit+0x1c8/0x2a0 _printk+0x52/0x6e ? sched_clock_tick+0x3d/0x60 collect_cpu_info_amd+0x93/0xd0 collect_cpu_info_local+0x23/0x30 flush_smp_call_function_queue+0x137/0x220 __sysvec_call_function_single+0x43/0x1c0 sysvec_call_function_single+0x43/0x80 asm_sysvec_call_function_single+0x12/0x20 RIP: 0010:cpuidle_enter_state+0x111/0x4b0 Code: 7c ff 45 84 ff 74 17 9c 58 0f 1f 44 00 00 f6 c4 02 0f 85 71 03 00 00 31 ff e8 bb 21 86 ff e8 76 2f 8e ff fb 66 0f 1f 44 00 00 <45> 85 f6 0f 88 12 01 00 00 49 63 d6 4c 2b 24 24 48 8d 04 52 48 8d RSP: 0018:ffffffffad603e48 EFLAGS: 00000206 RAX: 00000000000127c3 RBX: 0000000000000003 RCX: 0000000000000000 RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffffac32617a RBP: ffff8c5687ba4400 R08: 0000000000000001 R09: 0000000000000001 R10: ffffffffad603e10 R11: 0000000000000000 R12: 00000000685eb4a0 R13: ffffffffad918f80 R14: 0000000000000003 R15: 0000000000000000 ? cpuidle_enter_state+0x10a/0x4b0 ? cpuidle_enter_state+0x10a/0x4b0 cpuidle_enter+0x29/0x40 do_idle+0x24d/0x2c0 cpu_startup_entry+0x19/0x20 start_kernel+0x9c2/0x9e9 secondary_startup_64_no_verify+0xd5/0xdb Signed-off-by: Jiri Kosina --- drivers/gpu/drm/drm_fb_helper.c | 14 +++++++------- include/drm/drm_fb_helper.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index ed43b987d306..7c4ab6e6f865 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -436,11 +436,11 @@ static void drm_fb_helper_damage_work(struct work_struct *work) unsigned long flags; int ret; - spin_lock_irqsave(&helper->damage_lock, flags); + raw_spin_lock_irqsave(&helper->damage_lock, flags); clip_copy = *clip; clip->x1 = clip->y1 = ~0; clip->x2 = clip->y2 = 0; - spin_unlock_irqrestore(&helper->damage_lock, flags); + raw_spin_unlock_irqrestore(&helper->damage_lock, flags); /* Call damage handlers only if necessary */ if (!(clip_copy.x1 < clip_copy.x2 && clip_copy.y1 < clip_copy.y2)) @@ -465,12 +465,12 @@ static void drm_fb_helper_damage_work(struct work_struct *work) * Restore damage clip rectangle on errors. The next run * of the damage worker will perform the update. */ - spin_lock_irqsave(&helper->damage_lock, flags); + raw_spin_lock_irqsave(&helper->damage_lock, flags); clip->x1 = min_t(u32, clip->x1, clip_copy.x1); clip->y1 = min_t(u32, clip->y1, clip_copy.y1); clip->x2 = max_t(u32, clip->x2, clip_copy.x2); clip->y2 = max_t(u32, clip->y2, clip_copy.y2); - spin_unlock_irqrestore(&helper->damage_lock, flags); + raw_spin_unlock_irqrestore(&helper->damage_lock, flags); } /** @@ -486,7 +486,7 @@ void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper, const struct drm_fb_helper_funcs *funcs) { INIT_LIST_HEAD(&helper->kernel_fb_list); - spin_lock_init(&helper->damage_lock); + raw_spin_lock_init(&helper->damage_lock); INIT_WORK(&helper->resume_work, drm_fb_helper_resume_worker); INIT_WORK(&helper->damage_work, drm_fb_helper_damage_work); helper->damage_clip.x1 = helper->damage_clip.y1 = ~0; @@ -670,12 +670,12 @@ static void drm_fb_helper_damage(struct fb_info *info, u32 x, u32 y, if (!drm_fbdev_use_shadow_fb(helper)) return; - spin_lock_irqsave(&helper->damage_lock, flags); + raw_spin_lock_irqsave(&helper->damage_lock, flags); clip->x1 = min_t(u32, clip->x1, x); clip->y1 = min_t(u32, clip->y1, y); clip->x2 = max_t(u32, clip->x2, x + width); clip->y2 = max_t(u32, clip->y2, y + height); - spin_unlock_irqrestore(&helper->damage_lock, flags); + raw_spin_unlock_irqrestore(&helper->damage_lock, flags); schedule_work(&helper->damage_work); } diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h index 3af4624368d8..91178958896e 100644 --- a/include/drm/drm_fb_helper.h +++ b/include/drm/drm_fb_helper.h @@ -131,7 +131,7 @@ struct drm_fb_helper { struct fb_info *fbdev; u32 pseudo_palette[17]; struct drm_clip_rect damage_clip; - spinlock_t damage_lock; + raw_spinlock_t damage_lock; struct work_struct damage_work; struct work_struct resume_work; -- Jiri Kosina SUSE Labs