Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp26695pxb; Tue, 12 Apr 2022 15:49:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9ydaIjp/80wkgmnd8sNd8Pu1CWI/tjT5/1BLE+5sAfaLUHJtNqFlQrNE2WoED+Y4XXQQJ X-Received: by 2002:a05:6a00:1512:b0:505:da8c:26ba with SMTP id q18-20020a056a00151200b00505da8c26bamr8100359pfu.63.1649803784088; Tue, 12 Apr 2022 15:49:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649803784; cv=none; d=google.com; s=arc-20160816; b=kyqQY9RF6QpCcLJPhB0oBiLxibsoajXkHUcYcVgDxIbdKU8NJf+21eXftlFCbYYfZS 9tPkvokfCLDqtg6LI8oqVfCUQGGxP/U9M99KPcJWbKNHeK8p79J89YrbdG0k3cGzIV9a fslcbsGLAMBWHuBG1sB81Ym70jThAQP45MmjeQKl4+SF17+CkG6+n9+pbtqqgJdZ5I7F PB9JqDeoc1wpEbsyeHXChxsTsTsHrNaYz5qDJfWvhKvwNzaCZgKbNWGwUaE2NhyfIwzb LzX6PEA8mV0f+7v+mkgqufTtPr2oKfdQBGwKBN/CHCp00pL12i2JkSN7dtEEW7DvqCtv 5srg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=+UkpLblW1SxDWq4/v7EPOEjxoIVr/fJ5t6xgCjodwz4=; b=renveuEkWPqcog2myBRI8/QyNfz55dtnXagcESAZQwPwfschggQwL7GV425NXOxNCQ m567Pg0kyoOLzguGPQlUkqpdgwVhWwQHgBUExt9MYRGrF5c2UWEXpK/E79xZipGK+Tpt O+nKbFoIxVrx7PCB7zwm2G9NQn2w3M6N+j4+2B8rG7cdXTKWrOWf3Mi8qnGyeIm0AveJ fqQTDLZMOQvJvKzGWhWINjYEyWRGAdD6Mp7Kb48Cxxv5/ZSSI1Qc8oVw0YrME5O6NnJT eUxlrTSC2xV7+DTED1K2aZqj7q+A4mFDnOTC/B9zanorZxb7d+nXJAOZkyQMgSOdLkgq pv5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id z21-20020a634c15000000b003816043eea3si4002432pga.152.2022.04.12.15.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 15:49:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F15CF10F6D3; Tue, 12 Apr 2022 14:31:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343893AbiDKPUO (ORCPT + 99 others); Mon, 11 Apr 2022 11:20:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240410AbiDKPUM (ORCPT ); Mon, 11 Apr 2022 11:20:12 -0400 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51FE932076; Mon, 11 Apr 2022 08:17:58 -0700 (PDT) Received: by mail-yb1-f177.google.com with SMTP id g34so8146035ybj.1; Mon, 11 Apr 2022 08:17:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+UkpLblW1SxDWq4/v7EPOEjxoIVr/fJ5t6xgCjodwz4=; b=YHQzj1X4nZtYMaPyNfztxWY79MUlRIXNCNZdflDw+kn4aQOS1b0gJ4uD0Ucm3JTOJv 6kc/DgnCO2JrntjLzdWJKDCvsLwlc6A3ofY5GLmC5Dw+c1KsEvh7Zd/AXNNAT8ZXSCZK AHfuVs1WvdAMuINDGHuOENN22kUP5fWYEwVodtWwtZ5wyp0s8mayYAJhtBx79co41n40 zgVuB+gbd51ZjLSKCf1kOKFheXCeHwWv7LoNzOPBsSxfB0YMcqJamMtk3ymfuXNrqt5f zt/GpWoXhr+XdHTqgPCJO1SgcjqQTCHf7OANOEkNo7N2YHuqQjSEq311v2t91MINdKwL gG8Q== X-Gm-Message-State: AOAM531vidaL9nHdjTpZhnobBAkiEmKu0oKvm1oP4r+wYuUOdCJmmWET NfjyTzYt3kKQThuW8Y4gP7RQLhUdHanhdrPgRO9Q+RE/ X-Received: by 2002:a25:3cc3:0:b0:63e:6ee9:4840 with SMTP id j186-20020a253cc3000000b0063e6ee94840mr14606614yba.153.1649690277498; Mon, 11 Apr 2022 08:17:57 -0700 (PDT) MIME-Version: 1.0 References: <1836398.tdWV9SEqCh@kreacher> In-Reply-To: From: "Rafael J. Wysocki" Date: Mon, 11 Apr 2022 17:17:46 +0200 Message-ID: Subject: Re: [PATCH v1] PM: runtime: Avoid device usage count underflows To: Andy Shevchenko Cc: "Rafael J. Wysocki" , Linux PM , LKML , Ulf Hansson , Alan Stern Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 11, 2022 at 5:09 PM Andy Shevchenko wrote: > > On Wed, Apr 6, 2022 at 11:49 PM Rafael J. Wysocki wrote: > > > > From: Rafael J. Wysocki > > > > A PM-runtime device usage count underflow is potentially critical, > > because it may cause a device to be suspended when it is expected to > > be operational. > > > > For this reason, (1) make rpm_check_suspend_allowed() return an error > > when the device usage count is negative to prevent devices from being > > suspended in that case, (2) introduce rpm_drop_usage_count() that will > > detect device usage count underflows, warn about them and fix them up, > > and (3) use it to drop the usage count in a few places instead of > > atomic_dec_and_test(). > > ... > > > + retval = rpm_drop_usage_count(dev); > > + if (retval > 0) { > > trace_rpm_usage_rcuidle(dev, rpmflags); > > return 0; > > + } else if (retval < 0) { > > + return retval; > > } > > Can be written in a form > > if (retval < 0) > return retval; > if (retval > 0) { > trace_rpm_usage_rcuidle(dev, rpmflags); > return 0; > } > I know. And why would it be better?