From patchwork Mon Mar 21 07:46:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 8630141 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 E7AFA9F36E for ; Mon, 21 Mar 2016 07:56:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 22DAA20270 for ; Mon, 21 Mar 2016 07:56:29 +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 143072026F for ; Mon, 21 Mar 2016 07:56:28 +0000 (UTC) Received: from localhost ([::1]:56137 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahuhP-0000z8-JP for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Mar 2016 03:56:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahua1-0004gj-RS for qemu-devel@nongnu.org; Mon, 21 Mar 2016 03:48:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ahuZz-0001ys-AN for qemu-devel@nongnu.org; Mon, 21 Mar 2016 03:48:49 -0400 Received: from e23smtp02.au.ibm.com ([202.81.31.144]:55178) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahuZy-0001xc-Pe for qemu-devel@nongnu.org; Mon, 21 Mar 2016 03:48:47 -0400 Received: from localhost by e23smtp02.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 21 Mar 2016 17:48:43 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp02.au.ibm.com (202.81.31.208) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 21 Mar 2016 17:48:41 +1000 X-IBM-Helo: d23dlp02.au.ibm.com X-IBM-MailFrom: aik@ozlabs.ru X-IBM-RcptTo: qemu-devel@nongnu.org;qemu-ppc@nongnu.org Received: from d23relay09.au.ibm.com (d23relay09.au.ibm.com [9.185.63.181]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 441DF2BB0073; Mon, 21 Mar 2016 18:48:36 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u2L7mSDw6160712; Mon, 21 Mar 2016 18:48:36 +1100 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u2L7m33A030977; Mon, 21 Mar 2016 18:48:03 +1100 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u2L7m33V030148; Mon, 21 Mar 2016 18:48:03 +1100 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id 31238A0380; Mon, 21 Mar 2016 18:47:09 +1100 (AEDT) Received: from vpl2.ozlabs.ibm.com (vpl2.ozlabs.ibm.com [10.61.141.27]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id 36A1DE39C0; Mon, 21 Mar 2016 18:47:09 +1100 (AEDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 21 Mar 2016 18:46:59 +1100 Message-Id: <1458546426-26222-12-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 2.5.0.rc3 In-Reply-To: <1458546426-26222-1-git-send-email-aik@ozlabs.ru> References: <1458546426-26222-1-git-send-email-aik@ozlabs.ru> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16032107-0005-0000-0000-0000071901CF X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 202.81.31.144 Cc: Alexey Kardashevskiy , Alex Williamson , qemu-ppc@nongnu.org, David Gibson Subject: [Qemu-devel] [PATCH qemu v14 11/18] memory: Add reporting of supported page sizes 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Every IOMMU has some granularity which MemoryRegionIOMMUOps::translate uses when translating, however this information is not available outside the translate context for various checks. This adds a get_page_sizes callback to MemoryRegionIOMMUOps and a wrapper for it so IOMMU users (such as VFIO) can know the actual page size(s) used by an IOMMU. The qemu_real_host_page_mask is used as fallback. This removes vfio_container_granularity() and uses new callback in memory_region_iommu_replay() when replaying IOMMU mappings on added IOMMU memory region. Signed-off-by: Alexey Kardashevskiy --- Changes: v14: * removed vfio_container_granularity(), changed memory_region_iommu_replay() v4: * s/1<mig_table = tcet->table; } +static uint64_t spapr_tce_get_page_sizes(MemoryRegion *iommu) +{ + sPAPRTCETable *tcet = container_of(iommu, sPAPRTCETable, iommu); + + return 1ULL << tcet->page_shift; +} + static void spapr_tce_table_do_enable(sPAPRTCETable *tcet); static void spapr_tce_table_do_disable(sPAPRTCETable *tcet); @@ -203,6 +210,7 @@ static const VMStateDescription vmstate_spapr_tce_table = { static MemoryRegionIOMMUOps spapr_iommu_ops = { .translate = spapr_tce_translate_iommu, + .get_page_sizes = spapr_tce_get_page_sizes, }; static int spapr_tce_table_realize(DeviceState *dev) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index d45e2db..55723c9 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -313,11 +313,6 @@ out: rcu_read_unlock(); } -static hwaddr vfio_container_granularity(VFIOContainer *container) -{ - return (hwaddr)1 << ctz64(container->iova_pgsizes); -} - static void vfio_listener_region_add(MemoryListener *listener, MemoryRegionSection *section) { @@ -385,7 +380,6 @@ static void vfio_listener_region_add(MemoryListener *listener, memory_region_register_iommu_notifier(giommu->iommu, &giommu->n); memory_region_iommu_replay(giommu->iommu, &giommu->n, - vfio_container_granularity(container), false); return; diff --git a/include/exec/memory.h b/include/exec/memory.h index 2de7898..eb5ce67 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -150,6 +150,8 @@ typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMUOps; struct MemoryRegionIOMMUOps { /* Return a TLB entry that contains a given address. */ IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool is_write); + /* Returns supported page sizes */ + uint64_t (*get_page_sizes)(MemoryRegion *iommu); }; typedef struct CoalescedMemoryRange CoalescedMemoryRange; @@ -573,6 +575,15 @@ static inline bool memory_region_is_iommu(MemoryRegion *mr) /** + * memory_region_iommu_get_page_sizes: get supported page sizes in an iommu + * + * Returns %bitmap of supported page sizes for an iommu. + * + * @mr: the memory region being queried + */ +uint64_t memory_region_iommu_get_page_sizes(MemoryRegion *mr); + +/** * memory_region_notify_iommu: notify a change in an IOMMU translation entry. * * @mr: the memory region that was changed @@ -596,16 +607,15 @@ void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n); /** * memory_region_iommu_replay: replay existing IOMMU translations to - * a notifier + * a notifier with the minimum page granularity returned by + * mr->iommu_ops->get_page_sizes(). * * @mr: the memory region to observe * @n: the notifier to which to replay iommu mappings - * @granularity: Minimum page granularity to replay notifications for * @is_write: Whether to treat the replay as a translate "write" * through the iommu */ -void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n, - hwaddr granularity, bool is_write); +void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n, bool is_write); /** * memory_region_unregister_iommu_notifier: unregister a notifier for diff --git a/memory.c b/memory.c index 95f7209..64a84d3 100644 --- a/memory.c +++ b/memory.c @@ -1512,12 +1512,14 @@ void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n) notifier_list_add(&mr->iommu_notify, n); } -void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n, - hwaddr granularity, bool is_write) +void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n, bool is_write) { - hwaddr addr; + hwaddr addr, granularity; IOMMUTLBEntry iotlb; + g_assert(mr->iommu_ops && mr->iommu_ops->get_page_sizes); + granularity = (hwaddr)1 << ctz64(mr->iommu_ops->get_page_sizes(mr)); + for (addr = 0; addr < memory_region_size(mr); addr += granularity) { iotlb = mr->iommu_ops->translate(mr, addr, is_write); if (iotlb.perm != IOMMU_NONE) { @@ -1544,6 +1546,15 @@ void memory_region_notify_iommu(MemoryRegion *mr, notifier_list_notify(&mr->iommu_notify, &entry); } +uint64_t memory_region_iommu_get_page_sizes(MemoryRegion *mr) +{ + assert(memory_region_is_iommu(mr)); + if (mr->iommu_ops && mr->iommu_ops->get_page_sizes) { + return mr->iommu_ops->get_page_sizes(mr); + } + return qemu_real_host_page_size; +} + void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) { uint8_t mask = 1 << client;