Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2243155pxb; Sat, 28 Aug 2021 08:40:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfCg5iTMyNfIpwA9Yu00eCRfyCP76X8GYNvFR+Rrltwj3wgJO4n3VPbFdJDSKCg14NpDy9 X-Received: by 2002:a05:6e02:e8b:: with SMTP id t11mr10123618ilj.175.1630165208685; Sat, 28 Aug 2021 08:40:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630165208; cv=none; d=google.com; s=arc-20160816; b=CpezN/b/4nARO/uZYVcZB2AQqZ4gy4NCeVaugv41CSedpaCD+Y7nD1/4ynNQIaQocM WtOE+/wgcjiBdnVsxRn+lNm5CL3geY2UAzhO3aLp97vUtJgJs41SwdOOO8h6H1ttUfpg IY8vvYfT26fF43ZLByVCtGhVsUQQoT8GYd58eicyqhMGWYaeJvOkRwsp37Te3KfeQGzo Nq9L/VLSN0oG5vpq5xbLgIwWwiANm+Fpvtxny7kDRDWvDyzMdZ2MO77A/Ig0OuBfLTu4 trT0Vt55Xgl3J8SLI+C7jTD77N5Vu/t7PqR+b/Z+lcvkKNbH/g1zkvKb6xXWkyNyJkvX KGzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=Ir6zYPhgUh57BI7mV5KU6yepjS2qUU8+bficl9p0lPg=; b=iplowr99AMB/9zx/yyyny68LKzAvjCANCWU4g1Omf44Id6I7rnY8qW/KmEL3wbhCfI tneOd/VsgJp5804uYfesgETBFE7ljLxJ+h07+GlgweCH4WeiCXGhrpH6MyX1Dq0fF/8Y 0vP6X1Zh2kpb6fyxso/zTFZAcpxYl5RbYBQLAs7V/PLnL24a59xhxA7WGsqecZ4pXjHX ZmHvg857IaoBuo0N37RHkQR+UyfSGY5scSOzawPo7B7M6RRDtnQFpXmiFprVe3AC9uhC ALMHbCX7Yzvo90D6YdUksbXHHsd8RFtjPgd+JVSiqhP0srpsEkFp/Gbgmwl9Xj9s1j8m T7xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm2 header.b=ZzqtN+xt; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b="P6S4b/wG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g18si12141847jat.54.2021.08.28.08.39.39; Sat, 28 Aug 2021 08:40:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm2 header.b=ZzqtN+xt; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b="P6S4b/wG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230290AbhH1PjH (ORCPT + 99 others); Sat, 28 Aug 2021 11:39:07 -0400 Received: from new3-smtp.messagingengine.com ([66.111.4.229]:46913 "EHLO new3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229911AbhH1PjG (ORCPT ); Sat, 28 Aug 2021 11:39:06 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 6BF45580A6B; Sat, 28 Aug 2021 11:38:12 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sat, 28 Aug 2021 11:38:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm2; bh=Ir6zYPhgUh57BI7mV5KU6yepjS 2qUU8+bficl9p0lPg=; b=ZzqtN+xtBikn+rG2Af9z4cjrVsDvKJxCwzO9123bSk pqNYi02jgREEdC3Ty7ZZWni9O0fwjxzHeIswiucb7WUL6uelpXtLOmCeVuzMhoEp Dz4/0aKGZIWD59YT39DCkU0LDAEHPFtwrADIbvQR+5OCFdWO/AombyleJK4vPBYu o2OeKhxK34EbY+GyfriNm7+/IB5KjVB8OGPqDhd/a/vKUI0HRYqAH3l0g/PpjrYc xGT04Hyb2CmgAgmtEqI63TTrNuluR15Dn1UnK7KFYPDNIk+3XfZ2jwsAHG8i/PqN eUbHYo7DN9E/YCwcThx+Mw5+RGAzp27FOzwy+KPwy+lQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=Ir6zYPhgUh57BI7mV 5KU6yepjS2qUU8+bficl9p0lPg=; b=P6S4b/wGEncaiDS5vyzG1TU63TRTfOr/H aOzU0Y0kbTdO+qonIP5uWUE01Tpa74bsnvSuoZJnlqAxYeZfJEwVkvF+d2z98hDF 4MLXetPamxLvlMIJg8bJm/npGEKX2kdIjesLRzzivyj2e5u7Wv7FYIet2BcoD6s4 8Hd35pKzxEkdDhyvF9ZdZA9mvco25XQarujj4oCR6p1YuJR+zSF7ge3JUyV7zLA9 MgMVi3L0JWphoCXtDu4t14aeeWZw1cLKspFadxsUatCVW9tlh4tS7ALYmRelvOYB Dkgbg+P7atQXyUe1WX/MKyuwfLE0IkAqjoTyvjg4DG+Xtiyl9ML0g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudduhedgleduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpefuvhgvnhcurfgv thgvrhcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrfgrthhtvghrnh epfeehudeftddvhfehvdduhedtjeejheeuudfftdfgvdekvdelleeuveelgfeflefgnecu ffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehsvhgvnhesshhvvghnphgvthgvrhdruggvvh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 28 Aug 2021 11:38:07 -0400 (EDT) From: Sven Peter To: iommu@lists.linux-foundation.org Cc: Sven Peter , Joerg Roedel , Will Deacon , Robin Murphy , Arnd Bergmann , Mohamed Mediouni , Alexander Graf , Hector Martin , Alyssa Rosenzweig , linux-kernel@vger.kernel.org Subject: [PATCH v2 0/8] Support IOMMU page sizes larger than the CPU page size Date: Sat, 28 Aug 2021 17:36:34 +0200 Message-Id: <20210828153642.19396-1-sven@svenpeter.dev> X-Mailer: git-send-email 2.30.1 (Apple Git-130) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org RFC Patch: https://lore.kernel.org/linux-iommu/20210806155523.50429-1-sven@svenpeter.dev/ Hi, After a very helpful discussion with Robin Murphy on the RFC, here's v2 that is slowly starting to look sane. I've been running this code for two weeks now and mainly tested it with usb storage devices connected to dwc3 and to xhci over pcie on the M1. Some background: On the Apple M1 the IOMMUs are hardwired to only support 16 KB pages. We'd still like to boot Linux with 4KB pages though because that's what most distros ship these days. This patch series adds support for that setup to the IOMMU DMA API. This is essentially done by always mapping the encapsulating IOMMU page and adjusting the returned iova offset. There are also changes to only allow DMA domains to make use of this and prevent UNMANAGED domains from encountering unexpected situations. For untrusted devices the allocation size is simply aligned to iovad->granule if they don't already go through the swiotlb path. I have not been able to test that part so far though since there's no Thunderbolt support for the M1 yet. The series is based on top of iommu/next (and without the last commit probably also on iommu/core). It won't apply cleanly on apple/dart since it already takes Robin's DMA domain cleanup series into account. Best, Sven Sven Peter (8): iommu/dma: Align size for untrusted devs to IOVA granule iommu/dma: Fail unaligned map requests for untrusted devs iommu/dma: Disable get_sgtable for granule > PAGE_SIZE iommu/dma: Support granule > PAGE_SIZE in dma_map_sg iommu/dma: Support PAGE_SIZE < iovad->granule allocations iommu: Move IOMMU pagesize check to attach_device iommu: Introduce __IOMMU_DOMAIN_LP iommu/dart: Remove force_bypass logic drivers/iommu/apple-dart.c | 14 +-- drivers/iommu/dma-iommu.c | 172 ++++++++++++++++++++++++++++++++----- drivers/iommu/iommu.c | 36 +++++++- drivers/iommu/iova.c | 7 +- include/linux/iommu.h | 8 +- 5 files changed, 197 insertions(+), 40 deletions(-) -- 2.25.1