All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Roger Pau Monné" <roger@xenproject.org>,
	"Teddy Astie" <teddy.astie@vates.tech>,
	trenchboot-devel@googlegroups.com,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v4 02/23] x86/cpu: report SMX, TXT and SKINIT capabilities
Date: Thu, 20 Aug 2026 17:48:50 +0200	[thread overview]
Message-ID: <b64ee197-3186-47ed-89b1-5cdeec1c0cff@suse.com> (raw)
In-Reply-To: <aob9xUZF12IJhLRz@MjU3Nj>

On 20.08.2026 15:14, Sergii Dmytruk wrote:
> On Tue, Aug 18, 2026 at 02:08:48PM +0200, Jan Beulich wrote:
>> On 02.08.2026 15:09, Sergii Dmytruk wrote:
>>> From: Michał Żygowski <michal.zygowski@3mdeb.com>
>>>
>>> Report TXT capabilities so that dom0 can query the Intel TXT or AMD
>>> SKINIT support information using xl dmesg.
>>
>> Hmm. I first meant to ask: In how far is this extra logging useful,
>> especially as long as we don't use the features just yet? And only then
>> I noticed that I must have paid too little attention here already in v3.
>> Querying through "xl dmesg" is entirely unreliable. Sooner or later the
>> boot messages will scroll off of the ring buffer. Making this a
>> query-able interface also would mean we can't alter any of the messages,
>> should the want/need arise.
>>
>> For AMD the situation is easy: It's part of the featureset / CPU policy
>> exposed via sysctl. The same is true for SMX on Intel, but the further
>> GETSEC output requires some other means to communicate. I wonder whether
>> making this part of the CPU policy would make sense, or whether to
>> introduce a Dom0-only hypervisor-CPUID bit for it, or whether yet
>> something else would be best here. Likely Andrew will have had thoughts
>> on this long before ...
> 
> I'm not aware of anything relying on this output.  It's just for making
> this information more accessible to users that may be wondering if DRTM
> has a chance of working (e.g., if hardware supports it and firmware is
> properly configured).  The wording may be unfortunate (and needs a fix
> anyway), I can change it to
> 
>     Report DRTM-related capabilities to enable checking for them in dom0
>     using `xl dmesg`.  This targets debug and diagnostic use cases.
> 
> if that helps.

Yes, please. Provided we need this separate output at all. Furthermore,
if we need it, wouldn't it better be adjacent with other extended VT-x /
SVM features?

>>> @@ -620,6 +625,49 @@ static void init_intel_perf(struct cpuinfo_x86 *c)
>>>      }
>>>  }
>>>
>>> +/*
>>> + * Print out the SMX and TXT capabilties, so that dom0 can determine if the
>>> + * system is DRTM-capable.
>>> + */
>>> +static void intel_log_smx_txt(void)
>>> +{
>>> +    unsigned long cr4_val, getsec_caps;
>>> +
>>> +    /*
>>> +     * Run only on BSP and not during resume to report the capability only once.
>>> +     */
>>> +    if ( system_state == SYS_STATE_resume || smp_processor_id() )
>>> +        return;
>>> +
>>> +    printk("CPU: SMX capability ");
>>> +    if ( !test_bit(X86_FEATURE_SMX, &boot_cpu_data.x86_capability) )
>>> +    {
>>> +        printk("not supported\n");
>>> +        return;
>>> +    }
>>> +    printk("supported\n");
>>> +
>>> +    /* Can't run GETSEC without VMX and SMX */
>>> +    if ( !test_bit(X86_FEATURE_VMX, &boot_cpu_data.x86_capability) )
>>> +        return;
>>> +
>>> +    cr4_val = read_cr4();
>>> +    if ( !(cr4_val & X86_CR4_SMXE) )
>>> +        write_cr4(cr4_val | X86_CR4_SMXE);
>>> +
>>> +    asm volatile ("getsec\n"
>>> +        : "=a" (getsec_caps)
>>> +        : "a" (GETSEC_CAPABILITIES), "b" (0) :);
>>
>> Nit (style): Bad indentation, missing blanks, unnecessary \n, and stray colon.
>> Overall:
>>
>>     asm volatile ( "getsec"
>>                    : "=a" (getsec_caps)
>>                    : "a" (GETSEC_CAPABILITIES), "b" (0) );
>>
>> I further question the need for volatile here. (Like for we have for CPUID, we
>> anyway may want to gain a getsec() wrapper for GETSEC.)
> 
> I think `volatile` was added just because it doesn't hurt, rather than
> because it's necessary, so it can be dropped.  Can add a wrapper, but
> there is only one use so far and a generic wrapper will have to use
> 64-bit parameters (`GETSEC[EXITAC]` sets RBX).

Well, if it'll remain just one use, maybe indeed too early for having a
wrapper.

>>> +    if ( !(cr4_val & X86_CR4_SMXE) )
>>> +        write_cr4(cr4_val & ~X86_CR4_SMXE);
>>
>> The clearing of SMXE here is pointless, as the if() already guarantees the bit
>> to be clear.
> 
> This statement restores the value stored in `cr4_val` (see above).
> Maybe should name the variable `old_cr4_val` or `orig_cr4_val`.

Naming wasn't my point here. My point was that masking off a bit that's
already off is pretty clearly useless code.

Jan


  reply	other threads:[~2026-08-20 15:49 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02 13:09 [PATCH v4 00/23] x86: Trenchboot Secure Launch DRTM (Xen) Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 01/23] x86/mtrr: get rid of a static variable on pause/restore Sergii Dmytruk
2026-08-18 11:44   ` Jan Beulich
2026-08-20 12:34   ` Teddy Astie
2026-08-02 13:09 ` [PATCH v4 02/23] x86/cpu: report SMX, TXT and SKINIT capabilities Sergii Dmytruk
2026-08-18 12:08   ` Jan Beulich
2026-08-20 13:14     ` Sergii Dmytruk
2026-08-20 15:48       ` Jan Beulich [this message]
2026-08-20 15:48       ` Andrew Cooper
2026-08-20 12:59   ` Teddy Astie
2026-08-20 15:09     ` Andrew Cooper
2026-08-02 13:09 ` [PATCH v4 03/23] x86/tpm.c: hashing and extending PCRs for TPM1.2 Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 04/23] x86/tpm.c: support extending PCRs of TPM2.0 via TIS Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 05/23] x86/tpm.c: add CRB interface support Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 06/23] x86/include/asm/intel-txt.h: constants and accessors for TXT registers and heap Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 07/23] x86/boot: add CONFIG_SLAUNCH, MLE header and Secure Launch entry point Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 08/23] include/xen/slr-table.h: Secure Launch Resource Table definitions Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 09/23] x86/boot/slaunch-early: implement early initialization Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 10/23] x86/boot/slaunch-early: early Intel TXT sanity checks Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 11/23] xen/arch/x86: reserve TXT memory during Slaunch Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 12/23] x86/slaunch: restore boot MTRRs after Intel TXT DRTM Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 13/23] x86/slaunch: measure MBI into TPM Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 14/23] x86/slaunch: update TPM event log (TPM1.2 or TPM2.0) Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 15/23] x86/hvm: check for VMX in SMX if Slaunch is active Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 16/23] x86/boot: choose AP stack based on APIC ID Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 17/23] x86/smpboot.c: TXT AP bringup Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 18/23] x86/slaunch: process DRTM policy Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 19/23] x86/acpi: disallow S3 on Secure Launch boot Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 20/23] x86/slaunch: support AMD CPUs Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 21/23] x86/slaunch: support EFI boot Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 22/23] xen/arch/x86: add TPR (TXT Protected Range) DMA protection support Sergii Dmytruk
2026-08-02 13:09 ` [PATCH v4 23/23] MAINTAINERS: add a section for TrenchBoot Slaunch Sergii Dmytruk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b64ee197-3186-47ed-89b1-5cdeec1c0cff@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=roger@xenproject.org \
    --cc=sergii.dmytruk@3mdeb.com \
    --cc=teddy.astie@vates.tech \
    --cc=trenchboot-devel@googlegroups.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.