From patchwork Fri Apr 12 08:43:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Price X-Patchwork-Id: 13627228 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65FAA1353E4; Fri, 12 Apr 2024 08:44:58 +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=1712911499; cv=none; b=kRcYy8+yepWQS/i2t3n6Exa2+ImwmaRqSEMz9C5DXj60lOnblWcnH+n0Vm2TwWuyLubLD+mDn/ULHO9y5xt8zpHg6hCW3LKFNaaTcu9J5z5gSlcqien6OJyg1RgyL1Jy+YbdCLc+HfjSQNHZZvaJj2v/BUM9TsdMtDVkvfzsTSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911499; c=relaxed/simple; bh=9AF/omkmreyJOuEz9hkUAV6isI26rtVYqlnOfZxnhIY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uinMkOY1L5wXNgjMURh8duo1w7RK6Ink6uWibqUmNLTd5JVF4p8QGwZHqpGasqeeEFB2zIpxH05VhCSCB95RKhvD6dkrzurMA6sHjsVLgTy3PoIKUoTR2IgPt5RZfmC3uREKzY51gEJq3B0Qs5FveCo0sgOrMuDF45mhBtwnDDA= 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 59EEC113E; Fri, 12 Apr 2024 01:45:27 -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 F1BC53F6C4; Fri, 12 Apr 2024 01:44:55 -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 42/43] arm64: kvm: Expose support for private memory Date: Fri, 12 Apr 2024 09:43:08 +0100 Message-Id: <20240412084309.1733783-43-steven.price@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240412084309.1733783-1-steven.price@arm.com> References: <20240412084056.1733704-1-steven.price@arm.com> <20240412084309.1733783-1-steven.price@arm.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Select KVM_GENERIC_PRIVATE_MEM and provide the necessary support functions. Signed-off-by: Steven Price --- arch/arm64/include/asm/kvm_host.h | 4 ++++ arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/arm.c | 5 +++++ arch/arm64/kvm/mmu.c | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 902923402f6e..93de7f5009fe 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1259,6 +1259,10 @@ static inline bool kvm_vm_is_protected(struct kvm *kvm) return false; } +#ifdef CONFIG_KVM_PRIVATE_MEM +bool kvm_arch_has_private_mem(struct kvm *kvm); +#endif + int kvm_arm_vcpu_finalize(struct kvm_vcpu *vcpu, int feature); bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu); diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig index 58f09370d17e..8da57e74c86a 100644 --- a/arch/arm64/kvm/Kconfig +++ b/arch/arm64/kvm/Kconfig @@ -37,6 +37,7 @@ menuconfig KVM select HAVE_KVM_VCPU_RUN_PID_CHANGE select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS + select KVM_GENERIC_PRIVATE_MEM help Support hosting virtualized guest machines. diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 2dd014d3c366..a66d0a6eb4fa 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -89,6 +89,11 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE; } +bool kvm_arch_has_private_mem(struct kvm *kvm) +{ + return kvm_is_realm(kvm); +} + int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap) { diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 48c957e21c83..808bceebad4d 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -2171,6 +2171,25 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, return ret; } +bool kvm_arch_pre_set_memory_attributes(struct kvm *kvm, + struct kvm_gfn_range *range) +{ + WARN_ON_ONCE(!kvm_arch_has_private_mem(kvm)); + return false; +} + +bool kvm_arch_post_set_memory_attributes(struct kvm *kvm, + struct kvm_gfn_range *range) +{ + WARN_ON_ONCE(!kvm_arch_has_private_mem(kvm)); + + if (range->arg.attributes & KVM_MEMORY_ATTRIBUTE_PRIVATE) + range->only_shared = true; + kvm_unmap_gfn_range(kvm, range); + + return false; +} + void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot) { }