Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2045534pxb; Sun, 17 Oct 2021 04:34:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaA7PA9sgigwUB5mNC6TLrxRdRtVydB5deupDER4D78sY696LHcyS1IdM5COu/HO29tT4j X-Received: by 2002:a05:6a00:1346:b0:44d:242a:8151 with SMTP id k6-20020a056a00134600b0044d242a8151mr22493222pfu.62.1634470475029; Sun, 17 Oct 2021 04:34:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634470475; cv=none; d=google.com; s=arc-20160816; b=qkutTJt5LhXI4nM+YEbd4jCf8M0ksj79/rPo1MbOxib8CEs6Or38X3S/CBSWDM941y MAeNwsr6RGLoDCm2U6xLawbpV5FuLMZizXUd98PMQPFZ+BBkizjp0dJC1m8CX/GKh+N3 18HUSBcwTf3da9k/9kCkUxy3JbLLlB5uugbqizXl9j+qR67JjfGD1ed04eWzUDCTRINW sEdvTO0C3wH+JvyVPzflJGBGChCiqxEjDv3+WlGiT0NbgUbN7cHy2uWcJjy4vtOOdNvO hsWPkkOAMjdbYeVIkMg/yIE1eZboQzEf0FvB3ptIuY5CQSr6qbQ3JLU90/UKniTL6pPz 5Okw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vO4AeleHyDlG4sZ9O9ST1SyXfBpPO0Go4V2dXx639d4=; b=LmTrivZ1InwH2NJ49bWPE/H9pSdq07ACZxOxkt85X7gAdeAUG+kl4oRWkRmuPrMLBd 6UAmejiz94AB6d+1xmtrhSUBPUUfEwYrWkOBtDnQudaOy/F3hJZ3ysmepGoR4WYXyVJN DvY5jEdf67RpUy8X6d1J2bBRpW8pHLGHCudmfOLVBdGoM+tW1eXKEcSlmgAiqJbSiA6r 3iPWrc9dpGB6cUefqjOfXaQDXhh6mD1jkPtBX+xzNvwANdMawDExMaoxRsCToHV6CCYc blXqp9KPxaBjIJsSDZWry2s+ctSG1BxdywpoXT5Na8G7GUQb0xAYU8uqzbFgu3qwwPDa poBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id il9si28813200pjb.170.2021.10.17.04.34.22; Sun, 17 Oct 2021 04:34:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241956AbhJORHB (ORCPT + 99 others); Fri, 15 Oct 2021 13:07:01 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:54332 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241952AbhJORG5 (ORCPT ); Fri, 15 Oct 2021 13:06:57 -0400 Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 3.0.0) id b0d89b5bf84f41b0; Fri, 15 Oct 2021 19:04:49 +0200 Received: from kreacher.localnet (unknown [213.134.175.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id CA68A66A8C0; Fri, 15 Oct 2021 19:04:48 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: Linux PM , LKML , Mika Westerberg , Linux PCI Subject: [PATCH v1 1/3] ACPI: PM: Turn off unused wakeup power resources Date: Fri, 15 Oct 2021 19:01:28 +0200 Message-ID: <4657519.GXAFRqVoOG@kreacher> In-Reply-To: <4347933.LvFx2qVVIh@kreacher> References: <4347933.LvFx2qVVIh@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 213.134.175.255 X-CLIENT-HOSTNAME: 213.134.175.255 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvtddrvddugedguddtjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdejlefghfeiudektdelkeekvddugfeghffggeejgfeukeejleevgffgvdeluddtnecukfhppedvudefrddufeegrddujeehrddvheehnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehinhgvthepvddufedrudefgedrudejhedrvdehhedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehmihhkrgdrfigvshhtvghrsggvrhhgsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthht oheplhhinhhugidqphgtihesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki If an ACPI power resource is found to be "on" during the initialization of the list of wakeup power resources of a device, it is reference counted and its wakeup_enabled flag is set, which is problematic if the deivce in question is the only user of the given power resource, it is never runtime-suspended and it is not allowed to wake up the system from sleep, because in that case the given power resource will stay "on" until the system reboots and energy will be wasted. It is better to simply turn off wakeup power resources that are "on" during the initialization unless their reference counters are not zero, because that may be the only opportunity to prevent them from staying in the "on" state all the time. Fixes: b5d667eb392e ("ACPI / PM: Take unusual configurations of power resources into account") Signed-off-by: Rafael J. Wysocki --- drivers/acpi/power.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) Index: linux-pm/drivers/acpi/power.c =================================================================== --- linux-pm.orig/drivers/acpi/power.c +++ linux-pm/drivers/acpi/power.c @@ -615,20 +615,19 @@ int acpi_power_wakeup_list_init(struct l list_for_each_entry(entry, list, node) { struct acpi_power_resource *resource = entry->resource; - int result; u8 state; mutex_lock(&resource->resource_lock); - result = acpi_power_get_state(resource, &state); - if (result) { - mutex_unlock(&resource->resource_lock); - return result; - } - if (state == ACPI_POWER_RESOURCE_STATE_ON) { - resource->ref_count++; - resource->wakeup_enabled = true; - } + /* + * Make sure that the power resource state and its reference + * counter value are consistent with each other. + */ + if (!resource->ref_count && + !acpi_power_get_state(resource, &state) && + state == ACPI_POWER_RESOURCE_STATE_ON) + __acpi_power_off(resource); + if (system_level > resource->system_level) system_level = resource->system_level;