Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3542158pxb; Mon, 24 Jan 2022 11:49:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwfvhJUnKw2pOjSx5La87ZV4rgDRXdEBJ3p9xJRnUubAWIA627tZ3XmOVhBb9pjRMd3RQlj X-Received: by 2002:a17:90b:2507:: with SMTP id ns7mr3477446pjb.80.1643053750561; Mon, 24 Jan 2022 11:49:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643053750; cv=none; d=google.com; s=arc-20160816; b=fFfkfsyTwK0l52f7WhiMKsLmC5FWAcQy37zSb0g8C8S2DW8WppL20hINZqkuAUrhH0 rgAIpgrWzFn85uR/lnDum0mL3XN9Cefrk9GB/KOU++ttqBcgFJbzYnBVGd1TX135SL7A LDD7Ji3ZM3HnIWPk8qI464+HW3E+pAzuApaClaTxO6VwU77YwWSHysOwrpQZ7h7S6Kjr ao3s+AlvJk9tQc1v+eBoBnhAn5FqEB23JOxhlafP+1WshaQhrFPwDaR44tf15KWkNtEs Qi5jZFoF46a+nlkA1jZFXK3Hwrt0mZMCX+jnf/D2lY4UmZn4fqocvNppGpSKxK2P7LOW dbKg== 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 :dkim-signature; bh=NtjC8GJtWhPCzF1O+E8r8kpeY3QxluInaVM8vIRb3RM=; b=qt87OimEio4Wn+1ZBpdU3xROfQ5BREWbPHzQAid8UbKwIWpCIMXk8HI8+be67f1dtZ SY4mwxP7sI/T8+OWw/Mb1JgDD3jzpDNoluatp3qZZcpUV0EihxIV3jjgiqPEeQ+rYYEq ggX+IOjIJDy9jLhs+1sIsovnGx9EX6sW5c0/JWh/jAW8NEz5Iek5SG/HNulsV5FMHVgd VTmsJMVkYWWp9g2h/JsTI+7I3yQOd5evhuLBQJzKJq3jjcEDm/rqZ33ETJx0/b8JzvDP YqvASVYdWGzo4dL+BlucU6A32owdn3Ww9n2UDpx53O2PGQ3tkmmvp8YZ5Y5b7PYLr/Tk YEyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=bKBbSy6f; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 18si229894pjb.116.2022.01.24.11.48.58; Mon, 24 Jan 2022 11:49:10 -0800 (PST) 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; dkim=pass header.i=@linux.dev header.s=key1 header.b=bKBbSy6f; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235628AbiAXSDB (ORCPT + 99 others); Mon, 24 Jan 2022 13:03:01 -0500 Received: from out0.migadu.com ([94.23.1.103]:17236 "EHLO out0.migadu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235769AbiAXSC4 (ORCPT ); Mon, 24 Jan 2022 13:02:56 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1643047375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NtjC8GJtWhPCzF1O+E8r8kpeY3QxluInaVM8vIRb3RM=; b=bKBbSy6fPym/MRrA09RJIXkFlYKAWKOMZ3FKz5LNI3x7DUkJ4ipRMk3eZQPDdGKQEIJ+Rn j3caDMhxpDJoFvlu8+abP1Q+12iYW+9yQZ9ALHbERTjD13CazkPOVr1esNMbanQHMt1ZYL /Tgi6BMH04tWMfhdG1YeU09jhv3m/Vc= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, Vincenzo Frascino , Catalin Marinas , Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org, Peter Collingbourne , Evgenii Stepanov , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v6 02/39] kasan, page_alloc: move tag_clear_highpage out of kernel_init_free_pages Date: Mon, 24 Jan 2022 19:02:10 +0100 Message-Id: <7719874e68b23902629c7cf19f966c4fd5f57979.1643047180.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Konovalov Currently, kernel_init_free_pages() serves two purposes: it either only zeroes memory or zeroes both memory and memory tags via a different code path. As this function has only two callers, each using only one code path, this behaviour is confusing. Pull the code that zeroes both memory and tags out of kernel_init_free_pages(). As a result of this change, the code in free_pages_prepare() starts to look complicated, but this is improved in the few following patches. Those improvements are not integrated into this patch to make diffs easier to read. This patch does no functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- Changes v2->v3: - Update patch description. --- mm/page_alloc.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 25d4f9ad3525..012170b1c47a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1282,16 +1282,10 @@ static inline bool should_skip_kasan_poison(struct page *page, fpi_t fpi_flags) PageSkipKASanPoison(page); } -static void kernel_init_free_pages(struct page *page, int numpages, bool zero_tags) +static void kernel_init_free_pages(struct page *page, int numpages) { int i; - if (zero_tags) { - for (i = 0; i < numpages; i++) - tag_clear_highpage(page + i); - return; - } - /* s390's use of memset() could override KASAN redzones. */ kasan_disable_current(); for (i = 0; i < numpages; i++) { @@ -1387,7 +1381,7 @@ static __always_inline bool free_pages_prepare(struct page *page, bool init = want_init_on_free(); if (init) - kernel_init_free_pages(page, 1 << order, false); + kernel_init_free_pages(page, 1 << order); if (!skip_kasan_poison) kasan_poison_pages(page, order, init); } @@ -2430,9 +2424,17 @@ inline void post_alloc_hook(struct page *page, unsigned int order, bool init = !want_init_on_free() && want_init_on_alloc(gfp_flags); kasan_unpoison_pages(page, order, init); - if (init) - kernel_init_free_pages(page, 1 << order, - gfp_flags & __GFP_ZEROTAGS); + + if (init) { + if (gfp_flags & __GFP_ZEROTAGS) { + int i; + + for (i = 0; i < 1 << order; i++) + tag_clear_highpage(page + i); + } else { + kernel_init_free_pages(page, 1 << order); + } + } } set_page_owner(page, order, gfp_flags); -- 2.25.1