Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3423146iog; Mon, 27 Jun 2022 16:04:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vth32qzMqsaaN6mn5tlLzKAE0ONEU6cY1KzUV8ckBXeUChN1oz9hZPh2n/3HaUrr+/00vK X-Received: by 2002:a05:6402:e83:b0:435:a9bd:8134 with SMTP id h3-20020a0564020e8300b00435a9bd8134mr19259390eda.243.1656371084791; Mon, 27 Jun 2022 16:04:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656371084; cv=none; d=google.com; s=arc-20160816; b=fMxAlzFKX1SSM6JjTghkj+QeEfq13CJ8HeAZbzZg/rcGAGWVi/a0EDeZ5NiFswjmi+ m3Np2i3h9eSyKsCtjiyDUJqK+f8j4DUYCVYvkkjAjsw2A2JFyNDaNHz5Y0Zxb3L3Co8W PJGgwVSnBnTR9KC7BIyY8P/G/iDYdI6jIrEouRKeh3S0kQB+xaM3QO9h4l3+ahUGQb2Y XOSI+FEbbg+wh1hhbouOBlmWzAxMCde+3ynRyT9mFxmUocflCLwFOLKg3KUIB9K/Ulae 9aIigpdQRInG2HCPvO37KNGyECz9jOUp7K5PPIS8eCoM5IUOQnGK6UwM4KYyDUI0XQdS iW0w== 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=QKS18ndmSp7b3NzTwXm88+oKcwJFlp9xT1as3iZ6hL8=; b=yhlj1jmUpxcHgC/PwdHxNETdrCeYnFVwXP6zsYNZdQd0EtGYWr8OgsSTKdHX8Tx7MW dQIeEhjWuz9WBjzF4TEeQbmhk+ZftVOwDkeLDBxvUpuoN4SM7XRnbpDCxNoBPp4c/pLR xVKOpSUD7uwggZD7RaDt+EQr1BLvzk/L4OeUgjlODazheJA6xdFYeMgXX2WDL2GBSbXe GAazllfNX4+c5omiqHIkqGb2N/C/HZqXHsmnWQFrrOVx6JhK3AFFolcmUS/RQFai40SE 1L8eCJUaizfUi5+JC6vSrRGksr1p9vVY13FZYcDIHvWHHzjZorKd6K2Qfg7JooZ6D/ns CYrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=m3twIKay; 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 g8-20020a056402090800b0043567603f82si13721137edz.288.2022.06.27.16.04.18; Mon, 27 Jun 2022 16:04:44 -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=m3twIKay; 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 S241528AbiF0V43 (ORCPT + 99 others); Mon, 27 Jun 2022 17:56:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241337AbiF0Vy4 (ORCPT ); Mon, 27 Jun 2022 17:54:56 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 033B2636D; Mon, 27 Jun 2022 14:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656366894; x=1687902894; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TLfSg9fkW9Ol6Rant1TCFlyMti8/oM5cJHW1wx0IXMY=; b=m3twIKayJVbFVj04XtGrGvpkSf3HCyG6jNTlyPIFlFHmR7oGvBh+cIXM RGfxfyQ1Q6u85ThdPrNrJ9RedLlPAI/IP0XhoSIle4FO33HmLcG4GrOqf BEeM56KUErbjk7pTPPI/RzWIDDMzS1nwD+qWQl+bwFsKXwhkGUuTEwVUY wzD+7wSrGWYz38qMpIpNvM3r9IVY02QRwnSyOtU0z0cj5Mx6xIHqUU3Zz 5mMszhcaoki882HkBOTEyxNfNVftpqIFAyUXSeuwNSrpuPosvh5ojvbQp +E0Ljsk73PRsrAbOukjqt2vlagH4mn51HweGiijGkPjtqdh4X7CR5pMBx w==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="281609521" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="281609521" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:54:51 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="657863510" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:54:50 -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 Subject: [PATCH v7 024/102] KVM: TDX: Add place holder for TDX VM specific mem_enc_op ioctl Date: Mon, 27 Jun 2022 14:53:16 -0700 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=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 ec4ebba4152a..2a9dfd54189f 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 3027d9821fe1..ef6115ae0e88 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