From patchwork Wed Nov 17 21:15:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Peter X-Patchwork-Id: 12692992 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B735C433EF for ; Wed, 17 Nov 2021 21:17:20 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6E63B6139F for ; Wed, 17 Nov 2021 21:17:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6E63B6139F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=svenpeter.dev Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=zxcaGDUADH6gYA9ujmAEKCoHUUU+FxO7I1VYKGjqfMo=; b=U4V8Nj2GPyr5M6 vHXVa9uDqziNgcPW+S3Fh2Pw1IGM1PKtveyiTX8fXHnzfj2Hp8GeTg05O+U+on2Oaz6HmtZwJoR9b NqlCxF7KkIkReiwTV5nC5hQexyggZn/N3Ae7U/WFClHVsAPHNbRGO8TuBK6Fw/9d5EBKDa4vhILAG 2/5MhIl07Y4F+Qbhsbtia59ApUb+7WtXbGSf1uYlip7ZCnQfoug1sGuL8SoPrevMvk+FsYEBlEeXW XQkS83HDZvhbzbzfpkoa1xdyfO0HXXbJMpb86FIB02qlQ01ngG3hTIh/CH+RiFOc8WEzRHR16TqY8 TrYzHOB/Edvcx/oXMJGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnSHf-006I3G-4H; Wed, 17 Nov 2021 21:15:59 +0000 Received: from new2-smtp.messagingengine.com ([66.111.4.224]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnSHE-006HuP-N2 for linux-arm-kernel@lists.infradead.org; Wed, 17 Nov 2021 21:15:34 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 0D6945806D0; Wed, 17 Nov 2021 16:15:30 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 17 Nov 2021 16:15:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=wPBXm1hEB0gt3 4jZTLq7duc5h40FbhA9Yj5in8Tpo00=; b=F2QEnSh7HLLmJz1viZ1cWsA7UicA7 SX6lcHbylYTro07UIqm4ni5LevGAViojKswXZtIXWTskxfudYwpUJOPdmHGZBSfH cl9oVUVaR63S6MzMXJndhY8ZkP36aTJcOVfI7I2Ro3j1I7+L5x3O6mEOaLHkLIK6 hs+4Kk4JYIWYuupu1CDpnVqUGy1c7VKIQayM+AokxbDeLao9I4QdZj7AKEI/51lm UnWXi3AjNkoV2ext3XWHhf5zRNReIeYZAW8VUsktJAm6m5E4dffYFcJlJZNKrs7q JUOm15DCgL08/0cF9R2ifFdXGhsVG7KYA/28nAoeeXRtRyX4spJY3TnDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=wPBXm1hEB0gt34jZTLq7duc5h40FbhA9Yj5in8Tpo00=; b=cNK5VYz0 y3f1fiaPuvaRg193CzV90rdNs4a03fEjmgh7wR4cImrGkxlVPZK9r6Hna1BREClu FMRubxTmsD3MuLKfMEvmVgzeQjvcnxG+OhB7zZ7gn0rUYbrSHqEXMDaoh4iv+j7Z NIV1MMUWg1Mwws05GG7sj2a1n0/TsUpULvxy+v+dO/BoDH0cGzeYOZCIUqVDX1LW 8U8BSd6fWPJFi5zbqJ4d+rtfJN6hQoXmuThRTigu0SMaESyzgINl9b9X3Ww0fpTX nx44qttS7VWKIREVUJSSJz4nYgu2JNH1D3fSxswgQVke/VqJtwyHbvTGcXPLoRLu G7qnGzAWqVAO9Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrfeeggddugedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefuvhgvnhcu rfgvthgvrhcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrfgrthhtvg hrnheptedvkeetleeuffffhfekteetffeggffgveehieelueefvddtueffveevlefhfeej necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshhvvg hnsehsvhgvnhhpvghtvghrrdguvghv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 17 Nov 2021 16:15:27 -0500 (EST) From: Sven Peter To: iommu@lists.linux-foundation.org, Robin Murphy Cc: Sven Peter , Joerg Roedel , Will Deacon , Rob Herring , Janne Grunau , Hector Martin , Alyssa Rosenzweig , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/4] iommu/io-pgtable: Add DART subpage protection support Date: Wed, 17 Nov 2021 22:15:07 +0100 Message-Id: <20211117211509.28066-3-sven@svenpeter.dev> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20211117211509.28066-1-sven@svenpeter.dev> References: <20211117211509.28066-1-sven@svenpeter.dev> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211117_131532_851086_5DC92C5F X-CRM114-Status: GOOD ( 12.43 ) 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 DART allows to only expose a subpage to the device. While this is an optional feature on the M1 DARTs the new ones present on the Pro/Max models require this field in every PTE. Signed-off-by: Sven Peter --- drivers/iommu/io-pgtable-arm.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index dd9e47189d0d..a8c660b8b3e9 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -10,6 +10,7 @@ #define pr_fmt(fmt) "arm-lpae io-pgtable: " fmt #include +#include #include #include #include @@ -133,6 +134,9 @@ #define APPLE_DART_PTE_PROT_NO_WRITE (1<<7) #define APPLE_DART_PTE_PROT_NO_READ (1<<8) +#define APPLE_DART_PTE_SUBPAGE_START GENMASK_ULL(63, 52) +#define APPLE_DART_PTE_SUBPAGE_END GENMASK_ULL(51, 40) + /* IOPTE accessors */ #define iopte_deref(pte,d) __va(iopte_to_paddr(pte, d)) @@ -273,6 +277,12 @@ static void __arm_lpae_init_pte(struct arm_lpae_io_pgtable *data, else pte |= ARM_LPAE_PTE_TYPE_BLOCK; + if (data->iop.fmt == APPLE_DART) { + /* subpage protection: always allow access to the entire page */ + pte |= FIELD_PREP(APPLE_DART_PTE_SUBPAGE_START, 0); + pte |= FIELD_PREP(APPLE_DART_PTE_SUBPAGE_END, 0xfff); + } + for (i = 0; i < num_entries; i++) ptep[i] = pte | paddr_to_iopte(paddr + i * sz, data);