From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 C022E27587E for ; Fri, 29 Aug 2025 09:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756460252; cv=none; b=sLdQ6E8sxsaCpHvVSzMJ7iDy1LANUegmU37h11CO82j6BU3Q1aAUvpesIb351++xflDwYYpOuamHi/Cjy2eQxlPG08mxMhrhYEs99NrlyxHAqyOBb1qKUROUTGCM27/Gd2XDMtvBR47EvTXeOfN6BHe5vKA2uYk46HQxF4xQq4E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756460252; c=relaxed/simple; bh=Ap6TpSpSWfu+GxU/IBIYtbECJ/gJQjgTTVqFq2X5zn4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QDh/zpXIiBmuFy/+iO30zI5Qg1aLKbsE4Fj/ZH+puZUNMMguIcGo6TuwbMIFQGChulklHlioeNp+1Yd8Qm+PpBb2Igb3tO1bdfk1Uq6pCFWNOAhTFtOXDzSSZzwe7I1fkaA+yfLgeRK//EFI828Rt9JcWC0HQXLmonLaYjBiun4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=lwUEE9KO; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lwUEE9KO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1756460250; x=1787996250; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Ap6TpSpSWfu+GxU/IBIYtbECJ/gJQjgTTVqFq2X5zn4=; b=lwUEE9KO9i2eTD9WdwPBSucbkT+6rHxmNwM71Jo9LaU4XAZF3Slon6c6 0Q6NgqBHxnLP3Q1jVLLGfYDaW9nmXJBTOUa5GVUfCQeLc4B2Oilk2uebQ Btwc+otAJvk7140Y6M/XfGJUEwDjmkPkhUU0dLMtmb8uhzRg0+RlylAcz odzDXYOp6rdd8PRRt+1DPAfo56vf5JThJtv6I6MUzge2rjsdFYBsSUVvq SbE6y1IJbWtooEHm6slTUHQFcWj2UX0vBI40ySUjrYB8kfHvECn2iD62+ SCmAuCSGPw/U8PipLBOC1QwzHQMVd7o6MTXPtR3weJmtDBVhJ3xwXsqVX w==; X-CSE-ConnectionGUID: S6PnDaRcQw+YXHZG3H7bTA== X-CSE-MsgGUID: N7DMyUF0TUSigpzZ5zRw5w== X-IronPort-AV: E=McAfee;i="6800,10657,11536"; a="62389360" X-IronPort-AV: E=Sophos;i="6.18,221,1751266800"; d="scan'208";a="62389360" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2025 02:37:30 -0700 X-CSE-ConnectionGUID: J7/Vuy9PRtaesA1hnRSVOQ== X-CSE-MsgGUID: BWMYcSp6RXqR0c2ViZZwaQ== X-ExtLoop1: 1 Received: from kuha.fi.intel.com ([10.237.72.152]) by fmviesa003.fm.intel.com with SMTP; 29 Aug 2025 02:37:24 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Fri, 29 Aug 2025 12:37:23 +0300 Date: Fri, 29 Aug 2025 12:37:23 +0300 From: Heikki Krogerus To: Sven Peter Cc: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Felipe Balbi , Janne Grunau , Alyssa Rosenzweig , Neal Gompa , Vinod Koul , Kishon Vijay Abraham I , Thinh Nguyen , Philipp Zabel , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-phy@lists.infradead.org, stable@kernel.org Subject: Re: [PATCH RFC 08/22] usb: typec: tipd: Clear interrupts first Message-ID: References: <20250821-atcphy-6-17-v1-0-172beda182b8@kernel.org> <20250821-atcphy-6-17-v1-8-172beda182b8@kernel.org> Precedence: bulk X-Mailing-List: asahi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250821-atcphy-6-17-v1-8-172beda182b8@kernel.org> On Thu, Aug 21, 2025 at 03:39:00PM +0000, Sven Peter wrote: > Right now the interrupt handler first reads all updated status registers > and only then clears the interrupts. It's possible that a duplicate > interrupt for a changed register or plug state comes in after the > interrupts have been processed but before they have been cleared: > > * plug is inserted, TPS_REG_INT_PLUG_EVENT is set > * TPS_REG_INT_EVENT1 is read > * tps6598x_handle_plug_event() has run and registered the plug > * plug is removed again, TPS_REG_INT_PLUG_EVENT is set (again) > * TPS_REG_INT_CLEAR1 is written, TPS_REG_INT_PLUG_EVENT is cleared > > We then have no plug connected and no pending interrupt but the tipd > core still thinks there is a plug. It's possible to trigger this with > e.g. a slightly broken Type-C to USB A converter. > > Fix this by first clearing the interrupts and only then reading the > updated registers. > > Fixes: 45188f27b3d0 ("usb: typec: tipd: Add support for Apple CD321X") > Fixes: 0a4c005bd171 ("usb: typec: driver for TI TPS6598x USB Power Delivery controllers") > Cc: stable@kernel.org > Signed-off-by: Sven Peter Reviewed-by: Heikki Krogerus > --- > drivers/usb/typec/tipd/core.c | 24 +++++++++++------------- > 1 file changed, 11 insertions(+), 13 deletions(-) > > diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c > index dcf141ada07812295a6f07e41d77f95f98116010..1c80296c3b273e24ceacb3feff432c4f6e6835cc 100644 > --- a/drivers/usb/typec/tipd/core.c > +++ b/drivers/usb/typec/tipd/core.c > @@ -545,24 +545,23 @@ static irqreturn_t cd321x_interrupt(int irq, void *data) > if (!event) > goto err_unlock; > > + tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event); > + > if (!tps6598x_read_status(tps, &status)) > - goto err_clear_ints; > + goto err_unlock; > > if (event & APPLE_CD_REG_INT_POWER_STATUS_UPDATE) > if (!tps6598x_read_power_status(tps)) > - goto err_clear_ints; > + goto err_unlock; > > if (event & APPLE_CD_REG_INT_DATA_STATUS_UPDATE) > if (!tps6598x_read_data_status(tps)) > - goto err_clear_ints; > + goto err_unlock; > > /* Handle plug insert or removal */ > if (event & APPLE_CD_REG_INT_PLUG_EVENT) > tps6598x_handle_plug_event(tps, status); > > -err_clear_ints: > - tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event); > - > err_unlock: > mutex_unlock(&tps->lock); > > @@ -668,25 +667,24 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data) > if (!(event1[0] | event1[1] | event2[0] | event2[1])) > goto err_unlock; > > + tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, event1, intev_len); > + tps6598x_block_write(tps, TPS_REG_INT_CLEAR2, event2, intev_len); > + > if (!tps6598x_read_status(tps, &status)) > - goto err_clear_ints; > + goto err_unlock; > > if ((event1[0] | event2[0]) & TPS_REG_INT_POWER_STATUS_UPDATE) > if (!tps6598x_read_power_status(tps)) > - goto err_clear_ints; > + goto err_unlock; > > if ((event1[0] | event2[0]) & TPS_REG_INT_DATA_STATUS_UPDATE) > if (!tps6598x_read_data_status(tps)) > - goto err_clear_ints; > + goto err_unlock; > > /* Handle plug insert or removal */ > if ((event1[0] | event2[0]) & TPS_REG_INT_PLUG_EVENT) > tps6598x_handle_plug_event(tps, status); > > -err_clear_ints: > - tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, event1, intev_len); > - tps6598x_block_write(tps, TPS_REG_INT_CLEAR2, event2, intev_len); > - > err_unlock: > mutex_unlock(&tps->lock); > > > -- > 2.34.1 > -- heikki From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B6E5DCA0FF9 for ; Fri, 29 Aug 2025 11:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hBIUiGFxiLtKR2xBrbtrJxvEm8SitRy+TFexDot2Ezs=; b=wZL3FE49ciGjX6 wNilhXE2PZr5KAYBbiup6YvDPdLFxgaglCzeYQOn1LPReiYNXfUmf69S8Vb4KiawA8PCSww0FbL9s sjtMbd0iF5YadWYcjuSb0YJY+YSSLWq4+1qBLyXaQ8oAoXS0r6eWyUNq6CzsrPo+nGRdW3WBlZBp2 oX4ygnzxTOCWxNFaczyOZBVh6F40aCOP7GsbgOmTKtB5kQA69G0imApPbAwy5ymbR9WEsmOjXJ22U Cu5qsnQIlF1WXU6mT3pEQV88MWhNzqpu9Hr2QGVHumRWWkuNsDRCKaYjTdcSsCGAAEV59VXRuOtM2 mjMvq8A+8VrcZbCY2cLw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1urxFZ-00000005Tzk-1av2; Fri, 29 Aug 2025 11:26:33 +0000 Received: from mgamail.intel.com ([198.175.65.15]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1urvY3-00000005B7X-48yj; Fri, 29 Aug 2025 09:37:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1756460252; x=1787996252; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Ap6TpSpSWfu+GxU/IBIYtbECJ/gJQjgTTVqFq2X5zn4=; b=HArccxoMtF3UGFirNhnpXQz4D33g0ZIoAp8k78P5Ndvx6l0DWyFzVlz2 zSiUtK33awI8dz6MeLXxeR3gcLgLhpe5p+ofeddO+VzkZV7BVyR4+zFMs nEJ72Fzwz67jDNUArNBFR+BtL0hJc5qsNuxRw28SMLN3aYtXDMssT4pMt 7AD7FWmtdFrxZHE3UXTAq+MFGjswjKpBBGpMYZKobiSxxd7JUAi+taKaU XPXgWaFV4sgKhI5QLIhw6o4ibN75XH6rZ1m3eLG2Mju//RIdFjr/V6PUn YuGsiRCsaJCH9ULgLqcuMpyfc4VNEofy66sL/tXeHyhMmVoyg62s+nB2I g==; X-CSE-ConnectionGUID: EDfFoEI4TNawgzWqA6tKnw== X-CSE-MsgGUID: bJWjkg/lRgOEFUF4foWe6w== X-IronPort-AV: E=McAfee;i="6800,10657,11536"; a="62389369" X-IronPort-AV: E=Sophos;i="6.18,221,1751266800"; d="scan'208";a="62389369" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2025 02:37:30 -0700 X-CSE-ConnectionGUID: J7/Vuy9PRtaesA1hnRSVOQ== X-CSE-MsgGUID: BWMYcSp6RXqR0c2ViZZwaQ== X-ExtLoop1: 1 Received: from kuha.fi.intel.com ([10.237.72.152]) by fmviesa003.fm.intel.com with SMTP; 29 Aug 2025 02:37:24 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Fri, 29 Aug 2025 12:37:23 +0300 Date: Fri, 29 Aug 2025 12:37:23 +0300 From: Heikki Krogerus To: Sven Peter Cc: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Felipe Balbi , Janne Grunau , Alyssa Rosenzweig , Neal Gompa , Vinod Koul , Kishon Vijay Abraham I , Thinh Nguyen , Philipp Zabel , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-phy@lists.infradead.org, stable@kernel.org Subject: Re: [PATCH RFC 08/22] usb: typec: tipd: Clear interrupts first Message-ID: References: <20250821-atcphy-6-17-v1-0-172beda182b8@kernel.org> <20250821-atcphy-6-17-v1-8-172beda182b8@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250821-atcphy-6-17-v1-8-172beda182b8@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250829_023732_116309_747008B8 X-CRM114-Status: GOOD ( 22.77 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org On Thu, Aug 21, 2025 at 03:39:00PM +0000, Sven Peter wrote: > Right now the interrupt handler first reads all updated status registers > and only then clears the interrupts. It's possible that a duplicate > interrupt for a changed register or plug state comes in after the > interrupts have been processed but before they have been cleared: > > * plug is inserted, TPS_REG_INT_PLUG_EVENT is set > * TPS_REG_INT_EVENT1 is read > * tps6598x_handle_plug_event() has run and registered the plug > * plug is removed again, TPS_REG_INT_PLUG_EVENT is set (again) > * TPS_REG_INT_CLEAR1 is written, TPS_REG_INT_PLUG_EVENT is cleared > > We then have no plug connected and no pending interrupt but the tipd > core still thinks there is a plug. It's possible to trigger this with > e.g. a slightly broken Type-C to USB A converter. > > Fix this by first clearing the interrupts and only then reading the > updated registers. > > Fixes: 45188f27b3d0 ("usb: typec: tipd: Add support for Apple CD321X") > Fixes: 0a4c005bd171 ("usb: typec: driver for TI TPS6598x USB Power Delivery controllers") > Cc: stable@kernel.org > Signed-off-by: Sven Peter Reviewed-by: Heikki Krogerus > --- > drivers/usb/typec/tipd/core.c | 24 +++++++++++------------- > 1 file changed, 11 insertions(+), 13 deletions(-) > > diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c > index dcf141ada07812295a6f07e41d77f95f98116010..1c80296c3b273e24ceacb3feff432c4f6e6835cc 100644 > --- a/drivers/usb/typec/tipd/core.c > +++ b/drivers/usb/typec/tipd/core.c > @@ -545,24 +545,23 @@ static irqreturn_t cd321x_interrupt(int irq, void *data) > if (!event) > goto err_unlock; > > + tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event); > + > if (!tps6598x_read_status(tps, &status)) > - goto err_clear_ints; > + goto err_unlock; > > if (event & APPLE_CD_REG_INT_POWER_STATUS_UPDATE) > if (!tps6598x_read_power_status(tps)) > - goto err_clear_ints; > + goto err_unlock; > > if (event & APPLE_CD_REG_INT_DATA_STATUS_UPDATE) > if (!tps6598x_read_data_status(tps)) > - goto err_clear_ints; > + goto err_unlock; > > /* Handle plug insert or removal */ > if (event & APPLE_CD_REG_INT_PLUG_EVENT) > tps6598x_handle_plug_event(tps, status); > > -err_clear_ints: > - tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event); > - > err_unlock: > mutex_unlock(&tps->lock); > > @@ -668,25 +667,24 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data) > if (!(event1[0] | event1[1] | event2[0] | event2[1])) > goto err_unlock; > > + tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, event1, intev_len); > + tps6598x_block_write(tps, TPS_REG_INT_CLEAR2, event2, intev_len); > + > if (!tps6598x_read_status(tps, &status)) > - goto err_clear_ints; > + goto err_unlock; > > if ((event1[0] | event2[0]) & TPS_REG_INT_POWER_STATUS_UPDATE) > if (!tps6598x_read_power_status(tps)) > - goto err_clear_ints; > + goto err_unlock; > > if ((event1[0] | event2[0]) & TPS_REG_INT_DATA_STATUS_UPDATE) > if (!tps6598x_read_data_status(tps)) > - goto err_clear_ints; > + goto err_unlock; > > /* Handle plug insert or removal */ > if ((event1[0] | event2[0]) & TPS_REG_INT_PLUG_EVENT) > tps6598x_handle_plug_event(tps, status); > > -err_clear_ints: > - tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, event1, intev_len); > - tps6598x_block_write(tps, TPS_REG_INT_CLEAR2, event2, intev_len); > - > err_unlock: > mutex_unlock(&tps->lock); > > > -- > 2.34.1 > -- heikki -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy