From patchwork Mon Sep 18 21:16:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13390492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7FC5C46CA1 for ; Mon, 18 Sep 2023 21:16:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED82F6B0453; Mon, 18 Sep 2023 17:16:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E60EA6B0454; Mon, 18 Sep 2023 17:16:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D01F26B0455; Mon, 18 Sep 2023 17:16:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BB5366B0453 for ; Mon, 18 Sep 2023 17:16:15 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 86A09140545 for ; Mon, 18 Sep 2023 21:16:15 +0000 (UTC) X-FDA: 81250976310.08.9ED61DA Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf07.hostedemail.com (Postfix) with ESMTP id EE1AD4001F for ; Mon, 18 Sep 2023 21:16:12 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=bwIh3xev; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3G74IZQYKCOgcebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3G74IZQYKCOgcebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695071773; h=from:from:sender: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:in-reply-to: references:dkim-signature; bh=yc4butG+BWb+Qe3ZuJ7BVqA63qdbImB+9mEwJw3lgvg=; b=gtFao4mTHGo5RdU1cENC6zV/t8UUoXmgi1K73VHMeOG4rCjSOgEuf7x6dDwSGJ4xIAFvB1 US5/1O1CYqds3hqcKaxLYPLwcKxYM6wmtyx0eC1vqPZQmyOOe7WVBTy1dh/mhQ6xqAxUK3 85bYT7DaaNbs+uH+YkejTQo850xW7vw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=bwIh3xev; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3G74IZQYKCOgcebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3G74IZQYKCOgcebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695071773; a=rsa-sha256; cv=none; b=xtON9gLZh63nhARobWO7FphEJm0R3CCX7mrWCK42bnH5ESPR4klK/xgfbfY4sAbBdbZgvq F+skkKZ1q6Ka258q4x9OQf+hIAaptDrGvXfJoXzpk54sL+AIE9LRWkCjGC3acC864QRGqa 2j4z56wtt8ywEwavQG4hXzdw2bDhkCA= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-d814a1f7378so11360004276.1 for ; Mon, 18 Sep 2023 14:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695071772; x=1695676572; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=yc4butG+BWb+Qe3ZuJ7BVqA63qdbImB+9mEwJw3lgvg=; b=bwIh3xevMmFPtVCWmI6ZnCdAsU4bW+Buj+Ar2A3LemI5DgCC+OPNkg3V4/9UJdyK8c SanSEkB4eaBsiilTH64xxuoYvjDrK5znErjSb5ZfpIQGNwqu0V4xTNY87b+s1lRVnmGY hyB9+ZTne7njBc7+VqI4dhRBNU/iqBBR+RWDAkVssSZfn4xl2nE6XwMQ/K4RRKXDhSDf 73vi2HNcBhSw8qw8ICkUP4ljG5jvsxCeLmzi+YOLErR5Jst0XhfScjLgN7QoL4pTTSBB O/SrjFIX5ltb8TEJ7mZ5PvePukMlL2OUrhix26dZry6ox1AccuQFNGbPCjAopQm06CV4 LvWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695071772; x=1695676572; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yc4butG+BWb+Qe3ZuJ7BVqA63qdbImB+9mEwJw3lgvg=; b=dAuONWJCSFi4zkKu8a+9dtypxLyirvr4A4wMQIX0a90j+0/GQbrHM7pxuXDZZD2gTc ZubtCdVMtrZVNFgXKNWhjIXYPsnzTLRa8TKYB/aSDjk+ZrADdm+S8YzHh087d1sFThda iuwwr6OpoujqTlK24WAJQe6v5p81AReJllUOzeZooipD8W2/tg58e64DhfIuLyjlc2g5 HEkAyeHyQS9E9KH++cDboQK+mIEYNIWLU4a8yjbkd9DRxmQCy3mIx4fxVgFEO1RY30tP e0Zbjx9tQXESczyXJuNzJLk9KK6HAg2TlQkjVuqWJN4veq45CfIjk+heMGUGcmM1Fo+g SU2w== X-Gm-Message-State: AOJu0YzjilqBTct2bnzbnVHQLTiMS3RhCccp01p+YUBoy3frWPxGv/l2 u/rRcL6Rt+1gwJEjUrSRHPKAl0c22zw= X-Google-Smtp-Source: AGHT+IGgw8JZ/Scb/L4UPVe1y9d1eUoneO5O5nz4m++Nj62RgVWM1SbDUZOxeYP+4xMVpyAcx3I+S+qNxU4= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:9830:817:b32f:99da]) (user=surenb job=sendgmr) by 2002:a25:d3cb:0:b0:d80:8aa6:5ac0 with SMTP id e194-20020a25d3cb000000b00d808aa65ac0mr16652ybf.4.1695071771967; Mon, 18 Sep 2023 14:16:11 -0700 (PDT) Date: Mon, 18 Sep 2023 14:16:08 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog Message-ID: <20230918211608.3580629-1-surenb@google.com> Subject: [PATCH 1/1] mm: lock VMAs skipped by a failed queue_pages_range() From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, hughd@google.com, shy828301@gmail.com, mhocko@suse.com, vbabka@suse.cz, surenb@google.com, syzkaller-bugs@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, syzbot+b591856e0f0139f83023@syzkaller.appspotmail.com X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: EE1AD4001F X-Stat-Signature: trbgksnjwx3af8o7ctdo7n68eqk1ngm6 X-Rspam-User: X-HE-Tag: 1695071772-831317 X-HE-Meta: U2FsdGVkX1/b5r1vudeTTdDjVNk3IDkPIZQODJRb1xTol06T8xsE0FjalaaHQePnqD2UDEQAyh3/3Qm02ohFBUpG7KqPOmy+tcOdtk45KYGOWZDpjihtWa42AI8rPjRWFz50Wg0hBSJJ0hyJdIS5lDeUHXj9kxxcFLu1MM13ZUFR266Qus/xslAvl1Y5q3L+ccJ6hmkHM2xRm52zCoqsDFiYngz99XOKD6G4f2rHezW81UrtMjuBmJtX3+P9qlIrjwfnxSCQk3L+R8PX2Xdn4S4bEru7hcinDp5AW5UBPJqAH7e0AgKle+i0KaWMCc+4sdySKOWRKMj7u5FBuCpJRRqtBC2omio+j1KWcuC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F0+29Oj6GzqCmtNAdCIfTkcuNCwQVinHbldBDdSmSU0qJjIlJB6WSGIoJKg12RE/Stql3Ct+X/AuVPInVZU+o9tk7NfoFgXQU1eMcA+tNVUZlgPCGDr/DnESOshU3XrM/T3XhsNs02iJ3M1A8R06FM6AfFwKIFCxjeT9TOssjrpJoGQnzOOanLhVPKUpTVLX0BMPrrXO71sVMNjT2vrTZq50X/PuNE3GNVtcsb/73g10t1Hn7cE115IrUEbEbJQUhnyizeZPQAPM6iZ1R9GRBKC9Ay4Y6nx41kSyKOpISsSzDMWeAVmoP5FPh7yBA3xJQRUURl5z5Sz6GxGrtYpDzEh+Zwmk8B2SKANde89lzvowd674JIpXlAdNqorFxx6qVVYP9MEzCm5UFE9LHkDtPKfsp5D+rtOMxY468/0cLugcD8LM0fA/7OwTG43KA== 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: When queue_pages_range() encounters an unmovable page, it terminates its page walk. This walk, among other things, locks the VMAs in the range. This termination might result in some VMAs being left unlock after queue_pages_range() completes. Since do_mbind() continues to operate on these VMAs despite the failure from queue_pages_range(), it will encounter an unlocked VMA. This mbind() behavior has been modified several times before and might need some changes to either finish the page walk even in the presence of unmovable pages or to error out immediately after the failure to queue_pages_range(). However that requires more discussions, so to fix the immediate issue, explicitly lock the VMAs in the range if queue_pages_range() failed. The added condition does not save much but is added for documentation purposes to understand when this extra locking is needed. Fixes: 49b0638502da ("mm: enable page walking API to lock vmas during the walk") Reported-by: syzbot+b591856e0f0139f83023@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/000000000000f392a60604a65085@google.com/ Signed-off-by: Suren Baghdasaryan Acked-by: Hugh Dickins Acked-by: Michal Hocko --- mm/mempolicy.c | 3 +++ 1 file changed, 3 insertions(+) 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 = 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 = mbind_range(&vmi, vma, &prev, start, end, new); if (err) break;