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 2F0C3C433F5 for ; Thu, 25 Nov 2021 21:04:17 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Cxb0XVOaGExxprMs/wWSjT6b1aZQnBw/aOgsqOyv5xE=; b=Bx1A0pC7cnApyC JXKC9Vtihod3x8Iakqpsr1CZ+IR0P4fz4sjk/dJupDmvhd/I+a4PxWk1dJmurz2GT9i6jthvUu/sI AzFRHbyC7y58zOXBhQhoA6eycIjLSFCwbTFh1zZ0gEa2I6DhBX0ABcjj665MQN7XUDkqDiM5BMda3 KV1B4ld+0aj1al2wxOpDkcUoDJb8uTQaO625d6X9VVE+WzRp7rAviU4fJYorESH0bjdAQsdndgSNe 93Zmt3Wgav5JgPKR7gbGFUcn6y/EwWi6WDUSMgltUayGIOeUX8S6WCRmb/K5Dj8sGaPz7XG5Lpa3e NPwFqaGPsaWdEn91oObA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqLt3-008det-SG; Thu, 25 Nov 2021 21:02:33 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqLt2-008dem-2z for linux-arm-kernel@bombadil.infradead.org; Thu, 25 Nov 2021 21:02:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=6whOC0TKGHPxQK7AWkvSbq/nnQHgn420BvdvtIX5e9U=; b=fDmyyCipVl5lPnqbKdEPMegTzV HFDsVdla5bphMbGh+7EV0KFHgJLrVEjpxrC7U/+PPFFepp08yoIBFLW7U7hhOmc8MDJJFKatzWbXK WLyDBkfDAtHi7Yjd2VGTc2HhQH9qVumun2C6yBBrQuH49PvfUGHOpM4vgEey9HVHddPH78RKUDHZ0 S88l0v/qDztowz1PSr4G7vVaZrSoQOjYdEzrairMtUjVtFkhQObIJojCclDLFOquxxJikzReA3JK/ Lkbr76gzdZQH3z2bpMB8djessDrHZSR3hCTrW+27G2j3AvAEzAoxmw16XWjfbjTIuWeIYOBQiTssO W39v+IRA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqLsz-007nbV-Ak; Thu, 25 Nov 2021 21:02:29 +0000 Date: Thu, 25 Nov 2021 21:02:29 +0000 From: Matthew Wilcox To: Catalin Marinas Cc: Linus Torvalds , Josef Bacik , David Sterba , Andreas Gruenbacher , Al Viro , Andrew Morton , Will Deacon , linux-fsdevel , Linux Kernel Mailing List , Linux ARM , linux-btrfs Subject: Re: [PATCH 3/3] btrfs: Avoid live-lock in search_ioctl() on hardware with sub-page faults Message-ID: References: <20211124192024.2408218-1-catalin.marinas@arm.com> <20211124192024.2408218-4-catalin.marinas@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 On Thu, Nov 25, 2021 at 08:43:57PM +0000, Catalin Marinas wrote: > > I really believe that the fix is to make the read/write probing just > > be more aggressive. > > > > Make the read/write probing require that AT LEAST bytes be > > readable/writable at the beginning, where 'n' is 'min(len,ALIGN)', and > > ALIGN is whatever size that copy_from/to_user_xyz() might require just > > because it might do multi-byte accesses. > > > > In fact, make ALIGN be perhaps something reasonable like 512 bytes or > > whatever, and then you know you can handle the btrfs "copy a whole > > structure and reset if that fails" case too. > > IIUC what you are suggesting, we still need changes to the btrfs loop > similar to willy's but that should work fine together with a slightly > more aggressive fault_in_writable(). > > A probing of at least sizeof(struct btrfs_ioctl_search_key) should > suffice without any loop changes and 512 would cover it but it doesn't > look generic enough. We could pass a 'probe_prefix' argument to > fault_in_exact_writeable() to only probe this and btrfs would just > specify the above sizeof(). How about something like this? +++ b/mm/gup.c @@ -1672,6 +1672,13 @@ size_t fault_in_writeable(char __user *uaddr, size_t size) if (unlikely(size == 0)) return 0; + if (SUBPAGE_PROBE_INTERVAL) { + while (uaddr < PAGE_ALIGN((unsigned long)uaddr)) { + if (unlikely(__put_user(0, uaddr) != 0)) + goto out; + uaddr += SUBPAGE_PROBE_INTERVAL; + } + } if (!PAGE_ALIGNED(uaddr)) { if (unlikely(__put_user(0, uaddr) != 0)) return size; ARM then defines SUBPAGE_PROBE_INTERVAL to be 16 and the rest of us leave it as 0. That way we probe all the way to the end of the current page and the start of the next page. Oh, that needs to be checked to not exceed size as well ... anyway, you get the idea. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel