Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp174011lqr; Wed, 5 Jun 2024 02:34:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVz9jWCJK3Mvo3YvRZ0vPmkt99jEdVOvVTca+wf1To74TD1yva+gaYBMa+DRaVdC5kDm6XfrrLnBS/i0MyidSN4qhTJg/GVIxzht/Q6Pg== X-Google-Smtp-Source: AGHT+IHumOUq1UUlYBRUS9KNAkPFg7V2Xk3Gu7KILXzYkkGhsC393AY6wTg1oPejTiQ7eYZVcru1 X-Received: by 2002:a05:6a21:188:b0:1b1:d7a3:a76b with SMTP id adf61e73a8af0-1b2b6fca806mr2512434637.33.1717580052536; Wed, 05 Jun 2024 02:34:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717580052; cv=pass; d=google.com; s=arc-20160816; b=WxDSpIM7SSGw80HhWHPYHviQKMF6NV5CEMDcyScphpvOTl4EIEYddUoAnAdiqLneH4 1OfQQjUARumLClmjjoEa/3ifuHRwOmnQaU2q2wUh7leCIWGGrDY9aHy9qEJxSv7fXZm4 9q4kExJz3PNP1biEfzQmJl2ZnAz+vUKT/JSoiYoYbbz5lTe+pac8I0N96xPmqEj12mZi 5KQwpoRMLQv1MNNYjiKPzBWvOMa9RZnAZx2Piqn4w7pycIlSsWMjstb3OWl0nU4WtNrg ln97yzbRW/cI7D28ABUT+YJ2cc8SAmALqL4lXbZcAeaRttIf4PRH6qqHSBeO1BOOgMWc I9QA== 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=5htHnsZaBIuVlueYF76+PPqZG7q/bO+fn+6WDDnHwQg=; fh=NDCPdPn2hiqHaiIRDYQAzsW9PK20CTia4nECGof6enU=; b=pba8yhvfAodXQfepaYms011dP+NiPT4lmlULZL+cBPmcvVESSFQ67wqu7b62ArqDSD yqYGVXPkqUO2rsZpj0HALliA9D8GCjbqnXoguIXMa6RU6UI/6DaG47fObbNeCCFfSrjQ buWjcT/BS1F3MxaDqkctUbjxaWxg7y4bMXjnr+1w0i7Hzt3iFZtxkMY9YIDAoMJPencA FNmKLXGU2BfPcY6TLxcSn3EcMtOvVb3/HaaHiv3krkMzfWc6EDHvbftEevE1LnTiz00x 33cyKd/CIhy0LSMFpt+LUSHMsFQpQV5R8XeIRRAcGNeNqhOSLcb9h5hWKKMY28VyPXGC c98w==; 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-202107-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202107-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c35b40bdc8si9588003a12.458.2024.06.05.02.34.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 02:34:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202107-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-202107-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202107-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 23CAD283C09 for ; Wed, 5 Jun 2024 09:34:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B01E5194A40; Wed, 5 Jun 2024 09:30:53 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E88DA194148; Wed, 5 Jun 2024 09:30:51 +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=1717579853; cv=none; b=STKRiIYqv9BI3gphmj6nrkCDF2x0SccmnBGby2iy6prhECaQ7pwT+/Ht7JOwKNORL4+Pv6DxIBOzRb2kqzPba/G2O5/5AgY8vQEICJG7SUhxsbDDc8c0XKWU0gIihLASxPdc7mBZeQSFceHDkI7+lC7C9Wl2504BVkiZAbkuILQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717579853; c=relaxed/simple; bh=EIPGuKk7VNK7SQGYIGM4uDAI+WparEyuijxc1pMH28A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FedoIlr1wRLKq0Tu5AX7Byk+hGNhnZ4AGtHLLZOYk5Lf8eladnZUkej55iF72wpMbcym+nY0dwxmv9EueNj3apW4up0/BsOS04tnU4NQ6EStuY6lUKX63yLzk0MEOGv5i0o95q5F1WktijDmZAGiFPcQ6nrK4r2VN5ik7rmJkwQ= 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 B8D00DA7; Wed, 5 Jun 2024 02:31:15 -0700 (PDT) Received: from e122027.arm.com (unknown [10.57.39.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DEEA03F792; Wed, 5 Jun 2024 02:30:47 -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 v3 08/14] arm64: Enforce bounce buffers for realm DMA Date: Wed, 5 Jun 2024 10:30:00 +0100 Message-Id: <20240605093006.145492-9-steven.price@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605093006.145492-1-steven.price@arm.com> References: <20240605093006.145492-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 --- v3: Simplify mem_init() by using a 'flags' variable. --- arch/arm64/kernel/rsi.c | 2 ++ arch/arm64/mm/init.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/rsi.c b/arch/arm64/kernel/rsi.c index c5c03e8e341a..5cb42609219f 100644 --- a/arch/arm64/kernel/rsi.c +++ b/arch/arm64/kernel/rsi.c @@ -5,6 +5,8 @@ #include #include +#include + #include struct realm_config config; diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 9d8d38e3bee2..1d595b63da71 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -370,8 +370,14 @@ void __init bootmem_init(void) */ void __init mem_init(void) { + unsigned int flags = SWIOTLB_VERBOSE; bool swiotlb = max_pfn > PFN_DOWN(arm64_dma_phys_limit); + if (is_realm_world()) { + swiotlb = true; + flags |= SWIOTLB_FORCE; + } + if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb) { /* * If no bouncing needed for ZONE_DMA, reduce the swiotlb @@ -383,7 +389,8 @@ void __init mem_init(void) swiotlb = true; } - swiotlb_init(swiotlb, SWIOTLB_VERBOSE); + swiotlb_init(swiotlb, flags); + swiotlb_update_mem_attributes(); /* this will put all unused low memory onto the freelists */ memblock_free_all(); -- 2.34.1