Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp15306lql; Fri, 12 Apr 2024 02:01:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUt7OY0UWTN8PTqaEM5NEyqig3fJiEgAAYWD1Jkg3MXxft/sT8HWrBtTrVT2pJWW2zTiIQz+rAotMcbt/jRl3BMbkSywnmo5Vb0QUQGIg== X-Google-Smtp-Source: AGHT+IFaGsEvbMVgwOWQnnfKF1zk0mkrjewrrevkFxZwwRdcrSMLjLkNwrH7syXtMybHVPhy84I6 X-Received: by 2002:a17:906:c78d:b0:a51:ae39:d385 with SMTP id cw13-20020a170906c78d00b00a51ae39d385mr1212306ejb.1.1712912490525; Fri, 12 Apr 2024 02:01:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712912490; cv=pass; d=google.com; s=arc-20160816; b=j5zGrnYeKj8ojDbSv9+0PmrzZ3IlbTKTepxjLGakhmlGk2cRJzIBZmWK9vX9VmUvxL bUoEe1An6X6vmkyvbFYnPjt82m6/KyneIiMdr9DzON06cNDcy+TE+V74tyuZEGJcJheh 8Dgs8fPDAd1suL+SmA9OxwW68t04tS2FU7srKVrUASg6NwMLU+HcJ2J//dQ62Vl9WOxj lgtmRMpsSA4WKlV57y2wX8ckJozdQu6dhQq1jrKhIQCtKEV6r9myiCHOtf0ieBQlAsAj bMW81VWHOoYBnpFQ5Ier4YrEuVInoQjw5OxlMHQ3AJmU88F22+GK+e2IxMrN+Mbqrp2t Mhqw== 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=hl9cnhG1FcGWEI4wPZwxBljhIrOCaDe7sgN7rPXakR4=; fh=NDCPdPn2hiqHaiIRDYQAzsW9PK20CTia4nECGof6enU=; b=g9LGH8FkfAWRitO8epMJWNRKPA0wtjo712gfDCYiJrQLyg5WB4/sI2Bn6fPkUCIqTC Va6uakixeUj7KbaimQoOq68ts91BdzUmcXsmJVUzw0/zygsEAK4Egc/abzxTIBHe+nJB xJi0iPtJwM4MFXvYwA7DrPHj8UJ3YMqdg3GX/mHMy43iMEIbDpbxvUN0lAtUyYoZpu0h 6w6FZqXR7d0y3ZZ1/jacLAZ3vlbsTiQ1iStMNjAuumREgcgjTE3SarEeWwkfFnpBFHFt uJbOW7sSeUCNISe8k+FPLOoPb6B5ryUZySVUj30TKjkcOJvkXvNGnynNMwyB9bc4grB4 kxtA==; 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-142315-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142315-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b18-20020a170906491200b00a5210154eb2si1505647ejq.195.2024.04.12.02.01.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 02:01:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142315-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-142315-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142315-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C6A3D1F233B2 for ; Fri, 12 Apr 2024 09:01:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4316A135A48; Fri, 12 Apr 2024 08:45:00 +0000 (UTC) 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: 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 --- 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) { } -- 2.34.1