s390/uv: fix memblock virtual vs physical address confusion
authorHeiko Carstens <hca@linux.ibm.com>
Mon, 13 Dec 2021 18:16:38 +0000 (19:16 +0100)
committerHeiko Carstens <hca@linux.ibm.com>
Thu, 16 Dec 2021 18:58:07 +0000 (19:58 +0100)
memblock_alloc_try_nid() returns a virtual address, however in error
case the allocated memory is incorrectly freed with memblock_phys_free().
Properly use memblock_free() instead, and pass a physical address to
uv_init() to fix this.

Note: this doesn't fix a bug currently, since virtual and physical
addresses are identical.

Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/kernel/uv.c

index 386d4e42b8d361c95525602b9ec7dae64e6facf1..a5425075dd255d61ffc0353a72e62c512dec961d 100644 (file)
@@ -30,7 +30,7 @@ int __bootdata_preserved(prot_virt_host);
 EXPORT_SYMBOL(prot_virt_host);
 EXPORT_SYMBOL(uv_info);
 
-static int __init uv_init(unsigned long stor_base, unsigned long stor_len)
+static int __init uv_init(phys_addr_t stor_base, unsigned long stor_len)
 {
        struct uv_cb_init uvcb = {
                .header.cmd = UVC_CMD_INIT_UV,
@@ -49,12 +49,12 @@ static int __init uv_init(unsigned long stor_base, unsigned long stor_len)
 
 void __init setup_uv(void)
 {
-       unsigned long uv_stor_base;
+       void *uv_stor_base;
 
        if (!is_prot_virt_host())
                return;
 
-       uv_stor_base = (unsigned long)memblock_alloc_try_nid(
+       uv_stor_base = memblock_alloc_try_nid(
                uv_info.uv_base_stor_len, SZ_1M, SZ_2G,
                MEMBLOCK_ALLOC_ACCESSIBLE, NUMA_NO_NODE);
        if (!uv_stor_base) {
@@ -63,8 +63,8 @@ void __init setup_uv(void)
                goto fail;
        }
 
-       if (uv_init(uv_stor_base, uv_info.uv_base_stor_len)) {
-               memblock_phys_free(uv_stor_base, uv_info.uv_base_stor_len);
+       if (uv_init(__pa(uv_stor_base), uv_info.uv_base_stor_len)) {
+               memblock_free(uv_stor_base, uv_info.uv_base_stor_len);
                goto fail;
        }