From patchwork Wed Nov 21 06:21:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10691999 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 9C12713BF for ; Wed, 21 Nov 2018 06:21:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C0672B8B1 for ; Wed, 21 Nov 2018 06:21:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 805852B89F; Wed, 21 Nov 2018 06:21:56 +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 141052B896 for ; Wed, 21 Nov 2018 06:21:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE9486B248B; Wed, 21 Nov 2018 01:21:54 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D98CB6B248C; Wed, 21 Nov 2018 01:21:54 -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 C38A06B248D; Wed, 21 Nov 2018 01:21:54 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by kanga.kvack.org (Postfix) with ESMTP id 922F46B248B for ; Wed, 21 Nov 2018 01:21:54 -0500 (EST) Received: by mail-qk1-f197.google.com with SMTP id g22so5751767qke.15 for ; Tue, 20 Nov 2018 22:21:54 -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=13Xd4hA69jLTS4UEEtQy7QfFCo+mbPX/t8zrT3erd7w=; b=Kh36dyhGRmLjUHZxmEbU6tGWjvtZPAS2wh+CUnF71OVwsLAuTFEgNOLE5J9Sjbxcmt vsEiDZVttn4B9EW/KvH92iIY+V/KXClNkLlPWBNcTMuHLblbGxycf69oxIQsVD7nccwT A/3D0V53Y4kIOfStl+VNBPRogrB1+K+WgZGJ6dVvYhdtHfoXVEXVt84q7WQz+kqCdeGA 2Tkz7Bo4qe56bWMh3IP7MhB735KYcVWf/b6jiENt/Myny+6PczTFPxnjBoSeXMfLIL+c fb3pEj5s2fH0OBi5N365GuYw4CM1qo0wrT+0DK1uHQsyKywcT1gBezT+nLNH1gbYrHwp bm/A== 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: AA+aEWZbhNUxcXaxyGzwrWRjqW1ZlsjAl1u5VRCQW2cJZXeMGsvclIHc K+msAo48BRVOhbnRWVJbl+CTvn9aGNtxnLRL+NKZuujaMM5fuKPn5Dni8aLWdsxW7IJvKuAj42M 6vzYrYj/yq/o86FlSn2GCvtLuhxPJJrBKXw6z4UjT6zhGxTx2dR0JFV1tNI6GBKVDZw== X-Received: by 2002:a37:1b46:: with SMTP id b67mr4469521qkb.144.1542781314356; Tue, 20 Nov 2018 22:21:54 -0800 (PST) X-Google-Smtp-Source: AFSGD/XVrazR1xH0I+ndEVhTiJvia3WwDDJAn7+83Cro2yBhKFkSSOvOtMJWve5WR5lCfjDfEE5K X-Received: by 2002:a37:1b46:: with SMTP id b67mr4469510qkb.144.1542781313782; Tue, 20 Nov 2018 22:21:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542781313; cv=none; d=google.com; s=arc-20160816; b=qwX5Lsp+IoEqMSnJOsGp2cK4oEGcTwYrHKxiXLVLbFeBdQq3pbqWnbDFrWyx6DM/e6 YoZ92O26xP6GIJoo60+oxMMuPg75H+IqPjC8eRVc6Wayp206wvbE+hbGZCMiZ85yJyWP WNve1+TmsSPu2hX8WUOn5IB/B25MM+73f3f5FvHragicADVFGhPWMl+384N7EvIO63yR QHn9Gk6QOSUuWQS8nCHNiKs5XTgvRn17583CQZg/7Bv1VCQCzhWWfaQDvFyDzpMJKVlx hqIPY69DvuJWE7ArJxvFyXUgCK6qmo/tvjHiZ8vA0O8pxvSik/V2kQvcsOhiOo01mwli qilQ== 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=13Xd4hA69jLTS4UEEtQy7QfFCo+mbPX/t8zrT3erd7w=; b=awzkaz1v3ORJsfs7ZyYZJVaghMsw3bNjgclJw+G4KO7sZaHMiSsk+e/WiZVO0wGxPZ ktJKSXat8NiFHZX2paZuacKC7bf3B/dVajDhN4VFQDTnhfn1RhN+mai68L2Eft5ckThx iGSmrgF5kEbcRlOIzK3MZJtUS1XElOkWXSuQ3M3/7dXp9PU0+Qx+FNGperGGl76RFFzk OfZJyJYE34uDdO8Hx3dIafGJ/KU8oelXyPWqdEujj4ZKtBW9s4oRAaGSopnSb46cw/Dt yhC7kuqeuzRSUQb0sxS6jQastU8Qb+dy5X+cWt+xSB7IxYVrb1J8ZzXIvzm64H+g5KNM e8SQ== 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 o51si22641710qtj.204.2018.11.20.22.21.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 22:21:53 -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-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA7BC89ACE; Wed, 21 Nov 2018 06:21:52 +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 74DD2600C3; Wed, 21 Nov 2018 06:21:44 +0000 (UTC) From: Peter Xu To: linux-kernel@vger.kernel.org Cc: Keith Busch , Jerome Glisse , peterx@redhat.com, Dan Williams , linux-mm@kvack.org, Matthew Wilcox , Al Viro , Andrea Arcangeli , Huang Ying , Mike Kravetz , Mike Rapoport , Linus Torvalds , "Michael S. Tsirkin" , "Kirill A . Shutemov" , Michal Hocko , Vlastimil Babka , Pavel Tatashin , Andrew Morton Subject: [PATCH RFC v3 4/4] mm: gup: allow VM_FAULT_RETRY for multiple times Date: Wed, 21 Nov 2018 14:21:03 +0800 Message-Id: <20181121062103.18835-5-peterx@redhat.com> In-Reply-To: <20181121062103.18835-1-peterx@redhat.com> References: <20181121062103.18835-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 21 Nov 2018 06:21:53 +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 a40111c742ba..7c3b3ab6be88 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -528,7 +528,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; } @@ -944,17 +947,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)