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=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no 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 D5062C433E0 for ; Tue, 12 Jan 2021 22:06:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 953AD221F5 for ; Tue, 12 Jan 2021 22:06:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394243AbhALWFy (ORCPT ); Tue, 12 Jan 2021 17:05:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390359AbhALWFu (ORCPT ); Tue, 12 Jan 2021 17:05:50 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1E31C0617A6 for ; Tue, 12 Jan 2021 14:04:57 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id b5so2595862pjk.2 for ; Tue, 12 Jan 2021 14:04:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=jp/uGViJd1rFyzqwINzBwHrML5ENBaR5RE09FM8y2rk=; b=o+tEsxdhzGCGsoHV1sIPiVSiNVm3QfIVPZgQqlc+JiLmlwrr+cGXF6VcEO68es1sR5 4sjbYAIz+6YaEKlIsPnQk8QRrpepwBATzotV7rf4CMiOf++gQk+lqxVKH9egpXJwTCL6 gKP+7N8kY+E30jdEsOcYcTtCficEYaP6PMEmbFX7nzUSo2B0UbrYxQDdRX2pO/Yb9o4+ 4N9s2VkD8ozP3B6Zmj0YpZpyxxa5e0UwbJWCZGP3We/ZOQpeUdbFwt/NL5zQ8b5Rf57o cHK6gDSbbSM3KeSMMbf+xAdzFvilac1HfRLY1UPA6ALiHMB9QIw3AgN1kZ5Zn0TdakUo /G5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=jp/uGViJd1rFyzqwINzBwHrML5ENBaR5RE09FM8y2rk=; b=NV/5uylo3fa2ES2OAYrfGkjHTxkMRi4VIhCaO/2NIz/r64ZgX8Ye7k1x115YZ5qhlv g5O7Qw2GvStsPurFMQo4Lft54nDtdyV4QwkoaO7GAEYop0QBaswrMsUSzSbR2M1ViAwE bDFvs2h7cs5M3IZzws1B+tEtyKfsD5PpPgrCaNPQ71vZe1N0AuifKR2VClO444E9XRUh TKGI/nL9VNVWLz5KWHkgeCoN2x5z6yIBL7z5VNOPTJSH1gOPwizFmLbbv8h9JNcfW4mI YABuNMsb5z4kOvtgc2x3X9rZrhIhhV6fdxsQsEBF0yY8+FL4lPIT29QAvMX0n5hjQLnl hCcg== X-Gm-Message-State: AOAM531p/tlWM/hM885GmCDxaAzrC3wSuJpjvEjJG8e45aq5OlE+TNL7 CdH2vX+x46Wl7R3BGuaxFEbh/UWa2v0Kow== X-Google-Smtp-Source: ABdhPJy4y2gxKCe1VUOnE5Taoj0S544T+thXTxi76Iku+7ZGDndJn6pDg/pwbWqNbphh8wYmDWx1Cg== X-Received: by 2002:a17:902:d385:b029:da:c6e4:5cab with SMTP id e5-20020a170902d385b02900dac6e45cabmr1450926pld.7.1610489097172; Tue, 12 Jan 2021 14:04:57 -0800 (PST) Received: from ?IPv6:2601:646:c200:1ef2:58cc:4dec:a37:4486? ([2601:646:c200:1ef2:58cc:4dec:a37:4486]) by smtp.gmail.com with ESMTPSA id s1sm79453pfb.103.2021.01.12.14.04.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Jan 2021 14:04:56 -0800 (PST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Andy Lutomirski Mime-Version: 1.0 (1.0) Subject: Re: [PATCH v2 1/3] x86/mce: Avoid infinite loop for copy from user recovery Date: Tue, 12 Jan 2021 14:04:55 -0800 Message-Id: <38AF04BE-7F39-450F-8C26-879C9934E3D6@amacapital.net> References: <20210112205207.GA18195@agluck-desk2.amr.corp.intel.com> Cc: Andy Lutomirski , Borislav Petkov , X86 ML , Andrew Morton , Peter Zijlstra , Darren Hart , LKML , linux-edac , Linux-MM In-Reply-To: <20210112205207.GA18195@agluck-desk2.amr.corp.intel.com> To: "Luck, Tony" X-Mailer: iPhone Mail (18C66) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Jan 12, 2021, at 12:52 PM, Luck, Tony wrote: >=20 > =EF=BB=BFOn Tue, Jan 12, 2021 at 10:57:07AM -0800, Andy Lutomirski wrote: >>> On Tue, Jan 12, 2021 at 10:24 AM Luck, Tony wrote:= >>>=20 >>> On Tue, Jan 12, 2021 at 09:21:21AM -0800, Andy Lutomirski wrote: >>>> Well, we need to do *something* when the first __get_user() trips the >>>> #MC. It would be nice if we could actually fix up the page tables >>>> inside the #MC handler, but, if we're in a pagefault_disable() context >>>> we might have locks held. Heck, we could have the pagetable lock >>>> held, be inside NMI, etc. Skipping the task_work_add() might actually >>>> make sense if we get a second one. >>>>=20 >>>> We won't actually infinite loop in pagefault_disable() context -- if >>>> we would, then we would also infinite loop just from a regular page >>>> fault, too. >>>=20 >>> Fixing the page tables inside the #MC handler to unmap the poison >>> page would indeed be a good solution. But, as you point out, not possibl= e >>> because of locks. >>>=20 >>> Could we take a more drastic approach? We know that this case the kernel= >>> is accessing a user address for the current process. Could the machine >>> check handler just re-write %cr3 to point to a kernel-only page table[1]= . >>> I.e. unmap the entire current user process. >>=20 >> That seems scary, especially if we're in the middle of a context >> switch when this happens. We *could* make it work, but I'm not at all >> convinced it's wise. >=20 > Scary? It's terrifying! >=20 > But we know that the fault happend in a get_user() or copy_from_user() cal= l > (i.e. an RIP with an extable recovery address). Does context switch > access user memory? No, but NMI can. The case that would be very very hard to deal with is if we get an NMI just b= efore IRET/SYSRET and get #MC inside that NMI. What we should probably do is have a percpu list of pending memory failure c= leanups and just accept that we=E2=80=99re going to sometimes get a second M= CE (or third or fourth) before we can get to it. Can we do the cleanup from an interrupt? IPI-to-self might be a credible ap= proach, if so.