Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kristina Martšenko" <kristina.martsenko@arm.com>
Cc: "Oliver Upton" <oupton@kernel.org>,
	kvmarm@lists.linux.dev, "Marc Zyngier" <maz@kernel.org>
Subject: Re: [RFC 10/12] arm64: Support TLBIP instructions
Date: Thu, 01 Oct 2026 12:40:27 +0000	[thread overview]
Message-ID: <20261001124027.AF2FE1F00899@smtp.kernel.org> (raw)
In-Reply-To: <20261001110655.461473-11-kristina.martsenko@arm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] arm64: tlbflush: ipas2e1is() calls __tlbi instead of __tlbip, dropping domain ID
- [High] arm64: tlbflush: macro precedence bug in __tlbip() destroys domain ID
--

commit f57328676d294e62d35d640905ead85c0b306e45
Author: Kristina Martšenko <kristina.martsenko@arm.com>

arm64: Support TLBIP instructions

This commit modifies the TLBI helper functions in tlbflush.h to support
issuing TLBIP instructions when requested. It introduces the __tlbip macro
to pass 128-bit arguments containing a TLBI domain ID in two consecutive GPRs.

> diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h
> index b51df8e0ce631..dac35568570ff 100644
> --- a/arch/arm64/include/asm/tlbflush.h
> +++ b/arch/arm64/include/asm/tlbflush.h
> @@ -41,11 +41,26 @@
>  
>  #define __tlbi(op, ...)		__TLBI_N(op, ##__VA_ARGS__, 1, 0)
>  
> +#define __tlbip(op, arg) do {		\
> +	register u64 low asm ("x0") = (u64)arg;					\
> +	register u64 high asm ("x1") = (u64)(arg >> 64);			\

[Severity: High]
Does this macro expansion drop the upper 64 bits of arg when passed an
expression?

When __tlbip_user() calls this macro with a bitwise OR expression, the
expansion for the high register becomes:

    (u64)((arg) | (u128)USER_ASID_FLAG >> 64)

Because the bitwise shift operator (>>) has higher precedence than bitwise OR
(|), the shift applies only to USER_ASID_FLAG, yielding 0. This evaluates to
(u64)((arg) | 0), which truncates the 128-bit argument to its lower 64 bits and
causes the domain ID to be lost.

Should the macro definition enclose arg in parentheses, like ((arg) >> 64)?

> +										\
> +	asm (ARM64_ASM_PREAMBLE ".arch_extension tlbid\n"			\
> +	     "tlbip " #op ", %0, %1\n"						\
> +	  : : "r" (low), "r" (high));						\
> +} while (0)
> +
>  #define __tlbi_user(op, arg) do {						\
>  	if (arm64_kernel_unmapped_at_el0())					\
>  		__tlbi(op, (arg) | USER_ASID_FLAG);				\
>  } while (0)
>  
> +#define __tlbip_user(op, arg) do {						\
> +	if (arm64_kernel_unmapped_at_el0()) {					\
> +		__tlbip(op, (arg) | (u128)USER_ASID_FLAG);			\
> +	}									\
> +} while (0)
> +

[ ... ]

> -static __always_inline void ipas2e1is(u64 arg)
> +static __always_inline void ipas2e1is(bool tlbip, u128 arg)
>  {
> -	__tlbi(ipas2e1is, arg);
> +	if (tlbip)
> +		__tlbi(ipas2e1is, arg);

[Severity: High]
Does this branch mistakenly issue a regular TLBI instruction instead of a
TLBIP?

By calling __tlbi() instead of __tlbip() when tlbip is true, the 128-bit
argument is truncated, the domain ID is discarded, and domain-targeted stage-2
TLB invalidations will fail to apply to the correct domain.

Should this use __tlbip(ipas2e1is, arg) instead?

> +	else
> +		__tlbi(ipas2e1is, (u64)arg);
>  }
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261001110655.461473-1-kristina.martsenko@arm.com?part=10

  reply	other threads:[~2026-10-01 12:40 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 11:06 [RFC 00/12] arm64: Add support for TLBI domains Kristina Martšenko
2026-10-01 11:06 ` [RFC 01/12] arm64: sysreg: Add definitions for FEAT_TLBID Kristina Martšenko
2026-10-01 11:06 ` [RFC 02/12] arm64: Detect FEAT_TLBID Kristina Martšenko
2026-10-30  4:59   ` Linu Cherian
2026-10-01 11:06 ` [RFC 03/12] KVM: arm64: Hide TLBID from guest sysregs Kristina Martšenko
2026-10-12  8:12   ` Steffen Eiden
2026-10-14 13:45     ` Kristina Martšenko
2026-10-01 11:06 ` [RFC 04/12] KVM: arm64: Hide TLBID from guest instructions Kristina Martšenko
2026-10-01 11:06 ` [RFC 05/12] ACPICA: Add TLBI table definition Kristina Martšenko
2026-10-01 11:56   ` sashiko-bot
2026-10-01 11:06 ` [RFC 06/12] ACPI: TLBI: Parse domains from table Kristina Martšenko
2026-10-01 12:04   ` sashiko-bot
2026-10-19  7:38   ` Jinqian Yang
2026-10-01 11:06 ` [RFC 07/12] arm64: tlbid: Set up CPU domain bitmaps Kristina Martšenko
2026-10-19  7:50   ` Jinqian Yang
2026-10-01 11:06 ` [RFC 08/12] efi/arm: Check return value of init_new_context() Kristina Martšenko
2026-10-04  8:00   ` Ard Biesheuvel
2026-10-01 11:06 ` [RFC 09/12] arm64: tlbid: Track the TLBI domain of a task Kristina Martšenko
2026-10-01 11:06 ` [RFC 10/12] arm64: Support TLBIP instructions Kristina Martšenko
2026-10-01 12:40   ` sashiko-bot [this message]
2026-10-19  6:51   ` Jinqian Yang
2026-10-01 11:06 ` [RFC 11/12] arm64: tlbid: Pass domain to TLBI instructions Kristina Martšenko
2026-10-01 12:54   ` sashiko-bot
2026-10-01 11:06 ` [RFC 12/12] arm64: tlbid: Add documentation Kristina Martšenko
2026-10-03 16:12 ` [RFC 00/12] arm64: Add support for TLBI domains Marc Zyngier
2026-10-05  8:40   ` Oliver Upton
2026-10-04 18:06 ` Zi Yan
2026-10-05  6:29   ` Will Deacon
2026-10-05 18:13     ` Zi Yan
2026-10-05 11:07   ` Catalin Marinas
2026-10-19  8:52 ` Jinqian Yang
2026-10-19  9:27   ` Marc Zyngier
2026-10-27 14:22   ` Kristina Martšenko
2026-10-29 12:06 ` Linu Cherian

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=20261001124027.AF2FE1F00899@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kristina.martsenko@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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