From nobody Wed Apr 24 01:22:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org ARC-Seal: i=1; a=rsa-sha256; t=1622829805; cv=none; d=zohomail.com; s=zohoarc; b=kIhWXlsiYbXPk5mJlZZmEQYafw0j/VfcgcfKSIhuleKs2RYQXKw2X568vCXiFOrkL3CDjrLiG3IUto9d9/RujAzijw6f139jKxNbJrQEI9ENDM8uRvMQvM5Rr5yA6SgCeutXT6OoSA6EkANDrgYSBcyF1jiJDFkNN7XfLNG0cng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622829805; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:To; bh=6NjbeEMMc9e+Sb/LYQYhPgIUHbn+2Fnck7nwPVQjJKg=; b=IVB2dtyLPa4CEoyzA7q/k/i/YFLvBTb10efzDr2SErIwtPPWRaXRkaUperkgyseA5biTFlmM/DoJ2Qup211x0XP6PhTYQ0jJVndLfs3ZQ/z58VpaNvxsg056jj8tbtbm6+KR40xLk/ysn7IaTbdMWpsrdMc++AkttuDoXkek0Lo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1622829805741687.8411774825854; Fri, 4 Jun 2021 11:03:25 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 11BB41061B50; Fri, 4 Jun 2021 18:03:22 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 1FAA91061B4A for ; Fri, 4 Jun 2021 18:03:08 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by mailout09.t-online.de (Postfix) with SMTP id 703D774F6D; Fri, 4 Jun 2021 20:01:21 +0200 (CEST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lpE8H-0Powjo0; Fri, 4 Jun 2021 20:01:21 +0200 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id C08C62001F3; Fri, 4 Jun 2021 20:01:20 +0200 (CEST) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Kevin O'Connor Date: Fri, 4 Jun 2021 20:01:19 +0200 Message-Id: <20210604180120.10458-1-vr_qemu@t-online.de> In-Reply-To: References: MIME-Version: 1.0 X-ID: bVqt1MZAQhShUBH2zvn4u6t1ryZPgs76UXjolD-11vihESQHWqBAIAKX6TwOtUgZxz X-TOI-EXPURGATEID: 150726::1622829681-0000D63F-74B6A762/0/0 CLEAN NORMAL X-TOI-MSGID: 8b65aafc-3af9-4083-acdb-b7f052e8548c Message-ID-Hash: V6HTP7OIL6KZ3J42YVP7NOIBM3IQW2WI X-Message-ID-Hash: V6HTP7OIL6KZ3J42YVP7NOIBM3IQW2WI X-MailFrom: volker.ruemelin@t-online.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: seabios@seabios.org X-Mailman-Version: 3.3.4 Precedence: list Subject: [SeaBIOS] [PATCH v4 1/2] stacks: call check_irqs() in run_thread() List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: --- The comment above the yield() function suggests that yield() allows interrupts for a short time. But yield() only briefly enables interrupts if seabios was built without CONFIG_THREADS or if yield() is called from the main thread. In order to guarantee that the interrupts were enabled once before yield() returns in a background thread, the main thread must call check_irqs() before or after every thread switch. The function run_thread() also switches threads, but the call to check_irqs() was forgotten. Add the missing check_irqs() call. This fixes PS/2 keyboard initialization failures. The code in src/hw/ps2port.c relies on yield() to briefly enable interrupts. There is a comment above the yield() function in __ps2_command(), where the author left a remark why the call to yield() is actually needed. Here is one of the call sequences leading to a PS/2 keyboard initialization failure. ps2_keyboard_setup() | ret =3D i8042_command(I8042_CMD_CTL_TEST, param); # This command will register an interrupt if the PS/2 device # controller raises interrupts for replies to a controller # command. | ret =3D ps2_kbd_command(ATKBD_CMD_RESET_BAT, param); | ps2_command(0, command, param); | ret =3D __ps2_command(aux, command, param); | // Flush any interrupts already pending. yield(); # yield() doesn't flush interrupts if the main thread # hasn't reached wait_threads(). | ret =3D ps2_sendbyte(aux, command, 1000); # Reset the PS/2 keyboard controller and wait for # PS2_RET_ACK. | ret =3D ps2_recvbyte(aux, 0, 4000); | for (;;) { | status =3D inb(PORT_PS2_STATUS); # I8042_STR_OBF isn't set because the keyboard self # test reply is still on wire. | yield(); # After a few yield()s the keyboard interrupt fires # and clears the I8042_STR_OBF status bit. If the # keyboard self test reply arrives before the # interrupt fires the keyboard reply is lost and # ps2_recvbyte() returns after the timeout. } Signed-off-by: Volker R=C3=BCmelin --- src/stacks.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/stacks.c b/src/stacks.c index 2fe1bfb..df32325 100644 --- a/src/stacks.c +++ b/src/stacks.c @@ -549,6 +549,8 @@ __end_thread(struct thread_info *old) dprintf(1, "All threads complete.\n"); } =20 +void VISIBLE16 check_irqs(void); + // Create a new thread and start executing 'func' in it. void run_thread(void (*func)(void*), void *data) @@ -564,6 +566,7 @@ run_thread(void (*func)(void*), void *data) dprintf(DEBUG_thread, "/%08x\\ Start thread\n", (u32)thread); thread->stackpos =3D (void*)thread + THREADSTACKSIZE; struct thread_info *cur =3D getCurThread(); + struct thread_info *edx =3D cur; hlist_add_after(&thread->node, &cur->node); asm volatile( // Start thread @@ -582,9 +585,12 @@ run_thread(void (*func)(void*), void *data) " popl %%ebp\n" // restore %ebp " retl\n" // restore pc "1:\n" - : "+a"(data), "+c"(func), "+b"(thread), "+d"(cur) + : "+a"(data), "+c"(func), "+b"(thread), "+d"(edx) : "m"(*(u8*)__end_thread), "m"(MainThread) : "esi", "edi", "cc", "memory"); + if (cur =3D=3D &MainThread) + // Permit irqs to fire + check_irqs(); return; =20 fail: --=20 2.26.2 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Wed Apr 24 01:22:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org ARC-Seal: i=1; a=rsa-sha256; t=1622829713; cv=none; d=zohomail.com; s=zohoarc; b=bemsh5Z1hK2tHTjfzQV1kIrqssEcp9E64cUSFNR6VROGws8Ktxe0UeyfBb6O5htDv7CCZX+lLpnUW2nyCTGIzOiLzNZYAk7/7AE7RF9riiztvsSe0JWlhKfuGWM8nLSqbZJFO8JQOcCiWWEGz09RRXswyhzmtP0xRecGetWDKVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622829713; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:To; bh=qRHU2/1OI1b1V3LwMYPjJgI2aUkDUXO2+jz2Zd3DWhs=; b=UXn3tAsKwmqOlVru7qD+M+25DtuiRAotw2PNLmOpl7aLbDzeUEHb9lA4ZQdXhsr/lwamz9+UEWzHohdcOKu+wPAQveDkuUSQezbD8o2fd1RHVXv8F01q8LLZkeeg3DS0A0lsN7jn/FTzqAYbh7FeHMIqVDMJJRuQTjU9/wY3SdY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 162282971375868.97287581053138; Fri, 4 Jun 2021 11:01:53 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 60B2C1061B4F; Fri, 4 Jun 2021 18:01:50 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id DBABC1061B42 for ; Fri, 4 Jun 2021 18:01:36 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by mailout01.t-online.de (Postfix) with SMTP id 7C0906680F; Fri, 4 Jun 2021 20:01:36 +0200 (CEST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lpE8J-0gQCnY0; Fri, 4 Jun 2021 20:01:23 +0200 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id C2A07200461; Fri, 4 Jun 2021 20:01:20 +0200 (CEST) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Kevin O'Connor Date: Fri, 4 Jun 2021 20:01:20 +0200 Message-Id: <20210604180120.10458-2-vr_qemu@t-online.de> In-Reply-To: References: MIME-Version: 1.0 X-ID: TWtlJMZ6rhqDvXs-9YsNEvvyw774xQdfrRjzGe4qHGR9rWiNMTICQkUMNoLfePfZl3 X-TOI-EXPURGATEID: 150726::1622829683-00016BF9-607DE329/0/0 CLEAN NORMAL X-TOI-MSGID: 9ee92c25-227e-4efc-941c-72bd8a32d278 Message-ID-Hash: W4DQ3OQFRKAEXGVNMHOV74NA4TY2KDDE X-Message-ID-Hash: W4DQ3OQFRKAEXGVNMHOV74NA4TY2KDDE X-MailFrom: volker.ruemelin@t-online.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: seabios@seabios.org X-Mailman-Version: 3.3.4 Precedence: list Subject: [SeaBIOS] [PATCH v4 2/2] stacks: call check_irqs() after switch_next() List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: --- In function run_thread() the function check_irqs() gets called after the thread switch for atomic handoff reasons. In yield() it's the other way round. If check_irqs() is called after run_thread() and check_irqs() is called before switch_next() in yield(), it can happen in a constructed case that a background thread runs twice without a check_irqs() call in between. Call check_irqs() after switch_next() in yield() to prevent this. Signed-off-by: Volker R=C3=BCmelin --- src/stacks.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/stacks.c b/src/stacks.c index df32325..4c8e5df 100644 --- a/src/stacks.c +++ b/src/stacks.c @@ -629,12 +629,11 @@ yield(void) return; } struct thread_info *cur =3D getCurThread(); + // Switch to the next thread + switch_next(cur); if (cur =3D=3D &MainThread) // Permit irqs to fire check_irqs(); - - // Switch to the next thread - switch_next(cur); } =20 void VISIBLE16 --=20 2.26.2 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org