anolis: mm: fix some memory interface kabi changes

ANBZ: #21081

The previous patch modified the `add_memory_resource` and
`add_memory_driver_managed` interfaces, causing some drivers to fail to
compile on ANCK.

This patch re-implements the relevant functions, and no longer modifies
the relevant interfaces while maintaining the original logic.

Fixes: 6276951a54 ("anolis: virtio-mem: restrict offline memmap on
movable in x86_64")
Signed-off-by: hr567 <hr567@linux.alibaba.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/5301
This commit is contained in:
hr567 2025-05-16 11:48:14 +08:00 committed by 小龙
parent 4aed4f7cf2
commit 6bec8a39b9
5 changed files with 14 additions and 13 deletions

View File

@ -130,7 +130,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax)
* this as RAM automatically.
*/
rc = add_memory_driver_managed(data->mgid, range.start,
range_len(&range), kmem_name, MHP_NID_IS_MGID, 0);
range_len(&range), kmem_name, MHP_NID_IS_MGID);
if (rc) {
dev_warn(dev, "mapping%d: %#llx-%#llx memory add failed\n",

View File

@ -613,7 +613,7 @@ static int virtio_mem_add_memory(struct virtio_mem *vm, uint64_t addr,
uint64_t size)
{
int rc;
mhp_t extra_flags = 0;
mhp_t mhp_flags = MHP_MERGE_RESOURCE | MHP_NID_IS_MGID;
/*
* When force-unloading the driver and we still have memory added to
@ -633,10 +633,10 @@ static int virtio_mem_add_memory(struct virtio_mem *vm, uint64_t addr,
#ifdef CONFIG_X86_64
/* only support memmap_on_memory on sbm scenario */
if (vm->in_sbm)
extra_flags |= MHP_MEMMAP_ON_MEMORY;
mhp_flags |= MHP_VM_IN_SMB;
#endif
rc = add_memory_driver_managed(vm->mgid, addr, size, vm->resource_name,
MHP_MERGE_RESOURCE | MHP_NID_IS_MGID, extra_flags);
mhp_flags);
if (rc) {
atomic64_sub(size, &vm->offline_size);
dev_warn(&vm->vdev->dev, "adding memory failed: %d\n", rc);

View File

@ -336,7 +336,7 @@ static enum bp_state reserve_additional_memory(void)
mutex_unlock(&balloon_mutex);
/* add_memory_resource() requires the device_hotplug lock */
lock_device_hotplug();
rc = add_memory_resource(nid, resource, MHP_MERGE_RESOURCE, 0);
rc = add_memory_resource(nid, resource, MHP_MERGE_RESOURCE);
unlock_device_hotplug();
mutex_lock(&balloon_mutex);

View File

@ -128,6 +128,8 @@ typedef int __bitwise mhp_t;
*/
#define MHP_NID_IS_MGID ((__force mhp_t)BIT(2))
#define MHP_VM_IN_SMB ((__force mhp_t)BIT(3))
/*
* Extended parameters for memory hotplug:
* altmap: alternative allocator for memmap array (optional)
@ -332,10 +334,10 @@ extern void __ref free_area_init_core_hotplug(struct pglist_data *pgdat);
extern int __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags);
extern int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags);
extern int add_memory_resource(int nid, struct resource *resource,
mhp_t mhp_flags, mhp_t extra_flags);
mhp_t mhp_flags);
extern int add_memory_driver_managed(int nid, u64 start, u64 size,
const char *resource_name,
mhp_t mhp_flags, mhp_t extra_flags);
mhp_t mhp_flags);
extern void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn,
unsigned long nr_pages,
struct vmem_altmap *altmap, int migratetype);

View File

@ -1303,8 +1303,7 @@ bool mhp_supports_memmap_on_memory(unsigned long size)
*
* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG
*/
int __ref add_memory_resource(int nid, struct resource *res,
mhp_t mhp_flags, mhp_t extra_flags)
int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags)
{
struct mhp_params params = { .pgprot = pgprot_mhp(PAGE_KERNEL) };
struct vmem_altmap mhp_altmap = {};
@ -1346,7 +1345,7 @@ int __ref add_memory_resource(int nid, struct resource *res,
* Self hosted memmap array
*/
if ((mhp_flags & MHP_MEMMAP_ON_MEMORY) ||
((extra_flags & MHP_MEMMAP_ON_MEMORY) &&
((mhp_flags & MHP_VM_IN_SMB) &&
mhp_memmap_on_memory())) {
if (!mhp_supports_memmap_on_memory(size)) {
ret = -EINVAL;
@ -1421,7 +1420,7 @@ int __ref __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags)
if (IS_ERR(res))
return PTR_ERR(res);
ret = add_memory_resource(nid, res, mhp_flags, 0);
ret = add_memory_resource(nid, res, mhp_flags);
if (ret < 0)
release_memory_resource(res);
return ret;
@ -1462,7 +1461,7 @@ EXPORT_SYMBOL_GPL(add_memory);
*/
int add_memory_driver_managed(int nid, u64 start, u64 size,
const char *resource_name,
mhp_t mhp_flags, mhp_t extra_flags)
mhp_t mhp_flags)
{
struct resource *res;
int rc;
@ -1480,7 +1479,7 @@ int add_memory_driver_managed(int nid, u64 start, u64 size,
goto out_unlock;
}
rc = add_memory_resource(nid, res, mhp_flags, extra_flags);
rc = add_memory_resource(nid, res, mhp_flags);
if (rc < 0)
release_memory_resource(res);