Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kiryl Shutsemau" <kirill@shutemov.name>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v5 1/3] x86/tdx: Fix off-by-one in port I/O handling
Date: Wed, 01 Jul 2026 11:23:27 +0000	[thread overview]
Message-ID: <20260701112327.5CEAB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260701110547.764083-2-kirill@shutemov.name>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] SEV-ES vc_handle_ioio incorrectly zero-extends 8-bit and 16-bit IN instructions.
--

commit df84d995a704008239da9f3f6b57944d2f071dc7
Author: Kiryl Shutsemau (Meta) <kas@kernel.org>
x86/tdx: Fix off-by-one in port I/O handling

This commit fixes an off-by-one error in the GENMASK calculation for port
I/O handling in the TDX module. It corrects the mask to prevent it from
being one bit too wide for all I/O sizes.

Link: https://lore.kernel.org/all/CAKw_Dz96rfSQc6Rn+9QBcUFHhmkK+9zu+P=bxowfZwxrATCBRg@mail.gmail.com/

> diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
> index 29b6f1ed59ec5..b8bbd715fb624 100644
> --- a/arch/x86/coco/tdx/tdx.c
> +++ b/arch/x86/coco/tdx/tdx.c
> @@ -694,7 +694,7 @@ static bool handle_in(struct pt_regs *regs, int size, int port)
>  		.r13 = PORT_READ,
>  		.r14 = port,
>  	};
> -	u64 mask = GENMASK(BITS_PER_BYTE * size, 0);
> +	u64 mask = GENMASK(BITS_PER_BYTE * size - 1, 0);
>  	bool success;
>  
>  	/*

[ ... ]

While reviewing the port I/O handling changes here, I noticed a pre-existing
issue in the related SEV-ES code:

arch/x86/coco/sev/vc-shared.c:vc_handle_ioio() {
[ ... ]
> 		if (exit_info_1 & IOIO_TYPE_IN) {
> 			if (!ghcb_rax_is_valid(ghcb))
> 				return ES_VMM_ERROR;
> 			regs->ax = lower_bits(ghcb->save.rax, bits);
                        ^^^^^^^^

[Severity: High]
This is a pre-existing issue, but does this incorrectly zero-extend 8-bit and
16-bit in instructions?

When a guest executes an 8-bit or 16-bit in instruction, it triggers a #VC
exception (SVM_EXIT_IOIO) and calls vc_handle_ioio(). The function extracts
the result using lower_bits(ghcb->save.rax, bits) and assigns it directly to
the 64-bit regs->ax field, overwriting the entire register.

This violates x86-64 architectural semantics, which dictate that 8-bit and
16-bit register writes must leave the upper bits untouched.

Can this cause data corruption or crashes in guest code if the compiler or
assembly relies on the upper bits of rax being preserved across the in
instruction?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260701110547.764083-1-kirill@shutemov.name?part=1

  reply	other threads:[~2026-07-01 11:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 11:05 [PATCH v5 0/3] x86/tdx: Fix port I/O handling bugs Kiryl Shutsemau
2026-07-01 11:05 ` [PATCH v5 1/3] x86/tdx: Fix off-by-one in port I/O handling Kiryl Shutsemau
2026-07-01 11:23   ` sashiko-bot [this message]
2026-07-01 11:05 ` [PATCH v5 2/3] x86/insn-eval: Add insn_assign_reg() helper Kiryl Shutsemau
2026-07-01 14:59   ` Sean Christopherson
2026-07-01 17:00     ` David Laight
2026-07-01 11:05 ` [PATCH v5 3/3] x86/tdx: Fix zero-extension for 32-bit port I/O Kiryl Shutsemau

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=20260701112327.5CEAB1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kirill@shutemov.name \
    --cc=kvm@vger.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