Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp235321pxb; Fri, 15 Jan 2021 11:37:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLz/RBwg7eFPnyvZD0lYkPFVbgitmgAcj9d38EipQQbfT0CLch6oOXqBmESRFPkrYwiFPB X-Received: by 2002:a17:906:43c5:: with SMTP id j5mr10370214ejn.530.1610739448894; Fri, 15 Jan 2021 11:37:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610739448; cv=none; d=google.com; s=arc-20160816; b=DAkdk8CZQQkvjnxG0wZMOKO4wmnF92xCgKxhoJo/4DgsoZr7FanOgG4oDJ0Bidpz9b wB1nLXnXz66bp6W6Snh3vVpvAwJdJ1hQrW4rvybHjBkR2iGn2PXCdoBusP/ZogRq6grj vZrtSTLKdVo891p/zPwFoyZdE55EOZ+Q0d9V+4EJ6u4AoOmey/U19XsS3zsjCVR05KvJ yKfAE2lm6TNld0fl2U0+uP3hau0Rqp1xYj7CSMaqup/BeoMqDcJWmwR6+EGoMIjk//7i b7OG4Z9xhzaosHPlo8kd5va7TVhedO1GRhK5Zv1LXB/hUdY63qDhF+rJni6/M0lHpLyH Nz0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:ironport-sdr :ironport-sdr; bh=trNFHSfskwfJPbX73bSYSD8xq2hFUAvxLfirUk6DyjI=; b=Y/t+erMVgaWKybQKtbqHCWX+0AWOeh+68aYPighN8QsngReNXGJPXSzN4imjd+msVp c5qhy19nxtPIuJ8kfsSD301yosceVwGiQszGVg7hX7S6l9wCAzNnbenc2aNBrxxg8fgk 6JG32A05FzjXtmSxJ5H/PjutJKfxs5T+GVNq1hKukjoDyBjIYlXRdeGOdYDE28b5Q0bh AspHh/UtydkkxsSW5mzsLg9h9OqHZBTZquHfXxe8G2rjjdbTjGAFFGy5gQzDeuWLO2mC 6yXuVY9a8MHEeFGALlEQqHE+EDDw3kdh5cVH1MlJdgTkt6vaYeimaproplsk1NMaT1aj mZTQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f15si4331717ejh.394.2021.01.15.11.37.05; Fri, 15 Jan 2021 11:37:28 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727280AbhAOTg3 (ORCPT + 99 others); Fri, 15 Jan 2021 14:36:29 -0500 Received: from mga17.intel.com ([192.55.52.151]:5631 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388322AbhAOTfU (ORCPT ); Fri, 15 Jan 2021 14:35:20 -0500 IronPort-SDR: ADoGxpc7mu6MAsV17pcupeYsBvzhr+9DVR9aJn2hKWKOmtDuY9Lf/mnyYpc24Yji41GmAog7fJ skjBGgXb4nhw== X-IronPort-AV: E=McAfee;i="6000,8403,9865"; a="158371998" X-IronPort-AV: E=Sophos;i="5.79,350,1602572400"; d="scan'208";a="158371998" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jan 2021 11:34:39 -0800 IronPort-SDR: wWXQ7MO+mgxgE99JSEkjBJfSr0qsLFYjESrO72XEEJcZb7rLyXW4VnDC30+PB/kgls2RdnrfYx slPkiWM38T/w== X-IronPort-AV: E=Sophos;i="5.79,350,1602572400"; d="scan'208";a="354414793" Received: from agluck-desk2.sc.intel.com (HELO agluck-desk2.amr.corp.intel.com) ([10.3.52.68]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jan 2021 11:34:38 -0800 Date: Fri, 15 Jan 2021 11:34:35 -0800 From: "Luck, Tony" To: Borislav Petkov Cc: 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: Re: [PATCH v3] x86/mce: Avoid infinite loop for copy from user recovery Message-ID: <20210115193435.GA4663@agluck-desk2.amr.corp.intel.com> References: <20210111214452.1826-1-tony.luck@intel.com> <20210115003817.23657-1-tony.luck@intel.com> <20210115152754.GC9138@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210115152754.GC9138@zn.tnic> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 15, 2021 at 04:27:54PM +0100, Borislav Petkov wrote: > On Thu, Jan 14, 2021 at 04:38:17PM -0800, Tony Luck wrote: > > Add a "mce_busy" counter so that task_work_add() is only called once > > per faulty page in this task. > > Yeah, that sentence can be removed now too. I will update with new name "mce_count" and some details. > > -static void queue_task_work(struct mce *m, int kill_current_task) > > +static void queue_task_work(struct mce *m, char *msg, int kill_current_task) > > So this function gets called in the user mode MCE case too: > > if ((m.cs & 3) == 3) { > > queue_task_work(&m, msg, kill_current_task); > } > > Do we want to panic for multiple MCEs to different addresses in user > mode? In the user mode case we should only bump mce_count to "1" and before task_work() gets called. It shouldn't hurt to do the same checks. Maybe it will catch something weird - like an NMI handler on return from the machine check doing a get_user() that hits another machine check during the return from this machine check. AndyL has made me extra paranoid. :-) > > - current->mce_addr = m->addr; > > - current->mce_kflags = m->kflags; > > - current->mce_ripv = !!(m->mcgstatus & MCG_STATUS_RIPV); > > - current->mce_whole_page = whole_page(m); > > + if (current->mce_count++ == 0) { > > + current->mce_addr = m->addr; > > + current->mce_kflags = m->kflags; > > + current->mce_ripv = !!(m->mcgstatus & MCG_STATUS_RIPV); > > + current->mce_whole_page = whole_page(m); > > + } > > + > > /* Magic number should be large enough */ > > > + if (current->mce_count > 10) Will add similar comment here ... and to other tests in this function since it may not be obvious to me next year what I was thinking now :-) > > + if (current->mce_count > 10) > > + mce_panic("Too many machine checks while accessing user data", m, msg); > > + > > + if (current->mce_count > 1 || (current->mce_addr >> PAGE_SHIFT) != (m->addr >> PAGE_SHIFT)) > > + mce_panic("Machine checks to different user pages", m, msg); > > Will this second part of the test expression, after the "||" ever hit? No :-( This code is wrong. Should be "&&" not "||". Then it makes more sense. Will fix for v4. > In any case, what are you trying to catch with this? Two get_user() to > different pages both catching MCEs? Yes. Trying to catch two accesses to different pages. Need to do this because kill_me_maybe() is only going to offline one page. I'm not expecting that this would ever hit. It means that calling code took a machine check on one page and get_user() said -EFAULT. The the code decided to access a different page *and* that other page also triggered a machine check. > > + /* Do not call task_work_add() more than once */ > > + if (current->mce_count > 1) > > + return; > > That won't happen either, AFAICT. It'll panic above. With the s/||/&&/ above, we can get here. > > Regardless, I like how this is all confined to the MCE code and there's > no need to touch stuff outside... Thanks for the review. -Tony