From: Borislav Petkov <bp@alien8.de>
To: Toshi Kani <toshi.kani@hp.com>
Cc: akpm@linux-foundation.org, hpa@zytor.com, tglx@linutronix.de,
mingo@redhat.com, linux-mm@kvack.org, x86@kernel.org,
linux-kernel@vger.kernel.org, dave.hansen@intel.com,
Elliott@hp.com, pebolle@tiscali.nl
Subject: Re: [PATCH v4 2/7] mtrr, x86: Fix MTRR lookup to handle inclusive entry
Date: Tue, 5 May 2015 19:11:15 +0200 [thread overview]
Message-ID: <20150505171114.GM3910@pd.tnic> (raw)
In-Reply-To: <1427234921-19737-3-git-send-email-toshi.kani@hp.com>
On Tue, Mar 24, 2015 at 04:08:36PM -0600, Toshi Kani wrote:
> When an MTRR entry is inclusive to a requested range, i.e.
> the start and end of the request are not within the MTRR
> entry range but the range contains the MTRR entry entirely,
> __mtrr_type_lookup() ignores such a case because both
> start_state and end_state are set to zero.
>
> This bug can cause the following issues:
> 1) reserve_memtype() tracks an effective memory type in case
> a request type is WB (ex. /dev/mem blindly uses WB). Missing
> to track with its effective type causes a subsequent request
> to map the same range with the effective type to fail.
> 2) pud_set_huge() and pmd_set_huge() check if a requested range
> has any overlap with MTRRs. Missing to detect an overlap may
> cause a performance penalty or undefined behavior.
>
> This patch fixes the bug by adding a new flag, 'inclusive',
> to detect the inclusive case. This case is then handled in
> the same way as (!start_state && end_state). With this fix,
> __mtrr_type_lookup() handles the inclusive case properly.
>
> Signed-off-by: Toshi Kani <toshi.kani@hp.com>
> ---
> arch/x86/kernel/cpu/mtrr/generic.c | 17 +++++++++--------
> 1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
> index 7d74f7b..a82e370 100644
> --- a/arch/x86/kernel/cpu/mtrr/generic.c
> +++ b/arch/x86/kernel/cpu/mtrr/generic.c
> @@ -154,7 +154,7 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)
>
> prev_match = 0xFF;
> for (i = 0; i < num_var_ranges; ++i) {
> - unsigned short start_state, end_state;
> + unsigned short start_state, end_state, inclusive;
>
> if (!(mtrr_state.var_ranges[i].mask_lo & (1 << 11)))
> continue;
> @@ -166,15 +166,16 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)
>
> start_state = ((start & mask) == (base & mask));
> end_state = ((end & mask) == (base & mask));
> + inclusive = ((start < base) && (end > base));
>
> - if (start_state != end_state) {
> + if ((start_state != end_state) || inclusive) {
> /*
> * We have start:end spanning across an MTRR.
> - * We split the region into
> - * either
> - * (start:mtrr_end) (mtrr_end:end)
> - * or
> - * (start:mtrr_start) (mtrr_start:end)
> + * We split the region into either
> + * - start_state:1
> + * (start:mtrr_end) (mtrr_end:end)
> + * - end_state:1 or inclusive:1
> + * (start:mtrr_start) (mtrr_start:end)
Ok, I'm confused. Shouldn't the inclusive:1 case be
(start:mtrr_start) (mtrr_start:mtrr_end) (mtrr_end:end)
?
If so, this function would need more changes...
> * depending on kind of overlap.
> * Return the type for first region and a pointer to
> * the start of second region so that caller will
> @@ -195,7 +196,7 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)
> *repeat = 1;
> }
>
> - if ((start & mask) != (base & mask))
> + if (!start_state)
> continue;
That change actually makes the code more unreadable because you have to
go and look up what start_state was and the previous version actually
shows the check that start is within the range, exactly like it is
documented in the CPU manuals.
And I'd leave it this way because gcc is smart enough to reload the
result saved in start_state and not compute it again.
Thanks.
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2015-05-05 17:11 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-24 22:08 [PATCH v4 0/7] mtrr, mm, x86: Enhance MTRR checks for huge I/O mapping Toshi Kani
2015-03-24 22:08 ` [PATCH v4 1/7] mm, x86: Document return values of mapping funcs Toshi Kani
2015-05-05 11:19 ` Borislav Petkov
2015-05-05 13:46 ` Toshi Kani
2015-05-05 14:19 ` Borislav Petkov
2015-05-05 14:14 ` Toshi Kani
2015-03-24 22:08 ` [PATCH v4 2/7] mtrr, x86: Fix MTRR lookup to handle inclusive entry Toshi Kani
2015-05-05 17:11 ` Borislav Petkov [this message]
2015-05-05 17:32 ` Toshi Kani
2015-05-05 18:39 ` Borislav Petkov
2015-05-05 19:31 ` Toshi Kani
2015-05-05 20:09 ` Borislav Petkov
2015-05-05 20:06 ` Toshi Kani
2015-03-24 22:08 ` [PATCH v4 3/7] mtrr, x86: Remove a wrong address check in __mtrr_type_lookup() Toshi Kani
2015-05-06 10:46 ` Borislav Petkov
[not found] ` <1431332153-18566-8-git-send-email-bp@alien8.de>
2015-05-11 12:46 ` [tip:x86/mm] x86/mm/mtrr: Remove incorrect " tip-bot for Toshi Kani
2015-03-24 22:08 ` [PATCH v4 4/7] mtrr, x86: Fix MTRR state checks in mtrr_type_lookup() Toshi Kani
2015-05-06 11:47 ` Borislav Petkov
2015-05-06 15:23 ` Toshi Kani
2015-05-06 22:39 ` Borislav Petkov
2015-05-06 23:08 ` Toshi Kani
2015-03-24 22:08 ` [PATCH v4 5/7] mtrr, x86: Define MTRR_TYPE_INVALID for mtrr_type_lookup() Toshi Kani
2015-03-24 22:08 ` [PATCH v4 6/7] mtrr, x86: Clean up mtrr_type_lookup() Toshi Kani
2015-05-06 13:41 ` Borislav Petkov
2015-05-06 16:00 ` Toshi Kani
2015-05-06 22:49 ` Borislav Petkov
2015-05-06 23:42 ` Toshi Kani
2015-05-07 7:52 ` Borislav Petkov
2015-05-07 13:45 ` Toshi Kani
2015-03-24 22:08 ` [PATCH v4 7/7] mtrr, mm, x86: Enhance MTRR checks for KVA huge page mapping Toshi Kani
2015-05-09 9:08 ` Borislav Petkov
2015-05-11 19:25 ` Toshi Kani
2015-05-11 20:18 ` Borislav Petkov
2015-05-11 20:38 ` Toshi Kani
2015-05-11 21:42 ` Borislav Petkov
2015-05-11 22:09 ` Toshi Kani
2015-05-12 7:28 ` Borislav Petkov
2015-05-12 14:30 ` Toshi Kani
2015-05-12 16:31 ` Borislav Petkov
2015-05-12 16:57 ` Toshi Kani
2015-03-24 22:43 ` [PATCH v4 0/7] mtrr, mm, x86: Enhance MTRR checks for huge I/O mapping Andrew Morton
2015-04-03 6:33 ` Ingo Molnar
2015-04-03 15:22 ` Toshi Kani
2015-04-27 14:31 ` Toshi Kani
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=20150505171114.GM3910@pd.tnic \
--to=bp@alien8.de \
--cc=Elliott@hp.com \
--cc=akpm@linux-foundation.org \
--cc=dave.hansen@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.com \
--cc=pebolle@tiscali.nl \
--cc=tglx@linutronix.de \
--cc=toshi.kani@hp.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