Received: by 2002:a89:2d5:0:b0:1ef:f8eb:5d24 with SMTP id d21csp136613lqs; Sun, 17 Mar 2024 14:28:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXqPujBy9YepuKj5MBs8QtZ4ru0GGIaDUWThz2nyZK4xsqkOYgF1VPL20QPR+665sWMPfZ2orGBJK2xwwaWene2a/pwR7YtfukCqHclVg== X-Google-Smtp-Source: AGHT+IGJtVjpfnRK8cri/UYrM0qCEGPhwY1g5J14sd+Y3eIOPswEt4AW8LlrS+glI1R7Ri8XGV5U X-Received: by 2002:a05:6e02:1caf:b0:365:cf7:af3a with SMTP id x15-20020a056e021caf00b003650cf7af3amr15939366ill.21.1710710883667; Sun, 17 Mar 2024 14:28:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710710883; cv=pass; d=google.com; s=arc-20160816; b=NiPXXIIcoaa7SxzccVqEMm0WrzQRh0pbLMhtX5mfokTWP3NraIEblQjxBF2lt++RQ0 s2yc02rct65bAxEnSOop5Ir2KFL60w+GKWPgnWncvRe2ILuTA0DoduXjrnAm4AlY5LuZ itBcuTjs0MSl2lUF5H++Ch6cKVtz2kjzfeC3Kele4MDxc0U3Hb2tZdqyiO4N2CVMjnQd /YFCkkyHhGsDCubEdSQ3lr6ZWxcRSQPlrftjyOX2OGdJLwASzpBhzinVcUiX4lcHS/Mz /jBLfkNKwnO63OhSisqdjOonG7WbpIe9vjpviYQsdtWR+3owvSJJhbvPaZ5yYguUlHM6 XvKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:dkim-signature:dkim-signature:date; bh=3srrq43UiauzyNmV0S4k/pQ0+n44cbViGcHlmEyhFec=; fh=t2fWsTNy8keTLeYa2GGKAABJiuV95gmFjgbEzCjWvQ0=; b=ecP9a6OxxDZPe6V0SHuroAg5IDo0kgNCatF5iUvtv4nXH3JoNDzT6PyodCBlXXa1Ic HeLt+X9HstbzHJNqgp0p87XbfgCyPNo0pHVsN8z8OUj5yFHc9qO9R/LusmdwdQp+ZyCh mUe7EkVzy+jLhPQwKc58wqIue/HucdVJBk5zTCeDBFhSTvvxX0yr4IC1zDZPt/k4Edhr FHNxIHlMnqTvxCib+yioKd7ayYRhP2UN0+JfPeo2MElcK5RRuvXWE1bkiueIYHTQQ0lW TIqv7d0vfUEi/pb2jol5JlP76SbV9xp9c28b954BHnXD1KrdIRJ0RjNH7tuJPcx2dKvC H6xA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1fNVmtkO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-105562-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105562-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r184-20020a632bc1000000b005e438e96ae6si6712922pgr.601.2024.03.17.14.28.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Mar 2024 14:28:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-105562-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1fNVmtkO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-105562-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105562-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id DDD30B2149C for ; Sun, 17 Mar 2024 21:27:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B35B620B20; Sun, 17 Mar 2024 21:27:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1fNVmtkO"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="SylwjTSs" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B7EE20B0E; Sun, 17 Mar 2024 21:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710710850; cv=none; b=oGvhg9gnzni1/RWcCOGfRvnZ65+lL/ZNOJYi+hvM0uDKUpPna6YAk6WgjIn8lWfZ2MBx/3FbOzx5vbwqyEzlR/CcnXrApiAfcI9f+2I5+pEBQ8P03vWmeEofRaiqJII/gg5T7Fpp2LaJwHP3vdErvNBKrEyYM3ijmu6VhA2L7tU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710710850; c=relaxed/simple; bh=r1A5i7RbsqOv08lAHnRoEkHu4xFVjK0PL6GJ6TPUP4g=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ezoyAcm4esyaqlUMM8uEtkeGlXvspVsECHXWU8dF6CCkYrOgt5sc2LQlHs+y1xAJuwDcFX4n7V6WBG+71TVcynUM6Oi1Qw14MaABYiWd8sqlnQYF5jS9JeyQ4l5M7q6ldAetx/vhVZvHfifQZpmXbDuWYoeKFYD/uBNMwDS8bPY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1fNVmtkO; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=SylwjTSs; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Sun, 17 Mar 2024 22:27:18 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1710710841; 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=3srrq43UiauzyNmV0S4k/pQ0+n44cbViGcHlmEyhFec=; b=1fNVmtkODQCyt/lLuw8N+h0zm9GlRxTrwdCdxVYqb0U61pUF+sSwuEpypKO9P5v6SxPboT F/UM87VVCz4tp1gxAH+xHT9mxvwzX/bw1BiLnk1tX+fl6FQ8UGe1hH3YJaR2vZIEBAuj2h ej6eAmtwLZr31q/Aq7Nz7rJDI5EdONmSNSdVXhZnQDbvXa4r+5/TIh5A1F0yo+aNX1+7xe HWqK59rrfupWFrxBGbVA3mUhrks5kaGIEpEAdTqoAzofwv5NbVQFuS4tejEyTTKkDn3Nqq ilemSoMXJBAPOsCMWEj3CN+0sPjuWnkv+5PbUet5upLzYFVXbN+JORTcIyi8QQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1710710841; 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=3srrq43UiauzyNmV0S4k/pQ0+n44cbViGcHlmEyhFec=; b=SylwjTSsGZaa+c23HhGRyB4sQnKHpj5LUrtHGIBxrFtqZWnK0ugZz2u31upBqdXswNlDOi Z9nDIgvsqHsLJmCg== From: Nam Cao To: Eva Kurchatova Cc: linux-riscv , bugs@lists.linux.dev, linux-i2c@vger.kernel.org, jikos@kernel.org, benjamin.tissoires@redhat.com, dianders@chromium.org, mripard@kernel.org, johan+linaro@kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: Boot hang with SiFive PLIC when routing I2C-HID level-triggered interrupts Message-ID: <20240317222718.3e03edb1@namcao> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: HID folks On 14/Mar/2024 Eva Kurchatova wrote: > If an I2C-HID controller level-triggered IRQ line is routed directly as > a PLIC IRQ, and we spam input early enough in kernel boot process > (Somewhere between initializing NET, ALSA subsystems and before > i2c-hid driver init), then there is a chance of kernel locking up > completely and not going any further. > > There are no kernel messages printed with all the IRQ, task hang > debugging enabled - other than (sometimes) it reports sched RT > throttling after a few seconds. Basic timer interrupt handling is > intact - fbdev tty cursor is still blinking. > > It appears that in such a case the I2C-HID IRQ line is raised; PLIC > notifies the (single) boot system hart, kernel claims the IRQ and > immediately completes it by writing to CLAIM/COMPLETE register. > No access to the I2C controller (OpenCores) or I2C-HID registers > is made, so the HID report is never consumed and IRQ line stays > raised forever. The kernel endlessly claims & completes IRQs > without doing any work with the device. It doesn't always end up this > way; sometimes boot process completes and there are no signs of > interrupt storm or stuck IRQ processing afterwards. It seems I2C HID's interrupt handler (i2c_hid_irq) returns immediately if I2C_HID_READ_PENDING is set. This flag is supposed to be cleared in i2c_hid_xfer(), but since the (threaded) interrupt handler runs at higher priority, the flag is never cleared. So we have a lock-up: interrupt handler won't do anything unless the flag is cleared, but the clearing of this flag is done in a lower priority task which never gets scheduled while the interrupt handler is active. There is RT throttling to prevent RT tasks from locking up the system like this. I don't know much about scheduling stuffs, so I am not really sure why RT throttling does not work. I think because RT throttling triggers when RT tasks take too much CPU time, but in this case hard interrupt handlers take lots of CPU time too (~50% according to my measurement), so RT throttling doesn't trigger often enough (in this case, it triggers once and never again). Again, I don't know much about scheduler so I may be talking nonsense here. The flag I2C_HID_READ_PENDING seems to be used to make sure that only 1 I2C operation can happen at a time. But this seems pointless, because I2C subsystem already takes care of this. So I think we can just remove it. Can you give the below patch a try? diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c index 2735cd585af0..799ad0ef9c4a 100644 --- a/drivers/hid/i2c-hid/i2c-hid-core.c +++ b/drivers/hid/i2c-hid/i2c-hid-core.c @@ -64,7 +64,6 @@ /* flags */ #define I2C_HID_STARTED 0 #define I2C_HID_RESET_PENDING 1 -#define I2C_HID_READ_PENDING 2 #define I2C_HID_PWR_ON 0x00 #define I2C_HID_PWR_SLEEP 0x01 @@ -190,15 +189,10 @@ static int i2c_hid_xfer(struct i2c_hid *ihid, msgs[n].len = recv_len; msgs[n].buf = recv_buf; n++; - - set_bit(I2C_HID_READ_PENDING, &ihid->flags); } ret = i2c_transfer(client->adapter, msgs, n); - if (recv_len) - clear_bit(I2C_HID_READ_PENDING, &ihid->flags); - if (ret != n) return ret < 0 ? ret : -EIO; @@ -566,9 +560,6 @@ static irqreturn_t i2c_hid_irq(int irq, void *dev_id) { struct i2c_hid *ihid = dev_id; - if (test_bit(I2C_HID_READ_PENDING, &ihid->flags)) - return IRQ_HANDLED; - i2c_hid_get_input(ihid); return IRQ_HANDLED;