Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3699791imu; Fri, 30 Nov 2018 04:46:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/XiN4IbbQ5f3EMRv8i9M/ZjlRqtjR1To/1fTlDrvQynGLjZVGulVhx+4sAtZLxTpnMdrc7j X-Received: by 2002:a62:c583:: with SMTP id j125mr5534499pfg.37.1543582016296; Fri, 30 Nov 2018 04:46:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543582016; cv=none; d=google.com; s=arc-20160816; b=fVH/6VWyDH4MEHoONAhcpZ/1SOzYtylhDdQzL0QWR94CVJLtBUW36hO9F0hVW3CIOL 61fXpHrQOGVTag4dYa0f9TYkVHLy15WHztE9mLjA6saD+s4UYltMhW1Lea24PVnz/SLE t4/2cMrM+wgYhWYrGFmepzQ7O+NaCFfH/ntksfEO8ApY/+f18e3t5zy7jZXYKKqfb/Yw whpBOFLjFGoPHvnKyfgXDFjyCz1kB/XjLuj2jt+6hUHuA6pzIV6ba0rnnckH5bwifSAv KFwVb1TMtvgWVYFTr5uNdFMhFVFXjREUGRwzVAfbAjxGHxHIwlBYrPfHbnkN5MD/Sn9w rDag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=RydqxONgwmXblEEZ7ff4m+2kyt5iFb+C39O1GYEz1Lc=; b=W0/aggVbGDZVQFzYEPU7+PGDWm7VbXgUNMP7DOqhlt+soejtJnGR1kcu6U9Q1LXJ8h 1r9fXCJG/5ojH6AP2MULNbiPZ6uTsPZwZtxkw7Ru2oGYblLO1OHuZF8V/k4GV7QK700P fw6vdrEcDiHGzPr29N/HAHe4tT53ErEcNk7/sB8Y2UPOhQchA7bdIo0ekxFABs7ugw1I 3M4aTo+GD7c5jHeDXxhj0r2XfkvPZKzAAVha6/RUzHax2Fby625MF5X2X0L3ujoWVPgJ bKrA1tFrpskVSOHZFaWMcx6ZwzzhiliGYFDS+AmTenFLbGK4IL4PbZxz3tWl0xGz+I/2 DFZw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4si5461360plk.260.2018.11.30.04.46.41; Fri, 30 Nov 2018 04:46:56 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726744AbeK3Xy7 (ORCPT + 99 others); Fri, 30 Nov 2018 18:54:59 -0500 Received: from mx2.suse.de ([195.135.220.15]:48412 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726555AbeK3Xy7 (ORCPT ); Fri, 30 Nov 2018 18:54:59 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BFEC9ADDF; Fri, 30 Nov 2018 12:45:46 +0000 (UTC) Date: Fri, 30 Nov 2018 13:45:46 +0100 From: Michal Hocko To: "Kirill A. Shutemov" Cc: Jan Stancek , linux-mm@kvack.org, lersek@redhat.com, alex.williamson@redhat.com, aarcange@redhat.com, rientjes@google.com, mgorman@techsingularity.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: page_mapped: don't assume compound page is huge or THP Message-ID: <20181130124546.GJ6923@dhcp22.suse.cz> References: <20181130121851.GI6923@dhcp22.suse.cz> <20181130123651.5qrdrw3i5ergbuzl@kshutemo-mobl1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181130123651.5qrdrw3i5ergbuzl@kshutemo-mobl1> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 30-11-18 15:36:51, Kirill A. Shutemov wrote: > On Fri, Nov 30, 2018 at 01:18:51PM +0100, Michal Hocko wrote: > > On Fri 30-11-18 13:06:57, Jan Stancek wrote: > > > LTP proc01 testcase has been observed to rarely trigger crashes > > > on arm64: > > > page_mapped+0x78/0xb4 > > > stable_page_flags+0x27c/0x338 > > > kpageflags_read+0xfc/0x164 > > > proc_reg_read+0x7c/0xb8 > > > __vfs_read+0x58/0x178 > > > vfs_read+0x90/0x14c > > > SyS_read+0x60/0xc0 > > > > > > Issue is that page_mapped() assumes that if compound page is not > > > huge, then it must be THP. But if this is 'normal' compound page > > > (COMPOUND_PAGE_DTOR), then following loop can keep running > > > (for HPAGE_PMD_NR iterations) until it tries to read from memory > > > that isn't mapped and triggers a panic: > > > for (i = 0; i < hpage_nr_pages(page); i++) { > > > if (atomic_read(&page[i]._mapcount) >= 0) > > > return true; > > > } > > > > > > I could replicate this on x86 (v4.20-rc4-98-g60b548237fed) only > > > with a custom kernel module [1] which: > > > - allocates compound page (PAGEC) of order 1 > > > - allocates 2 normal pages (COPY), which are initialized to 0xff > > > (to satisfy _mapcount >= 0) > > > - 2 PAGEC page structs are copied to address of first COPY page > > > - second page of COPY is marked as not present > > > - call to page_mapped(COPY) now triggers fault on access to 2nd > > > COPY page at offset 0x30 (_mapcount) > > > > > > [1] https://github.com/jstancek/reproducers/blob/master/kernel/page_mapped_crash/repro.c > > > > > > Fix the loop to iterate for "1 << compound_order" pages. > > > > This is much less magic than the previous version. It is still not clear > > to me how is mapping higher order pages to page tables other than THP > > though. So a more detailed information about the source would bre really > > welcome. Once we know that we can add a Fixes tag and also mark the > > patch for stable because that sounds like a stable material. > > IIRC, sound subsystem can producuce custom mapped compound pages. Do I assume correctly that consecutive ptes simply point to subpages? > The bug dates back to e1534ae95004. Thanks for the pointer. I thought this was a new and creative usage of the pte->page mapping but it really looks like your commit just changed the underlying semantic. > > > Debugged-by: Laszlo Ersek > > > Suggested-by: "Kirill A. Shutemov" > > > Signed-off-by: Jan Stancek > > > > The patch looks sensible to me > > Acked-by: Michal Hocko > > Acked-by: Kirill A. Shutemov > > -- > Kirill A. Shutemov -- Michal Hocko SUSE Labs