From nobody Sat May 30 19:24:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1777022930379189.66956311820957; Fri, 24 Apr 2026 02:28:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wGCpg-0008Em-1a; Fri, 24 Apr 2026 05:28: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 1wGCp5-0007QI-1m for qemu-devel@nongnu.org; Fri, 24 Apr 2026 05:27:43 -0400 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wGCp0-0007aB-1L for qemu-devel@nongnu.org; Fri, 24 Apr 2026 05:27:42 -0400 Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 63O9RHId004358 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 24 Apr 2026 18:27:26 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=2lrFVsOwSY/n/C0RCLf6Y19MCgXdoAnnxYob5thdabU=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Message-Id:To:Subject:Date; s=rs20250326; t=1777022846; v=1; b=M6rzkSbAKaf0mJ0HK6MsyeudpxJReB/TfL3EMWS4U4j+Nmhn72rjPxMshnG5gh02 VC8xNrwfAzFdOGE4WoIeXj9bDOYzqxw0iUnTv9cEdFfo+56UmCs+kC5N2GVOL3B/ Rw/DGwda5xxBkhBkyrZzm3MvikNtXl6Da9uspDKi8Pl31YHtZml/pONaa5Lz1/GF /Tf5jYmkUJzE/hypHnjFKzViUYFTznmfx8sGCbXkv46+g9xwo1mdD9c17xeFw77T u375xMbHIKB99aIDRFmKJ6u7TmPoTfW6rNFo4kZOxiqA6PiGNKHrBo7dLPX+c64l FdqK0Rxv0P5j24bnzJXVXA== From: Akihiko Odaki Date: Fri, 24 Apr 2026 18:27:06 +0900 Subject: [PATCH v4 1/6] futex: Add qemu_futex_timedwait() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260424-force_rcu-v4-1-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> References: <20260424-force_rcu-v4-0-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20260424-force_rcu-v4-0-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> To: qemu-devel@nongnu.org, Dmitry Osipenko Cc: Paolo Bonzini , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki X-Mailer: b4 0.16-dev-16047 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=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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-ZM-MESSAGEID: 1777022932185154100 qemu_futex_timedwait() is equivalent to qemu_futex_wait(), except it has an absolute timeout. Signed-off-by: Akihiko Odaki Tested-by: Dmitry Osipenko --- include/qemu/futex.h | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/include/qemu/futex.h b/include/qemu/futex.h index 607613eec835..3f3b55008f61 100644 --- a/include/qemu/futex.h +++ b/include/qemu/futex.h @@ -24,13 +24,19 @@ #ifndef QEMU_FUTEX_H #define QEMU_FUTEX_H =20 +#include "qemu/timer.h" #define HAVE_FUTEX =20 #ifdef CONFIG_LINUX #include #include +#include =20 +#ifdef __NR_futex_time64 +#define qemu_futex(...) syscall(__NR_futex_time64, __VA_ARGS_= _) +#else #define qemu_futex(...) syscall(__NR_futex, __VA_ARGS__) +#endif =20 static inline void qemu_futex_wake_all(void *f) { @@ -42,18 +48,28 @@ static inline void qemu_futex_wake_single(void *f) qemu_futex(f, FUTEX_WAKE, 1, NULL, NULL, 0); } =20 -static inline void qemu_futex_wait(void *f, unsigned val) +static inline bool qemu_futex_timedwait(void *f, unsigned val, int64_t ns) { - while (qemu_futex(f, FUTEX_WAIT, (int) val, NULL, NULL, 0)) { + struct __kernel_timespec ts; + uint32_t bitset =3D FUTEX_BITSET_MATCH_ANY; + + ts.tv_sec =3D ns / NANOSECONDS_PER_SECOND; + ts.tv_nsec =3D ns % NANOSECONDS_PER_SECOND; + + while (qemu_futex(f, FUTEX_WAIT_BITSET, (int) val, &ts, NULL, bitset))= { switch (errno) { case EWOULDBLOCK: - return; + return true; case EINTR: break; /* get out of switch and retry */ + case ETIMEDOUT: + return false; default: abort(); } } + + return true; } #elif defined(CONFIG_WIN32) #include @@ -68,12 +84,22 @@ static inline void qemu_futex_wake_single(void *f) WakeByAddressSingle(f); } =20 -static inline void qemu_futex_wait(void *f, unsigned val) +static inline bool qemu_futex_timedwait(void *f, unsigned val, int64_t ns) { - WaitOnAddress(f, &val, sizeof(val), INFINITE); + int64_t now =3D get_clock(); + DWORD duration =3D MIN((ns - now) / SCALE_MS, INFINITE); + + return ns > now && WaitOnAddress(f, &val, sizeof(val), duration); } #else #undef HAVE_FUTEX #endif =20 +#ifdef HAVE_FUTEX +static inline void qemu_futex_wait(void *f, unsigned val) +{ + qemu_futex_timedwait(f, val, INT64_MAX); +} +#endif + #endif /* QEMU_FUTEX_H */ --=20 2.53.0 From nobody Sat May 30 19:24:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1777022915201377.09483703124226; Fri, 24 Apr 2026 02:28:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wGCpV-0007ts-BK; Fri, 24 Apr 2026 05:28:10 -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 1wGCp3-0007Mt-Ck for qemu-devel@nongnu.org; Fri, 24 Apr 2026 05:27:41 -0400 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wGCoz-0007aC-Nd for qemu-devel@nongnu.org; Fri, 24 Apr 2026 05:27:41 -0400 Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 63O9RHIe004358 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 24 Apr 2026 18:27:26 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=rXcv6yelvtBYoc9z4CKug8RC1XR4ObzkiQj9RjCrBck=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Message-Id:To:Subject:Date; s=rs20250326; t=1777022846; v=1; b=B77EdOnMQ1HS2uu106kSWucys2Esk9gh7mOrX4lQd6NT0nlqzTzOppyRWqk3zHf9 OBXNYG/KoSips4ezNX/icSgIySNMeWMbbGNS4G2FJ9J9vPYcKNOD9iPCMuNTy8l1 r0BcTLzD2ZoRO+eLIUbKZwEb2dm0CtlRsc1e4Y9jYBD7YvnfMqdta1CugDpWDbR/ ya1x4uuvry2pQC1kRFdo6IppDtF4Gdrj3P18pdbgs4HmOfn7IJO1v/Uoh1MwxQO2 3yrTwkqO4lq6YuiQel8NScjkYnJhzGK9g93Q6tpWVcbtUAfORwg7OyI8nTb6d83A oVXY/hraHNxueb/9w07MPg== From: Akihiko Odaki Date: Fri, 24 Apr 2026 18:27:07 +0900 Subject: [PATCH v4 2/6] qemu-thread: Add qemu_event_timedwait() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260424-force_rcu-v4-2-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> References: <20260424-force_rcu-v4-0-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20260424-force_rcu-v4-0-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> To: qemu-devel@nongnu.org, Dmitry Osipenko Cc: Paolo Bonzini , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki X-Mailer: b4 0.16-dev-16047 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=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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-ZM-MESSAGEID: 1777022919229154100 qemu_event_timedwait() is equivalent to qemu_event_wait(), except it has a relative timeout. Signed-off-by: Akihiko Odaki Tested-by: Dmitry Osipenko --- include/qemu/thread-posix.h | 11 +++++++++++ include/qemu/thread.h | 9 ++++++++- util/event.c | 31 ++++++++++++++++++++++++++----- util/qemu-thread-posix.c | 11 +---------- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h index 758808b705e4..11193b1580f8 100644 --- a/include/qemu/thread-posix.h +++ b/include/qemu/thread-posix.h @@ -36,4 +36,15 @@ struct QemuThread { pthread_t thread; }; =20 +static inline clockid_t qemu_timedwait_clockid(void) +{ +#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK + return CLOCK_MONOTONIC; +#else + return CLOCK_REALTIME; +#endif +} + +void compute_abs_deadline(struct timespec *ts, int ms); + #endif diff --git a/include/qemu/thread.h b/include/qemu/thread.h index 98cc5c41ac58..8536859bcb3a 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -201,7 +201,14 @@ void qemu_sem_destroy(QemuSemaphore *sem); void qemu_event_init(QemuEvent *ev, bool init); void qemu_event_set(QemuEvent *ev); void qemu_event_reset(QemuEvent *ev); -void qemu_event_wait(QemuEvent *ev); +bool qemu_event_timedwait(QemuEvent *ev, int ms); + +static inline void qemu_event_wait(QemuEvent *ev) +{ + while (!qemu_event_timedwait(ev, INT_MAX)) { + } +} + void qemu_event_destroy(QemuEvent *ev); =20 void qemu_thread_create(QemuThread *thread, const char *name, diff --git a/util/event.c b/util/event.c index 5a8141cd0e46..a7a5ee0aa5f5 100644 --- a/util/event.c +++ b/util/event.c @@ -33,7 +33,15 @@ void qemu_event_init(QemuEvent *ev, bool init) { #ifndef HAVE_FUTEX pthread_mutex_init(&ev->lock, NULL); +#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK + pthread_condattr_t attr; + pthread_condattr_init(&attr); + pthread_condattr_setclock(&attr, qemu_timedwait_clockid()); + pthread_cond_init(&ev->cond, &attr); + pthread_condattr_destroy(&attr); +#else pthread_cond_init(&ev->cond, NULL); +#endif #endif =20 ev->value =3D (init ? EV_SET : EV_FREE); @@ -121,15 +129,17 @@ void qemu_event_reset(QemuEvent *ev) #endif } =20 -void qemu_event_wait(QemuEvent *ev) +bool qemu_event_timedwait(QemuEvent *ev, int ms) { assert(ev->initialized); =20 #ifdef HAVE_FUTEX + int64_t deadline =3D get_clock() + (int64_t)ms * SCALE_MS; + while (true) { /* - * qemu_event_wait must synchronize with qemu_event_set even if it= does - * not go down the slow path, so this load-acquire is needed that + * qemu_event_timedwait must synchronize with qemu_event_set even = if it + * does not go down the slow path, so this load-acquire is needed = that * synchronizes with the first memory barrier in qemu_event_set(). */ unsigned value =3D qatomic_load_acquire(&ev->value); @@ -159,13 +169,24 @@ void qemu_event_wait(QemuEvent *ev) * a smp_mb() pairing with the second barrier of qemu_event_set(). * The barrier is inside the FUTEX_WAIT system call. */ - qemu_futex_wait(ev, EV_BUSY); + if (!qemu_futex_timedwait(ev, EV_BUSY, deadline)) { + return false; + } } #else + struct timespec ts; + + compute_abs_deadline(&ts, ms); + pthread_mutex_lock(&ev->lock); while (qatomic_read(&ev->value) !=3D EV_SET) { - pthread_cond_wait(&ev->cond, &ev->lock); + if (pthread_cond_timedwait(&ev->cond, &ev->lock, &ts)) { + pthread_mutex_unlock(&ev->lock); + return false; + } } pthread_mutex_unlock(&ev->lock); #endif + + return true; } diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index bd1c2ad2a596..dc1125006ceb 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -59,16 +59,7 @@ static void error_exit(int err, const char *msg) abort(); } =20 -static inline clockid_t qemu_timedwait_clockid(void) -{ -#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK - return CLOCK_MONOTONIC; -#else - return CLOCK_REALTIME; -#endif -} - -static void compute_abs_deadline(struct timespec *ts, int ms) +void compute_abs_deadline(struct timespec *ts, int ms) { clock_gettime(qemu_timedwait_clockid(), ts); ts->tv_nsec +=3D (ms % 1000) * 1000000; --=20 2.53.0 From nobody Sat May 30 19:24:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1777022961414383.7750561594479; Fri, 24 Apr 2026 02:29:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wGCqS-00010r-CE; Fri, 24 Apr 2026 05:29: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 1wGCp3-0007MT-3h for qemu-devel@nongnu.org; Fri, 24 Apr 2026 05:27:41 -0400 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wGCoz-0007aK-NY for qemu-devel@nongnu.org; Fri, 24 Apr 2026 05:27:40 -0400 Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 63O9RHIf004358 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 24 Apr 2026 18:27:26 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=7SYbmYKvDcRKPumrWJKsajKHA9ZFczVdAT+icArERIs=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Message-Id:To:Subject:Date; s=rs20250326; t=1777022846; v=1; b=r1WyzKCfsBIfLiK5TP5o5l70FP47lnYtx4hapwEniSOjN9Yfc2nODW+ZQPB7Pupv wSsfa1N9pO6HEaAw3JZr3rVpa42rCHJaqSMAO0+gtrdWHp1G8crqjLPd9Qn01RV4 Gj+6tHF5TiYDpuLT1c4giYY67m8Ih+SJGCam37+dqNq3CV1oQ/LMj356dbtYr8pX UdpzdCgXgLOm2KV9T7I8CLQB3laiUwrVEy0fufUMRsmB6RE3ThjgWTHS+ykQTHTL RnLIyqjlSiYcwAjXglBpSIct0OtEkTS2tghvuPjQ1t//+tzmhsMPCcV1V1EjsLhh jBiZERECneUh8BYFAKmEjg== From: Akihiko Odaki Date: Fri, 24 Apr 2026 18:27:08 +0900 Subject: [PATCH v4 3/6] rcu: Use call_rcu() in synchronize_rcu() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260424-force_rcu-v4-3-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> References: <20260424-force_rcu-v4-0-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20260424-force_rcu-v4-0-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> To: qemu-devel@nongnu.org, Dmitry Osipenko Cc: Paolo Bonzini , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki X-Mailer: b4 0.16-dev-16047 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=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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-ZM-MESSAGEID: 1777022962355158500 Previously, synchronize_rcu() was a single-threaded implementation that is protected with a mutex. It was used only in the RCU thread and tests, and real users instead use call_rcu(), which relies on the RCU thread. The usage of synchronize_rcu() in tests did not accurately represent real use cases because it caused locking with the mutex, which never happened in real use cases, and it did not exercise the logic in the RCU thread. Add a new implementation of synchronize_rcu() which uses call_rcu() to represent real use cases in tests. The old synchronize_rcu() is now renamed to enter_qs() and only used in the RCU thread, making the mutex unnecessary. Signed-off-by: Akihiko Odaki Tested-by: Dmitry Osipenko --- util/rcu.c | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/util/rcu.c b/util/rcu.c index acac9446ea98..3c4af9d213c8 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -38,7 +38,7 @@ =20 /* * Global grace period counter. Bit 0 is always one in rcu_gp_ctr. - * Bits 1 and above are defined in synchronize_rcu. + * Bits 1 and above are defined in enter_qs(). */ #define RCU_GP_LOCKED (1UL << 0) #define RCU_GP_CTR (1UL << 1) @@ -52,7 +52,6 @@ QemuEvent rcu_gp_event; static int in_drain_call_rcu; static int rcu_call_count; static QemuMutex rcu_registry_lock; -static QemuMutex rcu_sync_lock; =20 /* * Check whether a quiescent state was crossed between the beginning of @@ -111,7 +110,7 @@ static void wait_for_readers(void) * * If this is the last iteration, this barrier also prevents * frees from seeping upwards, and orders the two wait phases - * on architectures with 32-bit longs; see synchronize_rcu(). + * on architectures with 32-bit longs; see enter_qs(). */ smp_mb_global(); =20 @@ -137,9 +136,9 @@ static void wait_for_readers(void) * wait too much time. * * rcu_register_thread() may add nodes to ®istry; it will not - * wake up synchronize_rcu, but that is okay because at least anot= her + * wake up enter_qs(), but that is okay because at least another * thread must exit its RCU read-side critical section before - * synchronize_rcu is done. The next iteration of the loop will + * enter_qs() is done. The next iteration of the loop will * move the new thread's rcu_reader from ®istry to &qsreaders, * because rcu_gp_ongoing() will return false. * @@ -171,10 +170,8 @@ static void wait_for_readers(void) QLIST_SWAP(®istry, &qsreaders, node); } =20 -void synchronize_rcu(void) +static void enter_qs(void) { - QEMU_LOCK_GUARD(&rcu_sync_lock); - /* Write RCU-protected pointers before reading p_rcu_reader->ctr. * Pairs with smp_mb_placeholder() in rcu_read_lock(). * @@ -289,7 +286,7 @@ static void *call_rcu_thread(void *opaque) =20 /* * Fetch rcu_call_count now, we only must process elements that we= re - * added before synchronize_rcu() starts. + * added before enter_qs() starts. */ for (;;) { qemu_event_reset(&rcu_call_ready_event); @@ -304,7 +301,7 @@ static void *call_rcu_thread(void *opaque) qemu_event_wait(&rcu_call_ready_event); } =20 - synchronize_rcu(); + enter_qs(); qatomic_sub(&rcu_call_count, n); bql_lock(); while (n > 0) { @@ -337,15 +334,24 @@ void call_rcu1(struct rcu_head *node, void (*func)(st= ruct rcu_head *node)) } =20 =20 -struct rcu_drain { +typedef struct Sync { struct rcu_head rcu; - QemuEvent drain_complete_event; -}; + QemuEvent complete_event; +} Sync; =20 -static void drain_rcu_callback(struct rcu_head *node) +static void sync_rcu_callback(Sync *sync) { - struct rcu_drain *event =3D (struct rcu_drain *)node; - qemu_event_set(&event->drain_complete_event); + qemu_event_set(&sync->complete_event); +} + +void synchronize_rcu(void) +{ + Sync sync; + + qemu_event_init(&sync.complete_event, false); + call_rcu(&sync, sync_rcu_callback, rcu); + qemu_event_wait(&sync.complete_event); + qemu_event_destroy(&sync.complete_event); } =20 /* @@ -359,11 +365,11 @@ static void drain_rcu_callback(struct rcu_head *node) =20 void drain_call_rcu(void) { - struct rcu_drain rcu_drain; + Sync sync; bool locked =3D bql_locked(); =20 - memset(&rcu_drain, 0, sizeof(struct rcu_drain)); - qemu_event_init(&rcu_drain.drain_complete_event, false); + memset(&sync, 0, sizeof(sync)); + qemu_event_init(&sync.complete_event, false); =20 if (locked) { bql_unlock(); @@ -383,8 +389,8 @@ void drain_call_rcu(void) */ =20 qatomic_inc(&in_drain_call_rcu); - call_rcu1(&rcu_drain.rcu, drain_rcu_callback); - qemu_event_wait(&rcu_drain.drain_complete_event); + call_rcu(&sync, sync_rcu_callback, rcu); + qemu_event_wait(&sync.complete_event); qatomic_dec(&in_drain_call_rcu); =20 if (locked) { @@ -427,7 +433,6 @@ static void rcu_init_complete(void) QemuThread thread; =20 qemu_mutex_init(&rcu_registry_lock); - qemu_mutex_init(&rcu_sync_lock); qemu_event_init(&rcu_gp_event, true); =20 qemu_event_init(&rcu_call_ready_event, false); @@ -460,7 +465,6 @@ static void rcu_init_lock(void) return; } =20 - qemu_mutex_lock(&rcu_sync_lock); qemu_mutex_lock(&rcu_registry_lock); } =20 @@ -471,7 +475,6 @@ static void rcu_init_unlock(void) } =20 qemu_mutex_unlock(&rcu_registry_lock); - qemu_mutex_unlock(&rcu_sync_lock); } =20 static void rcu_init_child(void) --=20 2.53.0 From nobody Sat May 30 19:24:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1777022960935533.2347318345448; Fri, 24 Apr 2026 02:29:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wGCqY-0001Em-5F; Fri, 24 Apr 2026 05:29:14 -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 1wGCp5-0007QJ-1j for qemu-devel@nongnu.org; Fri, 24 Apr 2026 05:27:43 -0400 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wGCoz-0007aD-Sg for qemu-devel@nongnu.org; Fri, 24 Apr 2026 05:27:42 -0400 Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 63O9RHIg004358 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 24 Apr 2026 18:27:27 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=DuZVnJEzNDJNfZHbzJvYKnnfUFdaedXskL/mubdiSlE=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Message-Id:To:Subject:Date; s=rs20250326; t=1777022847; v=1; b=t927pcDW1Iuo5Rc3HHArB9tlk2Kaj3v7KnjpsK9PnNLglFDIQbikxhrFruFigs6q csg8o7chDfHUnlFBE+knGbiw+5hhOb1QI0ysKUnY39tEbHAEv2FyL1hBwlOAc9Tj cIW/Kjd2md1iDLiWg2s1sRKmeHPe9VZE3yVmSB9uyvOZLDvEO2p5E0OVTJ+4sZgY +C8jUpPRj2OLwEDmYu/fT4GEDuuR6jj3W3RcZQws0H7tqeMtWRC3c4Ekz0d+IYld c2R2VghhG4CW0DXjQRpcHgQWbM8XziupKI+yGiwRe+c4+RZ2ZAeLs19MdBoAIBKf KU6IIVPWkW0nbzEzrwjA8g== From: Akihiko Odaki Date: Fri, 24 Apr 2026 18:27:09 +0900 Subject: [PATCH v4 4/6] rcu: Wake the RCU thread when draining MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260424-force_rcu-v4-4-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> References: <20260424-force_rcu-v4-0-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20260424-force_rcu-v4-0-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> To: qemu-devel@nongnu.org, Dmitry Osipenko Cc: Paolo Bonzini , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki X-Mailer: b4 0.16-dev-16047 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=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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-ZM-MESSAGEID: 1777022962797154100 drain_call_rcu() triggers the force quiescent state, but it can be delayed if the RCU thread is sleeping. Ensure the force quiescent state is immediately triggered by waking the RCU thread up. The logic to trigger the force quiescent state is decoupled as force_rcu() so that it can be used independently. Signed-off-by: Akihiko Odaki Tested-by: Dmitry Osipenko --- include/qemu/rcu.h | 1 + util/rcu.c | 51 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h index 020dbe4d8b77..d6aa4e5854d3 100644 --- a/include/qemu/rcu.h +++ b/include/qemu/rcu.h @@ -118,6 +118,7 @@ static inline void rcu_read_unlock(void) } } =20 +void force_rcu(void); void synchronize_rcu(void); =20 /* diff --git a/util/rcu.c b/util/rcu.c index 3c4af9d213c8..2f58f3627f74 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -45,12 +45,14 @@ =20 =20 #define RCU_CALL_MIN_SIZE 30 +#define RCU_CALL_STATE_FORCED ((uint32_t)1 << 31) +#define RCU_CALL_STATE_COUNT (~RCU_CALL_STATE_FORCED) =20 unsigned long rcu_gp_ctr =3D RCU_GP_LOCKED; =20 QemuEvent rcu_gp_event; -static int in_drain_call_rcu; -static int rcu_call_count; +static QemuEvent rcu_call_force_event; +static uint32_t rcu_call_state; static QemuMutex rcu_registry_lock; =20 /* @@ -74,28 +76,35 @@ QEMU_DEFINE_CO_TLS(struct rcu_reader_data, rcu_reader) typedef QLIST_HEAD(, rcu_reader_data) ThreadList; static ThreadList registry =3D QLIST_HEAD_INITIALIZER(registry); =20 +void force_rcu(void) +{ + qatomic_or(&rcu_call_state, RCU_CALL_STATE_FORCED); + qemu_event_set(&rcu_call_force_event); +} + /* Wait for previous parity/grace period to be empty of readers. */ -static void wait_for_readers(void) +static void wait_for_readers(bool force) { ThreadList qsreaders =3D QLIST_HEAD_INITIALIZER(qsreaders); struct rcu_reader_data *index, *tmp; - int sleeps =3D 0; + int sleeps =3D force ? 0 : 5; bool forced =3D false; =20 + qemu_event_reset(&rcu_call_force_event); + for (;;) { /* * Force the grace period to end and wait for it if any of the * following heuristical conditions are satisfied: * - A decent number of callbacks piled up. + * - force_rcu() was called. * - It timed out. - * - It is in a drain_call_rcu() call. * * Otherwise, periodically poll the grace period, hoping it ends * promptly. */ if (!forced && - (qatomic_read(&rcu_call_count) >=3D RCU_CALL_MIN_SIZE || - sleeps >=3D 5 || qatomic_read(&in_drain_call_rcu))) { + (qatomic_read(&rcu_call_state) >=3D RCU_CALL_MIN_SIZE || !slee= ps)) { forced =3D true; =20 QLIST_FOREACH(index, ®istry, node) { @@ -159,8 +168,8 @@ static void wait_for_readers(void) */ qemu_event_reset(&rcu_gp_event); } else { - g_usleep(10000); - sleeps++; + qemu_event_timedwait(&rcu_call_force_event, 10); + sleeps--; } =20 qemu_mutex_lock(&rcu_registry_lock); @@ -170,7 +179,7 @@ static void wait_for_readers(void) QLIST_SWAP(®istry, &qsreaders, node); } =20 -static void enter_qs(void) +static void enter_qs(bool force) { /* Write RCU-protected pointers before reading p_rcu_reader->ctr. * Pairs with smp_mb_placeholder() in rcu_read_lock(). @@ -189,14 +198,14 @@ static void enter_qs(void) * Switch parity: 0 -> 1, 1 -> 0. */ qatomic_set(&rcu_gp_ctr, rcu_gp_ctr ^ RCU_GP_CTR); - wait_for_readers(); + wait_for_readers(force); qatomic_set(&rcu_gp_ctr, rcu_gp_ctr ^ RCU_GP_CTR); } else { /* Increment current grace period. */ qatomic_set(&rcu_gp_ctr, rcu_gp_ctr + RCU_GP_CTR); } =20 - wait_for_readers(); + wait_for_readers(force); } } =20 @@ -282,15 +291,17 @@ static void *call_rcu_thread(void *opaque) rcu_register_thread(); =20 for (;;) { - int n; + uint32_t state; + uint32_t n; =20 /* - * Fetch rcu_call_count now, we only must process elements that we= re + * Fetch rcu_call_state now, we only must process elements that we= re * added before enter_qs() starts. */ for (;;) { qemu_event_reset(&rcu_call_ready_event); - n =3D qatomic_read(&rcu_call_count); + state =3D qatomic_fetch_and(&rcu_call_state, RCU_CALL_STATE_CO= UNT); + n =3D state & RCU_CALL_STATE_COUNT; if (n) { break; } @@ -301,8 +312,8 @@ static void *call_rcu_thread(void *opaque) qemu_event_wait(&rcu_call_ready_event); } =20 - enter_qs(); - qatomic_sub(&rcu_call_count, n); + enter_qs(state & RCU_CALL_STATE_FORCED); + qatomic_sub(&rcu_call_state, n); bql_lock(); while (n > 0) { node =3D try_dequeue(); @@ -329,7 +340,7 @@ void call_rcu1(struct rcu_head *node, void (*func)(stru= ct rcu_head *node)) { node->func =3D func; enqueue(node); - qatomic_inc(&rcu_call_count); + qatomic_inc(&rcu_call_state); qemu_event_set(&rcu_call_ready_event); } =20 @@ -388,10 +399,9 @@ void drain_call_rcu(void) * assumed. */ =20 - qatomic_inc(&in_drain_call_rcu); call_rcu(&sync, sync_rcu_callback, rcu); + force_rcu(); qemu_event_wait(&sync.complete_event); - qatomic_dec(&in_drain_call_rcu); =20 if (locked) { bql_lock(); @@ -435,6 +445,7 @@ static void rcu_init_complete(void) qemu_mutex_init(&rcu_registry_lock); qemu_event_init(&rcu_gp_event, true); =20 + qemu_event_init(&rcu_call_force_event, false); qemu_event_init(&rcu_call_ready_event, false); =20 /* The caller is assumed to have BQL, so the call_rcu thread --=20 2.53.0 From nobody Sat May 30 19:24:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1777022925359412.48549417505285; Fri, 24 Apr 2026 02:28:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wGCpX-00082u-H1; Fri, 24 Apr 2026 05:28: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 1wGCp4-0007P0-DC for qemu-devel@nongnu.org; Fri, 24 Apr 2026 05:27:42 -0400 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wGCoz-0007a8-Sm for qemu-devel@nongnu.org; Fri, 24 Apr 2026 05:27:42 -0400 Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 63O9RHIh004358 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 24 Apr 2026 18:27:27 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=nzLYRcuCdqFWfvHtoSoGlURTO6nugE9Dg725YsMRZMk=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Message-Id:To:Subject:Date; s=rs20250326; t=1777022847; v=1; b=PkJdCx71mqP5xdztHYREDyrpAusenbp+oGE71U1ts5EaNWo7kMptSlOrHwB0EJ7t YipfuNjOF33OqPuGIGW8+CXBEfjBJcEH7W3ZstWQscHfczxvLkMzQZItuW2qmeyI EjfRgzTMEPurkrJeOiF5ZVguwR2zbeFtxIeksDskMrzhZl3zoP7sHAPnNsTSzhx0 VrktpSi1/YJuwNKTaN+D3NO7MxtifyvrFCwD3eamYYCN2zLzDq6w5xBs2/M023N4 eOpQvNkwJyho/Z7mT27eEE68vIpZjc1mdfsq0mXSZoiJLS1xYsb/DRomnnwP2zdN hyuA8RJnhKR0i16KAYi9qQ== From: Akihiko Odaki Date: Fri, 24 Apr 2026 18:27:10 +0900 Subject: [PATCH v4 5/6] virtio-gpu: Force RCU when unmapping blob MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260424-force_rcu-v4-5-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> References: <20260424-force_rcu-v4-0-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20260424-force_rcu-v4-0-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> To: qemu-devel@nongnu.org, Dmitry Osipenko Cc: Paolo Bonzini , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki X-Mailer: b4 0.16-dev-16047 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=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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-ZM-MESSAGEID: 1777022929843158500 Unmapping a blob changes the memory map, which is protected with RCU. RCU is designed to minimize the read-side overhead at the cost of reclamation delay. While this design usually makes sense, it is problematic when unmapping a blob because the operation blocks all virtio-gpu commands and causes perceivable disruption. Minimize such the disruption with force_rcu(), which minimizes the reclamation delay at the cost of a read-side overhead. Signed-off-by: Akihiko Odaki Tested-by: Dmitry Osipenko --- hw/display/virtio-gpu-virgl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index b7a2d160ddd8..69896618fef8 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -298,6 +298,7 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g, /* memory region owns self res->mr object and frees it by itself */ memory_region_del_subregion(&b->hostmem, mr); object_unparent(OBJECT(vmr)); + force_rcu(); =20 /* Fallthrough */ case VIRTIO_GPU_MR_UNMAP_STARTED: --=20 2.53.0 From nobody Sat May 30 19:24:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1777022932795847.572169888683; Fri, 24 Apr 2026 02:28:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wGCpe-0008Ba-V2; Fri, 24 Apr 2026 05:28:19 -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 1wGCp5-0007Q8-17 for qemu-devel@nongnu.org; Fri, 24 Apr 2026 05:27:43 -0400 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wGCp0-0007aA-1K for qemu-devel@nongnu.org; Fri, 24 Apr 2026 05:27:42 -0400 Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 63O9RHIi004358 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 24 Apr 2026 18:27:27 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=wzGInr5tGeKcs9kj5j/LreDA3mI0ZOwS94BodO37T70=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Message-Id:To:Subject:Date; s=rs20250326; t=1777022847; v=1; b=dbd146IriZSMW+4HN59foUhN0HnPvlIRsHb0CLOVq8/r1gg4Su1Zf3SUe1ZanY+x 69Rn8dn6MogTtYzUUZQus3pRf2bpUp5ujX8+fwvV3vMqqVy/EghHTHo9R+DdU+ZS Hd7sqJrlkt6IGlCzl3+dgYbxEDuyhswFFQsDRh4XU9AdhQNc3DQQvDWIfFP+5ayH Lf6a9amxwK6JxPPS+IAA/w8U1tSYIJ7Srk7ocuVw2gabceyV9dySyy4a4jLOGeE2 KfxMD2v31k+Ap+mlbvryJ5I34DI3H8ZHaXypDA3b94vwXfc5wJ2yzFCP7O0ONGyj zaxtXScjmvmDND+WKJak0A== From: Akihiko Odaki Date: Fri, 24 Apr 2026 18:27:11 +0900 Subject: [PATCH v4 6/6] scripts/checkpatch: Avoid false positive on empty blocks MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260424-force_rcu-v4-6-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> References: <20260424-force_rcu-v4-0-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20260424-force_rcu-v4-0-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp> To: qemu-devel@nongnu.org, Dmitry Osipenko Cc: Paolo Bonzini , "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki X-Mailer: b4 0.16-dev-16047 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=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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-ZM-MESSAGEID: 1777022936434154100 SUSPECT_CODE_INDENT checks the first line after a conditional statement. When the block is empty, the first line after the conditional is the closing brace at the same indentation level, so checkpatch reports a bogus indentation error. Ignore same-indented braces and else statements, matching with: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?= id=3Df6950a735f29e782bc219ece22bb91d6e1ab7bbc Signed-off-by: Akihiko Odaki --- scripts/checkpatch.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index b77bd693288b..df92b92ac975 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2282,7 +2282,8 @@ sub process { #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sinden= t> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> = stat_real<$stat_real> stat<$stat>\n"; =20 if ($check && (($sindent % 4) !=3D 0 || - ($sindent <=3D $indent && $s ne ''))) { + ($sindent <=3D $indent && + $s !~ /^\s*(?:\}|\{|else\b)/))) { ERROR("suspect code indent for conditional statements ($indent, $sinde= nt)\n" . $herecurr . "$stat_real\n"); } } --=20 2.53.0