[Crash-utility] 答复: [External Mail]Re: [PATCH v2] arm64: fix regression for the determination of section_size_bits

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Hi qiwu, tao

I made adjustments based on qiwu's patch.

qiwu and tao, is this attached patch OK ?


发件人: Tao Liu <ltao@xxxxxxxxxx>
发送时间: 2024年8月1日 7:35:50
收件人: qiwu.chen@xxxxxxxxxxxxx
抄送: devel@xxxxxxxxxxxxxxxxxxxxxxxxxxx
主题: [External Mail][Crash-utility] Re: [PATCH v2] arm64: fix regression for the determination of section_size_bits
 
[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xxxxxxxxxx进行反馈

Hi qiwu,

On Wed, Jul 31, 2024 at 9:21 PM <qiwu.chen@xxxxxxxxxxxxx> wrote:
>
> The commit 568c6f04 will cause a regression issue for the determination of
> section_size_bits on kernel version before android12-5.10 or Linux-v5.12.
> The section_size_bits is supposed to be compatible with linux upstream and
> android GKI version:
> Before android12-5.10 or Linux-v5.12:
>         SECTION_SIZE_BITS = 30
>
> After android12-5.10 or Linux-v5.12:
>     SECTION_SIZE_BITS = 27 when defined 4K_PAGES or 16K_PAGES.
>     SECTION_SIZE_BITS = 29 when defined 64K_PAGES.
>
> Introduce arm64_get_andriod_gki_version() to get Andriod GKI version by ut->release.
> The Andriod GKI version is determined either by arm64_get_andriod_gki_version()
> or the kernel config "CONFIG_ANDROID_KABI_RESERVE".
>
> Fixes: 568c6f04 ("arm64: section_size_bits compatible with macro definitions")
> Signed-off-by: qiwu.chen <qiwu.chen@xxxxxxxxxxxxx>
> ---
>  arm64.c | 68 ++++++++++++++++++++++++++++++++++++++++++---------------
>  1 file changed, 51 insertions(+), 17 deletions(-)
>
> diff --git a/arm64.c b/arm64.c
> index 78e6609..679f2ab 100644
> --- a/arm64.c
> +++ b/arm64.c
> @@ -95,6 +95,13 @@ static void arm64_calc_KERNELPACMASK(void);
>  static void arm64_recalc_KERNELPACMASK(void);
>  static int arm64_get_vmcoreinfo(unsigned long *vaddr, const char *label, int base);
>
> +/* Andriod GKI version definition */
> +struct andriod_gki_version {
> +       int kernel_version;
> +       int kernel_patch_level;
> +       int android_version;
> +};
> +
>  struct kernel_range {
>         unsigned long modules_vaddr, modules_end;
>         unsigned long vmalloc_start_addr, vmalloc_end;
> @@ -1615,6 +1622,30 @@ arm64_calc_phys_offset(void)
>                 fprintf(fp, "using %lx as phys_offset\n", ms->phys_offset);
>  }
>
> +/*
> + * Determine Andriod GKI vmcore by reading "android" from ut->release.
> + * The prefix of Andriod GKI release version is:
> + *     Kernel Version - Android release version
> + * For example:
> + *     5.10.209-android12, 5.15.148-android13
> + */
> +static bool arm64_get_andriod_gki_version(struct andriod_gki_version *version)
> +{
> +       char *p;
> +       struct new_utsname *uts = &kt->utsname;
> +
> +       if ((p = strstr(uts->release, "android"))) {
> +               sscanf(uts->release, "%d.%d", &version->kernel_version, &version->kernel_patch_level);
> +               sscanf(p, "android%d", &version->android_version);
> +               if (CRASHDEBUG(1))
> +                       fprintf(fp, "andriod_gki_version: andriod%d-%d.%d\n",
> +                           version->android_version, version->kernel_version, version->kernel_patch_level);

I think the version output as "5.10.209-android12, 5.15.148-android13"
would be better, so the format will stay consistent. Other than that,
the patch looks good to me. Let's wait to see if @lianbo likes the
extra code for android version parsing.

 Thanks,
Tao Liu

> +               return true;
> +       }
> +
> +       return false;
> +}
> +
>  /*
>   *  Determine SECTION_SIZE_BITS either by reading VMCOREINFO or the kernel
>   *  config, otherwise use the 64-bit ARM default definiton.
> @@ -1624,8 +1655,17 @@ arm64_get_section_size_bits(void)
>  {
>         int ret;
>         char *string;
> +       bool is_ikconfig_avail;
> +       struct andriod_gki_version ver = {0};
>
> -       if (THIS_KERNEL_VERSION >= LINUX(5,12,0)) {
> +       if (arm64_get_vmcoreinfo(&machdep->section_size_bits, "NUMBER(SECTION_SIZE_BITS)", NUM_DEC))
> +               goto exit;
> +
> +       is_ikconfig_avail = kt->ikconfig_flags & IKCONFIG_AVAIL ? TRUE : FALSE;
> +       /* The commit reduce section size for arm64 sparsemem is introduced since linux-v5.12 and android-12-5.10 */
> +       if (THIS_KERNEL_VERSION >= LINUX(5,12,0) ||
> +           (is_ikconfig_avail && get_kernel_config("CONFIG_ANDROID_KABI_RESERVE", NULL) == IKCONFIG_Y) ||
> +           (arm64_get_andriod_gki_version(&ver) && (ver.kernel_version * 100 + ver.kernel_patch_level >= 510) && ver.android_version >= 12)) {
>                 if (machdep->pagesize == 65536)
>                         machdep->section_size_bits = _SECTION_SIZE_BITS_5_12_64K;
>                 else
> @@ -1633,24 +1673,18 @@ arm64_get_section_size_bits(void)
>         } else
>                 machdep->section_size_bits = _SECTION_SIZE_BITS;
>
> -       if (arm64_get_vmcoreinfo(&machdep->section_size_bits, "NUMBER(SECTION_SIZE_BITS)", NUM_DEC)) {
> -               /* nothing */
> -       } else if (kt->ikconfig_flags & IKCONFIG_AVAIL) {
> -               if ((ret = get_kernel_config("CONFIG_MEMORY_HOTPLUG", NULL)) == IKCONFIG_Y) {
> -                       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;
> -               else if ((ret = get_kernel_config("CONFIG_ARM64_64K_PAGES", NULL)) == IKCONFIG_Y)
> -                       machdep->section_size_bits = _SECTION_SIZE_BITS_5_12_64K;
> +       /* section_size_bits for arm64 vendor special case */
> +       if (is_ikconfig_avail && get_kernel_config("CONFIG_MEMORY_HOTPLUG", NULL) == IKCONFIG_Y) {
> +               if (get_kernel_config("CONFIG_HOTPLUG_SIZE_BITS", &string) == IKCONFIG_STR)
> +                       machdep->section_size_bits = atol(string);
>         }
>
> -       if (CRASHDEBUG(1))
> -               fprintf(fp, "SECTION_SIZE_BITS: %ld\n", machdep->section_size_bits);
> +exit:
> +       if (machdep->section_size_bits) {
> +               if (CRASHDEBUG(1))
> +                       fprintf(fp, "SECTION_SIZE_BITS: %ld\n", machdep->section_size_bits);
> +       } else
> +               error(FATAL, "cannot determine SECTION_SIZE_BITS\n");
>  }
>
>  /*
> --
> 2.25.1
> --
> Crash-utility mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxxxxxx
> To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxxxxxx
> https://${domain_name}/admin/lists/devel.lists.crash-utility.osci.io/
> Contribution Guidelines: https://github.com/crash-utility/crash/wiki
--
Crash-utility mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxxxxxx
https://${domain_name}/admin/lists/devel.lists.crash-utility.osci.io/
Contribution Guidelines: https://github.com/crash-utility/crash/wiki
#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
From 8515b0c616d782faababae933ee637e843c7f197 Mon Sep 17 00:00:00 2001
From: chenguanyou <chenguanyou@xxxxxxxxxx>
Date: Thu, 8 Aug 2024 17:35:07 +0800
Subject: [PATCH] Fix: arm64: section_size_bits compatible with macro
 definitions

The commit 568c6f04 will cause a regression issue for the determination of
section_size_bits on kernel version before android12-5.10 or Linux-v5.12.
The section_size_bits is supposed to be compatible with linux upstream and
android GKI version:
Before android12-5.10 or Linux-v5.12:
        SECTION_SIZE_BITS = 30

After android12-5.10 or Linux-v5.12:
    SECTION_SIZE_BITS = 27 when defined 4K_PAGES or 16K_PAGES.
    SECTION_SIZE_BITS = 29 when defined 64K_PAGES.

Fixes: 568c6f04 ("arm64: section_size_bits compatible with macro definitions")
Change-Id: Ib6ec610753aabb52dfbafab65e1e6c04cbe65f72
Signed-off-by: qiwu.chen <qiwu.chen@xxxxxxxxxxxxx>
Signed-off-by: chenguanyou <chenguanyou@xxxxxxxxxx>
---
 arm64.c       | 22 ++++++++++------------
 defs.h        | 10 ++++++++++
 global_data.c |  7 +++++++
 kernel.c      | 23 +++++++++++++++++++++++
 4 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/arm64.c b/arm64.c
index 8ed1aaf..f0721b7 100644
--- a/arm64.c
+++ b/arm64.c
@@ -1667,30 +1667,28 @@ arm64_get_section_size_bits(void)
 	int ret;
 	char *string;
 
-	if (THIS_KERNEL_VERSION >= LINUX(5,12,0)) {
+	if (arm64_get_vmcoreinfo(&machdep->section_size_bits, "NUMBER(SECTION_SIZE_BITS)", NUM_DEC))
+		goto exit;
+
+	if (THIS_KERNEL_VERSION >= LINUX(5,12,0)
+			|| (IS_ANDROID_KERNEL_REL
+				&& THIS_KERNEL_VERSION >= LINUX(5,10,0)
+				&& THIS_ANDROID_VERSION >= ANDROID(12,0)))
 		if (machdep->pagesize == 65536)
 			machdep->section_size_bits = _SECTION_SIZE_BITS_5_12_64K;
 		else
 			machdep->section_size_bits = _SECTION_SIZE_BITS_5_12;
-	} else
+	else
 		machdep->section_size_bits = _SECTION_SIZE_BITS;
 
-	if (arm64_get_vmcoreinfo(&machdep->section_size_bits, "NUMBER(SECTION_SIZE_BITS)", NUM_DEC)) {
-		/* nothing */
-	} else if (kt->ikconfig_flags & IKCONFIG_AVAIL) {
+	if (kt->ikconfig_flags & IKCONFIG_AVAIL) {
 		if ((ret = get_kernel_config("CONFIG_MEMORY_HOTPLUG", NULL)) == IKCONFIG_Y) {
 			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;
-		else if ((ret = get_kernel_config("CONFIG_ARM64_64K_PAGES", NULL)) == IKCONFIG_Y)
-			machdep->section_size_bits = _SECTION_SIZE_BITS_5_12_64K;
 	}
 
+exit:
 	if (CRASHDEBUG(1))
 		fprintf(fp, "SECTION_SIZE_BITS: %ld\n", machdep->section_size_bits);
 }
diff --git a/defs.h b/defs.h
index 1b7649d..b0d3f8f 100644
--- a/defs.h
+++ b/defs.h
@@ -829,6 +829,15 @@ struct kernel_table {                   /* kernel data */
 #define IS_KERNEL_STATIC_TEXT(x) (((ulong)(x) >= kt->stext) && \
 		  	          ((ulong)(x) < kt->etext))
 
+#define THIS_KERNEL_RELEASE (kt->utsname.release)
+
+struct android_table {
+	uint android_version[2];
+};
+#define IS_ANDROID_KERNEL_REL (at->android_version[0] > 0)
+#define THIS_ANDROID_VERSION ((at->android_version[0] << 16) + (at->android_version[1]))
+#define ANDROID(x,y) (((uint)(x) << 16) + (uint)(y))
+
 #define TASK_COMM_LEN 16     /* task command name length including NULL */
 
 struct task_context {                     /* context stored for each task */
@@ -5353,6 +5362,7 @@ extern struct vm_table vm_table, *vt;
 extern struct machdep_table *machdep;
 extern struct symbol_table_data symbol_table_data, *st;
 extern struct extension_table *extension_table;
+extern struct android_table android_table, *at;
 
 /*
  *  Generated in build_data.c
diff --git a/global_data.c b/global_data.c
index f9bb7d0..dddde96 100644
--- a/global_data.c
+++ b/global_data.c
@@ -55,6 +55,13 @@ struct symbol_table_data *st = &symbol_table_data;
 struct machdep_table machdep_table = { 0 };
 struct machdep_table *machdep = &machdep_table;
 
+/*
+ *  The same thing goes for accesses to the frequently-accessed android_table,
+ *  making the "at" pointers globally available.
+ */
+struct android_table android_table = { 0, 0 };
+struct android_table *at = &android_table;
+
 /*
  *  Command functions are entered with the args[] array and argcnt value 
  *  pre-set for issuance to getopt().
diff --git a/kernel.c b/kernel.c
index adb19ad..814418c 100644
--- a/kernel.c
+++ b/kernel.c
@@ -104,6 +104,26 @@ static void check_vmcoreinfo(void);
 static int is_pvops_xen(void);
 static int get_linux_banner_from_vmlinux(char *, size_t);
 
+/*
+ * Determine Andriod GKI vmcore by reading "android" from ut->release.
+ * The prefix of Andriod GKI release version is:
+ *     Kernel Version - Android release version
+ * For example:
+ *     5.10.209-android12, 5.10.209-android12.1, 5.15.148-android13
+ */
+void
+parse_android_table(void)
+{
+    char *p;
+    if ((p = strstr(THIS_KERNEL_RELEASE, "android"))) {
+        sscanf(p, "android%d.%d", &at->android_version[0], &at->android_version[1]);
+
+        if (CRASHDEBUG(1))
+            fprintf(fp, "andriod_version: andriod-%d.%d\n",
+                    at->android_version[0], at->android_version[1]);
+    }
+}
+
 /*
  * popuplate the global kernel table (kt) with kernel version
  * information parsed from UTSNAME/OSRELEASE string
@@ -298,6 +318,9 @@ kernel_init()
 			kt->utsname.domainname : "(not printable)");
 	}
 
+	// non-upstream rel
+	parse_android_table();
+
 	strncpy(buf, kt->utsname.release, 65);
 	if (buf[64])
 		buf[64] = NULLCHAR;
-- 
2.39.0

--
Crash-utility mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxxxxxx
https://${domain_name}/admin/lists/devel.lists.crash-utility.osci.io/
Contribution Guidelines: https://github.com/crash-utility/crash/wiki

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux