Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3495459pxj; Mon, 7 Jun 2021 12:06:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXQXvAla9KjeWNGvo1L7cRTm0Q47+la2SAiko71SFkFbtsegara+9yylMWjsDl1+pxPu0A X-Received: by 2002:a17:906:c411:: with SMTP id u17mr19786125ejz.60.1623092762774; Mon, 07 Jun 2021 12:06:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623092762; cv=none; d=google.com; s=arc-20160816; b=YcX/tqTl5+/2GW5JENTgpwJYwCZ+KAMgDJtw3cfpl2iiZdBwdcGyM95tRKn+hW5fcD L3oJ5NYROJdB3q137l2Il7kyh5bBSbXs2lJ6HHwsKxYFxzrbBNae6q5mbnlHdrCWOXVo B3AR4z4rasUgwBrwGTSSpAeOnwknCr6Ne9yy/TGKt4nJRrDVOK9CTtKadebWP3IQRTXO +ft5K91u1bpJzrkMrDGU9rznzavSTiypcY7qDNX2qslCdV+ELxC9IRRICyQ4mcMRPaaa U9T0Idbt6+iD4Jl+IIJ8wHIZH3kqgTknFw9r7U618YfqTW9wLZf3FXcaOXaXBZiMSGIF GMag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gpCyRaWvrKvU/PVxSVlqs7O19Kt+5N+CG6yZ5xm4LxQ=; b=n2vds76dcn+mlFwfdofeaBYLPQzm7VPfnK82ojKfkRyl/XbucmueImnEDhjb9NFPpm 79KtzaYBa3mQvMuaIQmkwOCFy0UXYUwgsEgeiYmLeMBB01iem6/Qc4IbjyZ2d3GaLqte NhF3t6k8GIFZmIqfSiIZCkTwnO8l3hzg4yGTYftUwBw7Lbuor8fAA2dCA/za8mXW+a5m tlEWkpavkVGZaCGtpz6O0PuYUJc3xr97qGcvDK3mglabN83PuEmb3Jx5PjnWJ6lSq9iV JpdoVRwd6zQ18dre7xM1A4zESigmyXTR5X0L7vpiQkSyn2rsfZsNZaWIWMOOEO09Fjss n9/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y22si12739577edv.206.2021.06.07.12.05.38; Mon, 07 Jun 2021 12:06:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231157AbhFGTFP (ORCPT + 99 others); Mon, 7 Jun 2021 15:05:15 -0400 Received: from mail-wr1-f46.google.com ([209.85.221.46]:46034 "EHLO mail-wr1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230382AbhFGTFM (ORCPT ); Mon, 7 Jun 2021 15:05:12 -0400 Received: by mail-wr1-f46.google.com with SMTP id z8so18772139wrp.12; Mon, 07 Jun 2021 12:03:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gpCyRaWvrKvU/PVxSVlqs7O19Kt+5N+CG6yZ5xm4LxQ=; b=ESqJVSX7FcTzBe9BSWmDQB9qXJFW0Dg1zXZVVqFFjs55PLlB9L0BT7gI0NWT6ZFvlk 6Ro6qYvL27SLa+9VKziPCM5pXV//xsE+N1lxokgWJWIR9U5I+P9dugtQMwR8OA4QL+5+ 5hHG215h8QDuyc0ullY15I99YkjrKDeVIn+bCpLS3kKaynE5oVfo5+GoeTZlh31ZEkQI 2wAwp9rPAdccyB39h54ceFeB56wo7bZYPF5Bd5jyPLrEubiC4zAGU5NGntQyKQ7X2fy2 ACHkoc0bZIHpjQh0V/dhGTBFdAJCLHtSqkBirn77Wan6fLfSSySw146P6AMR5GW2Iyjs VQvA== X-Gm-Message-State: AOAM532mVd6iUH81dwCm4fv/Onhyk67RHnXKN9z3rPBPB9E0SueuHJ+n nk5lHNFdtYBSSOfHjMQ8Vfxp5YIDo4FBkQ== X-Received: by 2002:adf:f2ca:: with SMTP id d10mr18183035wrp.314.1623092599073; Mon, 07 Jun 2021 12:03:19 -0700 (PDT) Received: from msft-t490s.teknoraver.net (net-37-119-128-179.cust.vodafonedsl.it. [37.119.128.179]) by smtp.gmail.com with ESMTPSA id g17sm12185968wrp.61.2021.06.07.12.03.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 12:03:18 -0700 (PDT) From: Matteo Croce To: netdev@vger.kernel.org, linux-mm@kvack.org Cc: Ayush Sawal , Vinay Kumar Yadav , Rohit Maheshwari , "David S. Miller" , Jakub Kicinski , Thomas Petazzoni , Marcin Wojtas , Russell King , Mirko Lindner , Stephen Hemminger , Tariq Toukan , Jesper Dangaard Brouer , Ilias Apalodimas , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Boris Pismenny , Arnd Bergmann , Andrew Morton , "Peter Zijlstra (Intel)" , Vlastimil Babka , Yu Zhao , Will Deacon , Fenghua Yu , Roman Gushchin , Hugh Dickins , Peter Xu , Jason Gunthorpe , Jonathan Lemon , Alexander Lobakin , Cong Wang , wenxu , Kevin Hao , Jakub Sitnicki , Marco Elver , Willem de Bruijn , Miaohe Lin , Yunsheng Lin , Guillaume Nault , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, bpf@vger.kernel.org, Matthew Wilcox , Eric Dumazet , David Ahern , Lorenzo Bianconi , Saeed Mahameed , Andrew Lunn , Paolo Abeni , Sven Auhagen , Yonghong Song , Michel Lespinasse , KP Singh , Andrii Nakryiko , Martin KaFai Lau , David Hildenbrand , Song Liu Subject: [PATCH net-next v8 1/5] mm: add a signature in struct page Date: Mon, 7 Jun 2021 21:02:36 +0200 Message-Id: <20210607190240.36900-2-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210607190240.36900-1-mcroce@linux.microsoft.com> References: <20210607190240.36900-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matteo Croce This is needed by the page_pool to avoid recycling a page not allocated via page_pool. The page->signature field is aliased to page->lru.next and page->compound_head, but it can't be set by mistake because the signature value is a bad pointer, and can't trigger a false positive in PageTail() because the last bit is 0. Co-developed-by: Matthew Wilcox (Oracle) Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Matteo Croce --- include/linux/mm.h | 11 ++++++----- include/linux/mm_types.h | 7 +++++++ include/linux/poison.h | 3 +++ net/core/page_pool.c | 6 ++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index c274f75efcf9..a0434e8c2617 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1668,10 +1668,11 @@ struct address_space *page_mapping(struct page *page); static inline bool page_is_pfmemalloc(const struct page *page) { /* - * Page index cannot be this large so this must be - * a pfmemalloc page. + * lru.next has bit 1 set if the page is allocated from the + * pfmemalloc reserves. Callers may simply overwrite it if + * they do not need to preserve that information. */ - return page->index == -1UL; + return (uintptr_t)page->lru.next & BIT(1); } /* @@ -1680,12 +1681,12 @@ static inline bool page_is_pfmemalloc(const struct page *page) */ static inline void set_page_pfmemalloc(struct page *page) { - page->index = -1UL; + page->lru.next = (void *)BIT(1); } static inline void clear_page_pfmemalloc(struct page *page) { - page->index = 0; + page->lru.next = NULL; } /* diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 5aacc1c10a45..ed6862eacb52 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -96,6 +96,13 @@ struct page { unsigned long private; }; struct { /* page_pool used by netstack */ + /** + * @pp_magic: magic value to avoid recycling non + * page_pool allocated pages. + */ + unsigned long pp_magic; + struct page_pool *pp; + unsigned long _pp_mapping_pad; /** * @dma_addr: might require a 64-bit value on * 32-bit architectures. diff --git a/include/linux/poison.h b/include/linux/poison.h index aff1c9250c82..d62ef5a6b4e9 100644 --- a/include/linux/poison.h +++ b/include/linux/poison.h @@ -78,4 +78,7 @@ /********** security/ **********/ #define KEY_DESTROY 0xbd +/********** net/core/page_pool.c **********/ +#define PP_SIGNATURE (0x40 + POISON_POINTER_DELTA) + #endif diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 3c4c4c7a0402..e1321bc9d316 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -17,6 +17,7 @@ #include #include #include /* for __put_page() */ +#include #include @@ -221,6 +222,8 @@ static struct page *__page_pool_alloc_page_order(struct page_pool *pool, return NULL; } + page->pp_magic |= PP_SIGNATURE; + /* Track how many pages are held 'in-flight' */ pool->pages_state_hold_cnt++; trace_page_pool_state_hold(pool, page, pool->pages_state_hold_cnt); @@ -263,6 +266,7 @@ static struct page *__page_pool_alloc_pages_slow(struct page_pool *pool, put_page(page); continue; } + page->pp_magic |= PP_SIGNATURE; pool->alloc.cache[pool->alloc.count++] = page; /* Track how many pages are held 'in-flight' */ pool->pages_state_hold_cnt++; @@ -341,6 +345,8 @@ void page_pool_release_page(struct page_pool *pool, struct page *page) DMA_ATTR_SKIP_CPU_SYNC); page_pool_set_dma_addr(page, 0); skip_dma_unmap: + page->pp_magic = 0; + /* This may be the last page returned, releasing the pool, so * it is not safe to reference pool afterwards. */ -- 2.31.1