Linux Documentation
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: Borislav Petkov <bp@alien8.de>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
	linux-hyperv@vger.kernel.org, linux-doc@vger.kernel.org,
	mikelley@microsoft.com, Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"K. Y. Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	xen-devel@lists.xenproject.org, Jonathan Corbet <corbet@lwn.net>,
	Andy Lutomirski <luto@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH v6 00/16] x86/mtrr: fix handling with PAT but without MTRR
Date: Mon, 22 May 2023 16:17:50 +0200	[thread overview]
Message-ID: <0cd3899b-cf3b-61c1-14ae-60b6b49d14ab@suse.com> (raw)
In-Reply-To: <20230511163208.GDZF0YiOfxQhSo4RDm@fat_crate.local>


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

On 11.05.23 18:32, Borislav Petkov wrote:
> On Wed, May 10, 2023 at 05:53:15PM +0200, Juergen Gross wrote:
>> Urgh, yes, there is something missing:
>>
>> diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
>> index 031f7ea8e72b..9544e7d13bb3 100644
>> --- a/arch/x86/kernel/cpu/mtrr/generic.c
>> +++ b/arch/x86/kernel/cpu/mtrr/generic.c
>> @@ -521,8 +521,12 @@ u8 mtrr_type_lookup(u64 start, u64 end, u8 *uniform)
>>          for (i = 0; i < cache_map_n && start < end; i++) {
>>                  if (start >= cache_map[i].end)
>>                          continue;
> 
> So the loop will go through the map until...
> 
>> -               if (start < cache_map[i].start)
>> +               if (start < cache_map[i].start) {
> 
> ... it reaches the first entry where that is true.
> 
>>                          type = type_merge(type, mtrr_state.def_type, uniform);
> 
> the @type argument is MTRR_TYPE_INVALID, def_type is WRBACK so what
> this'll do is simply get you the default WRBACK type:
> 
> type_merge:
>          if (type == MTRR_TYPE_INVALID)
>                  return new_type;
> 
>> +                       start = cache_map[i].start;
>> +                       if (end <= start)
>> +                               break;
> 
> Now you break here because end <= start. Why?
> 
> You can just as well do:
> 
> 	if (start < cache_map[i].start) {
> 		/* region non-overlapping with the region in the map */
> 		if (end <= cache_map[i].start)
> 			return type_merge(type, mtrr_state.def_type, uniform);
> 
> 		... rest of the processing ...
> 
> In general, I get it that your code is slick but I want it to be
> maintainable - not slick. I'd like for when people look at this, not
> have to  add a bunch of debugging output in order to swap the whole
> thing back into their brains.
> 
> So mtrr_type_lookup() definitely needs comments explaining what goes
> where.
> 
> You can send it as a diff ontop - I'll merge it.

The attached diff is for patch 13.


Juergen


[-- Attachment #1.1.2: diff.patch --]
[-- Type: text/x-patch, Size: 1143 bytes --]

diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
index 031f7ea8e72b..4171788b8754 100644
--- a/arch/x86/kernel/cpu/mtrr/generic.c
+++ b/arch/x86/kernel/cpu/mtrr/generic.c
@@ -519,15 +519,26 @@ u8 mtrr_type_lookup(u64 start, u64 end, u8 *uniform)
 		return MTRR_TYPE_INVALID;
 
 	for (i = 0; i < cache_map_n && start < end; i++) {
+		/* Region after current map entry? -> continue with next one. */
 		if (start >= cache_map[i].end)
 			continue;
-		if (start < cache_map[i].start)
+
+		/* Start of region not covered by current map entry? */
+		if (start < cache_map[i].start) {
+			/* At least some part of region has default type. */
 			type = type_merge(type, mtrr_state.def_type, uniform);
+			/* End of region not covered, too? -> lookup done. */
+			if (end <= cache_map[i].start)
+				return type;
+		}
+
+		/* At least part of region covered by map entry. */
 		type = type_merge(type, cache_map[i].type, uniform);
 
 		start = cache_map[i].end;
 	}
 
+	/* End of region past last entry in map? -> use default type. */
 	if (start < end)
 		type = type_merge(type, mtrr_state.def_type, uniform);
 

[-- Attachment #1.1.3: 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:[~2023-05-22 14:17 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-02 12:09 [PATCH v6 00/16] x86/mtrr: fix handling with PAT but without MTRR Juergen Gross
2023-05-02 12:09 ` [PATCH v6 12/16] x86/mtrr: add mtrr=debug command line option Juergen Gross
2023-05-03  4:22 ` [PATCH v6 00/16] x86/mtrr: fix handling with PAT but without MTRR Michael Kelley (LINUX)
2023-05-03 18:14 ` Sohil Mehta
2023-05-03 19:12   ` Borislav Petkov
2023-05-09 20:14 ` Borislav Petkov
2023-05-09 23:36   ` Borislav Petkov
2023-05-10 13:30     ` Borislav Petkov
2023-05-10 13:31       ` Borislav Petkov
2023-05-10 15:53       ` Juergen Gross
2023-05-11 16:32         ` Borislav Petkov
2023-05-22 14:17           ` Juergen Gross [this message]
2023-05-30 15:28             ` Borislav Petkov
2023-05-31  7:28               ` Juergen Gross
2023-05-31  8:35                 ` Borislav Petkov
2023-05-31  9:31                   ` Juergen Gross
2023-05-31  9:58                     ` Borislav Petkov
2023-05-31 14:20                   ` Juergen Gross
     [not found]                     ` <20230531174857.GDZHeIib57h5lT5Vh1@fat_crate.local>
2023-06-01  6:39                       ` Juergen Gross
2023-06-01 12:48                         ` Borislav Petkov
2023-06-01 12:53                           ` Juergen Gross
2023-06-01  8:19                       ` Juergen Gross
2023-06-01 13:22                         ` Borislav Petkov
2023-06-01 14:33                           ` Borislav Petkov
2023-06-01 14:34                             ` Juergen Gross
2023-06-01 13:10                       ` 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=0cd3899b-cf3b-61c1-14ae-60b6b49d14ab@suse.com \
    --to=jgross@suse.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=hpa@zytor.com \
    --cc=kys@microsoft.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mikelley@microsoft.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=wei.liu@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox