Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp944929lql; Tue, 12 Mar 2024 02:49:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXNgMu97ftCEzeAZW3tG7xw/A9gv6wX0zjEBFbDhmrK26h7j4MMp0RCdTyjKn4BPnLdkvbiNvBSB9QBcaqGlYUIfT5bQmUkhUFR9t9oyQ== X-Google-Smtp-Source: AGHT+IEE3NxineXZGaE7hlAkp/P4mGp7hrxQNXPHpuv8O+05kE2pMQZttEFY2pW5uLTcKiXUpYx5 X-Received: by 2002:a05:6808:3c96:b0:3c2:2f44:ad9c with SMTP id gs22-20020a0568083c9600b003c22f44ad9cmr14285768oib.4.1710236973062; Tue, 12 Mar 2024 02:49:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710236973; cv=pass; d=google.com; s=arc-20160816; b=K8QXQ2+lH69+6FvMVN8cP+Gxsfg9CYDMXdJnKf1bujBeqckbSflYyOvxb3KUYsOYpw XGqIhh3exOQCGaS/Vg0ddSKP7Xv03EZ+gf+p4OlwRHYn1vT3X1HpycALRTZFW2vGg2W5 wFDG7/iuCUKvWP1WH7xvZyXwf6rzqNp2Ez0zhDQvDfO0Ee5nw5t3gzkhQmJrXKqGAF1f 3xffGiElyTLow4jI9aKc/j3QdSzeRXWjh9kZks2N0YAuO+wnnSu5LhRwb0cZZnqwOMe8 gUuSDZeDwK8xlZlfPM4rgxqLmf6jm+ZRxwOSpJLODjzxFMKmlYx5A4Rgnq8RI1KJ+uce OHxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=UOXvgd5nL7gApAixwLBmVSPDbvkCXFf36Bu9a1YyE0M=; fh=47weoF87iVsR+s1ZPUAbHdngXOtMKtzREBCuCaQRuXU=; b=Klc454FVmDi0+e0dKfB9fD4IRW+n3PY3RFwh0d8q2aPWMZhNvlYtjW/lHlyW+dbzOn 6iufqYVMX/+pnCTfe2z0v8GBIa2pDCrG0Yi4rPg94f/e1zUI4CAUFNL6JfmcQT0U/0Gr 1Kx3lVrml8clZJD000cXFmYtsAm2lbtNyDFcLXBYtUZs12nKXXeNJJoH0UcQuL1w8OZQ nXPrF8ot6GQbalB0V+gOU4K1oPoZzNcBlCdxJ8NsU+gTdPuJgicmo6jA2XIL6F2O6lrK tRjpdX6eAdl0kKxstG+Y/liDdlrQBriAkwdxGx/E9bcnGpnjIlBPY/iMFqnmxhSIsta7 O5og==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=CA83FBTD; arc=pass (i=1 spf=pass spfdomain=ionos.com dkim=pass dkdomain=ionos.com dmarc=pass fromdomain=ionos.com); spf=pass (google.com: domain of linux-kernel+bounces-100044-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100044-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id w3-20020a634743000000b005dc87f9cc78si6663319pgk.556.2024.03.12.02.49.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 02:49:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100044-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=CA83FBTD; arc=pass (i=1 spf=pass spfdomain=ionos.com dkim=pass dkdomain=ionos.com dmarc=pass fromdomain=ionos.com); spf=pass (google.com: domain of linux-kernel+bounces-100044-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100044-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id BF4FBB213FD for ; Tue, 12 Mar 2024 09:43:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A881878282; Tue, 12 Mar 2024 09:41:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b="CA83FBTD" Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4423B79DBB for ; Tue, 12 Mar 2024 09:41:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710236516; cv=none; b=dXT9hKkHP7saYVpEAqVMoA90KQQUgSWxfeM9WzaSt+TrBzmIaUAKulZqt9hNFon8KtefSOAZjhoIfwBptQZ24CppUuCsQKK1q2Yp6vPJRrP4eZuvRP+nOuLKpFJfzXbyoFhYpswI/jRiOSO+PDZuSVOMT0tzQX4XXOyEJe71xw4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710236516; c=relaxed/simple; bh=6XSamrQ8GvcwYgiZq1oDc5VOoarijJtGGH5zDeCqxHU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AE7mj+JvBNR9TxpG/Y/LvRmiOqHXd0EJDcTORA8r9ySN2tayIxywpOYrBhneKsdbTNKMqcdjGLoHFhiLmXmm/c/P+b+A7/k2tWZ3uOra7E4npJDGwJs6XLthtC8Hdzqqm/Nde/z/Aj/M78hqSitd5yGSKFqAX5GsbT/FU2mbnBg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ionos.com; spf=pass smtp.mailfrom=ionos.com; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b=CA83FBTD; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ionos.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ionos.com Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a44d084bfe1so475867066b.1 for ; Tue, 12 Mar 2024 02:41:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1710236512; x=1710841312; darn=vger.kernel.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=UOXvgd5nL7gApAixwLBmVSPDbvkCXFf36Bu9a1YyE0M=; b=CA83FBTD+qLbM9Ls/kv19mIHtAIObQIf7OilBdbl3NoB6mpG8uxHdzn1gvCn7XM9SO 9JrvRRn14Goia07M66CJuEvgJ7+T7tkLgCQsA2m/qTRP/iqMy4SZuWonHSkE9Qq8DW9S rkCqWwHSmqSD7IfZJvS5HEFonWNBaIowRlzOQuMrhCbvtzKovlu5M5C4Z8YPAW/9RUgj AnTCZ0Psn9+61pktgjU7O3b1G6CYz2Y3xlAnjkU6kqnY7YulvCKdPfvaAIa4o1LYWEeO 2b4bu5wSxIS0KZZi05gcN2j6E7Wfn5sp/EQVF6JAHTG6tC0pULWeIdw7EZvxgvrhE23e g71A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710236512; x=1710841312; 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=UOXvgd5nL7gApAixwLBmVSPDbvkCXFf36Bu9a1YyE0M=; b=bMqe/YJ5Aurk/YPal4vsmEQTIKoKxf0bBKNgsJWq39r699fYn6dkIlWeborXJ2w7pp pdXsGjUpU+elF+GMzF/DwrDE/yyL3d9D3H6bxQbnIHt9uV4zbl/hF/85272wOxebRFmo OEfCSJF5+FxKtaWiH7a5/0GPvt96tfJ0cEU44gX1lz0G9kgEVgSiyBcCC5XT9ymQW7TL GotxGlDSOTOLlkOtixkvKJBDLnI0YD2HBwimim47foiu/q78gO0audjxTD5NAeHXY1Qa KRBHcGspbVADrFYYLghyeXZEopcw5hiQuQX8OHZhsE3BQWo4D9Ld9uOx6mR+FnwQ23WY 1Htw== X-Forwarded-Encrypted: i=1; AJvYcCXajyALZiK2zF2TGKeH/tmebEy6C5B8KPIeVVtuTC12UUuyn4ji1JuV7vrvWMbu1d0jxcd9BS2am1E/oJ6ep06Umu4bsXA8/HwrCjPl X-Gm-Message-State: AOJu0YyELUng9ALiWLDDqgEk/cWFxuGGqaBfDRKYj5VZcGSBUyqEUzFW e0J07GLzh2vOVTTms8VPU+KsYrdQ+Se44zwpMm3U9fvCjAJKRIN+RUXrzi/xrbs= X-Received: by 2002:a17:907:1888:b0:a45:c997:2267 with SMTP id lj8-20020a170907188800b00a45c9972267mr5996063ejc.65.1710236512626; Tue, 12 Mar 2024 02:41:52 -0700 (PDT) Received: from raven.blarg.de (p200300dc6f010900023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f01:900:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id jw22-20020a170906e95600b00a4623030893sm2091961ejb.126.2024.03.12.02.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 02:41:52 -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, Max Kellermann Subject: [PATCH v4 04/15] linux/mm.h: move page_kasan_tag() to mm/page_kasan_tag.h Date: Tue, 12 Mar 2024 10:41:22 +0100 Message-Id: <20240312094133.2084996-5-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240312094133.2084996-1-max.kellermann@ionos.com> References: <20240312094133.2084996-1-max.kellermann@ionos.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 b43102ca365d..f2d32e2da433 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14218,6 +14218,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 0436b919f1c7..e140ee45f49c 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 @@ -27,7 +28,6 @@ #include #include #include -#include #include #include @@ -1818,60 +1818,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 */ -- 2.39.2