From nobody Tue Apr 16 11:32:58 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=1622574483; cv=none; d=zohomail.com; s=zohoarc; b=g5gcJs8jcEMyNqjhlPK5OR3aGcD19DKP8S3xk/Bv/DEw2tfV8LCnW36WDsxr/NoaayvfLKoK1Vh/f279nsoLEy4wt2hpuNfWOrSPvfo3HpeOaDAPk6IKpDDnNx0w1iP1sly0mlzmsAljujfLbRWnSXUp2laOwIZ1HvcvBYfvfvw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622574483; 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=hjrQNX0Zeai5DuYHJoIKIsnlC8k8McgH6A8LEHIrttU=; b=VPW80yigE65zw5fIOx7/h9oiW75+pSnikLRSC906WmGHyXQ+RUdMSZLAuA93QugPhyOCOWQDqlOsNSKV6p8J1dZ+ygyWN5oWrcJaNf8EOFKKRQzphNYE/Vo6gEl1CYkFv+/PVd2px5auw2ZOvrmKxztGJL1DQ9wYVkVvm0RMz2A= 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 1622574483626327.9936826962452; Tue, 1 Jun 2021 12:08:03 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id F01B410619E6; Tue, 1 Jun 2021 19:07:59 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 2D0BC10619E1 for ; Tue, 1 Jun 2021 19:07:46 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by mailout10.t-online.de (Postfix) with SMTP id 742A972525; Tue, 1 Jun 2021 21:07:01 +0200 (CEST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lo9j6-4ZFkTA0; Tue, 1 Jun 2021 21:06:56 +0200 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id 3A1242000A0; Tue, 1 Jun 2021 21:06:56 +0200 (CEST) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Kevin O'Connor Date: Tue, 1 Jun 2021 21:06:54 +0200 Message-Id: <20210601190656.7162-1-vr_qemu@t-online.de> In-Reply-To: <6bff0709-f229-c180-e91f-52c7c3fea5ac@t-online.de> References: <6bff0709-f229-c180-e91f-52c7c3fea5ac@t-online.de> MIME-Version: 1.0 X-ID: bHh+vuZfZh+DiffbqjCPjRXW-+AS3a0ewO-xYk8WB4mD1T8apYcWeYAgh8Y2ORSQOI X-TOI-EXPURGATEID: 150726::1622574416-000121E1-23BEF011/0/0 CLEAN NORMAL X-TOI-MSGID: 28333c42-cf7c-44ee-a0eb-13441c7c31ad Message-ID-Hash: P7QDMTTXQOMCRACNCPDGZKAIH5ZUHB6B X-Message-ID-Hash: P7QDMTTXQOMCRACNCPDGZKAIH5ZUHB6B 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 v3 1/3] stacks: fix asm constraints 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 variables data, func, thread and cur are input operands for the asm statement in run_thread(). The assembly code clobbers these inputs. From the gcc documentation chapter Extended-Asm, Input Operands: "It is not possible to use clobbers to inform the compiler that the values in these inputs are changing. One common work-around is to tie the changing input variable to an output variable that never gets used." Add unused output variables and fix the asm constraints in run_thread(). Signed-off-by: Volker R=C3=BCmelin --- src/stacks.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/stacks.c b/src/stacks.c index 2fe1bfb..ef0aba1 100644 --- a/src/stacks.c +++ b/src/stacks.c @@ -565,6 +565,7 @@ run_thread(void (*func)(void*), void *data) thread->stackpos =3D (void*)thread + THREADSTACKSIZE; struct thread_info *cur =3D getCurThread(); hlist_add_after(&thread->node, &cur->node); + u32 unused_a, unused_b, unused_c, unused_d; asm volatile( // Start thread " pushl $1f\n" // store return pc @@ -576,14 +577,15 @@ run_thread(void (*func)(void*), void *data) // End thread " movl %%ebx, %%eax\n" // %eax =3D thread " movl 4(%%ebx), %%ebx\n" // %ebx =3D thread->node.next - " movl (%5), %%esp\n" // %esp =3D MainThread.stackpos - " calll %4\n" // call __end_thread(thread) + " movl (%9), %%esp\n" // %esp =3D MainThread.stackpos + " calll %8\n" // call __end_thread(thread) " movl -4(%%ebx), %%esp\n" // %esp =3D next->stackpos " popl %%ebp\n" // restore %ebp " retl\n" // restore pc "1:\n" - : "+a"(data), "+c"(func), "+b"(thread), "+d"(cur) - : "m"(*(u8*)__end_thread), "m"(MainThread) + : "=3Da"(unused_a), "=3Dc"(unused_c), "=3Db"(unused_b), "=3Dd"(unu= sed_d) + : "0"(data), "1"(func), "2"(thread), "3"(cur), + "m"(*(u8*)__end_thread), "m"(MainThread) : "esi", "edi", "cc", "memory"); return; =20 --=20 2.26.2 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org From nobody Tue Apr 16 11:32:58 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=1622574437; cv=none; d=zohomail.com; s=zohoarc; b=iOcvkvPm1lTVLcNMPqzV57eZjp3yT9FCPGBETnz3TUTXRfYGLjGuXeQbYFpT91cF5dk8sX7skED6hFDFhqXZv4Hin0tuOgH+M6f28wqdEavDz0C1Q0cJfF1cc/nkxPgl5b8Z0QsAIfXZk/37BJCHjcENru8HwJhp7cVSCYBtucI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622574437; 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=5mvVSY4J7WGMDlrY8fI4bpvsizbaVq0qVBJHV9d75uY=; b=kfDRyOYAWFTPUcXqU3GppGpGJ5I8/ncQB1GR/nte4R1goz6YgG58d8HX/UMgyQ8NhScr4UooY6wvg/wgqQEBCkcOWxYzyiiRmE9Em8bzuK7D4QjdhYRp5f/0RZQaiKttYT3USwKUm/mB8eg9hIv2oPMqt+fezYEqzfGhgqiy8Yc= 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 1622574437669115.13117809241305; Tue, 1 Jun 2021 12:07:17 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 19F3510619E5; Tue, 1 Jun 2021 19:07:14 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 6394910619D6 for ; Tue, 1 Jun 2021 19:07:00 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by mailout08.t-online.de (Postfix) with SMTP id 1B9F870377; Tue, 1 Jun 2021 21:07:00 +0200 (CEST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lo9j9-1JY6G80; Tue, 1 Jun 2021 21:06:59 +0200 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id 3C0932000A1; Tue, 1 Jun 2021 21:06:56 +0200 (CEST) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Kevin O'Connor Date: Tue, 1 Jun 2021 21:06:55 +0200 Message-Id: <20210601190656.7162-2-vr_qemu@t-online.de> In-Reply-To: <6bff0709-f229-c180-e91f-52c7c3fea5ac@t-online.de> References: <6bff0709-f229-c180-e91f-52c7c3fea5ac@t-online.de> MIME-Version: 1.0 X-ID: V+DXMaZQ8hvXlIp7BvpFQ+75mzVrxRkEgJSNMtd72dlfGcuAms4kxAp+Rdmq1UHQKi X-TOI-EXPURGATEID: 150726::1622574419-0001611E-4CBD5E0E/0/0 CLEAN NORMAL X-TOI-MSGID: cad4af00-f878-4f50-895e-cd46bb0ffddf Message-ID-Hash: OAVPB7IJ56TFDQ5WBGJQZFRQW74WNLO5 X-Message-ID-Hash: OAVPB7IJ56TFDQ5WBGJQZFRQW74WNLO5 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 v3 2/3] 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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/stacks.c b/src/stacks.c index ef0aba1..58c0317 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) @@ -587,6 +589,9 @@ run_thread(void (*func)(void*), void *data) : "0"(data), "1"(func), "2"(thread), "3"(cur), "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 Tue Apr 16 11:32:58 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=1622574519; cv=none; d=zohomail.com; s=zohoarc; b=CCv6dTFFUfjRAx2VK4eaStjSOLXZ/BR1Igul2zFADZNtcsNktwzkKd8OnurcdwHw8gEt0nFm8zLZUTFw/xZqJvFUzdzlSMHrg2O3YSaxOOsIqDQyqc9QoXLwINsdsNFp6Loy1b+bLogxXDhJfLLFi/dfvPo1BHMfCfSncBrc95w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622574519; 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=bKCahNXXHzHqkWbh3lU9Oads/EArlQ9ffffPUdt184c=; b=cwdCJja1a/9oA10eQ4GaU+8HKQHd0WsD6kFU2Rf7eL6wbOd/yIGe2bOpctWtjdg3RKMcrdbd9tNIHenvnbbbGEAwCQRVCfGNQkncqk4aGY3nXNUR7yDjn14ldbly6JKs7jDtiLN780wG48yUEWhqbQhjRMQvzf1Oaammk+qFrHQ= 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 1622574519139582.2575397036835; Tue, 1 Jun 2021 12:08:39 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 76D8310619E9; Tue, 1 Jun 2021 19:08:21 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id EB17110619E2 for ; Tue, 1 Jun 2021 19:08:08 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by mailout05.t-online.de (Postfix) with SMTP id C2BB767BC6; Tue, 1 Jun 2021 21:07:05 +0200 (CEST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lo9jB-1H4w1A0; Tue, 1 Jun 2021 21:07:01 +0200 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) id 3D4FB200607; Tue, 1 Jun 2021 21:06:56 +0200 (CEST) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Kevin O'Connor Date: Tue, 1 Jun 2021 21:06:56 +0200 Message-Id: <20210601190656.7162-3-vr_qemu@t-online.de> In-Reply-To: <6bff0709-f229-c180-e91f-52c7c3fea5ac@t-online.de> References: <6bff0709-f229-c180-e91f-52c7c3fea5ac@t-online.de> MIME-Version: 1.0 X-ID: XLMOu8ZZghM3O0nvdrBijuBoJzV+Blu7MTDGEbKe0usScV43S+yP8Sqi0b94nLIZ8y X-TOI-EXPURGATEID: 150726::1622574421-0000B607-E8999779/0/0 CLEAN NORMAL X-TOI-MSGID: 0c145804-2a07-4882-b45f-789406413d42 Message-ID-Hash: VBZZLE6TH2EIO4E7TH3ENGENNJ7DXX3N X-Message-ID-Hash: VBZZLE6TH2EIO4E7TH3ENGENNJ7DXX3N 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 v3 3/3] 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 58c0317..e090919 100644 --- a/src/stacks.c +++ b/src/stacks.c @@ -630,12 +630,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