From patchwork Wed Sep 4 12:43:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Orzel X-Patchwork-Id: 13790767 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E7434CD37B4 for ; Wed, 4 Sep 2024 12:44:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.790256.1199998 (Exim 4.92) (envelope-from ) id 1slpMg-0006A1-Le; Wed, 04 Sep 2024 12:44:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 790256.1199998; Wed, 04 Sep 2024 12:44:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slpMg-00069u-J3; Wed, 04 Sep 2024 12:44:02 +0000 Received: by outflank-mailman (input) for mailman id 790256; Wed, 04 Sep 2024 12:44:01 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slpMf-00069o-HY for xen-devel@lists.xenproject.org; Wed, 04 Sep 2024 12:44:01 +0000 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on20611.outbound.protection.outlook.com [2a01:111:f403:2408::611]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5b38e0bd-6abb-11ef-99a1-01e77a169b0f; Wed, 04 Sep 2024 14:43:59 +0200 (CEST) Received: from CH2PR20CA0010.namprd20.prod.outlook.com (2603:10b6:610:58::20) by DM6PR12MB4419.namprd12.prod.outlook.com (2603:10b6:5:2aa::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Wed, 4 Sep 2024 12:43:55 +0000 Received: from CY4PEPF0000FCBF.namprd03.prod.outlook.com (2603:10b6:610:58:cafe::2) by CH2PR20CA0010.outlook.office365.com (2603:10b6:610:58::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27 via Frontend Transport; Wed, 4 Sep 2024 12:43:55 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000FCBF.mail.protection.outlook.com (10.167.242.101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Wed, 4 Sep 2024 12:43:54 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 4 Sep 2024 07:43:53 -0500 Received: from XIR-MICHALO-L1.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 4 Sep 2024 07:43:52 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5b38e0bd-6abb-11ef-99a1-01e77a169b0f ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Wo8b01x2zTcBEkMyP0hHU3QnoKcJjtu1GfxQ13dTca+4hHM0iZbeua5J0SsKDLnZUhevLmtDYSHtZI4o/MXlP63l0ZDeF1rgZb9PvO8XiOziprzko/aD8rgi+W+RxL4aaa8fJz3pmKK6OCRbHSZFndjkguNTca4A6Gtxb8xAsGziLexemlfVdClCVBj7TRSCcRSqGC5OtX4m3ocxtYyJXMMVKk7vhZLz/fkIsW0jYrAHrT7PJpqS1TZ/pWCevvx/NhF+5bxUsGVOiUGN+vDC8gEwfiAqiW1+OYvSMceoCwOeeg7nG3wreqxzEPWOAej0Vz2+WgaR25e6yjO1Q0erCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=t4aDycOgF3J4oZvhTiXzfFnja/EfK1sdRKYoPfoj2U4=; b=YrSbk0axl30XNbPpiBqlR088PKa3lU+uKWTsyfc/xguunrVCzOpsHS6S22My4hpj4jx+yZVc0mQ5FZt4yxQuoFCXOyIAIc3tBDOyepC5SkRF6Hor8nUUhjA3Kkl0tMbGX5Y4DBnBKlF45wQ5NUkg2CthCwjVTpB5IAO7QFQaXjJRXnIzU33z3dCi0HKRxbQQTtQIMmJVCqwOeg02kEruyN0PAyHhyU6MjG/wqPrNXYEBHu6Smqx5f3p6sPbTtj6gwD908uGIELF1Xg5C969BNohvERUT/HhWjjoAGhAoEc9bKZ1PNLhqL4sC90YDJj+iWxtBEahbftRXb42W128JGQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=t4aDycOgF3J4oZvhTiXzfFnja/EfK1sdRKYoPfoj2U4=; b=YSlrCg70DnV3xpgAC1TaQLU/ISJpXsqB+12pdF1VxJ8qzjBp0djNYxrVTi9t5fNKxxwEPaw02DAxCT2txpRLwCBXAu50ViBQY5JP+2rmmk2raXsTtW09orHC9ba1r7reSX9dGh9OTGy4JxZCLmLTyjexBcZdVd7BtVT8igjBuXI= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Michal Orzel To: CC: Michal Orzel , Julien Grall , "Rahul Singh" , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH] arm/smmu: Complete SMR masking support Date: Wed, 4 Sep 2024 14:43:49 +0200 Message-ID: <20240904124349.2058947-1-michal.orzel@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: michal.orzel@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCBF:EE_|DM6PR12MB4419:EE_ X-MS-Office365-Filtering-Correlation-Id: f60c44d1-7b84-44da-9aa7-08dcccdf3cd3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|376014|36860700013; X-Microsoft-Antispam-Message-Info: gAnXf0ZL+xwHfby996n574RECTbEMFTqgy2wQzNLr91YEty+XKGZNUGN/1PFkR2f0lQcDX6It6KbjZcQAfPzrkgbWOLaD/SoLXJAnejWJANgqkesCp7KXzeAI8ryARsUw3IaHrJx9X+xnbdHYqb9/KBG1KI2AOgXa973SvdRx45Ent1Pc3XdPVt7YxOkdU95EJHKrFc3ZxrmDDDDZpSlFhv76mcPyGvN+VZrdLT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1QTvWoc/nfPu98reaLDN9ohQmN0NP8wLm2wt2W2EW3SYL1HWkhbhOAfEAeWMtguku4lUVkH/B4XadufZ/LshEjR5zAJ4oNHbyD9Xw3k+VJiXgrlTYGqizklYvIqEJrluYV31VISwGtJCyvuAEWbR X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Sep 2024 12:43:54.8635 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f60c44d1-7b84-44da-9aa7-08dcccdf3cd3 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCBF.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4419 SMR masking support allows deriving a mask either using a 2-cell iommu specifier (per master) or stream-match-mask SMMU dt property (global config). Even though the mask is stored in the fwid when adding a device (in arm_smmu_dt_xlate_generic()), we still set it to 0 when allocating SMEs (in arm_smmu_master_alloc_smes()). So at the end, we always ignore the mask when programming SMRn registers. This leads to SMMU failures. Fix it by completing the support. A bit of history: Linux support for SMR allocation was mainly done with: 588888a7399d ("iommu/arm-smmu: Intelligent SMR allocation") 021bb8420d44 ("iommu/arm-smmu: Wire up generic configuration support") Taking the mask into account in arm_smmu_master_alloc_smes() was added as part of the second commit, although quite hidden in the thicket of other changes. We backported only the first patch with: 0435784cc75d ("xen/arm: smmuv1: Intelligent SMR allocation") but the changes to take the mask into account were missed. Signed-off-by: Michal Orzel Reviewed-by: Rahul Singh --- xen/drivers/passthrough/arm/smmu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index f2cee82f553a..4c8a446754cc 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -1619,19 +1619,21 @@ static int arm_smmu_master_alloc_smes(struct device *dev) spin_lock(&smmu->stream_map_lock); /* Figure out a viable stream map entry allocation */ for_each_cfg_sme(cfg, i, idx, fwspec->num_ids) { + uint16_t mask = (fwspec->ids[i] >> SMR_MASK_SHIFT) & SMR_MASK_MASK; + if (idx != INVALID_SMENDX) { ret = -EEXIST; goto out_err; } - ret = arm_smmu_find_sme(smmu, fwspec->ids[i], 0); + ret = arm_smmu_find_sme(smmu, fwspec->ids[i], mask); if (ret < 0) goto out_err; idx = ret; if (smrs && smmu->s2crs[idx].count == 0) { smrs[idx].id = fwspec->ids[i]; - smrs[idx].mask = 0; /* We don't currently share SMRs */ + smrs[idx].mask = mask; smrs[idx].valid = true; } smmu->s2crs[idx].count++;