public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Paolo Bonzini <pbonzini@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH] KVM/VMX: Do not declare vmread_error asmlinkage
Date: Thu, 1 Sep 2022 15:37:14 +0000	[thread overview]
Message-ID: <YxDRquTx2piSX66J@google.com> (raw)
In-Reply-To: <CAFULd4bVQ73Cur85Oj=oXHiMRvfrxkAVy=V4TfHcbtNWbqOQzw@mail.gmail.com>

On Wed, Aug 31, 2022, Uros Bizjak wrote:
> On Wed, Aug 17, 2022 at 5:58 PM Sean Christopherson <seanjc@google.com> wrote:
> >
> > +PeterZ
> >
> > On Wed, Aug 17, 2022, Uros Bizjak wrote:
> > > There is no need to declare vmread_error asmlinkage, its arguments
> > > can be passed via registers for both, 32-bit and 64-bit targets.
> > > Function argument registers are considered call-clobbered registers,
> > > they are saved in the trampoline just before the function call and
> > > restored afterwards.
> >
> > I'm officially confused.  What's the purpose of asmlinkage when used in the kernel?
> > Is it some historical wart that's no longer truly necessary and only causes pain?
> >
> > When I wrote this code, I thought that the intent was that it should be applied to
> > any and all asm => C function calls.  But that's obviously not required as there
> > are multiple instances of asm code calling C functions without annotations of any
> > kind.
> 
> It is the other way around. As written in coding-style.rst:
> 
> Large, non-trivial assembly functions should go in .S files, with corresponding
> C prototypes defined in C header files.  The C prototypes for assembly
> functions should use ``asmlinkage``.
> 
> So, prototypes for *assembly functions* should use asmlinkage.

I gotta imagine that documentation is stale.  I don't understand why asmlinkage
would be a one-way thing.

> That said, asmlinkage for i386 just switches ABI to the default
> stack-passing ABI. However, we are calling assembly files, so the
> argument handling in the callee is totally under our control and there
> is no need to switch ABIs. It looks to me that besides syscalls,
> asmlinkage is and should be used only for a large imported body of asm
> functions that use standard stack-passing ABI (e.g. x86 crypto and
> math-emu functions), otherwise it is just a burden to push and pop
> registers to/from stack for no apparent benefit.

Yeah, this is what I'm confused about.  Unless there's something we're missing,
we should update the docs to clarify when asmlinkage is actually needed.

> > And vmread_error() isn't the only case where asmlinkage appears to be a burden, e.g.
> > schedule_tail_wrapper() => schedule_tail() seems to exist purely to deal with the
> > side affect of asmlinkage generating -regparm=0 on 32-bit kernels.
> 
> schedule_tail is external to the x86 arch directory, and for some
> reason marked asmlinkage. So, the call from asm must follow asmlinkage
> ABI.

Ahhh, it's a common helper that's called from assembly on other architectures.
That makes sense.

Thanks much!

  reply	other threads:[~2022-09-01 15:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-17 14:40 [PATCH] KVM/VMX: Do not declare vmread_error asmlinkage Uros Bizjak
2022-08-17 15:58 ` Sean Christopherson
2022-08-31  7:10   ` Uros Bizjak
2022-09-01 15:37     ` Sean Christopherson [this message]
2022-09-06  7:28       ` Wang, Wei W
2022-09-08 15:47         ` Sean Christopherson
2022-09-01 15:39 ` Sean Christopherson
2022-09-01 17:29   ` Uros Bizjak
2022-09-08 17:23     ` Sean Christopherson
2022-09-08 17:25 ` 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=YxDRquTx2piSX66J@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ubizjak@gmail.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