Export memory policy related symbols needed by the KVM guest-memfd to
implement NUMA policy support.
These symbols are required to implement per-memory region NUMA policies
for guest memory, allowing VMMs to control guest memory placement across
NUMA nodes.
Signed-off-by: Shivank Garg <shivankg@amd.com>
---
mm/mempolicy.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index bbaadbeeb291..9c15780cfa63 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -214,6 +214,7 @@ struct mempolicy *get_task_policy(struct task_struct *p)
return &default_policy;
}
+EXPORT_SYMBOL(get_task_policy);
static const struct mempolicy_operations {
int (*create)(struct mempolicy *pol, const nodemask_t *nodes);
@@ -347,6 +348,7 @@ void __mpol_put(struct mempolicy *pol)
return;
kmem_cache_free(policy_cache, pol);
}
+EXPORT_SYMBOL(__mpol_put);
static void mpol_rebind_default(struct mempolicy *pol, const nodemask_t *nodes)
{
@@ -2736,6 +2738,7 @@ struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
read_unlock(&sp->lock);
return pol;
}
+EXPORT_SYMBOL(mpol_shared_policy_lookup);
static void sp_free(struct sp_node *n)
{
@@ -3021,6 +3024,7 @@ void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol)
mpol_put(mpol); /* drop our incoming ref on sb mpol */
}
}
+EXPORT_SYMBOL(mpol_shared_policy_init);
int mpol_set_shared_policy(struct shared_policy *sp,
struct vm_area_struct *vma, struct mempolicy *pol)
@@ -3039,6 +3043,7 @@ int mpol_set_shared_policy(struct shared_policy *sp,
sp_free(new);
return err;
}
+EXPORT_SYMBOL(mpol_set_shared_policy);
/* Free a backing policy store on inode delete. */
void mpol_free_shared_policy(struct shared_policy *sp)
@@ -3057,6 +3062,7 @@ void mpol_free_shared_policy(struct shared_policy *sp)
}
write_unlock(&sp->lock);
}
+EXPORT_SYMBOL(mpol_free_shared_policy);
#ifdef CONFIG_NUMA_BALANCING
static int __initdata numabalancing_override;
--
2.34.1
On 2/10/25 07:32, Shivank Garg wrote:
> Export memory policy related symbols needed by the KVM guest-memfd to
> implement NUMA policy support.
>
> These symbols are required to implement per-memory region NUMA policies
> for guest memory, allowing VMMs to control guest memory placement across
> NUMA nodes.
>
> Signed-off-by: Shivank Garg <shivankg@amd.com>
I think we should use EXPORT_SYMBOL_GPL() these days.
Wasn't there also some way to limit the exports to KVM?
> ---
> mm/mempolicy.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index bbaadbeeb291..9c15780cfa63 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -214,6 +214,7 @@ struct mempolicy *get_task_policy(struct task_struct *p)
>
> return &default_policy;
> }
> +EXPORT_SYMBOL(get_task_policy);
>
> static const struct mempolicy_operations {
> int (*create)(struct mempolicy *pol, const nodemask_t *nodes);
> @@ -347,6 +348,7 @@ void __mpol_put(struct mempolicy *pol)
> return;
> kmem_cache_free(policy_cache, pol);
> }
> +EXPORT_SYMBOL(__mpol_put);
>
> static void mpol_rebind_default(struct mempolicy *pol, const nodemask_t *nodes)
> {
> @@ -2736,6 +2738,7 @@ struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
> read_unlock(&sp->lock);
> return pol;
> }
> +EXPORT_SYMBOL(mpol_shared_policy_lookup);
>
> static void sp_free(struct sp_node *n)
> {
> @@ -3021,6 +3024,7 @@ void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol)
> mpol_put(mpol); /* drop our incoming ref on sb mpol */
> }
> }
> +EXPORT_SYMBOL(mpol_shared_policy_init);
>
> int mpol_set_shared_policy(struct shared_policy *sp,
> struct vm_area_struct *vma, struct mempolicy *pol)
> @@ -3039,6 +3043,7 @@ int mpol_set_shared_policy(struct shared_policy *sp,
> sp_free(new);
> return err;
> }
> +EXPORT_SYMBOL(mpol_set_shared_policy);
>
> /* Free a backing policy store on inode delete. */
> void mpol_free_shared_policy(struct shared_policy *sp)
> @@ -3057,6 +3062,7 @@ void mpol_free_shared_policy(struct shared_policy *sp)
> }
> write_unlock(&sp->lock);
> }
> +EXPORT_SYMBOL(mpol_free_shared_policy);
>
> #ifdef CONFIG_NUMA_BALANCING
> static int __initdata numabalancing_override;
On Mon, Feb 17, 2025, Vlastimil Babka wrote: > On 2/10/25 07:32, Shivank Garg wrote: > > Export memory policy related symbols needed by the KVM guest-memfd to > > implement NUMA policy support. > > > > These symbols are required to implement per-memory region NUMA policies > > for guest memory, allowing VMMs to control guest memory placement across > > NUMA nodes. > > > > Signed-off-by: Shivank Garg <shivankg@amd.com> > > I think we should use EXPORT_SYMBOL_GPL() these days. > > Wasn't there also some way to limit the exports to KVM? The infrastructure is still a WIP[1], though when that lands, I definitely plan on tightening down the KVM-induced exports[2]. [1] https://lore.kernel.org/all/20241202145946.108093528@infradead.org [2] https://lore.kernel.org/all/ZzJOoFFPjrzYzKir@google.com
On 2/18/2025 8:52 PM, Sean Christopherson wrote: > On Mon, Feb 17, 2025, Vlastimil Babka wrote: >> On 2/10/25 07:32, Shivank Garg wrote: >>> Export memory policy related symbols needed by the KVM guest-memfd to >>> implement NUMA policy support. >>> >>> These symbols are required to implement per-memory region NUMA policies >>> for guest memory, allowing VMMs to control guest memory placement across >>> NUMA nodes. >>> >>> Signed-off-by: Shivank Garg <shivankg@amd.com> >> >> I think we should use EXPORT_SYMBOL_GPL() these days. Thanks Vlastimil, will use EXPORT_SYMBOL_GPL. >> >> Wasn't there also some way to limit the exports to KVM? > > The infrastructure is still a WIP[1], though when that lands, I definitely plan > on tightening down the KVM-induced exports[2]. > > [1] https://lore.kernel.org/all/20241202145946.108093528@infradead.org > [2] https://lore.kernel.org/all/ZzJOoFFPjrzYzKir@google.com
On 10.02.25 07:32, Shivank Garg wrote: > Export memory policy related symbols needed by the KVM guest-memfd to > implement NUMA policy support. > > These symbols are required to implement per-memory region NUMA policies > for guest memory, allowing VMMs to control guest memory placement across > NUMA nodes. Probably worth mentioning something like "guest_memfd wants to implement support for NUMA policies just like shmem already does using the shared policy infrastructure. As guest_memfd currently resides in KVM module code, we have to export the relevant symbols. In the future, guest_memfd might be moved to core-mm, at which point the symbols no longer would have to be exported. When/if that happens is still unclear." Acked-by: David Hildenbrand <david@redhat.com> -- Cheers, David / dhildenb
On 2/12/2025 3:53 PM, David Hildenbrand wrote: > On 10.02.25 07:32, Shivank Garg wrote: >> Export memory policy related symbols needed by the KVM guest-memfd to >> implement NUMA policy support. >> >> These symbols are required to implement per-memory region NUMA policies >> for guest memory, allowing VMMs to control guest memory placement across >> NUMA nodes. > > Probably worth mentioning something like > > "guest_memfd wants to implement support for NUMA policies just like shmem already does using the shared policy infrastructure. As guest_memfd currently resides in KVM module code, we have to export the relevant symbols. > > In the future, guest_memfd might be moved to core-mm, at which point the symbols no longer would have to be exported. When/if that happens is still unclear." > > Acked-by: David Hildenbrand <david@redhat.com> > Thanks for the suggestion. I'll add it. Best Regards, Shivank
© 2016 - 2026 Red Hat, Inc.