Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vítor Hugo Silva" <vitorhg20080@gmail.com>
Cc: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
	alex@ghiti.fr, viro@zeniv.linux.org.uk, brauner@kernel.org,
	jack@suse.cz, kees@kernel.org, david@kernel.org,
	akpm@linux-foundation.org, linux-mm@kvack.org
Subject: Re: [PATCH RFC v4] riscv: Synchronize instructions written to ESP32-P4 PSRAM
Date: Thu, 03 Dec 2026 20:58:47 +0000	[thread overview]
Message-ID: <sashiko-outbox-248657@kernel.org> (raw)
In-Reply-To: <20261202205804.435026-1-vitorhg20080@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] riscv: undefined CONFIG_RISCV_ESP32P4_CLIC leaves ESP32-P4
  cache sync dead code
- [Medium] riscv: global icache flush in patch_insn_write() breaks
  stop_machine()
--

commit 1ae24c8e510defc8fad5a55c9c5e8db58020214d
Author: Vítor Hugo Silva <vitorhg20080@gmail.com>

riscv: Synchronize instructions written to ESP32-P4 PSRAM

This commit adds L1D/L2 writeback and L1I invalidation routines for
ESP32-P4 PSRAM and wires them into kernel text patching, executable
loading, NOMMU mappings, remote VM writes, and riscv_flush_icache().

Link: https://docs.espressif.com/projects/esp-idf/en/stable/esp32p4/api-reference/system/mm_sync.html

> diff --git a/arch/riscv/include/asm/cacheflush.h b/arch/riscv/include/asm/cacheflush.h
> index c2b0a2928f067..10cf0a105fe17 100644
> --- a/arch/riscv/include/asm/cacheflush.h
> +++ b/arch/riscv/include/asm/cacheflush.h
> @@ -75,15 +75,30 @@ void flush_icache_mm(struct mm_struct *mm, bool local);
>  
>  #endif /* CONFIG_SMP */
>  
> +#define flush_icache_range flush_icache_range
> +#ifdef CONFIG_RISCV_ESP32P4_CLIC
> +extern bool riscv_esp32p4_cache_enabled;
> +
> +void flush_icache_range(unsigned long start, unsigned long end);
> +int esp32p4_sync_user_text(unsigned long start, unsigned long end);
> +int copy_to_user_page_checked(struct vm_area_struct *vma, struct page *page,
> +			      unsigned long addr, void *dst,
> +			      const void *src, int len);
> +
> +#define flush_icache_user_range_checked esp32p4_sync_user_text
> +#define copy_to_user_page_checked copy_to_user_page_checked
> +#else
> +#define riscv_esp32p4_cache_enabled false

[Severity: High]
Is a Kconfig definition for RISCV_ESP32P4_CLIC missing from this patch?
Because RISCV_ESP32P4_CLIC is not defined in any Kconfig file in the
tree, CONFIG_RISCV_ESP32P4_CLIC is never set, riscv_esp32p4_cache_enabled
is always false, and all of the ESP32-P4 cache synchronization code in
setup.c, sys_riscv.c, and cacheflush.c is compiled out.

> diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c
> index 2b5adf01c5502..a10b91a445c94 100644
> --- a/arch/riscv/kernel/patch.c
> +++ b/arch/riscv/kernel/patch.c

[ ... ]

> @@ -237,13 +238,24 @@ int patch_insn_write(void *addr, const void *insn, size_t len)
>  
>  	return 0;
>  }
> +NOKPROBE_SYMBOL(patch_insn_copy);
> +
> +int patch_insn_write(void *addr, const void *insn, size_t len)
> +{
> +	int ret = patch_insn_copy(addr, insn, len);
> +
> +	if (!ret && riscv_esp32p4_cache_enabled)
> +		flush_icache_range((uintptr_t)addr, (uintptr_t)addr + len);
> +
> +	return ret;
> +}
>  NOKPROBE_SYMBOL(patch_insn_write);

[Severity: Medium]
Can calling flush_icache_range() from patch_insn_write() deadlock inside
patch_text_cb() when SMP is enabled with two online harts?

flush_icache_range() calls esp32p4_sync_text() followed by
flush_icache_all(), which sends a synchronous remote fence.i IPI when
num_online_cpus() >= 2.  However, patch_text() runs patch_text_cb() on
all online CPUs via stop_machine_cpuslocked() with local interrupts
disabled:

CPU0                                  CPU1
patch_text_cb()                       patch_text_cb()
  atomic_inc_return(&cpu_count)         while (cpu_count <= num_online_cpus())
  patch_insn_write()                      cpu_relax(); /* IRQs disabled */
    flush_icache_range()
      flush_icache_all()
        on_each_cpu(ipi_remote_fence_i, ..., 1)
          <-- waits forever for CPU1 to handle IPI

Could patch_insn_write() call esp32p4_sync_text() directly without
flush_icache_all() so stop_machine() callers do not broadcast IPIs?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202205804.435026-1-vitorhg20080@gmail.com?part=1


      reply	other threads:[~2026-12-03 20:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 23:30 [PATCH RFC 00/19] riscv: Add initial support for Espressif ESP32-P4 Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 14/19] riscv: Synchronize instructions written to ESP32-P4 PSRAM Vítor Hugo Silva
2026-11-26 23:32   ` sashiko-bot
2026-11-27 22:13   ` [PATCH RFC v2] " Vítor Hugo Silva
2026-11-28 22:16     ` sashiko-bot
2026-11-30 10:31       ` Vítor Hugo Silva
2026-11-30 12:23     ` [PATCH RFC v3] " Vítor Hugo Silva
2026-12-01 12:24       ` sashiko-bot
2026-12-02 12:25         ` Vítor Hugo Silva
2026-12-02 20:58       ` [PATCH RFC v4] " Vítor Hugo Silva
2026-12-03 20:58         ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-248657@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=brauner@kernel.org \
    --cc=david@kernel.org \
    --cc=jack@suse.cz \
    --cc=kees@kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vitorhg20080@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox