From patchwork Wed Nov 7 06:06:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10671879 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 95A6A1709 for ; Wed, 7 Nov 2018 06:07:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85BD328755 for ; Wed, 7 Nov 2018 06:07:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79DD128A11; Wed, 7 Nov 2018 06:07:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 162AB28755 for ; Wed, 7 Nov 2018 06:07:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBC746B04B9; Wed, 7 Nov 2018 01:07:45 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C6A2E6B04BB; Wed, 7 Nov 2018 01:07:45 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B801E6B04BC; Wed, 7 Nov 2018 01:07:45 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by kanga.kvack.org (Postfix) with ESMTP id 8E52A6B04B9 for ; Wed, 7 Nov 2018 01:07:45 -0500 (EST) Received: by mail-qk1-f200.google.com with SMTP id h68so29544059qke.3 for ; Tue, 06 Nov 2018 22:07:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=n4wGEVzmtOcKVDBg3rQlx6dTYRrrb8ymHIgdc7aT9rc=; b=iNiF7ioROG+1UGklt6htx+KkMG3LtyGLrnOSC8ZPn8wShjFWsKmQC91p4bzGEchvyd GnDxfkvQ6oIj/nUuvCYjoda/xvBxUR5qgbgw+6jkRwTQTshjMKNnTFfSAQbpEZMp1dbP NV4xQw6yzGVg25oISDLz8qT0od+DoDZj8HwVb8w2wLvjIuIue11NdVV5l4Z9n8+gx+Lv cKpBpMR2XZYI8NGlIx/2z6mJp1nnyAh292dnyagBmAKN4egBpQBEHRUldZm+S+QDqkWe iXgGvNKMvO4Eu+5bUNaVlB08doe3AIwQYLTi0+auifukmTY5TFABF5MYfAJ0xcy9gE2+ 0bxg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AGRZ1gI/rbg3rYDJEDf/rJmPtn3+N7HU0bFr65hd+hy+4ybyNBvFls7m NTn/1VYufYiOQDnmwZcCYP/MnQxnNhemVRfxu6QBd2pRW7/7Nl//IBCvCxFhVXhtNfrMbfKv2QB zEC5rMjmXF9apllsZIifMbIBI8BiHOA5RrpsVvIwjztga4qqqknmaJ3DzCdJQrBqeQg== X-Received: by 2002:ac8:4258:: with SMTP id r24mr505128qtm.213.1541570865311; Tue, 06 Nov 2018 22:07:45 -0800 (PST) X-Google-Smtp-Source: AJdET5fKO4iChwBoR2dO6KNlrjd0ofdHdK1pz40jG0CkN3Q/b08DDbDSDmIaprJeV56iYHwKtJOM X-Received: by 2002:ac8:4258:: with SMTP id r24mr505103qtm.213.1541570864854; Tue, 06 Nov 2018 22:07:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541570864; cv=none; d=google.com; s=arc-20160816; b=HHYu0efQW6BCbz0utK4tMiY7x9qW/quGMxD4s8+4D92OTv25ZFyiLlYiNcDu65x1ei AdV8B/jU8w7M8Abiop0tSnGC7w3jrILGjd2ZLUTlO1R1ocN7qf4ShOTH9zfpwXOMwwaN wG8/0/MX4D/zyvf2H3UiZp/5YTBIaVoVDsNxG1hRCvu0hV8ebLnvc8jtyBM+4eFoNax0 xcLcIS0OP9ABfbmGv0V4vn3YPc/Pe0MEXiHnMwGJz1pZKZqR9yKUxo4oIG6A5IMSRpxd mLi1bNtR9tojqU52dpTachtzhmYcj9Tlyv+y+sOXn8Kd3LPrWEeQL99XbFOWJ6jWmVTR OT4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=n4wGEVzmtOcKVDBg3rQlx6dTYRrrb8ymHIgdc7aT9rc=; b=CHGnCak+rcrCr1z79KxHzfbK3Ro2fW4eky3diL0SOr4hH++bT80xtcEFiqEDGloQ5B jfgI4I6YgGJYxq/vYrrzS0asLVbgA+dz6hCILZ27yybA8AWDdCnHAtCkf0WmtxKSYeca l7nn1s0xk2UOI3ikYpEmfZOY4lF6sQ5mk2RMTLk9SmbVpB/gekj6mfVEZEE5okBXoJTR it3hYTnzhqMyMByIuCijP4Xa4AMpTChjrfZSe9PY/JZPUm96dxHXVVICQa0eKlIaeF/I d9i8iisvO4QPxfbmpjkzwm+4mp9uc7cKjQfrSPUb4MPqiULiJzdBPMi955IkrkVbRUfg 3N5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id m68si76428qkd.120.2018.11.06.22.07.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 22:07:44 -0800 (PST) Received-SPF: pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D74FAC0495B1; Wed, 7 Nov 2018 06:07:43 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-128.nay.redhat.com [10.66.14.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10DD31057051; Wed, 7 Nov 2018 06:07:31 +0000 (UTC) From: Peter Xu To: linux-kernel@vger.kernel.org Cc: Keith Busch , Linus Torvalds , peterx@redhat.com, Dan Williams , linux-mm@kvack.org, Matthew Wilcox , Al Viro , Andrea Arcangeli , Huang Ying , Mike Kravetz , Mike Rapoport , Jerome Glisse , "Michael S. Tsirkin" , "Kirill A . Shutemov" , Michal Hocko , Vlastimil Babka , Pavel Tatashin , Andrew Morton Subject: [PATCH RFC v2 4/4] mm: gup: allow VM_FAULT_RETRY for multiple times Date: Wed, 7 Nov 2018 14:06:43 +0800 Message-Id: <20181107060643.10950-5-peterx@redhat.com> In-Reply-To: <20181107060643.10950-1-peterx@redhat.com> References: <20181107060643.10950-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 07 Nov 2018 06:07:44 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This is the gup counterpart of the change that allows the VM_FAULT_RETRY to happen for more than once. Signed-off-by: Peter Xu --- mm/gup.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 6faff46cd409..8a0e7f9bd29a 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -522,7 +522,10 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma, if (*flags & FOLL_NOWAIT) fault_flags |= FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_RETRY_NOWAIT; if (*flags & FOLL_TRIED) { - VM_WARN_ON_ONCE(fault_flags & FAULT_FLAG_ALLOW_RETRY); + /* + * Note: FAULT_FLAG_ALLOW_RETRY and FAULT_FLAG_TRIED + * can co-exist + */ fault_flags |= FAULT_FLAG_TRIED; } @@ -938,17 +941,23 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk, /* VM_FAULT_RETRY triggered, so seek to the faulting offset */ pages += ret; start += ret << PAGE_SHIFT; + lock_dropped = true; +retry: /* * Repeat on the address that fired VM_FAULT_RETRY - * without FAULT_FLAG_ALLOW_RETRY but with + * with both FAULT_FLAG_ALLOW_RETRY and * FAULT_FLAG_TRIED. */ *locked = 1; - lock_dropped = true; down_read(&mm->mmap_sem); ret = __get_user_pages(tsk, mm, start, 1, flags | FOLL_TRIED, - pages, NULL, NULL); + pages, NULL, locked); + if (!*locked) { + /* Continue to retry until we succeeded */ + BUG_ON(ret != 0); + goto retry; + } if (ret != 1) { BUG_ON(ret > 1); if (!pages_done)