From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796413093; b=BrYkZLX90q2bkFMoBW7pxG12b2h4Req1UfYmB36Wm/pxkVqGW4k3neKWRiHFy0oKgzXv 5XEcTJpiCVLETTQyoKoZ1t8weGvz/MBKrW4ccLuI9zCDsoNx3lMtUOKbS2BW077rEhSXW Pg/z4/Jh9blo+MzbsbPdJ+WCWqeTLYEBV+RwETDRFGFQ3Rd9eVcE01w5B8mu7wP6dwZ6u 09mGV7IBfbuvdZCaZYSu9CDrgEYoAdOBaYAi/xPGI3Vew0Nv0YbExtwgg9jrqcgIQyR4p 7ZIm89yIB1FxiVw3VgvKXd+mztFPWjK3Lf6wD60THIaX/38cm88EScY4sGSWDfQLtNw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796413093; 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:In-Reply-To; bh=4S54qcd4uxyZCrUxLv/Pbl8YaBiYsCslPYjNE3PB4Ik=; b=VKSJsTA7iWmERfvCGVPyrElqSd091cfFt/0iq5/rEKne8dZTXdXAZ2hGPaJrSSZf3sjo z/0cI4hx+mtHfAfL29Czv61Yd/bCH9WedGLukcpZGyYtKoxJJroBLMoelVsBTkExoNqhA WoFWnvQ2SUAZbf8Lj+2saHXU2+KQXX3w8jrwBhd9qpNaCsSf/5O9lavblFtqrjdlK/IQu M+FmaOZeprwN98DbBOePNyNMtMRnsr13C0GcF4zZdOr02SA/zaem3f1a8FgpfSPFg4QnU HHq+N5WEe/pGZPvhJjgurBy7LNePRU+RmekeW4jA1yTLHfQ7TvFd4bwO7pgPR5dWH/w== 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=kTZRmA0u; arc=none smtp.remote-ip=74.125.82.173 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173]) (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 DC0CA606A322 for ; Fri, 4 Dec 2026 19:38:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DC0CA606A322 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) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=kTZRmA0u Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-38190551625so1510757eec.1 for ; Fri, 04 Dec 2026 11:38:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1796413092; x=1797017892; darn=vger.kernel.org; h=in-reply-to: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=4S54qcd4uxyZCrUxLv/Pbl8YaBiYsCslPYjNE3PB4Ik=; b=kTZRmA0uAvwCQgpr6woaeIkMTqOKulOicObCNBzaXAPo8/rnJDwrh9BH2BqEhEG83t UAZN0g3NUV4zvr1tDLlv6zVEjz80WgKEc8Irq6wZOLWlw0rkD9iQkXsqikf4rqx9Ds6T VLBphfdiCU+yUOThNloe2pLzLtRHhGTjzHSHM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796413092; x=1797017892; h=in-reply-to: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=4S54qcd4uxyZCrUxLv/Pbl8YaBiYsCslPYjNE3PB4Ik=; b=roIaJQGRCMvmxH9nWzHfthwf3f4MOgKbNnx7iDBKl1amdNbpk4nwrQHQX0e39TP5ky D5K+rcvOi/NpAHb/CqY9Q198BCYtjiqUymaDGTIXRgz0oaaWzdg05syw3FKI7/PW/ddq 81hk6zq7IBMQTl67vmhmWj6QhVQLi6DWfnj7H+6JoTLF7rlrj6IvMOxorGZ1V41+3ttB TCgGKniCJ5+ye5NH0Ck6dc0K7oJKq9PnaQJkhhPG3vhsBPX4jlk1Hkuj2kOx8UIxbNGr 75RjGgqjp1dMUrCdpU5S53VoGGZ2grp+nwGBH6/P5Zsd2OrG+Q2qtsZj390PtU8GR8gY cfQw== X-Gm-Message-State: AB4q+uHBRmseBD5LY2LTt63fmP4kYVnMNT9031s+1fJsuAvAPQ3lxahe RUK+2ykO0nXjD13lxzciid0emmzaieJRACC6luK4GSA6KLlYc/FSiRRr8YBcLxfQNqCpkIGUFn9 fL5I= X-Gm-Gg: AZFdTZdQXyadNj3b99JeIBdslNm2kgqh2Y4upFDib4AVZtQmxwFzRbzedDl5Y8VPnbe JmapwX9z5jZZZsNxHjD0Cbm3RxuFMQFsvkKF471cUHaDQwkqCIAzLw126VANjfUYV7/ctYyg8jJ 9owPCgvEEDfPL8cPaVfQvHuv61I4DDn6tYSGx+e20oqUXunnR4YFkMyWkUy+iToRGPg6stazYlR GBhpkfEu7yJg5J+dH6QfEP5SL1gtesdgxxLRBTBjUtC2uzH+gMtVL++z6pGPlLO7YUrYSxRkZht IJFgn1xJ7it0cFEGwadDLXRRsHpCbLXOB5pSAk/CxMqQviitrbdAjpHUFMbjBqdfrSe+rAluEfL bUl3NOSGg6qPl5fu+GRw3uQxw3NrwMR5fp4fgCrjWCkdiwa4jnQuJqDTSJ4wGcNUoWR2JuQ0q0b EPE6dTx3MDaWPf7aT9O90sNK7xbjvz5a7oMB/awOus8FHekp6kvEcXVJFh6mRMLKztnIEYDhVBk AQZ4GQVc6ILTa/ZpdVXN8Bf1na6ia7XElr3wrxGwCd20Bu3u/RHZmbhpK1kvtolrKbipdDZbskf T9hbQc0BATexBS9RBd/YS74fGgqA087iyW++yyu7OVYGc0UthzMqZlJW57m0GLxl+R8= X-Received: by 2002:a05:693c:83da:20b0:386:95e7:8497 with SMTP id 5a478bee46e88-387521cb576mr2611805eec.28.1796413091791; Fri, 04 Dec 2026 11:38:11 -0800 (PST) Received: from localhost ([2a00:79e0:2e7c:8:965b:30a1:58ae:cf87]) by smtp.gmail.com with UTF8SMTPSA id 5a478bee46e88-387521f1360sm10291127eec.20.2026.12.04.11.38.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 11:38:11 -0800 (PST) Date: Fri, 4 Dec 2026 11:38:09 -0800 From: Brian Norris To: "Rafael J. Wysocki" 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=us-ascii Content-Disposition: inline In-Reply-To: <6056379.DvuYhMxLoT@rafael.j.wysocki> 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 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... ...we actually can dynamically increase rpm_active forever simply by calling pm_runtime_set_active() repeatedly. This feels less like a refcount and more like a bandaid over poor code structure. > Signed-off-by: Rafael J. Wysocki > --- > drivers/base/power/runtime.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > --- a/drivers/base/power/runtime.c > +++ b/drivers/base/power/runtime.c > @@ -334,13 +334,13 @@ void pm_runtime_release_supplier(struct > pm_runtime_mark_last_busy(supplier); > > /* > - * The additional power.usage_count check is a safety net in case > - * the rpm_active refcount becomes saturated, in which case > - * refcount_dec_not_one() would return true forever, but it is not > - * strictly necessary. > + * The rpm_active refcount value check is a safety net in > + * case it becomes saturated or underflows, which would cause > + * refcount_dec_not_one() to return true forever. A valid > + * rpm_active value cast to an int is always greater than 0. > */ > while (refcount_dec_not_one(&link->rpm_active) && > - atomic_read(&supplier->power.usage_count) > 0) > + (int)refcount_read(&link->rpm_active) > 0) > pm_runtime_put_noidle(supplier); > } > > > >