Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp476490pxj; Thu, 10 Jun 2021 05:33:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvv09YsavXE2Qwg7jSpkI/F+eV3NBexah9ckodPCASztug73CcKr7QaxU7Vd+JG+I0yuQ2 X-Received: by 2002:a17:906:d97:: with SMTP id m23mr4300227eji.392.1623328384424; Thu, 10 Jun 2021 05:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623328384; cv=none; d=google.com; s=arc-20160816; b=eaa7FYoE4oScx+RpENM6JCTXvNbsv9hRmX4Xz4xttn6CiViXCDW0GkgM5MV5ffacT+ Mspd0Pppbs3ci9OG4kU4fA+yBoA4Xl7i8N9qaKoLi2qOwkILDCpiN8etD9QgW4KcTRZK U8DRvvM6RExU+iS4iyvknzFPaGyQBHU7mHvopZBTHA+BWrdrDrVqqicEvSwGhbPVMW+n 96zJyWQRgP7mqH9pK51t7XauFCIAUJWOwM4b1dJ5i+QF+Nz/5/KSeP6vJCT8EkenuPF3 sH2zWS1uz6Z7j+8G4Hekv0+dPwHTd8nlWBNWrX4lrXeYSFgpf+5WMxJvTapUvPr8MP8n AfAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=35bw5pjdZNqYAGs3sns2GRGGZjK2Qjk7iy2KlgpNkiU=; b=D37owct7TIYsbneVgOv+PYQECOEJwWoJ+M1wPws9QZ6PPhL5iiTU1HDhKFK9T5twHK cHTKtUFCSPTyWuZ3OqX2JLnqeKG8C9OO9IuNVkKGzlJ6ePOJVh7B3w532ztpYeTuNx4C ItTQenVa2FPmash/BWA+1Te/l2B/fZEiasVsadCP1cCdw5L17PvwX0JVEdGlIu6JhCOB jSsT0MqTuKW8NkCsejIij0vrr2iZBpB/I6z1+Dsq3ei7w0j2KDcWYTOpTXt+Pd7dQdf0 DdLy75btbRdmiuoBdLO6EV9qpZ1abQdt1MmReYsnGHpbtkxIuRKFGwsDViYlWpiA1OMj XuDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=RIKAllYW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y35si2316102edy.60.2021.06.10.05.32.41; Thu, 10 Jun 2021 05:33:04 -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; dkim=pass header.i=@alien8.de header.s=dkim header.b=RIKAllYW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230392AbhFJMaZ (ORCPT + 99 others); Thu, 10 Jun 2021 08:30:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230435AbhFJMaK (ORCPT ); Thu, 10 Jun 2021 08:30:10 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D8A8C0617A6 for ; Thu, 10 Jun 2021 05:28:13 -0700 (PDT) Received: from zn.tnic (p200300ec2f0cf600e70433578266b34c.dip0.t-ipconnect.de [IPv6:2003:ec:2f0c:f600:e704:3357:8266:b34c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 29EBC1EC0493; Thu, 10 Jun 2021 14:28:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1623328092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=35bw5pjdZNqYAGs3sns2GRGGZjK2Qjk7iy2KlgpNkiU=; b=RIKAllYWEb5J2g7gciGdH+sAb+lW3D0dih5fGEQl640Lhp80+aeJBfOwt8cVlWqFSCjJo0 0f9d0Ni0lBufLaySu4Tmi1tlGJZZGib8c6/WwHPX2MIdRH3pyshGfv7xGQCO+V2W20xFwv cw4NTEp3iAbV5LY/hM88QIOdSPTh6t4= Date: Thu, 10 Jun 2021 14:28:06 +0200 From: Borislav Petkov To: Kuppuswamy Sathyanarayanan Cc: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Andy Lutomirski , Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Sean Christopherson , linux-kernel@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH v1 03/11] x86/cpufeatures: Add TDX Guest CPU feature Message-ID: References: <20210602022136.2186759-1-sathyanarayanan.kuppuswamy@linux.intel.com> <20210602022136.2186759-4-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210602022136.2186759-4-sathyanarayanan.kuppuswamy@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 01, 2021 at 07:21:28PM -0700, Kuppuswamy Sathyanarayanan wrote: > Add CPU feature detection for Trusted Domain Extensions support. > TDX feature adds capabilities to keep guest register state and > memory isolated from hypervisor. > > For TDX guest platforms, executing CPUID(0x21, 0) will return I'm assuming that 0 is ECX? > following values in EAX, EBX, ECX and EDX. > > EAX: Maximum sub-leaf number: 0 > EBX/EDX/ECX: Vendor string: > > EBX = "Inte" > EDX = "lTDX" > ECX = " " > > So when above condition is true, set X86_FEATURE_TDX_GUEST > feature cap bit ^ Fullstop. > diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h > index ac37830ae941..dddc3a27cc8a 100644 > --- a/arch/x86/include/asm/cpufeatures.h > +++ b/arch/x86/include/asm/cpufeatures.h > @@ -238,6 +238,7 @@ > #define X86_FEATURE_VMW_VMMCALL ( 8*32+19) /* "" VMware prefers VMMCALL hypercall instruction */ > #define X86_FEATURE_PVUNLOCK ( 8*32+20) /* "" PV unlock function */ > #define X86_FEATURE_VCPUPREEMPT ( 8*32+21) /* "" PV vcpu_is_preempted function */ > +#define X86_FEATURE_TDX_GUEST ( 8*32+22) /* Trusted Domain Extensions Guest */ What's the name of the feature bit? "TDX guest"? Why not only X86_FEATURE_TDX and then you can have "tdx" in cpuinfo? > > /* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */ > #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE instructions*/ > diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h > new file mode 100644 > index 000000000000..679500e807f3 > --- /dev/null > +++ b/arch/x86/include/asm/tdx.h > @@ -0,0 +1,20 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* Copyright (C) 2020 Intel Corporation */ > +#ifndef _ASM_X86_TDX_H > +#define _ASM_X86_TDX_H > + > +#define TDX_CPUID_LEAF_ID 0x21 > + > +#ifdef CONFIG_INTEL_TDX_GUEST > + > +#include As before - put the include at the top. > +void __init tdx_early_init(void); > + > +#else // !CONFIG_INTEL_TDX_GUEST No need for that // - comment > diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c > new file mode 100644 > index 000000000000..5b14b72e41c5 > --- /dev/null > +++ b/arch/x86/kernel/tdx.c > @@ -0,0 +1,30 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* Copyright (C) 2020 Intel Corporation */ > + > +#include > + > +static inline bool cpuid_has_tdx_guest(void) > +{ > + u32 eax, signature[3]; Shorten that array name to "sig" so that you don't have to break the cpuid_count() line below. > + > + if (cpuid_eax(0) < TDX_CPUID_LEAF_ID) > + return false; > + > + cpuid_count(TDX_CPUID_LEAF_ID, 0, &eax, &signature[0], > + &signature[1], &signature[2]); > + > + if (memcmp("IntelTDX ", signature, 12)) > + return false; > + > + return true; or simply: return !memcmp(... > +} > + > +void __init tdx_early_init(void) > +{ > + if (!cpuid_has_tdx_guest()) > + return; > + > + setup_force_cpu_cap(X86_FEATURE_TDX_GUEST); > + > + pr_info("TDX guest is initialized\n"); Use pr_fmt in this file: #undef pr_fmt #define pr_fmt(fmt) "x86/tdx: " fmt and then do pr_info("Guest initialized\n"); Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette