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 CA02931E828 for ; Thu, 23 Jul 2026 23:17:19 +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=1784848641; cv=none; b=BfsgHiu7fMuDWcaJhnnTGJ2h5ACU/dFOy5yKmwe3VPVCxrjkNkvaZrD8RI+zgWR9Zmxy//U/h3YtXGWjHVxQWfKloizivkHuRZT6OdNBkDFXYJ3j4ZEvluv2KQBpQUhoWGGtNB10dMMta7/cRY9bdflg9raBE7KhtJjRnkX54p8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784848641; c=relaxed/simple; bh=j824Di3k9kaD2/XvJV1Tp2jEZ9/qGj2s7Ph7CnnnKEU=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type; b=g3bkL6QvoloRFOvsuZlFseZ6hsdczZ+CJPB2U27RWdXz2Xe9AI8Pf3Ow8dgIkT5AZHdgWMoeXDbTwnR0xG3XJLGzK5nTHqFNA4J9ssiWlA3DFqesMqtqycffrOFXxsr2QvCrFs0K+bXabkxJnK9lZ+VTxQDMt96u4yncPgEtZLo= 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=WvmO2NuG; 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="WvmO2NuG" 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=iz6E4BrpWd+r0aWdrdKsx0L9pMZaz696rZOSQQ8lwLQ=; b=WvmO2NuGiN1okDC4E61j4ggHNW 33/Rc2fCFQXaqeZgaHYNnCckzodMQS+KjAJngAKh/TqS5qiW3aNDwY2SW9DOFMfpeC88LIUZM+PJQ XMZK+3oE5JnRaoVnTH3wphiwjC3c69DbckSzRYGYCmSHSJrRrg6wVOtuXgpNQnQcxAT/Sisw/ZpPO GzRdxFVfItLlHCBs8gsRSSCUQH18PLmvA62ZhPvCVfWhC/ydugpf5W9prsO4Sb2zv1E0XQxWJ/iQx DJy9dcTLSUNGYDO1HgyiCOST8663Eap8NxbzoFS4QAj4Gt0EXsGVNLLcYKUK95P/Bf8Pgk4khtW1p 7PJz8cUw==; 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 1wn2f3-003dxL-E8; Fri, 24 Jul 2026 01:17:05 +0200 Received: from webmail.service.igalia.com ([192.168.21.45]) by mail.igalia.com with esmtp (Exim) id 1wn2f0-001vGh-UY; Fri, 24 Jul 2026 01:17:05 +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 1wn2f0-000000031om-34zR; Fri, 24 Jul 2026 01:17:02 +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:17:02 -0300 From: Mauricio Faria de Oliveira To: Borislav Petkov Cc: "H. Peter Anvin" , 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: <20260722170334.GCamD35gwrCng30WH1@fat_crate.local> References: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@igalia.com> <20260721-pvh-kasan-inline-v7-2-38979a50cef0@igalia.com> <20260722170334.GCamD35gwrCng30WH1@fat_crate.local> Message-ID: <1e451a9179c1faa8e7805d17c6e1ee10@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 14:03, 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. Ok. > >> 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. Sure: https://lore.kernel.org/all/20260723-x86-memcmp-asm-v2-1-d93ecb43797f@igalia.com/ > Then you can base the rest ontop. Done: https://lore.kernel.org/all/20260723-pvh-kasan-inline-v8-0-c1f62c156f52@igalia.com/ Thanks, > > Thx. -- Mauricio