Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3918923pxv; Mon, 28 Jun 2021 16:39:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkfQthwrebGt5CQXlbixOfIPbVYjuWKmJ8vA8n4b10pCzxRklXi1SUgyv8Q/m1lkF23w6l X-Received: by 2002:a05:6e02:1545:: with SMTP id j5mr6579049ilu.102.1624923563707; Mon, 28 Jun 2021 16:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624923563; cv=none; d=google.com; s=arc-20160816; b=VY+8AUTfXxqFvveHixh7YXIeZo4D5yYIYSJ7zEOcWtVbppOSJGScBOSSOu4aDd1f5t V4h+4xTiiegONpd68Lr98bP3HaIJXdrecKiOXSv+9pkzc5xSqIAQBaCcjjIQlqGJysai pQUdlr+GmJfgw8kXukApsXZNfxd4rf4s5ESE1Gxh0/c7I3fAuoGqyjYIQA32zaMuEv72 3JCYeutsUWqeeKsJqpurCIPaI480nX39wmxus2xVFho82q/PEsP2nvTfigBJObJ6oVMp PmXwhsPogwNwLynAz8SQqvRvdWR55icy+GYJ9BHbnsDKM1XVv9QO2TLQ//6ee/dxkH/n JLyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=h/Ygcb6PuZTWJldevbJojqcbTHjtYoWaJ0JOU4ireDo=; b=gQDJsWA9ecYWiQlz+keHi4VCweR0pU9rrBxFJSsjWiL8zavATMzF7G04mVw0Pe9p6t FN7uk62trjO0Ha2hDkYquuYJcdFi4Zx2pxSbL85NaI/Wk2ems4cRUGbCPqw8eFbnvNQo uzTXpg3I4iJ71EJkE6oj6o3bFzDrm6biIbnl+401OImaQ8NRTVuUitCYRQDLcWGcnxLN SRHs/YUcwlvYfDL9n844e/8diQIyNiSDK30GifNqAWatEDJMqHhLtETasoJbc36wEYTq hdLY+3aU3Oim67ZgnTlMX3ZQc5R8uRVML6I+8/djUVJF5WbYY24J5pB7u/lMvlUaMhoR BUUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x19si18494864ioa.74.2021.06.28.16.39.12; Mon, 28 Jun 2021 16:39:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233695AbhF1ReR (ORCPT + 99 others); Mon, 28 Jun 2021 13:34:17 -0400 Received: from mail-pg1-f172.google.com ([209.85.215.172]:46073 "EHLO mail-pg1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232713AbhF1ReQ (ORCPT ); Mon, 28 Jun 2021 13:34:16 -0400 Received: by mail-pg1-f172.google.com with SMTP id y17so3761946pgf.12; Mon, 28 Jun 2021 10:31:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=h/Ygcb6PuZTWJldevbJojqcbTHjtYoWaJ0JOU4ireDo=; b=TB/cF9P5C1FtV3nMxw8cMUaksrEYgorCAKqjW9AWz0n/Sw7u0LUwSAIg5BtqzUWkc/ 8QckR6bvM/+IZTPKLVhdq6l4r541661iR/mqCS260nqSrm6+sZwhLPQDksWz8UpzyWkd XXfowF3G58uLarKXbT94CAgMfrj/5gNdmzzkt9Vc5AQxOmuqBIx8tm8YfPkYYdqXoHhD 4HlmkyFJtp8ebV7L+dp86AsiJmByqxz8IelvpRZPYTHZ/OMfhcKbTgk/mvUfWa+kI7AF xhjH1gbZQEHRMLPWwOF03sWJJRF6ywOKkREW1RG9Pj/JXTqBeZevKXgERBui/nmGf6kK lacg== X-Gm-Message-State: AOAM530zvZm9+wXoXkePIRYZ/K2+IYHYvfLf4oj+lo2yD0VCFlHKtkhs 4adeRSeJRXZhjW+YvGKOlSPGhIjllHY= X-Received: by 2002:a63:2cc4:: with SMTP id s187mr24098304pgs.233.1624901509737; Mon, 28 Jun 2021 10:31:49 -0700 (PDT) Received: from [192.168.3.217] (c-73-241-217-19.hsd1.ca.comcast.net. [73.241.217.19]) by smtp.gmail.com with ESMTPSA id o1sm15214298pfk.152.2021.06.28.10.31.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Jun 2021 10:31:48 -0700 (PDT) Subject: Re: [PATCH v4 06/10] scsi: ufs: Remove host_sem used in suspend/resume To: Can Guo Cc: Adrian Hunter , asutoshd@codeaurora.org, nguyenb@codeaurora.org, hongwus@codeaurora.org, ziqichen@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Jaegeuk Kim , open list References: <1624433711-9339-1-git-send-email-cang@codeaurora.org> <1624433711-9339-8-git-send-email-cang@codeaurora.org> <9105f328ee6ce916a7f01027b0d28332@codeaurora.org> <1b351766a6e40d0df90b3adec964eb33@codeaurora.org> <3970b015e444c1f1714c7e7bd4c44651@codeaurora.org> <7ba226fe-789c-bf20-076b-cc635530db42@acm.org> From: Bart Van Assche Message-ID: Date: Mon, 28 Jun 2021 10:31:46 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/28/21 1:17 AM, Can Guo wrote: > On 2021-06-25 01:11, Bart Van Assche wrote: >> On 6/23/21 11:31 PM, Can Guo wrote: >>> Using back host_sem in suspend_prepare()/resume_complete() won't have >>> this problem of deadlock, right? >> >> Although that would solve the deadlock discussed in this email thread, it >> wouldn't solve the issue of potential adverse interactions of the UFS >> error handler and the SCSI error handler running concurrently. > > I think I've explained it before, paste it here - > > ufshcd_eh_host_reset_handler() invokes ufshcd_err_handler() and flushes it, > so SCSI error handler and UFS error handler can safely run together. That code path is the exception. Do you agree that the following three functions all invoke the ufshcd_err_handler() function asynchronously? * ufshcd_uic_pwr_ctrl() * ufshcd_check_errors() * ufshcd_abort() >> How about using the >> standard approach for invoking the UFS error handler instead of using >> a custom >> mechanism, e.g. by using something like the (untested) patch below? This >> approach guarantees that the UFS error handler is only activated after >> all >> pending SCSI commands have failed or timed out and also guarantees >> that no new >> SCSI commands will be queued while the UFS error handler is in >> progress (see >> also scsi_host_queue_ready()). > > Per my understanding, SCSI error handling is scsi cmd based, meaning it > only works when certain SCSI cmds failed [ ... ] That is not completely correct. The SCSI error handler is activated if either all pending commands have failed or if it is scheduled explicitly. Please take a look at the host_eh_scheduled member variable, how it is used and also at scsi_schedule_eh(). The scsi_schedule_eh() function was introduced in 2006 and that the ATA code uses it since then to activate the SCSI error handler even if no commands are pending. See also the patch "SCSI: make scsi_implement_eh() generic API for SCSI transports". > However, most UFS (UIC) errors happens during gear scaling, clk gating > and suspend/resume (due to power mode changes and/or hibern8 > enter/exit), during which there is NO scsi cmds in UFS driver at all > (because these contexts start only when there is no ongoing data > transactions). Activating the SCSI error handler if no SCSI commands are in progress is supported by scsi_schedule_eh(). > Thus, scsi_unjam_host() won't even call scsi_eh_ready_devs() because > scsi_eh_get_sense() always returns TRUE in these cases (eh_work_q is > empty). Please take another look at the patch in my previous message. There is a scsi_transport_template instance in that patch. The eh_strategy_handler defined in a SCSI transport template is called *instead* of scsi_unjam_host(). In other words, scsi_unjam_host() won't be called if my patch would be applied to the UFS driver. Please let me know if you need more information. Bart.