All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Mathias Krause <minipli@grsecurity.net>
Cc: kvm@vger.kernel.org
Subject: Re: [kvm-unit-tests PATCH] x86/emulator: Test non-canonical memory access exceptions
Date: Wed, 5 Apr 2023 20:02:29 -0700	[thread overview]
Message-ID: <ZC42RavGH2Z82oJd@google.com> (raw)
In-Reply-To: <20230215142344.20200-1-minipli@grsecurity.net>

On Wed, Feb 15, 2023, Mathias Krause wrote:
> +static void test_reg_noncanonical(void)
> +{
> +	extern char nc_rsp_start, nc_rsp_end, nc_rbp_start, nc_rbp_end;
> +	extern char nc_rax_start, nc_rax_end;
> +	handler old_ss, old_gp;
> +
> +	old_ss = handle_exception(SS_VECTOR, advance_rip_and_note_exception);
> +	old_gp = handle_exception(GP_VECTOR, advance_rip_and_note_exception);
> +
> +	/* RAX based, should #GP(0) */
> +	exceptions = 0;
> +	rip_advance = &nc_rax_end - &nc_rax_start;
> +	asm volatile("nc_rax_start: orq $0, (%[msb]); nc_rax_end:\n\t"

Can't we use ASM_TRY() + exception_vector() + exception_error_code()?  Installing
a dedicated handler is (slowly) being phased out.  Even better, if you're willing
to take a dependency and/or wait a few weeks for my series to land[*], you should
be able to use asm_safe() to streamline this even further.

[*] https://lkml.kernel.org/r/20230406025117.738014-1-seanjc%40google.com


> +		     : : [msb]"a"(1ul << 63));

Use BIT_ULL().  Actually, scratch that, we have a NONCANONICAL macro.  It _probably_
won't matter, but who know what will happen with things like LAM and LASS.

And why hardcode use of RAX?  Won't any "r" constraint work?

E.g. I believe this can be something like:

	asm_safe_report_ex(GP_VECTOR, "orq $0, (%[noncanonical]), "r" (NONCANONICAL));
	report(!exception_error_code());

Or we could even add asm_safe_report_ex_ec(), e.g.

	asm_safe_report_ex_ec(GP_VECTOR, 0,
			      "orq $0, (%[noncanonical]), "r" (NONCANONICAL));

  reply	other threads:[~2023-04-06  3:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-15 14:23 [kvm-unit-tests PATCH] x86/emulator: Test non-canonical memory access exceptions Mathias Krause
2023-04-06  3:02 ` Sean Christopherson [this message]
2023-04-06  8:11   ` Mathias Krause
2023-04-06 16:43     ` Sean Christopherson
2023-04-13  7:55       ` Mathias Krause
2023-04-13 16:07         ` Sean Christopherson

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=ZC42RavGH2Z82oJd@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=minipli@grsecurity.net \
    /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.