@@ -121,6 +121,7 @@ mapping adds that mapping to the protection domain.
int pks_key_alloc(const char * const pkey_user);
#define PAGE_KERNEL_PKEY(pkey)
#define _PAGE_KEY(pkey)
+ void * vmalloc_pks(unsigned long size, int pkey);
void pks_mknoaccess(int pkey, bool global);
void pks_mkread(int pkey, bool global);
void pks_mkrdwr(int pkey, bool global);
@@ -138,6 +139,9 @@ Kernel users must set the PTE permissions in the page table entries for the
mappings they want to protect. This can be done with PAGE_KERNEL_PKEY() or
_PAGE_KEY().
+Alternatively, vmalloc_pks() is provided to allocate memory within the pkey
+domain specified.
+
The pks_mk*() family of calls allows kernel users the ability to change the
protections for the domain identified by the pkey specified. 3 states are
available pks_mknoaccess(), pks_mkread(), and pks_mkrdwr() which set the access
@@ -115,6 +115,7 @@ extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
const void *caller);
void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_mask,
int node, const void *caller);
+extern void *vmalloc_pks(unsigned long size, int pkey);
extern void vfree(const void *addr);
extern void vfree_atomic(const void *addr);
@@ -2589,6 +2589,34 @@ void *vmalloc(unsigned long size)
}
EXPORT_SYMBOL(vmalloc);
+/**
+ * vmalloc_pks - allocate virtually contiguous memory within the specified pkey
+ * domain
+ *
+ * @size: allocation size
+ * @pkey: the pkey domain to allocate the memory under
+ *
+ * Allocate enough pages to cover @size from the page level allocator and map
+ * them into contiguous kernel virtual space with the specific PKS protections
+ * if the architecture supports it.
+ *
+ * NOTE: This does not change the PKS settings established with other mappings
+ * such as the direct map.
+ *
+ * WARNING: Calling this with an invalid pkey is undefined.
+ *
+ * Return: pointer to the allocated memory or %NULL on error
+ */
+void *vmalloc_pks(unsigned long size, int pkey)
+{
+ void *ret = __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
+ GFP_KERNEL, PAGE_KERNEL_PKEY(pkey), 0,
+ NUMA_NO_NODE, __builtin_return_address(0));
+ vm_unmap_aliases();
+ return ret;
+}
+EXPORT_SYMBOL(vmalloc_pks);
+
/**
* vzalloc - allocate virtually contiguous memory with zero fill
* @size: allocation size