@@ -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
@@ -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);
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@oracle.com> --- arch/x86/include/asm/asi.h | 1 + arch/x86/mm/asi_pagetable.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-)