Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp270312ybl; Thu, 23 Jan 2020 23:27:23 -0800 (PST) X-Google-Smtp-Source: APXvYqyAjvBbb8rscMgCo1wKId9YSCFE4c7muFrG8yOFfsusO09vK4168m6FZgOk0nv6eFzMCF+M X-Received: by 2002:a9d:5c1:: with SMTP id 59mr1751453otd.192.1579850843206; Thu, 23 Jan 2020 23:27:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579850843; cv=none; d=google.com; s=arc-20160816; b=iLAx8e3uZBkzESKfDfxeG5iYRxWQgJLvJw4odb3BWhbHYUa3p4aOBaZeF5910MkUqh i2GZBRjR5FQmbriqyVSTfylV28ageA/7lR32F499Wg3DUn23eED0Mnh2nh3OBs5E/U1P ALrl1yY1VnFY7uuDR05bNlUekT5nyJOrL1lk6YmcceBwtypT7XgZLgiBqv9n6rs58I8R NGfoLbougncChM9TrHrf4jnZw/yKyGCKTgL4KQyR8cPcWCVGMQc0/UlVOx8kMdeO7wJT FqKepH56oJu5dNpgu/1e3gRvXWIkuYC4ub6nSUNpYb0fVAZGRpE1rS5VHdHwOEmWetTk uF5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=p8GGZGknnfG7tWMIgP6ZXfED0+y7Mb/Mp5pjgGPqFBI=; b=ChJRp/jt7aYg0wpEnRtWZ10reSazZGP4m3QNiLt73KnD0uSWbS8JO/f+ObHkURaIvu JQ1Pfv9/7FcnnDlvu7A2v8vQkHV5Oef2VuNKLIYWFXPbOo1lJ9iOrsbR0eFw8cGdjKsX ruMuk95Zxkh0gj8TJhFL9PK1PK7fG74JITgsD4UKIhuLYf30jnstCp6nLXzFb5FBvWIw gDYRWEeAOWpBJbjVqqqSBQaG740yMSW9OnbAsuax1uLaQmLJ6YyFJzCRMcZAG0jM4EMK TeIVg5g6etOgm9O1ypLrkNPLt5sPryhFguAt3PpRsO3zMsp5roj71uFyd931iOoMgxq3 aIEw== 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 30si2321639otr.75.2020.01.23.23.27.10; Thu, 23 Jan 2020 23:27:23 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730349AbgAXHVc (ORCPT + 99 others); Fri, 24 Jan 2020 02:21:32 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:38380 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725817AbgAXHVb (ORCPT ); Fri, 24 Jan 2020 02:21:31 -0500 Received: by mail-wm1-f65.google.com with SMTP id u2so669201wmc.3 for ; Thu, 23 Jan 2020 23:21:30 -0800 (PST) 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:message-id:references :mime-version:content-disposition:in-reply-to; bh=p8GGZGknnfG7tWMIgP6ZXfED0+y7Mb/Mp5pjgGPqFBI=; b=qyvDK+lcW3RMOT/vuP80DLXtbFLFMn6xdnMG0vV/Iznhpjw6EaiSc4HaafaZn5Y1QO wwc8qxKb8xuVcxpdopaAL136vC5eCTdk7AGzJz1BIELh+5xHFZcY8yiniDkxmPpvh93I c7rjWT+uBC1WGQ0OJzLTJc1CNFccMRI6ynqVboP0dgcPS0nPVF8zZnF/la/zySQ7Akkg xqxYDn3mt7to8gRK49WQtpmAa1eMuXzNiWctB4A8kHaOi4QzEf+Cv1dbczGqI03cZktu b9kKp/iMVdNxQdkTs1I6EtoKFXG6ddgNQFg99ekRB2mlGj6xjMz+tCb1DCC9ssBEpHnI q2rA== X-Gm-Message-State: APjAAAWIgyHDBABE0dFuJzhnFOiWf3VAwNB7lMNeUayY5F4e9wwdC7U2 lXt8SulUMTQiOdK517TmwzCv9fth X-Received: by 2002:a05:600c:2187:: with SMTP id e7mr737753wme.11.1579850489739; Thu, 23 Jan 2020 23:21:29 -0800 (PST) Received: from localhost (ip-37-188-162-110.eurotel.cz. [37.188.162.110]) by smtp.gmail.com with ESMTPSA id v14sm6322363wrm.28.2020.01.23.23.21.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2020 23:21:29 -0800 (PST) Date: Fri, 24 Jan 2020 08:21:27 +0100 From: Michal Hocko To: Wei Yang Cc: akpm@linux-foundation.org, yang.shi@linux.alibaba.com, jhubbard@nvidia.com, vbabka@suse.cz, cl@linux.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [Patch v2] mm/migrate.c: also overwrite error when it is bigger than zero Message-ID: <20200124072127.GO29276@dhcp22.suse.cz> References: <20200119065753.21694-1-richardw.yang@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200119065753.21694-1-richardw.yang@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [Sorry I have missed this patch previously] On Sun 19-01-20 14:57:53, Wei Yang wrote: > If we get here after successfully adding page to list, err would be > 1 to indicate the page is queued in the list. > > Current code has two problems: > > * on success, 0 is not returned > * on error, if add_page_for_migratioin() return 1, and the following err1 > from do_move_pages_to_node() is set, the err1 is not returned since err > is 1 This made my really scratch my head to grasp. So essentially err > 0 will happen when we reach the end of the loop and rely on the out_flush flushing to migrate the batch. Then err contains the add_page_for_migratioin return value. And that would leak to the userspace. What would you say about the following wording instead? " out_flush part of do_pages_move is responsible for migrating the last batch that accumulated while processing the input in the loop. do_move_pages_to_node return value is supposed to override any preexisting error (e.g. when the user input is garbage) but the current logic is wrong because add_page_for_migration returns 1 when successfully adding a page into the batch and therefore this will be the last err value after the loop is processed without any actual error. We want to override that value of course because do_pages_move would return 1 to the userspace even without any errors. " > And these behaviors break the user interface. > > Fixes: e0153fc2c760 ("mm: move_pages: return valid node id in status if the > page is already on the target node"). > Signed-off-by: Wei Yang Acked-by: Michal Hocko > > --- > v2: > * put more words to explain the error case > --- > mm/migrate.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/migrate.c b/mm/migrate.c > index 86873b6f38a7..430fdccc733e 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -1676,7 +1676,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes, > err1 = do_move_pages_to_node(mm, &pagelist, current_node); > if (!err1) > err1 = store_status(status, start, current_node, i - start); > - if (!err) > + if (err >= 0) > err = err1; > out: > return err; > -- > 2.17.1 > -- Michal Hocko SUSE Labs