From patchwork Fri Apr 12 08:42:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Price X-Patchwork-Id: 13627247 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 8CA49C00A94 for ; Fri, 12 Apr 2024 08:44:02 +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=s5pAouOJY6NWha25Cb5yDvDqCwMbJzTLDQmXUsnpbbQ=; b=WD5L0cSciPBZ+9 QFhIxY4eSBcOIvJ+gpRm+jBS3GnqYu+WSQIEVJcVXhEMaWmxI7hVj0U7q7JFwEuVAsujbBq/KNOsG iiaNcgt5mKyHEcgTXIavyEA9I8Lt5Fs13WiNDWlaoDdKduHOvjheDA2jyBn+eSMQ9fPFV3r06OSWA yRt1m4fnT9H22qmzvtYBRS8eAbngcsQQU1rvXt5ZP0aShzrn9wD9PihXGAOKOyF9AWSB+Xq89eBZS /tlBHgTSHG6OMb4tESFhKYSvWWIU11nOYqOYuPQjWhMWCGRMyITki89YhOC9zj+IkDY17dd82ANO7 TmEnF4PqZGYLhfozuRjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvCVi-0000000G85G-0FcJ; Fri, 12 Apr 2024 08:43:50 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvCUa-0000000G7Ic-3w03 for linux-arm-kernel@lists.infradead.org; Fri, 12 Apr 2024 08:42:42 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C66C3113E; Fri, 12 Apr 2024 01:43:09 -0700 (PDT) Received: from e112269-lin.cambridge.arm.com (e112269-lin.cambridge.arm.com [10.1.194.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6F1AE3F6C4; Fri, 12 Apr 2024 01:42:38 -0700 (PDT) From: Steven Price To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Steven Price , Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni Subject: [PATCH v2 08/14] arm64: Enforce bounce buffers for realm DMA Date: Fri, 12 Apr 2024 09:42:07 +0100 Message-Id: <20240412084213.1733764-9-steven.price@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240412084213.1733764-1-steven.price@arm.com> References: <20240412084056.1733704-1-steven.price@arm.com> <20240412084213.1733764-1-steven.price@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240412_014241_190399_6A0853AE X-CRM114-Status: GOOD ( 13.92 ) 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 Within a realm guest it's not possible for a device emulated by the VMM to access arbitrary guest memory. So force the use of bounce buffers to ensure that the memory the emulated devices are accessing is in memory which is explicitly shared with the host. Co-developed-by: Suzuki K Poulose Signed-off-by: Suzuki K Poulose Signed-off-by: Steven Price --- arch/arm64/kernel/rsi.c | 2 ++ arch/arm64/mm/init.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/rsi.c b/arch/arm64/kernel/rsi.c index 159bc428c77b..5c8ed3aaa35f 100644 --- a/arch/arm64/kernel/rsi.c +++ b/arch/arm64/kernel/rsi.c @@ -5,6 +5,8 @@ #include #include +#include + #include struct realm_config __attribute((aligned(PAGE_SIZE))) config; diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 786fd6ce5f17..01a2e3ce6921 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -370,7 +370,9 @@ void __init bootmem_init(void) */ void __init mem_init(void) { - bool swiotlb = max_pfn > PFN_DOWN(arm64_dma_phys_limit); + bool swiotlb = (max_pfn > PFN_DOWN(arm64_dma_phys_limit)); + + swiotlb |= is_realm_world(); if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb) { /* @@ -383,7 +385,12 @@ void __init mem_init(void) swiotlb = true; } - swiotlb_init(swiotlb, SWIOTLB_VERBOSE); + if (is_realm_world()) { + swiotlb_init(swiotlb, SWIOTLB_VERBOSE | SWIOTLB_FORCE); + swiotlb_update_mem_attributes(); + } else { + swiotlb_init(swiotlb, SWIOTLB_VERBOSE); + } /* this will put all unused low memory onto the freelists */ memblock_free_all();