From patchwork Thu Jul 6 18:29:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 116818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2761182vqx; Thu, 6 Jul 2023 11:41:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlH25MS+BtstJIKf8MFCLw5KTda+/TxzZDRfVeFRB4CwbB5LtgjXT2SxlXzg1sEYpvW+iSgA X-Received: by 2002:a17:903:32ce:b0:1b8:b4e5:15c2 with SMTP id i14-20020a17090332ce00b001b8b4e515c2mr2899348plr.22.1688668908633; Thu, 06 Jul 2023 11:41:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688668908; cv=none; d=google.com; s=arc-20160816; b=B3QbqLYtAppwFQntAn9BlU/MzrekgrD+CV3UYBQBVbChdM5cQFx3gUmDom+Lf4uuqv 3XpqOOQyjvgmhGQb7pNxCEHjWJ8lhaLWMg2s7MVnCxMPluda0dDDSXSgfd8Gl0uObW36 J6D2nmU2WVvWK/UJ9gpG9DfVbBw+xb9BuHMolGpGlZ23ZBAaG9j3R34Ye12NPNL9pTxe OZwn2CRCiMJsyRkeeCn6c/hzWQKTHxEaZlujfENIn0R1WPKngNma42VFUxyJrUsMo+Mn HwItbjFU04vGqUduRfrz8dphsG3edcOf9Ni+S3TKUKBdPq2cPggqDgkp9cDQoII3Tgwz 0hNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=D0cu2lwsj8lZsvKlL7iIsn2njGLUHuLcymfkJT5BpYk=; fh=m13O91RIJpWLA1E3t3OF4PWkN6piDivoH4+ccEA0NUM=; b=ndOzXLalO/mXVu3gLLfefj5ZNd65zBpUNfvsbbSOXqNIB6u4P0vLAPG5OY+AepBGQS b3t5b2G/Yw1vW05NEneC0dz3gv9c55TQCTP3npUiV+1Sn4EslHku6/fq6OfE6haYV+gk coPLtoANoPY8dV3LgFcS6vpKTas8OoGgm3eyOU8s6kAD9b2exwmUt8X4SHXL0nq5BssA qMDspEBePdP8Xe0e/nQmQdphDq7k8JgAxLj+zxvRCbnYxeyByTegiSuKaP9uErET33I/ 4Umbue66Pa9xhUFcRhg4gI2GgrmC+arjyC/j7XITnx8oNwsywgNSAa81u+27wm/g/qwk +srw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=YbNtEpUA; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a170902680800b001b9075dbda2si467851plk.199.2023.07.06.11.41.31; Thu, 06 Jul 2023 11:41:48 -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=@broadcom.com header.s=google header.b=YbNtEpUA; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232160AbjGFS3n (ORCPT + 99 others); Thu, 6 Jul 2023 14:29:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjGFS3h (ORCPT ); Thu, 6 Jul 2023 14:29:37 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B27A31BFC for ; Thu, 6 Jul 2023 11:29:36 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-666e3b15370so690112b3a.0 for ; Thu, 06 Jul 2023 11:29:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1688668176; x=1691260176; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=D0cu2lwsj8lZsvKlL7iIsn2njGLUHuLcymfkJT5BpYk=; b=YbNtEpUANR2TRTbcsFQ7k0zPPS9nd8WrCAYB1M6s13r0Go1H2SayophwDMv+oew+1Y ps5o7ePa6db7TtfhyMgimps8sjiL0xyNbFCU0EFi0ef+8tCol95GGFi4Ym2hUcgaJtMS b5mTLBKpOAuaLoda+kMmuifxBnoelM/HlUPss= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688668176; x=1691260176; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=D0cu2lwsj8lZsvKlL7iIsn2njGLUHuLcymfkJT5BpYk=; b=NbNxPvri25JhoL8WMKhIxNx7GJiGZZ0wdyyJN/fPf49CfbQZRYjmpK9fVJ5kJ3VDsP +siDbNakcqyI/x5S6We/BRyXseobBakd53hIQwxNL3BaNPTYPpBIOEo/7P5Yu1ttQH/Q LZI0FgGQp7pok4ILf9wPUKTWafR3akY4gJs/mkRH+nuUZtxlmfpkkzJihlVAhQJtCr+r tIk08cugTZQ9DoImr5BH+YnY7guNespsn1O/ds/6taNUxFxRjlxgS6EllF2j/pnPNvB4 2E+tdMqS0GJYwN3lOg/yIHpU1Q1jM+lgT3fk4/gnXmef6Joe1h/Vvqq02rSqDjMeKWZ2 ITXw== X-Gm-Message-State: ABy/qLbJlzgGv7JNNbLPB6SP+w07OFCG0TOsJ587avdf9gy1Pjp3gk3r 09zWx5p/wIEhVzfTrKIBiw173g== X-Received: by 2002:a05:6a00:139b:b0:679:bc89:e5b with SMTP id t27-20020a056a00139b00b00679bc890e5bmr2741416pfg.19.1688668176150; Thu, 06 Jul 2023 11:29:36 -0700 (PDT) Received: from ubuntu-22.localdomain ([192.19.222.250]) by smtp.gmail.com with ESMTPSA id y13-20020aa7804d000000b006826c9e4397sm1580871pfm.48.2023.07.06.11.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 11:29:35 -0700 (PDT) From: William Zhang To: Broadcom Kernel List , Linux MTD List Cc: f.fainelli@gmail.com, rafal@milecki.pl, kursad.oney@broadcom.com, joel.peshkin@broadcom.com, computersforpeace@gmail.com, anand.gore@broadcom.com, dregan@mail.com, kamal.dasu@broadcom.com, tomer.yacoby@broadcom.com, dan.beygelman@broadcom.com, William Zhang , Florian Fainelli , stable@vger.kernel.org, Miquel Raynal , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Richard Weinberger , Kamal Dasu Subject: [PATCH v4 3/5] mtd: rawnand: brcmnand: Fix crash during the panic_write Date: Thu, 6 Jul 2023 11:29:07 -0700 Message-Id: <20230706182909.79151-4-william.zhang@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706182909.79151-1-william.zhang@broadcom.com> References: <20230706182909.79151-1-william.zhang@broadcom.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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?1770697689657717195?= X-GMAIL-MSGID: =?utf-8?q?1770697689657717195?= When executing a NAND command within the panic write path, wait for any pending command instead of calling BUG_ON to avoid crashing while already crashing. Fixes: 27c5b17cd1b1 ("mtd: nand: add NAND driver "library" for Broadcom STB NAND controller") Signed-off-by: William Zhang Reviewed-by: Florian Fainelli Reviewed-by: Kursad Oney Reviewed-by: Kamal Dasu Cc: stable@vger.kernel.org --- Changes in v4: - Update commit message - Add cc stable tag Changes in v3: None Changes in v2: None drivers/mtd/nand/raw/brcmnand/brcmnand.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 9a373a10304d..b2c6396060db 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -1608,7 +1608,17 @@ static void brcmnand_send_cmd(struct brcmnand_host *host, int cmd) dev_dbg(ctrl->dev, "send native cmd %d addr 0x%llx\n", cmd, cmd_addr); - BUG_ON(ctrl->cmd_pending != 0); + /* + * If we came here through _panic_write and there is a pending + * command, try to wait for it. If it times out, rather than + * hitting BUG_ON, just return so we don't crash while crashing. + */ + if (oops_in_progress) { + if (ctrl->cmd_pending && + bcmnand_ctrl_poll_status(ctrl, NAND_CTRL_RDY, NAND_CTRL_RDY, 0)) + return; + } else + BUG_ON(ctrl->cmd_pending != 0); ctrl->cmd_pending = cmd; ret = bcmnand_ctrl_poll_status(ctrl, NAND_CTRL_RDY, NAND_CTRL_RDY, 0);