提交 1c29f25b 编写于 作者: T Toshi Kani 提交者: Ingo Molnar

memremap: Change region_intersects() to take @flags and @desc

Change region_intersects() to identify a target with @flags and
@desc, instead of @name with strcmp().

Change the callers of region_intersects(), memremap() and
devm_memremap(), to set IORESOURCE_SYSTEM_RAM in @flags and
IORES_DESC_NONE in @desc when searching System RAM.

Also, export region_intersects() so that the ACPI EINJ error
injection driver can call this function in a later patch.
Signed-off-by: NToshi Kani <toshi.kani@hpe.com>
Signed-off-by: NBorislav Petkov <bp@suse.de>
Acked-by: NDan Williams <dan.j.williams@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jakub Sitnicki <jsitnicki@gmail.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jiang Liu <jiang.liu@linux.intel.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Toshi Kani <toshi.kani@hp.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-arch@vger.kernel.org
Cc: linux-mm <linux-mm@kvack.org>
Link: http://lkml.kernel.org/r/1453841853-11383-13-git-send-email-bp@alien8.deSigned-off-by: NIngo Molnar <mingo@kernel.org>
上级 05fee7cf
...@@ -385,7 +385,8 @@ enum { ...@@ -385,7 +385,8 @@ enum {
REGION_MIXED, REGION_MIXED,
}; };
int region_intersects(resource_size_t offset, size_t size, const char *type); int region_intersects(resource_size_t offset, size_t size, unsigned long flags,
unsigned long desc);
/* Support for virtually mapped pages */ /* Support for virtually mapped pages */
struct page *vmalloc_to_page(const void *addr); struct page *vmalloc_to_page(const void *addr);
......
...@@ -47,7 +47,7 @@ static void *try_ram_remap(resource_size_t offset, size_t size) ...@@ -47,7 +47,7 @@ static void *try_ram_remap(resource_size_t offset, size_t size)
* being mapped does not have i/o side effects and the __iomem * being mapped does not have i/o side effects and the __iomem
* annotation is not applicable. * annotation is not applicable.
* *
* MEMREMAP_WB - matches the default mapping for "System RAM" on * MEMREMAP_WB - matches the default mapping for System RAM on
* the architecture. This is usually a read-allocate write-back cache. * the architecture. This is usually a read-allocate write-back cache.
* Morever, if MEMREMAP_WB is specified and the requested remap region is RAM * Morever, if MEMREMAP_WB is specified and the requested remap region is RAM
* memremap() will bypass establishing a new mapping and instead return * memremap() will bypass establishing a new mapping and instead return
...@@ -56,11 +56,12 @@ static void *try_ram_remap(resource_size_t offset, size_t size) ...@@ -56,11 +56,12 @@ static void *try_ram_remap(resource_size_t offset, size_t size)
* MEMREMAP_WT - establish a mapping whereby writes either bypass the * MEMREMAP_WT - establish a mapping whereby writes either bypass the
* cache or are written through to memory and never exist in a * cache or are written through to memory and never exist in a
* cache-dirty state with respect to program visibility. Attempts to * cache-dirty state with respect to program visibility. Attempts to
* map "System RAM" with this mapping type will fail. * map System RAM with this mapping type will fail.
*/ */
void *memremap(resource_size_t offset, size_t size, unsigned long flags) void *memremap(resource_size_t offset, size_t size, unsigned long flags)
{ {
int is_ram = region_intersects(offset, size, "System RAM"); int is_ram = region_intersects(offset, size,
IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE);
void *addr = NULL; void *addr = NULL;
if (is_ram == REGION_MIXED) { if (is_ram == REGION_MIXED) {
...@@ -76,7 +77,7 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags) ...@@ -76,7 +77,7 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags)
* MEMREMAP_WB is special in that it can be satisifed * MEMREMAP_WB is special in that it can be satisifed
* from the direct map. Some archs depend on the * from the direct map. Some archs depend on the
* capability of memremap() to autodetect cases where * capability of memremap() to autodetect cases where
* the requested range is potentially in "System RAM" * the requested range is potentially in System RAM.
*/ */
if (is_ram == REGION_INTERSECTS) if (is_ram == REGION_INTERSECTS)
addr = try_ram_remap(offset, size); addr = try_ram_remap(offset, size);
...@@ -88,7 +89,7 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags) ...@@ -88,7 +89,7 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags)
* If we don't have a mapping yet and more request flags are * If we don't have a mapping yet and more request flags are
* pending then we will be attempting to establish a new virtual * pending then we will be attempting to establish a new virtual
* address mapping. Enforce that this mapping is not aliasing * address mapping. Enforce that this mapping is not aliasing
* "System RAM" * System RAM.
*/ */
if (!addr && is_ram == REGION_INTERSECTS && flags) { if (!addr && is_ram == REGION_INTERSECTS && flags) {
WARN_ONCE(1, "memremap attempted on ram %pa size: %#lx\n", WARN_ONCE(1, "memremap attempted on ram %pa size: %#lx\n",
...@@ -266,7 +267,7 @@ void *devm_memremap_pages(struct device *dev, struct resource *res, ...@@ -266,7 +267,7 @@ void *devm_memremap_pages(struct device *dev, struct resource *res,
struct percpu_ref *ref, struct vmem_altmap *altmap) struct percpu_ref *ref, struct vmem_altmap *altmap)
{ {
int is_ram = region_intersects(res->start, resource_size(res), int is_ram = region_intersects(res->start, resource_size(res),
"System RAM"); IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE);
resource_size_t key, align_start, align_size; resource_size_t key, align_start, align_size;
struct dev_pagemap *pgmap; struct dev_pagemap *pgmap;
struct page_map *page_map; struct page_map *page_map;
......
...@@ -496,31 +496,34 @@ EXPORT_SYMBOL_GPL(page_is_ram); ...@@ -496,31 +496,34 @@ EXPORT_SYMBOL_GPL(page_is_ram);
* region_intersects() - determine intersection of region with known resources * region_intersects() - determine intersection of region with known resources
* @start: region start address * @start: region start address
* @size: size of region * @size: size of region
* @name: name of resource (in iomem_resource) * @flags: flags of resource (in iomem_resource)
* @desc: descriptor of resource (in iomem_resource) or IORES_DESC_NONE
* *
* Check if the specified region partially overlaps or fully eclipses a * Check if the specified region partially overlaps or fully eclipses a
* resource identified by @name. Return REGION_DISJOINT if the region * resource identified by @flags and @desc (optional with IORES_DESC_NONE).
* does not overlap @name, return REGION_MIXED if the region overlaps * Return REGION_DISJOINT if the region does not overlap @flags/@desc,
* @type and another resource, and return REGION_INTERSECTS if the * return REGION_MIXED if the region overlaps @flags/@desc and another
* region overlaps @type and no other defined resource. Note, that * resource, and return REGION_INTERSECTS if the region overlaps @flags/@desc
* REGION_INTERSECTS is also returned in the case when the specified * and no other defined resource. Note that REGION_INTERSECTS is also
* region overlaps RAM and undefined memory holes. * returned in the case when the specified region overlaps RAM and undefined
* memory holes.
* *
* region_intersect() is used by memory remapping functions to ensure * region_intersect() is used by memory remapping functions to ensure
* the user is not remapping RAM and is a vast speed up over walking * the user is not remapping RAM and is a vast speed up over walking
* through the resource table page by page. * through the resource table page by page.
*/ */
int region_intersects(resource_size_t start, size_t size, const char *name) int region_intersects(resource_size_t start, size_t size, unsigned long flags,
unsigned long desc)
{ {
unsigned long flags = IORESOURCE_MEM | IORESOURCE_BUSY;
resource_size_t end = start + size - 1; resource_size_t end = start + size - 1;
int type = 0; int other = 0; int type = 0; int other = 0;
struct resource *p; struct resource *p;
read_lock(&resource_lock); read_lock(&resource_lock);
for (p = iomem_resource.child; p ; p = p->sibling) { for (p = iomem_resource.child; p ; p = p->sibling) {
bool is_type = strcmp(p->name, name) == 0 && bool is_type = (((p->flags & flags) == flags) &&
((p->flags & flags) == flags); ((desc == IORES_DESC_NONE) ||
(desc == p->desc)));
if (start >= p->start && start <= p->end) if (start >= p->start && start <= p->end)
is_type ? type++ : other++; is_type ? type++ : other++;
...@@ -539,6 +542,7 @@ int region_intersects(resource_size_t start, size_t size, const char *name) ...@@ -539,6 +542,7 @@ int region_intersects(resource_size_t start, size_t size, const char *name)
return REGION_DISJOINT; return REGION_DISJOINT;
} }
EXPORT_SYMBOL_GPL(region_intersects);
void __weak arch_remove_reservations(struct resource *avail) void __weak arch_remove_reservations(struct resource *avail)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册