From patchwork Tue May 22 20:19:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10419569 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 04345600CC for ; Tue, 22 May 2018 20:20:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E53C229031 for ; Tue, 22 May 2018 20:20:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D994F29062; Tue, 22 May 2018 20:20:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C025E29031 for ; Tue, 22 May 2018 20:20:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F26D6B0003; Tue, 22 May 2018 16:20:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8A1736B0005; Tue, 22 May 2018 16:20:01 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 769446B0006; Tue, 22 May 2018 16:20:01 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f70.google.com (mail-pg0-f70.google.com [74.125.83.70]) by kanga.kvack.org (Postfix) with ESMTP id 34E066B0003 for ; Tue, 22 May 2018 16:20:01 -0400 (EDT) Received: by mail-pg0-f70.google.com with SMTP id 76-v6so2278312pga.18 for ; Tue, 22 May 2018 13:20:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:from:to:cc:subject :message-id:references:mime-version:content-disposition:in-reply-to :user-agent; bh=0awodtUtnxgGMzwqW49MAQH3ASlDiOVgjMlIBa5inWY=; b=hah1HMosfjOvRaUMebBoGVtOFOPJnoqQvJNm4yUct1zAZCb4x/ChGp2rBcGHvtMUat Z9+LZFOwSxV7GMhbdQANjBuisMBiPxOwPugoymMa7+V/mI9Xsz6+7FWlz9M2YvEE3+E3 hkbC+5QzR8bl42JPEjM7KmUbL0fjdRpyqnohe7hTMAGnXo940k3C90V2zJu5Di1yUl/y UgbZ7sE2CWQGkS6pTA+fl/ISL3fIRgCG2YZ4DAICvJUfBApCRWi9MGUyJW5xnMfj4ldq 2jBrupPIsYIn4yWazfcsj6AL1QBf6faKAFBJvzhsBaoQvj37Kj7KE/T7dBl1fc6waWyY 01qw== X-Gm-Message-State: ALKqPwdCwFs+yiDBUPC5FcmY0rQDy737hG83lEFnskDnphLe8v6/Oiru loNYRwxuOLGWy+rcDLk1cm7Pl2r3mBfhiFYqWE03haNRJdHo3dHAwM4vkLw8gMCXSiRoJHWOBu2 tUcUHHORYr6hNAj3miKCX7ygP8ypP/45XjMc+ujN57g5fYIs463PQWqGy209BtsPOIg== X-Received: by 2002:a62:5841:: with SMTP id m62-v6mr25299268pfb.116.1527020400825; Tue, 22 May 2018 13:20:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr14QFdfqq/V8PM6Pi9fpYqUQ5mOLraftNtUcsSshpnzAcUuaJoo9FOKLM98l8StD/jozbu X-Received: by 2002:a62:5841:: with SMTP id m62-v6mr25299224pfb.116.1527020399508; Tue, 22 May 2018 13:19:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527020399; cv=none; d=google.com; s=arc-20160816; b=pgQC2V96JYuLN1XGk/fV1e1r1TaP+upB4xC5bbXEY5DCCItFiMh2kHZhDqiR5RH/ip k3qUmFZOWF2PKZXYr5rr8EENSv/e8MYEIctm81aRf7vnbxYbQcTl53V5CSQ6IvmG0RGT bBaR6Fyfqq70yHwGaEKrpFExPtjn2bACJY5hmt7vCfs5oaYz5GVt1XAK24HQBvK7HDPb zWJiwyZqKZn+UYO0SgYtGxO4gEZiAQhGUzrbwaDhDIWF2hzTTQmuGeDjqy97de2Z3uLu i9Wm5A4zyuhd7DysrizBY7wrfnMzL6O5JSxjh++uEYQP5g33BGkTaFybCi1vGKgEnOWF F8uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=0awodtUtnxgGMzwqW49MAQH3ASlDiOVgjMlIBa5inWY=; b=rljcgdEXH4f3Y33zqavON5BREAzkAzsr6Xn/5VYrA3e53+C71Lqp0GQzuz4L0hbXmx chBlZhtTjKb5U0lsq+UXf/cmwyxGQY+HKTV/uhxD/iR8sOlVzHV4z6DD30Ih0LmF0IaS xM4F8BvkBRMBp0JNaCMGEraSLAnANf2Vs8OH+K9ZbZq2OY4x4niesqy0hti7eZOH9zIr GIcIuHNw5lcwm9MkPzSQUCb3PBcNvqvJt33S1MmpWrRGPx3e+JbQkb4vYRXpOr7nyHzW JKlhRjgTST0XkKaZRhw85mupnFwoBoFgO9do4cGr1FDW8kKzVVtaGyrzM1s8rNQvzPYq +L/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=ZnDDQ0rL; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id b13-v6si11157246pgu.558.2018.05.22.13.19.59 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 May 2018 13:19:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=ZnDDQ0rL; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=0awodtUtnxgGMzwqW49MAQH3ASlDiOVgjMlIBa5inWY=; b=ZnDDQ0rLDJdfjzwnnZ8KIVDe4 MyIv0foNU9Fxz71No92OQn0/8T6aj91UXIP89FRan949o24biajadr6jL2WsxmOLluItcgi86UwPf HYnx9ZeMXbvZJ9zxyj/l+7ow5kVQUXRrFzVAFGS0nfrI1dFvZU+XN8z0jdqFbPlGhV4Hpudow00oN oBj/3XAfyeDiXI5PE1Qs475byJXY8Xxu96gDnYs+EAocEYJUevKsUGrPSYbpPhSMIsu3NLTLpLKEx /O3JRUgdfAQLgKXgLCVIdxiTD3Jtwww6L4FMygH9B7ASM5dBzvq9/3YILbsSoJtTrJJUAP+KuDu4z by4wS1iLg==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLDlG-0001oP-Ep; Tue, 22 May 2018 20:19:58 +0000 Date: Tue, 22 May 2018 13:19:58 -0700 From: Matthew Wilcox To: Andrey Ryabinin Cc: linux-mm@kvack.org, Matthew Wilcox , Andrew Morton , "Kirill A . Shutemov" , Christoph Lameter , Lai Jiangshan , Pekka Enberg , Vlastimil Babka , Dave Hansen , =?iso-8859-1?B?Suly9G1l?= Glisse Subject: Re: [PATCH v6 17/17] mm: Distinguish VMalloc pages Message-ID: <20180522201958.GC1237@bombadil.infradead.org> References: <20180518194519.3820-1-willy@infradead.org> <20180518194519.3820-18-willy@infradead.org> <74e9bf39-ae17-cc00-8fca-c34b75675d49@virtuozzo.com> <20180522175836.GB1237@bombadil.infradead.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) 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: X-Virus-Scanned: ClamAV using ClamSMTP On Tue, May 22, 2018 at 10:57:34PM +0300, Andrey Ryabinin wrote: > On 05/22/2018 08:58 PM, Matthew Wilcox wrote: > > On Tue, May 22, 2018 at 07:10:52PM +0300, Andrey Ryabinin wrote: > >> On 05/18/2018 10:45 PM, Matthew Wilcox wrote: > >>> From: Matthew Wilcox > >>> > >>> For diagnosing various performance and memory-leak problems, it is helpful > >>> to be able to distinguish pages which are in use as VMalloc pages. > >>> Unfortunately, we cannot use the page_type field in struct page, as > >>> this is in use for mapcount by some drivers which map vmalloced pages > >>> to userspace. > >>> > >>> Use a special page->mapping value to distinguish VMalloc pages from > >>> other kinds of pages. Also record a pointer to the vm_struct and the > >>> offset within the area in struct page to help reconstruct exactly what > >>> this page is being used for. > >> > >> This seems useless. page->vm_area and page->vm_offset are never used. > >> There are no follow up patches which use this new information 'For diagnosing various performance and memory-leak problems', > >> and no explanation how is it can be used in current form. > > > > Right now, it's by-hand. tools/vm/page-types.c will tell you which pages > > are allocated to VMalloc. Many people use kernel debuggers, crashdumps > > and similar to examine the kernel's memory. Leaving these breadcrumbs > > is helpful, and those fields simply weren't in use before. > > > >> Also, this patch breaks code like this: > >> if (mapping = page_mapping(page)) > >> // access mapping > > > > Example of broken code, please? Pages allocated from the page allocator > > with alloc_page() come with page->mapping == NULL. This code snippet > > would not have granted access to vmalloc pages before. > > > > Some implementation of the flush_dcache_page(), also set_page_dirty() can be called > on userspace-mapped vmalloc pages during unmap - zap_pte_range() -> set_page_dirty() Ah, good catch! I'm anticipating we'll have other special values for page->mapping in the future. so how about this? (no changelog because I assume Andrew will add this as a -fix patch) diff --git a/mm/util.c b/mm/util.c index 10ca6f1d5c75..be81c9052ef7 100644 --- a/mm/util.c +++ b/mm/util.c @@ -561,6 +561,8 @@ struct address_space *page_mapping(struct page *page) mapping = page->mapping; if ((unsigned long)mapping & PAGE_MAPPING_ANON) return NULL; + if ((unsigned long)mapping < PAGE_SIZE) + return NULL; return (void *)((unsigned long)mapping & ~PAGE_MAPPING_FLAGS); }