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 A93E03955F4 for ; Tue, 21 Jul 2026 15:56:59 +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=1784649421; cv=none; b=sdlEPooBSPqQoNfwJP8FYmV3VKTDNZLp54G+9SFLb+g5bB4vcW2L/Mjio6SfgGyH1MUVsSkNHLLpaZ7r0ddFHq5sU9xp/aqKXqnd7WM9gZj14k1ufcB48J+7fGv0rDI8mgI9KahW/59WkCG5zRW2lsWo6ZrSUYaJi1XAOZSQL9Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784649421; c=relaxed/simple; bh=kozhnWxmpOYBAn4aLpYkh2Hx/xGDm+ocUMagv+v5iCk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uiVMY6I7mPqGXNFVoFK+yU+csHOFIeKOIsNgPEwKnJF142kXULl0QCnuAcHGxdLUvFUIMsZUUGEyFD9OM4s/KAVEyHmEDLH2KXTwMV+U55RKqosckghqmOF2EqVOpRSxwItfBod6BBY6RFAKPlHtW7EEef+ooCC8azCqlpXi+YY= 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=narRMe9q; 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="narRMe9q" 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=De2dzZj2ttdukFtf63NNllXcxOhpCCmsArNb8hGxCvQ=; b=narRMe9qdgSyv2htjupS5xLCA/ UpBYEUhR2i7F/ieE7TontYsiFUncVK+69v4Zh6RreeDii9nB5w0mQ/aC83KKCzLthuHglKUcYDjko u0Cs3LJCpghLi0lNGq+IcEyNpfEL2wVLDToXk09DFSc5KghK7ihXvzoVNm4zZ4CcP2+MKIgelye0E tPvA1WtxAd94eKFrS9Fot9kNePPEkXciEOfL5JniFP9DWPzl18KD8YGFqCyohIyZ8wM38mRYXw7RO L9jxpje39WQcyovalSh1T/nkn+h4gQawnjhvCxX5ydVUVcI4rE4mY7RvOoKNKr2w4EZ7sDPHeyiGL i7oZ772w==; 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 1wmCpx-001fqi-Oj; Tue, 21 Jul 2026 17:56:53 +0200 From: Mauricio Faria de Oliveira Date: Tue, 21 Jul 2026 12:56:43 -0300 Subject: [PATCH v7 2/5] x86/asm: add volatile, clobbers and zero-length check in inline 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: 7bit Message-Id: <20260721-pvh-kasan-inline-v7-2-38979a50cef0@igalia.com> References: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@igalia.com> In-Reply-To: <20260721-pvh-kasan-inline-v7-0-38979a50cef0@igalia.com> To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Juergen Gross , Alexey Dobriyan , Boris Ostrovsky Cc: kernel-dev@igalia.com, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.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 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 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; } -- 2.47.3