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=-7.0 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 2819CC2BA2B for ; Thu, 9 Apr 2020 13:53:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E38D82078E for ; Thu, 9 Apr 2020 13:53:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E38D82078E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 643828E000D; Thu, 9 Apr 2020 09:53:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F35F8E0006; Thu, 9 Apr 2020 09:53:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E2E48E000D; Thu, 9 Apr 2020 09:53:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3FC248E0006 for ; Thu, 9 Apr 2020 09:53:33 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 106C93499 for ; Thu, 9 Apr 2020 13:53:33 +0000 (UTC) X-FDA: 76688459106.22.smell25_3c0ee98ddf82c X-HE-Tag: smell25_3c0ee98ddf82c X-Filterd-Recvd-Size: 5657 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Thu, 9 Apr 2020 13:53:32 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id f13so5425100wrm.13 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=CuAKmp8ettRuobADRPl6PwKsgk4Nm9oOLA+y2bFfMrH/bl0KpojaMtzJuPGf3pBAqL WTk9FNtQLR1if3w3OqdM5Q6w1IBSLH6Ei0PM+gl6sb84Gta6/lyDbS7Ia2Mh8s7ruUQn RBqe+1amYGwX0Q1GHys0hA6ROt9YVdMc/oOgMyy49aNDsHXlOJdKGUNG4fIM8QsZ1jGi kYy9InF4R9ocRgi4EXVW2Vg1dVu50V2IKtkjt7ON8iDOI1C70Vgiul1c96uJ6bNYHG2X JH81MJ+mIzC1on/1w6URvDhAJT0zEh4lfVsYCcEqLsQwSdxWZBs38Sy8/3vh+ULsh49v 2KXg== X-Gm-Message-State: AGi0PuZVWYUZNLS2eKnpOHK7+3TimvHckwivu58+usPp/MpBwt9aBsDr 0K8Cu3y4TQJQgo0NxgnwrFs= X-Google-Smtp-Source: APiQypINKEmkU4epplatrkkKI1w1E/Sro3er6C0peFb0ml5TVRO95ltAF/sw9en/EZ9w//IPWwYWuw== 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> 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: 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