[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1562855138-19507-14-git-send-email-alexandre.chartre@oracle.com>
Date: Thu, 11 Jul 2019 16:25:25 +0200
From: Alexandre Chartre <alexandre.chartre@...cle.com>
To: pbonzini@...hat.com, rkrcmar@...hat.com, tglx@...utronix.de,
mingo@...hat.com, bp@...en8.de, hpa@...or.com,
dave.hansen@...ux.intel.com, luto@...nel.org, peterz@...radead.org,
kvm@...r.kernel.org, x86@...nel.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Cc: konrad.wilk@...cle.com, jan.setjeeilers@...cle.com,
liran.alon@...cle.com, jwadams@...gle.com, graf@...zon.de,
rppt@...ux.vnet.ibm.com, alexandre.chartre@...cle.com
Subject: [RFC v2 13/26] mm/asi: Add asi_remap() function
Add a function to remap an already mapped buffer with a new address
in an ASI page-table: the already mapped buffer is unmapped, and a
new mapping is added for the specified new address.
This is useful to track and remap a buffer which can be freed and
then reallocated.
Signed-off-by: Alexandre Chartre <alexandre.chartre@...cle.com>
---
arch/x86/include/asm/asi.h | 1 +
arch/x86/mm/asi_pagetable.c | 25 +++++++++++++++++++++++++
2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/arch/x86/include/asm/asi.h b/arch/x86/include/asm/asi.h
index 912b6a7..cf5d198 100644
--- a/arch/x86/include/asm/asi.h
+++ b/arch/x86/include/asm/asi.h
@@ -84,6 +84,7 @@ extern int asi_map_range(struct asi *asi, void *ptr, size_t size,
enum page_table_level level);
extern int asi_map(struct asi *asi, void *ptr, unsigned long size);
extern void asi_unmap(struct asi *asi, void *ptr);
+extern int asi_remap(struct asi *asi, void **mapping, void *ptr, size_t size);
/*
* Copy the memory mapping for the current module. This is defined as a
diff --git a/arch/x86/mm/asi_pagetable.c b/arch/x86/mm/asi_pagetable.c
index a4fe867..1ff0c47 100644
--- a/arch/x86/mm/asi_pagetable.c
+++ b/arch/x86/mm/asi_pagetable.c
@@ -842,3 +842,28 @@ int asi_map_percpu(struct asi *asi, void *percpu_ptr, size_t size)
return 0;
}
EXPORT_SYMBOL(asi_map_percpu);
+
+int asi_remap(struct asi *asi, void **current_ptrp, void *new_ptr, size_t size)
+{
+ void *current_ptr = *current_ptrp;
+ int err;
+
+ if (current_ptr == new_ptr) {
+ /* no change, already mapped */
+ return 0;
+ }
+
+ if (current_ptr) {
+ asi_unmap(asi, current_ptr);
+ *current_ptrp = NULL;
+ }
+
+ err = asi_map(asi, new_ptr, size);
+ if (err)
+ return err;
+
+ *current_ptrp = new_ptr;
+
+ return 0;
+}
+EXPORT_SYMBOL(asi_remap);
--
1.7.1
Powered by blists - more mailing lists