All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: Borislav Petkov <bp@alien8.de>
Cc: xen-devel@lists.xenproject.org, x86@kernel.org,
	linux-kernel@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH v3 03/10] x86/mtrr: replace use_intel() with a local flag
Date: Mon, 12 Sep 2022 11:10:29 +0200	[thread overview]
Message-ID: <80085512-5783-7ea0-fb7d-6e852f8942e0@suse.com> (raw)
In-Reply-To: <Yx21cizZHNzD38z7@nazgul.tnic>


[-- Attachment #1.1.1: Type: text/plain, Size: 3248 bytes --]

On 11.09.22 12:16, Borislav Petkov wrote:
> On Thu, Sep 08, 2022 at 10:49:07AM +0200, Juergen Gross wrote:
>> diff --git a/arch/x86/include/asm/cacheinfo.h b/arch/x86/include/asm/cacheinfo.h
>> index 86b2e0dcc4bf..1aeafa9888f7 100644
>> --- a/arch/x86/include/asm/cacheinfo.h
>> +++ b/arch/x86/include/asm/cacheinfo.h
>> @@ -2,6 +2,11 @@
>>   #ifndef _ASM_X86_CACHEINFO_H
>>   #define _ASM_X86_CACHEINFO_H
>>   
>> +/* Kernel controls MTRR and/or PAT MSRs. */
>> +extern unsigned int cache_generic;
> 
> So this should be called something more descriptive like
> 
> 	memory_caching_types

In the end this variable doesn't specify which caching types are available,
but the ways to select/control the caching types.

So what about "memory_caching_select" or "memory_caching_control" instead?

> or so to denote that this is a bitfield of supported memory caching
> technologies. The code then would read as
> 
> 	if (memory_caching_types & CACHE_MTRR)
> 
> The name's still not optimal tho - needs more brooding over.
> 
>> +#define CACHE_GENERIC_MTRR 0x01
>> +#define CACHE_GENERIC_PAT  0x02
> 
> And those should be CACHE_{MTRR,PAT}.

Fine with me.

>>   void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu);
>>   void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c, int cpu);
>>   
>> diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c
>> index 66556833d7af..3b05d3ade7a6 100644
>> --- a/arch/x86/kernel/cpu/cacheinfo.c
>> +++ b/arch/x86/kernel/cpu/cacheinfo.c
>> @@ -35,6 +35,9 @@ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
>>   /* Shared L2 cache maps */
>>   DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_l2c_shared_map);
>>   
>> +/* Kernel controls MTRR and/or PAT MSRs. */
>> +unsigned int cache_generic;
> 
> This should either be __ro_after_init and initialized to 0 or you need
> accessors...

Okay.

> 
>>   u32 num_var_ranges;
>> -static bool __mtrr_enabled;
>> -
>> -static bool mtrr_enabled(void)
>> -{
>> -	return __mtrr_enabled;
>> -}
>> +static bool mtrr_enabled;
> 
> Hmm, I don't like this. There's way too many boolean flags in the mtrr
> code. There's mtrr_state.enabled too. ;-\
> 
> Can we set (or clear) X86_FEATURE_MTRR to denote MTRR enablement status
> and get rid of one more boolean flag?

I'll have a look.

> 
> ...
> 
>>   void __init mtrr_bp_init(void)
>>   {
>> +	bool use_generic = false;
>>   	u32 phys_addr;
>>   
>>   	init_ifs();
>> @@ -694,6 +691,7 @@ void __init mtrr_bp_init(void)
>>   
>>   	if (boot_cpu_has(X86_FEATURE_MTRR)) {
>>   		mtrr_if = &generic_mtrr_ops;
>> +		use_generic = true;
>>   		size_or_mask = SIZE_OR_MASK_BITS(36);
>>   		size_and_mask = 0x00f00000;
>>   		phys_addr = 36;
>> @@ -755,15 +753,18 @@ void __init mtrr_bp_init(void)
>>   	}
>>   
>>   	if (mtrr_if) {
>> -		__mtrr_enabled = true;
>> -		set_num_var_ranges();
>> +		mtrr_enabled = true;
>> +		set_num_var_ranges(use_generic);
> 
> You don't need use_generic either:
> 
> 		set_num_var_ranges(mtrr_if == generic_mtrr_ops);
> 
> (The reason being I wanna get rid of that nasty minefield of boolean
> vars all round that code).

Fine with me.


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3149 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

  reply	other threads:[~2022-09-12  9:10 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-08  8:49 [PATCH v3 00/10] x86: make pat and mtrr independent from each other Juergen Gross
2022-09-08  8:49 ` [PATCH v3 01/10] x86/mtrr: add comment for set_mtrr_state() serialization Juergen Gross
2022-09-08  8:49 ` [PATCH v3 02/10] x86/mtrr: remove unused cyrix_set_all() function Juergen Gross
2022-09-08  8:49 ` [PATCH v3 03/10] x86/mtrr: replace use_intel() with a local flag Juergen Gross
2022-09-11 10:16   ` Borislav Petkov
2022-09-12  9:10     ` Juergen Gross [this message]
2022-09-19 19:10       ` Borislav Petkov
2022-09-28 10:17       ` Juergen Gross
2022-09-08  8:49 ` [PATCH v3 04/10] x86: move some code out of arch/x86/kernel/cpu/mtrr Juergen Gross
2022-09-11 11:02   ` Borislav Petkov
2022-09-12  9:11     ` Juergen Gross
2022-09-08  8:49 ` [PATCH v3 05/10] x86/mtrr: split generic_set_all() Juergen Gross
2022-09-19 19:25   ` Borislav Petkov
2022-09-08  8:49 ` [PATCH v3 06/10] x86/mtrr: remove set_all callback from struct mtrr_ops Juergen Gross
2022-09-08  8:49 ` [PATCH v3 07/10] x86/mtrr: simplify mtrr_bp_init() Juergen Gross
2022-09-26 18:40   ` Borislav Petkov
2022-09-08  8:49 ` [PATCH v3 08/10] x86/mtrr: let cache_aps_delayed_init replace mtrr_aps_delayed_init Juergen Gross
2022-09-26 21:11   ` Borislav Petkov
2022-09-27  8:57     ` Juergen Gross
2022-09-27 10:10       ` Borislav Petkov
2022-09-27 10:14         ` Juergen Gross
2022-09-27 11:19           ` Borislav Petkov
2022-09-27 11:25             ` Juergen Gross
2022-09-27 12:13               ` Borislav Petkov
2022-09-27 12:21                 ` Juergen Gross
2022-09-27 23:16                   ` Borislav Petkov
2022-09-28  5:30                     ` Juergen Gross
2022-09-28  6:16                       ` Juergen Gross
2022-09-28 10:48                         ` Borislav Petkov
2022-09-28 11:14                           ` Juergen Gross
2022-09-28 11:22                             ` Borislav Petkov
2022-09-28 13:43                               ` Juergen Gross
2022-09-28 16:12                                 ` Borislav Petkov
2022-09-28 16:32                                   ` Juergen Gross
2022-09-28 16:39                                     ` Borislav Petkov
2022-09-29  8:26                                     ` Juergen Gross
2022-09-30 11:55                                       ` Borislav Petkov
2022-09-30 13:11                                         ` Juergen Gross
2022-09-30 13:25                                           ` Borislav Petkov
2022-09-08  8:49 ` [PATCH v3 09/10] x86/mtrr: add a stop_machine() handler calling only cache_cpu_init() Juergen Gross
2022-09-08  8:49 ` [PATCH v3 10/10] x86: decouple pat and mtrr handling Juergen Gross

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=80085512-5783-7ea0-fb7d-6e852f8942e0@suse.com \
    --to=jgross@suse.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --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.