Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp511387rwb; Thu, 12 Jan 2023 08:46:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXvxpLWvnK+LUfqohRqSeOSTrPfQkIlCNiRUc4akjH11V0KIw5HKqr5CnM8nLKaICVgaUAeb X-Received: by 2002:a17:906:f2c9:b0:7ad:b14f:dea4 with SMTP id gz9-20020a170906f2c900b007adb14fdea4mr98763ejb.14.1673542012402; Thu, 12 Jan 2023 08:46:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673542012; cv=none; d=google.com; s=arc-20160816; b=bVwJxBNU5l1eld8LKSfgrceyGJAfQmpToD15nbPVjjbH9nq0DkaTpMIkSHdSvRjroY 3v2dBe+BT3eH5dJN4CiwQlSQmcEoVdEtfpcd6qYav8b0hWrJ3F+zClnE+2D+C7shWoFT Gj1a0ONDwRLYte0Qah//4BzpQkR8AY7gmkHgx+Ntsd3aPbJOUBeAfa+izoRnKBNczY/J +DUm8KjWQ8H5rFheYvKWf7sxh580EQboFTy9FF0HAEd6yLovr9/ZSuGBEbOdSxDD/TZK aauvQGjFEchrNUJSECW6l3LFce7PKnvIrJMPwO9v+C5qvnNXn3DWkCtNmQVRdT9Ae6Ol KC5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dmsXkYH0cgRZ/Zg01THnrQM1cv4gUJCD4gpZwdcZnKM=; b=bw6LOdPKgyu/4n9mzKk75c67005bgfPp3TR84w9fEYQKRPIuAaDePU4Di/qtqFtbHt 9bl60bkAwdXXlXYC0YDpmz7KvpMHRkn+iFIzbO6vRLBnzyVUzTYtT6EdOh3FnotdqgRU al2UW0a0U/htL5wyERQvjxhdnmAZSKCBgxodhIkD3/cMNIyi1k0m1wojhztUitzb3akT SGviLH26VTspKhRi39IVxZePHa87WQS02ggLaVSzmY4jTUHpU6LMWlN1j3bJyHs8Q29s tY5x9xAWVpVeQO86ImA3KUtT+kRCvi07Cf7ROhWzkZy+KGNzpkwLn0JmdVceg/P9K05y /K2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HFUFsGrA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne12-20020a1709077b8c00b007c0e155eae2si20508639ejc.58.2023.01.12.08.46.39; Thu, 12 Jan 2023 08:46:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HFUFsGrA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240911AbjALQnq (ORCPT + 50 others); Thu, 12 Jan 2023 11:43:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239768AbjALQhg (ORCPT ); Thu, 12 Jan 2023 11:37:36 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A88A15FCC; Thu, 12 Jan 2023 08:33:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673541235; x=1705077235; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=feOB2BzlNggpUsOL/RdqPhb1SxM36ZB3cZSTdfK4kfU=; b=HFUFsGrAuI2JNTIVrtDK67A6RDSQxnacZfR7bJxU5g6t93sge6c0kcv2 hUSMjUvbuXHcTspNus2EpLQYqeWsTky4cBg4eMGnP8FhEqIsP9I0fIEj4 x7Wf1oO/GC4LmVME6hpeYN0gdeH+4eAX4YMVryB8Q/SHUFAfVV3u3npnU HB+H4802iDUoL/NHqxN7wlFycT8VCDjFdU8w/74g8BtQhTGdbX8BpE1ac B3TDgY8zmbvVUkOW8zT6gDHjmIe3N9aktpryZk984yLpDW3LCvth3a7UY t+akfmgwmskGq7LNKK/2XEnX1vX7MQimx3KuLSNOWuiw3jNL2tGSY96Mg w==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="323811718" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="323811718" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:22 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="721151677" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="721151677" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:22 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack Subject: [PATCH v11 016/113] KVM: TDX: Add place holder for TDX VM specific mem_enc_op ioctl Date: Thu, 12 Jan 2023 08:31:24 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Isaku Yamahata Add a place holder function for TDX specific VM-scoped ioctl as mem_enc_op. TDX specific sub-commands will be added to retrieve/pass TDX specific parameters. KVM_MEMORY_ENCRYPT_OP was introduced for VM-scoped operations specific for guest state-protected VM. It defined subcommands for technology-specific operations under KVM_MEMORY_ENCRYPT_OP. Despite its name, the subcommands are not limited to memory encryption, but various technology-specific operations are defined. It's natural to repurpose KVM_MEMORY_ENCRYPT_OP for TDX specific operations and define subcommands. TDX requires VM-scoped TDX-specific operations for device model, for example, qemu. Getting system-wide parameters, TDX-specific VM initialization. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/main.c | 9 +++++++++ arch/x86/kvm/vmx/tdx.c | 26 ++++++++++++++++++++++++++ arch/x86/kvm/vmx/x86_ops.h | 4 ++++ 3 files changed, 39 insertions(+) diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 16053ec3e0ae..781fbc896120 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -37,6 +37,14 @@ static int vt_vm_init(struct kvm *kvm) return vmx_vm_init(kvm); } +static int vt_mem_enc_ioctl(struct kvm *kvm, void __user *argp) +{ + if (!is_td(kvm)) + return -ENOTTY; + + return tdx_vm_ioctl(kvm, argp); +} + struct kvm_x86_ops vt_x86_ops __initdata = { .name = KBUILD_MODNAME, @@ -179,6 +187,7 @@ struct kvm_x86_ops vt_x86_ops __initdata = { .vcpu_deliver_sipi_vector = kvm_vcpu_deliver_sipi_vector, .dev_mem_enc_ioctl = tdx_dev_ioctl, + .mem_enc_ioctl = vt_mem_enc_ioctl, }; struct kvm_x86_init_ops vt_init_ops __initdata = { diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index f46579102a44..2bd1cc37abab 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -78,6 +78,32 @@ int tdx_dev_ioctl(void __user *argp) return 0; } +int tdx_vm_ioctl(struct kvm *kvm, void __user *argp) +{ + struct kvm_tdx_cmd tdx_cmd; + int r; + + if (copy_from_user(&tdx_cmd, argp, sizeof(struct kvm_tdx_cmd))) + return -EFAULT; + if (tdx_cmd.error || tdx_cmd.unused) + return -EINVAL; + + mutex_lock(&kvm->lock); + + switch (tdx_cmd.id) { + default: + r = -EINVAL; + goto out; + } + + if (copy_to_user(argp, &tdx_cmd, sizeof(struct kvm_tdx_cmd))) + r = -EFAULT; + +out: + mutex_unlock(&kvm->lock); + return r; +} + static int __init tdx_module_setup(void) { const struct tdsysinfo_struct *tdsysinfo; diff --git a/arch/x86/kvm/vmx/x86_ops.h b/arch/x86/kvm/vmx/x86_ops.h index f0803cc15151..bb4090dbae37 100644 --- a/arch/x86/kvm/vmx/x86_ops.h +++ b/arch/x86/kvm/vmx/x86_ops.h @@ -141,10 +141,14 @@ void vmx_setup_mce(struct kvm_vcpu *vcpu); int __init tdx_hardware_setup(struct kvm_x86_ops *x86_ops); bool tdx_is_vm_type_supported(unsigned long type); int tdx_dev_ioctl(void __user *argp); + +int tdx_vm_ioctl(struct kvm *kvm, void __user *argp); #else static inline int tdx_hardware_setup(struct kvm_x86_ops *x86_ops) { return 0; } static inline bool tdx_is_vm_type_supported(unsigned long type) { return false; } static inline int tdx_dev_ioctl(void __user *argp) { return -EOPNOTSUPP; }; + +static inline int tdx_vm_ioctl(struct kvm *kvm, void __user *argp) { return -EOPNOTSUPP; } #endif #endif /* __KVM_X86_VMX_X86_OPS_H */ -- 2.25.1