Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp210868ybn; Tue, 24 Sep 2019 21:32:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDiZN6banCiI65zrSJHgbHl43z0uDk8Qgo9PFDOi9WOVyLxcemzadg6i8NwDxTSM9gWEjG X-Received: by 2002:a1c:cf4e:: with SMTP id f75mr4575423wmg.49.1569385971994; Tue, 24 Sep 2019 21:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569385971; cv=none; d=google.com; s=arc-20160816; b=IyaboD2D+fundGtY9EEFM2zpTIJbJITm52VNrbqoBOPwEeMaxRM7AzGYRAa3AGzTwC u8iwXzdBXHxbPbm98p3ewPtQQ2On+W5pQ0RX2sYVcjkY1eLhT6wVSEewYDybucG77tnW tNwtbt7jDLPLMhP+fwCzuxc9TCndvZh+bJfpmhyiCiMldk38E0VqzmMwj0n8h8fVBYwl 7KOnnaYIvVb7er/NqBpiyXZkP1SCVTDi21RcljCATu5Ux2c1JTbIr4W6CDYHPjEuVS/Y VgCC1xd8NwcnGqHTKFFpkX9bD9CODtgWrp5YX67brh3iISR8e0paj/iZGDv7zyau0zRT hU/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=AKkEfjdoHGbVoKbr4xUEMS07lQumUdJTKR+cWS6/cLc=; b=E+qPvyTomJyt7Jkww/4HFomfN4QZPSy3JUj3MHpuukgC1lC4/rsIKaQIOQKtdQQUlg IdRsEmAl+Z0jtYx4U/yqOH/LptDog1ObQVCaA42/weVuMGD9FWtnNXbMnVn6vHB7sKGT G10XyadI+CFTmTklAK0QrNbJB5wBI5TxpTRV++ff/9iBGH78n2xb4Zf/mmrixZy22IS0 R7sIA42QXDaWrNanN51uQWG1MIoASueb+/WmLp3j5cVSLt5/KS6mIKRvap0nK1wARwBE ASiyzh3v9F2NafBf/hORx9fKB9ti/XJanlz9a/TrqB33BT22OZQyrbI+WJclDjgEE53y 562w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c9si2435120edv.304.2019.09.24.21.32.27; Tue, 24 Sep 2019 21:32:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406158AbfIWE0k (ORCPT + 99 others); Mon, 23 Sep 2019 00:26:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9461 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405826AbfIWE0k (ORCPT ); Mon, 23 Sep 2019 00:26:40 -0400 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 81D7689AC2 for ; Mon, 23 Sep 2019 04:26:39 +0000 (UTC) Received: by mail-pg1-f200.google.com with SMTP id m1so6586806pgq.5 for ; Sun, 22 Sep 2019 21:26:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AKkEfjdoHGbVoKbr4xUEMS07lQumUdJTKR+cWS6/cLc=; b=HfS4FvngV1QF7SE12LuTaglIMjK6cbtG4k0EgIjLYMzqFRTWKrThKbszzAM0j1oUwj /99YBGFDoAMyghI/lLyqeHlQ6bPToEEM8xzX6ysZKdUI+6UlMif603LyKs4TdqOSQyY8 py+dveaNuCGFnnJcY2BXmDQwOm4KM0BUelHlQpTUKYr0V2lkkpxaa68TyJxjX1Apib7B twxdU76SFswNNM78rG+8ixwIPFeCyEpQOUEf/P1Bzl5bCQ+KL/92TZg1DksGy5uFmM5k oGhncN+y961q6XrXLoDAZXYOBgFJNAQ7KBSDnJOkUnO31HfuiNCFli4Or4RObNve01Hr 040w== X-Gm-Message-State: APjAAAX3awsl1FRxuGvxh/YVUkz5sgC9gjfMZepog7ICOzpcR/xC8MB9 UCwT1HYSLSGxK+uhqki+7q0wqcDhKmkYbg/p9a52YuBb7ETfZYSw35Vi9/CGrH5PS3Ah3CrRKB4 HzvAyWmLA2KMuSiR/QnumoJyS X-Received: by 2002:a63:f745:: with SMTP id f5mr12778397pgk.175.1569212798978; Sun, 22 Sep 2019 21:26:38 -0700 (PDT) X-Received: by 2002:a63:f745:: with SMTP id f5mr12778387pgk.175.1569212798740; Sun, 22 Sep 2019 21:26:38 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id x20sm11781867pfp.120.2019.09.22.21.26.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Sep 2019 21:26:38 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Hugh Dickins , Maya Gokhale , Jerome Glisse , Pavel Emelyanov , Johannes Weiner , peterx@redhat.com, Martin Cracauer , Marty McFadden , Shaohua Li , Andrea Arcangeli , Mike Kravetz , Denis Plotnikov , Mike Rapoport , Linus Torvalds , Mel Gorman , "Kirill A . Shutemov" , "Dr . David Alan Gilbert" Subject: [PATCH v4 08/10] mm/gup: Allow VM_FAULT_RETRY for multiple times Date: Mon, 23 Sep 2019 12:25:21 +0800 Message-Id: <20190923042523.10027-9-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190923042523.10027-1-peterx@redhat.com> References: <20190923042523.10027-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is the gup counterpart of the change that allows the VM_FAULT_RETRY to happen for more than once. One thing to mention is that we must check the fatal signal here before retry because the GUP can be interrupted by that, otherwise we can loop forever. Signed-off-by: Peter Xu --- mm/gup.c | 27 +++++++++++++++++++++------ mm/hugetlb.c | 6 ++++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index e60d32f1674d..d2811bb15a25 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -644,7 +644,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; } @@ -994,7 +997,6 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm, down_read(&mm->mmap_sem); if (!(fault_flags & FAULT_FLAG_TRIED)) { *unlocked = true; - fault_flags &= ~FAULT_FLAG_ALLOW_RETRY; fault_flags |= FAULT_FLAG_TRIED; goto retry; } @@ -1069,17 +1071,30 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk, if (likely(pages)) 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 - * FAULT_FLAG_TRIED. + * with both FAULT_FLAG_ALLOW_RETRY and + * FAULT_FLAG_TRIED. Note that GUP can be interrupted + * by fatal signals, so we need to check it before we + * start trying again otherwise it can loop forever. */ + + if (fatal_signal_pending(current)) + break; + *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) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 31c2a6275023..d0c98cff5b0f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4347,8 +4347,10 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma, 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; } ret = hugetlb_fault(mm, vma, vaddr, fault_flags); -- 2.21.0