qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: "Pranith Kumar" <bobby.prani@gmail.com>,
	"Alex Bennée" <alex.bennee@linaro.org>
Cc: qemu-devel <qemu-devel@nongnu.org>
Subject: Re: Reg. guest unaligned accesses in TCG
Date: Sat, 4 Oct 2025 09:41:47 -0700	[thread overview]
Message-ID: <c5976952-ecdc-420f-9025-c80018b6b123@linaro.org> (raw)
In-Reply-To: <CAJhHMCCfOqP6E2XvkY5JNtgQrXXH7uV_y9wfLcYFh9kecgocaQ@mail.gmail.com>

On 10/3/25 23:34, Pranith Kumar wrote:
> Hi Richard and Alex,
> 
> I am trying to implement efficient x86 guest on ARM64 host
> virtualization where the host has FEAT_LRCPC2 instructions. If I
> translate every x86 load to LDAPR and every x86 store to STLR, it will
> meet the memory consistency requirements.
> 
> The necessary condition for using these RCpc instructions is the
> alignment. The manual states that alignment fault will be raised if:
> 
> * Not all bytes of the memory access lie within a 16-byte quantity
> aligned to 16 bytes, and
> * The value of SCTLR_ELx.nAA applicable to the current Exception level is 0.
> 
> How does TCG check for alignment? How do I check if the guest memory
> access is within the 16-byte alignment? Will alignment fault be raised
> if it is not?

See prepare_host_addr in tcg/aarch64/tcg-target.c.inc.

a_mask is the alignment required by the guest, s_mask is the access size, so a_mask >= 
s_mask is required to be at least naturally aligned.

That's only enough to get you to the slow path for page crossings or guest misalignment. 
For additional host alignment along the fast path, you'd need to generate additional 
branches, and probably not here.

I'll warn you that I tried this once, and the extra work proving alignment overwhelmed the 
savings from substituting acquire/release for separate memory barriers.  I'd love for you 
to succeed, but this won't be a trivial task.


r~


      parent reply	other threads:[~2025-10-04 16:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-04  6:34 Reg. guest unaligned accesses in TCG Pranith Kumar
2025-10-04  7:22 ` Mohamed Mediouni
2025-10-04 16:09   ` Pranith Kumar
2025-10-04 16:41 ` Richard Henderson [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=c5976952-ecdc-420f-9025-c80018b6b123@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=bobby.prani@gmail.com \
    --cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).