Hi Kazu,

Compatible with google android GKI changes,
SECTION_SIZE_BITS = 27 when defined 4K_PAGES or 16K_PAGES.
SECTION_SIZE_BITS = 29 when defined 64K_PAGES.

Link: https://lore.kernel.org/lkml/15cf9a2359197fee0168f820c5c904650d07939e.1610146597.git.sudaraja@codeaurora.org
Link: https://lore.kernel.org/all/43843c5e092bfe3ec4c41e3c8c78a7ee35b69bb0.1611206601.git.sudaraja@codeaurora.org

See: https://cs.android.com/android/_/android/kernel/common/+/673e9ab6b64f981159aeff3b65675bb7dbedecd8
Before android-12-gki:
    crash> help -m | grep section_size_bits
       section_size_bits: 30

The first PFN error, the physical address should be 0x40000000.
    crash> kmem -p
          PAGE        PHYSICAL      MAPPING       INDEX CNT FLAGS
    ffffffff06e00000 200000000 ffffff80edf4fa12 ffffffff070f3640  1 4000000000002000 private

After android-12-gki:
    crash> help -m | grep section
       section_size_bits: 27

    crash> kmem -p
          PAGE        PHYSICAL      MAPPING       INDEX CNT FLAGS
    fffffffeffe00000  40000000                0        0  1 1000 reserved

Signed-off-by: chenguanyou <chenguanyou@xiaomi.com>
---
 arm64.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arm64.c b/arm64.c
index e36c723..50e22ea 100644
--- a/arm64.c
+++ b/arm64.c
@@ -1629,7 +1629,16 @@ arm64_get_section_size_bits(void)
            if ((ret = get_kernel_config("CONFIG_HOTPLUG_SIZE_BITS", &string)) == IKCONFIG_STR)
                machdep->section_size_bits = atol(string);
        }
-   }
+
+       // arm64: reduce section size for sparsemem
+       if ((ret = get_kernel_config("CONFIG_ARM64_4K_PAGES", NULL)) == IKCONFIG_Y
+               || (ret = get_kernel_config("CONFIG_ARM64_16K_PAGES", NULL)) == IKCONFIG_Y)
+           machdep->section_size_bits = _SECTION_SIZE_BITS_5_12;
+       // arm64/sparsemem: reduce SECTION_SIZE_BITS
+       else if ((ret = get_kernel_config("CONFIG_ARM64_64K_PAGES", NULL)) == IKCONFIG_Y)
+           machdep->section_size_bits = _SECTION_SIZE_BITS_5_12_64K;
+
+    }

    if (CRASHDEBUG(1))
        fprintf(fp, "SECTION_SIZE_BITS: %ld\n", machdep->section_size_bits);
--
2.39.0

Thanks,
Guanyou.Chen