From patchwork Mon Sep 30 15:28:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonios Motakis X-Patchwork-Id: 2966291 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D87D49F88A for ; Mon, 30 Sep 2013 15:30:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4E000201C8 for ; Mon, 30 Sep 2013 15:30:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A91E520274 for ; Mon, 30 Sep 2013 15:30:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756157Ab3I3P3r (ORCPT ); Mon, 30 Sep 2013 11:29:47 -0400 Received: from mail-we0-f170.google.com ([74.125.82.170]:62230 "EHLO mail-we0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756097Ab3I3P3Y (ORCPT ); Mon, 30 Sep 2013 11:29:24 -0400 Received: by mail-we0-f170.google.com with SMTP id w62so5913346wes.29 for ; Mon, 30 Sep 2013 08:29:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xEjALoAwI8R/US5pZW5F/mwLGebQd+lpsJ9OXGw26QM=; b=PvxNKnWMdxxoVpW6xM7nt0ReUA/F8iaJAYXBGTv8U5WYzE9RyzsItwYTnycR+LlgLY oPjVXqcubcZrrVC8fjtD3r35WZd1hQCAyCgS8MAld4cfVIZMayoij34zJwiNKXBFxuFl MBueAZ1gb1vR5xVY7bpnLZUHB9kYlVNYzh85bLeAP2UmAdZtgwH9+EtZn8i0pyZuJxc2 BCVRxbhbdi9ODqYiC9VcTWc2KXULcisR4gFe2tFL+AaHX4R0KehReLf1OvFq7dIU5Y7R 0e2dvWjTXY84WUXRyOyu2R0Xl3iVVh6o/sIhrniPmsAgHUJNtiAeDeibBBD3UVM5hDGw 0MQg== X-Gm-Message-State: ALoCoQn8WEVHtUDCA7yGJJ5o2XiKXhHRrCYECVQc7s3vu62nY5Omik3pr/x5j6/zGmKujwL25ycq X-Received: by 10.180.211.111 with SMTP id nb15mr14107474wic.55.1380554963444; Mon, 30 Sep 2013 08:29:23 -0700 (PDT) Received: from localhost.localdomain (home.tvelocity.eu. [82.67.68.96]) by mx.google.com with ESMTPSA id ey4sm2015579wic.11.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Sep 2013 08:29:22 -0700 (PDT) From: Antonios Motakis To: kvmarm@lists.cs.columbia.edu, alex.williamson@redhat.com Cc: iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org, kvm@vger.kernel.org, agraf@suse.de, B08248@freescale.com, tech@virtualopensystems.com, Antonios Motakis Subject: [PATCH 5/7] VFIO: DT: Read and write support for the device fd Date: Mon, 30 Sep 2013 17:28:41 +0200 Message-Id: <1380554923-17818-6-git-send-email-a.motakis@virtualopensystems.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1380554923-17818-1-git-send-email-a.motakis@virtualopensystems.com> References: <1380554923-17818-1-git-send-email-a.motakis@virtualopensystems.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP VFIO returns a file descriptor which we can use to manipulate the memory regions of the device. Since some memory regions we cannot mmap due to security concerns, we also allow to read and write to this file descriptor directly. Signed-off-by: Antonios Motakis --- drivers/vfio/vfio_platform.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/drivers/vfio/vfio_platform.c b/drivers/vfio/vfio_platform.c index 6364316..b92d7bb 100644 --- a/drivers/vfio/vfio_platform.c +++ b/drivers/vfio/vfio_platform.c @@ -102,7 +102,8 @@ static long vfio_platform_ioctl(void *device_data, info.offset = res.start; /* map phys addr with offset */ info.size = resource_size(&res); - info.flags = 0; + info.flags = VFIO_REGION_INFO_FLAG_READ + | VFIO_REGION_INFO_FLAG_WRITE; /* Only regions addressed with PAGE granularity can be MMAPed * securely. */ if (!(info.offset & ~PAGE_MASK) && !(info.size & ~PAGE_MASK)) @@ -153,13 +154,43 @@ static bool is_in_resource(struct resource res, u64 addr, u64 size) static ssize_t vfio_platform_read(void *device_data, char __user *buf, size_t count, loff_t *ppos) { - return 0; + struct vfio_platform_device *vdev = device_data; + struct device_node *of_node = vdev->pdev->dev.of_node; + struct resource res; + int i; + + for (i = 0; !of_address_to_resource(of_node, i, &res); i++) { + if (!is_in_resource(res, *ppos, count)) + continue; + + if (copy_to_user(buf, ppos, count)) + return -EFAULT; + else + return count; + } + + return -EINVAL; } static ssize_t vfio_platform_write(void *device_data, const char __user *buf, size_t count, loff_t *ppos) { - return 0; + struct vfio_platform_device *vdev = device_data; + struct device_node *of_node = vdev->pdev->dev.of_node; + struct resource res; + int i; + + for (i = 0; !of_address_to_resource(of_node, i, &res); i++) { + if (!is_in_resource(res, *ppos, count)) + continue; + + if (copy_from_user(ppos, buf, count)) + return -EFAULT; + else + return count; + } + + return -EINVAL; } static int vfio_platform_mmap(void *device_data, struct vm_area_struct *vma)