Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp79872lqt; Mon, 18 Mar 2024 01:48:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVY305hEr5YK7Jd9CRX2jJGtmCJG6LDjZbXL6gn2MIqNOgmp7Hnn3wtH5pgjRsUR1UdkLydZFqr/ccpNDIpahf7wtpTNM9u6cuqULEeJg== X-Google-Smtp-Source: AGHT+IHJQXtZbpvs4CLrpw488JNwYaruatWqqihtY2Vl2h1RWqC9hAhm/lNAFtfFeC/PdE6jw+ss X-Received: by 2002:a05:620a:621a:b0:788:41d6:14cb with SMTP id ou26-20020a05620a621a00b0078841d614cbmr12783505qkn.24.1710751729881; Mon, 18 Mar 2024 01:48:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710751729; cv=pass; d=google.com; s=arc-20160816; b=DV7zQSzmNQ1jjcyDnv3efCAnWdex1mSwhKxdX8xhX+P9egTCW8zDQCQqtcquny7mFc SArtUnIk2Z3f1fd7sAXfxfZu86gVIDZAmZNKuMpoRBK133NLWX7qUspX29xKhrY4dKbp MIXjCMZGG+/taryGnkCZV0zZo/5HIdCGWu0WH5LKifWjFosKm8fvEGnaFVAYNC3Z1eCM I4u7SBKPnKEXx9sszNDM8IlDSTthkYS4rzIlhIRBAQRepcyVP+KkQYIelKKZ+Wj2Ckxo cbsz7sje2sENdVl3d/MJsYfUBdDGxUQgkKfV2vrwVUGVnD4obXVD70seXV40yYK80C2p Fs6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=kpf6P/mv1nh+G+2opKvaPHFGchVDvvH/+dJJvdzBkJE=; fh=B1Z3MrYF3IfGcYMu4PsgVn1urF/k5B5aqvxP2oXre0o=; b=UimWHkZlrktkx35Up5DPaUZpXCqslhogj0w/VA/L0Ucq/Ll3p+F2/qUiVYsMOx1mAO 6QjtQElgwa1zB/UfxxzOdNvkOULu3SNH3S7aDzdqms9Rl7AxQRWgwxZY3uO6Bm90ajMQ HpWnGeOLbAj8h3+CIJJrybwawxLrYj2zMKt6GhadEn2SANOm4ULUrq+Fy8YtM6vrFif4 B1IDdno9cvmvSskFB6VUcTJEiO3qfszCd3RUZMebhQzeO9Ru6QASA2faAZL13C9b7u9c 1SxgBucuDc4LGZjJJqsTO7q308cYkiqphwLSunS15TeF99NHJDeeTEEnE0sLwQfNw0D/ HZpQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=looe8aZR; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-105834-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105834-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c11-20020a05620a200b00b00789e8865563si5586282qka.220.2024.03.18.01.48.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 01:48:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-105834-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=looe8aZR; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-105834-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105834-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 891AB1C2087D for ; Mon, 18 Mar 2024 08:48:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EEE5C28DD5; Mon, 18 Mar 2024 08:48:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="looe8aZR" Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 082EE288D7; Mon, 18 Mar 2024 08:48:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710751710; cv=none; b=X46RpzyQ5zPm11PSJyXd7SjU4iGM3HMTEyJOTWtRUUy5aI5ObqZO14SuD0U7zU7Lg/2mqIJVKCuyJ7zMN1RygKFta/j4DKQUiRK0upSHnP0ZDCR/c7ExUSPF9lOoGK1hJjY7kYc4AcjiQe+TZ8rz46GAEeiawRXuLt8B609obz8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710751710; c=relaxed/simple; bh=owIMFRWACGRv/fYCW/6DnXxYC1Wgpz6uLqFLSH/tF08=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=dkOBP6ts7EWGtdLhnPTQhLDvaP7OSSkBkTqz5sIJQmI6Ufg4LChkiFYdSo2jdsjVSsWFONeRb/VHbsaGMZYugyUCKC70tg3/QmUkgqXx8EOQ2NYtC7TS5vUq+W64uuuDznreYs9hlqRg8+ezWXSyrN51mjXlroKVOaIdSm1HeD0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=looe8aZR; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-513d247e3c4so3281108e87.0; Mon, 18 Mar 2024 01:48:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710751705; x=1711356505; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kpf6P/mv1nh+G+2opKvaPHFGchVDvvH/+dJJvdzBkJE=; b=looe8aZRPbDmG3Qkw73eTu7LJJSyPQ/+LUBI3CORf+zXFkySpPV0gJzc7biGT8WENP FsH4fcaL5VCitRbHLPHiCQgnGN7tVvqAoyRU3G2KIE99JMAhOga2oEqWEJAwncOHw38S 5kwwbhz7HSKgAHyk2wkn6ATJt9x7kh4uZAD243A9IVbgKIPSGQWD5N1xFfFanb7kqeYh LLY7HUkJMQuoe4oFCRrAd4eVlNFFg+LeoRxPfSyC0cKRKI0WPY7cO2fj/o/FufDTiK85 LdBCWi+1C69XiBUDDJrxFbHDaPTn3TE/iFCOYfX3ZLL3wqgOSveJL2gCbesCJN6TMhPQ i7Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710751705; x=1711356505; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kpf6P/mv1nh+G+2opKvaPHFGchVDvvH/+dJJvdzBkJE=; b=kXITKmtNZPiL+FALvm1NrBtsadd9Z0o0HTxY2+hno8rPMLJkm92FIQsVSacfX6roAt oM81yK/lZC8Hm0I7HyQMP9ZK3GIOrZatgl1nV7MD9uiE1XSt1ZVctMXQhUw2L5i+qZDl 2fJBzFT213rbEKZ9YhwYGLceXsdjZmhNmqLMXMsM8xkqtFTfjrBS6u0FqqUx4V1Qkr6q opL4Rlpqfi8z6AQngBa114RW4XxWbGfing13vn3pA19Mn5X+3SD6I40cy4N0cRs58f/3 +7MQBujzqhEuM/7ZUrORLz7z+boWuuvH/a9arB6wOiT5UYWreemyQUmT1/ywb+YI6vqE WCwg== X-Forwarded-Encrypted: i=1; AJvYcCVeF1G4NlYG4AtHndYM4/YrTvcDr0627SdWTASXlSoy3InGZFU4tLUPq1nCZkfa/lifQGZX/4ZrIrPQtqsiURJV+JHHuGiw58rhniaXl9cchGbIXVGAu9gDzTr6bsW2knwE/um4o+j/cN9W3hEx1vYde8gV4AEJ1hJD++KPcfbEBEprQBk= X-Gm-Message-State: AOJu0YwCFe8KBgZS8DeAc2VovGHZ0HoTTLhT/cDnSIcQZ8lI3BOa8xVX HhP0McLJxJJ1P31xvHYToQZ1WTx3W2AQcCfOOu5jkBQcu/1KIn1aZDe7Y4b8Fq3CAytRggN1p+c D/BkXqTvXNJB0825KQdy/aqPvNyI= X-Received: by 2002:a19:ca10:0:b0:513:e049:3e1a with SMTP id a16-20020a19ca10000000b00513e0493e1amr1779164lfg.17.1710751704969; Mon, 18 Mar 2024 01:48:24 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240317222718.3e03edb1@namcao> In-Reply-To: <20240317222718.3e03edb1@namcao> From: Eva Kurchatova Date: Mon, 18 Mar 2024 10:48:13 +0200 Message-ID: Subject: Re: Boot hang with SiFive PLIC when routing I2C-HID level-triggered interrupts To: Nam Cao 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Mar 17, 2024 at 11:27=E2=80=AFPM Nam Cao wro= te: > > 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 whi= le > the interrupt handler is active. > > There is RT throttling to prevent RT tasks from locking up the system lik= e > 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 onc= e > 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 =3D recv_len; > msgs[n].buf =3D recv_buf; > n++; > - > - set_bit(I2C_HID_READ_PENDING, &ihid->flags); > } > > ret =3D i2c_transfer(client->adapter, msgs, n); > > - if (recv_len) > - clear_bit(I2C_HID_READ_PENDING, &ihid->flags); > - > if (ret !=3D 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 =3D dev_id; > > - if (test_bit(I2C_HID_READ_PENDING, &ihid->flags)) > - return IRQ_HANDLED; > - > i2c_hid_get_input(ihid); > > return IRQ_HANDLED; Patch applied cleanly on top of 6.7.9, builds OK (No warns, etc). This indeed fixes the hang completely. I modified RVVM to send millions of keystroke events per second, and put `reboot` as a service hook in the guest. It has been continuously rebooting without a hitch for the last 30 minutes or so (Full boot takes around 2 seconds), whereas unpatched 6.7.9 hangs almost immediately in such conditions (Reverted your patch & rebuilt to be sure). Thank you very much for this! Hope to see it upstreamed soon