Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1886009pxv; Fri, 2 Jul 2021 15:09:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlUSnBCDSaUbBYtqYLo+hCDGnwVhr67ZfEzsVDdQOvGfrT2oj0AM1g/7EtjdRj8AuHgr8o X-Received: by 2002:a17:907:3f92:: with SMTP id hr18mr1929870ejc.462.1625263788374; Fri, 02 Jul 2021 15:09:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625263788; cv=none; d=google.com; s=arc-20160816; b=mKzYd1q4u4ErUfXpJxxUjb/u2KNPdkORm7DJVjWNDH1uCNmUdymlyY5GghxaugS3HJ MlINW0/3t/IUk8C/TWQWWhp14D7t4eiKYgX59xI04ghWO05SzGDt22tDtSz/rSSnDAhd 1tyyQSkgW3zm1HgwihHj5nwyu7GuNtlDp+zXosmS7GvBv957ug/BygUldcuzAXsYBoH1 85b/k+bKLH/Wpa+iUlwJtJ3dCgDJhb69BXFX4IWyFVVlH/xSlTCZjPSU8xd5nKzB0v+F zQAFkb50l2SSBZoM9O5zTgx/YfQsrKW+S7N/w9beRB6X55q3olkWn8iAt7uGJLTc6kIH VYyA== 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; bh=NpzCFqLe1Vz/vq6J2LoIGO6D0uMY4xA9KQyqgVNwsPU=; b=o+jBNilHY8tSmb9YxSq6fg5V+kRTujo94cpofG9M6F36puzXJ4LUbpk1hgV6s3aJWN znIZymyIVhVxCsrtCdo2iUfQQmQvQME8H3QDANznsy+AdhGZmvB9oXC6z7B99LiEwZg4 Pw7znzHbXYaow95zhzjXb/GxCVmp2WUAMqaB7lcUs/HvMLyYHtScv8+au/xdd26ikrpW C/r/KqPcLi3xHC/BHqGLte2wskiP7Rh9kYXHck1QM4WpQVU7/skdSPVfxYQNOEVW3jIx uFqOpX1dxBNIx0undjAE3Je3eWZMtSBlwL2mefiqWfeSIEAQclPpKWn/MfvddhN/0B/z tTjA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h20si4392937ejl.315.2021.07.02.15.09.25; Fri, 02 Jul 2021 15:09:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233213AbhGBWKj (ORCPT + 99 others); Fri, 2 Jul 2021 18:10:39 -0400 Received: from mga02.intel.com ([134.134.136.20]:51166 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233020AbhGBWHy (ORCPT ); Fri, 2 Jul 2021 18:07:54 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10033"; a="195951891" X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="195951891" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:21 -0700 X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="642814703" 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; 02 Jul 2021 15:05:21 -0700 From: isaku.yamahata@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Xiaoyao Li Subject: [RFC PATCH v2 11/69] KVM: TDX: Introduce pr_seamcall_ex_ret_info() to print more info when SEAMCALL fails Date: Fri, 2 Jul 2021 15:04:17 -0700 Message-Id: <44af6d41af20238916e33fa2a9c041f821e62d43.1625186503.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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaoyao Li Various SEAMCALLs may have additional info in RCX, RDX, R8, R9, R10 when it completes. Introduce pr_seamcall_ex_ret_info() to parse those additional info based on returned SEAMCALL status code. It only processes some cases for reference. More processes for other SEAMCALL status code can be added in the future on demand. Signed-off-by: Xiaoyao Li Co-developed-by: Isaku Yamahata Signed-off-by: Isaku Yamahata --- arch/x86/kvm/boot/seam/tdx_common.c | 54 +++++++++++++++++++++++++++++ arch/x86/kvm/vmx/seamcall.h | 6 ++-- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/boot/seam/tdx_common.c b/arch/x86/kvm/boot/seam/tdx_common.c index 4fe352fb8586..a81a4672bf58 100644 --- a/arch/x86/kvm/boot/seam/tdx_common.c +++ b/arch/x86/kvm/boot/seam/tdx_common.c @@ -186,3 +186,57 @@ const char *tdx_seamcall_error_name(u64 error_code) return "Unknown SEAMCALL status code"; } EXPORT_SYMBOL_GPL(tdx_seamcall_error_name); + +static const char * const TDX_SEPT_ENTRY_STATES[] = { + "SEPT_FREE", + "SEPT_BLOCKED", + "SEPT_PENDING", + "SEPT_PENDING_BLOCKED", + "SEPT_PRESENT" +}; + +void pr_seamcall_ex_ret_info(u64 op, u64 error_code, struct tdx_ex_ret *ex_ret) +{ + if (!ex_ret) + return; + + switch (error_code & TDX_SEAMCALL_STATUS_MASK) { + case TDX_INCORRECT_CPUID_VALUE: + pr_err("Expected CPUID [leaf 0x%x subleaf 0x%x]: " + "eax 0x%x check_mask 0x%x, ebx 0x%x check_mask 0x%x, " + "ecx 0x%x check_mask 0x%x, edx 0x%x check_mask 0x%x\n", + ex_ret->leaf, ex_ret->subleaf, + ex_ret->eax_val, ex_ret->eax_mask, + ex_ret->ebx_val, ex_ret->ebx_mask, + ex_ret->ecx_val, ex_ret->ecx_mask, + ex_ret->edx_val, ex_ret->edx_mask); + break; + case TDX_INCONSISTENT_CPUID_FIELD: + pr_err("Inconsistent CPUID [leaf 0x%x subleaf 0x%x]: " + "eax_mask 0x%x, ebx_mask 0x%x, ecx_mask %x, edx_mask 0x%x\n", + ex_ret->leaf, ex_ret->subleaf, + ex_ret->eax_mask, ex_ret->ebx_mask, + ex_ret->ecx_mask, ex_ret->edx_mask); + break; + case TDX_EPT_WALK_FAILED: { + const char *state; + + if (ex_ret->state >= ARRAY_SIZE(TDX_SEPT_ENTRY_STATES)) + state = "Invalid"; + else + state = TDX_SEPT_ENTRY_STATES[ex_ret->state]; + + pr_err("Secure EPT walk error: SEPTE 0x%llx, level %d, %s\n", + ex_ret->septe, ex_ret->level, state); + break; + } + default: + /* TODO: print only meaningful registers depending on op */ + pr_err("RCX 0x%llx, RDX 0x%llx, R8 0x%llx, R9 0x%llx, " + "R10 0x%llx, R11 0x%llx\n", + ex_ret->rcx, ex_ret->rdx, ex_ret->r8, ex_ret->r9, + ex_ret->r10, ex_ret->r11); + break; + } +} +EXPORT_SYMBOL_GPL(pr_seamcall_ex_ret_info); diff --git a/arch/x86/kvm/vmx/seamcall.h b/arch/x86/kvm/vmx/seamcall.h index fbb18aea1720..85eeedc06a4f 100644 --- a/arch/x86/kvm/vmx/seamcall.h +++ b/arch/x86/kvm/vmx/seamcall.h @@ -38,6 +38,7 @@ static inline u64 _seamcall(u64 op, u64 rcx, u64 rdx, u64 r8, u64 r9, u64 r10, #endif const char *tdx_seamcall_error_name(u64 error_code); +void pr_seamcall_ex_ret_info(u64 op, u64 error_code, struct tdx_ex_ret *ex_ret); static inline void __pr_seamcall_error(u64 op, const char *op_str, u64 err, struct tdx_ex_ret *ex) @@ -46,10 +47,7 @@ static inline void __pr_seamcall_error(u64 op, const char *op_str, op_str, smp_processor_id(), tdx_seamcall_error_name(err), err); if (ex) - pr_err_ratelimited( - "RCX 0x%llx, RDX 0x%llx, R8 0x%llx, R9 0x%llx, R10 0x%llx, R11 0x%llx\n", - (ex)->rcx, (ex)->rdx, (ex)->r8, (ex)->r9, (ex)->r10, - (ex)->r11); + pr_seamcall_ex_ret_info(op, err, ex); } #define pr_seamcall_error(op, err, ex) \ -- 2.25.1