From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796413093; b=At3qTe62/W5cjreeaiB4rVbgGwD+lUeoFpfn9xxaETYQDKc1M3VABjtrDHEU1yW3DWvh 0P29k4lmj6sQJf2JWZ4NuOJ4xz/e0zT0CmSaJyiKMLdV46nZBCMeoQ7VmPoevf3QbfFxQ 9FgO6nlqiyWIuNVSHEEnAx2vxXx7H1QuCChnErEFCigC6gwGZKozXbG2f4Z5U21xsr8hw fvG+cHV+LafO7IErm6JAF0G0Y8eFL3dxSCrRzHlk3e9knArBq0fkRDVKQlZDh3lbmtBlX vgOFoCfgsOMWi2XEb7kfSrtsc3aMbvepmfMBFe+9AC/DG62i/RjquFeK6/Z3EVJFlQw== 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-Forwarded-Encrypted: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=eZZYg0req0mKTxn8AXbm3rk7F9athWN2OmNyRhjfT0QnCUeLc3HF1jV6LjnUd6KU0bjQ Y3GCqoYYEev33FXrD4M8abJIjmLOXFaUnCrULdKaQSOulySfEsbwWSfsH3bVNOTXYoxAr E2Xjp6fB8bNyC1T1ZztjFHHSvw9aERmYfb9egXbdXjhKsR+t7cAwOlLcOHoHs80n+lhvd 2zZO0mJLwFrP7bEmgh/YfnFc17RmhKzvbTEYTOY23XRfu+UnwbhLnW1qr9ATW0Oyfu4fE u0KNKwCNw1A7c2m7JW9K6XKFZL7+rv4WzdOU90XvNDMraLU/lsvhLwsM7u29CwrfCeg== 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=SlUBPN5Y; arc=none smtp.remote-ip=74.125.82.172 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (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 E1B4F606A32C for ; Fri, 4 Dec 2026 19:38:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E1B4F606A32C 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=SlUBPN5Y Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-38190551625so1510756eec.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=lists.linux.dev; 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=SlUBPN5YHog2dZV/pbN+wDW9zPt3MNgzGRRcLj1Ux6yeQbpJgOJhsiBOtptUf8RGbF Nq3YwhtZ4ibO1aDVAfVf3Mdwm/uHk8XB3yXQ7J6isCuSzLWvE8o6ARXsh0es7fBXB8bZ GMqHzFeV3Lb0F5klG0m3XlPCpbcsF839UK3SI= 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=sC5FdVfV2Z8rLCghP3C6+FzqqA4ibGbG9Egl7mEXyNRd40w81Zfu8aQ7hgbPuGKZGA 83axXw1Gbd4+fuImgQTQOyomT7jCOuwvZRq8xhLu9eBHRJztoRZ+VzesQHtJJoO53el/ DnILfsd5aWYjSH29k28xRlyZDO5M/7iQdEXkIxEjQJrKlleyXnQepZvx2vXtO/yUHfDZ Ty+7+4j4zo6Vvlvc7UShYfX6D4iKyTsWFKchgBre/oBEG4URCSJvmfu+gbjl+oYXz/ms hRUaqrFu5R/LCMTidwMkTz/eoi+mQdhoiufmT/22RhbyWMudnjfeb4sp5nYHYMESvjww Ey7w== X-Forwarded-Encrypted: i=1; AL+hErHadt07v2tR8SBzIUENdGoU3Zs4Ecu1FBmtGDlBN5RFW/fyrLeAiQIVvVXTqp+j3weZ2RuWRedFwwWClA==@lists.linux.dev X-Gm-Message-State: AB4q+uG+Q0NFKgTb14hrXvp5ZxB+1imxuEouI0pl8eWnhWliWyoNAqt/ mJ+0kSmOcaBzGA5PyajXf0vFA6LUpBlWNzEpiwcmIkDHAUXrrOyQAKw9JvHvlUFU1w== X-Gm-Gg: AZFdTZctRGS3DmZQojTezWQhoFspTECUUbuhaJKvPgNH2BOAfema86hF9Q8GLadXEg2 A9GPl36wpkm5MNjGZFFJzcad46juSW3cTod3YuRMuH5q8vMeyJYqVqKFne8WWJIw1gU7ljSWYcz /YC9+/YfgRf2G+5fkOO37MpQvOBhDiFikTuFJ4Cx4V3+2egrDlblbqy/ms52bMJHLpdm00X12vd fezeH0f011Cfv3kOG/tOo5gT6R2t4S5F2ue26UrvhywhpPQAbT6AYL/J39YErH0z2XZpGpcnDg6 q+JYfUHEnH+qys2FEkK8QsizRKf2jcSdI7utYGDSIInq6gOPPYC4Cx0cPLte2louuunGTEsXlVg 0bqESrzckF/g2IPSJ2n8iXiOPY0R9y3s1o8wsO1gFcr+P24MXCUoOdHOXek+37/qn4bUbB9ciBB oP8VXSidkry4YFzLXpK5Q87dK9SXLSlpdOqR4S0GycmGBdrTMFQiRTYl4Ht/Het41hTO72qLe5M KFWYuGjWvpKgRPiM/e146hGGKNthfIapQE9J3oEDH/zbXUkYHrRn09yfgo0xY70pG1pyFZ96aa2 TF1EV+X5mUqOPYzfuqdSp5WQ5DNoaVTqQdjFJYIHBPkKDfp0Pkc3OhE0rwLgeL0lyww= 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: driver-core@lists.linux.dev 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); > } > > > >