From patchwork Mon Feb 26 17:07:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13572526 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 EB429C5478C for ; Mon, 26 Feb 2024 17:09:03 +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=s9BPs2JEWBJA3d0fyyDtL18V/eIkdK02CBEGKfHeKQc=; b=cIJBJRToXkmI8i rwVas7uNGToJZGt6RUR/o2iDzuaUgXdSkjqPkwji78N1+Jh5Hol/mvOXLa9Y0x9VY9pspOPvhVzfL BtandSv0aekmTAGCmRoLaFHA96+qODPGQTeaxBOkTPS7mOwtApsUJVI5J+W9v71HGy+t5DKpY6big hto4PR5UL0+Co9P/BvXHGQGs+yZM0ul2uh6lHWr0a9rxk5ynZEmHxZQob/+gYimo82WlhN4Vy0qZh 9jn7BkVqMJ5qWkrlu/odK7lDRi+Yqe8Zmb8O+G7v0PYAu7XHHM87ErRusbCikxxl8CsB1WHtADh9L biHuHkA0HVFbvu7qUGgg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeT9-00000001qKC-38Ms; Mon, 26 Feb 2024 17:08:47 +0000 Received: from mail-dm6nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2417::601] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reeS7-00000001pjD-3Hmr for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2024 17:07:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kharzl4TjagmRfR25HtxBDQquL3yLY43k9T9M+cyDlS72Qf3NrxUZpDPPG5q23ypQfixljs8MDPqOI/gEFvEqwtv0XzEf70MgLM7IHRAYh6BXHoXymehiaenGRWKMS8M1VXLUsqtwHhGwSlDy1wiafpYw3MhXRPhAqSQsl78eZIMAVV1vzul7q85aAfDEgtbsVgS+U5PPnzEPvEQ55KY6WKeLpqSbzeASgdFera7Ox3Mp/Zc42kLbQ/X47SoFaBhbK0ucB6fKU6WQMeYcuAxX04sJYLX+eYUgExvndav8Sq9MbF/uJAARw4DD9dmrGchMiILGnWO6eDvdiJZUUAE+g== 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=WT5WpzhVRk5h+mxlCBtaMXTz2F5qzBR0/9sy9KnolEo=; b=Jp81lN1XlAahBhEdyd9VLPETfV6f7KSfOc6vZPUpyP4nffFqHvlU0CWt+ElT+a+mgG2LPlTSNphB3mElsEsf+AFVmhQxHqtsagRPic2rtzgMNASDWlT1YtuYkUJVhV4fn6O2G0exWVKkiIQvOhoOkit0SVuEuFfdCX8OFtuIcrgTIiBsMgDPZm8V8J+a5eh4+ITf5ValfoXgAD6dCiuHGdYJjlIqM9J86cKZ4Zn996HZppV5QBpe25NraLGcbdbr59clkwYvtqoFIYkgHnvur3uIHxFAfddUStH93haH+GB2xCZqvDrMoXUgWBpyUpAsOARO6Mj1aV+uiYf06fDCRQ== 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=WT5WpzhVRk5h+mxlCBtaMXTz2F5qzBR0/9sy9KnolEo=; b=ncpnqi17JjmxzvVtCxgsQbByNC+rnu0xwXUcTifzoAIVmfZVH7+luoqYGOoVqyUipnmNoLj/z1gGv0CMCbpkUx+GQOmVH0Wl8SEurz/HehcZd12A1snBfBC0HBPWzIMKA2oVuaWZcH0R/7hOkrWKukfjBrTydkp2pZvpePOtkhMkoXawBoT9p/YKzgkgwlAaC98YtjnkH4rz1rXaccK4m7ENRkkTm3USuMzo/aKRqTBrTbMRvvkvtNyXnZgkgs9utk11slT3gBLBTGmRs86i2tqV6vZZH7COo92Z9xvsv9mtWNlOnVW+2hIRiNtWXNwxsGmRCX7nyR83CqVoOwMxAw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by PH7PR12MB6905.namprd12.prod.outlook.com (2603:10b6:510:1b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.33; Mon, 26 Feb 2024 17:07:29 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::2e3e:c7c0:84da:3941%6]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:07:29 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Lu Baolu , Jean-Philippe Brucker , Joerg Roedel , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameerali Kolothum Thodi , Mostafa Saleh , Zhangfei Gao Subject: [PATCH v6 11/16] iommu/arm-smmu-v3: Check that the RID domain is S1 in SVA Date: Mon, 26 Feb 2024 13:07:22 -0400 Message-ID: <11-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v6-96275f25c39d+2d4-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR03CA0026.namprd03.prod.outlook.com (2603:10b6:208:23a::31) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|PH7PR12MB6905:EE_ X-MS-Office365-Filtering-Correlation-Id: 52c8e0ac-9f5c-436e-822f-08dc36ed69c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: az4D3yDGN+z2RvMx7chEhTrAI0oE1Lzg6p5FZcFzehAhPtBSBHkApX6ctfS+O8p1Pm8emhgf1yePqJyLlqp6m1e1ijPfzSF+vsm11BvyExMkoVlWD0QKVMoCvE1lFtLdwf+rCe558ZaNh5x0IXks7rhvnxA1rwJPAF1xJUBcl9JDusGQOogRUdG395r1Bfmn3WFnyaiJ9SkvBjbTDs5LhRjf3gRAwtFFSwh/NEoTG9jPOe7V5pKxR9VROnJ/sj1GG3jk25PcfI26tbm/+tzyi2yLP8kLFBm3xC5uCxqvhN/ThzV4l7Log2Hu1sFQS3qJy3zpIsk4SC94U00hNFtO1+eXCoX+X9nIBQrCE6FVTxOhnzshgdFUSs2jmIgIjWiN8C73JqZPimuxCgAdnTmRvlomOoxIVKG40TWmFPv95l9UwlVgshN1Bj8yGI3rw2AmXyMVpnaNEShwq/p05v2oxO/XaMthbvjsWN6QO38obf62Lxrejok0yGCd6Tw7i41QN/2J+Hs/JfNqpFhTVGoA6ocRzgHxK97PcP/qD40bFDtyFApJFr3jgjA76IHxUqk5ALhQzjpFC0B/qMXVa5rArhIKAFeuIAiAmCGZXq5NVNX82pllmNnyizUDUMN/Iwjk9ShrHyNGN8LpxKRmCbJZRBAomC5dpsTsk7HRIMC6Mdc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JWlrZlonR4LDNkt2r3N6tHJKRe/rpoIs2ID8QLpct89AI+DPYVR0R8JpcXFeVqnW9cDV6oM122C00WceNCCyK6tA+jKfpQO6rYfqmhmmiuolTuBMiDny+khcDSP3P8ySL3Md4146qLvuVvvkUzvfBSe/38Ybe/rIsLqx+CD09xkJJxXjKVyRZtFp0xHE8xmWF7iVQE6yfSzZF2U4AI/cRKClZhWzipcVcypfo4R1XXkDOYYn+RYvWHBwYBOVDBkMsoIaFtQNXIYLK5v7OJQO5GmH9KME1KvJrYJaYpa46E+o7ZWMngLy/Cs3EmorGcd/Pk70t0o0jYs2kQ9L99GfiXiJ9HxSgrKH0swhaD5/XgOPsQ3HBwRlw2jsWAFcAHa3T1CsToLAYEU6xBa5uTQg5eL9Yat3lQPBHnAta5HgCIhuxbuu8ViveoEdwzk48TcZJe+1Jytx4j4ep3n/m4BHqSLIMAgl1VrucSV0PederVJFzE5VW7WlTm/8fvV1Jp0W3vki+IGAXDzmY9AFudOUM3o/AWH+PO1RFiEgdJ6g0qyL3cNr8YeCSEJdgafAREC7rowJHGgf8mpp8i51Utgf/GuCGdQKbhXM2cx/e2hctTRGNE/blD1z86oSXKH9qWh8h885SSGqBvBZ/Xwn973X9nIFTo2zzrNAeff1PSuDSfqeBYXJX+P8P0PePD2lEn55sjNro6BShGFuinfvANWx9rAEnKtKHEtF3ya2+rcf9KteRGvaEsWKib6YWLqd9h7tSl/dXQC+GLYRMtKOm60Q807m6eoCbxKHKnY5XHEGccV3RWdJW1i9otnUM5Kl4scRogmAar7f91xYfr/npCML782no/lD9Yl+v8ihoEqSJY8UB0X9C7UES1G+nPDrI1QyzWEvdWbfga3DuN+Pd6z93DiG723pdCyuUE9breKKz3z/+RaLLk9AGtDRfKkkdJrzutcjK+8Ib3hPoq1ATztcJ5nGYmzrxz4gU6nC3SJ04WYN644zPAcM/zT94RR+RSYAMjlk8XZajBdOjeyVOEiAmrtOYM7HzgakR8cZ7CesI7sUjbSRR9r+NSV9lnzzdq99jNjyMzupRGCIq8xPQ9K6K5VD7xt9Ppnew8Lk8DU1REPUN7Tk+vpOmeXw6HCEb+0kSblsJl7HYc4zjDtslhQuu2ixMFcMYOXFVEN7yvSeYrFKlsjr2WmS1pPHqoAYpYRkPyu2AdWjTpgt53STE7RKKidOAIXMU4vNXOVOFDksXHCRA4s5n/urtQyicEpF8MGUOdB5+f+nRII0hxQ1Fm8aCkVH+mJGqx9aqSlaa7/XOFEDP2ddSLA5LtY+OvTGLMBQiEreC2kM+GNpQhNSaggc1Bp1/+qhQdHjKzHLmn9zBvL1WLtm9yj27AZArNVvrQNNwygi6QM3VJ0QeeTkSXwTaa56FzpBVWGt7lCWb1YXW1+rCOjwIug0IdJP+9mYWAHJEHOCgdsALED3GLEFh4R2txYKyYQ+1eKYgFqgXgoH9wupLjyBHLhHbsW235iBXR39+RhNmytm6pLwNS2WHi8KMHUc486SK7BdZb1Z+xvUuQc= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 52c8e0ac-9f5c-436e-822f-08dc36ed69c8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:07:29.1683 (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: IdpZ0JC0XgQH/kmlVV2ihxbjNC843DI5gz0gSL/iXDHh25XTb2MJLL+UmDbyf/ty X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240226_090744_372113_F5F20237 X-CRM114-Status: GOOD ( 13.68 ) 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 The SVA code only works if the RID domain is a S1 domain and has already installed the cdtable. Originally the check for this was in arm_smmu_sva_bind() but when the op was removed the test didn't get copied over to the new arm_smmu_sva_set_dev_pasid(). Without the test wrong usage usually will hit a WARN_ON() in arm_smmu_write_ctx_desc() due to a missing ctx table. However, the next patches wil change things so that an IDENTITY domain is not a struct arm_smmu_domain and this will get into memory corruption if the struct is wrongly casted. Fail in arm_smmu_sva_set_dev_pasid() if the STE does not have a S1, which is a proxy for the STE having a pointer to the CD table. Write it in a way that will be compatible with the next patches. Fixes: 386fa64fd52b ("arm-smmu-v3/sva: Add SVA domain support") Reported-by: Shameerali Kolothum Thodi Closes: https://lore.kernel.org/linux-iommu/2a828e481416405fb3a4cceb9e075a59@huawei.com/ Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 4a27fbdb2d8446..2610e82c0ecd0d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -364,7 +364,13 @@ static int __arm_smmu_sva_bind(struct device *dev, ioasid_t pasid, struct arm_smmu_bond *bond; struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct iommu_domain *domain = iommu_get_domain_for_dev(dev); - struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct arm_smmu_domain *smmu_domain; + + if (!(domain->type & __IOMMU_DOMAIN_PAGING)) + return -ENODEV; + smmu_domain = to_smmu_domain(domain); + if (smmu_domain->stage != ARM_SMMU_DOMAIN_S1) + return -ENODEV; if (!master || !master->sva_enabled) return -ENODEV;