Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp944983ybj; Thu, 7 May 2020 11:05:51 -0700 (PDT) X-Google-Smtp-Source: APiQypL7ary74WFWqhTgt3ymgX5yy1+kswbGNWhT1PH+CfrTEmHRobHnj3/AIVuu9M3eqj+BifXf X-Received: by 2002:a50:e80a:: with SMTP id e10mr13254087edn.204.1588874751200; Thu, 07 May 2020 11:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588874751; cv=none; d=google.com; s=arc-20160816; b=VMj4urZXj+CXXxgzeLaCfcnuTA8eomKp6reYUpF2kZGMVHPwhGzNUC30qtuEn+u6R5 ugChQndOQ06QLP3DG6/nbZGnGLHzf5pkgJ9+hzBwAbRryhu/Z5XjguGrrM3TGM3aUGRW 0sMh9lN+g000DIYiMKQd7j3U+b20YYmOoMXDJpuW0oBSj6ecuqXdRq33MFmKiF7WBcUh JyNIBslhAetzH8QgC5NnQprfZz9iZewHrqVFyhI4P4kbY6PXTGOlu4ml2332CMMt1ht7 ZayQBUnh0DrNsn8Xysnv9DsZlNzH/r52p/nJ02ospQwmexHHaeqTPUjiabDdDibceNnA TLzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=8MF/SokzMHYjJEaSFDtgEd3L3BiHUw0VUKR/KDeHrSI=; b=bCuHGFlMBy6HM+1rPIn5iofzxRKR0SupqsUo3CA3v3DySMJyDZOx8sMLduI7MWgC5U QLYCwu49ojzmay4h2teiTachrcmbs227LYrSs5MsduBn9mQ17rR7ci3Xoi+WoaMkRZ/U 56xJvVrEZRmIEWUDXaZ+r9csMXEcBd2iifaNrIh1J6PeoipU4odK8qROUannpKFd1yRf rrgytYDdVabnjpO1kjXRxcWMW3BwE+7k9tjd+hGWbwPpl3i8vz68ZX5mjw7AX5CZDfGG IafN5IagtNaXwn5VbWQaSAdjJwnUzz40piVRGZ7zjcRWyxgDo0p/AcpSBf3QAXNrO2zX mwkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RBb8L9nU; 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 a24si3516497edy.1.2020.05.07.11.05.26; Thu, 07 May 2020 11:05:51 -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; dkim=pass header.i=@kernel.org header.s=default header.b=RBb8L9nU; 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 S1728289AbgEGSCZ (ORCPT + 99 others); Thu, 7 May 2020 14:02:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:53356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726491AbgEGSCY (ORCPT ); Thu, 7 May 2020 14:02:24 -0400 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 36A4A24954 for ; Thu, 7 May 2020 18:02:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588874543; bh=VwlZdvyZ65Zk5wRT7z0+h8x/so/vB6yAwldwafnFQW4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RBb8L9nURNjYclAs3LOnV3iMbO+08U1E+5fWF500lIiqowb9vDzqnVHrFf2R6YOJQ c+tksHteKwvzR1Qm0eZ7x2rQ2kbvCB7ivlAutVrE0BxRM68SEwe1gv8HbU+UH/XcWh EPxTkRL9XaVSXsP+hbwZovrdnQZqKFq9pKxr/jtI= Received: by mail-wr1-f41.google.com with SMTP id l18so7471969wrn.6 for ; Thu, 07 May 2020 11:02:23 -0700 (PDT) X-Gm-Message-State: AGi0PuZ42fCJFRil4AkpaeDbPwYStrdZUF35YX+atGWyrtEXXLNLh1E8 CMH8rcL/BB6FRZMXVpGRvIMcLFYnK7dXVimj2eL6+g== X-Received: by 2002:a5d:62cc:: with SMTP id o12mr16440356wrv.75.1588874541618; Thu, 07 May 2020 11:02:21 -0700 (PDT) MIME-Version: 1.0 References: <20200505131602.633487962@linutronix.de> <20200505134100.957390899@linutronix.de> In-Reply-To: <20200505134100.957390899@linutronix.de> From: Andy Lutomirski Date: Thu, 7 May 2020 11:02:09 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [patch V4 part 1 29/36] x86/mce: Send #MC singal from task work To: Thomas Gleixner Cc: LKML , X86 ML , "Paul E. McKenney" , Andy Lutomirski , Alexandre Chartre , Frederic Weisbecker , Paolo Bonzini , Sean Christopherson , Masami Hiramatsu , Petr Mladek , Steven Rostedt , Joel Fernandes , Boris Ostrovsky , Juergen Gross , Brian Gerst , Mathieu Desnoyers , Josh Poimboeuf , Will Deacon , "Peter Zijlstra (Intel)" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 5, 2020 at 7:13 AM Thomas Gleixner wrote: > > From: Peter Zijlstra > > Convert #MC over to using task_work_add(); it will run the same code > slightly later, on the return to user path of the same exception. I think this patch is correct, but I think it's only one small and not that obviously wrong step away from being broken: > if ((m.cs & 3) == 3) { > /* If this triggers there is no way to recover. Die hard. */ > BUG_ON(!on_thread_stack() || !user_mode(regs)); > - local_irq_enable(); > - preempt_enable(); > > - if (kill_it || do_memory_failure(&m)) > - force_sig(SIGBUS); > - preempt_disable(); > - local_irq_disable(); > + current->mce_addr = m.addr; > + current->mce_status = m.mcgstatus; > + current->mce_kill_me.func = kill_me_maybe; > + if (kill_it) > + current->mce_kill_me.func = kill_me_now; > + task_work_add(current, ¤t->mce_kill_me, true); This is fine if the source was CPL3, but it's not going to work if CPL was 0. We don't *currently* do this from CPL0, but people keep wanting to. So perhaps there should be a comment like: /* * The #MC originated at CPL3, so we know that we will go execute the task_work before returning to the offending user code. */ IOW, if we want to recover from CPL0 #MC, we will need a different mechanism. I also confess a certain amount of sadness that my beautiful haha-not-really-atomic-here mechanism isn't being used anymore. :( --Andy