Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2381880rwd; Wed, 14 Jun 2023 01:53:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6I3Czq3zaOtcqiMml4XXkslEAKMuBUypRhrm5N9HGARdI7ryb9ezrtH//6TzTnHs+Yw1rp X-Received: by 2002:a05:620a:28c8:b0:760:859a:d713 with SMTP id l8-20020a05620a28c800b00760859ad713mr11441815qkp.56.1686732802601; Wed, 14 Jun 2023 01:53:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686732802; cv=none; d=google.com; s=arc-20160816; b=wCfjMGCwrdvmGapbm37egvzcHRJ77cRnsPidYAUBxL/NSWKOO6qByq3l2Pn8RYDRmh AjJi9jZTMRbDvQD7STZodeRYCDzJJIxJM+Z4OD2UFkNCiXF78GX+wJZ3VUXBP/4lMBPa BchpIEa41khpm9M8/H6Zk6OqfUPPFgBVk9gWzzZ2kAHDLLIlds4paVPe/qVnPlUU4XDa +ZT7LiTv/O+qIlASLQvpJbnR/X9m333z+V9FGTzQ/2E67L828nyLCtsFTIBG6xNgbylH H/89MAM1MKaFH5Xo/YNBPobxAIo89/6QpBTx/YF6VJj3ZWGs8dc8lgfWX123ZiqOlwYZ Y78g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=zU7vTHGNGOkFDGHT4utTtg1onpxsh5x6oq5BFtksvGo=; b=P6duNXATMEpj/RMtuxF8rDx/07LnuolFiWBilxQVlQkME/TyJCNmMorDkQgiqpbDDq hEU1EI+lo5C7gwZ8zeN38NaBNITp/N1NThcJkTxDh8j0uuqX2wPsJ2LaFGTYaiKnLvuU A8FuGjdsnLW0dJqlbFAJjcEMNzu8IkYWfhjVJK1B/XP2TqcAhGZWZtv9KGC9m520HJf9 BOqOZrfJATf6Qd9p2P4ncp84TRn6N7LePmBaFZ3hcENjQ584sB6eJBMAhve81pGgNkOR FACFuEQhCMLhfiy9ooT8t/hxPDHEbg3HFD1rKuny5ax/qh5btlO2OxMR0cSFuhJ3LpKM g4Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=O0pXasE2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a056a00000300b00662a8b9b730si10264454pfk.200.2023.06.14.01.53.10; Wed, 14 Jun 2023 01:53:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=O0pXasE2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243640AbjFNIr7 (ORCPT + 99 others); Wed, 14 Jun 2023 04:47:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235409AbjFNIr6 (ORCPT ); Wed, 14 Jun 2023 04:47:58 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA8961BF8; Wed, 14 Jun 2023 01:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=zU7vTHGNGOkFDGHT4utTtg1onpxsh5x6oq5BFtksvGo=; b=O0pXasE2Kn5wmYU9m1T6l6fMbG at0qHfdy6UyepxXSgdmc1iFnPI/I4JVNrRgFni2pfrE/a7UB1xczcKCixSbQT/xVNE+z3NXpctRqZ H3gC9deJspth+OusfcDLWCrRQ+8ZOpnswLxjpOQCNXV7x9Mmks926o6PidaW+m8VouJmS03FUQ6FB /jf6nI581bwIIyZkgn0dO6SHZJZjhZt7Hv8qu3Dj/89vO5zYJ6cuNtUQa5t4e/SUBiwbZ0ZpGPyxU 9Qu/OqNVoXuo7LLRIRrr2dpLrjE6gjx6YGZyhgJqnBAyvQ0U6uiEtF3jR5WWn16N3wH5eePpLKQ+h pHdhXRMA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1q9MAB-005zdY-RS; Wed, 14 Jun 2023 08:47:36 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 137F73002F1; Wed, 14 Jun 2023 10:47:34 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 2337327F86A50; Wed, 14 Jun 2023 10:47:34 +0200 (CEST) Date: Wed, 14 Jun 2023 10:47:34 +0200 From: Peter Zijlstra To: "Rafael J. Wysocki" Cc: Linux ACPI , LKML , Linux PM , Srinivas Pandruvada , Will Deacon , Saket Dumbre , Xiaoming Ni Subject: Re: [PATCH v1] ACPI: sleep: Avoid breaking S3 wakeup due to might_sleep() Message-ID: <20230614084734.GD1639749@hirez.programming.kicks-ass.net> References: <12237421.O9o76ZdvQC@kreacher> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <12237421.O9o76ZdvQC@kreacher> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 Tue, Jun 13, 2023 at 05:25:07PM +0200, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > The addition of might_sleep() to down_timeout() caused the latter to > enable interrupts unconditionally in some cases, which in turn broke > the ACPI S3 wakeup path in acpi_suspend_enter(), where down_timeout() > is called by acpi_disable_all_gpes() via acpi_ut_acquire_mutex(). > > Namely, if CONFIG_DEBUG_ATOMIC_SLEEP is set, might_sleep() causes > might_resched() to be used and if CONFIG_PREEMPT_VOLUNTARY is set, > this triggers __cond_resched() which may call preempt_schedule_common(), > so __schedule() gets invoked and it ends up with enabled interrupts (in > the prev == next case). Urgh, so that code was relying on the lack of contention to not trigger the schedule path -- with the added might_sleep() it triggers a preemption point. > Now, enabling interrupts early in the S3 wakeup path causes the kernel > to crash. > > Address this by modifying acpi_suspend_enter() to disable GPEs without > attempting to acquire the sleeping lock which is not needed in that code > path anyway. > > Fixes: 99409b935c9a locking/semaphore: Add might_sleep() to down_*() family $ git show -s --pretty='format:%h ("%s")' 99409b935c9a 99409b935c9a ("locking/semaphore: Add might_sleep() to down_*() family") > Reported-by: Srinivas Pandruvada > Signed-off-by: Rafael J. Wysocki Acked-by: Peter Zijlstra (Intel) > --- > drivers/acpi/acpica/achware.h | 2 -- > drivers/acpi/sleep.c | 16 ++++++++++++---- > include/acpi/acpixf.h | 1 + > 3 files changed, 13 insertions(+), 6 deletions(-) > > Index: linux-pm/drivers/acpi/acpica/achware.h > =================================================================== > --- linux-pm.orig/drivers/acpi/acpica/achware.h > +++ linux-pm/drivers/acpi/acpica/achware.h > @@ -101,8 +101,6 @@ acpi_status > acpi_hw_get_gpe_status(struct acpi_gpe_event_info *gpe_event_info, > acpi_event_status *event_status); > > -acpi_status acpi_hw_disable_all_gpes(void); > - > acpi_status acpi_hw_enable_all_runtime_gpes(void); > > acpi_status acpi_hw_enable_all_wakeup_gpes(void); > Index: linux-pm/include/acpi/acpixf.h > =================================================================== > --- linux-pm.orig/include/acpi/acpixf.h > +++ linux-pm/include/acpi/acpixf.h > @@ -761,6 +761,7 @@ ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_sta > acpi_event_status > *event_status)) > ACPI_HW_DEPENDENT_RETURN_UINT32(u32 acpi_dispatch_gpe(acpi_handle gpe_device, u32 gpe_number)) > +ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_hw_disable_all_gpes(void)) > ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_disable_all_gpes(void)) > ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_enable_all_runtime_gpes(void)) > ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_enable_all_wakeup_gpes(void)) > Index: linux-pm/drivers/acpi/sleep.c > =================================================================== > --- linux-pm.orig/drivers/acpi/sleep.c > +++ linux-pm/drivers/acpi/sleep.c > @@ -636,11 +636,19 @@ static int acpi_suspend_enter(suspend_st > } > > /* > - * Disable and clear GPE status before interrupt is enabled. Some GPEs > - * (like wakeup GPE) haven't handler, this can avoid such GPE misfire. > - * acpi_leave_sleep_state will reenable specific GPEs later > + * Disable all GPE and clear their status bits before interrupts are > + * enabled. Some GPEs (like wakeup GPEs) have no handlers and this can > + * prevent them from producing spurious interrups. > + * > + * acpi_leave_sleep_state() will reenable specific GPEs later. > + * > + * Because this code runs on one CPU with disabled interrupts (all of > + * the other CPUs are offline at that time), it need not acquire any > + * sleeping locks which maybe harmful due to instrumentation even if > + * those locks are not contended, so avoid doing that by using a low- > + * level library routine here. I'm not sure I'd call the implicit preemption point 'instrumentation' but yeah, fair enough I suppose. > */ > - acpi_disable_all_gpes(); > + acpi_hw_disable_all_gpes(); > /* Allow EC transactions to happen. */ > acpi_ec_unblock_transactions(); > > > >