Skip to content

Commit bf0cc83

Browse files
committed
Merge branches 'pm-core', 'pm-pci', 'pm-sleep', 'pm-domains' and 'powercap'
* pm-core: PM: runtime: Add documentation for pm_runtime_resume_and_get() PM: runtime: Replace inline function pm_runtime_callbacks_present() PM: core: Remove duplicate declaration from header file * pm-pci: PCI: PM: Do not read power state in pci_enable_device_flags() * pm-sleep: PM: wakeup: remove redundant assignment to variable retval PM: hibernate: x86: Use crc32 instead of md5 for hibernation e820 integrity check PM: wakeup: use dev_set_name() directly PM: sleep: fix typos in comments freezer: Remove unused inline function try_to_freeze_nowarn() * pm-domains: PM: domains: Don't runtime resume devices at genpd_prepare() * powercap: powercap: RAPL: Fix struct declaration in header file MAINTAINERS: Add DTPM subsystem maintainer powercap: Add Hygon Fam18h RAPL support
6 parents dd9f2ae + 2c41233 + 4514d99 + e488023 + c1df456 + 35eb1f5 commit bf0cc83

16 files changed

Lines changed: 41 additions & 135 deletions

File tree

Documentation/power/runtime_pm.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
339339
checked additionally, and -EACCES means that 'power.disable_depth' is
340340
different from 0
341341

342+
`int pm_runtime_resume_and_get(struct device *dev);`
343+
- run pm_runtime_resume(dev) and if successful, increment the device's
344+
usage counter; return the result of pm_runtime_resume
345+
342346
`int pm_request_idle(struct device *dev);`
343347
- submit a request to execute the subsystem-level idle callback for the
344348
device (the request is represented by a work item in pm_wq); returns 0 on

MAINTAINERS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14312,6 +14312,15 @@ F: include/linux/pm_*
1431214312
F: include/linux/powercap.h
1431314313
F: kernel/configs/nopm.config
1431414314

14315+
DYNAMIC THERMAL POWER MANAGEMENT (DTPM)
14316+
M: Daniel Lezcano <daniel.lezcano@kernel.org>
14317+
L: linux-pm@vger.kernel.org
14318+
S: Supported
14319+
B: https://bugzilla.kernel.org
14320+
T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
14321+
F: drivers/powercap/dtpm*
14322+
F: include/linux/dtpm.h
14323+
1431514324
POWER STATE COORDINATION INTERFACE (PSCI)
1431614325
M: Mark Rutland <mark.rutland@arm.com>
1431714326
M: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>

arch/x86/kernel/e820.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
* - inform the user about the firmware's notion of memory layout
3232
* via /sys/firmware/memmap
3333
*
34-
* - the hibernation code uses it to generate a kernel-independent MD5
35-
* fingerprint of the physical memory layout of a system.
34+
* - the hibernation code uses it to generate a kernel-independent CRC32
35+
* checksum of the physical memory layout of a system.
3636
*
3737
* - 'e820_table_kexec': a slightly modified (by the kernel) firmware version
3838
* passed to us by the bootloader - the major difference between

arch/x86/power/hibernate.c

Lines changed: 14 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <linux/kdebug.h>
1414
#include <linux/cpu.h>
1515
#include <linux/pgtable.h>
16-
17-
#include <crypto/hash.h>
16+
#include <linux/types.h>
17+
#include <linux/crc32.h>
1818

1919
#include <asm/e820/api.h>
2020
#include <asm/init.h>
@@ -54,95 +54,33 @@ int pfn_is_nosave(unsigned long pfn)
5454
return pfn >= nosave_begin_pfn && pfn < nosave_end_pfn;
5555
}
5656

57-
58-
#define MD5_DIGEST_SIZE 16
59-
6057
struct restore_data_record {
6158
unsigned long jump_address;
6259
unsigned long jump_address_phys;
6360
unsigned long cr3;
6461
unsigned long magic;
65-
u8 e820_digest[MD5_DIGEST_SIZE];
62+
unsigned long e820_checksum;
6663
};
6764

68-
#if IS_BUILTIN(CONFIG_CRYPTO_MD5)
6965
/**
70-
* get_e820_md5 - calculate md5 according to given e820 table
66+
* compute_e820_crc32 - calculate crc32 of a given e820 table
7167
*
7268
* @table: the e820 table to be calculated
73-
* @buf: the md5 result to be stored to
69+
*
70+
* Return: the resulting checksum
7471
*/
75-
static int get_e820_md5(struct e820_table *table, void *buf)
72+
static inline u32 compute_e820_crc32(struct e820_table *table)
7673
{
77-
struct crypto_shash *tfm;
78-
struct shash_desc *desc;
79-
int size;
80-
int ret = 0;
81-
82-
tfm = crypto_alloc_shash("md5", 0, 0);
83-
if (IS_ERR(tfm))
84-
return -ENOMEM;
85-
86-
desc = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(tfm),
87-
GFP_KERNEL);
88-
if (!desc) {
89-
ret = -ENOMEM;
90-
goto free_tfm;
91-
}
92-
93-
desc->tfm = tfm;
94-
95-
size = offsetof(struct e820_table, entries) +
74+
int size = offsetof(struct e820_table, entries) +
9675
sizeof(struct e820_entry) * table->nr_entries;
9776

98-
if (crypto_shash_digest(desc, (u8 *)table, size, buf))
99-
ret = -EINVAL;
100-
101-
kfree_sensitive(desc);
102-
103-
free_tfm:
104-
crypto_free_shash(tfm);
105-
return ret;
106-
}
107-
108-
static int hibernation_e820_save(void *buf)
109-
{
110-
return get_e820_md5(e820_table_firmware, buf);
111-
}
112-
113-
static bool hibernation_e820_mismatch(void *buf)
114-
{
115-
int ret;
116-
u8 result[MD5_DIGEST_SIZE];
117-
118-
memset(result, 0, MD5_DIGEST_SIZE);
119-
/* If there is no digest in suspend kernel, let it go. */
120-
if (!memcmp(result, buf, MD5_DIGEST_SIZE))
121-
return false;
122-
123-
ret = get_e820_md5(e820_table_firmware, result);
124-
if (ret)
125-
return true;
126-
127-
return memcmp(result, buf, MD5_DIGEST_SIZE) ? true : false;
128-
}
129-
#else
130-
static int hibernation_e820_save(void *buf)
131-
{
132-
return 0;
133-
}
134-
135-
static bool hibernation_e820_mismatch(void *buf)
136-
{
137-
/* If md5 is not builtin for restore kernel, let it go. */
138-
return false;
77+
return ~crc32_le(~0, (unsigned char const *)table, size);
13978
}
140-
#endif
14179

14280
#ifdef CONFIG_X86_64
143-
#define RESTORE_MAGIC 0x23456789ABCDEF01UL
81+
#define RESTORE_MAGIC 0x23456789ABCDEF02UL
14482
#else
145-
#define RESTORE_MAGIC 0x12345678UL
83+
#define RESTORE_MAGIC 0x12345679UL
14684
#endif
14785

14886
/**
@@ -179,7 +117,8 @@ int arch_hibernation_header_save(void *addr, unsigned int max_size)
179117
*/
180118
rdr->cr3 = restore_cr3 & ~CR3_PCID_MASK;
181119

182-
return hibernation_e820_save(rdr->e820_digest);
120+
rdr->e820_checksum = compute_e820_crc32(e820_table_firmware);
121+
return 0;
183122
}
184123

185124
/**
@@ -200,7 +139,7 @@ int arch_hibernation_header_restore(void *addr)
200139
jump_address_phys = rdr->jump_address_phys;
201140
restore_cr3 = rdr->cr3;
202141

203-
if (hibernation_e820_mismatch(rdr->e820_digest)) {
142+
if (rdr->e820_checksum != compute_e820_crc32(e820_table_firmware)) {
204143
pr_crit("Hibernate inconsistent memory map detected!\n");
205144
return -ENODEV;
206145
}

drivers/base/power/domain.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,34 +1087,6 @@ static void genpd_sync_power_on(struct generic_pm_domain *genpd, bool use_lock,
10871087
genpd->status = GENPD_STATE_ON;
10881088
}
10891089

1090-
/**
1091-
* resume_needed - Check whether to resume a device before system suspend.
1092-
* @dev: Device to check.
1093-
* @genpd: PM domain the device belongs to.
1094-
*
1095-
* There are two cases in which a device that can wake up the system from sleep
1096-
* states should be resumed by genpd_prepare(): (1) if the device is enabled
1097-
* to wake up the system and it has to remain active for this purpose while the
1098-
* system is in the sleep state and (2) if the device is not enabled to wake up
1099-
* the system from sleep states and it generally doesn't generate wakeup signals
1100-
* by itself (those signals are generated on its behalf by other parts of the
1101-
* system). In the latter case it may be necessary to reconfigure the device's
1102-
* wakeup settings during system suspend, because it may have been set up to
1103-
* signal remote wakeup from the system's working state as needed by runtime PM.
1104-
* Return 'true' in either of the above cases.
1105-
*/
1106-
static bool resume_needed(struct device *dev,
1107-
const struct generic_pm_domain *genpd)
1108-
{
1109-
bool active_wakeup;
1110-
1111-
if (!device_can_wakeup(dev))
1112-
return false;
1113-
1114-
active_wakeup = genpd_is_active_wakeup(genpd);
1115-
return device_may_wakeup(dev) ? active_wakeup : !active_wakeup;
1116-
}
1117-
11181090
/**
11191091
* genpd_prepare - Start power transition of a device in a PM domain.
11201092
* @dev: Device to start the transition of.
@@ -1135,14 +1107,6 @@ static int genpd_prepare(struct device *dev)
11351107
if (IS_ERR(genpd))
11361108
return -EINVAL;
11371109

1138-
/*
1139-
* If a wakeup request is pending for the device, it should be woken up
1140-
* at this point and a system wakeup event should be reported if it's
1141-
* set up to wake up the system from sleep states.
1142-
*/
1143-
if (resume_needed(dev, genpd))
1144-
pm_runtime_resume(dev);
1145-
11461110
genpd_lock(genpd);
11471111

11481112
if (genpd->prepared_count++ == 0)

drivers/base/power/wakeup_stats.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static struct device *wakeup_source_device_create(struct device *parent,
137137
struct wakeup_source *ws)
138138
{
139139
struct device *dev = NULL;
140-
int retval = -ENODEV;
140+
int retval;
141141

142142
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
143143
if (!dev) {
@@ -154,7 +154,7 @@ static struct device *wakeup_source_device_create(struct device *parent,
154154
dev_set_drvdata(dev, ws);
155155
device_set_pm_not_required(dev);
156156

157-
retval = kobject_set_name(&dev->kobj, "wakeup%d", ws->id);
157+
retval = dev_set_name(dev, "wakeup%d", ws->id);
158158
if (retval)
159159
goto error;
160160

drivers/pci/pci.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,20 +1870,10 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags)
18701870
int err;
18711871
int i, bars = 0;
18721872

1873-
/*
1874-
* Power state could be unknown at this point, either due to a fresh
1875-
* boot or a device removal call. So get the current power state
1876-
* so that things like MSI message writing will behave as expected
1877-
* (e.g. if the device really is in D0 at enable time).
1878-
*/
1879-
if (dev->pm_cap) {
1880-
u16 pmcsr;
1881-
pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
1882-
dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
1883-
}
1884-
1885-
if (atomic_inc_return(&dev->enable_cnt) > 1)
1873+
if (atomic_inc_return(&dev->enable_cnt) > 1) {
1874+
pci_update_current_state(dev, dev->current_state);
18861875
return 0; /* already enabled */
1876+
}
18871877

18881878
bridge = pci_upstream_bridge(dev);
18891879
if (bridge)

drivers/powercap/intel_rapl_common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ static const struct x86_cpu_id rapl_ids[] __initconst = {
10691069

10701070
X86_MATCH_VENDOR_FAM(AMD, 0x17, &rapl_defaults_amd),
10711071
X86_MATCH_VENDOR_FAM(AMD, 0x19, &rapl_defaults_amd),
1072+
X86_MATCH_VENDOR_FAM(HYGON, 0x18, &rapl_defaults_amd),
10721073
{}
10731074
};
10741075
MODULE_DEVICE_TABLE(x86cpu, rapl_ids);

drivers/powercap/intel_rapl_msr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ static int rapl_msr_probe(struct platform_device *pdev)
150150
case X86_VENDOR_INTEL:
151151
rapl_msr_priv = &rapl_msr_priv_intel;
152152
break;
153+
case X86_VENDOR_HYGON:
153154
case X86_VENDOR_AMD:
154155
rapl_msr_priv = &rapl_msr_priv_amd;
155156
break;

include/linux/freezer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ static inline int freeze_kernel_threads(void) { return -ENOSYS; }
279279
static inline void thaw_processes(void) {}
280280
static inline void thaw_kernel_threads(void) {}
281281

282-
static inline bool try_to_freeze_nowarn(void) { return false; }
283282
static inline bool try_to_freeze(void) { return false; }
284283

285284
static inline void freezer_do_not_count(void) {}

0 commit comments

Comments
 (0)