From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB277CDE008 for ; Thu, 25 Jun 2026 10:10:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sLRVkQfNkbmqQPg5/CoxfYV5Wz3dafUxaadB1SlbK4A=; b=lw7thnutCgVb+v4mX1fqCAuMTJ A1E0dWOOAzrh3wMgSHhbX+u8Gd1B63pGrEd9stsaLUKBW8n5PNKU0BLBHZ+YCWEe3IMhk90KJ0Zmm lrJaqwFgem33lR8Dhxstw9DoTIVUygaHev15grHtplfwOAqEqH2EUe9prnIefOwCe1IjabnCjlUXb eJ0TwCGVJCds33pQH9TTeMzEQJ8m1nxymtvZ7SbYGKFGaWFJUUIbkFDhzyMdhGppfRWOFIX5rhjoP bGR+mUfTEcvdoGmA7rJNVYznbQ+sARDgWtfj6Ifltu2Pva/W4cbqkM3XLptyeTvai42wmQoIDYYFS wR3OyH5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wch2Q-00000008xtA-3ETX; Thu, 25 Jun 2026 10:10:26 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wch2P-00000008xsy-1Uek for linux-arm-kernel@lists.infradead.org; Thu, 25 Jun 2026 10:10:25 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 69E1160123; Thu, 25 Jun 2026 10:10:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E9B11F000E9; Thu, 25 Jun 2026 10:10:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782382224; bh=sLRVkQfNkbmqQPg5/CoxfYV5Wz3dafUxaadB1SlbK4A=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=ow0Y7wLttlgW6E0S9Xkf/kZHeUCKqBDxGluB/V9GQJTJk+ako8Ek3rxAZGwzh9hPS SpgiWKOXU0UOVoKiPjKk2wUv8tfvw3spG2Cu3ZzbOtBTNXfzKaNS7oMk2dnDykb4TB 5HmcHBkk9tVjdgh+XT9IKb57NhVPRIdBryYPw1BeBYOuq6d22OKXI/Lqv3UN1Yj+/9 uMZc6eViNCv9mNf7+77G3qNQdcHTfprCLBcxvx40R5ePEQAYBt+ysjyZOSZn1xjW/I Hpb+4E4kC4BfDBK16+M8MpMEWz4x0kUYKaaIsPUOBM1QzTelZtG//Oi8EeIP9m8m7Q dedHMAldbW6dw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wch2L-0000000FvsZ-3cAt; Thu, 25 Jun 2026 10:10:22 +0000 Date: Thu, 25 Jun 2026 11:10:21 +0100 Message-ID: <86fr2bq6b6.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Steffen Eiden , Catalin Marinas , Will Deacon , Shuah Khan , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] KVM: arm64: Fix sign-extension of MMIO loads In-Reply-To: References: <20260622190701.2039766-1-fuad.tabba@linux.dev> <20260622190701.2039766-2-fuad.tabba@linux.dev> <86tsqtqu9u.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: fuad.tabba@linux.dev, oupton@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, seiden@linux.ibm.com, catalin.marinas@arm.com, will@kernel.org, shuah@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 23 Jun 2026 14:51:49 +0100, Fuad Tabba wrote: > > My reading of the ARM ARM is that the byte reversal is keyed on the access > size there too. It lives in Mem{size}, with the register width handled > separately by SignExtend(regsize): > > data = Mem[address, 2]; // byte-reversed by the access size, BE > X[t] = SignExtend(data, regsize); > > So vcpu_data_host_to_guest(..., len) swapping by len matches the Mem-side > reversal. Swapping by the register width would reorder bytes that were never > loaded. An LDRSH into Wt reads 2 bytes but would bswap 4: the halfword > reaches the helper as 0x0180 host-native, cpu_to_be32 turns it into > 0x80010000 instead of the 0x8001 cpu_to_be16 gives, and it never sign-extends > to 0xffff8001. > > If that reading holds, none of the helper's ops are individually wrong, and > the only bug was the order, with the sign-extend running before the swap and > the width mask then dropping it. But I've gone round in circles on endianness > before (to say the least), so please say if I've done it again. That's quite convincing. And the quoted pseudocode is much easier to reason about than the current blurb in the commit message. For reference, J1.2.3.111 Mem{}() is the relevant bit of the M.b spec and clearly shows that the access is done LE, and only then byteswapped. Can you please repaint the commit log to describe things in those terms? Also, can you augment your test to cover for BE accesses from the guest if the HW supports it? Thanks, M. -- Without deviation from the norm, progress is not possible.