From patchwork Tue Oct 29 09:56:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 11217511 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 938E3139A for ; Tue, 29 Oct 2019 09:56:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 47A9521479 for ; Tue, 29 Oct 2019 09:56:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hiwLPue6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 47A9521479 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 4C3CD6B0005; Tue, 29 Oct 2019 05:56:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 473C66B0006; Tue, 29 Oct 2019 05:56:12 -0400 (EDT) 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 33AA06B0007; Tue, 29 Oct 2019 05:56:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0046.hostedemail.com [216.40.44.46]) by kanga.kvack.org (Postfix) with ESMTP id 09A886B0005 for ; Tue, 29 Oct 2019 05:56:12 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 8B27A8249980 for ; Tue, 29 Oct 2019 09:56:11 +0000 (UTC) X-FDA: 76096366542.30.mouth74_8d4de14e8a649 X-Spam-Summary: 30,2,0,2478745296319fde,d41d8cd98f00b204,lixinhai.lxh@gmail.com,::vbabka@suse.cz:mhocko@kernel.org:linux-kernel@vger.kernel.org:linux-api@vger.kernel.org:hughd@google.com:lixinhai.lxh@gmail.com,RULES_HIT:41:69:152:355:379:541:543:800:960:973:988:989:1185:1260:1277:1311:1313:1314:1345:1437:1514:1515:1516:1518:1535:1543:1593:1594:1605:1711:1730:1747:1777:1792:2393:2559:2562:2693:2895:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3874:4119:4250:5007:6121:6261:6653:7514:7903:9413:10004:10400:11026:11232:11473:11658:11783:11914:12043:12291:12296:12297:12438:12517:12519:12555:12679:12683:12895:12986:13161:13180:13229:13870:14093:14097:14181:14394:14687:14721:21080:21324:21444:21451:21627:21666:21740:21889:30054:30070,0,RBL:209.85.221.68:@gmail.com:.lbl8.mailshell.net-62.18.175.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:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: mouth74_8d4de14e8a649 X-Filterd-Recvd-Size: 8241 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Oct 2019 09:56:10 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id n15so12855894wrw.13 for ; Tue, 29 Oct 2019 02:56:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:mime-version:message-id :content-transfer-encoding; bh=0GNEenU2011/PH4SggKrsaKRrXslHs3UXAkLUcLLO8A=; b=hiwLPue6vy86WDrdqHm2o3s6xM93hQbe4km8mG3JrFVvLn5FnYi0GCLtCBfqh71xVU SoYFcP8bIKxZ1psKoWwybema1GZWpaR0jSprvgB3Q3EJTo3Hlgi+krX42LrFM2XpXCHq bnSiiNVDKHszrTMz1ZucynQNQy+lpgO4OulV7SFLrPHKYplrUdqTXxFsD6vX4dRbOtNa tuApwxvFn7YcKIw1WmoeAnA64G/9S+ki+W5R/Dr2Xs7XeCzGaGcy/Sr1pJNpU0ZljGub WJQcpv+tAUhp43wJ5iA4X2fl2GOsqv1DYIE59NZQrI7SfY9lZzzMG71kIT4aBb056lvg rBAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:mime-version:message-id :content-transfer-encoding; bh=0GNEenU2011/PH4SggKrsaKRrXslHs3UXAkLUcLLO8A=; b=b2Tqta4iyZCwtfcqWzjNfp52UzWkQ2g6HEaW1mhB3FJ5ChIR8Z39pi5aAQ9hT8M+e+ ip8GFqq1tlWxTkBke/sgK/akKs4AG+XjYa1iFi8sVTx9Db27naRov/ivr4d1qVYMsd3O 69w2fVuPymMtESb8A08GTwpUOZLL1Yu8NmCVauQkmMFGupIIiFYPcpOt0lns92qeQR0J SqbfVKLg2rabGvmggj33cOfaCTLJnendBWxqyRUMaFUuObH2rQuBRjaZHTU2KjQce4ln Xka+Tp0mRp9zPjTpzPP+QX3OYhNh202FFiuUh++uXcxQzPkItjcq4cQmHFB4N89UumKI Y34A== X-Gm-Message-State: APjAAAUW00ctfY8lj1T27UnnYjtXy4lSIdtaMjuI1es4mn2DHOYI1Si6 4XCmIMcKJgt3wOBAzv1ejTxkMO7oy1Y= X-Google-Smtp-Source: APXvYqzfFjBHTXKuP5Im1zoFpnPIG53tHWAfwEjwfOT4KbqX+pChWEmW0KMjtVOR+smMwtek/G2dSw== X-Received: by 2002:adf:9799:: with SMTP id s25mr19129714wrb.390.1572342969314; Tue, 29 Oct 2019 02:56:09 -0700 (PDT) Received: from N-20L6PF1KTYA2 ([131.228.2.20]) by smtp.gmail.com with ESMTPSA id u21sm2049943wmj.22.2019.10.29.02.56.06 (version=TLS1_2 cipher=AES128-GCM-SHA256 bits=128/128); Tue, 29 Oct 2019 02:56:08 -0700 (PDT) Date: Tue, 29 Oct 2019 17:56:06 +0800 From: "Li Xinhai" To: "linux-mm@kvack.org" Cc: Babka , Hocko , "linux-kernel@vger.kernel.org" , API , Dickins , lixinhai.lxh Subject: [PATCH v2] mm: Fix checking unmapped holes for mbind X-Priority: 3 X-GUID: B71B0C6B-59A2-47FA-A2D5-5061B26F9AC0 X-Has-Attach: no X-Mailer: Foxmail 7.2.13.365[cn] Mime-Version: 1.0 Message-ID: <201910291756045288126@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: queue_pages_range() will check for unmapped holes besides queue pages for migration. The rules for checking unmapped holes are: 1 Unmapped holes at any part of the specified range should be reported as   EFAULT if mbind() for none MPOL_DEFAULT cases; 2 Unmapped holes at any part of the specified range should be ignored if   mbind() for MPOL_DEFAULT case; Note that the second rule is the current implementation, but it seems conflicts the Linux API definition. queue_pages_test_walk() is fixed by introduce new fields in struct queue_pages which help to check: 1 holes at head and tail side of specified range; 2 the whole range is in a hole; Besides, queue_pages_test_walk() must update previous vma record no matter the current vma should be considered for queue pages or not. Fixes: 9d8cebd4bcd7 ("mm: fix mbind vma merge problem") Fixes: 6f4576e3687b ("mempolicy: apply page table walker on queue_pages_range()") Fixes: 48684a65b4e3 ("mm: pagewalk: fix misbehavior of walk_page_range for vma(VM_PFNMAP)") Signed-off-by: Li Xinhai --- Changes in v2:   - Fix the unmapped holes checking in queue_pages_test_walk() instead of      mbind_rnage().  mm/mempolicy.c | 44 +++++++++++++++++++++++++++++---------------  1 file changed, 29 insertions(+), 15 deletions(-) --  2.22.0 diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 4ae967bcf954..24087dfa4dcd 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -411,6 +411,9 @@ struct queue_pages {   unsigned long flags;   nodemask_t *nmask;   struct vm_area_struct *prev; + unsigned long start; + unsigned long end; + int in_hole;  };    /* @@ -618,28 +621,31 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end,   unsigned long endvma = vma->vm_end;   unsigned long flags = qp->flags;   - /* - * Need check MPOL_MF_STRICT to return -EIO if possible - * regardless of vma_migratable - */ - if (!vma_migratable(vma) && -    !(flags & MPOL_MF_STRICT)) - return 1; - + /* range check first */   if (endvma > end)   endvma = end; - if (vma->vm_start > start) - start = vma->vm_start; + BUG_ON((vma->vm_start > start) || (vma->vm_end < end));   + qp->in_hole = 0;   if (!(flags & MPOL_MF_DISCONTIG_OK)) { - if (!vma->vm_next && vma->vm_end < end) + if ((!vma->vm_next && vma->vm_end < qp->end) || + (vma->vm_next && qp->end < vma->vm_next->vm_start))   return -EFAULT; - if (qp->prev && qp->prev->vm_end < vma->vm_start) + if ((qp->prev && qp->prev->vm_end < vma->vm_start) || + (!qp->prev && qp->start < vma->vm_start))   return -EFAULT;   }     qp->prev = vma;   + /* + * Need check MPOL_MF_STRICT to return -EIO if possible + * regardless of vma_migratable + */ + if (!vma_migratable(vma) && +    !(flags & MPOL_MF_STRICT)) + return 1; +   if (flags & MPOL_MF_LAZY) {   /* Similar to task_numa_work, skip inaccessible VMAs */   if (!is_vm_hugetlb_page(vma) && @@ -679,14 +685,23 @@ queue_pages_range(struct mm_struct *mm, unsigned long start, unsigned long end,   nodemask_t *nodes, unsigned long flags,   struct list_head *pagelist)  { + int err;   struct queue_pages qp = {   .pagelist = pagelist,   .flags = flags,   .nmask = nodes,   .prev = NULL, + .start = start, + .end = end, + .in_hole = 1,   };   - return walk_page_range(mm, start, end, &queue_pages_walk_ops, &qp); + err = walk_page_range(mm, start, end, &queue_pages_walk_ops, &qp); + /* whole range in unmapped hole */ + if (qp->in_hole && !(flags & MPOL_MF_DISCONTIG_OK)) + err = -EFAULT; + + return err;  }    /* @@ -738,8 +753,7 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,   unsigned long vmend;     vma = find_vma(mm, start); - if (!vma || vma->vm_start > start) - return -EFAULT; + BUG_ON(!vma);     prev = vma->vm_prev;   if (start > vma->vm_start)