mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Borislav Petkov <bp@kernel.org>
Cc: X86 ML <x86@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
	"Borislav Petkov (AMD)" <bp@alien8.de>,
	Rik van Riel <riel@surriel.com>, "H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH] x86/tlb: Simplify choose_new_asid()
Date: Thu, 3 Apr 2025 13:36:20 +0200	[thread overview]
Message-ID: <Z-5ytG_1vnf3uj8t@gmail.com> (raw)
In-Reply-To: <20250403085623.20824-1-bp@kernel.org>


* Borislav Petkov <bp@kernel.org> wrote:

> From: "Borislav Petkov (AMD)" <bp@alien8.de>
> 
> Have it return the two things it does return:
> 
>  - a new ASID and
>  - the need to flush the TLB or not,
> 
> in a struct which fits in a single 32-bit register and whack the IO
> parameters.
> 
> No functional changes.
> 
> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
> ---
>  arch/x86/mm/tlb.c | 63 +++++++++++++++++++++++++----------------------
>  1 file changed, 34 insertions(+), 29 deletions(-)
> 
> diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
> index e459d97ef397..d00ae21d0ee2 100644
> --- a/arch/x86/mm/tlb.c
> +++ b/arch/x86/mm/tlb.c
> @@ -215,16 +215,20 @@ static void clear_asid_other(void)
>  
>  atomic64_t last_mm_ctx_id = ATOMIC64_INIT(1);
>  
> +struct new_asid {
> +	unsigned int asid	: 16;
> +	unsigned int need_flush : 1;
> +};
>  
> -static void choose_new_asid(struct mm_struct *next, u64 next_tlb_gen,
> -			    u16 *new_asid, bool *need_flush)
> +static struct new_asid choose_new_asid(struct mm_struct *next, u64 next_tlb_gen)

Nice!!

Note how the cleaned up return signature not only makes the code easier 
to read, but also helps the compiler generate better code:

  # arch/x86/mm/tlb.o:

   text	   data	    bss	    dec	    hex	filename
   9341	    753	    516	  10610	   2972	tlb.o.before
   9213	    753	    516	  10482	   28f2	tlb.o.after

Personally I also like the non-bool new_asid::need_flush easier to read 
in this 'HW interface' context.

Thanks,

	Ingo

  reply	other threads:[~2025-04-03 11:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03  8:56 Borislav Petkov
2025-04-03 11:36 ` Ingo Molnar [this message]
2025-04-03 11:39   ` Borislav Petkov
2025-04-03 11:48 ` [tip: x86/mm] x86/tlb: Simplify choose_new_asid() and generate better code tip-bot2 for Borislav Petkov (AMD)

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=Z-5ytG_1vnf3uj8t@gmail.com \
    --to=mingo@kernel.org \
    --cc=bp@alien8.de \
    --cc=bp@kernel.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=riel@surriel.com \
    --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®