Received: by 10.213.65.68 with SMTP id h4csp425196imn; Tue, 13 Mar 2018 08:39:39 -0700 (PDT) X-Google-Smtp-Source: AG47ELtzN0N5EsrHo06BttM8RMoZ2UWHtcJNOVKVu/rPKoSe6alamuyzJmHecdVyQkJP9EyHtWma X-Received: by 10.99.114.2 with SMTP id n2mr872287pgc.274.1520955579285; Tue, 13 Mar 2018 08:39:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520955579; cv=none; d=google.com; s=arc-20160816; b=sGKkp3JW/ptwcFMfJd/MrYR8oGUyurcxauwA6QL2GtVKFw3lnwKtOOsrXlHDwMp5Gt wdCTNA8W8afbpHFdOcrJEB2M9tYreQp9XmhrlJClp6NQohfKbePdNzqhv2NSu21BBkWe Y0NEvRuNgi9I3qkILNZN0o/+apm1CYsx/ItVhCsdopnL6drkdV6EtP384HdDbVEb0fXT ekWTzTTBD5lsut9jcX67qc/91fOhFMtDpczzxyxTLeAxuxOF3LY17KH/2ydnMCuIwiEs oyagJn+i6nh8CL9qyjfwOQSvf3fFz+iye0ZTGZ6q1BNQ5d/Mnzk5E2lczYIFCilOOv3Y UFMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=9Eo0oULG5BqyHHdADhzAGvu1kd+9zHGdVzdi07wapP8=; b=rPPpuLgsOdf9egv96hg2wm+NVSEFMSgQ1JrOt174w0Udo2m3LN4tu+U2X4bQpGvkOz RtkLC07n8bRk5wmo+q40Q6KlSfUBbWPWZytS0iqFHXeleMAKl7+IRcqvEACK7QVv4O2z IJdzhVlRK3gI4PUYUGPq1Y15GCVog5M1VnP2GElvVykM+25Vxf4DRLljnhbb4c9Ts8yg I75Ot+QUiRo4Jrh8iNf5jhQxIeL2IgU9U6H5ASh+uoRqjbmBVhHyhKgPechhak/HfOXa f1msTkfbzDkj3CSI9G+k8NULuUq2jgGJZek5QGVhlUsKa8LLg2uLVASSFSVpXoFcNYsu sebQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e12-v6si306175plj.126.2018.03.13.08.39.24; Tue, 13 Mar 2018 08:39:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934453AbeCMPhq (ORCPT + 99 others); Tue, 13 Mar 2018 11:37:46 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34076 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932486AbeCMPhn (ORCPT ); Tue, 13 Mar 2018 11:37:43 -0400 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1AA761250; Tue, 13 Mar 2018 15:37:42 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Natanael Copa , Damien Le Moal , Bart Van Assche , Alexandre Oliva , Pavel Tikhomirov , Hannes Reinecke , Johannes Thumshirn , "Martin K. Petersen" Subject: [PATCH 4.14 058/140] scsi: core: Avoid that ATA error handling can trigger a kernel hang or oops Date: Tue, 13 Mar 2018 16:24:21 +0100 Message-Id: <20180313152502.166776271@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180313152458.201155692@linuxfoundation.org> References: <20180313152458.201155692@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bart Van Assche commit 3be8828fc507cdafe7040a3dcf361a2bcd8e305b upstream. Avoid that the recently introduced call_rcu() call in the SCSI core triggers a double call_rcu() call. Reported-by: Natanael Copa Reported-by: Damien Le Moal References: https://bugzilla.kernel.org/show_bug.cgi?id=198861 Fixes: 3bd6f43f5cb3 ("scsi: core: Ensure that the SCSI error handler gets woken up") Signed-off-by: Bart Van Assche Reviewed-by: Damien Le Moal Tested-by: Damien Le Moal Cc: Natanael Copa Cc: Damien Le Moal Cc: Alexandre Oliva Cc: Pavel Tikhomirov Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/hosts.c | 3 --- drivers/scsi/scsi_error.c | 5 +++-- drivers/scsi/scsi_lib.c | 2 ++ include/scsi/scsi_cmnd.h | 3 +++ include/scsi/scsi_host.h | 2 -- 5 files changed, 8 insertions(+), 7 deletions(-) --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -328,8 +328,6 @@ static void scsi_host_dev_release(struct if (shost->work_q) destroy_workqueue(shost->work_q); - destroy_rcu_head(&shost->rcu); - if (shost->shost_state == SHOST_CREATED) { /* * Free the shost_dev device name here if scsi_host_alloc() @@ -404,7 +402,6 @@ struct Scsi_Host *scsi_host_alloc(struct INIT_LIST_HEAD(&shost->starved_list); init_waitqueue_head(&shost->host_wait); mutex_init(&shost->scan_mutex); - init_rcu_head(&shost->rcu); index = ida_simple_get(&host_index_ida, 0, 0, GFP_KERNEL); if (index < 0) --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -222,7 +222,8 @@ static void scsi_eh_reset(struct scsi_cm static void scsi_eh_inc_host_failed(struct rcu_head *head) { - struct Scsi_Host *shost = container_of(head, typeof(*shost), rcu); + struct scsi_cmnd *scmd = container_of(head, typeof(*scmd), rcu); + struct Scsi_Host *shost = scmd->device->host; unsigned long flags; spin_lock_irqsave(shost->host_lock, flags); @@ -258,7 +259,7 @@ void scsi_eh_scmd_add(struct scsi_cmnd * * Ensure that all tasks observe the host state change before the * host_failed change. */ - call_rcu(&shost->rcu, scsi_eh_inc_host_failed); + call_rcu(&scmd->rcu, scsi_eh_inc_host_failed); } /** --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -670,6 +670,7 @@ static bool scsi_end_request(struct requ if (!blk_rq_is_scsi(req)) { WARN_ON_ONCE(!(cmd->flags & SCMD_INITIALIZED)); cmd->flags &= ~SCMD_INITIALIZED; + destroy_rcu_head(&cmd->rcu); } if (req->mq_ctx) { @@ -1150,6 +1151,7 @@ void scsi_initialize_rq(struct request * struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); scsi_req_init(&cmd->req); + init_rcu_head(&cmd->rcu); cmd->jiffies_at_alloc = jiffies; cmd->retries = 0; } --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -69,6 +69,9 @@ struct scsi_cmnd { struct list_head list; /* scsi_cmnd participates in queue lists */ struct list_head eh_entry; /* entry for the host eh_cmd_q */ struct delayed_work abort_work; + + struct rcu_head rcu; + int eh_eflags; /* Used by error handlr */ /* --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -571,8 +571,6 @@ struct Scsi_Host { struct blk_mq_tag_set tag_set; }; - struct rcu_head rcu; - atomic_t host_busy; /* commands actually active on low-level */ atomic_t host_blocked;