From nobody Tue Dec 2 02:59:08 2025 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA867329E55 for ; Mon, 17 Nov 2025 18:48:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405324; cv=none; b=qZOcV1c2o2CHDgXzEdGVSPE2u7BcVyURovbVlX3hnsvMW4/PilZ22vrdIT+/QbNC8Ws1yMidII7yB3jbUtZdXjM/bTElUUyupIRgLeBQ8Oj1Eb/mv1MWaEyRKGRhPnBYaZGhrcDfdN3MoQsV2eFPFjWcXRGhgR+tWMpKEAVVMvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405324; c=relaxed/simple; bh=X1SB8xBsyDP9CObrHvadpvuvmKMLHDjQeJHpDgXwBrU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lTWbGVYzzzPCkjmFk/L/WEM+YysayW/+sgq540p/QWRz34SGcht7oyB+WtZZTopK860rykMuW14NQDg+qkl83oVvLzirLvRcvvIp4U99RKYEgGVmQ+W7XhdyU98fhAVYdwW5s4Oq4y/q6R/ujQWPrBE+gWs9kdjL+ViNoQvuUyI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=JkQQe+0O; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JkQQe+0O" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-42b3c965ce5so3210024f8f.2 for ; Mon, 17 Nov 2025 10:48:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763405318; x=1764010118; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VXBWv8Dw5hE8mlU4Sm4VTohDwotOri7T9rWgww1xmos=; b=JkQQe+0OMx78LAbxq7nTwU/i55+XSkrNeQOkbZJK+/j/2Qc4wA4PeKfn4nYVDqrWvB 6i86i0yXnywz8f94bV/7/hPRcnJYn4Eb2wgmEuAWmDWS9YXdn3yLAQ+PuxMnqw4t7HUZ E+cRzoHkirdyBqZq9UOPVjSngYYh2vk3eqr42HTpDXaURdN5sxXX1d212yBdEYF/zGBg LVqJhGThMuvGXIMM8hE4CJqdkgTJu8qKvsCIAkXlJHTvbbduNZ5XRpnH+ZIcP+eD58lQ gzTfiuxLscl6WvE/E9xHd7ytLzUvV14Xei39Ch9Q954To6IhjBK5HfbNxWZhNG9ZZVp6 bqug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763405318; x=1764010118; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VXBWv8Dw5hE8mlU4Sm4VTohDwotOri7T9rWgww1xmos=; b=Wszu2mBKZ0/CdGsQVetbRT3B0cu1eR9qq9Umzd2SwzXG7gxkCmDikgvLkd8oxA0/LS F4TVcijusrfiWPcD8+gXOy0vw4ET0fsEcmeRisaUH+aBnWpmsn+lfCfJWXJqEEK3h0JT 8FHjl4vI+NmEBUHQzKWiDqd/CwTq7Q/xh0Fjp/jC14CGMqEz6t8DzvnzTkQxQQBJ59Co W8P4aF0JlWVApdpIY6BPJmqZoP64oIf3uQMw1nHHeq6wIUg+qVx97YyVdgz+iahZx7Ae txa7aYlRStMTjLiTjtqPU4FbXamdGnRrl4b8iXtD735cu2TJ2szEbVzgYW9RV1b1gmHF bYGg== X-Forwarded-Encrypted: i=1; AJvYcCVPXp4IVfaV2imAqJldsnFyi8FEBhMwWn0j0+1GnoJq8/7NZLYcjwlwlXWP7G5uGLembyLRGHfrYcr5UUo=@vger.kernel.org X-Gm-Message-State: AOJu0YxaeIM6FP06xOmLYc4R0Hp7/PyARAvepu4vh4SE7T/xAPrJQDbN tG3hr5LBPU8CPX3Y9zB8D9wLVhkVhIYfBi1GLbYJf1uIe1TXnqC1pOilMOPxLO2OLj7+S4BefI+ Woj+WbOMI8khbmA== X-Google-Smtp-Source: AGHT+IHQBDWwjO/s1zZNuEFY1oL5kAjhY98F1o68vfkU7yeDw2zqyTvhCAFTbYHvFaunhrv4os5cxfn9oBJJZA== X-Received: from wrxe9.prod.google.com ([2002:a05:6000:1209:b0:428:563f:ce93]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:615:b0:42b:3a1b:f71a with SMTP id ffacd0b85a97d-42b5934e2b6mr13388046f8f.23.1763405318003; Mon, 17 Nov 2025 10:48:38 -0800 (PST) Date: Mon, 17 Nov 2025 18:47:59 +0000 In-Reply-To: <20251117184815.1027271-1-smostafa@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251117184815.1027271-1-smostafa@google.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251117184815.1027271-13-smostafa@google.com> Subject: [PATCH v5 12/27] iommu/arm-smmu-v3-kvm: Add SMMUv3 driver From: Mostafa Saleh To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, iommu@lists.linux.dev Cc: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, joro@8bytes.org, jean-philippe@linaro.org, jgg@ziepe.ca, praan@google.com, danielmentz@google.com, mark.rutland@arm.com, qperret@google.com, tabba@google.com, Mostafa Saleh Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jean-Philippe Brucker Add the skeleton for an Arm SMMUv3 driver at EL2. Signed-off-by: Jean-Philippe Brucker Signed-off-by: Mostafa Saleh --- arch/arm64/kvm/hyp/nvhe/Makefile | 5 ++++ drivers/iommu/arm/Kconfig | 9 ++++++ .../iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c | 29 +++++++++++++++++++ .../iommu/arm/arm-smmu-v3/pkvm/arm_smmu_v3.h | 16 ++++++++++ 4 files changed, 59 insertions(+) create mode 100644 drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c create mode 100644 drivers/iommu/arm/arm-smmu-v3/pkvm/arm_smmu_v3.h diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Mak= efile index 8210788d6f88..197685817546 100644 --- a/arch/arm64/kvm/hyp/nvhe/Makefile +++ b/arch/arm64/kvm/hyp/nvhe/Makefile @@ -32,6 +32,11 @@ hyp-obj-y +=3D ../../../kernel/smccc-call.o hyp-obj-$(CONFIG_LIST_HARDENED) +=3D list_debug.o hyp-obj-y +=3D $(lib-objs) =20 +HYP_SMMU_V3_DRV_PATH =3D ../../../../../drivers/iommu/arm/arm-smmu-v3 + +hyp-obj-$(CONFIG_ARM_SMMU_V3_PKVM) +=3D $(HYP_SMMU_V3_DRV_PATH)/pkvm/arm-s= mmu-v3.o \ + $(HYP_SMMU_V3_DRV_PATH)/arm-smmu-v3-common-lib.o + ## ## Build rules for compiling nVHE hyp code ## Output of this folder is `kvm_nvhe.o`, a partially linked object diff --git a/drivers/iommu/arm/Kconfig b/drivers/iommu/arm/Kconfig index ef42bbe07dbe..7eeb94d2499d 100644 --- a/drivers/iommu/arm/Kconfig +++ b/drivers/iommu/arm/Kconfig @@ -142,3 +142,12 @@ config QCOM_IOMMU select ARM_DMA_USE_IOMMU help Support for IOMMU on certain Qualcomm SoCs. + +config ARM_SMMU_V3_PKVM + bool "ARM SMMUv3 support for protected Virtual Machines" + depends on KVM && ARM64 && ARM_SMMU_V3=3Dy + help + Enable a SMMUv3 driver in the KVM hypervisor, to protect VMs against + memory accesses from devices owned by the host. + + Say Y here if you intend to enable KVM in protected mode. diff --git a/drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c b/drivers/iom= mu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c new file mode 100644 index 000000000000..fa8b71152560 --- /dev/null +++ b/drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * pKVM hyp driver for the Arm SMMUv3 + * + * Copyright (C) 2022 Linaro Ltd. + */ +#include + +#include + +#include "arm_smmu_v3.h" + +size_t __ro_after_init kvm_hyp_arm_smmu_v3_count; +struct hyp_arm_smmu_v3_device *kvm_hyp_arm_smmu_v3_smmus; + +static int smmu_init(void) +{ + return -ENOSYS; +} + +static void smmu_host_stage2_idmap(phys_addr_t start, phys_addr_t end, int= prot) +{ +} + +/* Shared with the kernel driver in EL1 */ +struct kvm_iommu_ops smmu_ops =3D { + .init =3D smmu_init, + .host_stage2_idmap =3D smmu_host_stage2_idmap, +}; diff --git a/drivers/iommu/arm/arm-smmu-v3/pkvm/arm_smmu_v3.h b/drivers/iom= mu/arm/arm-smmu-v3/pkvm/arm_smmu_v3.h new file mode 100644 index 000000000000..f6ad91d3fb85 --- /dev/null +++ b/drivers/iommu/arm/arm-smmu-v3/pkvm/arm_smmu_v3.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __KVM_ARM_SMMU_V3_H +#define __KVM_ARM_SMMU_V3_H + +#include + +struct hyp_arm_smmu_v3_device { +}; + +extern size_t kvm_nvhe_sym(kvm_hyp_arm_smmu_v3_count); +#define kvm_hyp_arm_smmu_v3_count kvm_nvhe_sym(kvm_hyp_arm_smmu_v3_count) + +extern struct hyp_arm_smmu_v3_device *kvm_nvhe_sym(kvm_hyp_arm_smmu_v3_smm= us); +#define kvm_hyp_arm_smmu_v3_smmus kvm_nvhe_sym(kvm_hyp_arm_smmu_v3_smmus) + +#endif /* __KVM_ARM_SMMU_V3_H */ --=20 2.52.0.rc1.455.g30608eb744-goog