Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2023284pxb; Thu, 28 Oct 2021 14:43:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBi4azLRki71MUoVyosFamvNiC9rAEI0/Hbg/RBqnsj1p5hGLVHn+rahHiAg2po3M5bb2I X-Received: by 2002:a17:90a:4f83:: with SMTP id q3mr7045445pjh.127.1635457379754; Thu, 28 Oct 2021 14:42:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635457379; cv=none; d=google.com; s=arc-20160816; b=W/oX4Dij0MapwSs02RoPnSvSZFD4QdSXADt423AssBQ0lbLomDoBAdIXRBLl4B6JYI lNOY/9U0/N/liqToCuoofSawE3TDqhxNrl3/ukO/nsfJaX47JgpqlWKPIT/x1MTQcH1C Ooul5ke4JK3VwYZEVjrCApXtsNlGfO0wWHq/LeYLwuMtUF3AixaMxzx58Guf6qlIHc1R c1VVjb6y89/iZ+ZkN9xL63O0fhm+vxTwJchCWpzg1jOPIat8vCw+5PU5j0EaK4Cv78P8 IQl8A0HFqtFCUT3xb2ASu8PZMJ+Q1Gkoqvckj7MKXWApfjOhEuC85orx2q1DDe+YJpkO rSjg== 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; bh=qUQfxcfMqYaoqN4UCDGeJvHsZkf9/JwBaQPDcA+l6Og=; b=aWPCKPPg18ez5TXWIZTPyAqPOSgVRAqh8HJsUaqTwl91MNSBQwBHuksEs2r5UekPyQ aO5x5vdvJ5pVi7rQs48uu/XwR16JRWoZFLz5XkD1LnwtsFtj1ko0WIIwFFWWkts17Wye X8PhUUpKaQNzw40mkCA9oPGax/ZYbmgvodfaPkUcakh5n7DuU643STsin/oXCeMm/rQy FRGMbj2tBz5CYWEi1Balqq2GK42K9x5+xz7eZoUzD89l6ZS0A+eOoRyV8LiJkOGER0SJ 9sym3EuB0eCg94a1b0WFdRuptS0bNcWTgq1w/2OFanxsGU5sJCBikwz2mla1ZOaRVvcK E1fA== 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=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si176742pll.312.2021.10.28.14.42.46; Thu, 28 Oct 2021 14:42:59 -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; 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=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231431AbhJ1Vm7 (ORCPT + 99 others); Thu, 28 Oct 2021 17:42:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:57376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231401AbhJ1Vm6 (ORCPT ); Thu, 28 Oct 2021 17:42:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4FD7360FF2; Thu, 28 Oct 2021 21:40:28 +0000 (UTC) Date: Thu, 28 Oct 2021 22:40:25 +0100 From: Catalin Marinas To: Linus Torvalds Cc: Andreas Gruenbacher , Paul Mackerras , Alexander Viro , Christoph Hellwig , "Darrick J. Wong" , Jan Kara , Matthew Wilcox , cluster-devel , linux-fsdevel , Linux Kernel Mailing List , ocfs2-devel@oss.oracle.com, kvm-ppc@vger.kernel.org, linux-btrfs Subject: Re: [PATCH v8 00/17] gfs2: Fix mmap + page fault deadlocks Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 28, 2021 at 10:20:52PM +0100, Catalin Marinas wrote: > On Wed, Oct 27, 2021 at 02:14:48PM -0700, Linus Torvalds wrote: > > On Wed, Oct 27, 2021 at 12:13 PM Catalin Marinas > > wrote: > > > As an alternative, you mentioned earlier that a per-thread fault status > > > was not feasible on x86 due to races. Was this only for the hw poison > > > case? I think the uaccess is slightly different. > > > > It's not x86-specific, it's very generic. > > > > If we set some flag in the per-thread status, we'll need to be careful > > about not overwriting it if we then have a subsequent NMI that _also_ > > takes a (completely unrelated) page fault - before we then read the > > per-thread flag. > > > > Think 'perf' and fetching backtraces etc. > > > > Note that the NMI page fault can easily also be a pointer coloring > > fault on arm64, for exactly the same reason that whatever original > > copy_from_user() code was. So this is not a "oh, pointer coloring > > faults are different". They have the same re-entrancy issue. > > > > And both the "pagefault_disable" and "fault happens in interrupt > > context" cases are also the exact same 'faulthandler_disabled()' > > thing. So even at fault time they look very similar. > > They do look fairly similar but we should have the information in the > fault handler to distinguish: not a page fault (pte permission or p*d > translation), in_task(), user address, fixup handler. But I agree the > logic looks fragile. > > I think for nested contexts we can save the uaccess fault state on > exception entry, restore it on return. Or (needs some thinking on > atomicity) save it in a local variable. The high-level API would look > something like: > > unsigned long uaccess_flags; /* we could use TIF_ flags */ > > uaccess_flags = begin_retriable_uaccess(); > copied = copy_page_from_iter_atomic(...); > retry = end_retriable_uaccess(uaccess_flags); It doesn't work with local flags, so it would need to be saved on exception entry (interrupt, breakpoint etc.) on the stack, restore on return. But the API would return pretty close (and probably still more complicated than copy_*() returning an error code). -- Catalin