Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1422305pxb; Wed, 6 Apr 2022 18:31:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx65AqIgTl/E+VOjgwZlh4BbOIpnAowj7353nN76cm487mGco+sHBRmk/OpZWuHnGiMhwuU X-Received: by 2002:a17:907:c05:b0:6db:f118:8834 with SMTP id ga5-20020a1709070c0500b006dbf1188834mr11195690ejc.536.1649295106699; Wed, 06 Apr 2022 18:31:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649295106; cv=none; d=google.com; s=arc-20160816; b=b0bC1MD06u3Gh3os+d8eTgUCR7vMLZaPqyksuMfD+P9dTJpEppilOQGFi0gfPGxz0P gcoe/MJUaT8ljj9qNSOoQJ0RRfORVpPtlb5SPmg8k7JJ/J07yiW2K57Q96lm1UiIximZ E6N5MCSm6u3zHGSq7sehzzW05aHwS3BX4hHa8/CWMipPAtx16IPPYe5cZh3IR+EsmvKC 5lrDlZt4/2gLjKJriyZ0fc+VEHtqCvgrt0jQDWs+rXx6XOUUMdDgYx/rc3jjw4ERn/xM HngiKXPf34JBGf2wOEytwbeykHhAAw6nT42maPBUPD9YI9RUs2F+rqueXdCONDdIVjbV C7Pw== 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=fxKsV2NyeHLOSpW8afO9MB1cVeBBFcyu40ZM2W3k5O8=; b=C42l7wc6yG4+6oTIY3mKsyjyCsN5Up6dv3FmvZ6/suIj6GYgQ8yDEs7pZ9IeEn8Uax SBkEHl24BvF2fZBTKDkwKYKkyYndeaBZFYPYjYd3lxNq/DyovIen5HronT6MkeDeEwkt TYWdlazvP3o2znwqA9s65L65plc01h3z0vavgWdf4W+VRFfyQbm3d9LxZXUHx6pjcYsS MOyrREYDsp7iTUCc2P7XMO29adyzAKCH5L/O9+G2IMvgnwC7hmjfNfv6A5FljUzT3MH8 WQOLUXW3iL5n4fgxKg1wDOJLJ9gcbiu+CkDORr4yZzPvbXBpgbhbjdjvevAyNwD1Pzbp JOzQ== 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 c17-20020a17090654d100b006e802115fc7si6690455ejp.526.2022.04.06.18.31.20; Wed, 06 Apr 2022 18:31:46 -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 S233310AbiDFVdE (ORCPT + 99 others); Wed, 6 Apr 2022 17:33:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236247AbiDFVcg (ORCPT ); Wed, 6 Apr 2022 17:32:36 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 601A0347993; Wed, 6 Apr 2022 13:40:30 -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 041F76123F; Wed, 6 Apr 2022 20:40:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2959AC385A1; Wed, 6 Apr 2022 20:40:27 +0000 (UTC) Date: Wed, 6 Apr 2022 21:40:23 +0100 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: Re: [PATCH v3 3/3] btrfs: Avoid live-lock in search_ioctl() on hardware with sub-page faults Message-ID: References: <20220406180922.1522433-1-catalin.marinas@arm.com> <20220406180922.1522433-4-catalin.marinas@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220406180922.1522433-4-catalin.marinas@arm.com> 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 On Wed, Apr 06, 2022 at 07:09:22PM +0100, Catalin Marinas wrote: > diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c > index 238cee5b5254..d49e8254f823 100644 > --- a/fs/btrfs/ioctl.c > +++ b/fs/btrfs/ioctl.c > @@ -2556,8 +2556,13 @@ static noinline int search_ioctl(struct inode *inode, > key.offset = sk->min_offset; > > while (1) { > + size_t len = *buf_size - sk_offset; > ret = -EFAULT; > - if (fault_in_writeable(ubuf + sk_offset, *buf_size - sk_offset)) > + /* > + * Ensure that the whole user buffer is faulted in at sub-page > + * granularity, otherwise the loop may live-lock. > + */ > + if (fault_in_subpage_writeable(ubuf + sk_offset, len)) > break; This doesn't need a new 'len' variable. It's a left-over from the v2 where fault_in_writeable() took the size and a min_size argument, both being 'len'. -- Catalin