public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sohil Mehta <sohil.mehta@intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: <x86@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Ingo Molnar" <mingo@redhat.com>,
	"H . Peter Anvin" <hpa@zytor.com>,
	Uros Bizjak <ubizjak@gmail.com>,
	Sandipan Das <sandipan.das@amd.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Vegard Nossum <vegard.nossum@oracle.com>,
	Tony Luck <tony.luck@intel.com>,
	Pawan Gupta <pawan.kumar.gupta@linux.intel.com>,
	Nikolay Borisov <nik.borisov@suse.com>,
	Eric Biggers <ebiggers@google.com>, Xin Li <xin3.li@intel.com>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH] x86/cpufeature: Add feature dependency checks
Date: Fri, 23 Aug 2024 12:05:19 -0700	[thread overview]
Message-ID: <096cdf1b-bc79-4e88-8ae9-99a373245ef8@intel.com> (raw)
In-Reply-To: <ZsfJUT0AWFhoONWf@google.com>

On 8/22/2024 4:27 PM, Sean Christopherson wrote:
> On Thu, Aug 22, 2024, Sohil Mehta wrote:
>> Arguably, this situation should only happen on broken hardware and it may not
>> make sense to add such a check to the kernel. OTOH, this can be viewed as a
>> safety mechanism to make failures more graceful on such configurations in real
>> or virtual environments.
> 
> And goofy Kconfigs.   But yeah, lack of any meaningful fallout is why my version
> didn't go anywhere.
> 

By fallout do you mean that the observed behavior when the kernel runs
into such a misconfiguration or just the general lack of such
misconfigured hardware/guest?

I tried experimenting with the behavior for the last entry on the
cpuid_deps[] table:
{ X86_FEATURE_FRED,                     X86_FEATURE_WRMSRNS   },

In this case, even if WRMSRNS is not present, the kernel would go ahead
and enable FRED, which would cause a panic when wrmsrns() is exercised
in update_task_stack().

I agree to the second part that such conditions are more likely to
happen in pre-production environments. But I still feel that for the
rare case when something like this seeps through it would be better to
disable the feature upfront than run in a kernel panic or some other
unexpected behavior.

> https://lore.kernel.org/all/20221203003745.1475584-2-seanjc@google.com
> 

The code is very similar to the one I proposed. If we do take this
forward, would it be fine if I add a Originally-by tag from you?


>> +void filter_feature_dependencies(struct cpuinfo_x86 *c)
>> +{
>> +	const struct cpuid_dep *d;
>> +
>> +	for (d = cpuid_deps; d->feature; d++) {
>> +		if (boot_cpu_has(d->feature) && !boot_cpu_has(d->depends))
> 
> I don't think checking boot_cpu_has() is correct, it's entirely possible for a CPU
> to have divergent features from the boot CPU, e.g. if a feature is dependent on
> BIOS enabling (or disabling) and BIOS messed up.
> 

Yeah, makes sense. cpu_has() would be better suited as you have done in
your original patch.

>> +			do_clear_cpu_cap(c, d->feature);
>> +	}
>> +}
>> -- 
>> 2.34.1
>>


  reply	other threads:[~2024-08-23 19:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-22 20:22 [RFC PATCH] x86/cpufeature: Add feature dependency checks Sohil Mehta
2024-08-22 23:27 ` Sean Christopherson
2024-08-23 19:05   ` Sohil Mehta [this message]
2024-08-26 20:05     ` Sean Christopherson
2024-08-26 21:47       ` Sohil Mehta

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=096cdf1b-bc79-4e88-8ae9-99a373245ef8@intel.com \
    --to=sohil.mehta@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=ebiggers@google.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nik.borisov@suse.com \
    --cc=pawan.kumar.gupta@linux.intel.com \
    --cc=peterz@infradead.org \
    --cc=sandipan.das@amd.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=ubizjak@gmail.com \
    --cc=vegard.nossum@oracle.com \
    --cc=x86@kernel.org \
    --cc=xin3.li@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox