From patchwork Tue Oct 15 08:51:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 13835880 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE167CFC276 for ; Tue, 15 Oct 2024 08:52:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0dI0-00072o-Ml; Tue, 15 Oct 2024 04:52:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dHx-000723-EF for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dHu-00088v-O5 for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728982324; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HxcQJk8yN2sQugipUZHtSXsGTe+akfuemPRXmMCv6rI=; b=fmAhoJzQ5BHtVm6GE53bsvmLlrL6q6jdimYyVFQWVagPp0eLyn+mFvey1wZYOatR7Uosc8 NtOe2B2Z4wHvrjbw+2qSMWlXGG01CfhyAPCbSEAWcDxpJ8iJa5IW+W+Ii3ryF2Q9Spfx1v klsmcaBOuhE8rxR5UyiFpWnopkJDeFo= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-656-vTNfh-LfOYaHXNqaY0_07g-1; Tue, 15 Oct 2024 04:52:00 -0400 X-MC-Unique: vTNfh-LfOYaHXNqaY0_07g-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C1F8C19560BF; Tue, 15 Oct 2024 08:51:59 +0000 (UTC) Received: from localhost (unknown [10.39.208.15]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CC1CD19560A2; Tue, 15 Oct 2024 08:51:58 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini Subject: [PULL 1/8] chardev/char: fix qemu_chr_is_busy() check Date: Tue, 15 Oct 2024 12:51:43 +0400 Message-ID: <20241015085150.219486-2-marcandre.lureau@redhat.com> In-Reply-To: <20241015085150.219486-1-marcandre.lureau@redhat.com> References: <20241015085150.219486-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.076, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Roman Penyaev `mux_cnt` struct member never goes negative or decrements, so mux chardev can be !busy only when there are no frontends attached. This patch fixes the always-true check. Fixes: a4afa548fc6d ("char: move front end handlers in CharBackend") Signed-off-by: Roman Penyaev Cc: "Marc-André Lureau" Cc: qemu-devel@nongnu.org Reviewed-by: Marc-André Lureau Message-ID: <20241014152408.427700-2-r.peniaev@gmail.com> --- chardev/char.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chardev/char.c b/chardev/char.c index c0cc52824b..f54dc3a862 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -333,7 +333,7 @@ static bool qemu_chr_is_busy(Chardev *s) { if (CHARDEV_IS_MUX(s)) { MuxChardev *d = MUX_CHARDEV(s); - return d->mux_cnt >= 0; + return d->mux_cnt > 0; } else { return s->be != NULL; } From patchwork Tue Oct 15 08:51:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 13835882 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D35CBCFC279 for ; Tue, 15 Oct 2024 08:52:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0dI2-00073R-70; Tue, 15 Oct 2024 04:52:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dHz-00072O-4V for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dHw-000896-3Q for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728982329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JK65KTaD4HUeV1X6yzOdYWgDmvibWf6gxPVoA4kqbSE=; b=gdaNopEWNlWL9+6+lCrp5a9HzZf++tWYk9o+xwa360JNzIrycUEeVd8Ox5jEUio9Km+J7f IBb40uT1zHJsxaP6QAtw0a+b96FSMioCTUqQ5MdIL32MnWULDjc0KAu0joLaHiLh6lslAr wIbW2CFij4ZFpwNvBFBjTZ6oMLn8HJs= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-4_OJ-m9qMBmrGYH5SdixXA-1; Tue, 15 Oct 2024 04:52:05 -0400 X-MC-Unique: 4_OJ-m9qMBmrGYH5SdixXA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AFFF71955F4A; Tue, 15 Oct 2024 08:52:04 +0000 (UTC) Received: from localhost (unknown [10.39.208.15]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B799B1956056; Tue, 15 Oct 2024 08:52:03 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini Subject: [PULL 2/8] chardev/chardev-internal: remove unused `max_size` struct member Date: Tue, 15 Oct 2024 12:51:44 +0400 Message-ID: <20241015085150.219486-3-marcandre.lureau@redhat.com> In-Reply-To: <20241015085150.219486-1-marcandre.lureau@redhat.com> References: <20241015085150.219486-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.076, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Roman Penyaev Clean up forgotten leftovers. Signed-off-by: Roman Penyaev Cc: "Marc-André Lureau" Cc: qemu-devel@nongnu.org Reviewed-by: Marc-André Lureau Message-ID: <20241014152408.427700-3-r.peniaev@gmail.com> --- chardev/chardev-internal.h | 1 - 1 file changed, 1 deletion(-) diff --git a/chardev/chardev-internal.h b/chardev/chardev-internal.h index 4e03af3147..c3024b51fd 100644 --- a/chardev/chardev-internal.h +++ b/chardev/chardev-internal.h @@ -40,7 +40,6 @@ struct MuxChardev { int focus; int mux_cnt; int term_got_escape; - int max_size; /* Intermediate input buffer catches escape sequences even if the currently active device is not accepting any input - but only until it is full as well. */ From patchwork Tue Oct 15 08:51:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 13835886 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC34CCFC276 for ; Tue, 15 Oct 2024 08:53:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0dI3-00073w-18; Tue, 15 Oct 2024 04:52:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dHz-00072P-5x for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dHw-00089j-3q for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728982338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k/XRfwmcrhHo6bRBMo1Ajn6i9VizFBtid5loVU0rVxc=; b=ITfcSKH33c+pLPLvHsLhlbTZKiclx6KPvIVc3XWM/d/T4PK7T3L7evqv37SWorBDJT6JQk pAM117jmJTXTIjWBrRSez1ikPZC322g1t9Qo9OARNFlPBVNkvSIv7bgOarLuWV5gj1a+6X Zke+oANJiEoIhiGsbi/xkyJw7fmLtuE= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-528-YUu35J8KMC-KySGf--fTRQ-1; Tue, 15 Oct 2024 04:52:10 -0400 X-MC-Unique: YUu35J8KMC-KySGf--fTRQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 816C71955EEA; Tue, 15 Oct 2024 08:52:09 +0000 (UTC) Received: from localhost (unknown [10.39.208.15]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 59EC91956089; Tue, 15 Oct 2024 08:52:07 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini Subject: [PULL 3/8] chardev/mux: use bool type for `linestart` and `term_got_escape` Date: Tue, 15 Oct 2024 12:51:45 +0400 Message-ID: <20241015085150.219486-4-marcandre.lureau@redhat.com> In-Reply-To: <20241015085150.219486-1-marcandre.lureau@redhat.com> References: <20241015085150.219486-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.076, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Roman Penyaev Those are boolean variables, not signed integers. Signed-off-by: Roman Penyaev Cc: "Marc-André Lureau" Cc: qemu-devel@nongnu.org Reviewed-by: Marc-André Lureau Message-ID: <20241014152408.427700-4-r.peniaev@gmail.com> --- chardev/chardev-internal.h | 4 ++-- chardev/char-mux.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/chardev/chardev-internal.h b/chardev/chardev-internal.h index c3024b51fd..975c16de80 100644 --- a/chardev/chardev-internal.h +++ b/chardev/chardev-internal.h @@ -39,7 +39,7 @@ struct MuxChardev { CharBackend chr; int focus; int mux_cnt; - int term_got_escape; + bool term_got_escape; /* Intermediate input buffer catches escape sequences even if the currently active device is not accepting any input - but only until it is full as well. */ @@ -49,7 +49,7 @@ struct MuxChardev { int timestamps; /* Protected by the Chardev chr_write_lock. */ - int linestart; + bool linestart; int64_t timestamps_start; }; typedef struct MuxChardev MuxChardev; diff --git a/chardev/char-mux.c b/chardev/char-mux.c index ee2d47b20d..728596c6f3 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -73,11 +73,11 @@ static int mux_chr_write(Chardev *chr, const uint8_t *buf, int len) * qemu_chr_fe_write and background I/O callbacks */ qemu_chr_fe_write_all(&d->chr, (uint8_t *)buf1, strlen(buf1)); - d->linestart = 0; + d->linestart = false; } ret += qemu_chr_fe_write(&d->chr, buf + i, 1); if (buf[i] == '\n') { - d->linestart = 1; + d->linestart = true; } } } @@ -145,7 +145,7 @@ static void mux_chr_be_event(Chardev *chr, QEMUChrEvent event) static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch) { if (d->term_got_escape) { - d->term_got_escape = 0; + d->term_got_escape = false; if (ch == term_escape_char) { goto send_char; } @@ -175,11 +175,11 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch) case 't': d->timestamps = !d->timestamps; d->timestamps_start = -1; - d->linestart = 0; + d->linestart = false; break; } } else if (ch == term_escape_char) { - d->term_got_escape = 1; + d->term_got_escape = true; } else { send_char: return 1; From patchwork Tue Oct 15 08:51:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 13835885 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA43FCFC279 for ; Tue, 15 Oct 2024 08:53:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0dI4-00074A-Lt; Tue, 15 Oct 2024 04:52:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dHz-00072Q-5m for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dHw-00089e-3u for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728982337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kanwf6jpaulQ85eKNKkpizPtZrgkkFI/YQtvjEV895Q=; b=fRK/qpc7TmjwPiL/APmr4f7E0PfLoZqEiOt8Z3skjaqb3y2nH+gwwb3Ldh9Mc3+yxvX2iH tfCKpad2LIshvyFC/Nk3fZSF4BRAJyBfPSYH3XDR9fbZKAfLo/j1G5kAzvcn8c6jMcje2f Qtz4H1Z8pdzIv+tc7N/UN98W9IV3qYE= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-ccfmMU78PyeiYtFHr-aWFQ-1; Tue, 15 Oct 2024 04:52:15 -0400 X-MC-Unique: ccfmMU78PyeiYtFHr-aWFQ-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 53E211956048; Tue, 15 Oct 2024 08:52:14 +0000 (UTC) Received: from localhost (unknown [10.39.208.15]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2F93519560A2; Tue, 15 Oct 2024 08:52:12 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini Subject: [PULL 4/8] chardev/mux: convert size members to unsigned int Date: Tue, 15 Oct 2024 12:51:46 +0400 Message-ID: <20241015085150.219486-5-marcandre.lureau@redhat.com> In-Reply-To: <20241015085150.219486-1-marcandre.lureau@redhat.com> References: <20241015085150.219486-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.076, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Roman Penyaev There is no sense to keep `focus`, `mux_cnt`, `prod`, `cons` and `tag` variables as signed, those represent either size, either position in array, which both are unsigned. `focus` member of `MuxChardev` is kept signed, because initially set to -1. Signed-off-by: Roman Penyaev Cc: "Marc-André Lureau" Cc: qemu-devel@nongnu.org Reviewed-by: Marc-André Lureau Message-ID: <20241014152408.427700-5-r.peniaev@gmail.com> --- chardev/chardev-internal.h | 8 ++++---- include/chardev/char-fe.h | 2 +- chardev/char-fe.c | 2 +- chardev/char-mux.c | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/chardev/chardev-internal.h b/chardev/chardev-internal.h index 975c16de80..ab93f6ea17 100644 --- a/chardev/chardev-internal.h +++ b/chardev/chardev-internal.h @@ -38,14 +38,14 @@ struct MuxChardev { CharBackend *backends[MAX_MUX]; CharBackend chr; int focus; - int mux_cnt; + unsigned int mux_cnt; bool term_got_escape; /* Intermediate input buffer catches escape sequences even if the currently active device is not accepting any input - but only until it is full as well. */ unsigned char buffer[MAX_MUX][MUX_BUFFER_SIZE]; - int prod[MAX_MUX]; - int cons[MAX_MUX]; + unsigned int prod[MAX_MUX]; + unsigned int cons[MAX_MUX]; int timestamps; /* Protected by the Chardev chr_write_lock. */ @@ -59,7 +59,7 @@ DECLARE_INSTANCE_CHECKER(MuxChardev, MUX_CHARDEV, #define CHARDEV_IS_MUX(chr) \ object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_MUX) -void mux_set_focus(Chardev *chr, int focus); +void mux_set_focus(Chardev *chr, unsigned int focus); void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event); Object *get_chardevs_root(void); diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h index 3310449eaf..8ef05b3dd0 100644 --- a/include/chardev/char-fe.h +++ b/include/chardev/char-fe.h @@ -20,7 +20,7 @@ struct CharBackend { IOReadHandler *chr_read; BackendChangeHandler *chr_be_change; void *opaque; - int tag; + unsigned int tag; bool fe_is_open; }; diff --git a/chardev/char-fe.c b/chardev/char-fe.c index b214ba3802..69b47d16bd 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -191,7 +191,7 @@ bool qemu_chr_fe_backend_open(CharBackend *be) bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp) { - int tag = 0; + unsigned int tag = 0; if (s) { if (CHARDEV_IS_MUX(s)) { diff --git a/chardev/char-mux.c b/chardev/char-mux.c index 728596c6f3..b2d7abf2fc 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -124,7 +124,8 @@ static void mux_print_help(Chardev *chr) } } -static void mux_chr_send_event(MuxChardev *d, int mux_nr, QEMUChrEvent event) +static void mux_chr_send_event(MuxChardev *d, unsigned int mux_nr, + QEMUChrEvent event) { CharBackend *be = d->backends[mux_nr]; @@ -242,7 +243,7 @@ static void mux_chr_read(void *opaque, const uint8_t *buf, int size) void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event) { MuxChardev *d = MUX_CHARDEV(chr); - int i; + unsigned int i; if (!muxes_opened) { return; @@ -275,7 +276,7 @@ static GSource *mux_chr_add_watch(Chardev *s, GIOCondition cond) static void char_mux_finalize(Object *obj) { MuxChardev *d = MUX_CHARDEV(obj); - int i; + unsigned int i; for (i = 0; i < d->mux_cnt; i++) { CharBackend *be = d->backends[i]; @@ -300,11 +301,10 @@ static void mux_chr_update_read_handlers(Chardev *chr) chr->gcontext, true, false); } -void mux_set_focus(Chardev *chr, int focus) +void mux_set_focus(Chardev *chr, unsigned int focus) { MuxChardev *d = MUX_CHARDEV(chr); - assert(focus >= 0); assert(focus < d->mux_cnt); if (d->focus != -1) { From patchwork Tue Oct 15 08:51:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 13835887 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 329E9CFC276 for ; Tue, 15 Oct 2024 08:54:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0dI6-00074j-VG; Tue, 15 Oct 2024 04:52:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dI3-00073y-Fb for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dI2-0008Aq-1M for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728982344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PxC9hmQbpuisQv0zzh5GHiArddQNkm0yVIPpV/eZueE=; b=NldoWOOwSHbXWsIiQ80s5y0pZ/X7PRbTR434HpDm8NlIZbTGbcdkQo1eSz88MDvqHR7qkh a9+KYU3i7gdO3na/f39ZxzhKwRjFu8b+WARkioEq6sOQzPRSzKf/d3NeMJs+CeN52PQqKh 3hL9JjsfgX+0QXL68VMoYqJWBeDEhPk= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-221-GiDg4mbjPWev8VRC8EC0QA-1; Tue, 15 Oct 2024 04:52:20 -0400 X-MC-Unique: GiDg4mbjPWev8VRC8EC0QA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1CE351955D5B; Tue, 15 Oct 2024 08:52:19 +0000 (UTC) Received: from localhost (unknown [10.39.208.15]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1DC251956056; Tue, 15 Oct 2024 08:52:17 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini Subject: [PULL 5/8] chardev/mux: introduce `mux_chr_attach_frontend() call Date: Tue, 15 Oct 2024 12:51:47 +0400 Message-ID: <20241015085150.219486-6-marcandre.lureau@redhat.com> In-Reply-To: <20241015085150.219486-1-marcandre.lureau@redhat.com> References: <20241015085150.219486-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.076, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Roman Penyaev Move away logic which attaches frontend device to a mux from `char-fe.c` to actual `char-mux.c` implementation and make it a separate function. No logic changes are made. Signed-off-by: Roman Penyaev Cc: "Marc-André Lureau" Cc: qemu-devel@nongnu.org Reviewed-by: Marc-André Lureau Message-ID: <20241014152408.427700-6-r.peniaev@gmail.com> --- chardev/chardev-internal.h | 2 ++ chardev/char-fe.c | 9 +-------- chardev/char-mux.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/chardev/chardev-internal.h b/chardev/chardev-internal.h index ab93f6ea17..8126ce1806 100644 --- a/chardev/chardev-internal.h +++ b/chardev/chardev-internal.h @@ -59,6 +59,8 @@ DECLARE_INSTANCE_CHECKER(MuxChardev, MUX_CHARDEV, #define CHARDEV_IS_MUX(chr) \ object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_MUX) +bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b, + unsigned int *tag, Error **errp); void mux_set_focus(Chardev *chr, unsigned int focus); void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event); diff --git a/chardev/char-fe.c b/chardev/char-fe.c index 69b47d16bd..3b8771ca2a 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -197,16 +197,9 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp) if (CHARDEV_IS_MUX(s)) { MuxChardev *d = MUX_CHARDEV(s); - if (d->mux_cnt >= MAX_MUX) { - error_setg(errp, - "too many uses of multiplexed chardev '%s'" - " (maximum is " stringify(MAX_MUX) ")", - s->label); + if (!mux_chr_attach_frontend(d, b, &tag, errp)) { return false; } - - d->backends[d->mux_cnt] = b; - tag = d->mux_cnt++; } else if (s->be) { error_setg(errp, "chardev '%s' is already in use", s->label); return false; diff --git a/chardev/char-mux.c b/chardev/char-mux.c index b2d7abf2fc..9294f95546 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -301,6 +301,23 @@ static void mux_chr_update_read_handlers(Chardev *chr) chr->gcontext, true, false); } +bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b, + unsigned int *tag, Error **errp) +{ + if (d->mux_cnt >= MAX_MUX) { + error_setg(errp, + "too many uses of multiplexed chardev '%s'" + " (maximum is " stringify(MAX_MUX) ")", + d->parent.label); + return false; + } + + d->backends[d->mux_cnt] = b; + *tag = d->mux_cnt++; + + return true; +} + void mux_set_focus(Chardev *chr, unsigned int focus) { MuxChardev *d = MUX_CHARDEV(chr); From patchwork Tue Oct 15 08:51:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 13835888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 718CDCFC276 for ; Tue, 15 Oct 2024 08:54:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0dI8-000752-0k; Tue, 15 Oct 2024 04:52:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dI4-00074N-Rl for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dI2-0008Av-TX for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728982346; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FX5rkXQSv2JrIBOkEoNjse+4RoZV6uSbYizMs/zWw7Q=; b=M0JD7Iq3O66vXee6BOjz9mGG7l9bjb1Dn3szvdnVh5R20p5hzrdR4DYCNY+ItaFy4JSPoz F0r8tnHa+6MGDloZ72KMxPRkGLNR8CaBzPqfjVWHyXPnWH/4hPsyTrkEr7OELYykO+8Cdo ob8S+QjCixjDt+PED87mgbw6mAkGaNM= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-497-3C1CkyTCMIWe9754Q_7TyA-1; Tue, 15 Oct 2024 04:52:24 -0400 X-MC-Unique: 3C1CkyTCMIWe9754Q_7TyA-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 125231955F0B; Tue, 15 Oct 2024 08:52:24 +0000 (UTC) Received: from localhost (unknown [10.39.208.15]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AEF7119560AE; Tue, 15 Oct 2024 08:52:22 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini Subject: [PULL 6/8] chardev/mux: switch mux frontends management to bitset Date: Tue, 15 Oct 2024 12:51:48 +0400 Message-ID: <20241015085150.219486-7-marcandre.lureau@redhat.com> In-Reply-To: <20241015085150.219486-1-marcandre.lureau@redhat.com> References: <20241015085150.219486-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.076, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Roman Penyaev Frontends can be attached and detached during run-time (although detach is not implemented, but will follow). Counter variable of muxes is not enough for proper attach/detach management, so this patch implements bitset: if bit is set for the `mux_bitset` variable, then frontend device can be found in the `backend` array (yes, huge confusion with backend and frontends names). Signed-off-by: Roman Penyaev Cc: "Marc-André Lureau" Cc: qemu-devel@nongnu.org Reviewed-by: Marc-André Lureau Message-ID: <20241014152408.427700-7-r.peniaev@gmail.com> --- chardev/chardev-internal.h | 2 +- chardev/char-mux.c | 42 +++++++++++++++++++++++++------------- chardev/char.c | 2 +- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/chardev/chardev-internal.h b/chardev/chardev-internal.h index 8126ce1806..b89aada541 100644 --- a/chardev/chardev-internal.h +++ b/chardev/chardev-internal.h @@ -37,8 +37,8 @@ struct MuxChardev { Chardev parent; CharBackend *backends[MAX_MUX]; CharBackend chr; + unsigned long mux_bitset; int focus; - unsigned int mux_cnt; bool term_got_escape; /* Intermediate input buffer catches escape sequences even if the currently active device is not accepting any input - but only until it diff --git a/chardev/char-mux.c b/chardev/char-mux.c index 9294f95546..4fc619b2da 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -26,6 +26,7 @@ #include "qapi/error.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qemu/bitops.h" #include "chardev/char.h" #include "sysemu/block-backend.h" #include "qapi/qapi-commands-control.h" @@ -168,12 +169,19 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch) case 'b': qemu_chr_be_event(chr, CHR_EVENT_BREAK); break; - case 'c': - assert(d->mux_cnt > 0); /* handler registered with first fe */ + case 'c': { + unsigned int bit; + + /* Handler registered with first fe */ + assert(d->mux_bitset != 0); /* Switch to the next registered device */ - mux_set_focus(chr, (d->focus + 1) % d->mux_cnt); + bit = find_next_bit(&d->mux_bitset, MAX_MUX, d->focus + 1); + if (bit >= MAX_MUX) { + bit = find_next_bit(&d->mux_bitset, MAX_MUX, 0); + } + mux_set_focus(chr, bit); break; - case 't': + } case 't': d->timestamps = !d->timestamps; d->timestamps_start = -1; d->linestart = false; @@ -243,15 +251,16 @@ static void mux_chr_read(void *opaque, const uint8_t *buf, int size) void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event) { MuxChardev *d = MUX_CHARDEV(chr); - unsigned int i; + int bit; if (!muxes_opened) { return; } /* Send the event to all registered listeners */ - for (i = 0; i < d->mux_cnt; i++) { - mux_chr_send_event(d, i, event); + bit = -1; + while ((bit = find_next_bit(&d->mux_bitset, MAX_MUX, bit + 1)) < MAX_MUX) { + mux_chr_send_event(d, bit, event); } } @@ -276,10 +285,11 @@ static GSource *mux_chr_add_watch(Chardev *s, GIOCondition cond) static void char_mux_finalize(Object *obj) { MuxChardev *d = MUX_CHARDEV(obj); - unsigned int i; + int bit; - for (i = 0; i < d->mux_cnt; i++) { - CharBackend *be = d->backends[i]; + bit = -1; + while ((bit = find_next_bit(&d->mux_bitset, MAX_MUX, bit + 1)) < MAX_MUX) { + CharBackend *be = d->backends[bit]; if (be) { be->chr = NULL; } @@ -304,7 +314,10 @@ static void mux_chr_update_read_handlers(Chardev *chr) bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b, unsigned int *tag, Error **errp) { - if (d->mux_cnt >= MAX_MUX) { + unsigned int bit; + + bit = find_next_zero_bit(&d->mux_bitset, MAX_MUX, 0); + if (bit >= MAX_MUX) { error_setg(errp, "too many uses of multiplexed chardev '%s'" " (maximum is " stringify(MAX_MUX) ")", @@ -312,8 +325,9 @@ bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b, return false; } - d->backends[d->mux_cnt] = b; - *tag = d->mux_cnt++; + d->mux_bitset |= (1 << bit); + d->backends[bit] = b; + *tag = bit; return true; } @@ -322,7 +336,7 @@ void mux_set_focus(Chardev *chr, unsigned int focus) { MuxChardev *d = MUX_CHARDEV(chr); - assert(focus < d->mux_cnt); + assert(find_next_bit(&d->mux_bitset, MAX_MUX, focus) == focus); if (d->focus != -1) { mux_chr_send_event(d, d->focus, CHR_EVENT_MUX_OUT); diff --git a/chardev/char.c b/chardev/char.c index f54dc3a862..a1722aa076 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -333,7 +333,7 @@ static bool qemu_chr_is_busy(Chardev *s) { if (CHARDEV_IS_MUX(s)) { MuxChardev *d = MUX_CHARDEV(s); - return d->mux_cnt > 0; + return d->mux_bitset != 0; } else { return s->be != NULL; } From patchwork Tue Oct 15 08:51:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 13835884 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A69B7CFC278 for ; Tue, 15 Oct 2024 08:53:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0dIE-00075b-Gz; Tue, 15 Oct 2024 04:52:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dID-00075S-5v for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dIB-0008BS-M2 for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728982354; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=elooLbY7k2M6MVGuTlkYRMqNz5nxbtsoK5pOiPAY6jg=; b=bfWw620qKar/eVp7HXF/77MDhN3ExxALUzcpZzGEAXC0T0PW6EOvwEunj3s+5PLs9PAnBm RaOKClvFjVnSQO8XeiG/FtJDAmxILfY20CSLcu3VD8pWn7Qrn/qQcppCEMEJ0aQ1k49yAV WJ10AE4Y2Vycrsx6HHQxyC/vubLMo28= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-278-NStpHPb-OY2FBPKHYgefZQ-1; Tue, 15 Oct 2024 04:52:30 -0400 X-MC-Unique: NStpHPb-OY2FBPKHYgefZQ-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EC6281955D5D; Tue, 15 Oct 2024 08:52:29 +0000 (UTC) Received: from localhost (unknown [10.39.208.15]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E55C03000198; Tue, 15 Oct 2024 08:52:27 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini Subject: [PULL 7/8] chardev/mux: implement detach of frontends from mux Date: Tue, 15 Oct 2024 12:51:49 +0400 Message-ID: <20241015085150.219486-8-marcandre.lureau@redhat.com> In-Reply-To: <20241015085150.219486-1-marcandre.lureau@redhat.com> References: <20241015085150.219486-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.076, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Roman Penyaev With bitset management now it becomes feasible to implement the logic of detaching frontends from multiplexer. Signed-off-by: Roman Penyaev Cc: "Marc-André Lureau" Cc: qemu-devel@nongnu.org Reviewed-by: Marc-André Lureau Message-ID: <20241014152408.427700-8-r.peniaev@gmail.com> --- chardev/chardev-internal.h | 1 + chardev/char-fe.c | 2 +- chardev/char-mux.c | 21 ++++++++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/chardev/chardev-internal.h b/chardev/chardev-internal.h index b89aada541..853807f3cb 100644 --- a/chardev/chardev-internal.h +++ b/chardev/chardev-internal.h @@ -61,6 +61,7 @@ DECLARE_INSTANCE_CHECKER(MuxChardev, MUX_CHARDEV, bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b, unsigned int *tag, Error **errp); +bool mux_chr_detach_frontend(MuxChardev *d, unsigned int tag); void mux_set_focus(Chardev *chr, unsigned int focus); void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event); diff --git a/chardev/char-fe.c b/chardev/char-fe.c index 3b8771ca2a..8ac6bebb6f 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -225,7 +225,7 @@ void qemu_chr_fe_deinit(CharBackend *b, bool del) } if (CHARDEV_IS_MUX(b->chr)) { MuxChardev *d = MUX_CHARDEV(b->chr); - d->backends[b->tag] = NULL; + mux_chr_detach_frontend(d, b->tag); } if (del) { Object *obj = OBJECT(b->chr); diff --git a/chardev/char-mux.c b/chardev/char-mux.c index 4fc619b2da..bda5c45e60 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -290,10 +290,10 @@ static void char_mux_finalize(Object *obj) bit = -1; while ((bit = find_next_bit(&d->mux_bitset, MAX_MUX, bit + 1)) < MAX_MUX) { CharBackend *be = d->backends[bit]; - if (be) { - be->chr = NULL; - } + be->chr = NULL; + d->backends[bit] = NULL; } + d->mux_bitset = 0; qemu_chr_fe_deinit(&d->chr, false); } @@ -332,6 +332,21 @@ bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b, return true; } +bool mux_chr_detach_frontend(MuxChardev *d, unsigned int tag) +{ + unsigned int bit; + + bit = find_next_bit(&d->mux_bitset, MAX_MUX, tag); + if (bit != tag) { + return false; + } + + d->mux_bitset &= ~(1 << bit); + d->backends[bit] = NULL; + + return true; +} + void mux_set_focus(Chardev *chr, unsigned int focus) { MuxChardev *d = MUX_CHARDEV(chr); From patchwork Tue Oct 15 08:51:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 13835883 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 131D2CFC278 for ; Tue, 15 Oct 2024 08:53:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t0dII-000769-6I; Tue, 15 Oct 2024 04:52:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dIG-00075v-Np for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t0dIF-0008CG-75 for qemu-devel@nongnu.org; Tue, 15 Oct 2024 04:52:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728982358; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Q5K6BeJaiZ2Fm44mfbHcepRRyNraqfAuk63pnZL6Ug=; b=L2DnFjaReDKpncjd+73dO6YyX3n7IuwYFjFAAaK0ItGBJ1IXlLdeTByTQMNJKNGAkhmwBy LI2nyFYlX9RPHFtSB4egPKk4AH8f8508GI60f6Et2Uwh8OQxBHmUdQz4RQXFRfRLXgeTfS XOgP0c2i7J0nssRaYqr9Y6FVS3RsQPM= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-575-o5g9fm_XMA6Y9Rnac2iW-A-1; Tue, 15 Oct 2024 04:52:35 -0400 X-MC-Unique: o5g9fm_XMA6Y9Rnac2iW-A-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B10FA1955F0B; Tue, 15 Oct 2024 08:52:34 +0000 (UTC) Received: from localhost (unknown [10.39.208.15]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8AB7B1956056; Tue, 15 Oct 2024 08:52:33 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PULL 8/8] tests/unit/test-char: implement a few mux remove test cases Date: Tue, 15 Oct 2024 12:51:50 +0400 Message-ID: <20241015085150.219486-9-marcandre.lureau@redhat.com> In-Reply-To: <20241015085150.219486-1-marcandre.lureau@redhat.com> References: <20241015085150.219486-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.076, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Roman Penyaev This patch tests: 1. feasibility of removing mux which does not have frontends attached or frontends were prior detached. 2. inability to remove mux which has frontends attached (mux is "busy") Signed-off-by: Roman Penyaev Cc: "Marc-André Lureau" Cc: qemu-devel@nongnu.org [ fixed *error leak ] Reviewed-by: Marc-André Lureau Message-ID: <20241014152408.427700-9-r.peniaev@gmail.com> --- tests/unit/test-char.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/unit/test-char.c b/tests/unit/test-char.c index f273ce5226..a1c6bb874c 100644 --- a/tests/unit/test-char.c +++ b/tests/unit/test-char.c @@ -1,6 +1,7 @@ #include "qemu/osdep.h" #include +#include "qapi/error.h" #include "qemu/config-file.h" #include "qemu/module.h" #include "qemu/option.h" @@ -184,6 +185,21 @@ static void char_mux_test(void) char *data; FeHandler h1 = { 0, false, 0, false, }, h2 = { 0, false, 0, false, }; CharBackend chr_be1, chr_be2; + Error *error = NULL; + + /* Create mux and chardev to be immediately removed */ + opts = qemu_opts_create(qemu_find_opts("chardev"), "mux-label", + 1, &error_abort); + qemu_opt_set(opts, "backend", "ringbuf", &error_abort); + qemu_opt_set(opts, "size", "128", &error_abort); + qemu_opt_set(opts, "mux", "on", &error_abort); + chr = qemu_chr_new_from_opts(opts, NULL, &error_abort); + g_assert_nonnull(chr); + qemu_opts_del(opts); + + /* Remove just created mux and chardev */ + qmp_chardev_remove("mux-label", &error_abort); + qmp_chardev_remove("mux-label-base", &error_abort); opts = qemu_opts_create(qemu_find_opts("chardev"), "mux-label", 1, &error_abort); @@ -334,7 +350,13 @@ static void char_mux_test(void) g_free(data); qemu_chr_fe_deinit(&chr_be1, false); - qemu_chr_fe_deinit(&chr_be2, true); + + qmp_chardev_remove("mux-label", &error); + g_assert_cmpstr(error_get_pretty(error), ==, "Chardev 'mux-label' is busy"); + error_free(error); + + qemu_chr_fe_deinit(&chr_be2, false); + qmp_chardev_remove("mux-label", &error_abort); }