From patchwork Tue Nov 26 01:10:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11261269 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 11D591393 for ; Tue, 26 Nov 2019 01:11:35 +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 EF2602068F for ; Tue, 26 Nov 2019 01:11:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF2602068F 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 44FAF6E1CD; Tue, 26 Nov 2019 01:11:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by gabe.freedesktop.org (Postfix) with ESMTPS id F18BC6E1CD for ; Tue, 26 Nov 2019 01:11:32 +0000 (UTC) Received: by mail-pl1-x641.google.com with SMTP id o8so2981316pls.5 for ; Mon, 25 Nov 2019 17:11:32 -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=kaPPIWsEF4upG4l+JTslBmj5SeIlIs0u8TXiyS8y8YE=; b=P5a+91HNhaw4l9nrvZVVTfmXFKuh7Ua+fq5corOakgCDJ7N5ixrVwTFmym9Ea8rieQ cBZSv/q9yT1WcLb3hO8rhfF+iPdfZU6+a+6nZmAvjRj2qc4P+yjJAhiutZP0zBnWwuqn +QnGrfB8ujr3odJ/pjVe2I2ljGlYCk3OGlTm1Z9lL4qiJQOpKG5Fep994xl4qcs76zWc reR51fxTV4HjDFg7R8VJPlaFOgBabg+zygc7GmtY8YnZwUJDKJcKjZuFA6SWfeiarBf5 TXZG5lQfatNi+bQp/lZJhWECs3UHTpHyrvDkVlJh7I60jmamwxmPkka2dsbr6UdBOJvH 4W7g== X-Gm-Message-State: APjAAAXZstBv6jbLZBvODI46XmltNpoe9uP4avdkVReYBc6Ki1pfnNyn Gk48h2fhOFz/eCoQ4SkcyERiZAOcn7c= X-Google-Smtp-Source: APXvYqy13Jc8EN+9gue54QDH3UcS2g6yMy02t4IHt328z0ehWIeXCTIH+h+pgNzM/I4cFrODmPsMUg== X-Received: by 2002:a17:902:b68c:: with SMTP id c12mr2947446pls.126.1574730692309; Mon, 25 Nov 2019 17:11:32 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id z10sm9672903pgg.39.2019.11.25.17.11.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Nov 2019 17:11:31 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 5/5] udmabuf: implement begin_cpu_access/end_cpu_access hooks Date: Mon, 25 Nov 2019 17:10:56 -0800 Message-Id: <20191126011056.67928-5-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191126011056.67928-1-gurchetansingh@chromium.org> References: <20191126011056.67928-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=kaPPIWsEF4upG4l+JTslBmj5SeIlIs0u8TXiyS8y8YE=; b=U0wBRPFw2/H930x4iZW30rQMMo2mQvK/5uDl+S7FrtZTV4XBj0O3kl2Jp8ytlFe9gG KE6X0YiGz/ZmRV7iXG30Zm2QRjJFWk+zpcFeaNL01XYzAinQ8vJZzag0NeAmp27QJfup xIvFwS09lrxp9yvGsIdATTyI4SENgMLvlE6ow= 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 | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 67e89bb034c5..142444922acd 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -19,6 +19,7 @@ struct udmabuf { u32 flags; pgoff_t pagecount; struct page **pages; + struct sg_table *sg; struct miscdevice *device; }; @@ -105,8 +106,12 @@ 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); @@ -127,6 +132,39 @@ static void kunmap_udmabuf(struct dma_buf *buf, unsigned long page_num, kunmap(vaddr); } +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, @@ -135,6 +173,8 @@ static const struct dma_buf_ops udmabuf_ops = { .map = kmap_udmabuf, .unmap = kunmap_udmabuf, .mmap = mmap_udmabuf, + .begin_cpu_access = begin_cpu_udmabuf, + .end_cpu_access = end_cpu_udmabuf, }; #define SEALS_WANTED (F_SEAL_SHRINK)