Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5390959pxj; Wed, 26 May 2021 09:25:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGQTSPHPCIrfoyb6V2aeoy0Bh66eOY1dGsnqlZ8FG6AB7DCo/PTqp9nztVQW/nbn+ONTzI X-Received: by 2002:a02:9621:: with SMTP id c30mr3988709jai.113.1622046305805; Wed, 26 May 2021 09:25:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622046305; cv=none; d=google.com; s=arc-20160816; b=RTM/bQFwg9u4vZDjZk5x2ECqW1TCCsdTDH3956YDl6SZbsTrOezyCor/o7qETNMRA9 SkAQQPFCAuJ2Ud4eZjVz0aPlKv4s1SK4gmm21OE95NHUm/wQdwsq0WRXhf63EazVJzmL yjZgZQRWfr9yjSN2za3KogyJLYYuPi9lvc2qY94dVfJ5yqyiiQUG9xpX+H1LQBHba5E8 Q25MaddusfTzgu3tTdJeCUoug5+Uk85iG9ku6k9xYwrfHujHbXO7SySlcEx1rb98ipgX 59vhMAGzQxFMLCx+6+nIqTH8zyV9loUG+OuszF8dgRrQ4cl3uz3c+rPTZbP1nqL2UlGv Mheg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=UAv1prA9lFdpB71KVRa/MBWYE+q7HFsi0Jl9wyYQxUk=; b=lGt+A+vSvy9Pqk51dA5QkuagYfoeR1OpZ9MrTXH/kyRbhNPXT139THpJaXDfdpwWDd RLi/VNsMolj6uPxwIRSRye8nBsA9OdKyKjwYN9wFD0bG9FY7ZCWaKr56OqTfl4Aiq5Jq xKumDOw1ExeBxN7Eeu5Gpz4GxYtiEpXNK6nYtpbaHWqLvgRaioXIzTqfPP4a8VI04z3y FgQE9shIzb8ErIIOmPaHAayeEanQe3LaPYm428V5Pi2+ulcOGU5ZH1SQbbjUW+cXARpQ Ooia4AKckX3wYCvUEY0otGJJHZ83tv1HVbRpL/mNdSM+NkhbYVdXDneHWefgkhlvhK40 mNeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OqFvy1CC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h17si8771118jas.28.2021.05.26.09.24.51; Wed, 26 May 2021 09:25:05 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OqFvy1CC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233778AbhEZQYk (ORCPT + 99 others); Wed, 26 May 2021 12:24:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:36818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232363AbhEZQYj (ORCPT ); Wed, 26 May 2021 12:24:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1C9CE613CA; Wed, 26 May 2021 16:23:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622046188; bh=EC/2FajTeQPvMVJu8QFCw8CA3KxI3R6E2U7b7VFhw7Q=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=OqFvy1CCupJA3GVoDKXRFZa5F85ZK0/mtdmFp+AuVxA4KFOyM4zzHqw+lr5giCimC tES7XtjSLd0dN3sxeObEe9RBjpCXsOrTFXZBT+Eq5B9NJraDOQN20shmb8BwlVkdIQ EIw5/YTcJ9LBhtdKlaImPW3eDG7qitX0zHlKbBXyqtKTyr/c+9VHkODEoc+AZxdkGM ZWzaoAiTGBJ/FCn6IDMu6UPuWQeixt5zyvCGYE2FojXsiVXU/vT5WXj7L84SQdVlQi AZ+EbHHGqFHZCES9TmpCoIZvKLZBGpbbcLPwdBAQWw4A2o0U+m6rQkVQSdvP6oo3lp tkEF+EjLZDxqw== Date: Wed, 26 May 2021 11:23:06 -0500 From: Bjorn Helgaas To: Lambert Wang Cc: Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] pci: add pci_dev_is_alive API Message-ID: <20210526162306.GA1299430@bjorn-Precision-5520> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 26, 2021 at 02:12:38PM +0800, Lambert Wang wrote: > ... > The user is our new PCI driver under development for WWAN devices . > Surprise removal could happen under multiple circumstances. > e.g. Exception, Link Failure, etc. > > We wanted this API to detect surprise removal or check device recovery > when AER and Hotplug are disabled. > > I thought the API could be commonly used for many similar devices. Be careful with this. pci_device_is_present() is not a good way to detect surprise removal. Surprise removal can happen at any time, for example, it can occur after you call pci_device_is_present() but before you use the result: present = pci_device_is_present(pdev); /* present == true */ /* device may be removed here */ if (present) xxx; /* this operation may fail */ You have to assume that *any* operation on the device can fail because the device has been removed. In general, there's no response for a PCIe write to the device, so you can't really check whether a write has failed. There *are* responses for reads, of course, if the device has been removed, a read will cause a failure response. Most PCIe controllers turn that response into ~0 data to satisfy the read. So the only reliable way to detect surprise removal is to check for ~0 data when doing an MMIO read from the device. Of course, ~0 may be either valid data or a symptom of a failure response, so you may have to do additional work to distinguish those two cases. Bjorn