From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796417464; b=rhrNM7NvR6ZPWUdRwhNMz2h8NM6K9PRYdiRX50o9JZb3HqFaRsSCxRExYu+duF05HSI4 sjnkf7MwOJNfRF5V3nHLssDv+z5l3lYnQ0Vpu8c2mfnMrXxcY316NaZAm5jJmyGwmRGXV X6uP70SEPcbcpHNBTvm9V740047KABK++BvbQ3ujggL2G7u1pwidL6WkLlRwTppeZcvEU T5DKv25xUOwxJO7il8VndBX/xPar9S/rKikv0lunUDrQN4qpU2lP/q4PS1SUv91OF/A5P qxuQMY87CRjF6pXdvjwiL4YtHpk1bAM186zkqRSWA4fHTLXtjt0URSXRdZ2EaODsQrQ== 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-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:Content-Transfer-Encoding: In-Reply-To; bh=lDW+RMOHJBwFpPQvST2hlqRXU8TTDjNSK3ChSMmEUPQ=; b=JkDb8mOCTgjDHIpyxDINa5PrqTRqnCa8wbWYUSvoUJbrBUz2ciwAzL7EIK/MehFpPSsf jxmhvKKk6VwpWbbk91Kl1xTM78yV6SDKR/G0a7yBj3SfGxNUsQpcnpAaMVwGeETrAmOXH hWgooI1BIFmBZOKI2aSMXsUrWMDvIraZuE2xNuWXUuCrhSEav0D+3CtLxvSrbUppb4dmj k8gAHPtdb7g31PXXI0qVxR6/ngUk93z/eq38TkefUsPq2IDkc7fRQe9qkDFl7kDh1gJUp CGbyl6kPBwneOFXZp+dIVmFMsMtADm2O6YBB61qlz9qUv6cGCTJ5CuoDNhxNcPe7X6A== 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=PzHtJ4rZ; arc=none smtp.remote-ip=74.125.82.49 Received: from mail-dl1-f49.google.com (mail-dl1-f49.google.com [74.125.82.49]) (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 20AEB606A322 for ; Fri, 4 Dec 2026 20:51:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 20AEB606A322 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=PzHtJ4rZ Received: by mail-dl1-f49.google.com with SMTP id a92af1059eb24-1b5ade5e0c1so2459841c88.1 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=lists.linux.dev; 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=PzHtJ4rZJ2IfYfVJ6js/AGQ45Ca/tzJAep0Ay2H9fNZNt1KdZhbfNIDb+06T0rNaIS 0ZGthIvxUqnR6O+mm3xUdsQlxiBUD6mNLV58aUNMR0YXWHhule9DqqEmU+ugZI4TSycV ifJQb5WqxLfH7YAsNfTdNM4LHQ0k6yXCtpZQs= 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=0PPxbRuVcrKx9e5I50arhksmX7OSah6xQIh0D85PqwYmZgmb/5RQ5LCCAWXMjKTBvf 2HJLDpTS0DT7WB3V7eIgvUgVFCmXawD8nD6NcAGZ46k1T/i39yxTfEEHZyY5hbFprpZS dLI3EsoJESwprptRI60ckLtTHcsaiHg53f0/DEezVZc/rNW69i6imoBhLVhF4FbfUMtT V7fC9qPJfna7TOhFSIQfXCmGDokzoonnL08SsJ5Arlg8a469WNBpkJtFF695syPPqJiC FaTrGjrtieCcjPXJffSn5gDgHzrCANOT3SfoJtEoj7VRpP8p1xq0DstPh0jBOCd+Sje7 dwQA== X-Forwarded-Encrypted: i=1; AL+hErHAOGK4fpYr/c4P8jMI/O9G2bKq78hmrAbRZ6IvD7hs+9gVX8QTf7RipCB/TjRQWRJumNrOgu7GvMvmAA==@lists.linux.dev X-Gm-Message-State: APuU4Z+hweC/tL+e9IYU8moCcmvmu9xaGhvgmqm6tz90s3/ezozzEytq nD+xXQ8rCKz8c+131EB8awy/uAHKdnHKAW5vlRpXYO2rcE3elHDmR0vFqeZnnk/agw== X-Gm-Gg: AZFdTZfEMLvEozb8oe2zXw6RvoiuVgQwSazRSl6VgGrFq6tPTyq7SLnFjfBosz8UUZT 565+zz3r9I4LubvhiiPqyNySVRr3ngOTB5+4zoXg4F1m/wBLHNJ/EotmMBM7djmpSldmr3DSOOA CN7xIMWOBEL55GSy0htrocgzn5LF8bk6SXPCl51IU65EOR3Q0Kze4qxCLR+MkCM8ryROQGoKxMV A00VfjQmWsnjyFStmDquSu+FTpdhI3Zma7Z9chrr7PSJn4mWJGbd4nCzEHy8K5P38ggaqsoY3nX HN8hhr/CgjGHwPk0VLgyuF8lTgt/7gr9EQijnUFtQzgGK0/FtBG+WMoPMMnuIWysHEhV3Y6jvvY JKpOhHmwgHPXb2pREXJ+cTn/aO5WlQjcLpbL2zUEZslIzfEwewEGA6E5r/2p2Cp2Kp8FD4KGmfR xcf6IydJXQmIGg8ZO92JTD21TKXINhAllKJ3D6ZX4Da9jutsU7CNM8EANgLkCFkeo4rdcZIIjby x5wB3kFQfyj4hJ0+gonJKdD4sncTRFo2/FQ9G21fen+vboMm3EkOzLSaOoA3NQ57iS4GrN5zIQz /9veP0z8OaDaHdOctpL0OMr9hWqIQgfyKDmAUDuLDhg4TOgRekiZw8I/KnlTKh8MN+HJPppsX3u ebtzZxRfLlQ4OSw== 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: 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=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