From patchwork Sun Oct 30 06:22:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 12840 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1665602wru; Sat, 29 Oct 2022 23:26:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4dK5FA8mpodjLpySptxZ2eTn+F1UFX3VSjMNIVWOheogYK9ynKLNUy0wrI2wJHb/iixuqR X-Received: by 2002:a17:907:160c:b0:78d:b6f5:9f56 with SMTP id hb12-20020a170907160c00b0078db6f59f56mr6984600ejc.325.1667111191106; Sat, 29 Oct 2022 23:26:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667111191; cv=none; d=google.com; s=arc-20160816; b=rgq+ErltvQeGTHDywYXGf3FC82dIQf8l0gG7AYv4aynRe3USrHKIIdSeXeCxiDrEmB ySbOcAhJchTEIU+hjvF5fJF1Pbe3n3RaISqip5TyLC512wAlCXIJBCgnEV4HMnBfY/Of G1oEj2YJn7Cc4rS9D2fwC+kP3lkiq5rDXVm7aym+gV4jpcU6XBOg9z4RCBEKaX1iEfxP 4aVjoE7suM12LpNaFrchs0xaf+jyVg7C23Nkkj7+i8DkyImDJOkE0/6kTrjfFsbeb+Kz SduD3kMtJqQALMFk1vYGIt2eHsSkXQrqubDHIpZksp5jvplZh5Do45YYsN4bXqHluFRb m9pw== 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=308qLUNyC3H+eVMoF+4HC902onVTc1xDsYR9c3x2koM=; b=hYdqoVPNXwopKaMOqITCdadSlp87r2fvdlNS82v+FWvUY4WWzJuvkU5VnsG0fzKZ7B 2wc/LeDv/WxJFUL3TnOKyhEdds+MLIwL0uChbrL1GDrAtEPRF8weOcy8vLC1T+HCd0uU ZfllZqClv4xPCoXoiGX5Abs+okQ3h9tpXh1S+kQFk88JlwmK8NOc1CFQRLfb9QH36Z29 lHWzzKuTydbWAd7VTT5jcduXtnW6B/QMesvxynwYOLRpRYOr4PT/a1TjAVsSfdNt4GNG cyqKFmT/S28WJ2deK1ypgvOUDszRqeftYkmWnaKxCVBTOzqLQRsOca9MhDtwcaLaEFEB VTxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XmjTl6s3; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd21-20020a170907629500b0076fb816dae7si4785963ejc.97.2022.10.29.23.26.07; Sat, 29 Oct 2022 23:26:31 -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=XmjTl6s3; 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 S229717AbiJ3GZM (ORCPT + 99 others); Sun, 30 Oct 2022 02:25:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbiJ3GYF (ORCPT ); Sun, 30 Oct 2022 02:24:05 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A83BDD; Sat, 29 Oct 2022 23:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667111044; x=1698647044; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S7sJ6GhRmBa9HotJtfVTbz0zU6hwSLQrUIW8UTLhzm8=; b=XmjTl6s3YnWZ5BYFeMbZGleSPZtkMPM/8uxh0zR0WPi2tQNEZx8mD5La i8ighYgK3svuHSnpzHklvPV/uFZnUKANWD7Isht6yJkFQ7H1Ie27BHT4i 2GfMia2sq+FqEBeQRYsFr17HJ9VDEyH1CchqWmw593fVUk7BdAdskdSqA PYd+ooAKVL4FgcpZFjiiuMhZPElfH45bgJ/C4P203OX7fGWbnbJboL7nQ apYxJymU048+0V57KUh7gdq09ErLuy5+H4RGpiS+wE62v4rTKFuAL1g7q OsKp25sTqrcWn6UVRz9Kw1tBwcz9LSVbNCswZ9wH6LLbXF+uCvphwvUz8 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="395037131" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="395037131" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:23:59 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="878392888" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="878392888" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:23:59 -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 , David Matlack Subject: [PATCH v10 019/108] KVM: TDX: Add place holder for TDX VM specific mem_enc_op ioctl Date: Sat, 29 Oct 2022 23:22:20 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-4.9 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748092784323384561?= X-GMAIL-MSGID: =?utf-8?q?1748092784323384561?= 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 aedba5acb8eb..b4e4c6c677f6 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -63,6 +63,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", @@ -205,6 +213,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 5a3ed8217a54..d77709a6da51 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -477,6 +477,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 057f2be3d818..93ffe2deb8e8 100644 --- a/arch/x86/kvm/vmx/x86_ops.h +++ b/arch/x86/kvm/vmx/x86_ops.h @@ -140,6 +140,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; } @@ -151,6 +153,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 */