From patchwork Sun Aug 21 18:35:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shigeru Yoshida X-Patchwork-Id: 12950055 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 7AC5AC00140 for ; Sun, 21 Aug 2022 18:36:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E71CA8E0002; Sun, 21 Aug 2022 14:36:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF96C8E0001; Sun, 21 Aug 2022 14:36:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C72E98E0002; Sun, 21 Aug 2022 14:36:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B12148E0001 for ; Sun, 21 Aug 2022 14:36:01 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 77FA7A0236 for ; Sun, 21 Aug 2022 18:36:01 +0000 (UTC) X-FDA: 79824454122.14.0B5CA36 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id E321F400FE for ; Sun, 21 Aug 2022 18:35:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661106959; 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; bh=03PWg65stwGYjyOpdF2SCxDfkaqjGHQjclYuR1+BMys=; b=L8KhZ5tl4jb7K4Rs6nI7hxiO2w6XD59NF1UrJxAcq2n2Og33ypIwUiDlhgeKHsfGXkgjrL OCfOBqLt3B1Y9Y0gnsUtSRRqb6KB+mmNFvVcP7T+5v3E7Gj3nTL6CuYlemNeuIgBAyW7G6 lnKTQG857wFkZUzn4Q1iiab6hBuSnRA= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-512-xplLXkBmOtG70PrPoPD88g-1; Sun, 21 Aug 2022 14:35:58 -0400 X-MC-Unique: xplLXkBmOtG70PrPoPD88g-1 Received: by mail-pj1-f70.google.com with SMTP id n30-20020a17090a5aa100b001fb0c492d5eso1555887pji.3 for ; Sun, 21 Aug 2022 11:35:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=03PWg65stwGYjyOpdF2SCxDfkaqjGHQjclYuR1+BMys=; b=Ujl14ZvmFpP0wlP1XyRIErfZ8d5hDEx5rpXlIbixRY0ZBF/1Rh1MPSevbR96TDuxT8 Tenb07CyYOP1zWWZyxPbtL//1YNR86IkS/RMmc3LDWigpwhEn+TA4wBVKxUKjK/F6DVB 60OWYd092w82bKj0qBkbVB2nM0IrKENJoqThmYd9q1M/WXnrpYPOidV4T1SnWqjoOxo4 fw4wc2X2UI7JzbxLAEpwS5p4n6iXYiuKqDsB+w+BdWHvWBqLY2cVX4073SubwZolbNgI 7jeYldy37uFDsrNQPbIgsxPnDba/f0Ln27/+5M9gEvAhd0bcGdBRmITLTIjswHmQlHwn m3HQ== X-Gm-Message-State: ACgBeo0Fa9VYCBfrxZPDWKhTBY7pogi3445Ils60TP012y2YLUs1nWfv f33tGQx2StGjjnF/ZTYlbEbpgF4pLUe34uKJ1nK3Qr7VlQfXpGgAFpdIH55wLqk63r8huZrZaOy ywvuFdZx4Oig= X-Received: by 2002:a05:6a00:b8b:b0:536:71f7:4ce3 with SMTP id g11-20020a056a000b8b00b0053671f74ce3mr4809938pfj.74.1661106957099; Sun, 21 Aug 2022 11:35:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR7cOKqKMmOZIFmj+50Xk++p5bxdG74FEoDVzQ57OYjfNjsA56ll5zZNjZzEtBTS3z8BixxH0g== X-Received: by 2002:a05:6a00:b8b:b0:536:71f7:4ce3 with SMTP id g11-20020a056a000b8b00b0053671f74ce3mr4809918pfj.74.1661106956725; Sun, 21 Aug 2022 11:35:56 -0700 (PDT) Received: from xps13.. ([240d:1a:c0d:9f00:4f2f:926a:23dd:8588]) by smtp.gmail.com with ESMTPSA id d9-20020a17090a2a4900b001f326ead012sm8584240pjg.37.2022.08.21.11.35.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 11:35:56 -0700 (PDT) From: Shigeru Yoshida To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shigeru Yoshida , Alistair Popple , syzbot+616ff0452fec30f4dcfd@syzkaller.appspotmail.com Subject: [PATCH] mm/gup.c: Fix return value for __gup_longterm_locked() Date: Mon, 22 Aug 2022 03:35:47 +0900 Message-Id: <20220821183547.950370-1-syoshida@redhat.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661106960; a=rsa-sha256; cv=none; b=WLktnHNGcujXQmyEOaf5G67ZxmFfgDJClo9rPvbvnmWi4Gbk2+BVfIgRuxLAhndMEzz6lh mCXBVhOqgw+n+Vh7kSgM0YRbrGE4kI/SvmvFyhz12jtXn2YPWiCd/arWG2ID3ZI2FrKAf4 FTixOjrYyXyuIhpZJJvf00jz/j7dyUQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L8KhZ5tl; spf=pass (imf27.hostedemail.com: domain of syoshida@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=syoshida@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661106960; 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:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=03PWg65stwGYjyOpdF2SCxDfkaqjGHQjclYuR1+BMys=; b=SDrec0cuMUrjZ5lDumbnaxFwnvAMhSh8oXziHj+v2N2SnqY6+/GD/XU/SCKKH0td004zA4 D5g34rNuYplUMG4IAi8TksLUiXXTn8DRlY+G5DniVP6ZbNEPxEPs7nj8ygUQ3nBB1jdiN9 0yqDpk7YyRbHK287p5SFunuKwkRofkw= X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E321F400FE X-Rspam-User: X-Stat-Signature: bmcpbzc5h61q8xg5raxyngxzkh4quxgj Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L8KhZ5tl; spf=pass (imf27.hostedemail.com: domain of syoshida@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=syoshida@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1661106959-525907 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: __get_user_pages_locked() may return the number of pages less than nr_pages. So __gup_longterm_locked() have to return the number of pages __get_user_pages_locked() returns if it succeeded, not nr_pages passed. Fixes: 61c63c2076d9 (mm/gup.c: simplify and fix check_and_migrate_movable_pages() return codes) CC: Alistair Popple Reported-by: syzbot+616ff0452fec30f4dcfd@syzkaller.appspotmail.com Signed-off-by: Shigeru Yoshida Reviewed-by: John Hubbard --- mm/gup.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 5aa7531a703b..542cf74c59b0 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2068,22 +2068,22 @@ static long __gup_longterm_locked(struct mm_struct *mm, unsigned int gup_flags) { unsigned int flags; - long rc; + long rc, nr_pinned_pages; if (!(gup_flags & FOLL_LONGTERM)) return __get_user_pages_locked(mm, start, nr_pages, pages, vmas, NULL, gup_flags); flags = memalloc_pin_save(); do { - rc = __get_user_pages_locked(mm, start, nr_pages, pages, vmas, - NULL, gup_flags); - if (rc <= 0) + nr_pinned_pages = __get_user_pages_locked(mm, start, nr_pages, pages, vmas, + NULL, gup_flags); + if (nr_pinned_pages <= 0) break; - rc = check_and_migrate_movable_pages(rc, pages, gup_flags); + rc = check_and_migrate_movable_pages(nr_pinned_pages, pages, gup_flags); } while (rc == -EAGAIN); memalloc_pin_restore(flags); - return rc ? rc : nr_pages; + return rc ? rc : nr_pinned_pages; } static bool is_valid_gup_flags(unsigned int gup_flags)