From patchwork Tue Jun 4 09:08:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Kellermann X-Patchwork-Id: 13684916 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 C98B4C25B7E for ; Tue, 4 Jun 2024 09:09:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D6EE6B0096; Tue, 4 Jun 2024 05:09:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5860C6B0098; Tue, 4 Jun 2024 05:09:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38D3F6B0099; Tue, 4 Jun 2024 05:09:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 167D76B0096 for ; Tue, 4 Jun 2024 05:09:15 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BC4A3A17EE for ; Tue, 4 Jun 2024 09:09:14 +0000 (UTC) X-FDA: 82192632228.22.F6ED65D Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) by imf25.hostedemail.com (Postfix) with ESMTP id C7D4CA0004 for ; Tue, 4 Jun 2024 09:09:12 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=Lx7hPiFM; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf25.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.208.47 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717492152; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Lu9yS7pQCrsoRi7ZUhn1+G2Y6nFzVt+avQdoI72cAe0=; b=A4ruJMPMM543LJWLLiGVvtNTVQ40+Mkb8JoTwLi4cPCSS75VsJohN3Ys2SvZtEWSVAwcJu bS9wcC9hpfKQn7EGciGR/ngnVmMSh8KDFS1QTHhESJRNKd85LvKu4xK0sX2YbOXNEtG0OQ SxGbU7S8rTQeLsP2oaFTtFHyEVxJC0s= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=ionos.com header.s=google header.b=Lx7hPiFM; dmarc=pass (policy=quarantine) header.from=ionos.com; spf=pass (imf25.hostedemail.com: domain of max.kellermann@ionos.com designates 209.85.208.47 as permitted sender) smtp.mailfrom=max.kellermann@ionos.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717492152; a=rsa-sha256; cv=none; b=jawfUFJAYuge1ziXxz7Uv7Q1ft0vzL7HquJHlAU3sSBiHdsEBKtOf0Ltr3+wkC16djukBx nCe1ydpVE2wTSLUQihnFzm3vxH6O1wdz2W7CAf0NDpg+JNSV4/czRMLxb5qWFQXygAVlpl laTzOhxx74DerIefx1QbkTau4kzY4OE= Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-57a677d3d79so2925456a12.1 for ; Tue, 04 Jun 2024 02:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1717492151; x=1718096951; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Lu9yS7pQCrsoRi7ZUhn1+G2Y6nFzVt+avQdoI72cAe0=; b=Lx7hPiFM9tb38XvIYkCazCxaEQpYlG2Or0g91whloVH6F65qfQ6WWq3tlwJl4Zf3Gg aH2odfZLX6izUtd4nojCF9PTOoEvKooyhXz5KePbQ4JXhq+txIuotbo2ryuyLn6B0Ts4 4YTHL2V/AZD5PLe1Tlp6WOfhI5GQdhpioX6zDyxQqxFssCj01xs8NO1xuugcXjoq1hMc +8Woz2UkY8ZXsPXhGYtvSe7sDGkO4OxJ6rTZPIHzb5VNrPs4Zb3bMVFs87mwVB+3Vfza 8Mel+lG1Yz/OtPC/hjAqmTa8DxWi0eIeqaMI2vPzcxsZcMg6YlUVfzO2TSn7+uiugLMS LDrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717492151; x=1718096951; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Lu9yS7pQCrsoRi7ZUhn1+G2Y6nFzVt+avQdoI72cAe0=; b=pN0Bu9IShBHU6PLr7DLbIcnzwRZj19X6uMWPlap+SKO9bVrR10hUsl8tmgFMoN0kZX JvGHaUk0oYD4YqM8Xnvqvp6yNWY1XRt4Q9kk5/o5c1cyXDE6X6ZwSmvAeB0eZiJUp6KU iSvVtn2A8xIwa9EH/NSFrb2nF+NdeaoqyLOLeXJG7AJJErKiGrGd3uU5eNQQ6/eyQXfo IzyynjF5+Jsmt1tcerwi1afymr5rhrUAGpQ5HU/O/OP/EaU784X28tFqQY0vscVERN73 8Ik+Xg016Msljo8I5o8/bznRhblpcARnvd3sCPA50cBIHl/A8pyw9FimORU1xRKclUyq tPPw== X-Forwarded-Encrypted: i=1; AJvYcCWNKlY7hxKR4wWXyot6hgd3EEiILSA2vLHTem2StFEh/1IaP6e9jn14GAvSrk6Uai0T3f97VfOCwWNZeFtnGb12MaQ= X-Gm-Message-State: AOJu0Ywxl9x5t23f0dqOFME22ve75A+6sQ9goOKxj7MTtpDYc9wVYlfo 7Dn/eGvZYqERX8V8yQ5J7XYzibVUq7NT9grPncNoVszY2ajFIcyv3MlAaxWNUKlzbXDyJ5v07D7 pYYg= X-Google-Smtp-Source: AGHT+IFXHmTUY2LAO0CrBslhuc7TrTKlPItnXfEjmCqfLbltfo+OCfR+cziyr/TPphDgOmpCJJexuA== X-Received: by 2002:a17:906:471a:b0:a59:dba0:1544 with SMTP id a640c23a62f3a-a69544242b4mr149880166b.31.1717492151196; Tue, 04 Jun 2024 02:09:11 -0700 (PDT) Received: from raven.blarg.de (p200300dc6f4f9200023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f4f:9200:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a68fa49e66fsm328376766b.129.2024.06.04.02.09.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 02:09:09 -0700 (PDT) From: Max Kellermann To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: willy@infradead.org, sfr@canb.auug.org.au, david@redhat.com, Max Kellermann Subject: [PATCH v6 04/15] linux/mm.h: move page_kasan_tag() to mm/page_kasan_tag.h Date: Tue, 4 Jun 2024 11:08:34 +0200 Message-Id: <20240604090845.2182265-5-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240604090845.2182265-1-max.kellermann@ionos.com> References: <20240604090845.2182265-1-max.kellermann@ionos.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: C7D4CA0004 X-Stat-Signature: tc69kgoufizqwg9zc1hpm6p94aupeurm X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1717492152-724151 X-HE-Meta: U2FsdGVkX1+f/hppSoBOxUJLvi83TATgwXaHPl6ru3oR8YTftYEH6i3G/01AlPIHqixDmnmw83YLukQzRhNJnWUMVW+3LJRDhbUGHQrSmshH+x+mKlNFWIdKzbP8Bk64BFBcSwE3h+rbKeeHwzqLU9/vE+25mnp9/ZZfNWHg99EAoeXhLxWCTI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cm3u/dH+R9yXTgFzileUjhUPhMjEONP8ngW5Hi3HCaClysKmR3EjuWhjT7/8Kji9jhdeqLp86ero/UBXs/WxXtposiiDPb0xwUy2yjhZpIcGiYtDdyklKOAJLpJ7ru1jVwbrnxntN1TQg7hCdSl9Nzr5kCsuM2/3tE= 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: List-Subscribe: List-Unsubscribe: Prepare to reduce dependencies on linux/mm.h. page_kasan_tag() is used by the page_to_virt() macro in ARM64 (but asm/memory.h does not include linux/mm.h). Thus, in order to be able to use anything that calls page_to_virt(), linux/mm.h needs to be included. This would prevent us from moving page_address() to a separate header, because it calls lowmem_page_address() which in turn calls page_to_virt(). To prepare for this move, we move page_kasan_tag() out of linux/mm.h into a separate lean header. A side effect of this patch is that the include line is moved inside the "#ifdef CONFIG_KASAN..." block, i.e. it is not included at all if KASAN is disabled. Signed-off-by: Max Kellermann --- MAINTAINERS | 1 + include/linux/mm.h | 56 +------------------------- include/linux/mm/page_kasan_tag.h | 66 +++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 55 deletions(-) create mode 100644 include/linux/mm/page_kasan_tag.h diff --git a/MAINTAINERS b/MAINTAINERS index bb9f8077b37d..a9459947a3b3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14475,6 +14475,7 @@ F: include/linux/mempolicy.h F: include/linux/mempool.h F: include/linux/memremap.h F: include/linux/mm.h +F: include/linux/mm/*.h F: include/linux/mm_*.h F: include/linux/mmzone.h F: include/linux/mmu_notifier.h diff --git a/include/linux/mm.h b/include/linux/mm.h index c41c82bcbec2..3ff239992d4c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2,6 +2,7 @@ #ifndef _LINUX_MM_H #define _LINUX_MM_H +#include #include #include #include @@ -28,7 +29,6 @@ #include #include #include -#include #include #include @@ -1812,60 +1812,6 @@ static inline void vma_set_access_pid_bit(struct vm_area_struct *vma) } #endif /* CONFIG_NUMA_BALANCING */ -#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) - -/* - * KASAN per-page tags are stored xor'ed with 0xff. This allows to avoid - * setting tags for all pages to native kernel tag value 0xff, as the default - * value 0x00 maps to 0xff. - */ - -static inline u8 page_kasan_tag(const struct page *page) -{ - u8 tag = KASAN_TAG_KERNEL; - - if (kasan_enabled()) { - tag = (page->flags >> KASAN_TAG_PGSHIFT) & KASAN_TAG_MASK; - tag ^= 0xff; - } - - return tag; -} - -static inline void page_kasan_tag_set(struct page *page, u8 tag) -{ - unsigned long old_flags, flags; - - if (!kasan_enabled()) - return; - - tag ^= 0xff; - old_flags = READ_ONCE(page->flags); - do { - flags = old_flags; - flags &= ~(KASAN_TAG_MASK << KASAN_TAG_PGSHIFT); - flags |= (tag & KASAN_TAG_MASK) << KASAN_TAG_PGSHIFT; - } while (unlikely(!try_cmpxchg(&page->flags, &old_flags, flags))); -} - -static inline void page_kasan_tag_reset(struct page *page) -{ - if (kasan_enabled()) - page_kasan_tag_set(page, KASAN_TAG_KERNEL); -} - -#else /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ - -static inline u8 page_kasan_tag(const struct page *page) -{ - return 0xff; -} - -static inline void page_kasan_tag_set(struct page *page, u8 tag) { } -static inline void page_kasan_tag_reset(struct page *page) { } - -#endif /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ - static inline struct zone *page_zone(const struct page *page) { return &NODE_DATA(page_to_nid(page))->node_zones[page_zonenum(page)]; diff --git a/include/linux/mm/page_kasan_tag.h b/include/linux/mm/page_kasan_tag.h new file mode 100644 index 000000000000..1210c62170a3 --- /dev/null +++ b/include/linux/mm/page_kasan_tag.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_MM_PAGE_KASAN_TAG_H +#define _LINUX_MM_PAGE_KASAN_TAG_H + +#include + +struct page; + +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) + +#include +#include // for struct page + +/* + * KASAN per-page tags are stored xor'ed with 0xff. This allows to avoid + * setting tags for all pages to native kernel tag value 0xff, as the default + * value 0x00 maps to 0xff. + */ + +static inline u8 page_kasan_tag(const struct page *page) +{ + u8 tag = KASAN_TAG_KERNEL; + + if (kasan_enabled()) { + tag = (page->flags >> KASAN_TAG_PGSHIFT) & KASAN_TAG_MASK; + tag ^= 0xff; + } + + return tag; +} + +static inline void page_kasan_tag_set(struct page *page, u8 tag) +{ + unsigned long old_flags, flags; + + if (!kasan_enabled()) + return; + + tag ^= 0xff; + old_flags = READ_ONCE(page->flags); + do { + flags = old_flags; + flags &= ~(KASAN_TAG_MASK << KASAN_TAG_PGSHIFT); + flags |= (tag & KASAN_TAG_MASK) << KASAN_TAG_PGSHIFT; + } while (unlikely(!try_cmpxchg(&page->flags, &old_flags, flags))); +} + +static inline void page_kasan_tag_reset(struct page *page) +{ + if (kasan_enabled()) + page_kasan_tag_set(page, KASAN_TAG_KERNEL); +} + +#else /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ + +static inline u8 page_kasan_tag(const struct page *page) +{ + return 0xff; +} + +static inline void page_kasan_tag_set(struct page *page, u8 tag) { } +static inline void page_kasan_tag_reset(struct page *page) { } + +#endif /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ + +#endif /* _LINUX_MM_PAGE_KASAN_TAG_H */