From patchwork Fri Jan 29 16:53:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 8165041 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A5C449F440 for ; Fri, 29 Jan 2016 16:57:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F136A20383 for ; Fri, 29 Jan 2016 16:57:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3663B20328 for ; Fri, 29 Jan 2016 16:57:58 +0000 (UTC) Received: from localhost ([::1]:35338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPCMv-0008BG-NF for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Jan 2016 11:57:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPCJV-0002Hc-5w for qemu-devel@nongnu.org; Fri, 29 Jan 2016 11:54:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aPCJP-00042P-V6 for qemu-devel@nongnu.org; Fri, 29 Jan 2016 11:54:25 -0500 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]:35356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPCJP-00042B-LK for qemu-devel@nongnu.org; Fri, 29 Jan 2016 11:54:19 -0500 Received: by mail-wm0-x22d.google.com with SMTP id r129so76818850wmr.0 for ; Fri, 29 Jan 2016 08:54:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=K9vXJ9fdBJF07Zx8bt3DW9yP494yTmhYatMxMqzAGx4=; b=bfd5HoEFRJ2m0wStI7PiDbH4Qdrx3X2UHRagB3rP45fCfd+CurLLyv+dG3k7421ajn oCsWf9CqfWsSjj9gJ9HKt0kQkmBSbJbS7G2VGBEY2JvvUmSeG4GUb/OjqA7rOk98hohw qoNotDN5w2XrskaZuQXvYOTcJef0UzmAs02Xo= 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=K9vXJ9fdBJF07Zx8bt3DW9yP494yTmhYatMxMqzAGx4=; b=IOxqeYNq6Gp1hpF3KTJCEhIna5z16DR9rd0WqdVqVxqTT76Z8ZT7YR4ZBruWQbZnrG YKB0rlXNB4XTNxesEbYvKHgS0W8PQhGOtm+AQw7lGZ+PcocVkNGBgifTB1BggoVuWU8i EZ9qIaOlJHLPm8bgoUNOjcwAsHSGAgryGvs01mRuAVc0l5Qa8gbf0hPIg/jkP33OtqZz E2e6CRzW9DByTFyjrShHozbKHuqzC41ddwK6gRNfLZNKfUvDWS5luYIRcYSZj4Q/Mmqg nrtoS6+QQ7opUGQHBZ5n4bb3KQ5hGbN92cRtMxiUEIdMZ34DoOA7ene2Rf79lfzL3JKr UwSw== X-Gm-Message-State: AG10YOQeGfk5nG/XuLjTV2jF5EaV49JfVMukIBTa9N4wPPG+b7KvLNHn2vSnRz5zENJiNwaF X-Received: by 10.28.5.213 with SMTP id 204mr9694489wmf.20.1454086458925; Fri, 29 Jan 2016 08:54:18 -0800 (PST) Received: from new-host-12.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id ei9sm16415530wjd.40.2016.01.29.08.54.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Jan 2016 08:54:17 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, alex.williamson@redhat.com, pranav.sawargaonkar@gmail.com, p.fedin@samsung.com, pbonzini@redhat.com, agraf@suse.de Date: Fri, 29 Jan 2016 16:53:49 +0000 Message-Id: <1454086429-4373-9-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1454086429-4373-1-git-send-email-eric.auger@linaro.org> References: <1454086429-4373-1-git-send-email-eric.auger@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22d Cc: Bharat.Bhushan@freescale.com, suravee.suthikulpanit@amd.com, christoffer.dall@linaro.org Subject: [Qemu-devel] [RFC v2 8/8] hw: vfio: common: adapt vfio_listeners for reserved_iova region X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 In case of reserved iova region, let's declare this region to the kernel so that it can use it for IOVA/PA bindings. Signed-off-by: Eric Auger --- hw/vfio/common.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 247c87b..ee957ba 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -217,10 +217,8 @@ static int vfio_dma_unmap(VFIOContainer *container, * * unregistration is handled using vfio_dma_unmap */ -int vfio_register_reserved_iova(VFIOContainer *container, hwaddr iova, - ram_addr_t size); -int vfio_register_reserved_iova(VFIOContainer *container, hwaddr iova, - ram_addr_t size) +static int vfio_register_reserved_iova(VFIOContainer *container, hwaddr iova, + ram_addr_t size) { struct vfio_iommu_type1_dma_map map = { .argsz = sizeof(map), @@ -271,6 +269,7 @@ static int vfio_dma_map(VFIOContainer *container, hwaddr iova, static bool vfio_listener_skipped_section(MemoryRegionSection *section) { return (!memory_region_is_ram(section->mr) && + !memory_region_is_reserved_iova(section->mr) && !memory_region_is_iommu(section->mr)) || /* * Sizing an enabled 64-bit BAR can cause spurious mappings to @@ -354,7 +353,7 @@ static void vfio_listener_region_add(MemoryListener *listener, hwaddr iova, end; Int128 llend; void *vaddr; - int ret; + int ret = -1; if (vfio_listener_skipped_section(section)) { trace_vfio_listener_region_add_skip( @@ -418,24 +417,35 @@ static void vfio_listener_region_add(MemoryListener *listener, return; } - /* Here we assume that memory_region_is_ram(section->mr)==true */ + /* Here we assume that the memory region is ram or reserved iova */ - vaddr = memory_region_get_ram_ptr(section->mr) + - section->offset_within_region + - (iova - section->offset_within_address_space); + if (memory_region_is_ram(section->mr)) { + vaddr = memory_region_get_ram_ptr(section->mr) + + section->offset_within_region + + (iova - section->offset_within_address_space); - trace_vfio_listener_region_add_ram(iova, end - 1, vaddr); + trace_vfio_listener_region_add_ram(iova, end - 1, vaddr); - ret = vfio_dma_map(container, iova, end - iova, vaddr, section->readonly); - if (ret) { - error_report("vfio_dma_map(%p, 0x%"HWADDR_PRIx", " - "0x%"HWADDR_PRIx", %p) = %d (%m)", - container, iova, end - iova, vaddr, ret); - goto fail; + ret = vfio_dma_map(container, iova, end - iova, vaddr, + section->readonly); + if (ret) { + error_report("vfio_dma_map(%p, 0x%"HWADDR_PRIx", " + "0x%"HWADDR_PRIx", %p) = %d (%m)", + container, iova, end - iova, vaddr, ret); + goto fail; + } + return; + } else if (memory_region_is_reserved_iova(section->mr)) { + ret = vfio_register_reserved_iova(container, iova, end - iova); + if (ret) { + error_report("vfio_register_reserved_iova(%p, 0x%"HWADDR_PRIx", " + "0x%"HWADDR_PRIx") = %d (%m)", + container, iova, end - iova, ret); + goto fail; + } + return; } - return; - fail: /* * On the initfn path, store the first error in the container so we