From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796417464; b=EPI7o5onZe7SYZg05AQ0oAoIs2VG91WgSdPatM8T7QOO46cPTIwpYCapaBStZ4vVNiE8 rAf7gklwz7njRBAq0lKkPjvaqKmdGZFxAQ6RQ7MQt9IPKwCXMJmbYxBmiDoGrXIJ0tFgl kukUGBJUpswKixvyuut2rw0zN+D/DqM3E1ATjkMMo8ze4gWQlWkWiAX5P0Y4xip7iEIrn j0SHWdGOlWHjzAqnDSM98Ou+1eR0nfDSyJFUwmIiJ+LaWLo+eDrfWLi+QnzxJ/VPub5n/ ZcYtdlC36rBTZlOPxc1s1ZWFBzrTRs40G0VHVwWbek7/1RMZu5jLcnE0uDQ956DVI1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796417464; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:Content-Transfer-Encoding:In-Reply-To; bh=lDW+RMOHJBwFpPQvST2hlqRXU8TTDjNSK3ChSMmEUPQ=; b=pBcxZOSvOHRJksBjz7feWe9c5MUFPqIpKsIyX8gl05Z+oKBY1wmxlzyWNKgvdRSu+VF3 bbNiPgPDV6MlRpnFPMwxet7s3JpWt2I1TOMwkW0bQMkWEDOC1jSeg9TETUBPEGwQAInXt uC+QXeuQaCZuWm+LQfgnNofVJ+u0A/x+vQYu9vgA70Qp0fRLLhd3mAZA/Dje5idfhF3vH W9cC389VCzXbHF3nidJRr7r/OLJy950JP2gskEcU+P5MK5Y7mWkVlTs6PpvgeqYr86PHg 6uTXDaJV9RNL1Ip+Qnezer69qq3PGQwZH066OIw7zPECXvR0exnSwRMo/VxFVJSLX9w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=iG5R8zIs; arc=none smtp.remote-ip=74.125.82.42 Received: from mail-dl1-f42.google.com (mail-dl1-f42.google.com [74.125.82.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2ABF5606A32C for ; Fri, 4 Dec 2026 20:51:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2ABF5606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=iG5R8zIs Received: by mail-dl1-f42.google.com with SMTP id a92af1059eb24-15ea896ddc8so1833006c88.0 for ; Fri, 04 Dec 2026 12:51:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1796417463; x=1797022263; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=lDW+RMOHJBwFpPQvST2hlqRXU8TTDjNSK3ChSMmEUPQ=; b=iG5R8zIsBg4lykI59wZE+FnvOIwR/L02AQ8wQveW0ztVbNfdjKClOBIibqwFqNp/Zm 6F5ff0eGXTSeb5oI8XVK6wwXiPec2MkDYfFJ5bCxkOWlcMAJhOr4+PMQymjRGJdXtstg EDDwhn5Do6S8cpgIf2v7iExwKoNLV36Swk9pk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796417463; x=1797022263; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=lDW+RMOHJBwFpPQvST2hlqRXU8TTDjNSK3ChSMmEUPQ=; b=2iNs8NJQglGrmODhDtIXLfCX3wF+cOy8rXy3CJxzc/dRqxILamY7IcFRoDc+AIJh0y Ho3/C4NmhIVq3q1xpt3cU3anaq0p773tmZliG6e/Z5xx3Y0eOTfHQtT+QLUCXx86kb5A xQjN1b3uEXaazQDFr9WY59NFNLPunN75W8VR4cAtA5T0TDIHpeVL1owqKnHNAa0vjxts PzSftZWTo7XDB+psp490uJzgxxrDmlE9cs8IxTWA0/0WcXIktl9vke9ESW54ovm1V7im niVUH2v/DXkrybwFway7sKPiF8TgmT5/SZ4pzJOLrGzwdvj4cSlelFnTRa4yM2R3o8jS 6uZw== X-Gm-Message-State: APuU4Z9zgRvzHVsRBHsgvHutl3bf2WLKz0egqSZsHl+gwGs1W40/LA4C NdkJ7URAJP6vQ0/1ZfvpjkobrtXF3ivG3GG60WWwdOlyuV1zRTC9CeTTmiH9niX2wA== X-Gm-Gg: AZFdTZcaKaXnc3DkqTCfXnYG+vZ/q/R5I+ugLMIauIkBYh9bkHz9qIhioBxw+nLdvoM 7JM/EKnyP/6iFiDAU9/XUEOz74RSd+HQjqI0riNQfZgiHVyAttN2XiLcMUpPhpbHmFIYFMDRmSV RpyyJN97DfEtXbr4Ksa8w+ENPnQ6lH8HAruTpPLpN9z2WQla0lIfg82I+kf/Cx6s78mRTKA8nCO hrHOEigSBPaDYSlYKYHgoma5TTWLVTE69Sqy20DPBMPGGFiFIKldhsvzR/pnOXGn0o1xq7ykzjg 2UAUV1cbzNL3LCHLNWCojkkddcY/BW1uEjYa4PORrn3j771w4a3N7YpKKVp2zRA3P5k+lVL+Ngj j4Rqv9by3cvyyBCUwaXZV2KrI5XrUK6TkJeBTQkOBi2IG9pEizn0/N0f84blLM353LhchY6i5Fp ZaI84r23uSWTJrzBa065N+Exd05knXNjWYuksAhAhrUdJ3PbSJidjK50XCXr1qpRBwKvZpJjO2B PjP6FO0beJz25v+KhqZNKsMvpHy10J6Zq8CHvjwlCpY4/HilPOnOJI7ELgn1U/pONLudfVfHafD fAIoaJnIOQLzyWuFVW1pxy9gicz5kfwA07vNKX1Bw9om1OHwFU13UI4hazoTQ+XIK0Sxxppl8z3 qdOuML40OJ9WcTw== X-Received: by 2002:a05:701b:220b:b0:144:fa57:c617 with SMTP id a92af1059eb24-1b5d710fcdemr2778431c88.34.1796417462934; Fri, 04 Dec 2026 12:51:02 -0800 (PST) Received: from localhost ([2a00:79e0:2e7c:8:965b:30a1:58ae:cf87]) by smtp.gmail.com with UTF8SMTPSA id a92af1059eb24-1b5d642e254sm9915725c88.4.2026.12.04.12.51.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 12:51:02 -0800 (PST) Date: Fri, 4 Dec 2026 12:51:00 -0800 From: Brian Norris To: "Rafael J. Wysocki (Intel)" Cc: Linux PM , Linux Driver Core Development , Ulf Hansson Subject: Re: [PATCH v1] PM: runtime: Check refcount value in pm_runtime_release_supplier() Message-ID: References: <6056379.DvuYhMxLoT@rafael.j.wysocki> X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Fri, Dec 04, 2026 at 09:19:25PM +0100, Rafael J. Wysocki (Intel) wrote: > On Fri, Dec 4, 2026 at 8:38 PM Brian Norris wrote: > > > > On Fri, Dec 04, 2026 at 05:05:44PM +0100, Rafael J. Wysocki wrote: > > > From: "Rafael J. Wysocki" > > > > > > If the device link's rpm_active refcount becomes saturated or > > > underflows, the loop in pm_runtime_release_supplier() will continue > > > until the supplier's usage_count goes down to 0, but that may allow > > > the supplier to suspend when it is in use for reasons other than the > > > consumer dependency. > > > > > > To avoid that, check the refcount value, expected to always be greater > > > than 0 when read as an int, and break out of the loop immediately when > > > it becomes invalid, instead of checking the supplier's usage counter. > > > > So, erring on the side of "hold reference forever", instead of premature > > drop? Seems OK, especially for something that should be extremely > > difficult to hit. > > > > Reviewed-by: Brian Norris > > Thanks! > > > BTW, I still think all this rpm_active logic is very strange. We > > shouldn't ever need to increase the rpm_active refcount larger than a > > small handful (approximately on the scale of how many DL_FLAG_RPM_ACTIVE > > links are created with the same consumer/supplier pair), but... > > True (I actually had to recall what the original problem addressed by it was). > > > ...we actually can dynamically increase rpm_active forever simply by > > calling pm_runtime_set_active() repeatedly. > > If anyone does that, they will get what they deserve. Haha, maybe. Although it doesn't seem all that impossible today; consider system suspend/resume for devices that never go through runtime suspend (e.g., .../power/control == on) in drivers like dwc3_pm_resume(). It forces a pm_runtime_set_active() on the resume path. Now, suspend your system INT_MAX times (lol) and... That pattern is even sort of in the docs: https://docs.kernel.org/power/runtime_pm.html#runtime-pm-and-system-sleep I think there may be some other similar paths in smart-suspend, which could potentially apply to lots of devices. > > This feels less like a refcount and more like a bandaid over poor code > > structure. > > So in theory, __pm_runtime_set_status() could somehow avoid calling > rpm_get_suppliers() if the current status of the device is RPM_ACTIVE, > but I had not found a good way to ensure that it would not be racy, so > I gave up. I didn't think too hard about that one, but I gotta believe it's possible. Maybe I'll spend time looking at it and come to the same conclusion :) > OTOH, I'm now thinking that it might be better to combine > __pm_runtime_set_status() with pm_runtime_enable(), so there would be > two "stateful" variants of the latter, pm_runtime_enable_active() and > pm_runtime_enable_suspended(), but then there needs to be a separate > way to clear runtime_error (if set) and system suspend/resume enable > and disable runtime PM. I'll admit, I'm not immediately seeing the value in this. Brian