From: Dave Hansen <dave.hansen@intel.com>
To: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
"K. Y. Srinivasan" <kys@microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Peter Zijlstra <peterz@infradead.org>
Cc: linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-hyperv@vger.kernel.org
Subject: Re: [PATCH] x86/tdx: Enhance code generation for TDCALL and SEAMCALL wrappers
Date: Mon, 3 Jun 2024 06:37:45 -0700 [thread overview]
Message-ID: <8992921e-7343-4279-9953-0c042d8baf90@intel.com> (raw)
In-Reply-To: <20240602115444.1863364-1-kirill.shutemov@linux.intel.com>
On 6/2/24 04:54, Kirill A. Shutemov wrote:
> Sean observed that the compiler is generating inefficient code to clear
> the tdx_module_args struct for TDCALL and SEAMCALL wrappers. The
> compiler is generating numerous instructions at each call site to clear
> the unused fields of the structure.
>
> To address this issue, avoid using C99-initializer and instead
> explicitly use string instructions to clear the struct.
>
> With Clang, this change results in a savings of approximately 3K with my
> configuration:
>
> add/remove: 0/0 grow/shrink: 0/21 up/down: 0/-3187 (-3187)
>
> With GCC, the savings are less significant at around 300 bytes:
>
> add/remove: 0/0 grow/shrink: 3/22 up/down: 17/-313 (-296)
>
> GCC tends to generate string instructions more frequently to clear the
> struct.
<shrug>
I don't think moving away from perfectly normal C struct initialization
is worth it for 300 bytes of text in couple of slow paths.
If someone out there is using clang, is confident that it is doing the
right thing and not just being silly, _and_ is horribly bothered by its
code generation, then please speak up.
> +static __always_inline void tdx_arg_init(struct tdx_module_args *args)
> +{
> + asm ("rep stosb"
> + : "+D" (args)
> + : "c" (sizeof(*args)), "a" (0)
> + : "memory");
> +}
The inline assembly also has the side-effect of tripping up the
compiler. The compiler can't optimize across these at all and it
probably has the effect of bloating the code.
Oh, and if we're going to leave this weirdo initialization idiom for
TDX, it needs to be well commented:
/*
* Using normal " = {};" to initialize tdx_module_args results in
* bloated hard-to-read assembly. Zero it using the most compact way
* available.
*/
Eh?
next prev parent reply other threads:[~2024-06-03 13:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-02 11:54 Kirill A. Shutemov
2024-06-03 13:37 ` Dave Hansen [this message]
2024-06-04 11:37 ` Kirill A. Shutemov
2024-06-04 19:34 ` Sean Christopherson
2024-08-28 13:34 ` Edgecombe, Rick P
2024-09-11 23:31 ` 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=8992921e-7343-4279-9953-0c042d8baf90@intel.com \
--to=dave.hansen@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=hpa@zytor.com \
--cc=jpoimboe@kernel.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=kys@microsoft.com \
--cc=linux-coco@lists.linux.dev \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=wei.liu@kernel.org \
--cc=x86@kernel.org \
/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
all inboxes | Powered by JetHome®