Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3379534imu; Mon, 24 Dec 2018 00:20:59 -0800 (PST) X-Google-Smtp-Source: ALg8bN4njvDLy3FCDMCGL/XBogeV6y+Y6n0bptmUdhKYsjh5TImmJWkypwPBIh5zCSthohbzkbvo X-Received: by 2002:a17:902:8e8a:: with SMTP id bg10mr12206083plb.192.1545639659217; Mon, 24 Dec 2018 00:20:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545639659; cv=none; d=google.com; s=arc-20160816; b=FSoAZCCYqmNbohuqDNR9TU+8/AEmuqKqKFdr1g7T0lTDdDzPV4ZlGhuapHMYLT0lJ7 tXttmCxvNUxLsT7jL3T/ZgSX0SPNJ+eIzCD16HpZBgXnUy5eAmOX77SNwBEDICiWUhtW 5R2VzcxHBXeGeQ1FKzklVHdk8DcEWiu039oyQGG8k+0Xdw56HIPloHvoOSqQVcct5RRp 4Muc8fBGdje8sOylGAJCV0LtlDHzCGsBOyZ0mdoL96N0A+PYrg7Bath577CdGkPc50cT v19EuTG/ghXg59yO3o09L+98K5nJk2DBB5xYncmWYnTS2jEolaNls40FyYHtATHsriJ1 WYdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=E738lcONGq4wTwd0NmGS4FL9K1fQeHLHQF3BRQmLQcU=; b=dea7dNqu+ZnW/67oWl9gOWGeSXypAqX8X5A4NLKhJMJwnT/c05zmCXz3SF1CYs4nny 3B14+H6/Uoc9EZhfLeXE1W7JCCA1L36TnqcN3t7R7VFJ+hfVIIMVFiZ8h83mwqlHR4Mc dS/1lbMaA+4tcg0L6WlmeaLyPFFzMyPaa2vRwVZyVq0TWLk635Rzvjoy/HROammiXSBk E3Ffuc6XowuivknspTSDHdV1ySV+LKuHPo+/JSIo29Ksbjh5aEdT7CXUfabZoZ2UkDtL xG9C9es3NCeehVr+aE8zEVc/9mouX8IVlbaCIwAzLXlta0Zmzz+BIYPchO5LZiInza7H 1ogg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1si6192069pgq.13.2018.12.24.00.20.43; Mon, 24 Dec 2018 00:20:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726849AbeLXITy (ORCPT + 99 others); Mon, 24 Dec 2018 03:19:54 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:60293 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726788AbeLXITy (ORCPT ); Mon, 24 Dec 2018 03:19:54 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 58632A8E6B83B; Mon, 24 Dec 2018 16:19:50 +0800 (CST) Received: from huawei.com (10.141.125.218) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.408.0; Mon, 24 Dec 2018 16:19:45 +0800 From: Qing Xia To: , , , , , CC: , , , , , , Subject: [PATCH] staging: android: ion: move map_kernel to ion_dma_buf_kmap Date: Mon, 24 Dec 2018 16:19:45 +0800 Message-ID: <1545639585-24785-1-git-send-email-saberlily.xia@hisilicon.com> X-Mailer: git-send-email 2.7.3 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.141.125.218] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now, as Google's user guide, if userspace need clean ION buffer's cache, they should call ioctl(fd, DMA_BUF_IOCTL_SYNC, sync). Then we found that ion_dma_buf_begin_cpu_access/ion_dma_buf_end_cpu_access will do ION buffer's map_kernel, it's not necessary. And if usersapce only need clean cache, they will call ion_dma_buf_end_cpu_access by dmabuf's ioctl, ION buffer's kmap_cnt will be wrong value -1, then driver could not get right kernel vaddr by dma_buf_kmap. Signed-off-by: Qing Xia --- drivers/staging/android/ion/ion.c | 46 ++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 9907332..f7e2812 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -303,45 +303,47 @@ static void ion_dma_buf_release(struct dma_buf *dmabuf) static void *ion_dma_buf_kmap(struct dma_buf *dmabuf, unsigned long offset) { struct ion_buffer *buffer = dmabuf->priv; + void *vaddr; - return buffer->vaddr + offset * PAGE_SIZE; + if (buffer->heap->ops->map_kernel) { + mutex_lock(&buffer->lock); + vaddr = ion_buffer_kmap_get(buffer); + mutex_unlock(&buffer->lock); + if (IS_ERR(vaddr)) + return vaddr; + + return vaddr + offset * PAGE_SIZE; + } + + return NULL; } static void ion_dma_buf_kunmap(struct dma_buf *dmabuf, unsigned long offset, void *ptr) { + struct ion_buffer *buffer = dmabuf->priv; + + if (buffer->heap->ops->map_kernel) { + mutex_lock(&buffer->lock); + ion_buffer_kmap_put(buffer); + mutex_unlock(&buffer->lock); + } } static int ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, enum dma_data_direction direction) { struct ion_buffer *buffer = dmabuf->priv; - void *vaddr; struct ion_dma_buf_attachment *a; - int ret = 0; - - /* - * TODO: Move this elsewhere because we don't always need a vaddr - */ - if (buffer->heap->ops->map_kernel) { - mutex_lock(&buffer->lock); - vaddr = ion_buffer_kmap_get(buffer); - if (IS_ERR(vaddr)) { - ret = PTR_ERR(vaddr); - goto unlock; - } - mutex_unlock(&buffer->lock); - } mutex_lock(&buffer->lock); list_for_each_entry(a, &buffer->attachments, list) { dma_sync_sg_for_cpu(a->dev, a->table->sgl, a->table->nents, direction); } - -unlock: mutex_unlock(&buffer->lock); - return ret; + + return 0; } static int ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, @@ -350,12 +352,6 @@ static int ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, struct ion_buffer *buffer = dmabuf->priv; struct ion_dma_buf_attachment *a; - if (buffer->heap->ops->map_kernel) { - mutex_lock(&buffer->lock); - ion_buffer_kmap_put(buffer); - mutex_unlock(&buffer->lock); - } - mutex_lock(&buffer->lock); list_for_each_entry(a, &buffer->attachments, list) { dma_sync_sg_for_device(a->dev, a->table->sgl, a->table->nents, -- 2.7.3