Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1483362rdb; Wed, 20 Sep 2023 10:16:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdMxcnOFg/Un3LThfNvCIKfra00u2f8LG/tTJzlRepOtdwmYMldsPEsM8x8B0MbQ1yLqe7 X-Received: by 2002:a17:90a:d18d:b0:274:8f11:96c9 with SMTP id fu13-20020a17090ad18d00b002748f1196c9mr3060056pjb.44.1695230205355; Wed, 20 Sep 2023 10:16:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695230205; cv=none; d=google.com; s=arc-20160816; b=qlmUCmRfhvLwPzS6FpL5FwtTlGnz1EVyaESFQijmPhkjtjtHeYjfzM5cKJdKp4nZNa m3k/XtrLaoWa4A1RK4eR0acuqhMTxPZpRi8WBJSizMUvlf7CCJ2raYvfM7whW39cv4ib h9jmeiCErrCW75xBQzFwi86+A9v+21vJAW1r/a55LafZDLKaQrW8jsLkbPDWn7N9BeRy AGOcwVcpX3XMuIy93rZPBvwiHrMVhZpHUTAzS/NZjRR1y3wACuTqj1C/nCCtnbIon+4k k0bGzd0TqESUEu3xPjmBHZV/bFFfZixHZf7I3Gnqzbs7JxSKYoGljSTFFjViC4BIaZ6q qnlw== 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=dq0Us6jgc8KxbneLdF2D9i/7B/TB9s9lbtLNUZgPGF4=; fh=tuN8Y/TIcADY3xx1ankuc0mMtVoXdEd9NMVqBagxM/I=; b=XxDwpgoQYmt6vFoF3BNUWJQh7K58e+sf6gE18R1Mtr+7St+1dpkpS6jUL8rz4l2x/J k4NQjp9TWiXjA9ieHo2MeG63qOqxv5dIBPZSHKh79Fl6NYSzVeg+a0mGYhvhFISJYmCq JEnb4R6hE9dP/9SYL3PRDo7+XwoniTG7aeHOwvT2ekzd9xjkn3TCkjVR8xFwFVsIvqaY 3s8QdJvJWTwu+sMwxWSbTZQMepItNNGF5pQW6W9raliKM4mxeFEHN8XZ+XBR0Nel7tmb +zDx+1E5RoWnxGn2mcoR91bW8eOayvyXSn0CNqhCFViQGIhvrZku2lTLwDjo4GUSivp/ qo3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=C7k4c7Ea; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id l15-20020a17090a72cf00b00276d97a73f3si746619pjk.154.2023.09.20.10.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 10:16:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=C7k4c7Ea; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id A30B98326585; Mon, 18 Sep 2023 14:20:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230151AbjIRVUm (ORCPT + 99 others); Mon, 18 Sep 2023 17:20:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbjIRVUl (ORCPT ); Mon, 18 Sep 2023 17:20:41 -0400 Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90C188E for ; Mon, 18 Sep 2023 14:20:35 -0700 (PDT) Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-59c0b5f984aso38168447b3.2 for ; Mon, 18 Sep 2023 14:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695072035; x=1695676835; 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=dq0Us6jgc8KxbneLdF2D9i/7B/TB9s9lbtLNUZgPGF4=; b=C7k4c7EavGL4URc3nGseTLwXp3PU4FEc+sGzUR7JnIJca6vSRzofgsNp8VSn8BJeBE Nq0vT34+3t2EHuH/UIYUobQbIlph5hCduiviRtw/ZaOsPm9IMzKj5abOG1hGnqXW8xdE kppZlm9+2xPUNHTrd8VDCkp73jhmtxodVmiwaDU6CFW1BKNO483jeqvol3EKl5VIkzqK 6RPpFdGSc5T1NvUDlMfIHtooK5isuxd2SegnYKg6iFukNrGnAAa4zBe2cvXoCMiWfDD5 wJg7eXf+foAm81m24W2g0e3N3guMrcwQYsVkeUsh6WGU4T6jl4EwO+o8ijPyCcvpNbK/ lE4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695072035; x=1695676835; 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=dq0Us6jgc8KxbneLdF2D9i/7B/TB9s9lbtLNUZgPGF4=; b=G73e/i2dVScJ9bC6W0jp7TW+GgNxoFHyDM5Vluu1XaBH0JmzxKQaVu+PY42Z0keFp3 J3JCpgSlCQikqc7ApZ5IhOzHywMp0WWAvjX7LND+dTWV0oq6Md6kPxMnsv2UVHOgiMsw 6JqiCkJzshwijLE0BiKsY0K7+68CKVMv74nnN8JleadNRaGY6LvQyBR0hzBipFeQwLXK Y9VxQbyPRd65vN4M4VlxMxNKbTnIEAqrejA4pgI76hpWUY30mBzQP8ScDHAGzDQomMff 0vmte4IHAP+aph7P1S7hVpHp5sdppbaKG+F2G9TqzkRi6oEn6el5q5931ek23X+pPqvx GEzA== X-Gm-Message-State: AOJu0YyXAZULba8bMmi4T8MPSkiahQF3Z/5s/8VOPn5SXrRKBjilg3PQ 41lUovKsHp9Iz4agf1Cqbt2nMebtqkupLNwehNXRAw== X-Received: by 2002:a0d:cb51:0:b0:59b:d899:f171 with SMTP id n78-20020a0dcb51000000b0059bd899f171mr9736557ywd.1.1695072034557; Mon, 18 Sep 2023 14:20:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Suren Baghdasaryan Date: Mon, 18 Sep 2023 14:20:21 -0700 Message-ID: Subject: Re: [syzbot] [mm?] kernel BUG in vma_replace_policy To: Hugh Dickins Cc: Matthew Wilcox , Yang Shi , Michal Hocko , Vlastimil Babka , 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 X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Mon, 18 Sep 2023 14:20:41 -0700 (PDT) On Fri, Sep 15, 2023 at 7:44=E2=80=AFPM Hugh Dickins wro= te: > > On Fri, 15 Sep 2023, Suren Baghdasaryan wrote: > > On Fri, Sep 15, 2023 at 9:09=E2=80=AFAM Suren Baghdasaryan wrote: > > > > > > Thanks for the feedback, Hugh! > > > Yeah, this positive err handling is kinda weird. If this behavior (do > > > as much as possible even if we fail eventually) is specific to mbind(= ) > > > then we could keep walk_page_range() as is and lock the VMAs inside > > > the loop that calls mbind_range() with a condition that ret is > > > positive. That would be the simplest solution IMHO. But if we expect > > > walk_page_range() to always apply requested page_walk_lock policy to > > > all VMAs even if some mm_walk_ops returns a positive error somewhere > > > in the middle of the walk then my fix would work for that. So, to me > > > the important question is how we want walk_page_range() to behave in > > > these conditions. I think we should answer that first and document > > > that. Then the fix will be easy. > > > > I looked at all the cases where we perform page walk while locking > > VMAs and mbind() seems to be the only one that would require > > walk_page_range() to lock all VMAs even for a failed walk. > > Yes, I can well believe that. > > > So, I suggest this fix instead and I can also document that if > > walk_page_range() fails it might not apply page_walk_lock policy to > > the VMAs. > > > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c > > index 42b5567e3773..cbc584e9b6ca 100644 > > --- a/mm/mempolicy.c > > +++ b/mm/mempolicy.c > > @@ -1342,6 +1342,9 @@ static long do_mbind(unsigned long start, > > unsigned long len, > > vma_iter_init(&vmi, mm, start); > > prev =3D vma_prev(&vmi); > > for_each_vma_range(vmi, vma, end) { > > + /* If queue_pages_range failed then not all VMAs > > might be locked */ > > + if (ret) > > + vma_start_write(vma); > > err =3D mbind_range(&vmi, vma, &prev, start, end, new)= ; > > if (err) > > break; > > > > If this looks good I'll post the patch. Matthew, Hugh, anyone else? > > Yes, I do prefer this, to adding those pos ret mods into the generic > pagewalk. The "if (ret)" above being just a minor optimization, that > I would probably not have bothered with (does it even save any atomics?) > - but I guess it helps as documentation. > > I think it's quite likely that mbind() will be changed sooner or later > not to need this; but it's much the best to fix this vma locking issue > urgently as above, without depending on any mbind() behavioral discussion= s. I posted this patch at https://lore.kernel.org/all/20230918211608.3580629-1-surenb@google.com/ to fix the immediate problem. Thanks! > > Thanks, > Hugh