From patchwork Thu May 4 16:51:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 98547 Delivered-To: patch@linaro.org Received: by 10.140.89.200 with SMTP id v66csp698232qgd; Thu, 4 May 2017 09:52:29 -0700 (PDT) X-Received: by 10.84.138.193 with SMTP id 59mr58475637plp.184.1493916749304; Thu, 04 May 2017 09:52:29 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5si2533622pgk.367.2017.05.04.09.52.29; Thu, 04 May 2017 09:52:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755918AbdEDQw2 (ORCPT + 6 others); Thu, 4 May 2017 12:52:28 -0400 Received: from mail-pg0-f53.google.com ([74.125.83.53]:32988 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755533AbdEDQw1 (ORCPT ); Thu, 4 May 2017 12:52:27 -0400 Received: by mail-pg0-f53.google.com with SMTP id y4so11518569pge.0 for ; Thu, 04 May 2017 09:52:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TwEVcVjLgxwKMQvde8lRV4hMbU+uepILzS+eLsAbWKE=; b=TWaA2z2/4mQMhO2R1aTIphemw+Zlh0SC6/AZRARJYAWwu4+k0LpKcmIH830i84t1qK yqOKrOrKuZ0myS4fgzTUjsMcorf3hmpISZPSRnoHmQhhomEtv+j7c/yO5y68Gy33Hrhb 2ciVhwujCFU96P+ZW5fm0dW0tvW5PN56o7qrA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TwEVcVjLgxwKMQvde8lRV4hMbU+uepILzS+eLsAbWKE=; b=Ztvaqtc0gHZQXPAm0MfbUcwhu7k1+9aXXxuk88m1vzdKzgUPzXbREGvAjUNinLfSkW RN1jbwdyNxFKAQJUY5RaACRutL4MrkLrLpSIyxsRpfqyI1c9XZYuI8Ha6on9bRMWDvCf UXbXGclgAFpR6QbWX6VO8A9IbxjijZ76zkHVv3k5y4UNIyoB+O1Piyo5xT92e61pGzfV SzOtckbS9r5MngXfrWI1iZfPeyBx5v6aKa+Va6EKPhh9c2oi5A7YfjCGdfzJIUNr26Pk mO1HI6OjKtlLBrEQAbOiqjtLnh/ra7MnXDVb2Tb0glZbRL5hC8OlGx1nwkhJMdnNbp0w pQLw== X-Gm-Message-State: AN3rC/5Ds37J0SWch1Y8GSZX/pdW6Cqaxfpzvg6ralQhrr73qUsMsD1p f90H6+mJunesVRuq X-Received: by 10.98.24.213 with SMTP id 204mr11487840pfy.237.1493916746956; Thu, 04 May 2017 09:52:26 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id w85sm4946121pfk.62.2017.05.04.09.52.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 May 2017 09:52:26 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: "Matthew R. Ochs" , "Martin K . Petersen" , Sumit Semwal Subject: [PATCH for-4.4 2/4] scsi: cxlflash: Fix to avoid EEH and host reset collisions Date: Thu, 4 May 2017 22:21:58 +0530 Message-Id: <1493916720-8819-3-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1493916720-8819-1-git-send-email-sumit.semwal@linaro.org> References: <1493916720-8819-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: "Matthew R. Ochs" [ Upstream commit 1d3324c382b1a617eb567e3650dcb51f22dfec9a ] The EEH reset handler is ignorant to the current state of the driver when processing a frozen event and initiating a device reset. This can be an issue if an EEH event occurs while a user or stack initiated reset is executing. More specifically, if an EEH occurs while the SCSI host reset handler is active, the reset initiated by the EEH thread will likely collide with the host reset thread. This can leave the device in an inconsistent state, or worse, cause a system crash. As a remedy, the EEH handler is updated to evaluate the device state and take appropriate action (proceed, wait, or disconnect host). The host reset handler is also updated to handle situations where an EEH occurred during a host reset. In such situations, the host reset handler will delay reporting back a success to give the EEH reset an opportunity to complete. Signed-off-by: Matthew R. Ochs Acked-by: Uma Krishnan Signed-off-by: Martin K. Petersen Signed-off-by: Sumit Semwal --- drivers/scsi/cxlflash/main.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/scsi/cxlflash/main.c b/drivers/scsi/cxlflash/main.c index 6150d29..d0eed07 100644 --- a/drivers/scsi/cxlflash/main.c +++ b/drivers/scsi/cxlflash/main.c @@ -1962,6 +1962,11 @@ retry: * cxlflash_eh_host_reset_handler() - reset the host adapter * @scp: SCSI command from stack identifying host. * + * Following a reset, the state is evaluated again in case an EEH occurred + * during the reset. In such a scenario, the host reset will either yield + * until the EEH recovery is complete or return success or failure based + * upon the current device state. + * * Return: * SUCCESS as defined in scsi/scsi.h * FAILED as defined in scsi/scsi.h @@ -1993,7 +1998,8 @@ static int cxlflash_eh_host_reset_handler(struct scsi_cmnd *scp) } else cfg->state = STATE_NORMAL; wake_up_all(&cfg->reset_waitq); - break; + ssleep(1); + /* fall through */ case STATE_RESET: wait_event(cfg->reset_waitq, cfg->state != STATE_RESET); if (cfg->state == STATE_NORMAL) @@ -2534,6 +2540,9 @@ static void drain_ioctls(struct cxlflash_cfg *cfg) * @pdev: PCI device struct. * @state: PCI channel state. * + * When an EEH occurs during an active reset, wait until the reset is + * complete and then take action based upon the device state. + * * Return: PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT */ static pci_ers_result_t cxlflash_pci_error_detected(struct pci_dev *pdev, @@ -2547,6 +2556,10 @@ static pci_ers_result_t cxlflash_pci_error_detected(struct pci_dev *pdev, switch (state) { case pci_channel_io_frozen: + wait_event(cfg->reset_waitq, cfg->state != STATE_RESET); + if (cfg->state == STATE_FAILTERM) + return PCI_ERS_RESULT_DISCONNECT; + cfg->state = STATE_RESET; scsi_block_requests(cfg->host); drain_ioctls(cfg);