All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Jan Kotas <jank@cadence.com>
Cc: Oliver Upton <oliver.upton@linux.dev>,
	"kvmarm@lists.linux.dev" <kvmarm@lists.linux.dev>
Subject: Re: HCR_EL2 GET_ONE_REG value difference
Date: Fri, 10 Oct 2025 11:31:45 +0100	[thread overview]
Message-ID: <86frbrxd2m.wl-maz@kernel.org> (raw)
In-Reply-To: <2268E166-0EA0-4C9D-B1AF-EEECB48B926B@global.cadence.com>

On Fri, 10 Oct 2025 10:51:52 +0100,
Jan Kotas <jank@cadence.com> wrote:
> 
> 
> > On 10 Oct 2025, at 11:37, Marc Zyngier <maz@kernel.org> wrote:
> > 
> > EXTERNAL MAIL
> > 
> > 
> > On Fri, 10 Oct 2025 09:30:12 +0100,
> > Jan Kotas <jank@cadence.com> wrote:
> >> 
> >> Hello,
> >> 
> >> During NV debugging I noticed a difference in HCR_EL2 value.
> >> 
> >> The value I get from accessing this register, using KVM_GET_ONE_REG:
> >> 0x30480000000
> > 
> > These bits are API, APK, E2H, RW.
> > 
> > When did you access this? After the vcpu has run? Before it has run?
> > What NV configuration did you use?
> 
> Hi Marc,
> 
> I wanted to reproduce the conditions when I observed it.
> 
> I run the guest without the improved EL2 detection,
> which was posted yesterday, in VHE mode. 
> I’m investigating the place at which E2H detection happens,
> just before an exception on ZCR_EL2.
> 
> > 
> >> 
> >> However, X1 value after executing mrs x1, hcr_el2 in guest:
> >> 0x100030080000000
> > 
> > You have ATA, API, APK, RW. Is that the *only* thing that has run in
> > your guest?
> 
> I just booted the kernel directly without E2H0.
> 
> > 
> >> I access both of these at the same place.
> > 
> > "at the same place"? What do you mean? One is accessed from host
> > userspace, and the other from the guest. How can that be the same
> > place?
> 
> By the same place I mean the same KVM_EXIT.
> Without resuming vCPUs, at the same PC.
> 
> > 
> >> I get the list of available registers from KVM_GET_REG_LIST.
> >> 
> >> I double checked my encoding, and it seems to be correct.
> >> HCR_EL2 3, 4, 1, 1, 0
> >> 
> >> I can check other registers, but I first wanted to check, if this expected?
> >> Is there something I’m missing, when accessing emulated registers?
> > 
> > Could you please start by clarifying what you are doing?
> 
> I placed a HW breakpoint at the MRS instruction.
> I did a single step, and then I checked X1 and HCR_EL2 values.
> By calling GET_ONE_REG on both, I see different values.

I'm very surprised that debug actually works, but hey, maybe I should
admit that miracles can happen... ;-)

The guest can write whatever it wants to the HCR_EL2 register. That's
just a 64bit chunk of memory, and if it wants to write Pi to it, it
can. Nothing the guest writes there will have any effect as long as it
doesn't ERET to EL1 anyway.

What GET_ONE_REG returns is the *sanitised* view of that register,
after having applied RES0 and RES1 masks, as well as the constraints
that are specific to your exact configuration.

Since you are running without the patch that makes the two views
consistent, your kernel is probably taking the wrong path, and
configuring bits that have no meaning in that configuration and
resulting in, amongst other things, E2H appearing to be 0 while
GET_ONE_REG clearly tells you it is 1.

	M.

-- 
Without deviation from the norm, progress is not possible.

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

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-10  8:30 HCR_EL2 GET_ONE_REG value difference Jan Kotas
2025-10-10  9:37 ` Marc Zyngier
2025-10-10  9:51   ` Jan Kotas
2025-10-10 10:31     ` Marc Zyngier [this message]
2025-10-10 10:59       ` Jan Kotas
2025-10-10 11:59         ` Marc Zyngier
2025-10-10 12:49           ` Jan Kotas
2025-10-10 13:12             ` Marc Zyngier

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=86frbrxd2m.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=jank@cadence.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=oliver.upton@linux.dev \
    /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.