Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4422477iob; Sun, 8 May 2022 12:12:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaSajltKaPyUO7KzRCRp/6TPyB8lBGUfuoaYk/F9VLq104QvNFtfAcZW/GssFFXslYHupX X-Received: by 2002:a17:90b:1001:b0:1d8:4978:c7d5 with SMTP id gm1-20020a17090b100100b001d84978c7d5mr14672349pjb.167.1652037124409; Sun, 08 May 2022 12:12:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652037124; cv=none; d=google.com; s=arc-20160816; b=WxVExSxwanX2Ia7Y/6OxVqeHEtsUmw1BpmMeJCpE/Fbyfjant+ikkh8R1Ma+6GtqeO DmoM44Swxwjk0UTkXx1r3VPCQSSE+f++Y/netkNtpQNGl9fggH7SGD0VxFT7L09x+8/D ApmkTrr6askQfk3WCY6gBDsTczkvTrBkPYiuKd53npTFSPsygSJNvYt9NA36+9MCBV88 1iBfEJPO/OOm93Cp0hOiL5VTFPjcUmBGm8dE6mjrrs3d69j/koqGwfFN2B4tMKFw6ree TA/mevKaZTBI3Aj4fpmW8HpgKKEzQ047xCZh6neG6IhTHnHWAEGXtzev7u09jLKUcG6X 0xRw== 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=w1FlKYaDrGd60D2p/ku1YIe5LBFFpo/WAvCxSXwpSfI=; b=fSaQS3kje1vGFfKUzZguTnT7g08nmSCpT8Gt8d7LZiFyNAM7BbFOpwrX1WxTfI9WLe yNA52cVivGVwOaosE1n0KQR3+D34aJRI5s95X6fuCfRLvL4OUAZAtOXM17JWKg08bEw2 v5Rke1QJQCb0MKH1KIAZChgCmuA1YnINtxL/MHY3GYOzu+ctm8ErBWwhobs4HZ3UhH0I 7ZeakB+61Yk0gOwZbQmqUlAUJJw9emwQ4LTd2oYRtDRRs79F10q+97vHWWSHzPDA/qZC pUWbddPC4+ngza6apAdsuut1aVO9LAVQcPHqv46LgW9vl9vc7SbeP6L4JDUi3B2kPeeG 1A2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BNtyeUKx; 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 f9-20020a636a09000000b003aa55f74d7csi11493106pgc.484.2022.05.08.12.11.50; Sun, 08 May 2022 12:12:04 -0700 (PDT) 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=BNtyeUKx; 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 S1384315AbiEES3B (ORCPT + 99 others); Thu, 5 May 2022 14:29:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383179AbiEESTl (ORCPT ); Thu, 5 May 2022 14:19:41 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F6962C67A; Thu, 5 May 2022 11:15:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651774552; x=1683310552; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lEoC3Ic1zLdkdH9xkBmGOfUxHuUICOpZJb0q3gtoue0=; b=BNtyeUKxVuO/6igdjDCJQd0fNlK+aAgY9JHALLhl4ahitDqNRGdaJqoW PlRSIBmyae6gcumi+Zwewg4mmcFvclDk999sgCr8k7kxdLyT/PqqjMPhC TkOZ/MbsnGYVfLnixmFUzQ0W/gI66iEsXPy4bNu2HP0D3L8id02IQtfVi bFLX66jkBaxoaVqZsXO3ov76BD7roJs8M4RApeQza/L3pwOLGB1qz8sfL USQotqDfsGUn00RMZpo859sOUoL2N006TFWh3iclV8xIZS7GRsFxB8Ey3 zq8YSRUF/OA2XEAg2g7qbqFuOgRF1PcTZu1hHduS7NliMfmk3uKaOdOq3 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10338"; a="328746257" X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="328746257" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 11:15:43 -0700 X-IronPort-AV: E=Sophos;i="5.91,202,1647327600"; d="scan'208";a="665083207" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 11:15:43 -0700 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 Subject: [RFC PATCH v6 024/104] KVM: TDX: Add place holder for TDX VM specific mem_enc_op ioctl Date: Thu, 5 May 2022 11:14:18 -0700 Message-Id: <46c9ee65c92b526f8c1c009099a08a2e0b291649.1651774250.git.isaku.yamahata@intel.com> 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=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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, and VCPU-scoped TDX-specific operations for device model, for example, qemu. Getting system-wide parameters, TDX-specific VM initialization, and TDX-specific vCPU initialization. Which requires KVM vCPU-scoped operations in addition to the existing VM-scoped operations. 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 7b497ed1f21c..067f5de56c53 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -73,6 +73,14 @@ static void vt_vm_free(struct kvm *kvm) return tdx_vm_free(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 = "kvm_intel", @@ -214,6 +222,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 07b69ffbe55b..a4be3ef313b2 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -438,6 +438,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; +} + 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 75e6cdcb06f5..1ff555cc6c17 100644 --- a/arch/x86/kvm/vmx/x86_ops.h +++ b/arch/x86/kvm/vmx/x86_ops.h @@ -137,6 +137,8 @@ int tdx_dev_ioctl(void __user *argp); int tdx_vm_init(struct kvm *kvm); void tdx_mmu_release_hkid(struct kvm *kvm); void tdx_vm_free(struct kvm *kvm); + +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; } @@ -147,6 +149,8 @@ static inline int tdx_vm_init(struct kvm *kvm) { return -EOPNOTSUPP; } static inline void tdx_mmu_release_hkid(struct kvm *kvm) {} static inline void tdx_flush_shadow_all_private(struct kvm *kvm) {} static inline void tdx_vm_free(struct kvm *kvm) {} + +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