mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Yang, Bin" <bin.yang@intel.com>
To: "tglx@linutronix.de" <tglx@linutronix.de>
Cc: "mingo@kernel.org" <mingo@kernel.org>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"Gross, Mark" <mark.gross@intel.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"Hansen, Dave" <dave.hansen@intel.com>
Subject: Re: [PATCH v3 3/5] x86/mm: add help function to check specific protection flags in range
Date: Tue, 4 Sep 2018 06:22:09 +0000	[thread overview]
Message-ID: <6709897a0ecec7112a52a53d3fe2d3fca649c902.camel@intel.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1809032357430.1462@nanos.tec.linutronix.de>

On Tue, 2018-09-04 at 00:10 +0200, Thomas Gleixner wrote:
> On Tue, 21 Aug 2018, Bin Yang wrote:
> >  /*
> > + * static_protections() "forces" page protections for some address
> > + * ranges.  Return true if any part of the address/len range is forced
> > + * to change from 'prot'.
> > + */
> > +static inline bool
> > +needs_static_protections(pgprot_t prot, unsigned long address,
> > +		unsigned long len, unsigned long pfn)
> > +{
> > +	int i;
> > +
> > +	address &= PAGE_MASK;
> > +	len = PFN_ALIGN(len);
> > +	for (i = 0; i < (len >> PAGE_SHIFT); i++, address += PAGE_SIZE, pfn++) {
> > +		pgprot_t chk_prot = static_protections(prot, address, pfn);
> > +
> > +		if (pgprot_val(chk_prot) != pgprot_val(prot))
> > +			return true;
> > +	}
> > +
> > +	/* Does static_protections() demand a change ? */
> > +	return false;
> > +}
> 
> ...
> 
> >  	if (cpa->force_split)
> > @@ -660,14 +684,8 @@ try_preserve_large_page(pte_t *kpte, unsigned long address,
> >  	 * static_protection() requires a different pgprot for one of
> >  	 * the pages in the range we try to preserve:
> >  	 */
> > -	pfn = old_pfn;
> > -	for (i = 0; i < (psize >> PAGE_SHIFT); i++, addr += PAGE_SIZE, pfn++) {
> > -		pgprot_t chk_prot = static_protections(req_prot, addr, pfn);
> > -
> > -		if (pgprot_val(chk_prot) != pgprot_val(new_prot))
> > -			goto out_unlock;
> > -	}
> > -
> > +	if (needs_static_protections(new_prot, addr, psize, old_pfn))
> > +		goto out_unlock;
> 
> This is not the same. The existing code does:
> 
>      new_prot = static_protections(req_prot, address, pfn);
> 
> which is the protection updated pgprot for the base of the address range
> which should be modified. The loop does:
> 
>     chk_prot = static_protections(req_prot, addr, pfn);
> 
>     if (chk_prot != new_prot)
>     	   goto split;
> 
> Now mapping your new function back and then the loop becomes:
> 
>     chk_prot = static_protections(new_prot, addr, pfn);
> 
>     if (chk_prot != new_prot)
>     	   goto split;
> 
> which is broken in case that after the initial static protections
> invocation
> 
> 	new_prot = static_protections(req_prot, address, pfn);
> 
> the result is:
> 
>    new_prot != req_prot
> 
> and in the loop
> 
>    new_prot is valid for _ALL_ pages in the large page because the static
>    protection which got applied for the first address can be applied to the
>    complete range, i.e. new_prot it is not further modified by
>    static_protections() for any page.
> 
> That again can cause wrong large page preservations.

Sorry for this mistake. Could I change it as below?

static inline bool
needs_static_protections(pgprot_t new_prot, pgprot_t req_prot,
                unsigned long address, unsigned long len, unsigned long pfn)
...
                pgprot_t chk_prot = static_protections(req_prot, address, pfn);

                if (pgprot_val(chk_prot) != pgprot_val(new_prot))
...

> 
> Thanks,
> 
> 	tglx
> 

  reply	other threads:[~2018-09-04  6:23 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-21  1:16 [PATCH v3 0/5] x86/mm: fix cpu stuck issue in __change_page_attr_set_clr Bin Yang
2018-08-21  1:16 ` [PATCH v3 1/5] x86/mm: avoid redundant checking if pgprot has no change Bin Yang
2018-09-03 21:57   ` Thomas Gleixner
2018-09-04  7:01     ` Yang, Bin
2018-09-04  7:49       ` Thomas Gleixner
2018-09-04  9:12         ` Yang, Bin
2018-09-04  9:22           ` Yang, Bin
2018-08-21  1:16 ` [PATCH v3 2/5] x86/mm: avoid static_protection() checking if not whole large page attr change Bin Yang
2018-08-21  1:16 ` [PATCH v3 3/5] x86/mm: add help function to check specific protection flags in range Bin Yang
2018-09-03 22:10   ` Thomas Gleixner
2018-09-04  6:22     ` Yang, Bin [this message]
2018-08-21  1:16 ` [PATCH v3 4/5] x86/mm: optimize static_protection() by using overlap() Bin Yang
2018-09-04 12:22   ` Thomas Gleixner
2018-09-07  1:14     ` Yang, Bin
2018-09-07  7:49       ` Thomas Gleixner
2018-09-07  8:04         ` Yang, Bin
2018-09-07  8:21           ` Thomas Gleixner
2018-09-07  8:26             ` Yang, Bin
2018-08-21  1:16 ` [PATCH v3 5/5] x86/mm: add WARN_ON_ONCE() for wrong large page mapping Bin Yang
2018-09-03 22:27   ` Thomas Gleixner
2018-09-04  6:32     ` Yang, Bin
2018-09-04  7:41       ` Thomas Gleixner
2018-09-04 16:52         ` Thomas Gleixner
2018-09-07  2:12           ` Yang, Bin

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=6709897a0ecec7112a52a53d3fe2d3fca649c902.camel@intel.com \
    --to=bin.yang@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.gross@intel.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --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

all inboxes | Powered by JetHome®