From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 124A22F39B8 for ; Tue, 7 Jul 2026 14:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783435620; cv=none; b=jKxhvAv4To9a7NYzMxFShjdeqIkap4wWlprd53OKMxsAZWv3J5euq1rN/+kjdBxsHT4Cg0G22VcB013plEB6jJPwww5q5C8s9A7K5lW9BBNg9T56r9fbyNhPpS6cgKfTkrfL1fAowdAP5D/LP63N7ySVgyujc1Pc+TCiNlDRsoI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783435620; c=relaxed/simple; bh=dbEhWFYQcuKtmA70mOptSUK8mT123phz+xATTayPUfk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FVd2tI4PaOf1wLsC5iqh25GZCR9+4Stmq00BeSidDIpNTT4FNUnQby3Y4+FxcKuFOLSwH9D2cmoEOpSNR2t7t/xwlG40Rp/PYGyTCmySMHmatpXhJQwcmsKMZsLvflhw5veReHamNEYXrV17/z6D9MRhTzzsIth6rMIo/xv+LwI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qZFjjmUy; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qZFjjmUy" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2c80f89b64bso75825855ad.2 for ; Tue, 07 Jul 2026 07:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783435618; x=1784040418; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=HufNVYu34je8HZzz4w1ytu+7VhpoP+vTfH7cDlFEijc=; b=qZFjjmUynfjxrsqgu/khQ3Q8LO1qM1jBb8s8Gj+7Zb7nNqPrEc3UjrKRzEYuKqqi/R gjf5G+SobBeWYLbPGYZAEn4f0RleCZpzmxg8C6dSw0XQXZd87VoLxQiOaS+oZGctqzse QHp3g1zpUF/VBBzOB4HMpz2TWTzsxf48WsyQf5qKJSTUuKYk/7ZYMw2VrICVP+ASsZrz ii3VtxQPRDmJ+PdJnPOUt2Zp1EyY+IoyijYTMGIkQ8tCWsDcZL8eYei7hyFTW68x4pYv waiFKqdpcbkHcoQImYElEhbWxzvw4+p9jYOcoRlLxqTY6wCAuvScBUp2hOFgAnx04OZC g6XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783435618; x=1784040418; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HufNVYu34je8HZzz4w1ytu+7VhpoP+vTfH7cDlFEijc=; b=m8CCd1Go/nruMp3AIrtx4SEWA/szf/C+gH/jJkrB3vQbWt8SPWVi/7sbPlXPUSg5Nc nmdlYMIdFHJyzqGH4PWsmHeuzb/80Ki4U8eotsJsYViF8OE+g4vPsd2aw94IgiDTQaZN gAdCQRV8xkFh+UBywPAIL/PI8XQtaV4poHB3M97R5SdoO/gf00RoQWJZ0pjxEYcLph0y 8iGf60U+Dah6Fk7v1T8y0Wr/vZYEM41YdXdomXMo76mIup2C1fAU8PNDBIOptyawZkwd FTwiz5xZMD6nqZ97q9snTONEb4VuSuV4NDTb9YKv7byCvGywyj4GYE+nSv3laHoOape2 Ms3w== X-Forwarded-Encrypted: i=1; AHgh+RoCcaEK/bTvR0wqLpaDgNI4MdXUK9N3RM9VjB5JIVYp8qMKXyT4GfApWP2y4OSVyWycS+j9Pl3tVXp0lkE=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2o4X2Dv0+yEeQO5lTIiuI1kzc0CNhtU7uUJVbMBXX49ujjfUt /w9KDrxbMSururnKqMJqN56G3b1BwUlcJ+XwHSk6bEW4mOrk/GIq2Y2LY4mZ1UWoNELt5wsPpB3 cvm9tsA== X-Received: from plse11.prod.google.com ([2002:a17:902:b78b:b0:2ca:d667:90e3]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:eccb:b0:2c9:b396:1a55 with SMTP id d9443c01a7336-2ccbe611f6amr53537385ad.12.1783435618181; Tue, 07 Jul 2026 07:46:58 -0700 (PDT) Date: Tue, 7 Jul 2026 07:46:57 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260701110547.764083-1-kirill@shutemov.name> <20260701110547.764083-3-kirill@shutemov.name> <20260701180033.6e9c07aa@pumpkin> Message-ID: Subject: Re: [PATCH v5 2/3] x86/insn-eval: Add insn_assign_reg() helper From: Sean Christopherson To: Kiryl Shutsemau Cc: David Laight , Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Paolo Bonzini , Kuppuswamy Sathyanarayanan , Kai Huang , Xiaoyao Li , Rick Edgecombe , Binbin Wu , Andi Kleen , Dan Williams , Borys Tsyrulnikov , kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Thu, Jul 02, 2026, Kiryl Shutsemau wrote: > On Wed, Jul 01, 2026 at 06:00:33PM +0100, David Laight wrote: > > Or be even more specific and use '& 0xffffffff' rather than a cast. > > Particularly since the casts of the RHS in the byte/short cases aren't > > needed at all. > > I'd rather keep the body exactly as KVM has it today. +1. My main argument for casting in the 1-byte and 2-byte cases is consistency above all else, using a mask for the 4-byte case defeats that goal. > This is now a straight move + rename with no functional change, and the v4 > attempt to rewrite it with arithmetic is precisely what introduced the > AH/CH/DH/BH clobber Sashiko flagged. Tidying the casts turns it back into a > rewrite and diverges from the form KVM has shipped for years. Feel free to > submit a separate cleanup on top if you feel strongly. > > Updated patch below; I'll fold it into v6. > > -- >8 -- > Subject: [PATCH] x86/insn-eval: Move assign_register() out of KVM as insn_assign_reg() > > KVM's instruction emulator has a small helper, assign_register(), that > writes a value into a register following the x86 rules for writes to > general-purpose registers: an 8- or 16-bit write leaves the rest of the > register untouched, a 32-bit write zero-extends the result to 64 bits, > and a 64-bit write replaces the whole register. > > The TDX guest #VE handler needs the same logic for port I/O emulation > to get 32-bit zero-extension right. Rather than add a third copy of > the same switch, move the helper verbatim to , rename > it to insn_assign_reg(), and route KVM's callers through it. > > Add to the header's includes so it builds standalone in > callers that have not pulled it in transitively. > > No functional change. > > Signed-off-by: Kiryl Shutsemau (Meta) > Cc: stable@vger.kernel.org # prerequisite for the following 32-bit port I/O zero-extension fix > --- Acked-by: Sean Christopherson