Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4151957ybi; Tue, 18 Jun 2019 12:45:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyXVS2HHtppRp58Ffq8cWr0Ui9XS87wGq73ki2LXfxRrmX54dGk2Hz4HepOA3WZMJzSUw7x X-Received: by 2002:a17:90a:1c17:: with SMTP id s23mr6979200pjs.108.1560887155728; Tue, 18 Jun 2019 12:45:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560887155; cv=none; d=google.com; s=arc-20160816; b=llVqqbvxf6KAuOhoUQLqldh72HeUUJ6q6q4szg7UjyYhLD6wxwXxrwtFLmfX1+zay1 OgjYY56Jesn11Ksxr6C50AREUt7Rd/B/3lOw7ZjsO3TBJU8BSRzcy6BWE4VCbSqF9+0u Jx9a9uDBSPY24yEnOSrbAZa9BmNzEZ9mtUboV0+QcbQGhKvKVEBqbSTmHmNgroC5IO3s muXJqGKSvJJm82q9N+iY+rZbflIrfYOykMk4VxWl6Kw7VFPOSgcr0C4wsBbyXSUxEndW Ml468xOwCzzI7Bk9OFbPLHgYvenl2X48evGH+sfcqHf6UheeFpjkUUVFxOqqWiNQSbFz r25Q== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=4C+WmZSxpp3YczqEWg3y+xZ7ocDXvhYqlG+DubtwrI4=; b=QgIol5xkvcjJ2xjO2GmgeV92I/N5PhobqKJVJKvoVfC/eHaJdoGKVMsVJm6uXrgkks snZ9ATnJLSXjOb7y6vL5SLp/DwOT8px3LahPPt3gTPLbZTdlu/C0r+BJH4KxTp1f+n1u 1k2XTgZjXTEYAp2uzXwl2d2L0XVM/8if6fdT2MMSNUIFNVWmUXVIUTRWENPfQBy3QV+9 bzahJIIvC/fkoNhKCkaufnqeoOx2wdtLQqWWcbo0xPr46+9i4vgY0JEw6Kfa0C890i53 C3CRt/xzQAf9V+A9xi8XtvfMSh2OQvOaB3zqCh2vzq5/GsjWWaLTcmDQVLxhfNsVtIAo rJqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ux/8q1+R"; 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 s13si14115966pfs.142.2019.06.18.12.45.40; Tue, 18 Jun 2019 12:45:55 -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="ux/8q1+R"; 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 S1730522AbfFRTpE (ORCPT + 99 others); Tue, 18 Jun 2019 15:45:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:58526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730494AbfFRTpE (ORCPT ); Tue, 18 Jun 2019 15:45:04 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) (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 2E4AF2084B; Tue, 18 Jun 2019 19:45:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560887103; bh=3SVyETw2E2EX1ucf8dX5XihBlytLx4R2+9VoWquLfZ0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ux/8q1+R+SGkuJvyxGL5MB3IcTZzJnsY9YYEa8vnbLQQxX+jPZ2QB7LNc/awkQVT8 KmXsHCVzPnOmtaydBRw3os8e2NolICsAgAYf7cg/CovkaTK/zb81ap2GkPdqCkCVX7 zPfEs99C5nkuUu3LGsXblb+6J32MdX/+ImBYsnw0= Date: Tue, 18 Jun 2019 12:45:02 -0700 From: Andrew Morton To: Colin King Cc: Michal Hocko , Mike Rapoport , Mel Gorman , Stephen Rothwell , Andrey Ryabinin , linux-mm@kvack.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, Vladimir Davydov Subject: Re: [PATCH] mm: idle-page: fix oops because end_pfn is larger than max_pfn Message-Id: <20190618124502.7b9c32a00a54f0c618a12ca4@linux-foundation.org> In-Reply-To: <20190618124352.28307-1-colin.king@canonical.com> References: <20190618124352.28307-1-colin.king@canonical.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 18 Jun 2019 13:43:52 +0100 Colin King wrote: > From: Colin Ian King > > 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: > cc Vladimir. This seems rather obvious - I'm wondering if the code was that way for some subtle reason? (I'll add a cc:stable to this) From: Colin Ian King Subject: mm/page_idle.c: fix oops because end_pfn is larger than max_pfn 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 [ 3812.222790] BUG: unable to handle kernel paging request at 00000000000020d8 [ 3812.224341] #PF error: [normal kernel read fault] [ 3812.225144] PGD 0 P4D 0 [ 3812.225626] Oops: 0000 [#1] SMP PTI [ 3812.226264] CPU: 1 PID: 11039 Comm: stress-ng-idle- Not tainted 5.0.0-5-generic #6-Ubuntu [ 3812.227643] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014 [ 3812.229286] RIP: 0010:page_idle_get_page+0xc8/0x1a0 [ 3812.230173] 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 [ 3812.234641] RSP: 0018:ffffafd7c672fde8 EFLAGS: 00010202 [ 3812.235792] RAX: 0000000000000005 RBX: ffffe36341fff700 RCX: 000000000000000f [ 3812.237739] RDX: 0000000000000284 RSI: 0000000000000275 RDI: 0000000001fff700 [ 3812.239225] RBP: ffffafd7c672fe00 R08: ffffa0bc34056410 R09: 0000000000000276 [ 3812.241027] R10: ffffa0bc754e9b40 R11: ffffa0bc330f6400 R12: 0000000000002080 [ 3812.242555] R13: ffffe36341fff700 R14: 0000000000080000 R15: ffffa0bc330f6400 [ 3812.244073] FS: 00007f0ec1ea5740(0000) GS:ffffa0bc7db00000(0000) knlGS:0000000000000000 [ 3812.245968] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 3812.247162] CR2: 00000000000020d8 CR3: 0000000077d68000 CR4: 00000000000006e0 [ 3812.249045] Call Trace: [ 3812.249625] page_idle_bitmap_write+0x8c/0x140 [ 3812.250567] sysfs_kf_bin_write+0x5c/0x70 [ 3812.251406] kernfs_fop_write+0x12e/0x1b0 [ 3812.252282] __vfs_write+0x1b/0x40 [ 3812.253002] vfs_write+0xab/0x1b0 [ 3812.253941] ksys_write+0x55/0xc0 [ 3812.254660] __x64_sys_write+0x1a/0x20 [ 3812.255446] do_syscall_64+0x5a/0x110 [ 3812.256254] entry_SYSCALL_64_after_hwframe+0x44/0xa9 --- a/mm/page_idle.c~mm-idle-page-fix-oops-because-end_pfn-is-larger-than-max_pfn +++ a/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; _