Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1822298ybb; Thu, 9 Apr 2020 09:38:10 -0700 (PDT) X-Google-Smtp-Source: APiQypLXyPI1EWFMPs7EVqqQZ+a0tsBoI0UD6I6vAusEfY3yDblMJYfl+Dc+h+XjubW+cEks3TG4 X-Received: by 2002:a0c:ed4c:: with SMTP id v12mr1008014qvq.120.1586450290606; Thu, 09 Apr 2020 09:38:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586450290; cv=none; d=google.com; s=arc-20160816; b=WkVUWtG88TSFN8aNrGgOA/+saj6VxrWSKRy8GfJLBv3KtDOwEPSg8B6ZWjqbWfInQo xAuHDNmdPl/SFbpaOU+e1GT06tL/FOcMbZogyjxdNtWelLUMLFo84jLiWJ2z+cIQMrri pNXV9FO7TdVjADUQ+XefrQZSZlc/OXDpHx6wxnjgdNO0UiUYdhPsO2BYHvSWdMYA57EJ UFafxqdHrFdr4KyybyBiwrzFXarjcvS7AeFmkY9gFEr5NVdIpKWD6vPxRMssgCF6GbGT 5aHmA4GwYUOLuw6VRVHNIDCv8nZ2oGFyvJeF4mUsTFdrEyAh5Sx6r5gAxkLF5eV9uRmg hzcA== 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=Akux9Z+0zMr8xGqw8muVR/uP7F01RBhzaSi9ymvwPQM=; b=CAeIxKlspwNku7uYi55GC5/h2CVEooYbqRnEVIjd+Tu72ZY+DKHFMI2SxXzQWJGx+F OK5CcJmm3IDAldjZKzw/GSgKfyE1lSSeLKDAKhIqo+muR3MRcrX5/RVthrNGsASkN9v5 s2pb04fmEcMt1/bFqkZflmbDBXRW0Zm73MajpzQ01C9wf/qFL1Cm5eMWUBRjTUZ1Tgos 0mxszuFsqqyh/iB0AFwS9zPspY61B+3+1WTB9WVLEtGyu3lb2X19dA8Lc/m3DIb4rK2P sm3s/H0oYjJRJLeq79T5BYUmJqcG2MCKHlhUc+bBOggQCVrSpuNGelALRgim24u0VTAN 6B5g== 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 p17si6265962qkg.49.2020.04.09.09.37.54; Thu, 09 Apr 2020 09:38:10 -0700 (PDT) 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 S1726952AbgDINxd (ORCPT + 99 others); Thu, 9 Apr 2020 09:53:33 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:32878 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726582AbgDINxd (ORCPT ); Thu, 9 Apr 2020 09:53:33 -0400 Received: by mail-wr1-f66.google.com with SMTP id a25so12038157wrd.0 for ; Thu, 09 Apr 2020 06:53:32 -0700 (PDT) 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=Akux9Z+0zMr8xGqw8muVR/uP7F01RBhzaSi9ymvwPQM=; b=f7gH6S7zRZy6zPPfAsJ49/pmhMT6gga2GfxcM1wIir4TkD1OaqUyMtY96zotzjRpw4 ubUBQm2ybiZAwvsgFY+HsaItvx36zHXrOgfb5bKkFErQpu6zjQ3+CnyKP0E2Kj1MT5RZ xwn+yR9d7ho0rcW5KHDaNMy+Xn6PBo71/rrWnrfJFGQ5PzifhgJDs/3VEF9IKRiTRnr5 d9Vrgi6BBYD1rIvuN0JrCfRfZUFeqMeD2OfX8MeI1GPsU7B/NgG7W5CqaBImB8IB6yCV OA5F3j71Ua1zJQ/R7QGBlzZ1xje560Zfh1F3t0d049ZfbKKZDcexVTPY/rtMMR5MO1ZM R2aA== X-Gm-Message-State: AGi0PuZWn7xEYbRq0SMMN8m3n7+UCPjmHX3a8eEIdjNAO+npRSXQBr7d e/k3IBD6W/MtOerwnwZsS4w= X-Received: by 2002:a5d:66c4:: with SMTP id k4mr15336291wrw.53.1586440411560; Thu, 09 Apr 2020 06:53:31 -0700 (PDT) Received: from localhost (ip-37-188-180-223.eurotel.cz. [37.188.180.223]) by smtp.gmail.com with ESMTPSA id f14sm3807055wmb.3.2020.04.09.06.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Apr 2020 06:53:30 -0700 (PDT) Date: Thu, 9 Apr 2020 15:53:29 +0200 From: Michal Hocko To: Peter Xu Cc: linux-kernel@vger.kernel.org, Linus Torvalds , linux-mm@kvack.org, Andrew Morton , syzbot+693dc11fcb53120b5559@syzkaller.appspotmail.com Subject: Re: [PATCH 1/2] mm/mempolicy: Allow lookup_node() to handle fatal signal Message-ID: <20200409135329.GI18386@dhcp22.suse.cz> References: <20200408014010.80428-1-peterx@redhat.com> <20200408014010.80428-2-peterx@redhat.com> <20200409070253.GB18386@dhcp22.suse.cz> <20200409125258.GA362416@xz-x1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200409125258.GA362416@xz-x1> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 09-04-20 08:52:58, Peter Xu wrote: > On Thu, Apr 09, 2020 at 09:02:53AM +0200, Michal Hocko wrote: > > This patch has been merged and it is actually wrong after ae46d2aa6a7f > > has been merged. We can either revert or I suggest just handling >0, > > like the patch below: > > > > From 03fbe30ec61e65b0927d0d41bccc7dff5f7eafd8 Mon Sep 17 00:00:00 2001 > > From: Michal Hocko > > Date: Thu, 9 Apr 2020 08:26:57 +0200 > > Subject: [PATCH] mm, mempolicy: fix up gup usage in lookup_node > > > > ba841078cd05 ("mm/mempolicy: Allow lookup_node() to handle fatal signal") has > > added a special casing for 0 return value because that was a possible > > gup return value when interrupted by fatal signal. This has been fixed > > by ae46d2aa6a7f ("mm/gup: Let __get_user_pages_locked() return -EINTR > > for fatal signal") in the mean time so ba841078cd05 can be reverted. > > This patch however doesn't go all the way to revert it because 0 return > > value is impossible. We always get an error or 1 for a single page > > request. > > > > Fixes: ba841078cd05 ("mm/mempolicy: Allow lookup_node() to handle fatal signal") > > Signed-off-by: Michal Hocko > > --- > > mm/mempolicy.c | 5 +---- > > 1 file changed, 1 insertion(+), 4 deletions(-) > > > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c > > index 48ba9729062e..1965e2681877 100644 > > --- a/mm/mempolicy.c > > +++ b/mm/mempolicy.c > > @@ -927,10 +927,7 @@ static int lookup_node(struct mm_struct *mm, unsigned long addr) > > > > int locked = 1; > > err = get_user_pages_locked(addr & PAGE_MASK, 1, 0, &p, &locked); > > - if (err == 0) { > > - /* E.g. GUP interrupted by fatal signal */ > > - err = -EFAULT; > > - } else if (err > 0) { > > + if (err > 0) { > > err = page_to_nid(p); > > put_page(p); > > } > > Hi, Michal, > > I'm totally not against this, but note that get_user_pages_locked() > could still return zero. Although I'm not 100% sure now on whether > npages==0 will be the only case, it won't hurt to keep this ret==0 > check until we consolidate the whole gup code to never return zero. As we have discussed in other email thread, returning 0 should be really possible only for an nr_pages == 0. And even in that case we should rather return EINVAL. I wanted to do that change as well but gup is a heavily used interface and I do not have time to check all existing callers. > Assuming there's another case (even possible for a future gup bug) > that could return a zero, your patch will let err be anything (which > you didn't initialize err with your patch), then the function will > return a random value. So even if you really want this change, I > would suggest you initialize err to some error code. I wouldn't really overcomplicate it. If you are worried about future bugs then we can warn into the log when !err && nr_pages somewher inside gup code. But let's keep callers as simple as possible. We surely do not want to check for !err in all users now. > I just don't see much gain we get from removing that check. The code clarity is the primary reason. -- Michal Hocko SUSE Labs