From patchwork Fri Nov 8 13:01:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 11234761 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DAD5A1864 for ; Fri, 8 Nov 2019 13:02:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A77F32246A for ; Fri, 8 Nov 2019 13:02:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ICNCj4oQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A77F32246A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3134F6B0006; Fri, 8 Nov 2019 08:02:28 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2775F6B0007; Fri, 8 Nov 2019 08:02:28 -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 1163A6B0008; Fri, 8 Nov 2019 08:02:28 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0037.hostedemail.com [216.40.44.37]) by kanga.kvack.org (Postfix) with ESMTP id ECBCD6B0006 for ; Fri, 8 Nov 2019 08:02:27 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 8805A82499A8 for ; Fri, 8 Nov 2019 13:02:27 +0000 (UTC) X-FDA: 76133123934.13.smash41_1568782eda417 X-Spam-Summary: 2,0,0,b9dbe315abb17a06,d41d8cd98f00b204,lixinhai.lxh@gmail.com,::akpm@linux-foundation.org:n-horiguchi@ah.jp.nec.com:mhocko@suse.com:vbabka@suse.cz:hughd@google.com:linux-man@vger.kernel.org,RULES_HIT:41:355:379:541:800:960:968:973:988:989:1260:1345:1359:1431:1437:1535:1542:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3872:5007:6121:6261:6653:7514:9413:9592:10004:11026:11473:11658:11914:12043:12114:12296:12297:12438:12517:12519:12555:12679:12895:13161:13229:14096:14181:14394:14687:14721:21060:21080:21094:21220:21323:21444:21451:21627:21666:21740:30054:30070,0,RBL:209.85.128.68:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: smash41_1568782eda417 X-Filterd-Recvd-Size: 5438 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Fri, 8 Nov 2019 13:02:26 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id q130so6162872wme.2 for ; Fri, 08 Nov 2019 05:02:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HPUhRkeh9B8kThmSnedxU9rFzUdfov5nG5Mv0o35La0=; b=ICNCj4oQpjkXiCCB0Lw81MOO95U7sKM5Kz8xpYLhoYoWOKMuZcvUoxtjKKt2jzSR7j B5OcXsUWasqOl0HZX88fjBqFaXzGpC64lEeWV8KES7451owMHRVYqpNcYa8q1l9gkETF br3nnWpAHxXNr8f4eAl6i72qi5FXxL1bDa0YlPKuOwRhzyLe8wDnrcT2pDYGNVQd7Ocs 9dotwsT9e/h2pKNp3/4UkbAKNYNPk8pwxD0kVfAtblBd7oSiuVGpBsOJN0Y65EQQxRTI uZOwvTSHB605E3E1LdbBCOnGxJN0/arC/Pkpx3ucDiXxdTXVSrX+eu8y1K+aMLNYeIaP bzpA== 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; bh=HPUhRkeh9B8kThmSnedxU9rFzUdfov5nG5Mv0o35La0=; b=AZbDoodukC4+y0gC9iJxubHHjsRGbZunSV9XWp6NZqieEGFBX/HZ3cJTzGNOiplmWA pQlvaoO1pO9AtrtTHi+8OXk+GCkB8yYLDSrsqO4tOXnbijIf/3rc+bNUS2/xxmnw3B3B 1sI3Vbg3ltsxW1nL2RKKgIDbvPWYX04cX35XKeedgrHxY8oDEKn41Ph0xf/OWRjyKlyR fN0FJVjLXt+VtMFqvEYQp4snZpTgH6ermQhtTgmEYKSnQhvCkDwIAws1AjAAWpqL68OW seleH0j27LhcJdpAZr6wS5lGgt6aZnavmyWzRfHOwfNdEoEysEinahFwCaf1ZGKuzd3X cPsA== X-Gm-Message-State: APjAAAWXiQMVkrhqKAR3hAaHOZ6wd3Y7BTLdjcsdfZGxjyTvjszZVqyT MjE5EuNcOF5Z+2gk/ZBZCl/+Eriq X-Google-Smtp-Source: APXvYqwMwb1ZXdjI8mkjWvVMXye8zLX+KycPXPXcNRDkji1B7sfa2iwgQH1CXXp9MvDKphQ3FqPzNw== X-Received: by 2002:a1c:9d07:: with SMTP id g7mr8198735wme.53.1573218145734; Fri, 08 Nov 2019 05:02:25 -0800 (PST) Received: from binjiang-hz-dhcp091254.china.nsn-net.net ([131.228.2.20]) by smtp.gmail.com with ESMTPSA id b8sm5873976wrt.39.2019.11.08.05.02.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Nov 2019 05:02:25 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: Andrew Morton , Naoya Horiguchi , Michal Hocko , Vlastimil Babka , Hugh Dickins , linux-man Subject: [PATCH v4 1/2] mm: Check range first in queue_pages_test_walk Date: Fri, 8 Nov 2019 21:01:43 +0800 Message-Id: <1573218104-11021-2-git-send-email-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1573218104-11021-1-git-send-email-lixinhai.lxh@gmail.com> References: <1573218104-11021-1-git-send-email-lixinhai.lxh@gmail.com> 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: Checking unmapped hole and updating the previous vma must be handled first, otherwise the unmapped hole could be calculated from a wrong previous vma. Several commits were relevant to this error: commit 6f4576e3687b ("mempolicy: apply page table walker on queue_pages_range()"), This commit was correct, the VM_PFNMAP check was after updateing previous vma commit 48684a65b4e3 (mm: pagewalk: fix misbehavior of walk_page_range for vma(VM_PFNMAP)), This commit added VM_PFNMAP check before updateing previous vma. Then, there were two VM_PFNMAP check did same thing twice. commit acda0c334028 (mm/mempolicy.c: get rid of duplicated check for vma(VM_PFNMAP) in queue_page s_range()), This commit tried to fix the duplicated VM_PFNMAP check, but it wrongly removed the one which was after updateing vma. Fixes: acda0c334028 (mm/mempolicy.c: get rid of duplicated check for vma(VM_PFNMAP) in queue_page s_range()) Cc: Andrew Morton Cc: Naoya Horiguchi Cc: Michal Hocko Cc: Vlastimil Babka Cc: Hugh Dickins Cc: linux-man Signed-off-by: Li Xinhai Reviewed-by: Naoya Horiguchi --- mm/mempolicy.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 4ae967b..807f06f 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -618,6 +618,16 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end, unsigned long endvma = vma->vm_end; unsigned long flags = qp->flags; + /* range check first */ + if (!(flags & MPOL_MF_DISCONTIG_OK)) { + if (!vma->vm_next && vma->vm_end < end) + return -EFAULT; + if (qp->prev && qp->prev->vm_end < vma->vm_start) + return -EFAULT; + } + + qp->prev = vma; + /* * Need check MPOL_MF_STRICT to return -EIO if possible * regardless of vma_migratable @@ -631,15 +641,6 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end, if (vma->vm_start > start) start = vma->vm_start; - if (!(flags & MPOL_MF_DISCONTIG_OK)) { - if (!vma->vm_next && vma->vm_end < end) - return -EFAULT; - if (qp->prev && qp->prev->vm_end < vma->vm_start) - return -EFAULT; - } - - qp->prev = vma; - if (flags & MPOL_MF_LAZY) { /* Similar to task_numa_work, skip inaccessible VMAs */ if (!is_vm_hugetlb_page(vma) &&