public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oliver Upton <oliver.upton@linux.dev>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Andrew Jones <andrew.jones@linux.dev>,
	Anup Patel <anup@brainfault.org>,
	Atish Patra <atishp@atishpatra.org>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Janosch Frank <frankja@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>
Subject: Re: [PATCH 2/5] KVM: selftests: Compare insn opcodes directly in fix_hypercall_test
Date: Mon, 19 Sep 2022 21:17:11 +0000	[thread overview]
Message-ID: <YyjcVydnLQzKtNC/@google.com> (raw)
In-Reply-To: <20220908233134.3523339-3-seanjc@google.com>

On Thu, Sep 08, 2022 at 11:31:31PM +0000, Sean Christopherson wrote:
> Directly compare the expected versus observed hypercall instructions when
> verifying that KVM patched in the native hypercall (FIX_HYPERCALL_INSN
> quirk enabled).  gcc rightly complains that doing a 4-byte memcpy() with
> an "unsigned char" as the source generates an out-of-bounds accesses.
> 
> Alternatively, "exp" and "obs" could be declared as 3-byte arrays, but
> there's no known reason to copy locally instead of comparing directly.

I was trying to print just the instruction bytes if such a comparison
failed, but that's already a bust given that it was a 4-byte copy.

Having said that, the assertion should be clear enough.

> In function ‘assert_hypercall_insn’,
>     inlined from ‘guest_main’ at x86_64/fix_hypercall_test.c:91:2:
> x86_64/fix_hypercall_test.c:63:9: error: array subscript ‘unsigned int[0]’
>  is partly outside array bounds of ‘unsigned char[1]’ [-Werror=array-bounds]
>    63 |         memcpy(&exp, exp_insn, sizeof(exp));
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> x86_64/fix_hypercall_test.c: In function ‘guest_main’:
> x86_64/fix_hypercall_test.c:42:22: note: object ‘vmx_hypercall_insn’ of size 1
>    42 | extern unsigned char vmx_hypercall_insn;
>       |                      ^~~~~~~~~~~~~~~~~~
> x86_64/fix_hypercall_test.c:25:22: note: object ‘svm_hypercall_insn’ of size 1
>    25 | extern unsigned char svm_hypercall_insn;
>       |                      ^~~~~~~~~~~~~~~~~~
> In function ‘assert_hypercall_insn’,
>     inlined from ‘guest_main’ at x86_64/fix_hypercall_test.c:91:2:
> x86_64/fix_hypercall_test.c:64:9: error: array subscript ‘unsigned int[0]’
>  is partly outside array bounds of ‘unsigned char[1]’ [-Werror=array-bounds]
>    64 |         memcpy(&obs, obs_insn, sizeof(obs));
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> x86_64/fix_hypercall_test.c: In function ‘guest_main’:
> x86_64/fix_hypercall_test.c:25:22: note: object ‘svm_hypercall_insn’ of size 1
>    25 | extern unsigned char svm_hypercall_insn;
>       |                      ^~~~~~~~~~~~~~~~~~
> x86_64/fix_hypercall_test.c:42:22: note: object ‘vmx_hypercall_insn’ of size 1
>    42 | extern unsigned char vmx_hypercall_insn;
>       |                      ^~~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> make: *** [../lib.mk:135: tools/testing/selftests/kvm/x86_64/fix_hypercall_test] Error 1
> 
> Fixes: 6c2fa8b20d0c ("selftests: KVM: Test KVM_X86_QUIRK_FIX_HYPERCALL_INSN")
> Cc: Oliver Upton <oliver.upton@linux.dev>
> Signed-off-by: Sean Christopherson <seanjc@google.com>

Reviewed-by: Oliver Upton <oliver.upton@linux.dev>

--
Thanks,
Oliver

  reply	other threads:[~2022-09-19 21:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-08 23:31 [PATCH 0/5] KVM: selftests: Fix "fix hypercall test" build errors Sean Christopherson
2022-09-08 23:31 ` [PATCH 1/5] KVM: selftests: Implement memcmp(), memcpy(), and memset() for guest use Sean Christopherson
2022-09-22 17:29   ` David Matlack
2022-09-22 17:40     ` Sean Christopherson
2022-09-22 17:49       ` David Matlack
2022-09-22 18:20         ` Sean Christopherson
2022-09-08 23:31 ` [PATCH 2/5] KVM: selftests: Compare insn opcodes directly in fix_hypercall_test Sean Christopherson
2022-09-19 21:17   ` Oliver Upton [this message]
2022-09-08 23:31 ` [PATCH 3/5] KVM: selftests: Remove unnecessary register shuffling " Sean Christopherson
2022-09-19 21:19   ` Oliver Upton
2022-09-08 23:31 ` [PATCH 4/5] KVM: selftests: Explicitly verify KVM doesn't patch hypercall if quirk==off Sean Christopherson
2022-09-19 21:23   ` Oliver Upton
2022-09-20 18:46     ` Sean Christopherson
2022-09-08 23:31 ` [PATCH 5/5] KVM: selftests: Dedup subtests of fix_hypercall_test Sean Christopherson
2022-09-19 21:26   ` Oliver Upton
2022-09-22  7:04 ` [PATCH 0/5] KVM: selftests: Fix "fix hypercall test" build errors Christian Borntraeger
2022-09-22 17:20 ` David Matlack
2022-09-22 17:53   ` Jim Mattson
2022-09-22 18:15     ` 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=YyjcVydnLQzKtNC/@google.com \
    --to=oliver.upton@linux.dev \
    --cc=andrew.jones@linux.dev \
    --cc=anup@brainfault.org \
    --cc=atishp@atishpatra.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=frankja@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox