Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2401566pxj; Mon, 17 May 2021 00:19:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHN8WD5FHhlAwtM92swebaSFTs3QqdfSyDHlZHo6FRm9oi1dvOygQ7CS3MrvZssKkh+4ka X-Received: by 2002:a05:6638:2643:: with SMTP id n3mr54836793jat.104.1621235947935; Mon, 17 May 2021 00:19:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621235947; cv=none; d=google.com; s=arc-20160816; b=lVA9+djk7iRlITXa4Ow+k6mTGLGLeFKV0LT64iMKwJ8cIIxuCN9IkmlRitrm+gScGG SadIUBZHw29cJG8uqdNSZJjRoUSq4CC5Zx+6DuEaR+Ls5upw40fMAJZGdQtcCIV0xC0t +qffnGvMCijHBYtLDZTnZG0sR/mt0rAPEhFAiChsrH+xnaZx2cE0IDOCjgAYQ8kcLh31 9+aFP5UV6a3ghPCptwJ4E8hweBCM++bZTcvlBvUT8FDcbVE8DPjKtnELA7H5lz72f9Wh +xAOTuRQEIx+zEw5HWO8Rv4Rp0I0Hbm1M4s7a8rZKVoDT0ILzD22PRO2cXid6eGLTmIA P4lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:user-agent:date :mime-version:references:in-reply-to:cc:to:reply-to:from:subject :message-id; bh=ZlBxGhYLZ60uGDaPOSr/zz7izf5PGo7iYr82/TiNDOQ=; b=BiZtDEdOih/DA4o+wDJZjbudLz8SH2gNlB89byfxtYGdj3rG1FQO63MRiMduzQueTx u9JNjbtnY0vdMQWVXWLdi/LNc/uDASRKkwPr8L+/ymzn7nIoFrTNh1Ia+1s8gvvIF195 YlyJNol3vH8N/CB0KGyq7wucM8AR8feO/XvBij/mTW+zZ+7jHiu2zw5igT14HX2WPhyl /jHOVU8fSyTi0cuvHcpb9vuWcT93ctEIgZPyiqhx3FifYJfnK0pwU6KIRAqFIvWMJ47S IViv5ZdjYi9006kYVbeBVumyJ4flb/GCsQPJCZZ/KDKMBUZJDUfi6vR2o+6ufiJ9xQJO Ccdg== ARC-Authentication-Results: i=1; mx.google.com; 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 f11si19122396ila.138.2021.05.17.00.18.55; Mon, 17 May 2021 00:19:07 -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; 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 S233693AbhEQE6k (ORCPT + 99 others); Mon, 17 May 2021 00:58:40 -0400 Received: from mail-lf1-f43.google.com ([209.85.167.43]:46894 "EHLO mail-lf1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbhEQE6j (ORCPT ); Mon, 17 May 2021 00:58:39 -0400 Received: by mail-lf1-f43.google.com with SMTP id i9so6759350lfe.13; Sun, 16 May 2021 21:57:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:reply-to:to:cc :in-reply-to:references:mime-version:date:user-agent :content-transfer-encoding; bh=ZlBxGhYLZ60uGDaPOSr/zz7izf5PGo7iYr82/TiNDOQ=; b=E+zP2LSMSbK65WxXy9THvknp5RylijQ7mfAxj5iwLuA63uOVbTCjdSsNakY2CFRo3w LOnsYBxw4rOJEBDxwkyHOhU8e3PhrV3jhAQEcg8v2PGCJA+bI6NQcBeUAvYHdZwsiiIo ORJg3fGAzaAf0EQH0cJAE4MsmWLVI3XlqFH9/Vm3w88MPoz9bY6vH1hSOZ4T73d46E4G 3BBNsMlzByFJb+O4NTJFY4gVg/V6ycwj/H0goTNZrGlmbrLiGbRW1KEiuaHWyzl8boEj 6uOrAtWE6cnAAJ2JZCYo4G4VycAS94EsWbjjBuqDdZlSHZkHwllHup3jUZ0QME1yOKNH FSSA== X-Gm-Message-State: AOAM531qw2B2rIgSesCMiMuLiYHI9jX9yZ3DTIqvI5Gc66Tq2hiYlbOa /4/FE+fdz+l3t4Q5Ox08GS4= X-Received: by 2002:ac2:54ba:: with SMTP id w26mr41231726lfk.78.1621227440658; Sun, 16 May 2021 21:57:20 -0700 (PDT) Received: from dc7vkhyyyyyyyyyyyyyby-3.rev.dnainternet.fi (dc7vkhyyyyyyyyyyyyyby-3.rev.dnainternet.fi. [2001:14ba:16e2:8300::2]) by smtp.gmail.com with ESMTPSA id g28sm2775163ljn.134.2021.05.16.21.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 May 2021 21:57:19 -0700 (PDT) Message-ID: Subject: Re: [PATCH v9 02/10] reboot: Add hardware protection power-off From: Matti Vaittinen Reply-To: matti.vaittinen@fi.rohmeurope.com To: Petr Mladek Cc: "josef@toxicpanda.com" , "keescook@chromium.org" , "rppt@kernel.org" , "linux-arm-msm@vger.kernel.org" , linux-power , "linux-kernel@vger.kernel.org" , "bjorn.andersson@linaro.org" , "rui.zhang@intel.com" , "linux-renesas-soc@vger.kernel.org" , "devicetree@vger.kernel.org" , "akpm@linux-foundation.org" , "linux@roeck-us.net" , "daniel.lezcano@linaro.org" , "lgirdwood@gmail.com" , "robh+dt@kernel.org" , "kai.heng.feng@canonical.com" , "mcroce@microsoft.com" , "amitk@kernel.org" , "linux-pm@vger.kernel.org" , "andy.shevchenko@gmail.com" , "agross@kernel.org" , "broonie@kernel.org" , "rafael.j.wysocki@intel.com" , rostedt@goodmis.org, Geert Uytterhoeven In-Reply-To: References: <97260f8e150abb898a262fade25860609b460912.1620645507.git.matti.vaittinen@fi.rohmeurope.com> <2149df3f542d25ce15d049e81d6188bb7198478c.camel@fi.rohmeurope.com> Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Mon, 17 May 2021 07:57:11 +0300 User-Agent: Evolution 3.34.4 (3.34.4-1.fc31) Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2021-05-13 at 10:34 +0200, Petr Mladek wrote: > On Wed 2021-05-12 12:00:46, Vaittinen, Matti wrote: > > On Wed, 2021-05-12 at 10:20 +0200, Petr Mladek wrote: > > > On Mon 2021-05-10 14:28:30, Matti Vaittinen wrote: > > > > There can be few cases when we need to shut-down the system in > > > > order to > > > > protect the hardware. Currently this is done at east by the > > > > thermal > > > > core > > > > when temperature raises over certain limit. > > > > > > > > Some PMICs can also generate interrupts for example for over- > > > > current or > > > > over-voltage, voltage drops, short-circuit, ... etc. On some > > > > systems > > > > these are a sign of hardware failure and only thing to do is > > > > try to > > > > protect the rest of the hardware by shutting down the system. > > > > > > > > Add shut-down logic which can be used by all subsystems instead > > > > of > > > > implementing the shutdown in each subsystem. The logic is > > > > stolen > > > > from > > > > thermal_core with difference of using atomic_t instead of a > > > > mutex > > > > in > > > > order to allow calls directly from IRQ context. > > > > > > > > Signed-off-by: Matti Vaittinen < > > > > matti.vaittinen@fi.rohmeurope.com> > > > > > > > > diff --git a/kernel/reboot.c b/kernel/reboot.c > > > > index a6ad5eb2fa73..5da8c80a2647 100644 > > > > --- a/kernel/reboot.c > > > > +++ b/kernel/reboot.c > > > > @@ -518,6 +519,85 @@ void orderly_reboot(void) > > > > } > > > > EXPORT_SYMBOL_GPL(orderly_reboot); > > > > > > > > +/** > > > > + * hw_failure_emergency_poweroff_func - emergency poweroff > > > > work > > > > after a known delay > > > > + * @work: work_struct associated with the emergency poweroff > > > > function > > > > + * > > > > + * This function is called in very critical situations to > > > > force > > > > + * a kernel poweroff after a configurable timeout value. > > > > + */ > > > > +static void hw_failure_emergency_poweroff_func(struct > > > > work_struct > > > > *work) > > > > +{ > > > > + /* > > > > + * We have reached here after the emergency shutdown > > > > waiting > > > > period has > > > > + * expired. This means orderly_poweroff has not been > > > > able to > > > > shut off > > > > + * the system for some reason. > > > > + * > > > > + * Try to shut down the system immediately using > > > > kernel_power_off > > > > + * if populated > > > > + */ > > > > + WARN(1, "Hardware protection timed-out. Trying forced > > > > poweroff\n"); > > > > + kernel_power_off(); > > > > > > WARN() look like an overkill here. It prints many lines that are > > > not > > > much useful in this case. The function is called from well-known > > > context (workqueue worker). > > > > This was the existing code which I stole from the thermal_core. I > > kind > > of think that eye-catching WARN is actually a good choice here. > > Doing > > autonomous power-off without a WARNing does not sound good to me :) > > > > > Also be aware that "panic_on_warn" commandline option will > > > trigger > > > panic() here. > > > > Hmm.. If panic() hangs the system that might indeed be a problem. > > Now > > we are (again) on a territory which I don't know well. I'd > > appreciate > > any input from thermal folks and Mark. I don't like the idea of > > making > > extreme things like power-off w/o well visible log-trace. Thus I > > would > > like to have WARN()-like eye-catcher, even if the call-trace was > > not > > too varying. It will at least point to this worker. Any better > > suggestions than WARN()? > > Heh, it might make sense to create a system wide API for these. I am > sure that WARN() is mis-used this way on many other locations. > > There already are two locations that use another eye-catching text. > A common API might help to avoid duplication of the common parts, > see > https://lore.kernel.org/lkml/20210305194206.3165917-2-elver@google.com/ > > Well, it might be out of scope for this patchset. I just had a very brief "chat" with Geert (3 IRC messages, posted during 4 or 5 days :]) - and Geert pointed me to this: https://lore.kernel.org/linux-iommu/20210331093104.383705-4-geert+renesas@glider.be/ So, maybe I'll just go with simple pr_emerg() and trust that the emerg() print should catch attention as such level print probably should. I'll respin the patch series (probably tomorrow) - let's see what thermal and regulator folks say :) Thanks for all the help this far! Best Regards Matti Vaittinen