Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2178159yba; Mon, 15 Apr 2019 06:36:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvE/TP9tnUxOmRHdmWvFI5WmrGSJlWy5KjX0kxh/2kARXsiqQj2N6JA/RX42irjmVyl8lr X-Received: by 2002:a17:902:7885:: with SMTP id q5mr76515573pll.12.1555335379978; Mon, 15 Apr 2019 06:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555335379; cv=none; d=google.com; s=arc-20160816; b=KUp6JZwiVIQwgoEsoZsUUTvyu1fL+jRDJKv1HBviBnL1g74KE8lC0kZJsi9KFK8ClG vHjAo85HwZHh39YnWJ+d9iFbbjQncDSfU+qyDzlwMcTWWGzVGJSzZDbiZOlQk5kDnzkc m9qIeHPpeJI8KAd9FhI9zEtANJmautRhegIcHRdjiXUlhRuu8sbtewAAOWFNwAeWfLc6 hMGQk0tVvhED8QhJSRaUIaCDpqMuwtL916WqPnuYxU4P5iosDnzzvAW1FbVlATqRkR+J nDZm4xM7XzRxiFmJWLpZw4MjT2WnyqQzGBGY3nl3d4SzBSsxtyXt/Sy8wtgze6r3DLCF MO7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=JGJl9LxeuHKJGjkbkuCaBg1C6+gRKDdrkOfv5e9SNaE=; b=qqNtjADnqg/hwr47BLwoKFah5iBrq67O+d51StfFOvjt7HGXhBcAuYQ6sq10Jhdplx PssTQWsOoFjoes8EpDs+z70nYXkTOf5pOhcO9ermTZwzfIz/d1sgkaA5Wqnu1iaPazb5 iEOpX963yMsGWFVYLQtkwzirdybnbnKws1vJuqlkC3mIcrH949lr/TUqnoYQ9auq4wc8 6lbnrW3kLFx5BMhM+42xwklodvmREl3QK8KakRPuAqnolwuT/TXLKV2DXC3F/DxR/yLd lF7kl06f4dtfAMb6YZUuFNMBzdxeghTf2Oqcb5tX2LVpTpQYn9FV/+Z5zyD0I/TwcS5y XX2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j16si44879034pll.291.2019.04.15.06.36.03; Mon, 15 Apr 2019 06:36:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727397AbfDONf3 (ORCPT + 99 others); Mon, 15 Apr 2019 09:35:29 -0400 Received: from mga12.intel.com ([192.55.52.136]:14990 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727218AbfDONf2 (ORCPT ); Mon, 15 Apr 2019 09:35:28 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Apr 2019 06:35:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,353,1549958400"; d="scan'208";a="143099088" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.174]) by fmsmga007.fm.intel.com with SMTP; 15 Apr 2019 06:35:24 -0700 Received: by stinkbox (sSMTP sendmail emulation); Mon, 15 Apr 2019 16:35:24 +0300 Date: Mon, 15 Apr 2019 16:35:24 +0300 From: Ville =?iso-8859-1?Q?Syrj=E4l=E4?= To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Andi Kleen , "Rafael J. Wysocki" , Viresh Kumar , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Subject: Re: [REGRESSION 4.20-rc1] 45975c7d21a1 ("rcu: Define RCU-sched API in terms of RCU for Tree RCU PREEMPT builds") Message-ID: <20190415133524.GS3888@intel.com> References: <20181113135453.GW9144@intel.com> <20181113151037.GG4170@linux.ibm.com> <20181114202013.GA27603@linux.ibm.com> <20181126220122.GA6345@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20181126220122.GA6345@linux.ibm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 26, 2018 at 02:01:22PM -0800, Paul E. McKenney wrote: > On Wed, Nov 14, 2018 at 12:20:13PM -0800, Paul E. McKenney wrote: > > On Tue, Nov 13, 2018 at 07:10:37AM -0800, Paul E. McKenney wrote: > > > On Tue, Nov 13, 2018 at 03:54:53PM +0200, Ville Syrj?l? wrote: > > > > Hi Paul, > > > > > > > > After 4.20-rc1 some of my 32bit UP machines no longer reboot/shutdown. > > > > I bisected this down to commit 45975c7d21a1 ("rcu: Define RCU-sched > > > > API in terms of RCU for Tree RCU PREEMPT builds"). > > > > > > > > I traced the hang into > > > > -> cpufreq_suspend() > > > > -> cpufreq_stop_governor() > > > > -> cpufreq_dbs_governor_stop() > > > > -> gov_clear_update_util() > > > > -> synchronize_sched() > > > > -> synchronize_rcu() > > > > > > > > Only PREEMPT=y is affected for obvious reasons, but that couldn't > > > > explain why the same UP kernel booted on an SMP machine worked fine. > > > > Eventually I realized that the difference between working and > > > > non-working machine was IOAPIC vs. PIC. With initcall_debug I saw > > > > that we mask everything in the PIC before cpufreq is shut down, > > > > and came up with the following fix: > > > > > > > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > > > > index 7aa3dcad2175..f88bf3c77fc0 100644 > > > > --- a/drivers/cpufreq/cpufreq.c > > > > +++ b/drivers/cpufreq/cpufreq.c > > > > @@ -2605,4 +2605,4 @@ static int __init cpufreq_core_init(void) > > > > return 0; > > > > } > > > > module_param(off, int, 0444); > > > > -core_initcall(cpufreq_core_init); > > > > +late_initcall(cpufreq_core_init); > > > > > > Thank you for testing this and tracking it down! > > > > > > I am glad that you have a fix, but I hope that we can arrive at a less > > > constraining one. > > > > > > > Here's the resulting change in inutcall_debug: > > > > pci 0000:00:00.1: shutdown > > > > hub 4-0:1.0: hub_ext_port_status failed (err = -110) > > > > agpgart-intel 0000:00:00.0: shutdown > > > > + PM: Calling cpufreq_suspend+0x0/0x100 > > > > PM: Calling mce_syscore_shutdown+0x0/0x10 > > > > PM: Calling i8259A_shutdown+0x0/0x10 > > > > - PM: Calling cpufreq_suspend+0x0/0x100 > > > > + reboot: Restarting system > > > > + reboot: machine restart > > > > > > > > I didn't really look into what other ramifications the cpufreq > > > > initcall change might have. cpufreq_global_kobject worries > > > > me a bit. Maybe that one has to remain in core_initcall() and > > > > we could just move the suspend to late_initcall()? Anyways, > > > > I figured I'd leave this for someone more familiar with the > > > > code to figure out ;) > > > > > > Let me guess... > > > > > > When the system suspends or shuts down, there comes a point after which > > > there is only a single CPU that is running with preemption and interrupts > > > are disabled. At this point, RCU must change the way that it works, and > > > the commit you bisected to would make the change more necessary. But if > > > I am guessing correctly, we have just been getting lucky in the past. > > > > > > It looks like RCU needs to create a struct syscore_ops with a shutdown > > > function and pass this to register_syscore_ops(). Maybe a suspend > > > function as well. And RCU needs to invoke register_syscore_ops() at > > > a time that causes RCU's shutdown function to be invoked in the right > > > order with respect to the other work in flight. The hope would be that > > > RCU's suspend function gets called just as the system transitions into > > > a mode where the scheduler is no longer active, give or take. > > > > > > Does this make sense, or am I confused? > > > > Well, it certainly does not make sense in that blocking is still legal > > at .shutdown() invocation time, which means that RCU cannot revert to > > its boot-time approach at that point. Looks like I need hooks in a > > bunch of arch-dependent functions. Which is certainly doable, but will > > take a bit more digging. > > A bit more detail, after some additional discussion at Linux Plumbers > conference... > > The preferred approach is to hook into syscore_suspend(), > syscore_resume(), and syscore_shutdown(). This can be done easily by > creating an appropriately initialized struct syscore_ops and passing a > pointer to it to register_syscore_ops() during boot. Taking these three > functions in turn: > > syscore_suspend(): > > o arch/x86/kernel/apm_32.c suspend(), standby() > > These calls to syscore_suspend() has interrupts disabled, which > is very good, but they are immediately re-enabled, and only then > is the call to set_system_power_state(). Unless both interrupts > and preemption are prevented somehow, it is not safe for > CONFIG_PREEMPT=y RCU implementations to revert back to boot-time > behavior at this point. > > o drivers/xen/manage.c xen_suspend() > > This looks to have interrupts disabled throughout. It is also > invoked within stop_machine(), which means that the other CPUs, > though online, are quiescent. This allows RCU to safely switch > back to early boot operating mode. That is, this is safe only > if there is no interaction with RCU-preempt read-side critical > sections that might well be underway in the other CPUs. This > assumption is likely violated in CONFIG_PREEMPT=y kernels. One > alternative that would work with RCU in CONFIG_PREEMPT=y kernels > is CPU-hotplug removing all but one CPU, but that might have > some other disadvantages. > > o kernel/kexec_core.c kernel_kexec() > > Before we get here, disable_nonboot_cpus() has been invoked, which > in turn invokes freeze_secondary_cpus(), which offlines all but > the boot CPU. Prior to that, all user-space tasks are frozen. > So in this case, it would be safe for RCU to revert back to its > boot-time behavior. Aside from the possibility of unfreezable > kthreads being preempted within RCU-preempt read-side critical > sections, anyway... :-/ > > However, one can argue that as long as the kthreads preempted > within an RCU-preempt read-side critical section are guaranteed > to never ever run again, we might be OK. And this guarantee > seems consistent with the kernel_kexec() operation. At least > when there are no errors that cause the kernel_kexec() to return > control to the initial kernel image... > > Of course, this line of reasoning does not apply when the > kernel is to resume on the same hardware, as in some of the > cases above. > > o kernel/power/hibernate.c create_image() > > Same as for kernel_kexec(), except that freeze_kernel_threads() > is invoked, which hopefully gets all tasks out of RCU read-side > critical sections. So this one might actually permit RCU to > revert back to boot-time behavior. Except for the possibility of > an error condition forcing an abort back into the original kernel > image, which again could have trouble with kthreads that were > preempted within an RCU read-side critical section throughout. > > o kernel/power/hibernate.c resume_target_kernel() > kernel/power/hibernate.c hibernation_platform_enter() > kernel/power/suspend.c suspend_enter() > > Same as for kernel_kexec(), but no obvious pretense of freezing > any tasks. > > > syscore_resume(): > > o arch/x86/kernel/apm_32.c suspend(), standby() > > Resume-time counterparts to the calls to syscore_suspend() called > out above, with the same interrupt-enabling problem, as well as > issues with tasks being preempted throughout within RCU-preempt > read-side critical sections. > > o drivers/xen/manage.c xen_suspend() > > Resume-time counterpart to the calls to xen_suspend() called out > above, with the same issues with tasks being preempted throughout > within RCU-preempt read-side critical sections. > > o kernel/kexec_core.c kernel_kexec() > > Resume-time counterpart to the calls to kernel_kexec() called out > above. This is the error case that causes trouble due to the > possibility of preempted RCU read-side critical sections. > > o kernel/power/hibernate.c create_image() > kernel/power/hibernate.c resume_target_kernel() > kernel/power/hibernate.c hibernation_platform_enter() > kernel/power/hibernate.c suspend_enter() > > Resume-time counterparts to calls within kernel/power/hibernate.c > and kernel/power/suspend.c called out above. This is the error > case that causes trouble due to the possibility of preempted > RCU read-side critical sections. > > > syscore_shutdown(): > > o kernel/reboot.c kernel_restart() > kernel/reboot.c kernel_halt() > kernel/reboot.c kernel_power_off() > > These appears to leave all CPUs online, which prevents RCU from > safely reverting back to boot-time mode. > > > So what is to be done? > > Here are the options I can see: > > 1. Status quo, which means that synchronize_rcu() and friends > cannot be used in syscore_suspend(), syscore_resume(), and > syscore_shutdown() callbacks. At the moment, this appears to > be the only workable approach, though ideas and suggestions are > quite welcome. > > 2. Make each code path to syscore_suspend(), syscore_resume(), and > syscore_shutdown() offline all but the boot CPU, ensure that > all tasks exit any RCU read-side critical sections that they > might be in, then run the remainder of the code path on the > boot CPU with interrupts disabled. > > Making all tasks exit any RCU read-side critical sections is > easy when CONFIG_PREEMPT=n via things like stop-machine, but > it is difficult and potentially time-consuming for > CONFIG_PREEMPT=y kernels. > > 3. Do error checking so that there cannot possibly be failures > beyond the time that syscore_suspend(), syscore_resume(), > and syscore_shutdown() are invoked. This is fine for > syscore_shutdown() and syscore_resume(), but syscore_suspend()'s > callbacks are permitted to return errors that force suspend > failures. > > And there are syscore_suspend() callbacks that actually do > return errors, for example, fsl_lbc_syscore_suspend() > in arch/powerpc/sysdev/fsl_lbc.c can return -ENOMEM. > As can save_ioapic_entries() in arch/x86/kernel/apic/io_apic.c > and arch/x86/include/asm/io_apic.h. And mvebu_mbus_suspend() > in drivers/bus/mvebu-mbus.c. And iommu_suspend() in > drivers/iommu/intel-iommu.c. > > And its_save_disable() in drivers/irqchip/irq-gic-v3-its.c > can return -EBUSY. > > Perhaps these can be remedied somehow, but unless that can > be done, this approach cannot work. > > 4. Your idea here!!! Paul, are we any closer to fixing this regression? It's been around for far too long, and I'd like to stop carrying my original hack around. -- Ville Syrj?l? Intel