Message ID | 20221026224640.7542-2-dmitry.osipenko@collabora.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp520450wru; Wed, 26 Oct 2022 15:48:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM419sAfxdF5E73N4DwFKW/F0SNbpceMgfJmyAj18VI2AYJpo/DSODCPhvFUyvdIvF+4kgWt X-Received: by 2002:a17:90b:19ca:b0:212:d2c4:83ac with SMTP id nm10-20020a17090b19ca00b00212d2c483acmr6687494pjb.166.1666824527255; Wed, 26 Oct 2022 15:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666824527; cv=none; d=google.com; s=arc-20160816; b=waE94N+PlehC8JmBk7A2ZCoT5Ma1Reh8RplLv5spamAUk4ElI8v51J+6iXCd1nAY2E o1DoZhveffJ9JhNG20aAkj4l62cVv0/Kkn5giFEO/42QAXBQwDydfwl8SyvD7jrXi37t BvDINgW0D+oXg873FuDG3sGF1adc838z6HJcjL3SeqKD0f33EKVe6v+f7RFJusPPp3hO WiMVz8Nk34nFqUTvepDSiaou4I/K1KRuWRmEmQY77T3jZitefgKHoX3u5nqumQM+fx/Z Q5YJ2TnUXvme/6TC2PJsHX/Z+ga3PzHiWBgCKHnruAFd7CafnZhvmakxnSefqMQ7SJzl R/CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7o6WqWihuUpukhhS6xCQA92HMp+JgEP6doMJ70USxY0=; b=Zn5Ysqa6TLfSaWvjZDbkDoqCf+QjvQO9dQUuUIBRfOmPPkRDnJE7C426Cuhgb4YA+k d0q4IDn2OFKyjGPXbcgXUwcnAgOTG6CQCSOhWfrzxeMij/545DMxSJKlQkTsUDG78bTP +TuqhS59mIV2rEmshIDhAfw9GoGICnVbzUm+v74vdLIFEkeETqm0tF/mb8MuFiH9g9gC yPBztS+u3uXstg0XGyzE1By6GyinG8LpXXTLAGVsysza2TaGm19sCwLU9y/7PDLdMFJF U3J48G+ot27Pqr1eFWJ89bOhWEZLdSk6X1zamFCSBJqh/WOvv2/Pa4+7i6elWIBN6It8 Y5+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=FxHJGJrX; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m4-20020a170902768400b00186a06a3396si7183400pll.153.2022.10.26.15.48.34; Wed, 26 Oct 2022 15:48:47 -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=FxHJGJrX; 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 S233677AbiJZWrx (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Wed, 26 Oct 2022 18:47:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233745AbiJZWrg (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 26 Oct 2022 18:47:36 -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 0C6C4550BE for <linux-kernel@vger.kernel.org>; Wed, 26 Oct 2022 15:47:23 -0700 (PDT) Received: from dimapc.. (109-252-112-196.nat.spd-mgts.ru [109.252.112.196]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id A74CB66028B0; Wed, 26 Oct 2022 23:47:20 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1666824441; bh=6QiRYUSIMrwPPW/bBvP2JzfoL5s94stAk7lsEZE9m8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FxHJGJrXr3g7J0J0RfrP4JFa3nf0DcPezfn4+8uA+S1ghQJkSPIgCGWeSfQj2nYQ5 JteVO3aWq8EK78cA3C2H9IKn5y3f+biO5ugA3yV6zqc976O+uzJEWaxxXo9zSlRbHY qpnaRMgGJ8RVu8iKcErs8ZXZjcuzdVjOKLRI6UrdtQCYUvmL4cDQb4LHR7TY6kbrOn s1Qzkg4NpCasK0MI2cO7jirXKaZRQCnbNzD1H9vFBAYe7akc7zKzBndF7ER9yMNaVu xLcCOMfL7LuBqXOwamj/BEpoxXF4nOXQru2umqRKw4t0wxANEL4+LZc2lIu0sk8Qgb It/Hk6J8WUfyA== From: Dmitry Osipenko <dmitry.osipenko@collabora.com> To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>, Maxime Ripard <mripard@kernel.org>, Sumit Semwal <sumit.semwal@linaro.org>, Thomas Zimmermann <tzimmermann@suse.de>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, noralf@tronnes.org, Dan Carpenter <dan.carpenter@oracle.com> Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/2] dma-buf: Make locking consistent in dma_buf_detach() Date: Thu, 27 Oct 2022 01:46:39 +0300 Message-Id: <20221026224640.7542-2-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221026224640.7542-1-dmitry.osipenko@collabora.com> References: <20221026224640.7542-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 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,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747792195114655430?= X-GMAIL-MSGID: =?utf-8?q?1747792195114655430?= |
Series |
Fixes for dma-buf locking issues found by Smatch
|
|
Commit Message
Dmitry Osipenko
Oct. 26, 2022, 10:46 p.m. UTC
The dma_buf_detach() locks attach->dmabuf->resv and then unlocks
dmabuf->resv, which could be a two different locks from a static
code checker perspective. In particular this triggers Smatch to
report the "double unlock" error. Make the locking pointers consistent.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/dri-devel/Y1fLfsccW3AS%2Fo+%2F@kili/
Fixes: 809d9c72c2f8 ("dma-buf: Move dma_buf_attach() to dynamic locking specification")
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
drivers/dma-buf/dma-buf.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
Am 27.10.22 um 00:46 schrieb Dmitry Osipenko: > The dma_buf_detach() locks attach->dmabuf->resv and then unlocks > dmabuf->resv, which could be a two different locks from a static > code checker perspective. In particular this triggers Smatch to > report the "double unlock" error. Make the locking pointers consistent. > > Reported-by: Dan Carpenter <dan.carpenter@oracle.com> > Link: https://lore.kernel.org/dri-devel/Y1fLfsccW3AS%2Fo+%2F@kili/ > Fixes: 809d9c72c2f8 ("dma-buf: Move dma_buf_attach() to dynamic locking specification") > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> It would be even cleaner if we completely drop the dmabuf parameter for the function and just use the inside the attachment. Anyway patch is Reviewed-by: Christian König <christian.koenig@amd.com> for now, wider cleanups can come later on. Regards, Christian. > --- > drivers/dma-buf/dma-buf.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c > index c40d72d318fd..6e33ef4fde34 100644 > --- a/drivers/dma-buf/dma-buf.c > +++ b/drivers/dma-buf/dma-buf.c > @@ -998,9 +998,10 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) > if (WARN_ON(!dmabuf || !attach)) > return; > > - dma_resv_lock(attach->dmabuf->resv, NULL); > + dma_resv_lock(dmabuf->resv, NULL); > > if (attach->sgt) { > + WARN_ON(dmabuf != attach->dmabuf); > > __unmap_dma_buf(attach, attach->sgt, attach->dir); >
On 10/27/22 09:13, Christian König wrote: > Am 27.10.22 um 00:46 schrieb Dmitry Osipenko: >> The dma_buf_detach() locks attach->dmabuf->resv and then unlocks >> dmabuf->resv, which could be a two different locks from a static >> code checker perspective. In particular this triggers Smatch to >> report the "double unlock" error. Make the locking pointers consistent. >> >> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> >> Link: https://lore.kernel.org/dri-devel/Y1fLfsccW3AS%2Fo+%2F@kili/ >> Fixes: 809d9c72c2f8 ("dma-buf: Move dma_buf_attach() to dynamic >> locking specification") >> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> > > It would be even cleaner if we completely drop the dmabuf parameter for > the function and just use the inside the attachment. > > Anyway patch is Reviewed-by: Christian König <christian.koenig@amd.com> > for now, wider cleanups can come later on. I had the same thought about dropping the dmabuf parameter. Looking at this patch again, perhaps a better dmabuf sanity-check will be: - if (WARN_ON(!dmabuf || !attach)) + if (WARN_ON(!dmabuf || !attach || dmabuf != attach->dmabuf)) I'll switch to this version in v2, if there are no objections. > >> --- >> drivers/dma-buf/dma-buf.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c >> index c40d72d318fd..6e33ef4fde34 100644 >> --- a/drivers/dma-buf/dma-buf.c >> +++ b/drivers/dma-buf/dma-buf.c >> @@ -998,9 +998,10 @@ void dma_buf_detach(struct dma_buf *dmabuf, >> struct dma_buf_attachment *attach) >> if (WARN_ON(!dmabuf || !attach)) >> return; >> - dma_resv_lock(attach->dmabuf->resv, NULL); >> + dma_resv_lock(dmabuf->resv, NULL); >> if (attach->sgt) { >> + WARN_ON(dmabuf != attach->dmabuf); >> __unmap_dma_buf(attach, attach->sgt, attach->dir); >> >
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index c40d72d318fd..6e33ef4fde34 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -998,9 +998,10 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) if (WARN_ON(!dmabuf || !attach)) return; - dma_resv_lock(attach->dmabuf->resv, NULL); + dma_resv_lock(dmabuf->resv, NULL); if (attach->sgt) { + WARN_ON(dmabuf != attach->dmabuf); __unmap_dma_buf(attach, attach->sgt, attach->dir);