Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3055258ybi; Tue, 2 Jul 2019 01:15:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMrj0utDQOqm5f44c6SsUL69OH7hU0Ul6k/ecGCuslPjKXz4CaAUk4GuxAbVJzy0AVovVa X-Received: by 2002:a63:df05:: with SMTP id u5mr28926128pgg.171.1562055309737; Tue, 02 Jul 2019 01:15:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562055309; cv=none; d=google.com; s=arc-20160816; b=d0LvTI734RZ5sduP9zgGf92tUIsTmTmMUltQXsL8AuePOpzggkdVmjOyQxX3cyYQJh 7dIzqcVd77mikoiwosVI9PFG4e9wyZb/K424zc3Jb6d6N0v8nK0inpXCBKG+hiQWNf9R saGYJ6MyYcOPoiHMYECRdAP6J77rUQHgV8h10HkfOu+uv107NUasT05+bD5rr6tlVUxA YpyyXETJarGY6CLgpRmwspU2tjecBZhceuivdphEBRH9iJi7p6yGCFD95OEnrnLwOu2e KbG+rp8y7n6Ph0ljAiTo5BITeCnO6y65wNSIikBWvCzT//SA4MnSNwmZPM9qU1tXJqDm FLSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=X0jY329FREza1BxjjsrHHzJ2V6JqArVDs+E1NjIsKEY=; b=Y4l3te1ENN11icfi2g+4gw+O9m8Vs6vz3eAdqJGsOumoXU+LDHtmaW3U6BH2u9+PsK aTBdr3ZjG64D6l+7Jlg8oQMis/Hss1a/Oj/9RxNfylAEuiukh20dpEttp+sLOH7Mh0Ua 2NHiNk4lR8R5aX6cWOlLCpolom6DhHY+BhWiQN66bcskQSsUS7zoGCBwbJMh4h+2JOoK 5Ax5W2vMYC1nK5gz3zYQR6/WPd4aIt3zS5ubRTjPbR8EL7aEVw/UONucPQr6xtSax76K IEINLTfJQh6JNpGkVnYPom1GJdhIcl/UeuRam5op3H8b0vs1I8X0hZ9hZ/HT8tGpaBQs h7cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PVEHbgNU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m9si11938439pgq.373.2019.07.02.01.14.54; Tue, 02 Jul 2019 01:15:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PVEHbgNU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728282AbfGBIOC (ORCPT + 99 others); Tue, 2 Jul 2019 04:14:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:53444 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728110AbfGBIGi (ORCPT ); Tue, 2 Jul 2019 04:06:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2BBD921850; Tue, 2 Jul 2019 08:06:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562054797; bh=DcM6BvikXnZQVDyUoJmwoTLl3k6lVmvyEkQXJvPKY7s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PVEHbgNUz63MUf1GNfrusqMjeHVsAragR6akxjGVrAfBdRhOJVSu+F9VD9upjR++W QRdUpi+f+TaGAvy2cXVku+JajPMJYrmsOSaKmqUH7a3A/+IqEAjCTZjMyJLM767Omw 8M06K8/0vlLom63Isrz0BTngXcRZEF1V28ZV34ow= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Andrew Morton , Vladimir Davydov , Michal Hocko , Mike Rapoport , Mel Gorman , Stephen Rothwell , Andrey Ryabinin , Linus Torvalds Subject: [PATCH 4.19 38/72] mm/page_idle.c: fix oops because end_pfn is larger than max_pfn Date: Tue, 2 Jul 2019 10:01:39 +0200 Message-Id: <20190702080126.637385479@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190702080124.564652899@linuxfoundation.org> References: <20190702080124.564652899@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King commit 7298e3b0a149c91323b3205d325e942c3b3b9ef6 upstream. Currently the calcuation of end_pfn can round up the pfn number to more than the actual maximum number of pfns, causing an Oops. Fix this by ensuring end_pfn is never more than max_pfn. This can be easily triggered when on systems where the end_pfn gets rounded up to more than max_pfn using the idle-page stress-ng stress test: sudo stress-ng --idle-page 0 BUG: unable to handle kernel paging request at 00000000000020d8 #PF error: [normal kernel read fault] PGD 0 P4D 0 Oops: 0000 [#1] SMP PTI CPU: 1 PID: 11039 Comm: stress-ng-idle- Not tainted 5.0.0-5-generic #6-Ubuntu Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014 RIP: 0010:page_idle_get_page+0xc8/0x1a0 Code: 0f b1 0a 75 7d 48 8b 03 48 89 c2 48 c1 e8 33 83 e0 07 48 c1 ea 36 48 8d 0c 40 4c 8d 24 88 49 c1 e4 07 4c 03 24 d5 00 89 c3 be <49> 8b 44 24 58 48 8d b8 80 a1 02 00 e8 07 d5 77 00 48 8b 53 08 48 RSP: 0018:ffffafd7c672fde8 EFLAGS: 00010202 RAX: 0000000000000005 RBX: ffffe36341fff700 RCX: 000000000000000f RDX: 0000000000000284 RSI: 0000000000000275 RDI: 0000000001fff700 RBP: ffffafd7c672fe00 R08: ffffa0bc34056410 R09: 0000000000000276 R10: ffffa0bc754e9b40 R11: ffffa0bc330f6400 R12: 0000000000002080 R13: ffffe36341fff700 R14: 0000000000080000 R15: ffffa0bc330f6400 FS: 00007f0ec1ea5740(0000) GS:ffffa0bc7db00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000000020d8 CR3: 0000000077d68000 CR4: 00000000000006e0 Call Trace: page_idle_bitmap_write+0x8c/0x140 sysfs_kf_bin_write+0x5c/0x70 kernfs_fop_write+0x12e/0x1b0 __vfs_write+0x1b/0x40 vfs_write+0xab/0x1b0 ksys_write+0x55/0xc0 __x64_sys_write+0x1a/0x20 do_syscall_64+0x5a/0x110 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Link: http://lkml.kernel.org/r/20190618124352.28307-1-colin.king@canonical.com Fixes: 33c3fc71c8cf ("mm: introduce idle page tracking") Signed-off-by: Colin Ian King Reviewed-by: Andrew Morton Acked-by: Vladimir Davydov Cc: Michal Hocko Cc: Mike Rapoport Cc: Mel Gorman Cc: Stephen Rothwell Cc: Andrey Ryabinin Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/page_idle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/mm/page_idle.c +++ b/mm/page_idle.c @@ -136,7 +136,7 @@ static ssize_t page_idle_bitmap_read(str end_pfn = pfn + count * BITS_PER_BYTE; if (end_pfn > max_pfn) - end_pfn = ALIGN(max_pfn, BITMAP_CHUNK_BITS); + end_pfn = max_pfn; for (; pfn < end_pfn; pfn++) { bit = pfn % BITMAP_CHUNK_BITS; @@ -181,7 +181,7 @@ static ssize_t page_idle_bitmap_write(st end_pfn = pfn + count * BITS_PER_BYTE; if (end_pfn > max_pfn) - end_pfn = ALIGN(max_pfn, BITMAP_CHUNK_BITS); + end_pfn = max_pfn; for (; pfn < end_pfn; pfn++) { bit = pfn % BITMAP_CHUNK_BITS;