From nobody Thu Nov 13 12:06:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=fail (BodyHash is different from the expected one) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1580309597211689.7936057790965; Wed, 29 Jan 2020 06:53:17 -0800 (PST) Received: from localhost ([::1]:47712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iwoiS-0008PF-1L for importer@patchew.org; Wed, 29 Jan 2020 09:53:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60202) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iwofM-0006AZ-EA for qemu-devel@nongnu.org; Wed, 29 Jan 2020 09:50:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iwofH-00010u-AN for qemu-devel@nongnu.org; Wed, 29 Jan 2020 09:50:04 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:36766) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iwofG-0000uA-SJ for qemu-devel@nongnu.org; Wed, 29 Jan 2020 09:49:59 -0500 Received: from michell-laptop.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id D4A3D96EF0; Wed, 29 Jan 2020 14:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1580309396; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=6LICdGlbcpteBkdpfMGTXk/0e4w7x8LAT7dNFujK1T4=; b=23SupqYVFPHtQSE0YmBRCrUpqvscE864m0jDkez/xCGx1bbRmvgl37qd7SumvjobwG+IR0 MWmVvJPvrSblCRcMXLkCSSev31jsySBkwSzOFzfKsBc2qCdq8KYz8iFTjEqfDZ4n7VTAU3 3W5Ad2YXqTE31u6AL95iTnAZb7Q8rNU= From: Luc Michel To: qemu-devel@nongnu.org, Paolo Bonzini Subject: [PATCH] seqlock: fix seqlock_write_unlock_impl function Date: Wed, 29 Jan 2020 15:49:48 +0100 Message-Id: <20200129144948.2161551-1-luc.michel@greensocs.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1580309396; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=6LICdGlbcpteBkdpfMGTXk/0e4w7x8LAT7dNFujK1T4=; b=Et3LCf5/WH96l9NeHK5ueXAzW0+3YDkSQ+xS7Hk6aVqeF91G81+6yiJ6t41kSr3LQsiUXU 3zTiF8whbV1woAamuRUXKFhZW/a59WMwrKi+GLVW6OBC26gGdhhQhsJMAzdLL5pD0vUkr8 Mc1H2rmbGTdDDM90UXVxqLRcumw7qFE= ARC-Seal: i=1; s=mail; d=greensocs.com; t=1580309396; a=rsa-sha256; cv=none; b=BgkFCCLmggFyWrFYkVWAkSAwQtGa+PuXHSbEOXJMR6jhRqpSbhrYDsavTCaPFtgVpUl77p RF0Znpizg2L9rU9yb3ukwiX6A+KrO2flNDWTlw4hx42V133eRIRR3xvlmqOqKayfqvQ3SX 5+RbfSsZ92p2xY4Y/WcAbjOln/HF/gE= ARC-Authentication-Results: i=1; beetle.greensocs.com; none Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 5.135.226.135 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Luc Michel Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The seqlock write unlock function was incorrectly calling seqlock_write_begin() instead of seqlock_write_end(), and was releasing the lock before incrementing the sequence. This could lead to a race condition and a corrupted sequence number becoming odd even though the lock is not held. Signed-off-by: Luc Michel Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/seqlock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/qemu/seqlock.h b/include/qemu/seqlock.h index fd408b7ec5..8b6b4ee4bb 100644 --- a/include/qemu/seqlock.h +++ b/include/qemu/seqlock.h @@ -53,15 +53,15 @@ static inline void seqlock_write_lock_impl(QemuSeqLock = *sl, QemuLockable *lock) seqlock_write_begin(sl); } #define seqlock_write_lock(sl, lock) \ seqlock_write_lock_impl(sl, QEMU_MAKE_LOCKABLE(lock)) =20 -/* Lock out other writers and update the count. */ +/* Update the count and release the lock. */ static inline void seqlock_write_unlock_impl(QemuSeqLock *sl, QemuLockable= *lock) { + seqlock_write_end(sl); qemu_lockable_unlock(lock); - seqlock_write_begin(sl); } #define seqlock_write_unlock(sl, lock) \ seqlock_write_unlock_impl(sl, QEMU_MAKE_LOCKABLE(lock)) =20 =20 --=20 2.25.0