From f1eda4169fd6b1d5721a1e07a35411d3fe07d65a Mon Sep 17 00:00:00 2001 From: Andi Kleen Date: Fri, 14 May 2004 20:41:03 -0700 Subject: [PATCH] [PATCH] x86-64: fix /dev/mem caching behaviour This changes the /dev/mem caching behaviour on x86-64 to be compatible with i386. By default everything is set cached. This actually makes WC MTRRs on AMD systems work, which would get overriden by the UC PAT bits that were set earlier. This can make DVD decoding with hardware support a lot faster. It also supports O_SYNC now, like i386, although that is not really safe, because it allows the user to create undefined cache attribute conflicts that can corrupt caches in some circumstances. I kept it for now. Better would to disallow it, until Terrence Ripperda's PAT framework is getting merged, that can avoid these problems. Actually it would be probably a good idea to add a printk here to catch broken programs for i386 and x86-64, but that is for another patch. --- drivers/char/mem.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 477c63d6b0f3b..619e16d357cb0 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -62,6 +62,19 @@ static inline int uncached_access(struct file *file, unsigned long addr) test_bit(X86_FEATURE_CYRIX_ARR, boot_cpu_data.x86_capability) || test_bit(X86_FEATURE_CENTAUR_MCR, boot_cpu_data.x86_capability) ) && addr >= __pa(high_memory); +#elif defined(__x86_64__) + /* + * This is broken because it can generate memory type aliases, + * which can cause cache corruptions + * But it is only available for root and we have to be bug-to-bug + * compatible with i386. + */ + if (file->f_flags & O_SYNC) + return 1; + /* same behaviour as i386. PAT always set to cached and MTRRs control the + caching behaviour. + Hopefully a full PAT implementation will fix that soon. */ + return 0; #elif defined(CONFIG_IA64) /* * On ia64, we ignore O_SYNC because we cannot tolerate memory attribute aliases. -- 2.53.0