Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4118392rwb; Sun, 7 Aug 2022 15:34:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR7u70S4Z0u2qTipvbfGkpFCTQAUjhuJGE0Ylc+wlmFoH5/Q72AFlwUgvJBVb7KY3cigqKjd X-Received: by 2002:a17:902:d50a:b0:16e:e1c1:dfa7 with SMTP id b10-20020a170902d50a00b0016ee1c1dfa7mr15924729plg.160.1659911661642; Sun, 07 Aug 2022 15:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659911661; cv=none; d=google.com; s=arc-20160816; b=slsaoN9/9oTkvSG0gqYXdeku09TX+zApW97MRqnyswmTQOFZrITbtj2zpTQ7DwegAT f7OeVbtGsw3r8dYH14uqoCPTot4/Kta0ym5TBCZ4v+sxI2Z7kQRZSEqNaKKZCly6bDfm 0u57K1qgPfrHZeNCF6kyZvbRQRr3UdCJRHTq+NnC/tt9Dofty+PVMBHAB4Ho3N1N8yvS DuM19i/hjls5CA2d9m8S6MIQxVngH4t6go+oKbesF9URj5UP0IR0+IBPYWCPsLqziwZI FrmD5gkrb6M5VrJIiDgaD4ZTDSE3jwVqLjCP6fMDEz+NUJe05veQCDmnHupKg4OttwEq rtpw== 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=4WhL0cHfTCgO8e7TOh8z8+M+Wy/YNqNGZXCD1IcZe00=; b=F7f5SUButj01AFpsXmCh3LYF/6PWJM/lKbSRNxx+f41kG1JusubfsUmYsgp47zF2rp 8Mrj0CsW1AyTj+5KNmZ2Z446YqQ/dmy0lWrQyw8f6rjBuigjMetTHjyWeUIV/i4ux/1J AyrylYmJXqZHTdWTz04ao5rYChVV6MqIT9oyHqLBIRTFMr+8fO+Ufb5t/O+Sl5tf9lPx buxtnQue9joLahlCAXtAJMNnZo+TlCvMe384YCYTqB401g0glX7u0yIE+tQDvdH9pY52 8ydlTQydc+EkvqPS2imzvCOVZFuNH0gNLqEPmHCfxyPHoa2BOfj50uOdowyz3JyRgUC0 1Onw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="H/v8gmtR"; 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 p11-20020a170902b08b00b001709c82ca08si2829464plr.297.2022.08.07.15.34.08; Sun, 07 Aug 2022 15:34:21 -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="H/v8gmtR"; 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 S236837AbiHGWEz (ORCPT + 99 others); Sun, 7 Aug 2022 18:04:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233379AbiHGWCj (ORCPT ); Sun, 7 Aug 2022 18:02:39 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 370156584; Sun, 7 Aug 2022 15:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659909757; x=1691445757; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wACt/vfMXjTYDT4uzZ33S82wBmB8TFY+cJ8HidPF5RE=; b=H/v8gmtRUF3mVOoZCpFe+IKNpNDqbNc43V2dfeebIfvWdjOP/mNCteUA TzIyRqf9YPeBG+lvyA0CrXyvNE9Qf5E1aPR/MtHFP13jkmQVFz5bmtEj3 WqNQYJv13U4WZjP2hKPBkiMC+cndK6PONP3+0hpnGP1Arki2rw/if74Qq L446vvqF7sxIxJ8Z1mG1V23K0jnhOCxjztSNml7QSMzB0pZ0lbuK3Cm+a ABz53QuX1qRE43G8Y8ei24/Oe3NPESeazY3K8dyA1khrlIhzCz9Ypok/H fPOlyjmzjsm4RD7Ex9LWLke1ikT6btlP49O3VP6VTx87mHdduSn+Q7JpJ A==; X-IronPort-AV: E=McAfee;i="6400,9594,10432"; a="289224088" X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="289224088" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2022 15:02:32 -0700 X-IronPort-AV: E=Sophos;i="5.93,220,1654585200"; d="scan'208";a="663682506" 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; 07 Aug 2022 15:02:32 -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: [PATCH v8 022/103] KVM: TDX: Add place holder for TDX VM specific mem_enc_op ioctl Date: Sun, 7 Aug 2022 15:01:07 -0700 Message-Id: <2d65bd56a7ab8c0776f5c6b7c8481dd45ad96794.1659854790.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=-5.0 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,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 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 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 16c6570dbe52..d3b9f653da4b 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -424,6 +424,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 02490515d190..f0fe40c7ac34 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