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=-3.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 B21C0C2BA19 for ; Tue, 14 Apr 2020 13:49:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 66FE720644 for ; Tue, 14 Apr 2020 13:49:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PFnyn+Co" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 66FE720644 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D905D8E0003; Tue, 14 Apr 2020 09:49:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3FB68E0001; Tue, 14 Apr 2020 09:49:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C54838E0003; Tue, 14 Apr 2020 09:49:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id AAC2D8E0001 for ; Tue, 14 Apr 2020 09:49:12 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 64712247F for ; Tue, 14 Apr 2020 13:49:12 +0000 (UTC) X-FDA: 76706592144.28.drop54_161d7bf16cb0c X-HE-Tag: drop54_161d7bf16cb0c X-Filterd-Recvd-Size: 6105 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Apr 2020 13:49:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586872151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x+ArsMfE1ghc0ammAkcYgi5iotTqCBWo/vftM0rYE5M=; b=PFnyn+CozpRp/mmmDoQFCqiIFNMDdVORtIvWm92CXD5Bo3SWqKHZ2QUkhBWP5JUKhyxxXr KF2MZhdJexDOmxPufcZtWhjcK/sFgWC4vWp0T2zQFdmlClIDaOokJivMmWHeyq8YFQGUcD iwbfZWiy6WP3OxILknuga12K05JufDk= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-294-wyU7O1-KOTm92r_ZZ71haw-1; Tue, 14 Apr 2020 09:49:09 -0400 X-MC-Unique: wyU7O1-KOTm92r_ZZ71haw-1 Received: by mail-qt1-f200.google.com with SMTP id e44so12384985qta.9 for ; Tue, 14 Apr 2020 06:49:09 -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=kHDd15U+utIVIYTBnW0m937vVJqUYSl9E32F9MiM/Ow=; b=rp1USYMqM5Xa2QVeSxax93HGTN4K1sxs+YKqk7TAfIox4bjIWyt+dwu3QpTvdkOxGM /u7p4wz7lC1X86q7/sxnD+XYSNQzgO3bw3aBLXcxgLzib3y4W2kny4rW7h7RzGzW0EM8 hm6ve0US64S2YnjQtqXcpL4Dl0pq9uzske2kjUJSC9ohLUiLXR2H6wgJZTAh6g3IEhOA +gdk1VJ3HTyHBE2oyWEAREft9bCQgLXR0ZI+WlC7pZp4CEwidZ7uRSAJKswWbai/7c3X qnPWwhas0dYd2aQnk9yHO9xj3F0QtDoApDYgJT3iJ80ut0sI6+kGKKy+d8SHvygyJieF +kYw== X-Gm-Message-State: AGi0Pub5el/UN4kPF3SI73PHr1laFC1Mg4CF3PfQFshr3mALVX/CLws8 MF/GB04jcfuB/z8x5Dz4FIoMoNOQi3MHSoikrhfsVL8e5AB8UuOoLa+JiVbDa6vy4hYMqSnGumN GkJWrJXPielw= X-Received: by 2002:ac8:23ed:: with SMTP id r42mr16349881qtr.372.1586872149304; Tue, 14 Apr 2020 06:49:09 -0700 (PDT) X-Google-Smtp-Source: APiQypKk1CxvePF721u7zCAPiQ9xQbBy20rE/GYRkwegXAxvCmLozUAOeoCxNg/oiUCi+k1GjuUhog== X-Received: by 2002:ac8:23ed:: with SMTP id r42mr16349845qtr.372.1586872148758; Tue, 14 Apr 2020 06:49:08 -0700 (PDT) Received: from xz-x1 ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id c41sm7218899qta.96.2020.04.14.06.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2020 06:49:07 -0700 (PDT) Date: Tue, 14 Apr 2020 09:49:06 -0400 From: Peter Xu To: Michal Hocko Cc: Linus Torvalds , Linux Kernel Mailing List , Linux-MM , Andrew Morton , syzbot+693dc11fcb53120b5559@syzkaller.appspotmail.com Subject: Re: [PATCH 1/2] mm/mempolicy: Allow lookup_node() to handle fatal signal Message-ID: <20200414134906.GF38470@xz-x1> References: <20200408014010.80428-1-peterx@redhat.com> <20200408014010.80428-2-peterx@redhat.com> <20200409070253.GB18386@dhcp22.suse.cz> <20200414110429.GF4629@dhcp22.suse.cz> MIME-Version: 1.0 In-Reply-To: <20200414110429.GF4629@dhcp22.suse.cz> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 Tue, Apr 14, 2020 at 01:04:29PM +0200, Michal Hocko wrote: [...] > @@ -1247,6 +1248,10 @@ int fixup_user_fault(struct task_struct *tsk, stru= ct mm_struct *mm, > } > EXPORT_SYMBOL_GPL(fixup_user_fault); > =20 > +/* > + * Please note that this function, unlike __get_user_pages will not > + * return 0 for nr_pages > 0 without FOLL_NOWAIT > + */ > static __always_inline long __get_user_pages_locked(struct task_struct *= tsk, > =09=09=09=09=09=09struct mm_struct *mm, > =09=09=09=09=09=09unsigned long start, > 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, unsigne= d long addr) > =20 > =09int locked =3D 1; > =09err =3D get_user_pages_locked(addr & PAGE_MASK, 1, 0, &p, &locked); > -=09if (err =3D=3D 0) { > -=09=09/* E.g. GUP interrupted by fatal signal */ > -=09=09err =3D -EFAULT; > -=09} else if (err > 0) { > +=09if (err > 0) { > =09=09err =3D page_to_nid(p); > =09=09put_page(p); > =09} Hi, Michal, IIUC this is not the only place that we check against ret=3D=3D0 for gup. For example, the other direct caller of the same function, get_vaddr_frames(), which will set -EFAULT too if ret=3D=3D0. So do we want to change all the places and don't check against zero explicitly? I'm now thinking whether this would be good even if we refactored gup and only allow it to return either >0 as number of page pinned, or <0 for all the rest. I'm not sure how others will see this, but the answer is probably the same at least to me as before for this issue. As a caller, I'll see gup as a black box. Even if the gup function guarantees that the retcode won't be zero and documented it, I (as a caller) will be using that to index page array so I'd still better to check that value before I do anything (because it's meaningless to index an array with zero size), and a convertion of "ret=3D=3D0" --> "-EFAULT" (or some other failures) in this case still makes sense. While removing that doesn't help a lot, imho, but instead make it slightly unsafer. Maybe that's also why ret=3D=3D0 hasn't been reworked for years? Maybe there is just never a reason strong enough to do that explicitly, because it's still good to check against ret=3D=3D0 after all... Thanks, --=20 Peter Xu