Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp750826lqb; Fri, 15 Mar 2024 05:45:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX5MIm1qSCng/oiOcwyW1r8CzIA/2uh38ViYbrWXXqQsu2QUYK4j3UiuJ6Iop1CQwakC4jgH13EffsbjwBRkR4AxDL+lO887xMO3x1JFA== X-Google-Smtp-Source: AGHT+IHOJRPTEmLVKuzKaedrgIbRVRW/XJk5bdl2H32ttatqcBFRIwaeweKu53EevWjzb3WxusVj X-Received: by 2002:a17:906:168a:b0:a46:9985:b264 with SMTP id s10-20020a170906168a00b00a469985b264mr280479ejd.62.1710506756983; Fri, 15 Mar 2024 05:45:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710506756; cv=pass; d=google.com; s=arc-20160816; b=NORSZDQHhX3jIriryOKGLQOnQMO6yw7CGvzEUW6t/mOFJ7RwPfekH6hGVQKVoQre4/ 7AqrDAFmPr/Z7losEQjhJco3a2QJrD7pap9BUIxGfNxZK3peWy6cQi0mLZOlNxb/4Icj gdklhiTX4wIu1rEs5JgUk/0Ppq/5gRftFR5Anp+GeuiYhQPd230YeTMawix5WwJSHcFB IrOF/fFdCW/h4Xzc9JzCULp08gJGBiOAXsQ6mdpRLGcdzrfGJcuNFYwB6w3rQxqOhT+8 f5fa8HjNhp3M6NAuJ22itP4zUiIG3sdxBPEQ6elj1HjoFIIJhT2AUv/sNv2zglGVx5S0 3PCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=1MwgKJv8d8Iv8GGN8JB0og0SOOXe2CZVDZDaNEEyP3M=; fh=+GloMyzIiqaisMqEA9rPHwg6uVVsAB7v3Fehs4atYMM=; b=EjARilLjMIqB0F/RtN0njB2Ch88E9uAZUkJcP3tPLHKxj3jZe6MBCjVPPbuN+axX+9 2aOtqFKGLQfeqPv+guPoXnR0YCX4IzA7kktNw+mGM0X0CSUnEW34yJGpMX7DArzpezRc 8FbybjTM7E0JgdOxFH/154cTN8ziThI+Ppf7hNaa5ycyCtObQ1/XBmhhZrhDK3mS6fns vLtJArtRCUUd4xcB7yUJSPjCWE6yFsPH0kGccob5+NavVMfI74SYwg0u3wQzol94KDfL MdLn32bH3fefR+5hMjCxG16gmPdJ4UV4uET08L3reo7UH7RLSHfrjZ1CKYgInmCGs/v5 NWTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dUam8kjt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-104407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l22-20020a170906795600b00a461537c354si1788498ejo.875.2024.03.15.05.45.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 05:45:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dUam8kjt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-104407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 7CED61F21AA5 for ; Fri, 15 Mar 2024 12:45:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A9E724B26; Fri, 15 Mar 2024 12:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dUam8kjt" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7355E22F1D; Fri, 15 Mar 2024 12:45:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710506748; cv=none; b=nHSyDUh6JVE20brHlvIoMpOVRNWpa6k6RQ2GPmtoRVc73K8FF1exOqPAV5k/pxn0yAPffT/ozB+fWaA4yVLLRuB0rohTzxi8uTKAUUnMWUjCvrHGcuO9JxUMFY2Q5Gl5s0rJYrLU6zxRWeioZyiHELKgRvIqeIw2y/B/16a2xHo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710506748; c=relaxed/simple; bh=3ebn+xDEz/kApOIo2PqJQ1LGPDZrqrbinFBG2nhEO4k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CYk9ub18uhWFbglA8zyJjoBt+CnIrk21P9nfUIgPNjrzz16UQsJwXMbfULDjxqQdJrcozzttNmcFpOn5jkT0i1ORmA73PQqRts5EOv2oJPt6IRBPL5Kvm933BxlfUdydHn/tjCh8YkuF0Kmjqadsv3nOCfrHfZasiNYg8dxp6Mk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dUam8kjt; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D2E7C433F1; Fri, 15 Mar 2024 12:45:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710506747; bh=3ebn+xDEz/kApOIo2PqJQ1LGPDZrqrbinFBG2nhEO4k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dUam8kjtL+Vr1KbYvq8Lhu9Omo2sl/D3fUYP9PcLJcP7eq1UGIDOxr6MAtYi+PwOz IGv5c2PoMrcfFgoRMgR1xYzRjMNpJBJvvYQ55j8XmGZmt+48aE1gdysQI3IoEtLEp3 Z8XXqS+YBNjysOPyK7DC2wl79JKXhZONFe6A2WvpYz2etlJcuvyhBu0jAPJEDHNVlh T0O3XrSPnRoFBdddKHTdpy+UOzNVQO/xGHQcDry/wax2NQJqEo5SiMBg/93/aVitJO roUHUNv6vFStMyLt+lMao+fUAk0RVs7J8ID287nnibrhBOz22Dk6Ub9ziu4atKGugF 46uOjQ3nS01Fg== Date: Fri, 15 Mar 2024 12:45:44 +0000 From: Conor Dooley To: Eva Kurchatova Cc: linux-riscv , bugs@lists.linux.dev, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Samuel Holland Subject: Re: Boot hang with SiFive PLIC when routing I2C-HID level-triggered interrupts Message-ID: <20240315-iguana-glacier-6dc38774fb65@spud> References: <20240314-sublevel-jargon-4234df3fa614@spud> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="cE8m9TG3tVI3eCoQ" Content-Disposition: inline In-Reply-To: --cE8m9TG3tVI3eCoQ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Mar 15, 2024 at 05:33:06AM +0200, Eva Kurchatova wrote: > On Thu, Mar 14, 2024 at 11:46=E2=80=AFPM Conor Dooley = wrote: > > This immediately seemed odd to me, but I have no reason to disbelieve > > you, given you say this was discovered in RVVM which is an emulator and > > you should know whether or not registers are accessed. > > The very first action taken by the ocores i2c controller driver when it > > gets an interrupt though is to read a register: > > > > u8 stat =3D oc_getreg(i2c, OCI2C_STATUS); > > > > I would expect that this handler would be called, and therefore you'd > > see the register read, had the probe function of that driver run to > > completion. I'd also expect that the interrupt would not even be > > unmasked if that probe function had failed. > > In your case though, you can see that the interrupt is not masked, > > since it is being raised and handled repeatedly by the PLIC driver. > > Has the i2c controller driver probed in the period of boot that you say > > this problem manifests? >=20 > There is not a single problem with the ocores I2C driver. I2C-HID device > itself has a separate IRQ line which is level-triggered. Ah, I see. I am still unsure as to how that interrupt is handled by the PLIC driver before the user for it (i2c-hid) requests it. > This is to signal the host that there is input available without polling, > since I2C is a master-driven bus with no "data available" notifications. > So in reality the I2C-HID driver should handle the interrupt; Then it > uses the I2C controller to access I2C-HID slave registers (via I2C) to > read the incoming HID input report. I2C controller interrupts are unrelat= ed; > it's the link between the HID device and the host and it doesn't seem > to be touched at all inside the I2C-HID IRQ handler (So it's just a pair > of Claim/Complete actions). I2C ocores interrupts are not generated > (and shouldn't) at that point, because no I2C transfer was initiated at a= ll. >=20 > There is a way to make I2C-HID device edge-triggered, in RVVM > emulation code, but it's not actually spec compliant. It gets rid of the > hang too; However the same Claim/Complete actions without any > handling inside the IRQ handler are observed at least once, which > technically means a lost interrupt (Pressing a key somewhere early in > boot thus doesn't propagate the keypress to the guest until you press > another key later, after which both HID reports are read), so it's not > a way how I'd like to mitigate this in the emulator code. > I, and another developer from Haiku OS team (X512), are almost sure > this is a kernel bug related to level triggered IRQs with PLIC or a > specific incompatibility of PLIC/I2C-HID (Not the ocores I2C controller). >=20 > This hang is not reproducible with a Haiku OS guest in any way and > most of the drivers involved seem to be FreeBSD based or written by > X512 (Specifically the PLIC and I2C-HID drivers are). This person also > believes that this Claim/Complete behavior on PLIC side without any > other actions made in between is erroneous kernel behavior too. Maybe it is, I've re-added Thomas and Samuel to CC as I said before that they know much more than I about the code in question. I was just pointing out that the behaviour you were seeing is inconsistent with what I have come across myself for interrupts that have not had a user request them. > I am open to discussions what specifically could be wrong with the VM > since one of my end goals is to just make HID devices work without > issues there; However if a simple 2-line patch (which I'm not entirely > sure of it's implications) that removes return path at line 223 in PLIC > driver resolves the issue (I kept a guest in a 24 hr reboot loop whilst > spamming fake I2C-HID input and no hang was observed), then it does > lead me to belief that it's at least not some blatant emulation issue. >=20 > I came here to collect some kernel devs opinions since we are > debugging this for some 2 weeks already. Your initial understanding > that something is wrong with ocores I2C controller is not what I meant, > sorry for lacking in my explanation. >=20 > >Are interrupts unmasked by default on RVVM? >=20 > By default all PLIC ENABLE registers are set to zero. All PRIO, > THRESHOLD registers are zero on reset. So all PLIC state is > simply zeroed on reset, as can be seen here: > https://github.com/LekKit/RVVM/blob/f81df57a2af77cbae25fd3cc65d07106d9505= e23/src/devices/plic.c#L265 >=20 > > Have you checked that this actually affects any actual hardware? >=20 > I might very soon if no one has immediate ideas what is wrong; > Problem is that I don't have hardware that exposes PLIC IRQ lines to > the user. It might be possible to use some FPGA or at least reproduce > in other simulators. >=20 --cE8m9TG3tVI3eCoQ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHQEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCZfRC+AAKCRB4tDGHoIJi 0sZQAQCs8x+fdD7uyy/sSkILvwAQeA/OzbkXq4IeDm/4oaopLQD4p7m8YJuT6z7U 4VGyV9mSNWX9O/PzZB7e5M5+Zqy1Bw== =1BNN -----END PGP SIGNATURE----- --cE8m9TG3tVI3eCoQ--