Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4300503rdb; Thu, 14 Sep 2023 19:38:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuT+7c5BhWcnt5iwPDeoA+AswAnhEABf2yL2i0tEqiLgXezaXOW4EPE0pYk85+k5ill4h2 X-Received: by 2002:a05:6a20:5488:b0:136:e26b:6401 with SMTP id i8-20020a056a20548800b00136e26b6401mr671540pzk.16.1694745512786; Thu, 14 Sep 2023 19:38:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694745512; cv=none; d=google.com; s=arc-20160816; b=fHLPFeX6NH2R2AuXl6Z3ASjAd+oHIm7ZA/ts643oz/wl5iHIPc/R38h37LhTGJ9X6R H1AQm6OzDWdkxDNNtbCVZYtLh+PocN9MV7Ce++daSALbwreDAuEgSTbJKjxYxwnf+zKu uKW/njJi7Blb2gmgtXe9f95HFtr9YxNgoVnRaSSYyIG+ahtJNs3ZYC1WwRV14Mw7tpjq BLpTMV+CGGN95ZaG7pxsBl2avYPz2+eisINJ249lpMMfhj+XnAgVZXWBfAqd9evoZPnB OAwgCe5Vc8AR1nXbIMz7do1gO5oriqnk7/d68ys0JibtVp99DDzaECO3akdDtg3q3Bdj y4zA== 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=BGIMEgSkXCbpKrdkhs9f3Eb1IgGXBmukqlPzTkm6Mos=; fh=VuSinnOYg5yTNCGSSw+83GHBJK9yGAw0IRMQjAyxyfA=; b=jIPaSvML0/QaJvByyNW6e+Z0q+j8vRhmoCVwvtcXYJHuByRpD13v0YNwBoe40rCRFk lYG6yl8t4hXuVwmrLRn2gsnzCEG0ULUbnmMaSXhWncUpqgkk8dLY+bY0oA0q593NGfJi mErgAigGLSYIdzOEQiyZBG7N5y4BKFIEfZeWPP8+7bFRwLSrSA0SRZqNseQGgEsSpY8p bJfoSuGB8Q0xbNtXlanRTU0fKp4WICcsTKm21ByVi5H2SHkhmf0OtZJtmUbSzWl5ksrr Qx8tIAZXKLfd6tQBWr9o2Uf63zjyqfJWRTj/Q6TED1wjNoLi+nM/rbNiGOhUoB9Bj9of vLXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Ul0ZkcgX; 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 t23-20020a656097000000b0056569ee3ae6si2353408pgu.798.2023.09.14.19.38.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 19:38:32 -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=Ul0ZkcgX; 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 96AB2832E367; Thu, 14 Sep 2023 15:21:31 -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 S229865AbjINWV3 (ORCPT + 99 others); Thu, 14 Sep 2023 18:21:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbjINWV2 (ORCPT ); Thu, 14 Sep 2023 18:21:28 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74B3F26A4 for ; Thu, 14 Sep 2023 15:21:24 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-31c5a2e8501so1338345f8f.0 for ; Thu, 14 Sep 2023 15:21:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694730083; x=1695334883; 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=BGIMEgSkXCbpKrdkhs9f3Eb1IgGXBmukqlPzTkm6Mos=; b=Ul0ZkcgXlqIwQXmzVBDGLxy6xF6e6QQozo7eD9klO4zu7nvCs+1892sVotwJLGRT2Y bJHg4WO0dkCDp3o1X2syuHcAuXOctZnFJU9yYPpaqSVIU3NL+29EmRhEl5qH3Iw0qu8J P6nj+nwaq3u0Pcu/yy70zWHM0dSIO1OUl36sPk3ebkyure9E05z0jvMNScDczXxuSGxl xvhMP5lzCorL9HdWJ77VSM53T+QKcDkwcvlZKCUI/udAti09Z0mOTPwBsmMpzojmPirQ dmLj9LKCVi2SEGOo7eq996WR6vmUuQCv+pQiK0PRDEwdKxKeM+V4c/dk4UaiyJtynqhX 18zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694730083; x=1695334883; 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=BGIMEgSkXCbpKrdkhs9f3Eb1IgGXBmukqlPzTkm6Mos=; b=mLZYWxx3hz7tz7BGFRjnwEMdu0GMKnmWGy5IMpkFuGC8RELy0vTDpxdm9ZvP9PNmgJ 6hPwHM0BwhjUQ/GwSvgsOF9poi00OKkHnoPq55RfiEVdZ8mUdyN3RYwaXpmuEVscH0CA H2TsEQyvWRpmLF/Kt6/uxEekGIl/mRU2511n7ugucjgfDuWVcwMzTXwtLMTkOGja5uTG /Stj7e/U1q3NcIZFLNyDaB+ZgqM1RaqD+zpybhZkJlYwOZEsvYpTdV9RRJY6p9RWVg32 WpSTFy0XQDZDDfGH/ObgwJzVAEZafL6K3jLomgOYLPJvZKiwposaYqQYGz7u5b9JAXtD /lIw== X-Gm-Message-State: AOJu0YyNFZXBZ8lxXvcHUg2QN0HQviJso6roW1sPOtR/yr7ji9p/C/bZ zid/ddhjncDu3lHGL4obbg3QyJ/6zksV7EOw5pT+Dg== X-Received: by 2002:a5d:5387:0:b0:317:731a:6702 with SMTP id d7-20020a5d5387000000b00317731a6702mr5546547wrv.19.1694730082641; Thu, 14 Sep 2023 15:21:22 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Suren Baghdasaryan Date: Thu, 14 Sep 2023 22:21:07 +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 15:21:31 -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 9:24=E2=80=AFPM Matthew Wilcox wrote: > > On Thu, Sep 14, 2023 at 08:53:59PM +0000, Suren Baghdasaryan wrote: > > 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. = While > > > > > walking the page range, queue_folios_pte_range() encounters an > > > > > unmovable page and queue_folios_pte_range() returns 1. That cause= s 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 th= e > > > > > expected behavior here)... > > > > > I think the safest way would be to modify walk_page_range() and m= ake > > > > > it continue calling process_vma_walk_lock() for all VMAs in the r= ange > > > > > even when __walk_page_range() returns a positive err. Any objecti= on or > > > > > 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 wh= at, > > > > 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, uns= igned 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, c= an > > > > 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. > > Right, I'm intentionally changing the behaviour. My thinking is > that mbind(MPOL_MF_MOVE | MPOL_MF_STRICT) is going to fail. Should > such a failure actually move the movable pages before reporting that > it failed? I don't know. > > > The simple fix I was thinking about that would not alter this behavior > > is smth like this: > > I don't like it, but can we run it past syzbot to be sure it solves the > issue and we're not chasing a ghost here? Yes, I just finished running the reproducer on both upstream and linux-next builds listed in https://syzkaller.appspot.com/bug?extid=3Db591856e0f0139f83023 and the problem does not happen anymore. I'm fine with your suggestion too, just wanted to point out it would introduce change in the behavior. Let me know how you want to proceed.