Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3462730rwb; Fri, 30 Sep 2022 04:05:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7BltU/rBZSoKSeSVw7AzEtUL0AjqCszmxHLZf6sT5wdJsqt+1yfGFwXRXydiGWr9wfB34Q X-Received: by 2002:a17:90b:1e0b:b0:205:bce5:467f with SMTP id pg11-20020a17090b1e0b00b00205bce5467fmr21310923pjb.24.1664535959111; Fri, 30 Sep 2022 04:05:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664535959; cv=none; d=google.com; s=arc-20160816; b=nIenZ/z2CAwOliz+8Nc9psU0+bYp7Kt1K41WVvBSt20JcAuYPWjL79h3Z/AXxcTc9K ZHRRZUpE720HBqsnfOdpy6BCv5iHQwJzYenWT7CZGQJ7KiCT6yRxLQYDoyOUZijCNItF ea1NMn6brDnH6b50WBAfysX7O9UCfC4gdsqmXYtERcpjSplYInqi20IAy1GXHnPAThe0 qdBzeNtUWE+oi7XkrCyN58fsoLbbFiovFfatEv9OapMcB1+WUo8ckp8ErV2Ha7GLagsU 0qJDqXdAEw62xdvnFXP3/W3hOmXtcG8x87U7mf7uekO13YHhGJFeqapgPEp4Cg0XGl7S IlWA== 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=v78mKpl9GlUE2F6d/ozdpP1xFr7a2O/G9E+zp4wI8ms=; b=lq34WDuQBYATq8snmh6cDOuCZr8Fa6kBjs96Ru6x53wO/UjR8Vpxjz8wTppCypDoKE YEAHjT2lQvDXu94NTY49LFfFDsEQdD4NoAKexbQ6U9pMOIptNaUCG7sIOwYuW9hpZvuT J8mnVEv0JKCCZUwXFKo2n+OdkNgRAMC4kNMh2cJT7FQ76ee4cInTpuDCQV0bPfOut0qj yqGai+pxC7tXb9KAt33mC58X1CwpARAJqUYr874y99+d0mjCJ6FXm5eLl0GgiY8kpKPA 7Qyq1+uSthvYbLeL8a+U8qEZ5MBKn/aBKiDkXNxCxLivB7UkJoZS82ijYuhZ1FeILP3h oQCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MTxp3eWl; 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 on1-20020a17090b1d0100b00205f1a25a31si2374581pjb.161.2022.09.30.04.05.46; Fri, 30 Sep 2022 04:05:59 -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=MTxp3eWl; 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 S231793AbiI3KUS (ORCPT + 99 others); Fri, 30 Sep 2022 06:20:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231328AbiI3KS5 (ORCPT ); Fri, 30 Sep 2022 06:18:57 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C664F15ED1E; Fri, 30 Sep 2022 03:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664533136; x=1696069136; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s70r+loZ+1jQv7SgNY3r7Wv+g31q3pKzMTqjzsqPQ7g=; b=MTxp3eWlVb3Jz2/2S1pGkStosrQNudz9A+Aagnhfsrqhpc2W8fXKIgLe wBQqYZMFsjXxvPcXp3vfseWCvglFvMDtGtcwHZXoz6kfXknLtp5aGm0sy uhqTAzJ3kDsHicQHxVsIQUs3jEF1x/Qcbmf5Hf07qCA9j6Gy6z1xDfa4g NSTb6Bkgp3x5txgAtqtkaWO4CU2wYVY+I62s2NAbNDjJQ7aTFP3IEypZx 9R4NXKkNazBW4haXSUB+WvQhqchmBSKjuI0/WYH5goyRWC5N5QWwVDT/0 bXJYzycaY5OErkSmDGI70XKFkWzvCQYBK1u59RUwyP76T+xz+Mh/HWNWU g==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="281870069" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="281870069" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:18:54 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="726807565" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="726807565" 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; 30 Sep 2022 03:18:54 -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 v9 019/105] KVM: TDX: Add place holder for TDX VM specific mem_enc_op ioctl Date: Fri, 30 Sep 2022 03:17:13 -0700 Message-Id: <5d72eef695c4a6368d2bef411a58c7a3ec7e62c0.1664530907.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=-4.5 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_PASS,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 071e7d148cb7..42b1243a89e5 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 60c5c08593c3..76e00e9bfe91 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -475,6 +475,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 a831dd9ee1a3..3576b5c7238d 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 */ -- 2.25.1