mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH resend] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disabled
       [not found] <20110801094611.AAF738A95F@mx2.suse.de>
@ 2011-08-01 23:33 ` Venki Pallipadi
  2011-08-02  8:03   ` Michal Hocko
  0 siblings, 1 reply; 4+ messages in thread
From: Venki Pallipadi @ 2011-08-01 23:33 UTC (permalink / raw)
  To: Michal Hocko; +Cc: x86, linux-kernel, H. Peter Anvin, Ingo Molnar

On Fri, Jul 22, 2011 at 2:01 AM, Michal Hocko <mhocko@suse.cz> wrote:
>
> since 0124cecf (x86, PAT: disable /dev/mem mmap RAM with PAT) we are
> disabling access to the system RAM as if STRICT_DEVMEM was enabled by
> default. If we, however, disable pat by nopat kernel parameter we can
> access that memory without considering CONFIG_STRICT_DEVMEM.

Looking at the code, I don't think this problem exists. Code in pat.c
disables /dev/mem mmap only when !CONFIG_STRICT_DEVMEM.

When CONFIG_STRICT_DEVMEM, irrespective of pat or nopat, code in mem.c
disables mmap access. The code in pat.c has no effect on whether mmap
is allowed or not.

When !CONFIG_STRICT_DEVMEM, mmap is disabled with pat. And on nopat
mmap is allowed with the check in pat.c:range_is_allowed() with the
change from commit 9e41bff2.

Thanks,
Venki

>
> Let's make the code to honor STRICT_DEVMEM while we still preserve
> disabled by default behavior. This means that the access to the system
> memory is granted only if nopat is provided and STRICT_DEVMEM is
> disabled.
>
> Signed-off-by: Michal Hocko <mhocko@suse.cz>
> ---
>  arch/x86/mm/pat.c |   10 ++--------
>  1 files changed, 2 insertions(+), 8 deletions(-)
>
> diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
> index f6ff57b..fbaf3fc 100644
> --- a/arch/x86/mm/pat.c
> +++ b/arch/x86/mm/pat.c
> @@ -472,13 +472,6 @@ pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
>        return vma_prot;
>  }
>
> -#ifdef CONFIG_STRICT_DEVMEM
> -/* This check is done in drivers/char/mem.c in case of STRICT_DEVMEM*/
> -static inline int range_is_allowed(unsigned long pfn, unsigned long size)
> -{
> -       return 1;
> -}
> -#else
>  /* This check is needed to avoid cache aliasing when PAT is enabled */
>  static inline int range_is_allowed(unsigned long pfn, unsigned long size)
>  {
> @@ -486,8 +479,10 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
>        u64 to = from + size;
>        u64 cursor = from;
>
> +#ifndef CONFIG_STRICT_DEVMEM
>        if (!pat_enabled)
>                return 1;
> +#endif
>
>        while (cursor < to) {
>                if (!devmem_is_allowed(pfn)) {
> @@ -501,7 +496,6 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
>        }
>        return 1;
>  }
> -#endif /* CONFIG_STRICT_DEVMEM */
>
>  int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
>                                unsigned long size, pgprot_t *vma_prot)
> --
> 1.7.5.4
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH resend] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disabled
  2011-08-01 23:33 ` [PATCH resend] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disabled Venki Pallipadi
@ 2011-08-02  8:03   ` Michal Hocko
  2011-08-02 16:33     ` Venki Pallipadi
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Hocko @ 2011-08-02  8:03 UTC (permalink / raw)
  To: Venki Pallipadi; +Cc: x86, linux-kernel, H. Peter Anvin, Ingo Molnar

On Mon 01-08-11 16:33:18, Venki Pallipadi wrote:
> On Fri, Jul 22, 2011 at 2:01 AM, Michal Hocko <mhocko@suse.cz> wrote:
> >
> > since 0124cecf (x86, PAT: disable /dev/mem mmap RAM with PAT) we are
> > disabling access to the system RAM as if STRICT_DEVMEM was enabled by
> > default. If we, however, disable pat by nopat kernel parameter we can
> > access that memory without considering CONFIG_STRICT_DEVMEM.
> 
> Looking at the code, I don't think this problem exists. Code in pat.c
> disables /dev/mem mmap only when !CONFIG_STRICT_DEVMEM.

Ahh yes, you are right. I got confused by having two separate
range_is_allowed functions and didn't realize which one is called from
which context.
	mmap_mem
	  -> range_is_allowed [drivers/char/mem.c]
	       -EPERM
	  -> phys_mem_access_prot_allowed
	       -> range_is_allowed [arch/x86/mm/pat.c]

So we really get stopped at the first check and do not get to the later
one.

While we are at it. {read,write}_mem checks only range_is_allowed (mem.c
version) and it doesn't call phys_mem_access_prot_allowed so we do not
consider PAT. {read,write}_kmem doesn't check the range at all.
Is this correct?
Why do we care _only_ about mmap?

Thanks
-- 
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH resend] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disabled
  2011-08-02  8:03   ` Michal Hocko
@ 2011-08-02 16:33     ` Venki Pallipadi
  2011-08-02 17:02       ` Michal Hocko
  0 siblings, 1 reply; 4+ messages in thread
From: Venki Pallipadi @ 2011-08-02 16:33 UTC (permalink / raw)
  To: Michal Hocko; +Cc: x86, linux-kernel, H. Peter Anvin, Ingo Molnar

On Tue, Aug 2, 2011 at 1:03 AM, Michal Hocko <mhocko@suse.cz> wrote:
> On Mon 01-08-11 16:33:18, Venki Pallipadi wrote:
>> On Fri, Jul 22, 2011 at 2:01 AM, Michal Hocko <mhocko@suse.cz> wrote:
>> >
>> > since 0124cecf (x86, PAT: disable /dev/mem mmap RAM with PAT) we are
>> > disabling access to the system RAM as if STRICT_DEVMEM was enabled by
>> > default. If we, however, disable pat by nopat kernel parameter we can
>> > access that memory without considering CONFIG_STRICT_DEVMEM.
>>
>> Looking at the code, I don't think this problem exists. Code in pat.c
>> disables /dev/mem mmap only when !CONFIG_STRICT_DEVMEM.
>
> Ahh yes, you are right. I got confused by having two separate
> range_is_allowed functions and didn't realize which one is called from
> which context.
>        mmap_mem
>          -> range_is_allowed [drivers/char/mem.c]
>               -EPERM
>          -> phys_mem_access_prot_allowed
>               -> range_is_allowed [arch/x86/mm/pat.c]
>
> So we really get stopped at the first check and do not get to the later
> one.
>
> While we are at it. {read,write}_mem checks only range_is_allowed (mem.c
> version) and it doesn't call phys_mem_access_prot_allowed so we do not
> consider PAT. {read,write}_kmem doesn't check the range at all.
> Is this correct?
> Why do we care _only_ about mmap?
>

Yes. The problem with PAT and /dev/mem mmap is with untracked mmaps in
user address space. Once mapped the mappings can stay in user space
and if there is a page attribute change for that physical address
later kernel doesn't have handle on all such user space mappings that
may exist.
Read/Write on the other hand use direct mappings and will not cause
this problem. I have generally been suggesting tools that want to
access /dev/mem and are unable to mmap it due to PAT to use read/write
instead. /dev/mem on 32 bit has some problems of its own and the
recent patchset on mailing list fixes most of the issues there.

Thanks,
Venki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH resend] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disabled
  2011-08-02 16:33     ` Venki Pallipadi
@ 2011-08-02 17:02       ` Michal Hocko
  0 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2011-08-02 17:02 UTC (permalink / raw)
  To: Venki Pallipadi; +Cc: x86, linux-kernel, H. Peter Anvin, Ingo Molnar

On Tue 02-08-11 09:33:28, Venki Pallipadi wrote:
> On Tue, Aug 2, 2011 at 1:03 AM, Michal Hocko <mhocko@suse.cz> wrote:
> > On Mon 01-08-11 16:33:18, Venki Pallipadi wrote:
> >> On Fri, Jul 22, 2011 at 2:01 AM, Michal Hocko <mhocko@suse.cz> wrote:
> >> >
> >> > since 0124cecf (x86, PAT: disable /dev/mem mmap RAM with PAT) we are
> >> > disabling access to the system RAM as if STRICT_DEVMEM was enabled by
> >> > default. If we, however, disable pat by nopat kernel parameter we can
> >> > access that memory without considering CONFIG_STRICT_DEVMEM.
> >>
> >> Looking at the code, I don't think this problem exists. Code in pat.c
> >> disables /dev/mem mmap only when !CONFIG_STRICT_DEVMEM.
> >
> > Ahh yes, you are right. I got confused by having two separate
> > range_is_allowed functions and didn't realize which one is called from
> > which context.
> >        mmap_mem
> >          -> range_is_allowed [drivers/char/mem.c]
> >               -EPERM
> >          -> phys_mem_access_prot_allowed
> >               -> range_is_allowed [arch/x86/mm/pat.c]
> >
> > So we really get stopped at the first check and do not get to the later
> > one.
> >
> > While we are at it. {read,write}_mem checks only range_is_allowed (mem.c
> > version) and it doesn't call phys_mem_access_prot_allowed so we do not
> > consider PAT. {read,write}_kmem doesn't check the range at all.
> > Is this correct?
> > Why do we care _only_ about mmap?
> >
> 
> Yes. The problem with PAT and /dev/mem mmap is with untracked mmaps in
> user address space. Once mapped the mappings can stay in user space
> and if there is a page attribute change for that physical address
> later kernel doesn't have handle on all such user space mappings that
> may exist.
> Read/Write on the other hand use direct mappings and will not cause
> this problem. I have generally been suggesting tools that want to
> access /dev/mem and are unable to mmap it due to PAT to use read/write
> instead. /dev/mem on 32 bit has some problems of its own and the
> recent patchset on mailing list fixes most of the issues there.

OK, understood. Thanks for the clarification.

-- 
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-08-02 17:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20110801094611.AAF738A95F@mx2.suse.de>
2011-08-01 23:33 ` [PATCH resend] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disabled Venki Pallipadi
2011-08-02  8:03   ` Michal Hocko
2011-08-02 16:33     ` Venki Pallipadi
2011-08-02 17:02       ` Michal Hocko

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®