From mboxrd@z Thu Jan 1 00:00:00 1970 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 2E970C636CD for ; Wed, 1 Feb 2023 14:25:14 +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=Uli7C5ay+ivTymWCWjal51wQSMtlj4n/3YPk0pS87s4=; b=fFdtB5N/4rUUdZ EPYGK9l6nfnF7LAsOcTqvVa7O/cNDuqOGzV9dWstmip/Cbbi4zwOa09YQ2gTBc27Bo0zWBB09YkQQ eMFJapgoX7jWEGLECjRHLRFfAY2TfjhlbbsKpBJ0m049A8TcIoPX/By9vl4ImjCscHmYdS5/Uklv0 CsY/SK6INoyk40mpf9QpE3GAgIwvJLvChWTZuZzfy3S/A8CUfKS9CBW0K49on3kd5e2yLJBJEixy3 qdJY0Al1v/g8Fq5L9jqfQe4gfOcTX+VbegwejgJeKuVhyc8XoOH8p1q8pShIV60Nknmly9KIP8ArR d9UwiH19ofZeQuL4xTow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNE1p-00CK9W-9K; Wed, 01 Feb 2023 14:24:01 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNDhT-00CBgK-9D for linux-arm-kernel@bombadil.infradead.org; Wed, 01 Feb 2023 14:02:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=YdP3DX4BPrTeIfyGSx6/ywhf75AZ8OaGFBR5uBxLPeI=; b=Be0Jd2nhdodULhJz4hK6vmPfnt qFOSh788znec9bIWmMEJitfGkGRgV3cocWXfgSffFeeuLDptnnNV75j1cRcZ8vfcQ59iwRj7n+alK m64qAAGTnpUHiv4P0fZLOCmNx7nBQFxWPcMjCDApT1hg2CUSQ8VkgszMbnnpldR0JBGt6KxvSCK7A 1m9yyp3qlbOc0F52rDxd9fF/86w0gKsA/KyfUSataqoSxDh70IsCyw1nP0txf8T0/6UtrnFtaENDA Kw1sCi+x8oQKIRGfsLYvWIc3uyyUhasawv2tsSXDciaN7nXSfcGx2Jf6AjPdjMJvWHMViVEZHrlyS 7F+VpHlw==; Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pNChb-004m1u-0A for linux-arm-kernel@lists.infradead.org; Wed, 01 Feb 2023 12:59:05 +0000 Received: by mail-wr1-x434.google.com with SMTP id d14so17221956wrr.9 for ; Wed, 01 Feb 2023 04:59:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YdP3DX4BPrTeIfyGSx6/ywhf75AZ8OaGFBR5uBxLPeI=; b=gi1u327r3bwhgQ0jcZTy2ePBAObJbV74KeqIs4sLYZ6oCBJp3nQUuE781l7zOxjyJ0 ht6clbf/Nk0rHGcIOoMHocLZTvz8WilfSn+eFjPb6R2j8LiNxXnu+x9FhW0Yr/+GAJfJ oMlpmE2yqEmbbW+m1ySj4CoRKcfvyM//ZIKSPCuqF4iaED1c4MoCccfGSqtvFZZtZx6y Vv1VizuB1FUNOOWizObIzkAeT7mcqoaCmWnvzlnFf569Fk7jM69tjzbXZeBJ9C9xfOBI reVXapwJdiLdHDi91UXtNiQkNhEKs2UNCli76l4WX0/7mDWAxEP3DX3ZwzR8tMqntD6Z MRRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YdP3DX4BPrTeIfyGSx6/ywhf75AZ8OaGFBR5uBxLPeI=; b=Z5bYpLzqKopnIlDaJsqKYguDnPymFfOh+QbO1NNmpmSnl/6Hl33VtlDxRvd9Gp7YIv hv8/nfjhQUEczJ03jFw41z0jbH6UvXt8l0ZyMR7wk0uPV2umU4QJiwnTCeovQT+H2pLK f1iMxK+u3acdb5CDFvz5or0l1W2uXyaXpZDqlppA7AJ4FJfMJa9Qks2eM7GE/v6q5aEj llcJ+hte/lNXMqc611Wpj7daN7KScBUkoNmvIp01kFdrz0/sP18m404GjN19tnRMQxT8 t/YiKyfPxLbljFv/WwTAbWbwL5Lv1z6xNM09LOiaRphrRzHujDZuF5sOEaVs3eWHgT7n iuBw== X-Gm-Message-State: AO0yUKVbVv/fV0e7Tj9Fs9c6tGFav4ss0oRv7YIxuB2J+1o/BxOOFHtT 0JoNZpHfyP2IOZUPuXHMQ+pZMg== X-Google-Smtp-Source: AK7set9uV9gcpJddzgbgGf+mtj837ImA617uXmGOdJV7SZrqmyd74oHFIscY1a8OJzgCGXL0U+HhLg== X-Received: by 2002:adf:f911:0:b0:2bd:e7a0:6b5e with SMTP id b17-20020adff911000000b002bde7a06b5emr2317032wrr.40.1675256376014; Wed, 01 Feb 2023 04:59:36 -0800 (PST) Received: from localhost.localdomain (054592b0.skybroadband.com. [5.69.146.176]) by smtp.gmail.com with ESMTPSA id m15-20020a056000024f00b002bfae16ee2fsm17972811wrz.111.2023.02.01.04.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 04:59:35 -0800 (PST) From: Jean-Philippe Brucker To: maz@kernel.org, catalin.marinas@arm.com, will@kernel.org, joro@8bytes.org Cc: robin.murphy@arm.com, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, smostafa@google.com, dbrazdil@google.com, ryan.roberts@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, iommu@lists.linux.dev, Jean-Philippe Brucker Subject: [RFC PATCH 21/45] KVM: arm64: iommu: Add SMMUv3 driver Date: Wed, 1 Feb 2023 12:53:05 +0000 Message-Id: <20230201125328.2186498-22-jean-philippe@linaro.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230201125328.2186498-1-jean-philippe@linaro.org> References: <20230201125328.2186498-1-jean-philippe@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230201_125903_504297_CC39D4D3 X-CRM114-Status: GOOD ( 20.51 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add the skeleton for an Arm SMMUv3 driver at EL2. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/Kconfig | 10 ++++++++ arch/arm64/kvm/hyp/nvhe/Makefile | 1 + arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/hyp/include/nvhe/iommu.h | 9 +++++++ include/kvm/arm_smmu_v3.h | 22 +++++++++++++++++ arch/arm64/kvm/hyp/nvhe/iommu/arm-smmu-v3.c | 27 +++++++++++++++++++++ arch/arm64/kvm/hyp/nvhe/setup.c | 2 ++ 7 files changed, 72 insertions(+) create mode 100644 include/kvm/arm_smmu_v3.h create mode 100644 arch/arm64/kvm/hyp/nvhe/iommu/arm-smmu-v3.c diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 79707685d54a..1689d416ccd8 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -410,6 +410,16 @@ config ARM_SMMU_V3_SVA Say Y here if your system supports SVA extensions such as PCIe PASID and PRI. +config ARM_SMMU_V3_PKVM + bool "ARM SMMUv3 support for protected Virtual Machines" + depends on KVM && ARM64 + select KVM_IOMMU + 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. + config S390_IOMMU def_bool y if S390 && PCI depends on S390 && PCI diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile index f7dfc88c9f5b..349c874762c8 100644 --- a/arch/arm64/kvm/hyp/nvhe/Makefile +++ b/arch/arm64/kvm/hyp/nvhe/Makefile @@ -29,6 +29,7 @@ hyp-obj-$(CONFIG_DEBUG_LIST) += list_debug.o hyp-obj-y += $(lib-objs) hyp-obj-$(CONFIG_KVM_IOMMU) += iommu/iommu.o +hyp-obj-$(CONFIG_ARM_SMMU_V3_PKVM) += iommu/arm-smmu-v3.o ## ## Build rules for compiling nVHE hyp code diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index b8e032bda022..c98ce17f8148 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -379,6 +379,7 @@ extern u64 kvm_nvhe_sym(hyp_cpu_logical_map)[NR_CPUS]; enum kvm_iommu_driver { KVM_IOMMU_DRIVER_NONE, + KVM_IOMMU_DRIVER_SMMUV3, }; struct vcpu_reset_state { diff --git a/arch/arm64/kvm/hyp/include/nvhe/iommu.h b/arch/arm64/kvm/hyp/include/nvhe/iommu.h index 76d3fa6ce331..0ba59d20bef3 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/iommu.h +++ b/arch/arm64/kvm/hyp/include/nvhe/iommu.h @@ -5,6 +5,15 @@ #include #include +#if IS_ENABLED(CONFIG_ARM_SMMU_V3_PKVM) +int kvm_arm_smmu_v3_register(void); +#else /* CONFIG_ARM_SMMU_V3_PKVM */ +static inline int kvm_arm_smmu_v3_register(void) +{ + return -EINVAL; +} +#endif /* CONFIG_ARM_SMMU_V3_PKVM */ + #if IS_ENABLED(CONFIG_KVM_IOMMU) int kvm_iommu_init(void); int kvm_iommu_init_device(struct kvm_hyp_iommu *iommu); diff --git a/include/kvm/arm_smmu_v3.h b/include/kvm/arm_smmu_v3.h new file mode 100644 index 000000000000..ebe488b2f93c --- /dev/null +++ b/include/kvm/arm_smmu_v3.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __KVM_ARM_SMMU_V3_H +#define __KVM_ARM_SMMU_V3_H + +#include +#include + +#if IS_ENABLED(CONFIG_ARM_SMMU_V3_PKVM) + +struct hyp_arm_smmu_v3_device { + struct kvm_hyp_iommu iommu; +}; + +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_smmus); +#define kvm_hyp_arm_smmu_v3_smmus kvm_nvhe_sym(kvm_hyp_arm_smmu_v3_smmus) + +#endif /* CONFIG_ARM_SMMU_V3_PKVM */ + +#endif /* __KVM_ARM_SMMU_V3_H */ diff --git a/arch/arm64/kvm/hyp/nvhe/iommu/arm-smmu-v3.c b/arch/arm64/kvm/hyp/nvhe/iommu/arm-smmu-v3.c new file mode 100644 index 000000000000..c167e4dbd28d --- /dev/null +++ b/arch/arm64/kvm/hyp/nvhe/iommu/arm-smmu-v3.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * pKVM hyp driver for the Arm SMMUv3 + * + * Copyright (C) 2022 Linaro Ltd. + */ +#include +#include +#include + +size_t __ro_after_init kvm_hyp_arm_smmu_v3_count; +struct hyp_arm_smmu_v3_device __ro_after_init *kvm_hyp_arm_smmu_v3_smmus; + +static int smmu_init(void) +{ + return -ENOSYS; +} + +static struct kvm_iommu_ops smmu_ops = { + .init = smmu_init, +}; + +int kvm_arm_smmu_v3_register(void) +{ + kvm_iommu_ops = smmu_ops; + return 0; +} diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c index 3e73c066d560..a25de8c5d489 100644 --- a/arch/arm64/kvm/hyp/nvhe/setup.c +++ b/arch/arm64/kvm/hyp/nvhe/setup.c @@ -294,6 +294,8 @@ static int select_iommu_ops(enum kvm_iommu_driver driver) switch (driver) { case KVM_IOMMU_DRIVER_NONE: return 0; + case KVM_IOMMU_DRIVER_SMMUV3: + return kvm_arm_smmu_v3_register(); } return -EINVAL; -- 2.39.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel