Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp388155lqp; Mon, 10 Jun 2024 07:12:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWg2Q8tJ+Gl88ngQFsqdHL+z8G3K9ocvE9UfOEkTgv2l4AGto3i3JmVbLwn6nrWnrcERMFfXt+Ap4I4ae2cIwipUyJ79M082tCZ/jr/oQ== X-Google-Smtp-Source: AGHT+IGj209L8Dh0mTRt1ksS6oRSg65kVyc8KpVOIZKgmSVem12Agx4cQi/rmMbB+3llTQ352FUS X-Received: by 2002:a05:6a20:9f8d:b0:1b6:fadd:886b with SMTP id adf61e73a8af0-1b6fadd89d5mr2692641637.58.1718028750118; Mon, 10 Jun 2024 07:12:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718028750; cv=pass; d=google.com; s=arc-20160816; b=cHk19cZtPxNTl81VUW/RQ3T5VvBFtEse1je56lXOF9v/QRdCh42bL+ABEu2I5baIl3 eyESZg2hwPPEuHNFaRR8PGbsKON/W9ODyxAGTsdCCWx71y5weFYBfNwpzdBkJREiPpaD z3Ot7rUeh7ssub1/N4dk1IfGDiOICbeaP4H79nEi7pHUEf+fWCgz7UiSbxfGAIJedY0g 6H7BpL3g7crCrwax4frkgahvPtr0DLAalcllAQp5A/o7IYca/mp5CokIOVEAOYhZDokY 6d3bw7IDb5EOcYEGVU+2C+7uoQ5AtMcwKmoouQBpPT1LKui4LmHZ4bbgecVG0ELSFg09 yPOA== 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=nhl9wehuEeFcJP61synp2Oja2apv/1GjWuF4SVlkqGI=; fh=NDCPdPn2hiqHaiIRDYQAzsW9PK20CTia4nECGof6enU=; b=X0cZ52nF+tiVFKmbjhbF2pg1/Se2HpDQeu2Flq7YFTInzRl21cOXS4ybS2e/nDhEq/ uOieIMYDsVNR5U4Ob+dq4LJ7PXSzON2ed908xutIr0T9fhAWEz5i8hmYyf7j/cIqJb0z BUaI311VAI5Y/BWJ6Zbr2ep/3sRpFAEKd9ZYucn+lrdtKjc3IZbsyYQQ7l+l6DeEPsWq j+HWilX/zGzQNdkG9f3bWxuyIKMlqxr1nSW/HerZtG8NhUGuoStoVX15asoBxMh1Rb+1 GQTXw1Lk2BUuBuNUCdBUZdZ3FQpsJbbpGhzFHSVJrlOnZpxevF7T2teUogYuvC/40scx 19qg==; 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-208291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208291-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de262c0837si4536953a12.372.2024.06.10.07.12.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 07:12:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-208291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208291-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 0C428B23964 for ; Mon, 10 Jun 2024 13:56:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E354158D91; Mon, 10 Jun 2024 13:44:34 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B3929158D92; Mon, 10 Jun 2024 13:44:32 +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=1718027074; cv=none; b=sYcKYhY6VMNt25BpUmHuqiLBLuP4RszTcsKShpJVFagU9qJkwgsYLokpfQ5EZ7vONZTn4FqVU7GIIm9ikqBGrmG2a9rNU5x7iPZfZLKQiqb0YTa4NrswjPNAMbAb7ZuODiSJQcV25BzGkg8C1695S4dadAFQDsG0Z6CF8Upv7j0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718027074; c=relaxed/simple; bh=r/KzGjTy1oCCo7hJcIq5YAmatu23kAJ2+nsKGNw48so=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ElohRxLGHwGZb0xGFufhJQKiUXbnsGoGpyWB97XtjuF2QJ/TeJqVcN5c9eBM6CY+osD51DKN9u1j6twDRiBtWdukLRGDg1K8rjuVjGD8lO1cehh83JSBIfkAQbP8noYciPKv8xWmd4BE9DT1I04vBj5VhXCBxe8K2baRSHrBPJc= 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 B29311688; Mon, 10 Jun 2024 06:44:56 -0700 (PDT) Received: from e122027.cambridge.arm.com (e122027.cambridge.arm.com [10.1.35.41]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 323543F58B; Mon, 10 Jun 2024 06:44:29 -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 42/43] arm64: kvm: Expose support for private memory Date: Mon, 10 Jun 2024 14:42:01 +0100 Message-Id: <20240610134202.54893-43-steven.price@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240610134202.54893-1-steven.price@arm.com> References: <20240610134202.54893-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 Select KVM_GENERIC_PRIVATE_MEM and provide the necessary support functions. Signed-off-by: Steven Price --- Changes since v2: * Switch kvm_arch_has_private_mem() to a macro to avoid overhead of a function call. * Guard definitions of kvm_arch_{pre,post}_set_memory_attributes() with #ifdef CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES. * Early out in kvm_arch_post_set_memory_attributes() if the WARN_ON should trigger. --- arch/arm64/include/asm/kvm_host.h | 6 ++++++ arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/mmu.c | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 804da7337439..b7ad94149c61 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1302,6 +1302,12 @@ struct kvm *kvm_arch_alloc_vm(void); #define vcpu_is_protected(vcpu) kvm_vm_is_protected((vcpu)->kvm) +#ifdef CONFIG_KVM_PRIVATE_MEM +#define kvm_arch_has_private_mem(kvm) ((kvm)->arch.is_realm) +#else +#define kvm_arch_has_private_mem(kvm) false +#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/mmu.c b/arch/arm64/kvm/mmu.c index b3793c2b8499..e693887af424 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -2141,6 +2141,28 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, return ret; } +#ifdef CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES +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) +{ + if (WARN_ON_ONCE(!kvm_arch_has_private_mem(kvm))) + return false; + + if (range->arg.attributes & KVM_MEMORY_ATTRIBUTE_PRIVATE) + range->only_shared = true; + kvm_unmap_gfn_range(kvm, range); + + return false; +} +#endif + void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot) { } -- 2.34.1