From patchwork Sun Nov 13 23:38:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 19481 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1876642wru; Sun, 13 Nov 2022 15:47:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf45frJmB7vZ8XlC9kTqzl+gLXwR0fZQoLqALLjiCIt1wKaqQzjrLRbnUSe/xUgqVsRXvll/ X-Received: by 2002:a17:906:af15:b0:78d:432b:ab1c with SMTP id lx21-20020a170906af1500b0078d432bab1cmr8903246ejb.427.1668383248313; Sun, 13 Nov 2022 15:47:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668383248; cv=none; d=google.com; s=arc-20160816; b=GkPf4AsdbwkI6cc2O9HwEMAccgzBnrvwhJYlbnq3SqBm+rju/7wu16mXRpf0K5G/lV DHCgCD7YoBKdniYTLGwJckqDHKZOhiyJ1uRNf4IeMpC9c3ZW8XtEMgu4h10R7D8u6iID X5KeCFcRBMX85ATddEMLqVoFax0CM59uCRVGtEzES2F9lA8Z7OY60GWxnjkn8ijgGQxQ DgkPbok13j+Bn2K8uh59uAZUsqx1ko8nyn1aN7DSVHIyrrvpz5V2Gj2VhqpACKHzx5nz pkS2CmMLejXmnIkxWMzchM9q6008PiZsiukJ9JcvDci0rSfPR33FcFUzTLrFu/e0bFOU 6xKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=qxZwtqgjDK5P1NcMYmlJU4fAeWpcVC9fZZoYg+MFNtg=; b=w7rqOlU8ScBTCP8FsDim3cYRr8d/VQdahgg6jJ1mJFieVrlnqIS43Dj4pTUNyO/b+K bDslnbCqN4KKuJ/5IU/4TR3oZ8yC1v12UueL17Q5Zew2Cs/1+FOy3mYFb49RSxhmRm7q /Q0tNaTcAdMibBp1GCsm28S2wy+XQq4R4923zqegIXttQvYmU5TRz0k2mzzxBpO0Vg1q 6ZjaqUuJVY1RcsNFBrKXfkyaB436eomalfJ4nGaJfJq77nVp02x6JjJHHtx2qigHNSKL sgmTU/uuKWOnuduAaUqUcKGRJOuNb3Y04nISwnQj4HbMrFfs/q6n6G3X9nPY4M8mHNm4 1TAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="b0cGLCM/"; 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=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d21-20020a50f695000000b00461727807a4si7738053edn.534.2022.11.13.15.47.03; Sun, 13 Nov 2022 15:47:28 -0800 (PST) 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=@collabora.com header.s=mail header.b="b0cGLCM/"; 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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235318AbiKMXlU (ORCPT + 99 others); Sun, 13 Nov 2022 18:41:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231252AbiKMXlS (ORCPT ); Sun, 13 Nov 2022 18:41:18 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04D4BD73 for ; Sun, 13 Nov 2022 15:41:18 -0800 (PST) Received: from dimapc.. (109-252-117-140.nat.spd-mgts.ru [109.252.117.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 5E29B6601DEB; Sun, 13 Nov 2022 23:41:15 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668382876; bh=gJizz7c+xyP2SpxmajSfdslozS7FNzwEJ2RHchPiu4I=; h=From:To:Cc:Subject:Date:From; b=b0cGLCM/etNSALXIWkniC99MFuBqjrhpw0/Ygks//v57zIgQO2PL5X9lHDEEqDXcf BtOII3ZZ2krf0YYC7rAKPHX+dHFLx4a0IWAAFujI84AKLplXsz3p+58kqwn7rU8bWR +kJV8K3jL2Aou8/55Tp5EY9YcgLAAda0GMpo3/uRAfvb7rGz2CJync8tNnWj38BcjO eyEaUTq7uR1UwreMHvSn3ALNOC1JsQf13dqmBjpnwCHQ8PugIVXYRsYbf9xCAfkr2m On8mKhjZIDo/l8IOiwuVVVR1RJOjO4NhrCNJURyYEywppctnkHPkIwFlg/5HQVUDyG /yikoMtDKK9vA== From: Dmitry Osipenko To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , =?utf-8?q?Christian_K=C3=B6nig?= , David Airlie , Daniel Vetter , Dmitry Vyukov Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] drm/gem-vram: Fix deadlock in drm_gem_vram_vmap() Date: Mon, 14 Nov 2022 02:38:50 +0300 Message-Id: <20221113233850.427704-1-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749426632885214010?= X-GMAIL-MSGID: =?utf-8?q?1749426632885214010?= Recently DRM framebuffer core and all drivers were moved to unlocked vmapping functions that take the reservation lock. The drm_gem_vram_vmap() was missed out by accident and now deadlocks drivers that use drm_gem_vram helpers when framebuffer is updated, like Bochs driver. Remove the locking from drm_gem_vram_v[un]map() functions to fix the deadlock. Reported-by: Dmitry Vyukov Fixes: 79e2cf2e7a19 ("drm/gem: Take reservation lock for vmap/vunmap operations") Signed-off-by: Dmitry Osipenko Reviewed-by: Christian König bo, true, false, NULL); - if (ret) - return ret; + dma_resv_assert_held(gbo->bo.base.resv); ret = drm_gem_vram_pin_locked(gbo, 0); if (ret) - goto err_ttm_bo_unreserve; + return ret; ret = drm_gem_vram_kmap_locked(gbo, map); if (ret) goto err_drm_gem_vram_unpin_locked; - ttm_bo_unreserve(&gbo->bo); - return 0; err_drm_gem_vram_unpin_locked: drm_gem_vram_unpin_locked(gbo); -err_ttm_bo_unreserve: - ttm_bo_unreserve(&gbo->bo); return ret; } EXPORT_SYMBOL(drm_gem_vram_vmap); @@ -467,16 +461,10 @@ EXPORT_SYMBOL(drm_gem_vram_vmap); void drm_gem_vram_vunmap(struct drm_gem_vram_object *gbo, struct iosys_map *map) { - int ret; - - ret = ttm_bo_reserve(&gbo->bo, false, false, NULL); - if (WARN_ONCE(ret, "ttm_bo_reserve_failed(): ret=%d\n", ret)) - return; + dma_resv_assert_held(gbo->bo.base.resv); drm_gem_vram_kunmap_locked(gbo, map); drm_gem_vram_unpin_locked(gbo); - - ttm_bo_unreserve(&gbo->bo); } EXPORT_SYMBOL(drm_gem_vram_vunmap);