Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1296811pxb; Wed, 6 Apr 2022 14:07:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvt44VbSxWD7f04q/ao2U3y8XhnPsYB5AuN8ZtygxYSc2WkARz4Dx8gWwiu2reXDG4mYN3 X-Received: by 2002:a05:6402:1941:b0:413:2b7e:676e with SMTP id f1-20020a056402194100b004132b7e676emr11032623edz.114.1649279231704; Wed, 06 Apr 2022 14:07:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649279231; cv=none; d=google.com; s=arc-20160816; b=lu5Duf7e9j/WcZOzPx1WrPUxUZDDdJGSjWszjQ9b6V/ut3OAADkw1CTi69xChSuyaX iU35IjLgtYRUB4jGVoXUhp0+QBRIfDCrBpz46OHh0YHLWTOTa9CN3whVA1sRI2csnwjb ZVGqdJ0D8HwtNV7QTTgbm9OQpQe149gzupba016mCBPxjginHu/C/iJfybmCl27hnQwE WncWYAWnrk987pbrjr+C9ntBO6Y2lFQdaozaBd0Xq+Mj7LXgLf5TkWJdMfH/rtewUjjJ vA/+gAPDBjMUKNqTbvcikk0/yxN3KpS/kNxv5KF5I1BWG3gc1FedzQ3k8+KUIYdicW4b EE5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=mmdPMLuiklEnPNxWG/7rK7BMCHqFFFssgkj/m737U1k=; b=L3Gq7lsV8Zq1kt8MeTQZOUVXoBv3GiOCCvV0VXkYaB+gP+ZWb6lAWlufTBP2fKJp30 cvAcYNbMSlu2DROskcf0ansBzA+dkJXAxErChfDk0uLAJJ8zxMNmMXFFq4o5g6QgOsxs 9yZFetvAL4VcurDZneCviHDOdIhYzOGVmESTy43JJ3J4fzu8hKHkozXrfOEqCYBb5gW2 JjvNMjF6pNsinIVpKfoQdHQfPGRdTOPWuJDUV4GX1jfrI0S2hp1eMQzYuYW71s65eTRl qPt8CU1d6IT/Z5Xt3lfVsThYS4e+oVaIOdIac0FyprZQSGP2GR8tLGslDuMyzeaiAc/8 Gu6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m26-20020aa7c2da000000b00418c2b5beb6si13642552edp.408.2022.04.06.14.06.46; Wed, 06 Apr 2022 14:07:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231577AbiDFTrB (ORCPT + 99 others); Wed, 6 Apr 2022 15:47:01 -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 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-)