From patchwork Wed Nov 2 06:35:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Riesch X-Patchwork-Id: 13027756 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 916B8C433FE for ; Wed, 2 Nov 2022 06:36:57 +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: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:In-Reply-To:References: List-Owner; bh=FMzxIG7ELjRFxORL3Yrv9vIIOdGPy025zbOPk3oe0PE=; b=VyBI3RYsRqptNx Ql8nkjxsRuKVfcVNIbBJ7fs7Wo5L29G6iEwsx/QGbF6Q9awdfMr/X4C3TVmI8PD6MskQvJYRcO4J7 5pckOmi1hmz76COjJ3d2Fndw97P8uTqGfSTpQEYO2/WcRrxnT1y6iRKkwQ34oHdU8Y3bqkrayV1VH DedwAXuT5RGLxgUy8a3+7xU5DYkBco4M1vv8VymFBtN784mKX615Yd0W0YhPG2q0ZQyeMSAXtwep3 X2BhjTfEFTDEulTQRPJz/pudXjCEPTr7Np/vjPYVBYMK8ZMP2VwU0hGJQzNrIY/BKpZezUc+D8CDw cPADfDYy3wcAUBJSfiJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oq7MT-008TSK-BF; Wed, 02 Nov 2022 06:36:29 +0000 Received: from mail-vi1eur05on2089.outbound.protection.outlook.com ([40.107.21.89] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oq7MH-008TQZ-VL; Wed, 02 Nov 2022 06:36:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LNTLeIQqt5bc9kUEM4ri2frMiYVDeKUv+SNEQeWz4LFK7uzWVHmSFoCnZ0ovNUkLEwoj9kwPxxGmeaTtG1cY7HsWnQewFQp0Kbm8HGzjqb4P+iOsoBOHBE+b0kc03jvBOvWp5Dnk1iIhGd/P+4wXmz30V5pHptl2b1dqbKW0lOIKaGwoFvcfS1A88yPlNIT/b2yRreWb4PDvxyyIVXshBAucNzajYVlc8R/5kR+mFvQmFN+k12GT1+nYBOpOVqzr3aeI4Rc3sNpi/y4cJZ0/rfiIc11in2yqUPWHnSkcSocrJev9ro5FcyuheKUdR1cJYYE4wx//gol9z8NWWNPQ5g== 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=++80gqbVUTcBqH4xW79UJARVRVB585J1tmdHb+KsZzg=; b=ZizmY3uDKwAfpG73SP4fQ+OGHmqzmmHDkisvHkgq1h0dP6hZ4nB7zLAZfUD0H3c6wgpvL/ZdGPyxMjxr71RAOtFFjssZFKxJLkhgtj3Das5es60V07hQWv2Vc1EsrRTshWiW54peqS65OeGqUFg4um3jwe9n59DEuDWzk60/oZCGKIQH9m8CMLbH1MxFl6yd3YnRCr7pWPSP00oyJvyTJ7iWsO94EqC31+X/NC60QzrTR60TLsUzXNnD3DtKZXMhdV43M/KGVzuoBx2YJwoJ6+jsk+ifzy+o7RbjUm9MhRLmVgnQySpPYgFoIODEOBofDs5/NPNLEwC4tm+Uw/A7/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wolfvision.net; dmarc=pass action=none header.from=wolfvision.net; dkim=pass header.d=wolfvision.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wolfvision.net; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=++80gqbVUTcBqH4xW79UJARVRVB585J1tmdHb+KsZzg=; b=rwT7Ql2G4H2C1/Oj6m3mPak7v+tKFGUHc5WGznuf6KE7TJb2D8voFVXciHipzcmg7BRGSjeu5GaW1yvoJiyFl0ipR4NtoXV/a3Q5R90niW65wikjzkMhhJaYxkbQXPWSjj7ajG6Zd3hwD5mUu9B3fpj2zRCsQfMkdbFzy5U6kb0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wolfvision.net; Received: from DU0PR08MB9155.eurprd08.prod.outlook.com (2603:10a6:10:416::5) by AM0PR08MB5459.eurprd08.prod.outlook.com (2603:10a6:208:186::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.21; Wed, 2 Nov 2022 06:36:06 +0000 Received: from DU0PR08MB9155.eurprd08.prod.outlook.com ([fe80::3643:6226:28c:e637]) by DU0PR08MB9155.eurprd08.prod.outlook.com ([fe80::3643:6226:28c:e637%2]) with mapi id 15.20.5769.019; Wed, 2 Nov 2022 06:36:05 +0000 From: Michael Riesch To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Joerg Roedel , Will Deacon , Robin Murphy , Heiko Stuebner , Benjamin Gaignard , Simon Xue , Michael Riesch Subject: [PATCH] iommu/rockchip: fix permission bits in page table entries v2 Date: Wed, 2 Nov 2022 07:35:53 +0100 Message-Id: <20221102063553.2464161-1-michael.riesch@wolfvision.net> X-Mailer: git-send-email 2.30.2 X-ClientProxiedBy: ZR0P278CA0004.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::14) To DU0PR08MB9155.eurprd08.prod.outlook.com (2603:10a6:10:416::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR08MB9155:EE_|AM0PR08MB5459:EE_ X-MS-Office365-Filtering-Correlation-Id: 1cb72067-b268-4473-eebf-08dabc9c84e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: au1DiVCuVkexk3Nq7hc/egyl4eGg3QoODZsUEs5XQ5eOrfndd6h4QI0Z920s+slAYAHqOMRaYfHbbYcKEdZqrcYCQGk/OA+aCRXPSmClxlEhDjlF4nNe6YBeLoGy3+/md+3Zq/NHWR8cYXWSSA/3Wd1ipPn3y9tJJQPpq/aIhhG9MQcLLqpye+LB4oyvRwwP5WTZP6bznOSd0LASKUhKarEJ4KWW2MwYfAFhSgLpkfdXP+DnayG8l9ZIabG3dqyLvkXB8QtCU/XL56ueGd+tAzaMmN6BYubt8AM9CEuhGy0BPuyYN63Lfqvo7BWp43vM9oAiWUkRILBngVtv44XNbDKvfbJDI6ppzdG2FEzX6I8oXH+WtTCbUe1S0I0jC9nL7OATtkcsU1gjKfclxVv7TP7ct9iWfhP2HSWOaN8n27CKNo3cHCrNTyTTzRfzrLK3cuoWTmVyT1HYxWdOhk3qJvANWRI8t+tAlSqvcBhNMzT+sKXzlFlrmkGTfXHil2R+CXlZF2cBBmLXpe1r2aFobX6rRE78yhHWGfmXgdWVjVIW9Lcvg5C0Y+jbixCHywrHgoUVNCEhSb7EcoLBoJTfoztgofsv3hFfNQlXibCsy1itYJjz+P4zbVn9pCl7mZIGEqkkLkZwS0V7bVKAdO7hEUNFA6ba8QGaAGwsDlKP/kRB39Dd9f964OcHSi9gWUKFjscRZtwJNsJvdcWlEEU/XNAsow+WLDRlrh2sl1DARec= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU0PR08MB9155.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(366004)(376002)(39840400004)(136003)(396003)(451199015)(478600001)(966005)(6486002)(186003)(2906002)(1076003)(2616005)(44832011)(6506007)(4326008)(6666004)(107886003)(54906003)(36756003)(316002)(8676002)(66476007)(52116002)(83380400001)(38100700002)(66946007)(66556008)(5660300002)(7416002)(8936002)(6512007)(86362001)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gRJsmnxn+SeF8rkDgqsXQW2pA7WRslPlFsyoQSFsG45M1vK9QYGUYNlf1AEeXNgKvvSIGrFv3obXTQKCxmyxqHjeK22Scmw0c3sFM+ORv/ELSL/KbuSQd+WAM9Q8va7+1YMyfJj5I4cT8ntB6QeQ2EpKzmhlw3iRMwS2jVMI7LiM4BtAAtSwgf4Po5LtQAKonw8hp7/NdM5rapWptBfXkUa2mJoKcnGIu3z72uNUSAvI3p2pNuU4UfIDLI4UW7uQ7d4at2VNTM2K8bgjinr+bo8Wjh3Idq9lYADiNt5rrdwy1WsIfGZCEEPIKjWJqhUjHAXUVgGm08Hn7N3/1cpZXiDqurhi6B2ODijlW6r8w9NwmzkRjZJxK+vvwhGcYB7hynEU0rYPolZ7RnWSVa2aWcnf0CdE9Bu7EAkkN2mk6N46zH3fJBtJ1p6Vr0ku2OEHC3/IgNfbACZyQZvE+BEOPdedGeJuxCH17NO/X7LiKqGaXb+4wbdi0Pq5PqHVTHRz4ZB258v358YSI+Novobr5X3yjAmsmE8qS5XHxZXqYFBNZUTwz1xM2xq5ihwYwVfX28wnrB5sIEdZKLNhCGuv/jumVT46xeOX6aH4LWM5rohd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.net X-MS-Exchange-CrossTenant-Network-Message-Id: 1cb72067-b268-4473-eebf-08dabc9c84e7 X-MS-Exchange-CrossTenant-AuthSource: DU0PR08MB9155.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2022 06:36:05.8308 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e94ec9da-9183-471e-83b3-51baa8eb804f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wikYqcQw9xFy8XtF4b6yiyueizbFy+HUc3haRF2QDqiei+R+4+HSm8lyhnaecQhWlM8xUGGU1/ERtJ/aSxK5Uyna37cCuUVLKSzki0X/xss= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB5459 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221101_233618_040066_522485BC X-CRM114-Status: GOOD ( 13.47 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org As pointed out in the corresponding downstream fix [0], the permission bits of the page table entries are compatible between v1 and v2 of the IOMMU. This is in contrast to the current mainline code that incorrectly assumes that the read and write permission bits are switched. Fix the permission bits by reusing the v1 bit defines. [0] https://github.com/rockchip-linux/kernel/commit/e3bc123a2260145e34b57454da3db0edd117eb8e Fixes: c55356c534aa ("iommu: rockchip: Add support for iommu v2") Signed-off-by: Michael Riesch Reviewed-by: Heiko Stuebner --- drivers/iommu/rockchip-iommu.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index a3fc59b814ab..a68eadd64f38 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -280,19 +280,17 @@ static u32 rk_mk_pte(phys_addr_t page, int prot) * 11:9 - Page address bit 34:32 * 8:4 - Page address bit 39:35 * 3 - Security - * 2 - Readable - * 1 - Writable + * 2 - Writable + * 1 - Readable * 0 - 1 if Page @ Page address is valid */ -#define RK_PTE_PAGE_READABLE_V2 BIT(2) -#define RK_PTE_PAGE_WRITABLE_V2 BIT(1) static u32 rk_mk_pte_v2(phys_addr_t page, int prot) { u32 flags = 0; - flags |= (prot & IOMMU_READ) ? RK_PTE_PAGE_READABLE_V2 : 0; - flags |= (prot & IOMMU_WRITE) ? RK_PTE_PAGE_WRITABLE_V2 : 0; + flags |= (prot & IOMMU_READ) ? RK_PTE_PAGE_READABLE : 0; + flags |= (prot & IOMMU_WRITE) ? RK_PTE_PAGE_WRITABLE : 0; return rk_mk_dte_v2(page) | flags; }