From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE4F6C2D0EA for ; Wed, 8 Apr 2020 15:01:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8DE5B206C0 for ; Wed, 8 Apr 2020 15:01:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="k4eym66f" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8DE5B206C0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3DDD88E0015; Wed, 8 Apr 2020 11:01:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 367AB8E000D; Wed, 8 Apr 2020 11:01:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27E198E0015; Wed, 8 Apr 2020 11:01:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0098.hostedemail.com [216.40.44.98]) by kanga.kvack.org (Postfix) with ESMTP id 0C4988E000D for ; Wed, 8 Apr 2020 11:01:52 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B8ADF180AD807 for ; Wed, 8 Apr 2020 15:01:51 +0000 (UTC) X-FDA: 76685002422.06.wall82_103a2c3f08e3a X-HE-Tag: wall82_103a2c3f08e3a X-Filterd-Recvd-Size: 3967 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Wed, 8 Apr 2020 15:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=gUwTlZA5YznaZDjo26j+ItO4N59cLDljGymU+RRW3Gs=; b=k4eym66f2KUwQXSdiJezGWAPfD zL+leCQMepfZ/SrNQrWfKsgiG5/+2p9oBiOskaiSqCUM+OE0V7qVdZ2/OQfs6Mjr0SVz5MMn4jVal i8g9p3ZKs6+QsEAosts9uhHq3j9LhrYfHSFvbcnLITqZ5brDiC0eEG/mrFrrClxsSkwJ5bXlNxf+a IvkigC3X/a5NGZ/PUZDjhTR3B5aBguWquhallEwzjiGV+3rYf16GYMidSOi0byFZ3VT1ZgGtsy0zO 5I1MBMb1SMq77tdvFmT1rkFtc1sP1WYjE327YxIgbg3YI8ircTBP5TVkAf9W4IMZxIY9+MIM+sNbM UQo0hPjg==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jMCD8-0006bM-8x; Wed, 08 Apr 2020 15:01:50 +0000 From: Matthew Wilcox To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , kirill.shutemov@linux.intel.com, pasha.tatashin@soleen.com Subject: [PATCH 5/5] mm: Check page poison before finding a head page Date: Wed, 8 Apr 2020 08:01:48 -0700 Message-Id: <20200408150148.25290-6-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200408150148.25290-1-willy@infradead.org> References: <20200408150148.25290-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: From: "Matthew Wilcox (Oracle)" If a page is poisoned, the page->compound_head will be set to -1. Since it has bit zero set, we will think it is a tail page, and the head page is at 0xff..fe. Checking said head page for being poisoned will not have good results. Therefore we need to check for poison in each of compound_head(), PageTail() and PageCompound() (and can remove the checks which are now redundant from the PF_ macros). Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/page-flags.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 331aef35f3e0..340ceeeda8ed 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -190,6 +190,7 @@ static inline int PagePoisoned(const struct page *pag= e) #define compound_head(page) ({ \ __typeof__(page) _page =3D page; \ unsigned long head =3D READ_ONCE(_page->compound_head); \ + VM_BUG_ON_PAGE(head =3D=3D PAGE_POISON_PATTERN, page); \ if (unlikely(head & 1)) \ _page =3D (void *)(head - 1); \ _page; \ @@ -197,11 +198,13 @@ static inline int PagePoisoned(const struct page *p= age) =20 static __always_inline int PageTail(const struct page *page) { + page_poison_check(page); return READ_ONCE(page->compound_head) & 1; } =20 static __always_inline int PageCompound(const struct page *page) { + page_poison_check(page); return test_bit(PG_head, &page->flags) || PageTail(page); } =20 @@ -234,13 +237,13 @@ static inline void page_init_poison(struct page *pa= ge, size_t size) * the page flag is not relevant for compound pages. */ #define PF_ANY(page, enforce) page_poison_check(page) -#define PF_HEAD(page, enforce) page_poison_check(compound_head(page)) +#define PF_HEAD(page, enforce) compound_head(page) #define PF_ONLY_HEAD(page, enforce) ({ \ VM_BUG_ON_PGFLAGS(PageTail(page), page); \ - page_poison_check(page); }) + page; }) #define PF_NO_TAIL(page, enforce) ({ \ VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page); \ - page_poison_check(compound_head(page)); }) + compound_head(page); }) #define PF_NO_COMPOUND(page, enforce) ({ \ VM_BUG_ON_PGFLAGS(enforce && PageCompound(page), page); \ page_poison_check(page); }) --=20 2.25.1