Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp4392860ioo; Tue, 31 May 2022 03:30:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBVnkHjavt6F7SdJ5OciiWkZbc9IeoqUUJEb7XPRwShA/ABDnNGWeHfUNIuy3oWl7+azKc X-Received: by 2002:a17:90a:b001:b0:1dd:30b9:1a45 with SMTP id x1-20020a17090ab00100b001dd30b91a45mr28373265pjq.132.1653993056935; Tue, 31 May 2022 03:30:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653993056; cv=none; d=google.com; s=arc-20160816; b=pFdM5xE0ubJ++xOmLbQlQSovxLdbOC4NjQAYSFovQZ4d3xdyi0SFo6cuqdjQEKMi6I OsBX+HSGv46Pij/apJW8I4WFk5l31lm/qQ8ZvroH+MmM9kjzkKOO4fPbsJZnpWEb9C2i CKAILAR3ZYXJKQ/70r+SsRGXWIb3Ys1CGiZt/VE5/00vlrwUjEw3XX2jimB2xNrL/0Sf 98zSiU9Nei1x3JcGjiQVBape0EUMaOazkRgrNhvTWdWCilDBEmA12AWHq6Ffr7tDZvLw 9o4zkmvwfvnwMj+4VkXrBgiwixBhVg7zHA8jn6ZMKYNhzEtFiXQ2TTOkvUilQufXvArV lNLg== 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=PcNNnL7EuUNN5M8KuoHzEzwV9LXlV7OOBZ9lZKOwy6M=; b=uaLssihC7vRqYfOBkoR1qO0uRdvt/E60Nyk5g9BvAlmDregu+xbEGIOEJ4zqladQ+t 4UHUTFG3edfz6z0wY9vcOtXtcNkYNeKMsd7yj10xOBoArOedSbPfFCSYJcSdgWhlM6mS cww6icWXA61W0cemG8c6PZgwL0YOxiSo4MbS9MMQF7fjPO1M6gbhKw7spbOGyMFxvbfL HaNx/xB5Bz4cuBBcE93f66OCbLQb1GSQ52ilhGFiLLY2/sibJPqizKMlwh4+Z2/WHKLL epa2GSMxSMC+NIZLNwYXKEJiXuS6WbOmbDN43xHJAOmt/fWTLC9Rma1qkX9OgSct8eYi WetA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=CZBBpXpJ; 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 om5-20020a17090b3a8500b001cb8bfcc721si2448000pjb.7.2022.05.31.03.30.42; Tue, 31 May 2022 03:30:56 -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=CZBBpXpJ; 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 S237229AbiE3NcR (ORCPT + 99 others); Mon, 30 May 2022 09:32:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237260AbiE3NaQ (ORCPT ); Mon, 30 May 2022 09:30:16 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D520C12A9C; Mon, 30 May 2022 06:26:58 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id B1F391F42E89 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1653917216; bh=y8CpXrtP+c6Qf6iu5Rkh+8kR5t7I7EuM/mXJ3s9H5Zs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=CZBBpXpJJByM/6l1wreC73qyaYOtUyAY912FO23xX9hwne0P8DnGHVfuPN4nMsGCT 8SkJMvb9QBciZR6HQOm2m0Pv+tBSMrQzbTJhWEU/RA9xCdqbSQHUQ/nV0EfPj5Fh0g /Bz633BDtP5oWyr2aY9l9/qknO9qze9TgXSMV4ZjAyn/uZyDn95jjXsxnqKUHAFUYj Xl1HS7BN4ZwJ0JAX6Azh2TmYj2i3WjRR80SU/1ps37ciW04RwtS6XWFaZAru9NCxqG jz7LyKVTcMBV9YNtk3fQE7sBherW3XwtioZyr1RjqcTCj2d+TQiehKVmn3qh2wdHis oxYI+SRObIGUA== Message-ID: Date: Mon, 30 May 2022 16:26:49 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v6 14/22] dma-buf: Introduce new locking convention Content-Language: en-US To: =?UTF-8?Q?Christian_K=c3=b6nig?= , 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 Herring , Steven Price , Alyssa Rosenzweig , Rob Clark , Emil Velikov , Robin Murphy , Qiang Yu , Sumit Semwal , "Pan, Xinhui" , Thierry Reding , Tomasz Figa , Marek Szyprowski , Mauro Carvalho Chehab , Alex Deucher , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Dmitry Osipenko , linux-tegra@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, kernel@collabora.com References: <20220526235040.678984-1-dmitry.osipenko@collabora.com> <20220526235040.678984-15-dmitry.osipenko@collabora.com> <0a02a31d-a256-4ca4-0e35-e2ea1868a8ae@amd.com> From: Dmitry Osipenko In-Reply-To: <0a02a31d-a256-4ca4-0e35-e2ea1868a8ae@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY 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 Hello Christian, On 5/30/22 09:50, Christian König wrote: > Hi Dmitry, > > First of all please separate out this patch from the rest of the series, > since this is a complex separate structural change. I assume all the patches will go via the DRM tree in the end since the rest of the DRM patches in this series depend on this dma-buf change. But I see that separation may ease reviewing of the dma-buf changes, so let's try it. > Am 27.05.22 um 01:50 schrieb Dmitry Osipenko: >> All dma-bufs have dma-reservation lock that allows drivers to perform >> exclusive operations over shared dma-bufs. Today's dma-buf API has >> incomplete locking specification, which creates dead lock situation >> for dma-buf importers and exporters that don't coordinate theirs locks. > > Well please drop that sentence. The locking specifications are actually > very well defined, it's just that some drivers are a bit broken > regarding them. > > What you do here is rather moving all the non-dynamic drivers over to > the dynamic locking specification (which is really nice to have). Indeed, this will be a better description, thank you! I'll update it. > I have tried this before and failed because catching all the locks in > the right code paths are very tricky. So expect some fallout from this > and make sure the kernel test robot and CI systems are clean. Sure, I'll fix up all the reported things in the next iteration. BTW, have you ever posted yours version of the patch? Will be great if we could compare the changed code paths. >> This patch introduces new locking convention for dma-buf users. From now >> on all dma-buf importers are responsible for holding dma-buf reservation >> lock around operations performed over dma-bufs. >> >> This patch implements the new dma-buf locking convention by: >> >>    1. Making dma-buf API functions to take the reservation lock. >> >>    2. Adding new locked variants of the dma-buf API functions for drivers >>       that need to manage imported dma-bufs under the held lock. > > Instead of adding new locked variants please mark all variants which > expect to be called without a lock with an _unlocked postfix. > > This should make it easier to remove those in a follow up patch set and > then fully move the locking into the importer. Do we really want to move all the locks to the importers? Seems the majority of drivers should be happy with the dma-buf helpers handling the locking for them. >>    3. Converting all drivers to the new locking scheme. > > I have strong doubts that you got all of them. At least radeon and > nouveau should grab the reservation lock in their ->attach callbacks > somehow. Radeon and Nouveau use gem_prime_import_sg_table() and they take resv lock already, seems they should be okay (?) I assume all the basics should covered in this v6. At minimum Intel, Tegra, Panfrost, Lima and Rockchip drivers should be good. If I missed something, then please let me know and I'll correct it. >> Signed-off-by: Dmitry Osipenko >> --- >>   drivers/dma-buf/dma-buf.c                     | 270 +++++++++++------- >>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       |   6 +- >>   drivers/gpu/drm/drm_client.c                  |   4 +- >>   drivers/gpu/drm/drm_gem.c                     |  33 +++ >>   drivers/gpu/drm/drm_gem_framebuffer_helper.c  |   6 +- >>   drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c    |  10 +- >>   drivers/gpu/drm/qxl/qxl_object.c              |  17 +- >>   drivers/gpu/drm/qxl/qxl_prime.c               |   4 +- >>   .../common/videobuf2/videobuf2-dma-contig.c   |  11 +- >>   .../media/common/videobuf2/videobuf2-dma-sg.c |  11 +- >>   .../common/videobuf2/videobuf2-vmalloc.c      |  11 +- >>   include/drm/drm_gem.h                         |   3 + >>   include/linux/dma-buf.h                       |  14 +- >>   13 files changed, 241 insertions(+), 159 deletions(-) >> >> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c >> index 32f55640890c..64a9909ccfa2 100644 >> --- a/drivers/dma-buf/dma-buf.c >> +++ b/drivers/dma-buf/dma-buf.c >> @@ -552,7 +552,6 @@ struct dma_buf *dma_buf_export(const struct >> dma_buf_export_info *exp_info) >>       file->f_mode |= FMODE_LSEEK; >>       dmabuf->file = file; >>   -    mutex_init(&dmabuf->lock); > > Please make removing dmabuf->lock a separate change. Alright -- Best regards, Dmitry