From patchwork Wed Oct 16 06:52:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tomasz Jeznach X-Patchwork-Id: 13837809 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6FC5D206A0 for ; Wed, 16 Oct 2024 07:00:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=JDLuN8TFwnusP/243eKYNQKjmpfY6MCZfGvkC4vyAJ4=; b=aX7kCE0+Ef6qyy tbqkGoaSo4DBEU+v9insrIUTqH1sZrB74wxQb4n4hTkCf9HGhN2OYdJn7esCD3E7xPPs1trpENZLa tv79VPAqHpKEKYlcJ5Oy70ZIO6mz73wy+ct3kKi6zSGItqKTqSaEF9l/5DbSWToelidg1oriBnm/1 U6YY72Z7pUohV5HD1/2igL3IpIfK8JkzkJ3A5PWb+Qelw9qZJZ1m7m8EIK5yIJmLSaJv7r/F+fKS6 BxXCinsnfiWhNzzCHxMUF1RV4P1hHk2U8b7eJBKdyu5JB0JbENHC+YaZsosvlE63AKs4gRctd/Q+9 MZFFspeoZgZ6OA1nF5Wg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0y1Z-0000000AlS0-42uP; Wed, 16 Oct 2024 07:00:49 +0000 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t0xtT-0000000AjmT-3QH3 for linux-riscv@lists.infradead.org; Wed, 16 Oct 2024 06:52:29 +0000 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-7e6cbf6cd1dso4326628a12.3 for ; Tue, 15 Oct 2024 23:52:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1729061547; x=1729666347; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=edrP7O7a6NncjkyeVVAJ0jiJhAYB2+mktJx+SnmTMmo=; b=DvNOTmHRvVNEB4Oh3D0kBRaZYLHP0AwLzysm0gXly379maJpYAYjmRTWo/kGOPB1KZ UVFUS0sTsAJuslQ6ahUKuirHwIaK0xI8UJA4wwWtiBDNCyKMo13h90Rct6BFxy33GI6G YdQxn40sDHs+QchJaKIjLIsMUImRLjjCjXXKkL+WCUvBSfk1HrKJdTMllxDNPmqkobZz AdSmIEf37xZderOEJ9XYAFo2OcgUFT5MVfvofLc75dZffmxAeJsHZqIdVstjuHU9+BaL EPLVXExzGlgC3129V4lB0tXk54oTCiCta5ZsoIe5+nitlEy26xZz8YlhP8kxhFqn4sp5 KfKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729061547; x=1729666347; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=edrP7O7a6NncjkyeVVAJ0jiJhAYB2+mktJx+SnmTMmo=; b=cx8n6XMbIjAcrwPZb0kfUUkg4MFL84K1ueR1ClS4QQ6pyTgA6FDFodSYnMvRHkxozx TcaZIi6Siw7rr9EUBMvLHJB+TGKEJr27Ivu7SAT3CmV3vHUp/+tagCZhG75UDl2VEWnv c5C2aqHjuCch6Pitz/H98MECLK2IFSy4bc+vHrvBOR7+Yp1Tpf3Wz9GfoslX7bka7I68 2p1CyBS3NXUd4ZDo8ji3LUbio2pO1CDnirCGUnZXwQgyCO8i9RKkwWCtUFyeDYBPEDM6 b0kbadeoTiTXubFXHpExQ034mLoulWojaFsQNGmqIsEy/dhSRDmk0CZfK5bF9srg7Jiw TZCA== X-Forwarded-Encrypted: i=1; AJvYcCVFmY5aQYj8UvvtR/BACGB5m+34Xpr3nihIHQDLqCBmxiHNGVqa+wMpnT5ueYATU3W6PFchxf/lKM4ygg==@lists.infradead.org X-Gm-Message-State: AOJu0Yy70UkcXOveHXeCJOpgSfXYSDAHKVM5+OMMSRbofNAs8CzbJagy eo5FmCfspgQIxeawXceQStKsC+hw9v3dapfK2bSSJ7lOP/h8odcIm0dtYjYgIbI= X-Google-Smtp-Source: AGHT+IHFpMiQBbiEBTkmPNQuDjgrwQrsX5LcLAK0wa6OKlIr/7npj2NUGYvuYiUcx/vU1hhIAlG0YA== X-Received: by 2002:a05:6a20:c888:b0:1d0:3a32:c3f8 with SMTP id adf61e73a8af0-1d8bcfaa0ffmr23847001637.39.1729061546751; Tue, 15 Oct 2024 23:52:26 -0700 (PDT) Received: from tjeznach.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77370a83sm2410762b3a.5.2024.10.15.23.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2024 23:52:26 -0700 (PDT) From: Tomasz Jeznach To: Joerg Roedel , Will Deacon , Robin Murphy , Paul Walmsley Subject: [PATCH v10 0/7] Linux RISC-V IOMMU Support Date: Tue, 15 Oct 2024 23:52:12 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241015_235227_894078_D21A6D9C X-CRM114-Status: GOOD ( 15.74 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , devicetree@vger.kernel.org, Conor Dooley , Albert Ou , Tomasz Jeznach , linux@rivosinc.com, linux-kernel@vger.kernel.org, Rob Herring , Sebastien Boeuf , iommu@lists.linux.dev, Palmer Dabbelt , Nick Kossifidis , Krzysztof Kozlowski , linux-riscv@lists.infradead.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This patch series introduces support for RISC-V IOMMU architected hardware into the Linux kernel. The RISC-V IOMMU specification, which this series is based on, is ratified and available at GitHub/riscv-non-isa [1]. At a high level, the RISC-V IOMMU specification defines: 1) Data structures: - Device-context: Associates devices with address spaces and holds per-device parameters for address translations. - Process-contexts: Associates different virtual address spaces based on device-provided process identification numbers. - MSI page table configuration used to direct an MSI to a guest interrupt file in an IMSIC. 2) In-memory queue interface: - Command-queue for issuing commands to the IOMMU. - Fault/event queue for reporting faults and events. - Page-request queue for reporting "Page Request" messages received from PCIe devices. - Message-signaled and wire-signaled interrupt mechanisms. 3) Memory-mapped programming interface: - Mandatory and optional register layout and description. - Software guidelines for device initialization and capabilities discovery. This series introduces RISC-V IOMMU hardware initialization and complete single-stage translation with paging domain support. The patches are organized as follows: Patch 1: Introduces minimal required device tree bindings for the driver. Patch 2: Defines RISC-V IOMMU data structures, hardware programming interface registers layout, and minimal initialization code for enabling global pass-through for all connected masters. Patch 3: Implements the device driver for PCIe implementation of RISC-V IOMMU architected hardware. Patch 4: Introduces IOMMU interfaces to the kernel subsystem. Patch 5: Implements device directory management with discovery sequences for I/O mapped or in-memory device directory table location, hardware capabilities discovery, and device to domain attach implementation. Patch 6: Implements command and fault queue, and introduces directory cache invalidation sequences. Patch 7: Implements paging domain, using highest page-table mode advertised by the hardware. This series enables only 4K mappings; complete support for large page mappings will be introduced in follow-up patch series. Follow-up patch series providing MSI interrupt remapping, complete ATS/PRI/SVA and VFIO/IOMMUFD support are available at the GitHub [2], and has been tested with published QEMU RISC-V IOMMU device model [3]. Changes from v9: - rebase on v6.12-rc3 - #6 Memory ordering fix and updated commentary, based on Will’s suggestions. - #7 Remove riscv_iommu_device_domain_type() and use head-less kfree_rcu in riscv_iommu_release_device(), based on Jason's suggestions. Best regards, Tomasz Jeznach [1] link: https://github.com/riscv-non-isa/riscv-iommu [2] link: https://github.com/tjeznach/linux/riscv_iommu.next [3] link: https://lore.kernel.org/qemu-devel/20241004155721.2154626-1-dbarboza@ventanamicro.com/ v9 link: https://lore.kernel.org/linux-iommu/cover.1728579958.git.tjeznach@rivosinc.com/ v8 link: https://lore.kernel.org/linux-iommu/cover.1718388908.git.tjeznach@rivosinc.com/ v7 link: https://lore.kernel.org/linux-iommu/cover.1717612298.git.tjeznach@rivosinc.com/ v6 link: https://lore.kernel.org/linux-iommu/cover.1716578450.git.tjeznach@rivosinc.com/ v5 link: https://lore.kernel.org/linux-iommu/cover.1715708679.git.tjeznach@rivosinc.com/ v4 link: https://lore.kernel.org/linux-iommu/cover.1714752293.git.tjeznach@rivosinc.com/ v3 link: https://lore.kernel.org/linux-iommu/cover.1714494653.git.tjeznach@rivosinc.com/ v2 link: https://lore.kernel.org/linux-iommu/cover.1713456597.git.tjeznach@rivosinc.com/ v1 link: https://lore.kernel.org/linux-iommu/cover.1689792825.git.tjeznach@rivosinc.com/ Tomasz Jeznach (7): dt-bindings: iommu: riscv: Add bindings for RISC-V IOMMU iommu/riscv: Add RISC-V IOMMU platform device driver iommu/riscv: Add RISC-V IOMMU PCIe device driver iommu/riscv: Enable IOMMU registration and device probe. iommu/riscv: Device directory management. iommu/riscv: Command and fault queue support iommu/riscv: Paging domain support .../bindings/iommu/riscv,iommu.yaml | 147 ++ MAINTAINERS | 9 + drivers/iommu/Kconfig | 1 + drivers/iommu/Makefile | 2 +- drivers/iommu/riscv/Kconfig | 20 + drivers/iommu/riscv/Makefile | 3 + drivers/iommu/riscv/iommu-bits.h | 784 ++++++++ drivers/iommu/riscv/iommu-pci.c | 120 ++ drivers/iommu/riscv/iommu-platform.c | 92 + drivers/iommu/riscv/iommu.c | 1661 +++++++++++++++++ drivers/iommu/riscv/iommu.h | 88 + 11 files changed, 2926 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/iommu/riscv,iommu.yaml create mode 100644 drivers/iommu/riscv/Kconfig create mode 100644 drivers/iommu/riscv/Makefile create mode 100644 drivers/iommu/riscv/iommu-bits.h create mode 100644 drivers/iommu/riscv/iommu-pci.c create mode 100644 drivers/iommu/riscv/iommu-platform.c create mode 100644 drivers/iommu/riscv/iommu.c create mode 100644 drivers/iommu/riscv/iommu.h base-commit: 8e929cb546ee42c9a61d24fae60605e9e3192354 Acked-by: Palmer Dabbelt