Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp5689894rwb; Tue, 9 Aug 2022 02:22:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR4VfFevFGoRnoaQg79MQvrhREm4jK7+bQOUgL8K6CshkM64WR5bdJI11T8fKuLLcP1KkYa/ X-Received: by 2002:a17:907:75e7:b0:730:bc2f:b26a with SMTP id jz7-20020a17090775e700b00730bc2fb26amr16048874ejc.738.1660036935992; Tue, 09 Aug 2022 02:22:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660036935; cv=none; d=google.com; s=arc-20160816; b=k3Whc9wyAl9JV5NWFGWM8TzHa1KPVBr4H28YXIUCYNxBmoZ2HkXYyWE1kBb75rEnfd 4E1LxNwIxyA9WgAFUx0P2JnglfwYqesI5JWXce26pcRC88HFkNIs43MLXfo05LbIkzvG mf/D7LqA2Jag0ZHRkf5ZLKUB+h8w5fFE8TByqcuBvA5sGgyoLKz0F2YuS9ZdCo9Kqd3y SkA2jxNI7AfX5gCkMrkHFd61dAXg3EHsMXLre6SgWWmuTcvi5gdJgrwxRHarUYVRj0Yc KZLHQkS3E1IX7xfR+fbMEJd7tv2qx+MB+lhXTjShLnv9V+TXU8TRwFpj8+n5EUZb0xyN tsXA== 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:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=/mBZEyfbsLHVdSLalS9CVrX3VcZkEHpxib5JJuFRu/w=; b=hvdeMopkvhRoLeC6klzdiCVCwQBtB1pt1M59Z7MIRDyLp27sxlV6cnfcE0HY8ZcaAt HIX+bJUNOo8oPY6fL9BP9uY2KO5E8bBc+wEVvvqorozPrxGngE/sAGchuWov2dh29uyx hhLlAweW1bOQVT1GZor5LolQI1lSwuw9MFl8Bq5XYOirBRaRLnV6/VDc5fBnzLHQYs7F 57pqbdW4r8QuR8chEMGtcJzOjBeG8dC0qrlhisiFcJjPftA448iHzG8jzq45p0VGJA/e vykJC3B6WBIRrHRoPptdJQeQjqRIqHbmXABfpRw4Nzi34ui3t0hFvcdnvRNZwnZHifyq g7/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=LgoTbOY9; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o2-20020a170906768200b0072b9b9820afsi1334256ejm.845.2022.08.09.02.21.49; Tue, 09 Aug 2022 02:22:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=LgoTbOY9; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237405AbiHIJTg (ORCPT + 99 others); Tue, 9 Aug 2022 05:19:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234639AbiHIJTe (ORCPT ); Tue, 9 Aug 2022 05:19:34 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4233183B9 for ; Tue, 9 Aug 2022 02:19:32 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7B7831FACB; Tue, 9 Aug 2022 09:19:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1660036771; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/mBZEyfbsLHVdSLalS9CVrX3VcZkEHpxib5JJuFRu/w=; b=LgoTbOY9iI+nhnC/DaSWC3W5FcZe3khDnwWxd+j38pUja50iDxBQLAyd2CAgtlKmifS/LM v1oWvrKCKMW/gEwhuzV7ETomyF7GgfzKz5H+YxYPMpfK8TnKt/yJX0S9QJDcvC/i/vMHsu DqeCIqA8U9+TvEB+Ig6JArqLa2B60e0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1660036771; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/mBZEyfbsLHVdSLalS9CVrX3VcZkEHpxib5JJuFRu/w=; b=o+Z+lYDassBQY3ZtIsm6eco0FppVzE+WMwzn+KJ1b9QSLugOqdaJ70xRJ7BnXdwEnWTYsI a7s6HOx375dJEfDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 52A8813A9D; Tue, 9 Aug 2022 09:19:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yOBqE6Mm8mKjMgAAMHmgww (envelope-from ); Tue, 09 Aug 2022 09:19:31 +0000 Date: Tue, 09 Aug 2022 11:19:30 +0200 Message-ID: <875yj1wz8d.wl-tiwai@suse.de> From: Takashi Iwai To: Thomas Zimmermann Cc: Takashi Iwai , Dave Airlie , Sean Paul , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: Re: [PATCH 3/4] drm/udl: Kill pending URBs at suspend and disconnect In-Reply-To: <32d98960-a952-b3ab-c3fb-0d615626a3d1@suse.de> References: <20220804075826.27036-1-tiwai@suse.de> <20220804075826.27036-4-tiwai@suse.de> <87h72lx4yw.wl-tiwai@suse.de> <2a307221-62a8-a5f8-354f-d92e90f74f04@suse.de> <87a68dwzzi.wl-tiwai@suse.de> <32d98960-a952-b3ab-c3fb-0d615626a3d1@suse.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 On Tue, 09 Aug 2022 11:13:46 +0200, Thomas Zimmermann wrote: > > Hi > > Am 09.08.22 um 11:03 schrieb Takashi Iwai: > > On Tue, 09 Aug 2022 09:41:19 +0200, > > Thomas Zimmermann wrote: > >> > >> Hi > >> > >> Am 09.08.22 um 09:15 schrieb Takashi Iwai: > >>> On Tue, 09 Aug 2022 09:13:16 +0200, > >>> Thomas Zimmermann wrote: > >>>> > >>>> Hi > >>>> > >>>> Am 04.08.22 um 09:58 schrieb Takashi Iwai: > >>>>> At both suspend and disconnect, we should rather cancel the pending > >>>>> URBs immediately. For the suspend case, the display will be turned > >>>>> off, so it makes no sense to process the rendering. And for the > >>>>> disconnect case, the device may be no longer accessible, hence we > >>>>> shouldn't do any submission. > >>>>> > >>>>> Tested-by: Thomas Zimmermann > >>>>> Signed-off-by: Takashi Iwai > >>>>> --- > >>>>> drivers/gpu/drm/udl/udl_drv.h | 2 ++ > >>>>> drivers/gpu/drm/udl/udl_main.c | 25 ++++++++++++++++++++++--- > >>>>> drivers/gpu/drm/udl/udl_modeset.c | 2 ++ > >>>>> 3 files changed, 26 insertions(+), 3 deletions(-) > >>>>> > >>>>> diff --git a/drivers/gpu/drm/udl/udl_drv.h b/drivers/gpu/drm/udl/udl_drv.h > >>>>> index f01e50c5b7b7..28aaf75d71cf 100644 > >>>>> --- a/drivers/gpu/drm/udl/udl_drv.h > >>>>> +++ b/drivers/gpu/drm/udl/udl_drv.h > >>>>> @@ -39,6 +39,7 @@ struct urb_node { > >>>>> struct urb_list { > >>>>> struct list_head list; > >>>>> + struct list_head in_flight; > >>>>> spinlock_t lock; > >>>>> wait_queue_head_t sleep; > >>>>> int available; > >>>>> @@ -84,6 +85,7 @@ static inline struct urb *udl_get_urb(struct drm_device *dev) > >>>>> int udl_submit_urb(struct drm_device *dev, struct urb *urb, > >>>>> size_t len); > >>>>> int udl_sync_pending_urbs(struct drm_device *dev); > >>>>> +void udl_kill_pending_urbs(struct drm_device *dev); > >>>>> void udl_urb_completion(struct urb *urb); > >>>>> int udl_init(struct udl_device *udl); > >>>>> diff --git a/drivers/gpu/drm/udl/udl_main.c b/drivers/gpu/drm/udl/udl_main.c > >>>>> index 93615648414b..47204b7eb10e 100644 > >>>>> --- a/drivers/gpu/drm/udl/udl_main.c > >>>>> +++ b/drivers/gpu/drm/udl/udl_main.c > >>>>> @@ -135,7 +135,7 @@ void udl_urb_completion(struct urb *urb) > >>>>> urb->transfer_buffer_length = udl->urbs.size; /* reset to actual */ > >>>>> spin_lock_irqsave(&udl->urbs.lock, flags); > >>>>> - list_add_tail(&unode->entry, &udl->urbs.list); > >>>>> + list_move(&unode->entry, &udl->urbs.list); > >>>>> udl->urbs.available++; > >>>>> spin_unlock_irqrestore(&udl->urbs.lock, flags); > >>>>> @@ -180,6 +180,7 @@ static int udl_alloc_urb_list(struct > >>>>> drm_device *dev, int count, size_t size) > >>>>> retry: > >>>>> udl->urbs.size = size; > >>>>> INIT_LIST_HEAD(&udl->urbs.list); > >>>>> + INIT_LIST_HEAD(&udl->urbs.in_flight); > >>>>> init_waitqueue_head(&udl->urbs.sleep); > >>>>> udl->urbs.count = 0; > >>>>> @@ -246,7 +247,7 @@ struct urb *udl_get_urb_timeout(struct drm_device *dev, long timeout) > >>>>> } > >>>>> unode = list_first_entry(&udl->urbs.list, struct urb_node, > >>>>> entry); > >>>>> - list_del_init(&unode->entry); > >>>>> + list_move(&unode->entry, &udl->urbs.in_flight); > >>>>> udl->urbs.available--; > >>>>> unlock: > >>>>> @@ -279,7 +280,7 @@ int udl_sync_pending_urbs(struct drm_device *dev) > >>>>> spin_lock_irq(&udl->urbs.lock); > >>>>> /* 2 seconds as a sane timeout */ > >>>>> if (!wait_event_lock_irq_timeout(udl->urbs.sleep, > >>>>> - udl->urbs.available == udl->urbs.count, > >>>>> + list_empty(&udl->urbs.in_flight), > >>>>> udl->urbs.lock, > >>>>> msecs_to_jiffies(2000))) > >>>>> ret = -ETIMEDOUT; > >>>>> @@ -287,6 +288,23 @@ int udl_sync_pending_urbs(struct drm_device *dev) > >>>>> return ret; > >>>>> } > >>>>> +/* kill pending URBs */ > >>>>> +void udl_kill_pending_urbs(struct drm_device *dev) > >>>>> +{ > >>>>> + struct udl_device *udl = to_udl(dev); > >>>>> + struct urb_node *unode; > >>>>> + > >>>>> + spin_lock_irq(&udl->urbs.lock); > >>>>> + while (!list_empty(&udl->urbs.in_flight)) { > >>>>> + unode = list_first_entry(&udl->urbs.in_flight, > >>>>> + struct urb_node, entry); > >>>>> + spin_unlock_irq(&udl->urbs.lock); > >>>>> + usb_kill_urb(unode->urb); > >>>>> + spin_lock_irq(&udl->urbs.lock); > >>>>> + } > >>>>> + spin_unlock_irq(&udl->urbs.lock); > >>>>> +} > >>>>> + > >>>>> int udl_init(struct udl_device *udl) > >>>>> { > >>>>> struct drm_device *dev = &udl->drm; > >>>>> @@ -335,6 +353,7 @@ int udl_drop_usb(struct drm_device *dev) > >>>>> { > >>>>> struct udl_device *udl = to_udl(dev); > >>>>> + udl_kill_pending_urbs(dev); > >>>>> udl_free_urb_list(dev); > >>>>> put_device(udl->dmadev); > >>>>> udl->dmadev = NULL; > >>>>> diff --git a/drivers/gpu/drm/udl/udl_modeset.c b/drivers/gpu/drm/udl/udl_modeset.c > >>>>> index 50025606b6ad..169110d8fc2e 100644 > >>>>> --- a/drivers/gpu/drm/udl/udl_modeset.c > >>>>> +++ b/drivers/gpu/drm/udl/udl_modeset.c > >>>>> @@ -397,6 +397,8 @@ udl_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) > >>>>> struct urb *urb; > >>>>> char *buf; > >>>>> + udl_kill_pending_urbs(dev); > >>>>> + > >>>> > >>>> I already reviewed the patchset, but I have another comment. I think > >>>> we should only kill urbs from within the suspend handler. Same for the > >>>> call to the URB-sync function in patch 2. > >>>> > >>>> This disable function is part of the regular modeset path. It's > >>>> probably not appropriate to outright remove pending URBs here. This > >>>> can lead to failed modesets, which would have succeeded otherwise. > >>> > >>> Well, the device shall be turned off right after that point, so the > >>> all pending rendering makes little sense, no? > >> > >> udl_simple_display_pipe_disable() only disables the display, but not > >> the device. The kill operation here could potentially kill some valid > >> modeset operation that was still going on. And who knows what the > >> device state is after that. > > > > But udl_simple_display_pipe_disable() invokes UDL_BLANK_MODE_POWERDOWN > > command right after the place I've put udl_kill_pending_urbs(). So it > > shall blank / turn off the power (of the device, as it has a single > > output). And the URB completion doesn't do any error handling but > > just re-links URB chain and wakes up the queue. So killing a pending > > URB would nothing but canceling the in-flight URBs, and there should > > be no disturbance to the modeset operation itself, as the screen will > > be blanked immediately. > > The blank mode is essentially DPMS. It's unrelated to the device's > display mode. The function invokes the UDL_BLANK_MODE_POWERDOWN command; that will discard the whole rendered picture. And, the counterpart, udl_simple_display_pipe_enable(), re-initializes the mode fully from the scratch again. So what's the point to continue rendering that is immediately cleared (from the screen and from the device state)? Killing pending URBs doesn't influence on the internal (modeset) state of the driver. Takashi