Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4406842rdb; Fri, 15 Sep 2023 00:44:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1jNHIBjSR7/lSvzy9DPUWDWwXtPhk8bC+K/WJ0SO/VQofLztWUpeYBJuy6q8xvWVwADyL X-Received: by 2002:a05:6a00:218e:b0:68e:2822:fb36 with SMTP id h14-20020a056a00218e00b0068e2822fb36mr966246pfi.8.1694763855967; Fri, 15 Sep 2023 00:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694763855; cv=none; d=google.com; s=arc-20160816; b=fG5zSmzXtimU6QayB7+ueO5D7MQs5GrKTr3t8c2GUBRdinIFt215l18swoEAIpZ2HN y477OLjHVxrOoLOwKzTDd57ulxtqVOS/hb7IG2D/uBKbHQyYANT4T6EXgNzWa1Gu4lXl 54pP3QfY3m4CO4kWljoBBPwkDSF7d1CrxCMP1om5qx1J57RH5FcikgA4EoNMl0v2bHrS OqozImQ/wGNeehhuERzJky5EZ3oDEO7Cd4KUzD2tMXETKdUgntI7UaC/so/WomML/kyn rbBhvkUa5+YrR621g/BjgAyCbbrmUs7nuOFA0HfhW36qi3kHzpEJv/2iCE7MO26flY1Z KXrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=UKqdJpEhXaeQzQWCZBTpv9uWAL/fOLXY3yRJZGmhuG4=; fh=VuSinnOYg5yTNCGSSw+83GHBJK9yGAw0IRMQjAyxyfA=; b=D7biDhGlkJEnwPA5ibPzmjFVMVK7pc5W/izCJUDTNC3MIRoI8TpGzMzI9LCZAxvA5K GVaTlvjUFf0bprc0V4KT7i1ak8LNMH50TPTL4j7ftqQ1lF5qTU7u22m5ied0IOixn49b AnBrfX7r8uLzL/qT6rw/1QXWfJ9U0+uQUwpuUXwi7tmJ/8geTcJH4p2qpGXVCPuNKVJH HqcXvXx+jkOiYSRboHygRziffj+xFMohirhHoTs8HY6YOjNQuL4hS5Qz2Y81gjU8W0ki 3vhxRJ8NPDOU3qKmbyY9IstUtPqleISPSkOb6o2UI/U4lcNe8PVQWs+3GxxjtdQWuNwu Rnmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=UsoH84Ua; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id j70-20020a638049000000b00573fe94635asi2861429pgd.642.2023.09.15.00.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 00:44:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=UsoH84Ua; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id E7808837B5F5; Thu, 14 Sep 2023 13:54:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229719AbjINUyS (ORCPT + 99 others); Thu, 14 Sep 2023 16:54:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjINUyR (ORCPT ); Thu, 14 Sep 2023 16:54:17 -0400 Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9104E1BEF for ; Thu, 14 Sep 2023 13:54:13 -0700 (PDT) Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-58c92a2c52dso15646837b3.2 for ; Thu, 14 Sep 2023 13:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694724853; x=1695329653; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UKqdJpEhXaeQzQWCZBTpv9uWAL/fOLXY3yRJZGmhuG4=; b=UsoH84UakKh1w0iRggqwt52thpyelaHQldRQGUWWB/r+qKyFeBjovW+00jurBoXZcH DjTKjBFLugfOIbOG1xpRu5WqdMgi7HI23IzAgBi0SPYE1wR64SywnwAutgXiNcFRQLnH NGFd/hz8osZnpyseMp82kEHJKSxrngEupGeSrPR2mBViG7TVzxgJtFev1DXiV4r663ja IGqD/LwTXG0L5DWj91AwULcwEaUXcmy6hcS7w5CYhI9qY6tqVv30OlCGHvvMJw8Bjr4V wwifs/IOjYlev6kd6qw7WUHXcf8WH4hB6qauPloUMkXcr2t1ylUzsyw+r5qlTqJT5dte fLkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694724853; x=1695329653; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UKqdJpEhXaeQzQWCZBTpv9uWAL/fOLXY3yRJZGmhuG4=; b=VhL98JUrE0NFR99LYCsPm5J2DOfObY0F3P7EQBMBflOq5WeqMd3nbCWGp47M/R95Yr odEGq445xaZ9GFqJHmI0QokmaAD0rXFPrHCpDAEumrWCKMWdISKz7di2OzIbG4XXUCWQ rkafFutuOqr6hdJ0SFSxfGXu2XDneaYP1drl0AbvA4JtG4Ng7btC/ilHwd5izD/zzAuc cWK52WQUQalWynINZ3Vd/5+8LfyvidVtMsNzTtkB6f0dmaUF6EelWKO+6P3N/mbeWeph w/UWdPYnXWKqjF9ACITnPp4Erq/MKDUd3s8iMbGhj/i7BuS2ugjDn0FK4GqzyNboyZJS xRtg== X-Gm-Message-State: AOJu0Yyz/M8az2wOkMQLw0f7kG3TkR1UeF4+RkSlouLdAjsIBmzhLj5N wWt17QlUqguz+Ul7RCE2G5DzVcWxkRhHQe9kLjZ76gtTuSxg6kabtiCReA== X-Received: by 2002:a0d:ca97:0:b0:59b:d351:60cd with SMTP id m145-20020a0dca97000000b0059bd35160cdmr5897145ywd.38.1694724852506; Thu, 14 Sep 2023 13:54:12 -0700 (PDT) MIME-Version: 1.0 References: <000000000000f392a60604a65085@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 14 Sep 2023 20:53:59 +0000 Message-ID: Subject: Re: [syzbot] [mm?] kernel BUG in vma_replace_policy To: Matthew Wilcox Cc: syzbot , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 14 Sep 2023 13:54:28 -0700 (PDT) X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email On Thu, Sep 14, 2023 at 8:00=E2=80=AFPM Suren Baghdasaryan wrote: > > On Thu, Sep 14, 2023 at 7:09=E2=80=AFPM Matthew Wilcox wrote: > > > > On Thu, Sep 14, 2023 at 06:20:56PM +0000, Suren Baghdasaryan wrote: > > > I think I found the problem and the explanation is much simpler. Whil= e > > > walking the page range, queue_folios_pte_range() encounters an > > > unmovable page and queue_folios_pte_range() returns 1. That causes a > > > break from the loop inside walk_page_range() and no more VMAs get > > > locked. After that the loop calling mbind_range() walks over all VMAs= , > > > even the ones which were skipped by queue_folios_pte_range() and that > > > causes this BUG assertion. > > > > > > Thinking what's the right way to handle this situation (what's the > > > expected behavior here)... > > > I think the safest way would be to modify walk_page_range() and make > > > it continue calling process_vma_walk_lock() for all VMAs in the range > > > even when __walk_page_range() returns a positive err. Any objection o= r > > > alternative suggestions? > > > > So we only return 1 here if MPOL_MF_MOVE* & MPOL_MF_STRICT were > > specified. That means we're going to return an error, no matter what, > > and there's no point in calling mbind_range(). Right? > > > > +++ b/mm/mempolicy.c > > @@ -1334,6 +1334,8 @@ static long do_mbind(unsigned long start, unsigne= d long len, > > ret =3D queue_pages_range(mm, start, end, nmask, > > flags | MPOL_MF_INVERT, &pagelist, true); > > > > + if (ret =3D=3D 1) > > + ret =3D -EIO; > > if (ret < 0) { > > err =3D ret; > > goto up_out; > > > > (I don't really understand this code, so it can't be this simple, can > > it? Why don't we just return -EIO from queue_folios_pte_range() if > > this is the right answer?) > > Yeah, I'm trying to understand the expected behavior of this function > to make sure we are not missing anything. I tried a simple fix that I > suggested in my previous email and it works but I want to understand a > bit more about this function's logic before posting the fix. So, current functionality is that after queue_pages_range() encounters an unmovable page, terminates the loop and returns 1, mbind_range() will still be called for the whole range (https://elixir.bootlin.com/linux/latest/source/mm/mempolicy.c#L1345), all pages in the pagelist will be migrated (https://elixir.bootlin.com/linux/latest/source/mm/mempolicy.c#L1355) and only after that the -EIO code will be returned (https://elixir.bootlin.com/linux/latest/source/mm/mempolicy.c#L1362). So, if we follow Matthew's suggestion we will be altering the current behavior which I assume is not what we want to do. The simple fix I was thinking about that would not alter this behavior is smth like this: diff --git a/mm/pagewalk.c b/mm/pagewalk.c index b7d7e4fcfad7..c37a7e8be4cb 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -493,11 +493,17 @@ int walk_page_range(struct mm_struct *mm, unsigned long start, if (!vma) { /* after the last vma */ walk.vma =3D NULL; next =3D end; + if (err) + continue; + if (ops->pte_hole) err =3D ops->pte_hole(start, next, -1, &wa= lk); } else if (start < vma->vm_start) { /* outside vma */ walk.vma =3D NULL; next =3D min(end, vma->vm_start); + if (err) + continue; + if (ops->pte_hole) err =3D ops->pte_hole(start, next, -1, &wa= lk); } else { /* inside vma */ @@ -505,6 +511,8 @@ int walk_page_range(struct mm_struct *mm, unsigned long start, walk.vma =3D vma; next =3D min(end, vma->vm_end); vma =3D find_vma(mm, vma->vm_end); + if (err) + continue; err =3D walk_page_test(start, next, &walk); if (err > 0) { @@ -520,8 +528,6 @@ int walk_page_range(struct mm_struct *mm, unsigned long start, break; err =3D __walk_page_range(start, next, &walk); } - if (err) - break; } while (start =3D next, start < end); return err; } WDYT?