From patchwork Fri Jun 16 19:02:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13283174 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 48569EB64D8 for ; Fri, 16 Jun 2023 19:05:34 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pGJcIsw0QsfUPFVDxGqaFIUEc+I4M5hQOFufGa0cDF4=; b=TnxaNpJUHKcv2m xMbEuQ3FGSCbcO6nN6Ui6WKgtmZZBhuURg6SyqaTzt4uWCk94Sy0mh2Buo+6OgNCsfy7dAcUUHS+r YktObMjPctDDOZCeKmGHLc76D+Gp5U21zJYNvuTcOarLv0bgCak1rsi98wf4wqhpRP/Wp/NpDHcwh VpKIT/Vm1e5DdjNxtAZmEdIEwPEa96dGhZG+BPfe8mGrYOfycKRLt5Whn6/df23aFCGTlMjKI/91J ZOtJFOm0mX/Ln8/sAQLBgNzLRA163LQWXtvafe5aOmpA0ka0TdgkE5+VsgLhdzDfszOOKfynfQFMt Qk7pEDMdAfUBqQuf9wnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAEkx-001YwH-0z; Fri, 16 Jun 2023 19:05:11 +0000 Received: from mail-bn7nam10on2062f.outbound.protection.outlook.com ([2a01:111:f400:7e8a::62f] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAEj4-001X1S-36; Fri, 16 Jun 2023 19:03:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bD0zS4K2sVuyELWL3hRonA2MHNgWezjEQSxmDwmjmv+berYiVbLikiW7pPYMO3vT78bzs6yS/+ftytBfz6fxoqa3jjGioteUINZZV3gm+GblFxbEHFUQ3p2BQ/yT8VFWBsnbsUrHeKwE1I9tDKUgvu8U8I7x9pIZmI3gSZT8+a/x0vPnpDkJEQtNbRoF7p7iR/vjv284Ap8icfjfN/wCOuHDopeYA/UywB5A0VYPP3bhKULPZQJuljn/qydHtiEhBBuL8SK74c9fI5GkOIyKcL5vxQHpxjuoqR7qVJA7ZPy8hQrPeB6Z9K9il5Eb/rh9Xz1TI8gS7oul1iWvXfJw7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=EMhb/bqTdUCpbXJCspFn2zl/ilrxq2bDon6W8QDV/+g=; b=blZFmr6lfF2wHhhQ5jeqim4fOgEVmjHJtOOIr2hxOvjEa36DJA1C+sBtdf46iGRZg1FVG0b0d6nfP2u87qAL9gBFXqmkBUZVp9xX+g01/EtMmFMugnVusVpRZdB+w7zGdKOcaLLx4Wy9TnVNISiSaDNknEXz+OMxhh4P0jq2U1nAGz19pC7INb5jbqj2UCUJKTjrSe7dZ9myN4wDw+Pl1TaqlUiLXJLUhtGXVBIsujIlH4czf842a2Y/1KoLMXzfuFqEQBIC0N6/CGuxzXpCVTYxA0+vrnPeS9s3S0lozc46eSVqpc8zvrCg4FPh2uyVSf2aFi67dPhtMXrB/sJh0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EMhb/bqTdUCpbXJCspFn2zl/ilrxq2bDon6W8QDV/+g=; b=R6I2cXDndKw+KeHvPFc7L1I619RqdH0S89sIVgR2sGLrsxTFuTae/hv+a8ksoe6Heux6UeJ0tYuDtihRf+Gjz+rOXZg/RtSUOjbOgaUN0otJ8dgN8pfwxS3DoyYeQF7xzolznRT+SaT0oFHfDea+UUKztt0voqAhYNaCPu846iPCrJLfZ4dX2GV+zN9saONiz8qhbyNfz7AZPOdO6bCdoiS8o8XyJdWfsBNEdHNXUVUuJMvtXJZ21zlp5nH7spd500ZngM2hJ63i8aobdeSS0pDi+tA3SxTE0FfyNEXWayJBy6VtZLcMqLQWI2+m6CIQ1QkZ5W/DxOim1D/K3XdDWw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SJ1PR12MB6051.namprd12.prod.outlook.com (2603:10b6:a03:48a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 19:03:04 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 19:03:04 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v4 18/25] iommu/ipmmu: Add an IOMMU_IDENTITIY_DOMAIN Date: Fri, 16 Jun 2023 16:02:47 -0300 Message-Id: <18-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v4-874277bde66e+1a9f6-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR20CA0066.namprd20.prod.outlook.com (2603:10b6:208:235::35) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ1PR12MB6051:EE_ X-MS-Office365-Filtering-Correlation-Id: ed5521ff-d650-4346-696f-08db6e9c4ba4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bZn5cnTWJDJlrabgJ0rhSoyddOG9zJp3Je/B7LxGj0rOuhx+Mnt/EWb3FlHGqpNNnZfcxNmkyG4CV7mrLr5aDjPKdfJcbFW9yLjujiurECZ0bIyHvgQg/Apla7KDcRFbw29daLUgkrjOtbm5KG96XqL0ZMg5aYrnBBimKJIKdqnH79OwhF2UmT4OcbdXGi0GapHszD7F0sVcorDxY53Lg0sAbDXkqOiGdZf8bm5/0Jje0lhEY+9RUUCTr8PV6rM+E1lFVuGBcF8wmmlcXnVNnqLO29ZP5vnUAky5kah0eg/kfCZJluUd/P5EysmThedMd/qdKiKn/eT9KtNVkbk289K8xaKRt6LZI89y5JXbP4+382f+E2YsgiKFit/3X8gFnO75iLDc8w6jq9TPC3PWSmEoOkAxZYeoVyVJ8C0abyRwj4Y8Z49j+oo/xLHDyVhYcPKCyWXs91zEo0zdgFPe5S9ySLu/8FGnL4OXwLsVk7dylELywv9Sok3r/jvgQ/QQTg/Xicy+/Lvc0yPNzGr+XvNLq2MC+Xi8py/Hm6v4FbLTn0uvEoZ7/yZN4UpA6PHPFlHOHyq7uGtyypIQqy+bSI5xbip07Rt7nZJqR5jX6z4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(36756003)(86362001)(921005)(38100700002)(8676002)(8936002)(5660300002)(107886003)(66556008)(316002)(478600001)(66476007)(66946007)(4326008)(6666004)(6486002)(186003)(7416002)(6506007)(54906003)(7406005)(110136005)(41300700001)(26005)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GXD7G2z5GYJOQSMDizAjxSxIOcU68V/jvY0vZN+0OD0kMh4GvgbHYtOBLJzq8DZBKYjIYIT/xIXzZb594y9ws6FicoaC5iWtOotcLpGV704IXRCvir4JTPX0ggUy+usvs7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1zQqpyEz7RJ898UvIxNAmFNDZcG4MTqK2rzYppeCv60EvWC0iPkQxL+MXO7SZ7U6tGObVXCS013da+v13cCPhFBBkanXsSVYAMKIswOSerSDB33dRV7g9eRGEKO0fgpilD8K8OHAPFQCER+fB+f91n0mx1U9sMLZz6wrnOb4bNOkgyWP1QS7ZiLjV5RCM4wAcCcGsj4St7Fs1O9rHhPbfDIHh/JHofSdPo+2hkVZF46iB5OgLlcU1azsSKjt0JnTURvgQqhZFlt0mHCRcr8ySllZwpQ1JHpD3rvoUhD7p8t3vU5Ud3WPxbpYjIHmJKUHwXIJis55GEsQP/wBEHyMb4gdmlpw/kKjJGLxzGnKITxsu4xeMdc3SQM3rzXfoM0nKBrDFkynWFscMSazWY21oo X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed5521ff-d650-4346-696f-08db6e9c4ba4 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 19:02:56.7333 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RNuzraxebkN9dWjZ06vF/yWaQS9qiY8lvzjEKypJ/IAzbJ81unqhkIf64+3xF8Vc X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6051 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_120315_030658_C74D0C56 X-CRM114-Status: GOOD ( 13.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This brings back the ops->detach_dev() code that commit 1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it into an IDENTITY domain. Also reverts commit 584d334b1393 ("iommu/ipmmu-vmsa: Remove ipmmu_utlb_disable()") Signed-off-by: Jason Gunthorpe --- drivers/iommu/ipmmu-vmsa.c | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 9f64c5c9f5b90a..de958e411a92e0 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -298,6 +298,18 @@ static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain, mmu->utlb_ctx[utlb] = domain->context_id; } +/* + * Disable MMU translation for the microTLB. + */ +static void ipmmu_utlb_disable(struct ipmmu_vmsa_domain *domain, + unsigned int utlb) +{ + struct ipmmu_vmsa_device *mmu = domain->mmu; + + ipmmu_imuctr_write(mmu, utlb, 0); + mmu->utlb_ctx[utlb] = IPMMU_CTX_INVALID; +} + static void ipmmu_tlb_flush_all(void *cookie) { struct ipmmu_vmsa_domain *domain = cookie; @@ -630,6 +642,36 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain, return 0; } +static int ipmmu_iommu_identity_attach(struct iommu_domain *identity_domain, + struct device *dev) +{ + struct iommu_domain *io_domain = iommu_get_domain_for_dev(dev); + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct ipmmu_vmsa_domain *domain; + unsigned int i; + + if (io_domain == identity_domain || !io_domain) + return 0; + + domain = to_vmsa_domain(io_domain); + for (i = 0; i < fwspec->num_ids; ++i) + ipmmu_utlb_disable(domain, fwspec->ids[i]); + + /* + * TODO: Optimize by disabling the context when no device is attached. + */ + return 0; +} + +static struct iommu_domain_ops ipmmu_iommu_identity_ops = { + .attach_dev = ipmmu_iommu_identity_attach, +}; + +static struct iommu_domain ipmmu_iommu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &ipmmu_iommu_identity_ops, +}; + static int ipmmu_map(struct iommu_domain *io_domain, unsigned long iova, phys_addr_t paddr, size_t pgsize, size_t pgcount, int prot, gfp_t gfp, size_t *mapped) @@ -848,6 +890,7 @@ static struct iommu_group *ipmmu_find_group(struct device *dev) } static const struct iommu_ops ipmmu_ops = { + .identity_domain = &ipmmu_iommu_identity_domain, .domain_alloc = ipmmu_domain_alloc, .probe_device = ipmmu_probe_device, .release_device = ipmmu_release_device,