Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3296865pxb; Tue, 12 Jan 2021 10:59:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwy/Vdk9rfaobXWC5nV3v7P7UsYv0jdS7zjbiyk704jqJcTM8qTfBNPSPnWuciJNUYJ1jl2 X-Received: by 2002:a17:906:a015:: with SMTP id p21mr179069ejy.49.1610477972136; Tue, 12 Jan 2021 10:59:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610477972; cv=none; d=google.com; s=arc-20160816; b=aMwA7q9g50HwTgASdTzhmGyH+N0LdK0aiF212XRvxQRrjFOHp/WPBR1qkEhYNW0YeT m/efme0O/Uey4W9Vudijk46Ba7nITcQPE1PpIYIQ57B2CgkgOQDzOFTi5d3eJ4LlE3+v n0Cq3tXPcBDgAkABjVaIHQFQhVTVZImdoVFglu/aP37PSH3fLK4jIwD91f9BiZJEB+zV 02cOyV7LDrczs5qACmKV6XdUgzcuvJ0hiFUegVEwKAK66LSCKOuYynOnb9KwS/o5LmcQ Mw2vvVAT2ZifM7m8QSbbXaJfJ2nMp6hVXZJvOlXdbukbUGdmlDoTtTBYaCzeyvwR6ONK uQuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qPxMWdb8ceRtslCNjqHuE87waDwF864UBakV0oNZPsU=; b=Vmvdl1UmppCWYTLtlNNgcj10ZJ/mUCYCgo+6F5d5FEE1qcuNnYvpSDWeCCumfWGh5z L7cQCnNzDBwUpZ5bYAdrZwyYmv8b2CHfqbKJY2/WskZOXll4YcN2aX5xUvXYLuK1p4Fb 3Rip9KmTNNWACAtKiiCTVzMsP5Vla9kttllyWzDCTsQAFgNBxPXp42TyPVBumdzb2RJJ BiWA6rhMCbVx4fS69djzWQqY1l3I8mPuCRk4CEoXxPEan5clKhrfjDWCXrV+vZvdN2rl 3vVUigTsqmWXfYvCbwoE6RH+tdq8cQd+KZ23eMTL1cqqEkybzveMN5qksTXraMIhB+DH tbmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="akkICKT/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r19si1699062edw.476.2021.01.12.10.59.07; Tue, 12 Jan 2021 10:59:32 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="akkICKT/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391486AbhALS6C (ORCPT + 99 others); Tue, 12 Jan 2021 13:58:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:39780 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729923AbhALS6C (ORCPT ); Tue, 12 Jan 2021 13:58:02 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 05FE22312E for ; Tue, 12 Jan 2021 18:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610477841; bh=qEYVDk2n6QAVg4WiGfYhBfpW3XJsw9qR39XuOVUrciE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=akkICKT/Ad1+870Mo6C2vghRidlTMaKmJyNl9M3MMg0Fj46tM11WaA419Hhkk6V53 Y76vH9U9+o6fwMpBm5zF9zniwc1rHCwxpOtoaaZJOB+IP2Zs7bzJHqFiYpQy6fdgzn OXExcIx/yV8f/cHkLWoFe1aQWJWkcEZ2CEK+d6h78BYHqpCPz9WOzAhnzKsWkFZsAA hfiSiM/ojga59/QNwXP4vMssZ+hCY6P+ArpQl2bFv08mEY7iShrx8Qvoio+hu3hsbe 0ydLXWwnLCfak5swkmlY11jSIbDjoHanbfiSGew0uoAQSvWq3SBX42pxrrqBGwDl1M M5cnfEkJqhApA== Received: by mail-ej1-f53.google.com with SMTP id q22so5042556eja.2 for ; Tue, 12 Jan 2021 10:57:20 -0800 (PST) X-Gm-Message-State: AOAM533JqgtRbZO1rnhzzwsrGC0leMXQIBBdOGpw4Rw46AdrtMW+FgM4 SyEDtq3PjgaFPCRFhyjJVScSWB7Au3pdcNEgf9Z+Xw== X-Received: by 2002:a17:906:351a:: with SMTP id r26mr174708eja.204.1610477839172; Tue, 12 Jan 2021 10:57:19 -0800 (PST) MIME-Version: 1.0 References: <20210111214452.1826-2-tony.luck@intel.com> <20210111222057.GA2369@agluck-desk2.amr.corp.intel.com> <20210112171628.GA15664@agluck-desk2.amr.corp.intel.com> <20210112182357.GA16390@agluck-desk2.amr.corp.intel.com> In-Reply-To: <20210112182357.GA16390@agluck-desk2.amr.corp.intel.com> From: Andy Lutomirski Date: Tue, 12 Jan 2021 10:57:07 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/3] x86/mce: Avoid infinite loop for copy from user recovery To: "Luck, Tony" Cc: Andy Lutomirski , Borislav Petkov , X86 ML , Andrew Morton , Peter Zijlstra , Darren Hart , LKML , linux-edac , Linux-MM Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 12, 2021 at 10:24 AM Luck, Tony wrote: > > 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. > > > > 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. > > 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 possible > because of locks. > > 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. 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. > > Then any subsequent access to user space will page fault. Maybe have a > flag in the task structure to help the #PF handler understand what just > happened. > > The code we execute in the task_work handler can restore %cr3 This would need to be integrated with something much more local IMO. Maybe it could be scoped to pagefault_disable()/pagefault_enable()? --Andy