From mboxrd@z Thu Jan 1 00:00:00 1970 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 210C1C38145 for ; Fri, 2 Sep 2022 10:38:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8BE5D10E7F3; Fri, 2 Sep 2022 10:38:41 +0000 (UTC) Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by gabe.freedesktop.org (Postfix) with ESMTPS id BA5E510E7F1; Fri, 2 Sep 2022 10:38:34 +0000 (UTC) Received: by mail-lj1-x22c.google.com with SMTP id z20so1827401ljq.3; Fri, 02 Sep 2022 03:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=zb5JB4hN023tPDYi3X8LwwwxfrMO5eJ6HDfLqyKNUp4=; b=b+3QDVeZ8R7VkX5Bf/lQ/zM5cKpssDiy6sioxY3jw9J59uDY2aLPinjOd5/AfzMPSF F25cqjiDBi0zlLf8NewvQzjGLBKLLwe77dGjcGOssNv9QG7GD4v9Y7R5vUVBkwhzJqAt W+NgPvhc+LGHFoczAHcg6Xd3RZE5aY0kB0c6sHOthdo2C6I6KgqGlMNMjWhr5LBa7hEJ PF8PoWJrMQEbxEgzwwdfZOe63pnK6yiDDUckqcBXrJcCgoCnkkMNTICwsyuKzCch5zAF oZnume/cpTmEe8YMT0zAnJRdyZ8FX7N+NEVx+V/5rqxYqoL28d0bRVzC4c7nr4HeYJuG nuzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=zb5JB4hN023tPDYi3X8LwwwxfrMO5eJ6HDfLqyKNUp4=; b=KCTywGyRFnTP/3C6JtyU2tQjbcq4goVqUdosWJwU50+IB4+/HnVTISCE6HE+CiZNs0 PTozkTgvFLATSMMx91utEhkN/tSswHQ/QcglzS8yzc3mmI9VyJVBA3uXgB/xk1AQ3viz 6JH5SpXhgmqVdVVOWMm/vgT9nyvnZahmXj5xPbR48K3qCaQk1RMaELMPRRmrQBLip3yV VspiZGcEbblkrDXOMA5u7MTSSE/N/w8Lc6KwOg6NyO/avtMTbr0C+oHfF34dxXT5yFvF R9dWFlE41N2O7MaYSzg4AJOXY3Ry5kruOVYCmugA4NGWubk9hd13OALS3FFDpui5Hlhb Gesg== X-Gm-Message-State: ACgBeo2BZA7RytIL4km1QxTdlwIU82nbn/vgOZiQwW2AgkrRw2Xfb6YH O4/qR4dnApRaEOAInwKs3iM= X-Google-Smtp-Source: AA6agR40LFWSHSrrETgLqAmkw4fHaA4WAaccG4Nn66YZ/3AUuSYYBeJUuN4jK3ma7gFMPZa8TWb1KQ== X-Received: by 2002:a2e:bf07:0:b0:261:cafb:d4a8 with SMTP id c7-20020a2ebf07000000b00261cafbd4a8mr10289818ljr.268.1662115113077; Fri, 02 Sep 2022 03:38:33 -0700 (PDT) Received: from [192.168.2.145] (109-252-119-13.nat.spd-mgts.ru. [109.252.119.13]) by smtp.googlemail.com with ESMTPSA id 5-20020a2eb945000000b00267232d0652sm147092ljs.46.2022.09.02.03.38.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 02 Sep 2022 03:38:32 -0700 (PDT) Message-ID: Date: Fri, 2 Sep 2022 13:38:30 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Content-Language: en-US From: Dmitry Osipenko To: "Ruhl, Michael J" , Dmitry Osipenko , Jani Nikula , Joonas Lahtinen , "Vivi, Rodrigo" , Tvrtko Ursulin , =?UTF-8?Q?Thomas_Hellstr=c3=b6m?= , =?UTF-8?Q?Christian_K=c3=b6nig?= , Chris Wilson References: <20220831153757.97381-1-dmitry.osipenko@collabora.com> <20220831153757.97381-7-dmitry.osipenko@collabora.com> <760b999f-b15d-102e-8bc7-c3e69f07f43f@gmail.com> In-Reply-To: <760b999f-b15d-102e-8bc7-c3e69f07f43f@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: Re: [Intel-gfx] [PATCH v4 06/21] drm/i915: Prepare to dynamic dma-buf locking specification X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Almeida , "dri-devel@lists.freedesktop.org" , "virtualization@lists.linux-foundation.org" , Srinivas Kandagatla , Gerd Hoffmann , "kernel@collabora.com" , Sumit Semwal , Marek Szyprowski , Mauro Carvalho Chehab , Leon Romanovsky , Jason Gunthorpe , "linux-rdma@vger.kernel.org" , Russell King , Daniel Stone , Gustavo Padovan , Chia-I Wu , "linux-media@vger.kernel.org" , Thomas Zimmermann , "linux-arm-msm@vger.kernel.org" , "intel-gfx@lists.freedesktop.org" , Maxime Ripard , "linaro-mm-sig@lists.linaro.org" , Christian Gmeiner , Stefano Stabellini , Gurchetan Singh , "Gross, Jurgen" , David Airlie , "amd-gfx@lists.freedesktop.org" , Tomi Valkeinen , Tomeu Vizoso , Gert Wollny , "Pan, Xinhui" , "linux-kernel@vger.kernel.org" , Tomasz Figa , Oleksandr Tyshchenko , Qiang Yu , Daniel Vetter , Alex Deucher , Amol Maheshwari , Lucas Stach Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 02.09.2022 13:31, Dmitry Osipenko пишет: > 01.09.2022 17:02, Ruhl, Michael J пишет: > ... >>> --- 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); >> >> There is a lot of stuff going here. Taking the lock may be premature... >> >>> __i915_gem_object_pages_fini(obj); >> >> The i915_gem_dmabuf.c:i915_gem_object_put_pages_dmabuf is where >> unmap_attachment is actually called, would it make more sense to make >> do the locking there? > > The __i915_gem_object_put_pages() is invoked with a held reservation > lock, while freeing object is a special time when we know that GEM is > unused. > > The __i915_gem_free_objects() was taking the lock two weeks ago until > the change made Chris Wilson [1] reached linux-next. > > [1] > https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=2826d447fbd60e6a05e53d5f918bceb8c04e315c > > I don't think we can take the lock within > i915_gem_object_put_pages_dmabuf(), it may/should deadlock other code paths. On the other hand, we can check whether the GEM's refcount number is zero in i915_gem_object_put_pages_dmabuf() and then take the lock if it's zero. Also, seems it should be possible just to bail out from i915_gem_object_put_pages_dmabuf() if refcount=0. The further drm_prime_gem_destroy() will take care of unmapping. Perhaps this could be the best option, I'll give it a test.