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 A04633F6C2A for ; Thu, 23 Jul 2026 23:20:56 +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=1784848863; cv=none; b=f2s7KRJ3WmxnUn9l8u7TDZrJdzfx0kHC9K7P9D/zlzkZpoVwJPXhT7NW4pItG4xHNbSPL4Ya3+e/4Iv7NoLL9BL7KjSP2lTGFdVsVsO0ukWh09/nV14GdqIK1ZZFeRQci3cYIHtUV0tttSuCazbA0dcoo5nmORyo415xuwWd4Zs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784848863; c=relaxed/simple; bh=gy6nBQCj2DsNZ+5th6Bp2uFRb5ISkBrzMrBAYsb7tLs=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type; b=eMcSZGK7TszcL1Mr2vASj4CVDlUbuQpYWcdYEpo9lTGBHHXdw3M63+lsvdZB+MOfywd3uLwOsEtaKXYlu53atpPgz5yeemkrXrmkjt6tEGL9LA5P/7HXQvItLTmJm/iQBUs2Q/CL7VF4EO66V2J+1SrQPXXhNG5T3fNNfoI0zt0= 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=c6zWkTi7; 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="c6zWkTi7" 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=DS/VCUC/4IbrLXtLc7lyjjd6XVFRv5g2nDbRWVShaGk=; b=c6zWkTi72rgX7bdnOSCCyIl7Sg MuapfGPST4KEJJTjmVDwKfci5Lubitq2W7jBsAXcONJidDySs/YsF29RWZHkv1PKBPYnQ1T3qLPDz vn6/jB3gWw5Ybsl3M4IS+/wTY3b5+GV2po7fvladXMLRhIhKVCSL1/ke+dhI/smx5gsi8oqaIY0ZX DM3djyFfAM5NURGH49eu5uMUDJymz9pYilvqjAW+4H/jpwN1eRLnydzrW5EVWcSeDPzlDF0Xize22 Ow/zJDKjy0ZEpWYBqNV85T+RbatDggswEtD+kqXh6X07rNr3P4AyboB62AaPRb7e0YEm7CLeZTc4H z4+j0a4Q==; 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 1wn2iT-003e1x-CQ; Fri, 24 Jul 2026 01:20:37 +0200 Received: from webmail.service.igalia.com ([192.168.21.45]) by mail.igalia.com with esmtp (Exim) id 1wn2iQ-001vgG-TF; Fri, 24 Jul 2026 01:20:37 +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 1wn2iQ-000000031qI-2r1S; Fri, 24 Jul 2026 01:20:34 +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:20:34 -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: <0F3A1121-208F-4F71-8C88-BEAE7CB50E75@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> <0F3A1121-208F-4F71-8C88-BEAE7CB50E75@zytor.com> Message-ID: <1251d04d8da8e2ecaba28eaaeab4a13a@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:45, 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. >> > > Also, this is silly. Instead of adding a whole separate test, just do "test %3,%3" before the repe to set ZF and let the REPE skip. This is elegant; done. Thanks! -- Mauricio