linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: mingo@kernel.org, hpa@zytor.com, bp@alien8.de,
	dvlasenk@redhat.com, bp@suse.de, akpm@linux-foundation.org,
	brgerst@gmail.com, tglx@linutronix.de, linux-mm@kvack.org,
	luto@amacapital.net, mcgrof@suse.com, toshi.kani@hp.com,
	torvalds@linux-foundation.org, linux-kernel@vger.kernel.org
Cc: linux-tip-commits@vger.kernel.org
Subject: Re: [tip:x86/mm] x86/mm/mtrr: Clean up mtrr_type_lookup()
Date: Fri, 31 Jul 2015 15:18:02 +0200	[thread overview]
Message-ID: <20150731131802.GW25159@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <tip-0cc705f56e400764a171055f727d28a48260bb4b@git.kernel.org>

On Wed, May 27, 2015 at 07:19:05AM -0700, tip-bot for Toshi Kani wrote:
> +/**
> + * mtrr_type_lookup - look up memory type in MTRR
> + *
> + * Return Values:
> + * MTRR_TYPE_(type)  - The effective MTRR type for the region
> + * MTRR_TYPE_INVALID - MTRR is disabled
>   */
>  u8 mtrr_type_lookup(u64 start, u64 end)
>  {

>  	int repeat;
>  	u64 partial_end;
>  
> +	if (!mtrr_state_set)
> +		return MTRR_TYPE_INVALID;
> +
> +	if (!(mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED))
> +		return MTRR_TYPE_INVALID;
> +
> +	/*
> +	 * Look up the fixed ranges first, which take priority over
> +	 * the variable ranges.
> +	 */
> +	if ((start < 0x100000) &&
> +	    (mtrr_state.have_fixed) &&
> +	    (mtrr_state.enabled & MTRR_STATE_MTRR_FIXED_ENABLED))
> +		return mtrr_type_lookup_fixed(start, end);
> +
> +	/*
> +	 * Look up the variable ranges.  Look of multiple ranges matching
> +	 * this address and pick type as per MTRR precedence.
> +	 */
> +	type = mtrr_type_lookup_variable(start, end, &partial_end, &repeat);
>  
>  	/*
>  	 * Common path is with repeat = 0.
>  	 * However, we can have cases where [start:end] spans across some
> +	 * MTRR ranges and/or the default type.  Do repeated lookups for
> +	 * that case here.
>  	 */
>  	while (repeat) {
>  		prev_type = type;
>  		start = partial_end;
> +		type = mtrr_type_lookup_variable(start, end, &partial_end, &repeat);
>  
>  		if (check_type_overlap(&prev_type, &type))
>  			return type;
>  	}
>  
> +	if (mtrr_tom2 && (start >= (1ULL<<32)) && (end < mtrr_tom2))
> +		return MTRR_TYPE_WRBACK;
> +
>  	return type;
>  }

So I got staring at this MTRR horror show because I _really_ _Really_
want to kill stop_machine_from_inactive_cpu().

But I wondered about these lookup functions, should they not have an
assertion that preemption is disabled?

Using these functions with preemption enabled is racy against MTRR
updates. And if that race is ok, at the very least explain that it is
indeed racy and why this is not a problem.

--
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>

  reply	other threads:[~2015-07-31 13:18 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-15 18:23 [PATCH v5 0/6] mtrr, mm, x86: Enhance MTRR checks for huge I/O mapping Toshi Kani
2015-05-15 18:23 ` [PATCH v5 1/6] mm, x86: Simplify conditions of HAVE_ARCH_HUGE_VMAP Toshi Kani
2015-05-17  8:30   ` Borislav Petkov
     [not found]   ` <1432628901-18044-2-git-send-email-bp@alien8.de>
2015-05-27 14:17     ` [tip:x86/mm] x86/mm/kconfig: Simplify conditions for HAVE_ARCH_HUGE_VMAP tip-bot for Toshi Kani
2015-05-15 18:23 ` [PATCH v5 2/6] mtrr, x86: Fix MTRR lookup to handle inclusive entry Toshi Kani
     [not found]   ` <1432628901-18044-3-git-send-email-bp@alien8.de>
2015-05-27 14:18     ` [tip:x86/mm] x86/mm/mtrr: Fix MTRR lookup to handle an " tip-bot for Toshi Kani
2015-05-15 18:23 ` [PATCH v5 3/6] mtrr, x86: Fix MTRR state checks in mtrr_type_lookup() Toshi Kani
     [not found]   ` <1432628901-18044-4-git-send-email-bp@alien8.de>
2015-05-27 14:18     ` [tip:x86/mm] x86/mm/mtrr: " tip-bot for Toshi Kani
2015-05-15 18:23 ` [PATCH v5 4/6] mtrr, x86: Define MTRR_TYPE_INVALID for mtrr_type_lookup() Toshi Kani
     [not found]   ` <1432628901-18044-5-git-send-email-bp@alien8.de>
2015-05-27 14:18     ` [tip:x86/mm] x86/mm/mtrr: Use symbolic define as a retval for disabled MTRRs tip-bot for Toshi Kani
2015-05-15 18:23 ` [PATCH v5 5/6] mtrr, x86: Clean up mtrr_type_lookup() Toshi Kani
     [not found]   ` <1432628901-18044-6-git-send-email-bp@alien8.de>
2015-05-27 14:19     ` [tip:x86/mm] x86/mm/mtrr: " tip-bot for Toshi Kani
2015-07-31 13:18       ` Peter Zijlstra [this message]
2015-07-31 14:44         ` Borislav Petkov
2015-07-31 15:08           ` Peter Zijlstra
2015-07-31 15:27             ` Borislav Petkov
2015-08-01 14:28               ` Luis R. Rodriguez
2015-08-01 16:33                 ` Borislav Petkov
2015-08-01 16:39                   ` Linus Torvalds
2015-08-01 16:49                     ` Borislav Petkov
2015-08-01 17:03                       ` Linus Torvalds
2015-05-15 18:23 ` [PATCH v5 6/6] mtrr, mm, x86: Enhance MTRR checks for KVA huge page mapping Toshi Kani
2015-05-18 13:33   ` Borislav Petkov
2015-05-18 17:22     ` Toshi Kani
2015-05-18 19:01       ` Borislav Petkov
2015-05-18 19:31         ` Toshi Kani
2015-05-18 20:01           ` Borislav Petkov
2015-05-18 20:21             ` Toshi Kani
2015-05-18 20:51               ` Borislav Petkov
2015-05-18 21:53                 ` Toshi Kani
2015-05-19 11:44                   ` Borislav Petkov
2015-05-19 13:23                     ` Borislav Petkov
2015-05-19 13:47                       ` Toshi Kani
2015-05-20 11:55                       ` Ingo Molnar
2015-05-20 14:34                         ` Toshi Kani
2015-05-20 15:01                           ` Ingo Molnar
2015-05-20 15:02                             ` Toshi Kani
2015-05-20 16:04                               ` Borislav Petkov
2015-05-20 15:46                                 ` Toshi Kani
     [not found]   ` <1432628901-18044-8-git-send-email-bp@alien8.de>
2015-05-27 14:19     ` [tip:x86/mm] x86/mm/mtrr: Enhance MTRR checks in kernel mapping helpers tip-bot for 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=20150731131802.GW25159@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=bp@suse.de \
    --cc=brgerst@gmail.com \
    --cc=dvlasenk@redhat.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mcgrof@suse.com \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=toshi.kani@hp.com \
    /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).