From mboxrd@z Thu Jan 1 00:00:00 1970 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 540F93BC664 for ; Thu, 23 Jul 2026 23:27:00 +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=1784849222; cv=none; b=uEfwVy00hNTUHg4+MUpew+ZzXqNCuI6teCAVF9CYficO98MQjB+ylFbGtvJKJZN3T16lxZbd4YZoyVU0DmAQ4ompkmJxwpktzuDZxTq3YjM9L56C0USBs/2727qPjYTn8UgdAZ1trIXM85qN6Gl/BvJ8N4aCIOj2ZLloPP3mDTo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784849222; c=relaxed/simple; bh=2gXCUGiqI6WEWPh/YZ89gT82e4W8K0L3inDeGT8pLFE=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type; b=OVqIv3rjGCg2mx1RDdmfH9VGH8V3Q817WhcQMxVyzTVV9rIGA4I6LQ7g7K1IXd9pJcf8UcPL174QQXzDXu1Is6qJpb2NGpcRZeTwI+3P0GsmUUTx+8AywmYxojkznbH7PHzmTpkep+htkyVjtgLTkSERyuOiscI3lsAZAnP6ptw= 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=cr/zucLa; 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="cr/zucLa" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:Message-ID:Subject:Cc:To :From:Date:MIME-Version:From:Reply-To; bh=fLZIWX2wSccqFNik9bhUsUlx9S80wKp6f12wJ1NBHj8=; b=cr/zucLaHLMdD0S1h4riL0nIts y9InaI9oC8hrKeP2gFjWw0b0i9wSmasJfpAB4xnXGfLPgtnp5mLkvrJ3rIGzB2bR+iTQivVTKjl5j jvXq/qnpoZrCAX6GfXffP9sL7/Ne5nvBUBxKsupykJC3Zm4pU6BzgBpn4teszoaokNz7yWfvy11lb D057F9tzX/JozgyY1E3QxOw4GiJ6GMlbAsuCsIPlICBumzEEzYMCLY8eS3pSYRJbLv6CaqSkifuq/ Ir88SDy8SpbFTp0XZs5uqeFvFWHJqSy4mZ0YELdNC8Vlv/LinUBe/R5GPrebmCarOR81IfKhuHNGu aONrK+Yg==; Received: from maestria.local.igalia.com ([192.168.10.14] helo=mail.igalia.com) by fanzine2.igalia.com with esmtps (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wn2oM-003e8A-1v; Fri, 24 Jul 2026 01:26:42 +0200 Received: from webmail.service.igalia.com ([192.168.21.45]) by mail.igalia.com with esmtp (Exim) id 1wn2oJ-001vz2-GQ; Fri, 24 Jul 2026 01:26:41 +0200 Received: from localhost ([127.0.0.1] helo=webmail.igalia.com) by webmail.service.igalia.com with esmtp (Exim 4.98.2) (envelope-from ) id 1wn2oJ-000000031ty-1Ci6; Fri, 24 Jul 2026 01:26:39 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 23 Jul 2026 20:26:39 -0300 From: Mauricio Faria de Oliveira To: "H. Peter Anvin" Cc: Borislav Petkov , Thomas Gleixner , Ingo Molnar , Dave Hansen , x86@kernel.org, Juergen Gross , Alexey Dobriyan , Boris Ostrovsky , kernel-dev@igalia.com, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: Re: [PATCH v7 2/5] x86/asm: add volatile, clobbers and zero-length check in inline memcmp In-Reply-To: <829A5D01-29A2-454E-AE78-AEAD8FC597E6@zytor.com> References: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@igalia.com> <20260721-pvh-kasan-inline-v7-2-38979a50cef0@igalia.com> <20260722170334.GCamD35gwrCng30WH1@fat_crate.local> <829A5D01-29A2-454E-AE78-AEAD8FC597E6@zytor.com> Message-ID: <182aa568ea05a0f1297d307a169eb687@igalia.com> X-Sender: mfo@igalia.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Report: NO, Score=-2.2, Tests=ALL_TRUSTED=-3,BAYES_50=0.8 X-Spam-Score: -21 X-Spam-Bar: -- On 2026-07-22 15:48, H. Peter Anvin wrote: > On July 22, 2026 10:03:34 AM PDT, Borislav Petkov wrote: >>hpa in To:. >> >>On Tue, Jul 21, 2026 at 12:56:43PM -0300, Mauricio Faria de Oliveira wrote: >>> Add the volatile qualifier and clobbers parameter to prevent bugs with >>> instruction reordering and optimization. >>> >>> Also check the zero-length case, as the 'repe' prefix does not run the >>> 'cmpsb' instruction if the 'count' register is zero, which doesn't set >> >>Please use capital letters for insns: REPE, CMPSB and you don't need to put >>words in '' - it reads fine without them. >> >>> the condition-code/zero flag, so the result is based on a stale flag. >>> >>> Those are pre-existing issues found by Sashiko. >>> >>> Link: https://sashiko.dev/#/patchset/20260701-pvh-kasan-inline-v6-0-ba99045dfa9f%40igalia.com >>> Signed-off-by: Mauricio Faria de Oliveira >>> --- >>> arch/x86/include/asm/shared/string.h | 8 ++++++-- >>> 1 file changed, 6 insertions(+), 2 deletions(-) >>> >>> diff --git a/arch/x86/include/asm/shared/string.h b/arch/x86/include/asm/shared/string.h >>> index 02b92927553f7b8e1c87e6122bbaa70439e57ea7..166274e44f3cb49e3dccab3cdac281d67aef5d44 100644 >>> --- a/arch/x86/include/asm/shared/string.h >>> +++ b/arch/x86/include/asm/shared/string.h >>> @@ -11,8 +11,12 @@ static __always_inline int __inline_memcmp(const void *s1, const void *s2, size_ >>> { >>> bool diff; >>> >>> - asm("repe cmpsb" >>> - : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)); >>> + if (len == 0) >>> + return 0; >>> + >>> + asm volatile("repe cmpsb" >>> + : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len) >>> + : : "cc", "memory"); >>> >>> return diff; >>> } >> >>So this is a fix which should probably go to stable, I think. Going back into >>git history, it points to >> >> 62bd0337d0c4 ("Top header file for new x86 setup code") >> >>from 2007. And we have carried it this way through the years and who knows >>what hit this or not. So please make this the first patch in your set - you >>can even send it separately so that I can get route it through stable. >> >>Then you can base the rest ontop. >> >>Thx. >> > > I suspect that the zero-length case simply can't happen in the real code, but who knows; the use of the code has expanded over the years. Agreed, and its use may expand more in the future, being in a header (e.g., this very series :) Thanks, -- Mauricio