Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1036532ybv; Thu, 20 Feb 2020 11:54:41 -0800 (PST) X-Google-Smtp-Source: APXvYqwXWBmhjMi9d0aVoK5nP7PmHFvuCtL9kjsLBjmwPosVmJ/tZaUZfvDVgI23dahf8E/IsKIx X-Received: by 2002:a54:4106:: with SMTP id l6mr3306049oic.76.1582228481237; Thu, 20 Feb 2020 11:54:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582228481; cv=none; d=google.com; s=arc-20160816; b=hkfND9JCiYKWtgP1R0hp8Vp1MZzMGKSsE7YkSU/bJBuk20Dt2XJnwlxr493eearoDj 2xApUcVdQULsxgFBS5vHfjRP7M325zoYrsQMTlu2VkiG8m6cyfdpV2gInlMu0LzAVVot JSHYJJmP+qqN0+JVYAZ3eF/5VoYF9P2DQg6Yz0MeCJNMYb+H8IQq7AYNedadBPq0Z5jf eg5Zkz6TDvHhbh0VHIatB1l0l9E7PvInQKpN/hMxzyo7iZonMkvpKtLFS8rqwGvSqmhY R0IjazPEDoYse38ihVytqCOZMQnn0Jx8ScrMwthEsApvEVZULXoq6Ng06m1kQI4bBqNJ QFxg== 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 :dkim-signature; bh=Fez1YLYoRTejKdl3XovFZRqHL8yeL2JwUep3jNimnQM=; b=uR2MugLp9PnaINcoxi7bSYVuxldpRMWbilnjb1mqgIZ/cFp/3j9OxlyzKB2KiuPMfl c/Jdw5JV4e8BHwWJk86UOwEu5AUlxRaTz5W3Q3x9A91XiKDWkLyQqwj6iJty72JVHCQt A7P79Z4otgfpcZNTM1+nDGLNPEv7EYVseYYmKqIf6TS8mcVZvBXmybFQCkgOal7t5pkp sQ9w8yvfMqwZfnsu51GQecHCHVyKJRKjp2/vR3tT0Zp45fMIHewFMnYAshMKZvJ0vyBe InnGo3ln4OvLnBU93Di2kIkYjd21TVfkjDKR5oP9ljktVpRwhzk1QInbHWL//9qFcnNy PvzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WLzTcpTU; 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=pass (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 u123si128636oif.84.2020.02.20.11.54.28; Thu, 20 Feb 2020 11:54:41 -0800 (PST) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WLzTcpTU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728985AbgBTTyD (ORCPT + 99 others); Thu, 20 Feb 2020 14:54:03 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:49865 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728556AbgBTTyD (ORCPT ); Thu, 20 Feb 2020 14:54:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582228442; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fez1YLYoRTejKdl3XovFZRqHL8yeL2JwUep3jNimnQM=; b=WLzTcpTU2VGcnTgHsUzdEjIub5u2+7yDAgL+UD16gT09lNzslx1xOEySgq2VV0xRu81c+l uwZZYwi9bTWbmf2qApbo6xlbsmQigyQhhJIDb5FRPCIK+UNKYcB9KjUT9sAWle88PT9+VC ubuiovkClXAykm67izuPw5nWX+OJaYE= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-31-Ar63fx_ePSS9Hvsku2YrUQ-1; Thu, 20 Feb 2020 14:54:00 -0500 X-MC-Unique: Ar63fx_ePSS9Hvsku2YrUQ-1 Received: by mail-qt1-f199.google.com with SMTP id r30so3373174qtb.10 for ; Thu, 20 Feb 2020 11:54:00 -0800 (PST) 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=Fez1YLYoRTejKdl3XovFZRqHL8yeL2JwUep3jNimnQM=; b=Db+NET4UXZ3i9Ya0tN5mVBrstQ4hFGW4FkHCL9gWu61FkOurCtmeQY2LaH4zEOZOYg pn/cZO4KMjIBS/Idgbi85LrcOrXJRL8zoGqu8lC9Ew/goPyhoiVmcrnRtP7rZxtX9vQb Sa+PsdnAKhNWOQK34Ri8XQcWpEyoJElIxpk8X1HLu4coKBdPSejaCWiZV35jIKqveqQJ QXyvM/U19Du/OhCd05AJzBGAg5Iy3eSbsgkN41HbQ4nCFLtKktyqErTnNpPOKEoI3zyl CG7V9awYnLX2qWFp5AdrpOODNu3odO4vHX9KsLSK+Dz5iep6ZHfufH4VMZHfep96FYic 7MZg== X-Gm-Message-State: APjAAAXD1bKmqJhDmp7VkXCiyXQzkrR1P5lHXKHIvsd6taDaFZ6juneY M/s6o10G44Wzxo/7q+IyaFAb9an3Ain9h7zDW4FlIZZOTugRyW4jh4y0Hmz/ZaUtP9GX1V+sd61 T6qEWbwGjduT+Hex7C6TwmYiu X-Received: by 2002:a05:6214:1750:: with SMTP id dc16mr27322419qvb.47.1582228439903; Thu, 20 Feb 2020 11:53:59 -0800 (PST) X-Received: by 2002:a05:6214:1750:: with SMTP id dc16mr27322394qvb.47.1582228439636; Thu, 20 Feb 2020 11:53:59 -0800 (PST) Received: from xz-x1.redhat.com ([104.156.64.75]) by smtp.gmail.com with ESMTPSA id a192sm332776qkb.53.2020.02.20.11.53.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 11:53:59 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Peter Xu , Martin Cracauer , Mike Rapoport , Hugh Dickins , Jerome Glisse , "Kirill A . Shutemov" , Matthew Wilcox , Pavel Emelyanov , Brian Geffon , Maya Gokhale , Denis Plotnikov , Andrea Arcangeli , Johannes Weiner , "Dr . David Alan Gilbert" , Linus Torvalds , Mike Kravetz , Marty McFadden , David Hildenbrand , Bobby Powers , Mel Gorman Subject: [PATCH RESEND v6 14/16] mm/gup: Allow VM_FAULT_RETRY for multiple times Date: Thu, 20 Feb 2020 14:53:57 -0500 Message-Id: <20200220195357.16371-1-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220155353.8676-1-peterx@redhat.com> References: 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 76cb420c0fb7..ec2b76f44a01 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -652,7 +652,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; } @@ -1012,7 +1015,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; } @@ -1096,17 +1098,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 c84f721db020..ac9a28d51674 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4343,8 +4343,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.24.1