From: Mathias Krause <minipli@grsecurity.net>
To: Chao Gao <chao.gao@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
kvm@vger.kernel.org
Subject: [kvm-unit-tests PATCH 6/8] x86/cet: Simplify IBT test
Date: Mon, 23 Jun 2025 22:29:41 +0200 [thread overview]
Message-ID: <8b2eb284-efb7-42d2-aaea-e9568e23f594@grsecurity.net> (raw)
In-Reply-To: <e53b66b9-6b32-4834-a34e-17c307c19a82@grsecurity.net>
[resend with kvm@ on cc]
On 23.06.25 07:32, Chao Gao wrote:
> On Fri, Jun 20, 2025 at 05:39:10PM +0200, Mathias Krause wrote:
>> static uint64_t cet_ibt_func(void)
>> {
>> + unsigned long tmp;
>> /*
>> * In below assembly code, the first instruction at label 2 is not
>> * endbr64, it'll trigger #CP with error code 0x3, and the execution
>> * is terminated when HW detects the violation.
>> */
>> printf("No endbr64 instruction at jmp target, this triggers #CP...\n");
>> - asm volatile ("movq $2, %rcx\n"
>> - "dec %rcx\n"
>> - "leaq 2f(%rip), %rax\n"
>> - "jmp *%rax \n"
>> - "2:\n"
>> - "dec %rcx\n");
>> + asm volatile ("leaq 2f(%%rip), %0\n\t"
>> + "jmpq *%0\n\t"
>> + "2:"
>> + : "=r"(tmp));
>
> @tmp isn't needed. We can still use "rax" and list it as clobbered.
>
I still prefer letting the compiler choose a fitting register. This also
makes it easier to enable this code to be 32-bit ready. So 'tmp' may
seem unnecessary, but it's a vehicle to allow the compiler to choose an
unused register. RAX needs to be set to zero, after all.
Thanks,
Mathias
>> return 0;
>> }
>>
next parent reply other threads:[~2025-06-23 20:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <e53b66b9-6b32-4834-a34e-17c307c19a82@grsecurity.net>
2025-06-23 20:29 ` Mathias Krause [this message]
2025-06-20 15:39 [kvm-unit-tests PATCH 0/8] x86: CET fixes and enhancements Mathias Krause
2025-06-20 15:39 ` [kvm-unit-tests PATCH 6/8] x86/cet: Simplify IBT test Mathias Krause
2025-06-23 5:32 ` Chao Gao
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=8b2eb284-efb7-42d2-aaea-e9568e23f594@grsecurity.net \
--to=minipli@grsecurity.net \
--cc=chao.gao@intel.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/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.