From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0523C33CB1 for ; Mon, 27 Jan 2020 10:28:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8402F20CC7 for ; Mon, 27 Jan 2020 10:28:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LjQf5sS1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8402F20CC7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F012A6B0003; Mon, 27 Jan 2020 05:28:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E8A056B0006; Mon, 27 Jan 2020 05:28:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D53616B0007; Mon, 27 Jan 2020 05:28:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0096.hostedemail.com [216.40.44.96]) by kanga.kvack.org (Postfix) with ESMTP id BB8E76B0003 for ; Mon, 27 Jan 2020 05:28:25 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8ECCC2461 for ; Mon, 27 Jan 2020 10:28:25 +0000 (UTC) X-FDA: 76423039770.01.fang87_83b3f34d27730 X-HE-Tag: fang87_83b3f34d27730 X-Filterd-Recvd-Size: 9358 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Mon, 27 Jan 2020 10:28:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580120904; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dsIS5pv+qF2vd3zrStw1LzoG/gRx2VeIgO2U3opeBJM=; b=LjQf5sS1a5bfudmz3Va+dagVz2+I9Am5hPd1QehZlh6rsjnL3NY0DoCOkF8XclMo/FxgoM 0fL6PMe/50XVjqKVdhBlq5omzEkgw0947E5NQdozHhuDfD6jZQXGOMIJFk5u3JdUSCHjpa By3SRAxSGnelVJ+5ImBlQK4BIKUudQY= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-120-3fuKZmewPSCyujT-qlZTSA-1; Mon, 27 Jan 2020 05:28:22 -0500 Received: by mail-wm1-f69.google.com with SMTP id z7so751164wmi.0 for ; Mon, 27 Jan 2020 02:28:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=8fokyBNPtsUbKBwZwksoLlR7AFo3Aw5I+PUuhOyENIk=; b=TBFYvdy/EYx1ingQCCYvxhKmuxkoZ9IRWssdix54NQJ+jCt0NLH7xTo4M+EXbiaV5u 5a360BzJv5Bb3Zgaghmrij4Ha9riwirgEmIhdj/EMwKEMdFc557NXpOtZrmizAglfRPy ym17o7fK9VeqDJEs+MTGPb37ZGREwNM+qDc78Vn/WaezrwYR9l0EHAJXCd45Uv3bfa18 1OCy1f0Wotw3dSgEy/sple4nSkJOONDQ5BvmgbUv0XfozsNGF6IxdwcNYueH81aNX2uk DRcp/VzRovu0YgYWh5HUYhJle2mAzvQuQO2akhpydgvo75vfUbs1h1IGAdODGiw2qOtz xbkg== X-Gm-Message-State: APjAAAVCVLP91CKO4iZTdn36SIdyi7DBqb7AunLW+I5ZRP6roprWwk9a wXySIHfGFPeO1p8OoB5BQK4fuL36e4Z5u5dmmf0KoufgfNw79FilULhEGkRPEgVt8QZolGN266K Rr9G6PxMogLk= X-Received: by 2002:adf:dc86:: with SMTP id r6mr20825663wrj.68.1580120900257; Mon, 27 Jan 2020 02:28:20 -0800 (PST) X-Google-Smtp-Source: APXvYqwLWleqqkTYz3vNYvSYX+2oj8y2inl971E8faKn2s20ZKZi1w9g3+F4v+wDDCi6S9HVQPkd7Q== X-Received: by 2002:adf:dc86:: with SMTP id r6mr20825596wrj.68.1580120899785; Mon, 27 Jan 2020 02:28:19 -0800 (PST) Received: from localhost (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id b10sm21694800wrt.90.2020.01.27.02.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 02:28:19 -0800 (PST) Date: Mon, 27 Jan 2020 11:28:18 +0100 From: Oleksandr Natalenko To: Grzegorz Halat Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, ssaner@redhat.com, atomlin@redhat.com, vbendel@redhat.com, kirill@shutemov.name, khlebnikov@yandex-team.ru, borntraeger@de.ibm.com, Andrew Morton , Iurii Zaikin , Kees Cook , Luis Chamberlain , Jonathan Corbet Subject: Re: [PATCH 1/1] mm: sysctl: add panic_on_mm_error sysctl Message-ID: <20200127102818.7hr5shcskfbwa7eu@butterfly.localdomain> References: <20200127101100.92588-1-ghalat@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200127101100.92588-1-ghalat@redhat.com> X-MC-Unique: 3fuKZmewPSCyujT-qlZTSA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Jan 27, 2020 at 11:11:00AM +0100, Grzegorz Halat wrote: > Memory management subsystem performs various checks at runtime, > if an inconsistency is detected then such event is being logged and kerne= l > continues to run. While debugging such problems it is helpful to collect > memory dump as early as possible. Currently, there is no easy way to pani= c > kernel when such error is detected. >=20 > It was proposed[1] to panic the kernel if panic_on_oops is set but this > approach was not accepted. One of alternative proposals was introduction = of > a new sysctl. >=20 > The patch adds panic_on_mm_error sysctl. If the sysctl is set then the > kernel will be crashed when an inconsistency is detected by memory > management. This currently means panic when bad page or bad PTE > is detected(this may be extended to other places in MM). >=20 > Another use case of this sysctl may be in security-wise environments, > it may be more desired to crash machine than continue to run with > potentially damaged data structures. >=20 > [1] https://marc.info/?l=3Dlinux-mm&m=3D142649500728327&w=3D2 >=20 > Signed-off-by: Grzegorz Halat > --- > Documentation/admin-guide/sysctl/kernel.rst | 12 ++++++++++++ > include/linux/kernel.h | 1 + > kernel/sysctl.c | 9 +++++++++ > mm/memory.c | 7 +++++++ > mm/page_alloc.c | 4 +++- > 5 files changed, 32 insertions(+), 1 deletion(-) >=20 > diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/= admin-guide/sysctl/kernel.rst > index def074807cee..2fecd6b2547e 100644 > --- a/Documentation/admin-guide/sysctl/kernel.rst > +++ b/Documentation/admin-guide/sysctl/kernel.rst > @@ -61,6 +61,7 @@ show up in /proc/sys/kernel: > - overflowgid > - overflowuid > - panic > +- panic_on_mm_error > - panic_on_oops > - panic_on_stackoverflow > - panic_on_unrecovered_nmi > @@ -611,6 +612,17 @@ an IO error. > and you can use this option to take a crash dump. > =20 > =20 > +panic_on_mm_error: > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > + > +Controls the kernel's behaviour when inconsistency is detected > +by memory management code, for example bad page state or bad PTE. > + > +0: try to continue operation. > + > +1: panic immediately. > + > + > panic_on_oops: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > =20 > diff --git a/include/linux/kernel.h b/include/linux/kernel.h > index 0d9db2a14f44..5f9d408512ff 100644 > --- a/include/linux/kernel.h > +++ b/include/linux/kernel.h > @@ -518,6 +518,7 @@ extern int oops_in_progress;=09=09/* If set, an oops,= panic(), BUG() or die() is in > extern int panic_timeout; > extern unsigned long panic_print; > extern int panic_on_oops; > +extern int panic_on_mm_error; > extern int panic_on_unrecovered_nmi; > extern int panic_on_io_nmi; > extern int panic_on_warn; > diff --git a/kernel/sysctl.c b/kernel/sysctl.c > index 70665934d53e..6477e1cce28b 100644 > --- a/kernel/sysctl.c > +++ b/kernel/sysctl.c > @@ -1238,6 +1238,15 @@ static struct ctl_table kern_table[] =3D { > =09=09.extra1=09=09=3D SYSCTL_ZERO, > =09=09.extra2=09=09=3D SYSCTL_ONE, > =09}, > +=09{ > +=09=09.procname=09=3D "panic_on_mm_error", > +=09=09.data=09=09=3D &panic_on_mm_error, > +=09=09.maxlen=09=09=3D sizeof(int), > +=09=09.mode=09=09=3D 0644, > +=09=09.proc_handler=09=3D proc_dointvec_minmax, > +=09=09.extra1=09=09=3D SYSCTL_ZERO, > +=09=09.extra2=09=09=3D SYSCTL_ONE, > +=09}, > #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON) > =09{ > =09=09.procname=09=3D "timer_migration", > diff --git a/mm/memory.c b/mm/memory.c > index 45442d9a4f52..cce74ff39447 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -71,6 +71,7 @@ > #include > #include > #include > +#include > =20 > #include > =20 > @@ -88,6 +89,8 @@ > #warning Unfortunate NUMA and NUMA Balancing config, growing page-frame = for last_cpupid. > #endif > =20 > +int panic_on_mm_error __read_mostly; > + > #ifndef CONFIG_NEED_MULTIPLE_NODES > /* use the per-pgdat data instead for discontigmem - mbligh */ > unsigned long max_mapnr; > @@ -543,6 +546,10 @@ static void print_bad_pte(struct vm_area_struct *vma= , unsigned long addr, > =09=09 vma->vm_ops ? vma->vm_ops->fault : NULL, > =09=09 vma->vm_file ? vma->vm_file->f_op->mmap : NULL, > =09=09 mapping ? mapping->a_ops->readpage : NULL); > + > +=09print_modules(); > +=09if (panic_on_mm_error) > +=09=09panic("Bad page map detected"); > =09dump_stack(); > =09add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); > } > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index d047bf7d8fd4..2ea6a65ba011 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -643,9 +643,11 @@ static void bad_page(struct page *page, const char *= reason, > =09if (bad_flags) > =09=09pr_alert("bad because of flags: %#lx(%pGp)\n", > =09=09=09=09=09=09bad_flags, &bad_flags); > -=09dump_page_owner(page); > =20 > +=09dump_page_owner(page); > =09print_modules(); > +=09if (panic_on_mm_error) > +=09=09panic("Bad page state detected"); > =09dump_stack(); > out: > =09/* Leave bad fields for debug, except PageBuddy could make trouble */ > --=20 > 2.21.1 >=20 Reviewed-by: Oleksandr Natalenko --=20 Best regards, Oleksandr Natalenko (post-factum) Senior Software Maintenance Engineer