Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp506527rdb; Thu, 15 Feb 2024 06:57:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVAvDW9CaVUlt20sG0smc6R24MYJY5bGJxGF/in8XJIRtvztKy6CIcaVkzSILoOcdHIVNwFi9QV2r89kZYNrdtXg/Nbpdc9Ne2K+2YzSA== X-Google-Smtp-Source: AGHT+IFmdFTBbg8mQd5U0CemulR6bxwrzG2QEozV4rMFmD/jPVRkXUpqInTvfbswvwOVP64SWdyA X-Received: by 2002:a05:620a:454d:b0:783:bcc9:cd84 with SMTP id u13-20020a05620a454d00b00783bcc9cd84mr2976294qkp.49.1708009029573; Thu, 15 Feb 2024 06:57:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708009029; cv=pass; d=google.com; s=arc-20160816; b=E3qCO07J5on407j7IqAKekwV2QuXZKrX2MifrW2lkAX5w9nplhhuwxe9VSJxdqQbp8 r4a4IlK/gsFvim8cAnLYAL/SIm+B4yuSYUnGl0cdU6UlXIayif1ko33npzwHzwsi/Ycv lMr7LSlr2iG5S6SYgoxQbYEM5pMJIrYmDa4gMxYlNZyz277V1qB+gGG/8zoOKDYf1tG1 37rBEuLigZFRufNeql10ErFiDCcpiEEcwPLjXM0qEKz1j4o5uuJ7t4qDretpfa5dpOof 1duFgGqM39kI3I6jf1kxPLI4QqgAtLHVpuv5cxAI1MqeS4FX9ufOKH7gmSUaPpX+0fWW 0VpQ== 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=5yWhRxx5j9/Xhrml0aMKDxvuRZarY+DeLwc3tl7RleQ=; fh=F0tbqXbT1oZsBuj5afmnHOv0UzkYm+NanjP2Uf6n73k=; b=LEMgJx7bcgOm+/C2roUXoIoVysbUn90Usz5ADko6e6NJuOd8ur3TA7NlwB/SPk3zKh deG+uHxjwzLsQmUChhwlgwSMjB7A55u+ZSJSW0HrLumM/RiZ/Zd2vKJAMhs91kCe5ncn xfgIFlT749Hs13AOvZwcmOHXIlIitWSWwPklM8AWEf1bBfzRHOgNznQA9yAN5PpxoapV T8Gp4NZK31+CGuJjxXvLYwIoyzBePRS9pO88QA62dVskYmEjp4oAz6jxVBQ7Ysc9b/5A PictPBcHoyD2jfDMbKkZzq3lLfCEDuohD48BBUSQLPPFBv1sPk9taRlGO9FPulldsiex IUCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=aHu1Gnts; 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-67114-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67114-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ionos.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z2-20020a05620a100200b00785dadba14asi1665168qkj.222.2024.02.15.06.57.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 06:57:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67114-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=aHu1Gnts; 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-67114-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67114-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 4863E1C22214 for ; Thu, 15 Feb 2024 14:57:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B1B94132498; Thu, 15 Feb 2024 14:56:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ionos.com header.i=@ionos.com header.b="aHu1Gnts" Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (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 70988132C1D for ; Thu, 15 Feb 2024 14:56:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708008978; cv=none; b=VhyTCzc1kXZ03Ny9pJL0nWsvSSFAaW+vPy8jcbUWxkghELguQyVV4xkzCtyXoP/d4o18x16QErGrRpynepKybYniW+sCnUYTo/1RhR6E+vIt6bq6CvA8zigZEhddqJdH0laQwFsMDhXYpVgRPySTbA3CfS9JgOgJeIPgbmoJNYo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708008978; c=relaxed/simple; bh=gVIds65BiYL/PkB0EIOcX5QkFlfKbFVbwd5jl45KB+c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PHYo3Dca/cjWQhzdxViasQm97LfMz6r3bnD3WQuGIqx0rUruGZDHq3niFHl7MY4Yz97RwS/7Q0BxIyuPgAPflVM5FMDfaJ62gjS9lJXxKbDbhHjDJW9daL2VvjbTCEm/OCKL6O0Av/fhCPybzfdfXHfAKKE1cZ6Kvrwa4Fg/iUk= 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=aHu1Gnts; arc=none smtp.client-ip=209.85.208.54 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-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-55a8fd60af0so1428273a12.1 for ; Thu, 15 Feb 2024 06:56:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; t=1708008975; x=1708613775; 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=5yWhRxx5j9/Xhrml0aMKDxvuRZarY+DeLwc3tl7RleQ=; b=aHu1Gnts7ESUimtXnVliJt87ieqUAZ58KDtFRje5csVltxLBJkrw0Wk1LhBx51OsMK pdEOsoLC/7AYtyvcojtYVpZaE0q+UdMV8HEMcdld0pjfmcB4FstAXCe5dNB95rMtkVSx rX/Dgyx23tuIMDhKIMul2B2Cuj0WXsGgLlkH8wzrziCpbXpdZa5Wnf12A4uvhoqRGPvO kdJnH5u+wN9pOw8D9I4clCGS3xvxE6PoUlInsqrchMaiSJ9NWR83u44j1RZeO+K1G6GI JBCyYeDk1919z/htK4cg+7kFv6LKNkBPgfLQDKqXUiiXr2CDFzWErZFAH5F3CtorH9oM nMkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708008975; x=1708613775; 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=5yWhRxx5j9/Xhrml0aMKDxvuRZarY+DeLwc3tl7RleQ=; b=M09p3sEN6mC4Kl8EUlrpvX84z2UOpDrpstxRUMfXSLugRlWIv14+Tx32k+DlsLHJeg qoBnayGbatXw3YbLO6wGNSyKhNw83K6LJNW0flhqCU1R/2aDPPA9AR2FBxzbg4rcRygI oxD14Yka0O7AViCNRqzzSQHZxYxmliDwXzPx8thDocj/hgi9ZjZ4kBCniaUqixUsvPdf I853CLEiox/PmrrOsdBkfxHeU7mXcJ9Xxvz1Gvxtjw6wiviRlVocHki7Qpo1Gmqfhi/w 33yMvLoPirMtovXTEFzHjq9Rj+/XxjfQg0A3b/KaBogrBWceFteFRivIg/E/VcKZ1hKZ yoTA== X-Forwarded-Encrypted: i=1; AJvYcCW/jmz3tsvStuSpDtv+Bvkq0qBEHUvt7NgLtMmgGF10O93d9iGaF/FSbidSQ9QTRwfmxn+toTHYF0aDnKclfkA81AUg1wtr4360zAzy X-Gm-Message-State: AOJu0Yx4UNNTBJ41Kt9nn4pyJLuOqV4VtFj0FkdWlG+Qdx0q2YkpUlIX 4SEyFrav4TTN45uk49HGFOOdG6650YZDvadbN13tC5LxKcu2tTt8I9vZQQnPM1Y= X-Received: by 2002:a17:906:1186:b0:a39:6c07:d31c with SMTP id n6-20020a170906118600b00a396c07d31cmr1552619eja.25.1708008972867; Thu, 15 Feb 2024 06:56:12 -0800 (PST) Received: from raven.intern.cm-ag (p200300dc6f267100023064fffe740809.dip0.t-ipconnect.de. [2003:dc:6f26:7100:230:64ff:fe74:809]) by smtp.gmail.com with ESMTPSA id s18-20020a170906169200b00a3d1897ab68sm631175ejd.113.2024.02.15.06.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 06:56:12 -0800 (PST) From: Max Kellermann To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Max Kellermann Subject: [PATCH v1 03/14] linux/mm.h: move page_kasan_tag() to mm/page_kasan_tag.h Date: Thu, 15 Feb 2024 15:55:51 +0100 Message-Id: <20240215145602.1371274-4-max.kellermann@ionos.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215145602.1371274-1-max.kellermann@ionos.com> References: <20240215145602.1371274-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 in linux/mm.h. 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 897fbf1b0701..4fba8597b2c1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14227,6 +14227,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 6095c86aa040..decc0cb8ed32 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 @@ -1805,60 +1805,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