From nobody Sun Feb 8 17:42:24 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665528230; cv=none; d=zohomail.com; s=zohoarc; b=EeF92teCddTYq8H2zwPe739BvKrTCQe7caPiyCFFj7fuSZdpb+bWaoVgsDtvOOp5mm9W0NwEHih897qYmA/mMNtJxU+m9BqVHR9quAu44JLNk7AVi3m2YmXFGiIdjOc7OZlSdH9eiMsJ0//havcf8RQ9eTXqEmf6druUHWpXT64= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665528230; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zG8XGUOfSRlv2X70Eucq0e5jnKWC6PhB0Zvcn9WGzqg=; b=IEB2x6XCRgiDwHWH3zF0sW5639acZ43C1IKPEp9y+ttWAOcJ+S9APVw9DoiZP+5/0feoG8sOJssb/I2Yv/bT2RFDUrwTOEIcZt7rx4rWONqfXPA9ZpdJ2yHPGygFm82sWT4JaN4gLdLCenhk93/IkOpi2LM1s/gdaEOr38Zsu9I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665528230585221.24638295727016; Tue, 11 Oct 2022 15:43:50 -0700 (PDT) Received: from localhost ([::1]:35224 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiNyW-00047U-4l for importer@patchew.org; Tue, 11 Oct 2022 18:43:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiNwo-0001os-U3 for qemu-devel@nongnu.org; Tue, 11 Oct 2022 18:42:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:24174) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiNwm-0001ch-Hb for qemu-devel@nongnu.org; Tue, 11 Oct 2022 18:42:02 -0400 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-321-CnAUp47QNNuqVFPSCIGfMg-1; Tue, 11 Oct 2022 18:41:58 -0400 Received: by mail-qv1-f70.google.com with SMTP id dn14-20020a056214094e00b004b1a231394eso8839819qvb.13 for ; Tue, 11 Oct 2022 15:41:58 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id h17-20020ac87771000000b0039ad65104fasm4258660qtu.12.2022.10.11.15.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 15:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665528119; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zG8XGUOfSRlv2X70Eucq0e5jnKWC6PhB0Zvcn9WGzqg=; b=BtkIgqQdJ2AG0GbAZTyUAqplVQMn2HyuSpAmfwLnqM2KrEJiTUNst9WqhVBkNw+J+CBzwM TXCF4pErWkNyahC/BsJ1UhjdT8pfjx1dE9MSuXb9NPlQMekRvAVOPrLKgRwsNINqAr4U+r P6zkFNKH8X6ulbZGhHHRg0Z+JbMp1Sg= X-MC-Unique: CnAUp47QNNuqVFPSCIGfMg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zG8XGUOfSRlv2X70Eucq0e5jnKWC6PhB0Zvcn9WGzqg=; b=sSi8sPUI5v1YfjzPhsPvyOWf2rCnN55RgyeppkvwlVjO8rL3wmkoZTQbIHJf6bgS6w TN/L+8Dc9wfmhJ6LbCPxglt6fKqIoPpygBKWgM6vkGKALZlR4nbPnN/ml1H5f8j9DP5N srIbhAJT30XGR/CqBN2nJTOqRWwr33n2T5lKSXVw85WJNT+ItmqtZ5Z7wdqGLqwhhazO sMGB531mgTRM2vwiNRWo5B5F5csNqmPk5D3rvK2sgwmYuRSNIW/ZRprKrk6c3PpCPtEk rIig2O6pS7LQLm3qESux2tfiJUPWio0O26SEhxlSAA2J0kcmw7jma0yhArOaub3w2b19 O0Jg== X-Gm-Message-State: ACrzQf0TdM+ZyaSGOJWQEAnWlnATL38rNuvOcE/v6Fhf9BQz18IA5TOo ZPKYblUPfIDU5EOOCnm74+OW36gPq5EZ0qMWyMsF0dWCO/2PLEyytHHWKjwmKhGpdT3tVETHfr0 h0h1u/e+ET3iT7vSxXXyNwNYTM5MgQkWG+O9wsKydnoz1LR5i50PaalylD9f3YS+g X-Received: by 2002:a05:622a:174b:b0:35d:1be5:c65e with SMTP id l11-20020a05622a174b00b0035d1be5c65emr20946953qtk.422.1665528117810; Tue, 11 Oct 2022 15:41:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4DEp8uKbDcSsssacVQByOntMAEaJ06/MzsLxIuyb6BzYl6fpH2IpHNR+dEpbuYOLLUznBnIg== X-Received: by 2002:a05:622a:174b:b0:35d:1be5:c65e with SMTP id l11-20020a05622a174b00b0035d1be5c65emr20946929qtk.422.1665528117559; Tue, 11 Oct 2022 15:41:57 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Paolo Bonzini , Peter Maydell , Yury Kotov , "Dr . David Alan Gilbert" Subject: [PATCH RFC 1/2] qemu-thread: Enable the new timedwait to use DEBUG_MUTEX too Date: Tue, 11 Oct 2022 18:41:53 -0400 Message-Id: <20221011224154.644379-2-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221011224154.644379-1-peterx@redhat.com> References: <20221011224154.644379-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665528231392100003 Content-Type: text/plain; charset="utf-8" The new _timedwait() version of qemu cond/mutex doesn't trigger the DEBUG_MUTEX paths; enable it too. Cc: Yury Kotov Signed-off-by: Peter Xu --- util/qemu-thread-posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index ac1d56e673..5840f6e6f5 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -229,9 +229,9 @@ qemu_cond_timedwait_ts(QemuCond *cond, QemuMutex *mutex= , struct timespec *ts, int err; =20 assert(cond->initialized); - trace_qemu_mutex_unlock(mutex, file, line); + qemu_mutex_pre_unlock(mutex, file, line); err =3D pthread_cond_timedwait(&cond->cond, &mutex->lock, ts); - trace_qemu_mutex_locked(mutex, file, line); + qemu_mutex_post_lock(mutex, file, line); if (err && err !=3D ETIMEDOUT) { error_exit(err, __func__); } --=20 2.37.3 From nobody Sun Feb 8 17:42:24 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665528242; cv=none; d=zohomail.com; s=zohoarc; b=Rjr0sRYWfNC+AvKvgdI2jS0kkhcyt8WeeMwZGIzKYh59fT4T+QIRgr6LjeNgFNfSuRZy8Q23efX7d1Mt7cNlS2Yf07tNW1BHSZyssdnub+kzgw4ucEDfSosud10yvWTkMcUlqUKip8hXJKMXiYcPAugVf86H/GGbjazSUsPopCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665528242; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6d9bkOd3BNy2hN6yorv0iwCbvrwpybUqg2X7NPYmqD0=; b=PEHgtf7/kVaLiRgtcSBfwm6RDcBBbZakdekrUu3fllAVz4Za1T1yh+/YOQs82tZSjqoGl/ks+RbI3Bb3lIYbeBLa5RBlQotq/99J/vrG2YhnnAQPJb6TgEkN51cRlGEy+Xz6AwOc3PJHCoeKYK1SLxnKWUHI62GuUdhNuTFL6CY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665528241927169.5445511096624; Tue, 11 Oct 2022 15:44:01 -0700 (PDT) Received: from localhost ([::1]:48156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiNyi-0004dq-VP for importer@patchew.org; Tue, 11 Oct 2022 18:44:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34354) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiNwr-0001qr-Ob for qemu-devel@nongnu.org; Tue, 11 Oct 2022 18:42:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32189) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiNwo-0001cp-K8 for qemu-devel@nongnu.org; Tue, 11 Oct 2022 18:42:03 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-656-YUMkZE3oOIaDvIVygPMLQg-1; Tue, 11 Oct 2022 18:41:59 -0400 Received: by mail-qk1-f199.google.com with SMTP id bm16-20020a05620a199000b006ee95743ad2so224854qkb.14 for ; Tue, 11 Oct 2022 15:41:59 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id h17-20020ac87771000000b0039ad65104fasm4258660qtu.12.2022.10.11.15.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 15:41:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665528120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6d9bkOd3BNy2hN6yorv0iwCbvrwpybUqg2X7NPYmqD0=; b=bJcos4EFewpuarn0Ow2MCdptwAptSu+e5vGfPvYgSZV9i5dqIvgdtVB98ZjKYSFODqLww3 nxT8uojbQxQdrUVkHytf8rq9xFBBaLYbDoogf5nJsJzFNi7dYwD6HGJu3BjC/S/XpyKQKc qMcdzg5/dSL2tU5NUHB9jNqrOxagv3A= X-MC-Unique: YUMkZE3oOIaDvIVygPMLQg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6d9bkOd3BNy2hN6yorv0iwCbvrwpybUqg2X7NPYmqD0=; b=aJopDbpj27q24vUlUOz4eks1q9uJQrZ2Hk0Xmy6jN1nENsgqPHFqrhLcweye3Wjf7R 494/OFAcU0xEfNFKrltWtLn3uWc66g4DnjjDHfbo/ZJqnihr00ixxXzVT60Vr4N/s02E N+uzhZClR1N8Dek35CxogQGB+HlqCqd1OssLg5BSUProjrdHOgP0spee4lB+TFrvqUSk dHQqfii1KI+f3Jgc5WTjBTKE62GHvy8PCCCWl9bkzPmKfbcLyW2MmO3z/NU/SVPvZiqv H8YXBB9MtlqAyMlMrmm9t5dByTScetp169Qnq0e7MRRJIdUaswdhEVVGGnppupLhAZln NfBw== X-Gm-Message-State: ACrzQf0tVt/GRXrLphDipQiHXnKxM07BXIRIOrd57lT4ZNPBssPMsJTq XYQkzvcivvfmavUUX3ULSeBpQsWSoBCqbH8IemTbmXP7DuoW3NVVd1WzslRSGHmTMFL1me6/Ubj NoWVYD+TGjFXvp7C6Fyppj2HnUB0n6uT+AKhRDcp5McpDJe3pT40aUq4DESZItz5t X-Received: by 2002:a05:622a:1711:b0:35c:ed48:83cb with SMTP id h17-20020a05622a171100b0035ced4883cbmr21652173qtk.264.1665528119124; Tue, 11 Oct 2022 15:41:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7CtZ9Wph72/m3iiGbf8O2nXmDbV//kS6OCCBjmSUhxJ/2wBEvM/B8Mt3SMdKVZzOImq1hQJA== X-Received: by 2002:a05:622a:1711:b0:35c:ed48:83cb with SMTP id h17-20020a05622a171100b0035ced4883cbmr21652154qtk.264.1665528118848; Tue, 11 Oct 2022 15:41:58 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Paolo Bonzini , Peter Maydell , Yury Kotov , "Dr . David Alan Gilbert" Subject: [PATCH RFC 2/2] qemu-thread: Fail hard for suspecious mutex unlocks Date: Tue, 11 Oct 2022 18:41:54 -0400 Message-Id: <20221011224154.644379-3-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221011224154.644379-1-peterx@redhat.com> References: <20221011224154.644379-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665528243476100001 Content-Type: text/plain; charset="utf-8" Add a field for QemuMutex to remember the locked status, then assert properly when CONFIG_DEBUG_MUTEX enabled on illegal unlocks. The pthread library is by default quite loose on this by allowing the unlock to quietly succeed. But that could cause the follow up things very unpredictable so if there's a bug it'll be harder to track than failing early at the illegal unlock. Signed-off-by: Peter Xu --- include/qemu/thread-posix.h | 1 + util/qemu-thread-common.h | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h index 5f2f3d1386..e13bd5492c 100644 --- a/include/qemu/thread-posix.h +++ b/include/qemu/thread-posix.h @@ -9,6 +9,7 @@ struct QemuMutex { #ifdef CONFIG_DEBUG_MUTEX const char *file; int line; + bool locked; #endif bool initialized; }; diff --git a/util/qemu-thread-common.h b/util/qemu-thread-common.h index 2af6b12085..ed74bdb0d1 100644 --- a/util/qemu-thread-common.h +++ b/util/qemu-thread-common.h @@ -21,6 +21,7 @@ static inline void qemu_mutex_post_init(QemuMutex *mutex) #ifdef CONFIG_DEBUG_MUTEX mutex->file =3D NULL; mutex->line =3D 0; + mutex->locked =3D false; #endif mutex->initialized =3D true; } @@ -37,6 +38,7 @@ static inline void qemu_mutex_post_lock(QemuMutex *mutex, #ifdef CONFIG_DEBUG_MUTEX mutex->file =3D file; mutex->line =3D line; + mutex->locked =3D true; #endif trace_qemu_mutex_locked(mutex, file, line); } @@ -47,6 +49,14 @@ static inline void qemu_mutex_pre_unlock(QemuMutex *mute= x, #ifdef CONFIG_DEBUG_MUTEX mutex->file =3D NULL; mutex->line =3D 0; + /* + * pthread_mutex_unlock() by default silently ignore unlocking a mutex + * even if it's not locked. Make it strict with QEMU when DEBUG_MUTEX + * is enabled, so that we can capture it at the exact wrong unlock. + * It'll be easier to track this than having misterious deadlock later. + */ + assert(mutex->locked); + mutex->locked =3D false; #endif trace_qemu_mutex_unlock(mutex, file, line); } --=20 2.37.3