From: Sean Christopherson <seanjc@google.com>
To: Nathan Chancellor <nathan@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Nick Desaulniers <ndesaulniers@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, llvm@lists.linux.dev,
linux-kernel@vger.kernel.org, Like Xu <like.xu.linux@gmail.com>
Subject: Re: [PATCH] KVM: x86: Fix pointer mistmatch warning when patching RET0 static calls
Date: Wed, 23 Feb 2022 18:56:28 +0000 [thread overview]
Message-ID: <YhaDXDfLBQtkmbtV@google.com> (raw)
In-Reply-To: <YhZ5Q8DNoGGWUBLh@dev-arch.archlinux-ax161>
On Wed, Feb 23, 2022, Nathan Chancellor wrote:
> On Wed, Feb 23, 2022 at 05:59:05PM +0000, Sean Christopherson wrote:
> > On Wed, Feb 23, 2022, Nathan Chancellor wrote:
> > > Hi Sean,
> > >
> > > On Wed, Feb 23, 2022 at 04:23:55PM +0000, Sean Christopherson wrote:
> > > > Cast kvm_x86_ops.func to 'void *' when updating KVM static calls that are
> > > > conditionally patched to __static_call_return0(). clang complains about
> > > > using mismatching pointers in the ternary operator, which breaks the
> > > > build when compiling with CONFIG_KVM_WERROR=y.
> > > >
> > > > >> arch/x86/include/asm/kvm-x86-ops.h:82:1: warning: pointer type mismatch
> > > > ('bool (*)(struct kvm_vcpu *)' and 'void *') [-Wpointer-type-mismatch]
> > > >
> > > > Fixes: 5be2226f417d ("KVM: x86: allow defining return-0 static calls")
> > > > Reported-by: Like Xu <like.xu.linux@gmail.com>
> > > > Reported-by: kernel test robot <lkp@intel.com>
> > > > Signed-off-by: Sean Christopherson <seanjc@google.com>
> > >
> > > Thank you for the patch! Is this a bug in clang?
> >
> > IMO, no. I think it's completely reasonable for the compiler to complain that KVM
> > is generating two different pointer types out of a ternary operator.
> >
> > clang is somewhat inconsistent, though it may be deliberate. clang doesn't complain
> > about implicitly casting a 'void *' to another data type, e.g. this complies clean,
> > where "data" is a 'void *'
> >
> > struct kvm_vcpu *x = vcpu ? : data;
>
> Right, I would assume this is deliberate. I think warning in this case
> might be quite noisy, as the kernel implicitly converts 'void *' to
> typed pointers for certain function pointer callbacks (although this
> particular case is probably pretty rare).
Aha! Looks like clang's behavior is correct, assuming a function is not considered
an "object". From C99 "6.5.15 Conditional operator":
One of the following shall hold for the second and third operands:
— both operands have arithmetic type;
— both operands have the same structure or union type;
— both operands have void type;
— both operands are pointers to qualified or unqualified versions of compatible types;
— one operand is a pointer and the other is a null pointer constant; or
— one operand is a pointer to an object or incomplete type and the other is a pointer to a
qualified or unqualified version of void.
That last case would explain why clang warns about a function pointer but not a
object pointer when the third operand is a 'void *'.
next prev parent reply other threads:[~2022-02-23 18:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-23 16:23 [PATCH] KVM: x86: Fix pointer mistmatch warning when patching RET0 static calls Sean Christopherson
2022-02-23 17:27 ` Nathan Chancellor
2022-02-23 17:59 ` Sean Christopherson
2022-02-23 18:13 ` Nathan Chancellor
2022-02-23 18:56 ` Sean Christopherson [this message]
2022-02-23 22:23 ` David Dunn
2022-02-24 14:23 ` 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=YhaDXDfLBQtkmbtV@google.com \
--to=seanjc@google.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=like.xu.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=pbonzini@redhat.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.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.