From patchwork Tue Dec 3 01:36:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11270141 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 654B1921 for ; Tue, 3 Dec 2019 01:36:47 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4E899206E1 for ; Tue, 3 Dec 2019 01:36:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E899206E1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 45D826E25D; Tue, 3 Dec 2019 01:36:45 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by gabe.freedesktop.org (Postfix) with ESMTPS id 50B356E25D for ; Tue, 3 Dec 2019 01:36:44 +0000 (UTC) Received: by mail-pj1-x1042.google.com with SMTP id r11so728200pjp.12 for ; Mon, 02 Dec 2019 17:36:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UC12aMZjZVB0hw5FURRfqe7EjweoFXTZMR/s1F02Qgs=; b=F4ZV9h0fr9oyE+EPRtAduooTnOHguSgOiFoZ7ea5z2/TxvRuzXV6fpz/le9LzaMUuo 1EeQ8r6jgq/x94kUv0uNp2G6eHDyjf+BEiSHAbg5PrgFnVQXz+rr1PifnbM781Fx+fGU t4RQiEca6099lrhlFiy4gVDPQSLGZkIHm/0kjD2Kd7pNFxWdBieGpixqCJhjPIzuyYTj /Sf1FqjC2nQD3BYvr3H/wWu9U18nY0vkHqH7/AC7uEMSCNqeaNnXdNV+shoO9fxxr/O3 fXhMnkY19tz2BvpIX2dbxM2r4eVSXKsRPMX/9qQMVNcDeeT6cCLryL7NAUTXB5UPYClK tu2Q== X-Gm-Message-State: APjAAAVyU0C+X7c/SQ5HzEGa2PDgEf8jN2M02LqBmmQUtAkDTOfTHbbY KWU5690nmOOOtHaoq35MqFy+mXurHCM= X-Google-Smtp-Source: APXvYqwokl7QfCw9qi4P1gu6pROxJy+Fn7i1+joycJVc7sIxc0Oz0YQbc2txYevyMRkUSHjp6yAewQ== X-Received: by 2002:a17:902:b90a:: with SMTP id bf10mr2444763plb.45.1575337003597; Mon, 02 Dec 2019 17:36:43 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id r4sm581916pji.11.2019.12.02.17.36.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Dec 2019 17:36:42 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/4] udmabuf: implement begin_cpu_access/end_cpu_access hooks Date: Mon, 2 Dec 2019 17:36:27 -0800 Message-Id: <20191203013627.85991-4-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191203013627.85991-1-gurchetansingh@chromium.org> References: <20191203013627.85991-1-gurchetansingh@chromium.org> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UC12aMZjZVB0hw5FURRfqe7EjweoFXTZMR/s1F02Qgs=; b=fmpA6UfGacoKv242CuqlcAnMVr7Ie44cQh+ijNdlzpPQ70luiLYdsUP4Y7hvIqkGuY 1CyXJiI8BK4lnXtgiczMzKl2DwYOMXFWlSCSKrz0sYdEPcd8lFLDgTjrYZCwv+G5Si6x OCE9NdXoTcGH9jxhpa1kV6EWECYfWoaGOMwjg= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gurchetan Singh , kraxel@redhat.com, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" With the misc device, we should end up using the result of get_arch_dma_ops(..) or dma-direct ops. This can allow us to have WC mappings in the guest after synchronization. Signed-off-by: Gurchetan Singh --- drivers/dma-buf/udmabuf.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 0a610e09ae23..61b0a2cff874 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -18,6 +18,7 @@ static const size_t size_limit_mb = 64; /* total dmabuf size, in megabytes */ struct udmabuf { pgoff_t pagecount; struct page **pages; + struct sg_table *sg; struct miscdevice *device; }; @@ -98,20 +99,58 @@ static void unmap_udmabuf(struct dma_buf_attachment *at, static void release_udmabuf(struct dma_buf *buf) { struct udmabuf *ubuf = buf->priv; + struct device *dev = ubuf->device->this_device; pgoff_t pg; + if (ubuf->sg) + put_sg_table(dev, ubuf->sg, DMA_BIDIRECTIONAL); + for (pg = 0; pg < ubuf->pagecount; pg++) put_page(ubuf->pages[pg]); kfree(ubuf->pages); kfree(ubuf); } +static int begin_cpu_udmabuf(struct dma_buf *buf, + enum dma_data_direction direction) +{ + struct udmabuf *ubuf = buf->priv; + struct device *dev = ubuf->device->this_device; + + if (!ubuf->sg) { + ubuf->sg = get_sg_table(dev, buf, direction); + if (IS_ERR(ubuf->sg)) + return PTR_ERR(ubuf->sg); + } else { + dma_sync_sg_for_device(dev, ubuf->sg->sgl, + ubuf->sg->nents, + direction); + } + + return 0; +} + +static int end_cpu_udmabuf(struct dma_buf *buf, + enum dma_data_direction direction) +{ + struct udmabuf *ubuf = buf->priv; + struct device *dev = ubuf->device->this_device; + + if (!ubuf->sg) + return -EINVAL; + + dma_sync_sg_for_cpu(dev, ubuf->sg->sgl, ubuf->sg->nents, direction); + return 0; +} + static const struct dma_buf_ops udmabuf_ops = { .cache_sgt_mapping = true, .map_dma_buf = map_udmabuf, .unmap_dma_buf = unmap_udmabuf, .release = release_udmabuf, .mmap = mmap_udmabuf, + .begin_cpu_access = begin_cpu_udmabuf, + .end_cpu_access = end_cpu_udmabuf, }; #define SEALS_WANTED (F_SEAL_SHRINK)