linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@suse.de>
To: Kyle Huey <me@kylehuey.com>
Cc: Robert O'Callahan <robert@ocallahan.org>,
	linux-api@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<x86@kernel.org>, "Peter Zijlstra (Intel)" <peterz@infradead.org>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Len Brown <len.brown@intel.com>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Huang Rui <ray.huang@amd.com>,
	Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>,
	Andy Lutomirski <luto@kernel.org>,
	Juergen Gross <jgross@suse.com>,
	Fenghua Yu <fenghua.yu@intel.com>,
	"Luis R. Rodriguez" <mcgrof@kernel.o>
Subject: Re: [PATCH] prctl,x86 Add PR_[GET|SET]_CPUID for controlling the CPUID instruction.
Date: Mon, 12 Sep 2016 16:34:13 +0200	[thread overview]
Message-ID: <20160912143413.ew4zry5vpw6ycpl3@pd.tnic> (raw)
In-Reply-To: <CAP045ArcuopWtoUTMFLW6zYse6OFX+SUDRqg=fn+Ty6vCPUJ8Q@mail.gmail.com>

On Mon, Sep 12, 2016 at 07:15:16AM -0700, Kyle Huey wrote:
> Copied from PR_SET_TSC. Would you prefer something like
> disable_cpuid/disable_cpuid_and_set_flag for
> hard_disable_CPUID/disable_CPUID?

Maybe something like this:

switch_cpuid_faulting(bool on)
{
	if (on)
		msr_set_bit(MSR_MISC_FEATURES_ENABLES, 0);
	else
		msr_clear_bit(MSR_MISC_FEATURES_ENABLES, 0);
}

and call it with the respective argument.

> >> @@ -210,6 +280,15 @@ void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
> >>               update_debugctlmsr(debugctl);
> >>       }
> >>
> >> +     if (test_tsk_thread_flag(prev_p, TIF_NOCPUID) ^
> >> +         test_tsk_thread_flag(next_p, TIF_NOCPUID)) {
> >> +             /* prev and next are different */
> >> +             if (test_tsk_thread_flag(next_p, TIF_NOCPUID))
> >> +                     hard_disable_CPUID();
> >> +             else
> >> +                     hard_enable_CPUID();
> >> +     }
> >> +
> >
> > Frankly, I can't say that I'm thrilled by this: if this is a niche
> > feature which has only a very narrow usage for debugging, I'd much
> > prefer if this whole thing were implemented with a static_key which was
> > false on the majority of the systems so that __switch_to() tests it much
> > cheaply.
> >
> > Then and only then if your debugger runs arch_prctl(), it would enable
> > the key and then set_cpuid_mode() can query the MSR directly instead of
> > using another flag in the thread_info flags.
> >
> > This would keep this niche feature out of the way of the hot paths.
> 
> My code is already in the slow path in __switch_to_xtra(), along with
> other debugging features like TIF_BLOCKSTEP and TIF_NOTSC. Adding a
> bit to the mask tested in __switch_to() shouldn't affect performance
> of the hot path.

TIF_BLOCKSTEP maybe but TIF_NOTSC doesn't look like a debugging feature
to me, especially if it is called in seccomp.

And I know it is not on the hot path. But you're using precious TIF bits
for a niche feature. Practically, this is code which will be dead on the
majority of machines out there, because either the hw feature is not
there or because nobody is using it.

Maybe the virtualization aspect would gather more users of this but I
don't know what kvm guys are thinking about faulting CPUID. Let me add
them to CC.

In any case, I'd do the static_key approach because it is simpler and
less obtrusive for your purpose.

But there are plenty more people on CC, this is just me.

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

  reply	other threads:[~2016-09-12 14:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-12  0:29 [PATCH] prctl,x86 Add PR_[GET|SET]_CPUID for controlling the CPUID instruction Kyle Huey
     [not found] ` <1473640169-24145-1-git-send-email-khuey-OhBmq/TcCDJWk0Htik3J/w@public.gmane.org>
2016-09-12  9:07   ` Borislav Petkov
2016-09-12 14:15     ` Kyle Huey
2016-09-12 14:34       ` Borislav Petkov [this message]
2016-09-13 18:42       ` Kyle Huey
2016-09-12 16:56   ` Andy Lutomirski
     [not found]     ` <CALCETrVJAib918qn9CL4Tvyfok-8eAHimYDabXUF=1Nsxo4-Pw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-09-12 17:18       ` Borislav Petkov
2016-09-12 17:56       ` Jann Horn
2016-09-12 21:07         ` Andy Lutomirski
2016-09-14  6:13       ` Kyle Huey
     [not found]         ` <CAP045ApLcQXZP44wry8mofLz2ip1vQbvpnhCjQZsT+JxXmVEzg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-09-14 18:52           ` Andy Lutomirski
2016-09-14 19:22             ` Andrew Cooper
2016-09-14 19:23             ` Boris Ostrovsky
     [not found]               ` <e7b0b419-ed32-e35b-2f7b-eee71834fafd-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2016-09-14 19:28                 ` Andrew Cooper
2016-09-14 19:36                   ` Andy Lutomirski
     [not found]                     ` <CALCETrUkmiwLDD0V-b5woDncOzdqZaS4Pg5EnneXD4ZEN7ttbg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-09-14 19:42                       ` Andrew Cooper

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=20160912143413.ew4zry5vpw6ycpl3@pd.tnic \
    --to=bp@suse.de \
    --cc=Aravind.Gopalakrishnan@amd.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=len.brown@intel.com \
    --cc=linux-api@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mcgrof@kernel.o \
    --cc=me@kylehuey.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=ray.huang@amd.com \
    --cc=robert@ocallahan.org \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=tglx@linutronix.de \
    --cc=vladimir_zapolskiy@mentor.com \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).