From nobody Sat Sep 26 20:51:02 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=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1789504548; cv=none; d=zohomail.com; s=zohoarc; b=dAtgandAN9jRWxrMw+VFk4fDA2soTTaG7vXsCb5q8h+XLP7LCV+NLidaJx4vFHHCz8EOJOUHaW9wgM3Tv/1t9ImBsyV5fKwe3Vd69E1TKbUOhBglE9gDlLkVOp4azKTiPUJ1ml2r9Ykq88kpAtKSefH/HePcmxwT2koZPydY5uc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789504548; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XTYYskXjomYjrh7QaEEaHTvJmk0WsJMpAIC97SU4vck=; b=mZK6fMmB8MjVSZmGt1kuSLncAWQ844FMh82jUOt+ofES8Lr9RQiDm19cwgZDNACip45nPuo5WaOKLfEv52w89mrPzl1iUDNrWoyDfkii+qwCgOnUO0VkYuI5XuPg5LNNTGKj9VDoqT/JXX4zYDjMAXkMRqtSNg/rfw3m+VDXuwk= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789504548904314.3567708934895; Tue, 15 Sep 2026 13:35:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6Zrt-0001Hh-JC; Tue, 15 Sep 2026 16:35:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x6Zrr-0001HI-S5 for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:03 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6Zrq-0005Zw-5S for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:03 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49e6598dd44so1299275e9.1 for ; Tue, 15 Sep 2026 13:35:01 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:f0fe:c7ed:403d:e487]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4870bf37e69sm1504073f8f.29.2026.09.15.13.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 13:35:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1789504500; x=1790109300; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=XTYYskXjomYjrh7QaEEaHTvJmk0WsJMpAIC97SU4vck=; b=nkLMKuv0QMMFsN9GKRib/zJXyhKn8HW9JuT0hb5eZws6X//s5JDzqUwW9EVBPpuy2Y 1FOqtKga0Jv+FjgF7iwMvDS482lYDZ66P8bjIYG4sXxDgVnAxFv87LRZR3FhRuYgEobT h3OZXGJzmU5K6yE3K5kmcHvk6xiorrayw0cZScHVfITs13VXRzleJf36o2f/qi60dNbQ aueP6xcy3wTuBoDjc4zf8H2+Vcel0JaaZzu8bqeMiloU93AVGF2cdj2AsSvcU8ULiwNX RdC8jXgwc2w6H0Yzv9Lr/pO9aMfVoKtvPLUNbbHjfUhW9Ou0d/JezrgCHwbs2DBdKepT QdoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789504500; x=1790109300; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=XTYYskXjomYjrh7QaEEaHTvJmk0WsJMpAIC97SU4vck=; b=phZHWfdRAkxMD97QZD+ZE4VGMd2GmV/nU+9zh/mWv/F+N8f+HJCEmg+PfAgPF3m6KD zo4VEB6tfapKLpN35vGGZybQEj820CDSaiNWsvjerG5IIja1f+Qciek393neZk4s10tB 5upEp6zq4RhFIFJ1XESvxU7bj5zAGLROKTKYZX5kbWoxkO1qdO5LOATE4AwERAvLvwPi tlxXqTQ35mndSI4X0/NtkjguooHbIEhaC5ykNHterGlxfCM7USVMfzrhIvmYbjL6ua0O cVSEgH8olz0rLaeTzaYEQeBtePw3hmJV4nEquEzFF/zxOu5aglX7hjV+3hZHiMVlAyDc DyvA== X-Gm-Message-State: AFuF++mItoEESR+f6q8tek+Lz2XmOGcCaSuLwyI4DZPPNDoWHUyFjfeW rH94gv2TOWKDKn4P0XBJC2h5UoZt5fzyFoerWHV/ZWUgQxndpyLBp67aE6bubHqehy+C2V7v32I Sgrma X-Gm-Gg: AYBFou2ocyfDtQ/XNhrRqr1PvOTsfsCwS4N5gJytUJfYFAGmhx3/tIqXi4e2n6LLakJ 1KZ1CK0BwqMc2DBaNCUECS7B82YfpY2WRRjq23TGDkh4QID/PFewzHsp21/C0By/ZxiXfOEhJKR e9v5ZYOKRKyJAFxxOdzwHARIPjaR4jXIPkRVwINvChyboP0J2iuFzJ/WdfNmNcKuhemq1wkeoMv kJgKycSrh/6hmFGrVRpoYVEgSw3gMZgjvwQu9Oo2VZ4K1jehuwRC3ot0hMtlgrtgoEQGSk4dRY2 xEjgA6LatDglDbJlqUqnIUNjQ0Rwjno6dVC8xZ2Iv7J3D+2cnGA49dPhYRPm5eQHsGvmYzqMw1e 4dVDNlBoPCiN/D4ZsXkPgVMk9AV5Y8a2OsGlIzcxPZSqHu5uifril9UErro2mxpI35lTzCymsy/ f+R8r7TabCVMB4EOuDwx9tcLts8e+Ij/50tQ8UqnMl1DMQvgpBXiP+dosKBYrw2UCuXcOX X-Received: by 2002:a5d:5e91:0:b0:486:e558:604 with SMTP id ffacd0b85a97d-4870d062624mr134707f8f.57.1789504500539; Tue, 15 Sep 2026 13:35:00 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu , Stefan Weil Subject: [PATCH 01/10] util/qemu-thread: track bql_locked across the timed condvar wait Date: Tue, 15 Sep 2026 22:34:45 +0200 Message-ID: <20260915203455.580999-2-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260915203455.580999-1-den@openvz.org> References: <20260915203455.580999-1-den@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.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, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1789504550480158500 From: Denis V. Lunev qemu_cond_timedwait_ts() releases and retakes the mutex around pthread_cond_timedwait(), but calls the two trace points by hand instead of going through the mutex hooks, so it never reaches bql_update_status(). A thread waiting there still reports bql_locked true while the mutex is released, which is the confusion the hooks were given that job to end. migration/cpu-throttle.c reaches this through qemu_cond_timedwait_bql(). The Windows qemu_cond_timedwait_impl() has the same two trace calls, next to a qemu_cond_wait_impl() that already uses the hooks. Call the hooks, which emit the same two trace points. Fixes: c89d1c879a ("bql: Fix bql_locked status with condvar APIs") Cc: Paolo Bonzini Cc: Richard Henderson Cc: Philippe Mathieu-Daud=C3=A9 Cc: Zhao Liu Cc: Stefan Weil Signed-off-by: Denis V. Lunev --- util/qemu-thread-posix.c | 4 ++-- util/qemu-thread-win32.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 089606c93f..580cdf8079 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -250,9 +250,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__); } diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index 3037732a6f..afdacdb5f2 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -177,11 +177,11 @@ bool qemu_cond_timedwait_impl(QemuCond *cond, QemuMut= ex *mutex, int ms, int rc =3D 0; =20 assert(cond->initialized); - trace_qemu_mutex_unlock(mutex, file, line); + qemu_mutex_pre_unlock(mutex, file, line); if (!SleepConditionVariableSRW(&cond->var, &mutex->lock, ms, 0)) { rc =3D GetLastError(); } - trace_qemu_mutex_locked(mutex, file, line); + qemu_mutex_post_lock(mutex, file, line); if (rc && rc !=3D ERROR_TIMEOUT) { error_exit(rc, __func__); } --=20 2.53.0 From nobody Sat Sep 26 20:51:02 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=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1789504595; cv=none; d=zohomail.com; s=zohoarc; b=Hy+PSo68a31sNjJhm/AOJcrAjeATp+ywTWsLDLhHkBDQ4plbtEufqYxzBVtjzwPIEYhlCg6geGuFMBSV/yOKpJjYYyq5QdyNwmpNe5ZBEqBuehH71bZXIGSRunTBSzYX2iYXbER3gUNgN128tpfIvAR2a4ET+F/r3j3aFnKu9WY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789504595; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tSwf+aSZl4o9EHWe1PTU6IuxaLQsk5COu15yj71WkRM=; b=Gp4lP0ageppP3ZgQ2tNfn9iuf2DTN73zxIfAlOcx5b6T3h3Msi6HPzqmEsda9ltMJdTBe22iMGlzEltWB4N1v/hSGTGZUP39KBmENhSU2o6OkJ9EaLHzXddlujAlfO3f+um/fI4deXQ8HNg0O1eeVqQBQdVePDzkqqPolf6e9MU= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789504595159266.88285366067953; Tue, 15 Sep 2026 13:36:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6Zrv-0001IA-5P; Tue, 15 Sep 2026 16:35:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x6Zrt-0001Hi-Ok for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:05 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6Zrs-0005aS-2d for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:05 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49e69b9e16aso2206835e9.1 for ; Tue, 15 Sep 2026 13:35:03 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:f0fe:c7ed:403d:e487]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4870bf37e69sm1504073f8f.29.2026.09.15.13.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 13:35:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1789504503; x=1790109303; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=tSwf+aSZl4o9EHWe1PTU6IuxaLQsk5COu15yj71WkRM=; b=R6t7HLfT8GVWP4y3KqY47IIoLK211Nf59fuq5H/GJO2mSaIwyRfUZ5FwyxCRtR2hCO 9aOMwD4KbsarkoOO4Ceqeazh+aI0MM3+8rbyFhsMFptJvNaxIvum8qyB2Gtwjyi7G68P 71vtHYuKybK0UlYK7fPfIHqi4PauHh9JjuloXeSllLH5alzCj16pP/PZf+4z2KEZsLxz lownTPhwOjihep+cWZkM7yVvkItznStT36YUaHyVbVmQGcC/bOtc+dc3R3n9xsP3qso3 kpT1eTnCGN/xjBA7KcMuDOFH0LCglv5Lzb1jrJSjGF/EiH08My1oSTvW0zuEJTXf+/pt rWeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789504503; x=1790109303; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=tSwf+aSZl4o9EHWe1PTU6IuxaLQsk5COu15yj71WkRM=; b=CjcFGk8Zyedm7sUPLPLuaGZPQPyPzLDtFyZCMgfDrhpO0tIpXNzQ/9zOqaqGhKz950 AUe6Pl6IjVe/sBmvdN5xZPsS2SLL/kRibPDpoS5QGiIA2CP1NhH5h29QvXormQ3Rd5Z7 WQa3B4ZxR+X/YaDiQAV23h5uWcNpsipQC2HpSaPpmYNbSq0CSLkQVkJyX9GO27WHAQn6 gy0CrOHXDJlCLLbJ4KYS7OZsTwQQrZUpLtKhLw5WxyECoXUqXphoWD9iAIiLS+HsXvQ8 jeeK8EqEhqGy/XYxcNxb6J3QRWKCYWpXm+EYFmPGK825/chcduPMYR31xr5s1Wo5Sstu KN8w== X-Gm-Message-State: AFuF++kgtQBfFnl8KCZR/eD5gmXQBgGoGdchGKSo2j0X/j6KU3ta14pv azCGfQrvPgug1NLdOAD3l32HIpzP7PIQPwzE/SvCQvaWTE1HmUq4hBdsQGxbmF7Sc9VPhNXFJEA 1MaU0 X-Gm-Gg: AYBFou0cvIXZqNNfZTyPBSX+4eYEpVf7jhDER4HLQR8+0gGQSemzRrMV8e8bFos2SDy rkaziOwsqZVb/ziZTnQ3+ZDqxPholYMpBorpuBoCLhx6iE36g7OSFdKNSoF0Ak86yWJa2//BNwR +YtUSoHGCLFmZ7kEu573rcO9k6f9yaynPJwu0T/REnejvZfOhvLpxwpJxAVz7Y0ym2jR7uARHLb nubTW6q5auAGBY8TX8S4mlpQRZISa5ZTpTZHrm60on1o4eD3F2GLmxMEqu5xFdDbVZ0RFoNibfx yMeRMdpZyP7MBiv7CDbqSWlb/L9tG2pLm6BoIFukem3TKuPbMLozbRADlkMIcnvRamBUwsl8kq1 i+SnCY8aQHX0pz/XtDeMqHYP5GGxwtzcYQfxRc7uljG5OF91QgVlPqfZhAVV9TYyxiO+O15FlN9 2xTafPyK1hCM4bUGdSq+hRp6Zt8b24LxlVc6sx5BdMzMMJt+6mxipG26YR0pF/a9KVskXbJsrnN SD7pB8= X-Received: by 2002:a05:600c:4f43:b0:49e:6c27:d093 with SMTP id 5b1f17b1804b1-49e7a6704d3mr117180085e9.15.1789504502723; Tue, 15 Sep 2026 13:35:02 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu , Stefan Weil Subject: [PATCH 02/10] oslib: add qemu_debugger_attached() Date: Tue, 15 Sep 2026 22:34:46 +0200 Message-ID: <20260915203455.580999-3-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260915203455.580999-1-den@openvz.org> References: <20260915203455.580999-1-den@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.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, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1789504596515158500 From: Denis V. Lunev Code that watches for a hang has to tell a hang apart from a debugger stop, because under a debugger every thread stops and whatever liveness signal the watcher samples stops changing with them. Linux reports the tracer in /proc/self/status and Windows has IsDebuggerPresent(). Answer false elsewhere, which leaves the caller behaving as it did before the check. Match the Linux field at the start of a line. The Name: line holds fifteen characters of comm, enough to spell the field name and appear ahead of the real one. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Philippe Mathieu-Daud=C3=A9 Cc: Zhao Liu Cc: Stefan Weil Signed-off-by: Denis V. Lunev --- include/qemu/osdep.h | 9 +++++++++ util/oslib-posix.c | 22 ++++++++++++++++++++++ util/oslib-win32.c | 5 +++++ 3 files changed, 36 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 1ec5b42230..96afe09632 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -658,6 +658,15 @@ bool qemu_write_pidfile(const char *pidfile, Error **e= rrp); =20 int qemu_get_thread_id(void); =20 +/** + * qemu_debugger_attached: + * + * Returns true if a debugger is currently tracing this process. Meant for + * code that would otherwise mistake a debugger stop for a hang, and false + * on hosts where this cannot be determined. + */ +bool qemu_debugger_attached(void); + /** * qemu_kill_thread: * @tid: thread id. diff --git a/util/oslib-posix.c b/util/oslib-posix.c index dc001da66d..4eb6a40628 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -112,6 +112,28 @@ int qemu_get_thread_id(void) #endif } =20 +bool qemu_debugger_attached(void) +{ +#ifdef CONFIG_LINUX + static const char key[] =3D "TracerPid:"; + g_autofree char *status =3D NULL; + const char *p =3D NULL; + + if (!g_file_get_contents("/proc/self/status", &status, NULL, NULL)) { + return false; + } + while ((p =3D strstr(p ? p : status, key))) { + if (p =3D=3D status || p[-1] =3D=3D '\n') { + return atoi(p + sizeof(key) - 1) > 0; + } + p +=3D sizeof(key) - 1; + } + return false; +#else + return false; +#endif +} + int qemu_kill_thread(int tid, int sig) { #if defined(__linux__) diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 5f3e8f4d98..6663d83151 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -228,6 +228,11 @@ int qemu_get_thread_id(void) return GetCurrentThreadId(); } =20 +bool qemu_debugger_attached(void) +{ + return IsDebuggerPresent(); +} + char * qemu_get_local_state_dir(void) { --=20 2.53.0 From nobody Sat Sep 26 20:51:02 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=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1789504589; cv=none; d=zohomail.com; s=zohoarc; b=FRmJar5hqNKVafEmGZIibZFUkWIuLiK3YLdrFiHQ1lHLEyZBpl1pWeMTZwcbMA+/CZrI++D9i3g258/bspHPwzXIG4IMv0zUzQIywThvWFuwHf1fy0pP5TtrtV6PClUK5Qe+PVWCf0Z6okIlIfCZhnIy05AQLFhNrg9Hbb/8x2g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789504589; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ya2xkpYj9xYatRBnkZU7QVEc+GAEhygQYkVwKQ4DXdc=; b=UI9jSJ24+izGbzPDRstj4y6oAuedaV4H5VJQX6VMXv7nPJ3KR9GkoGO62y5GPyxRUImIrk1V3nYGJ1rlZFXYvwsIN9VL3RNCaVSGu/4vgooo0E32Ar624YJwTsRkB820xc4nD0/TM28x+QPTgWyJ0rdd8yDBR5prLrnfuqBXSPo= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789504589018423.40378848024864; Tue, 15 Sep 2026 13:36:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6Zrw-0001IZ-E5; Tue, 15 Sep 2026 16:35:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x6Zrv-0001IC-Cx for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:07 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6Zrt-0005at-B4 for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:07 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49b912d3920so1666375e9.1 for ; Tue, 15 Sep 2026 13:35:04 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:f0fe:c7ed:403d:e487]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4870bf37e69sm1504073f8f.29.2026.09.15.13.35.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 13:35:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1789504504; x=1790109304; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=Ya2xkpYj9xYatRBnkZU7QVEc+GAEhygQYkVwKQ4DXdc=; b=HObJrGy+b/d2LZUullOF0UbDmnHMi2OPJmOgiVBTxj2xlVc8bMsPKJ804UhCQTNpX5 ak/VTAeGZY939b8GXSxR87umR1vKtOyVnLhp8Q8W0ZhaD8Akf85t+CyBV4RMjG1wkUXr iGHEHK4p8kEzPdyYt7XNTXJw5M/1BoKdiLdTcxKh90BkKhkmbBx3kcDWk+NSHc4vKLwj s7HR47fyIQDK94dJDg8h2Uevt5p7+/ohu+ed5QuR7Ey7jwEWesP3FgnHtb1ee4fz7LO5 5OUDQyERJNTYomqI6TY8bMH2TmyeVY4gSis0JPPm5JS/03uQcuVfBZVsd6q3EBK8agyC v9sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789504504; x=1790109304; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Ya2xkpYj9xYatRBnkZU7QVEc+GAEhygQYkVwKQ4DXdc=; b=CI1wzuEqN+tamB+rnYvNdlTDghHBEir2iffdJydQ3DOqelmXW/tGMi4ovA1KdRLEzL N7TNng2e04yGPs8tpKVUZfMCJDEajZPRCw+E7bm5VecOH5C+zT+bDYQ2uchtzT1pQygc q0Cfv2i9gAnzKb9cg9OXUWN+uEesSQ/XBmfZHev/qKRiRrBY8rag3f6swnqsBcyAcJ5Y 7huHwzzrMacd3ffhvKGMV3DcabpDsZYkydhpfu+2DKwEJDLlXsx9jvc2ZdCe96NTigQZ 98EEqjrsMRUsiY63pGElOCy7EeVK71ik35gY7dCjuXeeckHAhonGwAm/fx/9CmXAIycl mmVA== X-Gm-Message-State: AFuF++l6MbOcwAe5z17WJy8+VDqsLyMBOyYY/dmth9sZ3DdSJSl2b2ac rdtrxMGXtzGEb79YqcEeqkbFfh3KOKahN0ZUubwN6EbjpMvDmrMrCvBdm30AVMR686NQHkZvARt V6r+g X-Gm-Gg: AYBFou3GAO0l/bCePmjPe7BlQmKfcdnPnU52H2XBnFcRrOB5f8sH3Jdi2U5OHPzr5z0 4RrOWG9LN97URTdXfrPLLAhODQFylzrN3mjfFMapFOx3MQa7MC8L8KIonpixeZKJp9Q63oE1v4I fmFfsyEwTz4KuprB/PuisB83To9wuj3jTm5ETtr9kKItiqxoD0AtXtEiQJPS3s1xZKe9HeQxov9 HR9FKGNkEbyGX+UfsE2cIEq4vW0L4iavt5blkVgb60AbziDN5nehDMKqfKSavnhgZvjxDKzwo1I 6fDV6veaGhw9PdzJeSMfObDFmyHair7MI4HUWfqMVKNsLs8pCV6B+TfpYLkbdW7kwUAn5ByOpg7 3G0SfjubAeENiWNWpRjLwVJWr0wOIEeed6XqwHhvna3Sph12iWce7xfdhYHhZdFBcBc50OwmKnE FupuilPq1Y2g2OUbQxo4lsPYCcGhOHKvgiPACTPWos3kfZNs4SrmWBDxvOz0bMrPclRusA X-Received: by 2002:a05:6000:25f4:b0:487:999:9ad9 with SMTP id ffacd0b85a97d-4870d26f060mr132045f8f.52.1789504503970; Tue, 15 Sep 2026 13:35:03 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu , Stefan Weil Subject: [PATCH 03/10] oslib: add qemu_thread_states() Date: Tue, 15 Sep 2026 22:34:47 +0200 Message-ID: <20260915203455.580999-4-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260915203455.580999-1-den@openvz.org> References: <20260915203455.580999-1-den@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=den@openvz.org; helo=mail-wm2-x11.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1789504590538158500 From: Denis V. Lunev A watchdog that reports a hang wants to say what every thread was doing, and that answer is host specific. Put it beside the other process introspection helpers rather than in the code that happens to need it first. Describe each thread by id, name, scheduler state and the wait channel it is parked on, all of which Linux exposes in /proc/self/task without privilege. That is already enough to separate a thread blocked on a userspace lock, which waits in a futex, from one blocked in the kernel, which names the primitive it sits on. Skip the caller, which is reporting rather than hanging. Hosts with no way to answer return NULL, leaving the caller to print its own message and nothing more. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Philippe Mathieu-Daud=C3=A9 Cc: Zhao Liu Cc: Stefan Weil Signed-off-by: Denis V. Lunev --- include/qemu/osdep.h | 10 +++++++ util/oslib-posix.c | 71 ++++++++++++++++++++++++++++++++++++++++++++ util/oslib-win32.c | 5 ++++ 3 files changed, 86 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 96afe09632..8039bf91b8 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -667,6 +667,16 @@ int qemu_get_thread_id(void); */ bool qemu_debugger_attached(void); =20 +/** + * qemu_thread_states: + * + * Returns a newly allocated, newline terminated description of every thre= ad + * in this process apart from the caller: its id, name, scheduler state and + * the wait channel it is parked on, or NULL on a host that cannot report = any + * of that. + */ +char *qemu_thread_states(void); + /** * qemu_kill_thread: * @tid: thread id. diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 4eb6a40628..79887d370c 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -134,6 +134,77 @@ bool qemu_debugger_attached(void) #endif } =20 +#ifdef CONFIG_LINUX + +static char *read_task_file(const char *tid, const char *name) +{ + g_autofree char *path =3D g_strdup_printf("/proc/self/task/%s/%s", tid= , name); + char *buf =3D NULL; + + g_file_get_contents(path, &buf, NULL, NULL); + return buf; +} + +static void append_thread_state(GString *out, const char *tid) +{ + g_autofree char *comm =3D read_task_file(tid, "comm"); + g_autofree char *stat =3D NULL; + g_autofree char *wchan =3D NULL; + char state =3D '?'; + char *rparen; + + if (!comm) { + return; + } + g_strchomp(comm); + + stat =3D read_task_file(tid, "stat"); + if (stat) { + /* comm can hold anything, ')' included, so scan from the right */ + rparen =3D strrchr(stat, ')'); + if (rparen && rparen[1] =3D=3D ' ') { + state =3D rparen[2]; + } + } + g_string_append_printf(out, " %-7s %-16s %c\n", tid, comm, state); + + wchan =3D read_task_file(tid, "wchan"); + if (wchan && wchan[0]) { + g_string_append_printf(out, " wchan %s\n", wchan); + } +} + +char *qemu_thread_states(void) +{ + g_autoptr(GDir) dir =3D g_dir_open("/proc/self/task", 0, NULL); + const char *tid; + GString *out; + + if (!dir) { + return NULL; + } + out =3D g_string_new(NULL); + while ((tid =3D g_dir_read_name(dir))) { + if (atoi(tid) !=3D qemu_get_thread_id()) { + append_thread_state(out, tid); + } + } + if (!out->len) { + g_string_free(out, TRUE); + return NULL; + } + return g_string_free(out, FALSE); +} + +#else + +char *qemu_thread_states(void) +{ + return NULL; +} + +#endif /* CONFIG_LINUX */ + int qemu_kill_thread(int tid, int sig) { #if defined(__linux__) diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 6663d83151..d18886847c 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -233,6 +233,11 @@ bool qemu_debugger_attached(void) return IsDebuggerPresent(); } =20 +char *qemu_thread_states(void) +{ + return NULL; +} + char * qemu_get_local_state_dir(void) { --=20 2.53.0 From nobody Sat Sep 26 20:51:02 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=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1789504548; cv=none; d=zohomail.com; s=zohoarc; b=lPNYZLdOG5CpWxeByEA5+Zyoz0ZY3439rxFu0d/w8wwU57CNHgqN0+QONKnrjudGYZ0bRHKBe30LdgDJXNO7UNmEatgYDO6fh1ZtVH2GTqw9smRll99baAbTKT3r35FKjq+8Brk7iqOMg4WxplCq9K97z7eYBoWwZBalZqCyaYY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789504548; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9U6r6zduGROyZttH41usMCNKKJFsk0T5lUOSw3Zwo2M=; b=XycsUlrqnJwTi4DLLB7+vtbBfZ8KaJlHo8CIrRm3MbLviK13AzSmvPuxa1+SgPhrqwiUnel3ZfALMR27TeItjYH7qrQWu2EUm96dTL1kvoUOnZ4hAxcaJmIjnGPFXlV85alyFB0ON22E9LcEH/2xscOjm0zGJD3++BOLbTudEk4= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789504548349149.16464667252728; Tue, 15 Sep 2026 13:35:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6Zrz-0001JZ-6u; Tue, 15 Sep 2026 16:35:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x6Zrx-0001Iq-Ev for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:09 -0400 Received: from mail-wr2-x10.google.com ([2a00:1450:4864:30::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6Zrv-0005bU-GK for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:09 -0400 Received: by mail-wr2-x10.google.com with SMTP id ffacd0b85a97d-4843c3ee4cfso68924f8f.2 for ; Tue, 15 Sep 2026 13:35:07 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:f0fe:c7ed:403d:e487]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4870bf37e69sm1504073f8f.29.2026.09.15.13.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 13:35:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1789504506; x=1790109306; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=9U6r6zduGROyZttH41usMCNKKJFsk0T5lUOSw3Zwo2M=; b=d5f6scyDt6YmTKhIB4dYOlTlM+MLYuuWhIu3xO3zzs8QEFgKSsWPu+hxsZRj0/9VP5 3n8SgMLPU76QSfni4rsIkXFsi9ksDEKBX557Mg+TCmylhEYbsN50n6tJEjNDALnp0t/V QpdhZoPVj+XMFJNF54/Jbx2yHQVUGiK/c+7TU3IEQMT0ZiBcPW7PApAtPT2mv8rWiPZA wkBJSMQK45qSsT9EfIEkk77yZJcGwZ5n7IVTMaKmkR+YiSuoUkaamFLoRV3SWOvAQNSt jysTy6uXpQYvGZakfC0d/O4hrmzlm/tMrgVhFO65fXlAfaXBZM5o1V/yjPxneKF5e/Oy GGsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789504506; x=1790109306; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9U6r6zduGROyZttH41usMCNKKJFsk0T5lUOSw3Zwo2M=; b=DWnsEE8z7STE1ue3whroBlEQgFfZDfoHcxKmrqIJqrViqnx3hinkJLXmBWkxt87lON lFelSDW8bq5rucarQJoNQxeox1iIlN5ZNAeITaKPcRrvPyvG5ngy3NCP80DPAJ1Ryjep haQfR7/XceTYM3NyfORZv8GBoNdJv8ooEFU0T9riDmpsldgWSsjpUrOesF0ZNiMPTA+j KZ1SrG0QOte4PS698etwE2Zh48p9mPNsKfNXu5/l9C/LZWUbjvyBuA6lA8cCKK8L1MwB 1hq61t0dsxfiNbqbWDhKC73qAVx2t5QKwsgvsc1Fb6MBDpO+7HBZTpS5RZPeB6j11Lo5 XbsA== X-Gm-Message-State: AFuF++nfP4QTkYs3JZiN2mXNjiKn/QLDmj6OUH0jZI3tzai2mFVwues8 mx4OxbQ5pDt/zwffvco9666heCYGB+wjgrMcelE6WRLI5r3giobhNsz7Di4SDavZMazW8hfjvQL quVWp X-Gm-Gg: AYBFou1Uo0//B3ClOhWTfk902B2Ay6oWHyKkZ8weNieBzU/8jCn00aw2Zlm+DkTwlVM krsE/QYpbheGb+dWoEeHCJ3MzwLek3JI08AShecZGzzBryk8x9PkB1pzI+1nFnBBQeuyP7UBVXR gnS2j0czwdusCqsIMVNyEqfXVlN8XpgstVMVITiRPCndPCt3qPGjVQTyk/YsifVpjX1B31ChWJ0 Mmvowk38Xal9gL5Zoa1URLKYWH6+bq4xs9VqAgsroQoaGQLUMFMW3A+EFAw6OXn+PJ12hiykVWw ywxIvC+ezxA9FnPc1wKMTrtzioVT7yTBFRX0cWfrn/3uQfW31kOqVQDEHaEUtkQAhTAPeHZiJaP w9zsJGVhgDfWYKlJT+MdV+PvZFOAkjT5u2VncjR7K1X+5sZU74wMdwsPYziNMB58D3P8SLylOLA MEqwYl5JIP1g1ijEEA4Gd1kgi2GPUznZUxYX21FxFEc2FNJ/Ku/1Obr+KOZzYkN0V2ImwL X-Received: by 2002:a05:6000:644:b0:487:4ba:97f2 with SMTP id ffacd0b85a97d-4870cf27ad0mr155723f8f.3.1789504506078; Tue, 15 Sep 2026 13:35:06 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu Subject: [PATCH 04/10] oslib: report kernel stacks in qemu_thread_states() Date: Tue, 15 Sep 2026 22:34:48 +0200 Message-ID: <20260915203455.580999-5-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260915203455.580999-1-den@openvz.org> References: <20260915203455.580999-1-den@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::10; envelope-from=den@openvz.org; helo=mail-wr2-x10.google.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, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1789504550404158500 From: Denis V. Lunev A wait channel names the primitive a thread is parked on but not the path that got it there, and for a thread wedged in a syscall that path is the answer. Read /proc/tid/stack when the report is built, and keep the wait channel for when it cannot be. The file is restricted to CAP_SYS_ADMIN in the init namespace, so ask once rather than failing per thread, and say why the report came back thinner. Skip a running thread, which has no settled stack to unwind, and cap the frames, because the deep end of a stack is rarely the part that explains the hang. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Philippe Mathieu-Daud=C3=A9 Cc: Zhao Liu Signed-off-by: Denis V. Lunev --- include/qemu/osdep.h | 4 ++-- util/oslib-posix.c | 52 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 8039bf91b8..c15ffd7880 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -672,8 +672,8 @@ bool qemu_debugger_attached(void); * * Returns a newly allocated, newline terminated description of every thre= ad * in this process apart from the caller: its id, name, scheduler state and - * the wait channel it is parked on, or NULL on a host that cannot report = any - * of that. + * kernel stack, or NULL on a host that cannot report any of that. Where t= he + * kernel stack is privileged the description falls back to a wait channel. */ char *qemu_thread_states(void); =20 diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 79887d370c..6a683b849e 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -145,13 +145,39 @@ static char *read_task_file(const char *tid, const ch= ar *name) return buf; } =20 +#define THREAD_STACK_FRAMES 12 + +/* + * /proc/tid/stack is restricted to CAP_SYS_ADMIN in the init namespace, so + * ask once instead of failing per thread, and say why the report is thinn= er. + */ +static bool thread_stacks_readable(void) +{ + static int readable =3D -1; + g_autofree char *path =3D NULL; + g_autofree char *buf =3D NULL; + + if (readable >=3D 0) { + return readable; + } + path =3D g_strdup_printf("/proc/self/task/%d/stack", qemu_get_thread_i= d()); + readable =3D g_file_get_contents(path, &buf, NULL, NULL); + if (!readable) { + warn_report("kernel stacks need CAP_SYS_ADMIN, falling back to wch= an"); + } + return readable; +} + static void append_thread_state(GString *out, const char *tid) { g_autofree char *comm =3D read_task_file(tid, "comm"); g_autofree char *stat =3D NULL; + g_autofree char *stack =3D NULL; g_autofree char *wchan =3D NULL; + g_auto(GStrv) lines =3D NULL; char state =3D '?'; char *rparen; + int i; =20 if (!comm) { return; @@ -168,9 +194,26 @@ static void append_thread_state(GString *out, const ch= ar *tid) } g_string_append_printf(out, " %-7s %-16s %c\n", tid, comm, state); =20 - wchan =3D read_task_file(tid, "wchan"); - if (wchan && wchan[0]) { - g_string_append_printf(out, " wchan %s\n", wchan); + /* A running thread has no settled kernel stack to unwind */ + if (state !=3D 'R' && thread_stacks_readable()) { + stack =3D read_task_file(tid, "stack"); + } + if (!stack) { + wchan =3D read_task_file(tid, "wchan"); + if (wchan && wchan[0]) { + g_string_append_printf(out, " wchan %s\n", wchan); + } + return; + } + + lines =3D g_strsplit(stack, "\n", 0); + for (i =3D 0; i < THREAD_STACK_FRAMES && lines[i]; i++) { + if (lines[i][0]) { + g_string_append_printf(out, " %s\n", lines[i]); + } + } + if (lines[i]) { + g_string_append(out, " ...\n"); } } =20 @@ -183,6 +226,9 @@ char *qemu_thread_states(void) if (!dir) { return NULL; } + /* Emit the permission notice ahead of the listing, not inside it */ + thread_stacks_readable(); + out =3D g_string_new(NULL); while ((tid =3D g_dir_read_name(dir))) { if (atoi(tid) !=3D qemu_get_thread_id()) { --=20 2.53.0 From nobody Sat Sep 26 20:51:02 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=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1789504579; cv=none; d=zohomail.com; s=zohoarc; b=L0+73Ua9BKKABxksbDR5djYEh0ge79g98+pl0hPbU/PsyFS5aVSfHdRRAYsrqXE6uR12I2fE4Is7wL2zR4QZf5QedxFIsHEai5Ly7KF4oRCwcEiDQqVQru2UB6D6KL/wB1OpbJbej4zaLGuAAxsjEPA3VAt6jcfTN3uQsc/3k7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789504579; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mfggAYcfW+ee4C8Ti5nGRWscQD6bm2tdaOwAHPoXh0c=; b=B6/0vD8rfg3I9qaZCeH5cOg4GPnGQl91+nSlTToZxjjH+BoThcnm9DHYth/A3FtUDKlYisQH13SvCCHOchv4ZoTdMYaYTiTA3/CZhKyZ35p3fGyD/0gT0R0Lwd64QVpevMouGCGwYPf+AqCgE46dM2xFnSjISONPlEx2aDgIAwI= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789504579625640.1741203265502; Tue, 15 Sep 2026 13:36:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6Zs1-0001KU-25; Tue, 15 Sep 2026 16:35:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x6Zry-0001JJ-Fn for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:10 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6Zrw-0005bo-N2 for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:10 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49b912d3931so1617965e9.3 for ; Tue, 15 Sep 2026 13:35:08 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:f0fe:c7ed:403d:e487]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4870bf37e69sm1504073f8f.29.2026.09.15.13.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 13:35:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1789504507; x=1790109307; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=mfggAYcfW+ee4C8Ti5nGRWscQD6bm2tdaOwAHPoXh0c=; b=Un8RtduvA8y0gTfc2Nk3fo1m/tECufJiIsxG/KVnOboKN2NoC/7log+JBPmasTSlKr 1voMWfS4lkEru7IgGZ9tlcWMp1kJ4arHXf3BJvTLkcLlGk/cxv8ze4Nj3rUMGL+S8ROy 0qyBxxW/OPMpFvVhuY7RbzTmXcPLbb+7J3VRmwF6i/2isXMfhJZurB29TQLw9HdlcwWK x96MG472GzJgqNUY/kmnt45wTPu7m7UktxT5oW4h1FVLyfMGFh/aGTBNxLxikjrCiNzi WE8AMfCI1V6LkKnYpzcQHZy6fFtceEy7lb4y5SZXXeLD90xjTcIegXwJcToRv8FvpPP2 f+jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789504507; x=1790109307; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=mfggAYcfW+ee4C8Ti5nGRWscQD6bm2tdaOwAHPoXh0c=; b=FYKL7xIjutc3Bns9FAK8r7IHvp0+hF9c1H67fWNLIaqXMM1b6GA/r+qPRt10oZjTtf MGp00VY2Yi8jTf7xp8iSQ3HmwZ9s4/n5QhYNtTzn+nzkxTn7kvMLsuUsIbVZSK5wELxx mhijPGxGYrs+OZ9bISXm7GLQtka+ym3c8M89i7edmN3etsMYCvyfJEwawjwysMiXlHNI mlpCRAUbR91dC+8tWlV+RgotnVPRq5nemNxsk8DIZ1kqTKBmVxdNLac3OHOuC4z9e1HD ep2SWKtioIvyLEqMz2+nbKOuQK9Qp/HaVwH8e4eTxFzRSQ2sBzqoaMIFLyrZCj8y+k1B sN1A== X-Gm-Message-State: AFuF++m2KpjA8GdWhS64eJh/DVpKXw3z4kTemspeVi5bhDdvtBYZWWOf RGoOIxaltNGyFKzTj0iyMLTZ0T73JP5Q6raB0PG/+p0DWGfn/bOGArVozQIJ8K3KR5d0S63EUZ2 4PnUM X-Gm-Gg: AYBFou3NKvfyLZalbkXrsqiWAQsrezdxCJpafAg2zVJix+PexWZLDecUob0M3wOyrel pL8Ka/eW4lYd4+EbCFEfUUtah1hL0yAQqpuq+XI5qfTReSeJZA/0cGcB+2o6CkCrJ6oZHxbR2dP ABOFaAnZGAa+Z+eQN9G76i6hIbykZh+ixqIH+o0xBdaC3pZIYk093/RZeYE/kp8LRia18hOvN6B Qa61hbIxwLUYnJ2IdALcCYDYX+W8Gf1w3Bh6GtRuCjixZxJ1ZtzXphEwvKf3+siXcill47Ti9gh kquEd2wVxsx7u/DxbY2naf7oO7g7oaidO4/VYYxrcUF20Gsyrn2aJddqkHOlnBHZGnlz8VClTKa 7uJgwkmtsCFvQ3IhQe+gIRG8NmTmi2y95iDSz+UK2YAdxdLxO/UVCUa75bAJZDAmxaqr7qq+Fll cgOLCkVa9h1qeXYvDPpfN5msKz1mLAvbMWUMYMGPGefawcofnHb5SNsuYIKysOiG5RW8zum7WW+ zyVwI8= X-Received: by 2002:a05:600c:35c2:b0:49c:eb16:9fd with SMTP id 5b1f17b1804b1-49e821ffef1mr43234155e9.3.1789504507309; Tue, 15 Sep 2026 13:35:07 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu Subject: [PATCH 05/10] util/qemu-thread: reserve a signal for thread introspection Date: Tue, 15 Sep 2026 22:34:49 +0200 Message-ID: <20260915203455.580999-6-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260915203455.580999-1-den@openvz.org> References: <20260915203455.580999-1-den@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.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, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1789504580409158500 From: Denis V. Lunev qemu_thread_create() blocks every signal in the threads it starts so that process directed signals reach the main loop and nowhere else. That reasoning covers delivery the kernel is free to route: kill(2) picks any thread not blocking the signal, so leaving SIGTERM or SIGCHLD unblocked in a worker would let signalfd miss them. A thread directed signal is not routed. tgkill(2) delivers to the named thread whatever every other mask says, so a signal only ever sent that way was never the main loop's to receive, and unblocking it takes nothing from it. Reserve SIGRTMIN for asking a thread what it is doing, and leave that one unblocked. Nothing sends it yet, and until something installs a handler the change is invisible: a real time signal terminates by default, which is already what a stray one does through the main thread, where it was never blocked either. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Philippe Mathieu-Daud=C3=A9 Cc: Zhao Liu Signed-off-by: Denis V. Lunev --- include/qemu/osdep.h | 9 +++++++++ util/qemu-thread-posix.c | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index c15ffd7880..0bd08e0f7f 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -667,6 +667,15 @@ int qemu_get_thread_id(void); */ bool qemu_debugger_attached(void); =20 +/* + * Signal reserved for asking a thread what it is doing. It is only ever + * sent thread directed, so it does not compete for the process directed + * signals that qemu routes to the main loop. + */ +#if defined(SIGRTMIN) && !defined(_WIN32) +#define QEMU_SIG_INTROSPECT SIGRTMIN +#endif + /** * qemu_thread_states: * diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 580cdf8079..66bde85608 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -444,6 +444,10 @@ void qemu_thread_create(QemuThread *thread, const char= *name, sigdelset(&set, SIGFPE); sigdelset(&set, SIGILL); /* TODO avoid SIGBUS loss on macOS */ +#ifdef QEMU_SIG_INTROSPECT + /* Thread directed, so it was never the iothread's to receive */ + sigdelset(&set, QEMU_SIG_INTROSPECT); +#endif pthread_sigmask(SIG_SETMASK, &set, &oldset); =20 qemu_thread_args =3D g_new0(QemuThreadArgs, 1); --=20 2.53.0 From nobody Sat Sep 26 20:51:02 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=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1789504548; cv=none; d=zohomail.com; s=zohoarc; b=fb2ckLUXYDzeCn7vMRgtCyjwdvrqdG9Yu7eRNwO3/WD3H1KaTHgA17XJfocRrCo7eAyBf3EhhHiupazgqBR4hs0XbRuSWOxDyU2Rz7eskCL7f+sz378AL0yeFUHfEDJM5cYxL03puoJgCVHjM+XKLgq0UTQ6G0Bv4tqLRSI80e8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789504548; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZIoeg91zeWuTpwxotQCiRuVpQN1XOyBCM3H3hj1KbdA=; b=XpV/WNrJRBxqpKbd9NtNUuklPYBuPyklB43qArUmM+z7S6YGBwchR2UQndiFGIyx/+cfplQQalWfXEFroTLzKFra5gLfrKJOOL9QWrwx5MSHdjSe7UKkeaMa43ZWhtzknKiaOSGA0zYmCsd6wM2Hfe2j4wzdGVQTJsNYNDRfqgM= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17895045486407.6704280485074605; Tue, 15 Sep 2026 13:35:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6Zs3-0001N8-IP; Tue, 15 Sep 2026 16:35:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x6Zs0-0001KV-Qf for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:12 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6Zry-0005c4-1f for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:12 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49b912d37b6so1072865e9.0 for ; Tue, 15 Sep 2026 13:35:09 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:f0fe:c7ed:403d:e487]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4870bf37e69sm1504073f8f.29.2026.09.15.13.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 13:35:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1789504509; x=1790109309; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ZIoeg91zeWuTpwxotQCiRuVpQN1XOyBCM3H3hj1KbdA=; b=KXeDp5JlK7eCLOqvyhWqCuTBSUqE13uassb5Li5a7iHjlbspKO+bBrDkstgASIqTTV YHj+qXh7AwtNZF80XLldFQIXD4EOzrvkzbsMucBnNwGn32ztOffPjXEqVH+3lpJzTQQn yFALqzmIo/A3lh6mhhKmIZSVrgnnWH2rLgL/qoEXzyZcgxSeirfkdeFV9y6WFwFot4Wu mLapJePknVBL3UmrZBzNjxnPw45nG9flPRng+KyVxWbDq9WQDSQq9rODmLI8k/L3YRoE WxBxOAp7filCt5GnK6183eXNPv1WdlO51FI1yHdYyHTb2WlsmuA2R2i7mzs9Pw9rWRB2 Eb+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789504509; x=1790109309; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ZIoeg91zeWuTpwxotQCiRuVpQN1XOyBCM3H3hj1KbdA=; b=NIc2/C2gqLanWQ6nySuZbgMJol8gLWEpO5r7dEcvkbQnoxBwXpVrPEPiEdSbap9TI1 Pc5HeFHWnYvbg2rKvrlesCTnQDWLCNpR8DgpDVoT2MQVdMUpqKK7lFJXH3ffjqO+N0u3 NNNXjVaf6yKgK4+mEIpMJXRUKPJePdLH64lFuCUSSLw4uo6O7gzcZ3tTDXyRz3i5D1B/ 345ez0OyMcnPNdqPX+pb5d3zOWMkGcTDiZqLHjIFL6gM126brlovE9XWHLQ8KN5mBer4 QKeUyvixAtz4X1rXUr49WpMnp2/enqu/HqP55B9WpxHz5ct1jgEFJHHgFI/ijmxhwfFE 3hXQ== X-Gm-Message-State: AFuF++k6TWIChZkieFcNUjEeVXsO1aNtoSYDax0WwYJoKCD5hENk5XxF 3Xj1rdk1pBSLRgvJgyR1LEpI8cyQfiIutTKRROliDB5FHGGY/n0r5/92ozbxyf9bvOqM4UgIe8+ tqKfC X-Gm-Gg: AYBFou0kMPfKgt2pV9FWpA+XEwwjjEYFNuIu/9Mh4Wii4R8r/XYmD8WVTzfIfE7f2t0 m0Ey90jTGtnuoPZH9LJIN3XyDvoxgGmjIgwvGc3R1ECS1KHXCr9zfJaf03dKMXdEZlGB0TJqt/I 4+LyNJHvt/QTCtUw0tSVR4XWHDNK2c19j/Y6k5W5iZL+vAn7o3Ztu4nNVeDdKA/Aln5M8NqAM7K kKJskKjNQSWEWnBJmK3/x5xQ95g9953pkzNVKjo5vEZBXNgdyq1YRP82kcfIKQ/q1H3G4Queuz4 cNB64W5Y/I5BO+sPIkhYKOllB3MeijpYCiPFpYhk8uF7exfVQVusbUAyeOFeZL1Mz3Muc5sZ0WH wNnu3N142QID3mzQnGEQknnBKPDxUb+Klj46i+VwRvZLnmeBXUIg+P/VfKG5DOTznUa7AdfLvj6 nmZq4RGlfrr01Ih2XagQ4zizd9POyMZThirR4r/imco3IEjkSHpzph4Bib3A+ShZ2sOjB0S4zid Qdf+L8= X-Received: by 2002:adf:e19d:0:b0:486:f958:f221 with SMTP id ffacd0b85a97d-4870cedc88dmr350792f8f.5.1789504508663; Tue, 15 Sep 2026 13:35:08 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Pierrick Bouvier Subject: [PATCH 06/10] oslib: report each thread's program counter Date: Tue, 15 Sep 2026 22:34:50 +0200 Message-ID: <20260915203455.580999-7-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260915203455.580999-1-den@openvz.org> References: <20260915203455.580999-1-den@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=den@openvz.org; helo=mail-wm2-x11.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1789504550433158501 From: Denis V. Lunev A kernel stack describes a thread asleep in a syscall and says nothing about one spinning in userspace, which is the other way a thread stops making progress. Ask each thread where it is by signalling it and reading the program counter out of the signal frame. That is a register read and a store, which a handler may do, unlike unwinding: backtrace() is not async signal safe and takes the loader lock the first time it runs. Ask all of them at once, once every passive read is taken. The signal interrupts whatever a thread was blocked in, so probing earlier would make the kernel stack and the wait channel describe the interruption instead of the hang, and probing one at a time would spend the timeout again for every thread that never answers. Insert the answers from the back, so the offsets recorded during the reads still point where they did. A thread that never answers within the deadline can still run the handler later, once whatever held it lets go, and by then the slots it would write to are gone. Count handlers between entry and exit, withdraw the slots when the deadline expires and wait for the last handler out before returning to the caller that frees them. A handler that arrives after the withdrawal finds nothing to write to. Where the counter sits in the signal frame is a host property, so it is answered from host/include like the other per-host questions, with a generic fallback that reports no counter and leaves the host otherwise untouched. The Linux hosts covered are the ones whose signal frames linux-user already describes in host-signal.h. Name the address through dladdr() where there is a symbol for it. There often is not, because dladdr() sees exported symbols only and a thread parked inside a library sits in its internals, so fall back to the object and the offset within it. An offset resolves against the library afterwards; the raw address does not survive the process. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Philippe Mathieu-Daud=C3=A9 Cc: Zhao Liu Cc: Daniel P. Berrang=C3=A9 Cc: Marc-Andr=C3=A9 Lureau Cc: Pierrick Bouvier Signed-off-by: Denis V. Lunev --- host/include/aarch64/host/signal-pc.h | 20 +++ host/include/generic/host/signal-pc.h | 11 ++ host/include/loongarch64/host/signal-pc.h | 20 +++ host/include/ppc64/host/signal-pc.h | 22 +++ host/include/riscv64/host/signal-pc.h | 20 +++ host/include/s390x/host/signal-pc.h | 20 +++ host/include/x86_64/host/signal-pc.h | 20 +++ include/qemu/osdep.h | 7 +- meson.build | 2 + util/oslib-posix.c | 181 +++++++++++++++++++++- 10 files changed, 318 insertions(+), 5 deletions(-) create mode 100644 host/include/aarch64/host/signal-pc.h create mode 100644 host/include/generic/host/signal-pc.h create mode 100644 host/include/loongarch64/host/signal-pc.h create mode 100644 host/include/ppc64/host/signal-pc.h create mode 100644 host/include/riscv64/host/signal-pc.h create mode 100644 host/include/s390x/host/signal-pc.h create mode 100644 host/include/x86_64/host/signal-pc.h diff --git a/host/include/aarch64/host/signal-pc.h b/host/include/aarch64/h= ost/signal-pc.h new file mode 100644 index 0000000000..fe60ed1c96 --- /dev/null +++ b/host/include/aarch64/host/signal-pc.h @@ -0,0 +1,20 @@ +/* + * Program counter of an interrupted aarch64 thread, from its signal frame. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef AARCH64_HOST_SIGNAL_PC_H +#define AARCH64_HOST_SIGNAL_PC_H + +#ifdef CONFIG_LINUX +#define HAVE_HOST_SIGNAL_PC 1 + +static inline uintptr_t host_signal_pc(const ucontext_t *uc) +{ + return uc->uc_mcontext.pc; +} +#else +#define HAVE_HOST_SIGNAL_PC 0 +#endif + +#endif diff --git a/host/include/generic/host/signal-pc.h b/host/include/generic/h= ost/signal-pc.h new file mode 100644 index 0000000000..8ce3822069 --- /dev/null +++ b/host/include/generic/host/signal-pc.h @@ -0,0 +1,11 @@ +/* + * No host specific way to read the program counter from a signal frame. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HOST_SIGNAL_PC_H +#define HOST_SIGNAL_PC_H + +#define HAVE_HOST_SIGNAL_PC 0 + +#endif diff --git a/host/include/loongarch64/host/signal-pc.h b/host/include/loong= arch64/host/signal-pc.h new file mode 100644 index 0000000000..ccb2ac1c56 --- /dev/null +++ b/host/include/loongarch64/host/signal-pc.h @@ -0,0 +1,20 @@ +/* + * Program counter of an interrupted loongarch64 thread, from its signal f= rame. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef LOONGARCH64_HOST_SIGNAL_PC_H +#define LOONGARCH64_HOST_SIGNAL_PC_H + +#ifdef CONFIG_LINUX +#define HAVE_HOST_SIGNAL_PC 1 + +static inline uintptr_t host_signal_pc(const ucontext_t *uc) +{ + return uc->uc_mcontext.__pc; +} +#else +#define HAVE_HOST_SIGNAL_PC 0 +#endif + +#endif diff --git a/host/include/ppc64/host/signal-pc.h b/host/include/ppc64/host/= signal-pc.h new file mode 100644 index 0000000000..1473570a39 --- /dev/null +++ b/host/include/ppc64/host/signal-pc.h @@ -0,0 +1,22 @@ +/* + * Program counter of an interrupted ppc64 thread, from its signal frame. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef PPC64_HOST_SIGNAL_PC_H +#define PPC64_HOST_SIGNAL_PC_H + +#ifdef CONFIG_LINUX +#include + +#define HAVE_HOST_SIGNAL_PC 1 + +static inline uintptr_t host_signal_pc(const ucontext_t *uc) +{ + return uc->uc_mcontext.gp_regs[PT_NIP]; +} +#else +#define HAVE_HOST_SIGNAL_PC 0 +#endif + +#endif diff --git a/host/include/riscv64/host/signal-pc.h b/host/include/riscv64/h= ost/signal-pc.h new file mode 100644 index 0000000000..362b446040 --- /dev/null +++ b/host/include/riscv64/host/signal-pc.h @@ -0,0 +1,20 @@ +/* + * Program counter of an interrupted riscv64 thread, from its signal frame. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef RISCV64_HOST_SIGNAL_PC_H +#define RISCV64_HOST_SIGNAL_PC_H + +#ifdef CONFIG_LINUX +#define HAVE_HOST_SIGNAL_PC 1 + +static inline uintptr_t host_signal_pc(const ucontext_t *uc) +{ + return uc->uc_mcontext.__gregs[REG_PC]; +} +#else +#define HAVE_HOST_SIGNAL_PC 0 +#endif + +#endif diff --git a/host/include/s390x/host/signal-pc.h b/host/include/s390x/host/= signal-pc.h new file mode 100644 index 0000000000..6ad809c911 --- /dev/null +++ b/host/include/s390x/host/signal-pc.h @@ -0,0 +1,20 @@ +/* + * Program counter of an interrupted s390x thread, from its signal frame. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef S390X_HOST_SIGNAL_PC_H +#define S390X_HOST_SIGNAL_PC_H + +#ifdef CONFIG_LINUX +#define HAVE_HOST_SIGNAL_PC 1 + +static inline uintptr_t host_signal_pc(const ucontext_t *uc) +{ + return uc->uc_mcontext.psw.addr; +} +#else +#define HAVE_HOST_SIGNAL_PC 0 +#endif + +#endif diff --git a/host/include/x86_64/host/signal-pc.h b/host/include/x86_64/hos= t/signal-pc.h new file mode 100644 index 0000000000..c94ad2e976 --- /dev/null +++ b/host/include/x86_64/host/signal-pc.h @@ -0,0 +1,20 @@ +/* + * Program counter of an interrupted x86_64 thread, from its signal frame. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef X86_64_HOST_SIGNAL_PC_H +#define X86_64_HOST_SIGNAL_PC_H + +#ifdef CONFIG_LINUX +#define HAVE_HOST_SIGNAL_PC 1 + +static inline uintptr_t host_signal_pc(const ucontext_t *uc) +{ + return uc->uc_mcontext.gregs[REG_RIP]; +} +#else +#define HAVE_HOST_SIGNAL_PC 0 +#endif + +#endif diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 0bd08e0f7f..00eeb5dcc9 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -680,9 +680,10 @@ bool qemu_debugger_attached(void); * qemu_thread_states: * * Returns a newly allocated, newline terminated description of every thre= ad - * in this process apart from the caller: its id, name, scheduler state and - * kernel stack, or NULL on a host that cannot report any of that. Where t= he - * kernel stack is privileged the description falls back to a wait channel. + * in this process apart from the caller: its id, name, scheduler state, t= he + * program counter it stopped at and its kernel stack, or NULL on a host t= hat + * cannot report any of that. A privileged kernel stack falls back to a wa= it + * channel, and a host with no way to read a program counter omits it. */ char *qemu_thread_states(void); =20 diff --git a/meson.build b/meson.build index cfac634cf1..25e8842918 100644 --- a/meson.build +++ b/meson.build @@ -2646,6 +2646,8 @@ config_host_data.set('HAVE_GETIFADDRS', cc.has_functi= on('getifaddrs')) config_host_data.set('HAVE_GLIB_WITH_SLICE_ALLOCATOR', glib_has_gslice) config_host_data.set('HAVE_OPENPTY', cc.has_function('openpty', dependenci= es: util)) config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul', prefix= : osdep_prefix)) +config_host_data.set('CONFIG_DLADDR', cc.has_function('dladdr', + prefix: osdep_prefix + '#include ')) config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', pre= fix: '#include ')) if rbd.found() config_host_data.set('HAVE_RBD_NAMESPACE_EXISTS', diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 6a683b849e..ddc2b48df2 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -58,8 +58,13 @@ #include #endif =20 +#ifdef CONFIG_DLADDR +#include +#endif + #include "qemu/memalign.h" #include "qemu/mmap-alloc.h" +#include "host/signal-pc.h" =20 #define MAX_MEM_PREALLOC_THREAD_COUNT 32 =20 @@ -168,8 +173,164 @@ static bool thread_stacks_readable(void) return readable; } =20 -static void append_thread_state(GString *out, const char *tid) +/* Where a thread was, and where its line belongs in the report */ +typedef struct { + int tid; + size_t at; + void *pc; + int done; +} ThreadPc; + +#if HAVE_HOST_SIGNAL_PC + +/* How long to wait for the answers, however many threads were asked */ +#define THREAD_PC_WAIT_MS 100 + +/* + * Published to the handler, which runs in whichever thread was interrupted + * and so may only touch this with atomics: every qemu synchronisation + * primitive is built on a mutex, and none of them may be taken here. + * pc_handlers counts handlers between entry and exit, so the slots can be + * withdrawn and the last handler waited out before the caller frees them. + */ +static ThreadPc *pc_slots; +static int pc_nslots; +static int pc_handlers; + +static void thread_pc_handler(int sig, siginfo_t *si, void *ctx) +{ + ThreadPc *slots; + int me, i, n; + + qatomic_inc(&pc_handlers); + smp_mb__after_rmw(); + slots =3D qatomic_load_acquire(&pc_slots); + if (slots) { + n =3D qatomic_read(&pc_nslots); + me =3D qemu_get_thread_id(); + for (i =3D 0; i < n; i++) { + if (qatomic_read(&slots[i].tid) =3D=3D me) { + slots[i].pc =3D (void *)host_signal_pc(ctx); + qatomic_store_release(&slots[i].done, 1); + break; + } + } + } + qatomic_dec(&pc_handlers); +} + +static bool thread_pc_armed(void) +{ + static int armed =3D -1; + struct sigaction sa; + + if (armed >=3D 0) { + return armed; + } + memset(&sa, 0, sizeof(sa)); + sa.sa_sigaction =3D thread_pc_handler; + sa.sa_flags =3D SA_SIGINFO | SA_RESTART; + sigemptyset(&sa.sa_mask); + armed =3D sigaction(QEMU_SIG_INTROSPECT, &sa, NULL) =3D=3D 0; + return armed; +} + +/* + * Ask every thread at once. Asking one at a time would spend the timeout + * again for each thread that never answers, and the threads that never + * answer are the ones a hung qemu has most of. + */ +static void thread_pc_collect(GArray *slots) { + int64_t deadline; + guint i; + int left; + + if (!slots->len || !thread_pc_armed()) { + return; + } + qatomic_set(&pc_nslots, slots->len); + qatomic_store_release(&pc_slots, &g_array_index(slots, ThreadPc, 0)); + + for (i =3D 0; i < slots->len; i++) { + ThreadPc *slot =3D &g_array_index(slots, ThreadPc, i); + + if (qemu_kill_thread(slot->tid, QEMU_SIG_INTROSPECT) < 0) { + qatomic_store_release(&slot->done, -1); + } + } + + deadline =3D g_get_monotonic_time() + THREAD_PC_WAIT_MS * 1000; + do { + left =3D 0; + for (i =3D 0; i < slots->len; i++) { + if (!qatomic_load_acquire(&g_array_index(slots, ThreadPc, + i).done)) { + left++; + } + } + if (!left) { + break; + } + g_usleep(1000); + } while (g_get_monotonic_time() < deadline); + + qatomic_set(&pc_slots, NULL); + /* Pairs with the barrier in thread_pc_handler() */ + smp_mb(); + while (qatomic_read(&pc_handlers)) { + g_usleep(1000); + } +} + +static void insert_thread_pc(GString *out, const ThreadPc *slot) +{ + g_autofree char *line =3D NULL; + void *pc =3D slot->pc; +#ifdef CONFIG_DLADDR + Dl_info info =3D { }; +#endif + + if (qatomic_read(&slot->done) !=3D 1 || !pc) { + return; + } +#ifdef CONFIG_DLADDR + if (dladdr(pc, &info) && info.dli_sname) { + line =3D g_strdup_printf(" pc %p %s+0x%tx\n", pc, info.dli_sn= ame, + (char *)pc - (char *)info.dli_saddr); + } else if (info.dli_fname && info.dli_fbase) { + /* + * dladdr() only knows exported symbols, so an address inside a + * library's own internals has none. The object and the offset + * within it still resolve later, the raw address does not. + */ + g_autofree char *obj =3D g_path_get_basename(info.dli_fname); + + line =3D g_strdup_printf(" pc %p %s+0x%tx\n", pc, obj, + (char *)pc - (char *)info.dli_fbase); + } +#endif + if (!line) { + line =3D g_strdup_printf(" pc %p\n", pc); + } + g_string_insert(out, slot->at, line); +} + +#else + +static void thread_pc_collect(GArray *slots) +{ +} + +static void insert_thread_pc(GString *out, const ThreadPc *slot) +{ +} + +#endif /* HAVE_HOST_SIGNAL_PC */ + +static void append_thread_state(GString *out, GArray *slots, const char *t= id) +{ + ThreadPc slot =3D { }; g_autofree char *comm =3D read_task_file(tid, "comm"); g_autofree char *stat =3D NULL; g_autofree char *stack =3D NULL; @@ -194,6 +355,10 @@ static void append_thread_state(GString *out, const ch= ar *tid) } g_string_append_printf(out, " %-7s %-16s %c\n", tid, comm, state); =20 + slot.tid =3D atoi(tid); + slot.at =3D out->len; + g_array_append_val(slots, slot); + /* A running thread has no settled kernel stack to unwind */ if (state !=3D 'R' && thread_stacks_readable()) { stack =3D read_task_file(tid, "stack"); @@ -220,8 +385,10 @@ static void append_thread_state(GString *out, const ch= ar *tid) char *qemu_thread_states(void) { g_autoptr(GDir) dir =3D g_dir_open("/proc/self/task", 0, NULL); + g_autoptr(GArray) slots =3D g_array_new(FALSE, TRUE, sizeof(ThreadPc)); const char *tid; GString *out; + guint i; =20 if (!dir) { return NULL; @@ -232,13 +399,23 @@ char *qemu_thread_states(void) out =3D g_string_new(NULL); while ((tid =3D g_dir_read_name(dir))) { if (atoi(tid) !=3D qemu_get_thread_id()) { - append_thread_state(out, tid); + append_thread_state(out, slots, tid); } } if (!out->len) { g_string_free(out, TRUE); return NULL; } + + /* + * Only now, with every passive read taken, disturb the threads. Insert + * from the back so the offsets recorded above stay where they were. + */ + thread_pc_collect(slots); + for (i =3D slots->len; i > 0; i--) { + insert_thread_pc(out, &g_array_index(slots, ThreadPc, i - 1)); + } + return g_string_free(out, FALSE); } =20 --=20 2.53.0 From nobody Sat Sep 26 20:51:02 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=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1789504574; cv=none; d=zohomail.com; s=zohoarc; b=QGri242FcfxpUzes7nb3psILnQ+rqYzKahwJZ61hMjGqMeMMPEfOfiN+eZcrsIz0nC+OCOEm3oBMnRKI+SY/iFOSeNw6D+qeTSifve1B14sgcT/d5EwkjjwG3CoZ5GIIzs4LAvDkYQizhkRNbHhtczWQXgAiIh52VcGxeiY5kF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789504574; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oBBGUd0tnUmZGDjKutUwl1+Hd5+Ihg+QY1Fkbe3I8cQ=; b=L+cagEoH92zM9UF0lealt919vn8CJ9fiG7Qijb09oSz2CcHxRlYQYfwpRIlNX6qxh6F/4H/LSlRdocEZXobV2JHhFVnL+hdD87wScQmfNy6an9hzymLeXK95DyZ/o3ArIr12j/FfcIbq1OpP7k3iqNGdp3MwR5fL1VZ559J0gAM= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789504574836180.17026607831258; Tue, 15 Sep 2026 13:36:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6Zs7-0001Q3-8y; Tue, 15 Sep 2026 16:35:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x6Zs1-0001L2-7P for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:13 -0400 Received: from mail-wr2-x10.google.com ([2a00:1450:4864:30::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6Zrz-0005cH-2e for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:12 -0400 Received: by mail-wr2-x10.google.com with SMTP id ffacd0b85a97d-48583cc7ab1so57850f8f.2 for ; Tue, 15 Sep 2026 13:35:10 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:f0fe:c7ed:403d:e487]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4870bf37e69sm1504073f8f.29.2026.09.15.13.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 13:35:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1789504510; x=1790109310; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=oBBGUd0tnUmZGDjKutUwl1+Hd5+Ihg+QY1Fkbe3I8cQ=; b=Q74wUeo2y4bUX7JLVnaGp6F3EWg4c1/gi9iCwH5zfw7h6qw/oHZu02yZ/z3IUJZzBe 6pq5w0GbwBzOg8eiK189CFse7POC9Da4m5LXpYTP8kDMmcKBVX4LXVgSgPjwmhBf6aEf DCotP4gi/sqB/7Oa6SnVUyBqt62oD+zVFQGogBKl5rYcHF5ns0wgfIuzqBiSa9UZ4Y56 TCBIOCnTf9zT08KvzvnTKdSoZ/mM/L+bYkV+CUjfwT2e5lXvAUkxTxSMicgekVRKaxfG B+XgkP648sDHg28DOrD7gemOJeS5XElj4l4ZuEkGusctd1eyMa1MjWMlujbJhVognamR UA+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789504510; x=1790109310; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=oBBGUd0tnUmZGDjKutUwl1+Hd5+Ihg+QY1Fkbe3I8cQ=; b=isQrd6zusOvI4k92y6vN9gNz5elcKLkfDfr8z8SE8FPiwtRM6sTjyTatUALi+p1J8v bUGEmWPh6Ly77jLXHFba7WJlV9ytD2MnfRyEtJCm3RYStcCWZxKgewZGP6XacgsgSwzQ NgIZm7aFhkdZCiLxZNyZw4cDCefLyVROCNpEfnheb+HzyCppiRTuIdEHf5Bp9YW7X/wv NehY3Qh2VJEryWjfnSB5C283G5xbCqObPU6qSUnZfbXkXumn+aDyQbFIkPenTEr4PR3w 2hPlJJa2ccDkp8mVll37dCamtolbS7P09y1BG0zWiXTNWMKQro3ojGMnzLnSVSIQcyyL YPBQ== X-Gm-Message-State: AFuF++nbCw7+4WsbUsV5QCXxwStsTNCOG3Q57PHvoyyuCOqwznWmybbZ WvidwSYXSQNOAlfCt6+Sx17vjfExh0jeXqbHHofxQ/L0FlLJ2cHFQYHUql3MKUuY1ea3hG0fYrF vqQxt X-Gm-Gg: AYBFou1WlQugaRRXrdYHawMt8pe9fNuuAj1LNGTcn1LXaYGCKtlxMMRL8YER+nRAF8D fdJiD4NZuHaWxqURJ8DsyrXKknksW1VApxdtUpazN/nwgMDlWU1UsjKS6dmYrvJM1U1VnhhzVlW WbBNgLzJldv1ZiyJNXDwz9kQ+jg+D09XUSA7VYPWk2I6ALcyTIOoHBxolwYB7THlwPXWeZ70ELa IctwwSQaXO633G5x7JRN1mD4mWbD0IHQLi+rPfhLHOcVcgRk4mckhu8oFt3SAjBmq01ZqI78xmv pQBmHnaNXOpgMlL5prl7G5ZAdkr77NS8qM/F038wwb0V2SyjJqVVmSvgUpIgw8C8zG7AMn1FeiG fmSQqyLJ8s7slhblXw2nw+x2yq1Uy+q9RKh1Ld8wyNic2M+ECkz6wVxDazgAqXkCifySoY4B4xE AZ0lwBA2o0NqWLXQw2WkwyKRNzPvwlyfCqtuUpYns+2JqQQXLz3SQ1HCaTj0B4DsXt+pBmbg== X-Received: by 2002:a05:6000:200e:b0:487:c4b:71c5 with SMTP id ffacd0b85a97d-4870cf0498cmr155019f8f.17.1789504509614; Tue, 15 Sep 2026 13:35:09 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu Subject: [PATCH 07/10] system/cpus: report a BQL held past a deadline Date: Tue, 15 Sep 2026 22:34:51 +0200 Message-ID: <20260915203455.580999-8-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260915203455.580999-1-den@openvz.org> References: <20260915203455.580999-1-den@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::10; envelope-from=den@openvz.org; helo=mail-wr2-x10.google.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, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1789504576322158500 From: Denis V. Lunev A vCPU thread reacquires the BQL on every exit that needs userspace, so a lock held for tens of seconds stops those vCPUs dead and the guest reports its own soft lockup. Nothing in qemu records that this happened, which leaves a guest panic as the only evidence and no way to tell a stuck holder from a guest that wedged on its own. Add a BQL watchdog. A thread of its own samples a counter advanced on every acquire and every release, so it is odd while the lock is held. One odd value seen throughout the window means a single owner held the lock for the whole window, because any handover would have advanced the counter twice. Advance it in bql_update_status(), which the mutex hooks already call for exactly those two transitions, so a cond-wait that drops and retakes the lock is covered without the wrappers knowing, and so is any caller that reaches the BQL through the plain mutex API. Record the holder's tid beside it, under the same lock, because the thread listing alone cannot tell a thread parked on its own condvar from one blocked on the BQL. Cache the tid per thread, since gettid is a syscall and this is the lock path. On expiry, name the holder and list every thread's state. The listing separates a thread blocked on the BQL, which waits in a futex, from one idle inside KVM, which waits in kvm_vcpu_block, and names the syscall a wedged holder is stuck in. Report once per episode, or a lock held for a minute buries the log in copies of one answer. Put the time on the line unless -msg timestamp=3Don already does: a hold is only worth reporting if it can be lined up against what the guest saw, and that option has to be asked for in advance. The deadline has to clear the longest legitimate hold, and migration setup can hold the BQL for a while, so the watchdog stays off unless asked for. The bql-watchdog-ms machine property is the whole interface: it sets the deadline, on the command line or over qom-set at any time, and 0 turns the watchdog off. Reject a deadline above a minute: a hold that long has already shown up as a soft lockup inside the guest. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Philippe Mathieu-Daud=C3=A9 Cc: Zhao Liu Signed-off-by: Denis V. Lunev --- hw/core/machine.c | 27 ++++++++++ include/system/cpus.h | 4 ++ qemu-options.hx | 6 +++ system/cpus.c | 120 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index 8939ae1666..b55af89516 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -382,6 +382,27 @@ static void machine_set_dump_guest_core(Object *obj, b= ool value, Error **errp) ms->dump_guest_core =3D value; } =20 +static void machine_get_bql_watchdog_ms(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + uint64_t value =3D bql_watchdog_get_timeout_ms(); + + visit_type_uint64(v, name, &value, errp); +} + +static void machine_set_bql_watchdog_ms(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + uint64_t value; + + if (!visit_type_uint64(v, name, &value, errp)) { + return; + } + bql_watchdog_set_timeout_ms(value, errp); +} + static bool machine_get_new_accel_vmfd_on_reset(Object *obj, Error **errp) { MachineState *ms =3D MACHINE(obj); @@ -1147,6 +1168,12 @@ static void machine_class_init(ObjectClass *oc, cons= t void *data) object_class_property_set_description(oc, "dump-guest-core", "Include guest memory in a core dump"); =20 + object_class_property_add(oc, "bql-watchdog-ms", "uint64", + machine_get_bql_watchdog_ms, machine_set_bql_watchdog_ms, NULL, NU= LL); + object_class_property_set_description(oc, "bql-watchdog-ms", + "Watchdog deadline for a Big QEMU Lock hold, in ms. " + "Default: 0 (disabled)"); + object_class_property_add_bool(oc, "x-change-vmfd-on-reset", machine_get_new_accel_vmfd_on_reset, machine_set_new_accel_vmfd_on_reset); diff --git a/include/system/cpus.h b/include/system/cpus.h index bf36b82376..0e1e63bd85 100644 --- a/include/system/cpus.h +++ b/include/system/cpus.h @@ -40,4 +40,8 @@ void cpu_synchronize_all_post_reset(void); void cpu_synchronize_all_post_init(void); void cpu_synchronize_all_pre_loadvm(void); =20 +/* Watchdog deadline for a BQL hold. 0 disables the watchdog. */ +bool bql_watchdog_set_timeout_ms(uint64_t ms, Error **errp); +uint64_t bql_watchdog_get_timeout_ms(void); + #endif diff --git a/qemu-options.hx b/qemu-options.hx index 2f6863180b..9600620d34 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -32,6 +32,7 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " vmport=3Don|off|auto controls emulation of vmport (de= fault: auto)\n" " dump-guest-core=3Don|off include guest memory in a co= re dump (default=3Don)\n" " mem-merge=3Don|off controls memory merge support (def= ault: on)\n" + " bql-watchdog-ms=3Dms report a Big QEMU Lock held long= er than ms (default: 0, off)\n" " aes-key-wrap=3Don|off controls support for AES key wr= apping (default=3Don)\n" " dea-key-wrap=3Don|off controls support for DEA key wr= apping (default=3Don)\n" " suppress-vmdesc=3Don|off disables self-describing mig= ration (default=3Doff)\n" @@ -88,6 +89,11 @@ SRST supported by the host, de-duplicates identical memory pages among VMs instances (enabled by default). =20 + ``bql-watchdog-ms=3Dms`` + Report when the Big QEMU Lock has been held for more than ``ms`` + milliseconds, up to a minute. The default is 0, which disables the + watchdog. + ``aes-key-wrap=3Don|off`` Enables or disables AES key wrapping support on s390-ccw hosts. This feature controls whether AES wrapping keys will be created diff --git a/system/cpus.c b/system/cpus.c index e11a5aab6a..9e03f303f2 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -31,6 +31,7 @@ #include "exec/cpu-common.h" #include "qemu/thread.h" #include "qemu/main-loop.h" +#include "qemu/error-report.h" #include "qemu/plugin.h" #include "system/cpus.h" #include "qemu/guest-random.h" @@ -367,12 +368,129 @@ static QemuCond qemu_cpu_cond; /* system init */ static QemuCond qemu_pause_cond; =20 +/* + * Advanced by bql_update_status() below, so odd while the BQL is held and + * even while it is free. A sampler that sees one odd value throughout its + * window knows a single owner held the lock for the whole window: any + * handover would have advanced it twice. + */ +static unsigned int bql_seq; + +/* Who advanced bql_seq to its current odd value, 0 while the BQL is free = */ +static int bql_owner_tid; + +static int bql_this_tid(void) +{ + static __thread int tid; + + if (tid) { + return tid; + } + tid =3D qemu_get_thread_id(); + return tid; +} + +/* Poll this many times per timeout, to bound how late the watchdog reacts= */ +#define BQL_WATCHDOG_POLLS 4 + +#define BQL_WATCHDOG_MAX_MS (60 * 1000) + +static QemuThread bql_watchdog_thread; +static QemuSemaphore bql_watchdog_sem; +static uint64_t bql_watchdog_timeout_ms; + +static void bql_report_thread_states(void) +{ + g_autofree char *states =3D qemu_thread_states(); + + if (!states) { + return; + } + qemu_flockfile(stderr); + fputs(states, stderr); + qemu_funlockfile(stderr); +} + +static void *bql_watchdog_fn(void *opaque) +{ + unsigned int last =3D qatomic_read(&bql_seq); + unsigned int reported =3D 0; + int stuck_polls =3D 0; + + for (;;) { + uint64_t timeout_ms =3D qatomic_read(&bql_watchdog_timeout_ms); + g_autofree char *when =3D NULL; + unsigned int seq; + + if (!timeout_ms) { + /* Park rather than exit, so re-arming needs no new thread */ + qemu_sem_wait(&bql_watchdog_sem); + last =3D qatomic_read(&bql_seq); + stuck_polls =3D 0; + continue; + } + qemu_sem_timedwait(&bql_watchdog_sem, + MAX(timeout_ms / BQL_WATCHDOG_POLLS, 1)); + + seq =3D qatomic_read(&bql_seq); + if (seq !=3D last || !(seq & 1)) { + last =3D seq; + stuck_polls =3D 0; + continue; + } + if (++stuck_polls < BQL_WATCHDOG_POLLS) { + continue; + } + if (seq =3D=3D reported) { + continue; + } + reported =3D seq; + if (!message_with_timestamp) { + when =3D real_time_iso8601(); + } + error_report("%s%sBQL held for more than %" PRIu64 " ms by thread = %d", + when ?: "", when ? " " : "", timeout_ms, + qatomic_read(&bql_owner_tid)); + bql_report_thread_states(); + } +} + +uint64_t bql_watchdog_get_timeout_ms(void) +{ + return qatomic_read(&bql_watchdog_timeout_ms); +} + +bool bql_watchdog_set_timeout_ms(uint64_t ms, Error **errp) +{ + static bool started; + + assert(bql_locked()); + if (ms > BQL_WATCHDOG_MAX_MS) { + error_setg(errp, "BQL watchdog deadline must not exceed %d ms", + BQL_WATCHDOG_MAX_MS); + return false; + } + qatomic_set(&bql_watchdog_timeout_ms, ms); + if (!ms) { + return true; + } + if (!started) { + started =3D true; + qemu_thread_create(&bql_watchdog_thread, "bql-watchdog", + bql_watchdog_fn, NULL, QEMU_THREAD_DETACHED); + } else { + qemu_sem_post(&bql_watchdog_sem); + } + return true; +} + void qemu_init_cpu_loop(void) { qemu_init_sigbus(); qemu_cond_init(&qemu_cpu_cond); qemu_cond_init(&qemu_pause_cond); qemu_mutex_init(&bql); + qemu_sem_init(&bql_watchdog_sem, 0); =20 qemu_thread_get_self(&io_thread); } @@ -477,6 +595,8 @@ void bql_update_status(bool locked) /* This function should only be used when an update happened.. */ assert(bql_locked() !=3D locked); set_bql_locked(locked); + qatomic_set(&bql_owner_tid, locked ? bql_this_tid() : 0); + qatomic_set(&bql_seq, qatomic_read(&bql_seq) + 1); } =20 static uint32_t bql_unlock_blocked; --=20 2.53.0 From nobody Sat Sep 26 20:51:02 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=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1789504609; cv=none; d=zohomail.com; s=zohoarc; b=W5axHvbGbgye2pcWJiex4XD9f2ZySM8uqkV1NY+tlNqIc4lfjeGuqQCRMM8Jr4WzYg3C9FPGQdyvhyLJSyX3EqmGCebWYP/lvoZ2Qhlks1rKkG+tm6ERTimZLKJlAJk3yy2n0MnKDcNKVMa1Hw/WOU9mfmQnQhnK9wSrpU68LcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789504609; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ycZ2dbNgs+mypYkIGE7rKDXXsuWLMfAsfKt89XxETm8=; b=Yd+adJtR7ca+e6ZI6mW2LEWLZkFdnOzFdvwE6JApg8KQk2AXQto70FhqPQsztEwRRZqO5O3GXBuu0cW2Baub68G4Dl3DwFarS81YAsdTK3KyGlsAjobIysWECnhK0+Bgd8d/UDMCc58Kxn9fJ4xU3ByaiCD8m/+2hYcqkztk8ug= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789504609028640.9624268743305; Tue, 15 Sep 2026 13:36:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6ZsA-0001Tn-2C; Tue, 15 Sep 2026 16:35:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x6Zs2-0001Lc-1B for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:15 -0400 Received: from mail-wr2-x24.google.com ([2a00:1450:4864:30::24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6Zs0-0005cY-FN for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:13 -0400 Received: by mail-wr2-x24.google.com with SMTP id ffacd0b85a97d-482f63546c3so95582f8f.1 for ; Tue, 15 Sep 2026 13:35:12 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:f0fe:c7ed:403d:e487]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4870bf37e69sm1504073f8f.29.2026.09.15.13.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 13:35:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1789504511; x=1790109311; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ycZ2dbNgs+mypYkIGE7rKDXXsuWLMfAsfKt89XxETm8=; b=p8P2932h2cS0ZxKS7aV1LCtQkh8Rbt/NcFV+auoO5NRV+0NYcXYvvPkuJn1xMlijh4 Ou7PWq6t6ZgPcBCJeodFlDs9ZsLBUCt6sZRtknYykZVlpHf1odJ3udD7EWnYzeu7Jehu oOLwS6flm9k5oEzd4bYApiYykbYmX2hdPhClR8u4py53WtINWvS5Pcj9sl4s3XfV5I6c y2SN8EewCUXq9qDufoY21SCUNHPVartXi2kWn/sl4Vqa4kKxDqRTbC8Ll8LXJEBc499j 7K1NTXAS3VJcZqNWCIQzK6JCKOXE0cRNlW7D+cZMdSuwV0FSbN7jK2iXkTAftcN7r1AC 48OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789504511; x=1790109311; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ycZ2dbNgs+mypYkIGE7rKDXXsuWLMfAsfKt89XxETm8=; b=dq5p+nr3Ljv1rhIU8GPgx3uRTJjKxKbxCnampU2SvdDsv1vpRVVRt796rUVIyAooZ6 xuaD0ih6h653lW5iNoDDatxqeLOO8uCF41mGi9qpt4r66wVYW0wPvYwNCOUfstNHPTJ/ Yee917Ib20EIRgz1QQCvXs2Uj4c+2LjnSj0i7l0HW4hrS31meWResJtCGS69HfZ+Ckrg SIyybgvo0DisB+l9AQSjgl32CPeBH3GVFOSt5a3SANNMyKEM/Dm1x1dCPgjJbykeU09g k9Md3b2q+tL4IRB4IeTEjKKebsLKFGauBVY/a0ODptXASwz/wy7G3x91iTGW4S7mRzwC 2qbA== X-Gm-Message-State: AFuF++l9tRw50dywZ9y+Bn+MttoCB4+XcGMBncO/ikBthHlZ8Pa+DRm0 jumNss0TRXqPT60flQiQmfDnR0t9yohw0yxq+/wd0gkF3EgTYA3WDzWzs1KSJmgU94NzBCHIbg5 NGZ+3 X-Gm-Gg: AYBFou2lUMVSfIEYp5TdGBCnDe6y1DLa+/Ydh5UfxFi8aBy7P3GSxig2JP2APWDj2XO whOWxl1/2tbuVoIaKmbEn0FRcJhH5kA7smsCc3Cbz9K3XJjX0P/zXiXIqLriJJA80HwlV8T5v/s EUeNhtyHPR0qE+ucomtz7JwKUC+8WauPzer3YuWuSPS4riOcjbiSm+o5Z9u21fYd9Ls1SgJsW9q Q7JAmYagT6QonoFfcIIBKqBJPH5xqwSQrEW0rTr7RWSWIqDRHYexMhUaT4Z4wKkgBNxU/khRHif NkccWot2Ep1sFKoP48sX29sXUY+dv6BM1za88xinPB8YPyvG39vt9QXrZaCXGQ0Dpl051Z95G3O Eg2fIhsVaMKuvN+RS0Zgf3cVncN6FurgVS+Ef1kwjqU2pUaS+OJhDuljQndBznEUPUrIDtLlveA +3VCCeiwl0Jqx3gxxaqDuBcoCWIJOjNccVIuw3cZjBbKS5LJmeT5OkFxpOs0oUhD+SdWHWF0BCl 6RiPbQ= X-Received: by 2002:a05:6000:468c:b0:487:7b9:4f7e with SMTP id ffacd0b85a97d-4870cf0acfcmr87577f8f.5.1789504511049; Tue, 15 Sep 2026 13:35:11 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu Subject: [PATCH 08/10] system/cpus: hold off the BQL watchdog under a debugger Date: Tue, 15 Sep 2026 22:34:52 +0200 Message-ID: <20260915203455.580999-9-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260915203455.580999-1-den@openvz.org> References: <20260915203455.580999-1-den@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::24; envelope-from=den@openvz.org; helo=mail-wr2-x24.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1789504610532158500 From: Denis V. Lunev A debugger stops every thread, so the sequence counter freezes at an odd value and the watchdog cannot tell that apart from an owner that never lets go. Attaching gdb to a running guest would report a hang that is not one. Skip the report while a tracer is attached, and restart the count so that a detach gets a full deadline before the watchdog can fire. Any ptracer sets TracerPid, so strace holds the watchdog off as well. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Philippe Mathieu-Daud=C3=A9 Cc: Zhao Liu Signed-off-by: Denis V. Lunev --- system/cpus.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system/cpus.c b/system/cpus.c index 9e03f303f2..03a07e4824 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -441,6 +441,10 @@ static void *bql_watchdog_fn(void *opaque) if (++stuck_polls < BQL_WATCHDOG_POLLS) { continue; } + if (qemu_debugger_attached()) { + stuck_polls =3D 0; + continue; + } if (seq =3D=3D reported) { continue; } --=20 2.53.0 From nobody Sat Sep 26 20:51:02 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=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1789504572; cv=none; d=zohomail.com; s=zohoarc; b=Lxx7dtK3SnnAfMsadmlXzSA6lgqZ9sSZsimLjIbKEoWqSymm5yr1lD5570K1nKINZP8echo0tXab5FkqHnjzdEUk7FGt80xPUFBXD09fFf1UWMnnk5o0M/35abAj5Lj2bt2Q4aai9HY0QGCXVTMO4JtFeE+0c7uPdYWxIggqQYw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789504572; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QW5K/W0TiJTIitpSY5ssNog89nsYvNRU+uFyJOyaiQ4=; b=DPdI5lwwvQKY+1v3MCxxwkKSofyj1schCK4+uLYggIVxY6JEkVbISqQRBQeH/wYSM0eBNPxfBKEchzvVc7cqN+vovaadtMkzSW0gXZ1VtHTZN+UEjCJBJUei6JXDma1cZtbbxzMyZPUYUxI24B93zw1JEeuBhEnCoTohWLNSY1U= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789504572198521.098836271597; Tue, 15 Sep 2026 13:36:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6ZsF-0001UY-Cd; Tue, 15 Sep 2026 16:35:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x6Zs4-0001Qe-QF for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:19 -0400 Received: from mail-wr2-x1a.google.com ([2a00:1450:4864:30::1a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6Zs2-0005d9-U8 for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:16 -0400 Received: by mail-wr2-x1a.google.com with SMTP id ffacd0b85a97d-482f6350f88so83572f8f.2 for ; Tue, 15 Sep 2026 13:35:14 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:f0fe:c7ed:403d:e487]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4870bf37e69sm1504073f8f.29.2026.09.15.13.35.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 13:35:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1789504513; x=1790109313; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=QW5K/W0TiJTIitpSY5ssNog89nsYvNRU+uFyJOyaiQ4=; b=JShp3A5b/+8+CsBTYiO5Umpbt/XsBLbH30okZtX0+tDcFU3OlvGQmWgMbMoXvy/Wn6 nMzXl/sJwEurjq+hamv0GGhZbva7m7G90tKLcz0xUIgjXLXiQPGljWZ6ffhq4ZRu861H 1ogagQz589ovQ0N3uE33oq8oQngOTkEcFFXbDVPFiySRTrzAtQCYVqOVSOh0mIFzyR1I lwriF4822i6h//ZaOqxULt8n2bp5fFmq8HSWyRdqqB8GcMeRp0AK46fIbJolYYb63Jqd e32pREVUyCwA5GdJTuaxpRa+CckZRccImtGHHeGV2v6YLPIH9PCaK31tWmE93hIHp22B u1jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789504513; x=1790109313; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QW5K/W0TiJTIitpSY5ssNog89nsYvNRU+uFyJOyaiQ4=; b=tlWC28Rosoplogl9wk0Grhy0DJpNa7QWmmec2WIHKek8mHRfWI6295L0Qc3qa7Twzv z9n74Yme4ENsppQPrSdyAE3QgWtH+TOFniHt8zw+xW4EVkEQcLXNLtY9B5VnxnW11CFM CEOOqdio2RgeaouR3efHlimjEcybh4niFm0FtrqdAJAsI5+V2Se9IMnaSv2zvJoSfFus f4GB3zua2AS4+xlUz/9K2b1vQhaCUOJspSd1UUwQgV+MUsaai1mBVC+sAYD23XScZNo4 tSHRjCcHrWJszYDswW7kX5pJ0l1XrKN2JE5HEJUq0uCUvPsBmH/HNWEImd2XpZ0wdrW+ SkXQ== X-Gm-Message-State: AFuF++kj6ItoQ77XC4zm6YQAG8f0JUPbUjgUlGl1Dkzop9jT1Smd4XxI uqEtaOZKG/pXd/Wiu54KjC8bomBnmrbiZ3/fC8ybQs1143vpGbZEyql61dUOz1Jk8lBojNzJPqr kSEkw X-Gm-Gg: AYBFou021sCwgs7JVepWrDS1SigD7bc0hqPsClLaQtPu73kS3Rvqfio3Sn99/WTTp7T UDIAkj6SORKkaTwp7eJ9oqO/T+4CM9kYlJsqhJddH6fs9E3Rtaag0FsPZJdi9P534qBwhaioaqu uCDW9bjNL3gjfY/N+4WNhVtQgkDsM4CAt8zeqYXOYPMZGOJlqJcZ3OPTBjn2o00Dxrq3Y6WFRk8 9JyXPUNhbi32Xrql9Bq14rP/virhrOhzwuzQKAoMK2tjmpALNL9ISWQOYtwQCPFdbs/k3MjctQG aIp8RxbWDR4/3EfYpY02gAkinDI56KcVcDEQwrhHCOHAo0uPSMpFf9wd8e9ef1qHT85JYjRItYi WQsVC609WTOEl2K5Ogl22YJXXXaYKuecLJQqPdgTz5yKdJdRehuA6/l95XzPBzbAcpI/q+kuPWp wu6UhCwIzW79mwEIS1HaxpUJmSMnJQbSDsiy9i0Or0W6KOrX+6hejgt6TZIuX13xB/n66v X-Received: by 2002:a05:6000:71c:b0:487:4ba:97f0 with SMTP id ffacd0b85a97d-4870cf31e89mr174072f8f.23.1789504513129; Tue, 15 Sep 2026 13:35:13 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu Subject: [PATCH 09/10] system/cpus: add bql-watchdog-abort Date: Tue, 15 Sep 2026 22:34:53 +0200 Message-ID: <20260915203455.580999-10-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260915203455.580999-1-den@openvz.org> References: <20260915203455.580999-1-den@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::1a; envelope-from=den@openvz.org; helo=mail-wr2-x1a.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1789504574330158500 From: Denis V. Lunev The report says where each thread was when the watchdog looked, not how it got there. A core carries every thread's whole stack, at the price of the guest. A qemu whose BQL has been held this long is not running its vCPUs anyway, so on a host where the answer is worth more than the guest, abort after the report. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Philippe Mathieu-Daud=C3=A9 Cc: Zhao Liu Signed-off-by: Denis V. Lunev --- hw/core/machine.c | 17 +++++++++++++++++ include/system/cpus.h | 4 ++++ qemu-options.hx | 5 +++++ system/cpus.c | 19 +++++++++++++++++++ 4 files changed, 45 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index b55af89516..2abb9e6295 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -403,6 +403,17 @@ static void machine_set_bql_watchdog_ms(Object *obj, V= isitor *v, bql_watchdog_set_timeout_ms(value, errp); } =20 +static bool machine_get_bql_watchdog_abort(Object *obj, Error **errp) +{ + return bql_watchdog_get_abort(); +} + +static void machine_set_bql_watchdog_abort(Object *obj, bool value, + Error **errp) +{ + bql_watchdog_set_abort(value); +} + static bool machine_get_new_accel_vmfd_on_reset(Object *obj, Error **errp) { MachineState *ms =3D MACHINE(obj); @@ -1174,6 +1185,12 @@ static void machine_class_init(ObjectClass *oc, cons= t void *data) "Watchdog deadline for a Big QEMU Lock hold, in ms. " "Default: 0 (disabled)"); =20 + object_class_property_add_bool(oc, "bql-watchdog-abort", + machine_get_bql_watchdog_abort, machine_set_bql_watchdog_abort); + object_class_property_set_description(oc, "bql-watchdog-abort", + "Abort after the bql-watchdog-ms report, to leave a core dump. " + "Default: off"); + object_class_property_add_bool(oc, "x-change-vmfd-on-reset", machine_get_new_accel_vmfd_on_reset, machine_set_new_accel_vmfd_on_reset); diff --git a/include/system/cpus.h b/include/system/cpus.h index 0e1e63bd85..14dbc8ff0d 100644 --- a/include/system/cpus.h +++ b/include/system/cpus.h @@ -44,4 +44,8 @@ void cpu_synchronize_all_pre_loadvm(void); bool bql_watchdog_set_timeout_ms(uint64_t ms, Error **errp); uint64_t bql_watchdog_get_timeout_ms(void); =20 +/* Abort after reporting, to leave a core behind. */ +void bql_watchdog_set_abort(bool enable); +bool bql_watchdog_get_abort(void); + #endif diff --git a/qemu-options.hx b/qemu-options.hx index 9600620d34..f43d8ca480 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -33,6 +33,7 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " dump-guest-core=3Don|off include guest memory in a co= re dump (default=3Don)\n" " mem-merge=3Don|off controls memory merge support (def= ault: on)\n" " bql-watchdog-ms=3Dms report a Big QEMU Lock held long= er than ms (default: 0, off)\n" + " bql-watchdog-abort=3Don|off abort after the bql-watch= dog-ms report (default: off)\n" " aes-key-wrap=3Don|off controls support for AES key wr= apping (default=3Don)\n" " dea-key-wrap=3Don|off controls support for DEA key wr= apping (default=3Don)\n" " suppress-vmdesc=3Don|off disables self-describing mig= ration (default=3Doff)\n" @@ -94,6 +95,10 @@ SRST milliseconds, up to a minute. The default is 0, which disables the watchdog. =20 + ``bql-watchdog-abort=3Don|off`` + Abort after the ``bql-watchdog-ms`` report, to leave a core dump. + The default is off. + ``aes-key-wrap=3Don|off`` Enables or disables AES key wrapping support on s390-ccw hosts. This feature controls whether AES wrapping keys will be created diff --git a/system/cpus.c b/system/cpus.c index 03a07e4824..a200a07707 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -398,6 +398,7 @@ static int bql_this_tid(void) static QemuThread bql_watchdog_thread; static QemuSemaphore bql_watchdog_sem; static uint64_t bql_watchdog_timeout_ms; +static bool bql_watchdog_abort; =20 static void bql_report_thread_states(void) { @@ -411,6 +412,16 @@ static void bql_report_thread_states(void) qemu_funlockfile(stderr); } =20 +bool bql_watchdog_get_abort(void) +{ + return qatomic_read(&bql_watchdog_abort); +} + +void bql_watchdog_set_abort(bool enable) +{ + qatomic_set(&bql_watchdog_abort, enable); +} + static void *bql_watchdog_fn(void *opaque) { unsigned int last =3D qatomic_read(&bql_seq); @@ -456,6 +467,14 @@ static void *bql_watchdog_fn(void *opaque) when ?: "", when ? " " : "", timeout_ms, qatomic_read(&bql_owner_tid)); bql_report_thread_states(); + if (!qatomic_read(&bql_watchdog_abort)) { + continue; + } + /* + * A core carries the whole of every stack, and a qemu whose BQL h= as + * been held this long has stopped running its vCPUs anyway. + */ + abort(); } } =20 --=20 2.53.0 From nobody Sat Sep 26 20:51:02 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=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1789504558; cv=none; d=zohomail.com; s=zohoarc; b=JrciLFNTqO339J8cctYUY792vLddL8TlAEsrW9iWluwXXuEOobJWHPgT4TqhluigGY8l3CBzsTYwv2gOCHtCCi5mC01C2g/DV7OvZ4WkCkso5GK4A0jwsYrxo/qN1DaZsN7N1bzWnLCthR5GjqgEuOyrH+JW6MX5NCr/jkoC314= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789504558; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2ceqUPoH8MhXmSFtjgWPeXdjWgb1vco08D6FmhOncNY=; b=cgoQmNtSi0fYr0dt6K8+90Lh8uQrupNrL36sARQN68VpPSDe2MUMasOxeXo5Ex/qiq+WdE44uc/6ExGpid9oYwJVKZlB4dXIffT6CC/KIAQimjiv4G9XMMdOtxdS35CXuMbUgIvTZd3yYBcvietpX//th7U5MROEWyWPAGLlPvQ= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17895045588421009.8120751544537; Tue, 15 Sep 2026 13:35:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x6ZsA-0001UH-O3; Tue, 15 Sep 2026 16:35:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x6Zs6-0001TA-7K for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:19 -0400 Received: from mail-wr2-x10.google.com ([2a00:1450:4864:30::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x6Zs4-0005dY-3a for qemu-devel@nongnu.org; Tue, 15 Sep 2026 16:35:17 -0400 Received: by mail-wr2-x10.google.com with SMTP id ffacd0b85a97d-4843c2790ccso71008f8f.1 for ; Tue, 15 Sep 2026 13:35:15 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:f0fe:c7ed:403d:e487]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4870bf37e69sm1504073f8f.29.2026.09.15.13.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2026 13:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1789504515; x=1790109315; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=2ceqUPoH8MhXmSFtjgWPeXdjWgb1vco08D6FmhOncNY=; b=Mbx6VUjl8Xb+Qv6X2LzNnp/uvMjKHNbAiMUq2y2KxhJW0XZB5Ry+1pbBG4OGuM66y0 IBqXtkVPKJPW/jWLFTPRLL8N+VeX3B2dFnXopLxHuyUXdoHAzxbRIkL5YJ9idS+eiZ8c WzRUiH+Ad66Q5XrFaaTFhlFWkk3LONePW6sBwAvy2gksxtDnd9Z62yUrg8s3TJtJhfC/ /XHVm/oLHKVaoeiUhTb6DrWYiI0leZ+vFWydvDY9AxGjOWZ+nBlcSdhqYsOR733DNNNw sy1/58zrBDNvNHLuVLko8YL8ihniVz+RImqp/mxraB1W5wZ2BRuWNihE+s7KdoMIlepz s6KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789504515; x=1790109315; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=2ceqUPoH8MhXmSFtjgWPeXdjWgb1vco08D6FmhOncNY=; b=ZBRwXw+go4RtY1Nq6c3npn1QFA/UKsYqw0fXqow0ayojb7XNqglIiYjEZ50iHY5nUs ZIrr46bjVyxOu4qe6S07QWm37BSBO7qSXQJ9FRgD8OVW8q1b/HOwOW+gDfbKgqxVm1Yj yfTWn2EHaLWj34+ZhfTtOlSzdX+9jx1gJPGiZy+A6ok3LagcHvN3qMLE7WdpW+UQwr+6 zWufBGaGb+1MqE/SGJeptBZ1raDZbhQTrunpz/c1qP1oMaN6PxOasPRJoDIQfTnbzNsW C1qOrvAV4MYAjI66johtGTYFurAbUJKv/gYTWdgYdhsbVTvsDIGs4yGxKxoYLlPhzP7x UgqQ== X-Gm-Message-State: AFuF++meiZemi+x4wqNJ8vqGgl1iEnarbh5cQOdpryzrf2GuoMN6jHMM UyC6uoFo8oLwhcOWi7GVAA2EvnOh9GfaqYA//4YHtVoSJnNJHuQMwb2z1r89H5rNc1zlZqpaNch cYG3L X-Gm-Gg: AYBFou2aT9ihb5gM9+BrRmEhde6C92ZXMphJWSBLjSVS7ys8VrAbRSFMEgGUJxRHmpJ PaSKo999lcYnun4WqwdZYvM7kfu4pqgMGbqwzvoF1oynt9wykfG6k27RJTc1pbOJgkAkm0WUmID 8SVPh+0uFjKQhA4bJMccb9b3HkFP/5QpPpoFMHS9zgI+8JlFXR+KsXV55A0/kC01Vvb9SNLrMIc 21UgUEyVFIrOJReu6UgeYPGUK90O8fn/o+Ky2gFgnc2YTmUlsom/t7WmMGWICaim9h/Qc2ZhBE5 VxvXTFJxpTobThVPRiLUJlO9IRk7XIRwmLVl6kfLZvFuMB+BcsiJS9QgftSAKNSwq4om7iDLpMc ogYScSvRfwz6wXEhutuzn7048UpkFCnekhLCh7gKIkuZ6z9POs8xAx+XyzYnZfA9BN1KS3aHc4X qWvV3qJBPo6HMNtDAXwKMMgFv9h2OBHDClojU/MjCxypmJ2JC13RunaliRDRoO3Udm+PsD X-Received: by 2002:a05:6000:2990:10b0:485:8542:fee3 with SMTP id ffacd0b85a97d-4870cf29d43mr207690f8f.16.1789504514682; Tue, 15 Sep 2026 13:35:14 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, Paolo Bonzini , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH 10/10] tests/functional: cover the BQL watchdog Date: Tue, 15 Sep 2026 22:34:54 +0200 Message-ID: <20260915203455.580999-11-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260915203455.580999-1-den@openvz.org> References: <20260915203455.580999-1-den@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::10; envelope-from=den@openvz.org; helo=mail-wr2-x10.google.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, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1789504560127158500 From: Denis V. Lunev Hold the BQL from the main thread and check that the watchdog says so. human-monitor-command is not a coroutine command, so a write issued through it runs to completion under AIO_WAIT_WHILE() in the main thread, which keeps the BQL for as long as the backend takes to answer. Point that at a null-co node with a latency ten times the deadline and the hold is both long enough to report and short enough to end on its own. Arm the watchdog after launch rather than on the command line, because machine creation takes the BQL in bursts of its own and a deadline this short is meant for the hold, not for startup. Check the quiet case too. A counter that stops distinguishing a held lock from a free one would report a hang on a healthy qemu, and that failure is invisible to a test that only looks for the report. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Philippe Mathieu-Daud=C3=A9 Cc: Zhao Liu Cc: Thomas Huth Cc: Daniel P. Berrang=C3=A9 Signed-off-by: Denis V. Lunev --- tests/functional/generic/meson.build | 1 + tests/functional/generic/test_bql_watchdog.py | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100755 tests/functional/generic/test_bql_watchdog.py diff --git a/tests/functional/generic/meson.build b/tests/functional/generi= c/meson.build index c94105c62e..c20c2a91ea 100644 --- a/tests/functional/generic/meson.build +++ b/tests/functional/generic/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later =20 tests_generic_system =3D [ + 'bql_watchdog', 'empty_cpu_model', 'info_usernet', 'linters', diff --git a/tests/functional/generic/test_bql_watchdog.py b/tests/function= al/generic/test_bql_watchdog.py new file mode 100755 index 0000000000..193dad15e3 --- /dev/null +++ b/tests/functional/generic/test_bql_watchdog.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Test the BQL watchdog against a main thread blocked on IO. +# +# Copyright (C) 2026 Virtuozzo International GmbH + +from qemu_test import QemuSystemTest + +deadline_ms =3D 100 +hold_ns =3D 1000 * 1000 * 1000 + + +class BqlWatchdog(QemuSystemTest): + + def setUp(self): + super().setUp() + self.set_machine('none') + self.vm.add_args('-nodefaults') + self.vm.add_args('-blockdev', + f'driver=3Dnull-co,node-name=3Dnull0,size=3D10485= 76,' + f'latency-ns=3D{hold_ns}') + self.vm.launch() + + def arm(self, ms): + self.vm.cmd('qom-set', path=3D'/machine', + property=3D'bql-watchdog-ms', value=3Dms) + + def hold_the_bql(self): + """ + human-monitor-command is not a coroutine command, so the write runs + to completion under AIO_WAIT_WHILE() in the main thread, which kee= ps + the BQL for as long as null-co takes to answer. + """ + self.vm.cmd('human-monitor-command', + command_line=3D'qemu-io null0 "write 0 4k"') + + def log_after_shutdown(self): + """The log only reaches the harness once the VM is reaped""" + self.vm.shutdown() + return self.vm.get_log() or '' + + def test_reports_a_hold(self): + self.arm(deadline_ms) + self.hold_the_bql() + self.arm(0) + + log =3D self.log_after_shutdown() + self.assertIn(f'BQL held for more than {deadline_ms} ms', log) + + def test_silent_while_disarmed(self): + self.hold_the_bql() + + log =3D self.log_after_shutdown() + self.assertNotIn('BQL held for more than', log) + + +if __name__ =3D=3D '__main__': + QemuSystemTest.main() --=20 2.53.0