From nobody Fri Jul 24 21:53:03 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0EB026F2B0 for ; Thu, 23 Jul 2026 23:08:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784848094; cv=none; b=UeWi/LPf5RVdhNHJ4rvoyR4lRC5p7SUMTBJzOkWwvcXoGz11DnDRs3yPX65dk7wnJ81UKLOrU4B8eQ3nx+ufsQHCoJ3rF505DyyJJ4wJ/7d5BowCibrI5m4t3P3sMAzhvEZnvEfoqtMrszvBZqH827rtwtCznFhi6XmLgLXuO0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784848094; c=relaxed/simple; bh=gO6d79T2Qk9JaTNX3p95ymYJxDfmXBuf+X6Y2+q0xfA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=e2XmeRpyIYfP2RFPdpOJ0nKK1Mx2n4dPoZZP5RAKpWCDqoGbpVCwY7qugSoW/JvUOFlJ0HD5AjXWXoebbx9CR6AI0I+W/hfgnCFLPkX2y2Ilms40qOMa/qGQg3Y6C3wHB7Fe4McxN03K35vMD7axyCxncdKbLoPnLy6xjih/fY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=BKhvwe5W; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="BKhvwe5W" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=Yjprp8bqDldRF7sb/Q4Hs8UMRc58P2vIPxLzEudT7Gk=; b=BKhvwe5WJLQiNcFWvjDQAWtR6V qENIYdAweYICUbl0BmzlZDH7EhUeS8A6wJlvsFx1ZJ9HptL+cpCBSIb1fv6uxy9r5Txk7KZXqkcxS 7gjZBYVTrTNtCnmWEzkwgMVBFcpmP/KGuQlFqElU2xf6Aonx3q6HHwja9JKDliZlk7gIC6kvIeAiX Dr+B8evu0mVoBIZ/ZhCktWBLtGAjB6gKUaeEDwct3WW0ENeE3V76KkCbG5lDnSyE5DEBXEPMvKEmd L77/ubmhK4n/jv5Qj+0iLq8tt1Hq5nIi8egcrDgDbDfWOxV6WEZVcSiw4wBOfW7TPP4WYzDPzCGZw odiTCdfA==; Received: from 186-249-149-197.shared.desktop.com.br ([186.249.149.197] helo=[127.0.1.1]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wn2WL-003dkS-2q; Fri, 24 Jul 2026 01:08:05 +0200 From: Mauricio Faria de Oliveira Date: Thu, 23 Jul 2026 20:08:04 -0300 Subject: [PATCH v2] x86/boot: add volatile, clobbers and zero-length test in memcmp() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260723-x86-memcmp-asm-v2-1-d93ecb43797f@igalia.com> X-B4-Tracking: v=1; b=H4sIANOeYmoC/x3MQQqAIBBA0avErBuwEUq7SrQQm2oWmiiEEN09a fkW/z9QOAsXmLsHMt9S5IoN1HfgTxcPRtmagRSNaiKN1YwYOPiQ0JWAypDVE1uv7QAtSpl3qf9 wWd/3AylkPUBgAAAA X-Change-ID: 20260723-x86-memcmp-asm-082937e9c391 To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Jan Beulich , Brian Gerst Cc: kernel-dev@igalia.com, linux-kernel@vger.kernel.org, Mauricio Faria de Oliveira X-Mailer: b4 0.14.2 Add the volatile qualifier and clobbers parameter to prevent bugs with instruction reordering and optimization. Also add TEST for the zero-length case to set ZF, as, if the count register is zero, the REPE prefix does not run the CMPSB instruction, leaving the ZF flag undetermined. Suggested-by: Borislav Petkov Closes: https://sashiko.dev/#/patchset/20260701-pvh-kasan-inline-v6-0-ba990= 45dfa9f%40igalia.com Link: https://lore.kernel.org/all/20260718150230.GAaluVhlozNI__9IsA@fat_cra= te.local/ Fixes: 62bd0337d0c4 ("Top header file for new x86 setup code") Link: https://lore.kernel.org/all/20260722170334.GCamD35gwrCng30WH1@fat_cra= te.local/ Signed-off-by: Mauricio Faria de Oliveira --- Sending this patch separately from its previous series ("v1" below) as requ= ested [1]. The backports for 6.12 and earlier will be slightly different due to commit c6c973dbfa5e ("x86/asm: Remove code depending on __GCC_ASM_FLAG_OUTP= UTS__"). I'd be happy to handle it. The disassembly of memcmp() in arch/x86/boot/string.o is as expected: 32: 66 85 c9 test %cx,%cx 35: f3 a6 repz cmpsb %es:(%edi),%ds:(%esi) 37: 0f 95 c0 setne %al And bzImage still boots. [1] https://lore.kernel.org/all/20260722170334.GCamD35gwrCng30WH1@fat_crate= .local/ Changes in v2: - Remove this patch from "v1" series (Borislav Petkov). - Change some words' capitalization/quotes (Borislav Petkov). - Change zero-length check from C to asm (H. Peter Anvin). - Link to "v1": https://lore.kernel.org/all/20260721-pvh-kasan-inline-v7-2-= 38979a50cef0@igalia.com/ --- arch/x86/boot/string.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c index ac0f900ebc47efa81c92e1bb2010ea41677899c4..6827551720dd9b96afe8c55a051= 401d6cdc6f05e 100644 --- a/arch/x86/boot/string.c +++ b/arch/x86/boot/string.c @@ -32,8 +32,10 @@ int memcmp(const void *s1, const void *s2, size_t len) { bool diff; - asm("repe cmpsb" - : "=3D@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)); + asm volatile("test %3, %3\n\t" + "repe cmpsb" + : "=3D@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len) + : : "cc", "memory"); return diff; } =20 --- base-commit: b4515cf4156356e8f4fe6e0fdc17f59adab9772f change-id: 20260723-x86-memcmp-asm-082937e9c391 Best regards, --=20 Mauricio Faria de Oliveira