From patchwork Fri Jul 15 11:15:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12919017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4C44AC43334 for ; Fri, 15 Jul 2022 11:15:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F14AA12BF1D; Fri, 15 Jul 2022 11:15:38 +0000 (UTC) Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2DE6212BC28 for ; Fri, 15 Jul 2022 11:15:37 +0000 (UTC) Received: by mail-ej1-x633.google.com with SMTP id b11so8375802eju.10 for ; Fri, 15 Jul 2022 04:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MTLW9RlauZeKFDhXdi4NVzD2CUoBAKyaVfHA2bXsyzc=; b=cZzKwY+0ZdUuIruChrb8kdL6jBhxAJ4f/t6kQsUtfwJ2Ftwt55nqQeWtLRq/1/EqOd IEe0X0KFs0/RJKm7lds3bLi4V8YxryErPO2WieFPdCOUpdcKukib2XrjRD2Lr0NlYnFd PEUZJoSm6mfgsUw7aerd3Rnc2VOpd80bFQPj391hM8cGFuCRNS2B4xrjz+WE0Ciz0HMa DUy8l2mrTiXvqPGw8lXlV+hmdYxwnayirZNXv06SJ4MRvqWrR2OIW2RjpI8ijQmt7EkX ZylTiZ9WRdR5GfIqPbzhLFom/Abi1xk/e8kKtElUqUdopwjpMp76SEHRUtqpTeCZXZiQ GtqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MTLW9RlauZeKFDhXdi4NVzD2CUoBAKyaVfHA2bXsyzc=; b=V4WtxAyJwCE072pnESZA2rqpxzM5VQtHLGusqbwfvLMzZQM4hom827NfgUmx1+j5N2 pVqqzzcbPCksXhqGm+AYM4dfylE77ZhOmnOxaFQejmbKm3JVabIsz1YgwCR5iIeNqY3c a7ZBaA3Kchibja4pwWKzHARMWva0gQ89LbIgz+muabpInHhveFVZu7LK3bJNmpEQ1Qqb iw4lc6t5K1H4GK6tjSVIgEw+l+D1DgmWUQl4aWVQQ+MfpTlr5KokzD0jhq4NWKGr7/Y9 FsadvHsMQxqiMD259bwMjEU0IqFXBo4+nvSD6VO6lkKxy2gepyk+kmnsK2an4191D+89 2g9w== X-Gm-Message-State: AJIora9mAJHGWsgJkB5EI0pM7Bha2Lq7hUATNs3Hji11tIrMts5Ptvha x13qYCgxmVngfCiWZE6brHk= X-Google-Smtp-Source: AGRyM1sXRMBMo7CEcLdnL2/swmUdEsYDQErwuViUUaTNFULXYGvVIsnYfFGGd8Gq79nQOEH3mLwtKg== X-Received: by 2002:a17:907:a063:b0:72b:52f7:feea with SMTP id ia3-20020a170907a06300b0072b52f7feeamr13272643ejc.740.1657883735720; Fri, 15 Jul 2022 04:15:35 -0700 (PDT) Received: from able.fritz.box (p57b0bd9f.dip0.t-ipconnect.de. [87.176.189.159]) by smtp.gmail.com with ESMTPSA id s5-20020a1709066c8500b0071c6dc728b2sm1913543ejr.86.2022.07.15.04.15.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 04:15:35 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: tzimmermann@suse.de, dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm/ttm: fix locking in vmap/vunmap TTM GEM helpers Date: Fri, 15 Jul 2022 13:15:32 +0200 Message-Id: <20220715111533.467012-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Christian_K=C3=B6nig?= , dmitry.osipenko@collabora.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" I've stumbled over this while reviewing patches for DMA-buf and it looks like we completely messed the locking up here. In general most TTM function should only be called while holding the appropriate BO resv lock. Without this we could break the internal buffer object state here. Only compile tested! Signed-off-by: Christian König Fixes: 43676605f890 drm/ttm: Add vmap/vunmap to TTM and TTM GEM helpers Reviewed-by: Dmitry Osipenko --- drivers/gpu/drm/drm_gem_ttm_helper.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_gem_ttm_helper.c b/drivers/gpu/drm/drm_gem_ttm_helper.c index d5962a34c01d..e5fc875990c4 100644 --- a/drivers/gpu/drm/drm_gem_ttm_helper.c +++ b/drivers/gpu/drm/drm_gem_ttm_helper.c @@ -64,8 +64,13 @@ int drm_gem_ttm_vmap(struct drm_gem_object *gem, struct iosys_map *map) { struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gem); + int ret; + + dma_resv_lock(gem->resv, NULL); + ret = ttm_bo_vmap(bo, map); + dma_resv_unlock(gem->resv); - return ttm_bo_vmap(bo, map); + return ret; } EXPORT_SYMBOL(drm_gem_ttm_vmap); @@ -82,7 +87,9 @@ void drm_gem_ttm_vunmap(struct drm_gem_object *gem, { struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gem); + dma_resv_lock(gem->resv, NULL); ttm_bo_vunmap(bo, map); + dma_resv_unlock(gem->resv); } EXPORT_SYMBOL(drm_gem_ttm_vunmap); From patchwork Fri Jul 15 11:15:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12919018 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2EE86C433EF for ; Fri, 15 Jul 2022 11:15:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B2F5D14BBB2; Fri, 15 Jul 2022 11:15:45 +0000 (UTC) Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3F04E12BDFA for ; Fri, 15 Jul 2022 11:15:38 +0000 (UTC) Received: by mail-ed1-x534.google.com with SMTP id x91so5878939ede.1 for ; Fri, 15 Jul 2022 04:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hPsgPQujV5ih53XaLx+/Pzm3BQPgFoU/IJrYZRUs+24=; b=fpcAROxAr2fFPQsOMH7WoZWgRJCCFjWXZ0mHQG93ttjlxu7fA4Pcth2sGImAdpqIN6 Z87VN5wkBePKDROI5K6TQDxXynXb39UBWAjaA6qEU8GBQLdWEFk3Pu5iLj9z1SaIZQcV XNmdeq//1RbnjiMfvxGEsBEPbWuiHu60XYQqoGuIyYUXiKOPCVmYIwnyduhkdSP8/9DQ EmQrjPhHMir2+iKHQJwwjw9bcu1Cnpg8OF4CDkxZhn2mOIFo/hxnpdBGUHH0arD0zrbk yO5SCmsw/83Tr22S3mUNTNA5EYMZ3WqboABSZDAjsazpL6c3Dl3/aCw2f97f5wMHXzni Vpjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hPsgPQujV5ih53XaLx+/Pzm3BQPgFoU/IJrYZRUs+24=; b=i4a6ZRSCQ79FoJ+C+OiB/BvqPjwOVg+Iew4o+gHw1gsRLC00gS2whA623MYAoP6huj n6Y9JCgXvZ+JZJ+J0hPc4fOT0pQMK1swTXt17RaAEn72o+zufgPpViEOVk6oN0adm29B wA83iSjCtebRHoiS1yoPKk9Vyeg0DTUXCucel0YTema4Qerayne3b2eREtNgq0xMv7Fz sRZYSWabCIjZamM0PZQBz2PkiRZNf7BuFVHGVTyLvpfXSq98ioclqNIx5gsFpxqpya7e UFDMd7MYQhSmlm+QD2Z15DvDChzMV5mywCa136CfjcpW33u2vM43nLZ3gRCLMv+iQTHP 8X4A== X-Gm-Message-State: AJIora+20qLcExGRI+mRl2rtaQYbYCi5WYflWdfG1dkkMTXeVvqphReo JJk/T72MHX0pVcnKj6GtRu0= X-Google-Smtp-Source: AGRyM1tMakO+ZqqOlTHKSt5nYf6RCihmquy+97cDJWNUg5ME2FbSRbqMEba62M2cSwwoYbcLZwlwQA== X-Received: by 2002:a05:6402:378f:b0:43a:d3f5:79f2 with SMTP id et15-20020a056402378f00b0043ad3f579f2mr18625615edb.338.1657883736606; Fri, 15 Jul 2022 04:15:36 -0700 (PDT) Received: from able.fritz.box (p57b0bd9f.dip0.t-ipconnect.de. [87.176.189.159]) by smtp.gmail.com with ESMTPSA id s5-20020a1709066c8500b0071c6dc728b2sm1913543ejr.86.2022.07.15.04.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 04:15:36 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: tzimmermann@suse.de, dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] drm/ttm: add dma_resv_assert_held() calls to vmap/vunmap Date: Fri, 15 Jul 2022 13:15:33 +0200 Message-Id: <20220715111533.467012-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220715111533.467012-1-christian.koenig@amd.com> References: <20220715111533.467012-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Christian_K=C3=B6nig?= , dmitry.osipenko@collabora.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Let's make sure nobody is calling those functions without holding the appropriate locks. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo_util.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index 1530982338e9..497ee1fdbad7 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -402,6 +402,8 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map) struct ttm_resource *mem = bo->resource; int ret; + dma_resv_assert_held(bo->base.resv); + ret = ttm_mem_io_reserve(bo->bdev, mem); if (ret) return ret; @@ -460,6 +462,8 @@ void ttm_bo_vunmap(struct ttm_buffer_object *bo, struct iosys_map *map) { struct ttm_resource *mem = bo->resource; + dma_resv_assert_held(bo->base.resv); + if (iosys_map_is_null(map)) return;