Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp583269rwe; Thu, 1 Sep 2022 04:49:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR499qYqnkvrb3XmvaF+B4dtp0Vq4AsKFr4Tu6RJnt4MxtTbfmPUkHGhYJCesJa3pMYT2pey X-Received: by 2002:a17:90a:7805:b0:1fa:bdab:7d59 with SMTP id w5-20020a17090a780500b001fabdab7d59mr8130174pjk.37.1662032949067; Thu, 01 Sep 2022 04:49:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662032949; cv=none; d=google.com; s=arc-20160816; b=JSaFtvVJxPHmDxN80inV0vaWYqN9WUcDH3+bWyhvfbU2BAoclXnXvCmekBLmaE21Aq ds2b29x5nSU3X8BgemsGxA3FMqDh5VvS1EkR0I0GuYW/UDJLMmoIjPAL/KMv+h0+OYYw TduBP3AYe1DjXGUrNgmEktzuKqvkyiLM+RiFRqbNFsLa+Y2dcliSTFfYm8YjQY1r9lD3 yQnATBuHatOucsho+F4RYaDKc8e5I+v37LXGgNDxn0ocAnCN5uvzdxDO27Xfkbg3g4CR 8zG2qo6+xefY7UhpFqXYsmmFzW7d4MP9Tjd+S9XGvGO3Y2GRKWevPRM/HhglvE1R7Xtq b/3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=JCLE8VMTsa6YU8FmooKXSWW0M8DH/iB7IyFeOEVkzY8=; b=wVEGlwwsVIS7InAEXg6BszFe/hXASlxLH/7DdSxflYIvvYi0+Htide/Z6K58++29rt xixdimRqWfVztQuDI+8TE9dclj0LJ5qtq+ukv/AIY9MvGP0VBTiQksnvauyMId7uC9O5 i9vk/8PqwolztR2+J5rAA3LtIKuk5p283fQ2uVGa45pxTzJ0Q3BQXG5sCxfAFOoc2AV3 m0vpeD7It7WTpDYTqw4ShAE7pp/QohPKN4ar7yfgfOW4aglEcid0YrYJ6qNJyk0CH/Q3 oDKIvc0/HW3gNzZNDq1BGwdCTN1gaJVE2SWOeV/O4Sce1NakW/3ihkKX0zp+jdVJ80nS SGKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="cLbqiE/d"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y9-20020a17090322c900b001755c347071si2063794plg.451.2022.09.01.04.48.57; Thu, 01 Sep 2022 04:49:09 -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=@collabora.com header.s=mail header.b="cLbqiE/d"; 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 S232374AbiIAKpG (ORCPT + 99 others); Thu, 1 Sep 2022 06:45:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233364AbiIAKo7 (ORCPT ); Thu, 1 Sep 2022 06:44:59 -0400 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 225191155; Thu, 1 Sep 2022 03:44:50 -0700 (PDT) Received: from [192.168.2.145] (109-252-119-13.nat.spd-mgts.ru [109.252.119.13]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 7A7B86601E0A; Thu, 1 Sep 2022 11:44:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1662029088; bh=4/2i4aqnQm0eD8QgJbBg2gvDYzIG/ZG1bPLe6WFo/t0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=cLbqiE/dnqUzM66LeoPYWJt2ssxBDaSl7PG8koINMEoIuFiNO/S9FSirvSfstFJ7/ +3XhwZuh6bULact7FUzNWp72rHVbpmo2vfjnT0bf8Qj3J1aisyK0iDijIGVuyPUkDB 689ZWSP7OUdwJ6ZIL39SHAz6ocxJBaJqGoDfR10OvPmQYhlYOeoFfhDQEJIIzPL5bM BWvpDwgsTAnxEDtdvqtdec6MQmmV7eYnMN7pOGy4F132JMmubuV2LOmiSr77PlVDIj IQxQiPZ80EOR+8X3A/Gd+GCivXKpjYEhlMm0HDBHJ+PEbywTNtlYeAJTvojNfYCGzX QegYZmzerNARQ== Message-ID: <213eb3d6-53aa-915e-9565-3209491feeee@collabora.com> Date: Thu, 1 Sep 2022 13:44:43 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH v4 06/21] drm/i915: Prepare to dynamic dma-buf locking specification Content-Language: en-US To: =?UTF-8?Q?Christian_K=c3=b6nig?= , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , =?UTF-8?Q?Thomas_Hellstr=c3=b6m?= , Chris Wilson Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Dmitry Osipenko , linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, kernel@collabora.com, virtualization@lists.linux-foundation.org, linux-rdma@vger.kernel.org, linux-arm-msm@vger.kernel.org, David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gert Wollny , Gustavo Padovan , Daniel Stone , Tomeu Vizoso , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Clark , Sumit Semwal , "Pan, Xinhui" , Thierry Reding , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Alex Deucher , Qiang Yu , Srinivas Kandagatla , Amol Maheshwari , Jason Gunthorpe , Leon Romanovsky , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Tomi Valkeinen , Russell King , Lucas Stach , Christian Gmeiner References: <20220831153757.97381-1-dmitry.osipenko@collabora.com> <20220831153757.97381-7-dmitry.osipenko@collabora.com> <2463ccb0-6620-8760-fc06-532847835207@amd.com> From: Dmitry Osipenko In-Reply-To: <2463ccb0-6620-8760-fc06-532847835207@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 9/1/22 09:45, Christian König wrote: > Am 31.08.22 um 17:37 schrieb Dmitry Osipenko: >> Prepare i915 driver to the common dynamic dma-buf locking convention >> by starting to use the unlocked versions of dma-buf API functions >> and handling cases where importer now holds the reservation lock. >> >> Signed-off-by: Dmitry Osipenko > > Acked-by: Christian König , but it's probably > best if somebody from the Intel guys take a look as well. + Chris Wilson, who touched locks of __i915_gem_free_objects() recently >> --- >>   drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c       |  2 +- >>   drivers/gpu/drm/i915/gem/i915_gem_object.c       | 12 ++++++++++++ >>   .../gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c | 16 ++++++++-------- >>   3 files changed, 21 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c >> b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c >> index f5062d0c6333..07eee1c09aaf 100644 >> --- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c >> +++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c >> @@ -72,7 +72,7 @@ static int i915_gem_dmabuf_vmap(struct dma_buf >> *dma_buf, >>       struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf); >>       void *vaddr; >>   -    vaddr = i915_gem_object_pin_map_unlocked(obj, I915_MAP_WB); >> +    vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB); >>       if (IS_ERR(vaddr)) >>           return PTR_ERR(vaddr); >>   diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.c >> b/drivers/gpu/drm/i915/gem/i915_gem_object.c >> index 389e9f157ca5..7e2a9b02526c 100644 >> --- a/drivers/gpu/drm/i915/gem/i915_gem_object.c >> +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c >> @@ -331,7 +331,19 @@ static void __i915_gem_free_objects(struct >> drm_i915_private *i915, >>               continue; >>           } >>   +        /* >> +         * dma_buf_unmap_attachment() requires reservation to be >> +         * locked. The imported GEM shouldn't share reservation lock, >> +         * so it's safe to take the lock. >> +         */ >> +        if (obj->base.import_attach) >> +            i915_gem_object_lock(obj, NULL); >> + >>           __i915_gem_object_pages_fini(obj); >> + >> +        if (obj->base.import_attach) >> +            i915_gem_object_unlock(obj); >> + >>           __i915_gem_free_object(obj); >>             /* But keep the pointer alive for RCU-protected lookups */ >> diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c >> b/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c >> index 62c61af77a42..9e3ed634aa0e 100644 >> --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c >> +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c >> @@ -213,7 +213,7 @@ static int igt_dmabuf_import_same_driver(struct >> drm_i915_private *i915, >>           goto out_import; >>       } >>   -    st = dma_buf_map_attachment(import_attach, DMA_BIDIRECTIONAL); >> +    st = dma_buf_map_attachment_unlocked(import_attach, >> DMA_BIDIRECTIONAL); >>       if (IS_ERR(st)) { >>           err = PTR_ERR(st); >>           goto out_detach; >> @@ -226,7 +226,7 @@ static int igt_dmabuf_import_same_driver(struct >> drm_i915_private *i915, >>           timeout = -ETIME; >>       } >>       err = timeout > 0 ? 0 : timeout; >> -    dma_buf_unmap_attachment(import_attach, st, DMA_BIDIRECTIONAL); >> +    dma_buf_unmap_attachment_unlocked(import_attach, st, >> DMA_BIDIRECTIONAL); >>   out_detach: >>       dma_buf_detach(dmabuf, import_attach); >>   out_import: >> @@ -296,7 +296,7 @@ static int igt_dmabuf_import(void *arg) >>           goto out_obj; >>       } >>   -    err = dma_buf_vmap(dmabuf, &map); >> +    err = dma_buf_vmap_unlocked(dmabuf, &map); >>       dma_map = err ? NULL : map.vaddr; >>       if (!dma_map) { >>           pr_err("dma_buf_vmap failed\n"); >> @@ -337,7 +337,7 @@ static int igt_dmabuf_import(void *arg) >>         err = 0; >>   out_dma_map: >> -    dma_buf_vunmap(dmabuf, &map); >> +    dma_buf_vunmap_unlocked(dmabuf, &map); >>   out_obj: >>       i915_gem_object_put(obj); >>   out_dmabuf: >> @@ -358,7 +358,7 @@ static int igt_dmabuf_import_ownership(void *arg) >>       if (IS_ERR(dmabuf)) >>           return PTR_ERR(dmabuf); >>   -    err = dma_buf_vmap(dmabuf, &map); >> +    err = dma_buf_vmap_unlocked(dmabuf, &map); >>       ptr = err ? NULL : map.vaddr; >>       if (!ptr) { >>           pr_err("dma_buf_vmap failed\n"); >> @@ -367,7 +367,7 @@ static int igt_dmabuf_import_ownership(void *arg) >>       } >>         memset(ptr, 0xc5, PAGE_SIZE); >> -    dma_buf_vunmap(dmabuf, &map); >> +    dma_buf_vunmap_unlocked(dmabuf, &map); >>         obj = to_intel_bo(i915_gem_prime_import(&i915->drm, dmabuf)); >>       if (IS_ERR(obj)) { >> @@ -418,7 +418,7 @@ static int igt_dmabuf_export_vmap(void *arg) >>       } >>       i915_gem_object_put(obj); >>   -    err = dma_buf_vmap(dmabuf, &map); >> +    err = dma_buf_vmap_unlocked(dmabuf, &map); >>       ptr = err ? NULL : map.vaddr; >>       if (!ptr) { >>           pr_err("dma_buf_vmap failed\n"); >> @@ -435,7 +435,7 @@ static int igt_dmabuf_export_vmap(void *arg) >>       memset(ptr, 0xc5, dmabuf->size); >>         err = 0; >> -    dma_buf_vunmap(dmabuf, &map); >> +    dma_buf_vunmap_unlocked(dmabuf, &map); >>   out: >>       dma_buf_put(dmabuf); >>       return err; > -- Best regards, Dmitry