From: venkatesh.pallipadi@intel.com
To: ak@muc.de, ebiederm@xmission.com, rdreier@cisco.com,
torvalds@linux-foundation.org, gregkh@suse.de, airlied@skynet.ie,
davej@redhat.com, mingo@elte.hu, tglx@linutronix.de,
hpa@zytor.com, akpm@linux-foundation.org, arjan@infradead.org,
jesse.barnes@intel.com
Cc: linux-kernel@vger.kernel.org,
Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>,
Suresh Siddha <suresh.b.siddha@intel.com>
Subject: [RFC PATCH 04/12] PAT 64b: reserve_mattr and free_mattr for PAT
Date: Thu, 13 Dec 2007 15:55:47 -0800 [thread overview]
Message-ID: <20071213235711.900223000@intel.com> (raw)
In-Reply-To: <20071213235543.568682000@intel.com>
[-- Attachment #1: pat-conflict.patch --]
[-- Type: text/plain, Size: 5133 bytes --]
Straight forward port of pat-conflict.patch to x86 tree.
Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
---
Index: linux-2.6.24-rc4/arch/x86/mm/ioremap_64.c
===================================================================
--- linux-2.6.24-rc4.orig/arch/x86/mm/ioremap_64.c 2007-12-11 14:24:56.000000000 -0800
+++ linux-2.6.24-rc4/arch/x86/mm/ioremap_64.c 2007-12-12 15:03:26.000000000 -0800
@@ -19,6 +19,7 @@
#include <asm/tlbflush.h>
#include <asm/cacheflush.h>
#include <asm/proto.h>
+#include <asm/pat.h>
unsigned long __phys_addr(unsigned long x)
{
@@ -125,12 +126,23 @@
remove_vm_area((void *)(PAGE_MASK & (unsigned long) addr));
return NULL;
}
+
+ /* For plain ioremap() get the existing attributes. Otherwise
+ check against the existing ones */
+ if (reserve_mattr(phys_addr, phys_addr + size, flags,
+ flags ? NULL : &flags) < 0)
+ goto out;
+
if (flags && ioremap_change_attr(phys_addr, size, flags) < 0) {
- area->flags &= 0xffffff;
- vunmap(addr);
- return NULL;
+ free_mattr(phys_addr, phys_addr + size, flags);
+ goto out;
}
return (__force void __iomem *) (offset + (char *)addr);
+
+out:
+ area->flags &= 0xffffff;
+ vunmap(addr);
+ return NULL;
}
EXPORT_SYMBOL(__ioremap);
@@ -198,8 +210,10 @@
}
/* Reset the direct mapping. Can block */
- if (p->flags >> 20)
+ if (p->flags >> 20) {
+ free_mattr(p->phys_addr, p->phys_addr + p->size, p->flags>>20);
ioremap_change_attr(p->phys_addr, p->size, 0);
+ }
/* Finally remove it */
o = remove_vm_area((void *)addr);
Index: linux-2.6.24-rc4/arch/x86/mm/pat.c
===================================================================
--- linux-2.6.24-rc4.orig/arch/x86/mm/pat.c 2007-12-11 15:08:12.000000000 -0800
+++ linux-2.6.24-rc4/arch/x86/mm/pat.c 2007-12-12 15:06:52.000000000 -0800
@@ -6,6 +6,8 @@
#include <asm/msr.h>
#include <asm/tlbflush.h>
#include <asm/processor.h>
+#include <asm/pgtable.h>
+#include <asm/pat.h>
static u64 boot_pat_state;
@@ -55,3 +57,96 @@
}
}
+/* The global memattr list keeps track of caching attributes for specific
+ physical memory areas. Conflicting caching attributes in different
+ mappings can cause CPU cache corruption. To avoid this we keep track.
+
+ The list is sorted and can contain multiple entries for each address
+ (this allows reference counting for overlapping areas). All the aliases
+ have the same cache attributes of course. Zero attributes are represente
+ as holes.
+
+ Currently the data structure is a list because the number of mappings
+ are right now expected to be relatively small. If this should be a problem
+ it could be changed to a rbtree or similar.
+
+ mattr_lock protects the whole list. */
+
+struct memattr {
+ struct list_head nd;
+ u64 start;
+ u64 end;
+ unsigned long attr;
+};
+
+static LIST_HEAD(mattr_list);
+static DEFINE_SPINLOCK(mattr_lock); /* protects memattr list */
+
+int reserve_mattr(u64 start, u64 end, unsigned long attr, unsigned long *fattr)
+{
+ struct memattr *ma = NULL, *ml;
+ int err = 0;
+ if (attr) {
+ ma = kmalloc(sizeof(struct memattr), GFP_KERNEL);
+ if (!ma)
+ return -ENOMEM;
+ ma->start = start;
+ ma->end = end;
+ ma->attr = attr;
+ }
+ if (fattr)
+ *fattr = attr;
+ spin_lock(&mattr_lock);
+ list_for_each_entry(ml, &mattr_list, nd) {
+ if (ml->start <= start && ml->end >= end) {
+ if (fattr) {
+ attr = ml->attr;
+ *fattr = attr;
+ }
+ if (attr != ml->attr) {
+ printk(
+ KERN_ERR "%s:%d conflicting cache attribute %Lx-%Lx %lx<->%lx\n",
+ current->comm, current->pid,
+ start, end, attr, ml->attr);
+ err = -EBUSY;
+ break;
+ }
+ } else if (ml->start >= end) {
+ if (ma) {
+ list_add(&ma->nd, ml->nd.prev);
+ ma = NULL;
+ }
+ break;
+ }
+ }
+ if (ma)
+ list_add_tail(&ma->nd, &mattr_list);
+ spin_unlock(&mattr_lock);
+ return 0;
+}
+
+int free_mattr(u64 start, u64 end, unsigned long attr)
+{
+ struct memattr *ml;
+ int err = attr ? -EBUSY : 0;
+ spin_lock(&mattr_lock);
+ list_for_each_entry(ml, &mattr_list, nd) {
+ if (ml->start == start && ml->end == end) {
+ if (ml->attr != attr)
+ printk(KERN_ERR
+ "%s:%d conflicting cache attributes on free %Lx-%Lx %lx<->%lx\n",
+ current->comm, current->pid, start, end, attr,ml->attr);
+ list_del(&ml->nd);
+ kfree(ml);
+ err = 0;
+ break;
+ }
+ }
+ spin_unlock(&mattr_lock);
+ if (err)
+ printk(KERN_ERR "%s:%d freeing invalid mattr %Lx-%Lx %lx\n",
+ current->comm, current->pid,
+ start, end, attr);
+ return err;
+}
+
Index: linux-2.6.24-rc4/include/asm-x86/pat.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.24-rc4/include/asm-x86/pat.h 2007-12-11 15:39:28.000000000 -0800
@@ -0,0 +1,12 @@
+#ifndef _ASM_PAT_H
+#define _ASM_PAT_H 1
+
+#include <linux/types.h>
+
+/* Handle the page attribute table (PAT) of the CPU */
+
+int reserve_mattr(u64 start, u64 end, unsigned long attr, unsigned long *fattr);
+int free_mattr(u64 start, u64 end, unsigned long attr);
+
+#endif
+
--
next prev parent reply other threads:[~2007-12-14 0:04 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-13 23:55 [RFC PATCH 00/12] PAT 64b: PAT support for X86_64 venkatesh.pallipadi
2007-12-13 23:55 ` [RFC PATCH 01/12] PAT 64b: Add cpu_shutdown() support venkatesh.pallipadi
2007-12-13 23:55 ` [RFC PATCH 02/12] PAT 64b: Basic PAT implementation venkatesh.pallipadi
2007-12-14 0:42 ` Andi Kleen
2007-12-14 18:31 ` Venki Pallipadi
2007-12-18 4:50 ` Eric W. Biederman
2007-12-14 3:48 ` Eric W. Biederman
2007-12-14 4:23 ` Eric W. Biederman
2007-12-14 21:10 ` Siddha, Suresh B
2007-12-14 23:34 ` Siddha, Suresh B
2007-12-15 7:55 ` Ingo Molnar
2007-12-14 10:25 ` Andi Kleen
2007-12-14 19:45 ` H. Peter Anvin
2007-12-18 4:42 ` Eric W. Biederman
2007-12-14 21:06 ` Siddha, Suresh B
2007-12-13 23:55 ` [RFC PATCH 03/12] PAT 64b: drm driver changes for PAT venkatesh.pallipadi
2007-12-13 23:55 ` venkatesh.pallipadi [this message]
2007-12-13 23:55 ` [RFC PATCH 05/12] PAT 64b: pci mmap conlfict patch venkatesh.pallipadi
2007-12-13 23:55 ` [RFC PATCH 06/12] PAT 64b: Add ioremap_wc support venkatesh.pallipadi
2007-12-14 4:17 ` Roland Dreier
2007-12-14 4:28 ` Eric W. Biederman
2007-12-14 4:32 ` Roland Dreier
2007-12-14 4:48 ` Eric W. Biederman
2007-12-14 21:40 ` Siddha, Suresh B
2007-12-14 23:19 ` Andi Kleen
2007-12-18 8:29 ` Eric W. Biederman
2007-12-13 23:55 ` [RFC PATCH 07/12] PAT 64b: dev mem chanegs for pat venkatesh.pallipadi
2007-12-13 23:55 ` [RFC PATCH 08/12] PAT 64b: coherent mmap and sysfs bin ioctl venkatesh.pallipadi
2007-12-14 0:19 ` Greg KH
2007-12-14 0:35 ` David Miller
2007-12-14 6:34 ` Greg KH
2007-12-16 21:57 ` Paul Mackerras
2007-12-17 12:41 ` Andi Kleen
2007-12-18 4:30 ` Eric W. Biederman
2007-12-18 4:51 ` H. Peter Anvin
2007-12-18 9:35 ` Andi Kleen
2007-12-18 13:48 ` Eric W. Biederman
2007-12-14 0:43 ` Andi Kleen
2007-12-14 0:54 ` Jesse Barnes
2007-12-14 3:59 ` Eric W. Biederman
2007-12-14 6:02 ` Greg KH
2007-12-14 6:04 ` Eric W. Biederman
2007-12-14 10:19 ` Andi Kleen
2007-12-13 23:55 ` [RFC PATCH 09/12] PAT 64b: map only usable memory in identity mapping venkatesh.pallipadi
2007-12-13 23:55 ` [RFC PATCH 10/12] PAT 64b: Make acpi use early map instead of assuming identity map venkatesh.pallipadi
2007-12-13 23:55 ` [RFC PATCH 11/12] PAT 64b: devmem do not read pages not mapped in " venkatesh.pallipadi
2007-12-13 23:55 ` [RFC PATCH 12/12] PAT 64b: skip attr tracking for RAM venkatesh.pallipadi
2007-12-14 0:28 ` [RFC PATCH 00/12] PAT 64b: PAT support for X86_64 Dave Airlie
2007-12-14 22:00 ` Siddha, Suresh B
2007-12-14 22:27 ` Dave Airlie
2007-12-14 22:32 ` H. Peter Anvin
2007-12-14 22:37 ` Dave Airlie
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=20071213235711.900223000@intel.com \
--to=venkatesh.pallipadi@intel.com \
--cc=airlied@skynet.ie \
--cc=ak@muc.de \
--cc=akpm@linux-foundation.org \
--cc=arjan@infradead.org \
--cc=davej@redhat.com \
--cc=ebiederm@xmission.com \
--cc=gregkh@suse.de \
--cc=hpa@zytor.com \
--cc=jesse.barnes@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=rdreier@cisco.com \
--cc=suresh.b.siddha@intel.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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
Powered by JetHome