From patchwork Tue Sep 24 15:30:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 11159121 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 BCFDD13B1 for ; Tue, 24 Sep 2019 15:32:18 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 980D620665 for ; Tue, 24 Sep 2019 15:32:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="quS2noCz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 980D620665 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iCmmC-0007m2-99; Tue, 24 Sep 2019 15:30:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iCmmA-0007lx-V6 for xen-devel@lists.xenproject.org; Tue, 24 Sep 2019 15:30:50 +0000 X-Inumbo-ID: 4937eda0-dee0-11e9-8628-bc764e2007e4 Received: from mail-lj1-x244.google.com (unknown [2a00:1450:4864:20::244]) by localhost (Halon) with ESMTPS id 4937eda0-dee0-11e9-8628-bc764e2007e4; Tue, 24 Sep 2019 15:30:50 +0000 (UTC) Received: by mail-lj1-x244.google.com with SMTP id n14so2333924ljj.10 for ; Tue, 24 Sep 2019 08:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=VwbIUgUiBRcd4xYh+7xISmutJ510CQmOajiuKvNdjXs=; b=quS2noCz3X5GDY2ANXlekguFbw68bUQ7ndLbVjT9ptI2sslu8BGmJeipR4aeVOGYIl m3EQN7M9uIOYPkrHyQHDxQbE3RrlWQezRD38bihy1F3enor7HUIbprj8oQmfM73eKRtA kjL6M+hwUMVdlJm4cD7Ehfbl3uREp5OXASwTJDYSmivdaS7ORwTCNmbh01+kQHwU3xg1 fHG0X0PVlrzH9Yt55xZnAIQc1fyaIgGiKoTHEZhknBbFl1xVp8TYAmEvoBznySmqqeee SJQ6tkZAC+xdYhfE1SleVFHlt73R+jKSdpOFufgMxopd5hQYnDuGZZA1nQVP80srKXPh yBKA== 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; bh=VwbIUgUiBRcd4xYh+7xISmutJ510CQmOajiuKvNdjXs=; b=RBB6Fuo9vu6ypJgJjwNXKwkRjy51OAaw6G/DJWtReA5zDvnkU24FZ5MrOkbFaWmh32 Nh2cXH9VQsPeRTFaMk94ovvHnPaKh/tz/sgFfZfmYfZABe0jSw+MVG5ldFrUMPNGrsoM mawT9c6uaD7obujlHwL9s3dMf+bkPx5gSfQBfbDhlJ581ljB26L22gQK+00lch8ZT1U7 /WkgyHmp59AwQ9y9zx48AEB7S3/EkfnsUs20jz6atfJsl7A3FwVKFbZ0NtbWq2F3PX0f gS25ZvnMvcxOo25UMRFiLVUxDC3z9121LZZ81Au47tJyTpcgxE4zXRxkGa6JCaFvK3zM exug== X-Gm-Message-State: APjAAAXSJ7KaqpHythv+RH+4LHa4hYPl8LRM4irIZWl2wmxhJwaY4k1B xEuvFAybz/OwOynB6wEtiiC6THPG/HU= X-Google-Smtp-Source: APXvYqwnDrDWX+L0fp6Do2eZPrPCoBAMHtEv+hkR1IJsicJg2WOcQSPb6eyVYRQC2wc+ZKfWDjfBBQ== X-Received: by 2002:a2e:63da:: with SMTP id s87mr2372226lje.79.1569339048737; Tue, 24 Sep 2019 08:30:48 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id z128sm525818lfa.1.2019.09.24.08.30.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Sep 2019 08:30:48 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Tue, 24 Sep 2019 18:30:19 +0300 Message-Id: <1569339027-19484-1-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [Xen-devel] [PATCH V5 0/8] iommu/arm: Add Renesas IPMMU-VMSA support + Linux's iommu_fwspec X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Oleksandr Tyshchenko , julien.grall@arm.com, sstabellini@kernel.org, volodymyr_babchuk@epam.com, Yoshihiro Shimoda MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Oleksandr Tyshchenko The purpose of this patch series is to add IPMMU-VMSA support to Xen on ARM. Besides new IOMMU driver, this series contains "iommu_fwspec" support and new API iommu_add_dt_device() for adding DT device to IOMMU and many other things. The IPMMU-VMSA is VMSA-compatible I/O Memory Management Unit (IOMMU) which provides address translation and access protection functionalities to processing units and interconnect networks. Please note, this driver is supposed to work only with newest R-Car Gen3 SoCs revisions which IPMMU hardware supports stage 2 translation table format and is able to use CPU's P2M table as is if one is 3-level page table (up to 40 bit IPA). ---------- This driver is based on Linux's IPMMU-VMSA driver from Renesas BSP: https://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas-bsp.git/tree/drivers/iommu/ipmmu-vmsa.c?h=v4.14.75-ltsi/rcar-3.9.6 and Xen's SMMU driver: xen/drivers/passthrough/arm/smmu.c Although Xen driver has a lot in common with Linux driver, it is not a "direct ported" copy and should be treated as such. The major differences compare to the Linux driver are: 1. Stage 1/Stage 2 translation. Linux driver supports Stage 1 translation only (with Stage 1 translation table format). It manages page table by itself. But Xen driver supports Stage 2 translation (with Stage 2 translation table format) to be able to share the P2M with the CPU. Stage 1 translation is always bypassed in Xen driver. So, Xen driver is supposed to be used with newest R-Car Gen3 SoC revisions only (H3 ES3.0, M3-W+, etc.) which IPMMU H/W supports stage 2 translation table format. 2. AArch64 support. Linux driver uses VMSAv8-32 mode, while Xen driver enables Armv8 VMSAv8-64 mode to cover up to 40 bit input address. 3. Context bank (sets of page table) usage. In Xen, each context bank is mapped to one Xen domain. So, all devices being pass throughed to the same Xen domain share the same context bank. 4. IPMMU device tracking. In Xen, all IPMMU devices are managed by single driver instance. So, driver uses global list to keep track of registered devices. ---------- Series was tested on R-Car Gen3 H3 ES3.0/M3N ES1.0 based boards using current staging (df29d03 libxc/x86: avoid certain overflows in CPUID APIC ID adjustments) in a system with several DMA masters being assigned to different guest domains. Guest domain reboot, destroy/create are functional. You can find the whole series here: repo: https://github.com/otyshchenko1/xen.git branch: ipmmu_upstream5 You can find previous discussions here: [V1] https://lists.xenproject.org/archives/html/xen-devel/2019-06/msg01755.html [V2] https://lists.xenproject.org/archives/html/xen-devel/2019-08/msg00253.html [V3] https://lists.xenproject.org/archives/html/xen-devel/2019-08/msg01948.html [V4] https://lists.xenproject.org/archives/html/xen-devel/2019-09/msg01255.html Also, please note, there is a patch in ML which is intended to address the main TODO in the IPMMU-VMSA driver (I am about to send non-RFC version): https://lists.xenproject.org/archives/html/xen-devel/2019-09/msg00973.html For convenience: 1. iommu/arm: Add iommu_helpers.c file to keep common for IOMMUs stuff A-b 2. iommu/arm: Add ability to handle deferred probing request R-b 3. xen/common: Introduce _xrealloc function -none- 4. xen/common: Introduce xrealloc_flex_struct() helper macros R-b 5. iommu/arm: Add lightweight iommu_fwspec support -none- 6. iommu: Order the headers alphabetically in device_tree.c new 7. iommu/arm: Introduce iommu_add_dt_device API -none- 8. iommu/arm: Add Renesas IPMMU-VMSA support A-b/R-b Oleksandr Tyshchenko (8): iommu/arm: Add iommu_helpers.c file to keep common for IOMMUs stuff iommu/arm: Add ability to handle deferred probing request xen/common: Introduce _xrealloc function xen/common: Introduce xrealloc_flex_struct() helper macros iommu/arm: Add lightweight iommu_fwspec support iommu: Order the headers alphabetically in device_tree.c iommu/arm: Introduce iommu_add_dt_device API iommu/arm: Add Renesas IPMMU-VMSA support xen/arch/arm/domain_build.c | 22 +- xen/arch/arm/platforms/Kconfig | 1 + xen/common/xmalloc_tlsf.c | 113 ++- xen/drivers/passthrough/Kconfig | 13 + xen/drivers/passthrough/arm/Makefile | 3 +- xen/drivers/passthrough/arm/iommu.c | 56 +- xen/drivers/passthrough/arm/iommu_fwspec.c | 97 ++ xen/drivers/passthrough/arm/iommu_helpers.c | 84 ++ xen/drivers/passthrough/arm/ipmmu-vmsa.c | 1333 +++++++++++++++++++++++++++ xen/drivers/passthrough/arm/smmu.c | 48 +- xen/drivers/passthrough/device_tree.c | 77 +- xen/include/asm-arm/device.h | 7 +- xen/include/asm-arm/iommu.h | 10 + xen/include/asm-arm/iommu_fwspec.h | 68 ++ xen/include/xen/device_tree.h | 7 + xen/include/xen/iommu.h | 21 + xen/include/xen/xmalloc.h | 13 + 17 files changed, 1895 insertions(+), 78 deletions(-) create mode 100644 xen/drivers/passthrough/arm/iommu_fwspec.c create mode 100644 xen/drivers/passthrough/arm/iommu_helpers.c create mode 100644 xen/drivers/passthrough/arm/ipmmu-vmsa.c create mode 100644 xen/include/asm-arm/iommu_fwspec.h