From: Sean Christopherson <seanjc@google.com>
To: David Matlack <dmatlack@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Tom Rix <trix@redhat.com>, Peter Xu <peterx@redhat.com>,
Jim Mattson <jmattson@google.com>,
Oliver Upton <oupton@google.com>,
"open list:CLANG/LLVM BUILD SUPPORT" <llvm@lists.linux.dev>,
kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: selftests: Fix ambiguous mov in KVM_ASM_SAFE()
Date: Sat, 23 Jul 2022 00:14:08 +0000 [thread overview]
Message-ID: <Yts9UCEyOmr3uY4D@google.com> (raw)
In-Reply-To: <20220722234838.2160385-3-dmatlack@google.com>
On Fri, Jul 22, 2022, David Matlack wrote:
> Change the mov in KVM_ASM_SAFE() that zeroes @vector to a movb to
> make it unambiguous.
>
> This fixes a build failure with Clang since, unlike the GNU assembler,
> the LLVM integrated assembler rejects ambiguous X86 instructions that
> don't have suffixes:
>
> In file included from x86_64/hyperv_features.c:13:
> include/x86_64/processor.h:825:9: error: ambiguous instructions require an explicit suffix (could be 'movb', 'movw', 'movl', or 'movq')
> return kvm_asm_safe("wrmsr", "a"(val & -1u), "d"(val >> 32), "c"(msr));
> ^
> include/x86_64/processor.h:802:15: note: expanded from macro 'kvm_asm_safe'
> asm volatile(KVM_ASM_SAFE(insn) \
> ^
> include/x86_64/processor.h:788:16: note: expanded from macro 'KVM_ASM_SAFE'
> "1: " insn "\n\t" \
> ^
> <inline asm>:5:2: note: instantiated into assembly here
> mov $0, 15(%rsp)
> ^
>
> It seems like this change could introduce undesirable behavior in the
> future, e.g. if someone used a type larger than a u8 for @vector, since
> KVM_ASM_SAFE() will only zero the bottom byte. I tried changing the type
> of @vector to an int to see what would happen. GCC failed to compile due
> to a size mismatch between `movb` and `%eax`. Clang succeeded in
> compiling, but the generated code looked correct, so perhaps it will not
> be an issue. That being said it seems like there could be a better
> solution to this issue that does not assume @vector is a u8.
Hrm, IIRC my intent was to not care about the size of "vector", but that may just
be revisionist thinking because the:
"mov %%r9b, %[vector]\n\t" \
suggests it's nothing more than a screwed up. A static assert on the size would
be nice, but I don't know how to make that work since the macros dump directly
into the asm.
> Fixes: 3b23054cd3f5 ("KVM: selftests: Add x86-64 support for exception fixup")
> Signed-off-by: David Matlack <dmatlack@google.com>
Reviewed-by: Sean Christopherson <seanjc@google.com>
next prev parent reply other threads:[~2022-07-23 0:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-22 23:48 [PATCH 0/2] KVM: selftests: Fix Clang build issues in KVM_ASM_SAFE() David Matlack
2022-07-22 23:48 ` [PATCH 1/2] KVM: selftests: Fix KVM_EXCEPTION_MAGIC build with Clang David Matlack
2022-07-23 0:01 ` Sean Christopherson
2022-07-23 0:07 ` David Matlack
2022-07-22 23:48 ` [PATCH 2/2] KVM: selftests: Fix ambiguous mov in KVM_ASM_SAFE() David Matlack
2022-07-23 0:14 ` Sean Christopherson [this message]
2022-08-10 22:53 ` [PATCH 0/2] KVM: selftests: Fix Clang build issues " David Matlack
2022-08-12 7:49 ` Paolo Bonzini
2022-08-12 7:57 ` Paolo Bonzini
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=Yts9UCEyOmr3uY4D@google.com \
--to=seanjc@google.com \
--cc=dmatlack@google.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=trix@redhat.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.