* [PATCH] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disable]
@ 2011-07-22 9:11 Michal Hocko
2011-07-22 16:15 ` H. Peter Anvin
0 siblings, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2011-07-22 9:11 UTC (permalink / raw)
To: Venki Pallipadi; +Cc: x86, linux-kernel, Ingo Molnar, H. Peter Anvin
Hi,
I have just come across a strange behavior of /dev/[k]mem when PAT is
configured while STRICT_DEVMEM is disabled.
One would expect that /dev/kmem would allow to access also the
system RAM in that configuration but that is not obviously true as pat
code defines range_is_allowed to protect from accessing that memory.
AFAICS this behavior was introduced in 0124cecf (x86, PAT: disable
/dev/mem mmap RAM with PAT) which says that it disables [k]mem with PAT
because it is safer. There is no explanation why it allows to access
that memory if CONFIG_NONPROMISC_DEVMEM (CONFIG_STRICT_DEVMEM now).
The thing is even more complicated by the fact that the access is
allowed when nopat kernel parameter is specified because
range_is_allowed just does't call devmem_is_allowed in that case.
While I do agree that the feature is not safe in general we should honor
STRICT_DEVMEM setting in some way IMO.
What do you think about the following fix? I have tried to preserve
"disabled for PAT" by default behavior.
---
>From e905f034d860c52de306b410ef148d601eae9e7f Mon Sep 17 00:00:00 2001
From: Michal Hocko <mhocko@suse.cz>
Date: Fri, 22 Jul 2011 11:01:01 +0200
Subject: [PATCH] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disable
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.
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
--
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9
Czech Republic
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disable]
2011-07-22 9:11 [PATCH] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disable] Michal Hocko
@ 2011-07-22 16:15 ` H. Peter Anvin
2011-07-22 17:31 ` Michal Hocko
0 siblings, 1 reply; 5+ messages in thread
From: H. Peter Anvin @ 2011-07-22 16:15 UTC (permalink / raw)
To: Michal Hocko; +Cc: Venki Pallipadi, x86, linux-kernel, Ingo Molnar
On 07/22/2011 02:11 AM, Michal Hocko wrote:
> Hi,
> I have just come across a strange behavior of /dev/[k]mem when PAT is
> configured while STRICT_DEVMEM is disabled.
> One would expect that /dev/kmem would allow to access also the
> system RAM in that configuration but that is not obviously true as pat
> code defines range_is_allowed to protect from accessing that memory.
>
> AFAICS this behavior was introduced in 0124cecf (x86, PAT: disable
> /dev/mem mmap RAM with PAT) which says that it disables [k]mem with PAT
> because it is safer. There is no explanation why it allows to access
> that memory if CONFIG_NONPROMISC_DEVMEM (CONFIG_STRICT_DEVMEM now).
>
> The thing is even more complicated by the fact that the access is
> allowed when nopat kernel parameter is specified because
> range_is_allowed just does't call devmem_is_allowed in that case.
>
> While I do agree that the feature is not safe in general we should honor
> STRICT_DEVMEM setting in some way IMO.
>
> What do you think about the following fix? I have tried to preserve
> "disabled for PAT" by default behavior.
The reason it is disabled for PAT is that it is very hard to track maps
of that memory that are created by mapping /dev/[k]mem, since those maps
don't have a defined PAT type and really should be transparently
tracking the consensus caching type; this is a facility that *could* be
created but has no other user.
-hpa
--
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel. I don't speak on their behalf.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disable]
2011-07-22 16:15 ` H. Peter Anvin
@ 2011-07-22 17:31 ` Michal Hocko
2011-07-22 18:30 ` H. Peter Anvin
0 siblings, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2011-07-22 17:31 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: Venki Pallipadi, x86, linux-kernel, Ingo Molnar
On Fri 22-07-11 09:15:08, H. Peter Anvin wrote:
> On 07/22/2011 02:11 AM, Michal Hocko wrote:
> > Hi,
> > I have just come across a strange behavior of /dev/[k]mem when PAT is
> > configured while STRICT_DEVMEM is disabled.
> > One would expect that /dev/kmem would allow to access also the
> > system RAM in that configuration but that is not obviously true as pat
> > code defines range_is_allowed to protect from accessing that memory.
> >
> > AFAICS this behavior was introduced in 0124cecf (x86, PAT: disable
> > /dev/mem mmap RAM with PAT) which says that it disables [k]mem with PAT
> > because it is safer. There is no explanation why it allows to access
> > that memory if CONFIG_NONPROMISC_DEVMEM (CONFIG_STRICT_DEVMEM now).
> >
> > The thing is even more complicated by the fact that the access is
> > allowed when nopat kernel parameter is specified because
> > range_is_allowed just does't call devmem_is_allowed in that case.
> >
> > While I do agree that the feature is not safe in general we should honor
> > STRICT_DEVMEM setting in some way IMO.
> >
> > What do you think about the following fix? I have tried to preserve
> > "disabled for PAT" by default behavior.
>
> The reason it is disabled for PAT is that it is very hard to track maps
> of that memory that are created by mapping /dev/[k]mem, since those maps
> don't have a defined PAT type and really should be transparently
> tracking the consensus caching type; this is a facility that *could* be
> created but has no other user.
Thanks for the clarification!
What do you think about fixing the nopat with STRICT_DEVMEM like the
patch does?
--
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9
Czech Republic
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disable]
2011-07-22 17:31 ` Michal Hocko
@ 2011-07-22 18:30 ` H. Peter Anvin
2011-07-23 12:39 ` Michal Hocko
0 siblings, 1 reply; 5+ messages in thread
From: H. Peter Anvin @ 2011-07-22 18:30 UTC (permalink / raw)
To: Michal Hocko; +Cc: Venkatesh Pallipadi, x86, linux-kernel, Ingo Molnar
On 07/22/2011 10:31 AM, Michal Hocko wrote:
>
> Thanks for the clarification!
> What do you think about fixing the nopat with STRICT_DEVMEM like the
> patch does?
>
>From what I gather from your patch, the issue is that STRICT_DEVMEM
isn't being honored with nopat? This is an obvious bug and should be fixed.
-hpa
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disable]
2011-07-22 18:30 ` H. Peter Anvin
@ 2011-07-23 12:39 ` Michal Hocko
0 siblings, 0 replies; 5+ messages in thread
From: Michal Hocko @ 2011-07-23 12:39 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: Venkatesh Pallipadi, x86, linux-kernel, Ingo Molnar
On Fri 22-07-11 11:30:55, H. Peter Anvin wrote:
> On 07/22/2011 10:31 AM, Michal Hocko wrote:
> >
> > Thanks for the clarification!
> > What do you think about fixing the nopat with STRICT_DEVMEM like the
> > patch does?
> >
>
> From what I gather from your patch, the issue is that STRICT_DEVMEM
> isn't being honored with nopat?
Yes.
> This is an obvious bug and should be fixed.
OK, thanks for confirmation. Should I just repost the patch without the
question about PAT vs. /dev/[k]mem or you will just pick it up from
there? Or would you preffer a different fix?
Thanks
--
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9
Czech Republic
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-07-23 12:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-22 9:11 [PATCH] x86, PAT: honor CONFIG_STRICT_DEVMEM if pat is disable] Michal Hocko
2011-07-22 16:15 ` H. Peter Anvin
2011-07-22 17:31 ` Michal Hocko
2011-07-22 18:30 ` H. Peter Anvin
2011-07-23 12:39 ` Michal Hocko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox