Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp9468lql; Fri, 12 Apr 2024 01:45:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUV5HB9PgCmCl+6qYnZPdrzbyW5vhJijelr4Wsp5876dRZijRDOkkKkZr+w8Lp3LfKhKebxuK8eCK1VcRx/8eIZ4hQl1pPdK6eIJ70Axg== X-Google-Smtp-Source: AGHT+IFPTBZfyf4MxLvAVhmoeZYFdFnZbDFnKPz/UE2lIreJSBScVUh5NG29NVmJU8jzWCJyfYhy X-Received: by 2002:a50:a45a:0:b0:56c:17be:5b03 with SMTP id v26-20020a50a45a000000b0056c17be5b03mr1502541edb.36.1712911519668; Fri, 12 Apr 2024 01:45:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712911519; cv=pass; d=google.com; s=arc-20160816; b=x4cbx1U7QcejRWKOcpxk113EuOCzaBN7AYr3GcnDdFBP7kQzS6sSzcngDkMt52AxKi YOFQcQ6ylnm7vKVWMb27dQ8d84CfVCdTmGIF+qXlv04AlEXmElnpTtv1XzX0cx/0ieFV FCUHvpUQPh3UzYjOV3YVPEqByKmrrki0LRdFOS6exeWzNwi8RHviYU2LCrLGfC5vcqxU NblxNm+5sRcqtyvl8zhd72BBlXsnrquBJQruJl+PEBA1YLH2GMDSWjTvQmzdP9lQd+Z5 TpdfPbgMlqaBdLclmfyPvEIzrx80sC5lX65BuYvdrkMSjkDeZI2WKztnzohZxi7dlMie cX5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=cE5ei+lq3nOJ6ZP/7XJPIHNXIMtHSI4gUvPDRnPlUrM=; fh=NDCPdPn2hiqHaiIRDYQAzsW9PK20CTia4nECGof6enU=; b=NBmIhmpGNyZH/t5F5KjimiIlh4Kw9jRao4DmYcnYcZCswpZhNidpsPqdIs2Abnr98u 8PO9hc/F6BcHbvATbX4ozWrOVEfsK/auEoXbDVsbJ/pqJfhr+YPLigoeUed2wwrUuQhM W+LXXyGeMf1rzSfEy06C2ldDjFOYWpizSM4t3D/Ekf5xYoekI10H/M42BJO7DkRyeBcc WbLcZRBVS5pNOwvf3e3jH7+LkXfF6RMaFkgX9l5a4FL1S43Mkh5BzWgmZypcqDBJh+oN 37FIsZ3QQdj4wAQmuXAVR+w+D0qUtEOnXWA87CGrOOvOZPl4Hi2QJ9MX63fayvZpH87j zcrw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-142261-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142261-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w12-20020a50d78c000000b0056fffc2fa67si267584edi.490.2024.04.12.01.45.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 01:45:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142261-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-142261-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142261-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 638121F23781 for ; Fri, 12 Apr 2024 08:45:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C96D356B63; Fri, 12 Apr 2024 08:42:42 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1CEFD4A99C; Fri, 12 Apr 2024 08:42:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911362; cv=none; b=BxaDZPakbY3GQ0LmLXYgYzm0lgjP5gwnfgfdn1E3MjgIul0+eZOhu/su/gkR6+Li4O1eZ3QzvqSH8SY4OHNU+wZfNyObm7LLJtKyim1jTETGE94sTMf5C6GdHFsLtACI1WrAoSU/2nvjiVussoR2DYwZses1jBLE1FCPwhPULs0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911362; c=relaxed/simple; bh=vusBqg8J9e2zgFoPLiI0Ud8E+avtD985TjvvarLHPgI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Qz9m1Oo5JjXfBuwpixU0R1MWlEA+yCg4Bpwrp+Ji7w5ikvVxky84kJ/LtHvjtD/PL95L+NNlcbaKhcq2gLFkT2Gxh+Mg0L6WTiBm3E2qw87d9mDd+I5PgYEE7w65EfU2N52MtZlMO9ktIXkT7yIK1EFhCr1z3l5tOmjh2PlNpzk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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(); -- 2.34.1