From mboxrd@z Thu Jan 1 00:00:00 1970 From: Catalin Marinas Date: Thu, 28 Oct 2021 22:20:52 +0100 Subject: [Cluster-devel] [PATCH v8 00/17] gfs2: Fix mmap + page fault deadlocks In-Reply-To: References: Message-ID: List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit One last try on this path before I switch to the other options. 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); ... if (!retry) break; I think we'd need a TIF flag to mark the retriable region and another to track whether a non-recoverable fault occurred. It needs prototyping. Anyway, if you don't like this approach, I'll look at error codes being returned but rather than changing all copy_from_user() etc., introduce a new API that returns different error codes depending on the fault (e.g -EFAULT vs -EACCES). We already have copy_from_user_nofault(), we'd need something for the iov_iter stuff to use in the fs code. -- Catalin From mboxrd@z Thu Jan 1 00:00:00 1970 From: Catalin Marinas Date: Thu, 28 Oct 2021 21:20:52 +0000 Subject: Re: [PATCH v8 00/17] gfs2: Fix mmap + page fault deadlocks Message-Id: List-Id: References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 One last try on this path before I switch to the other options. 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); ... if (!retry) break; I think we'd need a TIF flag to mark the retriable region and another to track whether a non-recoverable fault occurred. It needs prototyping. Anyway, if you don't like this approach, I'll look at error codes being returned but rather than changing all copy_from_user() etc., introduce a new API that returns different error codes depending on the fault (e.g -EFAULT vs -EACCES). We already have copy_from_user_nofault(), we'd need something for the iov_iter stuff to use in the fs code. -- Catalin 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95739C433FE for ; Thu, 28 Oct 2021 21:21:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 774FD610E7 for ; Thu, 28 Oct 2021 21:21:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231324AbhJ1VX0 (ORCPT ); Thu, 28 Oct 2021 17:23:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:47886 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230404AbhJ1VXZ (ORCPT ); Thu, 28 Oct 2021 17:23:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EBF7A6023E; Thu, 28 Oct 2021 21:20:55 +0000 (UTC) Date: Thu, 28 Oct 2021 22:20:52 +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-btrfs@vger.kernel.org One last try on this path before I switch to the other options. 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); ... if (!retry) break; I think we'd need a TIF flag to mark the retriable region and another to track whether a non-recoverable fault occurred. It needs prototyping. Anyway, if you don't like this approach, I'll look at error codes being returned but rather than changing all copy_from_user() etc., introduce a new API that returns different error codes depending on the fault (e.g -EFAULT vs -EACCES). We already have copy_from_user_nofault(), we'd need something for the iov_iter stuff to use in the fs code. -- Catalin 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FAA2C433F5 for ; Thu, 28 Oct 2021 21:24:43 +0000 (UTC) Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7EB3C61056 for ; Thu, 28 Oct 2021 21:24:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7EB3C61056 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=oss.oracle.com Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19SKU6CH030820; Thu, 28 Oct 2021 21:24:41 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3byhy9muxv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 28 Oct 2021 21:24:40 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 19SLG2nD070916; Thu, 28 Oct 2021 21:24:38 GMT Received: from oss.oracle.com (oss-old-reserved.oracle.com [137.254.22.2]) by userp3020.oracle.com with ESMTP id 3bx4gtf4ke-1 (version=TLSv1 cipher=AES256-SHA bits=256 verify=NO); Thu, 28 Oct 2021 21:24:38 +0000 Received: from localhost ([127.0.0.1] helo=lb-oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1mgCq0-0007Ax-Kr; Thu, 28 Oct 2021 14:21:28 -0700 Received: from aserp3020.oracle.com ([141.146.126.70]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1mgCpZ-00079u-6f for ocfs2-devel@oss.oracle.com; Thu, 28 Oct 2021 14:21:01 -0700 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 19SLFdsN144142 for ; Thu, 28 Oct 2021 21:21:01 GMT Received: from mx0b-00069f01.pphosted.com (mx0b-00069f01.pphosted.com [205.220.177.26]) by aserp3020.oracle.com with ESMTP id 3bx4geyph4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 28 Oct 2021 21:21:00 +0000 Received: from pps.filterd (m0246577.ppops.net [127.0.0.1]) by mx0b-00069f01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19SJHu52004877 for ; Thu, 28 Oct 2021 21:21:00 GMT Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by mx0b-00069f01.pphosted.com with ESMTP id 3byhu55e2s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 28 Oct 2021 21:20:59 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id EBF7A6023E; Thu, 28 Oct 2021 21:20:55 +0000 (UTC) Date: Thu, 28 Oct 2021 22:20:52 +0100 From: Catalin Marinas To: Linus Torvalds Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Source-IP: 198.145.29.99 X-ServerName: mail.kernel.org X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 mx include:_spf.kernel.org ~all X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10151 signatures=668683 X-Proofpoint-Spam-Reason: safe X-Spam: OrgSafeList X-SpamRule: orgsafelist Cc: kvm-ppc@vger.kernel.org, Christoph Hellwig , cluster-devel , Jan Kara , Andreas Gruenbacher , Linux Kernel Mailing List , Paul Mackerras , Alexander Viro , linux-fsdevel , linux-btrfs , ocfs2-devel@oss.oracle.com Subject: Re: [Ocfs2-devel] [PATCH v8 00/17] gfs2: Fix mmap + page fault deadlocks X-BeenThere: ocfs2-devel@oss.oracle.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: ocfs2-devel-bounces@oss.oracle.com Errors-To: ocfs2-devel-bounces@oss.oracle.com X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10151 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 adultscore=0 suspectscore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2110280111 X-Proofpoint-ORIG-GUID: mOjQhtcyplSaDMr6OyYpKiJPHbWMrnbV X-Proofpoint-GUID: mOjQhtcyplSaDMr6OyYpKiJPHbWMrnbV One last try on this path before I switch to the other options. 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); ... if (!retry) break; I think we'd need a TIF flag to mark the retriable region and another to track whether a non-recoverable fault occurred. It needs prototyping. Anyway, if you don't like this approach, I'll look at error codes being returned but rather than changing all copy_from_user() etc., introduce a new API that returns different error codes depending on the fault (e.g -EFAULT vs -EACCES). We already have copy_from_user_nofault(), we'd need something for the iov_iter stuff to use in the fs code. -- Catalin _______________________________________________ Ocfs2-devel mailing list Ocfs2-devel@oss.oracle.com https://oss.oracle.com/mailman/listinfo/ocfs2-devel