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=-11.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT 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 1C949C433E6 for ; Fri, 8 Jan 2021 22:23:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B7A8A23A74 for ; Fri, 8 Jan 2021 22:23:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B7A8A23A74 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 07D528D01BE; Fri, 8 Jan 2021 17:23:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 005568D01BD; Fri, 8 Jan 2021 17:23:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E106B8D01BE; Fri, 8 Jan 2021 17:23:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id C63438D01BD for ; Fri, 8 Jan 2021 17:23:01 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 90D34824556B for ; Fri, 8 Jan 2021 22:23:01 +0000 (UTC) X-FDA: 77684034162.23.step78_2906653274f6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 7307837606 for ; Fri, 8 Jan 2021 22:23:01 +0000 (UTC) X-HE-Tag: step78_2906653274f6 X-Filterd-Recvd-Size: 3624 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Fri, 8 Jan 2021 22:23:00 +0000 (UTC) IronPort-SDR: y8m498975iOeNW1uh+1l74b/mWYbSnKK89xuH5pBxn0vpYZKNT7ES6U/RAL03aZR0SREkBsrvc 0u+3jibXeBUA== X-IronPort-AV: E=McAfee;i="6000,8403,9858"; a="157443600" X-IronPort-AV: E=Sophos;i="5.79,332,1602572400"; d="scan'208";a="157443600" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2021 14:22:59 -0800 IronPort-SDR: inne7I/ttTGlK6FhJGrjlSnCkt68DVMtrUoWr9UxVXLC1ADl9ukwd2+bA27atxUv7mcL4Y7SBK PWIOzmEuBpLA== X-IronPort-AV: E=Sophos;i="5.79,332,1602572400"; d="scan'208";a="423091290" Received: from agluck-desk2.sc.intel.com ([10.3.52.68]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2021 14:22:58 -0800 From: Tony Luck To: Borislav Petkov Cc: Tony Luck , x86@kernel.org, Andrew Morton , Peter Zijlstra , Darren Hart , Andy Lutomirski , linux-kernel@vger.kernel.org, linux-edac@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 0/2] Fix infinite machine check loop in futex_wait_setup() Date: Fri, 8 Jan 2021 14:22:49 -0800 Message-Id: <20210108222251.14391-1-tony.luck@intel.com> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: Linux can now recover from machine checks where kernel code is doing get_user() to access application memory. But there isn't a way to distinguish whether get_user() failed because of a page fault or a machine check. Thus there is a problem if any kernel code thinks it can retry an access after doing something that would fix the page fault. One such example (I'm sure there are more) is in futex_wait_setup() where an attempt to read the futex with page faults disabled. Then a retry (after dropping a lock so page faults are safe): ret =3D get_futex_value_locked(&uval, uaddr); if (ret) { queue_unlock(*hb); ret =3D get_user(uval, uaddr); It would be good to avoid deliberately taking a second machine check (especially as the recovery code does really bad things and ends up in an infinite loop!). My proposal is to add a new function arch_memory_failure() that can be called after get_user() returns -EFAULT to allow graceful recovery. Futex reviewers: I just have one new call (that fixes my test case). If you could point out other places this is needed, that would be most helpful. Patch roadmap: Part 1: Add code to avoid the infinite loop in the machine check code. Just panic if code runs into the same machine check a second time. This should make it much easier to debug other places where this happens. Part 2: Add arch_memory_failure() and use it in futex_wait_setup(). [Suggestions gladly accepted for the current best way to handle the #defines etc. to define an arch specific function to be used in generic code] Tony Luck (2): x86/mce: Avoid infinite loop for copy from user recovery futex, x86/mce: Avoid double machine checks arch/x86/include/asm/mmu.h | 7 +++++++ arch/x86/kernel/cpu/mce/core.c | 17 ++++++++++++++++- include/linux/mm.h | 4 ++++ include/linux/sched.h | 3 ++- kernel/futex.c | 3 +++ 5 files changed, 32 insertions(+), 2 deletions(-) --=20 2.21.1