Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp510773imm; Mon, 1 Oct 2018 13:41:25 -0700 (PDT) X-Google-Smtp-Source: ACcGV62sNuYX0zk+69CuohoMFQh3HaA/XrpPq14Ws8ggvRm7Y/46O6GxaFqQ9McyTOx1BYVFWwBB X-Received: by 2002:a17:902:506:: with SMTP id 6-v6mr13487243plf.132.1538426484961; Mon, 01 Oct 2018 13:41:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538426484; cv=none; d=google.com; s=arc-20160816; b=W79C4woRNU3ULbQwqaPnmWhLYSoGZNkdMmwLKD2ucZVIhmuZpW9E2d2C6ufe+0n2pv 5UlRgllwSgW2wQLCt/w2HpbHrFrOCh73Y+BK77oC4/H9oq02sguLW1+RQ/2V+3KqV0zN hRcPBm3AtnSTN4cNy2KjMirpaYfaiV+TIZMCv2Eyd7NKvGwrIbN+QZhuj9gxg3++Mcq5 wP0uVMNaMOLnmaDKO0EEJmd28stBqj30VK34SGCXzS0VO1RfaZXsLbybp7yWyrwnylSu efhVFTnh/uH+PCoTyDaKEy7K1V+XovRQ1Kgq3ImpEgTtKZPFU/DgyiCTdYQjS5aGVM9X ZoPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8GOtjb4utjxsj1wpOS/P+3R3gIJrufkRrmqrribMcEM=; b=moWB/SHdJhbSKHRN09HIWNuOAcQsM8yRNLEDv/tSCjwXh58vPn9Hdxfgb7uRbndOuI aaeP3by9vewgXpDUOSnzE5hkUzkbb0A225dbzxEaMDBN3O3uZphpWjYdKu8Ga28lorsy /n52C8XCHToNwSlOsBIeueRIsWTSYGSCuPzHG9mevVm8ZXeyF+//8GjepCeLfbLKrOQh TKm1bUB76OlVeyYqW/K9D9DqGVbI0mkJ+ZmVWw8Sa6tzJIUZI6TAgWJ6Oo0OLTnJ1FUd 5bP1UEo/Khmld0Ac3hec76fEqeGUpRxoZchktP/ffih6MwG3ySK8QBDzyFVVHwuJ4q/r IeVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HRjWmo9z; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x195-v6si13119726pgx.294.2018.10.01.13.41.09; Mon, 01 Oct 2018 13:41:24 -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; dkim=pass header.i=@kernel.org header.s=default header.b=HRjWmo9z; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726445AbeJBDU2 (ORCPT + 99 others); Mon, 1 Oct 2018 23:20:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:56450 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726287AbeJBDU2 (ORCPT ); Mon, 1 Oct 2018 23:20:28 -0400 Received: from localhost (unknown [69.71.4.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 90628208AE; Mon, 1 Oct 2018 20:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1538426452; bh=DQgJAjwHTliGl6ri8SgmSvR0ckheZ5C5Pxzn7UoAmrU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HRjWmo9zOrjE28IjHcLwZTCauu9QexCKI/R3vSwa2AQMVJkbo7jL9uxnGgQSfAHK0 OI3wPnk21a59sMyrmtkHTur2CesHKUPrOUQnhH9Rnmme8NCCrEiAuGFZQFYd1vpbmM 7iWTTTvFftAHOgIfQNx+SCyKDAiDwzWQUb3QSdec= Date: Mon, 1 Oct 2018 15:40:51 -0500 From: Bjorn Helgaas To: Suganath Prabu Subramani Cc: lukas@wunner.de, linux-scsi@vger.kernel.org, linux-pci@vger.kernel.org, Andy Shevchenko , Sathya Prakash , Sreekanth Reddy , linux-kernel@vger.kernel.org, benh@kernel.crashing.org, ruscur@russell.cc, sbobroff@linux.ibm.com, oohall@gmail.com Subject: Re: [PATCH v4 1/6] mpt3sas: Introduce mpt3sas_base_pci_device_is_available Message-ID: <20181001204051.GD142872@bhelgaas-glaptop.roam.corp.google.com> References: <1537935759-14754-1-git-send-email-suganath-prabu.subramani@broadcom.com> <1537935759-14754-2-git-send-email-suganath-prabu.subramani@broadcom.com> <20180926213241.GI28024@bhelgaas-glaptop.roam.corp.google.com> <20180927070327.wvl5glb4c7gtjoa3@wunner.de> <20180927184746.GM28024@bhelgaas-glaptop.roam.corp.google.com> <20180927190959.dio4qwti3i4accjm@wunner.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 01, 2018 at 12:27:28PM +0530, Suganath Prabu Subramani wrote: > On Fri, Sep 28, 2018 at 12:40 AM Lukas Wunner wrote: > > On Thu, Sep 27, 2018 at 01:47:46PM -0500, Bjorn Helgaas wrote: > > > I'm not sure how mpt3sas benefits from adding > > > mpt3sas_base_pci_device_is_available() here, other than the fact that > > > it avoids an MMIO read to the device in most cases. I think it would > > > be simpler and better to make mpt3sas_base_get_iocstate() smarter > > > about handling ~0 values from the readl(). > > > > Avoiding an MMIO read when it's known to run into a Completion Timeout > > buys about 17 ms. If the function is executed many times (I don't know > > if that's the case here, I'm referring to the general case), or if bailing > > out of it early avoids significant amounts of further I/O, then checking > > for disconnectedness makes sense. I agree that if we know the device is gone, it's helpful to avoid further I/O to it. The misleading pattern used in this patch is: R1) Check for device presence R2) Read from device R3) Consume data from device That promotes the misconception that "the device is present, so we got valid data from it." But in fact the device may disappear between R1 and R2, so the following pattern is better: A) Read from device B) Check data for validity, e.g., look for ~0 C) Consume data if valid If we're writing to the device, we don't expect any response, and it makes sense to do: W1) Check for device presence W2) If device present, write to device Obviously the device can disappear between W1 and W2, so this can't eliminate *all* writes to non-existent devices, but if we want to reduce them and we're only doing writes to the device (with no reads), this is the best we can do. We can learn that the device is gone in several ways: pciehp might notice the link is down, the driver might notice a ~0 return, etc. The driver writer knows the structure of communication with the device, so he/she should know the appropriate places to check for valid data from reads and where to check to minimize the number of writes to a non-existent device. > This function is called only during controller reset, system shutdown > and driver unload operations. > For this case we can remove mpt3sas_base_pci_device_is_available() check, > since we can make the device removal from readl in > mpt3sas_base_get_iocstate() as you suggested. > But we need mpt3sas_base_pci_device_is_available() in other places > like while submitting the > IO/TMs to the HBA firmware etc where driver is not checking for the > IOC state (through readl() operation) > to gracefully handle the HBA hot-unplug operation. This is the W1/W2 case above, and what you can do is constrained by the device model, i.e., where it requires reads from the device. I agree you may want to check whether the device is absent to minimize writes after a device has been removed. I think the names "pci_device_is_present()" and "mpt3sas_base_pci_device_is_available()" contribute to the problem because they make promises that can't be kept -- all we can say is that the device *was* present, but we know whether it is *still* present. I think it would be better if the interfaces were something like "pci_device_is_absent()" because that gives a result we can rely on. If that returns true, we know the device is definitely gone. Bjorn