[PATCH v2] ARM: imx: W+X ocram page in imx6q

Xavi Drudis Ferran xdrudis at tinet.cat
Tue Sep 22 08:02:07 EDT 2020


El Tue, Sep 22, 2020 at 03:15:38PM +0800, Shawn Guo deia:
> I tested it on my imx6q-sabresd board with v5.9-rc6 kernel, and
> suspend/resume still works with your patch applied.
>

Thank you very much.

> There is a build warning with your patch though.
>

Silly me. I'm sorry about that. This new version removes the warning.

I've tested on linux-libre-5.8.10 on a wandboard quad (imx6q) and it
works the same with or without the patch.  Hibernate gives a runtine
warning less in 5.8.10 than 5.8.9 (both with or without patch), but
suspend still fails to resume the eth phy (both with or without the patch).

 
imx6q: Mark the SRAM page for resume code read-only,executable (once written)

The code used for resume after suspend in imx6 is copied to a SRAM
on chip, so that it stays in the CPU chip while the system is
partially powered down.  The page mapping that SRAM was marked as
RW+X, which gave a warning when CONFIG_DEBUG_WX=y. Mark it
read-only and executable once the writting from kernel text is done
to get rid of the warning and prevent possible exploitation.

Signed-off-by: Xavier Drudis Ferran <xdrudis at tinet.cat>

diff --git a/arch/arm/mach-imx/pm-imx6.c b/arch/arm/mach-imx/pm-imx6.c
index 40c74b4c4..8baa1307f 100644
--- a/arch/arm/mach-imx/pm-imx6.c
+++ b/arch/arm/mach-imx/pm-imx6.c
@@ -16,6 +16,7 @@
 #include <linux/of_platform.h>
 #include <linux/regmap.h>
 #include <linux/suspend.h>
+#include <linux/set_memory.h>
 #include <asm/cacheflush.h>
 #include <asm/fncpy.h>
 #include <asm/proc-fns.h>
@@ -570,6 +571,13 @@ static int __init imx6q_suspend_init(const struct imx6_pm_socdata *socdata)
 		&imx6_suspend,
 		MX6Q_SUSPEND_OCRAM_SIZE - sizeof(*pm_info));
 
+	ret = set_memory_ro((unsigned long)suspend_ocram_base,
+			    __KERNEL_DIV_ROUND_UP(MX6Q_SUSPEND_OCRAM_SIZE, PAGE_SIZE));
+	if (ret) {
+		pr_warn("%s: failed to mark executable on chip SRAM as read only after writing to it: %d!\n",
+			__func__, ret);
+	}
+
 	goto put_device;
 
 pl310_cache_map_failed:




More information about the linux-arm-kernel mailing list