From nobody Wed Dec 17 17:45:10 2025 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 9509C2D8DAF for ; Fri, 3 Oct 2025 17:32:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759512769; cv=none; b=ZCBrKx1vfE3gakJoAzi2opfbXUO/O6qqjpZvDYGfQmpBQuN8dExd8seOf90aHnTXEzXZsilP+Co+VJRxfFA8M136bLJmlhInS6jso3UD2xUirolIqCdVArQ28uIbC+gZtgbwUwDX4KIiLWBc30k2je0/veaLQGxk6jVr3A9qHQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759512769; c=relaxed/simple; bh=s/PYXakXl6KqlrcIvciX5HalUknvMXRiakKCbQm7Wo4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=E1xLomXTF7j4H1MWPEQAyCXeJneGFeOryQnchDQHzUUfkeRYEaYdUPPsP8DT74JTuHI8xbL1klr7QurXqF/SXgqkTjAvsZbFZRUjFeqUc4l0sE5aRuRN5beVIxoYnwZh3ltT3MVGmkcnq0LvJFSKs2qEoVW1bBbT4NewjRPVSb4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Azhuuh5S; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Azhuuh5S" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-46e375dab7dso13299875e9.3 for ; Fri, 03 Oct 2025 10:32:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759512766; x=1760117566; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zH+wdcZ5EVKOe0qHDw87x4CzKKpCZFkdrN8PVNJB6b4=; b=Azhuuh5SydWj16ep/xglqbw5m+AYh+zJ7zrrY8ROSt7PXHJu/M/JjG6HkAXsNLRjRl Slk/0cSXy/tw61c18Q22jBCpJfuTTfgUpNa4fcltcBZ25RAUtfCB3cjIh2XLR49weGoF QZ8HxZaSjy2HTHfWoe+jffO3M9Zq7yk8YMjHWn/1buDyIKCSQ16Gw3WMkCful3dUsTIj IRWdaIGTjNHtdPH6qMAvy/QEq2dFeB6mCRtggC3Sj5C0pAx4XoPbTzez+9UArmRDqqGl IMVSPbscg9D9wuQyMVlg9dyDm30gpcFHIv3QDiNr5Qw2XSfuylVGprLxb7t7Hx5EH7xn V15A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759512766; x=1760117566; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zH+wdcZ5EVKOe0qHDw87x4CzKKpCZFkdrN8PVNJB6b4=; b=pD5t4agOo/xmHrh3USnHBuYYHSjDcXFsZfJdJq/BzMjxBBmxqN3boutYEuETx2BrSt 7lJw2CV6p4Cac2u5zsPUQ4T7nXK/BqQNgiSBP9UUcrXBWRxxOaG7KCC1jtaPSUpLsMDQ eNqOhj3SH+A0LYZsNcHDPm3aedfSWyaBR6tpuDnzTSPLZOV6KWQy0dC1LvNqfWtM6+Ef KdiXJicUhq8+hNs0I8fPaNhGwuaXPfNh6eSOJFt7oQF3M9i7ADpADHCLuhlrW6HaLBSH 5V+q9FD5jf069zVeXtAyUNQI+CvI+ZDQuLk7xC/OZQVnUlRxHlrlepua5+RCr4SMD/kK M6Zw== X-Forwarded-Encrypted: i=1; AJvYcCXZvtM7TVQ0+3+UB6Ubgclgm2GZ17Sj/Jdz7JQEvoCuA62eH1zJRGKqWbi7UdLWm0RA9M6CNZreUTfwS0s=@vger.kernel.org X-Gm-Message-State: AOJu0YxYkeTuHLo/qzF6AP0a5vvp/P88XZEgI5rN0NJk8giDoc6X+dun /VcCcmr6Xh5hp3pMVNGNNpFFO2hrP81KGDIZThB++nCgIe0wpOmQgK5Yj2E+JK4xTEZ28RVFCzZ Ak8JSBWvZZu2Llw== X-Google-Smtp-Source: AGHT+IGYvWG9xmF2kfRie55mVv+1GfRjdSpkjQnJcV3+O9KPqIxqc19jwTdv3Ui/FR4E11nQtZ5ZDpq1J3nuCg== X-Received: from wmbz22.prod.google.com ([2002:a05:600c:c096:b0:46e:6a75:2910]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:a343:b0:459:d451:3364 with SMTP id 5b1f17b1804b1-46e71144103mr28980925e9.24.1759512766152; Fri, 03 Oct 2025 10:32:46 -0700 (PDT) Date: Fri, 3 Oct 2025 17:32:26 +0000 In-Reply-To: <20251003173229.1533640-1-smostafa@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251003173229.1533640-1-smostafa@google.com> X-Mailer: git-send-email 2.51.0.618.g983fd99d29-goog Message-ID: <20251003173229.1533640-2-smostafa@google.com> Subject: [RFC PATCH 1/4] drivers/iommu: Add page_ext for IOMMU_DEBUG_PAGEALLOC From: Mostafa Saleh To: linux-mm@kvack.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: corbet@lwn.net, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, akpm@linux-foundation.org, vbabka@suse.cz, surenb@google.com, mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com, david@redhat.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, rppt@kernel.org, Mostafa Saleh Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a new config IOMMU_DEBUG_PAGEALLOC, which registers new data to page_ext. This config will be used by the IOMMU API to track pages mapped in the IOMMU to catch drivers trying to free kernel memory that they still map in their domains, causing all types of memory corruption. This behaviour is disabled by default and can be enabled using kernel cmdline iommu.debug_pagealloc. Signed-off-by: Mostafa Saleh Tested-by: Qinxin Xia --- .../admin-guide/kernel-parameters.txt | 6 ++++ drivers/iommu/Kconfig | 14 ++++++++ drivers/iommu/Makefile | 1 + drivers/iommu/iommu-debug.c | 32 +++++++++++++++++++ include/linux/iommu-debug.h | 17 ++++++++++ mm/page_ext.c | 4 +++ 6 files changed, 74 insertions(+) create mode 100644 drivers/iommu/iommu-debug.c create mode 100644 include/linux/iommu-debug.h diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 74ca438d2d6d..b2691a5527dd 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2539,6 +2539,12 @@ 1 - Bypass the IOMMU for DMA. unset - Use value of CONFIG_IOMMU_DEFAULT_PASSTHROUGH. =20 + iommu.debug_pagealloc=3D + [KNL,EARLY] When CONFIG_IOMMU_DEBUG_PAGEALLOC is set, this + parameter enables the feature at boot time. By default, it + is disabled and the system will work mostly the same as a + kernel built without CONFIG_IOMMU_DEBUG_PAGEALLOC. + io7=3D [HW] IO7 for Marvel-based Alpha systems See comment before marvel_specify_io7 in arch/alpha/kernel/core_marvel.c. diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 70d29b14d851..5b40ec9b6e04 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -383,4 +383,18 @@ config SPRD_IOMMU =20 Say Y here if you want to use the multimedia devices listed above. =20 +config IOMMU_DEBUG_PAGEALLOC + bool "Debug page memory allocations against IOMMU" + depends on DEBUG_PAGEALLOC && IOMMU_API && PAGE_EXTENSION + help + This config checks when a page is freed by the kernel + it's not mapped in any IOMMU domain. It can help with + debugging use-after-free from driver doing DMA. + This santaizer can have false-negative cases where some + problems won't be detected. + Expect overhead when enabling this + enabling the kernel + command line iommu.debug_pagealloc. + + If unsure, say N here. + endif # IOMMU_SUPPORT diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile index 355294fa9033..c834d3f70dfc 100644 --- a/drivers/iommu/Makefile +++ b/drivers/iommu/Makefile @@ -34,3 +34,4 @@ obj-$(CONFIG_IOMMU_SVA) +=3D iommu-sva.o obj-$(CONFIG_IOMMU_IOPF) +=3D io-pgfault.o obj-$(CONFIG_SPRD_IOMMU) +=3D sprd-iommu.o obj-$(CONFIG_APPLE_DART) +=3D apple-dart.o +obj-$(CONFIG_IOMMU_DEBUG_PAGEALLOC) +=3D iommu-debug.o \ No newline at end of file diff --git a/drivers/iommu/iommu-debug.c b/drivers/iommu/iommu-debug.c new file mode 100644 index 000000000000..297a35137b38 --- /dev/null +++ b/drivers/iommu/iommu-debug.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2025 - Google Inc + * Author: Mostafa Saleh + * IOMMU API santaizers and debug + */ +#include +#include +#include +#include + +static bool needed; + +struct iommu_debug_metadate { + atomic_t ref; +}; + +static __init bool need_iommu_debug(void) +{ + return needed; +} + +struct page_ext_operations page_iommu_debug_ops =3D { + .size =3D sizeof(struct iommu_debug_metadate), + .need =3D need_iommu_debug, +}; + +static int __init iommu_debug_pagealloc(char *str) +{ + return kstrtobool(str, &needed); +} +early_param("iommu.debug_pagealloc", iommu_debug_pagealloc); diff --git a/include/linux/iommu-debug.h b/include/linux/iommu-debug.h new file mode 100644 index 000000000000..a9c11855c4ed --- /dev/null +++ b/include/linux/iommu-debug.h @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2025 - Google Inc + * Author: Mostafa Saleh + * IOMMU API santaizers and debug + */ + +#ifndef __LINUX_IOMMU_DEBUG_H +#define __LINUX_IOMMU_DEBUG_H + +#ifdef CONFIG_IOMMU_DEBUG_PAGEALLOC + +extern struct page_ext_operations page_iommu_debug_ops; + +#endif /* CONFIG_IOMMU_DEBUG_PAGEALLOC */ + +#endif /* __LINUX_IOMMU_DEBUG_H */ diff --git a/mm/page_ext.c b/mm/page_ext.c index d7396a8970e5..37c764a55a0f 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -11,6 +11,7 @@ #include #include #include +#include =20 /* * struct page extension @@ -89,6 +90,9 @@ static struct page_ext_operations *page_ext_ops[] __initd= ata =3D { #ifdef CONFIG_PAGE_TABLE_CHECK &page_table_check_ops, #endif +#ifdef CONFIG_IOMMU_DEBUG_PAGEALLOC + &page_iommu_debug_ops, +#endif }; =20 unsigned long page_ext_size; --=20 2.51.0.618.g983fd99d29-goog From nobody Wed Dec 17 17:45:10 2025 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 DA4F32DAFA9 for ; Fri, 3 Oct 2025 17:32:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759512772; cv=none; b=UVPPBG5bOS7jV9gurfwg3Gb/BsLcs6AdZ9nf6+XhVb6D+Ts/HuXw1wuhYX7lJ0D7/iX4BTifr2oCvrvDULh/xp5aMYmomDIXQ04Zn1QnK2wCXfc5u4eVZNfKJdIRbR4OzK+pRv1luVhG40/1XkwCzg7j9V0t1h76z5+dWJ3GzgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759512772; c=relaxed/simple; bh=h8HRZAYE3mjXSc5Xyx6cIjeKK3BF7I4Fd5OR1DdLMiY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ric8rQkUBPt6l4F8alkaHenuUvySryvquI/b1D9GkpeYjDxFaMB2XGMbSCvxwmCIxEBo2yB408ENbJHPSG3Z0EW1W6dsxXg9NNq+b3T1Ey3gYqNb0PHbSL+d7n4eHJpQr483OB24V1zzYbMdUsOWd1P92mtX3C8sTPV9sxKUcZg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=RipcE+HB; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RipcE+HB" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-46e44b9779eso10258725e9.1 for ; Fri, 03 Oct 2025 10:32:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759512767; x=1760117567; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=MSJf223vDYvCAejMgpz8FoiY2GVLX/OUVEV8AW8P3rE=; b=RipcE+HBunm1LAWdVy/tQHlnskUKKlmTsX3e7PrCC5gslRSMr1iKOaRRFi2bcS7eV2 ZJz69qcrahzXrEJJWH0rE1YYT8ryA9+dm5//pC19fUfGl4AmKhwMP3E9J1FcFk7oEsRF eqrDhQO5DNRtb8OrkjYVONTgC94d/xNZx/1OGXJFNwSIPMt2SKgYeavfZCL6GtQs1Ytd NnA6yJLpUhuPpiHmkJYaLTTn1sCbI22YJ6CK3mXEmw77oplJJEV1E8fLl0Tf4W/bCqgB 41/CrLUtp6ZLwFntaQ6znQV90US4xxJs2o9xCXRmO+1MpBX+hyyT4KumXTrSgzGRla67 kTDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759512767; x=1760117567; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MSJf223vDYvCAejMgpz8FoiY2GVLX/OUVEV8AW8P3rE=; b=m/B9f1MpaGeTwI9igopfuBP8cvDfvObWZKEHohKBKAMWUIcm3TQIKQ74ppvaQqYsnx FI/rMimHcqISwwumIqH52GHw87DGFkWa3AF0uuGS6hcI47+6RJzbqX2wPd/LRbwtELnV 0c4Urtc16Ox1NInftGhS1Ny22xVdjknoUQKnwHra5YLir5kSgt02h8ezgIqYoIYkE/de JHcy2UeY4GeY86FJmUT+fqglPFyg/bTITBktpe6Eu1N2v6Vw7AxT0oo+AW2dSAThAnaB nxgtxYMRTYKvMMWaWCv3rUqip12zYqDu0syyZA9rE74tVwfQS/KoMi85E5nEtlhIWLiS DCkw== X-Forwarded-Encrypted: i=1; AJvYcCVRqI9LW5R+ISKyeaZS++odTjF60USqgKbBcTzJUo+9Kf7nVeQEqGrXvJak5B/W1I4wZbNcU/dbZnZLUYA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4Oh/+a75KPWi6Oixe7fRWKS6wgJaHiiyC4eoYhB3v0ISQc8ui atZrxpnt5UEmsB5iR2/UdJY1negcUQhzjEiahtl6L8YgsSkC+LE2dHaXnRDQl+ithnqeCUy9Uip YkExgORRRNsxH9A== X-Google-Smtp-Source: AGHT+IEWfYLAMSMP+OGgRaTAc1dXj7/wh5+WqknFdRddjMd1FN58CkXD5Dr6K3xA5OvV0fh2LeDAOUQkcNX7zw== X-Received: from wmna4.prod.google.com ([2002:a05:600c:684:b0:46d:6939:1b46]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:37c9:b0:46e:4341:7302 with SMTP id 5b1f17b1804b1-46e71155b8cmr26105425e9.34.1759512767276; Fri, 03 Oct 2025 10:32:47 -0700 (PDT) Date: Fri, 3 Oct 2025 17:32:27 +0000 In-Reply-To: <20251003173229.1533640-1-smostafa@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251003173229.1533640-1-smostafa@google.com> X-Mailer: git-send-email 2.51.0.618.g983fd99d29-goog Message-ID: <20251003173229.1533640-3-smostafa@google.com> Subject: [RFC PATCH 2/4] drivers/iommu: Add calls for iommu debug From: Mostafa Saleh To: linux-mm@kvack.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: corbet@lwn.net, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, akpm@linux-foundation.org, vbabka@suse.cz, surenb@google.com, mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com, david@redhat.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, rppt@kernel.org, Mostafa Saleh Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add calls for the new iommu debug config IOMMU_DEBUG_PAGEALLOC: - iommu_debug_init: Enable the debug mode if configured by the user. - iommu_debug_map: Track iommu pages mapped, using physical address. - iommu_debug_unmap: Track iommu pages unmapped, using IO virtual address. - iommu_debug_remap: Track iommu pages, already mapped using IOVA. We have to do the unmap/remap as once pages are unmapped we lose the information of the physical address. This is racy, but the API is racy by construction as it uses refcounts and doesn't attempt to lock/synchronize with the IOMMU API as that will be costly, meaning that possibility of false negative exists. Signed-off-by: Mostafa Saleh Tested-by: Qinxin Xia --- drivers/iommu/iommu-debug.c | 23 +++++++++++++++++++++++ drivers/iommu/iommu.c | 21 +++++++++++++++++++-- include/linux/iommu-debug.h | 6 ++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/iommu-debug.c b/drivers/iommu/iommu-debug.c index 297a35137b38..607f1fcf2235 100644 --- a/drivers/iommu/iommu-debug.c +++ b/drivers/iommu/iommu-debug.c @@ -5,11 +5,13 @@ * IOMMU API santaizers and debug */ #include +#include #include #include #include =20 static bool needed; +static DEFINE_STATIC_KEY_FALSE(iommu_debug_initialized); =20 struct iommu_debug_metadate { atomic_t ref; @@ -25,6 +27,27 @@ struct page_ext_operations page_iommu_debug_ops =3D { .need =3D need_iommu_debug, }; =20 +void iommu_debug_map(struct iommu_domain *domain, phys_addr_t phys, size_t= size) +{ +} + +void iommu_debug_unmap(struct iommu_domain *domain, unsigned long iova, si= ze_t size) +{ +} + +void iommu_debug_remap(struct iommu_domain *domain, unsigned long iova, si= ze_t size) +{ +} + +void iommu_debug_init(void) +{ + if (!needed) + return; + + pr_info("iommu: Debugging page allocations, expect overhead or disable io= mmu.debug_pagealloc"); + static_branch_enable(&iommu_debug_initialized); +} + static int __init iommu_debug_pagealloc(char *str) { return kstrtobool(str, &needed); diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 060ebe330ee1..56c89636a33c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -231,6 +232,9 @@ static int __init iommu_subsys_init(void) if (!nb) return -ENOMEM; =20 +#ifdef CONFIG_IOMMU_DEBUG_PAGEALLOC + iommu_debug_init(); +#endif for (int i =3D 0; i < ARRAY_SIZE(iommu_buses); i++) { nb[i].notifier_call =3D iommu_bus_notifier; bus_register_notifier(iommu_buses[i], &nb[i]); @@ -2518,10 +2522,14 @@ int iommu_map_nosync(struct iommu_domain *domain, u= nsigned long iova, } =20 /* unroll mapping in case something went wrong */ - if (ret) + if (ret) { iommu_unmap(domain, orig_iova, orig_size - size); - else + } else { trace_map(orig_iova, orig_paddr, orig_size); +#ifdef CONFIG_IOMMU_DEBUG_PAGEALLOC + iommu_debug_map(domain, orig_paddr, orig_size); +#endif + } =20 return ret; } @@ -2583,6 +2591,10 @@ static size_t __iommu_unmap(struct iommu_domain *dom= ain, =20 pr_debug("unmap this: iova 0x%lx size 0x%zx\n", iova, size); =20 +#ifdef CONFIG_IOMMU_DEBUG_PAGEALLOC + iommu_debug_unmap(domain, iova, size); +#endif + /* * Keep iterating until we either unmap 'size' bytes (or more) * or we hit an area that isn't mapped. @@ -2602,6 +2614,11 @@ static size_t __iommu_unmap(struct iommu_domain *dom= ain, unmapped +=3D unmapped_page; } =20 +#ifdef CONFIG_IOMMU_DEBUG_PAGEALLOC + if (unmapped < size) + iommu_debug_remap(domain, iova, size - unmapped); +#endif + trace_unmap(orig_iova, size, unmapped); return unmapped; } diff --git a/include/linux/iommu-debug.h b/include/linux/iommu-debug.h index a9c11855c4ed..8d3ea661660f 100644 --- a/include/linux/iommu-debug.h +++ b/include/linux/iommu-debug.h @@ -11,6 +11,12 @@ #ifdef CONFIG_IOMMU_DEBUG_PAGEALLOC =20 extern struct page_ext_operations page_iommu_debug_ops; +struct iommu_domain; + +void iommu_debug_map(struct iommu_domain *domain, phys_addr_t phys, size_t= size); +void iommu_debug_unmap(struct iommu_domain *domain, unsigned long iova, si= ze_t size); +void iommu_debug_remap(struct iommu_domain *domain, unsigned long iova, si= ze_t size); +void iommu_debug_init(void); =20 #endif /* CONFIG_IOMMU_DEBUG_PAGEALLOC */ =20 --=20 2.51.0.618.g983fd99d29-goog From nobody Wed Dec 17 17:45:10 2025 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 444CC2DC335 for ; Fri, 3 Oct 2025 17:32:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759512772; cv=none; b=U2/Yqy/QToTeO7Dals41jTchVH27HAqznPAjMYsouV846k3r7fgCTvVWvPyMEieqFFryBf9jGS+6D/5ylqeJRRngfsV40cUeRkyDw5Gj14y4/1Au8xkBXi1/F7twkjn8Pli+euGjeYnR82iyuJrmRLDVjx2ni4Xf9BGL2fhsgtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759512772; c=relaxed/simple; bh=yI6VMn+rJIop9uglbD/KsbP7syNK0e5JT3wJcuKCcIc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KCx28hNmXOdvFSBzOhBi+/VpY5i/+PSEAg2UssNIrtYL9qVL9Kk9w7/cdb866Vw43v62Pk5KcL/DmVEZYwi7ZN9kndG1TNpGCXsXg/JVWvG3wRFgfetsCceC3mbyDQ8MH624lkEdYcfe5rBCuemyhPyQDcx6d2Zg8f+0c/omXNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yUuZG1AP; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yUuZG1AP" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-46e4943d713so18227735e9.1 for ; Fri, 03 Oct 2025 10:32:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759512768; x=1760117568; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=AgDVF0Sn62dc4Fy33aQ885t/YxSjHp9XC3s20FTM60M=; b=yUuZG1AP+P1tvwByN5zKPtBVgY1tEx/0R9eeo74TwaVAFRiB8JTv6HUtmLjempE93O vTVKVASwjtJUbZEuyA+Rvtvq9zsEx2WhY9LqS8+GefZvNhOcaqB3Oebkf09zz8aiJ1lK tbIK542vK0W1gi90ujvg4sLQz7yb83KySy9sFPGxQPvrrU0TTi7Zn2EdfCyOj3/veE46 WRMzNyX/Bg0tpmc5ZX8YByMJzesoIKEmbSyCyHWH4mK+XB/LaeMBiigZMDpcSdXvoogV LQdP7Z13q2/lAO3QSQUcMbPUIdXVzT42PYfwLQmV7lqQZRKCx+kDFa+ae/2+k5XGLMeq VezA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759512768; x=1760117568; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AgDVF0Sn62dc4Fy33aQ885t/YxSjHp9XC3s20FTM60M=; b=f67xcmJSci7WYyptk/X7Rj8WxCGViYUbXFvNlfTMQo4pBrcoEeGJke4JU0vSy55Fmf M+8qZ3jfq8RVLaKwRmmlWYzzs9Rcixbi732SdjBFCUlrWGa7ghyt5hFZsEQ0uicuDxTJ hEEuhe7Cr3y8kXTgJpJWmtRC1zwfqP+XkoGFXck5p7jCsK1bKJ2fLgkiCKJLdNrhIL4P yQXvR3h6klXnB/+MZG7ZJTpMWdOjLHF5yDqhBYkg9/znEeeaGznOr/FtEo47DtxFNn59 2IEb8k/YVrGXRVsFFZ4ONOvK/U4RqVQHuJjog/QOKerjr2EBcxTSkMX0w23ajspnzgpw bOoQ== X-Forwarded-Encrypted: i=1; AJvYcCURjYwzwv3x+inW6IjW7PpRY4uTz6yJoXDZF77XdNQPoz38AfKN2LdN6ol+FrcjbpCL4vt+1OgnkjMpt0g=@vger.kernel.org X-Gm-Message-State: AOJu0YwYtLad5iS6+UrrP5ySF0UHE4MJVejoriUPj4PbSbG1z3gYGmXE GQdH02X0XSti9bP1CW4Gj8V0D2Ng3J7vvCENno/U20VcK/2pE5VuZinoLC+T3lJ1BD8Qil5P84+ ik5RhOtdc/lAV+Q== X-Google-Smtp-Source: AGHT+IE28Cn+D6RTRtX91pYwDnd5zfpJjbOEGfORhMIoLTvvcoagejiT2Mcgwr5tybnnq3WA/m4ZzUqRkVc5Cw== X-Received: from wmcn6.prod.google.com ([2002:a05:600c:c0c6:b0:45d:d522:48a9]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:8115:b0:46e:3b81:c3f9 with SMTP id 5b1f17b1804b1-46e71143012mr33226465e9.17.1759512768358; Fri, 03 Oct 2025 10:32:48 -0700 (PDT) Date: Fri, 3 Oct 2025 17:32:28 +0000 In-Reply-To: <20251003173229.1533640-1-smostafa@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251003173229.1533640-1-smostafa@google.com> X-Mailer: git-send-email 2.51.0.618.g983fd99d29-goog Message-ID: <20251003173229.1533640-4-smostafa@google.com> Subject: [RFC PATCH 3/4] drivers/iommu-debug: Track IOMMU pages From: Mostafa Saleh To: linux-mm@kvack.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: corbet@lwn.net, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, akpm@linux-foundation.org, vbabka@suse.cz, surenb@google.com, mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com, david@redhat.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, rppt@kernel.org, Mostafa Saleh Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Using the new calls use an atomic refcount to track how many times a page is mapped in any of the IOMMUs. For unmap we need to use iova_to_phys() to get the physical address of the pages. We use the smallest supported page size as the granularity of tracking per domain. This is important as it possible to map pages and unmap them with larger sizes (as in map_sg()) cases. Signed-off-by: Mostafa Saleh Tested-by: Qinxin Xia --- drivers/iommu/iommu-debug.c | 83 +++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/drivers/iommu/iommu-debug.c b/drivers/iommu/iommu-debug.c index 607f1fcf2235..cec8f594c7fa 100644 --- a/drivers/iommu/iommu-debug.c +++ b/drivers/iommu/iommu-debug.c @@ -27,16 +27,99 @@ struct page_ext_operations page_iommu_debug_ops =3D { .need =3D need_iommu_debug, }; =20 +static struct page_ext *get_iommu_page_ext(phys_addr_t phys) +{ + struct page *page =3D phys_to_page(phys); + struct page_ext *page_ext =3D page_ext_get(page); + + return page_ext; +} + +static struct iommu_debug_metadate *get_iommu_data(struct page_ext *page_e= xt) +{ + return page_ext_data(page_ext, &page_iommu_debug_ops); +} + +static void iommu_debug_inc_page(phys_addr_t phys) +{ + struct page_ext *page_ext =3D get_iommu_page_ext(phys); + struct iommu_debug_metadate *d =3D get_iommu_data(page_ext); + + WARN_ON(atomic_inc_return(&d->ref) <=3D 0); + page_ext_put(page_ext); +} + +static void iommu_debug_dec_page(phys_addr_t phys) +{ + struct page_ext *page_ext =3D get_iommu_page_ext(phys); + struct iommu_debug_metadate *d =3D get_iommu_data(page_ext); + + WARN_ON(atomic_dec_return(&d->ref) < 0); + page_ext_put(page_ext); +} + +/* + * IOMMU pages size might not match the CPU page size, in that case, we use + * the smallest IOMMU page size to refcount the pages in the vmemap. + * That's is important as both map and unmap has to use the same page size + * to update the refcount to avoid double counting the same page. + * And as we can't know from iommu_unmap() what was the original page size + * used for map, we just use the minimum supported one for both. + */ +static size_t iommu_debug_page_size(struct iommu_domain *domain) +{ + return 1UL << __ffs(domain->pgsize_bitmap); +} + void iommu_debug_map(struct iommu_domain *domain, phys_addr_t phys, size_t= size) { + size_t off; + size_t page_size =3D iommu_debug_page_size(domain); + + if (!static_branch_likely(&iommu_debug_initialized)) + return; + + for (off =3D 0 ; off < size ; off +=3D page_size) { + if (!pfn_valid(__phys_to_pfn(phys + off))) + continue; + iommu_debug_inc_page(phys + off); + } } =20 void iommu_debug_unmap(struct iommu_domain *domain, unsigned long iova, si= ze_t size) { + size_t off; + size_t page_size =3D iommu_debug_page_size(domain); + + if (!static_branch_likely(&iommu_debug_initialized)) + return; + + for (off =3D 0 ; off < size ; off +=3D page_size) { + phys_addr_t phys =3D iommu_iova_to_phys(domain, iova + off); + + if (!phys || !pfn_valid(__phys_to_pfn(phys + off))) + continue; + + iommu_debug_dec_page(phys); + } } =20 void iommu_debug_remap(struct iommu_domain *domain, unsigned long iova, si= ze_t size) { + size_t off; + size_t page_size =3D iommu_debug_page_size(domain); + + if (!static_branch_likely(&iommu_debug_initialized)) + return; + + for (off =3D 0 ; off < size ; off +=3D page_size) { + phys_addr_t phys =3D iommu_iova_to_phys(domain, iova + off); + + if (!phys || !pfn_valid(__phys_to_pfn(phys + off))) + continue; + + iommu_debug_inc_page(phys); + } } =20 void iommu_debug_init(void) --=20 2.51.0.618.g983fd99d29-goog From nobody Wed Dec 17 17:45:10 2025 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) (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 7605A2DC773 for ; Fri, 3 Oct 2025 17:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759512773; cv=none; b=HyqssA6vNgyiB/gAGGI+G0Asw4JfBz2M6b/KuJwa3j7LJpufb12DVj6HyDRIxXlwOiATsl8FSMyBvhBc4zksr7qLJ3lJSIq27SHL9MI6wQpHJft7CL/uI0L+ni2lh9IvsOQs0VPrJXySfiX+ByNS6Y/AXAwAJwPepkaZk2dNbTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759512773; c=relaxed/simple; bh=Ppoa9QsZOoSTV+IPfX4/odA4ZuwL+h+gqoPsnDxPufY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AgVd6jnQ8jeS9OqkfCS+4DcFHbX4SSpdmxJssKcxfonrafAEjAXx/p8PPrDbn9nDtWEhY2IKh3LEfUBB7aDRhsYmgeKce7AeEKNTPhgKHxnWCFSLQEtNciDoOLkhwB8pzE6lZlW8Bawdo7iCHGDp54P1yX3dD4m9OWUEGAcDkP8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Y9xltinL; arc=none smtp.client-ip=209.85.208.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Y9xltinL" Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-6305c385adbso2706611a12.1 for ; Fri, 03 Oct 2025 10:32:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759512770; x=1760117570; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=rsO4Y9+CDsR/9B2sBMziOZN6BaFGbVnMznIuFrkfbBE=; b=Y9xltinLofTfplfLEyXdU9qcihyxyb7ymbBTzK6/kMb4aiA/G08AvuEwhE6ICg2sTW Ll84pC7Qgx0kfWzJEKfatH9O6TkDm/Y9N2YCQKAV7CLLpCFWG6oD7L7IF9gWnUrIdmPf fj9ZyU64wtmdHK7X3DpPlPRpqpMYLfWXKCTVxA11M5KH9n0DQnWX6qhzlnaw/672W3ED 2jHNznATssRuYlEcBDRBFTnN74OPdIM/7jDMTbtxJpuvmqJBzmlmmN8nyX0fHZKESNq9 lctm3veeqx+xRrf9rNvPjeylCmJh9eViA4JnNA6CE5E9UZdzqGe11DxOknKWXfp2kAY1 3Ogw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759512770; x=1760117570; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=rsO4Y9+CDsR/9B2sBMziOZN6BaFGbVnMznIuFrkfbBE=; b=EABXCIRSl2pvRtI0A4ap/m3esyKN56Q9WAYYWlVaGNGrPACjrDirSXp2d4I5omQpTY qjvd+rDQBNGbdqXhb4Gk4Q24GoDZ0SJreOfFCerm2vyTHwqX0z3LEbgnSWa9ZGwvXJ9u TyYYcspuGa36se/NvN5X1bbWmgVexffb4Yl0yE/VWosPznFz02CdjPmhbCXbXyLzpHuw tZW7zrbuoIyQdLw46WrzVRqrQvyfY4kHelvU/7bzWZZ0x9k7xq8TLcIiPAYFewzkiam4 nrLgS35dNFEVbBXeZ7QTASWAfd6hmv95q6F/KYArWZRzYlyPHXdOLrpOdJfCppkzXccs 978Q== X-Forwarded-Encrypted: i=1; AJvYcCV3QQ3cKXPegW/SNl/R5hUVa+lXaEO+PJdakAMWmOmiEZsVG/kh44Klhq7Y/RFqs+SwJeppavsiiBjihlg=@vger.kernel.org X-Gm-Message-State: AOJu0YxN47UZo6vxmZe13XAOP2yJAS1qOnkxucVCvkDpML+BLYdlkCeb vw+KI7kEJGcBKfMTBPiM7cP1Rde5C01/TBGDOP1v26qGFHI8PTzWFk0PHF7zr/w90/eYp+VYKUg OOtytrUe4681tvg== X-Google-Smtp-Source: AGHT+IEICQMptfCkkk6D3e73QyAc9gpdDen9PXr6jWCu1S1AfhHO09M/A91ku8VJ/Ju4zq0R9Vac76YEgDbAjg== X-Received: from edqm10.prod.google.com ([2002:aa7:c48a:0:b0:636:871c:c865]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:3508:b0:639:102b:b8db with SMTP id 4fb4d7f45d1cf-63939c20419mr3602021a12.24.1759512769531; Fri, 03 Oct 2025 10:32:49 -0700 (PDT) Date: Fri, 3 Oct 2025 17:32:29 +0000 In-Reply-To: <20251003173229.1533640-1-smostafa@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251003173229.1533640-1-smostafa@google.com> X-Mailer: git-send-email 2.51.0.618.g983fd99d29-goog Message-ID: <20251003173229.1533640-5-smostafa@google.com> Subject: [RFC PATCH 4/4] drivers/iommu-debug: Check state of mapped/unmapped kernel memory From: Mostafa Saleh To: linux-mm@kvack.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: corbet@lwn.net, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, akpm@linux-foundation.org, vbabka@suse.cz, surenb@google.com, mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com, david@redhat.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, rppt@kernel.org, Mostafa Saleh Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now, as the page_ext holds count of IOMMU mappings, we can use it to assert that any page allocated/freed is indeed not in the IOMMU. The sanitizer doesn=E2=80=99t protect against mapping/unmapping during this period. However, that=E2=80=99s less harmful as the page is not used by the kernel. Signed-off-by: Mostafa Saleh Tested-by: Qinxin Xia --- drivers/iommu/iommu-debug.c | 22 ++++++++++++++++++++++ include/linux/iommu-debug.h | 1 + include/linux/mm.h | 7 +++++++ 3 files changed, 30 insertions(+) diff --git a/drivers/iommu/iommu-debug.c b/drivers/iommu/iommu-debug.c index cec8f594c7fa..09157fef697e 100644 --- a/drivers/iommu/iommu-debug.c +++ b/drivers/iommu/iommu-debug.c @@ -71,6 +71,28 @@ static size_t iommu_debug_page_size(struct iommu_domain = *domain) return 1UL << __ffs(domain->pgsize_bitmap); } =20 +static unsigned int iommu_debug_page_count(unsigned long phys) +{ + unsigned int ref; + struct page_ext *page_ext =3D get_iommu_page_ext(phys); + struct iommu_debug_metadate *d =3D get_iommu_data(page_ext); + + ref =3D atomic_read(&d->ref); + page_ext_put(page_ext); + return ref; +} + +void iommu_debug_check_unmapped(const struct page *page, int numpages) +{ + if (!static_branch_likely(&iommu_debug_initialized)) + return; + + while (numpages--) { + WARN_ON(iommu_debug_page_count(page_to_phys(page))); + page++; + } +} + void iommu_debug_map(struct iommu_domain *domain, phys_addr_t phys, size_t= size) { size_t off; diff --git a/include/linux/iommu-debug.h b/include/linux/iommu-debug.h index 8d3ea661660f..aaf893cfafd0 100644 --- a/include/linux/iommu-debug.h +++ b/include/linux/iommu-debug.h @@ -17,6 +17,7 @@ void iommu_debug_map(struct iommu_domain *domain, phys_ad= dr_t phys, size_t size) void iommu_debug_unmap(struct iommu_domain *domain, unsigned long iova, si= ze_t size); void iommu_debug_remap(struct iommu_domain *domain, unsigned long iova, si= ze_t size); void iommu_debug_init(void); +void iommu_debug_check_unmapped(const struct page *page, int numpages); =20 #endif /* CONFIG_IOMMU_DEBUG_PAGEALLOC */ =20 diff --git a/include/linux/mm.h b/include/linux/mm.h index 06978b4dbeb8..00f5de44faa0 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -36,6 +36,7 @@ #include #include #include +#include =20 struct mempolicy; struct anon_vma; @@ -3806,12 +3807,18 @@ extern void __kernel_map_pages(struct page *page, i= nt numpages, int enable); #ifdef CONFIG_DEBUG_PAGEALLOC static inline void debug_pagealloc_map_pages(struct page *page, int numpag= es) { +#ifdef CONFIG_IOMMU_DEBUG_PAGEALLOC + iommu_debug_check_unmapped(page, numpages); +#endif if (debug_pagealloc_enabled_static()) __kernel_map_pages(page, numpages, 1); } =20 static inline void debug_pagealloc_unmap_pages(struct page *page, int nump= ages) { +#ifdef CONFIG_IOMMU_DEBUG_PAGEALLOC + iommu_debug_check_unmapped(page, numpages); +#endif if (debug_pagealloc_enabled_static()) __kernel_map_pages(page, numpages, 0); } --=20 2.51.0.618.g983fd99d29-goog