Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

malta: Support kernel 6.6 and fix kernel_bump.sh script #15215

Merged
merged 4 commits into from Apr 28, 2024

Conversation

guidosarducci
Copy link
Contributor

@guidosarducci guidosarducci commented Apr 20, 2024

Adding kernel 6.6 support for malta has been tested and pending for more over a month in PR #14891 , but merging appears to be stalled. I've added this PR to tackle possibly outstanding issues and hopefully encourage some progress.

Additional changes from #14891 include:

  1. Use scripts/kernel_bump.sh while adding malta 6.6 support to preserve history.
  2. Fix scripts/kernel_bump.sh to generate commit text with correct word-wrapping.

@robimarko @PolynomialDivision @Ansuel @hauke Please feel free to pull anything needed from here into #14891, or simply merge this as is, or comment on further changes needed. I deferred my own malta/6.6 update expecting #14891 would be merged quickly, and would like to move things along since having 6.6 support helps with my upstream kernel work.

@github-actions github-actions bot added build/scripts/tools pull request/issues for build, scripts and tools related changes kernel pull request/issue with Linux kernel related changes target/malta pull request/issue for malta target labels Apr 20, 2024
@namiltd namiltd mentioned this pull request Apr 20, 2024
42 tasks
@guidosarducci
Copy link
Contributor Author

Added commit to revert mips64 breakage due to c5dee97. See commit comments for more information.

@guidosarducci guidosarducci changed the title malta: Add kernel 6.6 support and fix kernel_bump.sh script malta: Add kernel 6.6 support, fix kernel_bump.sh script, revert mips64 breakage Apr 21, 2024
@guidosarducci guidosarducci changed the title malta: Add kernel 6.6 support, fix kernel_bump.sh script, revert mips64 breakage malta: Support kernel 6.6, fix kernel_bump.sh script, revert mips64 breakage Apr 21, 2024
guidosarducci referenced this pull request Apr 21, 2024
This patch fixes the broken detect_memory_region() function on
6.6 kernel.

Signed-off-by: Shiji Yang <yangshiji66@qq.com>
@robimarko
Copy link
Contributor

@guidosarducci Has the revert been tested not to break other targets?

@guidosarducci
Copy link
Contributor Author

guidosarducci commented Apr 21, 2024

@guidosarducci Has the revert been tested not to break other targets?

@robimarko I tested that both malta/mips32el and malta/mips64el work after the revert.

The original commit was part of #14774 (you asked about it too) and targets ramips but breaks all mips64 targets, and looks only compatible with 32-bit targets. I don't know ramips specifics so let's ask @DragonBluep for more details.

I would be fine with merging the malta update separately from dealing with this revert.

@PolynomialDivision
Copy link
Member

The mentioned patch also targets ath79 see #14880.

void __init detect_memory_region(phys_addr_t start, phys_addr_t sz_min, phys_addr_t sz_max)
{
- void *dm = &detect_magic;
+ void *dm = (void *)KSEG1ADDR(&detect_magic);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@namiltd Hi! Could you help test if changing this line to void *dm = &detect_magic; can work on your MT7620 device? I don't have Linux build environment recently.

Copy link
Contributor

@namiltd namiltd Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, after this change, RAM size detection does not work correctly:

              total        used        free      shared  buff/cache   available
Mem:         251372       21644      205884         232       23844      193116
Swap:             0           0           0

instead of:

              total        used        free      shared  buff/cache   available
Mem:          56636       20804       11224         232       24608       11856
Swap:             0           0           0

This router only has 64MB RAM, but it incorrectly detects 256MB.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the patch so complicated to begin with and lack a description of how/why it should work? Why does it write when the original code doesn't?

@namiltd Maybe try replacing the whole patch with something simpler:

--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -103,7 +103,7 @@
        phys_addr_t size;

        for (size = sz_min; size < sz_max; size <<= 1) {
-               if (!memcmp(dm, dm + size, sizeof(detect_magic)))
+               if (*(long *)(dm) != *(volatile long __force *)(dm + size))
                        break;
        }

This at least compiles on 32-bit and 64-bit mips malta...

Copy link
Contributor

@namiltd namiltd Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch (https://github.com/openwrt/openwrt/blob/main/target/linux/generic/pending-6.6/350-mips-kernel-fix-detect_memory_region-function.patch) was not caused by compilation errors, but because the router stopped during startup and displayed the following message:

[    0.000000] Linux 6.6.20 (builder@buildhost) (mipsel-openwrt-linux-musl-gcc (OpenWrt GCC 12.3.0 r25430-eb44f39e39) 12.3.0, GNU ld (GNU Binutils) 2.40.0) Mar 6 11:40:57 2024
[    0.000000] Board has DDR2
[    0.000000] Analog PMU set to hw control
[    0.000000] Digital PMU set to hw control
[    0.000000] SoC Type: MediaTek MT7620A ver:2 eco:6
[    0.000000] printk: bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 00019650 (MIPS 24KEc)
[    0.000000] MIPS: machine is TP-Link Archer C5 v4
[    0.000000] detected buffer overflow in memcmp

@guidosarducci
Copy link
Contributor Author

The mentioned patch also targets ath79 see #14880.

@PolynomialDivision Yes, I'm aware. The upstream Linux patch history showed the reverted code was borrowed from existing ath79 implementation in 4d9f77d25268 ("MIPS: add detect_memory_region()") by @blogic . That doesn't really change anything however: the commit is still written for 32-bit only and thus wasn't well-tested, hasn't been reviewed upstream, and breaks mips64.

I assumed reverting this would be straightforward given the above but apparently not. Since I intended this PR to push along the stalled malta kernel 6.6 support rather than tangential development, maybe it's better to drop the revert and let any further testing/development continue in the original commit/PR by the folks involved.

@namiltd
Copy link
Contributor

namiltd commented Apr 23, 2024

350-mips-kernel-fix-detect_memory_region-function.patch
@guidosarducci I think the easiest way was to modify this patch (https://github.com/openwrt/openwrt/blob/main/target/linux/generic/pending-6.6/350-mips-kernel-fix-detect_memory_region-function.patch) by detecting whether 32 or 64 bits and implementing them differently.

e.g.:

#ifdef CONFIG_CPU_MIPS64
static void *detect_magic __initdata = detect_memory_region;
#else
static u32 detect_magic __initdata;
#define MIPS_MEM_TEST_PATTERN		0xaa5555aa
#endif

#ifdef CONFIG_MIPS_AUTO_PFN_OFFSET
unsigned long ARCH_PFN_OFFSET;
EXPORT_SYMBOL(ARCH_PFN_OFFSET);
#endif

void __init detect_memory_region(phys_addr_t start, phys_addr_t sz_min, phys_addr_t sz_max)
{
	phys_addr_t size;
#ifdef CONFIG_CPU_MIPS64
	void *dm = &detect_magic;

	for (size = sz_min; size < sz_max; size <<= 1) {
		if (!memcmp(dm, dm + size, sizeof(detect_magic)))
			break;
	}
#else
	void* dm = (void *)KSEG1ADDR(&detect_magic); 

	for (size = sz_min; size < sz_max; size <<= 1) {
		__raw_writel(MIPS_MEM_TEST_PATTERN, dm);
		if (__raw_readl(dm) == __raw_readl(dm + size)) {
			__raw_writel(~MIPS_MEM_TEST_PATTERN, dm);
			if (__raw_readl(dm) == __raw_readl(dm + size))
				break;
		}
	}
#endif

	pr_debug("Memory: %lluMB of RAM detected at 0x%llx (min: %lluMB, max: %lluMB)\n",
		((unsigned long long) size) / SZ_1M,
		(unsigned long long) start,
		((unsigned long long) sz_min) / SZ_1M,
		((unsigned long long) sz_max) / SZ_1M);

	memblock_add(start, size);
}

New 350-mips-kernel-fix-detect_memory_region-function.patch

@guidosarducci
Copy link
Contributor Author

@namiltd That seems very kludgy and it's difficult to see it being accepted upstream. The minimal patch I posted above has the original detect_memory_region() function behaviour but bypasses memcmp() by doing the equivalent of __raw_readl(). It also doesn't need any detection since sizeof(long) == sizeof(void *).

Could you try it on your device if you have a chance? i.e. just replace 350-mips-kernel-fix-detect_memory_region-function.patch with:

--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -103,7 +103,7 @@
        phys_addr_t size;

        for (size = sz_min; size < sz_max; size <<= 1) {
-               if (!memcmp(dm, dm + size, sizeof(detect_magic)))
+               if (*(long *)(dm) != *(volatile long __force *)(dm + size))
                        break;
        }

@DragonBluep Are you able to ping/bump your patch on the linux-mips mailing list to ask for advice?

@guidosarducci guidosarducci changed the title malta: Support kernel 6.6, fix kernel_bump.sh script, revert mips64 breakage malta: Support kernel 6.6 and fix kernel_bump.sh script Apr 24, 2024
@guidosarducci
Copy link
Contributor Author

I've dropped the revert of c5dee97 as mentioned in #15215 (comment). That can be dealt with separately/in the the original PR.

@PolynomialDivision @robimarko @hauke It should be OK to merge this or incorporate needed changes into #14891, if you'd care to have a look. Thanks...

@namiltd
Copy link
Contributor

namiltd commented Apr 24, 2024

@namiltd That seems very kludgy and it's difficult to see it being accepted upstream. The minimal patch I posted above has the original detect_memory_region() function behaviour but bypasses memcmp() by doing the equivalent of __raw_readl(). It also doesn't need any detection since sizeof(long) == sizeof(void *).

Could you try it on your device if you have a chance? i.e. just replace 350-mips-kernel-fix-detect_memory_region-function.patch with:

--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -103,7 +103,7 @@
        phys_addr_t size;

        for (size = sz_min; size < sz_max; size <<= 1) {
-               if (!memcmp(dm, dm + size, sizeof(detect_magic)))
+               if (*(long *)(dm) != *(volatile long __force *)(dm + size))
                        break;
        }

@guidosarducci I don't have physical access to the mt7620 router for the next two weeks, so I won't test it.

I took the risk of updating remotely and unfortunately the router did not get up after the update. That's all I can say without having physical access to it. On site, the network was connected to another router and I will restore it to the previous version at a later date.

@guidosarducci
Copy link
Contributor Author

@guidosarducci I don't have physical access to the mt7620 router for the next two weeks, so I won't test it.

I took the risk of updating remotely and unfortunately the router did not get up after the update. That's all I can say without having physical access to it. On site, the network was connected to another router and I will restore it to the previous version at a later date.

@namiltd Would you clarify if it was a "regular" update that failed to boot, or one with the last patch I posted? Timing of your post and then edit was a little confusing...

@DragonBluep
Copy link
Contributor

@namiltd @guidosarducci A workaround for mips64 ARCH:
0001-generic-MIPS64-fix-detect_memory_region-compilation-.patch

guidosarducci and others added 4 commits April 29, 2024 00:24
Text of a commit message body should wrap at 75 characters. Manual commits
are expected to do so, but automated commits *must* do so to avoid adding
repeated ugly commits.

Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
This is an automatically generated commit.

When doing `git bisect`, consider `git bisect --skip`.

Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
This is an automatically generated commit which aids following Kernel patch
history, as git will see the move and copy as a rename thus defeating the
purpose.

For the original discussion see:
https://lists.openwrt.org/pipermail/openwrt-devel/2023-October/041673.html

Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
This refreshes the configuration on top of kernel 6.6 and activates it
as test kernel configuration.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
@openwrt-bot openwrt-bot merged commit a638d01 into openwrt:main Apr 28, 2024
3 checks passed
@hauke
Copy link
Member

hauke commented Apr 28, 2024

Thank you for taking car of this PR and sorry for the delay.
@DragonBluep Could you please create a separate PR with the fix.

@guidosarducci guidosarducci deleted the master-add-malta-6.6 branch April 29, 2024 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build/scripts/tools pull request/issues for build, scripts and tools related changes kernel pull request/issue with Linux kernel related changes target/malta pull request/issue for malta target
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants