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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A0AFC433EF for ; Wed, 6 Apr 2022 18:10:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=8mqUahH8Yif2E4rTmzqAluFFKxnKGrvKPFBKq/PDvgY=; b=bxjBUK1YaGup1D f6TySLZcUCYxUOUbCyRA/WCQbvC9+rCIAJC16oiqgKskG3Ye6C145LP40fAK2wkfH9hPbHuTRVbp/ EdkkjSmfbFGwLjWh0BIqmGzF5uI7rmeoywXyc+U/WjYohR1Yz3yzmFLkcxf8kbujix8Y2nZkv+r8r 3fu9WeYv+64gQMEZP5BH9YjDykjxn1xdrbrI6L2Hy0UDlgUnL8KWg4TsEErHobkS6hZR8QvIGlN0g 0FcvSVw1+V25GRL+UdUA71e5+LnH30jEk9yuuBvgHJRttyI9b8WX4/LEgPtQb/jd6VcAXl53y2Zza RTonxupjQX3n6rldkzYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncA60-007Sso-AC; Wed, 06 Apr 2022 18:09:32 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncA5x-007Ss3-4K for linux-arm-kernel@lists.infradead.org; Wed, 06 Apr 2022 18:09:30 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1429C61BD2; Wed, 6 Apr 2022 18:09:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B317FC385A3; Wed, 6 Apr 2022 18:09:24 +0000 (UTC) From: Catalin Marinas To: Linus Torvalds , Andreas Gruenbacher , Josef Bacik Cc: Al Viro , Andrew Morton , Chris Mason , David Sterba , Will Deacon , linux-fsdevel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 0/3] Avoid live-lock in btrfs fault-in+uaccess loop Date: Wed, 6 Apr 2022 19:09:19 +0100 Message-Id: <20220406180922.1522433-1-catalin.marinas@arm.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220406_110929_245100_F12CF2AF X-CRM114-Status: GOOD ( 16.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 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: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, I finally got around to reviving this series. However, I simplified it from v2 and focussed on solving the btrfs search_ioctl() problem only: https://lore.kernel.org/r/20211201193750.2097885-1-catalin.marinas@arm.com The btrfs search_ioctl() function can potentially live-lock on arm64 with MTE enabled due to a fault_in_writeable() + copy_to_user_nofault() unbounded loop. The uaccess can fault in the middle of a page (MTE tag check fault) even if a prior fault_in_writeable() successfully wrote to the beginning of that page. The btrfs loop always restarts the fault-in loop from the beginning of the user buffer, hence the live-lock. The series introduces fault_in_subpage_writeable() together with the arm64 probing counterpart and the btrfs fix. I don't think with the current kernel anything other than btrfs search_ioctl() can live-lock. The buffered file I/O can already cope with current fault_in_*() + copy_*_user() loops (the uaccess makes progress). Direct I/O either goes via GUP + kernel mapping access (and memcpy() can't fault) or, if the user buffer is not PAGE aligned, it may fall back to buffered I/O. So we really only care about fault_in_writeable(), hence this simplified series. If at some point we'll need to address other places, we can expand the sub-page probing to the other fault_in_*() functions. Thanks. Catalin Marinas (3): mm: Add fault_in_subpage_writeable() to probe at sub-page granularity arm64: Add support for user sub-page fault probing btrfs: Avoid live-lock in search_ioctl() on hardware with sub-page faults arch/Kconfig | 7 +++++++ arch/arm64/Kconfig | 1 + arch/arm64/include/asm/mte.h | 1 + arch/arm64/include/asm/uaccess.h | 15 +++++++++++++++ arch/arm64/kernel/mte.c | 30 ++++++++++++++++++++++++++++++ fs/btrfs/ioctl.c | 7 ++++++- include/linux/pagemap.h | 1 + include/linux/uaccess.h | 22 ++++++++++++++++++++++ mm/gup.c | 29 +++++++++++++++++++++++++++++ 9 files changed, 112 insertions(+), 1 deletion(-) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D620C433F5 for ; Wed, 6 Apr 2022 19:45:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232240AbiDFTqx (ORCPT ); Wed, 6 Apr 2022 15:46:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231789AbiDFTpx (ORCPT ); Wed, 6 Apr 2022 15:45:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E4CB1DE59B; Wed, 6 Apr 2022 11:09:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B891461C4B; Wed, 6 Apr 2022 18:09:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B317FC385A3; Wed, 6 Apr 2022 18:09:24 +0000 (UTC) From: Catalin Marinas To: Linus Torvalds , Andreas Gruenbacher , Josef Bacik Cc: Al Viro , Andrew Morton , Chris Mason , David Sterba , Will Deacon , linux-fsdevel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 0/3] Avoid live-lock in btrfs fault-in+uaccess loop Date: Wed, 6 Apr 2022 19:09:19 +0100 Message-Id: <20220406180922.1522433-1-catalin.marinas@arm.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Hi, I finally got around to reviving this series. However, I simplified it from v2 and focussed on solving the btrfs search_ioctl() problem only: https://lore.kernel.org/r/20211201193750.2097885-1-catalin.marinas@arm.com The btrfs search_ioctl() function can potentially live-lock on arm64 with MTE enabled due to a fault_in_writeable() + copy_to_user_nofault() unbounded loop. The uaccess can fault in the middle of a page (MTE tag check fault) even if a prior fault_in_writeable() successfully wrote to the beginning of that page. The btrfs loop always restarts the fault-in loop from the beginning of the user buffer, hence the live-lock. The series introduces fault_in_subpage_writeable() together with the arm64 probing counterpart and the btrfs fix. I don't think with the current kernel anything other than btrfs search_ioctl() can live-lock. The buffered file I/O can already cope with current fault_in_*() + copy_*_user() loops (the uaccess makes progress). Direct I/O either goes via GUP + kernel mapping access (and memcpy() can't fault) or, if the user buffer is not PAGE aligned, it may fall back to buffered I/O. So we really only care about fault_in_writeable(), hence this simplified series. If at some point we'll need to address other places, we can expand the sub-page probing to the other fault_in_*() functions. Thanks. Catalin Marinas (3): mm: Add fault_in_subpage_writeable() to probe at sub-page granularity arm64: Add support for user sub-page fault probing btrfs: Avoid live-lock in search_ioctl() on hardware with sub-page faults arch/Kconfig | 7 +++++++ arch/arm64/Kconfig | 1 + arch/arm64/include/asm/mte.h | 1 + arch/arm64/include/asm/uaccess.h | 15 +++++++++++++++ arch/arm64/kernel/mte.c | 30 ++++++++++++++++++++++++++++++ fs/btrfs/ioctl.c | 7 ++++++- include/linux/pagemap.h | 1 + include/linux/uaccess.h | 22 ++++++++++++++++++++++ mm/gup.c | 29 +++++++++++++++++++++++++++++ 9 files changed, 112 insertions(+), 1 deletion(-)