From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 91B0C43CEEB for ; Fri, 15 May 2026 09:47:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778838475; cv=none; b=I2mGu64QBrdEpTRk0h78EK1SQCF4iI9PtoRTkkWgR5AHhAMl6o9b/pvohDBHZ2tWkrWk3DlmjZBHsUD4TNNazhHsibKRcKG8vOcClA7CRIoxBwtUjAkKX57xy6LU9Y15Yeynn3JMfGUJS1uj8sKN3gsDsRtewq7DOHw00RCvoW8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778838475; c=relaxed/simple; bh=YsVsPmo72PQUOPJu8nLHlVsqbrOYIiU0ZJsMqkQT5cw=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UqB7uoRMdou6ei7yTUrjbfirMsYCM/QC4VeubCb7lmZM84a5laCmBCAQA+dH9Ewkfxr+QBVFUPRaBGMBT0XYeYFB4GoT3bLwfxnVhsMAZPeS/843JSzt003vdquJ/Trq5RKCfOGrlTmy/40AAMu4snsHdLalBi0Vbk/FDHHBZXA= 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=FF/EhAus; arc=none smtp.client-ip=209.85.128.45 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FF/EhAus" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-48984d29fe3so96005205e9.0 for ; Fri, 15 May 2026 02:47:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778838472; x=1779443272; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=r/e37VgLdpUmdJ/sT4E0Yd2dWN5tYEQahe7Aa4DMknc=; b=FF/EhAusbfNX+WLjmvp0pNGZzXUwJi/D/svXJaGzag5n9QC/6Btq65WszrmpgHP3Ci 0Vi7bpinZTPoleXlWpLIa12LBLyAfu1Ggj4Q1jjExiXCZP58GlsRr9F/v2J+HXHagQ0I x5E+lvjZ9gCa4fL2AHs2SzXBvC+2K7JSsVOWQvTZSeakONRdhuH1SdyEshCzRVb5Onxq 3DNCbnpl3HE/cE6Uv8AHRnYGrShOcCTt/eukhNqtjm6lBzUdKeFOa83M0szbx1fxG1R7 +T9A3PwzNzEecAcaQHOZu4YYYvJ+Twkstu+M7Kj6Mh71sHKMrsPSCqIOBoxqfebv55XZ 7RUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778838472; x=1779443272; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=r/e37VgLdpUmdJ/sT4E0Yd2dWN5tYEQahe7Aa4DMknc=; b=eg841li6CsR1+iFRjfE+dMGtL9T76VgpuDxz6prABAImAHijH6ZM6RVIH2TfwWJSBm qqBJWJBlUiN6CCu3nxilZRCdS27waMmXcLT3LoP92cWX0S32kVn1ZdzYtqiaZ4SmDEqZ wwyMCNVcWnpMrBB94ZfTjK+fs3uCVdfxkooofpj3jKt4wgXURmPNmIxTmfRzEiHhf7ro cs7O7ZHz2iG/IRzszq0JR3WaOM3RbYC5GNQ9cs5VeKZyNYqaa66AVMOFCSr624uIj+wT JBJxKGY+9CfZy0ZUh4F/wlc54GpAV0Cd0VAD0GevbpqnJDHstvlbg9MgOm8okoKqjEU6 WfTw== X-Forwarded-Encrypted: i=1; AFNElJ9ByFvpVZupypkdxR1FoXo0oSeYxNPiWcOiTK2iAtGBMvajxMzhJT7MKSmpcUSxdFIjeLmzEY0=@vger.kernel.org X-Gm-Message-State: AOJu0YyC8DQVN8Kq6DYyvUF7rxXiUNisgHGFI6nEtziWCzXkOEMmL9z1 1yNXRIdR8qeZ3qc7yXak+CNYESbPkgiSFuD69amaMhjJvK5xXdVSh8KU X-Gm-Gg: Acq92OGbjqbdE+u3YcRpkfB9Fi9iMNc1Ge6Krp2MtgTK7lfjFKdmSTIZr580RAoe3Tv xJkT68TMorW8WaIDfCN1d2znHgjqw+LK/ODQPdf0+TVRMPaVyhe3dwHa5v67cVkj9lCaeUSLaew BraPxiD9crucjYrRW7EewMK3mMl2ZQYFS3TUZ4ZWKGgfAUc8i93O9h2cDxso8ZUhtrb93VHKQTq rFtsRos2hcsS6vosWI05UeQHAYbKg+GbVg+6MSYKyXxNV/IFUlXXn82KPmZ1b9HmB1QnfS4VbK7 6nSRHgb0SlpWzn4ilTOCZefiFwzaScBFrZ9M7HqYTif7X7bjlIM9L/RsN5vpdIKDIUC1hOi9w2L MZ3ju5iyECD0kMvehNcWhcuv7nV10NqgykZnc8nKuAC/tn0JA9JVUQQrg2USLVns5YCxwDILSPp oB8J4f8oX36Q9Y93ycrbgYAijuNbe8gjw8yfLlCSHacRirazo9YYGEEZbD/FwJ X-Received: by 2002:a05:600c:a4f:b0:48f:e230:2a24 with SMTP id 5b1f17b1804b1-48fe66204e8mr41076455e9.31.1778838471669; Fri, 15 May 2026 02:47:51 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48fe5cab882sm54024555e9.13.2026.05.15.02.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 02:47:51 -0700 (PDT) Date: Fri, 15 May 2026 10:47:49 +0100 From: David Laight To: Pavel Machek Cc: Claudiu Beznea , yoshihiro.shimoda.uh@renesas.com, vkoul@kernel.org, neil.armstrong@linaro.org, geert+renesas@glider.be, magnus.damm@gmail.com, prabhakar.mahadev-lad.rj@bp.renesas.com, linux-renesas-soc@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org, Nobuhiro Iwamatsu Subject: Re: [PATCH] phy: renesas: rcar-gen3-usb2: Avoid long delay in atomic context Message-ID: <20260515104749.24135f22@pumpkin> In-Reply-To: References: <20260514111300.2152386-1-claudiu.beznea@kernel.org> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 14 May 2026 23:18:44 +0200 Pavel Machek wrote: > Hi! > > > From: Claudiu Beznea > > > > The OTG PHY initialization sequence needs to wait for 20 ms at a specific > > step, as described in commit 72c0339c115b ("phy: renesas: > > rcar-gen3-usb2: follow the hardware manual procedure"). > > > > Commit 55a387ebb921 ("phy: renesas: rcar-gen3-usb2: Lock around hardware > > registers and driver data") tried to address various problems in the > > rcar-gen3-usb2 driver and converted the mutex protecting HW register > > accesses to a spin lock, leaving, however, a long delay in the critical > > section protected by the spin lock. This may become a problem, > > especially on RT kernels. > > > > To address this, release the spin lock before sleeping for 20 ms as > > required by the HW manual and reacquire it afterwards. To avoid other > > threads entering the critical section and configuring the HW while the > > software is waiting for the OTG initialization to complete, introduce the > > otg_initializing variable alongside the otg_init_done completion. Any > > other thread trying to configure the HW while the OTG PHY initialization > > is in progress waits for the completion instead of immediately returning > > errors to PHY users. The IRQs were also disabled while waiting for the OTG > > PHY initialization to complete, as the interrupt handler may also apply HW > > settings. > > Just... there has to be a better way. > > > +++ b/drivers/phy/renesas/phy-rcar-gen3-usb2.c > > +static int rcar_gen3_phy_wait_otg_init(struct rcar_gen3_chan *channel, > > + unsigned long *flags) > > +{ > > + unsigned long timeout = msecs_to_jiffies(25); > > + unsigned long ret = 1; > > + > > + lockdep_assert_held(&channel->lock); > > + > > + /* > > + * The OTG can be initialized only once and needs to release the lock > > + * and wait for 20 ms due to hardware constraints. Wait for the OTG PHY > > + * initialization to complete if another PHY executes configuration > > + * code while the OTG PHY is waiting. This avoids returning failures to > > + * PHY users. > > + */ > > + if (READ_ONCE(channel->otg_initializing)) { > > + spin_unlock_irqrestore(&channel->lock, *flags); > > This is not nice, passing flags between functions like this is a red flag. It would be better to just inline the code. And I'd guess you need to redo the initial tests after re-acquiring the lock? Or even need to do a state change/reference count before releasing the lock to stop other threads 'doing anything nasty'. -- David > > You are only accessing otg_initializing under the spinlock. That means > that READ_ONCE is reduntant. > > But AFAICT spinlock is only held over this function to protect > channel->otg_initializing access. I suspect correct answer here is > getting rid of spinlock over this function, and using > test_bit(BIT_INITIALIZING, ...) or something similar. > > Best regards, > Pavel >