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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32D44C433FE for ; Wed, 19 Jan 2022 15:05:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344565AbiASPFh (ORCPT ); Wed, 19 Jan 2022 10:05:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355627AbiASPFX (ORCPT ); Wed, 19 Jan 2022 10:05:23 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1AA3C06161C for ; Wed, 19 Jan 2022 07:05:22 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id az27-20020a05600c601b00b0034d2956eb04so5980293wmb.5 for ; Wed, 19 Jan 2022 07:05:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=0odyDD4qZWEyKf4dgk5bsg3tKYSY9CGvoUStfcevylA=; b=KY4YCZwWueLtUID+/YuRziwAprnxroizrhhiLqgR+VJv0dvAqf6p/e/Z8+2hbD5td3 M1RXz2Ulz5/UO405poQs0LC2mWECerbCYmm6/PclkyYapoYCKVCVsrH7+qHMc7mD7DNG yVv6KCpVaJQuyRwX173l73U/aTdl9LopqeRzs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=0odyDD4qZWEyKf4dgk5bsg3tKYSY9CGvoUStfcevylA=; b=RkuDCglsVjcEBLNjHA7aXH53ijQqWm+awEYUL644VtemHj+Q+oLHPlrJ06gRs6oGp+ tq4fuvnXRXKrBwjUahug8jzholY6cn4BW1pQYWqL/n+YXzE4tOsq/UiOXKO9oeMogzod epVXhiPUpRy8WDd1fpKZFlEUmijEC2ZMcKy45crg80o2R0cDqGCx2igIs+hYHZ6fQkxB N6EXJ2hqZMGJ0TBCoQ1I5MSlCSku0yVhvHfeg/2TKECQr65wkfI3K1crKjom/OPa/BG1 zszhHx1YUv6+hmr1wDXKYiUsxNPGOOd2iRDivtO3tblJKXWJ+5sAcBujbdaqfUJrpuPV rhzQ== X-Gm-Message-State: AOAM530GarK7JJg3p68l+yazTxpa8oAuMIR5dFxroS4E+P9yT0H20qYn lN1XmKdxdx/CZILO1e5JvWiM/A== X-Google-Smtp-Source: ABdhPJxqxOTFLl5T1cf1q2Ex/gbOeL3/4WLRyt3JAUtwMEe4sBmurRyS45VDAxAFnc6SDjv5q4TcRQ== X-Received: by 2002:adf:fec2:: with SMTP id q2mr29547534wrs.546.1642604721320; Wed, 19 Jan 2022 07:05:21 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id g17sm7645503wmq.9.2022.01.19.07.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jan 2022 07:05:20 -0800 (PST) Date: Wed, 19 Jan 2022 16:05:18 +0100 From: Daniel Vetter To: Weizhao Ouyang Cc: Sumit Semwal , Benjamin Gaignard , Liam Mark , Laura Abbott , Brian Starkey , John Stultz , christian.koenig@amd.com, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org Subject: Re: [PATCH] dma-buf: cma_heap: Fix mutex locking section Message-ID: Mail-Followup-To: Weizhao Ouyang , Sumit Semwal , Benjamin Gaignard , Liam Mark , Laura Abbott , Brian Starkey , John Stultz , christian.koenig@amd.com, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org References: <20220104073545.124244-1-o451686892@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220104073545.124244-1-o451686892@gmail.com> X-Operating-System: Linux phenom 5.10.0-8-amd64 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 04, 2022 at 03:35:45PM +0800, Weizhao Ouyang wrote: > Fix cma_heap_buffer mutex locking critical section to protect vmap_cnt > and vaddr. > > Fixes: a5d2d29e24be ("dma-buf: heaps: Move heap-helper logic into the cma_heap implementation") > Signed-off-by: Weizhao Ouyang > --- > drivers/dma-buf/heaps/cma_heap.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c > index 0c05b79870f9..83f02bd51dda 100644 > --- a/drivers/dma-buf/heaps/cma_heap.c > +++ b/drivers/dma-buf/heaps/cma_heap.c > @@ -124,10 +124,11 @@ static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, > struct cma_heap_buffer *buffer = dmabuf->priv; > struct dma_heap_attachment *a; > > + mutex_lock(&buffer->lock); > + > if (buffer->vmap_cnt) > invalidate_kernel_vmap_range(buffer->vaddr, buffer->len); Since this creates nesting with mm/, but optionally I think it'd be good to prime lockdep so it knows about this. See e.g. dma_resv_lockdep() in dma-resv.c, except I don't know offhand what the right lock for invalidate_kernel_vmap_range is. -Daniel > > - mutex_lock(&buffer->lock); > list_for_each_entry(a, &buffer->attachments, list) { > if (!a->mapped) > continue; > @@ -144,10 +145,11 @@ static int cma_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf, > struct cma_heap_buffer *buffer = dmabuf->priv; > struct dma_heap_attachment *a; > > + mutex_lock(&buffer->lock); > + > if (buffer->vmap_cnt) > flush_kernel_vmap_range(buffer->vaddr, buffer->len); > > - mutex_lock(&buffer->lock); > list_for_each_entry(a, &buffer->attachments, list) { > if (!a->mapped) > continue; > -- > 2.32.0 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch 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 271C1C433F5 for ; Wed, 19 Jan 2022 15:05:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E30E110E16B; Wed, 19 Jan 2022 15:05:23 +0000 (UTC) Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by gabe.freedesktop.org (Postfix) with ESMTPS id BE7F710E18C for ; Wed, 19 Jan 2022 15:05:22 +0000 (UTC) Received: by mail-wm1-x329.google.com with SMTP id f202-20020a1c1fd3000000b0034dd403f4fbso2747729wmf.1 for ; Wed, 19 Jan 2022 07:05:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=0odyDD4qZWEyKf4dgk5bsg3tKYSY9CGvoUStfcevylA=; b=KY4YCZwWueLtUID+/YuRziwAprnxroizrhhiLqgR+VJv0dvAqf6p/e/Z8+2hbD5td3 M1RXz2Ulz5/UO405poQs0LC2mWECerbCYmm6/PclkyYapoYCKVCVsrH7+qHMc7mD7DNG yVv6KCpVaJQuyRwX173l73U/aTdl9LopqeRzs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=0odyDD4qZWEyKf4dgk5bsg3tKYSY9CGvoUStfcevylA=; b=7qQpG1N708bK4rFz9Mj7p+7UdVho3EORC5s01J3lOznw2LiUu3h/01Fmk3YJRRKTxH BqvT7kzvMx4aFlAlVwvCUF0gCNQgwtIai9rlFzwbnP5N9fXuGaAOI7bi0Q21Ur1mCe10 +I2mlOoA6QSt1q+ZV7Y6sgffnqyAQ1Szo7qCRqT+Cp9ezPIBqk78ectwkymAik6+cyp0 GgX20iQHstsVKxsvbZQu0MfNbhOi/Lu+7/eWoGVSyPNNbqWwDU1k8GnSxSKxVrcUuoYZ Vm7WGVTUYMho0BqlEYLPyHbzTiFZoVwzi6g/rEVGuPXYADL1qXVu5qOq7LLKFlNCYLRi qkug== X-Gm-Message-State: AOAM533IeJtnPW7nVnWrXy/U+iFcyb5lKWYZksM3HsS+kuaXiu0pEHfW qKnu43yPrVImqih7PLnjS5voSw== X-Google-Smtp-Source: ABdhPJxqxOTFLl5T1cf1q2Ex/gbOeL3/4WLRyt3JAUtwMEe4sBmurRyS45VDAxAFnc6SDjv5q4TcRQ== X-Received: by 2002:adf:fec2:: with SMTP id q2mr29547534wrs.546.1642604721320; Wed, 19 Jan 2022 07:05:21 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id g17sm7645503wmq.9.2022.01.19.07.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jan 2022 07:05:20 -0800 (PST) Date: Wed, 19 Jan 2022 16:05:18 +0100 From: Daniel Vetter To: Weizhao Ouyang Subject: Re: [PATCH] dma-buf: cma_heap: Fix mutex locking section Message-ID: Mail-Followup-To: Weizhao Ouyang , Sumit Semwal , Benjamin Gaignard , Liam Mark , Laura Abbott , Brian Starkey , John Stultz , christian.koenig@amd.com, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org References: <20220104073545.124244-1-o451686892@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220104073545.124244-1-o451686892@gmail.com> X-Operating-System: Linux phenom 5.10.0-8-amd64 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: Benjamin Gaignard , christian.koenig@amd.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Liam Mark , linaro-mm-sig@lists.linaro.org, Laura Abbott , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Tue, Jan 04, 2022 at 03:35:45PM +0800, Weizhao Ouyang wrote: > Fix cma_heap_buffer mutex locking critical section to protect vmap_cnt > and vaddr. > > Fixes: a5d2d29e24be ("dma-buf: heaps: Move heap-helper logic into the cma_heap implementation") > Signed-off-by: Weizhao Ouyang > --- > drivers/dma-buf/heaps/cma_heap.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c > index 0c05b79870f9..83f02bd51dda 100644 > --- a/drivers/dma-buf/heaps/cma_heap.c > +++ b/drivers/dma-buf/heaps/cma_heap.c > @@ -124,10 +124,11 @@ static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, > struct cma_heap_buffer *buffer = dmabuf->priv; > struct dma_heap_attachment *a; > > + mutex_lock(&buffer->lock); > + > if (buffer->vmap_cnt) > invalidate_kernel_vmap_range(buffer->vaddr, buffer->len); Since this creates nesting with mm/, but optionally I think it'd be good to prime lockdep so it knows about this. See e.g. dma_resv_lockdep() in dma-resv.c, except I don't know offhand what the right lock for invalidate_kernel_vmap_range is. -Daniel > > - mutex_lock(&buffer->lock); > list_for_each_entry(a, &buffer->attachments, list) { > if (!a->mapped) > continue; > @@ -144,10 +145,11 @@ static int cma_heap_dma_buf_end_cpu_access(struct dma_buf *dmabuf, > struct cma_heap_buffer *buffer = dmabuf->priv; > struct dma_heap_attachment *a; > > + mutex_lock(&buffer->lock); > + > if (buffer->vmap_cnt) > flush_kernel_vmap_range(buffer->vaddr, buffer->len); > > - mutex_lock(&buffer->lock); > list_for_each_entry(a, &buffer->attachments, list) { > if (!a->mapped) > continue; > -- > 2.32.0 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch