From patchwork Tue May 31 15:43:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 12865878 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 676E2C433EF for ; Tue, 31 May 2022 15:43:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F15026B0072; Tue, 31 May 2022 11:43:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D42216B0075; Tue, 31 May 2022 11:43:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C073F6B0078; Tue, 31 May 2022 11:43:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A7ED26B0073 for ; Tue, 31 May 2022 11:43:56 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 77FAF34CE9 for ; Tue, 31 May 2022 15:43:56 +0000 (UTC) X-FDA: 79526458872.16.E7514CF Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf20.hostedemail.com (Postfix) with ESMTP id E47831C0063 for ; Tue, 31 May 2022 15:43:37 +0000 (UTC) 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=1654011834; 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=tEpZdGz90JlT1Su1SZxeM3e97n4OjIjhauOVgJs/x+Q=; b=ce+LyTosve/iVH9saoGKtCpSbSXfRease5nqKzuWRouhIjfI3dDzxtv5+qtA5s+Y92VtF2 wmJc5Qx8+aVF8+Uy8hMCmvAxR0hDqKOY8q+ijFj7KZt2K+NkCDldH2Z2GMZLcCO9Z4X82d Ki5a5OuzdcgrA4nhqYI0GSIKITJBrVM= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 2/3] mm: introduce clear_highpage_tagged Date: Tue, 31 May 2022 17:43:49 +0200 Message-Id: In-Reply-To: <4c76a95aff79723de76df146a10888a5a9196faf.1654011120.git.andreyknvl@google.com> References: <4c76a95aff79723de76df146a10888a5a9196faf.1654011120.git.andreyknvl@google.com> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Rspam-User: Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ce+LyTos; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf20.hostedemail.com: domain of andrey.konovalov@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: E47831C0063 X-Stat-Signature: wgata539a8pjitqo3kkhxpuik4p98tqx X-HE-Tag: 1654011817-111198 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: Andrey Konovalov Add a clear_highpage_tagged() helper that does clear_highpage() on a page potentially tagged by KASAN. This helper is used by the following patch. Signed-off-by: Andrey Konovalov --- include/linux/highmem.h | 11 +++++++++++ mm/page_alloc.c | 8 ++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 3af34de54330..df76a0db7cec 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -243,6 +243,17 @@ static inline void clear_highpage(struct page *page) kunmap_local(kaddr); } +static inline void clear_highpage_tagged(struct page *page) +{ + u8 tag; + + tag = page_kasan_tag(page); + page_kasan_tag_reset(page); + clear_highpage(page); + page_kasan_tag_set(page, tag); + +} + #ifndef __HAVE_ARCH_TAG_CLEAR_HIGHPAGE static inline void tag_clear_highpage(struct page *page) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 66ef8c310dce..d82ea983a7a3 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1302,12 +1302,8 @@ static void kernel_init_pages(struct page *page, int numpages) /* s390's use of memset() could override KASAN redzones. */ kasan_disable_current(); - for (i = 0; i < numpages; i++) { - u8 tag = page_kasan_tag(page + i); - page_kasan_tag_reset(page + i); - clear_highpage(page + i); - page_kasan_tag_set(page + i, tag); - } + for (i = 0; i < numpages; i++) + clear_highpage_tagged(page + i); kasan_enable_current(); }