From: "Björn Töpel" <bjorn@kernel.org>
To: guoren@kernel.org, guoren@kernel.org, palmer@dabbelt.com,
paul.walmsley@sifive.com, mhiramat@kernel.org,
conor.dooley@microchip.com, penberg@kernel.org,
mark.rutland@arm.com, jrtc27@jrtc27.com, andy.chiu@sifive.com,
zong.li@sifive.com
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
Greentime Hu <greentime.hu@sifive.com>
Subject: Re: [PATCH -next V3 1/2] riscv: jump_label: Fixup unaligned arch_static_branch function
Date: Mon, 30 Jan 2023 12:57:15 +0100 [thread overview]
Message-ID: <87357sjkv8.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <20230126170607.1489141-2-guoren@kernel.org>
guoren@kernel.org writes:
> From: Andy Chiu <andy.chiu@sifive.com>
>
> Runtime code patching must be done at a naturally aligned address, or we
> may execute on a partial instruction.
>
> We have encountered problems traced back to static jump functions during
> the test. We switched the tracer randomly for every 1~5 seconds on a
> dual-core QEMU setup and found the kernel sucking at a static branch
> where it jumps to itself.
>
> The reason is that the static branch was 2-byte but not 4-byte aligned.
> Then, the kernel would patch the instruction, either J or NOP, with two
> half-word stores if the machine does not have efficient unaligned
> accesses. Thus, moments exist where half of the NOP mixes with the other
> half of the J when transitioning the branch. In our particular case, on
> a little-endian machine, the upper half of the NOP was mixed with the
> lower part of the J when enabling the branch, resulting in a jump that
> jumped to itself. Conversely, it would result in a HINT instruction when
> disabling the branch, but it might not be observable.
>
> ARM64 does not have this problem since all instructions must be 4-byte
> aligned.
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Nice catch! And I guess this is an issue for kprobes as well, no?
I.e. in general replacing 32b insns with an ebreak. This is only valid
for natural aligned 32b insns?
@Guo I don't see the point of doing a series for this, and asking the
maintainers to "pick this patch to stable, and the other for
next". Isn't that just more work for the maintainers/reviewers?
Björn
next prev parent reply other threads:[~2023-01-30 11:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-26 17:06 [PATCH -next V3 0/2] riscv: jump_label: Fixup & Optimization guoren
2023-01-26 17:06 ` [PATCH -next V3 1/2] riscv: jump_label: Fixup unaligned arch_static_branch function guoren
2023-01-30 11:57 ` Björn Töpel [this message]
2023-01-31 13:35 ` Guo Ren
2023-01-26 17:06 ` [PATCH -next V3 2/2] riscv: jump_label: Optimize the code size with compressed instruction guoren
2023-02-22 15:00 ` [PATCH -next V3 0/2] riscv: jump_label: Fixup & Optimization patchwork-bot+linux-riscv
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=87357sjkv8.fsf@all.your.base.are.belong.to.us \
--to=bjorn@kernel.org \
--cc=andy.chiu@sifive.com \
--cc=conor.dooley@microchip.com \
--cc=greentime.hu@sifive.com \
--cc=guoren@kernel.org \
--cc=jrtc27@jrtc27.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=penberg@kernel.org \
--cc=zong.li@sifive.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
all inboxes | Powered by JetHome®