From patchwork Tue Apr 22 23:05:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 883412 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 9DDE1262FE2 for ; Tue, 22 Apr 2025 23:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745363160; cv=none; b=sxuhN+DM5ZOc4b+yWZsMkZFnOdPX2/h0lMp5KqdnIgATswfVLJOj2ixhaxxMCa54sDts1kWr+kV2bfrKNLj1dFljSIbg51EqAfUn8xBdjyMh9kCXzraWbGyqFHPIWJ/KLE+hEw32uRdWU7HpofRkSMsoeDYqDFiwszDtY1O/VO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745363160; c=relaxed/simple; bh=irEw6+L+FOASxlUvYZZgJczgjod4d4aOBm/qDTnfY3s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kE7+u9sgBIJsDDfs9wkW3nx1JymjnZIymRbQBh73JHw6R6CRgBRJPQnfLG87TQ272NxOeNjHSReK49gYrP8rUkeUlHQI4XAxUvS51gZWzg69nydPy+CBTdjpJpjH0+LnhZiQomqeBN4slG5cUWewutyRATkYwB4NQzGBl21UPfo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gVrAzPMv; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gVrAzPMv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745363157; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IkY27Gdp5eznLfjbt7qpVQ0OYk/4ucZm/cTdksHi7i8=; b=gVrAzPMvjEZoyAmEbj8i9w47Uj38DhLD1BUhcITIfLDoR0r1hDOyf5v9S35A+jYMbWngnt ds1Bau714tANn8N24h1r0Ev/D18g6HHHIJgk1X4g//MEQzNyexk6TtfHKoyZBXCQDmVxRY FtLOh/yFafuzfNNQwT8TESVubnrb4vs= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-sFOpMImRNl60evbqp62llg-1; Tue, 22 Apr 2025 19:05:42 -0400 X-MC-Unique: sFOpMImRNl60evbqp62llg-1 X-Mimecast-MFC-AGG-ID: sFOpMImRNl60evbqp62llg_1745363141 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 94E2C180056F; Tue, 22 Apr 2025 23:05:41 +0000 (UTC) Received: from omen.home.shazbot.org (unknown [10.22.88.22]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 283DA18001D7; Tue, 22 Apr 2025 23:05:39 +0000 (UTC) From: Alex Williamson To: bhelgaas@google.com, rafael@kernel.org Cc: Alex Williamson , linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] PM: runtime: Define pm_runtime_put cleanup helper Date: Tue, 22 Apr 2025 17:05:31 -0600 Message-ID: <20250422230534.2295291-2-alex.williamson@redhat.com> In-Reply-To: <20250422230534.2295291-1-alex.williamson@redhat.com> References: <20250422230534.2295291-1-alex.williamson@redhat.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Define a cleanup helper for use with __free to automatically drop the device usage count when out of scope. Signed-off-by: Alex Williamson Acked-by: Rafael J. Wysocki --- include/linux/pm_runtime.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h index 7fb5a459847e..69d4b2929ee6 100644 --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -466,6 +466,8 @@ static inline int pm_runtime_put(struct device *dev) return __pm_runtime_idle(dev, RPM_GET_PUT | RPM_ASYNC); } +DEFINE_FREE(pm_runtime_put, struct device *, if (_T) pm_runtime_put(_T)) + /** * __pm_runtime_put_autosuspend - Drop device usage counter and queue autosuspend if 0. * @dev: Target device. From patchwork Tue Apr 22 23:05:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 884184 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 85DCD27CB18 for ; Tue, 22 Apr 2025 23:05:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745363149; cv=none; b=YcWpB9IKxhiDZtxh1oa/+d23YcV6nAcvhcEN+wAO8o/6gf3Y4w2UNZTSLNIIcAKwXqaSfUUZPJgwVZCPoHCY0vpuALaCwlosZSitsZcj6/529F2DNdEsIoKA4u3be3XpA0C6JuMvZ5B2B5FRREZBAAFYGzdWadHoaRpEVNnYDUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745363149; c=relaxed/simple; bh=/3WEb+dygs+eWmYWF81aQ8qVlo9Y+tikEAZ8KqHjMzA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pjzw2wP/Dez8toflIRe/zalLw7lksr8B/t5d19n3uJu6KiM0YRKOlc4Eqvec29BHbiyyqy93V6/spNOeEN0H4JZAPF2puIT6LTJT0/RXlr/CfQwwGUGxVeDSbFoxxS69RfTsz4i/u7A8a4lD6752lpwQ4/MFY5p4m5LrR2azKYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Xy4kB2rU; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Xy4kB2rU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745363146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zkXnoeRkH2y5k80MjXEwQDOBw2xFVOkQ0IU4jNVrWtY=; b=Xy4kB2rUaWQSDpJ5k6Z9Etd2Qkmsjr2C2CvEGO4kO484xC+6a7G9hcso1tj927m53Zg+kO 3JwQppR2ksvFsBAeqtCrkOQHJoXx8nj1tZAlX1rznb5En9E0+hvVl1tynXU7LHd+P9g6e5 VA7AtWSHRRhxE9i9oPBUJE+1oN8dFNQ= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-423-ZIHoqVFGOqKgNcgFLbFd5A-1; Tue, 22 Apr 2025 19:05:44 -0400 X-MC-Unique: ZIHoqVFGOqKgNcgFLbFd5A-1 X-Mimecast-MFC-AGG-ID: ZIHoqVFGOqKgNcgFLbFd5A_1745363143 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 369121800368; Tue, 22 Apr 2025 23:05:43 +0000 (UTC) Received: from omen.home.shazbot.org (unknown [10.22.88.22]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EC0E518001D7; Tue, 22 Apr 2025 23:05:41 +0000 (UTC) From: Alex Williamson To: bhelgaas@google.com, rafael@kernel.org Cc: Alex Williamson , linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] PCI: Increment PM usage counter when probing reset methods Date: Tue, 22 Apr 2025 17:05:32 -0600 Message-ID: <20250422230534.2295291-3-alex.williamson@redhat.com> In-Reply-To: <20250422230534.2295291-1-alex.williamson@redhat.com> References: <20250422230534.2295291-1-alex.williamson@redhat.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 We can get different results probing reset methods for a device depending on its power state. For example, reading the PM control register of a device in D3cold will always indicate NoSoftRst+, preventing us from correctly probing PM reset support. Increment the PM usage counter before any probes and use the cleanup __free facility to automatically drop the usage counter out of scope. Signed-off-by: Alex Williamson --- drivers/pci/pci-sysfs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index c6cda56ca52c..71a36f57ef57 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1475,6 +1475,9 @@ static ssize_t reset_method_store(struct device *dev, return count; } + pm_runtime_get_sync(dev); + struct device *pmdev __free(pm_runtime_put) = dev; + if (sysfs_streq(buf, "default")) { pci_init_reset_methods(pdev); return count;