All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH v2 19/30] x86/cpu: Rework Intel masking/faulting setup
Date: Wed, 17 Feb 2016 00:57:22 -0700	[thread overview]
Message-ID: <56C435F202000078000D2EF2@prv-mh.provo.novell.com> (raw)
In-Reply-To: <1454679743-18133-20-git-send-email-andrew.cooper3@citrix.com>

>>> On 05.02.16 at 14:42, <andrew.cooper3@citrix.com> wrote:
> --- a/xen/arch/x86/cpu/intel.c
> +++ b/xen/arch/x86/cpu/intel.c
> @@ -18,11 +18,18 @@
>  
>  #define select_idle_routine(x) ((void)0)
>  
> -static unsigned int probe_intel_cpuid_faulting(void)
> +static bool_t __init probe_intel_cpuid_faulting(void)
>  {
>  	uint64_t x;
> -	return !rdmsr_safe(MSR_INTEL_PLATFORM_INFO, x) &&
> -		(x & MSR_PLATFORM_INFO_CPUID_FAULTING);
> +
> +	if ( rdmsr_safe(MSR_INTEL_PLATFORM_INFO, x) ||
> +	     !(x & MSR_PLATFORM_INFO_CPUID_FAULTING) )
> +		return 0;

Partial Xen coding style again.

> @@ -44,41 +51,46 @@ void set_cpuid_faulting(bool_t enable)
>  }
>  
>  /*
> - * opt_cpuid_mask_ecx/edx: cpuid.1[ecx, edx] feature mask.
> - * For example, E8400[Intel Core 2 Duo Processor series] ecx = 0x0008E3FD,
> - * edx = 0xBFEBFBFF when executing CPUID.EAX = 1 normally. If you want to
> - * 'rev down' to E8400, you can set these values in these Xen boot parameters.
> + * Set caps in expected_levelling_cap, probe a specific masking MSR, and set
> + * caps in levelling_caps if it is found, or clobber the MSR index if missing.
> + * If preset, reads the default value into msr_val.
>   */
> -static void set_cpuidmask(const struct cpuinfo_x86 *c)
> +static void __init __probe_mask_msr(unsigned int *msr, uint64_t caps,
> +				    uint64_t *msr_val)
>  {
> -	static unsigned int msr_basic, msr_ext, msr_xsave;
> -	static enum { not_parsed, no_mask, set_mask } status;
> -	u64 msr_val;
> +	uint64_t val;
>  
> -	if (status == no_mask)
> -		return;
> +	expected_levelling_cap |= caps;
>  
> -	if (status == set_mask)
> -		goto setmask;
> +	if (rdmsr_safe(*msr, val) || wrmsr_safe(*msr, val))
> +		*msr = 0;
> +	else
> +	{
> +		levelling_caps |= caps;
> +		*msr_val = val;
> +	}
> +}

Same as for the AMD side: Perhaps neater if the function returned
the MSR value? (Also again partial Xen coding style here.)

> +/* Indicies of the masking MSRs, or 0 if unavailable. */
> +static unsigned int __read_mostly msr_basic, msr_ext, msr_xsave;

I think this way __read_mostly applies only to msr_basic, which I
don't think is what you want. Also I think you mean "indices" or
"indexes".

> +static void __init probe_masking_msrs(void)
> +{
> +	const struct cpuinfo_x86 *c = &boot_cpu_data;
> +	unsigned int exp_msr_basic = 0, exp_msr_ext = 0, exp_msr_xsave = 0;
>  
>  	/* Only family 6 supports this feature. */
> -	if (c->x86 != 6) {
> -		printk("No CPUID feature masking support available\n");
> +	if (c->x86 != 6)
>  		return;
> -	}
>  
>  	switch (c->x86_model) {
>  	case 0x17: /* Yorkfield, Wolfdale, Penryn, Harpertown(DP) */
>  	case 0x1d: /* Dunnington(MP) */
> -		msr_basic = MSR_INTEL_MASK_V1_CPUID1;
> +		exp_msr_basic = msr_basic = MSR_INTEL_MASK_V1_CPUID1;
>  		break;
>  
>  	case 0x1a: /* Bloomfield, Nehalem-EP(Gainestown) */
> @@ -88,71 +100,126 @@ static void set_cpuidmask(const struct cpuinfo_x86 *c)
>  	case 0x2c: /* Gulftown, Westmere-EP */
>  	case 0x2e: /* Nehalem-EX(Beckton) */
>  	case 0x2f: /* Westmere-EX */
> -		msr_basic = MSR_INTEL_MASK_V2_CPUID1;
> -		msr_ext   = MSR_INTEL_MASK_V2_CPUID80000001;
> +		exp_msr_basic = msr_basic = MSR_INTEL_MASK_V2_CPUID1;
> +		exp_msr_ext   = msr_ext   = MSR_INTEL_MASK_V2_CPUID80000001;
>  		break;
>  
>  	case 0x2a: /* SandyBridge */
>  	case 0x2d: /* SandyBridge-E, SandyBridge-EN, SandyBridge-EP */
> -		msr_basic = MSR_INTEL_MASK_V3_CPUID1;
> -		msr_ext   = MSR_INTEL_MASK_V3_CPUID80000001;
> -		msr_xsave = MSR_INTEL_MASK_V3_CPUIDD_01;
> +		exp_msr_basic = msr_basic = MSR_INTEL_MASK_V3_CPUID1;
> +		exp_msr_ext   = msr_ext   = MSR_INTEL_MASK_V3_CPUID80000001;
> +		exp_msr_xsave = msr_xsave = MSR_INTEL_MASK_V3_CPUIDD_01;
>  		break;
>  	}

Instead of all these changes, and instead of the variable needing
initializers, you could simply initialize all three ext_msr_* right after
the switch().

> +static void intel_ctxt_switch_levelling(const struct domain *nextd)
> +{
> +	struct cpuidmasks *these_masks = &this_cpu(cpuidmasks);
> +	const struct cpuidmasks *masks = &cpuidmask_defaults;
> +
> +#define LAZY(msr, field)						\
> +	({								\
> +		if (msr && (these_masks->field != masks->field))	\
> +		{							\
> +			wrmsrl(msr, masks->field);			\
> +			these_masks->field = masks->field;		\
> +		}							\
> +	})
> +
> +	LAZY(msr_basic, _1cd);
> +	LAZY(msr_ext,   e1cd);
> +	LAZY(msr_xsave, Da1);

Please either use token concatenation inside the macro body to
eliminate the redundant msr_ prefixes here, or properly
parenthesize the uses of "msr" inside the macro body.

> +	if (opt_cpu_info) {
> +		printk(XENLOG_INFO "Levelling caps: %#x\n", levelling_caps);
> +		printk(XENLOG_INFO
> +		       "MSR defaults: 1d 0x%08x, 1c 0x%08x, e1d 0x%08x, "
> +		       "e1c 0x%08x, Da1 0x%08x\n",
> +		       (uint32_t)(cpuidmask_defaults._1cd >> 32),
> +		       (uint32_t)cpuidmask_defaults._1cd,
> +		       (uint32_t)(cpuidmask_defaults.e1cd >> 32),
> +		       (uint32_t)cpuidmask_defaults.e1cd,
> +		       (uint32_t)cpuidmask_defaults.Da1);

Could I convince you to make this second printk() dependent
upon there not being CPUID faulting support?

> @@ -190,22 +257,13 @@ static void early_init_intel(struct cpuinfo_x86 *c)
>  	    (boot_cpu_data.x86_mask == 3 || boot_cpu_data.x86_mask == 4))
>  		paddr_bits = 36;
>  
> -	if (c == &boot_cpu_data && c->x86 == 6) {
> -		if (probe_intel_cpuid_faulting())
> -			__set_bit(X86_FEATURE_CPUID_FAULTING,
> -				  c->x86_capability);
> -	} else if (boot_cpu_has(X86_FEATURE_CPUID_FAULTING)) {
> -		BUG_ON(!probe_intel_cpuid_faulting());
> -		__set_bit(X86_FEATURE_CPUID_FAULTING, c->x86_capability);
> -	}
> +	if (c == &boot_cpu_data)
> +		intel_init_levelling();
> +
> +	if (test_bit(X86_FEATURE_CPUID_FAULTING, boot_cpu_data.x86_capability))
> +            __set_bit(X86_FEATURE_CPUID_FAULTING, c->x86_capability);

Mixing tabs and spaces for indentation.

Jan

  reply	other threads:[~2016-02-17  7:57 UTC|newest]

Thread overview: 139+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-05 13:41 [PATCH RFC v2 00/30] x86: Improvements to cpuid handling for guests Andrew Cooper
2016-02-05 13:41 ` [PATCH v2 01/30] xen/x86: Drop X86_FEATURE_3DNOW_ALT Andrew Cooper
2016-02-05 13:41 ` [PATCH v2 02/30] xen/x86: Do not store VIA/Cyrix/Centaur CPU features Andrew Cooper
2016-02-05 13:41 ` [PATCH v2 03/30] xen/x86: Drop cpuinfo_x86.x86_power Andrew Cooper
2016-02-05 13:41 ` [PATCH v2 04/30] xen/x86: Improvements to pv_cpuid() Andrew Cooper
2016-02-05 13:41 ` [PATCH v2 05/30] xen/public: Export cpu featureset information in the public API Andrew Cooper
2016-02-12 16:27   ` Jan Beulich
2016-02-17 13:08     ` Andrew Cooper
2016-02-17 13:34       ` Jan Beulich
2016-02-19 17:29   ` Joao Martins
2016-02-19 17:55     ` Andrew Cooper
2016-02-19 22:03       ` Joao Martins
2016-02-20 16:17         ` Andrew Cooper
2016-02-20 17:39           ` Joao Martins
2016-02-20 19:17             ` Andrew Cooper
2016-02-22 18:50               ` Joao Martins
2016-02-05 13:41 ` [PATCH v2 06/30] xen/x86: Script to automatically process featureset information Andrew Cooper
2016-02-12 16:36   ` Jan Beulich
2016-02-12 16:43     ` Andrew Cooper
2016-02-05 13:42 ` [PATCH v2 07/30] xen/x86: Collect more cpuid feature leaves Andrew Cooper
2016-02-12 16:38   ` Jan Beulich
2016-02-05 13:42 ` [PATCH v2 08/30] xen/x86: Mask out unknown features from Xen's capabilities Andrew Cooper
2016-02-12 16:43   ` Jan Beulich
2016-02-12 16:48     ` Andrew Cooper
2016-02-12 17:14       ` Jan Beulich
2016-02-17 13:12         ` Andrew Cooper
2016-02-05 13:42 ` [PATCH v2 09/30] xen/x86: Store antifeatures inverted in a featureset Andrew Cooper
2016-02-12 16:47   ` Jan Beulich
2016-02-12 16:50     ` Andrew Cooper
2016-02-12 17:15       ` Jan Beulich
2016-02-05 13:42 ` [PATCH v2 10/30] xen/x86: Annotate VM applicability in featureset Andrew Cooper
2016-02-12 17:05   ` Jan Beulich
2016-02-12 17:42     ` Andrew Cooper
2016-02-15  9:20       ` Jan Beulich
2016-02-15 14:38         ` Andrew Cooper
2016-02-15 14:50           ` Jan Beulich
2016-02-15 14:53             ` Andrew Cooper
2016-02-15 15:02               ` Jan Beulich
2016-02-15 15:41                 ` Andrew Cooper
2016-02-17 19:02                   ` Is: PVH dom0 - MWAIT detection logic to get deeper C-states exposed in ACPI AML code. Was:Re: " Konrad Rzeszutek Wilk
2016-02-17 19:58                     ` Boris Ostrovsky
2016-02-18 15:02                     ` Roger Pau Monné
2016-02-18 15:12                       ` Andrew Cooper
2016-02-18 16:24                         ` Boris Ostrovsky
2016-02-18 16:48                           ` Andrew Cooper
2016-02-18 17:03                         ` Roger Pau Monné
2016-02-18 22:08                           ` Konrad Rzeszutek Wilk
2016-02-18 15:16                       ` David Vrabel
2016-02-05 13:42 ` [PATCH v2 11/30] xen/x86: Calculate maximum host and guest featuresets Andrew Cooper
2016-02-15 13:37   ` Jan Beulich
2016-02-15 14:57     ` Andrew Cooper
2016-02-15 15:07       ` Jan Beulich
2016-02-15 15:52         ` Andrew Cooper
2016-02-05 13:42 ` [PATCH v2 12/30] xen/x86: Generate deep dependencies of features Andrew Cooper
2016-02-15 14:06   ` Jan Beulich
2016-02-15 15:28     ` Andrew Cooper
2016-02-15 15:52       ` Jan Beulich
2016-02-15 16:09         ` Andrew Cooper
2016-02-15 16:27           ` Jan Beulich
2016-02-15 19:07             ` Andrew Cooper
2016-02-16  9:54               ` Jan Beulich
2016-02-17 10:25                 ` Andrew Cooper
2016-02-17 10:42                   ` Jan Beulich
2016-02-05 13:42 ` [PATCH v2 13/30] xen/x86: Clear dependent features when clearing a cpu cap Andrew Cooper
2016-02-15 14:53   ` Jan Beulich
2016-02-15 15:33     ` Andrew Cooper
2016-02-15 14:56   ` Jan Beulich
2016-02-05 13:42 ` [PATCH v2 14/30] xen/x86: Improve disabling of features which have dependencies Andrew Cooper
2016-02-05 13:42 ` [PATCH v2 15/30] xen/x86: Improvements to in-hypervisor cpuid sanity checks Andrew Cooper
2016-02-15 15:43   ` Jan Beulich
2016-02-15 17:12     ` Andrew Cooper
2016-02-16 10:06       ` Jan Beulich
2016-02-17 10:43         ` Andrew Cooper
2016-02-17 10:55           ` Jan Beulich
2016-02-17 14:02             ` Andrew Cooper
2016-02-17 14:45               ` Jan Beulich
2016-02-18 12:17                 ` Andrew Cooper
2016-02-18 13:23                   ` Jan Beulich
2016-02-05 13:42 ` [PATCH v2 16/30] x86/cpu: Move set_cpumask() calls into c_early_init() Andrew Cooper
2016-02-16 14:10   ` Jan Beulich
2016-02-17 10:45     ` Andrew Cooper
2016-02-17 10:58       ` Jan Beulich
2016-02-18 12:41         ` Andrew Cooper
2016-02-05 13:42 ` [PATCH v2 17/30] x86/cpu: Common infrastructure for levelling context switching Andrew Cooper
2016-02-16 14:15   ` Jan Beulich
2016-02-17  8:15     ` Jan Beulich
2016-02-17 10:46       ` Andrew Cooper
2016-02-17 19:06   ` Konrad Rzeszutek Wilk
2016-02-05 13:42 ` [PATCH v2 18/30] x86/cpu: Rework AMD masking MSR setup Andrew Cooper
2016-02-17  7:40   ` Jan Beulich
2016-02-17 10:56     ` Andrew Cooper
2016-02-05 13:42 ` [PATCH v2 19/30] x86/cpu: Rework Intel masking/faulting setup Andrew Cooper
2016-02-17  7:57   ` Jan Beulich [this message]
2016-02-17 10:59     ` Andrew Cooper
2016-02-05 13:42 ` [PATCH v2 20/30] x86/cpu: Context switch cpuid masks and faulting state in context_switch() Andrew Cooper
2016-02-17  8:06   ` Jan Beulich
2016-02-05 13:42 ` [PATCH v2 21/30] x86/pv: Provide custom cpumasks for PV domains Andrew Cooper
2016-02-17  8:13   ` Jan Beulich
2016-02-17 11:03     ` Andrew Cooper
2016-02-17 11:14       ` Jan Beulich
2016-02-18 12:48         ` Andrew Cooper
2016-02-05 13:42 ` [PATCH v2 22/30] x86/domctl: Update PV domain cpumasks when setting cpuid policy Andrew Cooper
2016-02-17  8:22   ` Jan Beulich
2016-02-17 12:13     ` Andrew Cooper
2016-02-05 13:42 ` [PATCH v2 23/30] xen+tools: Export maximum host and guest cpu featuresets via SYSCTL Andrew Cooper
2016-02-05 16:12   ` Wei Liu
2016-02-17  8:30   ` Jan Beulich
2016-02-17 12:17     ` Andrew Cooper
2016-02-17 12:23       ` Jan Beulich
2016-02-05 13:42 ` [PATCH v2 24/30] tools/libxc: Modify bitmap operations to take void pointers Andrew Cooper
2016-02-05 16:12   ` Wei Liu
2016-02-08 11:40     ` Andrew Cooper
2016-02-08 16:23   ` Tim Deegan
2016-02-08 16:36     ` Ian Campbell
2016-02-10 10:07       ` Andrew Cooper
2016-02-10 10:18         ` Ian Campbell
2016-02-18 13:37           ` Andrew Cooper
2016-02-17 20:06         ` Konrad Rzeszutek Wilk
2016-02-05 13:42 ` [PATCH v2 25/30] tools/libxc: Use public/featureset.h for cpuid policy generation Andrew Cooper
2016-02-05 16:12   ` Wei Liu
2016-02-05 13:42 ` [PATCH v2 26/30] tools/libxc: Expose the automatically generated cpu featuremask information Andrew Cooper
2016-02-05 16:12   ` Wei Liu
2016-02-05 16:15     ` Wei Liu
2016-02-05 13:42 ` [PATCH v2 27/30] tools: Utility for dealing with featuresets Andrew Cooper
2016-02-05 16:13   ` Wei Liu
2016-02-05 13:42 ` [PATCH v2 28/30] tools/libxc: Wire a featureset through to cpuid policy logic Andrew Cooper
2016-02-05 16:13   ` Wei Liu
2016-02-05 13:42 ` [PATCH v2 29/30] tools/libxc: Use featuresets rather than guesswork Andrew Cooper
2016-02-05 16:13   ` Wei Liu
2016-02-17  8:55   ` Jan Beulich
2016-02-17 13:03     ` Andrew Cooper
2016-02-17 13:19       ` Jan Beulich
2016-02-05 13:42 ` [PATCH v2 30/30] tools/libxc: Calculate xstate cpuid leaf from guest information Andrew Cooper
2016-02-05 14:28   ` Jan Beulich
2016-02-05 15:22     ` Andrew Cooper
2016-02-08 17:26 ` [PATCH v2.5 31/30] Fix PV guest XSAVE handling with levelling Andrew Cooper
2016-02-17  9:02   ` Jan Beulich
2016-02-17 13:06     ` Andrew Cooper
2016-02-17 13:36       ` Jan Beulich

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=56C435F202000078000D2EF2@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=xen-devel@lists.xen.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.