From patchwork Wed Oct 19 08:22:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp203341wrs; Wed, 19 Oct 2022 01:42:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Hw7j+z9Md/qbG9nBO95AA6x2o5Cjj0oef4oLm/KLK6fUQNCQ0neuIGChLhknzJr+ry42i X-Received: by 2002:a05:6402:170f:b0:458:9653:6466 with SMTP id y15-20020a056402170f00b0045896536466mr6376096edu.181.1666168972828; Wed, 19 Oct 2022 01:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666168972; cv=none; d=google.com; s=arc-20160816; b=fvZvGPiItqCiCNnXC01rmzTsGxieb1e+QLMzTfmEZcWpV3q/QK7pH6KnC5VRyNsP0F maNt6pBC1klPX8pMdVIYBujzNf1CG/13gWIZ2SAmAjWJ7CCAnFeTc8sS0QveX57FjsYu YtX8RuRsUaAYCIW76X5TeeKYnGR8gpeze+LchK19hrE6kiV5bRdGPcy1AtLxlJ/hfLkU 0zlQbyMDgq4XB5Nz9iVM9mp8tkaN+ZHxW9Vl8Zc3UpmycgGCUky2YwYMfW/zLdJoBiTl 2XuganqqQ2qAWtn9kwE0xtpWDUngAnUWVQdElFxmqW3SVQQloseNSCNOrTaLzRsWu68y CL1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SC1dvavRum/rZ+XA63jr5Pq4lYHqhje7TzAd/C62WBM=; b=ySB1lf84eDYRqZSoGngeCq7P13DP0W41ivYGItSMypTx6OrNiJxogo9d1CpUmr7PRy Pac5CaX7W76H4p8I4+oroxEmzYzfA3QRkT5pxBBp0LSnEftLLQDz9Sg1LvmKY5NfoQsj noY2YgbRj6W6awDZATSH76+y3oFQfzZ7BohboD3QAMk2duxgKZvF8LQCg0J4hyhOACdX wh9oYqm8D+snoQ11B0WviC1JvnwDXQeH3sycujgCrCxx4CEn8hkTxb5WD9TMYhCvLKrR MAH1wMOYkqAT6l/O58ehzpdgxrX/pefMPWJXcplNZwiWlurfdzEmmE8ouV5cWdFIiM27 t8fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OQ6HLMCY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg37-20020a170907972500b00791a37e665esi2702605ejc.10.2022.10.19.01.42.28; Wed, 19 Oct 2022 01:42:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OQ6HLMCY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230420AbiJSImF (ORCPT + 99 others); Wed, 19 Oct 2022 04:42:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230399AbiJSIkq (ORCPT ); Wed, 19 Oct 2022 04:40:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05B3F80BE0; Wed, 19 Oct 2022 01:39:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8D4B8B822BE; Wed, 19 Oct 2022 08:39:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E64CAC433D7; Wed, 19 Oct 2022 08:39:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168744; bh=HHK5F+bVk5ccs/l91De+g7lQ4jXHY0mt5/MgFWT9rdQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OQ6HLMCYEygX4CdoxKB2F1G4qJHJu/aQ8uK6jqMO1pFBxU7V8PpSh9hO4ZAKrU6es Afv4n1aa8+N/gFbK0W5f2LJAdy/d0ogvzFgy11XQAbacMENfEXFLV9fC+K8A0Pcd2z mDbXVtjmkTU1gzJNWlc6xfyDJqB3BNHxbzP95ExY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Samuel Clark , Jarkko Nikula , Andy Shevchenko , Wolfram Sang Subject: [PATCH 6.0 040/862] i2c: designware: Fix handling of real but unexpected device interrupts Date: Wed, 19 Oct 2022 10:22:07 +0200 Message-Id: <20221019083251.767513800@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747104797300676004?= X-GMAIL-MSGID: =?utf-8?q?1747104797300676004?= From: Jarkko Nikula commit 301c8f5c32c8fb79c67539bc23972dc3ef48024c upstream. Commit c7b79a752871 ("mfd: intel-lpss: Add Intel Alder Lake PCH-S PCI IDs") caused a regression on certain Gigabyte motherboards for Intel Alder Lake-S where system crashes to NULL pointer dereference in i2c_dw_xfer_msg() when system resumes from S3 sleep state ("deep"). I was able to debug the issue on Gigabyte Z690 AORUS ELITE and made following notes: - Issue happens when resuming from S3 but not when resuming from "s2idle" - PCI device 00:15.0 == i2c_designware.0 is already in D0 state when system enters into pci_pm_resume_noirq() while all other i2c_designware PCI devices are in D3. Devices were runtime suspended and in D3 prior entering into suspend - Interrupt comes after pci_pm_resume_noirq() when device interrupts are re-enabled - According to register dump the interrupt really comes from the i2c_designware.0. Controller is enabled, I2C target address register points to a one detectable I2C device address 0x60 and the DW_IC_RAW_INTR_STAT register START_DET, STOP_DET, ACTIVITY and TX_EMPTY bits are set indicating completed I2C transaction. My guess is that the firmware uses this controller to communicate with an on-board I2C device during resume but does not disable the controller before giving control to an operating system. I was told the UEFI update fixes this but never the less it revealed the driver is not ready to handle TX_EMPTY (or RX_FULL) interrupt when device is supposed to be idle and state variables are not set (especially the dev->msgs pointer which may point to NULL or stale old data). Introduce a new software status flag STATUS_ACTIVE indicating when the controller is active in driver point of view. Now treat all interrupts that occur when is not set as unexpected and mask all interrupts from the controller. Fixes: c7b79a752871 ("mfd: intel-lpss: Add Intel Alder Lake PCH-S PCI IDs") Reported-by: Samuel Clark Link: https://bugzilla.kernel.org/show_bug.cgi?id=215907 Cc: stable@vger.kernel.org # v5.12+ Signed-off-by: Jarkko Nikula Reviewed-by: Andy Shevchenko Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/busses/i2c-designware-core.h | 7 +++++-- drivers/i2c/busses/i2c-designware-master.c | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h @@ -126,8 +126,9 @@ * status codes */ #define STATUS_IDLE 0x0 -#define STATUS_WRITE_IN_PROGRESS 0x1 -#define STATUS_READ_IN_PROGRESS 0x2 +#define STATUS_ACTIVE 0x1 +#define STATUS_WRITE_IN_PROGRESS 0x2 +#define STATUS_READ_IN_PROGRESS 0x4 /* * operation modes @@ -334,12 +335,14 @@ void i2c_dw_disable_int(struct dw_i2c_de static inline void __i2c_dw_enable(struct dw_i2c_dev *dev) { + dev->status |= STATUS_ACTIVE; regmap_write(dev->map, DW_IC_ENABLE, 1); } static inline void __i2c_dw_disable_nowait(struct dw_i2c_dev *dev) { regmap_write(dev->map, DW_IC_ENABLE, 0); + dev->status &= ~STATUS_ACTIVE; } void __i2c_dw_disable(struct dw_i2c_dev *dev); --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c @@ -716,6 +716,19 @@ static int i2c_dw_irq_handler_master(str u32 stat; stat = i2c_dw_read_clear_intrbits(dev); + + if (!(dev->status & STATUS_ACTIVE)) { + /* + * Unexpected interrupt in driver point of view. State + * variables are either unset or stale so acknowledge and + * disable interrupts for suppressing further interrupts if + * interrupt really came from this HW (E.g. firmware has left + * the HW active). + */ + regmap_write(dev->map, DW_IC_INTR_MASK, 0); + return 0; + } + if (stat & DW_IC_INTR_TX_ABRT) { dev->cmd_err |= DW_IC_ERR_TX_ABRT; dev->status = STATUS_IDLE;