linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Alexandru Elisei <alexandru.elisei@arm.com>
Cc: catalin.marinas@arm.com, will@kernel.org,
	linux-arm-kernel@lists.infradead.org, james.morse@arm.com,
	suzuki.poulose@arm.com, kvmarm@lists.cs.columbia.edu,
	mark.rutland@arm.com
Subject: Re: [PATCH 5/5] KVM: arm64: uapi: Add kvm_debug_exit_arch.hsr_high
Date: Fri, 08 Apr 2022 08:47:00 +0100	[thread overview]
Message-ID: <87ee28auff.wl-maz@kernel.org> (raw)
In-Reply-To: <20220407162327.396183-6-alexandru.elisei@arm.com>

Hi Alex,

On Thu, 07 Apr 2022 17:23:27 +0100,
Alexandru Elisei <alexandru.elisei@arm.com> wrote:
> 
> When userspace is debugging a VM, the kvm_debug_exit_arch part of the
> kvm_run struct contains arm64 specific debug information: the ESR_EL2
> value, encoded in the field "hsr", and the address of the instruction
> that caused the exception, encoded in the field "far".
> 
> Linux has moved to treating ESR_EL2 as a 64-bit register, but unfortunately
> kvm_debug_exit_arch.hsr cannot be changed to match because that would
> change the memory layout of the struct on big endian machines:
> 
> Current layout:			| Layout with "hsr" extended to 64 bits:
> 				|
> offset 0: ESR_EL2[31:0] (hsr)   | offset 0: ESR_EL2[61:32] (hsr[61:32])
> offset 4: padding		| offset 4: ESR_EL2[31:0]  (hsr[31:0])
> offset 8: FAR_EL2[61:0] (far)	| offset 8: FAR_EL2[61:0]  (far)
> 
> which breaks existing code.
> 
> The padding is inserted by the compiler because the "far" field must be
> aligned to 8 bytes (each field must be naturally aligned - aapcs64 [1],
> page 18) and the struct itself must be aligned to 8 bytes (the struct must
> be aligned to the maximum alignment of its fields - aapcs64, page 18),
> which means that "hsr" must be aligned to 8 bytes as it is the first field
> in the struct.
> 
> To avoid changing the struct size and layout for the existing fields, add a
> new field, "hsr_high", which replaces the existing padding. "hsr_high" will
> be used to hold the ESR_EL2[61:32] bits of the register. The memory layout,
> both on big and little endian machine, becomes:
> 
> Layout with "hsr_high" added:
> 
> offset 0: ESR_EL2[31:0]  (hsr)
> offset 4: ESR_EL2[61:32] (hsr_high)
> offset 8: FAR_EL2[61:0]  (far)

My concern with this change is that it isn't clear what the padding is
currently initialised to, and I don't think there is any guarantee
that it is zeroed. With that, a new userspace on an old kernel would
interpret hsr_high, and potentially observe stuff that wasn't supposed
to be interpreted.

That's yet another mistake in our userspace ABI (where is the time
machine when you need it?).

In order to do this, we must advertise to userspace that we provide
more information. This probably means adding a flag of some sort to
kvm_run (there are at least 128 bits of x86 stuff that can be readily
reclaimed).

What do you think?

	M.

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-04-08  7:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-07 16:23 [PATCH 0/5] arm64: Treat ESR_ELx as a 64-bit register Alexandru Elisei
2022-04-07 16:23 ` [PATCH 1/5] arm64: Make ESR_ELx_xVC_IMM_MASK compatible with assembly Alexandru Elisei
2022-04-07 16:23 ` [PATCH 2/5] arm64: compat: Do not treat syscall number as ESR_ELx for a bad syscall Alexandru Elisei
2022-04-07 16:23 ` [PATCH 3/5] arm64: Treat ESR_ELx as a 64bit register Alexandru Elisei
2022-04-07 16:23 ` [PATCH 4/5] KVM: arm64: Treat ESR_EL2 as a 64-bit register Alexandru Elisei
2022-04-07 16:23 ` [PATCH 5/5] KVM: arm64: uapi: Add kvm_debug_exit_arch.hsr_high Alexandru Elisei
2022-04-08  7:47   ` Marc Zyngier [this message]
2022-04-11 10:46     ` Alexandru Elisei
2022-04-12 11:30       ` 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=87ee28auff.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=alexandru.elisei@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=james.morse@arm.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.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).