Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1000705ybt; Fri, 19 Jun 2020 21:10:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy68cUmv89Akw0mewQZzvlkvbf6kCl53bcmlKmIDO7iHBW/SpzylTPytEpHFtmoQkqPZE6g X-Received: by 2002:a17:906:5006:: with SMTP id s6mr6332919ejj.294.1592626221914; Fri, 19 Jun 2020 21:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592626221; cv=none; d=google.com; s=arc-20160816; b=tnt7pFT2Qsu8eDiOQo1k5VMcM3NLRUia39CkO2nPsbnNgr3viVe3fcOmPGHLQTBd5i 0BqLw1jl1VCHALR8bDEOcQ/1FFDTZ7OcYr7Ranxhv8bva1XoYv1vh6CvP1eEPj332AUK wGNjzWUDCp2JZy5dpRGOiGTcWS95ojzdl9Kzxm8xkCPe5/2H14xLMWl443DHhwhTZy9H eiWI958gG56PE8SkGPwsyIH2FUzhOWJbcDMDkGEPPXABj5xrU+U0rXHP5na7fbp4TNch JZYk/jZ+HpUyqMhedYA9M4g0i6Lm8esSb8nuIlyRMC4mtM8WQs6B/fDpDv0D/bBRxmf9 7R4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=I60h6ZiU1dcmm4PNks6ubJ5eApGVXhl8lsh4J9Q8OYA=; b=vElM5pLqSZHgfK+vLbkpR/IJdOADZEB19Y3r99G4LQ1FwZjIsRH2HIMamOkBHHy22s qqMl8tTDtRIRnFgL5fyMuWJmHzJ5kU1IFnhHAyJBz7aohuzXnHqybfM0I8zE/W4h8Zw2 xy2eRH7PqyCi4lp2KhShgFVZfn3mgn7aj+l2/tW2GlWrk5RO9zZCzeuN9issknIk4AQh 2Up+JJYvLfQSxGoiQRtUw8l6AnMBKVePff+ypaMgxx9RcwA2Rr/899CqYdu+IRF3gAXg bpjFPzmpGdh1ITlYZwSZTZdO0N6gQD7/ri33/yqAE6iYMypsJMbJDNzZp1XW26vHioR8 bI7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TMV7LW5+; 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 a21si4981421ejf.332.2020.06.19.21.09.58; Fri, 19 Jun 2020 21:10:21 -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; dkim=pass header.i=@kernel.org header.s=default header.b=TMV7LW5+; 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 S2389371AbgFSQsi (ORCPT + 99 others); Fri, 19 Jun 2020 12:48:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:58024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387677AbgFSOkN (ORCPT ); Fri, 19 Jun 2020 10:40:13 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8DF9E2166E; Fri, 19 Jun 2020 14:40:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592577613; bh=rHEGSsmEbjmH3vajWhmh1dtXlPV0gEnOdJBy5TGALE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TMV7LW5+3GxlI41YnBkHb5NTOg8FRkpG1QuF5MJGosCy9/CjE0l7l3VkvR/F7BjM1 HBzEUB5kTp80SZVQ+l5jp4ewxMQ4IEFowC5hVmkBNFDP64fA+wB6PmfHDkROnjnTcJ ECFOR5lyzs7T99znsyCGnTKY9DikBm/GgY7VXyDw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans de Goede , youling257@gmail.com, "Rafael J. Wysocki" Subject: [PATCH 4.9 019/128] ACPI: PM: Avoid using power resources if there are none for D0 Date: Fri, 19 Jun 2020 16:31:53 +0200 Message-Id: <20200619141621.196369073@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141620.148019466@linuxfoundation.org> References: <20200619141620.148019466@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki commit 956ad9d98b73f59e442cc119c98ba1e04e94fe6d upstream. As recently reported, some platforms provide a list of power resources for device power state D3hot, through the _PR3 object, but they do not provide a list of power resources for device power state D0. Among other things, this causes acpi_device_get_power() to return D3hot as the current state of the device in question if all of the D3hot power resources are "on", because it sees the power_resources flag set and calls acpi_power_get_inferred_state() which finds that D3hot is the shallowest power state with all of the associated power resources turned "on", so that's what it returns. Moreover, that value takes precedence over the acpi_dev_pm_explicit_get() return value, because it means a deeper power state. The device may very well be in D0 physically at that point, however. Moreover, the presence of _PR3 without _PR0 for a given device means that only one D3-level power state can be supported by it. Namely, because there are no power resources to turn "off" when transitioning the device from D0 into D3cold (which should be supported since _PR3 is present), the evaluation of _PS3 should be sufficient to put it straight into D3cold, but this means that the effect of turning "on" the _PR3 power resources is unclear, so it is better to avoid doing that altogether. Consequently, there is no practical way do distinguish D3cold from D3hot for the device in question and the power states of it can be labeled so that D3hot is the deepest supported one (and Linux assumes that putting a device into D3hot via ACPI may cause power to be removed from it anyway, for legacy reasons). To work around the problem described above modify the ACPI enumeration of devices so that power resources are only used for device power management if the list of D0 power resources is not empty and make it mart D3cold as supported only if that is the case and the D3hot list of power resources is not empty too. Fixes: ef85bdbec444 ("ACPI / scan: Consolidate extraction of power resources lists") Link: https://bugzilla.kernel.org/show_bug.cgi?id=205057 Link: https://lore.kernel.org/linux-acpi/20200603194659.185757-1-hdegoede@redhat.com/ Reported-by: Hans de Goede Tested-by: Hans de Goede Tested-by: youling257@gmail.com Cc: 3.10+ # 3.10+ Signed-off-by: Rafael J. Wysocki Reviewed-by: Hans de Goede Signed-off-by: Greg Kroah-Hartman --- drivers/acpi/device_pm.c | 2 +- drivers/acpi/scan.c | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -171,7 +171,7 @@ int acpi_device_set_power(struct acpi_de * possibly drop references to the power resources in use. */ state = ACPI_STATE_D3_HOT; - /* If _PR3 is not available, use D3hot as the target state. */ + /* If D3cold is not supported, use D3hot as the target state. */ if (!device->power.states[ACPI_STATE_D3_COLD].flags.valid) target_state = state; } else if (!device->power.states[state].flags.valid) { --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -927,12 +927,9 @@ static void acpi_bus_init_power_state(st if (buffer.length && package && package->type == ACPI_TYPE_PACKAGE - && package->package.count) { - int err = acpi_extract_power_resources(package, 0, - &ps->resources); - if (!err) - device->power.flags.power_resources = 1; - } + && package->package.count) + acpi_extract_power_resources(package, 0, &ps->resources); + ACPI_FREE(buffer.pointer); } @@ -979,14 +976,27 @@ static void acpi_bus_get_power_flags(str acpi_bus_init_power_state(device, i); INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources); - if (!list_empty(&device->power.states[ACPI_STATE_D3_HOT].resources)) - device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1; - /* Set defaults for D0 and D3hot states (always valid) */ + /* Set the defaults for D0 and D3hot (always supported). */ device->power.states[ACPI_STATE_D0].flags.valid = 1; device->power.states[ACPI_STATE_D0].power = 100; device->power.states[ACPI_STATE_D3_HOT].flags.valid = 1; + /* + * Use power resources only if the D0 list of them is populated, because + * some platforms may provide _PR3 only to indicate D3cold support and + * in those cases the power resources list returned by it may be bogus. + */ + if (!list_empty(&device->power.states[ACPI_STATE_D0].resources)) { + device->power.flags.power_resources = 1; + /* + * D3cold is supported if the D3hot list of power resources is + * not empty. + */ + if (!list_empty(&device->power.states[ACPI_STATE_D3_HOT].resources)) + device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1; + } + if (acpi_bus_init_power(device)) device->flags.power_manageable = 0; }