Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp1092240lqs; Fri, 14 Jun 2024 15:03:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX3S/cHRtloWL/sASM+9BL5jRRC9ltcQ1nd9l8G0vgh4Mj9zpNE5rovmm44VFKuEzvN0NYoeBXWImoGKTrYa4PHGKMsrHWeYhUUQJkhYg== X-Google-Smtp-Source: AGHT+IGmAQwBW73Pm/Qb0HMlx91GGCSJ5q69F12rBNEbMAx3MnTsPM3EXcErLKGe1AAhu0W5qfTA X-Received: by 2002:ad4:4b29:0:b0:6b0:67f1:384 with SMTP id 6a1803df08f44-6b2afc7944cmr35859436d6.2.1718402618510; Fri, 14 Jun 2024 15:03:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718402618; cv=pass; d=google.com; s=arc-20160816; b=RzCCqWsB2dqpoR7xbScq3wTnKM1mb5IuJ1SIozE6uXwklh8LpzOuTTKfb9fuU6b/eE 6+PoILJlfn/WTdoGWHcTtzLqEOAi8TzbU596DU3SoHue44X0lMi2FM0g4q474sNK9tvK YTRfEqjvajswYSJ7w2eFoExFQsD7LZQf1xIHiPVCymf8TNXtBVqLmzc5PgW9dqITjdEw mwVi9TaXsHssudGK1LOmKEKwsiQvDzEEakdpXxYSTt6VqGJnsf5DAqlXTiNgQzD714Lh qB28i3Y2w8bYxj8+EdbzgkAqzNDpBMWbWYLugnFOqxj6EBkOTiHd7fTVZ2Kcdw1JomlR XeFw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:subject:cc:to:from :date:dkim-signature; bh=GJ99l7vHQWV/LjV/hy9O9QbaDZ5s1ebv9QtnZlMBrQo=; fh=mMsbhHurWeKY8AWD9prjY/zXHAJvRPDktfqwT4iG29Y=; b=ncxkwzxHhnLiFLnAoCiRUHnkqodL2gLXccoREar7Q8xyb+x5bBk9+/IRmY+oHFvzNd rlwwxMcyzYlaoqjTSXBP5pDCPxQ9pxvttMfstsR60pPO27PchQcFhGtt9evRjlDWHzqh 5C7/nuAmag/IsydbHcBJuaBH1bBSaBlKw3eClVpQM7xS7S8iZfVvsUL3K6nujXZTi1ry UqmPCn+4rrQuozw7Ysx7ms6UUtoMx6OtzkTT7HreEKRP1/dDwpaOqhlb4GxQruD3rki0 9mv095Ie1I0GIxNgykbgqwwuVF7Wm99a2Beo8y5HpO6KsGgeOsNcCgAoXikKyx+RIqta CR4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OsXI2jcW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-215511-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215511-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6b2a5b89d87si45048186d6.573.2024.06.14.15.03.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 15:03:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215511-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OsXI2jcW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-215511-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215511-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3B36A1C21198 for ; Fri, 14 Jun 2024 22:03:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D9E71850A9; Fri, 14 Jun 2024 22:03:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OsXI2jcW" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4147149C44; Fri, 14 Jun 2024 22:03:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718402609; cv=none; b=JxIYA1yO1B4Nn2+GqWQm1xOmMtkxBQP1H7U2xRs7ANdURT4ewQXC8LF+1VRc6MTz8R/ptqmO+o9wxocjcoz4QO+0JbeuyaPt51Jj0U05hf+oilgAdC+JG6uraXq4QDTp/9xQ1zvPfD6im3SYXpawkbXwKyYf4Ct+YTzm4qjJYdw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718402609; c=relaxed/simple; bh=pnfRKVMJtcMvTZXgsbnPkluvMLxhMc1SMF0VOt5BoRQ=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=oMelfj6f0YT7nTFaO1Kst0Fu3CbUkTvpOM9VfL2NeGhy0uEercbgwVfbEf1LT+C2bEhZNeRERQzNs6X/PmpiGlZ69UjOCfSOaSxvn/uqC/ASWpGvenAFlKJhM/nu1o5xzo2wFb3+5LiIroVctmWTvlS/8CAXvgmZLSUf6uacGdM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OsXI2jcW; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28C8BC2BD10; Fri, 14 Jun 2024 22:03:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718402609; bh=pnfRKVMJtcMvTZXgsbnPkluvMLxhMc1SMF0VOt5BoRQ=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=OsXI2jcWYpgFuwwLeo3viE6MZZ5Zr3ulI4P+WzFGbdHbLKa0zpoT6JTwFrU3KbgdB 3NXjVaJ3ux4D5H/h8r1RofiY/h5d7dFmHm8JtkLRscEqqUmQC9vX/YDkI/NL9BDcK/ 1cFoaIKi6V7CoKgfIOZ3HkKlxA/nMx6rZ+zhSWElHPOOc1Q+bkiTI5l78ZgbrFkQa+ 3DhoZP9u6Pkq9RbL9t6NISOtaPmnDbnDfiHxwlBSAA8wz6iTDBQxlA/k+9ztyAFZH6 BWBqDtJ4VdCs8a14yyjjzbVT5ZYXpWoLHjVjW2tggzNOi+pC2BfAsz95LJBdEUx9/D 9qT2hecRbIMCA== Date: Fri, 14 Jun 2024 17:03:27 -0500 From: Bjorn Helgaas To: Lukas Wunner Cc: Bitao Hu , bhelgaas@google.com, weirongguang@kylinos.cn, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kanie@linux.alibaba.com, Ilpo =?utf-8?B?SsOkcnZpbmVu?= Subject: Re: [PATCHv2] PCI: pciehp: Use appropriate conditions to check the hotplug controller status Message-ID: <20240614220327.GA1125489@bhelgaas> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, Jun 14, 2024 at 09:36:57PM +0200, Lukas Wunner wrote: > On Fri, Jun 14, 2024 at 01:41:20PM -0500, Bjorn Helgaas wrote: > > On Tue, May 28, 2024 at 02:42:00PM +0800, Bitao Hu wrote: > > > "present" and "link_active" can be 1 if the status is ready, and 0 if > > > it is not. Both of them can be -ENODEV if reading the config space > > > of the hotplug port failed. That's typically the case if the hotplug > > > port itself was hot-removed. Therefore, this situation can occur: > > > pciehp_card_present() may return 1 and pciehp_check_link_active() > > > may return -ENODEV because the hotplug port was hot-removed in-between > > > the two function calls. In that case we'll emit both "Card present" > > > *and* "Link Up" since both 1 and -ENODEV are considered "true". This > > > is not the expected behavior. Those messages should be emited when > > > "present" and "link_active" are positive. > [...] > > > --- a/drivers/pci/hotplug/pciehp_ctrl.c > > > +++ b/drivers/pci/hotplug/pciehp_ctrl.c > > > @@ -276,10 +276,10 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) > > > case OFF_STATE: > > > ctrl->state = POWERON_STATE; > > > mutex_unlock(&ctrl->state_lock); > > > - if (present) > > > + if (present > 0) > > > > I completely agree that this is a problem and this patch addresses it. > > But ... > > > > It seems a little bit weird to me that we even get to this switch > > statement if we got -ENODEV from either pciehp_card_present() or > > pciehp_check_link_active(). If that happens, a config read failed, > > but we're going to go ahead and call pciehp_enable_slot(), which is > > going to do a bunch more config accesses, potentially try to power up > > the slot, etc. > > > > If a config read failed, it seems like we might want to avoid doing > > some of this stuff. > > Hm, good point. I guess we should change the logical expression instead: > > - if (present <= 0 && link_active <= 0) { > + if (present < 0 || link_active < 0 || (!present && !link_active)) { It gets to be a fairly complicated expression, and I'm not 100% sure we should handle the config read failure the same as the "!present && !link_active" case. The config read failure probably means the Downstream Port is gone, the other case means the device *below* that port is gone. We likely want to cancel the delayed work in both cases, but what about the indicators? If the Downstream Port is gone, we're not going to be able to change them. Do we want the same message for both? Maybe we should handle the config failures separately first? These error conditions make everything so ugly. > > > - if (link_active) > > > + if (link_active > 0) > > > ctrl_info(ctrl, "Slot(%s): Link Up\n", > > > slot_name(ctrl)); > > > > These are cases where we misinterpreted -ENODEV as "device is present" > > or "link is active". > > > > pciehp_ignore_dpc_link_change() and pciehp_slot_reset() also call > > pciehp_check_link_active(), and I think they also interpret -ENODEV as > > "link is active". > > > > Do we need similar changes there? > > Another good observation, both need to check for <= 0 instead of == 0. > Do you want to fix that yourself or would you prefer me (or someone else) > to submit a patch? It'd be great if you or somebody else could do that. Bjorn