Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3721598pxb; Mon, 24 Jan 2022 16:18:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJwdw8MWiORViPdEYblQWK+hoKTg0WuHGAK0miEaG5Fkn5SraQzypZzeeZAayO/QQDy4Y8wB X-Received: by 2002:a63:8c0f:: with SMTP id m15mr13418956pgd.598.1643069927736; Mon, 24 Jan 2022 16:18:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069927; cv=none; d=google.com; s=arc-20160816; b=HogbaSe2sKRzMgXcbXNqUnjX3QUNKTUUDT1SVdbkIHMH6d+fbmyYoXvCy2Fu++fXv8 z70KJz2FduL0+C1nlIE8C3dyT0bxoDKqiIbH8os852I0KK4Vxbmit6ej9HcZbwb2IkEF PLLEj+uaKMmS1wAM6LPnXhWRhpazKqRypQ06TbbRvnkNgYaTQ54QDGJczBW7Ml3cHznN 4kvRslNv2JtOHHVoVoc/Y2zCuHVIByNpk1C2UENrDKBnM/7K1DLWoR2PJOL/xOcSfP8l UGaiajJzeTAk10RMJntiEGihNWBYnx6FyfmI+2mvdd1vZ8l6UIJfWP3ZCsoc/4KzenUu EjVA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vi2uR+bjeNLup5DxJ/mjxWoZeqVIqPcpNZ/SuvNFiC4=; b=GwmtZ2WzPa2SSFKxQNQu7dcGhRMQOZ60aHlmu3mV1y2FhZVckJQknekFkXQHwOOg/3 NVXhLWKKRcpD4Jkl2qw/aGy67V8wu/9pWHdnkdY3xJvHGz8LfQ0lB7qjnCUK8ce71n3t /h6lQP/UG+sC25ZZWRhtjA5/CQz1H1iLRQ2b4ZFAn4vy/qwV0pARQFPmlbnX8giFQIYA DlO3ghC8P2XzQ0CYcMVsuKWjNMERV/chepmtG1NKwJzx4f2t+RTA2mkOf3GrwB4cWoh0 6ZUsCXz3/yRI+h5jy0z41hhrc7qBwJLGOIMvHYAKqf7kYH1oGV2Fb/eQ1Lth55aC5E4G ihPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NcAMyGDg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j123si14248239pfb.294.2022.01.24.16.18.35; Mon, 24 Jan 2022 16:18:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NcAMyGDg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2373083AbiAYANF (ORCPT + 99 others); Mon, 24 Jan 2022 19:13:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1842399AbiAXX2g (ORCPT ); Mon, 24 Jan 2022 18:28:36 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DB71C0A887B; Mon, 24 Jan 2022 13:34:27 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 01076B811FB; Mon, 24 Jan 2022 21:34:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AF44C340E5; Mon, 24 Jan 2022 21:34:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060065; bh=yGF2yk0DciZXVKy44TwKN8EX+j1uAZ+XFwglFSQ1H9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NcAMyGDgSgqdbmsE9ZBstrmg0q8EPnHIFvV4TzH/RaV5Nce2jnfA+g+nPyRs4q3JI rZOZI6x0JU4/cEwME3/bZ6ESzy2qGcyj7chwlv5t/XD4L+w0yBI2N5lC4j5fK0kuNe /wOnW6Bzbx426ssSJK6qXP4bT/fGAFQUfE3LMfiA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Weizhao Ouyang , John Stultz , Sumit Semwal , Sasha Levin Subject: [PATCH 5.16 0826/1039] dma-buf: cma_heap: Fix mutex locking section Date: Mon, 24 Jan 2022 19:43:35 +0100 Message-Id: <20220124184153.055320874@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Weizhao Ouyang [ Upstream commit 54329e6f7beea6af56c1230da293acc97d6a6ee7 ] 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 Acked-by: John Stultz Signed-off-by: Sumit Semwal Link: https://patchwork.freedesktop.org/patch/msgid/20220104073545.124244-1-o451686892@gmail.com Signed-off-by: Sasha Levin --- 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 0c05b79870f96..83f02bd51dda6 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); - 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.34.1