All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Julien Grall <julien@xen.org>,
	Xen-devel <xen-devel@lists.xenproject.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	Michal Orzel <michal.orzel@amd.com>,
	Oleksii Kurochko <oleksii.kurochko@gmail.com>
Subject: Re: [PATCH 2/4] ARM: Fix register constraints in run_in_exception_handler()
Date: Mon, 10 Feb 2025 22:10:26 +0000	[thread overview]
Message-ID: <b1f9fdd5-0d5c-4a01-be9c-0ace72d07d9b@citrix.com> (raw)
In-Reply-To: <e46af210-4e99-4324-aaae-d531e88c4792@xen.org>

On 10/02/2025 9:29 pm, Julien Grall wrote:
> Hi,
>
> On 08/02/2025 00:02, Andrew Cooper wrote:
>> Right now, run_in_exception_handler() takes an input in an arbitrary
>> register,
>> and clobbers BUG_FN_REG.  This causes the compiler to calculate fn in
>> the
>> wrong regsiter.
>
> Just to confirm, you mean, the compiler is not clever enough to notice
> that the value should be in the register BUG_FN_REG and therefore, two
> registers will be clobbered. Is that correct?

Not quite.

The clobbered register set is always disjoint from inputs and outputs,
so the combination of one clobbered + one input always means two
different registers.

For "here's an input but it gets modified", you need to express that as
an output into a variable which isn't subsequently used.

For ARM, that is best spelt "+r" (foo) so it can also be used with
register asm() to tie to a single register.  On x86, you can use "=a"
(tmp) : "a" (input).  In principle you can do it with named parameters,
so [fn] "=r" (tmp) : "[fn]" (input) I believe works too.

Here is a contrived example https://godbolt.org/z/WjqTKjWWb showing how
the output (discard only) is forced into r0, causing the compiler to
copy a into r3 around the asm block.  Notice that GCC and Clang pick the
input operand differently, as both r0 and r3 are valid candidates in
this case.


However, for run_in_exception_handler(), "fn" isn't even modified
(AFAICT), so it's correct to describe it as an input only.

~Andrew


  reply	other threads:[~2025-02-10 22:10 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-08  0:02 [PATCH 0/4] Other fixes from UBSAN enablement Andrew Cooper
2025-02-08  0:02 ` [PATCH for-4.20? 1/4] ARM32/traps: Fix do_trap_undefined_instruction()'s detection of kernel text Andrew Cooper
2025-02-10 10:13   ` Orzel, Michal
2025-02-10 22:31     ` Andrew Cooper
2025-02-10 21:23   ` Julien Grall
2025-02-10 22:23     ` Andrew Cooper
2025-02-11 10:05       ` Julien Grall
2025-02-08  0:02 ` [PATCH 2/4] ARM: Fix register constraints in run_in_exception_handler() Andrew Cooper
2025-02-10  9:21   ` Oleksii Kurochko
2025-02-10 21:31     ` Julien Grall
2025-02-10 22:41       ` Andrew Cooper
2025-02-12 22:59         ` Julien Grall
2025-02-10 10:33   ` Orzel, Michal
2025-02-10 21:29   ` Julien Grall
2025-02-10 22:10     ` Andrew Cooper [this message]
2025-02-08  0:02 ` [PATCH 3/4] xen: Centralise the declaration of dump_execution_state() Andrew Cooper
2025-02-10  9:23   ` Oleksii Kurochko
2025-02-10  9:25   ` Jan Beulich
2025-02-08  0:02 ` [PATCH 4/4] [BROKEN] PPC: Activate UBSAN in testing Andrew Cooper
2025-02-21 19:49   ` Shawn Anastasio

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=b1f9fdd5-0d5c-4a01-be9c-0ace72d07d9b@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=oleksii.kurochko@gmail.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.