From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1CA2CA9EAE for ; Wed, 30 Oct 2019 02:50:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A9ED420874 for ; Wed, 30 Oct 2019 02:50:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727026AbfJ3CuX (ORCPT ); Tue, 29 Oct 2019 22:50:23 -0400 Received: from out30-45.freemail.mail.aliyun.com ([115.124.30.45]:43316 "EHLO out30-45.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726747AbfJ3CuX (ORCPT ); Tue, 29 Oct 2019 22:50:23 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07486;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0TgfhIsK_1572403814; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TgfhIsK_1572403814) by smtp.aliyun-inc.com(127.0.0.1); Wed, 30 Oct 2019 10:50:17 +0800 Subject: Re: mbind() breaks its API definition since v5.2 by commit d883544515aa (mm: mempolicy: make the behavior consistent when MPOL_MF_MOVE* and MPOL_MF_STRICT were specified) To: Li Xinhai , linux-mm , akpm , torvalds Cc: Vlastimil Babka , Linux API , Michal Hocko , Hugh Dickins , "linux-kernel@vger.kernel.org" , lixinhai_lxh References: <2019103010274679257634@gmail.com> From: Yang Shi Message-ID: Date: Tue, 29 Oct 2019 19:50:11 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <2019103010274679257634@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/29/19 7:27 PM, Li Xinhai wrote: > One change in do_mbind() of this commit has suspicious usage of return value of > queue_pages_range(), excerpt as below: > > --- > @@ -1243,10 +1265,15 @@ static long do_mbind(unsigned long start, unsigned long len, >   if (err) >   goto mpol_out; > > - err = queue_pages_range(mm, start, end, nmask, > + ret = queue_pages_range(mm, start, end, nmask, >    flags | MPOL_MF_INVERT, &pagelist); > - if (!err) > - err = mbind_range(mm, start, end, new); > + > + if (ret < 0) {      /////// convert to all possible 'ret' to '-EIO' <<<< > + err = -EIO; > + goto up_out; > + } > + > + err = mbind_range(mm, start, end, new); > >   if (!err) { >   int nr_failed = 0; > --- > > Note that inside queue_pages_range(), the call to walk_page_range() may return > errors from 'test_walk' of 'struct mm_walk_ops', e.g. -EFAULT. Now, those error > codes are no longer reported to user space application. > > From user space, the mbind() call need to reported error, with EFAULT, as example: > EFAULT > Part or all of the memory range specified by nodemask and maxnode points > outside your accessible address space. Or, there was an unmapped hole in the > specified memory range specified by addr and len. Thanks for catching this. That commit was aimed to correct the return values for some corner cases in mbind(), but it should not alter the errno for other failure cases, i.e. -EFAULT. Could you please try the below patch (build test only)? diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 4ae967b..99df43a 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1286,7 +1286,7 @@ static long do_mbind(unsigned long start, unsigned long len,                           flags | MPOL_MF_INVERT, &pagelist);         if (ret < 0) { -               err = -EIO; +               err = ret;                 goto up_out;         } > > Please correct me if this is the intended change(and will have updated API > definition), or something was misunderstood. > > -Xinhai