From 1f9ba6f47ee0a75ac863e359fd74ac8762e2be7a Mon Sep 17 00:00:00 2001 From: deraadt Date: Tue, 15 Feb 2022 16:54:48 +0000 Subject: [PATCH] when the MI suspend code encounters problems, we need a way to reset the MD state before bailing out. New MD function sleep_abort() does that. --- sys/arch/arm64/dev/apm.c | 7 ++++++- sys/arch/macppc/dev/apm.c | 7 ++++++- sys/dev/acpi/acpi_x86.c | 10 +++++++++- sys/kern/subr_suspend.c | 15 +++++++++++---- sys/sys/device.h | 3 ++- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/sys/arch/arm64/dev/apm.c b/sys/arch/arm64/dev/apm.c index f50aef6e0b4..4b65791ff8f 100644 --- a/sys/arch/arm64/dev/apm.c +++ b/sys/arch/arm64/dev/apm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apm.c,v 1.13 2022/02/15 02:38:16 deraadt Exp $ */ +/* $OpenBSD: apm.c,v 1.14 2022/02/15 16:54:48 deraadt Exp $ */ /*- * Copyright (c) 2001 Alexander Guy. All rights reserved. @@ -382,6 +382,11 @@ gosleep(void *v) // XXX } +void +sleep_abort(void *v) +{ +} + int sleep_resume(void *v) { diff --git a/sys/arch/macppc/dev/apm.c b/sys/arch/macppc/dev/apm.c index ea912dd81d4..302f46e9336 100644 --- a/sys/arch/macppc/dev/apm.c +++ b/sys/arch/macppc/dev/apm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apm.c,v 1.29 2022/02/15 02:38:17 deraadt Exp $ */ +/* $OpenBSD: apm.c,v 1.30 2022/02/15 16:54:48 deraadt Exp $ */ /*- * Copyright (c) 2001 Alexander Guy. All rights reserved. @@ -369,6 +369,11 @@ sleep_setstate(void *v) return 0; } +void +sleep_abort(void *v) +{ +} + int sleep_resume(void *v) { diff --git a/sys/dev/acpi/acpi_x86.c b/sys/dev/acpi/acpi_x86.c index de9a7373210..c7756823abb 100644 --- a/sys/dev/acpi/acpi_x86.c +++ b/sys/dev/acpi/acpi_x86.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi_x86.c,v 1.5 2022/02/15 02:38:17 deraadt Exp $ */ +/* $OpenBSD: acpi_x86.c,v 1.6 2022/02/15 16:54:48 deraadt Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -135,6 +135,14 @@ gosleep(void *v) sc->sc_state = ACPI_STATE_S0; } +void +sleep_abort(void *v) +{ + struct acpi_softc *sc = v; + + sc->sc_state = ACPI_STATE_S0; +} + int sleep_resume(void *v) { diff --git a/sys/kern/subr_suspend.c b/sys/kern/subr_suspend.c index 6c34b27df89..c8c95573784 100644 --- a/sys/kern/subr_suspend.c +++ b/sys/kern/subr_suspend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_suspend.c,v 1.5 2022/02/15 02:38:18 deraadt Exp $ */ +/* $OpenBSD: subr_suspend.c,v 1.6 2022/02/15 16:54:48 deraadt Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -63,14 +63,17 @@ sleep_state(void *v, int sleepmode) uvmpd_hibernate(); if (hibernate_alloc()) { printf("failed to allocate hibernate memory\n"); + sleep_abort(v); goto fail_alloc; } } #endif /* HIBERNATE */ sensor_quiesce(); - if (config_suspend_all(DVACT_QUIESCE)) + if (config_suspend_all(DVACT_QUIESCE)) { + sleep_abort(v); goto fail_quiesce; + } vfs_stall(curproc, 1); #if NSOFTRAID > 0 @@ -103,13 +106,17 @@ sleep_state(void *v, int sleepmode) intr_disable(); /* PSL_I for resume; PIC/APIC broken until repair */ cold = 2; /* Force other code to delay() instead of tsleep() */ - if (config_suspend_all(DVACT_SUSPEND) != 0) + if (config_suspend_all(DVACT_SUSPEND) != 0) { + sleep_abort(v); goto fail_suspend; + } suspend_randomness(); - if (sleep_setstate(v)) + if (sleep_setstate(v)) { + sleep_abort(v); goto fail_pts; + } if (sleepmode == SLEEP_SUSPEND) { /* diff --git a/sys/sys/device.h b/sys/sys/device.h index a0d5a7d629f..bdae174cd4d 100644 --- a/sys/sys/device.h +++ b/sys/sys/device.h @@ -1,4 +1,4 @@ -/* $OpenBSD: device.h,v 1.59 2022/02/15 02:38:18 deraadt Exp $ */ +/* $OpenBSD: device.h,v 1.60 2022/02/15 16:54:48 deraadt Exp $ */ /* $NetBSD: device.h,v 1.15 1996/04/09 20:55:24 cgd Exp $ */ /* @@ -207,6 +207,7 @@ void resume_mp(void); int sleep_showstate(void *v, int sleepmode); int sleep_setstate(void *v); int sleep_resume(void *v); +void sleep_abort(void *v); void gosleep(void *v); void display_suspend(void *v); void display_resume(void *v); -- 2.20.1