syzbot


ID Workflow Result Correct Bug Created Started Finished Revision Error
87894511-0453-4318-be55-535061d610f0 assessment-security DenialOfService: ✅ Exploitable: ✅ FilesystemTrigger: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ kernel BUG in __page_table_check_zero (3) 2026/05/24 23:27 2026/05/24 23:27 2026/05/25 00:58 c69befb30ac10e158cc9d1557b508ee3f0eca1de

			
		
Agent: prod-syz-agent-0
External Bug ID: ---

Inputs:
BaseBranch master
BaseCommit RC
BaseRepository git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
BugTitle kernel BUG in __page_table_check_zero
CrashLogID 5397530289897472
CrashReportID 4667963401043968
KernelCommit 0ca1724b56af054e304a9f3f60623b02a81aba3f
KernelConfig
Show (234657 bytes)
#
# Automatically generated file; DO NOT EDIT.
# Linux/riscv syzkaller Kernel Configuration
#
CONFIG_CC_VERSION_TEXT="riscv64-linux-gnu-gcc (Debian 14.2.0-19) 14.2.0"
CONFIG_CC_IS_GCC=y
CONFIG_GCC_VERSION=140200
CONFIG_CLANG_VERSION=0
CONFIG_AS_IS_GNU=y
CONFIG_AS_VERSION=24400
CONFIG_LD_IS_BFD=y
CONFIG_LD_VERSION=24400
CONFIG_LLD_VERSION=0
CONFIG_RUSTC_VERSION=109101
CONFIG_RUST_IS_AVAILABLE=y
CONFIG_RUSTC_LLVM_VERSION=210102
CONFIG_RUSTC_LLVM_MAJOR_VERSION=21
CONFIG_ARCH_HAS_CC_CAN_LINK=y
CONFIG_CC_CAN_LINK=y
CONFIG_CC_HAS_ASM_GOTO_OUTPUT=y
CONFIG_CC_HAS_ASM_GOTO_TIED_OUTPUT=y
CONFIG_CC_HAS_ASM_INLINE=y
CONFIG_CC_HAS_ASSUME=y
CONFIG_CC_HAS_NO_PROFILE_FN_ATTR=y
CONFIG_LD_CAN_USE_KEEP_IN_OVERLAY=y
CONFIG_RUSTC_HAS_SPAN_FILE=y
CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES=y
CONFIG_RUSTC_HAS_FILE_WITH_NUL=y
CONFIG_RUSTC_HAS_FILE_AS_C_STR=y
CONFIG_PAHOLE_VERSION=130
CONFIG_CONSTRUCTORS=y
CONFIG_IRQ_WORK=y
CONFIG_BUILDTIME_TABLE_SORT=y
CONFIG_THREAD_INFO_IN_TASK=y

#
# General setup
#
CONFIG_INIT_ENV_ARG_LIMIT=32
# CONFIG_COMPILE_TEST is not set
# CONFIG_WERROR is not set
CONFIG_LOCALVERSION=""
CONFIG_LOCALVERSION_AUTO=y
CONFIG_BUILD_SALT=""
CONFIG_HAVE_KERNEL_GZIP=y
CONFIG_HAVE_KERNEL_BZIP2=y
CONFIG_HAVE_KERNEL_LZMA=y
CONFIG_HAVE_KERNEL_XZ=y
CONFIG_HAVE_KERNEL_LZO=y
CONFIG_HAVE_KERNEL_LZ4=y
CONFIG_HAVE_KERNEL_ZSTD=y
CONFIG_HAVE_KERNEL_UNCOMPRESSED=y
CONFIG_KERNEL_GZIP=y
# CONFIG_KERNEL_BZIP2 is not set
# CONFIG_KERNEL_LZMA is not set
# CONFIG_KERNEL_XZ is not set
# CONFIG_KERNEL_LZO is not set
# CONFIG_KERNEL_LZ4 is not set
# CONFIG_KERNEL_ZSTD is not set
# CONFIG_KERNEL_UNCOMPRESSED is not set
CONFIG_DEFAULT_INIT=""
CONFIG_DEFAULT_HOSTNAME="(none)"
CONFIG_SYSVIPC=y
CONFIG_SYSVIPC_SYSCTL=y
CONFIG_SYSVIPC_COMPAT=y
CONFIG_POSIX_MQUEUE=y
CONFIG_POSIX_MQUEUE_SYSCTL=y
CONFIG_WATCH_QUEUE=y
CONFIG_CROSS_MEMORY_ATTACH=y
CONFIG_AUDIT=y
CONFIG_HAVE_ARCH_AUDITSYSCALL=y
CONFIG_AUDITSYSCALL=y

#
# IRQ subsystem
#
CONFIG_GENERIC_IRQ_SHOW=y
CONFIG_GENERIC_IRQ_SHOW_LEVEL=y
CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK=y
CONFIG_GENERIC_PENDING_IRQ=y
CONFIG_GENERIC_IRQ_MIGRATION=y
CONFIG_HARDIRQS_SW_RESEND=y
CONFIG_IRQ_DOMAIN=y
CONFIG_IRQ_DOMAIN_HIERARCHY=y
CONFIG_GENERIC_IRQ_IPI=y
CONFIG_GENERIC_IRQ_IPI_MUX=y
CONFIG_GENERIC_MSI_IRQ=y
CONFIG_GENERIC_IRQ_MATRIX_ALLOCATOR=y
CONFIG_IRQ_FORCED_THREADING=y
CONFIG_SPARSE_IRQ=y
# CONFIG_GENERIC_IRQ_DEBUGFS is not set
# end of IRQ subsystem

CONFIG_GENERIC_IRQ_MULTI_HANDLER=y
CONFIG_GENERIC_TIME_VSYSCALL=y
CONFIG_GENERIC_CLOCKEVENTS=y
CONFIG_ARCH_HAS_TICK_BROADCAST=y
CONFIG_GENERIC_CLOCKEVENTS_BROADCAST=y
CONFIG_HRTIMER_REARM_DEFERRED=y
CONFIG_HAVE_POSIX_CPU_TIMERS_TASK_WORK=y
CONFIG_POSIX_CPU_TIMERS_TASK_WORK=y
CONFIG_CONTEXT_TRACKING=y
CONFIG_CONTEXT_TRACKING_IDLE=y

#
# Timers subsystem
#
CONFIG_TICK_ONESHOT=y
CONFIG_NO_HZ_COMMON=y
# CONFIG_HZ_PERIODIC is not set
CONFIG_NO_HZ_IDLE=y
# CONFIG_NO_HZ_FULL is not set
CONFIG_CONTEXT_TRACKING_USER=y
# CONFIG_CONTEXT_TRACKING_USER_FORCE is not set
CONFIG_NO_HZ=y
CONFIG_HIGH_RES_TIMERS=y
CONFIG_POSIX_AUX_CLOCKS=y
# end of Timers subsystem

CONFIG_BPF=y
CONFIG_HAVE_EBPF_JIT=y

#
# BPF subsystem
#
CONFIG_BPF_SYSCALL=y
CONFIG_BPF_JIT=y
CONFIG_BPF_JIT_ALWAYS_ON=y
CONFIG_BPF_JIT_DEFAULT_ON=y
CONFIG_BPF_UNPRIV_DEFAULT_OFF=y
# CONFIG_BPF_PRELOAD is not set
CONFIG_BPF_LSM=y
# end of BPF subsystem

CONFIG_PREEMPT_BUILD=y
CONFIG_ARCH_HAS_PREEMPT_LAZY=y
CONFIG_PREEMPT=y
# CONFIG_PREEMPT_LAZY is not set
# CONFIG_PREEMPT_RT is not set
CONFIG_PREEMPT_COUNT=y
CONFIG_PREEMPTION=y
# CONFIG_PREEMPT_DYNAMIC is not set

#
# CPU/Task time and stats accounting
#
CONFIG_VIRT_CPU_ACCOUNTING=y
# CONFIG_TICK_CPU_ACCOUNTING is not set
CONFIG_VIRT_CPU_ACCOUNTING_GEN=y
# CONFIG_IRQ_TIME_ACCOUNTING is not set
CONFIG_BSD_PROCESS_ACCT=y
CONFIG_BSD_PROCESS_ACCT_V3=y
CONFIG_TASKSTATS=y
# CONFIG_TASK_DELAY_ACCT is not set
CONFIG_TASK_XACCT=y
CONFIG_TASK_IO_ACCOUNTING=y
CONFIG_PSI=y
# CONFIG_PSI_DEFAULT_DISABLED is not set
# end of CPU/Task time and stats accounting

CONFIG_CPU_ISOLATION=y

#
# RCU Subsystem
#
CONFIG_TREE_RCU=y
CONFIG_PREEMPT_RCU=y
# CONFIG_RCU_EXPERT is not set
CONFIG_TREE_SRCU=y
CONFIG_TASKS_RCU_GENERIC=y
CONFIG_NEED_TASKS_RCU=y
CONFIG_TASKS_RCU=y
CONFIG_TASKS_TRACE_RCU=y
CONFIG_RCU_STALL_COMMON=y
CONFIG_RCU_NEED_SEGCBLIST=y
# end of RCU Subsystem

CONFIG_IKCONFIG=y
CONFIG_IKCONFIG_PROC=y
# CONFIG_IKHEADERS is not set
CONFIG_LOG_BUF_SHIFT=18
CONFIG_LOG_CPU_MAX_BUF_SHIFT=12
# CONFIG_PRINTK_INDEX is not set
CONFIG_GENERIC_SCHED_CLOCK=y

#
# Scheduler features
#
# CONFIG_SCHED_PROXY_EXEC is not set
# end of Scheduler features

CONFIG_ARCH_SUPPORTS_NUMA_BALANCING=y
CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH=y
CONFIG_CC_HAS_INT128=y
CONFIG_CC_IMPLICIT_FALLTHROUGH="-Wimplicit-fallthrough=5"
CONFIG_CC_MS_EXTENSIONS="-fms-extensions"
CONFIG_GCC10_NO_ARRAY_BOUNDS=y
CONFIG_CC_NO_ARRAY_BOUNDS=y
CONFIG_GCC_NO_STRINGOP_OVERFLOW=y
CONFIG_CC_NO_STRINGOP_OVERFLOW=y
CONFIG_ARCH_SUPPORTS_INT128=y
CONFIG_NUMA_BALANCING=y
CONFIG_NUMA_BALANCING_DEFAULT_ENABLED=y
CONFIG_SLAB_OBJ_EXT=y
CONFIG_CGROUPS=y
CONFIG_PAGE_COUNTER=y
# CONFIG_CGROUP_FAVOR_DYNMODS is not set
CONFIG_MEMCG=y
CONFIG_MEMCG_V1=y
CONFIG_BLK_CGROUP=y
CONFIG_CGROUP_WRITEBACK=y
CONFIG_CGROUP_SCHED=y
CONFIG_GROUP_SCHED_WEIGHT=y
CONFIG_GROUP_SCHED_BANDWIDTH=y
CONFIG_FAIR_GROUP_SCHED=y
CONFIG_CFS_BANDWIDTH=y
# CONFIG_RT_GROUP_SCHED is not set
CONFIG_SCHED_MM_CID=y
CONFIG_CGROUP_PIDS=y
CONFIG_CGROUP_RDMA=y
# CONFIG_CGROUP_DMEM is not set
CONFIG_CGROUP_FREEZER=y
CONFIG_CGROUP_HUGETLB=y
CONFIG_CPUSETS=y
# CONFIG_CPUSETS_V1 is not set
CONFIG_CGROUP_DEVICE=y
CONFIG_CGROUP_CPUACCT=y
CONFIG_CGROUP_PERF=y
CONFIG_CGROUP_BPF=y
# CONFIG_CGROUP_MISC is not set
# CONFIG_CGROUP_DEBUG is not set
CONFIG_SOCK_CGROUP_DATA=y
CONFIG_NAMESPACES=y
CONFIG_UTS_NS=y
CONFIG_TIME_NS=y
CONFIG_TIME_NS_VDSO=y
CONFIG_IPC_NS=y
CONFIG_USER_NS=y
CONFIG_PID_NS=y
CONFIG_NET_NS=y
CONFIG_CHECKPOINT_RESTORE=y
# CONFIG_SCHED_AUTOGROUP is not set
# CONFIG_RELAY is not set
CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE=""
# CONFIG_INITRAMFS_FORCE is not set
CONFIG_RD_GZIP=y
CONFIG_RD_BZIP2=y
CONFIG_RD_LZMA=y
CONFIG_RD_XZ=y
CONFIG_RD_LZO=y
CONFIG_RD_LZ4=y
CONFIG_RD_ZSTD=y
# CONFIG_BOOT_CONFIG is not set
CONFIG_CMDLINE_LOG_WRAP_IDEAL_LEN=1021
CONFIG_INITRAMFS_PRESERVE_MTIME=y
CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y
# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION=y
# CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is not set
CONFIG_LD_ORPHAN_WARN=y
CONFIG_LD_ORPHAN_WARN_LEVEL="warn"
CONFIG_SYSCTL=y
CONFIG_SYSCTL_EXCEPTION_TRACE=y
CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW=y
CONFIG_SYSFS_SYSCALL=y
CONFIG_EXPERT=y
CONFIG_MULTIUSER=y
# CONFIG_SGETMASK_SYSCALL is not set
CONFIG_FHANDLE=y
CONFIG_POSIX_TIMERS=y
CONFIG_PRINTK=y
CONFIG_BUG=y
CONFIG_ELF_CORE=y
# CONFIG_BASE_SMALL is not set
CONFIG_FUTEX=y
CONFIG_FUTEX_PI=y
CONFIG_FUTEX_PRIVATE_HASH=y
CONFIG_FUTEX_MPOL=y
CONFIG_EPOLL=y
CONFIG_SIGNALFD=y
CONFIG_TIMERFD=y
CONFIG_EVENTFD=y
CONFIG_SHMEM=y
CONFIG_AIO=y
CONFIG_IO_URING=y
CONFIG_IO_URING_MOCK_FILE=y
CONFIG_ADVISE_SYSCALLS=y
CONFIG_MEMBARRIER=y
CONFIG_KCMP=y
CONFIG_RSEQ=y
# CONFIG_RSEQ_SLICE_EXTENSION is not set
# CONFIG_RSEQ_STATS is not set
# CONFIG_RSEQ_DEBUG_DEFAULT_ENABLE is not set
CONFIG_CACHESTAT_SYSCALL=y
CONFIG_KALLSYMS=y
# CONFIG_KALLSYMS_SELFTEST is not set
CONFIG_KALLSYMS_ALL=y
CONFIG_ARCH_HAS_MEMBARRIER_CALLBACKS=y
CONFIG_ARCH_HAS_MEMBARRIER_SYNC_CORE=y
CONFIG_ARCH_SUPPORTS_MSEAL_SYSTEM_MAPPINGS=y
CONFIG_HAVE_PERF_EVENTS=y
CONFIG_GUEST_PERF_EVENTS=y

#
# Kernel Performance Events And Counters
#
CONFIG_PERF_EVENTS=y
# CONFIG_DEBUG_PERF_USE_VMALLOC is not set
# end of Kernel Performance Events And Counters

CONFIG_SYSTEM_DATA_VERIFICATION=y
CONFIG_PROFILING=y
CONFIG_TRACEPOINTS=y

#
# Kexec and crash features
#
CONFIG_VMCORE_INFO=y
CONFIG_KEXEC_CORE=y
CONFIG_KEXEC=y
# CONFIG_KEXEC_FILE is not set
# CONFIG_CRASH_DUMP is not set
# end of Kexec and crash features

#
# Live Update and Kexec HandOver
#
# end of Live Update and Kexec HandOver
# end of General setup

CONFIG_64BIT=y
CONFIG_RISCV=y
CONFIG_RUSTC_SUPPORTS_RISCV=y
CONFIG_GCC_SUPPORTS_DYNAMIC_FTRACE=y
CONFIG_ARCH_MMAP_RND_BITS_MIN=18
CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MIN=8
CONFIG_ARCH_MMAP_RND_BITS_MAX=24
CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MAX=17
CONFIG_RISCV_SBI=y
CONFIG_MMU=y
CONFIG_KASAN_SHADOW_OFFSET=0xdfffffff00000000
CONFIG_ARCH_SPARSEMEM_ENABLE=y
CONFIG_ARCH_SELECT_MEMORY_MODEL=y
CONFIG_ARCH_SUPPORTS_UPROBES=y
CONFIG_STACKTRACE_SUPPORT=y
CONFIG_GENERIC_BUG=y
CONFIG_GENERIC_BUG_RELATIVE_POINTERS=y
CONFIG_GENERIC_CALIBRATE_DELAY=y
CONFIG_GENERIC_CSUM=y
CONFIG_GENERIC_HWEIGHT=y
CONFIG_FIX_EARLYCON_MEM=y
CONFIG_ILLEGAL_POINTER_VALUE=0xdead000000000000
CONFIG_PGTABLE_LEVELS=5
CONFIG_LOCKDEP_SUPPORT=y
CONFIG_RISCV_DMA_NONCOHERENT=y
CONFIG_RISCV_NONSTANDARD_CACHE_OPS=y
CONFIG_AS_HAS_INSN=y
CONFIG_AS_HAS_OPTION_ARCH=y

#
# SoC selection
#
CONFIG_ARCH_ANDES=y
CONFIG_ARCH_ANLOGIC=y
# CONFIG_ARCH_ESWIN is not set
CONFIG_ARCH_MICROCHIP_POLARFIRE=y
CONFIG_ARCH_MICROCHIP=y
# CONFIG_ARCH_RENESAS is not set
CONFIG_ARCH_SIFIVE=y
CONFIG_ARCH_SOPHGO=y
CONFIG_ARCH_SPACEMIT=y
CONFIG_ARCH_STARFIVE=y
CONFIG_SOC_STARFIVE=y
CONFIG_ARCH_SUNXI=y
CONFIG_ARCH_TENSTORRENT=y
CONFIG_ARCH_THEAD=y
CONFIG_ARCH_VIRT=y
CONFIG_ARCH_CANAAN=y
# end of SoC selection

#
# CPU errata selection
#
CONFIG_ERRATA_ANDES=y
# CONFIG_ERRATA_MIPS is not set
CONFIG_ERRATA_SIFIVE=y
CONFIG_ERRATA_SIFIVE_CIP_453=y
CONFIG_ERRATA_SIFIVE_CIP_1200=y
CONFIG_ERRATA_THEAD=y
CONFIG_ERRATA_THEAD_MAE=y
CONFIG_ERRATA_THEAD_CMO=y
CONFIG_ERRATA_THEAD_PMU=y
CONFIG_ERRATA_THEAD_GHOSTWRITE=y
# end of CPU errata selection

#
# Platform type
#
# CONFIG_NONPORTABLE is not set
CONFIG_ARCH_RV64I=y
# CONFIG_CMODEL_MEDLOW is not set
CONFIG_CMODEL_MEDANY=y
CONFIG_SMP=y
CONFIG_NR_CPUS=8
CONFIG_HOTPLUG_CPU=y
CONFIG_TUNE_GENERIC=y
CONFIG_NUMA=y
CONFIG_NODES_SHIFT=2
# CONFIG_RISCV_TICKET_SPINLOCKS is not set
CONFIG_RISCV_COMBO_SPINLOCKS=y
CONFIG_RISCV_ALTERNATIVE=y
CONFIG_RISCV_ALTERNATIVE_EARLY=y
CONFIG_RISCV_ISA_C=y
CONFIG_RISCV_ISA_SUPM=y
CONFIG_RISCV_ISA_SVNAPOT=y
CONFIG_RISCV_ISA_SVPBMT=y
CONFIG_TOOLCHAIN_HAS_V=y
CONFIG_RISCV_ISA_V=y
CONFIG_RISCV_ISA_V_DEFAULT_ENABLE=y
CONFIG_RISCV_ISA_V_UCOPY_THRESHOLD=768
# CONFIG_RISCV_ISA_V_PREEMPTIVE is not set
CONFIG_RISCV_ISA_ZAWRS=y
CONFIG_RISCV_ISA_ZACAS=y
CONFIG_TOOLCHAIN_HAS_ZBB=y
CONFIG_TOOLCHAIN_HAS_VECTOR_CRYPTO=y
CONFIG_TOOLCHAIN_HAS_ZBA=y
CONFIG_RISCV_ISA_ZBA=y
CONFIG_RISCV_ISA_ZBB=y
CONFIG_TOOLCHAIN_HAS_ZBC=y
CONFIG_RISCV_ISA_ZBC=y
CONFIG_TOOLCHAIN_HAS_ZBKB=y
CONFIG_RISCV_ISA_ZBKB=y
CONFIG_RISCV_ISA_ZICBOM=y
CONFIG_RISCV_ISA_ZICBOZ=y
CONFIG_RISCV_ISA_ZICBOP=y
CONFIG_RISCV_ISA_SVRSW60T59B=y
CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI=y
CONFIG_FPU=y
CONFIG_IRQ_STACKS=y
CONFIG_THREAD_SIZE_ORDER=2
CONFIG_RISCV_MISALIGNED=y
CONFIG_RISCV_SCALAR_MISALIGNED=y
CONFIG_RISCV_VECTOR_MISALIGNED=y
CONFIG_RISCV_PROBE_UNALIGNED_ACCESS=y
# CONFIG_RISCV_EMULATED_UNALIGNED_ACCESS is not set
CONFIG_RISCV_PROBE_VECTOR_UNALIGNED_ACCESS=y

#
# Vendor extensions
#
CONFIG_RISCV_ISA_VENDOR_EXT=y

#
# Andes
#
CONFIG_RISCV_ISA_VENDOR_EXT_ANDES=y
# end of Andes

#
# MIPS
#
CONFIG_RISCV_ISA_VENDOR_EXT_MIPS=y
# end of MIPS

#
# SiFive
#
CONFIG_RISCV_ISA_VENDOR_EXT_SIFIVE=y
# end of SiFive

#
# T-Head
#
CONFIG_RISCV_ISA_VENDOR_EXT_THEAD=y
CONFIG_RISCV_ISA_XTHEADVECTOR=y
# end of T-Head
# end of Vendor extensions
# end of Platform type

#
# Kernel features
#
CONFIG_HZ_100=y
# CONFIG_HZ_250 is not set
# CONFIG_HZ_300 is not set
# CONFIG_HZ_1000 is not set
CONFIG_HZ=100
CONFIG_SCHED_HRTICK=y
# CONFIG_RISCV_SBI_V01 is not set
# CONFIG_RISCV_BOOT_SPINWAIT is not set
CONFIG_ARCH_SUPPORTS_KEXEC=y
CONFIG_ARCH_SELECTS_KEXEC=y
CONFIG_ARCH_SUPPORTS_KEXEC_FILE=y
CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY=y
CONFIG_ARCH_SUPPORTS_CRASH_DUMP=y
CONFIG_ARCH_DEFAULT_CRASH_DUMP=y
CONFIG_COMPAT=y
CONFIG_PARAVIRT=y
# CONFIG_PARAVIRT_TIME_ACCOUNTING is not set
# CONFIG_RELOCATABLE is not set
# end of Kernel features

#
# Boot options
#
CONFIG_CMDLINE="earlyprintk=serial net.ifnames=0 sysctl.kernel.hung_task_all_cpu_backtrace=1 ima_policy=tcb nf-conntrack-ftp.ports=20000 nf-conntrack-tftp.ports=20000 nf-conntrack-sip.ports=20000 nf-conntrack-irc.ports=20000 nf-conntrack-sane.ports=20000 binder.debug_mask=0 rcupdate.rcu_expedited=1 rcupdate.rcu_cpu_stall_cputime=1 no_hash_pointers page_owner=on sysctl.vm.nr_hugepages=4 sysctl.vm.nr_overcommit_hugepages=4 secretmem.enable=1 sysctl.max_rcu_stall_to_panic=1 msr.allow_writes=off coredump_filter=0xffff smp.csd_lock_timeout=300000 watchdog_thresh=165 workqueue.watchdog_thresh=420 sysctl.net.core.netdev_unregister_timeout_secs=420 dummy_hcd.num=2 max_loop=2 nbds_max=2 comedi.comedi_num_legacy_minors=4 panic_on_warn=1"
# CONFIG_CMDLINE_FALLBACK is not set
CONFIG_CMDLINE_EXTEND=y
# CONFIG_CMDLINE_FORCE is not set
CONFIG_EFI_STUB=y
CONFIG_EFI=y
CONFIG_DMI=y
CONFIG_CC_HAVE_STACKPROTECTOR_TLS=y
CONFIG_STACKPROTECTOR_PER_TASK=y
CONFIG_RISCV_ISA_FALLBACK=y
# end of Boot options

CONFIG_PORTABLE=y
CONFIG_ARCH_PROC_KCORE_TEXT=y
CONFIG_ARCH_CC_CAN_LINK=y
CONFIG_ARCH_USERFLAGS="-march=rv64g -mabi=lp64d"

#
# Power management options
#
CONFIG_SUSPEND=y
CONFIG_SUSPEND_FREEZER=y
# CONFIG_SUSPEND_SKIP_SYNC is not set
CONFIG_HIBERNATE_CALLBACKS=y
CONFIG_HIBERNATION=y
CONFIG_HIBERNATION_SNAPSHOT_DEV=y
# CONFIG_HIBERNATION_COMP_LZO is not set
CONFIG_HIBERNATION_COMP_LZ4=y
CONFIG_HIBERNATION_DEF_COMP="lz4"
CONFIG_PM_STD_PARTITION=""
CONFIG_PM_SLEEP=y
CONFIG_PM_SLEEP_SMP=y
# CONFIG_PM_AUTOSLEEP is not set
# CONFIG_PM_USERSPACE_AUTOSLEEP is not set
# CONFIG_PM_WAKELOCKS is not set
# CONFIG_PM_QOS_CPU_SYSTEM_WAKEUP is not set
CONFIG_PM=y
CONFIG_PM_DEBUG=y
# CONFIG_PM_ADVANCED_DEBUG is not set
# CONFIG_PM_TEST_SUSPEND is not set
CONFIG_PM_SLEEP_DEBUG=y
# CONFIG_DPM_WATCHDOG is not set
CONFIG_PM_CLK=y
CONFIG_PM_GENERIC_DOMAINS=y
# CONFIG_WQ_POWER_EFFICIENT_DEFAULT is not set
CONFIG_PM_GENERIC_DOMAINS_SLEEP=y
CONFIG_PM_GENERIC_DOMAINS_OF=y
CONFIG_CPU_PM=y
# CONFIG_ENERGY_MODEL is not set
CONFIG_ARCH_HIBERNATION_POSSIBLE=y
CONFIG_ARCH_HIBERNATION_HEADER=y
CONFIG_ARCH_SUSPEND_POSSIBLE=y
# end of Power management options

#
# CPU Power Management
#

#
# CPU Idle
#
CONFIG_CPU_IDLE=y
CONFIG_CPU_IDLE_MULTIPLE_DRIVERS=y
# CONFIG_CPU_IDLE_GOV_LADDER is not set
CONFIG_CPU_IDLE_GOV_MENU=y
# CONFIG_CPU_IDLE_GOV_TEO is not set
CONFIG_DT_IDLE_STATES=y
CONFIG_DT_IDLE_GENPD=y

#
# RISC-V CPU Idle Drivers
#
CONFIG_RISCV_SBI_CPUIDLE=y
# end of RISC-V CPU Idle Drivers
# end of CPU Idle

#
# CPU Frequency scaling
#
CONFIG_CPU_FREQ=y
CONFIG_CPU_FREQ_GOV_ATTR_SET=y
CONFIG_CPU_FREQ_GOV_COMMON=y
CONFIG_CPU_FREQ_STAT=y
CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
# CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE is not set
# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set
# CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set
# CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE is not set
# CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL is not set
CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
CONFIG_CPU_FREQ_GOV_POWERSAVE=y
CONFIG_CPU_FREQ_GOV_USERSPACE=y
CONFIG_CPU_FREQ_GOV_ONDEMAND=y
CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
# CONFIG_CPU_FREQ_GOV_SCHEDUTIL is not set

#
# CPU frequency scaling drivers
#
CONFIG_CPUFREQ_DT=y
# CONFIG_CPUFREQ_VIRT is not set
CONFIG_CPUFREQ_DT_PLATDEV=y
# CONFIG_ARM_ALLWINNER_SUN50I_CPUFREQ_NVMEM is not set
CONFIG_ACPI_CPPC_CPUFREQ=y
CONFIG_ACPI_CPPC_CPUFREQ_FIE=y
# end of CPU Frequency scaling
# end of CPU Power Management

CONFIG_KVM_COMMON=y
CONFIG_HAVE_KVM_IRQCHIP=y
CONFIG_HAVE_KVM_IRQ_ROUTING=y
CONFIG_HAVE_KVM_DIRTY_RING=y
CONFIG_HAVE_KVM_DIRTY_RING_ACQ_REL=y
CONFIG_KVM_MMIO=y
CONFIG_HAVE_KVM_MSI=y
CONFIG_HAVE_KVM_READONLY_MEM=y
CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT=y
CONFIG_VIRT_XFER_TO_GUEST_WORK=y
CONFIG_KVM_GENERIC_HARDWARE_ENABLING=y
CONFIG_VIRTUALIZATION=y
CONFIG_KVM=y
CONFIG_ARCH_SUPPORTS_ACPI=y
CONFIG_ACPI=y
CONFIG_ACPI_GENERIC_GSI=y
CONFIG_ACPI_THERMAL_LIB=y
# CONFIG_ACPI_DEBUGGER is not set
CONFIG_ACPI_SPCR_TABLE=y
# CONFIG_ACPI_EC is not set
CONFIG_ACPI_AC=y
CONFIG_ACPI_BATTERY=y
CONFIG_ACPI_BUTTON=y
CONFIG_ACPI_VIDEO=y
CONFIG_ACPI_FAN=y
# CONFIG_ACPI_TAD is not set
# CONFIG_ACPI_DOCK is not set
CONFIG_ACPI_PROCESSOR_IDLE=y
CONFIG_ACPI_MCFG=y
CONFIG_ACPI_CPPC_LIB=y
CONFIG_ACPI_PROCESSOR=y
CONFIG_ACPI_THERMAL=y
CONFIG_ACPI_DEBUG=y
# CONFIG_ACPI_PCI_SLOT is not set
# CONFIG_ACPI_CONTAINER is not set
# CONFIG_ACPI_HOTPLUG_MEMORY is not set
# CONFIG_ACPI_HED is not set
# CONFIG_ACPI_BGRT is not set
CONFIG_ACPI_REDUCED_HARDWARE_ONLY=y
CONFIG_ACPI_NHLT=y
# CONFIG_ACPI_NFIT is not set
CONFIG_ACPI_NUMA=y
# CONFIG_ACPI_HMAT is not set
# CONFIG_ACPI_CONFIGFS is not set
# CONFIG_ACPI_PFRUT is not set
CONFIG_ACPI_RIMT=y
CONFIG_ACPI_PPTT=y
CONFIG_ACPI_PCC=y
# CONFIG_ACPI_FFH is not set
CONFIG_PMIC_OPREGION=y
CONFIG_CPU_MITIGATIONS=y

#
# General architecture-dependent options
#
CONFIG_ARCH_SUPPORTS_SCHED_MC=y
CONFIG_SCHED_MC=y
CONFIG_HOTPLUG_CORE_SYNC=y
CONFIG_HOTPLUG_CORE_SYNC_DEAD=y
CONFIG_HOTPLUG_CORE_SYNC_FULL=y
CONFIG_HOTPLUG_SPLIT_STARTUP=y
CONFIG_HOTPLUG_PARALLEL=y
CONFIG_GENERIC_IRQ_ENTRY=y
CONFIG_GENERIC_SYSCALL=y
CONFIG_GENERIC_ENTRY=y
# CONFIG_KPROBES is not set
CONFIG_JUMP_LABEL=y
# CONFIG_STATIC_KEYS_SELFTEST is not set
CONFIG_UPROBES=y
CONFIG_HAVE_64BIT_ALIGNED_ACCESS=y
CONFIG_HAVE_IOREMAP_PROT=y
CONFIG_HAVE_KPROBES=y
CONFIG_HAVE_KRETPROBES=y
CONFIG_HAVE_FUNCTION_ERROR_INJECTION=y
CONFIG_TRACE_IRQFLAGS_SUPPORT=y
CONFIG_HAVE_ARCH_TRACEHOOK=y
CONFIG_HAVE_DMA_CONTIGUOUS=y
CONFIG_GENERIC_SMP_IDLE_THREAD=y
CONFIG_GENERIC_IDLE_POLL_SETUP=y
CONFIG_ARCH_HAS_FORTIFY_SOURCE=y
CONFIG_ARCH_HAS_SET_MEMORY=y
CONFIG_ARCH_HAS_SET_DIRECT_MAP=y
CONFIG_HAVE_ARCH_THREAD_STRUCT_WHITELIST=y
CONFIG_ARCH_WANTS_NO_INSTR=y
CONFIG_HAVE_ASM_MODVERSIONS=y
CONFIG_HAVE_REGS_AND_STACK_ACCESS_API=y
CONFIG_HAVE_RSEQ=y
CONFIG_HAVE_FUNCTION_ARG_ACCESS_API=y
CONFIG_HAVE_PERF_REGS=y
CONFIG_HAVE_PERF_USER_STACK_DUMP=y
CONFIG_HAVE_ARCH_JUMP_LABEL=y
CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE=y
CONFIG_MMU_GATHER_TABLE_FREE=y
CONFIG_MMU_GATHER_RCU_TABLE_FREE=y
CONFIG_MMU_LAZY_TLB_REFCOUNT=y
CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG=y
CONFIG_HAVE_ALIGNED_STRUCT_PAGE=y
CONFIG_ARCH_WEAK_RELEASE_ACQUIRE=y
CONFIG_HAVE_ARCH_SECCOMP=y
CONFIG_HAVE_ARCH_SECCOMP_FILTER=y
CONFIG_SECCOMP=y
CONFIG_SECCOMP_FILTER=y
# CONFIG_SECCOMP_CACHE_DEBUG is not set
CONFIG_HAVE_ARCH_KSTACK_ERASE=y
CONFIG_HAVE_STACKPROTECTOR=y
CONFIG_STACKPROTECTOR=y
CONFIG_STACKPROTECTOR_STRONG=y
CONFIG_ARCH_SUPPORTS_LTO_CLANG=y
CONFIG_ARCH_SUPPORTS_LTO_CLANG_THIN=y
CONFIG_LTO_NONE=y
CONFIG_ARCH_SUPPORTS_CFI=y
CONFIG_HAVE_CONTEXT_TRACKING_USER=y
CONFIG_HAVE_VIRT_CPU_ACCOUNTING_GEN=y
CONFIG_HAVE_IRQ_TIME_ACCOUNTING=y
CONFIG_HAVE_PV_STEAL_CLOCK_GEN=y
CONFIG_HAVE_MOVE_PUD=y
CONFIG_HAVE_MOVE_PMD=y
CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE=y
CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD=y
CONFIG_HAVE_ARCH_HUGE_VMAP=y
CONFIG_HAVE_ARCH_HUGE_VMALLOC=y
CONFIG_ARCH_WANT_HUGE_PMD_SHARE=y
CONFIG_ARCH_WANT_PMD_MKWRITE=y
CONFIG_HAVE_ARCH_SOFT_DIRTY=y
CONFIG_MODULES_USE_ELF_RELA=y
CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK=y
CONFIG_HAVE_SOFTIRQ_ON_OWN_STACK=y
CONFIG_SOFTIRQ_ON_OWN_STACK=y
CONFIG_ARCH_HAS_ELF_RANDOMIZE=y
CONFIG_HAVE_ARCH_MMAP_RND_BITS=y
CONFIG_ARCH_MMAP_RND_BITS=18
CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS=y
CONFIG_ARCH_MMAP_RND_COMPAT_BITS=8
CONFIG_HAVE_PAGE_SIZE_4KB=y
CONFIG_PAGE_SIZE_4KB=y
CONFIG_PAGE_SIZE_LESS_THAN_64KB=y
CONFIG_PAGE_SIZE_LESS_THAN_256KB=y
CONFIG_PAGE_SHIFT=12
CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT=y
CONFIG_CLONE_BACKWARDS=y
CONFIG_COMPAT_32BIT_TIME=y
CONFIG_ARCH_SUPPORTS_RT=y
CONFIG_HAVE_ARCH_VMAP_STACK=y
CONFIG_VMAP_STACK=y
CONFIG_HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET=y
CONFIG_RANDOMIZE_KSTACK_OFFSET=y
# CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT is not set
CONFIG_ARCH_OPTIONAL_KERNEL_RWX=y
CONFIG_ARCH_OPTIONAL_KERNEL_RWX_DEFAULT=y
CONFIG_ARCH_HAS_STRICT_KERNEL_RWX=y
CONFIG_STRICT_KERNEL_RWX=y
CONFIG_ARCH_HAS_STRICT_MODULE_RWX=y
CONFIG_STRICT_MODULE_RWX=y
CONFIG_ARCH_USE_MEMREMAP_PROT=y
# CONFIG_LOCK_EVENT_COUNTS is not set
CONFIG_ARCH_HAS_VDSO_ARCH_DATA=y
CONFIG_HAVE_PREEMPT_DYNAMIC=y
CONFIG_HAVE_PREEMPT_DYNAMIC_KEY=y
CONFIG_ARCH_WANT_LD_ORPHAN_WARN=y
CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC=y
CONFIG_ARCH_SUPPORTS_PAGE_TABLE_CHECK=y
CONFIG_DYNAMIC_SIGFRAME=y
CONFIG_ARCH_HAS_HW_PTE_YOUNG=y
CONFIG_ARCH_HAS_KERNEL_FPU_SUPPORT=y
CONFIG_HAVE_GENERIC_TIF_BITS=y

#
# GCOV-based kernel profiling
#
# CONFIG_GCOV_KERNEL is not set
CONFIG_ARCH_HAS_GCOV_PROFILE_ALL=y
# end of GCOV-based kernel profiling

CONFIG_HAVE_GCC_PLUGINS=y
CONFIG_FUNCTION_ALIGNMENT_4B=y
CONFIG_FUNCTION_ALIGNMENT=4
CONFIG_CC_HAS_MIN_FUNCTION_ALIGNMENT=y
CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT=y
CONFIG_HAVE_ARCH_GET_SECUREBOOT=y
# end of General architecture-dependent options

CONFIG_RT_MUTEXES=y
CONFIG_MODULE_SIG_FORMAT=y
CONFIG_MODULES=y
# CONFIG_MODULE_DEBUG is not set
# CONFIG_MODULE_FORCE_LOAD is not set
CONFIG_MODULE_UNLOAD=y
CONFIG_MODULE_FORCE_UNLOAD=y
# CONFIG_MODULE_UNLOAD_TAINT_TRACKING is not set
CONFIG_MODVERSIONS=y
# CONFIG_GENKSYMS is not set
CONFIG_GENDWARFKSYMS=y
CONFIG_ASM_MODVERSIONS=y
# CONFIG_EXTENDED_MODVERSIONS is not set
# CONFIG_BASIC_MODVERSIONS is not set
CONFIG_MODULE_SRCVERSION_ALL=y
CONFIG_MODULE_SIG=y
# CONFIG_MODULE_SIG_FORCE is not set
# CONFIG_MODULE_SIG_ALL is not set
CONFIG_MODULE_SIG_SHA256=y
# CONFIG_MODULE_SIG_SHA384 is not set
# CONFIG_MODULE_SIG_SHA512 is not set
# CONFIG_MODULE_SIG_SHA3_256 is not set
# CONFIG_MODULE_SIG_SHA3_384 is not set
# CONFIG_MODULE_SIG_SHA3_512 is not set
CONFIG_MODULE_SIG_HASH="sha256"
# CONFIG_MODULE_COMPRESS is not set
# CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS is not set
CONFIG_MODPROBE_PATH="/sbin/modprobe"
# CONFIG_TRIM_UNUSED_KSYMS is not set
CONFIG_MODULES_TREE_LOOKUP=y
CONFIG_BLOCK=y
CONFIG_BLOCK_LEGACY_AUTOLOAD=y
CONFIG_BLK_RQ_ALLOC_TIME=y
CONFIG_BLK_CGROUP_RWSTAT=y
CONFIG_BLK_DEV_BSG_COMMON=y
CONFIG_BLK_ICQ=y
CONFIG_BLK_DEV_BSGLIB=y
CONFIG_BLK_DEV_INTEGRITY=y
# CONFIG_BLK_DEV_WRITE_MOUNTED is not set
CONFIG_BLK_DEV_ZONED=y
CONFIG_BLK_DEV_THROTTLING=y
CONFIG_BLK_WBT=y
CONFIG_BLK_WBT_MQ=y
CONFIG_BLK_CGROUP_IOLATENCY=y
# CONFIG_BLK_CGROUP_FC_APPID is not set
CONFIG_BLK_CGROUP_IOCOST=y
# CONFIG_BLK_CGROUP_IOPRIO is not set
CONFIG_BLK_DEBUG_FS=y
# CONFIG_BLK_SED_OPAL is not set
CONFIG_BLK_INLINE_ENCRYPTION=y
CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK=y

#
# Partition Types
#
# CONFIG_PARTITION_ADVANCED is not set
CONFIG_MSDOS_PARTITION=y
CONFIG_EFI_PARTITION=y
# end of Partition Types

CONFIG_BLK_PM=y
CONFIG_BLOCK_HOLDER_DEPRECATED=y
CONFIG_BLK_MQ_STACKING=y

#
# IO Schedulers
#
CONFIG_MQ_IOSCHED_DEADLINE=y
CONFIG_MQ_IOSCHED_KYBER=y
CONFIG_IOSCHED_BFQ=y
CONFIG_BFQ_GROUP_IOSCHED=y
CONFIG_BFQ_CGROUP_DEBUG=y
# end of IO Schedulers

CONFIG_PREEMPT_NOTIFIERS=y
CONFIG_PADATA=y
CONFIG_ASN1=y
CONFIG_UNINLINE_SPIN_UNLOCK=y
CONFIG_ARCH_SUPPORTS_ATOMIC_RMW=y
CONFIG_MUTEX_SPIN_ON_OWNER=y
CONFIG_RWSEM_SPIN_ON_OWNER=y
CONFIG_LOCK_SPIN_ON_OWNER=y
CONFIG_ARCH_USE_QUEUED_SPINLOCKS=y
CONFIG_QUEUED_SPINLOCKS=y
CONFIG_ARCH_USE_QUEUED_RWLOCKS=y
CONFIG_QUEUED_RWLOCKS=y
CONFIG_ARCH_HAS_MMIOWB=y
CONFIG_MMIOWB=y
CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE=y
CONFIG_ARCH_HAS_PREPARE_SYNC_CORE_CMD=y
CONFIG_ARCH_HAS_SYNC_CORE_BEFORE_USERMODE=y
CONFIG_ARCH_HAS_SYSCALL_WRAPPER=y
CONFIG_FREEZER=y

#
# Executable file formats
#
CONFIG_BINFMT_ELF=y
CONFIG_COMPAT_BINFMT_ELF=y
CONFIG_ELFCORE=y
CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
CONFIG_BINFMT_SCRIPT=y
CONFIG_ARCH_HAS_BINFMT_FLAT=y
CONFIG_BINFMT_FLAT=y
# CONFIG_BINFMT_FLAT_OLD is not set
# CONFIG_BINFMT_ZFLAT is not set
CONFIG_BINFMT_MISC=y
CONFIG_COREDUMP=y
CONFIG_ARCH_HAS_ELF_CORE_EFLAGS=y
# end of Executable file formats

#
# Memory Management options
#
CONFIG_SWAP=y
CONFIG_ZSWAP=y
CONFIG_ZSWAP_DEFAULT_ON=y
CONFIG_ZSWAP_SHRINKER_DEFAULT_ON=y
# CONFIG_ZSWAP_COMPRESSOR_DEFAULT_DEFLATE is not set
# CONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZO is not set
CONFIG_ZSWAP_COMPRESSOR_DEFAULT_842=y
# CONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZ4 is not set
# CONFIG_ZSWAP_COMPRESSOR_DEFAULT_LZ4HC is not set
# CONFIG_ZSWAP_COMPRESSOR_DEFAULT_ZSTD is not set
CONFIG_ZSWAP_COMPRESSOR_DEFAULT="842"
CONFIG_ZSMALLOC=y

#
# Zsmalloc allocator options
#

#
# Zsmalloc is a common backend allocator for zswap & zram
#
# CONFIG_ZSMALLOC_STAT is not set
CONFIG_ZSMALLOC_CHAIN_SIZE=8
# end of Zsmalloc allocator options

#
# Slab allocator options
#
CONFIG_SLUB=y
CONFIG_KVFREE_RCU_BATCHED=y
# CONFIG_SLUB_TINY is not set
CONFIG_SLAB_MERGE_DEFAULT=y
# CONFIG_SLAB_FREELIST_RANDOM is not set
# CONFIG_SLAB_FREELIST_HARDENED is not set
# CONFIG_SLAB_BUCKETS is not set
# CONFIG_SLUB_STATS is not set
# CONFIG_RANDOM_KMALLOC_CACHES is not set
# end of Slab allocator options

# CONFIG_SHUFFLE_PAGE_ALLOCATOR is not set
# CONFIG_COMPAT_BRK is not set
CONFIG_SELECT_MEMORY_MODEL=y
CONFIG_SPARSEMEM_MANUAL=y
CONFIG_SPARSEMEM=y
CONFIG_SPARSEMEM_EXTREME=y
CONFIG_SPARSEMEM_VMEMMAP_ENABLE=y
CONFIG_SPARSEMEM_VMEMMAP=y
CONFIG_ARCH_WANT_OPTIMIZE_DAX_VMEMMAP=y
CONFIG_ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP=y
CONFIG_HAVE_GUP_FAST=y
CONFIG_ARCH_KEEP_MEMBLOCK=y
CONFIG_NUMA_KEEP_MEMINFO=y
CONFIG_MEMORY_ISOLATION=y
CONFIG_EXCLUSIVE_SYSTEM_RAM=y
CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
CONFIG_MEMORY_HOTPLUG=y
# CONFIG_MHP_DEFAULT_ONLINE_TYPE_OFFLINE is not set
CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_AUTO=y
# CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_KERNEL is not set
# CONFIG_MHP_DEFAULT_ONLINE_TYPE_ONLINE_MOVABLE is not set
CONFIG_MEMORY_HOTREMOVE=y
CONFIG_MHP_MEMMAP_ON_MEMORY=y
CONFIG_ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE=y
CONFIG_SPLIT_PTE_PTLOCKS=y
CONFIG_ARCH_ENABLE_SPLIT_PMD_PTLOCK=y
CONFIG_SPLIT_PMD_PTLOCKS=y
CONFIG_BALLOON=y
CONFIG_BALLOON_MIGRATION=y
CONFIG_COMPACTION=y
CONFIG_COMPACT_UNEVICTABLE_DEFAULT=1
CONFIG_PAGE_REPORTING=y
CONFIG_NUMA_MIGRATION=y
CONFIG_MIGRATION=y
CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION=y
CONFIG_ARCH_ENABLE_THP_MIGRATION=y
CONFIG_CONTIG_ALLOC=y
CONFIG_PCP_BATCH_SCALE_MAX=5
CONFIG_PHYS_ADDR_T_64BIT=y
CONFIG_MMU_NOTIFIER=y
CONFIG_KSM=y
CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
CONFIG_ARCH_WANTS_THP_SWAP=y
# CONFIG_PERSISTENT_HUGE_ZERO_FOLIO is not set
CONFIG_MM_ID=y
CONFIG_TRANSPARENT_HUGEPAGE=y
# CONFIG_TRANSPARENT_HUGEPAGE_ALWAYS is not set
CONFIG_TRANSPARENT_HUGEPAGE_MADVISE=y
# CONFIG_TRANSPARENT_HUGEPAGE_NEVER is not set
# CONFIG_TRANSPARENT_HUGEPAGE_SHMEM_HUGE_NEVER is not set
# CONFIG_TRANSPARENT_HUGEPAGE_SHMEM_HUGE_ALWAYS is not set
# CONFIG_TRANSPARENT_HUGEPAGE_SHMEM_HUGE_WITHIN_SIZE is not set
CONFIG_TRANSPARENT_HUGEPAGE_SHMEM_HUGE_ADVISE=y
# CONFIG_TRANSPARENT_HUGEPAGE_TMPFS_HUGE_NEVER is not set
# CONFIG_TRANSPARENT_HUGEPAGE_TMPFS_HUGE_ALWAYS is not set
# CONFIG_TRANSPARENT_HUGEPAGE_TMPFS_HUGE_WITHIN_SIZE is not set
CONFIG_TRANSPARENT_HUGEPAGE_TMPFS_HUGE_ADVISE=y
CONFIG_THP_SWAP=y
# CONFIG_READ_ONLY_THP_FOR_FS is not set
# CONFIG_NO_PAGE_MAPCOUNT is not set
CONFIG_PAGE_MAPCOUNT=y
CONFIG_PGTABLE_HAS_HUGE_LEAVES=y
CONFIG_HAVE_GIGANTIC_FOLIOS=y
CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP=y
CONFIG_ARCH_SUPPORTS_PMD_PFNMAP=y
CONFIG_ARCH_SUPPORTS_PUD_PFNMAP=y
CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK=y
CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK=y
CONFIG_USE_PERCPU_NUMA_NODE_ID=y
CONFIG_HAVE_SETUP_PER_CPU_AREA=y
CONFIG_CMA=y
# CONFIG_CMA_DEBUGFS is not set
# CONFIG_CMA_SYSFS is not set
CONFIG_CMA_AREAS=20
CONFIG_PAGE_BLOCK_MAX_ORDER=10
# CONFIG_MEM_SOFT_DIRTY is not set
CONFIG_GENERIC_EARLY_IOREMAP=y
# CONFIG_DEFERRED_STRUCT_PAGE_INIT is not set
CONFIG_PAGE_IDLE_FLAG=y
# CONFIG_IDLE_PAGE_TRACKING is not set
CONFIG_ARCH_HAS_CURRENT_STACK_POINTER=y
CONFIG_ZONE_DMA32=y
# CONFIG_ZONE_DEVICE is not set
CONFIG_HMM_MIRROR=y
CONFIG_VM_EVENT_COUNTERS=y
CONFIG_PERCPU_STATS=y
# CONFIG_GUP_TEST is not set
# CONFIG_DMAPOOL_TEST is not set
CONFIG_ARCH_HAS_PTE_SPECIAL=y
CONFIG_MEMFD_CREATE=y
CONFIG_SECRETMEM=y
CONFIG_ANON_VMA_NAME=y
CONFIG_HAVE_ARCH_USERFAULTFD_WP=y
CONFIG_HAVE_ARCH_USERFAULTFD_MINOR=y
CONFIG_USERFAULTFD=y
# CONFIG_PTE_MARKER_UFFD_WP is not set
CONFIG_LRU_GEN=y
CONFIG_LRU_GEN_ENABLED=y
# CONFIG_LRU_GEN_STATS is not set
CONFIG_LRU_GEN_WALKS_MMU=y
CONFIG_ARCH_SUPPORTS_PER_VMA_LOCK=y
CONFIG_PER_VMA_LOCK=y
CONFIG_LOCK_MM_AND_FIND_VMA=y
CONFIG_EXECMEM=y
CONFIG_NUMA_MEMBLKS=y
# CONFIG_NUMA_EMU is not set
CONFIG_PT_RECLAIM=y

#
# Data Access Monitoring
#
CONFIG_DAMON=y
# CONFIG_DAMON_DEBUG_SANITY is not set
CONFIG_DAMON_VADDR=y
CONFIG_DAMON_PADDR=y
# CONFIG_DAMON_SYSFS is not set
CONFIG_DAMON_RECLAIM=y
# CONFIG_DAMON_LRU_SORT is not set
# CONFIG_DAMON_STAT is not set
# end of Data Access Monitoring
# end of Memory Management options

CONFIG_NET=y
CONFIG_NET_INGRESS=y
CONFIG_NET_EGRESS=y
CONFIG_NET_XGRESS=y
CONFIG_NET_REDIRECT=y
CONFIG_SKB_DECRYPTED=y
CONFIG_SKB_EXTENSIONS=y
CONFIG_NET_DEVMEM=y
CONFIG_NET_SHAPER=y
CONFIG_NET_CRC32C=y

#
# Networking options
#
CONFIG_PACKET=y
CONFIG_PACKET_DIAG=y
CONFIG_INET_PSP=y
CONFIG_UNIX=y
CONFIG_AF_UNIX_OOB=y
CONFIG_UNIX_DIAG=y
CONFIG_TLS=y
CONFIG_TLS_DEVICE=y
CONFIG_TLS_TOE=y
CONFIG_XFRM=y
CONFIG_XFRM_OFFLOAD=y
CONFIG_XFRM_ALGO=y
CONFIG_XFRM_USER=y
CONFIG_XFRM_INTERFACE=y
CONFIG_XFRM_SUB_POLICY=y
CONFIG_XFRM_MIGRATE=y
CONFIG_XFRM_STATISTICS=y
CONFIG_XFRM_AH=y
CONFIG_XFRM_ESP=y
CONFIG_XFRM_IPCOMP=y
CONFIG_NET_KEY=y
CONFIG_NET_KEY_MIGRATE=y
# CONFIG_XFRM_IPTFS is not set
CONFIG_XFRM_ESPINTCP=y
CONFIG_SMC=y
CONFIG_SMC_DIAG=y
# CONFIG_SMC_HS_CTRL_BPF is not set
CONFIG_DIBS=y
CONFIG_DIBS_LO=y
CONFIG_XDP_SOCKETS=y
CONFIG_XDP_SOCKETS_DIAG=y
CONFIG_NET_HANDSHAKE=y
CONFIG_INET=y
CONFIG_IP_MULTICAST=y
CONFIG_IP_ADVANCED_ROUTER=y
CONFIG_IP_FIB_TRIE_STATS=y
CONFIG_IP_MULTIPLE_TABLES=y
CONFIG_IP_ROUTE_MULTIPATH=y
CONFIG_IP_ROUTE_VERBOSE=y
CONFIG_IP_ROUTE_CLASSID=y
CONFIG_IP_PNP=y
CONFIG_IP_PNP_DHCP=y
CONFIG_IP_PNP_BOOTP=y
CONFIG_IP_PNP_RARP=y
CONFIG_NET_IPIP=y
CONFIG_NET_IPGRE_DEMUX=y
CONFIG_NET_IP_TUNNEL=y
CONFIG_NET_IPGRE=y
CONFIG_NET_IPGRE_BROADCAST=y
CONFIG_IP_MROUTE_COMMON=y
CONFIG_IP_MROUTE=y
CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
CONFIG_IP_PIMSM_V1=y
CONFIG_IP_PIMSM_V2=y
CONFIG_SYN_COOKIES=y
CONFIG_NET_IPVTI=y
CONFIG_NET_UDP_TUNNEL=y
CONFIG_NET_FOU=y
CONFIG_NET_FOU_IP_TUNNELS=y
CONFIG_INET_AH=y
CONFIG_INET_ESP=y
CONFIG_INET_ESP_OFFLOAD=y
CONFIG_INET_ESPINTCP=y
CONFIG_INET_IPCOMP=y
CONFIG_INET_TABLE_PERTURB_ORDER=16
CONFIG_INET_XFRM_TUNNEL=y
CONFIG_INET_TUNNEL=y
CONFIG_INET_DIAG=y
CONFIG_INET_TCP_DIAG=y
CONFIG_INET_UDP_DIAG=y
CONFIG_INET_RAW_DIAG=y
CONFIG_INET_DIAG_DESTROY=y
CONFIG_TCP_CONG_ADVANCED=y
CONFIG_TCP_CONG_BIC=y
CONFIG_TCP_CONG_CUBIC=y
CONFIG_TCP_CONG_WESTWOOD=y
CONFIG_TCP_CONG_HTCP=y
CONFIG_TCP_CONG_HSTCP=y
CONFIG_TCP_CONG_HYBLA=y
CONFIG_TCP_CONG_VEGAS=y
CONFIG_TCP_CONG_NV=y
CONFIG_TCP_CONG_SCALABLE=y
CONFIG_TCP_CONG_LP=y
CONFIG_TCP_CONG_VENO=y
CONFIG_TCP_CONG_YEAH=y
CONFIG_TCP_CONG_ILLINOIS=y
CONFIG_TCP_CONG_DCTCP=y
CONFIG_TCP_CONG_CDG=y
CONFIG_TCP_CONG_BBR=y
# CONFIG_DEFAULT_BIC is not set
# CONFIG_DEFAULT_CUBIC is not set
# CONFIG_DEFAULT_HTCP is not set
# CONFIG_DEFAULT_HYBLA is not set
# CONFIG_DEFAULT_VEGAS is not set
# CONFIG_DEFAULT_VENO is not set
# CONFIG_DEFAULT_WESTWOOD is not set
# CONFIG_DEFAULT_DCTCP is not set
# CONFIG_DEFAULT_CDG is not set
CONFIG_DEFAULT_BBR=y
# CONFIG_DEFAULT_RENO is not set
CONFIG_DEFAULT_TCP_CONG="bbr"
# CONFIG_TCP_AO is not set
CONFIG_TCP_MD5SIG=y
CONFIG_IPV6=y
CONFIG_IPV6_ROUTER_PREF=y
CONFIG_IPV6_ROUTE_INFO=y
CONFIG_IPV6_OPTIMISTIC_DAD=y
CONFIG_INET6_AH=y
CONFIG_INET6_ESP=y
CONFIG_INET6_ESP_OFFLOAD=y
CONFIG_INET6_ESPINTCP=y
CONFIG_INET6_IPCOMP=y
CONFIG_IPV6_MIP6=y
CONFIG_IPV6_ILA=y
CONFIG_INET6_XFRM_TUNNEL=y
CONFIG_INET6_TUNNEL=y
CONFIG_IPV6_VTI=y
CONFIG_IPV6_SIT=y
CONFIG_IPV6_SIT_6RD=y
CONFIG_IPV6_NDISC_NODETYPE=y
CONFIG_IPV6_TUNNEL=y
CONFIG_IPV6_GRE=y
CONFIG_IPV6_FOU=y
CONFIG_IPV6_FOU_TUNNEL=y
CONFIG_IPV6_MULTIPLE_TABLES=y
CONFIG_IPV6_SUBTREES=y
CONFIG_IPV6_MROUTE=y
CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
CONFIG_IPV6_PIMSM_V2=y
CONFIG_IPV6_SEG6_LWTUNNEL=y
CONFIG_IPV6_SEG6_HMAC=y
CONFIG_IPV6_SEG6_BPF=y
CONFIG_IPV6_RPL_LWTUNNEL=y
# CONFIG_IPV6_IOAM6_LWTUNNEL is not set
CONFIG_NETLABEL=y
CONFIG_MPTCP=y
CONFIG_INET_MPTCP_DIAG=y
CONFIG_MPTCP_IPV6=y
CONFIG_NETWORK_SECMARK=y
# CONFIG_NETWORK_PHY_TIMESTAMPING is not set
CONFIG_NETFILTER=y
CONFIG_NETFILTER_ADVANCED=y

#
# Core Netfilter Configuration
#
CONFIG_NETFILTER_INGRESS=y
CONFIG_NETFILTER_EGRESS=y
CONFIG_NETFILTER_SKIP_EGRESS=y
CONFIG_NETFILTER_NETLINK=y
CONFIG_NETFILTER_FAMILY_ARP=y
CONFIG_NETFILTER_BPF_LINK=y
# CONFIG_NETFILTER_NETLINK_HOOK is not set
CONFIG_NETFILTER_NETLINK_ACCT=y
CONFIG_NETFILTER_NETLINK_QUEUE=y
CONFIG_NETFILTER_NETLINK_LOG=y
CONFIG_NETFILTER_NETLINK_OSF=y
CONFIG_NF_CONNTRACK=y
CONFIG_NF_LOG_SYSLOG=y
CONFIG_NETFILTER_CONNCOUNT=y
CONFIG_NF_CONNTRACK_MARK=y
CONFIG_NF_CONNTRACK_SECMARK=y
CONFIG_NF_CONNTRACK_ZONES=y
# CONFIG_NF_CONNTRACK_PROCFS is not set
CONFIG_NF_CONNTRACK_EVENTS=y
CONFIG_NF_CONNTRACK_TIMEOUT=y
CONFIG_NF_CONNTRACK_TIMESTAMP=y
CONFIG_NF_CONNTRACK_LABELS=y
CONFIG_NF_CONNTRACK_OVS=y
CONFIG_NF_CT_PROTO_GRE=y
# CONFIG_NF_CT_PROTO_SCTP is not set
CONFIG_NF_CONNTRACK_AMANDA=y
CONFIG_NF_CONNTRACK_FTP=y
CONFIG_NF_CONNTRACK_H323=y
CONFIG_NF_CONNTRACK_IRC=y
CONFIG_NF_CONNTRACK_BROADCAST=y
CONFIG_NF_CONNTRACK_NETBIOS_NS=y
CONFIG_NF_CONNTRACK_SNMP=y
CONFIG_NF_CONNTRACK_PPTP=y
CONFIG_NF_CONNTRACK_SANE=y
CONFIG_NF_CONNTRACK_SIP=y
CONFIG_NF_CONNTRACK_TFTP=y
CONFIG_NF_CT_NETLINK=y
CONFIG_NF_CT_NETLINK_TIMEOUT=y
CONFIG_NF_CT_NETLINK_HELPER=y
CONFIG_NETFILTER_NETLINK_GLUE_CT=y
CONFIG_NF_NAT=y
CONFIG_NF_NAT_AMANDA=y
CONFIG_NF_NAT_FTP=y
CONFIG_NF_NAT_IRC=y
CONFIG_NF_NAT_SIP=y
CONFIG_NF_NAT_TFTP=y
CONFIG_NF_NAT_REDIRECT=y
CONFIG_NF_NAT_MASQUERADE=y
CONFIG_NF_NAT_OVS=y
CONFIG_NETFILTER_SYNPROXY=y
CONFIG_NF_TABLES=y
CONFIG_NF_TABLES_INET=y
CONFIG_NF_TABLES_NETDEV=y
CONFIG_NFT_NUMGEN=y
CONFIG_NFT_CT=y
CONFIG_NFT_EXTHDR_DCCP=y
CONFIG_NFT_FLOW_OFFLOAD=y
CONFIG_NFT_CONNLIMIT=y
CONFIG_NFT_LOG=y
CONFIG_NFT_LIMIT=y
CONFIG_NFT_MASQ=y
CONFIG_NFT_REDIR=y
CONFIG_NFT_NAT=y
CONFIG_NFT_TUNNEL=y
CONFIG_NFT_QUEUE=y
CONFIG_NFT_QUOTA=y
CONFIG_NFT_REJECT=y
CONFIG_NFT_REJECT_INET=y
CONFIG_NFT_COMPAT=y
CONFIG_NFT_HASH=y
CONFIG_NFT_FIB=y
CONFIG_NFT_FIB_INET=y
CONFIG_NFT_XFRM=y
CONFIG_NFT_SOCKET=y
CONFIG_NFT_OSF=y
CONFIG_NFT_TPROXY=y
CONFIG_NFT_SYNPROXY=y
CONFIG_NF_DUP_NETDEV=y
CONFIG_NFT_DUP_NETDEV=y
CONFIG_NFT_FWD_NETDEV=y
CONFIG_NFT_FIB_NETDEV=y
CONFIG_NFT_REJECT_NETDEV=y
CONFIG_NF_FLOW_TABLE_INET=y
CONFIG_NF_FLOW_TABLE=y
# CONFIG_NF_FLOW_TABLE_PROCFS is not set
CONFIG_NETFILTER_XTABLES=y
CONFIG_NETFILTER_XTABLES_COMPAT=y
CONFIG_NETFILTER_XTABLES_LEGACY=y

#
# Xtables combined modules
#
CONFIG_NETFILTER_XT_MARK=y
CONFIG_NETFILTER_XT_CONNMARK=y

#
# Xtables targets
#
CONFIG_NETFILTER_XT_TARGET_AUDIT=y
CONFIG_NETFILTER_XT_TARGET_CHECKSUM=y
CONFIG_NETFILTER_XT_TARGET_CLASSIFY=y
CONFIG_NETFILTER_XT_TARGET_CONNMARK=y
CONFIG_NETFILTER_XT_TARGET_CONNSECMARK=y
CONFIG_NETFILTER_XT_TARGET_CT=y
CONFIG_NETFILTER_XT_TARGET_DSCP=y
CONFIG_NETFILTER_XT_TARGET_HL=y
CONFIG_NETFILTER_XT_TARGET_HMARK=y
CONFIG_NETFILTER_XT_TARGET_IDLETIMER=y
CONFIG_NETFILTER_XT_TARGET_LED=y
CONFIG_NETFILTER_XT_TARGET_LOG=y
CONFIG_NETFILTER_XT_TARGET_MARK=y
CONFIG_NETFILTER_XT_NAT=y
CONFIG_NETFILTER_XT_TARGET_NETMAP=y
CONFIG_NETFILTER_XT_TARGET_NFLOG=y
CONFIG_NETFILTER_XT_TARGET_NFQUEUE=y
CONFIG_NETFILTER_XT_TARGET_NOTRACK=y
CONFIG_NETFILTER_XT_TARGET_RATEEST=y
CONFIG_NETFILTER_XT_TARGET_REDIRECT=y
CONFIG_NETFILTER_XT_TARGET_MASQUERADE=y
CONFIG_NETFILTER_XT_TARGET_TEE=y
CONFIG_NETFILTER_XT_TARGET_TPROXY=y
CONFIG_NETFILTER_XT_TARGET_TRACE=y
CONFIG_NETFILTER_XT_TARGET_SECMARK=y
CONFIG_NETFILTER_XT_TARGET_TCPMSS=y
CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=y

#
# Xtables matches
#
CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=y
CONFIG_NETFILTER_XT_MATCH_BPF=y
CONFIG_NETFILTER_XT_MATCH_CGROUP=y
CONFIG_NETFILTER_XT_MATCH_CLUSTER=y
CONFIG_NETFILTER_XT_MATCH_COMMENT=y
CONFIG_NETFILTER_XT_MATCH_CONNBYTES=y
CONFIG_NETFILTER_XT_MATCH_CONNLABEL=y
CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=y
CONFIG_NETFILTER_XT_MATCH_CONNMARK=y
CONFIG_NETFILTER_XT_MATCH_CONNTRACK=y
CONFIG_NETFILTER_XT_MATCH_CPU=y
# CONFIG_NETFILTER_XT_MATCH_DCCP is not set
CONFIG_NETFILTER_XT_MATCH_DEVGROUP=y
CONFIG_NETFILTER_XT_MATCH_DSCP=y
CONFIG_NETFILTER_XT_MATCH_ECN=y
CONFIG_NETFILTER_XT_MATCH_ESP=y
CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=y
CONFIG_NETFILTER_XT_MATCH_HELPER=y
CONFIG_NETFILTER_XT_MATCH_HL=y
CONFIG_NETFILTER_XT_MATCH_IPCOMP=y
CONFIG_NETFILTER_XT_MATCH_IPRANGE=y
CONFIG_NETFILTER_XT_MATCH_L2TP=y
CONFIG_NETFILTER_XT_MATCH_LENGTH=y
CONFIG_NETFILTER_XT_MATCH_LIMIT=y
CONFIG_NETFILTER_XT_MATCH_MAC=y
CONFIG_NETFILTER_XT_MATCH_MARK=y
CONFIG_NETFILTER_XT_MATCH_MULTIPORT=y
CONFIG_NETFILTER_XT_MATCH_NFACCT=y
CONFIG_NETFILTER_XT_MATCH_OSF=y
CONFIG_NETFILTER_XT_MATCH_OWNER=y
CONFIG_NETFILTER_XT_MATCH_POLICY=y
CONFIG_NETFILTER_XT_MATCH_PKTTYPE=y
CONFIG_NETFILTER_XT_MATCH_QUOTA=y
CONFIG_NETFILTER_XT_MATCH_RATEEST=y
CONFIG_NETFILTER_XT_MATCH_REALM=y
CONFIG_NETFILTER_XT_MATCH_RECENT=y
# CONFIG_NETFILTER_XT_MATCH_SCTP is not set
CONFIG_NETFILTER_XT_MATCH_SOCKET=y
CONFIG_NETFILTER_XT_MATCH_STATE=y
CONFIG_NETFILTER_XT_MATCH_STATISTIC=y
CONFIG_NETFILTER_XT_MATCH_STRING=y
CONFIG_NETFILTER_XT_MATCH_TCPMSS=y
CONFIG_NETFILTER_XT_MATCH_TIME=y
CONFIG_NETFILTER_XT_MATCH_U32=y
# end of Core Netfilter Configuration

# CONFIG_IP_SET is not set
# CONFIG_IP_VS is not set

#
# IP: Netfilter Configuration
#
CONFIG_NF_DEFRAG_IPV4=y
CONFIG_IP_NF_IPTABLES_LEGACY=y
CONFIG_NF_SOCKET_IPV4=y
CONFIG_NF_TPROXY_IPV4=y
CONFIG_NF_TABLES_IPV4=y
CONFIG_NFT_REJECT_IPV4=y
CONFIG_NFT_DUP_IPV4=y
CONFIG_NFT_FIB_IPV4=y
CONFIG_NF_TABLES_ARP=y
CONFIG_NF_DUP_IPV4=y
CONFIG_NF_LOG_ARP=y
CONFIG_NF_LOG_IPV4=y
CONFIG_NF_REJECT_IPV4=y
CONFIG_NF_NAT_SNMP_BASIC=y
CONFIG_NF_NAT_PPTP=y
CONFIG_NF_NAT_H323=y
CONFIG_IP_NF_IPTABLES=y
CONFIG_IP_NF_MATCH_AH=y
CONFIG_IP_NF_MATCH_ECN=y
CONFIG_IP_NF_MATCH_RPFILTER=y
CONFIG_IP_NF_MATCH_TTL=y
CONFIG_IP_NF_FILTER=y
CONFIG_IP_NF_TARGET_REJECT=y
CONFIG_IP_NF_TARGET_SYNPROXY=y
CONFIG_IP_NF_NAT=y
CONFIG_IP_NF_TARGET_MASQUERADE=y
CONFIG_IP_NF_TARGET_NETMAP=y
CONFIG_IP_NF_TARGET_REDIRECT=y
CONFIG_IP_NF_MANGLE=y
CONFIG_IP_NF_TARGET_ECN=y
CONFIG_IP_NF_TARGET_TTL=y
CONFIG_IP_NF_RAW=y
CONFIG_IP_NF_SECURITY=y
CONFIG_IP_NF_ARPTABLES=y
CONFIG_NFT_COMPAT_ARP=y
CONFIG_IP_NF_ARPFILTER=y
CONFIG_IP_NF_ARP_MANGLE=y
# end of IP: Netfilter Configuration

#
# IPv6: Netfilter Configuration
#
CONFIG_IP6_NF_IPTABLES_LEGACY=y
CONFIG_NF_SOCKET_IPV6=y
CONFIG_NF_TPROXY_IPV6=y
CONFIG_NF_TABLES_IPV6=y
CONFIG_NFT_REJECT_IPV6=y
CONFIG_NFT_DUP_IPV6=y
CONFIG_NFT_FIB_IPV6=y
CONFIG_NF_DUP_IPV6=y
CONFIG_NF_REJECT_IPV6=y
CONFIG_NF_LOG_IPV6=y
CONFIG_IP6_NF_IPTABLES=y
CONFIG_IP6_NF_MATCH_AH=y
CONFIG_IP6_NF_MATCH_EUI64=y
CONFIG_IP6_NF_MATCH_FRAG=y
CONFIG_IP6_NF_MATCH_OPTS=y
CONFIG_IP6_NF_MATCH_HL=y
CONFIG_IP6_NF_MATCH_IPV6HEADER=y
CONFIG_IP6_NF_MATCH_MH=y
CONFIG_IP6_NF_MATCH_RPFILTER=y
CONFIG_IP6_NF_MATCH_RT=y
CONFIG_IP6_NF_MATCH_SRH=y
CONFIG_IP6_NF_TARGET_HL=y
CONFIG_IP6_NF_FILTER=y
CONFIG_IP6_NF_TARGET_REJECT=y
CONFIG_IP6_NF_TARGET_SYNPROXY=y
CONFIG_IP6_NF_MANGLE=y
CONFIG_IP6_NF_RAW=y
CONFIG_IP6_NF_SECURITY=y
CONFIG_IP6_NF_NAT=y
CONFIG_IP6_NF_TARGET_MASQUERADE=y
CONFIG_IP6_NF_TARGET_NPT=y
# end of IPv6: Netfilter Configuration

CONFIG_NF_DEFRAG_IPV6=y
# CONFIG_NF_CONNTRACK_BRIDGE is not set
# CONFIG_IP_SCTP is not set
CONFIG_RDS=y
CONFIG_RDS_RDMA=y
CONFIG_RDS_TCP=y
# CONFIG_RDS_DEBUG is not set
# CONFIG_TIPC is not set
# CONFIG_ATM is not set
CONFIG_L2TP=y
# CONFIG_L2TP_DEBUGFS is not set
CONFIG_L2TP_V3=y
CONFIG_L2TP_IP=y
CONFIG_L2TP_ETH=y
CONFIG_STP=y
CONFIG_GARP=y
CONFIG_MRP=y
# CONFIG_BRIDGE is not set
CONFIG_NET_DSA=y
# CONFIG_NET_DSA_TAG_NONE is not set
# CONFIG_NET_DSA_TAG_AR9331 is not set
CONFIG_NET_DSA_TAG_BRCM_COMMON=y
CONFIG_NET_DSA_TAG_BRCM=y
# CONFIG_NET_DSA_TAG_BRCM_LEGACY is not set
# CONFIG_NET_DSA_TAG_BRCM_LEGACY_FCS is not set
CONFIG_NET_DSA_TAG_BRCM_PREPEND=y
# CONFIG_NET_DSA_TAG_HELLCREEK is not set
# CONFIG_NET_DSA_TAG_GSWIP is not set
# CONFIG_NET_DSA_TAG_DSA is not set
# CONFIG_NET_DSA_TAG_EDSA is not set
CONFIG_NET_DSA_TAG_MTK=y
# CONFIG_NET_DSA_TAG_MXL_862XX is not set
# CONFIG_NET_DSA_TAG_MXL_GSW1XX is not set
# CONFIG_NET_DSA_TAG_KSZ is not set
# CONFIG_NET_DSA_TAG_OCELOT is not set
# CONFIG_NET_DSA_TAG_OCELOT_8021Q is not set
CONFIG_NET_DSA_TAG_QCA=y
CONFIG_NET_DSA_TAG_RTL4_A=y
# CONFIG_NET_DSA_TAG_RTL8_4 is not set
# CONFIG_NET_DSA_TAG_RZN1_A5PSW is not set
# CONFIG_NET_DSA_TAG_LAN9303 is not set
# CONFIG_NET_DSA_TAG_SJA1105 is not set
# CONFIG_NET_DSA_TAG_TRAILER is not set
# CONFIG_NET_DSA_TAG_VSC73XX_8021Q is not set
# CONFIG_NET_DSA_TAG_XRS700X is not set
# CONFIG_NET_DSA_TAG_YT921X is not set
CONFIG_VLAN_8021Q=y
CONFIG_VLAN_8021Q_GVRP=y
CONFIG_VLAN_8021Q_MVRP=y
CONFIG_LLC=y
CONFIG_LLC2=y
# CONFIG_ATALK is not set
# CONFIG_X25 is not set
# CONFIG_LAPB is not set
# CONFIG_PHONET is not set
# CONFIG_6LOWPAN is not set
# CONFIG_IEEE802154 is not set
CONFIG_NET_SCHED=y

#
# Queueing/Scheduling
#
CONFIG_NET_SCH_HTB=y
CONFIG_NET_SCH_HFSC=y
CONFIG_NET_SCH_PRIO=y
CONFIG_NET_SCH_MULTIQ=y
CONFIG_NET_SCH_RED=y
CONFIG_NET_SCH_SFB=y
CONFIG_NET_SCH_SFQ=y
CONFIG_NET_SCH_TEQL=y
CONFIG_NET_SCH_TBF=y
CONFIG_NET_SCH_CBS=y
CONFIG_NET_SCH_ETF=y
CONFIG_NET_SCH_MQPRIO_LIB=y
CONFIG_NET_SCH_TAPRIO=y
CONFIG_NET_SCH_GRED=y
CONFIG_NET_SCH_NETEM=y
CONFIG_NET_SCH_DRR=y
CONFIG_NET_SCH_MQPRIO=y
CONFIG_NET_SCH_SKBPRIO=y
CONFIG_NET_SCH_CHOKE=y
CONFIG_NET_SCH_QFQ=y
CONFIG_NET_SCH_CODEL=y
CONFIG_NET_SCH_FQ_CODEL=y
CONFIG_NET_SCH_CAKE=y
CONFIG_NET_SCH_FQ=y
CONFIG_NET_SCH_HHF=y
CONFIG_NET_SCH_PIE=y
CONFIG_NET_SCH_FQ_PIE=y
CONFIG_NET_SCH_INGRESS=y
CONFIG_NET_SCH_PLUG=y
CONFIG_NET_SCH_ETS=y
# CONFIG_NET_SCH_DUALPI2 is not set
CONFIG_NET_SCH_DEFAULT=y
# CONFIG_DEFAULT_FQ is not set
CONFIG_DEFAULT_CODEL=y
# CONFIG_DEFAULT_FQ_CODEL is not set
# CONFIG_DEFAULT_FQ_PIE is not set
# CONFIG_DEFAULT_SFQ is not set
# CONFIG_DEFAULT_PFIFO_FAST is not set
CONFIG_DEFAULT_NET_SCH="pfifo_fast"

#
# Classification
#
CONFIG_NET_CLS=y
CONFIG_NET_CLS_BASIC=y
CONFIG_NET_CLS_ROUTE4=y
CONFIG_NET_CLS_FW=y
CONFIG_NET_CLS_U32=y
CONFIG_CLS_U32_PERF=y
CONFIG_CLS_U32_MARK=y
CONFIG_NET_CLS_FLOW=y
CONFIG_NET_CLS_CGROUP=y
CONFIG_NET_CLS_BPF=y
CONFIG_NET_CLS_FLOWER=y
CONFIG_NET_CLS_MATCHALL=y
CONFIG_NET_EMATCH=y
CONFIG_NET_EMATCH_STACK=32
CONFIG_NET_EMATCH_CMP=y
CONFIG_NET_EMATCH_NBYTE=y
CONFIG_NET_EMATCH_U32=y
CONFIG_NET_EMATCH_META=y
CONFIG_NET_EMATCH_TEXT=y
CONFIG_NET_EMATCH_CANID=y
CONFIG_NET_EMATCH_IPT=y
CONFIG_NET_CLS_ACT=y
CONFIG_NET_ACT_POLICE=y
CONFIG_NET_ACT_GACT=y
CONFIG_GACT_PROB=y
CONFIG_NET_ACT_MIRRED=y
CONFIG_NET_ACT_SAMPLE=y
CONFIG_NET_ACT_NAT=y
CONFIG_NET_ACT_PEDIT=y
CONFIG_NET_ACT_SIMP=y
CONFIG_NET_ACT_SKBEDIT=y
CONFIG_NET_ACT_CSUM=y
# CONFIG_NET_ACT_MPLS is not set
CONFIG_NET_ACT_VLAN=y
CONFIG_NET_ACT_BPF=y
CONFIG_NET_ACT_CONNMARK=y
CONFIG_NET_ACT_CTINFO=y
CONFIG_NET_ACT_SKBMOD=y
CONFIG_NET_ACT_IFE=y
CONFIG_NET_ACT_TUNNEL_KEY=y
CONFIG_NET_ACT_CT=y
CONFIG_NET_ACT_GATE=y
CONFIG_NET_IFE_SKBMARK=y
CONFIG_NET_IFE_SKBPRIO=y
CONFIG_NET_IFE_SKBTCINDEX=y
CONFIG_NET_TC_SKB_EXT=y
CONFIG_NET_SCH_FIFO=y
CONFIG_DCB=y
CONFIG_DNS_RESOLVER=y
# CONFIG_BATMAN_ADV is not set
# CONFIG_OPENVSWITCH is not set
CONFIG_VSOCKETS=y
CONFIG_VSOCKETS_DIAG=y
CONFIG_VSOCKETS_LOOPBACK=y
CONFIG_VIRTIO_VSOCKETS=y
CONFIG_VIRTIO_VSOCKETS_COMMON=y
CONFIG_NETLINK_DIAG=y
# CONFIG_MPLS is not set
# CONFIG_NET_NSH is not set
CONFIG_HSR=y
CONFIG_NET_SWITCHDEV=y
CONFIG_NET_L3_MASTER_DEV=y
# CONFIG_QRTR is not set
CONFIG_NET_NCSI=y
# CONFIG_NCSI_OEM_CMD_GET_MAC is not set
# CONFIG_NCSI_OEM_CMD_KEEP_PHY is not set
# CONFIG_PCPU_DEV_REFCNT is not set
CONFIG_MAX_SKB_FRAGS=17
CONFIG_RPS=y
CONFIG_RFS_ACCEL=y
CONFIG_SOCK_RX_QUEUE_MAPPING=y
CONFIG_XPS=y
CONFIG_CGROUP_NET_PRIO=y
CONFIG_CGROUP_NET_CLASSID=y
CONFIG_NET_RX_BUSY_POLL=y
CONFIG_BQL=y
# CONFIG_BPF_STREAM_PARSER is not set
CONFIG_NET_FLOW_LIMIT=y

#
# Network testing
#
# CONFIG_NET_PKTGEN is not set
CONFIG_NET_DROP_MONITOR=y
# end of Network testing
# end of Networking options

CONFIG_CAN=y
CONFIG_CAN_RAW=y
CONFIG_CAN_BCM=y
CONFIG_CAN_GW=y
CONFIG_CAN_J1939=y
CONFIG_CAN_ISOTP=y
# CONFIG_BT is not set
# CONFIG_AF_RXRPC is not set
CONFIG_AF_KCM=y
CONFIG_STREAM_PARSER=y
CONFIG_MCTP=y
CONFIG_FIB_RULES=y
CONFIG_WIRELESS=y
# CONFIG_CFG80211 is not set

#
# CFG80211 needs to be enabled for MAC80211
#
CONFIG_MAC80211_STA_HASH_MAX_SIZE=0
CONFIG_RFKILL=y
CONFIG_RFKILL_LEDS=y
CONFIG_RFKILL_INPUT=y
# CONFIG_RFKILL_GPIO is not set
CONFIG_NET_9P=y
CONFIG_NET_9P_FD=y
CONFIG_NET_9P_VIRTIO=y
# CONFIG_NET_9P_USBG is not set
CONFIG_NET_9P_RDMA=y
# CONFIG_NET_9P_DEBUG is not set
CONFIG_CEPH_LIB=y
# CONFIG_CEPH_LIB_PRETTYDEBUG is not set
CONFIG_CEPH_LIB_USE_DNS_RESOLVER=y
CONFIG_NFC=y
CONFIG_NFC_DIGITAL=y
CONFIG_NFC_NCI=y
# CONFIG_NFC_NCI_SPI is not set
CONFIG_NFC_NCI_UART=y
CONFIG_NFC_HCI=y
CONFIG_NFC_SHDLC=y

#
# Near Field Communication (NFC) devices
#
# CONFIG_NFC_TRF7970A is not set
CONFIG_NFC_SIM=y
CONFIG_NFC_PORT100=y
CONFIG_NFC_VIRTUAL_NCI=y
CONFIG_NFC_FDP=y
# CONFIG_NFC_FDP_I2C is not set
# CONFIG_NFC_PN544_I2C is not set
CONFIG_NFC_PN533=y
CONFIG_NFC_PN533_USB=y
# CONFIG_NFC_PN533_I2C is not set
# CONFIG_NFC_PN532_UART is not set
# CONFIG_NFC_MICROREAD_I2C is not set
CONFIG_NFC_MRVL=y
CONFIG_NFC_MRVL_USB=y
# CONFIG_NFC_MRVL_UART is not set
# CONFIG_NFC_MRVL_I2C is not set
# CONFIG_NFC_ST21NFCA_I2C is not set
# CONFIG_NFC_ST_NCI_I2C is not set
# CONFIG_NFC_ST_NCI_SPI is not set
# CONFIG_NFC_NXP_NCI is not set
# CONFIG_NFC_S3FWRN5_I2C is not set
# CONFIG_NFC_S3FWRN82_UART is not set
# CONFIG_NFC_ST95HF is not set
# end of Near Field Communication (NFC) devices

CONFIG_PSAMPLE=y
CONFIG_NET_IFE=y
CONFIG_LWTUNNEL=y
CONFIG_LWTUNNEL_BPF=y
CONFIG_DST_CACHE=y
CONFIG_GRO_CELLS=y
CONFIG_SOCK_VALIDATE_XMIT=y
CONFIG_NET_SELFTESTS=y
CONFIG_NET_SOCK_MSG=y
CONFIG_NET_DEVLINK=y
CONFIG_PAGE_POOL=y
# CONFIG_PAGE_POOL_STATS is not set
CONFIG_FAILOVER=y
CONFIG_ETHTOOL_NETLINK=y

#
# Device Drivers
#
CONFIG_ARM_AMBA=y
CONFIG_HAVE_PCI=y
CONFIG_GENERIC_PCI_IOMAP=y
CONFIG_PCI=y
CONFIG_PCI_DOMAINS=y
CONFIG_PCI_DOMAINS_GENERIC=y
CONFIG_PCIEPORTBUS=y
CONFIG_HOTPLUG_PCI_PCIE=y
CONFIG_PCIEAER=y
# CONFIG_PCIEAER_INJECT is not set
# CONFIG_PCIE_ECRC is not set
CONFIG_PCIEASPM=y
CONFIG_PCIEASPM_DEFAULT=y
# CONFIG_PCIEASPM_POWERSAVE is not set
# CONFIG_PCIEASPM_POWER_SUPERSAVE is not set
# CONFIG_PCIEASPM_PERFORMANCE is not set
CONFIG_PCIE_PME=y
# CONFIG_PCIE_DPC is not set
# CONFIG_PCIE_PTM is not set
CONFIG_PCI_MSI=y
CONFIG_PCI_QUIRKS=y
# CONFIG_PCI_DEBUG is not set
# CONFIG_PCI_STUB is not set
# CONFIG_PCI_TSM is not set
# CONFIG_PCI_DOE is not set
CONFIG_PCI_ECAM=y
# CONFIG_PCI_IOV is not set
# CONFIG_PCI_NPEM is not set
# CONFIG_PCI_PRI is not set
# CONFIG_PCI_PASID is not set
# CONFIG_PCIE_TPH is not set
CONFIG_PCI_LABEL=y
# CONFIG_PCI_DYNAMIC_OF_NODES is not set
# CONFIG_PCIE_BUS_TUNE_OFF is not set
CONFIG_PCIE_BUS_DEFAULT=y
# CONFIG_PCIE_BUS_SAFE is not set
# CONFIG_PCIE_BUS_PERFORMANCE is not set
# CONFIG_PCIE_BUS_PEER2PEER is not set
CONFIG_VGA_ARB=y
CONFIG_VGA_ARB_MAX_GPUS=16
CONFIG_HOTPLUG_PCI=y
# CONFIG_HOTPLUG_PCI_ACPI is not set
# CONFIG_HOTPLUG_PCI_CPCI is not set
# CONFIG_HOTPLUG_PCI_OCTEONEP is not set
# CONFIG_HOTPLUG_PCI_SHPC is not set

#
# PCI controller drivers
#
CONFIG_PCI_HOST_COMMON=y
# CONFIG_PCI_FTPCI100 is not set
CONFIG_PCI_HOST_GENERIC=y
CONFIG_PCIE_XILINX=y

#
# Cadence-based PCIe controllers
#
# CONFIG_PCIE_CADENCE_PLAT_HOST is not set
# CONFIG_PCIE_CADENCE_PLAT_EP is not set
# CONFIG_PCIE_SG2042_HOST is not set
# end of Cadence-based PCIe controllers

#
# DesignWare-based PCIe controllers
#
CONFIG_PCIE_DW=y
# CONFIG_PCIE_DW_DEBUGFS is not set
CONFIG_PCIE_DW_HOST=y
# CONFIG_PCI_MESON is not set
# CONFIG_PCIE_ANDES_QILAI is not set
# CONFIG_PCIE_DW_PLAT_HOST is not set
# CONFIG_PCIE_DW_PLAT_EP is not set
CONFIG_PCIE_FU740=y
# CONFIG_PCIE_SOPHGO_DW is not set
CONFIG_PCIE_SPACEMIT_K1=y
# end of DesignWare-based PCIe controllers

#
# Mobiveil-based PCIe controllers
#
# end of Mobiveil-based PCIe controllers

#
# PLDA-based PCIe controllers
#
CONFIG_PCIE_PLDA_HOST=y
# CONFIG_PCIE_MICROCHIP_HOST is not set
CONFIG_PCIE_STARFIVE_HOST=y
# end of PLDA-based PCIe controllers
# end of PCI controller drivers

#
# PCI Endpoint
#
CONFIG_PCI_ENDPOINT=y
# CONFIG_PCI_ENDPOINT_CONFIGFS is not set
# CONFIG_PCI_ENDPOINT_MSI_DOORBELL is not set
# CONFIG_PCI_EPF_TEST is not set
# CONFIG_PCI_EPF_NTB is not set
# end of PCI Endpoint

#
# PCI switch controller drivers
#
# CONFIG_PCI_SW_SWITCHTEC is not set
# end of PCI switch controller drivers

CONFIG_PCI_PWRCTRL=y
CONFIG_PCI_PWRCTRL_GENERIC=y
# CONFIG_PCI_PWRCTRL_TC9563 is not set
# CONFIG_CXL_BUS is not set
CONFIG_PCCARD=y
CONFIG_PCMCIA=y
# CONFIG_PCMCIA_LOAD_CIS is not set
# CONFIG_CARDBUS is not set

#
# PC-card bridges
#
# CONFIG_YENTA is not set
# CONFIG_PD6729 is not set
# CONFIG_RAPIDIO is not set
# CONFIG_PC104 is not set

#
# Generic Driver Options
#
CONFIG_AUXILIARY_BUS=y
CONFIG_UEVENT_HELPER=y
CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y
# CONFIG_DEVTMPFS_SAFE is not set
CONFIG_DRIVER_DEFERRED_PROBE_TIMEOUT=10
CONFIG_STANDALONE=y
CONFIG_PREVENT_FIRMWARE_BUILD=y

#
# Firmware loader
#
CONFIG_FW_LOADER=y
# CONFIG_FW_LOADER_DEBUG is not set
CONFIG_FW_LOADER_PAGED_BUF=y
CONFIG_FW_LOADER_SYSFS=y
CONFIG_EXTRA_FIRMWARE=""
CONFIG_FW_LOADER_USER_HELPER=y
CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
CONFIG_FW_LOADER_COMPRESS=y
# CONFIG_FW_LOADER_COMPRESS_XZ is not set
# CONFIG_FW_LOADER_COMPRESS_ZSTD is not set
CONFIG_FW_CACHE=y
# CONFIG_FW_UPLOAD is not set
# end of Firmware loader

CONFIG_ALLOW_DEV_COREDUMP=y
# CONFIG_DEBUG_DRIVER is not set
CONFIG_DEBUG_DEVRES=y
# CONFIG_DEBUG_TEST_DRIVER_REMOVE is not set
# CONFIG_TEST_ASYNC_DRIVER_PROBE is not set
CONFIG_GENERIC_CPU_DEVICES=y
CONFIG_GENERIC_CPU_VULNERABILITIES=y
CONFIG_REGMAP=y
CONFIG_REGMAP_I2C=y
CONFIG_REGMAP_SPI=y
CONFIG_REGMAP_MMIO=y
CONFIG_REGMAP_IRQ=y
CONFIG_DMA_SHARED_BUFFER=y
# CONFIG_DMA_FENCE_TRACE is not set
CONFIG_GENERIC_ARCH_TOPOLOGY=y
CONFIG_GENERIC_ARCH_NUMA=y
# CONFIG_FW_DEVLINK_SYNC_STATE_TIMEOUT is not set
# end of Generic Driver Options

#
# Bus devices
#
# CONFIG_MOXTET is not set
# CONFIG_SUN50I_DE2_BUS is not set
# CONFIG_SUNXI_RSB is not set
# CONFIG_MHI_BUS is not set
# CONFIG_MHI_BUS_EP is not set
# end of Bus devices

CONFIG_CACHEMAINT_FOR_DMA=y
# CONFIG_AX45MP_L2_CACHE is not set
CONFIG_SIFIVE_CCACHE=y
# CONFIG_STARFIVE_STARLINK_CACHE is not set
CONFIG_CONNECTOR=y
# CONFIG_PROC_EVENTS is not set

#
# Firmware Drivers
#

#
# ARM System Control and Management Interface Protocol
#
# end of ARM System Control and Management Interface Protocol

# CONFIG_FIRMWARE_MEMMAP is not set
CONFIG_DMIID=y
# CONFIG_DMI_SYSFS is not set
# CONFIG_ISCSI_IBFT is not set
# CONFIG_FW_CFG_SYSFS is not set
# CONFIG_SYSFB_SIMPLEFB is not set
# CONFIG_TH1520_AON_PROTOCOL is not set
CONFIG_GOOGLE_FIRMWARE=y
# CONFIG_GOOGLE_CBMEM is not set
CONFIG_GOOGLE_COREBOOT_TABLE=y
CONFIG_GOOGLE_MEMCONSOLE=y
# CONFIG_GOOGLE_FRAMEBUFFER_COREBOOT is not set
CONFIG_GOOGLE_MEMCONSOLE_COREBOOT=y
CONFIG_GOOGLE_VPD=y

#
# EFI (Extensible Firmware Interface) Support
#
CONFIG_EFI_ESRT=y
# CONFIG_EFI_VARS_PSTORE is not set
CONFIG_EFI_PARAMS_FROM_FDT=y
CONFIG_EFI_RUNTIME_WRAPPERS=y
CONFIG_EFI_GENERIC_STUB=y
# CONFIG_EFI_ZBOOT is not set
# CONFIG_EFI_BOOTLOADER_CONTROL is not set
# CONFIG_EFI_CAPSULE_LOADER is not set
# CONFIG_EFI_TEST is not set
# CONFIG_RESET_ATTACK_MITIGATION is not set
# CONFIG_EFI_DISABLE_PCI_DMA is not set
CONFIG_EFI_EARLYCON=y
# CONFIG_EFI_CUSTOM_SSDT_OVERLAYS is not set
# CONFIG_EFI_DISABLE_RUNTIME is not set
# CONFIG_EFI_COCO_SECRET is not set
# CONFIG_OVMF_DEBUG_LOG is not set
# end of EFI (Extensible Firmware Interface) Support

#
# Qualcomm firmware drivers
#
# end of Qualcomm firmware drivers

#
# Tegra firmware driver
#
# end of Tegra firmware driver
# end of Firmware Drivers

# CONFIG_FWCTL is not set
CONFIG_GNSS=y
# CONFIG_GNSS_MTK_SERIAL is not set
# CONFIG_GNSS_SIRF_SERIAL is not set
# CONFIG_GNSS_UBX_SERIAL is not set
CONFIG_GNSS_USB=y
CONFIG_MTD=y
# CONFIG_MTD_TESTS is not set

#
# Partition parsers
#
# CONFIG_MTD_CMDLINE_PARTS is not set
CONFIG_MTD_OF_PARTS=y
# CONFIG_MTD_REDBOOT_PARTS is not set
# end of Partition parsers

#
# User Modules And Translation Layers
#
CONFIG_MTD_BLKDEVS=y
CONFIG_MTD_BLOCK=y

#
# Note that in some cases UBI block is preferred. See MTD_UBI_BLOCK.
#
CONFIG_FTL=y
# CONFIG_NFTL is not set
# CONFIG_INFTL is not set
# CONFIG_RFD_FTL is not set
# CONFIG_SSFDC is not set
# CONFIG_SM_FTL is not set
# CONFIG_MTD_OOPS is not set
# CONFIG_MTD_SWAP is not set
# CONFIG_MTD_PARTITIONED_MASTER is not set

#
# RAM/ROM/Flash chip drivers
#
CONFIG_MTD_CFI=y
# CONFIG_MTD_JEDECPROBE is not set
CONFIG_MTD_GEN_PROBE=y
CONFIG_MTD_CFI_ADV_OPTIONS=y
CONFIG_MTD_CFI_NOSWAP=y
# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
# CONFIG_MTD_CFI_GEOMETRY is not set
CONFIG_MTD_MAP_BANK_WIDTH_1=y
CONFIG_MTD_MAP_BANK_WIDTH_2=y
CONFIG_MTD_MAP_BANK_WIDTH_4=y
CONFIG_MTD_CFI_I1=y
CONFIG_MTD_CFI_I2=y
# CONFIG_MTD_OTP is not set
# CONFIG_MTD_CFI_INTELEXT is not set
# CONFIG_MTD_CFI_AMDSTD is not set
# CONFIG_MTD_CFI_STAA is not set
CONFIG_MTD_CFI_UTIL=y
# CONFIG_MTD_RAM is not set
# CONFIG_MTD_ROM is not set
# CONFIG_MTD_ABSENT is not set
# end of RAM/ROM/Flash chip drivers

#
# Mapping drivers for chip access
#
# CONFIG_MTD_COMPLEX_MAPPINGS is not set
# CONFIG_MTD_PHYSMAP is not set
# CONFIG_MTD_PLATRAM is not set
# end of Mapping drivers for chip access

#
# Self-contained MTD device drivers
#
# CONFIG_MTD_PMC551 is not set
# CONFIG_MTD_DATAFLASH is not set
# CONFIG_MTD_MCHP23K256 is not set
# CONFIG_MTD_MCHP48L640 is not set
# CONFIG_MTD_SST25L is not set
CONFIG_MTD_SLRAM=y
CONFIG_MTD_PHRAM=y
CONFIG_MTD_MTDRAM=y
CONFIG_MTDRAM_TOTAL_SIZE=128
CONFIG_MTDRAM_ERASE_SIZE=4
CONFIG_MTD_BLOCK2MTD=y

#
# Disk-On-Chip Device Drivers
#
# CONFIG_MTD_DOCG3 is not set
# end of Self-contained MTD device drivers

#
# NAND
#
# CONFIG_MTD_ONENAND is not set
# CONFIG_MTD_RAW_NAND is not set
# CONFIG_MTD_SPI_NAND is not set

#
# ECC engine support
#
# CONFIG_MTD_NAND_ECC_SW_HAMMING is not set
# CONFIG_MTD_NAND_ECC_SW_BCH is not set
# CONFIG_MTD_NAND_ECC_MXIC is not set
# end of ECC engine support
# end of NAND

#
# LPDDR & LPDDR2 PCM memory drivers
#
# CONFIG_MTD_LPDDR is not set
# end of LPDDR & LPDDR2 PCM memory drivers

CONFIG_MTD_SPI_NOR=y
CONFIG_MTD_SPI_NOR_USE_4K_SECTORS=y
# CONFIG_MTD_SPI_NOR_SWP_DISABLE is not set
CONFIG_MTD_SPI_NOR_SWP_DISABLE_ON_VOLATILE=y
# CONFIG_MTD_SPI_NOR_SWP_KEEP is not set
CONFIG_MTD_UBI=y
CONFIG_MTD_UBI_WL_THRESHOLD=4096
CONFIG_MTD_UBI_BEB_LIMIT=20
# CONFIG_MTD_UBI_FASTMAP is not set
# CONFIG_MTD_UBI_GLUEBI is not set
# CONFIG_MTD_UBI_BLOCK is not set
# CONFIG_MTD_UBI_FAULT_INJECTION is not set
# CONFIG_MTD_UBI_NVMEM is not set
# CONFIG_MTD_HYPERBUS is not set
CONFIG_DTC=y
CONFIG_OF=y
# CONFIG_OF_UNITTEST is not set
CONFIG_OF_FLATTREE=y
CONFIG_OF_EARLY_FLATTREE=y
CONFIG_OF_KOBJ=y
CONFIG_OF_ADDRESS=y
CONFIG_OF_IRQ=y
CONFIG_OF_RESERVED_MEM=y
# CONFIG_OF_OVERLAY is not set
CONFIG_OF_NUMA=y
CONFIG_PARPORT=y
# CONFIG_PARPORT_PC is not set
# CONFIG_PARPORT_1284 is not set
CONFIG_PARPORT_NOT_PC=y
CONFIG_PNP=y
CONFIG_PNP_DEBUG_MESSAGES=y

#
# Protocols
#
CONFIG_PNPACPI=y
CONFIG_BLK_DEV=y
CONFIG_BLK_DEV_NULL_BLK=y
CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION=y
CONFIG_CDROM=y
# CONFIG_BLK_DEV_PCIESSD_MTIP32XX is not set
CONFIG_ZRAM=y
# CONFIG_ZRAM_BACKEND_LZ4 is not set
# CONFIG_ZRAM_BACKEND_LZ4HC is not set
# CONFIG_ZRAM_BACKEND_ZSTD is not set
# CONFIG_ZRAM_BACKEND_DEFLATE is not set
# CONFIG_ZRAM_BACKEND_842 is not set
CONFIG_ZRAM_BACKEND_FORCE_LZO=y
CONFIG_ZRAM_BACKEND_LZO=y
# CONFIG_ZRAM_DEF_COMP_LZORLE is not set
CONFIG_ZRAM_DEF_COMP_LZO=y
CONFIG_ZRAM_DEF_COMP="lzo"
# CONFIG_ZRAM_WRITEBACK is not set
# CONFIG_ZRAM_TRACK_ENTRY_ACTIME is not set
# CONFIG_ZRAM_MEMORY_TRACKING is not set
# CONFIG_ZRAM_MULTI_COMP is not set
CONFIG_BLK_DEV_LOOP=y
CONFIG_BLK_DEV_LOOP_MIN_COUNT=16
# CONFIG_BLK_DEV_DRBD is not set
CONFIG_BLK_DEV_NBD=y
CONFIG_BLK_DEV_RAM=y
CONFIG_BLK_DEV_RAM_COUNT=16
CONFIG_BLK_DEV_RAM_SIZE=4096
CONFIG_ATA_OVER_ETH=y
CONFIG_VIRTIO_BLK=y
# CONFIG_BLK_DEV_RBD is not set
# CONFIG_BLK_DEV_UBLK is not set
CONFIG_BLK_DEV_RNBD=y
CONFIG_BLK_DEV_RNBD_CLIENT=y
# CONFIG_BLK_DEV_ZONED_LOOP is not set

#
# NVME Support
#
CONFIG_NVME_CORE=y
CONFIG_BLK_DEV_NVME=y
CONFIG_NVME_MULTIPATH=y
# CONFIG_NVME_VERBOSE_ERRORS is not set
# CONFIG_NVME_HWMON is not set
CONFIG_NVME_FABRICS=y
CONFIG_NVME_RDMA=y
CONFIG_NVME_FC=y
CONFIG_NVME_TCP=y
# CONFIG_NVME_TCP_TLS is not set
# CONFIG_NVME_HOST_AUTH is not set
CONFIG_NVME_TARGET=y
# CONFIG_NVME_TARGET_DEBUGFS is not set
# CONFIG_NVME_TARGET_PASSTHRU is not set
CONFIG_NVME_TARGET_LOOP=y
CONFIG_NVME_TARGET_RDMA=y
CONFIG_NVME_TARGET_FC=y
CONFIG_NVME_TARGET_FCLOOP=y
CONFIG_NVME_TARGET_TCP=y
# CONFIG_NVME_TARGET_TCP_TLS is not set
# CONFIG_NVME_TARGET_AUTH is not set
# CONFIG_NVME_TARGET_PCI_EPF is not set
# end of NVME Support

#
# Misc devices
#
# CONFIG_AD525X_DPOT is not set
# CONFIG_DUMMY_IRQ is not set
# CONFIG_PHANTOM is not set
# CONFIG_RPMB is not set
# CONFIG_TI_FPC202 is not set
# CONFIG_TIFM_CORE is not set
# CONFIG_ICS932S401 is not set
# CONFIG_ENCLOSURE_SERVICES is not set
# CONFIG_HP_ILO is not set
# CONFIG_APDS9802ALS is not set
# CONFIG_ISL29003 is not set
# CONFIG_ISL29020 is not set
# CONFIG_SENSORS_TSL2550 is not set
# CONFIG_SENSORS_BH1770 is not set
# CONFIG_SENSORS_APDS990X is not set
# CONFIG_HMC6352 is not set
# CONFIG_DS1682 is not set
# CONFIG_LATTICE_ECP3_CONFIG is not set
# CONFIG_SRAM is not set
# CONFIG_DW_XDATA_PCIE is not set
# CONFIG_PCI_ENDPOINT_TEST is not set
# CONFIG_XILINX_SDFEC is not set
CONFIG_MISC_RTSX=y
# CONFIG_HISI_HIKEY_USB is not set
# CONFIG_OPEN_DICE is not set
# CONFIG_NTSYNC is not set
# CONFIG_VCPU_STALL_DETECTOR is not set
# CONFIG_NSM is not set
# CONFIG_C2PORT is not set

#
# EEPROM support
#
# CONFIG_EEPROM_AT24 is not set
# CONFIG_EEPROM_AT25 is not set
# CONFIG_EEPROM_MAX6875 is not set
CONFIG_EEPROM_93CX6=y
# CONFIG_EEPROM_93XX46 is not set
# CONFIG_EEPROM_IDT_89HPESX is not set
# CONFIG_EEPROM_EE1004 is not set
# CONFIG_EEPROM_M24LR is not set
# end of EEPROM support

# CONFIG_CB710_CORE is not set
# CONFIG_SENSORS_LIS3_I2C is not set
# CONFIG_ALTERA_STAPL is not set
# CONFIG_GENWQE is not set
# CONFIG_BCM_VK is not set
# CONFIG_MISC_ALCOR_PCI is not set
# CONFIG_MISC_RTSX_PCI is not set
CONFIG_MISC_RTSX_USB=y
# CONFIG_UACCE is not set
# CONFIG_PVPANIC is not set
# CONFIG_GP_PCI1XXXX is not set
# CONFIG_MISC_RP1 is not set
# end of Misc devices

#
# SCSI device support
#
CONFIG_SCSI_MOD=y
CONFIG_RAID_ATTRS=y
CONFIG_SCSI_COMMON=y
CONFIG_SCSI=y
CONFIG_SCSI_DMA=y
CONFIG_SCSI_NETLINK=y
CONFIG_SCSI_PROC_FS=y

#
# SCSI support type (disk, tape, CD-ROM)
#
CONFIG_BLK_DEV_SD=y
CONFIG_CHR_DEV_ST=y
CONFIG_BLK_DEV_SR=y
CONFIG_CHR_DEV_SG=y
CONFIG_BLK_DEV_BSG=y
# CONFIG_CHR_DEV_SCH is not set
CONFIG_SCSI_CONSTANTS=y
CONFIG_SCSI_LOGGING=y
CONFIG_SCSI_SCAN_ASYNC=y

#
# SCSI Transports
#
CONFIG_SCSI_SPI_ATTRS=y
CONFIG_SCSI_FC_ATTRS=y
CONFIG_SCSI_ISCSI_ATTRS=y
CONFIG_SCSI_SAS_ATTRS=y
CONFIG_SCSI_SAS_LIBSAS=y
CONFIG_SCSI_SAS_ATA=y
# CONFIG_SCSI_SAS_HOST_SMP is not set
CONFIG_SCSI_SRP_ATTRS=y
# end of SCSI Transports

CONFIG_SCSI_LOWLEVEL=y
# CONFIG_ISCSI_TCP is not set
# CONFIG_ISCSI_BOOT_SYSFS is not set
# CONFIG_SCSI_CXGB3_ISCSI is not set
# CONFIG_SCSI_CXGB4_ISCSI is not set
# CONFIG_SCSI_BNX2_ISCSI is not set
# CONFIG_BE2ISCSI is not set
# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
CONFIG_SCSI_HPSA=y
# CONFIG_SCSI_3W_9XXX is not set
# CONFIG_SCSI_3W_SAS is not set
# CONFIG_SCSI_ACARD is not set
# CONFIG_SCSI_AACRAID is not set
# CONFIG_SCSI_AIC7XXX is not set
# CONFIG_SCSI_AIC79XX is not set
# CONFIG_SCSI_AIC94XX is not set
# CONFIG_SCSI_MVSAS is not set
# CONFIG_SCSI_MVUMI is not set
# CONFIG_SCSI_ADVANSYS is not set
# CONFIG_SCSI_ARCMSR is not set
# CONFIG_SCSI_ESAS2R is not set
# CONFIG_MEGARAID_NEWGEN is not set
# CONFIG_MEGARAID_LEGACY is not set
# CONFIG_MEGARAID_SAS is not set
# CONFIG_SCSI_MPT3SAS is not set
# CONFIG_SCSI_MPT2SAS is not set
# CONFIG_SCSI_MPI3MR is not set
# CONFIG_SCSI_SMARTPQI is not set
# CONFIG_SCSI_HPTIOP is not set
# CONFIG_SCSI_BUSLOGIC is not set
# CONFIG_SCSI_MYRB is not set
# CONFIG_SCSI_MYRS is not set
# CONFIG_LIBFC is not set
# CONFIG_SCSI_SNIC is not set
# CONFIG_SCSI_DMX3191D is not set
# CONFIG_SCSI_FDOMAIN_PCI is not set
# CONFIG_SCSI_IPS is not set
# CONFIG_SCSI_INITIO is not set
# CONFIG_SCSI_INIA100 is not set
# CONFIG_SCSI_STEX is not set
# CONFIG_SCSI_SYM53C8XX_2 is not set
# CONFIG_SCSI_IPR is not set
# CONFIG_SCSI_QLOGIC_1280 is not set
# CONFIG_SCSI_QLA_FC is not set
# CONFIG_SCSI_QLA_ISCSI is not set
# CONFIG_SCSI_LPFC is not set
# CONFIG_SCSI_EFCT is not set
# CONFIG_SCSI_DC395x is not set
# CONFIG_SCSI_AM53C974 is not set
# CONFIG_SCSI_WD719X is not set
# CONFIG_SCSI_DEBUG is not set
# CONFIG_SCSI_PMCRAID is not set
# CONFIG_SCSI_PM8001 is not set
# CONFIG_SCSI_BFA_FC is not set
CONFIG_SCSI_VIRTIO=y
# CONFIG_SCSI_CHELSIO_FCOE is not set
# CONFIG_SCSI_LOWLEVEL_PCMCIA is not set
# CONFIG_SCSI_DH is not set
# end of SCSI device support

CONFIG_ATA=y
CONFIG_SATA_HOST=y
CONFIG_PATA_TIMINGS=y
CONFIG_ATA_VERBOSE_ERROR=y
CONFIG_ATA_FORCE=y
CONFIG_ATA_ACPI=y
# CONFIG_SATA_ZPODD is not set
CONFIG_SATA_PMP=y

#
# Controllers with non-SFF native interface
#
CONFIG_SATA_AHCI=y
CONFIG_SATA_MOBILE_LPM_POLICY=3
CONFIG_SATA_AHCI_PLATFORM=y
# CONFIG_AHCI_DWC is not set
# CONFIG_AHCI_CEVA is not set
# CONFIG_AHCI_SUNXI is not set
# CONFIG_SATA_INIC162X is not set
# CONFIG_SATA_ACARD_AHCI is not set
# CONFIG_SATA_SIL24 is not set
CONFIG_ATA_SFF=y

#
# SFF controllers with custom DMA interface
#
# CONFIG_PDC_ADMA is not set
# CONFIG_SATA_QSTOR is not set
# CONFIG_SATA_SX4 is not set
CONFIG_ATA_BMDMA=y

#
# SATA SFF controllers with BMDMA
#
CONFIG_ATA_PIIX=y
# CONFIG_SATA_DWC is not set
# CONFIG_SATA_MV is not set
# CONFIG_SATA_NV is not set
# CONFIG_SATA_PROMISE is not set
# CONFIG_SATA_SIL is not set
# CONFIG_SATA_SIS is not set
# CONFIG_SATA_SVW is not set
# CONFIG_SATA_ULI is not set
# CONFIG_SATA_VIA is not set
# CONFIG_SATA_VITESSE is not set

#
# PATA SFF controllers with BMDMA
#
# CONFIG_PATA_ALI is not set
CONFIG_PATA_AMD=y
# CONFIG_PATA_ARTOP is not set
# CONFIG_PATA_ATIIXP is not set
# CONFIG_PATA_ATP867X is not set
# CONFIG_PATA_CMD64X is not set
# CONFIG_PATA_CYPRESS is not set
# CONFIG_PATA_EFAR is not set
# CONFIG_PATA_HPT366 is not set
# CONFIG_PATA_HPT37X is not set
# CONFIG_PATA_HPT3X2N is not set
# CONFIG_PATA_HPT3X3 is not set
# CONFIG_PATA_IT8213 is not set
# CONFIG_PATA_IT821X is not set
# CONFIG_PATA_JMICRON is not set
# CONFIG_PATA_MARVELL is not set
# CONFIG_PATA_NETCELL is not set
# CONFIG_PATA_NINJA32 is not set
# CONFIG_PATA_NS87415 is not set
CONFIG_PATA_OLDPIIX=y
# CONFIG_PATA_OPTIDMA is not set
# CONFIG_PATA_PDC2027X is not set
# CONFIG_PATA_PDC_OLD is not set
# CONFIG_PATA_RADISYS is not set
# CONFIG_PATA_RDC is not set
CONFIG_PATA_SCH=y
# CONFIG_PATA_SERVERWORKS is not set
# CONFIG_PATA_SIL680 is not set
# CONFIG_PATA_SIS is not set
# CONFIG_PATA_TOSHIBA is not set
# CONFIG_PATA_TRIFLEX is not set
# CONFIG_PATA_VIA is not set
# CONFIG_PATA_WINBOND is not set

#
# PIO-only SFF controllers
#
# CONFIG_PATA_CMD640_PCI is not set
# CONFIG_PATA_MPIIX is not set
# CONFIG_PATA_NS87410 is not set
# CONFIG_PATA_OPTI is not set
# CONFIG_PATA_PCMCIA is not set
# CONFIG_PATA_OF_PLATFORM is not set
# CONFIG_PATA_RZ1000 is not set

#
# Generic fallback / legacy drivers
#
# CONFIG_PATA_ACPI is not set
CONFIG_ATA_GENERIC=y
# CONFIG_PATA_LEGACY is not set
CONFIG_MD=y
CONFIG_BLK_DEV_MD=y
CONFIG_MD_BITMAP=y
# CONFIG_MD_LLBITMAP is not set
# CONFIG_MD_AUTODETECT is not set
# CONFIG_MD_BITMAP_FILE is not set
# CONFIG_MD_LINEAR is not set
CONFIG_MD_RAID0=y
CONFIG_MD_RAID1=y
CONFIG_MD_RAID10=y
CONFIG_MD_RAID456=y
# CONFIG_MD_CLUSTER is not set
CONFIG_BCACHE=y
# CONFIG_BCACHE_DEBUG is not set
# CONFIG_BCACHE_ASYNC_REGISTRATION is not set
CONFIG_BLK_DEV_DM_BUILTIN=y
CONFIG_BLK_DEV_DM=y
# CONFIG_DM_DEBUG is not set
CONFIG_DM_BUFIO=y
# CONFIG_DM_DEBUG_BLOCK_MANAGER_LOCKING is not set
CONFIG_DM_BIO_PRISON=y
CONFIG_DM_PERSISTENT_DATA=y
# CONFIG_DM_UNSTRIPED is not set
CONFIG_DM_CRYPT=y
CONFIG_DM_SNAPSHOT=y
CONFIG_DM_THIN_PROVISIONING=y
CONFIG_DM_CACHE=y
CONFIG_DM_CACHE_SMQ=y
CONFIG_DM_WRITECACHE=y
# CONFIG_DM_EBS is not set
# CONFIG_DM_ERA is not set
CONFIG_DM_CLONE=y
CONFIG_DM_MIRROR=y
# CONFIG_DM_LOG_USERSPACE is not set
CONFIG_DM_RAID=y
CONFIG_DM_ZERO=y
CONFIG_DM_MULTIPATH=y
CONFIG_DM_MULTIPATH_QL=y
CONFIG_DM_MULTIPATH_ST=y
# CONFIG_DM_MULTIPATH_HST is not set
# CONFIG_DM_MULTIPATH_IOA is not set
# CONFIG_DM_DELAY is not set
# CONFIG_DM_DUST is not set
# CONFIG_DM_INIT is not set
CONFIG_DM_UEVENT=y
CONFIG_DM_FLAKEY=y
CONFIG_DM_VERITY=y
# CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG is not set
CONFIG_DM_VERITY_FEC=y
# CONFIG_DM_SWITCH is not set
# CONFIG_DM_LOG_WRITES is not set
CONFIG_DM_INTEGRITY=y
CONFIG_DM_ZONED=y
CONFIG_DM_AUDIT=y
# CONFIG_DM_VDO is not set
CONFIG_TARGET_CORE=y
# CONFIG_TCM_IBLOCK is not set
# CONFIG_TCM_FILEIO is not set
# CONFIG_TCM_PSCSI is not set
# CONFIG_LOOPBACK_TARGET is not set
# CONFIG_ISCSI_TARGET is not set
# CONFIG_SBP_TARGET is not set
# CONFIG_REMOTE_TARGET is not set
# CONFIG_FUSION is not set

#
# IEEE 1394 (FireWire) support
#
CONFIG_FIREWIRE=y
CONFIG_FIREWIRE_OHCI=y
CONFIG_FIREWIRE_SBP2=y
CONFIG_FIREWIRE_NET=y
# CONFIG_FIREWIRE_NOSY is not set
# end of IEEE 1394 (FireWire) support

CONFIG_NETDEVICES=y
CONFIG_MII=y
CONFIG_NET_CORE=y
CONFIG_BONDING=y
CONFIG_DUMMY=y
CONFIG_WIREGUARD=y
# CONFIG_WIREGUARD_DEBUG is not set
# CONFIG_OVPN is not set
CONFIG_EQUALIZER=y
CONFIG_NET_FC=y
CONFIG_IFB=y
# CONFIG_NET_TEAM is not set
CONFIG_MACVLAN=y
CONFIG_MACVTAP=y
CONFIG_IPVLAN_L3S=y
CONFIG_IPVLAN=y
CONFIG_IPVTAP=y
CONFIG_VXLAN=y
CONFIG_GENEVE=y
CONFIG_BAREUDP=y
CONFIG_GTP=y
# CONFIG_PFCP is not set
# CONFIG_AMT is not set
CONFIG_MACSEC=y
CONFIG_NETCONSOLE=y
# CONFIG_NETCONSOLE_DYNAMIC is not set
# CONFIG_NETCONSOLE_EXTENDED_LOG is not set
CONFIG_NETPOLL=y
CONFIG_NET_POLL_CONTROLLER=y
CONFIG_TUN=y
CONFIG_TAP=y
CONFIG_TUN_VNET_CROSS_LE=y
CONFIG_VETH=y
CONFIG_VIRTIO_NET=y
CONFIG_NLMON=y
# CONFIG_NETKIT is not set
CONFIG_NET_VRF=y
CONFIG_VSOCKMON=y
# CONFIG_ARCNET is not set

#
# Distributed Switch Architecture drivers
#
# CONFIG_B53 is not set
# CONFIG_NET_DSA_BCM_SF2 is not set
# CONFIG_NET_DSA_LOOP is not set
# CONFIG_NET_DSA_LANTIQ_GSWIP is not set
# CONFIG_NET_DSA_MXL_GSW1XX is not set
# CONFIG_NET_DSA_MT7530 is not set
# CONFIG_NET_DSA_MV88E6060 is not set
# CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON is not set
# CONFIG_NET_DSA_MV88E6XXX is not set
# CONFIG_NET_DSA_MXL862 is not set
# CONFIG_NET_DSA_AR9331 is not set
# CONFIG_NET_DSA_QCA8K is not set
# CONFIG_NET_DSA_SJA1105 is not set
# CONFIG_NET_DSA_XRS700X_I2C is not set
# CONFIG_NET_DSA_XRS700X_MDIO is not set
# CONFIG_NET_DSA_REALTEK is not set
# CONFIG_NET_DSA_KS8995 is not set
# CONFIG_NET_DSA_SMSC_LAN9303_I2C is not set
# CONFIG_NET_DSA_SMSC_LAN9303_MDIO is not set
# CONFIG_NET_DSA_VITESSE_VSC73XX_SPI is not set
# CONFIG_NET_DSA_VITESSE_VSC73XX_PLATFORM is not set
# CONFIG_NET_DSA_YT921X is not set
# end of Distributed Switch Architecture drivers

CONFIG_ETHERNET=y
# CONFIG_NET_VENDOR_3COM is not set
# CONFIG_NET_VENDOR_ADAPTEC is not set
# CONFIG_NET_VENDOR_AGERE is not set
# CONFIG_NET_VENDOR_ALACRITECH is not set
CONFIG_NET_VENDOR_ALLWINNER=y
# CONFIG_SUN4I_EMAC is not set
# CONFIG_ALTERA_TSE is not set
CONFIG_NET_VENDOR_AMAZON=y
# CONFIG_ENA_ETHERNET is not set
# CONFIG_NET_VENDOR_AMD is not set
# CONFIG_NET_VENDOR_AQUANTIA is not set
# CONFIG_NET_VENDOR_ARC is not set
CONFIG_NET_VENDOR_ASIX=y
# CONFIG_SPI_AX88796C is not set
# CONFIG_NET_VENDOR_ATHEROS is not set
# CONFIG_NET_VENDOR_BROADCOM is not set
# CONFIG_NET_VENDOR_CADENCE is not set
# CONFIG_NET_VENDOR_CAVIUM is not set
# CONFIG_NET_VENDOR_CHELSIO is not set
CONFIG_NET_VENDOR_CISCO=y
# CONFIG_ENIC is not set
# CONFIG_NET_VENDOR_CORTINA is not set
CONFIG_NET_VENDOR_DAVICOM=y
# CONFIG_DM9051 is not set
# CONFIG_NET_VENDOR_DEC is not set
# CONFIG_NET_VENDOR_DLINK is not set
# CONFIG_NET_VENDOR_EMULEX is not set
CONFIG_NET_VENDOR_ENGLEDER=y
# CONFIG_TSNEP is not set
# CONFIG_NET_VENDOR_EZCHIP is not set
CONFIG_NET_VENDOR_FUNGIBLE=y
# CONFIG_FUN_ETH is not set
CONFIG_NET_VENDOR_GOOGLE=y
CONFIG_NET_VENDOR_HISILICON=y
# CONFIG_HIBMCGE is not set
# CONFIG_NET_VENDOR_HUAWEI is not set
CONFIG_NET_VENDOR_I825XX=y
CONFIG_NET_VENDOR_INTEL=y
CONFIG_E100=y
# CONFIG_E1000 is not set
CONFIG_E1000E=y
# CONFIG_IGB is not set
# CONFIG_IGBVF is not set
# CONFIG_IXGBE is not set
# CONFIG_IXGBEVF is not set
# CONFIG_I40E is not set
# CONFIG_I40EVF is not set
# CONFIG_ICE is not set
# CONFIG_FM10K is not set
# CONFIG_IGC is not set
# CONFIG_IDPF is not set
# CONFIG_JME is not set
CONFIG_NET_VENDOR_ADI=y
# CONFIG_ADIN1110 is not set
CONFIG_NET_VENDOR_LITEX=y
# CONFIG_LITEX_LITEETH is not set
# CONFIG_NET_VENDOR_MARVELL is not set
CONFIG_NET_VENDOR_MELLANOX=y
# CONFIG_MLX4_EN is not set
CONFIG_MLX4_CORE=y
# CONFIG_MLX4_DEBUG is not set
# CONFIG_MLX4_CORE_GEN2 is not set
# CONFIG_MLX5_CORE is not set
# CONFIG_MLXSW_CORE is not set
# CONFIG_MLXFW is not set
CONFIG_NET_VENDOR_META=y
# CONFIG_FBNIC is not set
# CONFIG_NET_VENDOR_MICREL is not set
# CONFIG_NET_VENDOR_MICROCHIP is not set
# CONFIG_NET_VENDOR_MICROSEMI is not set
CONFIG_NET_VENDOR_MICROSOFT=y
CONFIG_NET_VENDOR_MUCSE=y
# CONFIG_MGBE is not set
# CONFIG_NET_VENDOR_MYRI is not set
# CONFIG_FEALNX is not set
# CONFIG_NET_VENDOR_NI is not set
# CONFIG_NET_VENDOR_NATSEMI is not set
# CONFIG_NET_VENDOR_NETRONOME is not set
# CONFIG_NET_VENDOR_NVIDIA is not set
# CONFIG_NET_VENDOR_OKI is not set
# CONFIG_ETHOC is not set
# CONFIG_NET_VENDOR_PENSANDO is not set
# CONFIG_NET_VENDOR_QLOGIC is not set
# CONFIG_NET_VENDOR_BROCADE is not set
# CONFIG_NET_VENDOR_QUALCOMM is not set
# CONFIG_NET_VENDOR_RDC is not set
# CONFIG_NET_VENDOR_REALTEK is not set
# CONFIG_NET_VENDOR_RENESAS is not set
# CONFIG_NET_VENDOR_ROCKER is not set
# CONFIG_NET_VENDOR_SAMSUNG is not set
# CONFIG_NET_VENDOR_SEEQ is not set
# CONFIG_NET_VENDOR_SILAN is not set
# CONFIG_NET_VENDOR_SIS is not set
# CONFIG_NET_VENDOR_SOLARFLARE is not set
# CONFIG_NET_VENDOR_SMSC is not set
# CONFIG_NET_VENDOR_SOCIONEXT is not set
CONFIG_NET_VENDOR_SPACEMIT=y
CONFIG_SPACEMIT_K1_EMAC=y
# CONFIG_NET_VENDOR_STMICRO is not set
# CONFIG_NET_VENDOR_SUN is not set
# CONFIG_NET_VENDOR_SYNOPSYS is not set
# CONFIG_NET_VENDOR_TEHUTI is not set
# CONFIG_NET_VENDOR_TI is not set
CONFIG_NET_VENDOR_VERTEXCOM=y
# CONFIG_MSE102X is not set
# CONFIG_NET_VENDOR_VIA is not set
CONFIG_NET_VENDOR_WANGXUN=y
# CONFIG_NGBE is not set
# CONFIG_TXGBE is not set
# CONFIG_TXGBEVF is not set
# CONFIG_NGBEVF is not set
# CONFIG_NET_VENDOR_WIZNET is not set
# CONFIG_NET_VENDOR_XILINX is not set
# CONFIG_NET_VENDOR_XIRCOM is not set
CONFIG_FDDI=y
# CONFIG_DEFXX is not set
# CONFIG_SKFP is not set
CONFIG_PHYLINK=y
CONFIG_PHYLIB=y
CONFIG_SWPHY=y
CONFIG_PHY_PACKAGE=y
# CONFIG_LED_TRIGGER_PHY is not set
CONFIG_PHYLIB_LEDS=y
CONFIG_FIXED_PHY=y
# CONFIG_SFP is not set

#
# MII PHY device drivers
#
# CONFIG_AS21XXX_PHY is not set
# CONFIG_AIR_EN8811H_PHY is not set
# CONFIG_AMD_PHY is not set
# CONFIG_ADIN_PHY is not set
# CONFIG_ADIN1100_PHY is not set
# CONFIG_AQUANTIA_PHY is not set
CONFIG_AX88796B_PHY=y
# CONFIG_BROADCOM_PHY is not set
# CONFIG_BCM54140_PHY is not set
# CONFIG_BCM7XXX_PHY is not set
# CONFIG_BCM84881_PHY is not set
# CONFIG_BCM87XX_PHY is not set
# CONFIG_CICADA_PHY is not set
# CONFIG_CORTINA_PHY is not set
# CONFIG_DAVICOM_PHY is not set
# CONFIG_ICPLUS_PHY is not set
# CONFIG_LXT_PHY is not set
# CONFIG_INTEL_XWAY_PHY is not set
# CONFIG_LSI_ET1011C_PHY is not set
# CONFIG_MARVELL_PHY is not set
# CONFIG_MARVELL_10G_PHY is not set
# CONFIG_MARVELL_88Q2XXX_PHY is not set
# CONFIG_MARVELL_88X2222_PHY is not set
# CONFIG_MAXLINEAR_GPHY is not set
# CONFIG_MAXLINEAR_86110_PHY is not set
# CONFIG_MEDIATEK_GE_PHY is not set
CONFIG_MICREL_PHY=y
# CONFIG_MICROCHIP_T1S_PHY is not set
CONFIG_MICROCHIP_PHY=y
# CONFIG_MICROCHIP_T1_PHY is not set
CONFIG_MICROSEMI_PHY=y
CONFIG_MOTORCOMM_PHY=y
# CONFIG_NATIONAL_PHY is not set
# CONFIG_NXP_CBTX_PHY is not set
# CONFIG_NXP_C45_TJA11XX_PHY is not set
# CONFIG_NXP_TJA11XX_PHY is not set
# CONFIG_NCN26000_PHY is not set
# CONFIG_AT803X_PHY is not set
# CONFIG_QCA83XX_PHY is not set
# CONFIG_QCA808X_PHY is not set
# CONFIG_QCA807X_PHY is not set
# CONFIG_QSEMI_PHY is not set
CONFIG_REALTEK_PHY=y
# CONFIG_REALTEK_PHY_HWMON is not set
# CONFIG_RENESAS_PHY is not set
# CONFIG_ROCKCHIP_PHY is not set
CONFIG_SMSC_PHY=y
# CONFIG_STE10XP is not set
# CONFIG_TERANETICS_PHY is not set
# CONFIG_DP83822_PHY is not set
# CONFIG_DP83TC811_PHY is not set
# CONFIG_DP83848_PHY is not set
# CONFIG_DP83867_PHY is not set
# CONFIG_DP83869_PHY is not set
# CONFIG_DP83TD510_PHY is not set
# CONFIG_DP83TG720_PHY is not set
# CONFIG_VITESSE_PHY is not set
# CONFIG_XILINX_GMII2RGMII is not set
# CONFIG_PSE_CONTROLLER is not set
CONFIG_CAN_DEV=y
CONFIG_CAN_VCAN=y
CONFIG_CAN_VXCAN=y
CONFIG_CAN_NETLINK=y
CONFIG_CAN_CALC_BITTIMING=y
CONFIG_CAN_RX_OFFLOAD=y
# CONFIG_CAN_CAN327 is not set
# CONFIG_CAN_DUMMY is not set
# CONFIG_CAN_FLEXCAN is not set
# CONFIG_CAN_GRCAN is not set
# CONFIG_CAN_KVASER_PCIEFD is not set
CONFIG_CAN_SLCAN=y
# CONFIG_CAN_SUN4I is not set
# CONFIG_CAN_C_CAN is not set
# CONFIG_CAN_CC770 is not set
# CONFIG_CAN_CTUCANFD_PCI is not set
# CONFIG_CAN_CTUCANFD_PLATFORM is not set
# CONFIG_CAN_ESD_402_PCI is not set
CONFIG_CAN_IFI_CANFD=y
# CONFIG_CAN_M_CAN is not set
# CONFIG_CAN_PEAK_PCIEFD is not set
# CONFIG_CAN_SJA1000 is not set
# CONFIG_CAN_SOFTING is not set

#
# CAN SPI interfaces
#
# CONFIG_CAN_HI311X is not set
# CONFIG_CAN_MCP251X is not set
# CONFIG_CAN_MCP251XFD is not set
# end of CAN SPI interfaces

#
# CAN USB interfaces
#
CONFIG_CAN_8DEV_USB=y
CONFIG_CAN_EMS_USB=y
CONFIG_CAN_ESD_USB=y
CONFIG_CAN_ETAS_ES58X=y
CONFIG_CAN_F81604=y
CONFIG_CAN_GS_USB=y
CONFIG_CAN_KVASER_USB=y
CONFIG_CAN_MCBA_USB=y
CONFIG_CAN_PEAK_USB=y
CONFIG_CAN_UCAN=y
# end of CAN USB interfaces

# CONFIG_CAN_DEBUG_DEVICES is not set

#
# MCTP Device Drivers
#
# CONFIG_MCTP_SERIAL is not set
# CONFIG_MCTP_TRANSPORT_I2C is not set
# CONFIG_MCTP_TRANSPORT_USB is not set
# end of MCTP Device Drivers

CONFIG_FWNODE_MDIO=y
CONFIG_OF_MDIO=y
CONFIG_ACPI_MDIO=y
# CONFIG_MDIO_SUN4I is not set
# CONFIG_MDIO_BITBANG is not set
# CONFIG_MDIO_BCM_UNIMAC is not set
# CONFIG_MDIO_HISI_FEMAC is not set
CONFIG_MDIO_MVUSB=y
# CONFIG_MDIO_MSCC_MIIM is not set
# CONFIG_MDIO_OCTEON is not set
# CONFIG_MDIO_PIC64HPSC is not set
# CONFIG_MDIO_IPQ4019 is not set
# CONFIG_MDIO_IPQ8064 is not set
# CONFIG_MDIO_THUNDER is not set

#
# MDIO Multiplexers
#
# CONFIG_MDIO_BUS_MUX_GPIO is not set
# CONFIG_MDIO_BUS_MUX_MULTIPLEXER is not set
# CONFIG_MDIO_BUS_MUX_MMIOREG is not set

#
# PCS device drivers
#
CONFIG_PCS_XPCS=y
# end of PCS device drivers

# CONFIG_PLIP is not set
# CONFIG_PPP is not set
# CONFIG_SLIP is not set
CONFIG_USB_NET_DRIVERS=y
CONFIG_USB_CATC=y
CONFIG_USB_KAWETH=y
CONFIG_USB_PEGASUS=y
CONFIG_USB_RTL8150=y
CONFIG_USB_RTL8152=y
CONFIG_USB_LAN78XX=y
CONFIG_USB_USBNET=y
CONFIG_USB_NET_AX8817X=y
CONFIG_USB_NET_AX88179_178A=y
CONFIG_USB_NET_CDCETHER=y
CONFIG_USB_NET_CDC_EEM=y
CONFIG_USB_NET_CDC_NCM=y
CONFIG_USB_NET_HUAWEI_CDC_NCM=y
CONFIG_USB_NET_CDC_MBIM=y
CONFIG_USB_NET_DM9601=y
CONFIG_USB_NET_SR9700=y
CONFIG_USB_NET_SR9800=y
CONFIG_USB_NET_SMSC75XX=y
CONFIG_USB_NET_SMSC95XX=y
CONFIG_USB_NET_GL620A=y
CONFIG_USB_NET_NET1080=y
CONFIG_USB_NET_PLUSB=y
CONFIG_USB_NET_MCS7830=y
CONFIG_USB_NET_RNDIS_HOST=y
CONFIG_USB_NET_CDC_SUBSET_ENABLE=y
CONFIG_USB_NET_CDC_SUBSET=y
CONFIG_USB_ALI_M5632=y
CONFIG_USB_AN2720=y
CONFIG_USB_BELKIN=y
CONFIG_USB_ARMLINUX=y
CONFIG_USB_EPSON2888=y
CONFIG_USB_KC2190=y
CONFIG_USB_NET_ZAURUS=y
CONFIG_USB_NET_CX82310_ETH=y
CONFIG_USB_NET_KALMIA=y
CONFIG_USB_NET_QMI_WWAN=y
CONFIG_USB_HSO=y
CONFIG_USB_NET_INT51X1=y
CONFIG_USB_IPHETH=y
CONFIG_USB_SIERRA_NET=y
CONFIG_USB_VL600=y
CONFIG_USB_NET_CH9200=y
CONFIG_USB_NET_AQC111=y
CONFIG_USB_RTL8153_ECM=y
# CONFIG_WLAN is not set
# CONFIG_WAN is not set

#
# Wireless WAN
#
# CONFIG_WWAN is not set
# end of Wireless WAN

CONFIG_VMXNET3=y
# CONFIG_FUJITSU_ES is not set
CONFIG_USB4_NET=y
CONFIG_NETDEVSIM=y
CONFIG_NET_FAILOVER=y

#
# Input device support
#
CONFIG_INPUT=y
# CONFIG_INPUT_LEDS is not set
CONFIG_INPUT_FF_MEMLESS=y
# CONFIG_INPUT_SPARSEKMAP is not set
# CONFIG_INPUT_MATRIXKMAP is not set
CONFIG_INPUT_VIVALDIFMAP=y

#
# Userland interfaces
#
CONFIG_INPUT_MOUSEDEV=y
CONFIG_INPUT_MOUSEDEV_PSAUX=y
CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
CONFIG_INPUT_JOYDEV=y
CONFIG_INPUT_EVDEV=y

#
# Input Device Drivers
#
CONFIG_INPUT_KEYBOARD=y
# CONFIG_KEYBOARD_ADC is not set
# CONFIG_KEYBOARD_ADP5588 is not set
CONFIG_KEYBOARD_ATKBD=y
# CONFIG_KEYBOARD_QT1050 is not set
# CONFIG_KEYBOARD_QT1070 is not set
# CONFIG_KEYBOARD_QT2160 is not set
# CONFIG_KEYBOARD_DLINK_DIR685 is not set
# CONFIG_KEYBOARD_LKKBD is not set
CONFIG_KEYBOARD_GPIO=y
# CONFIG_KEYBOARD_GPIO_POLLED is not set
# CONFIG_KEYBOARD_TCA8418 is not set
# CONFIG_KEYBOARD_MATRIX is not set
# CONFIG_KEYBOARD_CHARLIEPLEX is not set
# CONFIG_KEYBOARD_LM8323 is not set
# CONFIG_KEYBOARD_LM8333 is not set
# CONFIG_KEYBOARD_MAX7359 is not set
# CONFIG_KEYBOARD_MPR121 is not set
# CONFIG_KEYBOARD_NEWTON is not set
# CONFIG_KEYBOARD_OPENCORES is not set
# CONFIG_KEYBOARD_PINEPHONE is not set
# CONFIG_KEYBOARD_SAMSUNG is not set
# CONFIG_KEYBOARD_GOLDFISH_EVENTS is not set
# CONFIG_KEYBOARD_STOWAWAY is not set
# CONFIG_KEYBOARD_SUNKBD is not set
CONFIG_KEYBOARD_SUN4I_LRADC=y
# CONFIG_KEYBOARD_OMAP4 is not set
# CONFIG_KEYBOARD_TM2_TOUCHKEY is not set
# CONFIG_KEYBOARD_TWL4030 is not set
# CONFIG_KEYBOARD_XTKBD is not set
# CONFIG_KEYBOARD_CAP11XX is not set
# CONFIG_KEYBOARD_BCM is not set
# CONFIG_KEYBOARD_CYPRESS_SF is not set
CONFIG_INPUT_MOUSE=y
CONFIG_MOUSE_PS2=y
CONFIG_MOUSE_PS2_ALPS=y
CONFIG_MOUSE_PS2_BYD=y
CONFIG_MOUSE_PS2_LOGIPS2PP=y
CONFIG_MOUSE_PS2_SYNAPTICS=y
CONFIG_MOUSE_PS2_SYNAPTICS_SMBUS=y
CONFIG_MOUSE_PS2_CYPRESS=y
CONFIG_MOUSE_PS2_TRACKPOINT=y
# CONFIG_MOUSE_PS2_ELANTECH is not set
# CONFIG_MOUSE_PS2_SENTELIC is not set
# CONFIG_MOUSE_PS2_TOUCHKIT is not set
CONFIG_MOUSE_PS2_FOCALTECH=y
CONFIG_MOUSE_PS2_SMBUS=y
# CONFIG_MOUSE_SERIAL is not set
CONFIG_MOUSE_APPLETOUCH=y
CONFIG_MOUSE_BCM5974=y
# CONFIG_MOUSE_CYAPA is not set
# CONFIG_MOUSE_ELAN_I2C is not set
# CONFIG_MOUSE_VSXXXAA is not set
# CONFIG_MOUSE_GPIO is not set
# CONFIG_MOUSE_SYNAPTICS_I2C is not set
CONFIG_MOUSE_SYNAPTICS_USB=y
CONFIG_INPUT_JOYSTICK=y
# CONFIG_JOYSTICK_ANALOG is not set
# CONFIG_JOYSTICK_A3D is not set
# CONFIG_JOYSTICK_ADC is not set
# CONFIG_JOYSTICK_ADI is not set
# CONFIG_JOYSTICK_COBRA is not set
# CONFIG_JOYSTICK_GF2K is not set
# CONFIG_JOYSTICK_GRIP is not set
# CONFIG_JOYSTICK_GRIP_MP is not set
# CONFIG_JOYSTICK_GUILLEMOT is not set
# CONFIG_JOYSTICK_INTERACT is not set
# CONFIG_JOYSTICK_SIDEWINDER is not set
# CONFIG_JOYSTICK_TMDC is not set
CONFIG_JOYSTICK_IFORCE=y
CONFIG_JOYSTICK_IFORCE_USB=y
# CONFIG_JOYSTICK_IFORCE_232 is not set
# CONFIG_JOYSTICK_WARRIOR is not set
# CONFIG_JOYSTICK_MAGELLAN is not set
# CONFIG_JOYSTICK_SPACEORB is not set
# CONFIG_JOYSTICK_SPACEBALL is not set
# CONFIG_JOYSTICK_STINGER is not set
# CONFIG_JOYSTICK_TWIDJOY is not set
# CONFIG_JOYSTICK_ZHENHUA is not set
# CONFIG_JOYSTICK_DB9 is not set
# CONFIG_JOYSTICK_GAMECON is not set
# CONFIG_JOYSTICK_TURBOGRAFX is not set
# CONFIG_JOYSTICK_AS5011 is not set
# CONFIG_JOYSTICK_JOYDUMP is not set
CONFIG_JOYSTICK_XPAD=y
CONFIG_JOYSTICK_XPAD_FF=y
CONFIG_JOYSTICK_XPAD_LEDS=y
# CONFIG_JOYSTICK_WALKERA0701 is not set
# CONFIG_JOYSTICK_PSXPAD_SPI is not set
CONFIG_JOYSTICK_PXRC=y
# CONFIG_JOYSTICK_QWIIC is not set
# CONFIG_JOYSTICK_FSIA6B is not set
# CONFIG_JOYSTICK_SENSEHAT is not set
# CONFIG_JOYSTICK_SEESAW is not set
CONFIG_INPUT_TABLET=y
CONFIG_TABLET_USB_ACECAD=y
CONFIG_TABLET_USB_AIPTEK=y
CONFIG_TABLET_USB_HANWANG=y
CONFIG_TABLET_USB_KBTAB=y
CONFIG_TABLET_USB_PEGASUS=y
# CONFIG_TABLET_SERIAL_WACOM4 is not set
CONFIG_INPUT_TOUCHSCREEN=y
# CONFIG_TOUCHSCREEN_ADS7846 is not set
# CONFIG_TOUCHSCREEN_AD7877 is not set
# CONFIG_TOUCHSCREEN_AD7879 is not set
# CONFIG_TOUCHSCREEN_ADC is not set
# CONFIG_TOUCHSCREEN_AR1021_I2C is not set
# CONFIG_TOUCHSCREEN_ATMEL_MXT is not set
# CONFIG_TOUCHSCREEN_AUO_PIXCIR is not set
# CONFIG_TOUCHSCREEN_BU21013 is not set
# CONFIG_TOUCHSCREEN_BU21029 is not set
# CONFIG_TOUCHSCREEN_CHIPONE_ICN8318 is not set
# CONFIG_TOUCHSCREEN_CHIPONE_ICN8505 is not set
# CONFIG_TOUCHSCREEN_CY8CTMA140 is not set
# CONFIG_TOUCHSCREEN_CY8CTMG110 is not set
# CONFIG_TOUCHSCREEN_CYTTSP_CORE is not set
# CONFIG_TOUCHSCREEN_CYTTSP5 is not set
# CONFIG_TOUCHSCREEN_DYNAPRO is not set
# CONFIG_TOUCHSCREEN_HAMPSHIRE is not set
# CONFIG_TOUCHSCREEN_EETI is not set
# CONFIG_TOUCHSCREEN_EGALAX is not set
# CONFIG_TOUCHSCREEN_EGALAX_SERIAL is not set
# CONFIG_TOUCHSCREEN_EXC3000 is not set
# CONFIG_TOUCHSCREEN_FUJITSU is not set
# CONFIG_TOUCHSCREEN_GOODIX is not set
# CONFIG_TOUCHSCREEN_GOODIX_BERLIN_I2C is not set
# CONFIG_TOUCHSCREEN_GOODIX_BERLIN_SPI is not set
# CONFIG_TOUCHSCREEN_HIDEEP is not set
# CONFIG_TOUCHSCREEN_HIMAX_HX852X is not set
# CONFIG_TOUCHSCREEN_HYCON_HY46XX is not set
# CONFIG_TOUCHSCREEN_HYNITRON_CSTXXX is not set
# CONFIG_TOUCHSCREEN_HYNITRON_CST816X is not set
# CONFIG_TOUCHSCREEN_ILI210X is not set
# CONFIG_TOUCHSCREEN_ILITEK is not set
# CONFIG_TOUCHSCREEN_S6SY761 is not set
# CONFIG_TOUCHSCREEN_GUNZE is not set
# CONFIG_TOUCHSCREEN_EKTF2127 is not set
# CONFIG_TOUCHSCREEN_ELAN is not set
# CONFIG_TOUCHSCREEN_ELO is not set
# CONFIG_TOUCHSCREEN_WACOM_W8001 is not set
# CONFIG_TOUCHSCREEN_WACOM_I2C is not set
# CONFIG_TOUCHSCREEN_MAX11801 is not set
# CONFIG_TOUCHSCREEN_MMS114 is not set
# CONFIG_TOUCHSCREEN_MELFAS_MIP4 is not set
# CONFIG_TOUCHSCREEN_MSG2638 is not set
# CONFIG_TOUCHSCREEN_MTOUCH is not set
# CONFIG_TOUCHSCREEN_NOVATEK_NVT_TS is not set
# CONFIG_TOUCHSCREEN_IMAGIS is not set
# CONFIG_TOUCHSCREEN_IMX6UL_TSC is not set
# CONFIG_TOUCHSCREEN_INEXIO is not set
# CONFIG_TOUCHSCREEN_PENMOUNT is not set
# CONFIG_TOUCHSCREEN_EDT_FT5X06 is not set
# CONFIG_TOUCHSCREEN_TOUCHRIGHT is not set
# CONFIG_TOUCHSCREEN_TOUCHWIN is not set
# CONFIG_TOUCHSCREEN_PIXCIR is not set
# CONFIG_TOUCHSCREEN_WDT87XX_I2C is not set
CONFIG_TOUCHSCREEN_USB_COMPOSITE=y
CONFIG_TOUCHSCREEN_USB_EGALAX=y
CONFIG_TOUCHSCREEN_USB_PANJIT=y
CONFIG_TOUCHSCREEN_USB_3M=y
CONFIG_TOUCHSCREEN_USB_ITM=y
CONFIG_TOUCHSCREEN_USB_ETURBO=y
CONFIG_TOUCHSCREEN_USB_GUNZE=y
CONFIG_TOUCHSCREEN_USB_DMC_TSC10=y
CONFIG_TOUCHSCREEN_USB_IRTOUCH=y
CONFIG_TOUCHSCREEN_USB_IDEALTEK=y
CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH=y
CONFIG_TOUCHSCREEN_USB_GOTOP=y
CONFIG_TOUCHSCREEN_USB_JASTEC=y
CONFIG_TOUCHSCREEN_USB_ELO=y
CONFIG_TOUCHSCREEN_USB_E2I=y
CONFIG_TOUCHSCREEN_USB_ZYTRONIC=y
CONFIG_TOUCHSCREEN_USB_ETT_TC45USB=y
CONFIG_TOUCHSCREEN_USB_NEXIO=y
CONFIG_TOUCHSCREEN_USB_EASYTOUCH=y
# CONFIG_TOUCHSCREEN_TOUCHIT213 is not set
# CONFIG_TOUCHSCREEN_TSC_SERIO is not set
# CONFIG_TOUCHSCREEN_TSC2004 is not set
# CONFIG_TOUCHSCREEN_TSC2005 is not set
# CONFIG_TOUCHSCREEN_TSC2007 is not set
# CONFIG_TOUCHSCREEN_RM_TS is not set
# CONFIG_TOUCHSCREEN_SILEAD is not set
# CONFIG_TOUCHSCREEN_SIS_I2C is not set
# CONFIG_TOUCHSCREEN_ST1232 is not set
# CONFIG_TOUCHSCREEN_STMFTS is not set
# CONFIG_TOUCHSCREEN_SUN4I is not set
# CONFIG_TOUCHSCREEN_SURFACE3_SPI is not set
# CONFIG_TOUCHSCREEN_SX8654 is not set
# CONFIG_TOUCHSCREEN_TPS6507X is not set
# CONFIG_TOUCHSCREEN_ZET6223 is not set
# CONFIG_TOUCHSCREEN_ZFORCE is not set
# CONFIG_TOUCHSCREEN_COLIBRI_VF50 is not set
# CONFIG_TOUCHSCREEN_ROHM_BU21023 is not set
# CONFIG_TOUCHSCREEN_IQS5XX is not set
# CONFIG_TOUCHSCREEN_IQS7211 is not set
# CONFIG_TOUCHSCREEN_ZINITIX is not set
# CONFIG_TOUCHSCREEN_HIMAX_HX83112B is not set
CONFIG_INPUT_MISC=y
# CONFIG_INPUT_AD714X is not set
# CONFIG_INPUT_ATMEL_CAPTOUCH is not set
# CONFIG_INPUT_AW86927 is not set
# CONFIG_INPUT_BMA150 is not set
# CONFIG_INPUT_E3X0_BUTTON is not set
# CONFIG_INPUT_MMA8450 is not set
# CONFIG_INPUT_GPIO_BEEPER is not set
# CONFIG_INPUT_GPIO_DECODER is not set
# CONFIG_INPUT_GPIO_VIBRA is not set
CONFIG_INPUT_ATI_REMOTE2=y
CONFIG_INPUT_KEYSPAN_REMOTE=y
# CONFIG_INPUT_KXTJ9 is not set
CONFIG_INPUT_POWERMATE=y
CONFIG_INPUT_YEALINK=y
CONFIG_INPUT_CM109=y
# CONFIG_INPUT_REGULATOR_HAPTIC is not set
# CONFIG_INPUT_RETU_PWRBUTTON is not set
# CONFIG_INPUT_AXP20X_PEK is not set
# CONFIG_INPUT_TWL4030_PWRBUTTON is not set
# CONFIG_INPUT_TWL4030_VIBRA is not set
CONFIG_INPUT_UINPUT=y
# CONFIG_INPUT_PCF8574 is not set
# CONFIG_INPUT_PWM_BEEPER is not set
# CONFIG_INPUT_PWM_VIBRA is not set
# CONFIG_INPUT_GPIO_ROTARY_ENCODER is not set
# CONFIG_INPUT_DA7280_HAPTICS is not set
# CONFIG_INPUT_ADXL34X is not set
# CONFIG_INPUT_IBM_PANEL is not set
CONFIG_INPUT_IMS_PCU=y
# CONFIG_INPUT_IQS269A is not set
# CONFIG_INPUT_IQS626A is not set
# CONFIG_INPUT_IQS7222 is not set
# CONFIG_INPUT_CMA3000 is not set
# CONFIG_INPUT_SOC_BUTTON_ARRAY is not set
# CONFIG_INPUT_DRV260X_HAPTICS is not set
# CONFIG_INPUT_DRV2665_HAPTICS is not set
# CONFIG_INPUT_DRV2667_HAPTICS is not set
CONFIG_RMI4_CORE=y
# CONFIG_RMI4_I2C is not set
# CONFIG_RMI4_SPI is not set
# CONFIG_RMI4_SMB is not set
CONFIG_RMI4_F03=y
CONFIG_RMI4_F03_SERIO=y
CONFIG_RMI4_2D_SENSOR=y
CONFIG_RMI4_F11=y
CONFIG_RMI4_F12=y
# CONFIG_RMI4_F1A is not set
# CONFIG_RMI4_F21 is not set
CONFIG_RMI4_F30=y
# CONFIG_RMI4_F34 is not set
CONFIG_RMI4_F3A=y
# CONFIG_RMI4_F55 is not set

#
# Hardware I/O ports
#
CONFIG_SERIO=y
CONFIG_SERIO_SERPORT=y
# CONFIG_SERIO_PARKBD is not set
# CONFIG_SERIO_AMBAKMI is not set
# CONFIG_SERIO_PCIPS2 is not set
CONFIG_SERIO_LIBPS2=y
# CONFIG_SERIO_RAW is not set
# CONFIG_SERIO_ALTERA_PS2 is not set
# CONFIG_SERIO_PS2MULT is not set
# CONFIG_SERIO_ARC_PS2 is not set
# CONFIG_SERIO_APBPS2 is not set
# CONFIG_SERIO_SUN4I_PS2 is not set
# CONFIG_SERIO_GPIO_PS2 is not set
CONFIG_USERIO=y
# CONFIG_GAMEPORT is not set
# end of Hardware I/O ports
# end of Input device support

#
# Character devices
#
CONFIG_TTY=y
CONFIG_VT=y
CONFIG_CONSOLE_TRANSLATIONS=y
CONFIG_VT_CONSOLE=y
CONFIG_VT_CONSOLE_SLEEP=y
CONFIG_VT_HW_CONSOLE_BINDING=y
CONFIG_UNIX98_PTYS=y
CONFIG_LEGACY_PTYS=y
CONFIG_LEGACY_PTY_COUNT=256
CONFIG_LEGACY_TIOCSTI=y
CONFIG_LDISC_AUTOLOAD=y

#
# Serial drivers
#
CONFIG_SERIAL_EARLYCON=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_PNP=y
CONFIG_SERIAL_8250_16550A_VARIANTS=y
# CONFIG_SERIAL_8250_FINTEK is not set
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_SERIAL_8250_DMA=y
CONFIG_SERIAL_8250_PCILIB=y
CONFIG_SERIAL_8250_PCI=y
# CONFIG_SERIAL_8250_EXAR is not set
# CONFIG_SERIAL_8250_CS is not set
CONFIG_SERIAL_8250_NR_UARTS=32
CONFIG_SERIAL_8250_RUNTIME_UARTS=4
CONFIG_SERIAL_8250_EXTENDED=y
CONFIG_SERIAL_8250_SHARE_IRQ=y
CONFIG_SERIAL_8250_DETECT_IRQ=y
CONFIG_SERIAL_8250_RSA=y
CONFIG_SERIAL_8250_MANY_PORTS=y
# CONFIG_SERIAL_8250_PCI1XXXX is not set
CONFIG_SERIAL_8250_DW=y
# CONFIG_SERIAL_8250_RT288X is not set
CONFIG_SERIAL_8250_PERICOM=y
CONFIG_SERIAL_OF_PLATFORM=y
CONFIG_SERIAL_8250_DWLIB=y

#
# Non-8250 serial port support
#
# CONFIG_SERIAL_AMBA_PL010 is not set
# CONFIG_SERIAL_AMBA_PL011 is not set
# CONFIG_SERIAL_EARLYCON_SEMIHOST is not set
CONFIG_SERIAL_EARLYCON_RISCV_SBI=y
# CONFIG_SERIAL_ATMEL is not set
# CONFIG_SERIAL_MAX3100 is not set
# CONFIG_SERIAL_MAX310X is not set
# CONFIG_SERIAL_UARTLITE is not set
CONFIG_SERIAL_CORE=y
CONFIG_SERIAL_CORE_CONSOLE=y
# CONFIG_SERIAL_JSM is not set
CONFIG_SERIAL_SIFIVE=y
CONFIG_SERIAL_SIFIVE_CONSOLE=y
# CONFIG_SERIAL_SCCNXP is not set
# CONFIG_SERIAL_SC16IS7XX is not set
# CONFIG_SERIAL_ALTERA_JTAGUART is not set
# CONFIG_SERIAL_ALTERA_UART is not set
# CONFIG_SERIAL_XILINX_PS_UART is not set
# CONFIG_SERIAL_ARC is not set
# CONFIG_SERIAL_RP2 is not set
# CONFIG_SERIAL_FSL_LPUART is not set
# CONFIG_SERIAL_FSL_LINFLEXUART is not set
# CONFIG_SERIAL_CONEXANT_DIGICOLOR is not set
# CONFIG_SERIAL_SPRD is not set
# end of Serial drivers

CONFIG_SERIAL_MCTRL_GPIO=y
CONFIG_SERIAL_NONSTANDARD=y
# CONFIG_MOXA_INTELLIO is not set
# CONFIG_MOXA_SMARTIO is not set
CONFIG_N_HDLC=y
# CONFIG_GOLDFISH_TTY is not set
# CONFIG_IPWIRELESS is not set
CONFIG_N_GSM=y
CONFIG_NOZOMI=y
CONFIG_NULL_TTY=y
CONFIG_HVC_DRIVER=y
# CONFIG_RPMSG_TTY is not set
CONFIG_SERIAL_DEV_BUS=y
CONFIG_SERIAL_DEV_CTRL_TTYPORT=y
CONFIG_TTY_PRINTK=y
CONFIG_TTY_PRINTK_LEVEL=6
# CONFIG_PRINTER is not set
# CONFIG_PPDEV is not set
CONFIG_VIRTIO_CONSOLE=y
# CONFIG_IPMI_HANDLER is not set
# CONFIG_SSIF_IPMI_BMC is not set
# CONFIG_IPMB_DEVICE_INTERFACE is not set
CONFIG_HW_RANDOM=y
# CONFIG_HW_RANDOM_TIMERIOMEM is not set
CONFIG_HW_RANDOM_ATMEL=y
# CONFIG_HW_RANDOM_BA431 is not set
CONFIG_HW_RANDOM_VIRTIO=y
# CONFIG_HW_RANDOM_CCTRNG is not set
# CONFIG_HW_RANDOM_XIPHERA is not set
CONFIG_HW_RANDOM_JH7110=y
# CONFIG_APPLICOM is not set
# CONFIG_DEVMEM is not set
# CONFIG_DEVPORT is not set
CONFIG_TCG_TPM=y
# CONFIG_TCG_TPM2_HMAC is not set
# CONFIG_HW_RANDOM_TPM is not set
# CONFIG_TCG_TIS is not set
# CONFIG_TCG_TIS_SPI is not set
# CONFIG_TCG_TIS_I2C is not set
# CONFIG_TCG_TIS_I2C_CR50 is not set
# CONFIG_TCG_TIS_I2C_ATMEL is not set
# CONFIG_TCG_TIS_I2C_INFINEON is not set
# CONFIG_TCG_TIS_I2C_NUVOTON is not set
# CONFIG_TCG_ATMEL is not set
# CONFIG_TCG_INFINEON is not set
CONFIG_TCG_CRB=y
# CONFIG_TCG_VTPM_PROXY is not set
# CONFIG_TCG_TIS_ST33ZP24_I2C is not set
# CONFIG_TCG_TIS_ST33ZP24_SPI is not set
CONFIG_XILLYBUS_CLASS=y
# CONFIG_XILLYBUS is not set
CONFIG_XILLYUSB=y
# end of Character devices

#
# I2C support
#
CONFIG_I2C=y
CONFIG_ACPI_I2C_OPREGION=y
CONFIG_I2C_BOARDINFO=y
CONFIG_I2C_CHARDEV=y
CONFIG_I2C_MUX=y

#
# Multiplexer I2C Chip support
#
# CONFIG_I2C_ARB_GPIO_CHALLENGE is not set
# CONFIG_I2C_MUX_GPIO is not set
# CONFIG_I2C_MUX_GPMUX is not set
# CONFIG_I2C_MUX_LTC4306 is not set
# CONFIG_I2C_MUX_PCA9541 is not set
# CONFIG_I2C_MUX_PCA954x is not set
# CONFIG_I2C_MUX_PINCTRL is not set
CONFIG_I2C_MUX_REG=y
# CONFIG_I2C_DEMUX_PINCTRL is not set
# CONFIG_I2C_MUX_MLXCPLD is not set
# end of Multiplexer I2C Chip support

CONFIG_I2C_HELPER_AUTO=y
CONFIG_I2C_ALGOBIT=y

#
# I2C Hardware Bus support
#

#
# PC SMBus host controller drivers
#
# CONFIG_I2C_ALI1535 is not set
# CONFIG_I2C_ALI1563 is not set
# CONFIG_I2C_ALI15X3 is not set
# CONFIG_I2C_AMD756 is not set
# CONFIG_I2C_AMD8111 is not set
# CONFIG_I2C_AMD_MP2 is not set
# CONFIG_I2C_I801 is not set
# CONFIG_I2C_ISCH is not set
# CONFIG_I2C_PIIX4 is not set
# CONFIG_I2C_NFORCE2 is not set
# CONFIG_I2C_NVIDIA_GPU is not set
# CONFIG_I2C_SIS5595 is not set
# CONFIG_I2C_SIS630 is not set
# CONFIG_I2C_SIS96X is not set
# CONFIG_I2C_VIA is not set
# CONFIG_I2C_VIAPRO is not set
# CONFIG_I2C_ZHAOXIN is not set

#
# ACPI drivers
#
# CONFIG_I2C_SCMI is not set

#
# I2C system bus drivers (mostly embedded / system-on-chip)
#
# CONFIG_I2C_AT91 is not set
# CONFIG_I2C_CADENCE is not set
# CONFIG_I2C_CBUS_GPIO is not set
CONFIG_I2C_DESIGNWARE_CORE=y
CONFIG_I2C_DESIGNWARE_PLATFORM=y
# CONFIG_I2C_DESIGNWARE_PCI is not set
# CONFIG_I2C_EMEV2 is not set
# CONFIG_I2C_GPIO is not set
# CONFIG_I2C_K1 is not set
# CONFIG_I2C_MICROCHIP_CORE is not set
CONFIG_I2C_MV64XXX=y
# CONFIG_I2C_NOMADIK is not set
# CONFIG_I2C_OCORES is not set
# CONFIG_I2C_PCA_PLATFORM is not set
# CONFIG_I2C_RK3X is not set
# CONFIG_I2C_SIMTEC is not set
# CONFIG_I2C_XILINX is not set

#
# External I2C/SMBus adapter drivers
#
CONFIG_I2C_DIOLAN_U2C=y
CONFIG_I2C_DLN2=y
CONFIG_I2C_LJCA=y
CONFIG_I2C_CP2615=y
# CONFIG_I2C_PARPORT is not set
# CONFIG_I2C_PCI1XXXX is not set
CONFIG_I2C_ROBOTFUZZ_OSIF=y
# CONFIG_I2C_TAOS_EVM is not set
CONFIG_I2C_TINY_USB=y
CONFIG_I2C_VIPERBOARD=y

#
# Other I2C/SMBus bus drivers
#
# CONFIG_I2C_VIRTIO is not set
# end of I2C Hardware Bus support

# CONFIG_I2C_STUB is not set
CONFIG_I2C_SLAVE=y
CONFIG_I2C_SLAVE_EEPROM=y
# CONFIG_I2C_SLAVE_TESTUNIT is not set
# CONFIG_I2C_DEBUG_CORE is not set
# CONFIG_I2C_DEBUG_ALGO is not set
# CONFIG_I2C_DEBUG_BUS is not set
# end of I2C support

# CONFIG_I3C is not set
CONFIG_I3C_OR_I2C=y
CONFIG_SPI=y
# CONFIG_SPI_DEBUG is not set
CONFIG_SPI_MASTER=y
CONFIG_SPI_MEM=y

#
# SPI Master Controller Drivers
#
# CONFIG_SPI_ALTERA is not set
# CONFIG_SPI_ATCSPI200 is not set
# CONFIG_SPI_ATMEL is not set
# CONFIG_SPI_AXI_SPI_ENGINE is not set
# CONFIG_SPI_BITBANG is not set
# CONFIG_SPI_BUTTERFLY is not set
# CONFIG_SPI_CADENCE is not set
CONFIG_SPI_CADENCE_QUADSPI=y
# CONFIG_SPI_CADENCE_XSPI is not set
# CONFIG_SPI_CH341 is not set
# CONFIG_SPI_DESIGNWARE is not set
CONFIG_SPI_DLN2=y
CONFIG_SPI_FSL_QUADSPI=y
# CONFIG_SPI_GPIO is not set
# CONFIG_SPI_LM70_LLP is not set
# CONFIG_SPI_FSL_SPI is not set
CONFIG_SPI_LJCA=y
# CONFIG_SPI_MICROCHIP_CORE_QSPI is not set
# CONFIG_SPI_MICROCHIP_CORE_SPI is not set
# CONFIG_SPI_OC_TINY is not set
# CONFIG_SPI_PCI1XXXX is not set
CONFIG_SPI_PL022=y
# CONFIG_SPI_POLARFIRE_SOC is not set
# CONFIG_SPI_SC18IS602 is not set
CONFIG_SPI_SIFIVE=y
# CONFIG_SPI_SN_F_OSPI is not set
# CONFIG_SPI_SG2044_NOR is not set
# CONFIG_SPI_SUN4I is not set
CONFIG_SPI_SUN6I=y
# CONFIG_SPI_MXIC is not set
# CONFIG_SPI_VIRTIO is not set
# CONFIG_SPI_XCOMM is not set
# CONFIG_SPI_XILINX is not set
# CONFIG_SPI_ZYNQMP_GQSPI is not set
# CONFIG_SPI_AMD is not set

#
# SPI Multiplexer support
#
# CONFIG_SPI_MUX is not set

#
# SPI Protocol Masters
#
# CONFIG_SPI_SPIDEV is not set
# CONFIG_SPI_LOOPBACK_TEST is not set
# CONFIG_SPI_TLE62X0 is not set
# CONFIG_SPI_SLAVE is not set
CONFIG_SPI_DYNAMIC=y
# CONFIG_SPMI is not set
# CONFIG_HSI is not set
# CONFIG_PPS is not set

#
# PTP clock support
#
# CONFIG_PTP_1588_CLOCK is not set
CONFIG_PTP_1588_CLOCK_OPTIONAL=y

#
# Enable PHYLIB and NETWORK_PHY_TIMESTAMPING to see the additional clocks.
#
# end of PTP clock support

#
# DPLL device support
#
# CONFIG_ZL3073X_I2C is not set
# CONFIG_ZL3073X_SPI is not set
# end of DPLL device support

CONFIG_PINCTRL=y
CONFIG_GENERIC_PINCTRL_GROUPS=y
CONFIG_PINMUX=y
CONFIG_GENERIC_PINMUX_FUNCTIONS=y
CONFIG_PINCONF=y
CONFIG_GENERIC_PINCONF=y
CONFIG_GENERIC_PINCTRL=y
# CONFIG_DEBUG_PINCTRL is not set
# CONFIG_PINCTRL_AMD is not set
# CONFIG_PINCTRL_AXP209 is not set
# CONFIG_PINCTRL_AW9523 is not set
# CONFIG_PINCTRL_CY8C95X0 is not set
# CONFIG_PINCTRL_K230 is not set
# CONFIG_PINCTRL_MCP23S08 is not set
# CONFIG_PINCTRL_MICROCHIP_SGPIO is not set
# CONFIG_PINCTRL_OCELOT is not set
# CONFIG_PINCTRL_SINGLE is not set
# CONFIG_PINCTRL_STMFX is not set
# CONFIG_PINCTRL_SX150X is not set
CONFIG_PINCTRL_TH1520=y
CONFIG_PINCTRL_PIC64GX=y
CONFIG_PINCTRL_POLARFIRE_SOC=y

#
# Renesas pinctrl drivers
#
# end of Renesas pinctrl drivers

CONFIG_PINCTRL_SOPHGO_COMMON=y
CONFIG_PINCTRL_SOPHGO_CV18XX_OPS=y
CONFIG_PINCTRL_SOPHGO_CV1800B=y
CONFIG_PINCTRL_SOPHGO_CV1812H=y
CONFIG_PINCTRL_SOPHGO_SG2000=y
CONFIG_PINCTRL_SOPHGO_SG2002=y
# CONFIG_PINCTRL_SOPHGO_SG2042 is not set
# CONFIG_PINCTRL_SOPHGO_SG2044 is not set
CONFIG_PINCTRL_SPACEMIT_K1=y
CONFIG_PINCTRL_STARFIVE_JH7100=y
CONFIG_PINCTRL_STARFIVE_JH7110=y
CONFIG_PINCTRL_STARFIVE_JH7110_SYS=y
CONFIG_PINCTRL_STARFIVE_JH7110_AON=y
CONFIG_PINCTRL_SUNXI=y
# CONFIG_PINCTRL_SUN4I_A10 is not set
# CONFIG_PINCTRL_SUN5I is not set
# CONFIG_PINCTRL_SUN6I_A31 is not set
# CONFIG_PINCTRL_SUN6I_A31_R is not set
# CONFIG_PINCTRL_SUN8I_A23 is not set
# CONFIG_PINCTRL_SUN8I_A33 is not set
# CONFIG_PINCTRL_SUN8I_A83T is not set
# CONFIG_PINCTRL_SUN8I_A83T_R is not set
# CONFIG_PINCTRL_SUN8I_A23_R is not set
# CONFIG_PINCTRL_SUN8I_H3 is not set
# CONFIG_PINCTRL_SUN8I_H3_R is not set
# CONFIG_PINCTRL_SUN8I_V3S is not set
# CONFIG_PINCTRL_SUN9I_A80 is not set
# CONFIG_PINCTRL_SUN9I_A80_R is not set
CONFIG_PINCTRL_SUN20I_D1=y
# CONFIG_PINCTRL_SUN50I_A64 is not set
# CONFIG_PINCTRL_SUN50I_A64_R is not set
# CONFIG_PINCTRL_SUN50I_A100 is not set
# CONFIG_PINCTRL_SUN50I_A100_R is not set
# CONFIG_PINCTRL_SUN50I_H5 is not set
# CONFIG_PINCTRL_SUN50I_H6 is not set
# CONFIG_PINCTRL_SUN50I_H6_R is not set
# CONFIG_PINCTRL_SUN50I_H616 is not set
# CONFIG_PINCTRL_SUN50I_H616_R is not set
# CONFIG_PINCTRL_SUN55I_A523 is not set
# CONFIG_PINCTRL_SUN55I_A523_R is not set
CONFIG_GPIOLIB_LEGACY=y
CONFIG_GPIOLIB=y
CONFIG_GPIOLIB_FASTPATH_LIMIT=512
CONFIG_OF_GPIO=y
CONFIG_GPIO_ACPI=y
CONFIG_GPIOLIB_IRQCHIP=y
# CONFIG_DEBUG_GPIO is not set
# CONFIG_GPIO_SYSFS is not set
CONFIG_GPIO_CDEV=y
CONFIG_GPIO_CDEV_V1=y
CONFIG_GPIO_GENERIC=y

#
# Memory mapped GPIO drivers
#
# CONFIG_GPIO_74XX_MMIO is not set
# CONFIG_GPIO_ALTERA is not set
# CONFIG_GPIO_AMDPT is not set
# CONFIG_GPIO_BY_PINCTRL is not set
# CONFIG_GPIO_CADENCE is not set
CONFIG_GPIO_DWAPB=y
# CONFIG_GPIO_FTGPIO010 is not set
# CONFIG_GPIO_GENERIC_PLATFORM is not set
# CONFIG_GPIO_GRGPIO is not set
# CONFIG_GPIO_HLWD is not set
# CONFIG_GPIO_LOGICVC is not set
# CONFIG_GPIO_MB86S7X is not set
# CONFIG_GPIO_PL061 is not set
# CONFIG_GPIO_POLARFIRE_SOC is not set
CONFIG_GPIO_SIFIVE=y
CONFIG_GPIO_SPACEMIT_K1=y
# CONFIG_GPIO_SYSCON is not set
# CONFIG_GPIO_XILINX is not set
# CONFIG_GPIO_AMD_FCH is not set
# end of Memory mapped GPIO drivers

#
# I2C GPIO expanders
#
# CONFIG_GPIO_ADNP is not set
# CONFIG_GPIO_FXL6408 is not set
# CONFIG_GPIO_DS4520 is not set
# CONFIG_GPIO_GW_PLD is not set
# CONFIG_GPIO_MAX7300 is not set
# CONFIG_GPIO_MAX732X is not set
# CONFIG_GPIO_PCA953X is not set
# CONFIG_GPIO_PCA9570 is not set
# CONFIG_GPIO_PCF857X is not set
# CONFIG_GPIO_TPIC2810 is not set
# end of I2C GPIO expanders

#
# MFD GPIO expanders
#
CONFIG_GPIO_DLN2=y
CONFIG_GPIO_LJCA=y
# CONFIG_GPIO_QIXIS_FPGA is not set
# CONFIG_GPIO_TWL4030 is not set
# end of MFD GPIO expanders

#
# PCI GPIO expanders
#
# CONFIG_GPIO_BT8XX is not set
# CONFIG_GPIO_PCI_IDIO_16 is not set
# CONFIG_GPIO_PCIE_IDIO_24 is not set
# CONFIG_GPIO_RDC321X is not set
# end of PCI GPIO expanders

#
# SPI GPIO expanders
#
# CONFIG_GPIO_74X164 is not set
# CONFIG_GPIO_MAX3191X is not set
# CONFIG_GPIO_MAX7301 is not set
# CONFIG_GPIO_MC33880 is not set
# CONFIG_GPIO_PISOSR is not set
# CONFIG_GPIO_XRA1403 is not set
# end of SPI GPIO expanders

#
# USB GPIO expanders
#
CONFIG_GPIO_VIPERBOARD=y
# CONFIG_GPIO_MPSSE is not set
# end of USB GPIO expanders

#
# Virtual GPIO drivers
#
# CONFIG_GPIO_AGGREGATOR is not set
# CONFIG_GPIO_LATCH is not set
# CONFIG_GPIO_LINE_MUX is not set
# CONFIG_GPIO_MOCKUP is not set
# CONFIG_GPIO_VIRTIO is not set
# CONFIG_GPIO_SIM is not set
# end of Virtual GPIO drivers

#
# GPIO Debugging utilities
#
# CONFIG_GPIO_SLOPPY_LOGIC_ANALYZER is not set
# CONFIG_GPIO_VIRTUSER is not set
# end of GPIO Debugging utilities

# CONFIG_W1 is not set
CONFIG_POWER_RESET=y
# CONFIG_POWER_RESET_GPIO is not set
CONFIG_POWER_RESET_GPIO_RESTART=y
# CONFIG_POWER_RESET_LTC2952 is not set
# CONFIG_POWER_RESET_REGULATOR is not set
# CONFIG_POWER_RESET_RESTART is not set
CONFIG_POWER_RESET_SPACEMIT_P1=y
CONFIG_POWER_RESET_SYSCON=y
CONFIG_POWER_RESET_SYSCON_POWEROFF=y
# CONFIG_SYSCON_REBOOT_MODE is not set
# CONFIG_NVMEM_REBOOT_MODE is not set
# CONFIG_POWER_RESET_QEMU_VIRT_CTRL is not set
CONFIG_POWER_SEQUENCING=y
# CONFIG_POWER_SEQUENCING_QCOM_WCN is not set
# CONFIG_POWER_SEQUENCING_TH1520_GPU is not set
# CONFIG_POWER_SEQUENCING_PCIE_M2 is not set
CONFIG_POWER_SUPPLY=y
# CONFIG_POWER_SUPPLY_DEBUG is not set
CONFIG_POWER_SUPPLY_HWMON=y
# CONFIG_GENERIC_ADC_BATTERY is not set
# CONFIG_IP5XXX_POWER is not set
# CONFIG_TEST_POWER is not set
# CONFIG_CHARGER_ADP5061 is not set
# CONFIG_BATTERY_CHAGALL is not set
# CONFIG_BATTERY_CW2015 is not set
# CONFIG_BATTERY_DS2780 is not set
# CONFIG_BATTERY_DS2781 is not set
# CONFIG_BATTERY_DS2782 is not set
# CONFIG_BATTERY_SAMSUNG_SDI is not set
# CONFIG_BATTERY_S2MU005 is not set
# CONFIG_BATTERY_SBS is not set
# CONFIG_CHARGER_SBS is not set
# CONFIG_MANAGER_SBS is not set
# CONFIG_BATTERY_BQ27XXX is not set
# CONFIG_AXP20X_POWER is not set
# CONFIG_BATTERY_MAX17040 is not set
# CONFIG_BATTERY_MAX17042 is not set
# CONFIG_BATTERY_MAX1720X is not set
CONFIG_CHARGER_ISP1704=y
# CONFIG_CHARGER_MAX8903 is not set
# CONFIG_CHARGER_TWL4030 is not set
# CONFIG_CHARGER_TWL6030 is not set
# CONFIG_CHARGER_LP8727 is not set
# CONFIG_CHARGER_GPIO is not set
# CONFIG_CHARGER_MANAGER is not set
# CONFIG_CHARGER_LT3651 is not set
# CONFIG_CHARGER_LTC4162L is not set
# CONFIG_CHARGER_DETECTOR_MAX14656 is not set
# CONFIG_CHARGER_MAX77976 is not set
# CONFIG_CHARGER_MAX8971 is not set
# CONFIG_CHARGER_MT6360 is not set
# CONFIG_CHARGER_MT6370 is not set
# CONFIG_CHARGER_BQ2415X is not set
CONFIG_CHARGER_BQ24190=y
# CONFIG_CHARGER_BQ24257 is not set
# CONFIG_CHARGER_BQ24735 is not set
# CONFIG_CHARGER_BQ2515X is not set
# CONFIG_CHARGER_BQ25890 is not set
# CONFIG_CHARGER_BQ25980 is not set
# CONFIG_CHARGER_BQ256XX is not set
# CONFIG_CHARGER_SMB347 is not set
# CONFIG_BATTERY_GAUGE_LTC2941 is not set
# CONFIG_BATTERY_GOLDFISH is not set
# CONFIG_BATTERY_RT5033 is not set
# CONFIG_CHARGER_RT9455 is not set
# CONFIG_CHARGER_RT9467 is not set
# CONFIG_CHARGER_RT9471 is not set
# CONFIG_CHARGER_RT9756 is not set
# CONFIG_FUEL_GAUGE_STC3117 is not set
# CONFIG_CHARGER_UCS1002 is not set
# CONFIG_CHARGER_BD99954 is not set
# CONFIG_BATTERY_UG3105 is not set
# CONFIG_FUEL_GAUGE_MM8013 is not set
CONFIG_HWMON=y
# CONFIG_HWMON_DEBUG_CHIP is not set

#
# Native drivers
#
# CONFIG_SENSORS_AD7314 is not set
# CONFIG_SENSORS_AD7414 is not set
# CONFIG_SENSORS_AD7418 is not set
# CONFIG_SENSORS_ADM1025 is not set
# CONFIG_SENSORS_ADM1026 is not set
# CONFIG_SENSORS_ADM1029 is not set
# CONFIG_SENSORS_ADM1031 is not set
# CONFIG_SENSORS_ADM1177 is not set
# CONFIG_SENSORS_ADM9240 is not set
# CONFIG_SENSORS_ADT7310 is not set
# CONFIG_SENSORS_ADT7410 is not set
# CONFIG_SENSORS_ADT7411 is not set
# CONFIG_SENSORS_ADT7462 is not set
# CONFIG_SENSORS_ADT7470 is not set
# CONFIG_SENSORS_ADT7475 is not set
# CONFIG_SENSORS_AHT10 is not set
CONFIG_SENSORS_AQUACOMPUTER_D5NEXT=y
# CONFIG_SENSORS_AS370 is not set
# CONFIG_SENSORS_ASC7621 is not set
# CONFIG_SENSORS_ASUS_ROG_RYUJIN is not set
# CONFIG_SENSORS_AXI_FAN_CONTROL is not set
# CONFIG_SENSORS_ATXP1 is not set
# CONFIG_SENSORS_CHIPCAP2 is not set
CONFIG_SENSORS_CORSAIR_CPRO=y
CONFIG_SENSORS_CORSAIR_PSU=y
# CONFIG_SENSORS_DRIVETEMP is not set
# CONFIG_SENSORS_DS620 is not set
# CONFIG_SENSORS_DS1621 is not set
# CONFIG_SENSORS_I5K_AMB is not set
# CONFIG_SENSORS_F71805F is not set
# CONFIG_SENSORS_F71882FG is not set
# CONFIG_SENSORS_F75375S is not set
# CONFIG_SENSORS_FTSTEUTATES is not set
CONFIG_SENSORS_GIGABYTE_WATERFORCE=y
# CONFIG_SENSORS_GL518SM is not set
# CONFIG_SENSORS_GL520SM is not set
# CONFIG_SENSORS_G760A is not set
# CONFIG_SENSORS_G762 is not set
# CONFIG_SENSORS_GPIO_FAN is not set
# CONFIG_SENSORS_HIH6130 is not set
# CONFIG_SENSORS_HS3001 is not set
# CONFIG_SENSORS_HTU31 is not set
# CONFIG_SENSORS_IIO_HWMON is not set
# CONFIG_SENSORS_ISL28022 is not set
# CONFIG_SENSORS_IT87 is not set
# CONFIG_SENSORS_JC42 is not set
CONFIG_SENSORS_POWERZ=y
# CONFIG_SENSORS_POWR1220 is not set
# CONFIG_SENSORS_LINEAGE is not set
# CONFIG_SENSORS_LTC2945 is not set
# CONFIG_SENSORS_LTC2947_I2C is not set
# CONFIG_SENSORS_LTC2947_SPI is not set
# CONFIG_SENSORS_LTC2990 is not set
# CONFIG_SENSORS_LTC2991 is not set
# CONFIG_SENSORS_LTC2992 is not set
# CONFIG_SENSORS_LTC4151 is not set
# CONFIG_SENSORS_LTC4215 is not set
# CONFIG_SENSORS_LTC4222 is not set
# CONFIG_SENSORS_LTC4245 is not set
# CONFIG_SENSORS_LTC4260 is not set
# CONFIG_SENSORS_LTC4261 is not set
# CONFIG_SENSORS_LTC4282 is not set
# CONFIG_SENSORS_MAX1111 is not set
# CONFIG_SENSORS_MAX127 is not set
# CONFIG_SENSORS_MAX16065 is not set
# CONFIG_SENSORS_MAX1619 is not set
# CONFIG_SENSORS_MAX1668 is not set
# CONFIG_SENSORS_MAX197 is not set
# CONFIG_SENSORS_MAX31722 is not set
# CONFIG_SENSORS_MAX31730 is not set
# CONFIG_SENSORS_MAX31760 is not set
# CONFIG_MAX31827 is not set
# CONFIG_SENSORS_MAX6620 is not set
# CONFIG_SENSORS_MAX6621 is not set
# CONFIG_SENSORS_MAX6639 is not set
# CONFIG_SENSORS_MAX6650 is not set
# CONFIG_SENSORS_MAX6697 is not set
# CONFIG_SENSORS_MAX31790 is not set
# CONFIG_SENSORS_MC34VR500 is not set
# CONFIG_SENSORS_MCP3021 is not set
# CONFIG_SENSORS_MCP9982 is not set
# CONFIG_SENSORS_TC654 is not set
# CONFIG_SENSORS_TPS23861 is not set
# CONFIG_SENSORS_MR75203 is not set
# CONFIG_SENSORS_ADCXX is not set
# CONFIG_SENSORS_LM63 is not set
# CONFIG_SENSORS_LM70 is not set
# CONFIG_SENSORS_LM73 is not set
# CONFIG_SENSORS_LM75 is not set
# CONFIG_SENSORS_LM77 is not set
# CONFIG_SENSORS_LM78 is not set
# CONFIG_SENSORS_LM80 is not set
# CONFIG_SENSORS_LM83 is not set
# CONFIG_SENSORS_LM85 is not set
# CONFIG_SENSORS_LM87 is not set
# CONFIG_SENSORS_LM90 is not set
# CONFIG_SENSORS_LM92 is not set
# CONFIG_SENSORS_LM93 is not set
# CONFIG_SENSORS_LM95234 is not set
# CONFIG_SENSORS_LM95241 is not set
# CONFIG_SENSORS_LM95245 is not set
# CONFIG_SENSORS_PC87360 is not set
# CONFIG_SENSORS_PC87427 is not set
# CONFIG_SENSORS_NTC_THERMISTOR is not set
# CONFIG_SENSORS_NCT6683 is not set
# CONFIG_SENSORS_NCT6775 is not set
# CONFIG_SENSORS_NCT6775_I2C is not set
# CONFIG_SENSORS_NCT7363 is not set
# CONFIG_SENSORS_NCT7802 is not set
# CONFIG_SENSORS_NCT7904 is not set
# CONFIG_SENSORS_NPCM7XX is not set
CONFIG_SENSORS_NZXT_KRAKEN2=y
# CONFIG_SENSORS_NZXT_KRAKEN3 is not set
CONFIG_SENSORS_NZXT_SMART2=y
# CONFIG_SENSORS_OCC_P8_I2C is not set
# CONFIG_SENSORS_PCF8591 is not set
# CONFIG_PMBUS is not set
# CONFIG_SENSORS_PT5161L is not set
# CONFIG_SENSORS_PWM_FAN is not set
# CONFIG_SENSORS_SBTSI is not set
# CONFIG_SENSORS_SHT15 is not set
# CONFIG_SENSORS_SHT21 is not set
# CONFIG_SENSORS_SHT3x is not set
# CONFIG_SENSORS_SHT4x is not set
# CONFIG_SENSORS_SHTC1 is not set
# CONFIG_SENSORS_SIS5595 is not set
# CONFIG_SENSORS_DME1737 is not set
# CONFIG_SENSORS_EMC1403 is not set
# CONFIG_SENSORS_EMC2103 is not set
# CONFIG_SENSORS_EMC2305 is not set
# CONFIG_SENSORS_EMC6W201 is not set
# CONFIG_SENSORS_SMSC47M1 is not set
# CONFIG_SENSORS_SMSC47M192 is not set
# CONFIG_SENSORS_SMSC47B397 is not set
# CONFIG_SENSORS_SCH5627 is not set
# CONFIG_SENSORS_SCH5636 is not set
# CONFIG_SENSORS_STTS751 is not set
CONFIG_SENSORS_SFCTEMP=y
# CONFIG_SENSORS_SG2042_MCU is not set
# CONFIG_SENSORS_ADC128D818 is not set
# CONFIG_SENSORS_ADS7828 is not set
# CONFIG_SENSORS_ADS7871 is not set
# CONFIG_SENSORS_AMC6821 is not set
# CONFIG_SENSORS_INA209 is not set
# CONFIG_SENSORS_INA2XX is not set
# CONFIG_SENSORS_INA238 is not set
# CONFIG_SENSORS_INA3221 is not set
# CONFIG_SENSORS_SPD5118 is not set
# CONFIG_SENSORS_TC74 is not set
# CONFIG_SENSORS_THMC50 is not set
# CONFIG_SENSORS_TMP102 is not set
# CONFIG_SENSORS_TMP103 is not set
# CONFIG_SENSORS_TMP108 is not set
# CONFIG_SENSORS_TMP401 is not set
# CONFIG_SENSORS_TMP421 is not set
# CONFIG_SENSORS_TMP464 is not set
# CONFIG_SENSORS_TMP513 is not set
# CONFIG_SENSORS_TSC1641 is not set
# CONFIG_SENSORS_VIA686A is not set
# CONFIG_SENSORS_VT1211 is not set
# CONFIG_SENSORS_VT8231 is not set
# CONFIG_SENSORS_W83773G is not set
# CONFIG_SENSORS_W83781D is not set
# CONFIG_SENSORS_W83791D is not set
# CONFIG_SENSORS_W83792D is not set
# CONFIG_SENSORS_W83793 is not set
# CONFIG_SENSORS_W83795 is not set
# CONFIG_SENSORS_W83L785TS is not set
# CONFIG_SENSORS_W83L786NG is not set
# CONFIG_SENSORS_W83627HF is not set
# CONFIG_SENSORS_W83627EHF is not set
# CONFIG_SENSORS_XGENE is not set
# CONFIG_SENSORS_YOGAFAN is not set

#
# ACPI drivers
#
# CONFIG_SENSORS_ACPI_POWER is not set
CONFIG_THERMAL=y
CONFIG_THERMAL_NETLINK=y
# CONFIG_THERMAL_STATISTICS is not set
# CONFIG_THERMAL_DEBUGFS is not set
# CONFIG_THERMAL_CORE_TESTING is not set
CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS=0
CONFIG_THERMAL_HWMON=y
CONFIG_THERMAL_OF=y
CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE=y
# CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE is not set
# CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE is not set
# CONFIG_THERMAL_GOV_FAIR_SHARE is not set
CONFIG_THERMAL_GOV_STEP_WISE=y
# CONFIG_THERMAL_GOV_BANG_BANG is not set
# CONFIG_THERMAL_GOV_USER_SPACE is not set
CONFIG_CPU_THERMAL=y
CONFIG_CPU_FREQ_THERMAL=y
CONFIG_DEVFREQ_THERMAL=y
# CONFIG_PCIE_THERMAL is not set
# CONFIG_THERMAL_EMULATION is not set
# CONFIG_THERMAL_MMIO is not set
# CONFIG_SUN8I_THERMAL is not set
# CONFIG_GENERIC_ADC_THERMAL is not set
CONFIG_WATCHDOG=y
CONFIG_WATCHDOG_CORE=y
# CONFIG_WATCHDOG_NOWAYOUT is not set
CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED=y
CONFIG_WATCHDOG_OPEN_TIMEOUT=0
# CONFIG_WATCHDOG_SYSFS is not set
# CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT is not set

#
# Watchdog Pretimeout Governors
#
# CONFIG_WATCHDOG_PRETIMEOUT_GOV is not set

#
# Watchdog Device Drivers
#
# CONFIG_SOFT_WATCHDOG is not set
# CONFIG_GPIO_WATCHDOG is not set
# CONFIG_WDAT_WDT is not set
# CONFIG_XILINX_WATCHDOG is not set
# CONFIG_ZIIRAVE_WATCHDOG is not set
# CONFIG_CADENCE_WATCHDOG is not set
# CONFIG_DW_WATCHDOG is not set
CONFIG_SUNXI_WATCHDOG=y
# CONFIG_TWL4030_WATCHDOG is not set
# CONFIG_MAX63XX_WATCHDOG is not set
# CONFIG_RETU_WATCHDOG is not set
# CONFIG_ALIM7101_WDT is not set
# CONFIG_I6300ESB_WDT is not set
# CONFIG_NIC7018_WDT is not set
# CONFIG_MEN_A21_WDT is not set
CONFIG_STARFIVE_WATCHDOG=y

#
# PCI-based Watchdog Cards
#
# CONFIG_PCIPCWATCHDOG is not set
# CONFIG_WDTPCI is not set

#
# USB-based Watchdog Cards
#
CONFIG_USBPCWATCHDOG=y
CONFIG_SSB_POSSIBLE=y
CONFIG_SSB=y
CONFIG_SSB_PCIHOST_POSSIBLE=y
# CONFIG_SSB_PCIHOST is not set
CONFIG_SSB_PCMCIAHOST_POSSIBLE=y
# CONFIG_SSB_PCMCIAHOST is not set
CONFIG_SSB_SDIOHOST_POSSIBLE=y
# CONFIG_SSB_SDIOHOST is not set
# CONFIG_SSB_DRIVER_GPIO is not set
CONFIG_BCMA_POSSIBLE=y
CONFIG_BCMA=y
CONFIG_BCMA_HOST_PCI_POSSIBLE=y
# CONFIG_BCMA_HOST_PCI is not set
# CONFIG_BCMA_HOST_SOC is not set
# CONFIG_BCMA_DRIVER_PCI is not set
# CONFIG_BCMA_DRIVER_GMAC_CMN is not set
# CONFIG_BCMA_DRIVER_GPIO is not set
# CONFIG_BCMA_DEBUG is not set

#
# Multifunction device drivers
#
CONFIG_MFD_CORE=y
# CONFIG_MFD_ADP5585 is not set
# CONFIG_MFD_ACT8945A is not set
# CONFIG_MFD_SUN4I_GPADC is not set
# CONFIG_MFD_AS3711 is not set
# CONFIG_MFD_SMPRO is not set
# CONFIG_MFD_AS3722 is not set
# CONFIG_PMIC_ADP5520 is not set
# CONFIG_MFD_AAT2870_CORE is not set
# CONFIG_MFD_AT91_USART is not set
# CONFIG_MFD_ATMEL_FLEXCOM is not set
# CONFIG_MFD_ATMEL_HLCDC is not set
# CONFIG_MFD_BCM590XX is not set
# CONFIG_MFD_BD9571MWV is not set
CONFIG_MFD_AXP20X=y
CONFIG_MFD_AXP20X_I2C=y
# CONFIG_MFD_CS40L50_I2C is not set
# CONFIG_MFD_CS40L50_SPI is not set
# CONFIG_MFD_CS42L43_I2C is not set
# CONFIG_MFD_CS42L43_SDW is not set
# CONFIG_MFD_LOCHNAGAR is not set
# CONFIG_MFD_MADERA is not set
# CONFIG_PMIC_DA903X is not set
# CONFIG_MFD_DA9052_SPI is not set
# CONFIG_MFD_DA9052_I2C is not set
# CONFIG_MFD_DA9055 is not set
# CONFIG_MFD_DA9062 is not set
# CONFIG_MFD_DA9063 is not set
# CONFIG_MFD_DA9150 is not set
CONFIG_MFD_DLN2=y
# CONFIG_MFD_GATEWORKS_GSC is not set
# CONFIG_MFD_MC13XXX_SPI is not set
# CONFIG_MFD_MC13XXX_I2C is not set
# CONFIG_MFD_MP2629 is not set
# CONFIG_MFD_PF1550 is not set
# CONFIG_MFD_HI6421_PMIC is not set
CONFIG_LPC_ICH=y
# CONFIG_LPC_SCH is not set
# CONFIG_MFD_IQS62X is not set
# CONFIG_MFD_JANZ_CMODIO is not set
# CONFIG_MFD_KEMPLD is not set
# CONFIG_MFD_88PM800 is not set
# CONFIG_MFD_88PM805 is not set
# CONFIG_MFD_88PM860X is not set
# CONFIG_MFD_88PM886_PMIC is not set
# CONFIG_MFD_MAX5970 is not set
# CONFIG_MFD_MAX14577 is not set
# CONFIG_MFD_MAX77541 is not set
# CONFIG_MFD_MAX77620 is not set
# CONFIG_MFD_MAX77650 is not set
# CONFIG_MFD_MAX77686 is not set
# CONFIG_MFD_MAX77693 is not set
# CONFIG_MFD_MAX77705 is not set
# CONFIG_MFD_MAX77714 is not set
# CONFIG_MFD_MAX77759 is not set
# CONFIG_MFD_MAX77843 is not set
# CONFIG_MFD_MAX8907 is not set
# CONFIG_MFD_MAX8925 is not set
# CONFIG_MFD_MAX8997 is not set
# CONFIG_MFD_MAX8998 is not set
CONFIG_MFD_MT6360=y
CONFIG_MFD_MT6370=y
# CONFIG_MFD_MT6397 is not set
# CONFIG_MFD_MENF21BMC is not set
# CONFIG_MFD_NCT6694 is not set
# CONFIG_MFD_OCELOT is not set
# CONFIG_EZX_PCAP is not set
# CONFIG_MFD_CPCAP is not set
CONFIG_MFD_VIPERBOARD=y
# CONFIG_MFD_NTXEC is not set
CONFIG_MFD_RETU=y
CONFIG_MFD_SPACEMIT_P1=y
# CONFIG_MFD_SY7636A is not set
# CONFIG_MFD_RDC321X is not set
# CONFIG_MFD_RT4831 is not set
# CONFIG_MFD_RT5033 is not set
# CONFIG_MFD_RT5120 is not set
# CONFIG_MFD_RC5T583 is not set
# CONFIG_MFD_RK8XX_I2C is not set
# CONFIG_MFD_RK8XX_SPI is not set
# CONFIG_MFD_RN5T618 is not set
# CONFIG_MFD_SEC_I2C is not set
# CONFIG_MFD_SI476X_CORE is not set
CONFIG_MFD_SIMPLE_MFD_I2C=y
# CONFIG_MFD_SM501 is not set
# CONFIG_MFD_SKY81452 is not set
# CONFIG_MFD_STMPE is not set
# CONFIG_MFD_SUN6I_PRCM is not set
CONFIG_MFD_SYSCON=y
# CONFIG_MFD_LP3943 is not set
# CONFIG_MFD_LP8788 is not set
# CONFIG_MFD_TI_LMU is not set
# CONFIG_MFD_BQ257XX is not set
# CONFIG_MFD_PALMAS is not set
# CONFIG_TPS6105X is not set
# CONFIG_TPS65010 is not set
# CONFIG_TPS6507X is not set
# CONFIG_MFD_TPS65086 is not set
# CONFIG_MFD_TPS65090 is not set
# CONFIG_MFD_TPS65217 is not set
# CONFIG_MFD_TI_LP873X is not set
# CONFIG_MFD_TI_LP87565 is not set
# CONFIG_MFD_TPS65218 is not set
# CONFIG_MFD_TPS65219 is not set
# CONFIG_MFD_TPS6586X is not set
# CONFIG_MFD_TPS65910 is not set
# CONFIG_MFD_TPS65912_I2C is not set
# CONFIG_MFD_TPS65912_SPI is not set
# CONFIG_MFD_TPS6594_I2C is not set
# CONFIG_MFD_TPS6594_SPI is not set
CONFIG_TWL4030_CORE=y
# CONFIG_MFD_TWL4030_AUDIO is not set
# CONFIG_TWL6040_CORE is not set
# CONFIG_MFD_LM3533 is not set
# CONFIG_MFD_TC3589X is not set
# CONFIG_MFD_TQMX86 is not set
# CONFIG_MFD_VX855 is not set
# CONFIG_MFD_ARIZONA_I2C is not set
# CONFIG_MFD_ARIZONA_SPI is not set
# CONFIG_MFD_WM8400 is not set
# CONFIG_MFD_WM831X_I2C is not set
# CONFIG_MFD_WM831X_SPI is not set
# CONFIG_MFD_WM8350_I2C is not set
# CONFIG_MFD_WM8994 is not set
# CONFIG_MFD_ROHM_BD718XX is not set
# CONFIG_MFD_ROHM_BD71828 is not set
# CONFIG_MFD_ROHM_BD957XMUF is not set
# CONFIG_MFD_ROHM_BD96801 is not set
# CONFIG_MFD_STPMIC1 is not set
# CONFIG_MFD_STMFX is not set
# CONFIG_MFD_ATC260X_I2C is not set
# CONFIG_MFD_QCOM_PM8008 is not set
# CONFIG_RAVE_SP_CORE is not set
# CONFIG_MFD_INTEL_M10_BMC_SPI is not set
# CONFIG_MFD_LS2K_BMC_CORE is not set
# CONFIG_MFD_QNAP_MCU is not set
# CONFIG_MFD_RSMU_I2C is not set
# CONFIG_MFD_RSMU_SPI is not set
# CONFIG_MFD_MAX7360 is not set
# end of Multifunction device drivers

CONFIG_REGULATOR=y
# CONFIG_REGULATOR_DEBUG is not set
CONFIG_REGULATOR_FIXED_VOLTAGE=y
# CONFIG_REGULATOR_VIRTUAL_CONSUMER is not set
# CONFIG_REGULATOR_USERSPACE_CONSUMER is not set
# CONFIG_REGULATOR_NETLINK_EVENTS is not set
# CONFIG_REGULATOR_88PG86X is not set
# CONFIG_REGULATOR_ACT8865 is not set
# CONFIG_REGULATOR_AD5398 is not set
# CONFIG_REGULATOR_ADP5055 is not set
# CONFIG_REGULATOR_AW37503 is not set
CONFIG_REGULATOR_AXP20X=y
# CONFIG_REGULATOR_DA9121 is not set
# CONFIG_REGULATOR_DA9210 is not set
# CONFIG_REGULATOR_DA9211 is not set
# CONFIG_REGULATOR_FAN53555 is not set
# CONFIG_REGULATOR_FAN53880 is not set
CONFIG_REGULATOR_GPIO=y
# CONFIG_REGULATOR_ISL9305 is not set
# CONFIG_REGULATOR_ISL6271A is not set
# CONFIG_REGULATOR_FP9931 is not set
# CONFIG_REGULATOR_LP3971 is not set
# CONFIG_REGULATOR_LP3972 is not set
# CONFIG_REGULATOR_LP872X is not set
# CONFIG_REGULATOR_LP8755 is not set
# CONFIG_REGULATOR_LTC3589 is not set
# CONFIG_REGULATOR_LTC3676 is not set
# CONFIG_REGULATOR_MAX1586 is not set
# CONFIG_REGULATOR_MAX77503 is not set
# CONFIG_REGULATOR_MAX77675 is not set
# CONFIG_REGULATOR_MAX77857 is not set
# CONFIG_REGULATOR_MAX8649 is not set
# CONFIG_REGULATOR_MAX8660 is not set
# CONFIG_REGULATOR_MAX8893 is not set
# CONFIG_REGULATOR_MAX8952 is not set
# CONFIG_REGULATOR_MAX8973 is not set
# CONFIG_REGULATOR_MAX20086 is not set
# CONFIG_REGULATOR_MAX20411 is not set
# CONFIG_REGULATOR_MAX77826 is not set
# CONFIG_REGULATOR_MAX77838 is not set
# CONFIG_REGULATOR_MCP16502 is not set
# CONFIG_REGULATOR_MP5416 is not set
# CONFIG_REGULATOR_MP8859 is not set
# CONFIG_REGULATOR_MP886X is not set
# CONFIG_REGULATOR_MPQ7920 is not set
# CONFIG_REGULATOR_MT6311 is not set
# CONFIG_REGULATOR_MT6360 is not set
# CONFIG_REGULATOR_MT6370 is not set
# CONFIG_REGULATOR_PCA9450 is not set
# CONFIG_REGULATOR_PF9453 is not set
# CONFIG_REGULATOR_PF0900 is not set
# CONFIG_REGULATOR_PF530X is not set
# CONFIG_REGULATOR_PF8X00 is not set
# CONFIG_REGULATOR_PFUZE100 is not set
# CONFIG_REGULATOR_PV88060 is not set
# CONFIG_REGULATOR_PV88080 is not set
# CONFIG_REGULATOR_PV88090 is not set
# CONFIG_REGULATOR_PWM is not set
# CONFIG_REGULATOR_RAA215300 is not set
# CONFIG_REGULATOR_RT4801 is not set
# CONFIG_REGULATOR_RT4803 is not set
# CONFIG_REGULATOR_RT5133 is not set
# CONFIG_REGULATOR_RT5190A is not set
# CONFIG_REGULATOR_RT5739 is not set
# CONFIG_REGULATOR_RT5759 is not set
# CONFIG_REGULATOR_RT6160 is not set
# CONFIG_REGULATOR_RT6190 is not set
# CONFIG_REGULATOR_RT6245 is not set
# CONFIG_REGULATOR_RT8092 is not set
# CONFIG_REGULATOR_RTQ2134 is not set
# CONFIG_REGULATOR_RTMV20 is not set
# CONFIG_REGULATOR_RTQ6752 is not set
# CONFIG_REGULATOR_RTQ2208 is not set
# CONFIG_REGULATOR_SLG51000 is not set
CONFIG_REGULATOR_SPACEMIT_P1=y
CONFIG_REGULATOR_SUN20I=y
# CONFIG_REGULATOR_SY8106A is not set
# CONFIG_REGULATOR_SY8824X is not set
# CONFIG_REGULATOR_SY8827N is not set
# CONFIG_REGULATOR_TPS51632 is not set
# CONFIG_REGULATOR_TPS62360 is not set
# CONFIG_REGULATOR_TPS6286X is not set
# CONFIG_REGULATOR_TPS6287X is not set
# CONFIG_REGULATOR_TPS65023 is not set
# CONFIG_REGULATOR_TPS6507X is not set
# CONFIG_REGULATOR_TPS65132 is not set
# CONFIG_REGULATOR_TPS65185 is not set
# CONFIG_REGULATOR_TPS6524X is not set
CONFIG_REGULATOR_TWL4030=y
# CONFIG_REGULATOR_VCTRL is not set
CONFIG_RC_CORE=y
# CONFIG_LIRC is not set
# CONFIG_RC_MAP is not set
# CONFIG_RC_DECODERS is not set
CONFIG_RC_DEVICES=y
# CONFIG_IR_ENE is not set
# CONFIG_IR_FINTEK is not set
# CONFIG_IR_GPIO_CIR is not set
# CONFIG_IR_HIX5HD2 is not set
CONFIG_IR_IGORPLUGUSB=y
CONFIG_IR_IGUANA=y
CONFIG_IR_IMON=y
CONFIG_IR_IMON_RAW=y
# CONFIG_IR_ITE_CIR is not set
CONFIG_IR_MCEUSB=y
# CONFIG_IR_NUVOTON is not set
CONFIG_IR_REDRAT3=y
# CONFIG_IR_SERIAL is not set
CONFIG_IR_STREAMZAP=y
# CONFIG_IR_SUNXI is not set
CONFIG_IR_TOY=y
CONFIG_IR_TTUSBIR=y
CONFIG_RC_ATI_REMOTE=y
# CONFIG_RC_LOOPBACK is not set
CONFIG_RC_XBOX_DVD=y
CONFIG_CEC_CORE=y

#
# CEC support
#
# CONFIG_MEDIA_CEC_RC is not set
CONFIG_MEDIA_CEC_SUPPORT=y
# CONFIG_CEC_CH7322 is not set
# CONFIG_CEC_NXP_TDA9950 is not set
# CONFIG_CEC_GPIO is not set
CONFIG_USB_PULSE8_CEC=y
CONFIG_USB_RAINSHADOW_CEC=y
# end of CEC support

# CONFIG_MEDIA_SUPPORT is not set

#
# Graphics support
#
CONFIG_APERTURE_HELPERS=y
CONFIG_VIDEO=y
# CONFIG_AUXDISPLAY is not set
# CONFIG_PANEL is not set
CONFIG_DRM=y

#
# DRM debugging options
#
# CONFIG_DRM_WERROR is not set
CONFIG_DRM_DEBUG_MM=y
# end of DRM debugging options

CONFIG_DRM_MIPI_DSI=y
CONFIG_DRM_KMS_HELPER=y
# CONFIG_DRM_PANIC is not set
# CONFIG_DRM_RAS is not set
# CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS is not set
# CONFIG_DRM_DEBUG_MODESET_LOCK is not set
CONFIG_DRM_CLIENT=y
CONFIG_DRM_CLIENT_LIB=y
CONFIG_DRM_CLIENT_SELECTION=y
CONFIG_DRM_CLIENT_SETUP=y

#
# Supported DRM clients
#
CONFIG_DRM_FBDEV_EMULATION=y
CONFIG_DRM_FBDEV_OVERALLOC=100
# CONFIG_DRM_FBDEV_LEAK_PHYS_SMEM is not set
# CONFIG_DRM_CLIENT_LOG is not set
CONFIG_DRM_CLIENT_DEFAULT_FBDEV=y
CONFIG_DRM_CLIENT_DEFAULT="fbdev"
# end of Supported DRM clients

# CONFIG_DRM_LOAD_EDID_FIRMWARE is not set
CONFIG_DRM_DISPLAY_DP_AUX_BUS=y
CONFIG_DRM_DISPLAY_HELPER=y
# CONFIG_DRM_DISPLAY_DP_AUX_CEC is not set
# CONFIG_DRM_DISPLAY_DP_AUX_CHARDEV is not set
CONFIG_DRM_DISPLAY_DP_HELPER=y
CONFIG_DRM_DISPLAY_HDMI_HELPER=y
CONFIG_DRM_TTM=y
CONFIG_DRM_EXEC=y
CONFIG_DRM_GPUVM=y
CONFIG_DRM_TTM_HELPER=y
CONFIG_DRM_GEM_DMA_HELPER=y
CONFIG_DRM_GEM_SHMEM_HELPER=y
CONFIG_DRM_SUBALLOC_HELPER=y
CONFIG_DRM_SCHED=y
# CONFIG_DRM_AMDGPU is not set

#
# ARM devices
#
# CONFIG_DRM_KOMEDA is not set
# end of ARM devices

# CONFIG_DRM_AST is not set
CONFIG_DRM_BRIDGE=y
CONFIG_DRM_PANEL_BRIDGE=y
CONFIG_DRM_AUX_BRIDGE=y
CONFIG_DRM_AUX_HPD_BRIDGE=y

#
# Display Interface Bridges
#
# CONFIG_DRM_CHIPONE_ICN6211 is not set
# CONFIG_DRM_CHRONTEL_CH7033 is not set
# CONFIG_DRM_DISPLAY_CONNECTOR is not set
# CONFIG_DRM_I2C_NXP_TDA998X is not set
# CONFIG_DRM_ITE_IT6263 is not set
# CONFIG_DRM_ITE_IT6505 is not set
# CONFIG_DRM_LONTIUM_LT8912B is not set
# CONFIG_DRM_LONTIUM_LT9211 is not set
# CONFIG_DRM_LONTIUM_LT9611 is not set
# CONFIG_DRM_LONTIUM_LT9611UXC is not set
# CONFIG_DRM_LONTIUM_LT8713SX is not set
# CONFIG_DRM_ITE_IT66121 is not set
# CONFIG_DRM_LVDS_CODEC is not set
# CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW is not set
# CONFIG_DRM_NWL_MIPI_DSI is not set
# CONFIG_DRM_NXP_PTN3460 is not set
# CONFIG_DRM_PARADE_PS8622 is not set
# CONFIG_DRM_PARADE_PS8640 is not set
# CONFIG_DRM_SAMSUNG_DSIM is not set
# CONFIG_DRM_SIL_SII8620 is not set
# CONFIG_DRM_SII902X is not set
# CONFIG_DRM_SII9234 is not set
# CONFIG_DRM_SIMPLE_BRIDGE is not set
# CONFIG_DRM_SOLOMON_SSD2825 is not set
# CONFIG_DRM_THINE_THC63LVD1024 is not set
# CONFIG_DRM_THEAD_TH1520_DW_HDMI is not set
# CONFIG_DRM_TOSHIBA_TC358762 is not set
# CONFIG_DRM_TOSHIBA_TC358764 is not set
# CONFIG_DRM_TOSHIBA_TC358767 is not set
# CONFIG_DRM_TOSHIBA_TC358768 is not set
# CONFIG_DRM_TOSHIBA_TC358775 is not set
# CONFIG_DRM_TI_DLPC3433 is not set
# CONFIG_DRM_TI_TDP158 is not set
# CONFIG_DRM_TI_TFP410 is not set
# CONFIG_DRM_TI_SN65DSI83 is not set
# CONFIG_DRM_TI_SN65DSI86 is not set
# CONFIG_DRM_TI_TPD12S015 is not set
# CONFIG_DRM_WAVESHARE_BRIDGE is not set
# CONFIG_DRM_ANALOGIX_ANX6345 is not set
# CONFIG_DRM_ANALOGIX_ANX78XX is not set
# CONFIG_DRM_ANALOGIX_ANX7625 is not set
# CONFIG_DRM_I2C_ADV7511 is not set
# CONFIG_DRM_CDNS_DSI is not set
# CONFIG_DRM_CDNS_MHDP8546 is not set
CONFIG_DRM_DW_HDMI=y
# CONFIG_DRM_DW_HDMI_AHB_AUDIO is not set
# CONFIG_DRM_DW_HDMI_I2S_AUDIO is not set
# CONFIG_DRM_DW_HDMI_GP_AUDIO is not set
# CONFIG_DRM_DW_HDMI_CEC is not set
# end of Display Interface Bridges

# CONFIG_DRM_ETNAVIV is not set
CONFIG_DRM_GUD=y
# CONFIG_DRM_HISI_HIBMC is not set
# CONFIG_DRM_POWERVR is not set
# CONFIG_DRM_LOGICVC is not set
# CONFIG_DRM_MGAG200 is not set
CONFIG_DRM_NOUVEAU=y
CONFIG_NOUVEAU_DEBUG=5
CONFIG_NOUVEAU_DEBUG_DEFAULT=3
# CONFIG_NOUVEAU_DEBUG_MMU is not set
# CONFIG_NOUVEAU_DEBUG_PUSH is not set
CONFIG_DRM_NOUVEAU_BACKLIGHT=y
CONFIG_DRM_NOUVEAU_CH7006=y
CONFIG_DRM_NOUVEAU_SIL164=y
CONFIG_DRM_PANEL=y

#
# Display Panels
#
# CONFIG_DRM_PANEL_ABT_Y030XX067A is not set
# CONFIG_DRM_PANEL_ARM_VERSATILE is not set
# CONFIG_DRM_PANEL_ASUS_Z00T_TM5P5_NT35596 is not set
# CONFIG_DRM_PANEL_AUO_A030JTN01 is not set
# CONFIG_DRM_PANEL_BOE_BF060Y8M_AJ0 is not set
# CONFIG_DRM_PANEL_BOE_HIMAX8279D is not set
# CONFIG_DRM_PANEL_BOE_TD4320 is not set
# CONFIG_DRM_PANEL_BOE_TH101MB31UIG002_28A is not set
# CONFIG_DRM_PANEL_BOE_TV101WUM_NL6 is not set
# CONFIG_DRM_PANEL_BOE_TV101WUM_LL2 is not set
# CONFIG_DRM_PANEL_EBBG_FT8719 is not set
# CONFIG_DRM_PANEL_ELIDA_KD35T133 is not set
# CONFIG_DRM_PANEL_FEIXIN_K101_IM2BA02 is not set
# CONFIG_DRM_PANEL_FEIYANG_FY07024DI26A30D is not set
# CONFIG_DRM_PANEL_DSI_CM is not set
# CONFIG_DRM_PANEL_LVDS is not set
# CONFIG_DRM_PANEL_HIMAX_HX8279 is not set
# CONFIG_DRM_PANEL_HIMAX_HX83102 is not set
# CONFIG_DRM_PANEL_HIMAX_HX83112A is not set
# CONFIG_DRM_PANEL_HIMAX_HX83112B is not set
# CONFIG_DRM_PANEL_HIMAX_HX83121A is not set
# CONFIG_DRM_PANEL_HIMAX_HX8394 is not set
# CONFIG_DRM_PANEL_HYDIS_HV101HD1 is not set
# CONFIG_DRM_PANEL_ILITEK_IL9322 is not set
# CONFIG_DRM_PANEL_ILITEK_ILI9341 is not set
# CONFIG_DRM_PANEL_ILITEK_ILI9805 is not set
# CONFIG_DRM_PANEL_ILITEK_ILI9806E_DSI is not set
# CONFIG_DRM_PANEL_ILITEK_ILI9806E_SPI is not set
# CONFIG_DRM_PANEL_ILITEK_ILI9881C is not set
# CONFIG_DRM_PANEL_ILITEK_ILI9882T is not set
# CONFIG_DRM_PANEL_INNOLUX_EJ030NA is not set
# CONFIG_DRM_PANEL_INNOLUX_P079ZCA is not set
# CONFIG_DRM_PANEL_JADARD_JD9365DA_H3 is not set
# CONFIG_DRM_PANEL_JDI_LPM102A188A is not set
# CONFIG_DRM_PANEL_JDI_LT070ME05000 is not set
# CONFIG_DRM_PANEL_JDI_R63452 is not set
# CONFIG_DRM_PANEL_KHADAS_TS050 is not set
# CONFIG_DRM_PANEL_KINGDISPLAY_KD097D04 is not set
# CONFIG_DRM_PANEL_LEADTEK_LTK050H3146W is not set
# CONFIG_DRM_PANEL_LEADTEK_LTK500HD1829 is not set
# CONFIG_DRM_PANEL_LINCOLNTECH_LCD197 is not set
# CONFIG_DRM_PANEL_LG_LB035Q02 is not set
# CONFIG_DRM_PANEL_LG_LD070WX3 is not set
# CONFIG_DRM_PANEL_LG_LG4573 is not set
# CONFIG_DRM_PANEL_LG_SW43408 is not set
# CONFIG_DRM_PANEL_LXD_M9189A is not set
# CONFIG_DRM_PANEL_MAGNACHIP_D53E6EA8966 is not set
# CONFIG_DRM_PANEL_MANTIX_MLAF057WE51 is not set
# CONFIG_DRM_PANEL_MOTOROLA_MOT is not set
# CONFIG_DRM_PANEL_NEC_NL8048HL11 is not set
# CONFIG_DRM_PANEL_NEWVISION_NV3051D is not set
# CONFIG_DRM_PANEL_NEWVISION_NV3052C is not set
# CONFIG_DRM_PANEL_NOVATEK_NT35510 is not set
# CONFIG_DRM_PANEL_NOVATEK_NT35560 is not set
# CONFIG_DRM_PANEL_NOVATEK_NT35950 is not set
# CONFIG_DRM_PANEL_NOVATEK_NT36523 is not set
# CONFIG_DRM_PANEL_NOVATEK_NT36672A is not set
# CONFIG_DRM_PANEL_NOVATEK_NT36672E is not set
# CONFIG_DRM_PANEL_NOVATEK_NT37700F is not set
# CONFIG_DRM_PANEL_NOVATEK_NT37801 is not set
# CONFIG_DRM_PANEL_NOVATEK_NT39016 is not set
# CONFIG_DRM_PANEL_OLIMEX_LCD_OLINUXINO is not set
# CONFIG_DRM_PANEL_ORISETECH_OTA5601A is not set
# CONFIG_DRM_PANEL_ORISETECH_OTM8009A is not set
# CONFIG_DRM_PANEL_OSD_OSD101T2587_53TS is not set
# CONFIG_DRM_PANEL_PANASONIC_VVX10F034N00 is not set
# CONFIG_DRM_PANEL_RASPBERRYPI_TOUCHSCREEN is not set
# CONFIG_DRM_PANEL_RAYDIUM_RM67191 is not set
# CONFIG_DRM_PANEL_RAYDIUM_RM67200 is not set
# CONFIG_DRM_PANEL_RAYDIUM_RM68200 is not set
# CONFIG_DRM_PANEL_RAYDIUM_RM692E5 is not set
# CONFIG_DRM_PANEL_RAYDIUM_RM69380 is not set
# CONFIG_DRM_PANEL_RENESAS_R61307 is not set
# CONFIG_DRM_PANEL_RENESAS_R69328 is not set
# CONFIG_DRM_PANEL_RONBO_RB070D30 is not set
# CONFIG_DRM_PANEL_SAMSUNG_AMS581VF01 is not set
# CONFIG_DRM_PANEL_SAMSUNG_AMS639RQ08 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6E88A0_AMS427AP24 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01 is not set
# CONFIG_DRM_PANEL_SAMSUNG_ATNA33XC20 is not set
# CONFIG_DRM_PANEL_SAMSUNG_DB7430 is not set
# CONFIG_DRM_PANEL_SAMSUNG_LD9040 is not set
# CONFIG_DRM_PANEL_SAMSUNG_LTL106HL02 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6E3FA7 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6D16D0 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6D27A1 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6D7AA0 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6E3FC2X01 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6E3HA2 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6E3HA8 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6E63J0X03 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6E63M0 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6E8AA0 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6E8AA5X01_AMS561RA01 is not set
# CONFIG_DRM_PANEL_SAMSUNG_S6E8FC0 is not set
# CONFIG_DRM_PANEL_SAMSUNG_SOFEF00 is not set
# CONFIG_DRM_PANEL_SEIKO_43WVF1G is not set
# CONFIG_DRM_PANEL_SHARP_LQ079L1SX01 is not set
# CONFIG_DRM_PANEL_SHARP_LQ101R1SX01 is not set
# CONFIG_DRM_PANEL_SHARP_LS037V7DW01 is not set
# CONFIG_DRM_PANEL_SHARP_LS043T1LE01 is not set
# CONFIG_DRM_PANEL_SHARP_LS060T1SX01 is not set
# CONFIG_DRM_PANEL_SITRONIX_ST7701 is not set
# CONFIG_DRM_PANEL_SITRONIX_ST7703 is not set
# CONFIG_DRM_PANEL_SITRONIX_ST7789V is not set
# CONFIG_DRM_PANEL_SONY_ACX565AKM is not set
# CONFIG_DRM_PANEL_SONY_TD4353_JDI is not set
# CONFIG_DRM_PANEL_SONY_TULIP_TRULY_NT35521 is not set
# CONFIG_DRM_PANEL_STARTEK_KD070FHFID015 is not set
CONFIG_DRM_PANEL_EDP=y
# CONFIG_DRM_PANEL_SIMPLE is not set
# CONFIG_DRM_PANEL_SUMMIT is not set
# CONFIG_DRM_PANEL_SYNAPTICS_R63353 is not set
# CONFIG_DRM_PANEL_SYNAPTICS_TDDI is not set
# CONFIG_DRM_PANEL_TDO_TL070WSH30 is not set
# CONFIG_DRM_PANEL_TPO_TD028TTEC1 is not set
# CONFIG_DRM_PANEL_TPO_TD043MTEA1 is not set
# CONFIG_DRM_PANEL_TPO_TPG110 is not set
# CONFIG_DRM_PANEL_TRULY_NT35597_WQXGA is not set
# CONFIG_DRM_PANEL_VISIONOX_G2647FB105 is not set
# CONFIG_DRM_PANEL_VISIONOX_R66451 is not set
# CONFIG_DRM_PANEL_VISIONOX_RM69299 is not set
# CONFIG_DRM_PANEL_VISIONOX_RM692E5 is not set
# CONFIG_DRM_PANEL_VISIONOX_VTDR6130 is not set
# CONFIG_DRM_PANEL_WIDECHIPS_WS2401 is not set
# CONFIG_DRM_PANEL_XINPENG_XPP055C272 is not set
# end of Display Panels

# CONFIG_DRM_QXL is not set
CONFIG_DRM_RADEON=y
# CONFIG_DRM_RADEON_USERPTR is not set
# CONFIG_DRM_ST7571 is not set
# CONFIG_DRM_ST7586 is not set
# CONFIG_DRM_ST7735R is not set
# CONFIG_DRM_ST7920 is not set
# CONFIG_DRM_SSD130X is not set
CONFIG_DRM_SUN4I=y
CONFIG_DRM_SUN6I_DSI=y
CONFIG_DRM_SUN8I_DW_HDMI=y
CONFIG_DRM_SUN8I_MIXER=y
CONFIG_DRM_SUN8I_TCON_TOP=y

#
# Drivers for system framebuffers
#
CONFIG_DRM_SYSFB_HELPER=y
# CONFIG_DRM_EFIDRM is not set
CONFIG_DRM_SIMPLEDRM=y
# end of Drivers for system framebuffers

# CONFIG_DRM_ARCPGU is not set
CONFIG_DRM_BOCHS=y
CONFIG_DRM_CIRRUS_QEMU=y
CONFIG_DRM_GM12U320=y
# CONFIG_DRM_PANEL_MIPI_DBI is not set
# CONFIG_DRM_PIXPAPER is not set
# CONFIG_TINYDRM_HX8357D is not set
# CONFIG_TINYDRM_ILI9163 is not set
# CONFIG_TINYDRM_ILI9225 is not set
# CONFIG_TINYDRM_ILI9341 is not set
# CONFIG_TINYDRM_ILI9486 is not set
# CONFIG_TINYDRM_MI0283QT is not set
# CONFIG_TINYDRM_REPAPER is not set
# CONFIG_TINYDRM_SHARP_MEMORY is not set
CONFIG_DRM_UDL=y
# CONFIG_DRM_VERISILICON_DC is not set
CONFIG_DRM_VGEM=y
CONFIG_DRM_VIRTIO_GPU=y
CONFIG_DRM_VIRTIO_GPU_KMS=y
CONFIG_DRM_VKMS=y
# CONFIG_DRM_XE is not set
CONFIG_DRM_PANEL_ORIENTATION_QUIRKS=y

#
# Frame buffer Devices
#
CONFIG_FB=y
# CONFIG_FB_CIRRUS is not set
# CONFIG_FB_PM2 is not set
# CONFIG_FB_CYBER2000 is not set
# CONFIG_FB_ASILIANT is not set
# CONFIG_FB_IMSTT is not set
# CONFIG_FB_UVESA is not set
# CONFIG_FB_EFI is not set
# CONFIG_FB_OPENCORES is not set
# CONFIG_FB_S1D13XXX is not set
# CONFIG_FB_NVIDIA is not set
# CONFIG_FB_RIVA is not set
# CONFIG_FB_I740 is not set
# CONFIG_FB_MATROX is not set
# CONFIG_FB_RADEON is not set
# CONFIG_FB_ATY128 is not set
# CONFIG_FB_ATY is not set
# CONFIG_FB_S3 is not set
# CONFIG_FB_SAVAGE is not set
# CONFIG_FB_SIS is not set
# CONFIG_FB_NEOMAGIC is not set
# CONFIG_FB_KYRO is not set
# CONFIG_FB_3DFX is not set
# CONFIG_FB_VOODOO1 is not set
# CONFIG_FB_VT8623 is not set
# CONFIG_FB_TRIDENT is not set
# CONFIG_FB_ARK is not set
# CONFIG_FB_PM3 is not set
# CONFIG_FB_CARMINE is not set
# CONFIG_FB_SMSCUFX is not set
# CONFIG_FB_UDL is not set
# CONFIG_FB_IBM_GXT4500 is not set
# CONFIG_FB_GOLDFISH is not set
CONFIG_FB_VIRTUAL=y
# CONFIG_FB_METRONOME is not set
# CONFIG_FB_MB862XX is not set
# CONFIG_FB_SSD1307 is not set
# CONFIG_FB_SM712 is not set
CONFIG_FB_CORE=y
CONFIG_FB_NOTIFY=y
CONFIG_FB_DEVICE=y
CONFIG_FB_CFB_FILLRECT=y
CONFIG_FB_CFB_COPYAREA=y
CONFIG_FB_CFB_IMAGEBLIT=y
CONFIG_FB_SYS_FILLRECT=y
CONFIG_FB_SYS_COPYAREA=y
CONFIG_FB_SYS_IMAGEBLIT=y
# CONFIG_FB_FOREIGN_ENDIAN is not set
CONFIG_FB_SYSMEM_FOPS=y
CONFIG_FB_DEFERRED_IO=y
CONFIG_FB_DMAMEM_HELPERS=y
CONFIG_FB_DMAMEM_HELPERS_DEFERRED=y
CONFIG_FB_IOMEM_FOPS=y
CONFIG_FB_IOMEM_HELPERS=y
CONFIG_FB_SYSMEM_HELPERS=y
CONFIG_FB_SYSMEM_HELPERS_DEFERRED=y
CONFIG_FB_TILEBLITTING=y
# end of Frame buffer Devices

#
# Backlight & LCD device support
#
CONFIG_LCD_CLASS_DEVICE=y
# CONFIG_LCD_L4F00242T03 is not set
# CONFIG_LCD_LMS283GF05 is not set
# CONFIG_LCD_LTV350QV is not set
# CONFIG_LCD_ILI922X is not set
# CONFIG_LCD_ILI9320 is not set
# CONFIG_LCD_TDO24M is not set
# CONFIG_LCD_VGG2432A4 is not set
# CONFIG_LCD_PLATFORM is not set
# CONFIG_LCD_AMS369FG06 is not set
# CONFIG_LCD_LMS501KF03 is not set
# CONFIG_LCD_HX8357 is not set
# CONFIG_LCD_OTM3225A is not set
CONFIG_BACKLIGHT_CLASS_DEVICE=y
# CONFIG_BACKLIGHT_AW99706 is not set
# CONFIG_BACKLIGHT_KTD253 is not set
# CONFIG_BACKLIGHT_KTD2801 is not set
# CONFIG_BACKLIGHT_KTZ8866 is not set
# CONFIG_BACKLIGHT_PWM is not set
# CONFIG_BACKLIGHT_MT6370 is not set
# CONFIG_BACKLIGHT_QCOM_WLED is not set
# CONFIG_BACKLIGHT_ADP8860 is not set
# CONFIG_BACKLIGHT_ADP8870 is not set
# CONFIG_BACKLIGHT_LM3509 is not set
# CONFIG_BACKLIGHT_LM3630A is not set
# CONFIG_BACKLIGHT_LM3639 is not set
# CONFIG_BACKLIGHT_LP855X is not set
# CONFIG_BACKLIGHT_MP3309C is not set
# CONFIG_BACKLIGHT_PANDORA is not set
# CONFIG_BACKLIGHT_GPIO is not set
# CONFIG_BACKLIGHT_LV5207LP is not set
# CONFIG_BACKLIGHT_BD6107 is not set
# CONFIG_BACKLIGHT_ARCXCNN is not set
# CONFIG_BACKLIGHT_LED is not set
# end of Backlight & LCD device support

CONFIG_VIDEOMODE_HELPERS=y
CONFIG_HDMI=y
# CONFIG_FIRMWARE_EDID is not set

#
# Console display driver support
#
CONFIG_DUMMY_CONSOLE=y
CONFIG_DUMMY_CONSOLE_COLUMNS=80
CONFIG_DUMMY_CONSOLE_ROWS=25
CONFIG_FRAMEBUFFER_CONSOLE=y
# CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION is not set
CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y
CONFIG_FRAMEBUFFER_CONSOLE_ROTATION=y
# CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER is not set
# end of Console display driver support

CONFIG_LOGO=y
CONFIG_LOGO_LINUX_MONO=y
CONFIG_LOGO_LINUX_MONO_FILE="drivers/video/logo/logo_linux_mono.pbm"
CONFIG_LOGO_LINUX_VGA16=y
CONFIG_LOGO_LINUX_VGA16_FILE="drivers/video/logo/logo_linux_vga16.ppm"
# CONFIG_LOGO_LINUX_CLUT224 is not set
# CONFIG_TRACE_GPU_MEM is not set
# end of Graphics support

# CONFIG_DRM_ACCEL is not set
CONFIG_SOUND=y
CONFIG_SOUND_OSS_CORE=y
CONFIG_SOUND_OSS_CORE_PRECLAIM=y
CONFIG_SND=y
CONFIG_SND_TIMER=y
CONFIG_SND_PCM=y
CONFIG_SND_DMAENGINE_PCM=y
CONFIG_SND_HWDEP=y
CONFIG_SND_SEQ_DEVICE=y
CONFIG_SND_RAWMIDI=y
CONFIG_SND_UMP=y
CONFIG_SND_UMP_LEGACY_RAWMIDI=y
CONFIG_SND_JACK=y
CONFIG_SND_JACK_INPUT_DEV=y
CONFIG_SND_OSSEMUL=y
CONFIG_SND_MIXER_OSS=y
CONFIG_SND_PCM_OSS=y
CONFIG_SND_PCM_OSS_PLUGINS=y
CONFIG_SND_PCM_TIMER=y
CONFIG_SND_HRTIMER=y
# CONFIG_SND_DYNAMIC_MINORS is not set
# CONFIG_SND_SUPPORT_OLD_API is not set
CONFIG_SND_PROC_FS=y
CONFIG_SND_VERBOSE_PROCFS=y
CONFIG_SND_CTL_FAST_LOOKUP=y
# CONFIG_SND_DEBUG is not set
# CONFIG_SND_CTL_INPUT_VALIDATION is not set
# CONFIG_SND_UTIMER is not set
CONFIG_SND_VMASTER=y
CONFIG_SND_CTL_LED=y
CONFIG_SND_SEQUENCER=y
CONFIG_SND_SEQ_DUMMY=y
CONFIG_SND_SEQUENCER_OSS=y
# CONFIG_SND_SEQ_HRTIMER_DEFAULT is not set
CONFIG_SND_SEQ_MIDI_EVENT=y
CONFIG_SND_SEQ_MIDI=y
CONFIG_SND_SEQ_VIRMIDI=y
# CONFIG_SND_SEQ_UMP is not set
CONFIG_SND_DRIVERS=y
CONFIG_SND_DUMMY=y
CONFIG_SND_ALOOP=y
# CONFIG_SND_PCMTEST is not set
CONFIG_SND_VIRMIDI=y
# CONFIG_SND_MTPAV is not set
# CONFIG_SND_MTS64 is not set
# CONFIG_SND_SERIAL_U16550 is not set
# CONFIG_SND_SERIAL_GENERIC is not set
# CONFIG_SND_MPU401 is not set
# CONFIG_SND_PORTMAN2X4 is not set
CONFIG_SND_PCI=y
# CONFIG_SND_AD1889 is not set
# CONFIG_SND_ATIIXP is not set
# CONFIG_SND_ATIIXP_MODEM is not set
# CONFIG_SND_AU8810 is not set
# CONFIG_SND_AU8820 is not set
# CONFIG_SND_AU8830 is not set
# CONFIG_SND_AW2 is not set
# CONFIG_SND_BT87X is not set
# CONFIG_SND_CA0106 is not set
# CONFIG_SND_CMIPCI is not set
# CONFIG_SND_OXYGEN is not set
# CONFIG_SND_CS4281 is not set
# CONFIG_SND_CS46XX is not set
# CONFIG_SND_CTXFI is not set
# CONFIG_SND_DARLA20 is not set
# CONFIG_SND_GINA20 is not set
# CONFIG_SND_LAYLA20 is not set
# CONFIG_SND_DARLA24 is not set
# CONFIG_SND_GINA24 is not set
# CONFIG_SND_LAYLA24 is not set
# CONFIG_SND_MONA is not set
# CONFIG_SND_MIA is not set
# CONFIG_SND_ECHO3G is not set
# CONFIG_SND_INDIGO is not set
# CONFIG_SND_INDIGOIO is not set
# CONFIG_SND_INDIGODJ is not set
# CONFIG_SND_INDIGOIOX is not set
# CONFIG_SND_INDIGODJX is not set
# CONFIG_SND_ENS1370 is not set
# CONFIG_SND_ENS1371 is not set
# CONFIG_SND_FM801 is not set
# CONFIG_SND_HDSP is not set
# CONFIG_SND_HDSPM is not set
# CONFIG_SND_ICE1724 is not set
# CONFIG_SND_INTEL8X0 is not set
# CONFIG_SND_INTEL8X0M is not set
# CONFIG_SND_KORG1212 is not set
# CONFIG_SND_LOLA is not set
# CONFIG_SND_LX6464ES is not set
# CONFIG_SND_MIXART is not set
# CONFIG_SND_NM256 is not set
# CONFIG_SND_PCXHR is not set
# CONFIG_SND_RIPTIDE is not set
# CONFIG_SND_RME32 is not set
# CONFIG_SND_RME96 is not set
# CONFIG_SND_RME9652 is not set
# CONFIG_SND_SE6X is not set
# CONFIG_SND_VIA82XX is not set
# CONFIG_SND_VIA82XX_MODEM is not set
# CONFIG_SND_VIRTUOSO is not set
# CONFIG_SND_VX222 is not set
# CONFIG_SND_YMFPCI is not set

#
# HD-Audio
#
CONFIG_SND_HDA=y
CONFIG_SND_HDA_HWDEP=y
CONFIG_SND_HDA_RECONFIG=y
CONFIG_SND_HDA_INPUT_BEEP=y
CONFIG_SND_HDA_INPUT_BEEP_MODE=1
CONFIG_SND_HDA_PATCH_LOADER=y
CONFIG_SND_HDA_POWER_SAVE_DEFAULT=0
# CONFIG_SND_HDA_CTL_DEV_ID is not set
CONFIG_SND_HDA_PREALLOC_SIZE=0
CONFIG_SND_HDA_INTEL=y
# CONFIG_SND_HDA_ACPI is not set
CONFIG_SND_HDA_GENERIC_LEDS=y
CONFIG_SND_HDA_CODEC_ANALOG=y
CONFIG_SND_HDA_CODEC_SIGMATEL=y
CONFIG_SND_HDA_CODEC_VIA=y
CONFIG_SND_HDA_CODEC_CONEXANT=y
# CONFIG_SND_HDA_CODEC_SENARYTECH is not set
CONFIG_SND_HDA_CODEC_CA0110=y
CONFIG_SND_HDA_CODEC_CA0132=y
# CONFIG_SND_HDA_CODEC_CA0132_DSP is not set
CONFIG_SND_HDA_CODEC_CMEDIA=y
# CONFIG_SND_HDA_CODEC_CM9825 is not set
CONFIG_SND_HDA_CODEC_SI3054=y
CONFIG_SND_HDA_GENERIC=y
CONFIG_SND_HDA_CODEC_REALTEK=y
# CONFIG_SND_HDA_CODEC_ALC260 is not set
# CONFIG_SND_HDA_CODEC_ALC262 is not set
# CONFIG_SND_HDA_CODEC_ALC268 is not set
# CONFIG_SND_HDA_CODEC_ALC269 is not set
# CONFIG_SND_HDA_CODEC_ALC662 is not set
# CONFIG_SND_HDA_CODEC_ALC680 is not set
# CONFIG_SND_HDA_CODEC_ALC861 is not set
# CONFIG_SND_HDA_CODEC_ALC861VD is not set
# CONFIG_SND_HDA_CODEC_ALC880 is not set
# CONFIG_SND_HDA_CODEC_ALC882 is not set
CONFIG_SND_HDA_CODEC_CIRRUS=y
# CONFIG_SND_HDA_CODEC_CS420X is not set
# CONFIG_SND_HDA_CODEC_CS421X is not set
# CONFIG_SND_HDA_CODEC_CS8409 is not set
CONFIG_SND_HDA_CODEC_HDMI=y
# CONFIG_SND_HDA_CODEC_HDMI_GENERIC is not set
# CONFIG_SND_HDA_CODEC_HDMI_SIMPLE is not set
# CONFIG_SND_HDA_CODEC_HDMI_INTEL is not set
# CONFIG_SND_HDA_CODEC_HDMI_ATI is not set
# CONFIG_SND_HDA_CODEC_HDMI_NVIDIA is not set
# CONFIG_SND_HDA_CODEC_HDMI_NVIDIA_MCP is not set
# CONFIG_SND_HDA_CODEC_HDMI_TEGRA is not set
# CONFIG_SND_HDA_SCODEC_CS35L41_I2C is not set
# CONFIG_SND_HDA_SCODEC_CS35L41_SPI is not set
# CONFIG_SND_HDA_SCODEC_CS35L56_I2C is not set
# CONFIG_SND_HDA_SCODEC_CS35L56_SPI is not set
# CONFIG_SND_HDA_SCODEC_TAS2781_I2C is not set
# CONFIG_SND_HDA_SCODEC_TAS2781_SPI is not set
CONFIG_SND_HDA_CORE=y
CONFIG_SND_HDA_COMPONENT=y
CONFIG_SND_INTEL_NHLT=y
CONFIG_SND_INTEL_DSP_CONFIG=y
CONFIG_SND_INTEL_SOUNDWIRE_ACPI=y
# end of HD-Audio

CONFIG_SND_SPI=y
CONFIG_SND_USB=y
CONFIG_SND_USB_AUDIO=y
CONFIG_SND_USB_AUDIO_MIDI_V2=y
CONFIG_SND_USB_UA101=y
CONFIG_SND_USB_CAIAQ=y
CONFIG_SND_USB_CAIAQ_INPUT=y
CONFIG_SND_USB_6FIRE=y
CONFIG_SND_USB_HIFACE=y
CONFIG_SND_BCD2000=y
CONFIG_SND_USB_LINE6=y
CONFIG_SND_USB_POD=y
CONFIG_SND_USB_PODHD=y
CONFIG_SND_USB_TONEPORT=y
CONFIG_SND_USB_VARIAX=y
# CONFIG_SND_FIREWIRE is not set
# CONFIG_SND_PCMCIA is not set
CONFIG_SND_SOC=y
CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM=y
# CONFIG_SND_SOC_USB is not set

#
# Analog Devices
#
# CONFIG_SND_SOC_ADI_AXI_I2S is not set
# CONFIG_SND_SOC_ADI_AXI_SPDIF is not set
# end of Analog Devices

#
# AMD
#
# CONFIG_SND_SOC_AMD_ACP is not set
# CONFIG_SND_AMD_ACP_CONFIG is not set
# end of AMD

#
# Apple
#
# end of Apple

#
# Atmel
#
# CONFIG_SND_SOC_MIKROE_PROTO is not set
# end of Atmel

#
# Au1x
#
# end of Au1x

#
# Broadcom
#
# CONFIG_SND_BCM63XX_I2S_WHISTLER is not set
# end of Broadcom

#
# Cirrus Logic
#
# end of Cirrus Logic

#
# DesignWare
#
CONFIG_SND_DESIGNWARE_I2S=y
# CONFIG_SND_DESIGNWARE_PCM is not set
# end of DesignWare

#
# Freescale
#

#
# Common SoC Audio options for Freescale CPUs:
#
# CONFIG_SND_SOC_FSL_ASRC is not set
# CONFIG_SND_SOC_FSL_SAI is not set
# CONFIG_SND_SOC_FSL_AUDMIX is not set
# CONFIG_SND_SOC_FSL_SSI is not set
# CONFIG_SND_SOC_FSL_SPDIF is not set
# CONFIG_SND_SOC_FSL_ESAI is not set
# CONFIG_SND_SOC_FSL_MICFIL is not set
# CONFIG_SND_SOC_FSL_XCVR is not set
# CONFIG_SND_SOC_FSL_RPMSG is not set
# CONFIG_SND_SOC_IMX_AUDMUX is not set
# end of Freescale

#
# Google
#
# CONFIG_SND_SOC_CHV3_I2S is not set
# end of Google

#
# Hisilicon
#
# CONFIG_SND_I2S_HI6210_I2S is not set
# end of Hisilicon

#
# JZ4740
#
# end of JZ4740

#
# Kirkwood
#
# end of Kirkwood

#
# Loongson
#
# end of Loongson

#
# Intel
#
# end of Intel

#
# Mediatek
#
# CONFIG_SND_SOC_MTK_BTCVSD is not set
# end of Mediatek

#
# PXA
#
# end of PXA

#
# SoundWire (SDCA)
#
CONFIG_SND_SOC_SDCA_OPTIONAL=y
# end of SoundWire (SDCA)

#
# Sophgo
#
# CONFIG_SND_SOC_CV1800B_TDM is not set
# CONFIG_SND_SOC_CV1800B_ADC_CODEC is not set
# CONFIG_SND_SOC_CV1800B_DAC_CODEC is not set
# end of Sophgo

#
# SpacemiT
#
# CONFIG_SND_SOC_K1_I2S is not set
# end of SpacemiT

#
# ST SPEAr
#
# end of ST SPEAr

#
# Spreadtrum
#
# end of Spreadtrum

#
# StarFive
#
CONFIG_SND_SOC_JH7110_PWMDAC=y
CONFIG_SND_SOC_JH7110_TDM=y
# end of StarFive

#
# STMicroelectronics STM32
#
# end of STMicroelectronics STM32

#
# Allwinner
#
# CONFIG_SND_SUN4I_CODEC is not set
# CONFIG_SND_SUN4I_I2S is not set
# CONFIG_SND_SUN4I_SPDIF is not set
# CONFIG_SND_SUN50I_DMIC is not set
# end of Allwinner

#
# Tegra
#
# end of Tegra

#
# Xilinx
#
# CONFIG_SND_SOC_XILINX_I2S is not set
# CONFIG_SND_SOC_XILINX_AUDIO_FORMATTER is not set
# CONFIG_SND_SOC_XILINX_SPDIF is not set
# end of Xilinx

#
# Xtensa
#
# CONFIG_SND_SOC_XTFPGA_I2S is not set
# end of Xtensa

# CONFIG_SND_SOC_SOF_TOPLEVEL is not set
CONFIG_SND_SOC_I2C_AND_SPI=y

#
# CODEC drivers
#
# CONFIG_SND_SOC_AC97_CODEC is not set
# CONFIG_SND_SOC_ADAU1372_I2C is not set
# CONFIG_SND_SOC_ADAU1372_SPI is not set
# CONFIG_SND_SOC_ADAU1373 is not set
# CONFIG_SND_SOC_ADAU1701 is not set
# CONFIG_SND_SOC_ADAU1761_I2C is not set
# CONFIG_SND_SOC_ADAU1761_SPI is not set
# CONFIG_SND_SOC_ADAU7002 is not set
# CONFIG_SND_SOC_ADAU7118_HW is not set
# CONFIG_SND_SOC_ADAU7118_I2C is not set
# CONFIG_SND_SOC_AK4104 is not set
# CONFIG_SND_SOC_AK4118 is not set
# CONFIG_SND_SOC_AK4375 is not set
# CONFIG_SND_SOC_AK4458 is not set
# CONFIG_SND_SOC_AK4554 is not set
# CONFIG_SND_SOC_AK4613 is not set
# CONFIG_SND_SOC_AK4619 is not set
# CONFIG_SND_SOC_AK4642 is not set
# CONFIG_SND_SOC_AK5386 is not set
# CONFIG_SND_SOC_AK5558 is not set
# CONFIG_SND_SOC_ALC5623 is not set
# CONFIG_SND_SOC_AUDIO_IIO_AUX is not set
# CONFIG_SND_SOC_AW8738 is not set
# CONFIG_SND_SOC_AW88395 is not set
# CONFIG_SND_SOC_AW88166 is not set
# CONFIG_SND_SOC_AW88261 is not set
# CONFIG_SND_SOC_AW88081 is not set
# CONFIG_SND_SOC_AW87390 is not set
# CONFIG_SND_SOC_AW88399 is not set
# CONFIG_SND_SOC_BD28623 is not set
# CONFIG_SND_SOC_BT_SCO is not set
# CONFIG_SND_SOC_CHV3_CODEC is not set
# CONFIG_SND_SOC_CS35L32 is not set
# CONFIG_SND_SOC_CS35L33 is not set
# CONFIG_SND_SOC_CS35L34 is not set
# CONFIG_SND_SOC_CS35L35 is not set
# CONFIG_SND_SOC_CS35L36 is not set
# CONFIG_SND_SOC_CS35L41_SPI is not set
# CONFIG_SND_SOC_CS35L41_I2C is not set
# CONFIG_SND_SOC_CS35L45_SPI is not set
# CONFIG_SND_SOC_CS35L45_I2C is not set
# CONFIG_SND_SOC_CS35L56_I2C is not set
# CONFIG_SND_SOC_CS35L56_SPI is not set
# CONFIG_SND_SOC_CS35L56_SDW is not set
# CONFIG_SND_SOC_CS42L42 is not set
# CONFIG_SND_SOC_CS42L42_SDW is not set
# CONFIG_SND_SOC_CS42L51_I2C is not set
# CONFIG_SND_SOC_CS42L52 is not set
# CONFIG_SND_SOC_CS42L56 is not set
# CONFIG_SND_SOC_CS42L73 is not set
# CONFIG_SND_SOC_CS42L83 is not set
# CONFIG_SND_SOC_CS42L84 is not set
# CONFIG_SND_SOC_CS4234 is not set
# CONFIG_SND_SOC_CS4265 is not set
# CONFIG_SND_SOC_CS4270 is not set
# CONFIG_SND_SOC_CS4271_I2C is not set
# CONFIG_SND_SOC_CS4271_SPI is not set
# CONFIG_SND_SOC_CS42XX8_I2C is not set
# CONFIG_SND_SOC_CS43130 is not set
# CONFIG_SND_SOC_CS4341 is not set
# CONFIG_SND_SOC_CS4349 is not set
# CONFIG_SND_SOC_CS48L32 is not set
# CONFIG_SND_SOC_CS53L30 is not set
# CONFIG_SND_SOC_CS530X_I2C is not set
# CONFIG_SND_SOC_CS530X_SPI is not set
# CONFIG_SND_SOC_CX2072X is not set
# CONFIG_SND_SOC_DA7213 is not set
# CONFIG_SND_SOC_DMIC is not set
# CONFIG_SND_SOC_ES7134 is not set
# CONFIG_SND_SOC_ES7241 is not set
# CONFIG_SND_SOC_ES8311 is not set
# CONFIG_SND_SOC_ES8316 is not set
# CONFIG_SND_SOC_ES8323 is not set
# CONFIG_SND_SOC_ES8326 is not set
# CONFIG_SND_SOC_ES8328_I2C is not set
# CONFIG_SND_SOC_ES8328_SPI is not set
# CONFIG_SND_SOC_ES8375 is not set
# CONFIG_SND_SOC_ES8389 is not set
# CONFIG_SND_SOC_FS210X is not set
# CONFIG_SND_SOC_GTM601 is not set
# CONFIG_SND_SOC_HDA is not set
# CONFIG_SND_SOC_ICS43432 is not set
# CONFIG_SND_SOC_IDT821034 is not set
# CONFIG_SND_SOC_MAX98088 is not set
# CONFIG_SND_SOC_MAX98090 is not set
# CONFIG_SND_SOC_MAX98357A is not set
# CONFIG_SND_SOC_MAX98504 is not set
# CONFIG_SND_SOC_MAX9867 is not set
# CONFIG_SND_SOC_MAX98927 is not set
# CONFIG_SND_SOC_MAX98520 is not set
# CONFIG_SND_SOC_MAX98363 is not set
# CONFIG_SND_SOC_MAX98373_I2C is not set
# CONFIG_SND_SOC_MAX98373_SDW is not set
# CONFIG_SND_SOC_MAX98388 is not set
# CONFIG_SND_SOC_MAX98390 is not set
# CONFIG_SND_SOC_MAX98396 is not set
# CONFIG_SND_SOC_MAX9860 is not set
# CONFIG_SND_SOC_MSM8916_WCD_DIGITAL is not set
# CONFIG_SND_SOC_PCM1681 is not set
# CONFIG_SND_SOC_PCM1754 is not set
# CONFIG_SND_SOC_PCM1789_I2C is not set
# CONFIG_SND_SOC_PCM179X_I2C is not set
# CONFIG_SND_SOC_PCM179X_SPI is not set
# CONFIG_SND_SOC_PCM186X_I2C is not set
# CONFIG_SND_SOC_PCM186X_SPI is not set
# CONFIG_SND_SOC_PCM3060_I2C is not set
# CONFIG_SND_SOC_PCM3060_SPI is not set
# CONFIG_SND_SOC_PCM3168A_I2C is not set
# CONFIG_SND_SOC_PCM3168A_SPI is not set
# CONFIG_SND_SOC_PCM5102A is not set
# CONFIG_SND_SOC_PCM512x_I2C is not set
# CONFIG_SND_SOC_PCM512x_SPI is not set
# CONFIG_SND_SOC_PCM6240 is not set
# CONFIG_SND_SOC_PEB2466 is not set
# CONFIG_SND_SOC_PM4125_SDW is not set
# CONFIG_SND_SOC_RT1017_SDCA_SDW is not set
# CONFIG_SND_SOC_RT1308_SDW is not set
# CONFIG_SND_SOC_RT1316_SDW is not set
# CONFIG_SND_SOC_RT1318_SDW is not set
# CONFIG_SND_SOC_RT1320_SDW is not set
# CONFIG_SND_SOC_RT5575 is not set
# CONFIG_SND_SOC_RT5616 is not set
# CONFIG_SND_SOC_RT5631 is not set
# CONFIG_SND_SOC_RT5640 is not set
# CONFIG_SND_SOC_RT5659 is not set
# CONFIG_SND_SOC_RT5682_SDW is not set
# CONFIG_SND_SOC_RT700_SDW is not set
# CONFIG_SND_SOC_RT711_SDW is not set
# CONFIG_SND_SOC_RT711_SDCA_SDW is not set
# CONFIG_SND_SOC_RT712_SDCA_SDW is not set
# CONFIG_SND_SOC_RT712_SDCA_DMIC_SDW is not set
# CONFIG_SND_SOC_RT721_SDCA_SDW is not set
# CONFIG_SND_SOC_RT722_SDCA_SDW is not set
# CONFIG_SND_SOC_RT715_SDW is not set
# CONFIG_SND_SOC_RT715_SDCA_SDW is not set
# CONFIG_SND_SOC_RT9120 is not set
# CONFIG_SND_SOC_RT9123 is not set
# CONFIG_SND_SOC_RT9123P is not set
# CONFIG_SND_SOC_RTQ9124 is not set
# CONFIG_SND_SOC_RTQ9128 is not set
# CONFIG_SND_SOC_SDW_MOCKUP is not set
# CONFIG_SND_SOC_SGTL5000 is not set
# CONFIG_SND_SOC_SIMPLE_AMPLIFIER is not set
# CONFIG_SND_SOC_SIMPLE_MUX is not set
# CONFIG_SND_SOC_SMA1303 is not set
# CONFIG_SND_SOC_SMA1307 is not set
CONFIG_SND_SOC_SPDIF=y
# CONFIG_SND_SOC_SRC4XXX_I2C is not set
# CONFIG_SND_SOC_SSM2305 is not set
# CONFIG_SND_SOC_SSM2518 is not set
# CONFIG_SND_SOC_SSM2602_SPI is not set
# CONFIG_SND_SOC_SSM2602_I2C is not set
# CONFIG_SND_SOC_SSM3515 is not set
# CONFIG_SND_SOC_SSM4567 is not set
# CONFIG_SND_SOC_STA32X is not set
# CONFIG_SND_SOC_STA350 is not set
# CONFIG_SND_SOC_STI_SAS is not set
# CONFIG_SND_SOC_TAS2552 is not set
# CONFIG_SND_SOC_TAS2562 is not set
# CONFIG_SND_SOC_TAS2764 is not set
# CONFIG_SND_SOC_TAS2770 is not set
# CONFIG_SND_SOC_TAS2780 is not set
# CONFIG_SND_SOC_TAS2781_I2C is not set
# CONFIG_SND_SOC_TAS5086 is not set
# CONFIG_SND_SOC_TAS571X is not set
# CONFIG_SND_SOC_TAS5720 is not set
# CONFIG_SND_SOC_TAS5805M is not set
# CONFIG_SND_SOC_TAS6424 is not set
# CONFIG_SND_SOC_TDA7419 is not set
# CONFIG_SND_SOC_TFA9879 is not set
# CONFIG_SND_SOC_TFA989X is not set
# CONFIG_SND_SOC_TLV320ADC3XXX is not set
# CONFIG_SND_SOC_TLV320AIC23_I2C is not set
# CONFIG_SND_SOC_TLV320AIC23_SPI is not set
# CONFIG_SND_SOC_TLV320AIC31XX is not set
# CONFIG_SND_SOC_TLV320AIC32X4_I2C is not set
# CONFIG_SND_SOC_TLV320AIC32X4_SPI is not set
# CONFIG_SND_SOC_TLV320AIC3X_I2C is not set
# CONFIG_SND_SOC_TLV320AIC3X_SPI is not set
# CONFIG_SND_SOC_TLV320ADCX140 is not set
# CONFIG_SND_SOC_TS3A227E is not set
# CONFIG_SND_SOC_TSCS42XX is not set
# CONFIG_SND_SOC_TSCS454 is not set
# CONFIG_SND_SOC_UDA1334 is not set
# CONFIG_SND_SOC_UDA1342 is not set
# CONFIG_SND_SOC_UDA1380 is not set
# CONFIG_SND_SOC_WCD937X_SDW is not set
# CONFIG_SND_SOC_WCD938X_SDW is not set
# CONFIG_SND_SOC_WCD939X_SDW is not set
# CONFIG_SND_SOC_WM8510 is not set
# CONFIG_SND_SOC_WM8523 is not set
# CONFIG_SND_SOC_WM8524 is not set
# CONFIG_SND_SOC_WM8580 is not set
# CONFIG_SND_SOC_WM8711 is not set
# CONFIG_SND_SOC_WM8728 is not set
# CONFIG_SND_SOC_WM8731_I2C is not set
# CONFIG_SND_SOC_WM8731_SPI is not set
# CONFIG_SND_SOC_WM8737 is not set
# CONFIG_SND_SOC_WM8741 is not set
# CONFIG_SND_SOC_WM8750 is not set
# CONFIG_SND_SOC_WM8753 is not set
# CONFIG_SND_SOC_WM8770 is not set
# CONFIG_SND_SOC_WM8776 is not set
# CONFIG_SND_SOC_WM8782 is not set
# CONFIG_SND_SOC_WM8804_I2C is not set
# CONFIG_SND_SOC_WM8804_SPI is not set
# CONFIG_SND_SOC_WM8903 is not set
# CONFIG_SND_SOC_WM8904 is not set
# CONFIG_SND_SOC_WM8940 is not set
# CONFIG_SND_SOC_WM8960 is not set
# CONFIG_SND_SOC_WM8961 is not set
# CONFIG_SND_SOC_WM8962 is not set
# CONFIG_SND_SOC_WM8974 is not set
CONFIG_SND_SOC_WM8978=y
# CONFIG_SND_SOC_WM8985 is not set
# CONFIG_SND_SOC_WSA881X is not set
# CONFIG_SND_SOC_WSA883X is not set
# CONFIG_SND_SOC_WSA884X is not set
# CONFIG_SND_SOC_ZL38060 is not set
# CONFIG_SND_SOC_MAX9759 is not set
# CONFIG_SND_SOC_MT6351 is not set
# CONFIG_SND_SOC_MT6357 is not set
# CONFIG_SND_SOC_MT6358 is not set
# CONFIG_SND_SOC_MT6660 is not set
# CONFIG_SND_SOC_NAU8315 is not set
# CONFIG_SND_SOC_NAU8325 is not set
# CONFIG_SND_SOC_NAU8540 is not set
# CONFIG_SND_SOC_NAU8810 is not set
# CONFIG_SND_SOC_NAU8821 is not set
# CONFIG_SND_SOC_NAU8822 is not set
# CONFIG_SND_SOC_NAU8824 is not set
# CONFIG_SND_SOC_NTP8918 is not set
# CONFIG_SND_SOC_NTP8835 is not set
# CONFIG_SND_SOC_TPA6130A2 is not set
# CONFIG_SND_SOC_LPASS_WSA_MACRO is not set
# CONFIG_SND_SOC_LPASS_VA_MACRO is not set
# CONFIG_SND_SOC_LPASS_RX_MACRO is not set
# CONFIG_SND_SOC_LPASS_TX_MACRO is not set
# end of CODEC drivers

#
# Generic drivers
#
CONFIG_SND_SIMPLE_CARD_UTILS=y
CONFIG_SND_SIMPLE_CARD=y
# CONFIG_SND_AUDIO_GRAPH_CARD is not set
# CONFIG_SND_AUDIO_GRAPH_CARD2 is not set
# CONFIG_SND_TEST_COMPONENT is not set
# end of Generic drivers

CONFIG_SND_VIRTIO=y
CONFIG_HID_SUPPORT=y
CONFIG_HID=y
CONFIG_HID_BATTERY_STRENGTH=y
CONFIG_HIDRAW=y
CONFIG_UHID=y
CONFIG_HID_GENERIC=y
CONFIG_HID_HAPTIC=y

#
# Special HID drivers
#
CONFIG_HID_A4TECH=y
CONFIG_HID_ACCUTOUCH=y
CONFIG_HID_ACRUX=y
CONFIG_HID_ACRUX_FF=y
CONFIG_HID_APPLE=y
CONFIG_HID_APPLEIR=y
CONFIG_HID_ASUS=y
CONFIG_HID_AUREAL=y
CONFIG_HID_BELKIN=y
CONFIG_HID_BETOP_FF=y
CONFIG_HID_BIGBEN_FF=y
CONFIG_HID_CHERRY=y
CONFIG_HID_CHICONY=y
CONFIG_HID_CORSAIR=y
CONFIG_HID_COUGAR=y
CONFIG_HID_MACALLY=y
CONFIG_HID_PRODIKEYS=y
CONFIG_HID_CMEDIA=y
CONFIG_HID_CP2112=y
CONFIG_HID_CREATIVE_SB0540=y
CONFIG_HID_CYPRESS=y
CONFIG_HID_DRAGONRISE=y
CONFIG_DRAGONRISE_FF=y
CONFIG_HID_EMS_FF=y
CONFIG_HID_ELAN=y
CONFIG_HID_ELECOM=y
CONFIG_HID_ELO=y
CONFIG_HID_EVISION=y
CONFIG_HID_EZKEY=y
CONFIG_HID_FT260=y
CONFIG_HID_GEMBIRD=y
CONFIG_HID_GFRM=y
CONFIG_HID_GLORIOUS=y
CONFIG_HID_HOLTEK=y
CONFIG_HOLTEK_FF=y
CONFIG_HID_VIVALDI_COMMON=y
# CONFIG_HID_GOODIX_SPI is not set
CONFIG_HID_GOOGLE_STADIA_FF=y
CONFIG_HID_VIVALDI=y
CONFIG_HID_GT683R=y
CONFIG_HID_KEYTOUCH=y
CONFIG_HID_KYE=y
# CONFIG_HID_KYSONA is not set
CONFIG_HID_UCLOGIC=y
CONFIG_HID_WALTOP=y
CONFIG_HID_VIEWSONIC=y
CONFIG_HID_VRC2=y
CONFIG_HID_XIAOMI=y
CONFIG_HID_GYRATION=y
CONFIG_HID_ICADE=y
CONFIG_HID_ITE=y
CONFIG_HID_JABRA=y
CONFIG_HID_TWINHAN=y
CONFIG_HID_KENSINGTON=y
CONFIG_HID_LCPOWER=y
CONFIG_HID_LED=y
CONFIG_HID_LENOVO=y
# CONFIG_HID_LENOVO_GO is not set
# CONFIG_HID_LENOVO_GO_S is not set
CONFIG_HID_LETSKETCH=y
CONFIG_HID_LOGITECH=y
CONFIG_HID_LOGITECH_DJ=y
CONFIG_HID_LOGITECH_HIDPP=y
CONFIG_LOGITECH_FF=y
CONFIG_LOGIRUMBLEPAD2_FF=y
CONFIG_LOGIG940_FF=y
CONFIG_LOGIWHEELS_FF=y
CONFIG_HID_MAGICMOUSE=y
CONFIG_HID_MALTRON=y
CONFIG_HID_MAYFLASH=y
CONFIG_HID_MEGAWORLD_FF=y
CONFIG_HID_REDRAGON=y
CONFIG_HID_MICROSOFT=y
CONFIG_HID_MONTEREY=y
CONFIG_HID_MULTITOUCH=y
CONFIG_HID_NINTENDO=y
CONFIG_NINTENDO_FF=y
CONFIG_HID_NTI=y
CONFIG_HID_NTRIG=y
CONFIG_HID_ORTEK=y
CONFIG_HID_PANTHERLORD=y
CONFIG_PANTHERLORD_FF=y
CONFIG_HID_PENMOUNT=y
CONFIG_HID_PETALYNX=y
CONFIG_HID_PICOLCD=y
CONFIG_HID_PICOLCD_FB=y
CONFIG_HID_PICOLCD_BACKLIGHT=y
CONFIG_HID_PICOLCD_LCD=y
CONFIG_HID_PICOLCD_LEDS=y
CONFIG_HID_PICOLCD_CIR=y
CONFIG_HID_PLANTRONICS=y
CONFIG_HID_PLAYSTATION=y
CONFIG_PLAYSTATION_FF=y
CONFIG_HID_PXRC=y
# CONFIG_HID_RAPOO is not set
CONFIG_HID_RAZER=y
CONFIG_HID_PRIMAX=y
CONFIG_HID_RETRODE=y
CONFIG_HID_ROCCAT=y
CONFIG_HID_SAITEK=y
CONFIG_HID_SAMSUNG=y
CONFIG_HID_SEMITEK=y
CONFIG_HID_SIGMAMICRO=y
CONFIG_HID_SONY=y
CONFIG_SONY_FF=y
CONFIG_HID_SPEEDLINK=y
CONFIG_HID_STEAM=y
CONFIG_STEAM_FF=y
CONFIG_HID_STEELSERIES=y
CONFIG_HID_SUNPLUS=y
CONFIG_HID_RMI=y
CONFIG_HID_GREENASIA=y
CONFIG_GREENASIA_FF=y
CONFIG_HID_SMARTJOYPLUS=y
CONFIG_SMARTJOYPLUS_FF=y
CONFIG_HID_TIVO=y
CONFIG_HID_TOPSEED=y
CONFIG_HID_TOPRE=y
CONFIG_HID_THINGM=y
CONFIG_HID_THRUSTMASTER=y
CONFIG_THRUSTMASTER_FF=y
CONFIG_HID_UDRAW_PS3=y
CONFIG_HID_U2FZERO=y
# CONFIG_HID_UNIVERSAL_PIDFF is not set
CONFIG_HID_WACOM=y
CONFIG_HID_WIIMOTE=y
# CONFIG_HID_WINWING is not set
CONFIG_HID_XINMO=y
CONFIG_HID_ZEROPLUS=y
CONFIG_ZEROPLUS_FF=y
CONFIG_HID_ZYDACRON=y
CONFIG_HID_SENSOR_HUB=y
CONFIG_HID_SENSOR_CUSTOM_SENSOR=y
CONFIG_HID_ALPS=y
CONFIG_HID_MCP2200=y
CONFIG_HID_MCP2221=y
# CONFIG_HID_HUAWEI is not set
# end of Special HID drivers

#
# HID-BPF support
#
# end of HID-BPF support

CONFIG_I2C_HID=y
CONFIG_I2C_HID_ACPI=y
CONFIG_I2C_HID_OF=y
# CONFIG_I2C_HID_OF_ELAN is not set
# CONFIG_I2C_HID_OF_GOODIX is not set
CONFIG_I2C_HID_CORE=y

#
# USB HID support
#
CONFIG_USB_HID=y
CONFIG_HID_PID=y
CONFIG_USB_HIDDEV=y
# end of USB HID support

CONFIG_USB_OHCI_LITTLE_ENDIAN=y
CONFIG_USB_SUPPORT=y
CONFIG_USB_COMMON=y
CONFIG_USB_LED_TRIG=y
CONFIG_USB_ULPI_BUS=y
CONFIG_USB_CONN_GPIO=y
CONFIG_USB_ARCH_HAS_HCD=y
CONFIG_USB=y
CONFIG_USB_PCI=y
CONFIG_USB_PCI_AMD=y
CONFIG_USB_ANNOUNCE_NEW_DEVICES=y

#
# Miscellaneous USB options
#
CONFIG_USB_DEFAULT_PERSIST=y
CONFIG_USB_FEW_INIT_RETRIES=y
CONFIG_USB_DYNAMIC_MINORS=y
CONFIG_USB_OTG=y
# CONFIG_USB_OTG_PRODUCTLIST is not set
# CONFIG_USB_OTG_DISABLE_EXTERNAL_HUB is not set
CONFIG_USB_OTG_FSM=y
CONFIG_USB_LEDS_TRIGGER_USBPORT=y
CONFIG_USB_AUTOSUSPEND_DELAY=2
CONFIG_USB_DEFAULT_AUTHORIZATION_MODE=1
CONFIG_USB_MON=y

#
# USB Host Controller Drivers
#
CONFIG_USB_C67X00_HCD=y
CONFIG_USB_XHCI_HCD=y
CONFIG_USB_XHCI_DBGCAP=y
CONFIG_USB_XHCI_PCI=y
CONFIG_USB_XHCI_PCI_RENESAS=y
CONFIG_USB_XHCI_PLATFORM=y
# CONFIG_USB_XHCI_SIDEBAND is not set
CONFIG_USB_EHCI_HCD=y
CONFIG_USB_EHCI_ROOT_HUB_TT=y
CONFIG_USB_EHCI_TT_NEWSCHED=y
CONFIG_USB_EHCI_PCI=y
CONFIG_USB_EHCI_FSL=y
CONFIG_USB_EHCI_HCD_PLATFORM=y
CONFIG_USB_OXU210HP_HCD=y
CONFIG_USB_ISP116X_HCD=y
CONFIG_USB_MAX3421_HCD=y
CONFIG_USB_OHCI_HCD=y
CONFIG_USB_OHCI_HCD_PCI=y
# CONFIG_USB_OHCI_HCD_SSB is not set
CONFIG_USB_OHCI_HCD_PLATFORM=y
CONFIG_USB_UHCI_HCD=y
CONFIG_USB_SL811_HCD=y
CONFIG_USB_SL811_HCD_ISO=y
CONFIG_USB_SL811_CS=y
CONFIG_USB_R8A66597_HCD=y
CONFIG_USB_HCD_BCMA=y
CONFIG_USB_HCD_SSB=y
# CONFIG_USB_HCD_TEST_MODE is not set

#
# USB Device Class drivers
#
CONFIG_USB_ACM=y
CONFIG_USB_PRINTER=y
CONFIG_USB_WDM=y
CONFIG_USB_TMC=y

#
# NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may also be needed; see USB_STORAGE Help for more info
#
CONFIG_USB_STORAGE=y
# CONFIG_USB_STORAGE_DEBUG is not set
CONFIG_USB_STORAGE_REALTEK=y
CONFIG_REALTEK_AUTOPM=y
CONFIG_USB_STORAGE_DATAFAB=y
CONFIG_USB_STORAGE_FREECOM=y
CONFIG_USB_STORAGE_ISD200=y
CONFIG_USB_STORAGE_USBAT=y
CONFIG_USB_STORAGE_SDDR09=y
CONFIG_USB_STORAGE_SDDR55=y
CONFIG_USB_STORAGE_JUMPSHOT=y
CONFIG_USB_STORAGE_ALAUDA=y
CONFIG_USB_STORAGE_ONETOUCH=y
CONFIG_USB_STORAGE_KARMA=y
CONFIG_USB_STORAGE_CYPRESS_ATACB=y
CONFIG_USB_STORAGE_ENE_UB6250=y
CONFIG_USB_UAS=y

#
# USB Imaging devices
#
CONFIG_USB_MDC800=y
CONFIG_USB_MICROTEK=y
# CONFIG_USBIP_CORE is not set

#
# USB dual-mode controller drivers
#
CONFIG_USB_CDNS_SUPPORT=y
CONFIG_USB_CDNS_HOST=y
CONFIG_USB_CDNS3=y
CONFIG_USB_CDNS3_GADGET=y
CONFIG_USB_CDNS3_HOST=y
CONFIG_USB_CDNS3_PCI_WRAP=y
CONFIG_USB_CDNS3_STARFIVE=y
CONFIG_USB_CDNSP_PCI=y
CONFIG_USB_CDNSP_GADGET=y
CONFIG_USB_CDNSP_HOST=y
CONFIG_USB_MUSB_HDRC=y
# CONFIG_USB_MUSB_HOST is not set
# CONFIG_USB_MUSB_GADGET is not set
CONFIG_USB_MUSB_DUAL_ROLE=y

#
# Platform Glue Layer
#
CONFIG_USB_MUSB_SUNXI=y
# CONFIG_USB_MUSB_POLARFIRE_SOC is not set

#
# MUSB DMA mode
#
CONFIG_MUSB_PIO_ONLY=y
CONFIG_USB_DWC3=y
CONFIG_USB_DWC3_ULPI=y
# CONFIG_USB_DWC3_HOST is not set
CONFIG_USB_DWC3_GADGET=y
# CONFIG_USB_DWC3_DUAL_ROLE is not set

#
# Platform Glue Driver Support
#
CONFIG_USB_DWC3_PCI=y
CONFIG_USB_DWC3_HAPS=y
CONFIG_USB_DWC3_OF_SIMPLE=y
CONFIG_USB_DWC3_GENERIC_PLAT=y
# CONFIG_USB_DWC3_GOOGLE is not set
CONFIG_USB_DWC2=y
CONFIG_USB_DWC2_HOST=y

#
# Gadget/Dual-role mode requires USB Gadget support to be enabled
#
# CONFIG_USB_DWC2_PERIPHERAL is not set
# CONFIG_USB_DWC2_DUAL_ROLE is not set
CONFIG_USB_DWC2_PCI=y
# CONFIG_USB_DWC2_DEBUG is not set
# CONFIG_USB_DWC2_TRACK_MISSED_SOFS is not set
CONFIG_USB_CHIPIDEA=y
CONFIG_USB_CHIPIDEA_UDC=y
CONFIG_USB_CHIPIDEA_HOST=y
CONFIG_USB_CHIPIDEA_PCI=y
CONFIG_USB_CHIPIDEA_MSM=y
CONFIG_USB_CHIPIDEA_NPCM=y
# CONFIG_USB_CHIPIDEA_IMX is not set
CONFIG_USB_CHIPIDEA_GENERIC=y
# CONFIG_USB_CHIPIDEA_TEGRA is not set
CONFIG_USB_ISP1760=y
CONFIG_USB_ISP1760_HCD=y
CONFIG_USB_ISP1761_UDC=y
# CONFIG_USB_ISP1760_HOST_ROLE is not set
# CONFIG_USB_ISP1760_GADGET_ROLE is not set
CONFIG_USB_ISP1760_DUAL_ROLE=y

#
# USB port drivers
#
CONFIG_USB_SERIAL=y
CONFIG_USB_SERIAL_CONSOLE=y
CONFIG_USB_SERIAL_GENERIC=y
CONFIG_USB_SERIAL_SIMPLE=y
CONFIG_USB_SERIAL_AIRCABLE=y
CONFIG_USB_SERIAL_ARK3116=y
CONFIG_USB_SERIAL_BELKIN=y
CONFIG_USB_SERIAL_CH341=y
CONFIG_USB_SERIAL_WHITEHEAT=y
CONFIG_USB_SERIAL_DIGI_ACCELEPORT=y
CONFIG_USB_SERIAL_CP210X=y
CONFIG_USB_SERIAL_CYPRESS_M8=y
CONFIG_USB_SERIAL_EMPEG=y
CONFIG_USB_SERIAL_FTDI_SIO=y
CONFIG_USB_SERIAL_VISOR=y
CONFIG_USB_SERIAL_IPAQ=y
CONFIG_USB_SERIAL_IR=y
CONFIG_USB_SERIAL_EDGEPORT=y
CONFIG_USB_SERIAL_EDGEPORT_TI=y
CONFIG_USB_SERIAL_F81232=y
CONFIG_USB_SERIAL_F8153X=y
CONFIG_USB_SERIAL_GARMIN=y
CONFIG_USB_SERIAL_IPW=y
CONFIG_USB_SERIAL_IUU=y
CONFIG_USB_SERIAL_KEYSPAN_PDA=y
CONFIG_USB_SERIAL_KEYSPAN=y
CONFIG_USB_SERIAL_KLSI=y
CONFIG_USB_SERIAL_KOBIL_SCT=y
CONFIG_USB_SERIAL_MCT_U232=y
CONFIG_USB_SERIAL_METRO=y
CONFIG_USB_SERIAL_MOS7720=y
CONFIG_USB_SERIAL_MOS7715_PARPORT=y
CONFIG_USB_SERIAL_MOS7840=y
CONFIG_USB_SERIAL_MXUPORT=y
CONFIG_USB_SERIAL_NAVMAN=y
CONFIG_USB_SERIAL_PL2303=y
CONFIG_USB_SERIAL_OTI6858=y
CONFIG_USB_SERIAL_QCAUX=y
CONFIG_USB_SERIAL_QUALCOMM=y
CONFIG_USB_SERIAL_SPCP8X5=y
CONFIG_USB_SERIAL_SAFE=y
# CONFIG_USB_SERIAL_SAFE_PADDED is not set
CONFIG_USB_SERIAL_SIERRAWIRELESS=y
CONFIG_USB_SERIAL_SYMBOL=y
CONFIG_USB_SERIAL_TI=y
CONFIG_USB_SERIAL_CYBERJACK=y
CONFIG_USB_SERIAL_WWAN=y
CONFIG_USB_SERIAL_OPTION=y
CONFIG_USB_SERIAL_OMNINET=y
CONFIG_USB_SERIAL_OPTICON=y
CONFIG_USB_SERIAL_XSENS_MT=y
CONFIG_USB_SERIAL_WISHBONE=y
CONFIG_USB_SERIAL_SSU100=y
CONFIG_USB_SERIAL_QT2=y
CONFIG_USB_SERIAL_UPD78F0730=y
CONFIG_USB_SERIAL_XR=y
CONFIG_USB_SERIAL_DEBUG=y

#
# USB Miscellaneous drivers
#
CONFIG_USB_USS720=y
CONFIG_USB_EMI62=y
CONFIG_USB_EMI26=y
CONFIG_USB_ADUTUX=y
CONFIG_USB_SEVSEG=y
CONFIG_USB_LEGOTOWER=y
CONFIG_USB_LCD=y
CONFIG_USB_CYPRESS_CY7C63=y
CONFIG_USB_CYTHERM=y
CONFIG_USB_IDMOUSE=y
CONFIG_USB_APPLEDISPLAY=y
CONFIG_APPLE_MFI_FASTCHARGE=y
CONFIG_USB_LJCA=y
CONFIG_USB_SISUSBVGA=y
CONFIG_USB_LD=y
CONFIG_USB_TRANCEVIBRATOR=y
CONFIG_USB_IOWARRIOR=y
CONFIG_USB_TEST=y
CONFIG_USB_EHSET_TEST_FIXTURE=y
CONFIG_USB_ISIGHTFW=y
CONFIG_USB_YUREX=y
CONFIG_USB_EZUSB_FX2=y
CONFIG_USB_HUB_USB251XB=y
CONFIG_USB_HSIC_USB3503=y
CONFIG_USB_HSIC_USB4604=y
CONFIG_USB_LINK_LAYER_TEST=y
CONFIG_USB_CHAOSKEY=y
# CONFIG_USB_ONBOARD_DEV is not set

#
# USB Physical Layer drivers
#
CONFIG_USB_PHY=y
CONFIG_NOP_USB_XCEIV=y
CONFIG_TAHVO_USB=y
CONFIG_TAHVO_USB_HOST_BY_DEFAULT=y
CONFIG_USB_ISP1301=y
# end of USB Physical Layer drivers

CONFIG_USB_GADGET=y
# CONFIG_USB_GADGET_DEBUG is not set
CONFIG_USB_GADGET_DEBUG_FILES=y
CONFIG_USB_GADGET_DEBUG_FS=y
CONFIG_USB_GADGET_VBUS_DRAW=2
CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=2
CONFIG_U_SERIAL_CONSOLE=y

#
# USB Peripheral Controller
#
CONFIG_USB_GR_UDC=y
CONFIG_USB_R8A66597=y
CONFIG_USB_PXA27X=y
CONFIG_USB_SNP_CORE=y
# CONFIG_USB_SNP_UDC_PLAT is not set
# CONFIG_USB_M66592 is not set
CONFIG_USB_BDC_UDC=y
CONFIG_USB_AMD5536UDC=y
CONFIG_USB_NET2280=y
CONFIG_USB_GOKU=y
CONFIG_USB_EG20T=y
# CONFIG_USB_GADGET_XILINX is not set
CONFIG_USB_MAX3420_UDC=y
CONFIG_USB_CDNS2_UDC=y
CONFIG_USB_DUMMY_HCD=y
# end of USB Peripheral Controller

CONFIG_USB_LIBCOMPOSITE=y
CONFIG_USB_F_ACM=y
CONFIG_USB_F_SS_LB=y
CONFIG_USB_U_SERIAL=y
CONFIG_USB_U_ETHER=y
CONFIG_USB_U_AUDIO=y
CONFIG_USB_F_SERIAL=y
CONFIG_USB_F_OBEX=y
CONFIG_USB_F_NCM=y
CONFIG_USB_F_ECM=y
CONFIG_USB_F_EEM=y
CONFIG_USB_F_SUBSET=y
CONFIG_USB_F_RNDIS=y
CONFIG_USB_F_MASS_STORAGE=y
CONFIG_USB_F_FS=y
CONFIG_USB_F_UAC1=y
CONFIG_USB_F_UAC1_LEGACY=y
CONFIG_USB_F_UAC2=y
CONFIG_USB_F_MIDI=y
CONFIG_USB_F_MIDI2=y
CONFIG_USB_F_HID=y
CONFIG_USB_F_PRINTER=y
CONFIG_USB_F_TCM=y
CONFIG_USB_CONFIGFS=y
CONFIG_USB_CONFIGFS_SERIAL=y
CONFIG_USB_CONFIGFS_ACM=y
CONFIG_USB_CONFIGFS_OBEX=y
CONFIG_USB_CONFIGFS_NCM=y
CONFIG_USB_CONFIGFS_ECM=y
CONFIG_USB_CONFIGFS_ECM_SUBSET=y
CONFIG_USB_CONFIGFS_RNDIS=y
CONFIG_USB_CONFIGFS_EEM=y
CONFIG_USB_CONFIGFS_MASS_STORAGE=y
CONFIG_USB_CONFIGFS_F_LB_SS=y
CONFIG_USB_CONFIGFS_F_FS=y
CONFIG_USB_CONFIGFS_F_UAC1=y
CONFIG_USB_CONFIGFS_F_UAC1_LEGACY=y
CONFIG_USB_CONFIGFS_F_UAC2=y
CONFIG_USB_CONFIGFS_F_MIDI=y
CONFIG_USB_CONFIGFS_F_MIDI2=y
CONFIG_USB_CONFIGFS_F_HID=y
CONFIG_USB_CONFIGFS_F_PRINTER=y
CONFIG_USB_CONFIGFS_F_TCM=y

#
# USB Gadget precomposed configurations
#
# CONFIG_USB_ZERO is not set
# CONFIG_USB_AUDIO is not set
# CONFIG_USB_ETH is not set
# CONFIG_USB_G_NCM is not set
CONFIG_USB_GADGETFS=y
# CONFIG_USB_FUNCTIONFS is not set
# CONFIG_USB_MASS_STORAGE is not set
# CONFIG_USB_GADGET_TARGET is not set
# CONFIG_USB_G_SERIAL is not set
# CONFIG_USB_MIDI_GADGET is not set
# CONFIG_USB_G_PRINTER is not set
# CONFIG_USB_CDC_COMPOSITE is not set
# CONFIG_USB_G_ACM_MS is not set
# CONFIG_USB_G_MULTI is not set
# CONFIG_USB_G_HID is not set
# CONFIG_USB_G_DBGP is not set
CONFIG_USB_RAW_GADGET=y
# end of USB Gadget precomposed configurations

CONFIG_TYPEC=y
CONFIG_TYPEC_TCPM=y
CONFIG_TYPEC_TCPCI=y
CONFIG_TYPEC_RT1711H=y
CONFIG_TYPEC_MT6360=y
CONFIG_TYPEC_TCPCI_MT6370=y
CONFIG_TYPEC_TCPCI_MAXIM=y
CONFIG_TYPEC_FUSB302=y
CONFIG_TYPEC_UCSI=y
CONFIG_UCSI_CCG=y
CONFIG_UCSI_ACPI=y
CONFIG_UCSI_STM32G0=y
CONFIG_TYPEC_TPS6598X=y
CONFIG_TYPEC_ANX7411=y
CONFIG_TYPEC_RT1719=y
CONFIG_TYPEC_HD3SS3220=y
CONFIG_TYPEC_STUSB160X=y
CONFIG_TYPEC_WUSB3801=y

#
# USB Type-C Multiplexer/DeMultiplexer Switch support
#
CONFIG_TYPEC_MUX_FSA4480=y
CONFIG_TYPEC_MUX_GPIO_SBU=y
CONFIG_TYPEC_MUX_PI3USB30532=y
# CONFIG_TYPEC_MUX_IT5205 is not set
CONFIG_TYPEC_MUX_NB7VPQ904M=y
# CONFIG_TYPEC_MUX_PS883X is not set
CONFIG_TYPEC_MUX_PTN36502=y
# CONFIG_TYPEC_MUX_TUSB1046 is not set
CONFIG_TYPEC_MUX_WCD939X_USBSS=y
# end of USB Type-C Multiplexer/DeMultiplexer Switch support

#
# USB Type-C Alternate Mode drivers
#
CONFIG_TYPEC_DP_ALTMODE=y
CONFIG_TYPEC_NVIDIA_ALTMODE=y
# CONFIG_TYPEC_TBT_ALTMODE is not set
# end of USB Type-C Alternate Mode drivers

CONFIG_USB_ROLE_SWITCH=y
CONFIG_MMC=y
CONFIG_PWRSEQ_EMMC=y
CONFIG_PWRSEQ_SIMPLE=y
CONFIG_MMC_BLOCK=y
CONFIG_MMC_BLOCK_MINORS=8
# CONFIG_SDIO_UART is not set
# CONFIG_MMC_TEST is not set
# CONFIG_MMC_CRYPTO is not set

#
# MMC/SD/SDIO Host Controller Drivers
#
# CONFIG_MMC_DEBUG is not set
# CONFIG_MMC_ARMMMCI is not set
CONFIG_MMC_SDHCI=y
CONFIG_MMC_SDHCI_IO_ACCESSORS=y
# CONFIG_MMC_SDHCI_PCI is not set
# CONFIG_MMC_SDHCI_ACPI is not set
CONFIG_MMC_SDHCI_PLTFM=y
# CONFIG_MMC_SDHCI_OF_ARASAN is not set
# CONFIG_MMC_SDHCI_OF_AT91 is not set
CONFIG_MMC_SDHCI_OF_DWCMSHC=y
CONFIG_MMC_SDHCI_OF_K1=y
CONFIG_MMC_SDHCI_CADENCE=y
# CONFIG_MMC_SDHCI_F_SDH30 is not set
# CONFIG_MMC_SDHCI_MILBEAUT is not set
# CONFIG_MMC_TIFM_SD is not set
CONFIG_MMC_SPI=y
# CONFIG_MMC_SDRICOH_CS is not set
# CONFIG_MMC_CB710 is not set
# CONFIG_MMC_VIA_SDMMC is not set
CONFIG_MMC_DW=y
CONFIG_MMC_DW_PLTFM=y
# CONFIG_MMC_DW_BLUEFIELD is not set
# CONFIG_MMC_DW_EXYNOS is not set
# CONFIG_MMC_DW_HI3798CV200 is not set
# CONFIG_MMC_DW_HI3798MV200 is not set
# CONFIG_MMC_DW_K3 is not set
# CONFIG_MMC_DW_PCI is not set
CONFIG_MMC_DW_STARFIVE=y
CONFIG_MMC_VUB300=y
CONFIG_MMC_USHC=y
# CONFIG_MMC_USDHI6ROL0 is not set
CONFIG_MMC_REALTEK_USB=y
CONFIG_MMC_SUNXI=y
CONFIG_MMC_CQHCI=y
# CONFIG_MMC_HSQ is not set
# CONFIG_MMC_TOSHIBA_PCI is not set
# CONFIG_MMC_MTK is not set
# CONFIG_MMC_SDHCI_XENON is not set
# CONFIG_SCSI_UFSHCD is not set
CONFIG_MEMSTICK=y
# CONFIG_MEMSTICK_DEBUG is not set

#
# MemoryStick drivers
#
# CONFIG_MEMSTICK_UNSAFE_RESUME is not set
# CONFIG_MSPRO_BLOCK is not set
# CONFIG_MS_BLOCK is not set

#
# MemoryStick Host Controller Drivers
#
# CONFIG_MEMSTICK_TIFM_MS is not set
# CONFIG_MEMSTICK_JMICRON_38X is not set
# CONFIG_MEMSTICK_R592 is not set
CONFIG_MEMSTICK_REALTEK_USB=y
CONFIG_NEW_LEDS=y
CONFIG_LEDS_CLASS=y
# CONFIG_LEDS_CLASS_FLASH is not set
CONFIG_LEDS_CLASS_MULTICOLOR=y
# CONFIG_LEDS_BRIGHTNESS_HW_CHANGED is not set

#
# LED drivers
#
# CONFIG_LEDS_AN30259A is not set
# CONFIG_LEDS_OSRAM_AMS_AS3668 is not set
# CONFIG_LEDS_AW200XX is not set
# CONFIG_LEDS_AW2013 is not set
# CONFIG_LEDS_BCM6328 is not set
# CONFIG_LEDS_BCM6358 is not set
# CONFIG_LEDS_CR0014114 is not set
# CONFIG_LEDS_EL15203000 is not set
# CONFIG_LEDS_LM3530 is not set
# CONFIG_LEDS_LM3532 is not set
# CONFIG_LEDS_LM3642 is not set
# CONFIG_LEDS_LM3692X is not set
# CONFIG_LEDS_SUN50I_A100 is not set
# CONFIG_LEDS_PCA9532 is not set
# CONFIG_LEDS_GPIO is not set
# CONFIG_LEDS_LP3944 is not set
# CONFIG_LEDS_LP3952 is not set
# CONFIG_LEDS_LP50XX is not set
# CONFIG_LEDS_LP55XX_COMMON is not set
# CONFIG_LEDS_LP8860 is not set
# CONFIG_LEDS_LP8864 is not set
# CONFIG_LEDS_PCA955X is not set
# CONFIG_LEDS_PCA963X is not set
# CONFIG_LEDS_PCA995X is not set
# CONFIG_LEDS_DAC124S085 is not set
# CONFIG_LEDS_PWM is not set
# CONFIG_LEDS_REGULATOR is not set
# CONFIG_LEDS_BD2606MVV is not set
# CONFIG_LEDS_BD2802 is not set
# CONFIG_LEDS_LT3593 is not set
# CONFIG_LEDS_TCA6507 is not set
# CONFIG_LEDS_TLC591XX is not set
# CONFIG_LEDS_LM355x is not set
# CONFIG_LEDS_IS31FL319X is not set
# CONFIG_LEDS_IS31FL32XX is not set

#
# LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)
#
# CONFIG_LEDS_BLINKM is not set
# CONFIG_LEDS_SYSCON is not set
# CONFIG_LEDS_MLXREG is not set
# CONFIG_LEDS_USER is not set
# CONFIG_LEDS_SPI_BYTE is not set
# CONFIG_LEDS_LM3697 is not set
# CONFIG_LEDS_ST1202 is not set

#
# Flash and Torch LED drivers
#

#
# RGB LED drivers
#
# CONFIG_LEDS_GROUP_MULTICOLOR is not set
# CONFIG_LEDS_KTD202X is not set
# CONFIG_LEDS_LP5812 is not set
# CONFIG_LEDS_NCP5623 is not set
# CONFIG_LEDS_PWM_MULTICOLOR is not set
# CONFIG_LEDS_MT6370_RGB is not set

#
# LED Triggers
#
CONFIG_LEDS_TRIGGERS=y
# CONFIG_LEDS_TRIGGER_TIMER is not set
# CONFIG_LEDS_TRIGGER_ONESHOT is not set
# CONFIG_LEDS_TRIGGER_DISK is not set
# CONFIG_LEDS_TRIGGER_MTD is not set
# CONFIG_LEDS_TRIGGER_HEARTBEAT is not set
# CONFIG_LEDS_TRIGGER_BACKLIGHT is not set
# CONFIG_LEDS_TRIGGER_CPU is not set
# CONFIG_LEDS_TRIGGER_ACTIVITY is not set
# CONFIG_LEDS_TRIGGER_GPIO is not set
# CONFIG_LEDS_TRIGGER_DEFAULT_ON is not set

#
# iptables trigger is under Netfilter config (LED target)
#
# CONFIG_LEDS_TRIGGER_TRANSIENT is not set
# CONFIG_LEDS_TRIGGER_CAMERA is not set
# CONFIG_LEDS_TRIGGER_PANIC is not set
# CONFIG_LEDS_TRIGGER_NETDEV is not set
# CONFIG_LEDS_TRIGGER_PATTERN is not set
# CONFIG_LEDS_TRIGGER_TTY is not set
# CONFIG_LEDS_TRIGGER_INPUT_EVENTS is not set

#
# Simatic LED drivers
#
# CONFIG_ACCESSIBILITY is not set
CONFIG_INFINIBAND=y
CONFIG_INFINIBAND_USER_MAD=y
CONFIG_INFINIBAND_USER_ACCESS=y
CONFIG_INFINIBAND_USER_MEM=y
CONFIG_INFINIBAND_ON_DEMAND_PAGING=y
CONFIG_INFINIBAND_ADDR_TRANS=y
CONFIG_INFINIBAND_ADDR_TRANS_CONFIGFS=y
CONFIG_INFINIBAND_VIRT_DMA=y
# CONFIG_INFINIBAND_EFA is not set
# CONFIG_INFINIBAND_ERDMA is not set
CONFIG_MLX4_INFINIBAND=y
# CONFIG_INFINIBAND_MTHCA is not set
# CONFIG_INFINIBAND_OCRDMA is not set
# CONFIG_INFINIBAND_VMWARE_PVRDMA is not set
CONFIG_RDMA_RXE=y
CONFIG_RDMA_SIW=y
CONFIG_INFINIBAND_IPOIB=y
CONFIG_INFINIBAND_IPOIB_CM=y
CONFIG_INFINIBAND_IPOIB_DEBUG=y
# CONFIG_INFINIBAND_IPOIB_DEBUG_DATA is not set
CONFIG_INFINIBAND_SRP=y
# CONFIG_INFINIBAND_SRPT is not set
CONFIG_INFINIBAND_ISER=y
CONFIG_INFINIBAND_RTRS=y
CONFIG_INFINIBAND_RTRS_CLIENT=y
# CONFIG_INFINIBAND_RTRS_SERVER is not set
CONFIG_EDAC_SUPPORT=y
CONFIG_EDAC=y
# CONFIG_EDAC_DEBUG is not set
# CONFIG_EDAC_SCRUB is not set
# CONFIG_EDAC_ECS is not set
# CONFIG_EDAC_MEM_REPAIR is not set
# CONFIG_EDAC_SIFIVE is not set
CONFIG_RTC_LIB=y
CONFIG_RTC_CLASS=y
# CONFIG_RTC_HCTOSYS is not set
CONFIG_RTC_SYSTOHC=y
CONFIG_RTC_SYSTOHC_DEVICE="rtc0"
# CONFIG_RTC_DEBUG is not set
# CONFIG_RTC_NVMEM is not set

#
# RTC interfaces
#
CONFIG_RTC_INTF_SYSFS=y
CONFIG_RTC_INTF_PROC=y
CONFIG_RTC_INTF_DEV=y
# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
# CONFIG_RTC_DRV_TEST is not set

#
# I2C RTC drivers
#
# CONFIG_RTC_DRV_ABB5ZES3 is not set
# CONFIG_RTC_DRV_ABEOZ9 is not set
# CONFIG_RTC_DRV_ABX80X is not set
# CONFIG_RTC_DRV_DS1307 is not set
# CONFIG_RTC_DRV_DS1374 is not set
# CONFIG_RTC_DRV_DS1672 is not set
# CONFIG_RTC_DRV_HYM8563 is not set
# CONFIG_RTC_DRV_MAX6900 is not set
# CONFIG_RTC_DRV_MAX31335 is not set
CONFIG_RTC_DRV_SPACEMIT_P1=y
# CONFIG_RTC_DRV_NCT3018Y is not set
# CONFIG_RTC_DRV_RS5C372 is not set
# CONFIG_RTC_DRV_ISL1208 is not set
# CONFIG_RTC_DRV_ISL12022 is not set
# CONFIG_RTC_DRV_ISL12026 is not set
# CONFIG_RTC_DRV_X1205 is not set
# CONFIG_RTC_DRV_PCF8523 is not set
# CONFIG_RTC_DRV_PCF85363 is not set
# CONFIG_RTC_DRV_PCF8563 is not set
# CONFIG_RTC_DRV_PCF8583 is not set
# CONFIG_RTC_DRV_M41T80 is not set
# CONFIG_RTC_DRV_BQ32K is not set
# CONFIG_RTC_DRV_TWL4030 is not set
# CONFIG_RTC_DRV_S35390A is not set
# CONFIG_RTC_DRV_FM3130 is not set
# CONFIG_RTC_DRV_RX8010 is not set
# CONFIG_RTC_DRV_RX8111 is not set
# CONFIG_RTC_DRV_RX8581 is not set
# CONFIG_RTC_DRV_RX8025 is not set
# CONFIG_RTC_DRV_EM3027 is not set
# CONFIG_RTC_DRV_RV3028 is not set
# CONFIG_RTC_DRV_RV3032 is not set
# CONFIG_RTC_DRV_RV8803 is not set
# CONFIG_RTC_DRV_SD2405AL is not set
# CONFIG_RTC_DRV_SD3078 is not set

#
# SPI RTC drivers
#
# CONFIG_RTC_DRV_M41T93 is not set
# CONFIG_RTC_DRV_M41T94 is not set
# CONFIG_RTC_DRV_DS1302 is not set
# CONFIG_RTC_DRV_DS1305 is not set
# CONFIG_RTC_DRV_DS1343 is not set
# CONFIG_RTC_DRV_DS1347 is not set
# CONFIG_RTC_DRV_DS1390 is not set
# CONFIG_RTC_DRV_MAX6916 is not set
# CONFIG_RTC_DRV_R9701 is not set
# CONFIG_RTC_DRV_RX4581 is not set
# CONFIG_RTC_DRV_RS5C348 is not set
# CONFIG_RTC_DRV_MAX6902 is not set
# CONFIG_RTC_DRV_PCF2123 is not set
# CONFIG_RTC_DRV_MCP795 is not set
CONFIG_RTC_I2C_AND_SPI=y

#
# SPI and I2C RTC drivers
#
# CONFIG_RTC_DRV_DS3232 is not set
# CONFIG_RTC_DRV_PCF2127 is not set
# CONFIG_RTC_DRV_PCF85063 is not set
# CONFIG_RTC_DRV_RV3029C2 is not set
# CONFIG_RTC_DRV_RX6110 is not set

#
# Platform RTC drivers
#
# CONFIG_RTC_DRV_ATCRTC100 is not set
# CONFIG_RTC_DRV_DS1286 is not set
# CONFIG_RTC_DRV_DS1511 is not set
# CONFIG_RTC_DRV_DS1553 is not set
# CONFIG_RTC_DRV_DS1685_FAMILY is not set
# CONFIG_RTC_DRV_DS1742 is not set
# CONFIG_RTC_DRV_DS2404 is not set
# CONFIG_RTC_DRV_EFI is not set
# CONFIG_RTC_DRV_STK17TA8 is not set
# CONFIG_RTC_DRV_M48T86 is not set
# CONFIG_RTC_DRV_M48T35 is not set
# CONFIG_RTC_DRV_M48T59 is not set
# CONFIG_RTC_DRV_MSM6242 is not set
# CONFIG_RTC_DRV_RP5C01 is not set
# CONFIG_RTC_DRV_ZYNQMP is not set

#
# on-CPU RTC drivers
#
# CONFIG_RTC_DRV_PL030 is not set
# CONFIG_RTC_DRV_PL031 is not set
CONFIG_RTC_DRV_SUN6I=y
# CONFIG_RTC_DRV_CADENCE is not set
# CONFIG_RTC_DRV_FTRTC010 is not set
# CONFIG_RTC_DRV_R7301 is not set
CONFIG_RTC_DRV_GOLDFISH=y
# CONFIG_RTC_DRV_POLARFIRE_SOC is not set

#
# HID Sensor RTC drivers
#
CONFIG_RTC_DRV_HID_SENSOR_TIME=y
CONFIG_DMADEVICES=y
# CONFIG_DMADEVICES_DEBUG is not set

#
# DMA Devices
#
CONFIG_DMA_ENGINE=y
CONFIG_DMA_VIRTUAL_CHANNELS=y
CONFIG_DMA_ACPI=y
CONFIG_DMA_OF=y
# CONFIG_ALTERA_MSGDMA is not set
# CONFIG_AMBA_PL08X is not set
# CONFIG_AT_XDMAC is not set
CONFIG_DMA_SUN6I=y
CONFIG_DW_AXI_DMAC=y
# CONFIG_FSL_EDMA is not set
# CONFIG_INTEL_IDMA64 is not set
CONFIG_MMP_PDMA=y
# CONFIG_PL330_DMA is not set
# CONFIG_PLX_DMA is not set
# CONFIG_SOPHGO_CV1800B_DMAMUX is not set
# CONFIG_SWITCHTEC_DMA is not set
# CONFIG_XILINX_DMA is not set
# CONFIG_XILINX_XDMA is not set
# CONFIG_XILINX_ZYNQMP_DPDMA is not set
# CONFIG_AMD_QDMA is not set
# CONFIG_QCOM_HIDMA_MGMT is not set
# CONFIG_QCOM_HIDMA is not set
# CONFIG_DW_DMAC is not set
# CONFIG_DW_DMAC_PCI is not set
# CONFIG_DW_EDMA is not set
# CONFIG_SF_PDMA is not set

#
# DMA Clients
#
CONFIG_ASYNC_TX_DMA=y
# CONFIG_DMATEST is not set

#
# DMABUF options
#
CONFIG_SYNC_FILE=y
CONFIG_SW_SYNC=y
CONFIG_UDMABUF=y
# CONFIG_DMABUF_DEBUG is not set
# CONFIG_DMABUF_SELFTESTS is not set
CONFIG_DMABUF_HEAPS=y
CONFIG_DMABUF_HEAPS_SYSTEM=y
CONFIG_DMABUF_HEAPS_CMA=y
# end of DMABUF options

# CONFIG_UIO is not set
# CONFIG_VFIO is not set
CONFIG_IRQ_BYPASS_MANAGER=y
# CONFIG_VIRT_DRIVERS is not set
CONFIG_VIRTIO_ANCHOR=y
CONFIG_VIRTIO=y
CONFIG_VIRTIO_PCI_LIB=y
CONFIG_VIRTIO_PCI_LIB_LEGACY=y
CONFIG_VIRTIO_MENU=y
CONFIG_VIRTIO_PCI=y
CONFIG_VIRTIO_PCI_LEGACY=y
CONFIG_VIRTIO_VDPA=y
# CONFIG_VIRTIO_PMEM is not set
CONFIG_VIRTIO_BALLOON=y
# CONFIG_VIRTIO_MEM is not set
CONFIG_VIRTIO_INPUT=y
CONFIG_VIRTIO_MMIO=y
CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
CONFIG_VIRTIO_DMA_SHARED_BUFFER=y
# CONFIG_VIRTIO_DEBUG is not set
# CONFIG_VIRTIO_RTC is not set
CONFIG_VDPA=y
# CONFIG_VDPA_SIM is not set
# CONFIG_VDPA_USER is not set
# CONFIG_IFCVF is not set
# CONFIG_MLX5_VDPA_STEERING_DEBUG is not set
CONFIG_VP_VDPA=y
# CONFIG_OCTEONEP_VDPA is not set
CONFIG_VHOST_IOTLB=y
CONFIG_VHOST_TASK=y
CONFIG_VHOST=y
CONFIG_VHOST_MENU=y
CONFIG_VHOST_NET=y
# CONFIG_VHOST_SCSI is not set
CONFIG_VHOST_VSOCK=y
CONFIG_VHOST_VDPA=y
CONFIG_VHOST_CROSS_ENDIAN_LEGACY=y
CONFIG_VHOST_ENABLE_FORK_OWNER_CONTROL=y

#
# Microsoft Hyper-V guest support
#
# end of Microsoft Hyper-V guest support

CONFIG_GREYBUS=y
# CONFIG_GREYBUS_BEAGLEPLAY is not set
CONFIG_GREYBUS_ES2=y
CONFIG_COMEDI=y
# CONFIG_COMEDI_DEBUG is not set
CONFIG_COMEDI_DEFAULT_BUF_SIZE_KB=2048
CONFIG_COMEDI_DEFAULT_BUF_MAXSIZE_KB=20480
CONFIG_COMEDI_MISC_DRIVERS=y
CONFIG_COMEDI_BOND=y
CONFIG_COMEDI_TEST=y
CONFIG_COMEDI_PARPORT=y
CONFIG_COMEDI_PCI_DRIVERS=y
CONFIG_COMEDI_8255_PCI=y
# CONFIG_COMEDI_ADDI_APCI_1032 is not set
# CONFIG_COMEDI_ADDI_APCI_1500 is not set
# CONFIG_COMEDI_ADDI_APCI_1516 is not set
# CONFIG_COMEDI_ADDI_APCI_1564 is not set
# CONFIG_COMEDI_ADDI_APCI_16XX is not set
# CONFIG_COMEDI_ADDI_APCI_2032 is not set
# CONFIG_COMEDI_ADDI_APCI_2200 is not set
# CONFIG_COMEDI_ADDI_APCI_3120 is not set
# CONFIG_COMEDI_ADDI_APCI_3501 is not set
# CONFIG_COMEDI_ADDI_APCI_3XXX is not set
# CONFIG_COMEDI_ADL_PCI6208 is not set
# CONFIG_COMEDI_ADL_PCI7250 is not set
# CONFIG_COMEDI_ADL_PCI7X3X is not set
# CONFIG_COMEDI_ADL_PCI8164 is not set
# CONFIG_COMEDI_ADL_PCI9111 is not set
CONFIG_COMEDI_ADL_PCI9118=y
# CONFIG_COMEDI_ADV_PCI1710 is not set
# CONFIG_COMEDI_ADV_PCI1720 is not set
# CONFIG_COMEDI_ADV_PCI1723 is not set
# CONFIG_COMEDI_ADV_PCI1724 is not set
# CONFIG_COMEDI_ADV_PCI1760 is not set
# CONFIG_COMEDI_ADV_PCI_DIO is not set
# CONFIG_COMEDI_AMPLC_DIO200_PCI is not set
# CONFIG_COMEDI_AMPLC_PC236_PCI is not set
# CONFIG_COMEDI_AMPLC_PC263_PCI is not set
# CONFIG_COMEDI_AMPLC_PCI224 is not set
# CONFIG_COMEDI_AMPLC_PCI230 is not set
# CONFIG_COMEDI_CONTEC_PCI_DIO is not set
# CONFIG_COMEDI_DAS08_PCI is not set
# CONFIG_COMEDI_DT3000 is not set
# CONFIG_COMEDI_DYNA_PCI10XX is not set
# CONFIG_COMEDI_GSC_HPDI is not set
# CONFIG_COMEDI_MF6X4 is not set
# CONFIG_COMEDI_ICP_MULTI is not set
# CONFIG_COMEDI_DAQBOARD2000 is not set
# CONFIG_COMEDI_JR3_PCI is not set
# CONFIG_COMEDI_KE_COUNTER is not set
# CONFIG_COMEDI_CB_PCIDAS64 is not set
# CONFIG_COMEDI_CB_PCIDAS is not set
# CONFIG_COMEDI_CB_PCIDDA is not set
# CONFIG_COMEDI_CB_PCIMDAS is not set
# CONFIG_COMEDI_CB_PCIMDDA is not set
# CONFIG_COMEDI_ME4000 is not set
# CONFIG_COMEDI_ME_DAQ is not set
# CONFIG_COMEDI_NI_6527 is not set
# CONFIG_COMEDI_NI_65XX is not set
# CONFIG_COMEDI_NI_660X is not set
# CONFIG_COMEDI_NI_670X is not set
CONFIG_COMEDI_NI_LABPC_PCI=y
# CONFIG_COMEDI_NI_PCIDIO is not set
# CONFIG_COMEDI_NI_PCIMIO is not set
# CONFIG_COMEDI_RTD520 is not set
# CONFIG_COMEDI_S626 is not set
CONFIG_COMEDI_PCMCIA_DRIVERS=y
# CONFIG_COMEDI_CB_DAS16_CS is not set
# CONFIG_COMEDI_DAS08_CS is not set
CONFIG_COMEDI_NI_DAQ_700_CS=y
# CONFIG_COMEDI_NI_DAQ_DIO24_CS is not set
CONFIG_COMEDI_NI_LABPC_CS=y
# CONFIG_COMEDI_NI_MIO_CS is not set
# CONFIG_COMEDI_QUATECH_DAQP_CS is not set
CONFIG_COMEDI_USB_DRIVERS=y
CONFIG_COMEDI_DT9812=y
CONFIG_COMEDI_NI_USB6501=y
CONFIG_COMEDI_USBDUX=y
CONFIG_COMEDI_USBDUXFAST=y
CONFIG_COMEDI_USBDUXSIGMA=y
CONFIG_COMEDI_VMK80XX=y
CONFIG_COMEDI_8254=y
CONFIG_COMEDI_8255=y
CONFIG_COMEDI_8255_SA=y
CONFIG_COMEDI_KCOMEDILIB=y
CONFIG_COMEDI_NI_LABPC=y
# CONFIG_COMEDI_TESTS is not set
# CONFIG_GPIB is not set
CONFIG_STAGING=y

#
# IIO staging drivers
#

#
# Accelerometers
#
# CONFIG_ADIS16203 is not set
# end of Accelerometers

#
# Analog to digital converters
#
# CONFIG_AD7816 is not set
# end of Analog to digital converters

#
# Analog digital bi-direction converters
#
# CONFIG_ADT7316 is not set
# end of Analog digital bi-direction converters

#
# Direct Digital Synthesis
#
# CONFIG_AD9832 is not set
# CONFIG_AD9834 is not set
# end of Direct Digital Synthesis

#
# Network Analyzer, Impedance Converters
#
# CONFIG_AD5933 is not set
# end of Network Analyzer, Impedance Converters
# end of IIO staging drivers

# CONFIG_FB_SM750 is not set
# CONFIG_STAGING_MEDIA is not set
# CONFIG_FB_TFT is not set
# CONFIG_MOST_COMPONENTS is not set
# CONFIG_GREYBUS_AUDIO is not set
# CONFIG_GREYBUS_BOOTROM is not set
# CONFIG_GREYBUS_FIRMWARE is not set
CONFIG_GREYBUS_HID=y
# CONFIG_GREYBUS_LOG is not set
# CONFIG_GREYBUS_LOOPBACK is not set
# CONFIG_GREYBUS_POWER is not set
# CONFIG_GREYBUS_RAW is not set
# CONFIG_GREYBUS_VIBRATOR is not set
CONFIG_GREYBUS_BRIDGED_PHY=y
# CONFIG_GREYBUS_GPIO is not set
# CONFIG_GREYBUS_I2C is not set
# CONFIG_GREYBUS_PWM is not set
# CONFIG_GREYBUS_SDIO is not set
# CONFIG_GREYBUS_SPI is not set
# CONFIG_GREYBUS_UART is not set
CONFIG_GREYBUS_USB=y
# CONFIG_XIL_AXIS_FIFO is not set
# CONFIG_VME_BUS is not set
CONFIG_GOLDFISH=y
# CONFIG_GOLDFISH_PIPE is not set
CONFIG_HAVE_CLK=y
CONFIG_HAVE_CLK_PREPARE=y
CONFIG_COMMON_CLK=y
# CONFIG_LMK04832 is not set
# CONFIG_COMMON_CLK_MAX9485 is not set
# CONFIG_COMMON_CLK_SI5341 is not set
# CONFIG_COMMON_CLK_SI5351 is not set
# CONFIG_COMMON_CLK_SI514 is not set
# CONFIG_COMMON_CLK_SI544 is not set
# CONFIG_COMMON_CLK_SI570 is not set
# CONFIG_COMMON_CLK_CDCE706 is not set
# CONFIG_COMMON_CLK_CDCE925 is not set
# CONFIG_COMMON_CLK_CS2000_CP is not set
# CONFIG_CLK_TWL is not set
# CONFIG_COMMON_CLK_AXI_CLKGEN is not set
# CONFIG_COMMON_CLK_PWM is not set
# CONFIG_COMMON_CLK_RS9_PCIE is not set
# CONFIG_COMMON_CLK_SI521XX is not set
# CONFIG_COMMON_CLK_VC3 is not set
# CONFIG_COMMON_CLK_VC5 is not set
# CONFIG_COMMON_CLK_VC7 is not set
# CONFIG_COMMON_CLK_FIXED_MMIO is not set
CONFIG_COMMON_CLK_RPMI=y
CONFIG_CLK_ANALOGBITS_WRPLL_CLN28HPC=y
CONFIG_MCHP_CLK_MPFS=y
CONFIG_CLK_SIFIVE=y
CONFIG_CLK_SIFIVE_PRCI=y
CONFIG_CLK_SOPHGO_CV1800=y
CONFIG_CLK_SOPHGO_SG2042_PLL=y
CONFIG_CLK_SOPHGO_SG2042_CLKGEN=y
CONFIG_CLK_SOPHGO_SG2042_RPGATE=y
# CONFIG_CLK_SOPHGO_SG2044 is not set
# CONFIG_CLK_SOPHGO_SG2044_PLL is not set

#
# Clock support for SpacemiT platforms
#
CONFIG_SPACEMIT_CCU=y
CONFIG_SPACEMIT_K1_CCU=y
# CONFIG_SPACEMIT_K3_CCU is not set
# end of Clock support for SpacemiT platforms

CONFIG_CLK_STARFIVE_JH71X0=y
CONFIG_CLK_STARFIVE_JH7100=y
CONFIG_CLK_STARFIVE_JH7100_AUDIO=y
CONFIG_CLK_STARFIVE_JH7110_PLL=y
CONFIG_CLK_STARFIVE_JH7110_SYS=y
CONFIG_CLK_STARFIVE_JH7110_AON=y
CONFIG_CLK_STARFIVE_JH7110_STG=y
CONFIG_CLK_STARFIVE_JH7110_ISP=y
CONFIG_CLK_STARFIVE_JH7110_VOUT=y
CONFIG_SUNXI_CCU=y
CONFIG_SUN20I_D1_CCU=y
CONFIG_SUN20I_D1_R_CCU=y
CONFIG_SUN6I_RTC_CCU=y
CONFIG_SUN8I_DE2_CCU=y
CONFIG_TENSTORRENT_ATLANTIS_PRCM=y
CONFIG_CLK_THEAD_TH1520_AP=y
# CONFIG_XILINX_VCU is not set
# CONFIG_COMMON_CLK_XLNX_CLKWZRD is not set
# CONFIG_HWSPINLOCK is not set

#
# Clock Source drivers
#
CONFIG_TIMER_OF=y
CONFIG_TIMER_PROBE=y
CONFIG_CLKSRC_MMIO=y
CONFIG_SUN4I_TIMER=y
CONFIG_RISCV_TIMER=y
# end of Clock Source drivers

CONFIG_MAILBOX=y
# CONFIG_ARM_MHU is not set
# CONFIG_ARM_MHU_V2 is not set
# CONFIG_CV1800_MBOX is not set
# CONFIG_PLATFORM_MHU is not set
# CONFIG_PL320_MBOX is not set
CONFIG_PCC=y
# CONFIG_ALTERA_MBOX is not set
# CONFIG_MAILBOX_TEST is not set
# CONFIG_POLARFIRE_SOC_MAILBOX is not set
# CONFIG_MCHP_SBI_IPC_MBOX is not set
CONFIG_SUN6I_MSGBOX=y
# CONFIG_THEAD_TH1520_MBOX is not set
CONFIG_RISCV_SBI_MPXY_MBOX=y
CONFIG_IOMMU_API=y
CONFIG_IOMMU_SUPPORT=y

#
# Generic IOMMU Pagetable Support
#
# end of Generic IOMMU Pagetable Support

# CONFIG_IOMMU_DEBUGFS is not set
CONFIG_IOMMU_DEFAULT_DMA_STRICT=y
# CONFIG_IOMMU_DEFAULT_DMA_LAZY is not set
# CONFIG_IOMMU_DEFAULT_PASSTHROUGH is not set
CONFIG_OF_IOMMU=y
CONFIG_IOMMUFD_DRIVER_CORE=y
CONFIG_IOMMUFD=y
CONFIG_RISCV_IOMMU=y
CONFIG_RISCV_IOMMU_PCI=y
CONFIG_SUN50I_IOMMU=y
CONFIG_GENERIC_PT=y
# CONFIG_DEBUG_GENERIC_PT is not set
CONFIG_IOMMU_PT=y
# CONFIG_IOMMU_PT_AMDV1 is not set
# CONFIG_IOMMU_PT_VTDSS is not set
CONFIG_IOMMU_PT_RISCV64=y
# CONFIG_IOMMU_PT_X86_64 is not set

#
# Remoteproc drivers
#
# CONFIG_REMOTEPROC is not set
# end of Remoteproc drivers

#
# Rpmsg drivers
#
CONFIG_RPMSG=y
CONFIG_RPMSG_CHAR=y
CONFIG_RPMSG_CTRL=y
CONFIG_RPMSG_NS=y
# CONFIG_RPMSG_QCOM_GLINK_RPM is not set
CONFIG_RPMSG_VIRTIO=y
# end of Rpmsg drivers

CONFIG_SOUNDWIRE=y

#
# SoundWire Devices
#
# CONFIG_SOUNDWIRE_AMD is not set
# CONFIG_SOUNDWIRE_INTEL is not set
# CONFIG_SOUNDWIRE_QCOM is not set

#
# SOC (System On Chip) specific Drivers
#

#
# Amlogic SoC drivers
#
# end of Amlogic SoC drivers

#
# Broadcom SoC drivers
#
# end of Broadcom SoC drivers

#
# NXP/Freescale QorIQ SoC drivers
#
# end of NXP/Freescale QorIQ SoC drivers

#
# fujitsu SoC drivers
#
# end of fujitsu SoC drivers

#
# i.MX SoC drivers
#
# end of i.MX SoC drivers

#
# Enable LiteX SoC Builder specific drivers
#
# CONFIG_LITEX_SOC_CONTROLLER is not set
# end of Enable LiteX SoC Builder specific drivers

CONFIG_POLARFIRE_SOC_IRQ_MUX=y
CONFIG_POLARFIRE_SOC_SYSCONS=y
# CONFIG_WPCM450_SOC is not set

#
# Qualcomm SoC drivers
#
# CONFIG_QCOM_PMIC_PDCHARGER_ULOG is not set
# CONFIG_QCOM_PMIC_GLINK is not set
# end of Qualcomm SoC drivers

#
# Sophgo SoC drivers
#
# CONFIG_SOPHGO_CV1800_RTCSYS is not set
# CONFIG_SOPHGO_SG2044_TOPSYS is not set
# end of Sophgo SoC drivers

CONFIG_SUNXI_SRAM=y
# CONFIG_SOC_TI is not set

#
# Xilinx SoC drivers
#
# end of Xilinx SoC drivers
# end of SOC (System On Chip) specific Drivers

#
# PM Domains
#

#
# Amlogic PM Domains
#
# end of Amlogic PM Domains

#
# Broadcom PM Domains
#
# end of Broadcom PM Domains

#
# i.MX PM Domains
#
# end of i.MX PM Domains

#
# Qualcomm PM Domains
#
# end of Qualcomm PM Domains

CONFIG_JH71XX_PMU=y
CONFIG_SUN20I_PPU=y
# CONFIG_SUN50I_H6_PRCM_PPU is not set
CONFIG_SUN55I_PCK600=y
# end of PM Domains

CONFIG_PM_DEVFREQ=y

#
# DEVFREQ Governors
#
# CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND is not set
# CONFIG_DEVFREQ_GOV_PERFORMANCE is not set
# CONFIG_DEVFREQ_GOV_POWERSAVE is not set
# CONFIG_DEVFREQ_GOV_USERSPACE is not set
# CONFIG_DEVFREQ_GOV_PASSIVE is not set

#
# DEVFREQ Drivers
#
# CONFIG_ARM_HISI_UNCORE_DEVFREQ is not set
# CONFIG_ARM_SUN8I_A33_MBUS_DEVFREQ is not set
# CONFIG_PM_DEVFREQ_EVENT is not set
CONFIG_EXTCON=y

#
# Extcon Device Drivers
#
# CONFIG_EXTCON_ADC_JACK is not set
# CONFIG_EXTCON_FSA9480 is not set
# CONFIG_EXTCON_GPIO is not set
# CONFIG_EXTCON_LC824206XA is not set
# CONFIG_EXTCON_MAX3355 is not set
# CONFIG_EXTCON_MAX14526 is not set
CONFIG_EXTCON_PTN5150=y
# CONFIG_EXTCON_RT8973A is not set
# CONFIG_EXTCON_SM5502 is not set
# CONFIG_EXTCON_USB_GPIO is not set
CONFIG_EXTCON_USBC_TUSB320=y
# CONFIG_MEMORY is not set
CONFIG_IIO=y
CONFIG_IIO_BUFFER=y
# CONFIG_IIO_BUFFER_CB is not set
# CONFIG_IIO_BUFFER_DMA is not set
# CONFIG_IIO_BUFFER_DMAENGINE is not set
# CONFIG_IIO_BUFFER_HW_CONSUMER is not set
CONFIG_IIO_KFIFO_BUF=y
CONFIG_IIO_TRIGGERED_BUFFER=y
# CONFIG_IIO_CONFIGFS is not set
CONFIG_IIO_TRIGGER=y
CONFIG_IIO_CONSUMERS_PER_TRIGGER=2
# CONFIG_IIO_SW_DEVICE is not set
# CONFIG_IIO_SW_TRIGGER is not set
# CONFIG_IIO_TRIGGERED_EVENT is not set

#
# Accelerometers
#
# CONFIG_ADIS16201 is not set
# CONFIG_ADIS16209 is not set
# CONFIG_ADXL313_I2C is not set
# CONFIG_ADXL313_SPI is not set
# CONFIG_ADXL345_I2C is not set
# CONFIG_ADXL345_SPI is not set
# CONFIG_ADXL355_I2C is not set
# CONFIG_ADXL355_SPI is not set
# CONFIG_ADXL367_SPI is not set
# CONFIG_ADXL367_I2C is not set
# CONFIG_ADXL372_SPI is not set
# CONFIG_ADXL372_I2C is not set
# CONFIG_ADXL380_SPI is not set
# CONFIG_ADXL380_I2C is not set
# CONFIG_BMA180 is not set
# CONFIG_BMA220 is not set
# CONFIG_BMA400 is not set
# CONFIG_BMC150_ACCEL is not set
# CONFIG_BMI088_ACCEL is not set
# CONFIG_DA280 is not set
# CONFIG_DA311 is not set
# CONFIG_DMARD06 is not set
# CONFIG_DMARD09 is not set
# CONFIG_DMARD10 is not set
# CONFIG_FXLS8962AF_I2C is not set
# CONFIG_FXLS8962AF_SPI is not set
CONFIG_HID_SENSOR_ACCEL_3D=y
# CONFIG_IIO_ST_ACCEL_3AXIS is not set
# CONFIG_IIO_KX022A_SPI is not set
# CONFIG_IIO_KX022A_I2C is not set
# CONFIG_KXSD9 is not set
# CONFIG_KXCJK1013 is not set
# CONFIG_MC3230 is not set
# CONFIG_MMA7455_I2C is not set
# CONFIG_MMA7455_SPI is not set
# CONFIG_MMA7660 is not set
# CONFIG_MMA8452 is not set
# CONFIG_MMA9551 is not set
# CONFIG_MMA9553 is not set
# CONFIG_MSA311 is not set
# CONFIG_MXC4005 is not set
# CONFIG_MXC6255 is not set
# CONFIG_SCA3000 is not set
# CONFIG_SCA3300 is not set
# CONFIG_STK8312 is not set
# CONFIG_STK8BA50 is not set
# end of Accelerometers

#
# Analog to digital converters
#
# CONFIG_AD4000 is not set
# CONFIG_AD4030 is not set
# CONFIG_AD4080 is not set
# CONFIG_AD4130 is not set
# CONFIG_AD4134 is not set
# CONFIG_AD4170_4 is not set
# CONFIG_AD4695 is not set
# CONFIG_AD4851 is not set
# CONFIG_AD7091R5 is not set
# CONFIG_AD7091R8 is not set
# CONFIG_AD7124 is not set
# CONFIG_AD7173 is not set
# CONFIG_AD7191 is not set
# CONFIG_AD7192 is not set
# CONFIG_AD7266 is not set
# CONFIG_AD7280 is not set
# CONFIG_AD7291 is not set
# CONFIG_AD7292 is not set
# CONFIG_AD7298 is not set
# CONFIG_AD7380 is not set
# CONFIG_AD7476 is not set
# CONFIG_AD7606_IFACE_PARALLEL is not set
# CONFIG_AD7606_IFACE_SPI is not set
# CONFIG_AD7625 is not set
# CONFIG_AD7766 is not set
# CONFIG_AD7768_1 is not set
# CONFIG_AD7779 is not set
# CONFIG_AD7780 is not set
# CONFIG_AD7791 is not set
# CONFIG_AD7793 is not set
# CONFIG_AD7887 is not set
# CONFIG_AD7923 is not set
# CONFIG_AD7944 is not set
# CONFIG_AD7949 is not set
# CONFIG_AD799X is not set
# CONFIG_AD9467 is not set
# CONFIG_ADE9000 is not set
# CONFIG_AXP20X_ADC is not set
# CONFIG_AXP288_ADC is not set
# CONFIG_CC10001_ADC is not set
CONFIG_DLN2_ADC=y
# CONFIG_ENVELOPE_DETECTOR is not set
# CONFIG_GEHC_PMC_ADC is not set
# CONFIG_HI8435 is not set
# CONFIG_HX711 is not set
# CONFIG_INA2XX_ADC is not set
# CONFIG_LTC2309 is not set
# CONFIG_LTC2471 is not set
# CONFIG_LTC2485 is not set
# CONFIG_LTC2496 is not set
# CONFIG_LTC2497 is not set
# CONFIG_MAX1027 is not set
# CONFIG_MAX11100 is not set
# CONFIG_MAX1118 is not set
# CONFIG_MAX11205 is not set
# CONFIG_MAX11410 is not set
# CONFIG_MAX1241 is not set
# CONFIG_MAX1363 is not set
# CONFIG_MAX14001 is not set
# CONFIG_MAX34408 is not set
# CONFIG_MAX9611 is not set
# CONFIG_MCP320X is not set
# CONFIG_MCP3422 is not set
# CONFIG_MCP3564 is not set
# CONFIG_MCP3911 is not set
# CONFIG_MEDIATEK_MT6360_ADC is not set
# CONFIG_MEDIATEK_MT6370_ADC is not set
# CONFIG_NAU7802 is not set
# CONFIG_NCT7201 is not set
# CONFIG_PAC1921 is not set
# CONFIG_PAC1934 is not set
# CONFIG_ROHM_BD79112 is not set
# CONFIG_ROHM_BD79124 is not set
# CONFIG_RICHTEK_RTQ6056 is not set
# CONFIG_SOPHGO_CV1800B_ADC is not set
# CONFIG_SD_ADC_MODULATOR is not set
# CONFIG_SUN20I_GPADC is not set
# CONFIG_TI_ADC081C is not set
# CONFIG_TI_ADC0832 is not set
# CONFIG_TI_ADC084S021 is not set
# CONFIG_TI_ADC108S102 is not set
# CONFIG_TI_ADC12138 is not set
# CONFIG_TI_ADC128S052 is not set
# CONFIG_TI_ADC161S626 is not set
# CONFIG_TI_ADS1015 is not set
# CONFIG_TI_ADS1018 is not set
# CONFIG_TI_ADS1100 is not set
# CONFIG_TI_ADS1119 is not set
# CONFIG_TI_ADS124S08 is not set
# CONFIG_TI_ADS1298 is not set
# CONFIG_TI_ADS131E08 is not set
# CONFIG_TI_ADS131M02 is not set
# CONFIG_TI_ADS7138 is not set
# CONFIG_TI_ADS7924 is not set
# CONFIG_TI_ADS7950 is not set
# CONFIG_TI_ADS8344 is not set
# CONFIG_TI_ADS8688 is not set
# CONFIG_TI_LMP92064 is not set
# CONFIG_TI_TLC4541 is not set
# CONFIG_TI_TSC2046 is not set
# CONFIG_TWL4030_MADC is not set
# CONFIG_TWL6030_GPADC is not set
# CONFIG_VF610_ADC is not set
CONFIG_VIPERBOARD_ADC=y
# CONFIG_XILINX_XADC is not set
# end of Analog to digital converters

#
# Analog to digital and digital to analog converters
#
# CONFIG_AD74115 is not set
# CONFIG_AD74413R is not set
# end of Analog to digital and digital to analog converters

#
# Analog Front Ends
#
# CONFIG_IIO_RESCALE is not set
# end of Analog Front Ends

#
# Amplifiers
#
# CONFIG_AD8366 is not set
# CONFIG_ADA4250 is not set
# CONFIG_ADL8113 is not set
# CONFIG_HMC425 is not set
# end of Amplifiers

#
# Capacitance to digital converters
#
# CONFIG_AD7150 is not set
# CONFIG_AD7746 is not set
# end of Capacitance to digital converters

#
# Chemical Sensors
#
# CONFIG_AOSONG_AGS02MA is not set
# CONFIG_ATLAS_PH_SENSOR is not set
# CONFIG_ATLAS_EZO_SENSOR is not set
# CONFIG_BME680 is not set
# CONFIG_CCS811 is not set
# CONFIG_ENS160 is not set
# CONFIG_IAQCORE is not set
# CONFIG_MHZ19B is not set
# CONFIG_PMS7003 is not set
# CONFIG_SCD30_CORE is not set
# CONFIG_SCD4X is not set
# CONFIG_SEN0322 is not set
# CONFIG_SENSIRION_SGP30 is not set
# CONFIG_SENSIRION_SGP40 is not set
# CONFIG_SPS30_I2C is not set
# CONFIG_SPS30_SERIAL is not set
# CONFIG_SENSEAIR_SUNRISE_CO2 is not set
# CONFIG_VZ89X is not set
# end of Chemical Sensors

#
# Hid Sensor IIO Common
#
CONFIG_HID_SENSOR_IIO_COMMON=y
CONFIG_HID_SENSOR_IIO_TRIGGER=y
# end of Hid Sensor IIO Common

#
# IIO SCMI Sensors
#
# end of IIO SCMI Sensors

#
# SSP Sensor Common
#
# CONFIG_IIO_SSP_SENSORHUB is not set
# end of SSP Sensor Common

#
# Digital to analog converters
#
# CONFIG_AD3530R is not set
# CONFIG_AD3552R_HS is not set
# CONFIG_AD3552R is not set
# CONFIG_AD5064 is not set
# CONFIG_AD5360 is not set
# CONFIG_AD5380 is not set
# CONFIG_AD5421 is not set
# CONFIG_AD5446_SPI is not set
# CONFIG_AD5446_I2C is not set
# CONFIG_AD5449 is not set
# CONFIG_AD5592R is not set
# CONFIG_AD5593R is not set
# CONFIG_AD5504 is not set
# CONFIG_AD5624R_SPI is not set
# CONFIG_AD9739A is not set
# CONFIG_LTC2688 is not set
# CONFIG_AD5686_SPI is not set
# CONFIG_AD5696_I2C is not set
# CONFIG_AD5755 is not set
# CONFIG_AD5758 is not set
# CONFIG_AD5761 is not set
# CONFIG_AD5764 is not set
# CONFIG_AD5766 is not set
# CONFIG_AD5770R is not set
# CONFIG_AD5791 is not set
# CONFIG_AD7293 is not set
# CONFIG_AD7303 is not set
# CONFIG_AD8460 is not set
# CONFIG_AD8801 is not set
# CONFIG_BD79703 is not set
# CONFIG_DPOT_DAC is not set
# CONFIG_DS4424 is not set
# CONFIG_LTC1660 is not set
# CONFIG_LTC2632 is not set
# CONFIG_LTC2664 is not set
# CONFIG_M62332 is not set
# CONFIG_MAX517 is not set
# CONFIG_MAX22007 is not set
# CONFIG_MAX5522 is not set
# CONFIG_MAX5821 is not set
# CONFIG_MCP4725 is not set
# CONFIG_MCP4728 is not set
# CONFIG_MCP47FEB02 is not set
# CONFIG_MCP4821 is not set
# CONFIG_MCP4922 is not set
# CONFIG_TI_DAC082S085 is not set
# CONFIG_TI_DAC5571 is not set
# CONFIG_TI_DAC7311 is not set
# CONFIG_TI_DAC7612 is not set
# CONFIG_VF610_DAC is not set
# end of Digital to analog converters

#
# IIO dummy driver
#
# end of IIO dummy driver

#
# Filters
#
# CONFIG_ADMV8818 is not set
# end of Filters

#
# Frequency Synthesizers DDS/PLL
#

#
# Clock Generator/Distribution
#
# CONFIG_AD9523 is not set
# end of Clock Generator/Distribution

#
# Phase-Locked Loop (PLL) frequency synthesizers
#
# CONFIG_ADF4350 is not set
# CONFIG_ADF4371 is not set
# CONFIG_ADF4377 is not set
# CONFIG_ADMFM2000 is not set
# CONFIG_ADMV1013 is not set
# CONFIG_ADMV1014 is not set
# CONFIG_ADMV4420 is not set
# CONFIG_ADRF6780 is not set
# end of Phase-Locked Loop (PLL) frequency synthesizers
# end of Frequency Synthesizers DDS/PLL

#
# Digital gyroscope sensors
#
# CONFIG_ADIS16080 is not set
# CONFIG_ADIS16130 is not set
# CONFIG_ADIS16136 is not set
# CONFIG_ADIS16260 is not set
# CONFIG_ADXRS290 is not set
# CONFIG_ADXRS450 is not set
# CONFIG_BMG160 is not set
# CONFIG_FXAS21002C is not set
CONFIG_HID_SENSOR_GYRO_3D=y
# CONFIG_MPU3050_I2C is not set
# CONFIG_IIO_ST_GYRO_3AXIS is not set
# CONFIG_ITG3200 is not set
# end of Digital gyroscope sensors

#
# Health Sensors
#

#
# Heart Rate Monitors
#
# CONFIG_AFE4403 is not set
# CONFIG_AFE4404 is not set
# CONFIG_MAX30100 is not set
# CONFIG_MAX30102 is not set
# end of Heart Rate Monitors
# end of Health Sensors

#
# Humidity sensors
#
# CONFIG_AM2315 is not set
# CONFIG_DHT11 is not set
# CONFIG_ENS210 is not set
# CONFIG_HDC100X is not set
# CONFIG_HDC2010 is not set
# CONFIG_HDC3020 is not set
CONFIG_HID_SENSOR_HUMIDITY=y
# CONFIG_HTS221 is not set
# CONFIG_HTU21 is not set
# CONFIG_SI7005 is not set
# CONFIG_SI7020 is not set
# end of Humidity sensors

#
# Inertial measurement units
#
# CONFIG_ADIS16400 is not set
# CONFIG_ADIS16460 is not set
# CONFIG_ADIS16475 is not set
# CONFIG_ADIS16480 is not set
# CONFIG_ADIS16550 is not set
# CONFIG_BMI160_I2C is not set
# CONFIG_BMI160_SPI is not set
# CONFIG_BMI270_I2C is not set
# CONFIG_BMI270_SPI is not set
# CONFIG_BMI323_I2C is not set
# CONFIG_BMI323_SPI is not set
# CONFIG_BOSCH_BNO055_SERIAL is not set
# CONFIG_BOSCH_BNO055_I2C is not set
# CONFIG_FXOS8700_I2C is not set
# CONFIG_FXOS8700_SPI is not set
# CONFIG_KMX61 is not set
# CONFIG_INV_ICM42600_I2C is not set
# CONFIG_INV_ICM42600_SPI is not set
# CONFIG_INV_ICM45600_I2C is not set
# CONFIG_INV_ICM45600_SPI is not set
# CONFIG_INV_MPU6050_I2C is not set
# CONFIG_INV_MPU6050_SPI is not set
# CONFIG_SMI240 is not set
# CONFIG_SMI330_I2C is not set
# CONFIG_SMI330_SPI is not set
# CONFIG_IIO_ST_LSM6DSX is not set
# CONFIG_IIO_ST_LSM9DS0 is not set
# end of Inertial measurement units

#
# Light sensors
#
# CONFIG_ACPI_ALS is not set
# CONFIG_ADJD_S311 is not set
# CONFIG_ADUX1020 is not set
# CONFIG_AL3000A is not set
# CONFIG_AL3010 is not set
# CONFIG_AL3320A is not set
# CONFIG_APDS9160 is not set
# CONFIG_APDS9300 is not set
# CONFIG_APDS9306 is not set
# CONFIG_APDS9960 is not set
# CONFIG_AS73211 is not set
# CONFIG_BH1745 is not set
# CONFIG_BH1750 is not set
# CONFIG_BH1780 is not set
# CONFIG_CM32181 is not set
# CONFIG_CM3232 is not set
# CONFIG_CM3323 is not set
# CONFIG_CM3605 is not set
# CONFIG_CM36651 is not set
# CONFIG_GP2AP002 is not set
# CONFIG_GP2AP020A00F is not set
# CONFIG_SENSORS_ISL29018 is not set
# CONFIG_SENSORS_ISL29028 is not set
# CONFIG_ISL29125 is not set
# CONFIG_ISL76682 is not set
CONFIG_HID_SENSOR_ALS=y
CONFIG_HID_SENSOR_PROX=y
# CONFIG_JSA1212 is not set
# CONFIG_ROHM_BU27034 is not set
# CONFIG_RPR0521 is not set
# CONFIG_LTR390 is not set
# CONFIG_LTR501 is not set
# CONFIG_LTRF216A is not set
# CONFIG_LV0104CS is not set
# CONFIG_MAX44000 is not set
# CONFIG_MAX44009 is not set
# CONFIG_NOA1305 is not set
# CONFIG_OPT3001 is not set
# CONFIG_OPT4001 is not set
# CONFIG_OPT4060 is not set
# CONFIG_PA12203001 is not set
# CONFIG_SI1133 is not set
# CONFIG_SI1145 is not set
# CONFIG_STK3310 is not set
# CONFIG_ST_UVIS25 is not set
# CONFIG_TCS3414 is not set
# CONFIG_TCS3472 is not set
# CONFIG_SENSORS_TSL2563 is not set
# CONFIG_TSL2583 is not set
# CONFIG_TSL2591 is not set
# CONFIG_TSL2772 is not set
# CONFIG_TSL4531 is not set
# CONFIG_US5182D is not set
# CONFIG_VCNL4000 is not set
# CONFIG_VCNL4035 is not set
# CONFIG_VEML3235 is not set
# CONFIG_VEML6030 is not set
# CONFIG_VEML6040 is not set
# CONFIG_VEML6046X00 is not set
# CONFIG_VEML6070 is not set
# CONFIG_VEML6075 is not set
# CONFIG_VL6180 is not set
# CONFIG_ZOPT2201 is not set
# end of Light sensors

#
# Magnetometer sensors
#
# CONFIG_AF8133J is not set
# CONFIG_AK8974 is not set
# CONFIG_AK8975 is not set
# CONFIG_AK09911 is not set
# CONFIG_ALS31300 is not set
# CONFIG_BMC150_MAGN_I2C is not set
# CONFIG_BMC150_MAGN_SPI is not set
# CONFIG_MAG3110 is not set
CONFIG_HID_SENSOR_MAGNETOMETER_3D=y
# CONFIG_MMC35240 is not set
# CONFIG_MMC5633 is not set
# CONFIG_IIO_ST_MAGN_3AXIS is not set
# CONFIG_INFINEON_TLV493D is not set
# CONFIG_SENSORS_HMC5843_I2C is not set
# CONFIG_SENSORS_HMC5843_SPI is not set
# CONFIG_SENSORS_RM3100_I2C is not set
# CONFIG_SENSORS_RM3100_SPI is not set
# CONFIG_SI7210 is not set
# CONFIG_TI_TMAG5273 is not set
# CONFIG_YAMAHA_YAS530 is not set
# end of Magnetometer sensors

#
# Multiplexers
#
# CONFIG_IIO_MUX is not set
# end of Multiplexers

#
# Inclinometer sensors
#
CONFIG_HID_SENSOR_INCLINOMETER_3D=y
CONFIG_HID_SENSOR_DEVICE_ROTATION=y
# end of Inclinometer sensors

#
# Triggers - standalone
#
# CONFIG_IIO_INTERRUPT_TRIGGER is not set
# CONFIG_IIO_SYSFS_TRIGGER is not set
# end of Triggers - standalone

#
# Linear and angular position sensors
#
CONFIG_HID_SENSOR_CUSTOM_INTEL_HINGE=y
# end of Linear and angular position sensors

#
# Digital potentiometers
#
# CONFIG_AD5110 is not set
# CONFIG_AD5272 is not set
# CONFIG_DS1803 is not set
# CONFIG_MAX5432 is not set
# CONFIG_MAX5481 is not set
# CONFIG_MAX5487 is not set
# CONFIG_MCP4018 is not set
# CONFIG_MCP4131 is not set
# CONFIG_MCP4531 is not set
# CONFIG_MCP41010 is not set
# CONFIG_TPL0102 is not set
# CONFIG_X9250 is not set
# end of Digital potentiometers

#
# Digital potentiostats
#
# CONFIG_LMP91000 is not set
# end of Digital potentiostats

#
# Pressure sensors
#
# CONFIG_ABP060MG is not set
# CONFIG_ABP2030PA_I2C is not set
# CONFIG_ABP2030PA_SPI is not set
# CONFIG_ROHM_BM1390 is not set
# CONFIG_BMP280 is not set
# CONFIG_DLHL60D is not set
# CONFIG_DPS310 is not set
CONFIG_HID_SENSOR_PRESS=y
# CONFIG_HP03 is not set
# CONFIG_HSC030PA is not set
# CONFIG_ICP10100 is not set
# CONFIG_MPL115_I2C is not set
# CONFIG_MPL115_SPI is not set
# CONFIG_MPL3115 is not set
# CONFIG_MPRLS0025PA_I2C is not set
# CONFIG_MPRLS0025PA_SPI is not set
# CONFIG_MS5611 is not set
# CONFIG_MS5637 is not set
# CONFIG_SDP500 is not set
# CONFIG_IIO_ST_PRESS is not set
# CONFIG_T5403 is not set
# CONFIG_HP206C is not set
# CONFIG_ZPA2326 is not set
# CONFIG_ADP810 is not set
# end of Pressure sensors

#
# Lightning sensors
#
# CONFIG_AS3935 is not set
# end of Lightning sensors

#
# Proximity and distance sensors
#
# CONFIG_D3323AA is not set
# CONFIG_HX9023S is not set
# CONFIG_IRSD200 is not set
# CONFIG_ISL29501 is not set
# CONFIG_LIDAR_LITE_V2 is not set
# CONFIG_MB1232 is not set
# CONFIG_PING is not set
# CONFIG_RFD77402 is not set
# CONFIG_SRF04 is not set
# CONFIG_SX9310 is not set
# CONFIG_SX9324 is not set
# CONFIG_SX9360 is not set
# CONFIG_SX9500 is not set
# CONFIG_SRF08 is not set
# CONFIG_VCNL3020 is not set
# CONFIG_VL53L0X_I2C is not set
# CONFIG_VL53L1X_I2C is not set
# CONFIG_AW96103 is not set
# end of Proximity and distance sensors

#
# Resolver to digital converters
#
# CONFIG_AD2S90 is not set
# CONFIG_AD2S1200 is not set
# CONFIG_AD2S1210 is not set
# end of Resolver to digital converters

#
# Temperature sensors
#
# CONFIG_LTC2983 is not set
# CONFIG_MAXIM_THERMOCOUPLE is not set
CONFIG_HID_SENSOR_TEMP=y
# CONFIG_MLX90614 is not set
# CONFIG_MLX90632 is not set
# CONFIG_MLX90635 is not set
# CONFIG_TMP006 is not set
# CONFIG_TMP007 is not set
# CONFIG_TMP117 is not set
# CONFIG_TSYS01 is not set
# CONFIG_TSYS02D is not set
# CONFIG_MAX30208 is not set
# CONFIG_MAX31856 is not set
# CONFIG_MAX31865 is not set
# CONFIG_MCP9600 is not set
# end of Temperature sensors

# CONFIG_NTB is not set
CONFIG_PWM=y
# CONFIG_PWM_DEBUG is not set
# CONFIG_PWM_PROVIDE_GPIO is not set
# CONFIG_PWM_ARGON_FAN_HAT is not set
# CONFIG_PWM_ATMEL_TCB is not set
# CONFIG_PWM_CLK is not set
# CONFIG_PWM_DWC is not set
# CONFIG_PWM_FSL_FTM is not set
# CONFIG_PWM_GPIO is not set
# CONFIG_PWM_MC33XS2410 is not set
# CONFIG_PWM_MICROCHIP_CORE is not set
# CONFIG_PWM_PCA9685 is not set
CONFIG_PWM_PXA=y
# CONFIG_PWM_SIFIVE is not set
# CONFIG_PWM_SOPHGO_SG2042 is not set
# CONFIG_PWM_SUN4I is not set
# CONFIG_PWM_TWL is not set
# CONFIG_PWM_TWL_LED is not set
# CONFIG_PWM_XILINX is not set

#
# IRQ chip support
#
CONFIG_IRQCHIP=y
CONFIG_IRQ_MSI_LIB=y
# CONFIG_AL_FIC is not set
# CONFIG_XILINX_INTC is not set
CONFIG_RISCV_INTC=y
CONFIG_RISCV_APLIC=y
CONFIG_RISCV_APLIC_MSI=y
CONFIG_RISCV_IMSIC=y
CONFIG_RISCV_RPMI_SYSMSI=y
CONFIG_SIFIVE_PLIC=y
CONFIG_STARFIVE_JH8100_INTC=y
# CONFIG_ACLINT_SSWI is not set
# CONFIG_SOPHGO_SG2042_MSI is not set
# end of IRQ chip support

# CONFIG_IPACK_BUS is not set
CONFIG_RESET_CONTROLLER=y
# CONFIG_RESET_GPIO is not set
# CONFIG_RESET_K230 is not set
CONFIG_RESET_POLARFIRE_SOC=y
CONFIG_RESET_SIMPLE=y
CONFIG_RESET_SUNXI=y
CONFIG_RESET_TENSTORRENT_ATLANTIS=y
# CONFIG_RESET_TH1520 is not set
# CONFIG_RESET_TI_SYSCON is not set
# CONFIG_RESET_TI_TPS380X is not set

#
# Reset support for SpacemiT platforms
#
CONFIG_RESET_SPACEMIT_COMMON=y
CONFIG_RESET_SPACEMIT_K1=y
# end of Reset support for SpacemiT platforms

CONFIG_RESET_STARFIVE_JH71X0=y
CONFIG_RESET_STARFIVE_JH7100=y
CONFIG_RESET_STARFIVE_JH7110=y

#
# PHY Subsystem
#
CONFIG_GENERIC_PHY=y
CONFIG_GENERIC_PHY_MIPI_DPHY=y
# CONFIG_PHY_CAN_TRANSCEIVER is not set
# CONFIG_PHY_GOOGLE_USB is not set
# CONFIG_PHY_NXP_PTN3222 is not set
CONFIG_PHY_SUN4I_USB=y
CONFIG_PHY_SUN6I_MIPI_DPHY=y
# CONFIG_PHY_SUN9I_USB is not set
# CONFIG_PHY_SUN50I_USB3 is not set

#
# PHY drivers for Broadcom platforms
#
# CONFIG_BCM_KONA_USB2_PHY is not set
# end of PHY drivers for Broadcom platforms

# CONFIG_PHY_CADENCE_TORRENT is not set
# CONFIG_PHY_CADENCE_DPHY is not set
# CONFIG_PHY_CADENCE_DPHY_RX is not set
# CONFIG_PHY_CADENCE_SIERRA is not set
# CONFIG_PHY_CADENCE_SALVO is not set
# CONFIG_PHY_CANAAN_USB is not set
# CONFIG_PHY_PXA_28NM_HSIC is not set
# CONFIG_PHY_PXA_28NM_USB2 is not set
CONFIG_PHY_CPCAP_USB=y
# CONFIG_PHY_MAPPHONE_MDM6600 is not set
# CONFIG_PHY_OCELOT_SERDES is not set
CONFIG_PHY_QCOM_USB_HS=y
CONFIG_PHY_QCOM_USB_HSIC=y
CONFIG_PHY_SAMSUNG_USB2=y
# CONFIG_PHY_SOPHGO_CV1800_USB2 is not set
CONFIG_PHY_SPACEMIT_K1_PCIE=y
# CONFIG_PHY_SPACEMIT_K1_USB2 is not set
CONFIG_PHY_STARFIVE_JH7110_DPHY_RX=y
# CONFIG_PHY_STARFIVE_JH7110_DPHY_TX is not set
CONFIG_PHY_STARFIVE_JH7110_PCIE=y
CONFIG_PHY_STARFIVE_JH7110_USB=y
CONFIG_PHY_TUSB1210=y
# end of PHY Subsystem

# CONFIG_POWERCAP is not set
# CONFIG_MCB is not set

#
# Performance monitor support
#
CONFIG_RISCV_PMU=y
CONFIG_RISCV_PMU_LEGACY=y
CONFIG_RISCV_PMU_SBI=y
# CONFIG_STARFIVE_STARLINK_PMU is not set
# CONFIG_DWC_PCIE_PMU is not set
# end of Performance monitor support

CONFIG_RAS=y
CONFIG_USB4=y
# CONFIG_USB4_DEBUGFS_WRITE is not set
# CONFIG_USB4_DMA_TEST is not set

#
# Android
#
CONFIG_ANDROID_BINDER_IPC=y
CONFIG_ANDROID_BINDERFS=y
CONFIG_ANDROID_BINDER_DEVICES="binder0,binder1"
# end of Android

CONFIG_LIBNVDIMM=y
CONFIG_BLK_DEV_PMEM=y
CONFIG_ND_CLAIM=y
CONFIG_ND_BTT=y
CONFIG_BTT=y
CONFIG_OF_PMEM=y
CONFIG_RAMDAX=y
CONFIG_NVDIMM_KEYS=y
# CONFIG_NVDIMM_SECURITY_TEST is not set
CONFIG_DAX=y
# CONFIG_DEV_DAX is not set
CONFIG_NVMEM=y
CONFIG_NVMEM_SYSFS=y
CONFIG_NVMEM_LAYOUTS=y

#
# Layout Types
#
# CONFIG_NVMEM_LAYOUT_SL28_VPD is not set
# CONFIG_NVMEM_LAYOUT_ONIE_TLV is not set
# CONFIG_NVMEM_LAYOUT_U_BOOT_ENV is not set
# end of Layout Types

# CONFIG_NVMEM_RMEM is not set
CONFIG_NVMEM_SUNXI_SID=y
# CONFIG_NVMEM_U_BOOT_ENV is not set

#
# HW tracing support
#
# CONFIG_STM is not set
# CONFIG_INTEL_TH is not set
# end of HW tracing support

# CONFIG_FPGA is not set
# CONFIG_FSI is not set
# CONFIG_MUX_CORE is not set
CONFIG_PM_OPP=y
# CONFIG_SIOX is not set
# CONFIG_SLIMBUS is not set
# CONFIG_INTERCONNECT is not set
CONFIG_COUNTER=y
# CONFIG_INTERRUPT_CNT is not set
CONFIG_MOST=y
CONFIG_MOST_USB_HDM=y
# CONFIG_MOST_CDEV is not set
# CONFIG_MOST_SND is not set
# CONFIG_PECI is not set
# CONFIG_HTE is not set
# end of Device Drivers

#
# File systems
#
CONFIG_VALIDATE_FS_PARSER=y
CONFIG_FS_IOMAP=y
CONFIG_BUFFER_HEAD=y
# CONFIG_EXT2_FS is not set
CONFIG_EXT4_FS=y
CONFIG_EXT4_USE_FOR_EXT2=y
CONFIG_EXT4_FS_POSIX_ACL=y
CONFIG_EXT4_FS_SECURITY=y
# CONFIG_EXT4_DEBUG is not set
CONFIG_JBD2=y
# CONFIG_JBD2_DEBUG is not set
CONFIG_FS_MBCACHE=y
# CONFIG_JFS_FS is not set
# CONFIG_XFS_FS is not set
# CONFIG_GFS2_FS is not set
# CONFIG_OCFS2_FS is not set
# CONFIG_BTRFS_FS is not set
# CONFIG_NILFS2_FS is not set
# CONFIG_F2FS_FS is not set
# CONFIG_ZONEFS_FS is not set
CONFIG_FS_POSIX_ACL=y
CONFIG_EXPORTFS=y
# CONFIG_EXPORTFS_BLOCK_OPS is not set
CONFIG_FILE_LOCKING=y
CONFIG_FS_ENCRYPTION=y
CONFIG_FS_ENCRYPTION_ALGS=y
# CONFIG_FS_ENCRYPTION_INLINE_CRYPT is not set
CONFIG_FS_VERITY=y
CONFIG_FS_VERITY_BUILTIN_SIGNATURES=y
CONFIG_FSNOTIFY=y
CONFIG_DNOTIFY=y
CONFIG_INOTIFY_USER=y
CONFIG_FANOTIFY=y
CONFIG_FANOTIFY_ACCESS_PERMISSIONS=y
CONFIG_QUOTA=y
CONFIG_QUOTA_NETLINK_INTERFACE=y
# CONFIG_QUOTA_DEBUG is not set
CONFIG_QUOTA_TREE=y
# CONFIG_QFMT_V1 is not set
CONFIG_QFMT_V2=y
CONFIG_QUOTACTL=y
CONFIG_AUTOFS_FS=y
CONFIG_FUSE_FS=y
CONFIG_CUSE=y
CONFIG_VIRTIO_FS=y
# CONFIG_FUSE_PASSTHROUGH is not set
# CONFIG_FUSE_IO_URING is not set
# CONFIG_OVERLAY_FS is not set

#
# Caches
#
CONFIG_NETFS_SUPPORT=y
# CONFIG_NETFS_STATS is not set
# CONFIG_NETFS_DEBUG is not set
# CONFIG_FSCACHE is not set
# end of Caches

#
# CD-ROM/DVD Filesystems
#
# CONFIG_ISO9660_FS is not set
# CONFIG_UDF_FS is not set
# end of CD-ROM/DVD Filesystems

#
# DOS/FAT/EXFAT/NT Filesystems
#
# CONFIG_MSDOS_FS is not set
# CONFIG_VFAT_FS is not set
# CONFIG_EXFAT_FS is not set
# CONFIG_NTFS_FS is not set
# CONFIG_NTFS3_FS is not set
# end of DOS/FAT/EXFAT/NT Filesystems

#
# Pseudo filesystems
#
CONFIG_PROC_FS=y
CONFIG_PROC_KCORE=y
CONFIG_PROC_SYSCTL=y
CONFIG_PROC_PAGE_MONITOR=y
CONFIG_PROC_CHILDREN=y
CONFIG_KERNFS=y
CONFIG_SYSFS=y
CONFIG_TMPFS=y
CONFIG_TMPFS_POSIX_ACL=y
CONFIG_TMPFS_XATTR=y
# CONFIG_TMPFS_INODE64 is not set
CONFIG_TMPFS_QUOTA=y
CONFIG_ARCH_SUPPORTS_HUGETLBFS=y
CONFIG_HUGETLBFS=y
# CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON is not set
CONFIG_HUGETLB_PAGE=y
CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP=y
CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING=y
CONFIG_ARCH_HAS_GIGANTIC_PAGE=y
CONFIG_CONFIGFS_FS=y
CONFIG_EFIVAR_FS=y
# end of Pseudo filesystems

CONFIG_MISC_FILESYSTEMS=y
# CONFIG_ORANGEFS_FS is not set
# CONFIG_ADFS_FS is not set
# CONFIG_AFFS_FS is not set
CONFIG_ECRYPT_FS=y
CONFIG_ECRYPT_FS_MESSAGING=y
# CONFIG_HFS_FS is not set
# CONFIG_HFSPLUS_FS is not set
# CONFIG_BEFS_FS is not set
# CONFIG_BFS_FS is not set
# CONFIG_EFS_FS is not set
# CONFIG_JFFS2_FS is not set
# CONFIG_UBIFS_FS is not set
# CONFIG_CRAMFS is not set
# CONFIG_SQUASHFS is not set
# CONFIG_VXFS_FS is not set
# CONFIG_MINIX_FS is not set
# CONFIG_OMFS_FS is not set
# CONFIG_HPFS_FS is not set
# CONFIG_QNX4FS_FS is not set
# CONFIG_QNX6FS_FS is not set
# CONFIG_ROMFS_FS is not set
CONFIG_PSTORE=y
CONFIG_PSTORE_DEFAULT_KMSG_BYTES=10240
CONFIG_PSTORE_COMPRESS=y
# CONFIG_PSTORE_CONSOLE is not set
# CONFIG_PSTORE_PMSG is not set
# CONFIG_PSTORE_RAM is not set
# CONFIG_PSTORE_BLK is not set
# CONFIG_UFS_FS is not set
# CONFIG_EROFS_FS is not set
CONFIG_NETWORK_FILESYSTEMS=y
# CONFIG_NFS_FS is not set
# CONFIG_NFSD is not set
# CONFIG_CEPH_FS is not set
# CONFIG_CIFS is not set
CONFIG_SMB_SERVER=y
# CONFIG_SMB_SERVER_SMBDIRECT is not set
# CONFIG_SMB_SERVER_CHECK_CAP_NET_ADMIN is not set
# CONFIG_SMB_SERVER_KERBEROS5 is not set
CONFIG_SMBFS=y
# CONFIG_CODA_FS is not set
# CONFIG_AFS_FS is not set
# CONFIG_9P_FS is not set
CONFIG_NLS=y
CONFIG_NLS_DEFAULT="utf8"
CONFIG_NLS_CODEPAGE_437=y
CONFIG_NLS_CODEPAGE_737=y
CONFIG_NLS_CODEPAGE_775=y
CONFIG_NLS_CODEPAGE_850=y
CONFIG_NLS_CODEPAGE_852=y
CONFIG_NLS_CODEPAGE_855=y
CONFIG_NLS_CODEPAGE_857=y
CONFIG_NLS_CODEPAGE_860=y
CONFIG_NLS_CODEPAGE_861=y
CONFIG_NLS_CODEPAGE_862=y
CONFIG_NLS_CODEPAGE_863=y
CONFIG_NLS_CODEPAGE_864=y
CONFIG_NLS_CODEPAGE_865=y
CONFIG_NLS_CODEPAGE_866=y
CONFIG_NLS_CODEPAGE_869=y
CONFIG_NLS_CODEPAGE_936=y
CONFIG_NLS_CODEPAGE_950=y
CONFIG_NLS_CODEPAGE_932=y
CONFIG_NLS_CODEPAGE_949=y
CONFIG_NLS_CODEPAGE_874=y
CONFIG_NLS_ISO8859_8=y
CONFIG_NLS_CODEPAGE_1250=y
CONFIG_NLS_CODEPAGE_1251=y
CONFIG_NLS_ASCII=y
CONFIG_NLS_ISO8859_1=y
CONFIG_NLS_ISO8859_2=y
CONFIG_NLS_ISO8859_3=y
CONFIG_NLS_ISO8859_4=y
CONFIG_NLS_ISO8859_5=y
CONFIG_NLS_ISO8859_6=y
CONFIG_NLS_ISO8859_7=y
CONFIG_NLS_ISO8859_9=y
CONFIG_NLS_ISO8859_13=y
CONFIG_NLS_ISO8859_14=y
CONFIG_NLS_ISO8859_15=y
CONFIG_NLS_KOI8_R=y
CONFIG_NLS_KOI8_U=y
CONFIG_NLS_MAC_ROMAN=y
CONFIG_NLS_MAC_CELTIC=y
CONFIG_NLS_MAC_CENTEURO=y
CONFIG_NLS_MAC_CROATIAN=y
CONFIG_NLS_MAC_CYRILLIC=y
CONFIG_NLS_MAC_GAELIC=y
CONFIG_NLS_MAC_GREEK=y
CONFIG_NLS_MAC_ICELAND=y
CONFIG_NLS_MAC_INUIT=y
CONFIG_NLS_MAC_ROMANIAN=y
CONFIG_NLS_MAC_TURKISH=y
CONFIG_NLS_UTF8=y
CONFIG_NLS_UCS2_UTILS=y
CONFIG_DLM=y
# CONFIG_DLM_DEBUG is not set
CONFIG_UNICODE=y
CONFIG_IO_WQ=y
# end of File systems

#
# Security options
#
CONFIG_KEYS=y
CONFIG_KEYS_REQUEST_CACHE=y
CONFIG_PERSISTENT_KEYRINGS=y
CONFIG_BIG_KEYS=y
CONFIG_TRUSTED_KEYS=y
# CONFIG_TRUSTED_KEYS_TPM is not set

#
# No trust source selected!
#
CONFIG_ENCRYPTED_KEYS=y
# CONFIG_USER_DECRYPTED_DATA is not set
CONFIG_KEY_DH_OPERATIONS=y
CONFIG_KEY_NOTIFICATIONS=y
# CONFIG_SECURITY_DMESG_RESTRICT is not set
CONFIG_PROC_MEM_ALWAYS_FORCE=y
# CONFIG_PROC_MEM_FORCE_PTRACE is not set
# CONFIG_PROC_MEM_NO_FORCE is not set
CONFIG_SECURITY=y
CONFIG_HAS_SECURITY_AUDIT=y
CONFIG_SECURITYFS=y
CONFIG_SECURITY_NETWORK=y
CONFIG_SECURITY_INFINIBAND=y
CONFIG_SECURITY_NETWORK_XFRM=y
CONFIG_SECURITY_PATH=y
# CONFIG_STATIC_USERMODEHELPER is not set
# CONFIG_SECURITY_SELINUX is not set
# CONFIG_SECURITY_SMACK is not set
CONFIG_SECURITY_TOMOYO=y
CONFIG_SECURITY_TOMOYO_MAX_ACCEPT_ENTRY=64
CONFIG_SECURITY_TOMOYO_MAX_AUDIT_LOG=32
CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER=y
CONFIG_SECURITY_TOMOYO_INSECURE_BUILTIN_SETTING=y
CONFIG_SECURITY_APPARMOR=y
CONFIG_SECURITY_APPARMOR_DEBUG=y
CONFIG_SECURITY_APPARMOR_DEBUG_ASSERTS=y
# CONFIG_SECURITY_APPARMOR_DEBUG_MESSAGES is not set
CONFIG_SECURITY_APPARMOR_INTROSPECT_POLICY=y
CONFIG_SECURITY_APPARMOR_HASH=y
CONFIG_SECURITY_APPARMOR_HASH_DEFAULT=y
CONFIG_SECURITY_APPARMOR_EXPORT_BINARY=y
CONFIG_SECURITY_APPARMOR_PARANOID_LOAD=y
# CONFIG_SECURITY_LOADPIN is not set
CONFIG_SECURITY_YAMA=y
CONFIG_SECURITY_SAFESETID=y
CONFIG_SECURITY_LOCKDOWN_LSM=y
CONFIG_SECURITY_LOCKDOWN_LSM_EARLY=y
CONFIG_LOCK_DOWN_KERNEL_FORCE_NONE=y
# CONFIG_LOCK_DOWN_KERNEL_FORCE_INTEGRITY is not set
# CONFIG_LOCK_DOWN_KERNEL_FORCE_CONFIDENTIALITY is not set
CONFIG_SECURITY_LANDLOCK=y
# CONFIG_SECURITY_IPE is not set
CONFIG_INTEGRITY=y
CONFIG_INTEGRITY_SIGNATURE=y
CONFIG_INTEGRITY_ASYMMETRIC_KEYS=y
CONFIG_INTEGRITY_TRUSTED_KEYRING=y
CONFIG_INTEGRITY_AUDIT=y
CONFIG_IMA=y
CONFIG_IMA_MEASURE_PCR_IDX=10
CONFIG_IMA_LSM_RULES=y
CONFIG_IMA_NG_TEMPLATE=y
# CONFIG_IMA_SIG_TEMPLATE is not set
CONFIG_IMA_DEFAULT_TEMPLATE="ima-ng"
# CONFIG_IMA_DEFAULT_HASH_SHA1 is not set
CONFIG_IMA_DEFAULT_HASH_SHA256=y
# CONFIG_IMA_DEFAULT_HASH_SHA512 is not set
# CONFIG_IMA_DEFAULT_HASH_WP512 is not set
CONFIG_IMA_DEFAULT_HASH="sha256"
CONFIG_IMA_WRITE_POLICY=y
CONFIG_IMA_READ_POLICY=y
CONFIG_IMA_APPRAISE=y
# CONFIG_IMA_ARCH_POLICY is not set
# CONFIG_IMA_APPRAISE_BUILD_POLICY is not set
# CONFIG_IMA_APPRAISE_BOOTPARAM is not set
CONFIG_IMA_APPRAISE_MODSIG=y
# CONFIG_IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY is not set
# CONFIG_IMA_BLACKLIST_KEYRING is not set
# CONFIG_IMA_LOAD_X509 is not set
CONFIG_IMA_MEASURE_ASYMMETRIC_KEYS=y
CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS=y
# CONFIG_IMA_DISABLE_HTABLE is not set
CONFIG_EVM=y
CONFIG_EVM_ATTR_FSUUID=y
CONFIG_EVM_ADD_XATTRS=y
# CONFIG_EVM_LOAD_X509 is not set
# CONFIG_DEFAULT_SECURITY_TOMOYO is not set
CONFIG_DEFAULT_SECURITY_APPARMOR=y
# CONFIG_DEFAULT_SECURITY_DAC is not set
CONFIG_LSM="landlock,lockdown,yama,safesetid,integrity,tomoyo,apparmor,bpf"

#
# Kernel hardening options
#

#
# Memory initialization
#
CONFIG_CC_HAS_AUTO_VAR_INIT_PATTERN=y
CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_BARE=y
CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO=y
# CONFIG_INIT_STACK_NONE is not set
# CONFIG_INIT_STACK_ALL_PATTERN is not set
CONFIG_INIT_STACK_ALL_ZERO=y
CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y
# CONFIG_INIT_ON_FREE_DEFAULT_ON is not set
CONFIG_CC_HAS_ZERO_CALL_USED_REGS=y
# CONFIG_ZERO_CALL_USED_REGS is not set
# end of Memory initialization

#
# Bounds checking
#
# CONFIG_FORTIFY_SOURCE is not set
CONFIG_HARDENED_USERCOPY=y
# CONFIG_HARDENED_USERCOPY_DEFAULT_ON is not set
# end of Bounds checking

#
# Hardening of kernel data structures
#
CONFIG_LIST_HARDENED=y
CONFIG_BUG_ON_DATA_CORRUPTION=y
# end of Hardening of kernel data structures

CONFIG_RANDSTRUCT_NONE=y
# end of Kernel hardening options
# end of Security options

CONFIG_ASYNC_CORE=y
CONFIG_ASYNC_MEMCPY=y
CONFIG_ASYNC_XOR=y
CONFIG_ASYNC_PQ=y
CONFIG_ASYNC_RAID6_RECOV=y
CONFIG_CRYPTO=y

#
# Crypto core or helper
#
CONFIG_CRYPTO_ALGAPI=y
CONFIG_CRYPTO_ALGAPI2=y
CONFIG_CRYPTO_AEAD=y
CONFIG_CRYPTO_AEAD2=y
CONFIG_CRYPTO_SIG=y
CONFIG_CRYPTO_SIG2=y
CONFIG_CRYPTO_SKCIPHER=y
CONFIG_CRYPTO_SKCIPHER2=y
CONFIG_CRYPTO_HASH=y
CONFIG_CRYPTO_HASH2=y
CONFIG_CRYPTO_RNG=y
CONFIG_CRYPTO_RNG2=y
CONFIG_CRYPTO_AKCIPHER2=y
CONFIG_CRYPTO_AKCIPHER=y
CONFIG_CRYPTO_KPP2=y
CONFIG_CRYPTO_KPP=y
CONFIG_CRYPTO_ACOMP2=y
CONFIG_CRYPTO_MANAGER=y
CONFIG_CRYPTO_MANAGER2=y
CONFIG_CRYPTO_USER=y
# CONFIG_CRYPTO_SELFTESTS is not set
# CONFIG_CRYPTO_NULL is not set
CONFIG_CRYPTO_PCRYPT=y
# CONFIG_CRYPTO_CRYPTD is not set
CONFIG_CRYPTO_AUTHENC=y
CONFIG_CRYPTO_KRB5ENC=y
# CONFIG_CRYPTO_BENCHMARK is not set
CONFIG_CRYPTO_ENGINE=y
# end of Crypto core or helper

#
# Public-key cryptography
#
CONFIG_CRYPTO_RSA=y
CONFIG_CRYPTO_DH=y
# CONFIG_CRYPTO_DH_RFC7919_GROUPS is not set
CONFIG_CRYPTO_ECC=y
# CONFIG_CRYPTO_ECDH is not set
CONFIG_CRYPTO_ECDSA=y
CONFIG_CRYPTO_ECRDSA=y
CONFIG_CRYPTO_MLDSA=y
# end of Public-key cryptography

#
# Block ciphers
#
CONFIG_CRYPTO_AES=y
CONFIG_CRYPTO_ANUBIS=y
CONFIG_CRYPTO_ARIA=y
CONFIG_CRYPTO_BLOWFISH=y
CONFIG_CRYPTO_BLOWFISH_COMMON=y
CONFIG_CRYPTO_CAMELLIA=y
# CONFIG_CRYPTO_CAST5 is not set
# CONFIG_CRYPTO_CAST6 is not set
CONFIG_CRYPTO_DES=y
# CONFIG_CRYPTO_FCRYPT is not set
CONFIG_CRYPTO_KHAZAD=y
CONFIG_CRYPTO_SEED=y
# CONFIG_CRYPTO_SERPENT is not set
CONFIG_CRYPTO_SM4=y
CONFIG_CRYPTO_SM4_GENERIC=y
CONFIG_CRYPTO_TEA=y
CONFIG_CRYPTO_TWOFISH=y
CONFIG_CRYPTO_TWOFISH_COMMON=y
# end of Block ciphers

#
# Length-preserving ciphers and modes
#
CONFIG_CRYPTO_ADIANTUM=y
CONFIG_CRYPTO_ARC4=y
CONFIG_CRYPTO_CHACHA20=y
CONFIG_CRYPTO_CBC=y
CONFIG_CRYPTO_CTR=y
CONFIG_CRYPTO_CTS=y
CONFIG_CRYPTO_ECB=y
CONFIG_CRYPTO_HCTR2=y
CONFIG_CRYPTO_LRW=y
# CONFIG_CRYPTO_PCBC is not set
CONFIG_CRYPTO_XCTR=y
CONFIG_CRYPTO_XTS=y
# end of Length-preserving ciphers and modes

#
# AEAD (authenticated encryption with associated data) ciphers
#
CONFIG_CRYPTO_AEGIS128=y
CONFIG_CRYPTO_CHACHA20POLY1305=y
CONFIG_CRYPTO_CCM=y
CONFIG_CRYPTO_GCM=y
CONFIG_CRYPTO_GENIV=y
CONFIG_CRYPTO_SEQIV=y
CONFIG_CRYPTO_ECHAINIV=y
CONFIG_CRYPTO_ESSIV=y
# end of AEAD (authenticated encryption with associated data) ciphers

#
# Hashes, digests, and MACs
#
CONFIG_CRYPTO_BLAKE2B=y
CONFIG_CRYPTO_CMAC=y
CONFIG_CRYPTO_HMAC=y
# CONFIG_CRYPTO_MD4 is not set
# CONFIG_CRYPTO_MD5 is not set
CONFIG_CRYPTO_RMD160=y
CONFIG_CRYPTO_SHA1=y
CONFIG_CRYPTO_SHA256=y
CONFIG_CRYPTO_SHA512=y
CONFIG_CRYPTO_SHA3=y
# CONFIG_CRYPTO_SM3 is not set
CONFIG_CRYPTO_STREEBOG=y
CONFIG_CRYPTO_WP512=y
CONFIG_CRYPTO_XCBC=y
CONFIG_CRYPTO_XXHASH=y
# end of Hashes, digests, and MACs

#
# CRCs (cyclic redundancy checks)
#
CONFIG_CRYPTO_CRC32C=y
# CONFIG_CRYPTO_CRC32 is not set
# end of CRCs (cyclic redundancy checks)

#
# Compression
#
CONFIG_CRYPTO_DEFLATE=y
CONFIG_CRYPTO_LZO=y
CONFIG_CRYPTO_842=y
CONFIG_CRYPTO_LZ4=y
CONFIG_CRYPTO_LZ4HC=y
# CONFIG_CRYPTO_ZSTD is not set
# end of Compression

#
# Random number generation
#
CONFIG_CRYPTO_DRBG_MENU=y
CONFIG_CRYPTO_DRBG_HMAC=y
CONFIG_CRYPTO_DRBG_HASH=y
CONFIG_CRYPTO_DRBG_CTR=y
CONFIG_CRYPTO_DRBG=y
CONFIG_CRYPTO_JITTERENTROPY=y
CONFIG_CRYPTO_JITTERENTROPY_MEMORY_BLOCKS=64
CONFIG_CRYPTO_JITTERENTROPY_MEMORY_BLOCKSIZE=32
CONFIG_CRYPTO_JITTERENTROPY_OSR=1
CONFIG_CRYPTO_KDF800108_CTR=y
CONFIG_CRYPTO_DF80090A=y
# end of Random number generation

#
# Userspace interface
#
CONFIG_CRYPTO_USER_API=y
CONFIG_CRYPTO_USER_API_HASH=y
CONFIG_CRYPTO_USER_API_SKCIPHER=y
CONFIG_CRYPTO_USER_API_RNG=y
# CONFIG_CRYPTO_USER_API_RNG_CAVP is not set
CONFIG_CRYPTO_USER_API_AEAD=y
CONFIG_CRYPTO_USER_API_ENABLE_OBSOLETE=y
# end of Userspace interface

#
# Accelerated Cryptographic Algorithms for CPU (riscv)
#
# end of Accelerated Cryptographic Algorithms for CPU (riscv)

CONFIG_CRYPTO_HW=y
CONFIG_CRYPTO_DEV_ALLWINNER=y
# CONFIG_CRYPTO_DEV_SUN4I_SS is not set
# CONFIG_CRYPTO_DEV_SUN8I_CE is not set
# CONFIG_CRYPTO_DEV_SUN8I_SS is not set
# CONFIG_CRYPTO_DEV_ATMEL_AES is not set
# CONFIG_CRYPTO_DEV_ATMEL_ECC is not set
# CONFIG_CRYPTO_DEV_ATMEL_SHA204A is not set
# CONFIG_CRYPTO_DEV_NITROX_CNN55XX is not set
# CONFIG_CRYPTO_DEV_QAT_DH895xCC is not set
# CONFIG_CRYPTO_DEV_QAT_C3XXX is not set
# CONFIG_CRYPTO_DEV_QAT_C62X is not set
# CONFIG_CRYPTO_DEV_QAT_4XXX is not set
# CONFIG_CRYPTO_DEV_QAT_420XX is not set
# CONFIG_CRYPTO_DEV_QAT_DH895xCCVF is not set
# CONFIG_CRYPTO_DEV_QAT_C3XXXVF is not set
# CONFIG_CRYPTO_DEV_QAT_C62XVF is not set
CONFIG_CRYPTO_DEV_VIRTIO=y
# CONFIG_CRYPTO_DEV_SAFEXCEL is not set
# CONFIG_CRYPTO_DEV_CCREE is not set
# CONFIG_CRYPTO_DEV_AMLOGIC_GXL is not set
CONFIG_ASYMMETRIC_KEY_TYPE=y
CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=y
CONFIG_X509_CERTIFICATE_PARSER=y
CONFIG_PKCS8_PRIVATE_KEY_PARSER=y
CONFIG_PKCS7_MESSAGE_PARSER=y
# CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA is not set
CONFIG_PKCS7_TEST_KEY=y
CONFIG_SIGNED_PE_FILE_VERIFICATION=y
# CONFIG_FIPS_SIGNATURE_SELFTEST is not set

#
# Certificates for signature checking
#
CONFIG_MODULE_SIG_KEY="certs/signing_key.pem"
# CONFIG_MODULE_SIG_KEY_TYPE_RSA is not set
CONFIG_MODULE_SIG_KEY_TYPE_MLDSA_44=y
# CONFIG_MODULE_SIG_KEY_TYPE_MLDSA_65 is not set
# CONFIG_MODULE_SIG_KEY_TYPE_MLDSA_87 is not set
CONFIG_SYSTEM_TRUSTED_KEYRING=y
CONFIG_SYSTEM_TRUSTED_KEYS=""
# CONFIG_SYSTEM_EXTRA_CERTIFICATE is not set
CONFIG_SECONDARY_TRUSTED_KEYRING=y
# CONFIG_SECONDARY_TRUSTED_KEYRING_SIGNED_BY_BUILTIN is not set
# CONFIG_SYSTEM_BLACKLIST_KEYRING is not set
CONFIG_OPENSSL_SUPPORTS_ML_DSA=y
# end of Certificates for signature checking

CONFIG_CRYPTO_KRB5=y
# CONFIG_CRYPTO_KRB5_SELFTESTS is not set
CONFIG_BINARY_PRINTF=y

#
# Library routines
#
CONFIG_RAID6_PQ=y
CONFIG_RAID6_PQ_BENCHMARK=y
CONFIG_LINEAR_RANGES=y
# CONFIG_PACKING is not set
CONFIG_BITREVERSE=y
CONFIG_GENERIC_STRNCPY_FROM_USER=y
CONFIG_GENERIC_STRNLEN_USER=y
CONFIG_GENERIC_NET_UTILS=y
# CONFIG_CORDIC is not set
# CONFIG_PRIME_NUMBERS is not set
CONFIG_RATIONAL=y
CONFIG_ARCH_USE_CMPXCHG_LOCKREF=y
CONFIG_ARCH_HAS_FAST_MULTIPLIER=y
CONFIG_ARCH_USE_SYM_ANNOTATIONS=y
CONFIG_CRC7=y
CONFIG_CRC8=y
CONFIG_CRC16=y
CONFIG_CRC_CCITT=y
CONFIG_CRC_ITU_T=y
CONFIG_CRC_T10DIF=y
CONFIG_CRC_T10DIF_ARCH=y
CONFIG_CRC32=y
CONFIG_CRC32_ARCH=y
CONFIG_CRC64=y
CONFIG_CRC64_ARCH=y
CONFIG_CRC_OPTIMIZATIONS=y
CONFIG_CRYPTO_HASH_INFO=y
CONFIG_CRYPTO_LIB_UTILS=y
CONFIG_CRYPTO_LIB_AES=y
CONFIG_CRYPTO_LIB_AES_CBC_MACS=y
CONFIG_CRYPTO_LIB_ARC4=y
CONFIG_CRYPTO_LIB_GF128MUL=y
CONFIG_CRYPTO_LIB_BLAKE2B=y
CONFIG_CRYPTO_LIB_CHACHA=y
CONFIG_CRYPTO_LIB_CURVE25519=y
CONFIG_CRYPTO_LIB_CURVE25519_GENERIC=y
CONFIG_CRYPTO_LIB_DES=y
CONFIG_CRYPTO_LIB_GF128HASH=y
CONFIG_CRYPTO_LIB_MD5=y
CONFIG_CRYPTO_LIB_MLDSA=y
CONFIG_CRYPTO_LIB_NH=y
CONFIG_CRYPTO_LIB_POLY1305=y
CONFIG_CRYPTO_LIB_POLY1305_ARCH=y
CONFIG_CRYPTO_LIB_POLY1305_GENERIC=y
CONFIG_CRYPTO_LIB_POLY1305_RSIZE=2
CONFIG_CRYPTO_LIB_CHACHA20POLY1305=y
CONFIG_CRYPTO_LIB_SHA1=y
CONFIG_CRYPTO_LIB_SHA256=y
CONFIG_CRYPTO_LIB_SHA512=y
CONFIG_CRYPTO_LIB_SHA3=y
CONFIG_XOR_BLOCKS=y
CONFIG_XOR_BLOCKS_ARCH=y
CONFIG_XXHASH=y
CONFIG_AUDIT_GENERIC=y
# CONFIG_RANDOM32_SELFTEST is not set
CONFIG_842_COMPRESS=y
CONFIG_842_DECOMPRESS=y
CONFIG_ZLIB_INFLATE=y
CONFIG_ZLIB_DEFLATE=y
CONFIG_LZO_COMPRESS=y
CONFIG_LZO_DECOMPRESS=y
CONFIG_LZ4_COMPRESS=y
CONFIG_LZ4HC_COMPRESS=y
CONFIG_LZ4_DECOMPRESS=y
CONFIG_ZSTD_COMMON=y
CONFIG_ZSTD_COMPRESS=y
CONFIG_ZSTD_DECOMPRESS=y
CONFIG_XZ_DEC=y
CONFIG_XZ_DEC_X86=y
CONFIG_XZ_DEC_POWERPC=y
CONFIG_XZ_DEC_ARM=y
CONFIG_XZ_DEC_ARMTHUMB=y
CONFIG_XZ_DEC_ARM64=y
CONFIG_XZ_DEC_SPARC=y
CONFIG_XZ_DEC_RISCV=y
# CONFIG_XZ_DEC_MICROLZMA is not set
CONFIG_XZ_DEC_BCJ=y
# CONFIG_XZ_DEC_TEST is not set
CONFIG_DECOMPRESS_GZIP=y
CONFIG_DECOMPRESS_BZIP2=y
CONFIG_DECOMPRESS_LZMA=y
CONFIG_DECOMPRESS_XZ=y
CONFIG_DECOMPRESS_LZO=y
CONFIG_DECOMPRESS_LZ4=y
CONFIG_DECOMPRESS_ZSTD=y
CONFIG_GENERIC_ALLOCATOR=y
CONFIG_REED_SOLOMON=y
CONFIG_REED_SOLOMON_DEC8=y
CONFIG_TEXTSEARCH=y
CONFIG_TEXTSEARCH_KMP=y
CONFIG_TEXTSEARCH_BM=y
CONFIG_TEXTSEARCH_FSM=y
CONFIG_INTERVAL_TREE=y
CONFIG_INTERVAL_TREE_SPAN_ITER=y
CONFIG_XARRAY_MULTI=y
CONFIG_ASSOCIATIVE_ARRAY=y
CONFIG_CLOSURES=y
CONFIG_HAS_IOMEM=y
CONFIG_HAS_IOPORT=y
CONFIG_HAS_IOPORT_MAP=y
CONFIG_HAS_DMA=y
CONFIG_NEED_DMA_MAP_STATE=y
CONFIG_ARCH_DMA_ADDR_T_64BIT=y
CONFIG_DMA_DECLARE_COHERENT=y
CONFIG_ARCH_HAS_SETUP_DMA_OPS=y
CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE=y
CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU=y
CONFIG_ARCH_HAS_DMA_PREP_COHERENT=y
CONFIG_ARCH_DMA_DEFAULT_COHERENT=y
CONFIG_SWIOTLB=y
# CONFIG_SWIOTLB_DYNAMIC is not set
CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC=y
CONFIG_DMA_NEED_SYNC=y
# CONFIG_DMA_RESTRICTED_POOL is not set
CONFIG_DMA_NONCOHERENT_MMAP=y
CONFIG_DMA_COHERENT_POOL=y
CONFIG_DMA_DIRECT_REMAP=y
CONFIG_DMA_CMA=y
# CONFIG_DMA_NUMA_CMA is not set

#
# Default contiguous memory area size:
#
CONFIG_CMA_SIZE_MBYTES=16
CONFIG_CMA_SIZE_PERCENTAGE=10
# CONFIG_CMA_SIZE_SEL_MBYTES is not set
# CONFIG_CMA_SIZE_SEL_PERCENTAGE is not set
# CONFIG_CMA_SIZE_SEL_MIN is not set
CONFIG_CMA_SIZE_SEL_MAX=y
CONFIG_CMA_ALIGNMENT=8
# CONFIG_DMA_API_DEBUG is not set
# CONFIG_DMA_MAP_BENCHMARK is not set
CONFIG_SGL_ALLOC=y
CONFIG_CHECK_SIGNATURE=y
# CONFIG_CPUMASK_OFFSTACK is not set
CONFIG_CPU_RMAP=y
CONFIG_DQL=y
CONFIG_GLOB=y
CONFIG_NLATTR=y
CONFIG_CLZ_TAB=y
CONFIG_IRQ_POLL=y
CONFIG_MPILIB=y
CONFIG_SIGNATURE=y
CONFIG_DIMLIB=y
CONFIG_LIBFDT=y
CONFIG_OID_REGISTRY=y
CONFIG_UCS2_STRING=y
CONFIG_HAVE_GENERIC_VDSO=y
CONFIG_GENERIC_GETTIMEOFDAY=y
CONFIG_VDSO_GETRANDOM=y
CONFIG_FONT_SUPPORT=y
# CONFIG_FONTS is not set
CONFIG_FONT_8x8=y
CONFIG_FONT_8x16=y
CONFIG_SG_POOL=y
CONFIG_ARCH_HAS_PMEM_API=y
CONFIG_MEMREGION=y
CONFIG_ARCH_STACKWALK=y
CONFIG_STACKDEPOT=y
CONFIG_STACKDEPOT_ALWAYS_INIT=y
CONFIG_STACKDEPOT_MAX_FRAMES=64
CONFIG_REF_TRACKER=y
CONFIG_SBITMAP=y
# CONFIG_LWQ_TEST is not set
# end of Library routines

CONFIG_GENERIC_IOREMAP=y
CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED=y
CONFIG_FIRMWARE_TABLE=y
CONFIG_UNION_FIND=y

#
# Kernel hacking
#

#
# printk and dmesg options
#
CONFIG_PRINTK_TIME=y
CONFIG_PRINTK_CALLER=y
# CONFIG_STACKTRACE_BUILD_ID is not set
CONFIG_CONSOLE_LOGLEVEL_DEFAULT=7
CONFIG_CONSOLE_LOGLEVEL_QUIET=4
CONFIG_MESSAGE_LOGLEVEL_DEFAULT=4
# CONFIG_BOOT_PRINTK_DELAY is not set
CONFIG_DYNAMIC_DEBUG=y
CONFIG_DYNAMIC_DEBUG_CORE=y
CONFIG_SYMBOLIC_ERRNAME=y
CONFIG_DEBUG_BUGVERBOSE=y
CONFIG_DEBUG_BUGVERBOSE_DETAILED=y
# end of printk and dmesg options

CONFIG_DEBUG_KERNEL=y
CONFIG_DEBUG_MISC=y

#
# Compile-time checks and compiler options
#
CONFIG_DEBUG_INFO=y
CONFIG_AS_HAS_NON_CONST_ULEB128=y
# CONFIG_DEBUG_INFO_NONE is not set
# CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT is not set
CONFIG_DEBUG_INFO_DWARF4=y
# CONFIG_DEBUG_INFO_DWARF5 is not set
# CONFIG_DEBUG_INFO_REDUCED is not set
CONFIG_DEBUG_INFO_COMPRESSED_NONE=y
# CONFIG_DEBUG_INFO_COMPRESSED_ZLIB is not set
# CONFIG_DEBUG_INFO_COMPRESSED_ZSTD is not set
# CONFIG_DEBUG_INFO_SPLIT is not set
# CONFIG_DEBUG_INFO_BTF is not set
CONFIG_PAHOLE_HAS_LANG_EXCLUDE=y
# CONFIG_GDB_SCRIPTS is not set
CONFIG_FRAME_WARN=2048
# CONFIG_STRIP_ASM_SYMS is not set
# CONFIG_READABLE_ASM is not set
# CONFIG_HEADERS_INSTALL is not set
# CONFIG_DEBUG_SECTION_MISMATCH is not set
CONFIG_SECTION_MISMATCH_WARN_ONLY=y
# CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_64B is not set
CONFIG_ARCH_WANT_FRAME_POINTERS=y
CONFIG_FRAME_POINTER=y
# CONFIG_VMLINUX_MAP is not set
# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
# end of Compile-time checks and compiler options

#
# Generic Kernel Debugging Instruments
#
# CONFIG_MAGIC_SYSRQ is not set
CONFIG_DEBUG_FS=y
CONFIG_DEBUG_FS_ALLOW_ALL=y
# CONFIG_DEBUG_FS_ALLOW_NONE is not set
CONFIG_HAVE_ARCH_KGDB=y
CONFIG_HAVE_ARCH_KGDB_QXFER_PKT=y
# CONFIG_KGDB is not set
CONFIG_ARCH_HAS_UBSAN=y
CONFIG_UBSAN=y
# CONFIG_UBSAN_TRAP is not set
CONFIG_CC_HAS_UBSAN_BOUNDS_STRICT=y
CONFIG_UBSAN_BOUNDS=y
CONFIG_UBSAN_BOUNDS_STRICT=y
CONFIG_UBSAN_SHIFT=y
# CONFIG_UBSAN_DIV_ZERO is not set
# CONFIG_UBSAN_UNREACHABLE is not set
# CONFIG_UBSAN_BOOL is not set
# CONFIG_UBSAN_ENUM is not set
# CONFIG_UBSAN_ALIGNMENT is not set
# CONFIG_TEST_UBSAN is not set
CONFIG_HAVE_KCSAN_COMPILER=y
# end of Generic Kernel Debugging Instruments

#
# Networking Debugging
#
CONFIG_NET_DEV_REFCNT_TRACKER=y
CONFIG_NET_NS_REFCNT_TRACKER=y
CONFIG_DEBUG_NET=y
# CONFIG_DEBUG_NET_SMALL_RTNL is not set
# end of Networking Debugging

#
# Memory Debugging
#
CONFIG_PAGE_EXTENSION=y
# CONFIG_DEBUG_PAGEALLOC is not set
CONFIG_SLUB_DEBUG=y
# CONFIG_SLUB_DEBUG_ON is not set
CONFIG_SLUB_RCU_DEBUG=y
CONFIG_PAGE_OWNER=y
CONFIG_PAGE_TABLE_CHECK=y
CONFIG_PAGE_TABLE_CHECK_ENFORCED=y
CONFIG_PAGE_POISONING=y
# CONFIG_DEBUG_PAGE_REF is not set
# CONFIG_DEBUG_RODATA_TEST is not set
CONFIG_ARCH_HAS_DEBUG_WX=y
# CONFIG_DEBUG_WX is not set
CONFIG_ARCH_HAS_PTDUMP=y
CONFIG_PTDUMP=y
CONFIG_PTDUMP_DEBUGFS=y
CONFIG_HAVE_DEBUG_KMEMLEAK=y
# CONFIG_DEBUG_KMEMLEAK is not set
# CONFIG_PER_VMA_LOCK_STATS is not set
CONFIG_DEBUG_OBJECTS=y
# CONFIG_DEBUG_OBJECTS_SELFTEST is not set
CONFIG_DEBUG_OBJECTS_FREE=y
CONFIG_DEBUG_OBJECTS_TIMERS=y
CONFIG_DEBUG_OBJECTS_WORK=y
CONFIG_DEBUG_OBJECTS_RCU_HEAD=y
CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER=y
CONFIG_DEBUG_OBJECTS_ENABLE_DEFAULT=1
# CONFIG_SHRINKER_DEBUG is not set
# CONFIG_DEBUG_STACK_USAGE is not set
CONFIG_SCHED_STACK_END_CHECK=y
CONFIG_ARCH_HAS_DEBUG_VM_PGTABLE=y
CONFIG_DEBUG_VFS=y
CONFIG_DEBUG_VM_IRQSOFF=y
CONFIG_DEBUG_VM=y
CONFIG_DEBUG_VM_MAPLE_TREE=y
CONFIG_DEBUG_VM_RB=y
CONFIG_DEBUG_VM_PGFLAGS=y
CONFIG_DEBUG_VM_PGTABLE=y
CONFIG_ARCH_HAS_DEBUG_VIRTUAL=y
CONFIG_DEBUG_VIRTUAL=y
CONFIG_DEBUG_MEMORY_INIT=y
CONFIG_DEBUG_PER_CPU_MAPS=y
# CONFIG_MEM_ALLOC_PROFILING is not set
CONFIG_HAVE_ARCH_KASAN=y
CONFIG_HAVE_ARCH_KASAN_VMALLOC=y
CONFIG_CC_HAS_KASAN_GENERIC=y
CONFIG_CC_HAS_WORKING_NOSANITIZE_ADDRESS=y
CONFIG_KASAN=y
CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX=y
CONFIG_KASAN_GENERIC=y
# CONFIG_KASAN_OUTLINE is not set
CONFIG_KASAN_INLINE=y
CONFIG_KASAN_STACK=y
CONFIG_KASAN_VMALLOC=y
# CONFIG_KASAN_EXTRA_INFO is not set
CONFIG_HAVE_ARCH_KFENCE=y
CONFIG_KFENCE=y
CONFIG_KFENCE_SAMPLE_INTERVAL=100
CONFIG_KFENCE_NUM_OBJECTS=255
# CONFIG_KFENCE_DEFERRABLE is not set
CONFIG_KFENCE_STATIC_KEYS=y
CONFIG_KFENCE_STRESS_TEST_FAULTS=0
# end of Memory Debugging

# CONFIG_DEBUG_SHIRQ is not set

#
# Debug Oops, Lockups and Hangs
#
CONFIG_PANIC_ON_OOPS=y
CONFIG_PANIC_TIMEOUT=86400
CONFIG_LOCKUP_DETECTOR=y
CONFIG_SOFTLOCKUP_DETECTOR=y
CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC=0
CONFIG_HAVE_HARDLOCKUP_DETECTOR_BUDDY=y
# CONFIG_HARDLOCKUP_DETECTOR is not set
CONFIG_DETECT_HUNG_TASK=y
CONFIG_DEFAULT_HUNG_TASK_TIMEOUT=420
CONFIG_BOOTPARAM_HUNG_TASK_PANIC=1
# CONFIG_DETECT_HUNG_TASK_BLOCKER is not set
CONFIG_WQ_WATCHDOG=y
CONFIG_BOOTPARAM_WQ_STALL_PANIC=0
# CONFIG_WQ_CPU_INTENSIVE_REPORT is not set
# CONFIG_TEST_LOCKUP is not set
# end of Debug Oops, Lockups and Hangs

#
# Scheduler Debugging
#
CONFIG_SCHED_INFO=y
CONFIG_SCHEDSTATS=y
# end of Scheduler Debugging

CONFIG_DEBUG_PREEMPT=y
# CONFIG_DEBUG_ATOMIC is not set

#
# Lock Debugging (spinlocks, mutexes, etc...)
#
CONFIG_LOCK_DEBUGGING_SUPPORT=y
CONFIG_PROVE_LOCKING=y
CONFIG_PROVE_RAW_LOCK_NESTING=y
# CONFIG_LOCK_STAT is not set
CONFIG_DEBUG_RT_MUTEXES=y
CONFIG_DEBUG_SPINLOCK=y
CONFIG_DEBUG_MUTEXES=y
CONFIG_DEBUG_WW_MUTEX_SLOWPATH=y
CONFIG_DEBUG_RWSEMS=y
CONFIG_DEBUG_LOCK_ALLOC=y
CONFIG_LOCKDEP=y
CONFIG_LOCKDEP_BITS=20
CONFIG_LOCKDEP_CHAINS_BITS=20
CONFIG_LOCKDEP_STACK_TRACE_BITS=20
CONFIG_LOCKDEP_STACK_TRACE_HASH_BITS=14
CONFIG_LOCKDEP_CIRCULAR_QUEUE_BITS=12
# CONFIG_DEBUG_LOCKDEP is not set
CONFIG_DEBUG_ATOMIC_SLEEP=y
# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
# CONFIG_LOCK_TORTURE_TEST is not set
# CONFIG_WW_MUTEX_SELFTEST is not set
# CONFIG_SCF_TORTURE_TEST is not set
CONFIG_CSD_LOCK_WAIT_DEBUG=y
# CONFIG_CSD_LOCK_WAIT_DEBUG_DEFAULT is not set
# end of Lock Debugging (spinlocks, mutexes, etc...)

CONFIG_TRACE_IRQFLAGS=y
CONFIG_DEBUG_IRQFLAGS=y
CONFIG_STACKTRACE=y
# CONFIG_DEBUG_KOBJECT is not set
# CONFIG_DEBUG_KOBJECT_RELEASE is not set

#
# Debug kernel data structures
#
CONFIG_DEBUG_LIST=y
CONFIG_DEBUG_PLIST=y
CONFIG_DEBUG_SG=y
CONFIG_DEBUG_NOTIFIERS=y
# CONFIG_DEBUG_CLOSURES is not set
CONFIG_DEBUG_MAPLE_TREE=y
# end of Debug kernel data structures

#
# RCU Debugging
#
CONFIG_PROVE_RCU=y
# CONFIG_RCU_SCALE_TEST is not set
# CONFIG_RCU_TORTURE_TEST is not set
# CONFIG_RCU_REF_SCALE_TEST is not set
CONFIG_RCU_CPU_STALL_TIMEOUT=300
CONFIG_RCU_EXP_CPU_STALL_TIMEOUT=0
# CONFIG_RCU_CPU_STALL_CPUTIME is not set
# CONFIG_RCU_TRACE is not set
CONFIG_RCU_EQS_DEBUG=y
# end of RCU Debugging

# CONFIG_DEBUG_WQ_FORCE_RR_CPU is not set
# CONFIG_CPU_HOTPLUG_STATE_CONTROL is not set
# CONFIG_LATENCYTOP is not set
CONFIG_USER_STACKTRACE_SUPPORT=y
CONFIG_NOP_TRACER=y
CONFIG_HAVE_RETHOOK=y
CONFIG_HAVE_FUNCTION_TRACER=y
CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
CONFIG_HAVE_FUNCTION_GRAPH_FREGS=y
CONFIG_HAVE_FTRACE_GRAPH_FUNC=y
CONFIG_HAVE_DYNAMIC_FTRACE=y
CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS=y
CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
CONFIG_HAVE_BUILDTIME_MCOUNT_SORT=y
CONFIG_TRACE_CLOCK=y
CONFIG_RING_BUFFER=y
CONFIG_EVENT_TRACING=y
CONFIG_CONTEXT_SWITCH_TRACER=y
CONFIG_PREEMPTIRQ_TRACEPOINTS=y
CONFIG_TRACING=y
CONFIG_TRACING_SUPPORT=y
CONFIG_FTRACE=y
CONFIG_TRACEFS_AUTOMOUNT_DEPRECATED=y
# CONFIG_BOOTTIME_TRACING is not set
# CONFIG_FUNCTION_TRACER is not set
# CONFIG_STACK_TRACER is not set
# CONFIG_IRQSOFF_TRACER is not set
# CONFIG_PREEMPT_TRACER is not set
# CONFIG_SCHED_TRACER is not set
# CONFIG_HWLAT_TRACER is not set
# CONFIG_OSNOISE_TRACER is not set
# CONFIG_TIMERLAT_TRACER is not set
# CONFIG_ENABLE_DEFAULT_TRACERS is not set
# CONFIG_FTRACE_SYSCALLS is not set
# CONFIG_TRACER_SNAPSHOT is not set
CONFIG_BRANCH_PROFILE_NONE=y
# CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
# CONFIG_PROFILE_ALL_BRANCHES is not set
# CONFIG_BLK_DEV_IO_TRACE is not set
CONFIG_UPROBE_EVENTS=y
CONFIG_EPROBE_EVENTS=y
CONFIG_BPF_EVENTS=y
CONFIG_DYNAMIC_EVENTS=y
CONFIG_PROBE_EVENTS=y
# CONFIG_SYNTH_EVENTS is not set
# CONFIG_USER_EVENTS is not set
# CONFIG_HIST_TRIGGERS is not set
# CONFIG_TRACE_EVENT_INJECT is not set
# CONFIG_TRACEPOINT_BENCHMARK is not set
# CONFIG_RING_BUFFER_BENCHMARK is not set
# CONFIG_TRACE_EVAL_MAP_FILE is not set
# CONFIG_RING_BUFFER_STARTUP_TEST is not set
# CONFIG_RING_BUFFER_VALIDATE_TIME_DELTAS is not set
# CONFIG_PREEMPTIRQ_DELAY_TEST is not set
# CONFIG_RV is not set
# CONFIG_TRACE_REMOTE_TEST is not set
# CONFIG_SAMPLES is not set
CONFIG_HAVE_SAMPLE_FTRACE_DIRECT=y
CONFIG_HAVE_SAMPLE_FTRACE_DIRECT_MULTI=y
# CONFIG_STRICT_DEVMEM is not set

#
# riscv Debugging
#

#
# arch/riscv/kernel Testing and Coverage
#
CONFIG_AS_HAS_ULEB128=y
CONFIG_RUNTIME_KERNEL_TESTING_MENU=y
# end of arch/riscv/kernel Testing and Coverage
# end of riscv Debugging

#
# Kernel Testing and Coverage
#
# CONFIG_KUNIT is not set
# CONFIG_NOTIFIER_ERROR_INJECTION is not set
CONFIG_FAULT_INJECTION=y
CONFIG_FAILSLAB=y
CONFIG_FAIL_PAGE_ALLOC=y
CONFIG_FAULT_INJECTION_USERCOPY=y
CONFIG_FAIL_MAKE_REQUEST=y
CONFIG_FAIL_IO_TIMEOUT=y
CONFIG_FAIL_FUTEX=y
CONFIG_FAULT_INJECTION_DEBUG_FS=y
# CONFIG_FAIL_MMC_REQUEST is not set
# CONFIG_FAIL_SKB_REALLOC is not set
CONFIG_FAULT_INJECTION_CONFIGFS=y
# CONFIG_FAULT_INJECTION_STACKTRACE_FILTER is not set
CONFIG_ARCH_HAS_KCOV=y
CONFIG_KCOV=y
CONFIG_KCOV_ENABLE_COMPARISONS=y
CONFIG_KCOV_INSTRUMENT_ALL=y
CONFIG_KCOV_IRQ_AREA_SIZE=0x40000
# CONFIG_KCOV_SELFTEST is not set
CONFIG_RUNTIME_TESTING_MENU=y
# CONFIG_TEST_DHRY is not set
# CONFIG_LKDTM is not set
# CONFIG_TEST_DIV64 is not set
# CONFIG_TEST_MULDIV64 is not set
# CONFIG_BACKTRACE_SELF_TEST is not set
# CONFIG_TEST_REF_TRACKER is not set
# CONFIG_RBTREE_TEST is not set
# CONFIG_REED_SOLOMON_TEST is not set
# CONFIG_INTERVAL_TREE_TEST is not set
# CONFIG_PERCPU_TEST is not set
# CONFIG_ATOMIC64_SELFTEST is not set
# CONFIG_ASYNC_RAID6_TEST is not set
# CONFIG_TEST_HEXDUMP is not set
# CONFIG_TEST_KSTRTOX is not set
# CONFIG_TEST_BITMAP is not set
# CONFIG_TEST_XARRAY is not set
# CONFIG_TEST_MAPLE_TREE is not set
# CONFIG_TEST_RHASHTABLE is not set
# CONFIG_TEST_IDA is not set
# CONFIG_TEST_LKM is not set
# CONFIG_TEST_BITOPS is not set
# CONFIG_TEST_VMALLOC is not set
# CONFIG_TEST_WORKQUEUE is not set
# CONFIG_TEST_BPF is not set
# CONFIG_FIND_BIT_BENCHMARK is not set
# CONFIG_TEST_FIRMWARE is not set
# CONFIG_TEST_SYSCTL is not set
# CONFIG_CONTEXT_ANALYSIS_TEST is not set
# CONFIG_TEST_UDELAY is not set
# CONFIG_TEST_STATIC_KEYS is not set
# CONFIG_TEST_DYNAMIC_DEBUG is not set
# CONFIG_TEST_KMOD is not set
# CONFIG_TEST_KALLSYMS is not set
# CONFIG_TEST_DEBUG_VIRTUAL is not set
# CONFIG_TEST_MEMCAT_P is not set
# CONFIG_TEST_MEMINIT is not set
# CONFIG_TEST_FREE_PAGES is not set
# CONFIG_TEST_OBJPOOL is not set
CONFIG_ARCH_USE_MEMTEST=y
CONFIG_MEMTEST=y
# end of Kernel Testing and Coverage

#
# Rust hacking
#
# end of Rust hacking
# end of Kernel hacking

CONFIG_IO_URING_ZCRX=y
CONFIG_IO_URING_BPF=y
KernelRepo git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git
ReproCID 0
ReproOpts
ReproSyzID 0
SyzkallerCommit c69befb30ac10e158cc9d1557b508ee3f0eca1de

Outputs:
DenialOfService
Exploitable
FilesystemTrigger
NetworkTrigger
PeripheralTrigger
RemoteTrigger
Unprivileged
UserNamespace
VMGuestTrigger
VMHostTrigger
Explanation
The bug report indicates a `BUG_ON` triggering in `__page_table_check_zero()` at
`mm/page_table_check.c:142` during process exit (`exit_mmap` -> `tlb_finish_mmu`
-> `free_pages_and_swap_cache`).

### Analysis of the Crash
The `CONFIG_PAGE_TABLE_CHECK` feature synchronously tracks the number of user
page table entries (PTEs, PMDs, etc.) that map each physical page. When a page
is finally freed to the buddy allocator (`__free_pages_prepare`),
`__page_table_check_zero()` verifies that the page is no longer mapped anywhere
by checking that its `anon_map_count` and `file_map_count` are exactly zero.

The crash (`BUG_ON(atomic_read(&ptc->anon_map_count));`) means that a page is
being freed while the kernel's page table tracking still believes there are
active user PTEs pointing to it.

There are two main ways this can happen:
1. **An accounting bug in architecture-specific page table macros:** A PTE was
cleared without calling the corresponding `page_table_check_pte_clear()` hook,
leaving a dangling map count.
2. **A genuine refcount bug (Use-After-Free):** The page was mapped multiple
times (e.g., shared between processes or threads), but its `refcount` was
erroneously decremented too many times. When the current process unmapped its
PTE, the refcount dropped to 0, causing the page to be freed. However, because
it was still mapped in another process, its `anon_map_count` was still > 0,
triggering the `BUG_ON`.

### Investigation of RISC-V Page Table Macros
Extensive review of the RISC-V page table manipulation code (including HugeTLB,
NAPOT, and generic PTE/PMD helpers) confirms that the accounting hooks are
correctly placed:
- `ptep_get_and_clear()` correctly calls `page_table_check_pte_clear()`.
- `set_pte_at()` correctly calls `page_table_check_ptes_set()`.
- `ptep_get_and_clear_full()` falls back to the generic implementation which
correctly hooks into the checks.
- While `huge_pte_clear()` in RISC-V bypasses the checks by using `pte_clear()`,
it is strictly only ever called on non-present PTEs (like migration entries or
UFFD_WP markers) which do not contribute to the map count anyway.
- The recent fix in commit `83d78ac677b9` ("riscv: Fix hugetlb retrieval of
number of ptes in case of !present pte") addressed an issue where only 1 PTE of
a 16-PTE NAPOT block was cleared for non-present entries. However, since
non-present entries do not increment the `page_table_check` map count, leaving
them behind does not cause this specific `BUG_ON`.

### Conclusion
Since the page table accounting macros are sound, the crash is the result of a
**genuine page refcount bug (Use-After-Free)**. The `mmu_gather` batching
correctly unmapped the page and decremented its map count, but the page's
refcount hit 0 prematurely while it was still mapped elsewhere.

Because the page is freed while another process (or thread) still holds a valid
PTE pointing to it, the kernel might reallocate this physical page for sensitive
kernel data or another user's memory. The process holding the dangling PTE can
then read or write to the reallocated page. This is a classic Use-After-Free
(UAF) via page tables, which is highly exploitable for local privilege
escalation (LPE) and memory corruption.

### Impact Assessment
* **Exploitable:** Yes. A UAF via page tables allows an attacker to achieve
read/write primitives over reallocated physical memory, leading to privilege
escalation.
* **Denial Of Service:** Yes. The `BUG_ON` halts the kernel, and the underlying
memory corruption can cause system instability.
* **Accessible From Unprivileged Processes:** Yes. The bug is triggered by
standard memory management syscalls (like `mmap`, `madvise`, `fork`, `exit`)
which are available to unprivileged users.
* **Accessible From User Namespaces:** Yes. No special capabilities are required
to trigger memory management paths.
* **Remote / Peripheral / VM / Filesystem Triggers:** No. This is a core virtual
memory management bug, triggered by local syscalls.

Crash report:
------------[ cut here ]------------
kernel BUG at [] mm/page_table_check.c:142!
Kernel BUG [#1]
Modules linked in:
CPU: 0 UID: 0 PID: 5067 Comm: syz.0.366 Tainted: G        W           syzkaller #0 PREEMPT 
Tainted: [W]=WARN
Hardware name: riscv-virtio,qemu (DT)
epc : __page_table_check_zero+0x386/0x534 mm/page_table_check.c:142
 ra : __page_table_check_zero+0x386/0x534 mm/page_table_check.c:142
epc : ffffffff80c6a8b6 ra : ffffffff80c6a8b6 sp : ffff8f800a0a6fa0
 gp : ffffffff8a24e5c0 tp : ffffaf801b6d0000 t0 : ffff8f800a0a6f40
 t1 : fffff5ef02738409 t2 : ffffffff91627f80 s0 : ffff8f800a0a7010
 s1 : ffffaf80139c2048 a0 : 0000000000000005 a1 : 0000000000000000
 a2 : 0000000000000002 a3 : ffffffff80c6a8b6 a4 : 0000000000000000
 a5 : ffffaf801b6d1000 a6 : 0000000000000003 a7 : ffffaf80139c204b
 s2 : 0000000000000001 s3 : 0000000000000000 s4 : ffffaf80139c2000
 s5 : dfffffff00000000 s6 : 00000000000b5a00 s7 : 0000000000000200
 s8 : 0000000000000009 s9 : 0000000000007fff s10: fffffffef146d78c
 s11: ffffffff8a36bc60 t3 : 0000000000000001 t4 : fffff5ef02738409
 t5 : fffff5ef0273840a t6 : 0000000000000002 ssp : 0000000000000000
status: 0000000200000120 badaddr: ffffffff80c6a8b6 cause: 0000000000000003
[<ffffffff80c6a8b6>] __page_table_check_zero+0x386/0x534 mm/page_table_check.c:142
[<ffffffff80ae7672>] page_table_check_free include/linux/page_table_check.h:46 [inline]
[<ffffffff80ae7672>] __free_pages_prepare mm/page_alloc.c:1403 [inline]
[<ffffffff80ae7672>] free_unref_folios+0xb1e/0x1ad0 mm/page_alloc.c:3004
[<ffffffff80914374>] folios_put_refs+0x458/0x7c8 mm/swap.c:1008
[<ffffffff80b33b42>] free_pages_and_swap_cache+0x22e/0x3c0 mm/swap_state.c:401
[<ffffffff80a59ce0>] __tlb_batch_free_encoded_pages+0xe4/0x25c mm/mmu_gather.c:138
[<ffffffff80a5c864>] tlb_batch_pages_flush mm/mmu_gather.c:151 [inline]
[<ffffffff80a5c864>] tlb_flush_mmu_free mm/mmu_gather.c:417 [inline]
[<ffffffff80a5c864>] tlb_flush_mmu mm/mmu_gather.c:424 [inline]
[<ffffffff80a5c864>] tlb_finish_mmu+0x188/0x824 mm/mmu_gather.c:549
[<ffffffff80a56262>] exit_mmap+0x416/0xcc0 mm/mmap.c:1313
[<ffffffff80141ed6>] __mmput+0x106/0x3d0 kernel/fork.c:1178
[<ffffffff80142214>] mmput+0x74/0x88 kernel/fork.c:1201
[<ffffffff80162c26>] exit_mm kernel/exit.c:582 [inline]
[<ffffffff80162c26>] do_exit+0x876/0x2a18 kernel/exit.c:964
[<ffffffff801652f6>] do_group_exit+0xca/0x258 kernel/exit.c:1119
[<ffffffff8019efb2>] get_signal+0x1f56/0x2224 kernel/signal.c:3037
[<ffffffff80072924>] arch_do_signal_or_restart+0xf4/0x1e08 arch/riscv/kernel/signal.c:534
[<ffffffff86483ca4>] __exit_to_user_mode_loop kernel/entry/common.c:64 [inline]
[<ffffffff86483ca4>] exit_to_user_mode_loop kernel/entry/common.c:98 [inline]
[<ffffffff86483ca4>] __exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
[<ffffffff86483ca4>] irqentry_exit_to_user_mode_prepare include/linux/irq-entry-common.h:244 [inline]
[<ffffffff86483ca4>] irqentry_exit_to_user_mode include/linux/irq-entry-common.h:315 [inline]
[<ffffffff86483ca4>] irqentry_exit+0x6a0/0xe8c kernel/entry/common.c:162
[<ffffffff8648279e>] do_page_fault+0x3e/0x58 arch/riscv/kernel/traps.c:420
[<ffffffff864ad412>] handle_exception+0x15e/0x16a arch/riscv/kernel/entry.S:232
Code: f580 8526 d0ef 88af 8a2a b7a1 7097 ff8c 80e7 f460 (9002) 7097 
---[ end trace 0000000000000000 ]---
----------------
Code disassembly (best guess):
   0:	f580                	fsw	fs0,40(a1)
   2:	8526                	mv	a0,s1
   4:	88afd0ef          	jal	0xffffffffffffd08e
   8:	8a2a                	mv	s4,a0
   a:	b7a1                	j	0xffffffffffffff52
   c:	ff8c7097          	auipc	ra,0xff8c7
  10:	f46080e7          	jalr	-186(ra) # 0xff8c6f52
* 14:	9002                	ebreak <-- trapping instruction
  16:	9770                	.short	0x7097

Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/05/24 23:27 flow assessment-security
1h30m Results:
map[DenialOfService:true Explanation:The bug report indicates a `BUG_ON` triggering in `__page_table_check_zero()` at
`mm/page_table_check.c:142` during process exit (`exit_mmap` -> `tlb_finish_mmu`
-> `free_pages_and_swap_cache`).

### Analysis of the Crash
The `CONFIG_PAGE_TABLE_CHECK` feature synchronously tracks the number of user
page table entries (PTEs, PMDs, etc.) that map each physical page. When a page
is finally freed to the buddy allocator (`__free_pages_prepare`),
`__page_table_check_zero()` verifies that the page is no longer mapped anywhere
by checking that its `anon_map_count` and `file_map_count` are exactly zero.

The crash (`BUG_ON(atomic_read(&ptc->anon_map_count));`) means that a page is
being freed while the kernel's page table tracking still believes there are
active user PTEs pointing to it.

There are two main ways this can happen:
1. **An accounting bug in architecture-specific page table macros:** A PTE was
cleared without calling the corresponding `page_table_check_pte_clear()` hook,
leaving a dangling map count.
2. **A genuine refcount bug (Use-After-Free):** The page was mapped multiple
times (e.g., shared between processes or threads), but its `refcount` was
erroneously decremented too many times. When the current process unmapped its
PTE, the refcount dropped to 0, causing the page to be freed. However, because
it was still mapped in another process, its `anon_map_count` was still > 0,
triggering the `BUG_ON`.

### Investigation of RISC-V Page Table Macros
Extensive review of the RISC-V page table manipulation code (including HugeTLB,
NAPOT, and generic PTE/PMD helpers) confirms that the accounting hooks are
correctly placed:
- `ptep_get_and_clear()` correctly calls `page_table_check_pte_clear()`.
- `set_pte_at()` correctly calls `page_table_check_ptes_set()`.
- `ptep_get_and_clear_full()` falls back to the generic implementation which
correctly hooks into the checks.
- While `huge_pte_clear()` in RISC-V bypasses the checks by using `pte_clear()`,
it is strictly only ever called on non-present PTEs (like migration entries or
UFFD_WP markers) which do not contribute to the map count anyway.
- The recent fix in commit `83d78ac677b9` ("riscv: Fix hugetlb retrieval of
number of ptes in case of !present pte") addressed an issue where only 1 PTE of
a 16-PTE NAPOT block was cleared for non-present entries. However, since
non-present entries do not increment the `page_table_check` map count, leaving
them behind does not cause this specific `BUG_ON`.

### Conclusion
Since the page table accounting macros are sound, the crash is the result of a
**genuine page refcount bug (Use-After-Free)**. The `mmu_gather` batching
correctly unmapped the page and decremented its map count, but the page's
refcount hit 0 prematurely while it was still mapped elsewhere.

Because the page is freed while another process (or thread) still holds a valid
PTE pointing to it, the kernel might reallocate this physical page for sensitive
kernel data or another user's memory. The process holding the dangling PTE can
then read or write to the reallocated page. This is a classic Use-After-Free
(UAF) via page tables, which is highly exploitable for local privilege
escalation (LPE) and memory corruption.

### Impact Assessment
* **Exploitable:** Yes. A UAF via page tables allows an attacker to achieve
read/write primitives over reallocated physical memory, leading to privilege
escalation.
* **Denial Of Service:** Yes. The `BUG_ON` halts the kernel, and the underlying
memory corruption can cause system instability.
* **Accessible From Unprivileged Processes:** Yes. The bug is triggered by
standard memory management syscalls (like `mmap`, `madvise`, `fork`, `exit`)
which are available to unprivileged users.
* **Accessible From User Namespaces:** Yes. No special capabilities are required
to trigger memory management paths.
* **Remote / Peripheral / VM / Filesystem Triggers:** No. This is a core virtual
memory management bug, triggered by local syscalls. Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]

1/1 2026/05/24 23:27 action syz-repro-to-c-repro
0m Results:
map[SimplifiedCRepro:]

2/1 2026/05/24 23:27 action kernel-checkouter
1m Results:
map[KernelSrc:/app/workdir/cache/src/0a8da66c6e720ca0cf58bfd35158c310dcb0cdae]

3/1 2026/05/24 23:28 action kernel-builder
13m Results:
map[KernelObj:/app/workdir/cache/build/27eff92a205e350aebd99b93186d9821be84bca9]

4/1 2026/05/24 23:42 action codesearch-prepare
14m Results:
map[Index:codesearch-index]

5/1 2026/05/24 23:56 agent expert
1h02m Model:
gemini-3.1-pro-preview

Results:
map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]

Instruction:
You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.

Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by greeping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).

Try different strategies when analyzing the bug:
 - think of ways in which the vulnerable code is unreachable
 - or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.

Analysis dimensions:

* Exploitable:
Determine if the bug can result in memory corruption or elevated privileges.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completly wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control tranfers, that's also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitabability depends on how exactly the uninit value
is used in the code, and what it affects.

Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.

* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.

* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).

* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.

* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.

* VM Host Trigger in The Confidetial Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).

* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.

* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).

* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.

* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.

Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.

Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
The kernel bug report is:

------------[ cut here ]------------
kernel BUG at [] mm/page_table_check.c:142!
Kernel BUG [#1]
Modules linked in:
CPU: 0 UID: 0 PID: 5067 Comm: syz.0.366 Tainted: G        W           syzkaller #0 PREEMPT 
Tainted: [W]=WARN
Hardware name: riscv-virtio,qemu (DT)
epc : __page_table_check_zero+0x386/0x534 mm/page_table_check.c:142
 ra : __page_table_check_zero+0x386/0x534 mm/page_table_check.c:142
epc : ffffffff80c6a8b6 ra : ffffffff80c6a8b6 sp : ffff8f800a0a6fa0
 gp : ffffffff8a24e5c0 tp : ffffaf801b6d0000 t0 : ffff8f800a0a6f40
 t1 : fffff5ef02738409 t2 : ffffffff91627f80 s0 : ffff8f800a0a7010
 s1 : ffffaf80139c2048 a0 : 0000000000000005 a1 : 0000000000000000
 a2 : 0000000000000002 a3 : ffffffff80c6a8b6 a4 : 0000000000000000
 a5 : ffffaf801b6d1000 a6 : 0000000000000003 a7 : ffffaf80139c204b
 s2 : 0000000000000001 s3 : 0000000000000000 s4 : ffffaf80139c2000
 s5 : dfffffff00000000 s6 : 00000000000b5a00 s7 : 0000000000000200
 s8 : 0000000000000009 s9 : 0000000000007fff s10: fffffffef146d78c
 s11: ffffffff8a36bc60 t3 : 0000000000000001 t4 : fffff5ef02738409
 t5 : fffff5ef0273840a t6 : 0000000000000002 ssp : 0000000000000000
status: 0000000200000120 badaddr: ffffffff80c6a8b6 cause: 0000000000000003
[<ffffffff80c6a8b6>] __page_table_check_zero+0x386/0x534 mm/page_table_check.c:142
[<ffffffff80ae7672>] page_table_check_free include/linux/page_table_check.h:46 [inline]
[<ffffffff80ae7672>] __free_pages_prepare mm/page_alloc.c:1403 [inline]
[<ffffffff80ae7672>] free_unref_folios+0xb1e/0x1ad0 mm/page_alloc.c:3004
[<ffffffff80914374>] folios_put_refs+0x458/0x7c8 mm/swap.c:1008
[<ffffffff80b33b42>] free_pages_and_swap_cache+0x22e/0x3c0 mm/swap_state.c:401
[<ffffffff80a59ce0>] __tlb_batch_free_encoded_pages+0xe4/0x25c mm/mmu_gather.c:138
[<ffffffff80a5c864>] tlb_batch_pages_flush mm/mmu_gather.c:151 [inline]
[<ffffffff80a5c864>] tlb_flush_mmu_free mm/mmu_gather.c:417 [inline]
[<ffffffff80a5c864>] tlb_flush_mmu mm/mmu_gather.c:424 [inline]
[<ffffffff80a5c864>] tlb_finish_mmu+0x188/0x824 mm/mmu_gather.c:549
[<ffffffff80a56262>] exit_mmap+0x416/0xcc0 mm/mmap.c:1313
[<ffffffff80141ed6>] __mmput+0x106/0x3d0 kernel/fork.c:1178
[<ffffffff80142214>] mmput+0x74/0x88 kernel/fork.c:1201
[<ffffffff80162c26>] exit_mm kernel/exit.c:582 [inline]
[<ffffffff80162c26>] do_exit+0x876/0x2a18 kernel/exit.c:964
[<ffffffff801652f6>] do_group_exit+0xca/0x258 kernel/exit.c:1119
[<ffffffff8019efb2>] get_signal+0x1f56/0x2224 kernel/signal.c:3037
[<ffffffff80072924>] arch_do_signal_or_restart+0xf4/0x1e08 arch/riscv/kernel/signal.c:534
[<ffffffff86483ca4>] __exit_to_user_mode_loop kernel/entry/common.c:64 [inline]
[<ffffffff86483ca4>] exit_to_user_mode_loop kernel/entry/common.c:98 [inline]
[<ffffffff86483ca4>] __exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
[<ffffffff86483ca4>] irqentry_exit_to_user_mode_prepare include/linux/irq-entry-common.h:244 [inline]
[<ffffffff86483ca4>] irqentry_exit_to_user_mode include/linux/irq-entry-common.h:315 [inline]
[<ffffffff86483ca4>] irqentry_exit+0x6a0/0xe8c kernel/entry/common.c:162
[<ffffffff8648279e>] do_page_fault+0x3e/0x58 arch/riscv/kernel/traps.c:420
[<ffffffff864ad412>] handle_exception+0x15e/0x16a arch/riscv/kernel/entry.S:232
Code: f580 8526 d0ef 88af 8a2a b7a1 7097 ff8c 80e7 f460 (9002) 7097 
---[ end trace 0000000000000000 ]---
----------------
Code disassembly (best guess):
   0:	f580                	fsw	fs0,40(a1)
   2:	8526                	mv	a0,s1
   4:	88afd0ef          	jal	0xffffffffffffd08e
   8:	8a2a                	mv	s4,a0
   a:	b7a1                	j	0xffffffffffffff52
   c:	ff8c7097          	auipc	ra,0xff8c7
  10:	f46080e7          	jalr	-186(ra) # 0xff8c6f52
* 14:	9002                	ebreak <-- trapping instruction
  16:	9770                	.short	0x7097




Reply:
The bug report indicates a `BUG_ON` triggering in `__page_table_check_zero()` at `mm/page_table_check.c:142` during process exit (`exit_mmap` -> `tlb_finish_mmu` -> `free_pages_and_swap_cache`). 

### Analysis of the Crash
The `CONFIG_PAGE_TABLE_CHECK` feature synchronously tracks the number of user page table entries (PTEs, PMDs, etc.) that map each physical page. When a page is finally freed to the buddy allocator (`__free_pages_prepare`), `__page_table_check_zero()` verifies that the page is no longer mapped anywhere by checking that its `anon_map_count` and `file_map_count` are exactly zero. 

The crash (`BUG_ON(atomic_read(&ptc->anon_map_count));`) means that a page is being freed while the kernel's page table tracking still believes there are active user PTEs pointing to it.

There are two main ways this can happen:
1. **An accounting bug in architecture-specific page table macros:** A PTE was cleared without calling the corresponding `page_table_check_pte_clear()` hook, leaving a dangling map count.
2. **A genuine refcount bug (Use-After-Free):** The page was mapped multiple times (e.g., shared between processes or threads), but its `refcount` was erroneously decremented too many times. When the current process unmapped its PTE, the refcount dropped to 0, causing the page to be freed. However, because it was still mapped in another process, its `anon_map_count` was still > 0, triggering the `BUG_ON`.

### Investigation of RISC-V Page Table Macros
Extensive review of the RISC-V page table manipulation code (including HugeTLB, NAPOT, and generic PTE/PMD helpers) confirms that the accounting hooks are correctly placed:
- `ptep_get_and_clear()` correctly calls `page_table_check_pte_clear()`.
- `set_pte_at()` correctly calls `page_table_check_ptes_set()`.
- `ptep_get_and_clear_full()` falls back to the generic implementation which correctly hooks into the checks.
- While `huge_pte_clear()` in RISC-V bypasses the checks by using `pte_clear()`, it is strictly only ever called on non-present PTEs (like migration entries or UFFD_WP markers) which do not contribute to the map count anyway.
- The recent fix in commit `83d78ac677b9` ("riscv: Fix hugetlb retrieval of number of ptes in case of !present pte") addressed an issue where only 1 PTE of a 16-PTE NAPOT block was cleared for non-present entries. However, since non-present entries do not increment the `page_table_check` map count, leaving them behind does not cause this specific `BUG_ON`.

### Conclusion
Since the page table accounting macros are sound, the crash is the result of a **genuine page refcount bug (Use-After-Free)**. The `mmu_gather` batching correctly unmapped the page and decremented its map count, but the page's refcount hit 0 prematurely while it was still mapped elsewhere. 

Because the page is freed while another process (or thread) still holds a valid PTE pointing to it, the kernel might reallocate this physical page for sensitive kernel data or another user's memory. The process holding the dangling PTE can then read or write to the reallocated page. This is a classic Use-After-Free (UAF) via page tables, which is highly exploitable for local privilege escalation (LPE) and memory corruption.

### Impact Assessment
* **Exploitable:** Yes. A UAF via page tables allows an attacker to achieve read/write primitives over reallocated physical memory, leading to privilege escalation.
* **Denial Of Service:** Yes. The `BUG_ON` halts the kernel, and the underlying memory corruption can cause system instability.
* **Accessible From Unprivileged Processes:** Yes. The bug is triggered by standard memory management syscalls (like `mmap`, `madvise`, `fork`, `exit`) which are available to unprivileged users.
* **Accessible From User Namespaces:** Yes. No special capabilities are required to trigger memory management paths.
* **Remote / Peripheral / VM / Filesystem Triggers:** No. This is a core virtual memory management bug, triggered by local syscalls.

6/2 2026/05/24 23:56 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 7562
							output: 46
							thoughts: 208
						

Thoughts:
**Kernel Bug Investigation: Zero Page Table Entry**

Okay, so I've got a kernel BUG, and it's pinpointed to `mm/page_table_check.c:142`. The function in question is `__page_table_check_zero`. This immediately flags a potential issue with zero-initialized page table entries, which, if mishandled, can lead to serious corruption. Let's see what the stack trace tells me: `__page_table_check_zero` leads into `page_table_check_free`, then down through the freeing path: `__free_pages_prepare`, `free_unref_folios`, `folios_put_refs`, `free_pages_and_swap_cache`, and then we get to the TLB flushing (`__tlb_batch_free_encoded_pages`, `tlb_batch_pages_flush`, `tlb_flush_mmu_free`, `tlb_flush_mmu`, `tlb_finish_mmu`). Then it looks like we're exiting the memory map (`exit_mmap`, `__mmput`, `mmput`, `exit_mm`, `do_exit`).

Based on the stack trace, the bug seems to be triggered during a memory map exit, probably related to freeing pages and potentially TLB invalidation. The presence of `__page_table_check_zero` combined with the "free" functions implies some kind of corruption or incorrect handling of page table entries when the memory map is released. It's likely an issue where a page table entry meant to be zero is being incorrectly processed, or where a check on its status is failing. My next step will be to dive into `mm/page_table_check.c:142` and see precisely what `__page_table_check_zero` is doing and what its inputs are. I also need to understand how the memory map is structured in this specific scenario, as that will likely provide the critical context. I need to be careful with the TLB flushing operations as that could cause instability.



7/2 2026/05/24 23:56 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/page_table_check.c IncludeLines:true Name:__page_table_check_zero]

Results:
map[SourceCode: 127:	/*
 128:	 * page is on free list, or is being allocated, verify that counters are zeroes
 129:	 * crash if they are not.
 130:	 */
 131:	void __page_table_check_zero(struct page *page, unsigned int order)
 132:	{
 133:		struct page_ext_iter iter;
 134:		struct page_ext *page_ext;
 135:	
 136:		BUG_ON(PageSlab(page));
 137:	
 138:		rcu_read_lock();
 139:		for_each_page_ext(page, 1 << order, page_ext, iter) {
 140:			struct page_table_check *ptc = get_page_table_check(page_ext);
 141:	
 142:			BUG_ON(atomic_read(&ptc->anon_map_count));
 143:			BUG_ON(atomic_read(&ptc->file_map_count));
 144:		}
 145:		rcu_read_unlock();
 146:	}
 SourceFile:mm/page_table_check.c]

8/2 2026/05/24 23:56 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 8598
							output: 20
							thoughts: 115
						

Thoughts:
**Debugging a Page Table Anomaly**

Okay, so I'm staring at this `BUG_ON` triggering at either `atomic_read(&ptc->anon_map_count)` or `atomic_read(&ptc->file_map_count)`. That's a classic sign – a page is being freed, but the page table check counters are telling us it's *still* mapped. Sounds like a textbook mismatch. I'm pretty sure I've seen this before, and it's almost certainly related to that `CONFIG_PAGE_TABLE_CHECK` feature. It's designed to catch precisely this sort of thing, a great tool but it can be noisy.

The big question now is, is `CONFIG_PAGE_TABLE_CHECK` even *enabled* in the production builds? It’s usually more of a debugging and testing flag, so I need to check its Kconfig entry to confirm. If it's on in prod, we have a bigger issue, if it's off, we have a bigger issue that the debug tools aren't catching. Let's see if we can get to the root of this.



9/2 2026/05/24 23:56 tool grepper
0m Args:
map[Expression:config PAGE_TABLE_CHECK]

Results:
map[Output:mm/Kconfig.debug=105=config PAGE_OWNER
--
mm/Kconfig.debug-121-
mm/Kconfig.debug:122:config PAGE_TABLE_CHECK
mm/Kconfig.debug-123-	bool "Check for invalid mappings in user page tables"
--
mm/Kconfig.debug-135-
mm/Kconfig.debug:136:config PAGE_TABLE_CHECK_ENFORCED
mm/Kconfig.debug-137-	bool "Enforce the page table checking by default"
]

10/2 2026/05/24 23:56 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 9122
							output: 21
							thoughts: 15
						

Thoughts:
Okay, here's my attempt at summarizing that thought process, tailored for an expert audience:

**Diving into the PAGE_TABLE_CHECK Kconfig**

Right, let's get down to brass tacks. I need to get a comprehensive view of the `PAGE_TABLE_CHECK` Kconfig option. I'm not looking for a superficial overview; I want the complete picture. I need to understand its dependencies, its implications, and where it fits into the broader kernel configuration landscape. This isn't just about whether it's enabled or disabled, I need the detailed specification. I'm thinking about the low-level details, so I need to see the entire Kconfig fragment to get a feel for the underlying architectural considerations and any potential caveats. Let's see all the relevant context.



11/2 2026/05/24 23:56 tool read-file
0m Args:
map[File:mm/Kconfig.debug]

Results:
map[Contents:# SPDX-License-Identifier: GPL-2.0-only
config PAGE_EXTENSION
	bool "Extend memmap on extra space for more information on page"
	help
	  Extend memmap on extra space for more information on page. This
	  could be used for debugging features that need to insert extra
	  field for every page. This extension enables us to save memory
	  by not allocating this extra memory according to boottime
	  configuration.

config DEBUG_PAGEALLOC
	bool "Debug page memory allocations"
	depends on DEBUG_KERNEL
	depends on !HIBERNATION || ARCH_SUPPORTS_DEBUG_PAGEALLOC && !PPC && !SPARC
	select PAGE_POISONING if !ARCH_SUPPORTS_DEBUG_PAGEALLOC
	help
	  Unmap pages from the kernel linear mapping after free_pages().
	  Depending on runtime enablement, this results in a small or large
	  slowdown, but helps to find certain types of memory corruption.

	  Also, the state of page tracking structures is checked more often as
	  pages are being allocated and freed, as unexpected state changes
	  often happen for same reasons as memory corruption (e.g. double free,
	  use-after-free). The error reports for these checks can be augmented
	  with stack traces of last allocation and freeing of the page, when
	  PAGE_OWNER is also selected and enabled on boot.

	  For architectures which don't enable ARCH_SUPPORTS_DEBUG_PAGEALLOC,
	  fill the pages with poison patterns after free_pages() and verify
	  the patterns before alloc_pages(). Additionally, this option cannot
	  be enabled in combination with hibernation as that would result in
	  incorrect warnings of memory corruption after a resume because free
	  pages are not saved to the suspend image.

	  By default this option will have a small overhead, e.g. by not
	  allowing the kernel mapping to be backed by large pages on some
	  architectures. Even bigger overhead comes when the debugging is
	  enabled by DEBUG_PAGEALLOC_ENABLE_DEFAULT or the debug_pagealloc
	  command line parameter.

config DEBUG_PAGEALLOC_ENABLE_DEFAULT
	bool "Enable debug page memory allocations by default?"
	depends on DEBUG_PAGEALLOC
	help
	  Enable debug page memory allocations by default? This value
	  can be overridden by debug_pagealloc=off|on.

config SLUB_DEBUG
	default y
	bool "Enable SLUB debugging support" if EXPERT
	depends on SYSFS && !SLUB_TINY
	select STACKDEPOT if STACKTRACE_SUPPORT
	help
	  SLUB has extensive debug support features. Disabling these can
	  result in significant savings in code size. While /sys/kernel/slab
	  will still exist (with SYSFS enabled), it will not provide e.g. cache
	  validation.

config SLUB_DEBUG_ON
	bool "SLUB debugging on by default"
	depends on SLUB_DEBUG
	select STACKDEPOT_ALWAYS_INIT if STACKTRACE_SUPPORT
	default n
	help
	  Boot with debugging on by default. SLUB boots by default with
	  the runtime debug capabilities switched off. Enabling this is
	  equivalent to specifying the "slab_debug" parameter on boot.
	  There is no support for more fine grained debug control like
	  possible with slab_debug=xxx. SLUB debugging may be switched
	  off in a kernel built with CONFIG_SLUB_DEBUG_ON by specifying
	  "slab_debug=-".

config SLUB_RCU_DEBUG
	bool "Enable UAF detection in TYPESAFE_BY_RCU caches (for KASAN)"
	depends on SLUB_DEBUG
	# SLUB_RCU_DEBUG should build fine without KASAN, but is currently useless
	# without KASAN, so mark it as a dependency of KASAN for now.
	depends on KASAN
	default KASAN_GENERIC || KASAN_SW_TAGS
	help
	  Make SLAB_TYPESAFE_BY_RCU caches behave approximately as if the cache
	  was not marked as SLAB_TYPESAFE_BY_RCU and every caller used
	  kfree_rcu() instead.

	  This is intended for use in combination with KASAN, to enable KASAN to
	  detect use-after-free accesses in such caches.
	  (KFENCE is able to do that independent of this flag.)

	  This might degrade performance.
	  Unfortunately this also prevents a very specific bug pattern from
	  triggering (insufficient checks against an object being recycled
	  within the RCU grace period); so this option can be turned off even on
	  KASAN builds, in case you want to test for such a bug.

	  If you're using this for testing bugs / fuzzing and care about
	  catching all the bugs WAY more than performance, you might want to
	  also turn on CONFIG_RCU_STRICT_GRACE_PERIOD.

	  WARNING:
	  This is designed as a debugging feature, not a security feature.
	  Objects are sometimes recycled without RCU delay under memory pressure.

	  If unsure, say N.

config PAGE_OWNER
	bool "Track page owner"
	depends on DEBUG_KERNEL && STACKTRACE_SUPPORT
	select DEBUG_FS
	select STACKTRACE
	select STACKDEPOT
	select PAGE_EXTENSION
	help
	  This keeps track of what call chain is the owner of a page, may
	  help to find bare alloc_page(s) leaks. Even if you include this
	  feature on your build, it is disabled in default. You should pass
	  "page_owner=on" to boot parameter in order to enable it. Eats
	  a fair amount of memory if enabled. See tools/mm/page_owner_sort.c
	  for user-space helper.

	  If unsure, say N.

config PAGE_TABLE_CHECK
	bool "Check for invalid mappings in user page tables"
	depends on ARCH_SUPPORTS_PAGE_TABLE_CHECK
	depends on EXCLUSIVE_SYSTEM_RAM
	select PAGE_EXTENSION
	help
	  Check that anonymous page is not being mapped twice with read write
	  permissions. Check that anonymous and file pages are not being
	  erroneously shared. Since the checking is performed at the time
	  entries are added and removed to user page tables, leaking, corruption
	  and double mapping problems are detected synchronously.

	  If unsure say "n".

config PAGE_TABLE_CHECK_ENFORCED
	bool "Enforce the page table checking by default"
	depends on PAGE_TABLE_CHECK
	help
	  Always enable page table checking.  By default the page table checking
	  is disabled, and can be optionally enabled via page_table_check=on
	  kernel parameter. This config enforces that page table check is always
	  enabled.

	  If unsure say "n".

config PAGE_POISONING
	bool "Poison pages after freeing"
	help
	  Fill the pages with poison patterns after free_pages() and verify
	  the patterns before alloc_pages. The filling of the memory helps
	  reduce the risk of information leaks from freed data. This does
	  have a potential performance impact if enabled with the
	  "page_poison=1" kernel boot option.

	  Note that "poison" here is not the same thing as the "HWPoison"
	  for CONFIG_MEMORY_FAILURE. This is software poisoning only.

	  If you are only interested in sanitization of freed pages without
	  checking the poison pattern on alloc, you can boot the kernel with
	  "init_on_free=1" instead of enabling this.

	  If unsure, say N

config DEBUG_PAGE_REF
	bool "Enable tracepoint to track down page reference manipulation"
	depends on DEBUG_KERNEL
	depends on TRACEPOINTS
	help
	  This is a feature to add tracepoint for tracking down page reference
	  manipulation. This tracking is useful to diagnose functional failure
	  due to migration failures caused by page reference mismatches.  Be
	  careful when enabling this feature because it adds about 30 KB to the
	  kernel code.  However the runtime performance overhead is virtually
	  nil until the tracepoints are actually enabled.

config DEBUG_RODATA_TEST
	bool "Testcase for the marking rodata read-only"
	depends on STRICT_KERNEL_RWX
	help
	  This option enables a testcase for the setting rodata read-only.

config ARCH_HAS_DEBUG_WX
	bool

config DEBUG_WX
	bool "Warn on W+X mappings at boot"
	depends on ARCH_HAS_DEBUG_WX
	depends on ARCH_HAS_PTDUMP
	depends on MMU
	select PTDUMP
	help
	  Generate a warning if any W+X mappings are found at boot.

	  This is useful for discovering cases where the kernel is leaving W+X
	  mappings after applying NX, as such mappings are a security risk.

	  Look for a message in dmesg output like this:

	    <arch>/mm: Checked W+X mappings: passed, no W+X pages found.

	  or like this, if the check failed:

	    <arch>/mm: Checked W+X mappings: failed, <N> W+X pages found.

	  Note that even if the check fails, your kernel is possibly
	  still fine, as W+X mappings are not a security hole in
	  themselves, what they do is that they make the exploitation
	  of other unfixed kernel bugs easier.

	  There is no runtime or memory usage effect of this option
	  once the kernel has booted up - it's a one time check.

	  If in doubt, say "Y".

config ARCH_HAS_PTDUMP
	bool

config PTDUMP
	bool

config PTDUMP_DEBUGFS
	bool "Export kernel pagetable layout to userspace via debugfs"
	depends on DEBUG_KERNEL
	depends on DEBUG_FS
	depends on ARCH_HAS_PTDUMP
	select PTDUMP
	help
	  Say Y here if you want to show the kernel pagetable layout in a
	  debugfs file. This information is only useful for kernel developers
	  who are working in architecture specific areas of the kernel.
	  It is probably not a good idea to enable this feature in a production
	  kernel.

	  If in doubt, say N.

config HAVE_DEBUG_KMEMLEAK
	bool

config DEBUG_KMEMLEAK
	bool "Kernel memory leak detector"
	depends on DEBUG_KERNEL && HAVE_DEBUG_KMEMLEAK
	select DEBUG_FS
	select STACKTRACE if STACKTRACE_SUPPORT
	select KALLSYMS
	select CRC32
	select STACKDEPOT
	select STACKDEPOT_ALWAYS_INIT if !DEBUG_KMEMLEAK_DEFAULT_OFF
	help
	  Say Y here if you want to enable the memory leak
	  detector. The memory allocation/freeing is traced in a way
	  similar to the Boehm's conservative garbage collector, the
	  difference being that the orphan objects are not freed but
	  only shown in /sys/kernel/debug/kmemleak. Enabling this
	  feature will introduce an overhead to memory
	  allocations. See Documentation/dev-tools/kmemleak.rst for more
	  details.

	  Enabling SLUB_DEBUG may increase the chances of finding leaks
	  due to the slab objects poisoning.

	  In order to access the kmemleak file, debugfs needs to be
	  mounted (usually at /sys/kernel/debug).

config DEBUG_KMEMLEAK_MEM_POOL_SIZE
	int "Kmemleak memory pool size"
	depends on DEBUG_KMEMLEAK
	range 200 1000000
	default 16000
	help
	  Kmemleak must track all the memory allocations to avoid
	  reporting false positives. Since memory may be allocated or
	  freed before kmemleak is fully initialised, use a static pool
	  of metadata objects to track such callbacks. After kmemleak is
	  fully initialised, this memory pool acts as an emergency one
	  if slab allocations fail.

config DEBUG_KMEMLEAK_DEFAULT_OFF
	bool "Default kmemleak to off"
	depends on DEBUG_KMEMLEAK
	help
	  Say Y here to disable kmemleak by default. It can then be enabled
	  on the command line via kmemleak=on.

config DEBUG_KMEMLEAK_AUTO_SCAN
	bool "Enable kmemleak auto scan thread on boot up"
	default y
	depends on DEBUG_KMEMLEAK
	help
	  Depending on the cpu, kmemleak scan may be cpu intensive and can
	  stall user tasks at times. This option enables/disables automatic
	  kmemleak scan at boot up.

	  Say N here to disable kmemleak auto scan thread to stop automatic
	  scanning. Disabling this option disables automatic reporting of
	  memory leaks.

	  If unsure, say Y.

config DEBUG_KMEMLEAK_VERBOSE
	bool "Default kmemleak to verbose mode"
	depends on DEBUG_KMEMLEAK_AUTO_SCAN
	help
	  Say Y here to have kmemleak print unreferenced object details
	  (backtrace, hex dump, address) to dmesg when new memory leaks are
	  detected during automatic scanning. This can also be toggled at
	  runtime via /sys/module/kmemleak/parameters/verbose.

	  If unsure, say N.

config PER_VMA_LOCK_STATS
	bool "Statistics for per-vma locks"
	depends on PER_VMA_LOCK
	help
	  Say Y here to enable success, retry and failure counters of page
	  faults handled under protection of per-vma locks. When enabled, the
	  counters are exposed in /proc/vmstat. This information is useful for
	  kernel developers to evaluate effectiveness of per-vma locks and to
	  identify pathological cases. Counting these events introduces a small
	  overhead in the page fault path.

	  If in doubt, say N.
]

12/2 2026/05/24 23:56 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 12645
							output: 47
							thoughts: 100
						

Thoughts:
**Debugging Page Table Checks**

Okay, so I'm looking at this code and it seems to relate to debugging. Specifically, it's about page table checking, which, by default, is disabled. You can switch it on with the `page_table_check=on` kernel parameter, but this config seems to be forcing the checks to *always* be enabled. Interesting.

Now, if `PAGE_TABLE_CHECK` is disabled in a production environment, then the code path that calls `__page_table_check_zero` is either skipped entirely or, perhaps, the function is just a no-op. So, if I really want to understand how this works, I should probably take a look at `include/linux/page_table_check.h`. That's where the definition and relevant logic would reside. Let's see what's in there.



13/2 2026/05/24 23:56 tool codesearch-definition-source
0m Args:
map[ContextFile:include/linux/page_table_check.h IncludeLines:true Name:page_table_check_free]

Results:
map[SourceCode:  41:	static inline void page_table_check_free(struct page *page, unsigned int order)
  42:	{
  43:		if (static_branch_likely(&page_table_check_disabled))
  44:			return;
  45:	
  46:		__page_table_check_zero(page, order);
  47:	}
 SourceFile:include/linux/page_table_check.h]

14/2 2026/05/24 23:56 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 13107
							output: 47
							thoughts: 26
						

Thoughts:
Okay, here's my attempt at summarizing those thoughts from a first-person, expert perspective, focusing on the implied implications:

**Investigating a Conditional Dependency in Page Table Management**

Alright, I'm looking at this code and immediately something jumps out. If `CONFIG_PAGE_TABLE_CHECK` isn't defined, what the hell is `page_table_check_free`? It's a dangling reference, right? It's like asking "where is the missing piece?" and expecting the answer to appear, but it won't be there. This suggests a potential bug, either a build configuration issue or, worse, a subtle logic error where that function *should* be defined in all circumstances, but isn't.

My initial thought is to trace the definition and use of that function. Is it only used in conditional sections, or is it always called under some other, non-obvious circumstances that are being missed? I need to understand the implications of it being *undefined* when this particular configuration option is missing.

Does the build system have a default implementation somewhere, maybe a stub that does nothing? Or is this going to lead to a linker error? More importantly, is there a performance impact if that check is missing, and what are the functional consequences of missing this page table check? Is this a safety check, performance optimization, or both?

I need to dive deeper and see where `page_table_check_free` is used and where its definition is located (or *should* be located). I'm immediately suspicious. Time to grab my debugger and see what's actually happening on the ground.



15/2 2026/05/24 23:56 tool codesearch-definition-source
0m Args:
map[ContextFile:include/linux/page_table_check.h IncludeLines:true Name:page_table_check_free]

Results:
map[SourceCode:  41:	static inline void page_table_check_free(struct page *page, unsigned int order)
  42:	{
  43:		if (static_branch_likely(&page_table_check_disabled))
  44:			return;
  45:	
  46:		__page_table_check_zero(page, order);
  47:	}
 SourceFile:include/linux/page_table_check.h]

16/2 2026/05/24 23:56 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 13651
							output: 26
							thoughts: 22
						

Thoughts:
Here's my thought process, as if I were considering this myself:

**Analyzing the Conditional Compilation Directive**

Okay, first things first, I need the complete context. Seeing just that `#ifdef CONFIG_PAGE_TABLE_CHECK` snippet is useless. I need to get my hands on the whole file immediately. I need to see *where* this conditional compilation directive is used, the surrounding code, and especially how it relates to the other configurations. What is the scope of this condition? Is it checking something specific, or setting something up? What values are associated with CONFIG_PAGE_TABLE_CHECK? Understanding the surrounding code will tell the story.



17/2 2026/05/24 23:56 tool read-file
0m Args:
map[File:include/linux/page_table_check.h]

Results:
map[Contents:/* SPDX-License-Identifier: GPL-2.0 */

/*
 * Copyright (c) 2021, Google LLC.
 * Pasha Tatashin <pasha.tatashin@soleen.com>
 */
#ifndef __LINUX_PAGE_TABLE_CHECK_H
#define __LINUX_PAGE_TABLE_CHECK_H

#ifdef CONFIG_PAGE_TABLE_CHECK
#include <linux/jump_label.h>

extern struct static_key_true page_table_check_disabled;
extern struct page_ext_operations page_table_check_ops;

void __page_table_check_zero(struct page *page, unsigned int order);
void __page_table_check_pte_clear(struct mm_struct *mm, unsigned long addr,
				  pte_t pte);
void __page_table_check_pmd_clear(struct mm_struct *mm, unsigned long addr,
				  pmd_t pmd);
void __page_table_check_pud_clear(struct mm_struct *mm, unsigned long addr,
				  pud_t pud);
void __page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr,
		pte_t *ptep, pte_t pte, unsigned int nr);
void __page_table_check_pmds_set(struct mm_struct *mm, unsigned long addr,
		pmd_t *pmdp, pmd_t pmd, unsigned int nr);
void __page_table_check_puds_set(struct mm_struct *mm, unsigned long addr,
		pud_t *pudp, pud_t pud, unsigned int nr);
void __page_table_check_pte_clear_range(struct mm_struct *mm,
					unsigned long addr,
					pmd_t pmd);

static inline void page_table_check_alloc(struct page *page, unsigned int order)
{
	if (static_branch_likely(&page_table_check_disabled))
		return;

	__page_table_check_zero(page, order);
}

static inline void page_table_check_free(struct page *page, unsigned int order)
{
	if (static_branch_likely(&page_table_check_disabled))
		return;

	__page_table_check_zero(page, order);
}

static inline void page_table_check_pte_clear(struct mm_struct *mm,
					      unsigned long addr, pte_t pte)
{
	if (static_branch_likely(&page_table_check_disabled))
		return;

	__page_table_check_pte_clear(mm, addr, pte);
}

static inline void page_table_check_pmd_clear(struct mm_struct *mm,
					      unsigned long addr, pmd_t pmd)
{
	if (static_branch_likely(&page_table_check_disabled))
		return;

	__page_table_check_pmd_clear(mm, addr, pmd);
}

static inline void page_table_check_pud_clear(struct mm_struct *mm,
					      unsigned long addr, pud_t pud)
{
	if (static_branch_likely(&page_table_check_disabled))
		return;

	__page_table_check_pud_clear(mm, addr, pud);
}

static inline void page_table_check_ptes_set(struct mm_struct *mm,
					     unsigned long addr, pte_t *ptep,
					     pte_t pte, unsigned int nr)
{
	if (static_branch_likely(&page_table_check_disabled))
		return;

	__page_table_check_ptes_set(mm, addr, ptep, pte, nr);
}

static inline void page_table_check_pmds_set(struct mm_struct *mm,
		unsigned long addr, pmd_t *pmdp, pmd_t pmd, unsigned int nr)
{
	if (static_branch_likely(&page_table_check_disabled))
		return;

	__page_table_check_pmds_set(mm, addr, pmdp, pmd, nr);
}

static inline void page_table_check_puds_set(struct mm_struct *mm,
		unsigned long addr, pud_t *pudp, pud_t pud, unsigned int nr)
{
	if (static_branch_likely(&page_table_check_disabled))
		return;

	__page_table_check_puds_set(mm, addr, pudp, pud, nr);
}

static inline void page_table_check_pte_clear_range(struct mm_struct *mm,
						    unsigned long addr,
						    pmd_t pmd)
{
	if (static_branch_likely(&page_table_check_disabled))
		return;

	__page_table_check_pte_clear_range(mm, addr, pmd);
}

#else

static inline void page_table_check_alloc(struct page *page, unsigned int order)
{
}

static inline void page_table_check_free(struct page *page, unsigned int order)
{
}

static inline void page_table_check_pte_clear(struct mm_struct *mm,
					      unsigned long addr, pte_t pte)
{
}

static inline void page_table_check_pmd_clear(struct mm_struct *mm,
					      unsigned long addr, pmd_t pmd)
{
}

static inline void page_table_check_pud_clear(struct mm_struct *mm,
					      unsigned long addr, pud_t pud)
{
}

static inline void page_table_check_ptes_set(struct mm_struct *mm,
					     unsigned long addr, pte_t *ptep,
					     pte_t pte, unsigned int nr)
{
}

static inline void page_table_check_pmds_set(struct mm_struct *mm,
		unsigned long addr, pmd_t *pmdp, pmd_t pmd, unsigned int nr)
{
}

static inline void page_table_check_puds_set(struct mm_struct *mm,
		unsigned long addr, pud_t *pudp, pud_t pud, unsigned int nr)
{
}

static inline void page_table_check_pte_clear_range(struct mm_struct *mm,
						    unsigned long addr,
						    pmd_t pmd)
{
}

#endif /* CONFIG_PAGE_TABLE_CHECK */

#define page_table_check_pmd_set(mm, addr, pmdp, pmd)	page_table_check_pmds_set(mm, addr, pmdp, pmd, 1)
#define page_table_check_pud_set(mm, addr, pudp, pud)	page_table_check_puds_set(mm, addr, pudp, pud, 1)

#endif /* __LINUX_PAGE_TABLE_CHECK_H */
]

18/2 2026/05/24 23:56 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 15519
							output: 48
							thoughts: 350
						

Thoughts:
**Analyzing a Suspected Page Table Corruption**

Okay, so I'm looking at this code and if `CONFIG_PAGE_TABLE_CHECK` isn't set, then `page_table_check_free` just does nothing. That narrows the scope of the potential issue significantly, which means this problem *only* occurs when that check is enabled. Now, the real question is, is this a false positive from `PAGE_TABLE_CHECK` itself, or is there a genuine bug where a page is being freed while still mapped? If it's the latter, this is a critical use-after-free or double-free vulnerability, which demands immediate attention.

Let's do a quick search. Are there any existing bugs reported that seem related? I'll need to dig through some resources to see if this has come up before.

The stack trace gives me a better picture: `__page_table_check_zero`, `page_table_check_free`, `__free_pages_prepare`, and then it goes through `free_unref_folios`, `folios_put_refs`, to `free_pages_and_swap_cache`, and then finally `__tlb_batch_free_encoded_pages`, which leads to the TLB flush functions before finally ending up in `exit_mmap`, `__mmput`, `mmput`, and `exit_mm`, all the way to `do_exit`.

Ah, this is happening during process exit, specifically during `exit_mmap`. So, `exit_mmap` is unmapping everything and then freeing the page tables. Right, that makes sense. It's when memory is released. And hang on, `free_pages_and_swap_cache` is called from `tlb_batch_pages_flush`! That could be a critical clue. Okay, let's take a closer look at `__tlb_batch_free_encoded_pages` and see what it is doing.



19/2 2026/05/24 23:56 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/mmu_gather.c IncludeLines:true Name:__tlb_batch_free_encoded_pages]

Results:
map[SourceCode: 103:	static void __tlb_batch_free_encoded_pages(struct mmu_gather_batch *batch)
 104:	{
 105:		struct encoded_page **pages = batch->encoded_pages;
 106:		unsigned int nr, nr_pages;
 107:	
 108:		while (batch->nr) {
 109:			if (!page_poisoning_enabled_static() && !want_init_on_free()) {
 110:				nr = min(MAX_NR_FOLIOS_PER_FREE, batch->nr);
 111:	
 112:				/*
 113:				 * Make sure we cover page + nr_pages, and don't leave
 114:				 * nr_pages behind when capping the number of entries.
 115:				 */
 116:				if (unlikely(encoded_page_flags(pages[nr - 1]) &
 117:					     ENCODED_PAGE_BIT_NR_PAGES_NEXT))
 118:					nr++;
 119:			} else {
 120:				/*
 121:				 * With page poisoning and init_on_free, the time it
 122:				 * takes to free memory grows proportionally with the
 123:				 * actual memory size. Therefore, limit based on the
 124:				 * actual memory size and not the number of involved
 125:				 * folios.
 126:				 */
 127:				for (nr = 0, nr_pages = 0;
 128:				     nr < batch->nr && nr_pages < MAX_NR_FOLIOS_PER_FREE;
 129:				     nr++) {
 130:					if (unlikely(encoded_page_flags(pages[nr]) &
 131:						     ENCODED_PAGE_BIT_NR_PAGES_NEXT))
 132:						nr_pages += encoded_nr_pages(pages[++nr]);
 133:					else
 134:						nr_pages++;
 135:				}
 136:			}
 137:	
 138:			free_pages_and_swap_cache(pages, nr);
 139:			pages += nr;
 140:			batch->nr -= nr;
 141:	
 142:			cond_resched();
 143:		}
 144:	}
 SourceFile:mm/mmu_gather.c]

20/2 2026/05/24 23:56 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 17002
							output: 45
							thoughts: 20
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience, and presented as if it were my own internal monologue:

**Analyzing the `free_pages_and_swap_cache` Function**

Alright, let's break this down. When I see `free_pages_and_swap_cache` taking an array of `encoded_page`, a few things immediately jump to mind. First, the function's name itself is pretty explicit: it's designed to release memory associated with pages. The "and swap cache" part is critical because it tells me this isn't just a simple page freeing operation. It's tied into the virtual memory subsystem. We're dealing with pages that might have a presence in the swap space, not just physical RAM.

The use of an *array* of `encoded_page` is also telling. This suggests a batch operation. It's likely optimized to handle multiple pages simultaneously for efficiency. This screams "parallelism" and "locking considerations" to me; we have to be *very* careful about concurrent access if multiple tasks could be calling this. What specific locking mechanisms does it use and how they work would be the first thing I would check.

The `encoded_page` structure is the central point. I need to understand what that entails in the kernel's memory management scheme. Is it a generic wrapper around a physical page, or does it hold metadata specific to the swap cache? Does it involve flags for page states (dirty, clean, present in swap, etc.)? Are there pointers to other relevant data structures like the page table entries or the swap entry? The encoding part suggests there's some kind of abstraction or internal representation. The exact details are crucial for understanding how the system tracks and manages these pages. I need to check the definition, to get a clear picture.

The function is most likely part of the page reclaim logic, possibly handling pages evicted from memory that were previously written to swap. This also makes me consider the surrounding code and the situations in which this function would be called: during memory pressure, process termination, file system flush operations. A good understanding of those contexts will clarify the function's role.

Finally, the question I need to ask is about error handling and resource cleanup. What are the checks it performs? Does it handle potential errors during swap operations gracefully? Does it protect against double-free situations or memory leaks? The implications of an improperly handled page release are severe, so it's a good place to double-check error handling.



21/2 2026/05/24 23:56 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/swap_state.c IncludeLines:true Name:free_pages_and_swap_cache]

Results:
map[SourceCode: 381:	/*
 382:	 * Passed an array of pages, drop them all from swapcache and then release
 383:	 * them.  They are removed from the LRU and freed if this is their last use.
 384:	 */
 385:	void free_pages_and_swap_cache(struct encoded_page **pages, int nr)
 386:	{
 387:		struct folio_batch folios;
 388:		unsigned int refs[FOLIO_BATCH_SIZE];
 389:	
 390:		folio_batch_init(&folios);
 391:		for (int i = 0; i < nr; i++) {
 392:			struct folio *folio = page_folio(encoded_page_ptr(pages[i]));
 393:	
 394:			free_swap_cache(folio);
 395:			refs[folios.nr] = 1;
 396:			if (unlikely(encoded_page_flags(pages[i]) &
 397:				     ENCODED_PAGE_BIT_NR_PAGES_NEXT))
 398:				refs[folios.nr] = encoded_nr_pages(pages[++i]);
 399:	
 400:			if (folio_batch_add(&folios, folio) == 0)
 401:				folios_put_refs(&folios, refs);
 402:		}
 403:		if (folios.nr)
 404:			folios_put_refs(&folios, refs);
 405:	}
 SourceFile:mm/swap_state.c]

22/2 2026/05/24 23:56 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 18032
							output: 30
							thoughts: 295
						

Thoughts:
**Debugging a Page-Freeing Anomaly**

Okay, so I've got this bug where a page is getting freed, but the `anon_map_count` or `file_map_count` isn't zero. This is a classic, but the question is where it stems from. Could be a problem within `page_table_check` itself, or a deeper, more troubling issue where a page is actually getting freed while still mapped. If it *is* a real bug, then we're looking at a scenario where either the unmapping process isn't updating `page_table_check` correctly, or the page is somehow still mapped *somewhere* else and the reference count dipped to zero.

Wait a second, the `page_table_check` counters are supposed to be updated whenever PTEs are set or cleared. So, if a page is truly freed, its refcount *must* be zero. Conversely, if it's still mapped, the refcount should be greater than zero. Thus, if the refcount is zero, but `page_table_check` thinks it’s mapped, we have two possibilities:

1.  The page was correctly unmapped, but `page_table_check` counters weren't decremented properly. That’s a bug in the checker itself, or a missing hook somewhere.
2.  The page is *actually* still mapped, but its refcount was erroneously decremented to zero. That would be a use-after-free, and that's *bad*.

Alright, time to get digging. I need to start looking at recent commits. Let's start with a search for anything related to `page_table_check`, `free_pages_and_swap_cache`, or `tlb_batch_pages_flush`. Hopefully, something recent might shed light on this discrepancy or fix the underlying issue.



23/2 2026/05/24 23:57 tool git-log
10m Error:
git log timed out. Please specify a tighter search scope (e.g. by providing a PathPrefix).

Args:
map[CodeRegexp:__page_table_check_zero Count:10]

Results:
map[Output:]

24/2 2026/05/25 00:07 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 18792
							output: 30
							thoughts: 18
						

Thoughts:
Okay, here's my attempt at summarizing those thoughts from a first-person, expert perspective:

**Diving into `mm/page_table_check.c` Commits**

Right, let's get down to brass tacks. I need to zero in on some recent activity surrounding `mm/page_table_check.c`. This suggests a specific area of interest: likely memory management or, more specifically, page table validation and debugging within the kernel. I'm probably looking for commits related to bug fixes, performance improvements, new features within that subsystem, or maybe even refactoring efforts. Knowing the specific context, I might have a hunch about what I'm looking for - perhaps a recent issue I've been tracking, or some optimization ideas I'm thinking about. The search will likely involve using `git log` or a similar tool to pinpoint commits touching that particular file. I'll need to use some strategic filtering to refine the results. Things like date ranges, author keywords, or commit message content would be essential to sift through the noise and quickly zero in on the relevant changes. Let's see what we can find.



25/2 2026/05/25 00:07 tool git-log
0m Args:
map[Count:20 PathPrefix:mm/page_table_check.c]

Results:
map[Output:cf8771ca4cdb mm/page_table_check: Pass mm_struct to pxx_user_accessible_page()
d79f9c9cf703 mm: provide address parameter to p{te,md,ud}_user_accessible_page()
d7b4b67eb6b3 mm/page_table_check: reinstate address parameter in [__]page_table_check_pte_clear()
649ec9e3d03c mm/page_table_check: reinstate address parameter in [__]page_table_check_pmd_clear()
2e6ac078ce5d mm/page_table_check: reinstate address parameter in [__]page_table_check_pud_clear()
0a5ae4483177 mm/page_table_check: provide addr parameter to page_table_check_ptes_set()
6e2d8f9fc4ed mm/page_table_check: reinstate address parameter in [__]page_table_check_pmd[s]_set()
c4a0c5ff85b7 mm/page_table_check: reinstate address parameter in [__]page_table_check_pud[s]_set()
0ac881efe164 mm: replace pmd_to_swp_entry() with softleaf_from_pmd()
aa62204cb680 mm: avoid unnecessary use of is_swap_pmd()
fb888710e26a mm: avoid unnecessary uses of is_swap_pte()
91e40668e70a mm/page_table_check: Batch-check pmds/puds just like ptes
4e30b94cdad6 mm: page_table_check: use new iteration API
c25465eb7630 mm: use single SWP_DEVICE_EXCLUSIVE entry type
8bb592c2eca8 mm/page_table_check: fix crash on ZONE_DEVICE
8430557fc584 mm/page_table_check: support userfault wr-protect entries
a379322022c0 mm: convert page_table_check_pte_set() to page_table_check_ptes_set()
d981e2804c92 mm/page_ext: use page_ext_data helper in page_table_check
6d144436d954 mm/page_table_check: remove unused parameter in [__]page_table_check_pud_set
a3b837130b58 mm/page_table_check: remove unused parameter in [__]page_table_check_pmd_set
]

26/2 2026/05/25 00:07 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 19740
							output: 31
							thoughts: 22
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Investigating `page_table_check_zero` Bug Fixes**

Alright, let's dive into this. My initial thought is to quickly ascertain the commit history for `page_table_check_zero`. Specifically, I want to check if any recent commits address a bug. This implies a possible regression or a previously known, but recently addressed, issue in the page table zeroing process. I'm implicitly assuming that the code in question is likely part of either memory management or virtual memory handling – so, if there's an issue there, it's pretty critical. Finding the relevant commits is the first step in understanding the context. Perhaps there was a race condition, a subtle off-by-one error, or maybe an interaction with a different part of the kernel that wasn't properly accounted for initially. I need to understand the fix's rationale and if it impacts any other areas I'm familiar with in the architecture. This search is the starting point for a deeper dive.



27/2 2026/05/25 00:07 tool git-log
0m Args:
map[Count:20 MessageRegexps:[page_table_check fix]]

Results:
map[Output:29f40594a281 mm/rmap: fix incorrect pte restoration for lazyfree folios
cd7a5651db26 alpha: add missing address argument in call to page_table_check_pte_clear()
641d47d4c963 powerpc/mm: support page table check
d7b4b67eb6b3 mm/page_table_check: reinstate address parameter in [__]page_table_check_pte_clear()
4e30b94cdad6 mm: page_table_check: use new iteration API
9039b9096ea2 mm: page_ext: add an iteration API for page extensions
8977752c8056 mm/gup: reject FOLL_SPLIT_PMD with hugetlb VMAs
0cef0bb836e3 mm: clear uffd-wp PTE/PMD state on mremap()
0b1ef4fde7a2 mm/debug_vm_pgtable: drop RANDOM_ORVALUE trick
8bb592c2eca8 mm/page_table_check: fix crash on ZONE_DEVICE
c88033efe9a3 mm/userfaultfd: reset ptes when close() for wr-protected ones
00de2c9f26b1 arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()
3ce2c24cb68f mm: hugetlb_vmemmap: fix a race between vmemmap pmd split
44d0fb387b53 mm: page_table_check: Ensure user pages are not slab pages
0143d148d1e8 usb: usbfs: Enforce page requirements for mmap
6189eb82f0ae mm/page_ext: do not allocate space for page_ext->flags if not needed
730a11f982e6 arm64/mm: add pud_user_exec() check in pud_user_accessible_page()
74c2f8105451 arm64/mm: fix incorrect file_map_count for invalid pmd
5b47348fc0b1 arm64/mm: fix incorrect file_map_count for non-leaf pmd/pud
3ae6d3e30a52 mm/page_table_check: fix typos
]

28/2 2026/05/25 00:07 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 20605
							output: 27
							thoughts: 34
						

Thoughts:
Here's a summary of my thought process, as requested:

**Diving into Commit 29f40594a281: mm/rmap fix**

Alright, let's take a look at commit `29f40594a281`. The title immediately grabs my attention: "mm/rmap: fix incorrect pte restoration for lazyfree folios." I'm already anticipating some interesting details related to the intricacies of the memory management subsystem, specifically around the rmap and how it interacts with lazyfree folios. The "incorrect PTE restoration" part suggests a potential bug impacting the integrity of page table entries. Given my understanding of these areas, I'm expecting this to deal with how page table entries are handled during the recovery or re-establishment of mappings related to lazyfree folios. I'm keen to see if this involves any race conditions or subtle edge cases within the reclaim process. My hunch is this commit will likely be fixing a potential memory corruption issue when attempting to re-establish the correct page table mappings after a lazyfree folio has been processed. Let's dig in and see what the specifics are!



29/2 2026/05/25 00:07 tool git-show
0m Args:
map[Commit:29f40594a281]

Results:
map[Output:commit 29f40594a28114b9a9bc87f6cf7bbee9609628f2
Author: Dev Jain <dev.jain@arm.com>
Date:   Tue Mar 3 11:45:28 2026 +0530

    mm/rmap: fix incorrect pte restoration for lazyfree folios
    
    We batch unmap anonymous lazyfree folios by folio_unmap_pte_batch.  If the
    batch has a mix of writable and non-writable bits, we may end up setting
    the entire batch writable.  Fix this by respecting writable bit during
    batching.
    
    Although on a successful unmap of a lazyfree folio, the soft-dirty bit is
    lost, preserve it on pte restoration by respecting the bit during
    batching, to make the fix consistent w.r.t both writable bit and
    soft-dirty bit.
    
    I was able to write the below reproducer and crash the kernel.
    Explanation of reproducer (set 64K mTHP to always):
    
    Fault in a 64K large folio.  Split the VMA at mid-point with
    MADV_DONTFORK.  fork() - parent points to the folio with 8 writable ptes
    and 8 non-writable ptes.  Merge the VMAs with MADV_DOFORK so that
    folio_unmap_pte_batch() can determine all the 16 ptes as a batch.  Do
    MADV_FREE on the range to mark the folio as lazyfree.  Write to the memory
    to dirty the pte, eventually rmap will dirty the folio.  Then trigger
    reclaim, we will hit the pte restoration path, and the kernel will crash
    with the trace given below.
    
    The BUG happens at:
    
            BUG_ON(atomic_inc_return(&ptc->anon_map_count) > 1 && rw);
    
    The code path is asking for anonymous page to be mapped writable into the
    pagetable.  The BUG_ON() firing implies that such a writable page has been
    mapped into the pagetables of more than one process, which breaks
    anonymous memory/CoW semantics.
    
    [   21.134473] kernel BUG at mm/page_table_check.c:118!
    [   21.134497] Internal error: Oops - BUG: 00000000f2000800 [#1]  SMP
    [   21.135917] Modules linked in:
    [   21.136085] CPU: 1 UID: 0 PID: 1735 Comm: dup-lazyfree Not tainted 7.0.0-rc1-00116-g018018a17770 #1028 PREEMPT
    [   21.136858] Hardware name: linux,dummy-virt (DT)
    [   21.137019] pstate: 21400005 (nzCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
    [   21.137308] pc : page_table_check_set+0x28c/0x2a8
    [   21.137607] lr : page_table_check_set+0x134/0x2a8
    [   21.137885] sp : ffff80008a3b3340
    [   21.138124] x29: ffff80008a3b3340 x28: fffffdffc3d14400 x27: ffffd1a55e03d000
    [   21.138623] x26: 0040000000000040 x25: ffffd1a55f7dd000 x24: 0000000000000001
    [   21.139045] x23: 0000000000000001 x22: 0000000000000001 x21: ffffd1a55f217f30
    [   21.139629] x20: 0000000000134521 x19: 0000000000134519 x18: 005c43e000040000
    [   21.140027] x17: 0001400000000000 x16: 0001700000000000 x15: 000000000000ffff
    [   21.140578] x14: 000000000000000c x13: 005c006000000000 x12: 0000000000000020
    [   21.140828] x11: 0000000000000000 x10: 005c000000000000 x9 : ffffd1a55c079ee0
    [   21.141077] x8 : 0000000000000001 x7 : 005c03e000040000 x6 : 000000004000ffff
    [   21.141490] x5 : ffff00017fffce00 x4 : 0000000000000001 x3 : 0000000000000002
    [   21.141741] x2 : 0000000000134510 x1 : 0000000000000000 x0 : ffff0000c08228c0
    [   21.141991] Call trace:
    [   21.142093]  page_table_check_set+0x28c/0x2a8 (P)
    [   21.142265]  __page_table_check_ptes_set+0x144/0x1e8
    [   21.142441]  __set_ptes_anysz.constprop.0+0x160/0x1a8
    [   21.142766]  contpte_set_ptes+0xe8/0x140
    [   21.142907]  try_to_unmap_one+0x10c4/0x10d0
    [   21.143177]  rmap_walk_anon+0x100/0x250
    [   21.143315]  try_to_unmap+0xa0/0xc8
    [   21.143441]  shrink_folio_list+0x59c/0x18a8
    [   21.143759]  shrink_lruvec+0x664/0xbf0
    [   21.144043]  shrink_node+0x218/0x878
    [   21.144285]  __node_reclaim.constprop.0+0x98/0x338
    [   21.144763]  user_proactive_reclaim+0x2a4/0x340
    [   21.145056]  reclaim_store+0x3c/0x60
    [   21.145216]  dev_attr_store+0x20/0x40
    [   21.145585]  sysfs_kf_write+0x84/0xa8
    [   21.145835]  kernfs_fop_write_iter+0x130/0x1c8
    [   21.145994]  vfs_write+0x2b8/0x368
    [   21.146119]  ksys_write+0x70/0x110
    [   21.146240]  __arm64_sys_write+0x24/0x38
    [   21.146380]  invoke_syscall+0x50/0x120
    [   21.146513]  el0_svc_common.constprop.0+0x48/0xf8
    [   21.146679]  do_el0_svc+0x28/0x40
    [   21.146798]  el0_svc+0x34/0x110
    [   21.146926]  el0t_64_sync_handler+0xa0/0xe8
    [   21.147074]  el0t_64_sync+0x198/0x1a0
    [   21.147225] Code: f9400441 b4fff241 17ffff94 d4210000 (d4210000)
    [   21.147440] ---[ end trace 0000000000000000 ]---
    
    #define _GNU_SOURCE
    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <sys/mman.h>
    #include <string.h>
    #include <sys/wait.h>
    #include <sched.h>
    #include <fcntl.h>
    
    void write_to_reclaim() {
        const char *path = "/sys/devices/system/node/node0/reclaim";
        const char *value = "409600000000";
        int fd = open(path, O_WRONLY);
        if (fd == -1) {
            perror("open");
            exit(EXIT_FAILURE);
        }
    
        if (write(fd, value, sizeof("409600000000") - 1) == -1) {
            perror("write");
            close(fd);
            exit(EXIT_FAILURE);
        }
    
        printf("Successfully wrote %s to %s\n", value, path);
        close(fd);
    }
    
    int main()
    {
            char *ptr = mmap((void *)(1UL << 30), 1UL << 16, PROT_READ | PROT_WRITE,
                             MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
            if ((unsigned long)ptr != (1UL << 30)) {
                    perror("mmap");
                    return 1;
            }
    
            /* a 64K folio gets faulted in */
            memset(ptr, 0, 1UL << 16);
    
            /* 32K half will not be shared into child */
            if (madvise(ptr, 1UL << 15, MADV_DONTFORK)) {
                    perror("madvise madv dontfork");
                    return 1;
            }
    
            pid_t pid = fork();
    
            if (pid < 0) {
                    perror("fork");
                    return 1;
            } else if (pid == 0) {
                    sleep(15);
            } else {
                    /* merge VMAs. now first half of the 16 ptes are writable, the other half not. */
                    if (madvise(ptr, 1UL << 15, MADV_DOFORK)) {
                            perror("madvise madv fork");
                            return 1;
                    }
                    if (madvise(ptr, (1UL << 16), MADV_FREE)) {
                            perror("madvise madv free");
                            return 1;
                    }
    
                    /* dirty the large folio */
                    (*ptr) += 10;
    
                    write_to_reclaim();
                    // sleep(10);
                    waitpid(pid, NULL, 0);
    
            }
    }
    
    Link: https://lkml.kernel.org/r/20260303061528.2429162-1-dev.jain@arm.com
    Fixes: 354dffd29575 ("mm: support batched unmap for lazyfree large folios during reclamation")
    Signed-off-by: Dev Jain <dev.jain@arm.com>
    Acked-by: David Hildenbrand (Arm) <david@kernel.org>
    Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
    Reviewed-by: Barry Song <baohua@kernel.org>
    Reviewed-by: Wei Yang <richard.weiyang@gmail.com>
    Tested-by: Lance Yang <lance.yang@linux.dev>
    Cc: Anshuman Khandual <anshuman.khandual@arm.com>
    Cc: Harry Yoo <harry.yoo@oracle.com>
    Cc: Jann Horn <jannh@google.com>
    Cc: Liam Howlett <liam.howlett@oracle.com>
    Cc: Rik van Riel <riel@surriel.com>
    Cc: Ryan Roberts <ryan.roberts@arm.com>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

diff --git a/mm/rmap.c b/mm/rmap.c
index 0f00570d1b9e..b1ba1236ffba 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1955,7 +1955,14 @@ static inline unsigned int folio_unmap_pte_batch(struct folio *folio,
 	if (userfaultfd_wp(vma))
 		return 1;
 
-	return folio_pte_batch(folio, pvmw->pte, pte, max_nr);
+	/*
+	 * If unmap fails, we need to restore the ptes. To avoid accidentally
+	 * upgrading write permissions for ptes that were not originally
+	 * writable, and to avoid losing the soft-dirty bit, use the
+	 * appropriate FPB flags.
+	 */
+	return folio_pte_batch_flags(folio, vma, pvmw->pte, &pte, max_nr,
+				     FPB_RESPECT_WRITE | FPB_RESPECT_SOFT_DIRTY);
 }
 
 /*
]

30/2 2026/05/25 00:07 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 24779
							output: 38
							thoughts: 292
						

Thoughts:
**Analyzing a Memory Management Bug**

Okay, so I've been presented with a commit that supposedly fixes a `folio_unmap_pte_batch` issue related to the writable bit. But hold on, the bug report I'm looking at, this one with the `kernel BUG at [] mm/page_table_check.c:142!` error in `__page_table_check_zero`, doesn't quite match. The referenced commit's bug seems to be at `mm/page_table_check.c:118` in `page_table_check_set`. My issue is deeper, at line 142 in `__page_table_check_zero`, so these are different.

Let me circle back to `__page_table_check_zero`. The crash I'm seeing arises when `atomic_read(&ptc->anon_map_count)` or `atomic_read(&ptc->file_map_count)` are *not* zero. This strongly suggests that a page is being prematurely freed while the `page_table_check` mechanism believes it's still mapped. Now, the crucial question: Is this a false positive in the check itself, or a real indication of a page being freed while still actively mapped? A real bug, of course, would mean a memory corruption issue that needs to be fixed. Time to dig through the commit history and see what I can find related to `__page_table_check_zero`.



31/2 2026/05/25 00:07 tool git-log
0m Args:
map[CodeRegexp:__page_table_check_zero Count:20 PathPrefix:mm/]

Results:
map[Output:df4e817b7108 mm: page table check
]

32/2 2026/05/25 00:08 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 25456
							output: 37
							thoughts: 16
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:

**Navigating the Memory Management Labyrinth**

Alright, so the task at hand seems to involve memory management, specifically concerning page tables and their freeing process. The phrase `page_table_check_free` immediately signals that we're dealing with a routine designed to verify the proper deallocation of page table entries. Given the potential for subtle, hard-to-debug memory corruption issues that often arise in this area, I need to understand the surrounding context.

My initial approach, naturally, is to dive straight into the code. The immediate question in my mind is: what commits specifically touch this function? Examining commit history is a highly effective way to gain insight into the evolution, bug fixes, and intended usage of a function. By filtering for commits that include `page_table_check_free`, I'm hoping to quickly identify relevant changes. I expect to find information on why this check was introduced, any known issues it addresses, and perhaps even some usage examples or best practices. This will serve as a foundational understanding to guide my further investigation.



33/2 2026/05/25 00:08 tool git-log
0m Args:
map[CodeRegexp:page_table_check_free Count:20 PathPrefix:mm/]

Results:
map[Output:df4e817b7108 mm: page table check
]

34/2 2026/05/25 00:08 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 25781
							output: 31
							thoughts: 18
						

Thoughts:
Okay, here's my interpretation of those thoughts, crafted with the expectation that I'm discussing this with a fellow expert:

**Investigating Memory Management Bugs: A Targeted Approach**

Right, let's zero in on a potential memory management issue. My immediate thought is to use a focused search strategy to pinpoint the problematic code. I'm thinking, let's hunt for commits that explicitly mention both `page_table_check` and `free`. The rationale is straightforward: `page_table_check` suggests we're dealing with the intricate world of page tables, and `free` is a direct indicator of memory deallocation. Combining these terms is a good bet to quickly identify commits where modifications related to page table integrity interact with memory freeing operations. This filtering strategy should narrow the search significantly, hopefully bringing the relevant commits to the forefront. I'm hoping this will lead me right to the heart of the bug or potential vulnerability. Let's see what we find.



35/2 2026/05/25 00:08 tool git-log
0m Args:
map[Count:20 MessageRegexps:[page_table_check free]]

Results:
map[Output:29f40594a281 mm/rmap: fix incorrect pte restoration for lazyfree folios
8977752c8056 mm/gup: reject FOLL_SPLIT_PMD with hugetlb VMAs
0143d148d1e8 usb: usbfs: Enforce page requirements for mmap
80110bbfbba6 mm/page_table_check: check entries at pmd levels
fb5222aae64f mm/debug_vm_pgtable: remove pte entry from the page table
]

36/2 2026/05/25 00:09 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 26184
							output: 30
							thoughts: 25
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Analyzing Relevant Kernel Commits**

Alright, let's dive in. My immediate thought is to zero in on commits related to two key areas: the Translation Lookaside Buffer (TLB) flush operations, specifically `tlb_batch_pages_flush`, and anything touching `page_table_check`. Given my experience, I'm expecting this will likely point me toward potential performance bottlenecks or subtle correctness issues, especially if these functions are interacting or even racing with each other. I'm imagining a scenario where either the batch flushing or the page table validation isn't perfectly synchronized, potentially leading to stale TLB entries or missed errors. Depending on how these functions are used, it could expose cache coherency concerns or even issues during page table manipulations during memory management operations. My goal here is to establish the context around their interactions, any design decisions, and discover the specific reasons these functions need to be called together. I'm going to start with a broad net, then tighten it up based on what I see.



37/2 2026/05/25 00:09 tool git-log
0m Args:
map[Count:20 MessageRegexps:[tlb_batch_pages_flush]]

Results:
map[Output:7cd1f5f77925 LoongArch: Add architecture specific huge_pte_clear()
66edc3a5894c mm: page_alloc: move mlocked flag clearance into free_pages_prepare()
818f916e3a07 mm: swap: prevent possible data-race in __try_to_reclaim_swap
237f3cf13b20 xsk: validate user input for XDP_{UMEM|COMPLETION}_FILL_RING
661779e1fcaf netlink: Fix kernel-infoleak-after-free in __skb_datagram_iter
e61abd449068 mm/mmu_gather: improve cond_resched() handling with large folios and expensive page freeing
d7f861b9c43a mm/mmu_gather: add __tlb_remove_folio_pages()
5a08d0065a91 ipv6: add debug checks in fib6_info_release()
b2f557a21bc8 mm/madvise: add cond_resched() in madvise_cold_or_pageout_pte_range()
ca71fe1ad922 mm, pcp: avoid to drain PCP when process exit
804ca14d04df iommufd: Do not access the area pointer after unlocking
228ebc41dfab net: do not sense pfmemalloc status in skb_append_pagefrags()
b191c9bc334a mm/mmu_gather: limit free batch count and add schedule point in tlb_batch_pages_flush
04c2a47ffb13 net: sched: fix use-after-free in tc_new_tfilter()
f1796544a0ca memcg: fix use-after-free in uncharge_batch
]

38/2 2026/05/25 00:09 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 26929
							output: 33
							thoughts: 20
						

Thoughts:
Okay, here's my summary, presented as a stream of thought:

**Diving into the Kernel's Memory Management**

Alright, I need to investigate something related to `__tlb_batch_free_encoded_pages`. Given my background, I recognize that function name as likely being tied to Translation Lookaside Buffer (TLB) management and potentially batch freeing of pages, particularly encoded or compressed pages, within the kernel. My initial thought is to zero in on commits that specifically reference this function. This will provide valuable context. I'm thinking I need to find the specific instances of `__tlb_batch_free_encoded_pages` to understand its use, modifications, and any related bugs or optimizations. This search will be the foundation for my further investigation.



39/2 2026/05/25 00:09 tool git-log
0m Args:
map[Count:20 MessageRegexps:[__tlb_batch_free_encoded_pages]]

Results:
map[Output:66edc3a5894c mm: page_alloc: move mlocked flag clearance into free_pages_prepare()
818f916e3a07 mm: swap: prevent possible data-race in __try_to_reclaim_swap
]

40/2 2026/05/25 00:09 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 27219
							output: 31
							thoughts: 18
						

Thoughts:
Okay, here's my attempt at summarizing that thought process, tailored for an expert audience:

**Investigating Memory Management in the Kernel**

Alright, time to dig into this memory issue. I need to get a handle on the interaction between free pages and the swap cache. My immediate thought is to start with a targeted search. I'll focus on commit messages. They're usually a good source for understanding the rationale behind changes, and the commit message is the first, and sometimes only, documentation of why this code even exists. Specifically, I'm going to look for any commits that explicitly mention `free_pages_and_swap_cache`. That function name is pretty specific, so it should narrow down the results considerably. This should quickly give me a sense of how that function is being used, what kinds of problems it's associated with, and what improvements or fixes have been implemented in the past. Hopefully, I can glean enough context to form an hypothesis. Then, I can start looking at the code directly.



41/2 2026/05/25 00:10 tool git-log
0m Args:
map[Count:20 MessageRegexps:[free_pages_and_swap_cache]]

Results:
map[Output:00c14a09a70e hfs/hfsplus: prevent getting negative values of offset/length
7cd1f5f77925 LoongArch: Add architecture specific huge_pte_clear()
66edc3a5894c mm: page_alloc: move mlocked flag clearance into free_pages_prepare()
818f916e3a07 mm: swap: prevent possible data-race in __try_to_reclaim_swap
4907e80b76af mm: convert free_pages_and_swap_cache() to use folios_put()
661779e1fcaf netlink: Fix kernel-infoleak-after-free in __skb_datagram_iter
b2f557a21bc8 mm/madvise: add cond_resched() in madvise_cold_or_pageout_pte_range()
228ebc41dfab net: do not sense pfmemalloc status in skb_append_pagefrags()
2a57d83c78f8 mm/hwpoison: clear MF_COUNT_INCREASED before retrying get_any_page()
7d9a935e169b RDMA/restrack: Don't rely on uninitialized variable in restrack_add flow
770a5370226c mm: thp: broken page count after commit aa88b68c3b1d
95813b8faa0c mm/page_ref: add tracepoint to track down page reference manipulation
721c21c17ab9 mm: mmu_gather: use tlb->end != 0 only for TLB invalidation
8e1e1df29d83 tracing: Add additional marks to signal very large time deltas
aabfb57296e3 mm: memcontrol: do not kill uncharge batching in free_pages_and_swap_cache
54b9dd14d09f mm/memory-failure.c: shift page lock from head page to tail page after thp split
53a59fc67f97 mm: limit mmu_gather batching to fix soft lockups on !CONFIG_PREEMPT
bfaef4b46b17 perf diff: Use hists__link when not pairing just with baseline
7512102cf64d memcg: fix GPF when cgroup removal races with last exit
f95ba941d1be mm/pgtable-generic.c: fix CONFIG_SWAP=n build
]

42/2 2026/05/25 00:10 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 28106
							output: 30
							thoughts: 17
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience, and presented as if it's my own internal dialogue:

**Investigating Potential Memory Corruption in the Linux Kernel**

Right, let's dive into this. The presence of `__page_table_check_zero` immediately flags a potential area of concern. My immediate thought is, "Okay, we're looking at something related to page table integrity checks, likely related to zeroing out page table entries. That function's name suggests it's involved in verifying that a particular portion of the page table has, in fact, been zeroed, which is a key step to preventing information leakage or stale pointers when handling memory allocation and deallocation."

So, the next logical step is to pinpoint the commits that touch this function. Finding commits mentioning `__page_table_check_zero` is the best starting point. This should give me a chronological trace of the code's evolution, pinpointing any modifications, additions, or bug fixes around that function. I'm hoping to understand:

*   **Rationale:** Why was this check introduced or modified? What vulnerabilities or potential problems was it addressing?
*   **Context:** What other parts of the memory management system are interacting with this function? Does it interact with more general memory allocation, deallocation, or protection.
*   **Bug Reports:** Are there any reported issues or CVEs linked to these commits?
*   **Side Effects:** Did any of these commits introduce any regressions or performance issues that may have not been realized at the time.

Essentially, I want to establish a timeline of changes, understand the *why* behind them, and then assess any potential fallout or current vulnerabilities that may still exist. This initial search is essential to build a solid foundation for further analysis.



43/2 2026/05/25 00:10 tool git-log
0m Args:
map[Count:20 MessageRegexps:[__page_table_check_zero]]

Results:
map[Output:80110bbfbba6 mm/page_table_check: check entries at pmd levels
]

44/2 2026/05/25 00:10 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 28570
							output: 21
							thoughts: 513
						

Thoughts:
**Analyzing a Kernel Bug: Page Table Check Failure**

Okay, let's dive back into this bug report. The kernel's complaining with a `BUG at mm/page_table_check.c:142!` and a reference to `__page_table_check_zero`. This looks like we're hitting a `BUG_ON` either due to a non-zero `anon_map_count` or `file_map_count`. Essentially, the system's telling us a page is being freed, but the counters in `page_table_check` are saying it's still mapped.

My initial thought is to question the integrity of `page_table_check` itself. Is there a flaw *within* the checker, leading to a false positive? Remember, the purpose of `page_table_check` is to ensure pages are *not* mapped when they are freed. If it detects a mapping during a free operation, it crashes – which is what we're seeing.

The immediate question is exploitability. If this is just a false positive within the checking mechanism, it’s a denial-of-service, a kernel crash, but not necessarily exploitable. However, if it's a real bug where a page is genuinely freed while still mapped, we have a classic use-after-free, which would be *highly* exploitable.

Hold on a second, a crucial detail – `page_table_check` is a *debugging* feature, right? If `PAGE_TABLE_CHECK` isn't enabled in a production environment, `__page_table_check_zero` wouldn't even be called. We need to check whether `PAGE_TABLE_CHECK` is on. Typically, it’s disabled by default. If it’s disabled, this bug is essentially unreachable in production, right? The documentation is right here, it says page table checking can be enabled by a kernel parameter.

But wait, hold on. If it's a *real* use-after-free, the *bug* is still there, regardless of whether we're using `page_table_check`! `PAGE_TABLE_CHECK` just makes us aware of it. So even if it's disabled, the underlying vulnerability remains and is exploitable. We just don't have a helpful debugging tool to catch it early.

So, how does a page end up being freed while still mapped? It means its reference count dropped to zero while it's still actually in use. Or, perhaps it was unmapped, but the `page_table_check` counters weren't updated correctly, creating this false positive. If it's the second case, it means the check tool is the source of the false positive.

I think the next logical step is to search for related commits to see if this specific bug has already been identified and addressed. Let's start with that search.



45/2 2026/05/25 00:10 tool grepper
0m Args:
map[Expression:page_table_check_zero]

Results:
map[Output:include/linux/page_table_check.h=14=extern struct page_ext_operations page_table_check_ops;
include/linux/page_table_check.h-15-
include/linux/page_table_check.h:16:void __page_table_check_zero(struct page *page, unsigned int order);
include/linux/page_table_check.h-17-void __page_table_check_pte_clear(struct mm_struct *mm, unsigned long addr,
--
include/linux/page_table_check.h=33=static inline void page_table_check_alloc(struct page *page, unsigned int order)
--
include/linux/page_table_check.h-37-
include/linux/page_table_check.h:38:	__page_table_check_zero(page, order);
include/linux/page_table_check.h-39-}
--
include/linux/page_table_check.h=41=static inline void page_table_check_free(struct page *page, unsigned int order)
--
include/linux/page_table_check.h-45-
include/linux/page_table_check.h:46:	__page_table_check_zero(page, order);
include/linux/page_table_check.h-47-}
--
mm/page_table_check.c=97=static void page_table_check_set(unsigned long pfn, unsigned long pgcnt,
--
mm/page_table_check.c-130- */
mm/page_table_check.c:131:void __page_table_check_zero(struct page *page, unsigned int order)
mm/page_table_check.c-132-{
]

46/2 2026/05/25 00:10 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 30160
							output: 32
							thoughts: 17
						

Thoughts:
Okay, here's my attempt at summarizing that thought process, tailored for an expert audience:

**Hunting Down Those Pesky `page_table_check` False Positives**

Alright, time to get down to brass tacks. I need to dig into the commit history. The goal? To find the fixes that specifically addressed those frustrating false positives we've been seeing with `page_table_check`. We know they're there, intermittent, and maddening to track down, so let's try to focus our search. I'm going to concentrate the search to changes that target the checks itself. Let's see what we can find. I expect that these will be the most useful.



47/2 2026/05/25 00:10 tool git-log
0m Args:
map[Count:20 MessageRegexps:[page_table_check false positive]]

Results:
map[Output:00de2c9f26b1 arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()
81a31a860bb6 mm: page_table_check: Make it dependent on EXCLUSIVE_SYSTEM_RAM
]

48/2 2026/05/25 00:11 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 30436
							output: 26
							thoughts: 17
						

Thoughts:
Okay, let's dive into this. Here's my thought process on this task:

**Analyzing the Hash `00de2c9f26b1`**

Right, let's start by looking at `00de2c9f26b1`. My immediate thought is, what is this? Is it an MD5 hash, SHA-1, SHA-256? Based on its length, it's most likely an MD5 hash, but I always verify. I'd typically run it through my standard hash identifier tools, just to confirm the algorithm. No assumptions here, I always triple-check these things. Now, if it *is* MD5, I know the inherent vulnerabilities. Collision attacks are pretty well-documented, so I need to keep that in mind. Is this likely a password hash? If so, I'd immediately consider rainbow tables, brute-forcing, and dictionary attacks. I'd have to consider the context of where I found it to decide which route to take first. If it's a file hash, then I need to figure out what file it represents, and if it's potentially malicious. My first thought is to use a site like VirusTotal to see if the hash is associated with any known malware. If not, I'll need to use sandboxing to test the file. My next steps will depend on the result of those initial inquiries.



49/2 2026/05/25 00:11 tool git-show
0m Args:
map[Commit:00de2c9f26b1]

Results:
map[Output:commit 00de2c9f26b15f1a6f2af516dd8ec5f8d28189b7
Author: Qi Zheng <qi.zheng@linux.dev>
Date:   Thu Aug 10 09:32:41 2023 +0000

    arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()
    
    In clear_flush(), the original pte may be a present entry, so we should
    use ptep_clear() to let page_table_check track the pte clearing operation,
    otherwise it may cause false positive in subsequent set_pte_at().
    
    Link: https://lkml.kernel.org/r/20230810093241.1181142-1-qi.zheng@linux.dev
    Fixes: 42b2547137f5 ("arm64/mm: enable ARCH_SUPPORTS_PAGE_TABLE_CHECK")
    Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
    Acked-by: Will Deacon <will@kernel.org>
    Cc: Catalin Marinas <catalin.marinas@arm.com>
    Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
    Cc: Muchun Song <muchun.song@linux.dev>
    Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
    Cc: Qi Zheng <zhengqi.arch@bytedance.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
index 21716c940682..9c52718ea750 100644
--- a/arch/arm64/mm/hugetlbpage.c
+++ b/arch/arm64/mm/hugetlbpage.c
@@ -236,7 +236,7 @@ static void clear_flush(struct mm_struct *mm,
 	unsigned long i, saddr = addr;
 
 	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
-		pte_clear(mm, addr, ptep);
+		ptep_clear(mm, addr, ptep);
 
 	flush_tlb_range(&vma, saddr, addr);
 }
]

50/2 2026/05/25 00:11 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 31430
							output: 32
							thoughts: 85
						

Thoughts:
Okay, here's my take on those thoughts, framed as an expert in the field:

**Debugging a Potential Architecture Mismatch**

Right, so this crash dump is specifically mentioning `arm64`, but the hardware identified is `riscv-virtio,qemu`. Hmm, that's immediately concerning. The bug report itself points to a `riscv` issue, but the initial data seems to contradict that. We're looking at an error within `__page_table_check_zero` which is a critical function in memory management. The location given is `mm/page_table_check.c:142`, which is very precise. This suggests a potential misinterpretation or an incorrect build configuration somewhere along the line.

My first instinct is to dig into the possibility that there's a mix-up or a build system issue. This requires an immediate search focusing on `riscv page_table_check` errors. I'll focus that search as specifically as I can, looking for any reports that involve the interaction with a virtualized environment like QEMU.



51/2 2026/05/25 00:11 tool git-log
0m Args:
map[Count:20 MessageRegexps:[page_table_check riscv]]

Results:
map[Output:641d47d4c963 powerpc/mm: support page table check
d7b4b67eb6b3 mm/page_table_check: reinstate address parameter in [__]page_table_check_pte_clear()
649ec9e3d03c mm/page_table_check: reinstate address parameter in [__]page_table_check_pmd_clear()
0a5ae4483177 mm/page_table_check: provide addr parameter to page_table_check_ptes_set()
6e2d8f9fc4ed mm/page_table_check: reinstate address parameter in [__]page_table_check_pmd[s]_set()
c4a0c5ff85b7 mm/page_table_check: reinstate address parameter in [__]page_table_check_pud[s]_set()
34c0a5b04da8 riscv/mm: fix build error while PAGE_TABLE_CHECK enabled without MMU
24c8e27e6322 mm/page_table_check: fix accessing unmapped ptep
2c8a81dc0cc5 riscv/mm: fix two page table check related issues
3fee229a8eb9 riscv/mm: enable ARCH_SUPPORTS_PAGE_TABLE_CHECK
92fb05242a1b mm: page_table_check: using PxD_SIZE instead of PxD_PAGE_SIZE
]

52/2 2026/05/25 00:11 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 32139
							output: 25
							thoughts: 16
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience, and rendered in the first person:

**Initial Assessment: A Hash to Investigate**

Alright, I'm presented with `2c8a81dc0cc5`. My immediate reaction is to treat this as a potentially significant hash value. Without context, it could represent anything from a cryptographic checksum to an MD5 hash of some critical data. The specific format suggests it's likely a relatively common hashing algorithm, probably MD5 or SHA-1, although I can't rule out others offhand without more information. My first instinct is to try and determine its origin and purpose. What system generated this hash? What data is associated with it? Is there an associated key or salt I need to consider? I'll need to use various methods to dig further.



53/2 2026/05/25 00:11 tool git-show
0m Args:
map[Commit:2c8a81dc0cc5]

Results:
map[Output:commit 2c8a81dc0cc533c666c64f4139a608b0ae55d96f
Author: Tong Tiangen <tongtiangen@huawei.com>
Date:   Tue May 17 07:45:47 2022 +0000

    riscv/mm: fix two page table check related issues
    
    Two page table check related issues have been fixed here.
    
    1. Open CONFIG_PAGE_TABLE_CHECK in riscv32, we got a compile error[1]:
    
       error: implicit declaration of function 'pud_leaf'
    
       Add pud_leaf() definition to incluce/asm-generic/pgtable-nopmd.h to fix
       this issue.
    
    2. Keep consistent with other pud_xxx() helpers, move pud_user() to
       pgtable-64.h and add pud_user() to pgtable-nopmd.h.
    
    [1]https://lore.kernel.org/linux-mm/202205161811.2nLxmN2O-lkp@intel.com/T/
    
    Link: https://lkml.kernel.org/r/20220517074548.2227779-2-tongtiangen@huawei.com
    Fixes: 856eed79f8d3 ("riscv/mm: enable ARCH_SUPPORTS_PAGE_TABLE_CHECK")
    Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
    Reported-by: kernel test robot <lkp@intel.com>
    Cc: Anshuman Khandual <anshuman.khandual@arm.com>
    Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
    Cc: Anshuman Khandual <anshuman.khandual@arm.com>
    Cc: Albert Ou <aou@eecs.berkeley.edu>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Catalin Marinas <catalin.marinas@arm.com>
    Cc: Guohanjun <guohanjun@huawei.com>
    Cc: Palmer Dabbelt <palmer@dabbelt.com>
    Cc: Paul Walmsley <paul.walmsley@sifive.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Xie XiuQi <xiexiuqi@huawei.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h
index 7e246e9f8d70..ba2494cbc24f 100644
--- a/arch/riscv/include/asm/pgtable-64.h
+++ b/arch/riscv/include/asm/pgtable-64.h
@@ -86,6 +86,11 @@ static inline int pud_leaf(pud_t pud)
 	return pud_present(pud) && (pud_val(pud) & _PAGE_LEAF);
 }
 
+static inline int pud_user(pud_t pud)
+{
+	return pud_val(pud) & _PAGE_USER;
+}
+
 static inline void set_pud(pud_t *pudp, pud_t pud)
 {
 	*pudp = pud;
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 62e733c85836..4200ddede880 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -634,11 +634,6 @@ static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
 	return __set_pte_at(mm, addr, (pte_t *)pmdp, pmd_pte(pmd));
 }
 
-static inline int pud_user(pud_t pud)
-{
-	return pte_user(pud_pte(pud));
-}
-
 static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
 				pud_t *pudp, pud_t pud)
 {
diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
index 10789cf51d16..8ffd64e7a24c 100644
--- a/include/asm-generic/pgtable-nopmd.h
+++ b/include/asm-generic/pgtable-nopmd.h
@@ -30,6 +30,8 @@ typedef struct { pud_t pud; } pmd_t;
 static inline int pud_none(pud_t pud)		{ return 0; }
 static inline int pud_bad(pud_t pud)		{ return 0; }
 static inline int pud_present(pud_t pud)	{ return 1; }
+static inline int pud_user(pud_t pud)		{ return 0; }
+static inline int pud_leaf(pud_t pud)		{ return 0; }
 static inline void pud_clear(pud_t *pud)	{ }
 #define pmd_ERROR(pmd)				(pud_ERROR((pmd).pud))
 
]

54/2 2026/05/25 00:11 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 33775
							output: 30
							thoughts: 27
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Quick Fix & Deep Dive Potential**

Right, this looks like another minor build hiccup. Nothing too earth-shattering, hopefully. But these little things can often be a symptom of a deeper issue, you know? It's easy to get tunnel vision and just patch the immediate problem, but let's not be *that* engineer.

Since this is RISC-V related, my instincts are pulling me towards memory management. Specifically, I'm thinking about page table entries and the functions used to manipulate them. I'm going to do a quick scan of the codebase, maybe a `git grep` or a similar tool. I'll search for uses of `riscv pte_clear` and `riscv ptep_clear`, or their equivalent for whatever RISC-V implementation this is. That seems like a prime area for a subtle race condition or an off-by-one error to creep in, especially given the various memory access patterns in modern systems. It's a bit of a hunch, but these types of low-level issues can be incredibly insidious and often manifest in seemingly unrelated build failures. Let's see what we can find.



55/2 2026/05/25 00:11 tool git-log
0m Args:
map[Count:20 MessageRegexps:[riscv pte_clear]]

Results:
map[Output:641d47d4c963 powerpc/mm: support page table check
d7b4b67eb6b3 mm/page_table_check: reinstate address parameter in [__]page_table_check_pte_clear()
83d78ac677b9 riscv: Fix hugetlb retrieval of number of ptes in case of !present pte
02410ac72ac3 mm: hugetlb: Add huge page size param to huge_ptep_get_and_clear()
935d4f0c6dc8 mm: hugetlb: add huge page size param to set_huge_pte_at()
34c0a5b04da8 riscv/mm: fix build error while PAGE_TABLE_CHECK enabled without MMU
401035d5c456 mm/debug_vm_pgtable: avoid none pte in pte_clear_test
]

56/2 2026/05/25 00:12 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 34328
							output: 26
							thoughts: 17
						

Thoughts:
Okay, let's dive into this. Here's my thought process on this task:

**Analyzing the Commit Hash**

Alright, the first thing that jumps out is that I need to analyze this commit hash: `83d78ac677b9`. As a seasoned professional, my immediate inclination is to understand the context. Is this a Git commit hash? If so, what repository are we working with? What's the associated project or codebase? Without that background, I'm essentially starting blind, though the hash itself hints at a specific point in time within the project's history. I'll need more information before I can offer a truly insightful interpretation. I'll mentally file this as a placeholder for later if further context comes to light. The raw hash value alone gives me little to work with.



57/2 2026/05/25 00:12 tool git-show
0m Args:
map[Commit:83d78ac677b9]

Results:
map[Output:commit 83d78ac677b9fdd8ea763507c6fe02d6bf415f3a
Author: Alexandre Ghiti <alexghiti@rivosinc.com>
Date:   Mon Mar 17 08:25:51 2025 +0100

    riscv: Fix hugetlb retrieval of number of ptes in case of !present pte
    
    Ryan sent a fix [1] for arm64 that applies to riscv too: in some hugetlb
    functions, we must not use the pte value to get the size of a mapping
    because the pte may not be present.
    
    So use the already present size parameter for huge_pte_clear() and the
    newly introduced size parameter for huge_ptep_get_and_clear(). And make
    sure to gather A/D bits only on present ptes.
    
    Fixes: 82a1a1f3bfb6 ("riscv: mm: support Svnapot in hugetlb page")
    Link: https://lore.kernel.org/all/20250217140419.1702389-1-ryan.roberts@arm.com/ [1]
    Link: https://lore.kernel.org/r/20250317072551.572169-1-alexghiti@rivosinc.com
    Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>

diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c
index b4a78a4b35cf..375dd96bb4a0 100644
--- a/arch/riscv/mm/hugetlbpage.c
+++ b/arch/riscv/mm/hugetlbpage.c
@@ -148,22 +148,25 @@ unsigned long hugetlb_mask_last_page(struct hstate *h)
 static pte_t get_clear_contig(struct mm_struct *mm,
 			      unsigned long addr,
 			      pte_t *ptep,
-			      unsigned long pte_num)
+			      unsigned long ncontig)
 {
-	pte_t orig_pte = ptep_get(ptep);
-	unsigned long i;
-
-	for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++) {
-		pte_t pte = ptep_get_and_clear(mm, addr, ptep);
-
-		if (pte_dirty(pte))
-			orig_pte = pte_mkdirty(orig_pte);
-
-		if (pte_young(pte))
-			orig_pte = pte_mkyoung(orig_pte);
+	pte_t pte, tmp_pte;
+	bool present;
+
+	pte = ptep_get_and_clear(mm, addr, ptep);
+	present = pte_present(pte);
+	while (--ncontig) {
+		ptep++;
+		addr += PAGE_SIZE;
+		tmp_pte = ptep_get_and_clear(mm, addr, ptep);
+		if (present) {
+			if (pte_dirty(tmp_pte))
+				pte = pte_mkdirty(pte);
+			if (pte_young(tmp_pte))
+				pte = pte_mkyoung(pte);
+		}
 	}
-
-	return orig_pte;
+	return pte;
 }
 
 static pte_t get_clear_contig_flush(struct mm_struct *mm,
@@ -212,6 +215,26 @@ static void clear_flush(struct mm_struct *mm,
 	flush_tlb_range(&vma, saddr, addr);
 }
 
+static int num_contig_ptes_from_size(unsigned long sz, size_t *pgsize)
+{
+	unsigned long hugepage_shift;
+
+	if (sz >= PGDIR_SIZE)
+		hugepage_shift = PGDIR_SHIFT;
+	else if (sz >= P4D_SIZE)
+		hugepage_shift = P4D_SHIFT;
+	else if (sz >= PUD_SIZE)
+		hugepage_shift = PUD_SHIFT;
+	else if (sz >= PMD_SIZE)
+		hugepage_shift = PMD_SHIFT;
+	else
+		hugepage_shift = PAGE_SHIFT;
+
+	*pgsize = 1 << hugepage_shift;
+
+	return sz >> hugepage_shift;
+}
+
 /*
  * When dealing with NAPOT mappings, the privileged specification indicates that
  * "if an update needs to be made, the OS generally should first mark all of the
@@ -226,22 +249,10 @@ void set_huge_pte_at(struct mm_struct *mm,
 		     pte_t pte,
 		     unsigned long sz)
 {
-	unsigned long hugepage_shift, pgsize;
+	size_t pgsize;
 	int i, pte_num;
 
-	if (sz >= PGDIR_SIZE)
-		hugepage_shift = PGDIR_SHIFT;
-	else if (sz >= P4D_SIZE)
-		hugepage_shift = P4D_SHIFT;
-	else if (sz >= PUD_SIZE)
-		hugepage_shift = PUD_SHIFT;
-	else if (sz >= PMD_SIZE)
-		hugepage_shift = PMD_SHIFT;
-	else
-		hugepage_shift = PAGE_SHIFT;
-
-	pte_num = sz >> hugepage_shift;
-	pgsize = 1 << hugepage_shift;
+	pte_num = num_contig_ptes_from_size(sz, &pgsize);
 
 	if (!pte_present(pte)) {
 		for (i = 0; i < pte_num; i++, ptep++, addr += pgsize)
@@ -295,13 +306,14 @@ pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
 			      unsigned long addr,
 			      pte_t *ptep, unsigned long sz)
 {
+	size_t pgsize;
 	pte_t orig_pte = ptep_get(ptep);
 	int pte_num;
 
 	if (!pte_napot(orig_pte))
 		return ptep_get_and_clear(mm, addr, ptep);
 
-	pte_num = napot_pte_num(napot_cont_order(orig_pte));
+	pte_num = num_contig_ptes_from_size(sz, &pgsize);
 
 	return get_clear_contig(mm, addr, ptep, pte_num);
 }
@@ -351,6 +363,7 @@ void huge_pte_clear(struct mm_struct *mm,
 		    pte_t *ptep,
 		    unsigned long sz)
 {
+	size_t pgsize;
 	pte_t pte = ptep_get(ptep);
 	int i, pte_num;
 
@@ -359,8 +372,9 @@ void huge_pte_clear(struct mm_struct *mm,
 		return;
 	}
 
-	pte_num = napot_pte_num(napot_cont_order(pte));
-	for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++)
+	pte_num = num_contig_ptes_from_size(sz, &pgsize);
+
+	for (i = 0; i < pte_num; i++, addr += pgsize, ptep++)
 		pte_clear(mm, addr, ptep);
 }
 
]

58/2 2026/05/25 00:12 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 36556
							output: 47
							thoughts: 239
						

Thoughts:
**Debugging a RISC-V PTE Clearing Issue**

Okay, so I'm digging into this `huge_pte_clear` function in RISC-V, and I think I've spotted a potential problem. It looks like it's using `pte_napot(pte)` to figure out how many PTEs to clear. Hmm, that seems straightforward enough... except, what if the PTE isn't *present*? The `pte_napot` function relies on that NAPOT bit being set, right? If the PTE isn't present, that bit might not even be valid. It could be garbage or indicate a swap entry.

Right, so if `pte_napot` returns an incorrect value, and `huge_pte_clear` clears *fewer* PTEs than it's supposed to, that leaves some PTEs uncleared! And that's not good. Hold on, `huge_pte_clear` then calls `pte_clear(mm, addr, ptep)`. `pte_clear` in turn calls `page_table_check_pte_clear`, to decrement counters.

Aha! If `huge_pte_clear` clears fewer entries than it should, the counters in `page_table_check` aren't decremented for those remaining PTEs! So later, when the page is freed, `page_table_check` is going to see those non-zero counters and trigger that dreaded BUG! That explains the crash.

I need to confirm that `huge_pte_clear` is the source of the issue. Let me go back and examine the function's behavior before this commit.



59/2 2026/05/25 00:12 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/mm/hugetlbpage.c IncludeLines:true Name:huge_pte_clear]

Results:
map[SourceCode:  62:	static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
  63:			    pte_t *ptep, unsigned long sz)
  64:	{
  65:		pte_clear(mm, addr, ptep);
  66:	}
 SourceFile:include/asm-generic/hugetlb.h]

60/2 2026/05/25 00:12 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 37302
							output: 19
							thoughts: 71
						

Thoughts:
**Investigating the `huge_pte_clear` Function**

Okay, so I'm seeing `huge_pte_clear` listed in the commit log within `arch/riscv/mm/hugetlbpage.c`. But then, my initial code search also turned up an instance in `include/asm-generic/hugetlb.h`. Hmm, that's a bit odd. I need to get to the bottom of this. To clarify the situation and ensure I'm looking at the correct version and implementation specific to the RISC-V architecture, I'm going to bypass the search results and examine `arch/riscv/mm/hugetlbpage.c` directly. This should give me the most definitive answer regarding the function's definition and usage in this particular context.



61/2 2026/05/25 00:12 tool grepper
0m Args:
map[Expression:huge_pte_clear]

Results:
map[Output:arch/arm64/include/asm/hugetlb.h=51=extern pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
--
arch/arm64/include/asm/hugetlb.h-53-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/arm64/include/asm/hugetlb.h:54:extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/arm64/include/asm/hugetlb.h-55-			   pte_t *ptep, unsigned long sz);
--
arch/arm64/mm/hugetlbpage.c=344=pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
--
arch/arm64/mm/hugetlbpage.c-368-
arch/arm64/mm/hugetlbpage.c:369:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/arm64/mm/hugetlbpage.c-370-		    pte_t *ptep, unsigned long sz)
--
arch/loongarch/include/asm/hugetlb.h=11=uint64_t pmd_to_entrylo(unsigned long pmd_val);
--
arch/loongarch/include/asm/hugetlb.h-13-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/loongarch/include/asm/hugetlb.h:14:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/loongarch/include/asm/hugetlb.h-15-				  pte_t *ptep, unsigned long sz)
--
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h=23=static inline pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
--
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-30-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h:31:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-32-				  pte_t *ptep, unsigned long sz)
--
arch/riscv/include/asm/hugetlb.h=15=bool arch_hugetlb_migration_supported(struct hstate *h);
--
arch/riscv/include/asm/hugetlb.h-20-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/riscv/include/asm/hugetlb.h:21:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/riscv/include/asm/hugetlb.h-22-		    pte_t *ptep, unsigned long sz);
--
arch/riscv/mm/hugetlbpage.c=346=pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
--
arch/riscv/mm/hugetlbpage.c-360-
arch/riscv/mm/hugetlbpage.c:361:void huge_pte_clear(struct mm_struct *mm,
arch/riscv/mm/hugetlbpage.c-362-		    unsigned long addr,
--
arch/s390/include/asm/hugetlb.h=33=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
--
arch/s390/include/asm/hugetlb.h-40-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/s390/include/asm/hugetlb.h:41:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/s390/include/asm/hugetlb.h-42-				  pte_t *ptep, unsigned long sz)
--
arch/s390/include/asm/hugetlb.h=81=static inline pte_t huge_pte_mkuffd_wp(pte_t pte)
--
arch/s390/include/asm/hugetlb.h-86-#define __HAVE_ARCH_HUGE_PTE_CLEAR_UFFD_WP
arch/s390/include/asm/hugetlb.h:87:static inline pte_t huge_pte_clear_uffd_wp(pte_t pte)
arch/s390/include/asm/hugetlb.h-88-{
--
include/asm-generic/hugetlb.h=41=static inline pte_t huge_pte_mkuffd_wp(pte_t pte)
--
include/asm-generic/hugetlb.h-47-#ifndef __HAVE_ARCH_HUGE_PTE_CLEAR_UFFD_WP
include/asm-generic/hugetlb.h:48:static inline pte_t huge_pte_clear_uffd_wp(pte_t pte)
include/asm-generic/hugetlb.h-49-{
--
include/asm-generic/hugetlb.h=55=static inline int huge_pte_uffd_wp(pte_t pte)
--
include/asm-generic/hugetlb.h-61-#ifndef __HAVE_ARCH_HUGE_PTE_CLEAR
include/asm-generic/hugetlb.h:62:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
include/asm-generic/hugetlb.h-63-		    pte_t *ptep, unsigned long sz)
--
mm/hugetlb.c=4869=int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
--
mm/hugetlb.c-4936-			if (!userfaultfd_wp(dst_vma))
mm/hugetlb.c:4937:				entry = huge_pte_clear_uffd_wp(entry);
mm/hugetlb.c-4938-			set_huge_pte_at(dst, addr, dst_pte, entry, sz);
--
mm/hugetlb.c-4954-			if (!userfaultfd_wp(dst_vma))
mm/hugetlb.c:4955:				entry = huge_pte_clear_uffd_wp(entry);
mm/hugetlb.c-4956-			set_huge_pte_at(dst, addr, dst_pte, entry, sz);
--
mm/hugetlb.c-5030-			if (!userfaultfd_wp(dst_vma))
mm/hugetlb.c:5031:				entry = huge_pte_clear_uffd_wp(entry);
mm/hugetlb.c-5032-
--
mm/hugetlb.c=5052=static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,
--
mm/hugetlb.c-5074-	if (need_clear_uffd_wp && pte_is_uffd_wp_marker(pte)) {
mm/hugetlb.c:5075:		huge_pte_clear(mm, new_addr, dst_pte, sz);
mm/hugetlb.c-5076-	} else {
--
mm/hugetlb.c-5078-			if (pte_present(pte))
mm/hugetlb.c:5079:				pte = huge_pte_clear_uffd_wp(pte);
mm/hugetlb.c-5080-			else
--
mm/hugetlb.c=5156=void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
--
mm/hugetlb.c-5220-			else
mm/hugetlb.c:5221:				huge_pte_clear(mm, address, ptep, sz);
mm/hugetlb.c-5222-			spin_unlock(ptl);
--
mm/hugetlb.c=5956=vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
--
mm/hugetlb.c-6084-
mm/hugetlb.c:6085:		vmf.orig_pte = huge_pte_clear_uffd_wp(vmf.orig_pte);
mm/hugetlb.c-6086-		set_huge_pte_at(mm, vmf.address, vmf.pte, vmf.orig_pte,
--
mm/hugetlb.c=6398=long hugetlb_change_protection(struct vm_area_struct *vma,
--
mm/hugetlb.c-6506-				/* Safe to modify directly (non-present->none). */
mm/hugetlb.c:6507:				huge_pte_clear(mm, address, ptep, psize);
mm/hugetlb.c-6508-		} else {
--
mm/hugetlb.c-6517-			else if (uffd_wp_resolve)
mm/hugetlb.c:6518:				pte = huge_pte_clear_uffd_wp(pte);
mm/hugetlb.c-6519-			huge_ptep_modify_prot_commit(vma, address, ptep, old_pte, pte);
]

62/2 2026/05/25 00:12 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 40035
							output: 47
							thoughts: 32
						

Thoughts:
Here's my take on the thought process, summarized as you requested:

**Investigating Huge Page PTE Clearing in the RISC-V Kernel**

Okay, so I need to refresh my memory on how huge page table entries are cleared in the RISC-V architecture, specifically within the kernel. Let's see...I'm pretty sure that code would reside in the memory management section, somewhere related to HugeTLB pages. The naming conventions usually point me in the right direction, so `arch/riscv/mm/hugetlbpage.c` seems like a solid starting point. I'll need to look for the function `huge_pte_clear` there. That name is pretty self-explanatory, so finding it shouldn't be too tricky. Hopefully, the code comments will be clear enough to quickly grasp the relevant details surrounding the clearing mechanism. This should give me a good understanding of how the kernel handles the low-level tasks associated with managing those larger page sizes on RISC-V.



63/2 2026/05/25 00:12 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/mm/hugetlbpage.c IncludeLines:true Name:huge_pte_clear]

Results:
map[SourceCode:  62:	static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
  63:			    pte_t *ptep, unsigned long sz)
  64:	{
  65:		pte_clear(mm, addr, ptep);
  66:	}
 SourceFile:include/asm-generic/hugetlb.h]

64/2 2026/05/25 00:12 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 40435
							output: 28
							thoughts: 49
						

Thoughts:
Okay, let's see... **Digging into RISC-V HugeTLB Page Handling**

Wait a second, I'm pretty sure I've worked with this code before, but I'm drawing a blank. Where is `huge_pte_clear` defined for RISC-V? I could have sworn... Nope, not here in `arch/riscv/mm/hugetlbpage.c`. Time to dive in and get a handle on what's actually happening in this specific RISC-V huge page implementation. Let's start by reading `arch/riscv/mm/hugetlbpage.c` thoroughly. I need to refresh my memory and understand the flow.



65/2 2026/05/25 00:12 tool read-file
0m Args:
map[File:arch/riscv/mm/hugetlbpage.c]

Results:
map[Contents:// SPDX-License-Identifier: GPL-2.0
#include <linux/hugetlb.h>
#include <linux/err.h>

#ifdef CONFIG_RISCV_ISA_SVNAPOT
pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
{
	unsigned long pte_num;
	int i;
	pte_t orig_pte = ptep_get(ptep);

	if (!pte_present(orig_pte) || !pte_napot(orig_pte))
		return orig_pte;

	pte_num = napot_pte_num(napot_cont_order(orig_pte));

	for (i = 0; i < pte_num; i++, ptep++) {
		pte_t pte = ptep_get(ptep);

		if (pte_dirty(pte))
			orig_pte = pte_mkdirty(orig_pte);

		if (pte_young(pte))
			orig_pte = pte_mkyoung(orig_pte);
	}

	return orig_pte;
}

pte_t *huge_pte_alloc(struct mm_struct *mm,
		      struct vm_area_struct *vma,
		      unsigned long addr,
		      unsigned long sz)
{
	unsigned long order;
	pte_t *pte = NULL;
	pgd_t *pgd;
	p4d_t *p4d;
	pud_t *pud;
	pmd_t *pmd;

	pgd = pgd_offset(mm, addr);
	p4d = p4d_alloc(mm, pgd, addr);
	if (!p4d)
		return NULL;

	pud = pud_alloc(mm, p4d, addr);
	if (!pud)
		return NULL;

	if (sz == PUD_SIZE) {
		pte = (pte_t *)pud;
		goto out;
	}

	if (sz == PMD_SIZE) {
		if (want_pmd_share(vma, addr) && pud_none(pudp_get(pud)))
			pte = huge_pmd_share(mm, vma, addr, pud);
		else
			pte = (pte_t *)pmd_alloc(mm, pud, addr);
		goto out;
	}

	pmd = pmd_alloc(mm, pud, addr);
	if (!pmd)
		return NULL;

	for_each_napot_order(order) {
		if (napot_cont_size(order) == sz) {
			pte = pte_alloc_huge(mm, pmd, addr & napot_cont_mask(order));
			break;
		}
	}

out:
	if (pte) {
		pte_t pteval = ptep_get_lockless(pte);

		WARN_ON_ONCE(pte_present(pteval) && !pte_huge(pteval));
	}
	return pte;
}

pte_t *huge_pte_offset(struct mm_struct *mm,
		       unsigned long addr,
		       unsigned long sz)
{
	unsigned long order;
	pte_t *pte = NULL;
	pgd_t *pgd;
	p4d_t *p4d;
	pud_t *pud;
	pmd_t *pmd;

	pgd = pgd_offset(mm, addr);
	if (!pgd_present(pgdp_get(pgd)))
		return NULL;

	p4d = p4d_offset(pgd, addr);
	if (!p4d_present(p4dp_get(p4d)))
		return NULL;

	pud = pud_offset(p4d, addr);
	if (sz == PUD_SIZE)
		/* must be pud huge, non-present or none */
		return (pte_t *)pud;

	if (!pud_present(pudp_get(pud)))
		return NULL;

	pmd = pmd_offset(pud, addr);
	if (sz == PMD_SIZE)
		/* must be pmd huge, non-present or none */
		return (pte_t *)pmd;

	if (!pmd_present(pmdp_get(pmd)))
		return NULL;

	for_each_napot_order(order) {
		if (napot_cont_size(order) == sz) {
			pte = pte_offset_huge(pmd, addr & napot_cont_mask(order));
			break;
		}
	}
	return pte;
}

unsigned long hugetlb_mask_last_page(struct hstate *h)
{
	unsigned long hp_size = huge_page_size(h);

	switch (hp_size) {
#ifndef __PAGETABLE_PMD_FOLDED
	case PUD_SIZE:
		return P4D_SIZE - PUD_SIZE;
#endif
	case PMD_SIZE:
		return PUD_SIZE - PMD_SIZE;
	case napot_cont_size(NAPOT_CONT64KB_ORDER):
		return PMD_SIZE - napot_cont_size(NAPOT_CONT64KB_ORDER);
	default:
		break;
	}

	return 0UL;
}

static pte_t get_clear_contig(struct mm_struct *mm,
			      unsigned long addr,
			      pte_t *ptep,
			      unsigned long ncontig)
{
	pte_t pte, tmp_pte;
	bool present;

	pte = ptep_get_and_clear(mm, addr, ptep);
	present = pte_present(pte);
	while (--ncontig) {
		ptep++;
		addr += PAGE_SIZE;
		tmp_pte = ptep_get_and_clear(mm, addr, ptep);
		if (present) {
			if (pte_dirty(tmp_pte))
				pte = pte_mkdirty(pte);
			if (pte_young(tmp_pte))
				pte = pte_mkyoung(pte);
		}
	}
	return pte;
}

static pte_t get_clear_contig_flush(struct mm_struct *mm,
				    unsigned long addr,
				    pte_t *ptep,
				    unsigned long pte_num)
{
	pte_t orig_pte = get_clear_contig(mm, addr, ptep, pte_num);
	struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0);
	bool valid = !pte_none(orig_pte);

	if (valid)
		flush_tlb_range(&vma, addr, addr + (PAGE_SIZE * pte_num));

	return orig_pte;
}

pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
{
	unsigned long order;

	for_each_napot_order(order) {
		if (shift == napot_cont_shift(order)) {
			entry = pte_mknapot(entry, order);
			break;
		}
	}
	if (order == NAPOT_ORDER_MAX)
		entry = pte_mkhuge(entry);

	return entry;
}

static void clear_flush(struct mm_struct *mm,
			unsigned long addr,
			pte_t *ptep,
			unsigned long pgsize,
			unsigned long ncontig)
{
	struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0);
	unsigned long i, saddr = addr;

	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
		ptep_get_and_clear(mm, addr, ptep);

	flush_tlb_range(&vma, saddr, addr);
}

static int num_contig_ptes_from_size(unsigned long sz, size_t *pgsize)
{
	unsigned long hugepage_shift;

	if (sz >= PGDIR_SIZE)
		hugepage_shift = PGDIR_SHIFT;
	else if (sz >= P4D_SIZE)
		hugepage_shift = P4D_SHIFT;
	else if (sz >= PUD_SIZE)
		hugepage_shift = PUD_SHIFT;
	else if (sz >= PMD_SIZE)
		hugepage_shift = PMD_SHIFT;
	else
		hugepage_shift = PAGE_SHIFT;

	*pgsize = 1 << hugepage_shift;

	return sz >> hugepage_shift;
}

/*
 * When dealing with NAPOT mappings, the privileged specification indicates that
 * "if an update needs to be made, the OS generally should first mark all of the
 * PTEs invalid, then issue SFENCE.VMA instruction(s) covering all 4 KiB regions
 * within the range, [...] then update the PTE(s), as described in Section
 * 4.2.1.". That's the equivalent of the Break-Before-Make approach used by
 * arm64.
 */
void set_huge_pte_at(struct mm_struct *mm,
		     unsigned long addr,
		     pte_t *ptep,
		     pte_t pte,
		     unsigned long sz)
{
	size_t pgsize;
	int i, pte_num;

	pte_num = num_contig_ptes_from_size(sz, &pgsize);

	if (!pte_present(pte)) {
		for (i = 0; i < pte_num; i++, ptep++, addr += pgsize)
			set_ptes(mm, addr, ptep, pte, 1);
		return;
	}

	if (!pte_napot(pte)) {
		set_ptes(mm, addr, ptep, pte, 1);
		return;
	}

	clear_flush(mm, addr, ptep, pgsize, pte_num);

	for (i = 0; i < pte_num; i++, ptep++, addr += pgsize)
		set_pte_at(mm, addr, ptep, pte);
}

int huge_ptep_set_access_flags(struct vm_area_struct *vma,
			       unsigned long addr,
			       pte_t *ptep,
			       pte_t pte,
			       int dirty)
{
	struct mm_struct *mm = vma->vm_mm;
	unsigned long order;
	pte_t orig_pte;
	int i, pte_num;

	if (!pte_napot(pte))
		return ptep_set_access_flags(vma, addr, ptep, pte, dirty);

	order = napot_cont_order(pte);
	pte_num = napot_pte_num(order);
	ptep = huge_pte_offset(mm, addr, napot_cont_size(order));
	orig_pte = get_clear_contig_flush(mm, addr, ptep, pte_num);

	if (pte_dirty(orig_pte))
		pte = pte_mkdirty(pte);

	if (pte_young(orig_pte))
		pte = pte_mkyoung(pte);

	for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++)
		set_pte_at(mm, addr, ptep, pte);

	return true;
}

pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
			      unsigned long addr,
			      pte_t *ptep, unsigned long sz)
{
	size_t pgsize;
	pte_t orig_pte = ptep_get(ptep);
	int pte_num;

	if (!pte_napot(orig_pte))
		return ptep_get_and_clear(mm, addr, ptep);

	pte_num = num_contig_ptes_from_size(sz, &pgsize);

	return get_clear_contig(mm, addr, ptep, pte_num);
}

void huge_ptep_set_wrprotect(struct mm_struct *mm,
			     unsigned long addr,
			     pte_t *ptep)
{
	pte_t pte = ptep_get(ptep);
	unsigned long order;
	pte_t orig_pte;
	int i, pte_num;

	if (!pte_napot(pte)) {
		ptep_set_wrprotect(mm, addr, ptep);
		return;
	}

	order = napot_cont_order(pte);
	pte_num = napot_pte_num(order);
	ptep = huge_pte_offset(mm, addr, napot_cont_size(order));
	orig_pte = get_clear_contig_flush(mm, addr, ptep, pte_num);

	orig_pte = pte_wrprotect(orig_pte);

	for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++)
		set_pte_at(mm, addr, ptep, orig_pte);
}

pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
			    unsigned long addr,
			    pte_t *ptep)
{
	pte_t pte = ptep_get(ptep);
	int pte_num;

	if (!pte_napot(pte))
		return ptep_clear_flush(vma, addr, ptep);

	pte_num = napot_pte_num(napot_cont_order(pte));

	return get_clear_contig_flush(vma->vm_mm, addr, ptep, pte_num);
}

void huge_pte_clear(struct mm_struct *mm,
		    unsigned long addr,
		    pte_t *ptep,
		    unsigned long sz)
{
	size_t pgsize;
	pte_t pte = ptep_get(ptep);
	int i, pte_num;

	if (!pte_napot(pte)) {
		pte_clear(mm, addr, ptep);
		return;
	}

	pte_num = num_contig_ptes_from_size(sz, &pgsize);

	for (i = 0; i < pte_num; i++, addr += pgsize, ptep++)
		pte_clear(mm, addr, ptep);
}

static bool is_napot_size(unsigned long size)
{
	unsigned long order;

	if (!has_svnapot())
		return false;

	for_each_napot_order(order) {
		if (size == napot_cont_size(order))
			return true;
	}
	return false;
}

static __init int napot_hugetlbpages_init(void)
{
	if (has_svnapot()) {
		unsigned long order;

		for_each_napot_order(order)
			hugetlb_add_hstate(order);
	}
	return 0;
}
arch_initcall(napot_hugetlbpages_init);

#else

static bool is_napot_size(unsigned long size)
{
	return false;
}

#endif /*CONFIG_RISCV_ISA_SVNAPOT*/

static bool __hugetlb_valid_size(unsigned long size)
{
	if (size == HPAGE_SIZE)
		return true;
	else if (IS_ENABLED(CONFIG_64BIT) && size == PUD_SIZE)
		return true;
	else if (is_napot_size(size))
		return true;
	else
		return false;
}

bool __init arch_hugetlb_valid_size(unsigned long size)
{
	return __hugetlb_valid_size(size);
}

#ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION
bool arch_hugetlb_migration_supported(struct hstate *h)
{
	return __hugetlb_valid_size(huge_page_size(h));
}
#endif

#ifdef CONFIG_CONTIG_ALLOC
static __init int gigantic_pages_init(void)
{
	/* With CONTIG_ALLOC, we can allocate gigantic pages at runtime */
	if (IS_ENABLED(CONFIG_64BIT))
		hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
	return 0;
}
arch_initcall(gigantic_pages_init);
#endif

unsigned int __init arch_hugetlb_cma_order(void)
{
	if (IS_ENABLED(CONFIG_64BIT))
		return PUD_SHIFT - PAGE_SHIFT;

	return 0;
}
]

66/2 2026/05/25 00:12 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 44793
							output: 46
							thoughts: 292
						

Thoughts:
**Analyzing `huge_pte_clear` in the RISC-V Kernel**

Okay, so I'm looking at `huge_pte_clear` within `arch/riscv/mm/hugetlbpage.c`. The code itself seems straightforward enough. It takes the memory map, the starting address, a pointer to the page table entry, and the size of the huge page as input. The core idea appears to be to clear the PTEs associated with a huge page.

The conditional `if (!pte_napot(pte))` immediately caught my eye. If `pte_napot` returns false, it just calls `pte_clear` on a *single* PTE. That seems... potentially problematic given the intent of handling huge pages. The intention is clear: `sz` could indeed represent a NAPOT size. I have to wonder, under which conditions would `pte_napot(pte)` return false? Especially when we're dealing with potentially absent PTEs (swap entries, or PTEs that might already be cleared).

Aha! That's it! If the PTE isn't present, `pte_napot(pte)` might very well return false. Which means it skips the loop and only clears a single PTE. This is the place to be careful and make sure all PTEs are cleared! I'll need to double check the behavior of `pte_napot` in various scenarios to ensure it handles absent PTEs correctly. Let's dig deeper into the definition of `pte_napot` and see what's going on... I have a feeling there's a subtle but important detail here.



67/2 2026/05/25 00:13 tool codesearch-definition-source
0m Error:
requested entity does not exist

Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:pte_napot]

Results:
map[SourceCode: SourceFile:]

68/2 2026/05/25 00:13 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 45495
							output: 18
							thoughts: 11
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience:

**Initiating Code Exploration: `pte_napot` Inquiry**

Right, let's get down to brass tacks. I'm hitting the search bar. My immediate inclination is to look for the term `pte_napot`. This probably indicates an interest in investigating a specific function or data structure within a page table entry (PTE) context related to Non-Aligned Page Offset Table (NAPOT) configurations. It's likely I'm trying to understand how the memory management unit (MMU) handles or interacts with this specific NAPOT optimization. I need to figure out what functionality or context uses `pte_napot`. Is it related to a specific architecture, virtual machine layer, or hypervisor? I'm hoping this search will lead me directly to the relevant kernel code, header files, or documentation that illuminates the implementation details and usage scenarios. I suspect I might be dealing with either a performance optimization or a particular hardware feature and I need to see how its implemented to understand its capabilities.



69/2 2026/05/25 00:13 tool grepper
0m Args:
map[Expression:pte_napot]

Results:
map[Output:arch/riscv/include/asm/pgtable.h=276=static __always_inline bool has_svnapot(void)
--
arch/riscv/include/asm/pgtable.h-280-
arch/riscv/include/asm/pgtable.h:281:static inline unsigned long pte_napot(pte_t pte)
arch/riscv/include/asm/pgtable.h-282-{
--
arch/riscv/include/asm/pgtable.h=297=static __always_inline bool has_svnapot(void) { return false; }
arch/riscv/include/asm/pgtable.h-298-
arch/riscv/include/asm/pgtable.h:299:static inline unsigned long pte_napot(pte_t pte)
arch/riscv/include/asm/pgtable.h-300-{
--
arch/riscv/include/asm/pgtable.h=307=static inline unsigned long pte_pfn(pte_t pte)
--
arch/riscv/include/asm/pgtable.h-310-
arch/riscv/include/asm/pgtable.h:311:	if (has_svnapot() && pte_napot(pte))
arch/riscv/include/asm/pgtable.h-312-		res = res & (res - 1UL);
--
arch/riscv/include/asm/pgtable.h=515=static inline pte_t pte_swp_clear_soft_dirty(pte_t pte)
--
arch/riscv/include/asm/pgtable.h-521-#ifdef CONFIG_RISCV_ISA_SVNAPOT
arch/riscv/include/asm/pgtable.h:522:#define pte_leaf_size(pte)	(pte_napot(pte) ?				\
arch/riscv/include/asm/pgtable.h-523-					napot_cont_size(napot_cont_order(pte)) :\
--
arch/riscv/mm/hugetlbpage.c=6=pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
--
arch/riscv/mm/hugetlbpage.c-11-
arch/riscv/mm/hugetlbpage.c:12:	if (!pte_present(orig_pte) || !pte_napot(orig_pte))
arch/riscv/mm/hugetlbpage.c-13-		return orig_pte;
--
arch/riscv/mm/hugetlbpage.c=246=void set_huge_pte_at(struct mm_struct *mm,
--
arch/riscv/mm/hugetlbpage.c-262-
arch/riscv/mm/hugetlbpage.c:263:	if (!pte_napot(pte)) {
arch/riscv/mm/hugetlbpage.c-264-		set_ptes(mm, addr, ptep, pte, 1);
--
arch/riscv/mm/hugetlbpage.c=274=int huge_ptep_set_access_flags(struct vm_area_struct *vma,
--
arch/riscv/mm/hugetlbpage.c-284-
arch/riscv/mm/hugetlbpage.c:285:	if (!pte_napot(pte))
arch/riscv/mm/hugetlbpage.c-286-		return ptep_set_access_flags(vma, addr, ptep, pte, dirty);
--
arch/riscv/mm/hugetlbpage.c=305=pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
--
arch/riscv/mm/hugetlbpage.c-312-
arch/riscv/mm/hugetlbpage.c:313:	if (!pte_napot(orig_pte))
arch/riscv/mm/hugetlbpage.c-314-		return ptep_get_and_clear(mm, addr, ptep);
--
arch/riscv/mm/hugetlbpage.c=321=void huge_ptep_set_wrprotect(struct mm_struct *mm,
--
arch/riscv/mm/hugetlbpage.c-329-
arch/riscv/mm/hugetlbpage.c:330:	if (!pte_napot(pte)) {
arch/riscv/mm/hugetlbpage.c-331-		ptep_set_wrprotect(mm, addr, ptep);
--
arch/riscv/mm/hugetlbpage.c=346=pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
--
arch/riscv/mm/hugetlbpage.c-352-
arch/riscv/mm/hugetlbpage.c:353:	if (!pte_napot(pte))
arch/riscv/mm/hugetlbpage.c-354-		return ptep_clear_flush(vma, addr, ptep);
--
arch/riscv/mm/hugetlbpage.c=361=void huge_pte_clear(struct mm_struct *mm,
--
arch/riscv/mm/hugetlbpage.c-369-
arch/riscv/mm/hugetlbpage.c:370:	if (!pte_napot(pte)) {
arch/riscv/mm/hugetlbpage.c-371-		pte_clear(mm, addr, ptep);
]

70/2 2026/05/25 00:14 llm expert
1m Model:
gemini-3.1-pro-preview

Tokens:
							input: 47167
							output: 46
							thoughts: 12
						

Thoughts:
Okay, let's dive into this. Here's my thought process summarized, assuming I'm already pretty familiar with the general topic:

**Analyzing the `pte_napot` Definition**

Alright, my immediate thought is to get a clearer picture of what `pte_napot` actually represents. It's a term that's clearly important, likely related to page table entries, but I need to quickly refresh my understanding and nail down the precise meaning. I need to understand this very specifically. My expert knowledge demands clarity; ambiguity isn't an option when dealing with this level of detail. I'm going to look up the definition, and that's the next step.



71/2 2026/05/25 00:17 tool codesearch-definition-source
1m Error:
requested entity does not exist

Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:pte_napot]

Results:
map[SourceCode: SourceFile:]

72/2 2026/05/25 00:20 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 47390
							output: 28
							thoughts: 35
						

Thoughts:
Here's my take on the thought process, summarized as you requested:

**Deconstructing the Inline Function**

Okay, so I see it's an inline function. That immediately narrows the scope of investigation, but I need to understand its exact behavior. Let me see... I should check the header file for the architecture in question, specifically `arch/riscv/include/asm/pgtable.h`. I'll focus on line 281 and its surrounding context. That should give me the core definition and any relevant macros or dependencies related to this inline function. From there, I can analyze the code.



73/2 2026/05/25 00:20 tool read-file
0m Args:
map[File:arch/riscv/include/asm/pgtable.h]

Results:
map[Contents:/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (C) 2012 Regents of the University of California
 */

#ifndef _ASM_RISCV_PGTABLE_H
#define _ASM_RISCV_PGTABLE_H

#include <linux/mmzone.h>
#include <linux/sizes.h>

#include <asm/pgtable-bits.h>

#ifndef CONFIG_MMU
#ifdef CONFIG_RELOCATABLE
#define KERNEL_LINK_ADDR	UL(0)
#else
#define KERNEL_LINK_ADDR	_AC(CONFIG_PHYS_RAM_BASE, UL)
#endif
#define KERN_VIRT_SIZE		(UL(-1))
#else

#define ADDRESS_SPACE_END	(UL(-1))

#ifdef CONFIG_64BIT
/* Leave 2GB for kernel and BPF at the end of the address space */
#define KERNEL_LINK_ADDR	(ADDRESS_SPACE_END - SZ_2G + 1)
#else
#define KERNEL_LINK_ADDR	PAGE_OFFSET
#endif

/* Number of entries in the page global directory */
#define PTRS_PER_PGD    (PAGE_SIZE / sizeof(pgd_t))
/* Number of entries in the page table */
#define PTRS_PER_PTE    (PAGE_SIZE / sizeof(pte_t))

/*
 * Half of the kernel address space (1/4 of the entries of the page global
 * directory) is for the direct mapping.
 */
#define KERN_VIRT_SIZE          ((PTRS_PER_PGD / 2 * PGDIR_SIZE) / 2)

#define VMALLOC_SIZE     (KERN_VIRT_SIZE >> 1)
#define VMALLOC_END      PAGE_OFFSET
#define VMALLOC_START    (PAGE_OFFSET - VMALLOC_SIZE)

#define BPF_JIT_REGION_SIZE	(SZ_128M)
#ifdef CONFIG_64BIT
#define BPF_JIT_REGION_START	(BPF_JIT_REGION_END - BPF_JIT_REGION_SIZE)
#define BPF_JIT_REGION_END	(MODULES_END)
#else
#define BPF_JIT_REGION_START	(PAGE_OFFSET - BPF_JIT_REGION_SIZE)
#define BPF_JIT_REGION_END	(VMALLOC_END)
#endif

/* Modules always live before the kernel */
#ifdef CONFIG_64BIT
/* This is used to define the end of the KASAN shadow region */
#define MODULES_LOWEST_VADDR	(KERNEL_LINK_ADDR - SZ_2G)
#define MODULES_VADDR		(PFN_ALIGN((unsigned long)&_end) - SZ_2G)
#define MODULES_END		(PFN_ALIGN((unsigned long)&_start))
#else
#define MODULES_VADDR		VMALLOC_START
#define MODULES_END		VMALLOC_END
#endif

/*
 * Roughly size the vmemmap space to be large enough to fit enough
 * struct pages to map half the virtual address space. Then
 * position vmemmap directly below the VMALLOC region.
 */
#define VA_BITS_SV32 32
#ifdef CONFIG_64BIT
#define VA_BITS_SV39 39
#define VA_BITS_SV48 48
#define VA_BITS_SV57 57

#define VA_BITS		(pgtable_l5_enabled ? \
				VA_BITS_SV57 : (pgtable_l4_enabled ? VA_BITS_SV48 : VA_BITS_SV39))
#else
#define VA_BITS		VA_BITS_SV32
#endif

#define VMEMMAP_SHIFT \
	(VA_BITS - PAGE_SHIFT - 1 + STRUCT_PAGE_MAX_SHIFT)
#define VMEMMAP_SIZE	BIT(VMEMMAP_SHIFT)
#define VMEMMAP_END	VMALLOC_START
#define VMEMMAP_START	(VMALLOC_START - VMEMMAP_SIZE)

/*
 * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
 * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
 */
#define vmemmap		((struct page *)VMEMMAP_START - vmemmap_start_pfn)

#define PCI_IO_SIZE      SZ_16M
#define PCI_IO_END       VMEMMAP_START
#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)

#define FIXADDR_TOP      PCI_IO_START
#ifdef CONFIG_64BIT
#define MAX_FDT_SIZE	 PMD_SIZE
#define FIX_FDT_SIZE	 (MAX_FDT_SIZE + SZ_2M)
#define FIXADDR_SIZE     (PMD_SIZE + FIX_FDT_SIZE)
#else
#define MAX_FDT_SIZE	 PGDIR_SIZE
#define FIX_FDT_SIZE	 MAX_FDT_SIZE
#define FIXADDR_SIZE     (PGDIR_SIZE + FIX_FDT_SIZE)
#endif
#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)

#endif

#ifndef __ASSEMBLER__

#include <asm/page.h>
#include <asm/tlbflush.h>
#include <linux/mm_types.h>
#include <asm/compat.h>
#include <asm/cpufeature.h>

#define __page_val_to_pfn(_val)  (((_val) & _PAGE_PFN_MASK) >> _PAGE_PFN_SHIFT)

#ifdef CONFIG_64BIT
#include <asm/pgtable-64.h>

#define MMAP_VA_BITS_64 ((VA_BITS >= VA_BITS_SV48) ? VA_BITS_SV48 : VA_BITS)
#define MMAP_MIN_VA_BITS_64 (VA_BITS_SV39)
#define MMAP_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_VA_BITS_64)
#define MMAP_MIN_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_MIN_VA_BITS_64)
#else
#include <asm/pgtable-32.h>
#endif /* CONFIG_64BIT */

#include <linux/page_table_check.h>

struct pt_alloc_ops {
	pte_t *(*get_pte_virt)(phys_addr_t pa);
	phys_addr_t (*alloc_pte)(uintptr_t va);
#ifndef __PAGETABLE_PMD_FOLDED
	pmd_t *(*get_pmd_virt)(phys_addr_t pa);
	phys_addr_t (*alloc_pmd)(uintptr_t va);
	pud_t *(*get_pud_virt)(phys_addr_t pa);
	phys_addr_t (*alloc_pud)(uintptr_t va);
	p4d_t *(*get_p4d_virt)(phys_addr_t pa);
	phys_addr_t (*alloc_p4d)(uintptr_t va);
#endif
};

extern struct pt_alloc_ops pt_ops __meminitdata;

#ifdef CONFIG_MMU
/* Number of PGD entries that a user-mode program can use */
#define USER_PTRS_PER_PGD   (TASK_SIZE / PGDIR_SIZE)

/* Page protection bits */
#define _PAGE_BASE	(_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_USER)

#define PAGE_NONE		__pgprot(_PAGE_PROT_NONE | _PAGE_READ)
#define PAGE_READ		__pgprot(_PAGE_BASE | _PAGE_READ)
#define PAGE_WRITE		__pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_WRITE)
#define PAGE_EXEC		__pgprot(_PAGE_BASE | _PAGE_EXEC)
#define PAGE_READ_EXEC		__pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_EXEC)
#define PAGE_WRITE_EXEC		__pgprot(_PAGE_BASE | _PAGE_READ |	\
					 _PAGE_EXEC | _PAGE_WRITE)
#define PAGE_SHADOWSTACK       __pgprot(_PAGE_BASE | _PAGE_WRITE)

#define PAGE_COPY		PAGE_READ
#define PAGE_COPY_EXEC		PAGE_READ_EXEC
#define PAGE_SHARED		PAGE_WRITE
#define PAGE_SHARED_EXEC	PAGE_WRITE_EXEC

#define _PAGE_KERNEL		(_PAGE_READ \
				| _PAGE_WRITE \
				| _PAGE_PRESENT \
				| _PAGE_ACCESSED \
				| _PAGE_DIRTY \
				| _PAGE_GLOBAL)

#define PAGE_KERNEL		__pgprot(_PAGE_KERNEL)
#define PAGE_KERNEL_READ	__pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
#define PAGE_KERNEL_EXEC	__pgprot(_PAGE_KERNEL | _PAGE_EXEC)
#define PAGE_KERNEL_READ_EXEC	__pgprot((_PAGE_KERNEL & ~_PAGE_WRITE) \
					 | _PAGE_EXEC)

#define PAGE_TABLE		__pgprot(_PAGE_TABLE)

#define _PAGE_KERNEL_NC ((_PAGE_KERNEL & ~_PAGE_MTMASK) | _PAGE_NOCACHE)
#define _PAGE_IOREMAP	((_PAGE_KERNEL & ~_PAGE_MTMASK) | _PAGE_IO)
#define PAGE_KERNEL_IO		__pgprot(_PAGE_IOREMAP)

extern pgd_t swapper_pg_dir[];
extern pgd_t trampoline_pg_dir[];
extern pgd_t early_pg_dir[];

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
static inline int pmd_present(pmd_t pmd)
{
	/*
	 * Checking for _PAGE_LEAF is needed too because:
	 * When splitting a THP, split_huge_page() will temporarily clear
	 * the present bit, in this situation, pmd_present() and
	 * pmd_trans_huge() still needs to return true.
	 */
	return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE | _PAGE_LEAF));
}
#else
static inline int pmd_present(pmd_t pmd)
{
	return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
}
#endif

static inline int pmd_none(pmd_t pmd)
{
	return (pmd_val(pmd) == 0);
}

static inline int pmd_bad(pmd_t pmd)
{
	return !pmd_present(pmd) || (pmd_val(pmd) & _PAGE_LEAF);
}

#define pmd_leaf	pmd_leaf
static inline bool pmd_leaf(pmd_t pmd)
{
	return pmd_present(pmd) && (pmd_val(pmd) & _PAGE_LEAF);
}

static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
{
	WRITE_ONCE(*pmdp, pmd);
}

static inline void pmd_clear(pmd_t *pmdp)
{
	set_pmd(pmdp, __pmd(0));
}

static inline pgd_t pfn_pgd(unsigned long pfn, pgprot_t prot)
{
	unsigned long prot_val = pgprot_val(prot);

	ALT_THEAD_PMA(prot_val);

	return __pgd((pfn << _PAGE_PFN_SHIFT) | prot_val);
}

static inline unsigned long _pgd_pfn(pgd_t pgd)
{
	return __page_val_to_pfn(pgd_val(pgd));
}

static inline struct page *pmd_page(pmd_t pmd)
{
	return pfn_to_page(__page_val_to_pfn(pmd_val(pmd)));
}

static inline unsigned long pmd_page_vaddr(pmd_t pmd)
{
	return (unsigned long)pfn_to_virt(__page_val_to_pfn(pmd_val(pmd)));
}

static inline pte_t pmd_pte(pmd_t pmd)
{
	return __pte(pmd_val(pmd));
}

static inline pte_t pud_pte(pud_t pud)
{
	return __pte(pud_val(pud));
}

#ifdef CONFIG_RISCV_ISA_SVNAPOT

static __always_inline bool has_svnapot(void)
{
	return riscv_has_extension_likely(RISCV_ISA_EXT_SVNAPOT);
}

static inline unsigned long pte_napot(pte_t pte)
{
	return pte_val(pte) & _PAGE_NAPOT;
}

static inline pte_t pte_mknapot(pte_t pte, unsigned int order)
{
	int pos = order - 1 + _PAGE_PFN_SHIFT;
	unsigned long napot_bit = BIT(pos);
	unsigned long napot_mask = ~GENMASK(pos, _PAGE_PFN_SHIFT);

	return __pte((pte_val(pte) & napot_mask) | napot_bit | _PAGE_NAPOT);
}

#else

static __always_inline bool has_svnapot(void) { return false; }

static inline unsigned long pte_napot(pte_t pte)
{
	return 0;
}

#endif /* CONFIG_RISCV_ISA_SVNAPOT */

/* Yields the page frame number (PFN) of a page table entry */
static inline unsigned long pte_pfn(pte_t pte)
{
	unsigned long res  = __page_val_to_pfn(pte_val(pte));

	if (has_svnapot() && pte_napot(pte))
		res = res & (res - 1UL);

	return res;
}

#define pte_page(x)     pfn_to_page(pte_pfn(x))

/* Constructs a page table entry */
static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
{
	unsigned long prot_val = pgprot_val(prot);

	ALT_THEAD_PMA(prot_val);

	return __pte((pfn << _PAGE_PFN_SHIFT) | prot_val);
}

#define pte_pgprot pte_pgprot
static inline pgprot_t pte_pgprot(pte_t pte)
{
	unsigned long pfn = pte_pfn(pte);

	return __pgprot(pte_val(pfn_pte(pfn, __pgprot(0))) ^ pte_val(pte));
}

static inline int pte_present(pte_t pte)
{
	return (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
}

#define pte_accessible pte_accessible
static inline unsigned long pte_accessible(struct mm_struct *mm, pte_t a)
{
	if (pte_val(a) & _PAGE_PRESENT)
		return true;

	if ((pte_val(a) & _PAGE_PROT_NONE) &&
	    atomic_read(&mm->tlb_flush_pending))
		return true;

	return false;
}

static inline int pte_none(pte_t pte)
{
	return (pte_val(pte) == 0);
}

static inline int pte_write(pte_t pte)
{
	return pte_val(pte) & _PAGE_WRITE;
}

static inline int pte_exec(pte_t pte)
{
	return pte_val(pte) & _PAGE_EXEC;
}

static inline int pte_user(pte_t pte)
{
	return pte_val(pte) & _PAGE_USER;
}

static inline int pte_huge(pte_t pte)
{
	return pte_present(pte) && (pte_val(pte) & _PAGE_LEAF);
}

static inline int pte_dirty(pte_t pte)
{
	return pte_val(pte) & _PAGE_DIRTY;
}

static inline int pte_young(pte_t pte)
{
	return pte_val(pte) & _PAGE_ACCESSED;
}

static inline int pte_special(pte_t pte)
{
	return pte_val(pte) & _PAGE_SPECIAL;
}

/* static inline pte_t pte_rdprotect(pte_t pte) */

static inline pte_t pte_wrprotect(pte_t pte)
{
	return __pte((pte_val(pte) & ~(_PAGE_WRITE)) | (_PAGE_READ));
}

#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
#define pgtable_supports_uffd_wp()	\
	riscv_has_extension_unlikely(RISCV_ISA_EXT_SVRSW60T59B)

static inline bool pte_uffd_wp(pte_t pte)
{
	return !!(pte_val(pte) & _PAGE_UFFD_WP);
}

static inline pte_t pte_mkuffd_wp(pte_t pte)
{
	return pte_wrprotect(__pte(pte_val(pte) | _PAGE_UFFD_WP));
}

static inline pte_t pte_clear_uffd_wp(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_UFFD_WP));
}

static inline bool pte_swp_uffd_wp(pte_t pte)
{
	return !!(pte_val(pte) & _PAGE_SWP_UFFD_WP);
}

static inline pte_t pte_swp_mkuffd_wp(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SWP_UFFD_WP);
}

static inline pte_t pte_swp_clear_uffd_wp(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_SWP_UFFD_WP));
}
#endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */

/* static inline pte_t pte_mkread(pte_t pte) */

struct vm_area_struct;
pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma);
#define pte_mkwrite pte_mkwrite

static inline pte_t pte_mkwrite_novma(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_WRITE);
}

static inline pte_t pte_mkwrite_shstk(pte_t pte)
{
	return __pte((pte_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE);
}

/* static inline pte_t pte_mkexec(pte_t pte) */

static inline pte_t pte_mkdirty(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_DIRTY | _PAGE_SOFT_DIRTY);
}

static inline pte_t pte_mkclean(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_DIRTY));
}

static inline pte_t pte_mkyoung(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_ACCESSED);
}

static inline pte_t pte_mkold(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_ACCESSED));
}

static inline pte_t pte_mkspecial(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SPECIAL);
}

static inline pte_t pte_mkhuge(pte_t pte)
{
	return pte;
}

#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
#define pgtable_supports_soft_dirty()				\
	(IS_ENABLED(CONFIG_MEM_SOFT_DIRTY) &&			\
	 riscv_has_extension_unlikely(RISCV_ISA_EXT_SVRSW60T59B))

static inline bool pte_soft_dirty(pte_t pte)
{
	return !!(pte_val(pte) & _PAGE_SOFT_DIRTY);
}

static inline pte_t pte_mksoft_dirty(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SOFT_DIRTY);
}

static inline pte_t pte_clear_soft_dirty(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_SOFT_DIRTY));
}

static inline bool pte_swp_soft_dirty(pte_t pte)
{
	return !!(pte_val(pte) & _PAGE_SWP_SOFT_DIRTY);
}

static inline pte_t pte_swp_mksoft_dirty(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SWP_SOFT_DIRTY);
}

static inline pte_t pte_swp_clear_soft_dirty(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_SWP_SOFT_DIRTY));
}
#endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */

#ifdef CONFIG_RISCV_ISA_SVNAPOT
#define pte_leaf_size(pte)	(pte_napot(pte) ?				\
					napot_cont_size(napot_cont_order(pte)) :\
					PAGE_SIZE)
#endif

#ifdef CONFIG_NUMA_BALANCING
/*
 * See the comment in include/asm-generic/pgtable.h
 */
static inline int pte_protnone(pte_t pte)
{
	return (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROT_NONE)) == _PAGE_PROT_NONE;
}

static inline int pmd_protnone(pmd_t pmd)
{
	return pte_protnone(pmd_pte(pmd));
}
#endif

/* Modify page protection bits */
static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
{
	unsigned long newprot_val = pgprot_val(newprot);

	ALT_THEAD_PMA(newprot_val);

	return __pte((pte_val(pte) & _PAGE_CHG_MASK) | newprot_val);
}

#define pgd_ERROR(e) \
	pr_err("%s:%d: bad pgd " PTE_FMT ".\n", __FILE__, __LINE__, pgd_val(e))


/* Commit new configuration to MMU hardware */
static inline void update_mmu_cache_range(struct vm_fault *vmf,
		struct vm_area_struct *vma, unsigned long address,
		pte_t *ptep, unsigned int nr)
{
	/*
	 * Svvptc guarantees that the new valid pte will be visible within
	 * a bounded timeframe, so when the uarch does not cache invalid
	 * entries, we don't have to do anything.
	 */
	if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SVVPTC))
		return;

	/*
	 * The kernel assumes that TLBs don't cache invalid entries, but
	 * in RISC-V, SFENCE.VMA specifies an ordering constraint, not a
	 * cache flush; it is necessary even after writing invalid entries.
	 * Relying on flush_tlb_fix_spurious_fault would suffice, but
	 * the extra traps reduce performance.  So, eagerly SFENCE.VMA.
	 */
	while (nr--)
		local_flush_tlb_page(address + nr * PAGE_SIZE);

}
#define update_mmu_cache(vma, addr, ptep) \
	update_mmu_cache_range(NULL, vma, addr, ptep, 1)

#define update_mmu_tlb_range(vma, addr, ptep, nr) \
	update_mmu_cache_range(NULL, vma, addr, ptep, nr)

static inline void update_mmu_cache_pmd(struct vm_area_struct *vma,
		unsigned long address, pmd_t *pmdp)
{
	pte_t *ptep = (pte_t *)pmdp;

	update_mmu_cache(vma, address, ptep);
}

#define __HAVE_ARCH_PTE_SAME
static inline int pte_same(pte_t pte_a, pte_t pte_b)
{
	return pte_val(pte_a) == pte_val(pte_b);
}

/*
 * Certain architectures need to do special things when PTEs within
 * a page table are directly modified.  Thus, the following hook is
 * made available.
 */
static inline void set_pte(pte_t *ptep, pte_t pteval)
{
	WRITE_ONCE(*ptep, pteval);
}

void flush_icache_pte(struct mm_struct *mm, pte_t pte);

static inline void __set_pte_at(struct mm_struct *mm, pte_t *ptep, pte_t pteval)
{
	if (pte_present(pteval) && pte_exec(pteval))
		flush_icache_pte(mm, pteval);

	set_pte(ptep, pteval);
}

#define PFN_PTE_SHIFT		_PAGE_PFN_SHIFT

static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
		pte_t *ptep, pte_t pteval, unsigned int nr)
{
	page_table_check_ptes_set(mm, addr, ptep, pteval, nr);

	for (;;) {
		__set_pte_at(mm, ptep, pteval);
		if (--nr == 0)
			break;
		ptep++;
		pte_val(pteval) += 1 << _PAGE_PFN_SHIFT;
	}
}
#define set_ptes set_ptes

static inline void pte_clear(struct mm_struct *mm,
	unsigned long addr, pte_t *ptep)
{
	__set_pte_at(mm, ptep, __pte(0));
}

#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS	/* defined in mm/pgtable.c */
extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
				 pte_t *ptep, pte_t entry, int dirty);
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG	/* defined in mm/pgtable.c */
bool ptep_test_and_clear_young(struct vm_area_struct *vma,
		unsigned long address, pte_t *ptep);

#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
				       unsigned long address, pte_t *ptep)
{
#ifdef CONFIG_SMP
	pte_t pte = __pte(xchg(&ptep->pte, 0));
#else
	pte_t pte = *ptep;

	set_pte(ptep, __pte(0));
#endif

	page_table_check_pte_clear(mm, address, pte);

	return pte;
}

#define __HAVE_ARCH_PTEP_SET_WRPROTECT
static inline void ptep_set_wrprotect(struct mm_struct *mm,
				      unsigned long address, pte_t *ptep)
{
	pte_t read_pte = READ_ONCE(*ptep);
	/*
	 * ptep_set_wrprotect can be called for shadow stack ranges too.
	 * shadow stack memory is XWR = 010 and thus clearing _PAGE_WRITE will lead to
	 * encoding 000b which is wrong encoding with V = 1. This should lead to page fault
	 * but we dont want this wrong configuration to be set in page tables.
	 */
	atomic_long_set((atomic_long_t *)ptep,
			((pte_val(read_pte) & ~(unsigned long)_PAGE_WRITE) | _PAGE_READ));
}

#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
		unsigned long address, pte_t *ptep)
{
	/*
	 * This comment is borrowed from x86, but applies equally to RISC-V:
	 *
	 * Clearing the accessed bit without a TLB flush
	 * doesn't cause data corruption. [ It could cause incorrect
	 * page aging and the (mistaken) reclaim of hot pages, but the
	 * chance of that should be relatively low. ]
	 *
	 * So as a performance optimization don't flush the TLB when
	 * clearing the accessed bit, it will eventually be flushed by
	 * a context switch or a VM operation anyway. [ In the rare
	 * event of it not getting flushed for a long time the delay
	 * shouldn't really matter because there's no real memory
	 * pressure for swapout to react to. ]
	 */
	return ptep_test_and_clear_young(vma, address, ptep);
}

#define pgprot_nx pgprot_nx
static inline pgprot_t pgprot_nx(pgprot_t _prot)
{
	return __pgprot(pgprot_val(_prot) & ~_PAGE_EXEC);
}

#define pgprot_noncached pgprot_noncached
static inline pgprot_t pgprot_noncached(pgprot_t _prot)
{
	unsigned long prot = pgprot_val(_prot);

	prot &= ~_PAGE_MTMASK;
	prot |= _PAGE_IO;

	return __pgprot(prot);
}

#define pgprot_writecombine pgprot_writecombine
static inline pgprot_t pgprot_writecombine(pgprot_t _prot)
{
	unsigned long prot = pgprot_val(_prot);

	prot &= ~_PAGE_MTMASK;
	prot |= _PAGE_NOCACHE;

	return __pgprot(prot);
}

#define pgprot_dmacoherent pgprot_writecombine

/*
 * Both Svade and Svadu control the hardware behavior when the PTE A/D bits need to be set. By
 * default the M-mode firmware enables the hardware updating scheme when only Svadu is present in
 * DT.
 */
#define arch_has_hw_pte_young arch_has_hw_pte_young
static inline bool arch_has_hw_pte_young(void)
{
	return riscv_has_extension_unlikely(RISCV_ISA_EXT_SVADU);
}

/*
 * THP functions
 */
static inline pmd_t pte_pmd(pte_t pte)
{
	return __pmd(pte_val(pte));
}

static inline pud_t pte_pud(pte_t pte)
{
	return __pud(pte_val(pte));
}

static inline pmd_t pmd_mkhuge(pmd_t pmd)
{
	return pmd;
}

static inline pmd_t pmd_mkinvalid(pmd_t pmd)
{
	return __pmd(pmd_val(pmd) & ~(_PAGE_PRESENT|_PAGE_PROT_NONE));
}

#define __pmd_to_phys(pmd)  (__page_val_to_pfn(pmd_val(pmd)) << PAGE_SHIFT)

static inline unsigned long pmd_pfn(pmd_t pmd)
{
	return ((__pmd_to_phys(pmd) & PMD_MASK) >> PAGE_SHIFT);
}

#define __pud_to_phys(pud)  (__page_val_to_pfn(pud_val(pud)) << PAGE_SHIFT)

#define pud_pfn pud_pfn
static inline unsigned long pud_pfn(pud_t pud)
{
	return ((__pud_to_phys(pud) & PUD_MASK) >> PAGE_SHIFT);
}

#define pmd_pgprot pmd_pgprot
static inline pgprot_t pmd_pgprot(pmd_t pmd)
{
	return pte_pgprot(pmd_pte(pmd));
}

#define pud_pgprot pud_pgprot
static inline pgprot_t pud_pgprot(pud_t pud)
{
	return pte_pgprot(pud_pte(pud));
}

static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
{
	return pte_pmd(pte_modify(pmd_pte(pmd), newprot));
}

#define pmd_write pmd_write
static inline int pmd_write(pmd_t pmd)
{
	return pte_write(pmd_pte(pmd));
}

#define pud_write pud_write
static inline int pud_write(pud_t pud)
{
	return pte_write(pud_pte(pud));
}

#define pmd_dirty pmd_dirty
static inline int pmd_dirty(pmd_t pmd)
{
	return pte_dirty(pmd_pte(pmd));
}

#define pmd_young pmd_young
static inline int pmd_young(pmd_t pmd)
{
	return pte_young(pmd_pte(pmd));
}

static inline int pmd_user(pmd_t pmd)
{
	return pte_user(pmd_pte(pmd));
}

static inline pmd_t pmd_mkold(pmd_t pmd)
{
	return pte_pmd(pte_mkold(pmd_pte(pmd)));
}

static inline pmd_t pmd_mkyoung(pmd_t pmd)
{
	return pte_pmd(pte_mkyoung(pmd_pte(pmd)));
}

pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
#define pmd_mkwrite pmd_mkwrite

static inline pmd_t pmd_mkwrite_novma(pmd_t pmd)
{
	return pte_pmd(pte_mkwrite_novma(pmd_pte(pmd)));
}

static inline pmd_t pmd_mkwrite_shstk(pmd_t pte)
{
	return __pmd((pmd_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE);
}

static inline pmd_t pmd_wrprotect(pmd_t pmd)
{
	return pte_pmd(pte_wrprotect(pmd_pte(pmd)));
}

static inline pmd_t pmd_mkclean(pmd_t pmd)
{
	return pte_pmd(pte_mkclean(pmd_pte(pmd)));
}

static inline pmd_t pmd_mkdirty(pmd_t pmd)
{
	return pte_pmd(pte_mkdirty(pmd_pte(pmd)));
}

#ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP
static inline bool pmd_special(pmd_t pmd)
{
	return pte_special(pmd_pte(pmd));
}

static inline pmd_t pmd_mkspecial(pmd_t pmd)
{
	return pte_pmd(pte_mkspecial(pmd_pte(pmd)));
}
#endif

#ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP
static inline bool pud_special(pud_t pud)
{
	return pte_special(pud_pte(pud));
}

static inline pud_t pud_mkspecial(pud_t pud)
{
	return pte_pud(pte_mkspecial(pud_pte(pud)));
}
#endif

#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
static inline bool pmd_uffd_wp(pmd_t pmd)
{
	return pte_uffd_wp(pmd_pte(pmd));
}

static inline pmd_t pmd_mkuffd_wp(pmd_t pmd)
{
	return pte_pmd(pte_mkuffd_wp(pmd_pte(pmd)));
}

static inline pmd_t pmd_clear_uffd_wp(pmd_t pmd)
{
	return pte_pmd(pte_clear_uffd_wp(pmd_pte(pmd)));
}

static inline bool pmd_swp_uffd_wp(pmd_t pmd)
{
	return pte_swp_uffd_wp(pmd_pte(pmd));
}

static inline pmd_t pmd_swp_mkuffd_wp(pmd_t pmd)
{
	return pte_pmd(pte_swp_mkuffd_wp(pmd_pte(pmd)));
}

static inline pmd_t pmd_swp_clear_uffd_wp(pmd_t pmd)
{
	return pte_pmd(pte_swp_clear_uffd_wp(pmd_pte(pmd)));
}
#endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */

#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
static inline bool pmd_soft_dirty(pmd_t pmd)
{
	return pte_soft_dirty(pmd_pte(pmd));
}

static inline pmd_t pmd_mksoft_dirty(pmd_t pmd)
{
	return pte_pmd(pte_mksoft_dirty(pmd_pte(pmd)));
}

static inline pmd_t pmd_clear_soft_dirty(pmd_t pmd)
{
	return pte_pmd(pte_clear_soft_dirty(pmd_pte(pmd)));
}

#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION
static inline bool pmd_swp_soft_dirty(pmd_t pmd)
{
	return pte_swp_soft_dirty(pmd_pte(pmd));
}

static inline pmd_t pmd_swp_mksoft_dirty(pmd_t pmd)
{
	return pte_pmd(pte_swp_mksoft_dirty(pmd_pte(pmd)));
}

static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd)
{
	return pte_pmd(pte_swp_clear_soft_dirty(pmd_pte(pmd)));
}
#endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */
#endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */

static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
				pmd_t *pmdp, pmd_t pmd)
{
	page_table_check_pmd_set(mm, addr, pmdp, pmd);
	return __set_pte_at(mm, (pte_t *)pmdp, pmd_pte(pmd));
}

static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
				pud_t *pudp, pud_t pud)
{
	page_table_check_pud_set(mm, addr, pudp, pud);
	return __set_pte_at(mm, (pte_t *)pudp, pud_pte(pud));
}

#ifdef CONFIG_PAGE_TABLE_CHECK
static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
{
	return pte_present(pte) && pte_user(pte);
}

static inline bool pmd_user_accessible_page(struct mm_struct *mm, unsigned long addr, pmd_t pmd)
{
	return pmd_leaf(pmd) && pmd_user(pmd);
}

static inline bool pud_user_accessible_page(struct mm_struct *mm, unsigned long addr, pud_t pud)
{
	return pud_leaf(pud) && pud_user(pud);
}
#endif

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
static inline int pmd_trans_huge(pmd_t pmd)
{
	return pmd_leaf(pmd);
}

#define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
					unsigned long address, pmd_t *pmdp,
					pmd_t entry, int dirty)
{
	return ptep_set_access_flags(vma, address, (pte_t *)pmdp, pmd_pte(entry), dirty);
}

#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
		unsigned long address, pmd_t *pmdp)
{
	return ptep_test_and_clear_young(vma, address, (pte_t *)pmdp);
}

#define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
					unsigned long address, pmd_t *pmdp)
{
#ifdef CONFIG_SMP
	pmd_t pmd = __pmd(xchg(&pmdp->pmd, 0));
#else
	pmd_t pmd = *pmdp;

	pmd_clear(pmdp);
#endif

	page_table_check_pmd_clear(mm, address, pmd);

	return pmd;
}

#define __HAVE_ARCH_PMDP_SET_WRPROTECT
static inline void pmdp_set_wrprotect(struct mm_struct *mm,
					unsigned long address, pmd_t *pmdp)
{
	ptep_set_wrprotect(mm, address, (pte_t *)pmdp);
}

#define pmdp_establish pmdp_establish
static inline pmd_t pmdp_establish(struct vm_area_struct *vma,
				unsigned long address, pmd_t *pmdp, pmd_t pmd)
{
	page_table_check_pmd_set(vma->vm_mm, address, pmdp, pmd);
	return __pmd(atomic_long_xchg((atomic_long_t *)pmdp, pmd_val(pmd)));
}

#define pmdp_collapse_flush pmdp_collapse_flush
extern pmd_t pmdp_collapse_flush(struct vm_area_struct *vma,
				 unsigned long address, pmd_t *pmdp);

static inline pud_t pud_wrprotect(pud_t pud)
{
	return pte_pud(pte_wrprotect(pud_pte(pud)));
}

static inline int pud_trans_huge(pud_t pud)
{
	return pud_leaf(pud);
}

static inline int pud_dirty(pud_t pud)
{
	return pte_dirty(pud_pte(pud));
}

static inline pud_t pud_mkyoung(pud_t pud)
{
	return pte_pud(pte_mkyoung(pud_pte(pud)));
}

static inline pud_t pud_mkold(pud_t pud)
{
	return pte_pud(pte_mkold(pud_pte(pud)));
}

static inline pud_t pud_mkdirty(pud_t pud)
{
	return pte_pud(pte_mkdirty(pud_pte(pud)));
}

static inline pud_t pud_mkclean(pud_t pud)
{
	return pte_pud(pte_mkclean(pud_pte(pud)));
}

static inline pud_t pud_mkwrite(pud_t pud)
{
	return pte_pud(pte_mkwrite_novma(pud_pte(pud)));
}

static inline pud_t pud_mkhuge(pud_t pud)
{
	return pud;
}

static inline int pudp_set_access_flags(struct vm_area_struct *vma,
					unsigned long address, pud_t *pudp,
					pud_t entry, int dirty)
{
	return ptep_set_access_flags(vma, address, (pte_t *)pudp, pud_pte(entry), dirty);
}

static inline bool pudp_test_and_clear_young(struct vm_area_struct *vma,
		unsigned long address, pud_t *pudp)
{
	return ptep_test_and_clear_young(vma, address, (pte_t *)pudp);
}

#define __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR
static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm,
					    unsigned long address,  pud_t *pudp)
{
#ifdef CONFIG_SMP
	pud_t pud = __pud(xchg(&pudp->pud, 0));
#else
	pud_t pud = *pudp;

	pud_clear(pudp);
#endif

	page_table_check_pud_clear(mm, address, pud);

	return pud;
}

static inline int pud_young(pud_t pud)
{
	return pte_young(pud_pte(pud));
}

static inline void update_mmu_cache_pud(struct vm_area_struct *vma,
					unsigned long address, pud_t *pudp)
{
	pte_t *ptep = (pte_t *)pudp;

	update_mmu_cache(vma, address, ptep);
}

static inline pud_t pudp_establish(struct vm_area_struct *vma,
				   unsigned long address, pud_t *pudp, pud_t pud)
{
	page_table_check_pud_set(vma->vm_mm, address, pudp, pud);
	return __pud(atomic_long_xchg((atomic_long_t *)pudp, pud_val(pud)));
}

static inline pud_t pud_mkinvalid(pud_t pud)
{
	return __pud(pud_val(pud) & ~(_PAGE_PRESENT | _PAGE_PROT_NONE));
}

extern pud_t pudp_invalidate(struct vm_area_struct *vma, unsigned long address,
			     pud_t *pudp);

static inline pud_t pud_modify(pud_t pud, pgprot_t newprot)
{
	return pte_pud(pte_modify(pud_pte(pud), newprot));
}

#endif /* CONFIG_TRANSPARENT_HUGEPAGE */

/*
 * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that
 * are !pte_none() && !pte_present().
 *
 * Format of swap PTE:
 *	bit            0:	_PAGE_PRESENT (zero)
 *	bit       1 to 2:	(zero)
 *	bit            3:	_PAGE_SWP_SOFT_DIRTY
 *	bit            4:	_PAGE_SWP_UFFD_WP
 *	bit            5:	_PAGE_PROT_NONE (zero)
 *	bit            6:	exclusive marker
 *	bits      7 to 11:	swap type
 *	bits 12 to XLEN-1:	swap offset
 */
#define __SWP_TYPE_SHIFT	7
#define __SWP_TYPE_BITS		5
#define __SWP_TYPE_MASK		((1UL << __SWP_TYPE_BITS) - 1)
#define __SWP_OFFSET_SHIFT	(__SWP_TYPE_BITS + __SWP_TYPE_SHIFT)

#define MAX_SWAPFILES_CHECK()	\
	BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > __SWP_TYPE_BITS)

#define __swp_type(x)	(((x).val >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK)
#define __swp_offset(x)	((x).val >> __SWP_OFFSET_SHIFT)
#define __swp_entry(type, offset) ((swp_entry_t) \
	{ (((type) & __SWP_TYPE_MASK) << __SWP_TYPE_SHIFT) | \
	  ((offset) << __SWP_OFFSET_SHIFT) })

#define __pte_to_swp_entry(pte)	((swp_entry_t) { pte_val(pte) })
#define __swp_entry_to_pte(x)	((pte_t) { (x).val })

static inline bool pte_swp_exclusive(pte_t pte)
{
	return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
}

static inline pte_t pte_swp_mkexclusive(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SWP_EXCLUSIVE);
}

static inline pte_t pte_swp_clear_exclusive(pte_t pte)
{
	return __pte(pte_val(pte) & ~_PAGE_SWP_EXCLUSIVE);
}

#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION
#define __pmd_to_swp_entry(pmd) ((swp_entry_t) { pmd_val(pmd) })
#define __swp_entry_to_pmd(swp) __pmd((swp).val)
#endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */

/*
 * In the RV64 Linux scheme, we give the user half of the virtual-address space
 * and give the kernel the other (upper) half.
 */
#ifdef CONFIG_64BIT
#define KERN_VIRT_START	(-(BIT(VA_BITS)) + TASK_SIZE)
#else
#define KERN_VIRT_START	FIXADDR_START
#endif

/*
 * Task size is 0x4000000000 for RV64 or 0x9fc00000 for RV32.
 * Note that PGDIR_SIZE must evenly divide TASK_SIZE.
 * Task size is:
 * -        0x9fc00000	(~2.5GB) for RV32.
 * -      0x4000000000	( 256GB) for RV64 using SV39 mmu
 * -    0x800000000000	( 128TB) for RV64 using SV48 mmu
 * - 0x100000000000000	(  64PB) for RV64 using SV57 mmu
 *
 * Note that PGDIR_SIZE must evenly divide TASK_SIZE since "RISC-V
 * Instruction Set Manual Volume II: Privileged Architecture" states that
 * "load and store effective addresses, which are 64bits, must have bits
 * 63–48 all equal to bit 47, or else a page-fault exception will occur."
 * Similarly for SV57, bits 63–57 must be equal to bit 56.
 */
#ifdef CONFIG_64BIT
#define TASK_SIZE_64	(PGDIR_SIZE * PTRS_PER_PGD / 2)

#ifdef CONFIG_COMPAT
#define TASK_SIZE_32	(_AC(0x80000000, UL) - PAGE_SIZE)
#define TASK_SIZE	(is_compat_task() ? \
			 TASK_SIZE_32 : TASK_SIZE_64)
#else
#define TASK_SIZE	TASK_SIZE_64
#endif

#else
#define TASK_SIZE	FIXADDR_START
#endif

#else /* CONFIG_MMU */

#define PAGE_SHARED		__pgprot(0)
#define PAGE_KERNEL		__pgprot(0)
#define swapper_pg_dir		NULL
#define TASK_SIZE		_AC(-1, UL)
#define VMALLOC_START		_AC(0, UL)
#define VMALLOC_END		TASK_SIZE

#endif /* !CONFIG_MMU */

extern char _start[];
extern void *_dtb_early_va;
extern uintptr_t _dtb_early_pa;
#define dtb_early_va	_dtb_early_va
#define dtb_early_pa	_dtb_early_pa
extern u64 satp_mode;

void paging_init(void);
void misc_mem_init(void);

/*
 * Use set_p*_safe(), and elide TLB flushing, when confident that *no*
 * TLB flush will be required as a result of the "set". For example, use
 * in scenarios where it is known ahead of time that the routine is
 * setting non-present entries, or re-setting an existing entry to the
 * same value. Otherwise, use the typical "set" helpers and flush the
 * TLB.
 */
#define set_p4d_safe(p4dp, p4d) \
({ \
	WARN_ON_ONCE(p4d_present(*p4dp) && !p4d_same(*p4dp, p4d)); \
	set_p4d(p4dp, p4d); \
})

#define set_pgd_safe(pgdp, pgd) \
({ \
	WARN_ON_ONCE(pgd_present(*pgdp) && !pgd_same(*pgdp, pgd)); \
	set_pgd(pgdp, pgd); \
})
#endif /* !__ASSEMBLER__ */

#endif /* _ASM_RISCV_PGTABLE_H */
]

74/2 2026/05/25 00:21 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 60996
							output: 49
							thoughts: 1031
						

Thoughts:
**Analyzing Potential PTE Clearing Issues in Huge Page Management**

Okay, so I'm looking at this `pte_napot` definition, it's a simple bit check:
```c
static inline unsigned long pte_napot(pte_t pte)
{
	return pte_val(pte) & _PAGE_NAPOT;
}
```
Now, here's the thing that's making me think. If the PTE isn't *present* – like it's a swap entry or has been cleared already – this `pte_napot` function might return incorrect results. The `pte_val(pte)` won't have the `_PAGE_NAPOT` bit set because it's not even a valid page entry.  

I have to stop for a second and think, does a swap entry have the `_PAGE_NAPOT` bit set? No, it uses different bits.

Right, so if `pte_napot` returns false for a swap entry, `huge_pte_clear` only clears one PTE instead of all of them! I know `huge_pte_clear` is called by `__unmap_hugepage_range` or `hugetlb_change_protection`, but that doesn't matter yet. If it only clears one PTE, the other PTEs are left untouched.

But wait, if it's a swap entry, it's *non-present*, so `pte_clear` *should* clear it. Ah, but even if it's non-present, it still has a value (e.g., swap entry information). The problem is, if `huge_pte_clear` only clears the first PTE, all the other PTEs still contain the swap entry! Then when the page is freed. Wait, I guess hugetlb pages don't use swap entries in *exactly* the same way as normal pages, but they can have migration entries or hwpoison entries, which makes this important.

Okay, let's step back and consider the *present* case, if `huge_pte_clear` is called on an actual huge page, then `pte_napot(pte)` is true, so it will clear all PTEs.

But *what if* `huge_pte_clear` is called on a *non-present* PTE? It's like in this commit `83d78ac677b9` that mentions not using the pte value to determine the size if the pte may not be present.

Let me think this through. If `huge_pte_clear` is called on a non-present PTE (like a migration entry), `pte_napot(pte)` is false, and it will only clear the first PTE! This means the other PTEs would still contain the migration entry! When the migration entry is restored, it might restore *all* PTEs, potentially putting a "ghost" of the page there.

Okay, so we're talking about unmap. If `huge_pte_clear` is called during an unmap operation and it only clears the first PTE, the remaining PTEs are left with that migration entry. Then, the page table is freed. If that happens, those PTEs are *never* cleared!

Now, the page table's `page_table_check` has to be considered. It checks when a page is freed. If a page is freed, its `anon_map_count` or `file_map_count` *must* be zero.

So, when a page is mapped, `page_table_check_ptes_set` increments the counter, and when a page is unmapped, `page_table_check_pte_clear` decrements the counter. If `huge_pte_clear` *only* calls `pte_clear` on the *first* PTE, then the counter is only decremented by one!

But, when the page was mapped, `set_huge_pte_at` (in the `arch/riscv/mm/hugetlbpage.c`) called `set_ptes`, which called `page_table_check_ptes_set` for `pte_num` PTEs, incrementing the counter by `pte_num`.  The important part here, from `arch/riscv/mm/hugetlbpage.c`:
```c
	if (!pte_present(pte)) {
		for (i = 0; i < pte_num; i++, ptep++, addr += pgsize)
			set_ptes(mm, addr, ptep, pte, 1);
		return;
	}
```
Okay, *if* the PTE isn't present, `set_huge_pte


75/2 2026/05/25 00:21 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/page_table_check.c IncludeLines:true Name:__page_table_check_ptes_set]

Results:
map[SourceCode: 199:	void __page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr,
 200:					 pte_t *ptep, pte_t pte, unsigned int nr)
 201:	{
 202:		unsigned int i;
 203:	
 204:		if (&init_mm == mm)
 205:			return;
 206:	
 207:		page_table_check_pte_flags(pte);
 208:	
 209:		for (i = 0; i < nr; i++)
 210:			__page_table_check_pte_clear(mm, addr + PAGE_SIZE * i, ptep_get(ptep + i));
 211:		if (pte_user_accessible_page(mm, addr, pte))
 212:			page_table_check_set(pte_pfn(pte), nr, pte_write(pte));
 213:	}
 SourceFile:mm/page_table_check.c]

76/2 2026/05/25 00:21 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 63395
							output: 45
							thoughts: 463
						

Thoughts:
**Analyzing Page Table Entry Clearing in the Kernel**

Okay, so I'm digging into how the kernel handles clearing Page Table Entries (PTEs), particularly around huge pages and migration. The `pte_user_accessible_page` check is key here; it confirms both presence and user access. The immediate thought is that migration entries, being absent, elegantly bypass the counter increment – that's expected.

But then, it hits me: what if the PTE *is* present? When `huge_pte_clear` gets invoked on a *present* PTE, `pte_napot(pte)` becomes the deciding factor. If it's a huge page, that means all the relevant PTEs are cleaned.

However, what if it *isn't* a huge page even if it's present? When would you have a present page but no `_PAGE_NAPOT` bit? It has to be a PMD-sized huge page! Bingo. When `pte_napot` is false, it's a PMD-sized huge page.

Thinking about PMD-sized huge pages, `huge_pte_clear` is called with `sz == PMD_SIZE`, and `pte_num` is correctly calculated as 1 since `pte_num = PMD_SIZE >> PMD_SHIFT = 1`. This makes sense, one PMD entry is being cleared. So far, so good.

But wait, `huge_pte_clear` takes a `pte_t *ptep`. In the PMD case, `ptep` is really a `pmd_t *`! I recall that on RISC-V, `pte_clear` is just a fundamental operation to clear a PTE, and a PMD is just a PTE at a higher level, so the function should be safe. However, I recall that `pte_clear` calls `__page_table_check_pte_clear`, but shouldn't it be `__page_table_check_pmd_clear` for the PMD case? Let's trace it and see.



77/2 2026/05/25 00:21 tool codesearch-definition-source
0m Error:
requested entity does not exist

Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:pte_clear]

Results:
map[SourceCode: SourceFile:]

78/2 2026/05/25 00:21 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 64367
							output: 19
							thoughts: 25
						

Thoughts:
Here's my thought process, summarized as if I were considering this myself:

**Investigating `pte_clear` in RISC-V Page Table Headers**

Okay, time to dig into the RISC-V page table machinery. The task at hand likely involves managing or manipulating page table entries, so the logical starting point is the core definitions. Let me go straight to `arch/riscv/include/asm/pgtable.h`. I'm specifically looking for the implementation or macro definition of `pte_clear`. This is probably a fundamental function or macro that's used to invalidate or clear a page table entry, perhaps marking it as unused or invalidating its associated physical frame. Knowing its implementation will give me insight into how the architecture handles memory mapping invalidation at the lowest level. I'm hoping to quickly grasp how it works – is it a simple bit clear, a more complex operation, or something involving hardware TLB invalidation? I'm curious if it uses atomic instructions. This will influence how I approach the problem.



79/2 2026/05/25 00:21 tool grepper
0m Args:
map[Expression:define pte_clear]

Results:
map[Output:arch/arc/include/asm/pgtable-levels.h-173-#define pte_present(x)		(pte_val(x) & _PAGE_PRESENT)
arch/arc/include/asm/pgtable-levels.h:174:#define pte_clear(mm,addr,ptep)	set_pte_at(mm, addr, ptep, __pte(0))
arch/arc/include/asm/pgtable-levels.h-175-#define pte_page(pte)		pfn_to_page(pte_pfn(pte))
--
arch/arm/include/asm/pgtable.h=151=static inline pte_t *pmd_page_vaddr(pmd_t pmd)
--
arch/arm/include/asm/pgtable.h-162-
arch/arm/include/asm/pgtable.h:163:#define pte_clear(mm,addr,ptep)	set_pte_ext(ptep, __pte(0), 0)
arch/arm/include/asm/pgtable.h-164-
--
arch/arm64/include/asm/pgtable.h=849=static inline unsigned long pmd_page_vaddr(pmd_t pmd)
--
arch/arm64/include/asm/pgtable.h-858-#define pte_set_fixmap_offset(pmd, addr)	pte_set_fixmap(pte_offset_phys(pmd, addr))
arch/arm64/include/asm/pgtable.h:859:#define pte_clear_fixmap()		clear_fixmap(FIX_PTE)
arch/arm64/include/asm/pgtable.h-860-
--
arch/arm64/include/asm/pgtable.h=1919=static inline void clear_young_dirty_ptes(struct vm_area_struct *vma,
--
arch/arm64/include/asm/pgtable.h-1933-#define set_ptes				__set_ptes
arch/arm64/include/asm/pgtable.h:1934:#define pte_clear				__pte_clear
arch/arm64/include/asm/pgtable.h-1935-#define clear_full_ptes				__clear_full_ptes
--
arch/csky/include/asm/pgtable.h-33-#define pmd_page(pmd)	(pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
arch/csky/include/asm/pgtable.h:34:#define pte_clear(mm, addr, ptep)	set_pte((ptep), \
arch/csky/include/asm/pgtable.h-35-	(((unsigned int) addr >= PAGE_OFFSET) ? __pte(_PAGE_GLOBAL) : __pte(0)))
--
arch/m68k/include/asm/motorola_pgtable.h=95=static inline void pud_set(pud_t *pudp, pmd_t *pmdp)
--
arch/m68k/include/asm/motorola_pgtable.h-106-#define pte_present(pte)	(pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROTNONE))
arch/m68k/include/asm/motorola_pgtable.h:107:#define pte_clear(mm,addr,ptep)		({ pte_val(*(ptep)) = 0; })
arch/m68k/include/asm/motorola_pgtable.h-108-
--
arch/microblaze/include/asm/pgtable.h=29=extern pte_t *va_to_pte(unsigned long address);
--
arch/microblaze/include/asm/pgtable.h-211-#define pte_present(pte)	(pte_val(pte) & _PAGE_PRESENT)
arch/microblaze/include/asm/pgtable.h:212:#define pte_clear(mm, addr, ptep) \
arch/microblaze/include/asm/pgtable.h-213-	do { set_pte_at((mm), (addr), (ptep), __pte(0)); } while (0)
--
arch/openrisc/include/asm/pgtable.h=42=extern void paging_init(void);
--
arch/openrisc/include/asm/pgtable.h-183-#define pte_present(x)	(pte_val(x) & _PAGE_PRESENT)
arch/openrisc/include/asm/pgtable.h:184:#define pte_clear(mm, addr, xp)	do { pte_val(*(xp)) = 0; } while (0)
arch/openrisc/include/asm/pgtable.h-185-
--
arch/parisc/include/asm/pgtable.h=263=extern pte_t pg0[];
--
arch/parisc/include/asm/pgtable.h-267-#define pte_user(x)	(pte_val(x) & _PAGE_USER)
arch/parisc/include/asm/pgtable.h:268:#define pte_clear(mm, addr, xp) set_pte_at((mm), (addr), (xp), __pte(0))
arch/parisc/include/asm/pgtable.h-269-
--
arch/powerpc/include/asm/book3s/32/pgtable.h=138=void unmap_kernel_page(unsigned long va);
--
arch/powerpc/include/asm/book3s/32/pgtable.h-212-
arch/powerpc/include/asm/book3s/32/pgtable.h:213:#define pte_clear(mm, addr, ptep) \
arch/powerpc/include/asm/book3s/32/pgtable.h-214-	do { pte_update(mm, addr, ptep, ~_PAGE_HASHPTE, 0, 0); } while (0)
--
arch/sh/include/asm/pgtable_32.h=300=static inline void set_pte(pte_t *ptep, pte_t pte)
--
arch/sh/include/asm/pgtable_32.h-324-
arch/sh/include/asm/pgtable_32.h:325:#define pte_clear(mm, addr, ptep) set_pte(ptep, __pte(0))
arch/sh/include/asm/pgtable_32.h-326-
--
arch/sparc/include/asm/pgtable_64.h=931=static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
--
arch/sparc/include/asm/pgtable_64.h-944-
arch/sparc/include/asm/pgtable_64.h:945:#define pte_clear(mm,addr,ptep)		\
arch/sparc/include/asm/pgtable_64.h-946-	set_pte_at((mm), (addr), (ptep), __pte(0UL))
--
arch/sparc/include/asm/pgtable_64.h-948-#define __HAVE_ARCH_PTE_CLEAR_NOT_PRESENT_FULL
arch/sparc/include/asm/pgtable_64.h:949:#define pte_clear_not_present_full(mm,addr,ptep,fullmm)	\
arch/sparc/include/asm/pgtable_64.h-950-	__set_pte_at((mm), (addr), (ptep), __pte(0UL), (fullmm))
--
arch/um/include/asm/page.h=42=typedef struct { unsigned long pud; } pud_t;
--
arch/um/include/asm/page.h-52-#define pte_set_bits(p, bits) ((p).pte |= (bits))
arch/um/include/asm/page.h:53:#define pte_clear_bits(p, bits) ((p).pte &= ~(bits))
arch/um/include/asm/page.h-54-#define pte_copy(to, from) ((to).pte = (from).pte)
--
arch/um/include/asm/pgtable.h=35=extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
--
arch/um/include/asm/pgtable.h-73-
arch/um/include/asm/pgtable.h:74:#define pte_clear(mm, addr, xp) pte_set_val(*(xp), (phys_t) 0, __pgprot(_PAGE_NEEDSYNC))
arch/um/include/asm/pgtable.h-75-
--
arch/x86/include/asm/pgtable.h=55=extern pmdval_t early_pmd_flags;
--
arch/x86/include/asm/pgtable.h-87-
arch/x86/include/asm/pgtable.h:88:#define pte_clear(mm, addr, ptep)	native_pte_clear(mm, addr, ptep)
arch/x86/include/asm/pgtable.h-89-#define pmd_clear(pmd)			native_pmd_clear(pmd)
--
arch/xtensa/include/asm/pgtable.h=217=static inline void paging_init(void) { }
--
arch/xtensa/include/asm/pgtable.h-237-#endif
arch/xtensa/include/asm/pgtable.h:238:#define pte_clear(mm,addr,ptep)						\
arch/xtensa/include/asm/pgtable.h-239-	do { update_pte(ptep, __pte(_PAGE_CA_INVALID | _PAGE_USER)); } while (0)
]

80/2 2026/05/25 00:21 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 67111
							output: 45
							thoughts: 299
						

Thoughts:
**My Analysis of RISC-V Page Table Clearing**

Okay, hold on a second. I'm looking at the `pte_clear` function defined within `arch/riscv/include/asm/pgtable.h`. Here it is:

```c
static inline void pte_clear(struct mm_struct *mm,
	unsigned long addr, pte_t *ptep)
{
	__set_pte_at(mm, ptep, __pte(0));
}
```

Wait a minute... it uses `__set_pte_at`. I need to be *absolutely* sure about this... Does `__set_pte_at` call `page_table_check_pte_clear`? No, it doesn't! That's... unexpected.

Okay, let's back up and check `ptep_get_and_clear` to see how it's handled there:

```c
static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
				       unsigned long address, pte_t *ptep)
{
#ifdef CONFIG_SMP
	pte_t pte = __pte(xchg(&ptep->pte, 0));
#else
	pte_t pte = *ptep;

	set_pte(ptep, __pte(0));
#endif

	page_table_check_pte_clear(mm, address, pte);

	return pte;
}
```

Aha! Now I see it. *This* function, `ptep_get_and_clear`, *does* call `page_table_check_pte_clear`. So the critical difference is `pte_clear` *does not* and `ptep_get_and_clear` *does*. That's... not what I expected. Let me go back and look at that `pte_clear` one more time. I really need to understand this discrepancy.



81/2 2026/05/25 00:21 tool codesearch-definition-source
0m Error:
requested entity does not exist

Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:pte_clear]

Results:
map[SourceCode: SourceFile:]

82/2 2026/05/25 00:21 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 67914
							output: 28
							thoughts: 26
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Diving into the RISC-V Page Table Definitions**

Okay, let's pull up the `arch/riscv/include/asm/pgtable.h` header. I need to refresh my memory on the specifics of the RISC-V page table structures, particularly around line 500. I'm focusing on that region because it's likely where the core definitions of the page table entries (PTEs) or perhaps some crucial macro definitions relating to their structure and manipulation reside. I'm probably looking for bitfield definitions for things like valid/present bits, read/write/execute permissions, accessed/dirty flags, physical page frame number (PFN) locations, and potentially any architectural extensions that impact the page table format. I need to quickly grasp the organization of the PTEs to understand how memory mappings are being handled, any optimizations used, and potential areas for performance improvements or security considerations in the kernel. I might quickly skim any surrounding comments for context, but I’m really zeroing in on the low-level data structure declarations themselves. I'm assuming that the kernel implements a multi-level page table, so I'm looking for the structure that governs that layout and how each entry is defined.



83/2 2026/05/25 00:21 tool read-file
0m Args:
map[File:arch/riscv/include/asm/pgtable.h]

Results:
map[Contents:/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (C) 2012 Regents of the University of California
 */

#ifndef _ASM_RISCV_PGTABLE_H
#define _ASM_RISCV_PGTABLE_H

#include <linux/mmzone.h>
#include <linux/sizes.h>

#include <asm/pgtable-bits.h>

#ifndef CONFIG_MMU
#ifdef CONFIG_RELOCATABLE
#define KERNEL_LINK_ADDR	UL(0)
#else
#define KERNEL_LINK_ADDR	_AC(CONFIG_PHYS_RAM_BASE, UL)
#endif
#define KERN_VIRT_SIZE		(UL(-1))
#else

#define ADDRESS_SPACE_END	(UL(-1))

#ifdef CONFIG_64BIT
/* Leave 2GB for kernel and BPF at the end of the address space */
#define KERNEL_LINK_ADDR	(ADDRESS_SPACE_END - SZ_2G + 1)
#else
#define KERNEL_LINK_ADDR	PAGE_OFFSET
#endif

/* Number of entries in the page global directory */
#define PTRS_PER_PGD    (PAGE_SIZE / sizeof(pgd_t))
/* Number of entries in the page table */
#define PTRS_PER_PTE    (PAGE_SIZE / sizeof(pte_t))

/*
 * Half of the kernel address space (1/4 of the entries of the page global
 * directory) is for the direct mapping.
 */
#define KERN_VIRT_SIZE          ((PTRS_PER_PGD / 2 * PGDIR_SIZE) / 2)

#define VMALLOC_SIZE     (KERN_VIRT_SIZE >> 1)
#define VMALLOC_END      PAGE_OFFSET
#define VMALLOC_START    (PAGE_OFFSET - VMALLOC_SIZE)

#define BPF_JIT_REGION_SIZE	(SZ_128M)
#ifdef CONFIG_64BIT
#define BPF_JIT_REGION_START	(BPF_JIT_REGION_END - BPF_JIT_REGION_SIZE)
#define BPF_JIT_REGION_END	(MODULES_END)
#else
#define BPF_JIT_REGION_START	(PAGE_OFFSET - BPF_JIT_REGION_SIZE)
#define BPF_JIT_REGION_END	(VMALLOC_END)
#endif

/* Modules always live before the kernel */
#ifdef CONFIG_64BIT
/* This is used to define the end of the KASAN shadow region */
#define MODULES_LOWEST_VADDR	(KERNEL_LINK_ADDR - SZ_2G)
#define MODULES_VADDR		(PFN_ALIGN((unsigned long)&_end) - SZ_2G)
#define MODULES_END		(PFN_ALIGN((unsigned long)&_start))
#else
#define MODULES_VADDR		VMALLOC_START
#define MODULES_END		VMALLOC_END
#endif

/*
 * Roughly size the vmemmap space to be large enough to fit enough
 * struct pages to map half the virtual address space. Then
 * position vmemmap directly below the VMALLOC region.
 */
#define VA_BITS_SV32 32
#ifdef CONFIG_64BIT
#define VA_BITS_SV39 39
#define VA_BITS_SV48 48
#define VA_BITS_SV57 57

#define VA_BITS		(pgtable_l5_enabled ? \
				VA_BITS_SV57 : (pgtable_l4_enabled ? VA_BITS_SV48 : VA_BITS_SV39))
#else
#define VA_BITS		VA_BITS_SV32
#endif

#define VMEMMAP_SHIFT \
	(VA_BITS - PAGE_SHIFT - 1 + STRUCT_PAGE_MAX_SHIFT)
#define VMEMMAP_SIZE	BIT(VMEMMAP_SHIFT)
#define VMEMMAP_END	VMALLOC_START
#define VMEMMAP_START	(VMALLOC_START - VMEMMAP_SIZE)

/*
 * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
 * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
 */
#define vmemmap		((struct page *)VMEMMAP_START - vmemmap_start_pfn)

#define PCI_IO_SIZE      SZ_16M
#define PCI_IO_END       VMEMMAP_START
#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)

#define FIXADDR_TOP      PCI_IO_START
#ifdef CONFIG_64BIT
#define MAX_FDT_SIZE	 PMD_SIZE
#define FIX_FDT_SIZE	 (MAX_FDT_SIZE + SZ_2M)
#define FIXADDR_SIZE     (PMD_SIZE + FIX_FDT_SIZE)
#else
#define MAX_FDT_SIZE	 PGDIR_SIZE
#define FIX_FDT_SIZE	 MAX_FDT_SIZE
#define FIXADDR_SIZE     (PGDIR_SIZE + FIX_FDT_SIZE)
#endif
#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)

#endif

#ifndef __ASSEMBLER__

#include <asm/page.h>
#include <asm/tlbflush.h>
#include <linux/mm_types.h>
#include <asm/compat.h>
#include <asm/cpufeature.h>

#define __page_val_to_pfn(_val)  (((_val) & _PAGE_PFN_MASK) >> _PAGE_PFN_SHIFT)

#ifdef CONFIG_64BIT
#include <asm/pgtable-64.h>

#define MMAP_VA_BITS_64 ((VA_BITS >= VA_BITS_SV48) ? VA_BITS_SV48 : VA_BITS)
#define MMAP_MIN_VA_BITS_64 (VA_BITS_SV39)
#define MMAP_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_VA_BITS_64)
#define MMAP_MIN_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_MIN_VA_BITS_64)
#else
#include <asm/pgtable-32.h>
#endif /* CONFIG_64BIT */

#include <linux/page_table_check.h>

struct pt_alloc_ops {
	pte_t *(*get_pte_virt)(phys_addr_t pa);
	phys_addr_t (*alloc_pte)(uintptr_t va);
#ifndef __PAGETABLE_PMD_FOLDED
	pmd_t *(*get_pmd_virt)(phys_addr_t pa);
	phys_addr_t (*alloc_pmd)(uintptr_t va);
	pud_t *(*get_pud_virt)(phys_addr_t pa);
	phys_addr_t (*alloc_pud)(uintptr_t va);
	p4d_t *(*get_p4d_virt)(phys_addr_t pa);
	phys_addr_t (*alloc_p4d)(uintptr_t va);
#endif
};

extern struct pt_alloc_ops pt_ops __meminitdata;

#ifdef CONFIG_MMU
/* Number of PGD entries that a user-mode program can use */
#define USER_PTRS_PER_PGD   (TASK_SIZE / PGDIR_SIZE)

/* Page protection bits */
#define _PAGE_BASE	(_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_USER)

#define PAGE_NONE		__pgprot(_PAGE_PROT_NONE | _PAGE_READ)
#define PAGE_READ		__pgprot(_PAGE_BASE | _PAGE_READ)
#define PAGE_WRITE		__pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_WRITE)
#define PAGE_EXEC		__pgprot(_PAGE_BASE | _PAGE_EXEC)
#define PAGE_READ_EXEC		__pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_EXEC)
#define PAGE_WRITE_EXEC		__pgprot(_PAGE_BASE | _PAGE_READ |	\
					 _PAGE_EXEC | _PAGE_WRITE)
#define PAGE_SHADOWSTACK       __pgprot(_PAGE_BASE | _PAGE_WRITE)

#define PAGE_COPY		PAGE_READ
#define PAGE_COPY_EXEC		PAGE_READ_EXEC
#define PAGE_SHARED		PAGE_WRITE
#define PAGE_SHARED_EXEC	PAGE_WRITE_EXEC

#define _PAGE_KERNEL		(_PAGE_READ \
				| _PAGE_WRITE \
				| _PAGE_PRESENT \
				| _PAGE_ACCESSED \
				| _PAGE_DIRTY \
				| _PAGE_GLOBAL)

#define PAGE_KERNEL		__pgprot(_PAGE_KERNEL)
#define PAGE_KERNEL_READ	__pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
#define PAGE_KERNEL_EXEC	__pgprot(_PAGE_KERNEL | _PAGE_EXEC)
#define PAGE_KERNEL_READ_EXEC	__pgprot((_PAGE_KERNEL & ~_PAGE_WRITE) \
					 | _PAGE_EXEC)

#define PAGE_TABLE		__pgprot(_PAGE_TABLE)

#define _PAGE_KERNEL_NC ((_PAGE_KERNEL & ~_PAGE_MTMASK) | _PAGE_NOCACHE)
#define _PAGE_IOREMAP	((_PAGE_KERNEL & ~_PAGE_MTMASK) | _PAGE_IO)
#define PAGE_KERNEL_IO		__pgprot(_PAGE_IOREMAP)

extern pgd_t swapper_pg_dir[];
extern pgd_t trampoline_pg_dir[];
extern pgd_t early_pg_dir[];

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
static inline int pmd_present(pmd_t pmd)
{
	/*
	 * Checking for _PAGE_LEAF is needed too because:
	 * When splitting a THP, split_huge_page() will temporarily clear
	 * the present bit, in this situation, pmd_present() and
	 * pmd_trans_huge() still needs to return true.
	 */
	return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE | _PAGE_LEAF));
}
#else
static inline int pmd_present(pmd_t pmd)
{
	return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
}
#endif

static inline int pmd_none(pmd_t pmd)
{
	return (pmd_val(pmd) == 0);
}

static inline int pmd_bad(pmd_t pmd)
{
	return !pmd_present(pmd) || (pmd_val(pmd) & _PAGE_LEAF);
}

#define pmd_leaf	pmd_leaf
static inline bool pmd_leaf(pmd_t pmd)
{
	return pmd_present(pmd) && (pmd_val(pmd) & _PAGE_LEAF);
}

static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
{
	WRITE_ONCE(*pmdp, pmd);
}

static inline void pmd_clear(pmd_t *pmdp)
{
	set_pmd(pmdp, __pmd(0));
}

static inline pgd_t pfn_pgd(unsigned long pfn, pgprot_t prot)
{
	unsigned long prot_val = pgprot_val(prot);

	ALT_THEAD_PMA(prot_val);

	return __pgd((pfn << _PAGE_PFN_SHIFT) | prot_val);
}

static inline unsigned long _pgd_pfn(pgd_t pgd)
{
	return __page_val_to_pfn(pgd_val(pgd));
}

static inline struct page *pmd_page(pmd_t pmd)
{
	return pfn_to_page(__page_val_to_pfn(pmd_val(pmd)));
}

static inline unsigned long pmd_page_vaddr(pmd_t pmd)
{
	return (unsigned long)pfn_to_virt(__page_val_to_pfn(pmd_val(pmd)));
}

static inline pte_t pmd_pte(pmd_t pmd)
{
	return __pte(pmd_val(pmd));
}

static inline pte_t pud_pte(pud_t pud)
{
	return __pte(pud_val(pud));
}

#ifdef CONFIG_RISCV_ISA_SVNAPOT

static __always_inline bool has_svnapot(void)
{
	return riscv_has_extension_likely(RISCV_ISA_EXT_SVNAPOT);
}

static inline unsigned long pte_napot(pte_t pte)
{
	return pte_val(pte) & _PAGE_NAPOT;
}

static inline pte_t pte_mknapot(pte_t pte, unsigned int order)
{
	int pos = order - 1 + _PAGE_PFN_SHIFT;
	unsigned long napot_bit = BIT(pos);
	unsigned long napot_mask = ~GENMASK(pos, _PAGE_PFN_SHIFT);

	return __pte((pte_val(pte) & napot_mask) | napot_bit | _PAGE_NAPOT);
}

#else

static __always_inline bool has_svnapot(void) { return false; }

static inline unsigned long pte_napot(pte_t pte)
{
	return 0;
}

#endif /* CONFIG_RISCV_ISA_SVNAPOT */

/* Yields the page frame number (PFN) of a page table entry */
static inline unsigned long pte_pfn(pte_t pte)
{
	unsigned long res  = __page_val_to_pfn(pte_val(pte));

	if (has_svnapot() && pte_napot(pte))
		res = res & (res - 1UL);

	return res;
}

#define pte_page(x)     pfn_to_page(pte_pfn(x))

/* Constructs a page table entry */
static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
{
	unsigned long prot_val = pgprot_val(prot);

	ALT_THEAD_PMA(prot_val);

	return __pte((pfn << _PAGE_PFN_SHIFT) | prot_val);
}

#define pte_pgprot pte_pgprot
static inline pgprot_t pte_pgprot(pte_t pte)
{
	unsigned long pfn = pte_pfn(pte);

	return __pgprot(pte_val(pfn_pte(pfn, __pgprot(0))) ^ pte_val(pte));
}

static inline int pte_present(pte_t pte)
{
	return (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
}

#define pte_accessible pte_accessible
static inline unsigned long pte_accessible(struct mm_struct *mm, pte_t a)
{
	if (pte_val(a) & _PAGE_PRESENT)
		return true;

	if ((pte_val(a) & _PAGE_PROT_NONE) &&
	    atomic_read(&mm->tlb_flush_pending))
		return true;

	return false;
}

static inline int pte_none(pte_t pte)
{
	return (pte_val(pte) == 0);
}

static inline int pte_write(pte_t pte)
{
	return pte_val(pte) & _PAGE_WRITE;
}

static inline int pte_exec(pte_t pte)
{
	return pte_val(pte) & _PAGE_EXEC;
}

static inline int pte_user(pte_t pte)
{
	return pte_val(pte) & _PAGE_USER;
}

static inline int pte_huge(pte_t pte)
{
	return pte_present(pte) && (pte_val(pte) & _PAGE_LEAF);
}

static inline int pte_dirty(pte_t pte)
{
	return pte_val(pte) & _PAGE_DIRTY;
}

static inline int pte_young(pte_t pte)
{
	return pte_val(pte) & _PAGE_ACCESSED;
}

static inline int pte_special(pte_t pte)
{
	return pte_val(pte) & _PAGE_SPECIAL;
}

/* static inline pte_t pte_rdprotect(pte_t pte) */

static inline pte_t pte_wrprotect(pte_t pte)
{
	return __pte((pte_val(pte) & ~(_PAGE_WRITE)) | (_PAGE_READ));
}

#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
#define pgtable_supports_uffd_wp()	\
	riscv_has_extension_unlikely(RISCV_ISA_EXT_SVRSW60T59B)

static inline bool pte_uffd_wp(pte_t pte)
{
	return !!(pte_val(pte) & _PAGE_UFFD_WP);
}

static inline pte_t pte_mkuffd_wp(pte_t pte)
{
	return pte_wrprotect(__pte(pte_val(pte) | _PAGE_UFFD_WP));
}

static inline pte_t pte_clear_uffd_wp(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_UFFD_WP));
}

static inline bool pte_swp_uffd_wp(pte_t pte)
{
	return !!(pte_val(pte) & _PAGE_SWP_UFFD_WP);
}

static inline pte_t pte_swp_mkuffd_wp(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SWP_UFFD_WP);
}

static inline pte_t pte_swp_clear_uffd_wp(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_SWP_UFFD_WP));
}
#endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */

/* static inline pte_t pte_mkread(pte_t pte) */

struct vm_area_struct;
pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma);
#define pte_mkwrite pte_mkwrite

static inline pte_t pte_mkwrite_novma(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_WRITE);
}

static inline pte_t pte_mkwrite_shstk(pte_t pte)
{
	return __pte((pte_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE);
}

/* static inline pte_t pte_mkexec(pte_t pte) */

static inline pte_t pte_mkdirty(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_DIRTY | _PAGE_SOFT_DIRTY);
}

static inline pte_t pte_mkclean(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_DIRTY));
}

static inline pte_t pte_mkyoung(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_ACCESSED);
}

static inline pte_t pte_mkold(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_ACCESSED));
}

static inline pte_t pte_mkspecial(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SPECIAL);
}

static inline pte_t pte_mkhuge(pte_t pte)
{
	return pte;
}

#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
#define pgtable_supports_soft_dirty()				\
	(IS_ENABLED(CONFIG_MEM_SOFT_DIRTY) &&			\
	 riscv_has_extension_unlikely(RISCV_ISA_EXT_SVRSW60T59B))

static inline bool pte_soft_dirty(pte_t pte)
{
	return !!(pte_val(pte) & _PAGE_SOFT_DIRTY);
}

static inline pte_t pte_mksoft_dirty(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SOFT_DIRTY);
}

static inline pte_t pte_clear_soft_dirty(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_SOFT_DIRTY));
}

static inline bool pte_swp_soft_dirty(pte_t pte)
{
	return !!(pte_val(pte) & _PAGE_SWP_SOFT_DIRTY);
}

static inline pte_t pte_swp_mksoft_dirty(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SWP_SOFT_DIRTY);
}

static inline pte_t pte_swp_clear_soft_dirty(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_SWP_SOFT_DIRTY));
}
#endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */

#ifdef CONFIG_RISCV_ISA_SVNAPOT
#define pte_leaf_size(pte)	(pte_napot(pte) ?				\
					napot_cont_size(napot_cont_order(pte)) :\
					PAGE_SIZE)
#endif

#ifdef CONFIG_NUMA_BALANCING
/*
 * See the comment in include/asm-generic/pgtable.h
 */
static inline int pte_protnone(pte_t pte)
{
	return (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROT_NONE)) == _PAGE_PROT_NONE;
}

static inline int pmd_protnone(pmd_t pmd)
{
	return pte_protnone(pmd_pte(pmd));
}
#endif

/* Modify page protection bits */
static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
{
	unsigned long newprot_val = pgprot_val(newprot);

	ALT_THEAD_PMA(newprot_val);

	return __pte((pte_val(pte) & _PAGE_CHG_MASK) | newprot_val);
}

#define pgd_ERROR(e) \
	pr_err("%s:%d: bad pgd " PTE_FMT ".\n", __FILE__, __LINE__, pgd_val(e))


/* Commit new configuration to MMU hardware */
static inline void update_mmu_cache_range(struct vm_fault *vmf,
		struct vm_area_struct *vma, unsigned long address,
		pte_t *ptep, unsigned int nr)
{
	/*
	 * Svvptc guarantees that the new valid pte will be visible within
	 * a bounded timeframe, so when the uarch does not cache invalid
	 * entries, we don't have to do anything.
	 */
	if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SVVPTC))
		return;

	/*
	 * The kernel assumes that TLBs don't cache invalid entries, but
	 * in RISC-V, SFENCE.VMA specifies an ordering constraint, not a
	 * cache flush; it is necessary even after writing invalid entries.
	 * Relying on flush_tlb_fix_spurious_fault would suffice, but
	 * the extra traps reduce performance.  So, eagerly SFENCE.VMA.
	 */
	while (nr--)
		local_flush_tlb_page(address + nr * PAGE_SIZE);

}
#define update_mmu_cache(vma, addr, ptep) \
	update_mmu_cache_range(NULL, vma, addr, ptep, 1)

#define update_mmu_tlb_range(vma, addr, ptep, nr) \
	update_mmu_cache_range(NULL, vma, addr, ptep, nr)

static inline void update_mmu_cache_pmd(struct vm_area_struct *vma,
		unsigned long address, pmd_t *pmdp)
{
	pte_t *ptep = (pte_t *)pmdp;

	update_mmu_cache(vma, address, ptep);
}

#define __HAVE_ARCH_PTE_SAME
static inline int pte_same(pte_t pte_a, pte_t pte_b)
{
	return pte_val(pte_a) == pte_val(pte_b);
}

/*
 * Certain architectures need to do special things when PTEs within
 * a page table are directly modified.  Thus, the following hook is
 * made available.
 */
static inline void set_pte(pte_t *ptep, pte_t pteval)
{
	WRITE_ONCE(*ptep, pteval);
}

void flush_icache_pte(struct mm_struct *mm, pte_t pte);

static inline void __set_pte_at(struct mm_struct *mm, pte_t *ptep, pte_t pteval)
{
	if (pte_present(pteval) && pte_exec(pteval))
		flush_icache_pte(mm, pteval);

	set_pte(ptep, pteval);
}

#define PFN_PTE_SHIFT		_PAGE_PFN_SHIFT

static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
		pte_t *ptep, pte_t pteval, unsigned int nr)
{
	page_table_check_ptes_set(mm, addr, ptep, pteval, nr);

	for (;;) {
		__set_pte_at(mm, ptep, pteval);
		if (--nr == 0)
			break;
		ptep++;
		pte_val(pteval) += 1 << _PAGE_PFN_SHIFT;
	}
}
#define set_ptes set_ptes

static inline void pte_clear(struct mm_struct *mm,
	unsigned long addr, pte_t *ptep)
{
	__set_pte_at(mm, ptep, __pte(0));
}

#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS	/* defined in mm/pgtable.c */
extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
				 pte_t *ptep, pte_t entry, int dirty);
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG	/* defined in mm/pgtable.c */
bool ptep_test_and_clear_young(struct vm_area_struct *vma,
		unsigned long address, pte_t *ptep);

#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
				       unsigned long address, pte_t *ptep)
{
#ifdef CONFIG_SMP
	pte_t pte = __pte(xchg(&ptep->pte, 0));
#else
	pte_t pte = *ptep;

	set_pte(ptep, __pte(0));
#endif

	page_table_check_pte_clear(mm, address, pte);

	return pte;
}

#define __HAVE_ARCH_PTEP_SET_WRPROTECT
static inline void ptep_set_wrprotect(struct mm_struct *mm,
				      unsigned long address, pte_t *ptep)
{
	pte_t read_pte = READ_ONCE(*ptep);
	/*
	 * ptep_set_wrprotect can be called for shadow stack ranges too.
	 * shadow stack memory is XWR = 010 and thus clearing _PAGE_WRITE will lead to
	 * encoding 000b which is wrong encoding with V = 1. This should lead to page fault
	 * but we dont want this wrong configuration to be set in page tables.
	 */
	atomic_long_set((atomic_long_t *)ptep,
			((pte_val(read_pte) & ~(unsigned long)_PAGE_WRITE) | _PAGE_READ));
}

#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
		unsigned long address, pte_t *ptep)
{
	/*
	 * This comment is borrowed from x86, but applies equally to RISC-V:
	 *
	 * Clearing the accessed bit without a TLB flush
	 * doesn't cause data corruption. [ It could cause incorrect
	 * page aging and the (mistaken) reclaim of hot pages, but the
	 * chance of that should be relatively low. ]
	 *
	 * So as a performance optimization don't flush the TLB when
	 * clearing the accessed bit, it will eventually be flushed by
	 * a context switch or a VM operation anyway. [ In the rare
	 * event of it not getting flushed for a long time the delay
	 * shouldn't really matter because there's no real memory
	 * pressure for swapout to react to. ]
	 */
	return ptep_test_and_clear_young(vma, address, ptep);
}

#define pgprot_nx pgprot_nx
static inline pgprot_t pgprot_nx(pgprot_t _prot)
{
	return __pgprot(pgprot_val(_prot) & ~_PAGE_EXEC);
}

#define pgprot_noncached pgprot_noncached
static inline pgprot_t pgprot_noncached(pgprot_t _prot)
{
	unsigned long prot = pgprot_val(_prot);

	prot &= ~_PAGE_MTMASK;
	prot |= _PAGE_IO;

	return __pgprot(prot);
}

#define pgprot_writecombine pgprot_writecombine
static inline pgprot_t pgprot_writecombine(pgprot_t _prot)
{
	unsigned long prot = pgprot_val(_prot);

	prot &= ~_PAGE_MTMASK;
	prot |= _PAGE_NOCACHE;

	return __pgprot(prot);
}

#define pgprot_dmacoherent pgprot_writecombine

/*
 * Both Svade and Svadu control the hardware behavior when the PTE A/D bits need to be set. By
 * default the M-mode firmware enables the hardware updating scheme when only Svadu is present in
 * DT.
 */
#define arch_has_hw_pte_young arch_has_hw_pte_young
static inline bool arch_has_hw_pte_young(void)
{
	return riscv_has_extension_unlikely(RISCV_ISA_EXT_SVADU);
}

/*
 * THP functions
 */
static inline pmd_t pte_pmd(pte_t pte)
{
	return __pmd(pte_val(pte));
}

static inline pud_t pte_pud(pte_t pte)
{
	return __pud(pte_val(pte));
}

static inline pmd_t pmd_mkhuge(pmd_t pmd)
{
	return pmd;
}

static inline pmd_t pmd_mkinvalid(pmd_t pmd)
{
	return __pmd(pmd_val(pmd) & ~(_PAGE_PRESENT|_PAGE_PROT_NONE));
}

#define __pmd_to_phys(pmd)  (__page_val_to_pfn(pmd_val(pmd)) << PAGE_SHIFT)

static inline unsigned long pmd_pfn(pmd_t pmd)
{
	return ((__pmd_to_phys(pmd) & PMD_MASK) >> PAGE_SHIFT);
}

#define __pud_to_phys(pud)  (__page_val_to_pfn(pud_val(pud)) << PAGE_SHIFT)

#define pud_pfn pud_pfn
static inline unsigned long pud_pfn(pud_t pud)
{
	return ((__pud_to_phys(pud) & PUD_MASK) >> PAGE_SHIFT);
}

#define pmd_pgprot pmd_pgprot
static inline pgprot_t pmd_pgprot(pmd_t pmd)
{
	return pte_pgprot(pmd_pte(pmd));
}

#define pud_pgprot pud_pgprot
static inline pgprot_t pud_pgprot(pud_t pud)
{
	return pte_pgprot(pud_pte(pud));
}

static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
{
	return pte_pmd(pte_modify(pmd_pte(pmd), newprot));
}

#define pmd_write pmd_write
static inline int pmd_write(pmd_t pmd)
{
	return pte_write(pmd_pte(pmd));
}

#define pud_write pud_write
static inline int pud_write(pud_t pud)
{
	return pte_write(pud_pte(pud));
}

#define pmd_dirty pmd_dirty
static inline int pmd_dirty(pmd_t pmd)
{
	return pte_dirty(pmd_pte(pmd));
}

#define pmd_young pmd_young
static inline int pmd_young(pmd_t pmd)
{
	return pte_young(pmd_pte(pmd));
}

static inline int pmd_user(pmd_t pmd)
{
	return pte_user(pmd_pte(pmd));
}

static inline pmd_t pmd_mkold(pmd_t pmd)
{
	return pte_pmd(pte_mkold(pmd_pte(pmd)));
}

static inline pmd_t pmd_mkyoung(pmd_t pmd)
{
	return pte_pmd(pte_mkyoung(pmd_pte(pmd)));
}

pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
#define pmd_mkwrite pmd_mkwrite

static inline pmd_t pmd_mkwrite_novma(pmd_t pmd)
{
	return pte_pmd(pte_mkwrite_novma(pmd_pte(pmd)));
}

static inline pmd_t pmd_mkwrite_shstk(pmd_t pte)
{
	return __pmd((pmd_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE);
}

static inline pmd_t pmd_wrprotect(pmd_t pmd)
{
	return pte_pmd(pte_wrprotect(pmd_pte(pmd)));
}

static inline pmd_t pmd_mkclean(pmd_t pmd)
{
	return pte_pmd(pte_mkclean(pmd_pte(pmd)));
}

static inline pmd_t pmd_mkdirty(pmd_t pmd)
{
	return pte_pmd(pte_mkdirty(pmd_pte(pmd)));
}

#ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP
static inline bool pmd_special(pmd_t pmd)
{
	return pte_special(pmd_pte(pmd));
}

static inline pmd_t pmd_mkspecial(pmd_t pmd)
{
	return pte_pmd(pte_mkspecial(pmd_pte(pmd)));
}
#endif

#ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP
static inline bool pud_special(pud_t pud)
{
	return pte_special(pud_pte(pud));
}

static inline pud_t pud_mkspecial(pud_t pud)
{
	return pte_pud(pte_mkspecial(pud_pte(pud)));
}
#endif

#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
static inline bool pmd_uffd_wp(pmd_t pmd)
{
	return pte_uffd_wp(pmd_pte(pmd));
}

static inline pmd_t pmd_mkuffd_wp(pmd_t pmd)
{
	return pte_pmd(pte_mkuffd_wp(pmd_pte(pmd)));
}

static inline pmd_t pmd_clear_uffd_wp(pmd_t pmd)
{
	return pte_pmd(pte_clear_uffd_wp(pmd_pte(pmd)));
}

static inline bool pmd_swp_uffd_wp(pmd_t pmd)
{
	return pte_swp_uffd_wp(pmd_pte(pmd));
}

static inline pmd_t pmd_swp_mkuffd_wp(pmd_t pmd)
{
	return pte_pmd(pte_swp_mkuffd_wp(pmd_pte(pmd)));
}

static inline pmd_t pmd_swp_clear_uffd_wp(pmd_t pmd)
{
	return pte_pmd(pte_swp_clear_uffd_wp(pmd_pte(pmd)));
}
#endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */

#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
static inline bool pmd_soft_dirty(pmd_t pmd)
{
	return pte_soft_dirty(pmd_pte(pmd));
}

static inline pmd_t pmd_mksoft_dirty(pmd_t pmd)
{
	return pte_pmd(pte_mksoft_dirty(pmd_pte(pmd)));
}

static inline pmd_t pmd_clear_soft_dirty(pmd_t pmd)
{
	return pte_pmd(pte_clear_soft_dirty(pmd_pte(pmd)));
}

#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION
static inline bool pmd_swp_soft_dirty(pmd_t pmd)
{
	return pte_swp_soft_dirty(pmd_pte(pmd));
}

static inline pmd_t pmd_swp_mksoft_dirty(pmd_t pmd)
{
	return pte_pmd(pte_swp_mksoft_dirty(pmd_pte(pmd)));
}

static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd)
{
	return pte_pmd(pte_swp_clear_soft_dirty(pmd_pte(pmd)));
}
#endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */
#endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */

static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
				pmd_t *pmdp, pmd_t pmd)
{
	page_table_check_pmd_set(mm, addr, pmdp, pmd);
	return __set_pte_at(mm, (pte_t *)pmdp, pmd_pte(pmd));
}

static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
				pud_t *pudp, pud_t pud)
{
	page_table_check_pud_set(mm, addr, pudp, pud);
	return __set_pte_at(mm, (pte_t *)pudp, pud_pte(pud));
}

#ifdef CONFIG_PAGE_TABLE_CHECK
static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
{
	return pte_present(pte) && pte_user(pte);
}

static inline bool pmd_user_accessible_page(struct mm_struct *mm, unsigned long addr, pmd_t pmd)
{
	return pmd_leaf(pmd) && pmd_user(pmd);
}

static inline bool pud_user_accessible_page(struct mm_struct *mm, unsigned long addr, pud_t pud)
{
	return pud_leaf(pud) && pud_user(pud);
}
#endif

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
static inline int pmd_trans_huge(pmd_t pmd)
{
	return pmd_leaf(pmd);
}

#define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
					unsigned long address, pmd_t *pmdp,
					pmd_t entry, int dirty)
{
	return ptep_set_access_flags(vma, address, (pte_t *)pmdp, pmd_pte(entry), dirty);
}

#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
		unsigned long address, pmd_t *pmdp)
{
	return ptep_test_and_clear_young(vma, address, (pte_t *)pmdp);
}

#define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
					unsigned long address, pmd_t *pmdp)
{
#ifdef CONFIG_SMP
	pmd_t pmd = __pmd(xchg(&pmdp->pmd, 0));
#else
	pmd_t pmd = *pmdp;

	pmd_clear(pmdp);
#endif

	page_table_check_pmd_clear(mm, address, pmd);

	return pmd;
}

#define __HAVE_ARCH_PMDP_SET_WRPROTECT
static inline void pmdp_set_wrprotect(struct mm_struct *mm,
					unsigned long address, pmd_t *pmdp)
{
	ptep_set_wrprotect(mm, address, (pte_t *)pmdp);
}

#define pmdp_establish pmdp_establish
static inline pmd_t pmdp_establish(struct vm_area_struct *vma,
				unsigned long address, pmd_t *pmdp, pmd_t pmd)
{
	page_table_check_pmd_set(vma->vm_mm, address, pmdp, pmd);
	return __pmd(atomic_long_xchg((atomic_long_t *)pmdp, pmd_val(pmd)));
}

#define pmdp_collapse_flush pmdp_collapse_flush
extern pmd_t pmdp_collapse_flush(struct vm_area_struct *vma,
				 unsigned long address, pmd_t *pmdp);

static inline pud_t pud_wrprotect(pud_t pud)
{
	return pte_pud(pte_wrprotect(pud_pte(pud)));
}

static inline int pud_trans_huge(pud_t pud)
{
	return pud_leaf(pud);
}

static inline int pud_dirty(pud_t pud)
{
	return pte_dirty(pud_pte(pud));
}

static inline pud_t pud_mkyoung(pud_t pud)
{
	return pte_pud(pte_mkyoung(pud_pte(pud)));
}

static inline pud_t pud_mkold(pud_t pud)
{
	return pte_pud(pte_mkold(pud_pte(pud)));
}

static inline pud_t pud_mkdirty(pud_t pud)
{
	return pte_pud(pte_mkdirty(pud_pte(pud)));
}

static inline pud_t pud_mkclean(pud_t pud)
{
	return pte_pud(pte_mkclean(pud_pte(pud)));
}

static inline pud_t pud_mkwrite(pud_t pud)
{
	return pte_pud(pte_mkwrite_novma(pud_pte(pud)));
}

static inline pud_t pud_mkhuge(pud_t pud)
{
	return pud;
}

static inline int pudp_set_access_flags(struct vm_area_struct *vma,
					unsigned long address, pud_t *pudp,
					pud_t entry, int dirty)
{
	return ptep_set_access_flags(vma, address, (pte_t *)pudp, pud_pte(entry), dirty);
}

static inline bool pudp_test_and_clear_young(struct vm_area_struct *vma,
		unsigned long address, pud_t *pudp)
{
	return ptep_test_and_clear_young(vma, address, (pte_t *)pudp);
}

#define __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR
static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm,
					    unsigned long address,  pud_t *pudp)
{
#ifdef CONFIG_SMP
	pud_t pud = __pud(xchg(&pudp->pud, 0));
#else
	pud_t pud = *pudp;

	pud_clear(pudp);
#endif

	page_table_check_pud_clear(mm, address, pud);

	return pud;
}

static inline int pud_young(pud_t pud)
{
	return pte_young(pud_pte(pud));
}

static inline void update_mmu_cache_pud(struct vm_area_struct *vma,
					unsigned long address, pud_t *pudp)
{
	pte_t *ptep = (pte_t *)pudp;

	update_mmu_cache(vma, address, ptep);
}

static inline pud_t pudp_establish(struct vm_area_struct *vma,
				   unsigned long address, pud_t *pudp, pud_t pud)
{
	page_table_check_pud_set(vma->vm_mm, address, pudp, pud);
	return __pud(atomic_long_xchg((atomic_long_t *)pudp, pud_val(pud)));
}

static inline pud_t pud_mkinvalid(pud_t pud)
{
	return __pud(pud_val(pud) & ~(_PAGE_PRESENT | _PAGE_PROT_NONE));
}

extern pud_t pudp_invalidate(struct vm_area_struct *vma, unsigned long address,
			     pud_t *pudp);

static inline pud_t pud_modify(pud_t pud, pgprot_t newprot)
{
	return pte_pud(pte_modify(pud_pte(pud), newprot));
}

#endif /* CONFIG_TRANSPARENT_HUGEPAGE */

/*
 * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that
 * are !pte_none() && !pte_present().
 *
 * Format of swap PTE:
 *	bit            0:	_PAGE_PRESENT (zero)
 *	bit       1 to 2:	(zero)
 *	bit            3:	_PAGE_SWP_SOFT_DIRTY
 *	bit            4:	_PAGE_SWP_UFFD_WP
 *	bit            5:	_PAGE_PROT_NONE (zero)
 *	bit            6:	exclusive marker
 *	bits      7 to 11:	swap type
 *	bits 12 to XLEN-1:	swap offset
 */
#define __SWP_TYPE_SHIFT	7
#define __SWP_TYPE_BITS		5
#define __SWP_TYPE_MASK		((1UL << __SWP_TYPE_BITS) - 1)
#define __SWP_OFFSET_SHIFT	(__SWP_TYPE_BITS + __SWP_TYPE_SHIFT)

#define MAX_SWAPFILES_CHECK()	\
	BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > __SWP_TYPE_BITS)

#define __swp_type(x)	(((x).val >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK)
#define __swp_offset(x)	((x).val >> __SWP_OFFSET_SHIFT)
#define __swp_entry(type, offset) ((swp_entry_t) \
	{ (((type) & __SWP_TYPE_MASK) << __SWP_TYPE_SHIFT) | \
	  ((offset) << __SWP_OFFSET_SHIFT) })

#define __pte_to_swp_entry(pte)	((swp_entry_t) { pte_val(pte) })
#define __swp_entry_to_pte(x)	((pte_t) { (x).val })

static inline bool pte_swp_exclusive(pte_t pte)
{
	return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
}

static inline pte_t pte_swp_mkexclusive(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SWP_EXCLUSIVE);
}

static inline pte_t pte_swp_clear_exclusive(pte_t pte)
{
	return __pte(pte_val(pte) & ~_PAGE_SWP_EXCLUSIVE);
}

#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION
#define __pmd_to_swp_entry(pmd) ((swp_entry_t) { pmd_val(pmd) })
#define __swp_entry_to_pmd(swp) __pmd((swp).val)
#endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */

/*
 * In the RV64 Linux scheme, we give the user half of the virtual-address space
 * and give the kernel the other (upper) half.
 */
#ifdef CONFIG_64BIT
#define KERN_VIRT_START	(-(BIT(VA_BITS)) + TASK_SIZE)
#else
#define KERN_VIRT_START	FIXADDR_START
#endif

/*
 * Task size is 0x4000000000 for RV64 or 0x9fc00000 for RV32.
 * Note that PGDIR_SIZE must evenly divide TASK_SIZE.
 * Task size is:
 * -        0x9fc00000	(~2.5GB) for RV32.
 * -      0x4000000000	( 256GB) for RV64 using SV39 mmu
 * -    0x800000000000	( 128TB) for RV64 using SV48 mmu
 * - 0x100000000000000	(  64PB) for RV64 using SV57 mmu
 *
 * Note that PGDIR_SIZE must evenly divide TASK_SIZE since "RISC-V
 * Instruction Set Manual Volume II: Privileged Architecture" states that
 * "load and store effective addresses, which are 64bits, must have bits
 * 63–48 all equal to bit 47, or else a page-fault exception will occur."
 * Similarly for SV57, bits 63–57 must be equal to bit 56.
 */
#ifdef CONFIG_64BIT
#define TASK_SIZE_64	(PGDIR_SIZE * PTRS_PER_PGD / 2)

#ifdef CONFIG_COMPAT
#define TASK_SIZE_32	(_AC(0x80000000, UL) - PAGE_SIZE)
#define TASK_SIZE	(is_compat_task() ? \
			 TASK_SIZE_32 : TASK_SIZE_64)
#else
#define TASK_SIZE	TASK_SIZE_64
#endif

#else
#define TASK_SIZE	FIXADDR_START
#endif

#else /* CONFIG_MMU */

#define PAGE_SHARED		__pgprot(0)
#define PAGE_KERNEL		__pgprot(0)
#define swapper_pg_dir		NULL
#define TASK_SIZE		_AC(-1, UL)
#define VMALLOC_START		_AC(0, UL)
#define VMALLOC_END		TASK_SIZE

#endif /* !CONFIG_MMU */

extern char _start[];
extern void *_dtb_early_va;
extern uintptr_t _dtb_early_pa;
#define dtb_early_va	_dtb_early_va
#define dtb_early_pa	_dtb_early_pa
extern u64 satp_mode;

void paging_init(void);
void misc_mem_init(void);

/*
 * Use set_p*_safe(), and elide TLB flushing, when confident that *no*
 * TLB flush will be required as a result of the "set". For example, use
 * in scenarios where it is known ahead of time that the routine is
 * setting non-present entries, or re-setting an existing entry to the
 * same value. Otherwise, use the typical "set" helpers and flush the
 * TLB.
 */
#define set_p4d_safe(p4dp, p4d) \
({ \
	WARN_ON_ONCE(p4d_present(*p4dp) && !p4d_same(*p4dp, p4d)); \
	set_p4d(p4dp, p4d); \
})

#define set_pgd_safe(pgdp, pgd) \
({ \
	WARN_ON_ONCE(pgd_present(*pgdp) && !pgd_same(*pgdp, pgd)); \
	set_pgd(pgdp, pgd); \
})
#endif /* !__ASSEMBLER__ */

#endif /* _ASM_RISCV_PGTABLE_H */
]

84/2 2026/05/25 00:21 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 81657
							output: 44
							thoughts: 897
						

Thoughts:
**Investigating a Potential Huge Page Counter Bug**

Okay, so I'm looking at `pte_clear` and something feels off. It's defined as a straightforward `__set_pte_at` with a zero PTE. The critical thing here is that `__set_pte_at` *doesn't* call `page_table_check_pte_clear`. I know that `ptep_get_and_clear` *does* call `page_table_check_pte_clear`, which is essential for decrementing the page table check counter.

My immediate concern is that if `huge_pte_clear` calls this `pte_clear`, then `page_table_check_pte_clear` is never called within the huge page clearing process! If that's the case, the counter tracking these huge page entries is never decremented. Consequently, any huge page unmapped via `huge_pte_clear` will leave that counter incorrectly incremented. Then, when the huge page is eventually freed, this would trigger a `__page_table_check_zero` BUG, which we absolutely don't want.

Hang on, is `pte_clear` *supposed* to call `page_table_check_pte_clear`? The arm64 architecture's commit `00de2c9f26b1` changed `pte_clear` to `ptep_clear` in `clear_flush`. This seems to confirm my suspicion.

Looking at the riscv implementation, `huge_pte_clear` *does* call `pte_clear`. This is where the problem is. If `pte_clear` isn't calling `page_table_check_pte_clear` in this context, the check is skipped. This is a very clear and present danger to the stability of the system.

Now I'm thinking, `pte_clear` is used all over the place. How does the overall `page_table_check` mechanism even *work* if `pte_clear` doesn't participate in decrementing the counter? Typically, `ptep_get_and_clear` or `ptep_clear` are used for PTE clearing and correctly interact with the counter.

Let's check `include/linux/pgtable.h`: there it is, `ptep_clear` is just a macro that expands to `ptep_get_and_clear`, which calls `page_table_check_pte_clear`. Excellent. `ptep_clear` *will* decrement the counter, but `pte_clear` just nukes the PTE to zero.

So, here's the issue in stark relief: if `pte_clear` *doesn't* call `page_table_check_pte_clear`, then any use of `pte_clear` to clear a *present* PTE is going to cause a false positive in `page_table_check`.

The question becomes, is `huge_pte_clear` clearing a *present* PTE? It has to be, because it's called by `__unmap_hugepage_range`, and that function is specifically dealing with unmapping pages. However, in looking at `__unmap_hugepage_range`, it uses `huge_ptep_get_and_clear` for present PTEs! That should be safe and correct. So, let me investigate further in `__unmap_hugepage_range`.



85/2 2026/05/25 00:22 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/hugetlb.c IncludeLines:true Name:__unmap_hugepage_range]

Results:
map[SourceCode:5156:	void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
5157:				    unsigned long start, unsigned long end,
5158:				    struct folio *folio, zap_flags_t zap_flags)
5159:	{
5160:		struct mm_struct *mm = vma->vm_mm;
5161:		const bool folio_provided = !!folio;
5162:		unsigned long address;
5163:		pte_t *ptep;
5164:		pte_t pte;
5165:		spinlock_t *ptl;
5166:		struct hstate *h = hstate_vma(vma);
5167:		unsigned long sz = huge_page_size(h);
5168:		bool adjust_reservation;
5169:		unsigned long last_addr_mask;
5170:	
5171:		WARN_ON(!is_vm_hugetlb_page(vma));
5172:		BUG_ON(start & ~huge_page_mask(h));
5173:		BUG_ON(end & ~huge_page_mask(h));
5174:	
5175:		/*
5176:		 * This is a hugetlb vma, all the pte entries should point
5177:		 * to huge page.
5178:		 */
5179:		tlb_change_page_size(tlb, sz);
5180:		tlb_start_vma(tlb, vma);
5181:	
5182:		last_addr_mask = hugetlb_mask_last_page(h);
5183:		address = start;
5184:		for (; address < end; address += sz) {
5185:			ptep = hugetlb_walk(vma, address, sz);
5186:			if (!ptep) {
5187:				address |= last_addr_mask;
5188:				continue;
5189:			}
5190:	
5191:			ptl = huge_pte_lock(h, mm, ptep);
5192:			if (huge_pmd_unshare(tlb, vma, address, ptep)) {
5193:				spin_unlock(ptl);
5194:				address |= last_addr_mask;
5195:				continue;
5196:			}
5197:	
5198:			pte = huge_ptep_get(mm, address, ptep);
5199:			if (huge_pte_none(pte)) {
5200:				spin_unlock(ptl);
5201:				continue;
5202:			}
5203:	
5204:			/*
5205:			 * Migrating hugepage or HWPoisoned hugepage is already
5206:			 * unmapped and its refcount is dropped, so just clear pte here.
5207:			 */
5208:			if (unlikely(!pte_present(pte))) {
5209:				/*
5210:				 * If the pte was wr-protected by uffd-wp in any of the
5211:				 * swap forms, meanwhile the caller does not want to
5212:				 * drop the uffd-wp bit in this zap, then replace the
5213:				 * pte with a marker.
5214:				 */
5215:				if (pte_swp_uffd_wp_any(pte) &&
5216:				    !(zap_flags & ZAP_FLAG_DROP_MARKER))
5217:					set_huge_pte_at(mm, address, ptep,
5218:							make_pte_marker(PTE_MARKER_UFFD_WP),
5219:							sz);
5220:				else
5221:					huge_pte_clear(mm, address, ptep, sz);
5222:				spin_unlock(ptl);
5223:				continue;
5224:			}
5225:	
5226:			/*
5227:			 * If a folio is supplied, it is because a specific
5228:			 * folio is being unmapped, not a range. Ensure the folio we
5229:			 * are about to unmap is the actual folio of interest.
5230:			 */
5231:			if (folio_provided) {
5232:				if (folio != page_folio(pte_page(pte))) {
5233:					spin_unlock(ptl);
5234:					continue;
5235:				}
5236:				/*
5237:				 * Mark the VMA as having unmapped its page so that
5238:				 * future faults in this VMA will fail rather than
5239:				 * looking like data was lost
5240:				 */
5241:				set_vma_resv_flags(vma, HPAGE_RESV_UNMAPPED);
5242:			} else {
5243:				folio = page_folio(pte_page(pte));
5244:			}
5245:	
5246:			pte = huge_ptep_get_and_clear(mm, address, ptep, sz);
5247:			tlb_remove_huge_tlb_entry(h, tlb, ptep, address);
5248:			if (huge_pte_dirty(pte))
5249:				folio_mark_dirty(folio);
5250:			/* Leave a uffd-wp pte marker if needed */
5251:			if (huge_pte_uffd_wp(pte) &&
5252:			    !(zap_flags & ZAP_FLAG_DROP_MARKER))
5253:				set_huge_pte_at(mm, address, ptep,
5254:						make_pte_marker(PTE_MARKER_UFFD_WP),
5255:						sz);
5256:			hugetlb_count_sub(pages_per_huge_page(h), mm);
5257:			hugetlb_remove_rmap(folio);
5258:			spin_unlock(ptl);
5259:	
5260:			/*
5261:			 * Restore the reservation for anonymous page, otherwise the
5262:			 * backing page could be stolen by someone.
5263:			 * If there we are freeing a surplus, do not set the restore
5264:			 * reservation bit.
5265:			 */
5266:			adjust_reservation = false;
5267:	
5268:			spin_lock_irq(&hugetlb_lock);
5269:			if (!h->surplus_huge_pages && __vma_private_lock(vma) &&
5270:			    folio_test_anon(folio)) {
5271:				folio_set_hugetlb_restore_reserve(folio);
5272:				/* Reservation to be adjusted after the spin lock */
5273:				adjust_reservation = true;
5274:			}
5275:			spin_unlock_irq(&hugetlb_lock);
5276:	
5277:			/*
5278:			 * Adjust the reservation for the region that will have the
5279:			 * reserve restored. Keep in mind that vma_needs_reservation() changes
5280:			 * resv->adds_in_progress if it succeeds. If this is not done,
5281:			 * do_exit() will not see it, and will keep the reservation
5282:			 * forever.
5283:			 */
5284:			if (adjust_reservation) {
5285:				int rc = vma_needs_reservation(h, vma, address);
5286:	
5287:				if (rc < 0)
5288:					/* Pressumably allocate_file_region_entries failed
5289:					 * to allocate a file_region struct. Clear
5290:					 * hugetlb_restore_reserve so that global reserve
5291:					 * count will not be incremented by free_huge_folio.
5292:					 * Act as if we consumed the reservation.
5293:					 */
5294:					folio_clear_hugetlb_restore_reserve(folio);
5295:				else if (rc)
5296:					vma_add_reservation(h, vma, address);
5297:			}
5298:	
5299:			tlb_remove_page_size(tlb, folio_page(folio, 0),
5300:					     folio_size(folio));
5301:			/*
5302:			 * If we were instructed to unmap a specific folio, we're done.
5303:			 */
5304:			if (folio_provided)
5305:				break;
5306:		}
5307:		tlb_end_vma(tlb, vma);
5308:	
5309:		huge_pmd_unshare_flush(tlb, vma);
5310:	}
 SourceFile:mm/hugetlb.c]

86/2 2026/05/25 00:22 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 85775
							output: 43
							thoughts: 889
						

Thoughts:
**Analyzing Huge Page Unmapping and PTE Clearing**

Okay, so I'm digging into how huge pages are unmapped in this RISC-V context, specifically focusing on the interactions with PTE (Page Table Entry) checks. My initial observation is that `__unmap_hugepage_range` calls `huge_ptep_get_and_clear`, which seems crucial for present PTEs. Let's trace this...

`huge_ptep_get_and_clear` in turn checks if the PTE is a huge page (using `pte_napot`). If it isn't, it delegates to the standard `ptep_get_and_clear`, which I assume handles standard page sizes. But for *huge* pages, `huge_ptep_get_and_clear` calls `get_clear_contig`.

Here's the key: `get_clear_contig` iterates and, critically, calls `ptep_get_and_clear` *for each PTE* within the huge page! This is where things get interesting, because `ptep_get_and_clear` does, in fact, call `page_table_check_pte_clear`. So, for present PTEs within a huge page, that check *is* being performed on every individual PTE. Excellent.

Now, what about the non-present PTEs? The code shows that if a PTE isn't present, `__unmap_hugepage_range` calls `huge_pte_clear` instead. Ah, but that is the trick isn't it? If the PTE is non-present, `page_table_check_pte_set` was never called in the first place, because the counter is *only* incremented for present, user-accessible PTEs! So, `huge_pte_clear` not calling the check is perfectly fine – the counter hasn't been touched for that PTE anyway. That makes perfect sense.

I need to confirm if there are any other call sites for `huge_pte_clear`. I'll now check out `hugetlb_change_protection` and see if any present PTEs are passed there.



87/2 2026/05/25 00:22 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/hugetlb.c IncludeLines:true Name:hugetlb_change_protection]

Results:
map[SourceCode:6398:	long hugetlb_change_protection(struct vm_area_struct *vma,
6399:			unsigned long address, unsigned long end,
6400:			pgprot_t newprot, unsigned long cp_flags)
6401:	{
6402:		struct mm_struct *mm = vma->vm_mm;
6403:		unsigned long start = address;
6404:		pte_t *ptep;
6405:		pte_t pte;
6406:		struct hstate *h = hstate_vma(vma);
6407:		long pages = 0, psize = huge_page_size(h);
6408:		struct mmu_notifier_range range;
6409:		unsigned long last_addr_mask;
6410:		bool uffd_wp = cp_flags & MM_CP_UFFD_WP;
6411:		bool uffd_wp_resolve = cp_flags & MM_CP_UFFD_WP_RESOLVE;
6412:		struct mmu_gather tlb;
6413:	
6414:		/*
6415:		 * In the case of shared PMDs, the area to flush could be beyond
6416:		 * start/end.  Set range.start/range.end to cover the maximum possible
6417:		 * range if PMD sharing is possible.
6418:		 */
6419:		mmu_notifier_range_init(&range, MMU_NOTIFY_PROTECTION_VMA,
6420:					0, mm, start, end);
6421:		adjust_range_if_pmd_sharing_possible(vma, &range.start, &range.end);
6422:	
6423:		BUG_ON(address >= end);
6424:		flush_cache_range(vma, range.start, range.end);
6425:		tlb_gather_mmu_vma(&tlb, vma);
6426:	
6427:		mmu_notifier_invalidate_range_start(&range);
6428:		hugetlb_vma_lock_write(vma);
6429:		i_mmap_lock_write(vma->vm_file->f_mapping);
6430:		last_addr_mask = hugetlb_mask_last_page(h);
6431:		for (; address < end; address += psize) {
6432:			softleaf_t entry;
6433:			spinlock_t *ptl;
6434:	
6435:			ptep = hugetlb_walk(vma, address, psize);
6436:			if (!ptep) {
6437:				if (!uffd_wp) {
6438:					address |= last_addr_mask;
6439:					continue;
6440:				}
6441:				/*
6442:				 * Userfaultfd wr-protect requires pgtable
6443:				 * pre-allocations to install pte markers.
6444:				 */
6445:				ptep = huge_pte_alloc(mm, vma, address, psize);
6446:				if (!ptep) {
6447:					pages = -ENOMEM;
6448:					break;
6449:				}
6450:			}
6451:			ptl = huge_pte_lock(h, mm, ptep);
6452:			if (huge_pmd_unshare(&tlb, vma, address, ptep)) {
6453:				/*
6454:				 * When uffd-wp is enabled on the vma, unshare
6455:				 * shouldn't happen at all.  Warn about it if it
6456:				 * happened due to some reason.
6457:				 */
6458:				WARN_ON_ONCE(uffd_wp || uffd_wp_resolve);
6459:				pages++;
6460:				spin_unlock(ptl);
6461:				address |= last_addr_mask;
6462:				continue;
6463:			}
6464:			pte = huge_ptep_get(mm, address, ptep);
6465:			if (huge_pte_none(pte)) {
6466:				if (unlikely(uffd_wp))
6467:					/* Safe to modify directly (none->non-present). */
6468:					set_huge_pte_at(mm, address, ptep,
6469:							make_pte_marker(PTE_MARKER_UFFD_WP),
6470:							psize);
6471:				goto next;
6472:			}
6473:	
6474:			entry = softleaf_from_pte(pte);
6475:			if (unlikely(softleaf_is_hwpoison(entry))) {
6476:				/* Nothing to do. */
6477:			} else if (unlikely(softleaf_is_migration(entry))) {
6478:				struct folio *folio = softleaf_to_folio(entry);
6479:				pte_t newpte = pte;
6480:	
6481:				if (softleaf_is_migration_write(entry)) {
6482:					if (folio_test_anon(folio))
6483:						entry = make_readable_exclusive_migration_entry(
6484:									swp_offset(entry));
6485:					else
6486:						entry = make_readable_migration_entry(
6487:									swp_offset(entry));
6488:					newpte = swp_entry_to_pte(entry);
6489:					pages++;
6490:				}
6491:	
6492:				if (uffd_wp)
6493:					newpte = pte_swp_mkuffd_wp(newpte);
6494:				else if (uffd_wp_resolve)
6495:					newpte = pte_swp_clear_uffd_wp(newpte);
6496:				if (!pte_same(pte, newpte))
6497:					set_huge_pte_at(mm, address, ptep, newpte, psize);
6498:			} else if (unlikely(pte_is_marker(pte))) {
6499:				/*
6500:				 * Do nothing on a poison marker; page is
6501:				 * corrupted, permissions do not apply. Here
6502:				 * pte_marker_uffd_wp()==true implies !poison
6503:				 * because they're mutual exclusive.
6504:				 */
6505:				if (pte_is_uffd_wp_marker(pte) && uffd_wp_resolve)
6506:					/* Safe to modify directly (non-present->none). */
6507:					huge_pte_clear(mm, address, ptep, psize);
6508:			} else {
6509:				pte_t old_pte;
6510:				unsigned int shift = huge_page_shift(hstate_vma(vma));
6511:	
6512:				old_pte = huge_ptep_modify_prot_start(vma, address, ptep);
6513:				pte = huge_pte_modify(old_pte, newprot);
6514:				pte = arch_make_huge_pte(pte, shift, vma->vm_flags);
6515:				if (uffd_wp)
6516:					pte = huge_pte_mkuffd_wp(pte);
6517:				else if (uffd_wp_resolve)
6518:					pte = huge_pte_clear_uffd_wp(pte);
6519:				huge_ptep_modify_prot_commit(vma, address, ptep, old_pte, pte);
6520:				pages++;
6521:				tlb_remove_huge_tlb_entry(h, &tlb, ptep, address);
6522:			}
6523:	
6524:	next:
6525:			spin_unlock(ptl);
6526:			cond_resched();
6527:		}
6528:	
6529:		tlb_flush_mmu_tlbonly(&tlb);
6530:		huge_pmd_unshare_flush(&tlb, vma);
6531:		/*
6532:		 * No need to call mmu_notifier_arch_invalidate_secondary_tlbs() we are
6533:		 * downgrading page table protection not changing it to point to a new
6534:		 * page.
6535:		 *
6536:		 * See Documentation/mm/mmu_notifier.rst
6537:		 */
6538:		i_mmap_unlock_write(vma->vm_file->f_mapping);
6539:		hugetlb_vma_unlock_write(vma);
6540:		mmu_notifier_invalidate_range_end(&range);
6541:		tlb_finish_mmu(&tlb);
6542:	
6543:		return pages > 0 ? (pages << h->order) : pages;
6544:	}
 SourceFile:mm/hugetlb.c]

88/2 2026/05/25 00:22 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 89659
							output: 41
							thoughts: 149
						

Thoughts:
**Analyzing `hugetlb_change_protection` and Page Table Modifications**

Okay, let me break this down. In the `hugetlb_change_protection` function, I'm seeing this conditional: we're dealing with a PTE marker, which indicates a non-present page. Specifically, it's a `uffd_wp_marker`, and if `uffd_wp_resolve` is also true, we're calling `huge_pte_clear`. The critical point is that this non-present PTE is being directly cleared. This means `page_table_check_ptes_set` was *never* called on it. Hmm, that's interesting and seems correct.

Now, a question is popping into my mind... what about `move_huge_pte`? Did that function handle these types of PTE markers? Perhaps that function does more than just the basics with these special types of PTEs. I need to refresh my memory and check what `move_huge_pte` does and when it's called in relation to these markers. The interaction here requires a deeper look, especially given that we're talking about clearing a non-present PTE, which is a key process.



89/2 2026/05/25 00:22 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/hugetlb.c IncludeLines:true Name:move_huge_pte]

Results:
map[SourceCode:5052:	static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,
5053:				  unsigned long new_addr, pte_t *src_pte, pte_t *dst_pte,
5054:				  unsigned long sz)
5055:	{
5056:		bool need_clear_uffd_wp = vma_has_uffd_without_event_remap(vma);
5057:		struct hstate *h = hstate_vma(vma);
5058:		struct mm_struct *mm = vma->vm_mm;
5059:		spinlock_t *src_ptl, *dst_ptl;
5060:		pte_t pte;
5061:	
5062:		dst_ptl = huge_pte_lock(h, mm, dst_pte);
5063:		src_ptl = huge_pte_lockptr(h, mm, src_pte);
5064:	
5065:		/*
5066:		 * We don't have to worry about the ordering of src and dst ptlocks
5067:		 * because exclusive mmap_lock (or the i_mmap_lock) prevents deadlock.
5068:		 */
5069:		if (src_ptl != dst_ptl)
5070:			spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
5071:	
5072:		pte = huge_ptep_get_and_clear(mm, old_addr, src_pte, sz);
5073:	
5074:		if (need_clear_uffd_wp && pte_is_uffd_wp_marker(pte)) {
5075:			huge_pte_clear(mm, new_addr, dst_pte, sz);
5076:		} else {
5077:			if (need_clear_uffd_wp) {
5078:				if (pte_present(pte))
5079:					pte = huge_pte_clear_uffd_wp(pte);
5080:				else
5081:					pte = pte_swp_clear_uffd_wp(pte);
5082:			}
5083:			set_huge_pte_at(mm, new_addr, dst_pte, pte, sz);
5084:		}
5085:	
5086:		if (src_ptl != dst_ptl)
5087:			spin_unlock(src_ptl);
5088:		spin_unlock(dst_ptl);
5089:	}
 SourceFile:mm/hugetlb.c]

90/2 2026/05/25 00:22 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 90822
							output: 48
							thoughts: 337
						

Thoughts:
**Analyzing the `huge_pte_clear` Function**

Okay, let's break this down. It seems we're looking at a situation where `huge_pte_clear` is being called on `dst_pte` if `pte` is a uffd_wp marker. The tricky part is that `dst_pte` represents a *new*, currently empty, address. My initial thought was that clearing a "none" PTE with `huge_pte_clear` seemed redundant, like a wasted instruction.

The more significant question arises: is `huge_pte_clear` *ever* called on a present PTE? If not, then the lack of a call to `page_table_check_pte_clear` within `huge_pte_clear` is not a problem.

Let's do a quick check, let me search for `huge_pte_clear` within `mm/hugetlb.c`. Alright, here's what we found: `move_huge_pte` calls it on `dst_pte` (which, again, is the new, absent PTE); `__unmap_hugepage_range` calls it on `pte` if the PTE isn't present; and `hugetlb_change_protection` calls it on `pte` if it's a marker.

So, in the huge page code base, it appears `huge_pte_clear` is *never* called on a present PTE. This means we don't have to worry about the counter. 

That leads me to a critical point: `page_table_check_pte_clear` is only decremented if the PTE is present and user-accessible. If the PTE is absent, `page_table_check_pte_clear` does absolutely nothing. No decrement necessary, and this makes perfect sense. So, the original concern was a non-issue! We can verify this but I think we can stop here.



91/2 2026/05/25 00:22 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/page_table_check.c IncludeLines:true Name:__page_table_check_pte_clear]

Results:
map[SourceCode: 148:	void __page_table_check_pte_clear(struct mm_struct *mm, unsigned long addr,
 149:					  pte_t pte)
 150:	{
 151:		if (&init_mm == mm)
 152:			return;
 153:	
 154:		if (pte_user_accessible_page(mm, addr, pte))
 155:			page_table_check_clear(pte_pfn(pte), PAGE_SIZE >> PAGE_SHIFT);
 156:	}
 SourceFile:mm/page_table_check.c]

92/2 2026/05/25 00:22 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 91794
							output: 49
							thoughts: 1075
						

Thoughts:
**The PMD-Sized Huge Page Conundrum**

Okay, so `pte_user_accessible_page` correctly handles the presence check; if the PTE isn't present, `page_table_check_clear` isn't called, so `huge_pte_clear` is fine. The focus is elsewhere. I was initially thrown by the apparent lack of a call to `page_table_check_pte_clear` in `huge_pte_clear`, but that's logically correct because it only operates on present entries.

The real bug is in `huge_ptep_get_and_clear` on RISC-V. Looking at it again, the logic flow is the key: if the `orig_pte` *is* present, but it's *not* a huge page (`pte_napot` is false), the code falls into the regular `ptep_get_and_clear` path. That makes sense for PMD-sized huge pages, where `pte_napot` is deliberately false. However, the problem is that `ptep` is actually a `pmd_t *` cast to a `pte_t *`. So, `ptep_get_and_clear` *does* call `page_table_check_pte_clear`.

And `page_table_check_pte_clear` calls `page_table_check_clear(pte_pfn(pte), 1)`, which decrements the reference counter by 1. Now, a PMD-sized huge page covers many pages: `PMD_SIZE / PAGE_SIZE`. So, when it was initially mapped, what happened? Let's check `set_huge_pte_at` on RISC-V.

Here, if `pte_napot(pte)` is false (PMD-sized), it calls `set_ptes(mm, addr, ptep, pte, 1)`. Wait! `set_ptes` with `nr=1`! But `set_ptes` calls `page_table_check_ptes_set(mm, addr, ptep, pte, 1)`. Therefore, it increments the reference counter by *1*. So, if we decrement the counter by 1 in `ptep_get_and_clear`, and then we set it using `set_ptes(nr=1)`, then they cancel each other out!

That means the PMD-sized page only increments the reference count for the first page in the PMD. So now, the question is how this is handled in other functions.

However, a PMD-sized huge page consists of multiple pages, `PMD_SIZE / PAGE_SIZE`, if `page_table_check` only checks the first page, what about the other pages? Wait, `page_table_check_ptes_set` takes `nr`, if `nr=1`, it only increments the counter for the FIRST page!

But, `page_table_check_pmd_set` increments the counter for ALL pages in the PMD. So the actual problem must be in `page_table_check_pmd_set`, or in a function called by it!

The bug is here, in that the reference count only accounts for the first page within a PMD, and not the other pages, and therefore, an over-release can occur with PMD-sized pages. Now I know where to look.



93/2 2026/05/25 00:22 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/page_table_check.c IncludeLines:true Name:__page_table_check_pmds_set]

Results:
map[SourceCode: 228:	void __page_table_check_pmds_set(struct mm_struct *mm, unsigned long addr,
 229:			pmd_t *pmdp, pmd_t pmd, unsigned int nr)
 230:	{
 231:		unsigned long stride = PMD_SIZE >> PAGE_SHIFT;
 232:		unsigned int i;
 233:	
 234:		if (&init_mm == mm)
 235:			return;
 236:	
 237:		page_table_check_pmd_flags(pmd);
 238:	
 239:		for (i = 0; i < nr; i++)
 240:			__page_table_check_pmd_clear(mm, addr + PMD_SIZE * i, *(pmdp + i));
 241:		if (pmd_user_accessible_page(mm, addr, pmd))
 242:			page_table_check_set(pmd_pfn(pmd), stride * nr, pmd_write(pmd));
 243:	}
 SourceFile:mm/page_table_check.c]

94/2 2026/05/25 00:22 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 93980
							output: 46
							thoughts: 1953
						

Thoughts:
**Analyzing Potential Race Conditions in Huge Page Handling**

Okay, let's break this down systematically. My initial thought process focused on the interplay between `page_table_check_pmds_set` and `set_huge_pte_at`, specifically regarding the incrementing and decrementing of the internal counters used for page table validation. My initial concern was whether the counter increments and decrements matched up correctly, especially when dealing with PMD-sized huge pages, where a single `set_huge_pte_at` call affects multiple underlying pages. I was specifically looking at the potential for under-counting or over-counting PTEs.

The initial hunch seemed to point to an issue where only the first page counter might be incremented and decremented for PMD huge pages and then when the page is freed, the check would look at all pages in order, but that wasn't the case. I quickly realized this isn't a problem because it's incrementing the count by stride * nr which equates to 1 page for all pages in a PMD huge page. The logic in `__page_table_check_zero` handles this correctly, ensuring the counter is 0 for all of them.

Next, I shifted focus to NAPOT (Not-a-Power-of-Two) huge pages. This scenario felt more complex. `set_huge_pte_at` handles NAPOT pages by iterating through each PTE and calling `set_pte_at`, incrementing the counter for each. Similarly, `huge_ptep_get_and_clear` correctly decrements the counter for each PTE. This part seemed well-behaved, with a clean match between increment and decrement.

However, a potential race condition became apparent with the interplay of non-present NAPOT PTEs. The key lies in understanding the context when `huge_ptep_get_and_clear` is called, specifically when the "original PTE" is not present, meaning it's a migration entry. This is where things get interesting. If `pte_napot` is false on this "original" PTE, indicating it's not a NAPOT entry, the function only clears the *first* PTE in the range. If the original PTE *was* a migration entry, set by `set_ptes` in the event of page migration, and then `huge_ptep_get_and_clear` gets called on this, the rest of the PTEs aren't cleared!

This is where `__unmap_hugepage_range` comes into play. I noticed that if a PTE isn't present, the code calls `huge_pte_clear` instead of `huge_ptep_get_and_clear`. Then `huge_pte_clear` actually does correctly loop to clear all PTEs.

But then, if `huge_ptep_get_and_clear` gets called from `hugetlb_change_protection`, and if the migration entry is restored before the VMA is unmapped, would a race condition be possible? However, the migration entry isn't restored when the VMA is gone.

The code flow, especially in riscv, shows that for migration entries, only the *first* PTE is cleared. If we are setting a migration entry with `!pte_present`, `set_ptes` will be called on `pte_num` PTEs, which all become migration entries! But then `huge_ptep_get_and_clear` will only clear the FIRST, leaving the rest still as migration entries!

The race condition comes if `hugetlb_change_protection` calls `huge_ptep_get_and_clear` and there are still migration entries, then we end up with a problem because they can potentially get out of sync.

So, in summary, the crucial point is the case of migration entries in NAPOT pages. If `huge_ptep_get_and_clear` is called on a NAPOT range where the initial PTE is a migration entry, it may leave *some* of the PTEs uncleared, which can lead to invalid entries. If it is a problem with the check, it should be in the checks within `hugetlb_change_protection`!



95/2 2026/05/25 00:23 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/hugetlb.c IncludeLines:true Name:huge_ptep_modify_prot_start]

Results:
map[SourceCode:1061:	static inline pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma,
1062:							unsigned long addr, pte_t *ptep)
1063:	{
1064:		unsigned long psize = huge_page_size(hstate_vma(vma));
1065:	
1066:		return huge_ptep_get_and_clear(vma->vm_mm, addr, ptep, psize);
1067:	}
 SourceFile:include/linux/hugetlb.h]

96/2 2026/05/25 00:23 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 97043
							output: 45
							thoughts: 898
						

Thoughts:
**Analyzing a Potential Kernel Bug**

Okay, let's break this down. My initial thought was centered on `huge_ptep_modify_prot_start` and its interaction with `huge_ptep_get_and_clear`. I see that it's called within `hugetlb_change_protection`, but only when the PTE is `PRESENT`. That makes sense. For `PRESENT` PTEs, and considering a NAPOT huge page,  `pte_napot(pte)` *should* be true.  So,  `huge_ptep_get_and_clear` should clear all PTEs.

But then I had a nagging doubt: what if `pte_napot(pte)` *isn't* true for a `PRESENT` PTE on a NAPOT huge page?  That's impossible, really, given how `set_huge_pte_at` is implemented. It always sets `_PAGE_NAPOT`. Unless... something *else* wrote the PTE? No, that's not right. It should still have `_PAGE_NAPOT`.

Then, I recalled a relevant commit, `83d78ac677b9`. It states that we shouldn't rely on the PTE value to determine mapping size in some hugetlb functions because the PTE might not be present. The commit notes the use of a size parameter in `huge_pte_clear` and `huge_ptep_get_and_clear`.

This got me thinking, if `huge_pte_clear` only clears the *first* PTE when the PTE is not present, then what happens to the remaining PTEs if the VMA is unmapped?  The page tables are freed, and `free_pte_range` gets called, which in turn frees the page table page. But what if there are uncleared migration entries? Does that matter? I considered `ptes_sync`, but `free_pte_range` just frees the page, which caused more concern, if the migration entry is still in the page table and then gets freed. Is this a potential use-after-free situation? But wait, this is a migrating page, so it still has a refcount which will eventually drop once the migration is complete.  So, no. I should be able to rule that out.

Now, let's step back, is this even *related* to hugetlb?  Looking at the bug report, the kernel BUG is in `mm/page_table_check.c`, specifically `__page_table_check_zero` called from `page_table_check_free`, all the way down to `exit_mmap`.  The stack trace goes through `tlb_batch_pages_flush`. These pages are getting freed from `tlb_batch_pages_flush`, and they are *normal* pages or THPs, not hugetlb pages!  Hugetlb pages use a completely different freeing mechanism. They don't go through `free_pages_and_swap_cache`.  `free_pages_and_swap_cache` is for normal and swap cache pages. Therefore, the bug is *not* in hugetlb, but rather normal pages.

My focus should be on `free_pages_and_swap_cache`. That's where I need to dig next.



97/2 2026/05/25 00:23 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/swap_state.c IncludeLines:true Name:free_pages_and_swap_cache]

Results:
map[SourceCode: 381:	/*
 382:	 * Passed an array of pages, drop them all from swapcache and then release
 383:	 * them.  They are removed from the LRU and freed if this is their last use.
 384:	 */
 385:	void free_pages_and_swap_cache(struct encoded_page **pages, int nr)
 386:	{
 387:		struct folio_batch folios;
 388:		unsigned int refs[FOLIO_BATCH_SIZE];
 389:	
 390:		folio_batch_init(&folios);
 391:		for (int i = 0; i < nr; i++) {
 392:			struct folio *folio = page_folio(encoded_page_ptr(pages[i]));
 393:	
 394:			free_swap_cache(folio);
 395:			refs[folios.nr] = 1;
 396:			if (unlikely(encoded_page_flags(pages[i]) &
 397:				     ENCODED_PAGE_BIT_NR_PAGES_NEXT))
 398:				refs[folios.nr] = encoded_nr_pages(pages[++i]);
 399:	
 400:			if (folio_batch_add(&folios, folio) == 0)
 401:				folios_put_refs(&folios, refs);
 402:		}
 403:		if (folios.nr)
 404:			folios_put_refs(&folios, refs);
 405:	}
 SourceFile:mm/swap_state.c]

98/2 2026/05/25 00:23 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 99133
							output: 49
							thoughts: 129
						

Thoughts:
**Investigating Unexpected Page Counts**

Okay, so I'm looking at these regular pages, or rather, what's left of them after `unmap_vmas` has done its work. The question that's bugging me is: why on earth would I see a `anon_map_count` greater than zero on a normal page that's supposed to be *freed*? It doesn't make sense. The page should have been unmapped, right? Therefore, `anon_map_count` should be zero.

The only reason I can think of is that the unmapping process went sideways somewhere. Specifically, it seems like `page_table_check_pte_clear` either wasn't called at all, or it *was* called, but somehow the counter didn't get decremented. But why wouldn't the counter get decremented?

The obvious culprit, then, is a failure within `page_table_check_pte_clear` itself. It must be that `pte_user_accessible_page` returned `false`. This, is the most likely cause.

Therefore, the next step is crystal clear: I need to scrutinize `pte_user_accessible_page` on riscv. I need to understand exactly what conditions are causing it to return false, and whether those conditions are valid or a bug. This seems like a potential problem.



99/2 2026/05/25 00:23 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:pte_user_accessible_page]

Results:
map[SourceCode:1675:	static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
1676:	{
1677:		return (pte_val(pte) & _PAGE_PRESENT) && (pte_val(pte) & _PAGE_USER);
1678:	}
 SourceFile:arch/x86/include/asm/pgtable.h]

100/2 2026/05/25 00:23 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 99730
							output: 21
							thoughts: 41
						

Thoughts:
Okay, here's my interpretation of that thought process, assuming I'm deep in the weeds of kernel development:

**Initial Code Search Snag and RISC-V Cross-Reference**

Hmm, so the code search is pointing me to `arch/x86/include/asm/pgtable.h` for something related to page table entries? That's a bit unexpected. I was expecting something closer to the relevant architecture I'm working with. It suggests a potential issue, or maybe just a less-than-ideal code organization. Regardless, the X86 reference doesn't feel right. Let me pivot and see what's happening on the RISC-V side of things. I'll need to figure out what's going on with `pte_user_accessible_page`, or what's equivalent to it, in the context of the RISC-V architecture. It's likely that a similar mechanism exists, even if the implementation is completely different. I need to understand how user-mode access to physical pages is handled on that platform to solve this issue.



101/2 2026/05/25 00:23 tool grepper
0m Args:
map[Expression:pte_user_accessible_page]

Results:
map[Output:arch/arm64/include/asm/pgtable.h=1269=static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
--
arch/arm64/include/asm/pgtable.h-1278-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/arm64/include/asm/pgtable.h:1279:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/arm64/include/asm/pgtable.h-1280-{
--
arch/powerpc/include/asm/book3s/32/pgtable.h=426=static inline bool pte_access_permitted(pte_t pte, bool write)
--
arch/powerpc/include/asm/book3s/32/pgtable.h-440-
arch/powerpc/include/asm/book3s/32/pgtable.h:441:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/powerpc/include/asm/book3s/32/pgtable.h-442-{
--
arch/powerpc/include/asm/book3s/64/pgtable.h=537=static inline bool pte_access_permitted(pte_t pte, bool write)
--
arch/powerpc/include/asm/book3s/64/pgtable.h-551-
arch/powerpc/include/asm/book3s/64/pgtable.h:552:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/powerpc/include/asm/book3s/64/pgtable.h-553-{
--
arch/powerpc/include/asm/book3s/64/pgtable.h=928=static inline bool pud_user_accessible_page(struct mm_struct *mm, unsigned long addr, pud_t pud)
arch/powerpc/include/asm/book3s/64/pgtable.h-929-{
arch/powerpc/include/asm/book3s/64/pgtable.h:930:	return pud_leaf(pud) && pte_user_accessible_page(mm, addr, pud_pte(pud));
arch/powerpc/include/asm/book3s/64/pgtable.h-931-}
--
arch/powerpc/include/asm/book3s/64/pgtable.h=1099=static inline bool pmd_user_accessible_page(struct mm_struct *mm, unsigned long addr, pmd_t pmd)
arch/powerpc/include/asm/book3s/64/pgtable.h-1100-{
arch/powerpc/include/asm/book3s/64/pgtable.h:1101:	return pmd_leaf(pmd) && pte_user_accessible_page(mm, addr, pmd_pte(pmd));
arch/powerpc/include/asm/book3s/64/pgtable.h-1102-}
--
arch/powerpc/include/asm/nohash/pgtable.h=237=static inline bool pte_access_permitted(pte_t pte, bool write)
--
arch/powerpc/include/asm/nohash/pgtable.h-251-
arch/powerpc/include/asm/nohash/pgtable.h:252:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/powerpc/include/asm/nohash/pgtable.h-253-{
--
arch/riscv/include/asm/pgtable.h=964=static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
--
arch/riscv/include/asm/pgtable.h-971-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/riscv/include/asm/pgtable.h:972:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/riscv/include/asm/pgtable.h-973-{
--
arch/s390/include/asm/pgtable.h=1803=static inline int has_transparent_hugepage(void)
--
arch/s390/include/asm/pgtable.h-1809-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/s390/include/asm/pgtable.h:1810:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/s390/include/asm/pgtable.h-1811-{
--
arch/x86/include/asm/pgtable.h=1668=static inline bool arch_has_hw_nonleaf_pmd_young(void)
--
arch/x86/include/asm/pgtable.h-1674-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/x86/include/asm/pgtable.h:1675:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/x86/include/asm/pgtable.h-1676-{
--
mm/page_table_check.c=148=void __page_table_check_pte_clear(struct mm_struct *mm, unsigned long addr,
--
mm/page_table_check.c-153-
mm/page_table_check.c:154:	if (pte_user_accessible_page(mm, addr, pte))
mm/page_table_check.c-155-		page_table_check_clear(pte_pfn(pte), PAGE_SIZE >> PAGE_SHIFT);
--
mm/page_table_check.c=199=void __page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr,
--
mm/page_table_check.c-210-		__page_table_check_pte_clear(mm, addr + PAGE_SIZE * i, ptep_get(ptep + i));
mm/page_table_check.c:211:	if (pte_user_accessible_page(mm, addr, pte))
mm/page_table_check.c-212-		page_table_check_set(pte_pfn(pte), nr, pte_write(pte));
]

102/2 2026/05/25 00:23 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 101688
							output: 20
							thoughts: 814
						

Thoughts:
**Analyzing a Potential Page Table Check Issue in RISC-V**

Okay, let's dive into this. I'm looking at `arch/riscv/include/asm/pgtable.h`, specifically around line 972. I see the `pte_user_accessible_page` function. It seems straightforward: it checks if a PTE is present *and* user accessible. The crucial part is that if *either* condition is false, the function returns false. I start to think through the cases... what if the `pte_user` check is false? That implies a kernel mapping, which seems fine, except... wait, `page_table_check` is *only* for user page tables, not kernel ones!

So, the next scenario is if a user page table entry is cleared, but the `pte_user` bit remains false. If `pte_user` is false, the `_PAGE_USER` bit isn't set. User pages *must* have that bit set, by definition! But if `pte_clear` comes in and sets the PTE to zero, and then `ptep_get_and_clear` is called later, that will return zero and `pte_user_accessible_page(0)` is false. Thus the counter isn't decremented. `page_table_check_pte_clear` is never called. So, if `pte_clear` is called before `ptep_get_and_clear`, the counter is *never* decremented.

I need to confirm if there are any calls to `pte_clear` on a user PTE. I quickly identify `huge_pte_clear` in the RISC-V code as calling `pte_clear`. It makes perfect sense, clearing huge pages. But... `pte_clear` *doesn't* call `page_table_check_pte_clear`. So, if `huge_pte_clear` is called on a *present* user PTE (which I need to verify), it'll clear the PTE, but the `page_table_check` counter isn't decremented. Consequently, when the page is freed, the check will bug!

I recall checking `mm/hugetlb.c` earlier, and I don't see any calls to `huge_pte_clear` on present PTEs there. Just to be completely sure, I'll search the entire tree for calls to `huge_pte_clear` to be certain I haven't missed a call that clears a present user PTE.



103/2 2026/05/25 00:23 tool grepper
0m Args:
map[Expression:huge_pte_clear\(]

Results:
map[Output:arch/arm64/include/asm/hugetlb.h=51=extern pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
--
arch/arm64/include/asm/hugetlb.h-53-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/arm64/include/asm/hugetlb.h:54:extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/arm64/include/asm/hugetlb.h-55-			   pte_t *ptep, unsigned long sz);
--
arch/arm64/mm/hugetlbpage.c=344=pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
--
arch/arm64/mm/hugetlbpage.c-368-
arch/arm64/mm/hugetlbpage.c:369:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/arm64/mm/hugetlbpage.c-370-		    pte_t *ptep, unsigned long sz)
--
arch/loongarch/include/asm/hugetlb.h=11=uint64_t pmd_to_entrylo(unsigned long pmd_val);
--
arch/loongarch/include/asm/hugetlb.h-13-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/loongarch/include/asm/hugetlb.h:14:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/loongarch/include/asm/hugetlb.h-15-				  pte_t *ptep, unsigned long sz)
--
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h=23=static inline pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
--
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-30-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h:31:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-32-				  pte_t *ptep, unsigned long sz)
--
arch/riscv/include/asm/hugetlb.h=15=bool arch_hugetlb_migration_supported(struct hstate *h);
--
arch/riscv/include/asm/hugetlb.h-20-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/riscv/include/asm/hugetlb.h:21:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/riscv/include/asm/hugetlb.h-22-		    pte_t *ptep, unsigned long sz);
--
arch/riscv/mm/hugetlbpage.c=346=pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
--
arch/riscv/mm/hugetlbpage.c-360-
arch/riscv/mm/hugetlbpage.c:361:void huge_pte_clear(struct mm_struct *mm,
arch/riscv/mm/hugetlbpage.c-362-		    unsigned long addr,
--
arch/s390/include/asm/hugetlb.h=33=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
--
arch/s390/include/asm/hugetlb.h-40-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/s390/include/asm/hugetlb.h:41:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/s390/include/asm/hugetlb.h-42-				  pte_t *ptep, unsigned long sz)
--
include/asm-generic/hugetlb.h=55=static inline int huge_pte_uffd_wp(pte_t pte)
--
include/asm-generic/hugetlb.h-61-#ifndef __HAVE_ARCH_HUGE_PTE_CLEAR
include/asm-generic/hugetlb.h:62:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
include/asm-generic/hugetlb.h-63-		    pte_t *ptep, unsigned long sz)
--
mm/hugetlb.c=5052=static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,
--
mm/hugetlb.c-5074-	if (need_clear_uffd_wp && pte_is_uffd_wp_marker(pte)) {
mm/hugetlb.c:5075:		huge_pte_clear(mm, new_addr, dst_pte, sz);
mm/hugetlb.c-5076-	} else {
--
mm/hugetlb.c=5156=void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
--
mm/hugetlb.c-5220-			else
mm/hugetlb.c:5221:				huge_pte_clear(mm, address, ptep, sz);
mm/hugetlb.c-5222-			spin_unlock(ptl);
--
mm/hugetlb.c=6398=long hugetlb_change_protection(struct vm_area_struct *vma,
--
mm/hugetlb.c-6506-				/* Safe to modify directly (non-present->none). */
mm/hugetlb.c:6507:				huge_pte_clear(mm, address, ptep, psize);
mm/hugetlb.c-6508-		} else {
]

104/2 2026/05/25 00:23 llm expert
1m Model:
gemini-3.1-pro-preview

Tokens:
							input: 104635
							output: 18
							thoughts: 97
						

Thoughts:
**Debugging a Suspected Memory Issue**

Okay, so `huge_pte_clear`... no, that's definitely not it. My initial hunch was wrong. Looking back at the code, it's pretty clear that function is only used within `mm/hugetlb.c`. And we've already confirmed that it's only ever called when dealing with PTEs that aren't marked as present. So, scrap that lead. `huge_pte_clear` is a dead end.

Right, back to basics. If it's not the `huge_pte` related function, then what else could be clearing a PTE? Let's zoom out. What about the regular `pte_clear` function? Is *that* ever called on a user PTE that's currently present? That's the key question, isn't it? Gotta find any potential call sites. Time to run a quick search across the `mm/` directory for any instances of `pte_clear`. Hopefully, that will give me a new direction to pursue.



105/2 2026/05/25 00:24 tool grepper
0m Args:
map[Expression:pte_clear\(]

Results:
map[Output:
Full output is too long, showing 500 out of 731 lines.
Use more precise expression if possible.

[arch/alpha/include/asm/pgtable.h=211=extern inline int pte_present(pte_t pte)	{ return pte_val(pte) & _PAGE_VALID; }
 arch/alpha/include/asm/pgtable.h:212:extern inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/alpha/include/asm/pgtable.h-213-{
 --
 arch/alpha/include/asm/pgtable.h=279=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/alpha/include/asm/pgtable.h-284-
 arch/alpha/include/asm/pgtable.h:285:	pte_clear(mm, address, ptep);
 arch/alpha/include/asm/pgtable.h-286-	return pte;
 --
 arch/alpha/include/asm/pgtable.h=291=static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/alpha/include/asm/pgtable.h-296-
 arch/alpha/include/asm/pgtable.h:297:	page_table_check_pte_clear(mm, addr, pte);
 arch/alpha/include/asm/pgtable.h-298-	migrate_flush_tlb_page(vma, addr);
 --
 arch/arc/include/asm/pgtable-levels.h-173-#define pte_present(x)		(pte_val(x) & _PAGE_PRESENT)
 arch/arc/include/asm/pgtable-levels.h:174:#define pte_clear(mm,addr,ptep)	set_pte_at(mm, addr, ptep, __pte(0))
 arch/arc/include/asm/pgtable-levels.h-175-#define pte_page(pte)		pfn_to_page(pte_pfn(pte))
 --
 arch/arm/include/asm/pgtable.h=151=static inline pte_t *pmd_page_vaddr(pmd_t pmd)
 --
 arch/arm/include/asm/pgtable.h-162-
 arch/arm/include/asm/pgtable.h:163:#define pte_clear(mm,addr,ptep)	set_pte_ext(ptep, __pte(0), 0)
 arch/arm/include/asm/pgtable.h-164-
 --
 arch/arm/mm/mmu.c=390=void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
 --
 arch/arm/mm/mmu.c-407-	else
 arch/arm/mm/mmu.c:408:		pte_clear(NULL, vaddr, pte);
 arch/arm/mm/mmu.c-409-	local_flush_tlb_kernel_range(vaddr, vaddr + PAGE_SIZE);
 --
 arch/arm64/include/asm/hugetlb.h=51=extern pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/arm64/include/asm/hugetlb.h-53-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/arm64/include/asm/hugetlb.h:54:extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/arm64/include/asm/hugetlb.h-55-			   pte_t *ptep, unsigned long sz);
 --
 arch/arm64/include/asm/pgtable.h=1289=static inline bool pud_user_accessible_page(struct mm_struct *mm, unsigned long addr, pud_t pud)
 --
 arch/arm64/include/asm/pgtable.h-1298-
 arch/arm64/include/asm/pgtable.h:1299:static inline void __pte_clear(struct mm_struct *mm,
 arch/arm64/include/asm/pgtable.h-1300-			       unsigned long addr, pte_t *ptep)
 --
 arch/arm64/include/asm/pgtable.h=1352=static inline pte_t __ptep_get_and_clear_anysz(struct mm_struct *mm,
 --
 arch/arm64/include/asm/pgtable.h-1360-	case PAGE_SIZE:
 arch/arm64/include/asm/pgtable.h:1361:		page_table_check_pte_clear(mm, address, pte);
 arch/arm64/include/asm/pgtable.h-1362-		break;
 --
 arch/arm64/include/asm/pgtable.h=1775=static __always_inline void set_ptes(struct mm_struct *mm, unsigned long addr,
 --
 arch/arm64/include/asm/pgtable.h-1788-
 arch/arm64/include/asm/pgtable.h:1789:static inline void pte_clear(struct mm_struct *mm,
 arch/arm64/include/asm/pgtable.h-1790-				unsigned long addr, pte_t *ptep)
 --
 arch/arm64/include/asm/pgtable.h-1792-	contpte_try_unfold(mm, addr, ptep, __ptep_get(ptep));
 arch/arm64/include/asm/pgtable.h:1793:	__pte_clear(mm, addr, ptep);
 arch/arm64/include/asm/pgtable.h-1794-}
 --
 arch/arm64/mm/fixmap.c=119=void __set_fixmap(enum fixed_addresses idx,
 --
 arch/arm64/mm/fixmap.c-131-	} else {
 arch/arm64/mm/fixmap.c:132:		__pte_clear(&init_mm, addr, ptep);
 arch/arm64/mm/fixmap.c-133-		flush_tlb_kernel_range(addr, addr+PAGE_SIZE);
 --
 arch/arm64/mm/hugetlbpage.c=344=pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
 --
 arch/arm64/mm/hugetlbpage.c-368-
 arch/arm64/mm/hugetlbpage.c:369:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/arm64/mm/hugetlbpage.c-370-		    pte_t *ptep, unsigned long sz)
 --
 arch/arm64/mm/hugetlbpage.c-377-	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
 arch/arm64/mm/hugetlbpage.c:378:		__pte_clear(mm, addr, ptep);
 arch/arm64/mm/hugetlbpage.c-379-}
 --
 arch/arm64/mm/mmu.c=1466=static void unmap_hotplug_pte_range(pmd_t *pmdp, unsigned long addr,
 --
 arch/arm64/mm/mmu.c-1478-		WARN_ON(!pte_present(pte));
 arch/arm64/mm/mmu.c:1479:		__pte_clear(&init_mm, addr, ptep);
 arch/arm64/mm/mmu.c-1480-		if (free_mapped) {
 --
 arch/csky/include/asm/pgtable.h-33-#define pmd_page(pmd)	(pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
 arch/csky/include/asm/pgtable.h:34:#define pte_clear(mm, addr, ptep)	set_pte((ptep), \
 arch/csky/include/asm/pgtable.h-35-	(((unsigned int) addr >= PAGE_OFFSET) ? __pte(_PAGE_GLOBAL) : __pte(0)))
 --
 arch/hexagon/include/asm/pgtable.h=165=static inline void pmd_clear(pmd_t *pmd_entry_ptr)
 --
 arch/hexagon/include/asm/pgtable.h-172- */
 arch/hexagon/include/asm/pgtable.h:173:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/hexagon/include/asm/pgtable.h-174-				pte_t *ptep)
 --
 arch/loongarch/include/asm/hugetlb.h=11=uint64_t pmd_to_entrylo(unsigned long pmd_val);
 --
 arch/loongarch/include/asm/hugetlb.h-13-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/loongarch/include/asm/hugetlb.h:14:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/loongarch/include/asm/hugetlb.h-15-				  pte_t *ptep, unsigned long sz)
 --
 arch/loongarch/include/asm/pgtable.h=364=static inline void set_pte(pte_t *ptep, pte_t pteval)
 --
 arch/loongarch/include/asm/pgtable.h-373-
 arch/loongarch/include/asm/pgtable.h:374:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/loongarch/include/asm/pgtable.h-375-{
 --
 arch/loongarch/mm/init.c=210=void __init __set_fixmap(enum fixed_addresses idx,
 --
 arch/loongarch/mm/init.c-226-	else {
 arch/loongarch/mm/init.c:227:		pte_clear(&init_mm, addr, ptep);
 arch/loongarch/mm/init.c-228-		flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
 --
 arch/m68k/include/asm/mcf_pgtable.h=120=static inline int pte_present(pte_t pte)
 --
 arch/m68k/include/asm/mcf_pgtable.h-124-
 arch/m68k/include/asm/mcf_pgtable.h:125:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/m68k/include/asm/mcf_pgtable.h-126-	pte_t *ptep)
 --
 arch/m68k/include/asm/motorola_pgtable.h=95=static inline void pud_set(pud_t *pudp, pmd_t *pmdp)
 --
 arch/m68k/include/asm/motorola_pgtable.h-106-#define pte_present(pte)	(pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROTNONE))
 arch/m68k/include/asm/motorola_pgtable.h:107:#define pte_clear(mm,addr,ptep)		({ pte_val(*(ptep)) = 0; })
 arch/m68k/include/asm/motorola_pgtable.h-108-
 --
 arch/microblaze/include/asm/pgtable.h=29=extern pte_t *va_to_pte(unsigned long address);
 --
 arch/microblaze/include/asm/pgtable.h-211-#define pte_present(pte)	(pte_val(pte) & _PAGE_PRESENT)
 arch/microblaze/include/asm/pgtable.h:212:#define pte_clear(mm, addr, ptep) \
 arch/microblaze/include/asm/pgtable.h-213-	do { set_pte_at((mm), (addr), (ptep), __pte(0)); } while (0)
 --
 arch/mips/include/asm/pgtable.h=119=static inline void set_pte(pte_t *ptep, pte_t pte)
 --
 arch/mips/include/asm/pgtable.h-142-
 arch/mips/include/asm/pgtable.h:143:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/mips/include/asm/pgtable.h-144-{
 --
 arch/mips/include/asm/pgtable.h=171=static inline void set_pte(pte_t *ptep, pte_t pteval)
 --
 arch/mips/include/asm/pgtable.h-189-
 arch/mips/include/asm/pgtable.h:190:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/mips/include/asm/pgtable.h-191-{
 --
 arch/nios2/include/asm/pgtable.h=195=static inline int pmd_none(pmd_t pmd)
 --
 arch/nios2/include/asm/pgtable.h-202-
 arch/nios2/include/asm/pgtable.h:203:static inline void pte_clear(struct mm_struct *mm,
 arch/nios2/include/asm/pgtable.h-204-				unsigned long addr, pte_t *ptep)
 --
 arch/openrisc/include/asm/pgtable.h=42=extern void paging_init(void);
 --
 arch/openrisc/include/asm/pgtable.h-183-#define pte_present(x)	(pte_val(x) & _PAGE_PRESENT)
 arch/openrisc/include/asm/pgtable.h:184:#define pte_clear(mm, addr, xp)	do { pte_val(*(xp)) = 0; } while (0)
 arch/openrisc/include/asm/pgtable.h-185-
 --
 arch/openrisc/mm/init.c=196=static int __init map_page(unsigned long va, phys_addr_t pa, pgprot_t prot)
 --
 arch/openrisc/mm/init.c-213-	else
 arch/openrisc/mm/init.c:214:		pte_clear(&init_mm, va, pte);
 arch/openrisc/mm/init.c-215-
 --
 arch/parisc/include/asm/pgtable.h=263=extern pte_t pg0[];
 --
 arch/parisc/include/asm/pgtable.h-267-#define pte_user(x)	(pte_val(x) & _PAGE_USER)
 arch/parisc/include/asm/pgtable.h:268:#define pte_clear(mm, addr, xp) set_pte_at((mm), (addr), (xp), __pte(0))
 arch/parisc/include/asm/pgtable.h-269-
 --
 arch/parisc/kernel/pci-dma.c=153=static inline void unmap_uncached_pte(pmd_t * pmd, unsigned long vaddr,
 --
 arch/parisc/kernel/pci-dma.c-175-
 arch/parisc/kernel/pci-dma.c:176:		pte_clear(&init_mm, vaddr, pte);
 arch/parisc/kernel/pci-dma.c-177-		purge_tlb_start(flags);
 --
 arch/parisc/mm/fixmap.c=27=void notrace clear_fixmap(enum fixed_addresses idx)
 --
 arch/parisc/mm/fixmap.c-34-
 arch/parisc/mm/fixmap.c:35:	pte_clear(&init_mm, vaddr, pte);
 arch/parisc/mm/fixmap.c-36-
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h=138=void unmap_kernel_page(unsigned long va);
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h-212-
 arch/powerpc/include/asm/book3s/32/pgtable.h:213:#define pte_clear(mm, addr, ptep) \
 arch/powerpc/include/asm/book3s/32/pgtable.h-214-	do { pte_update(mm, addr, ptep, ~_PAGE_HASHPTE, 0, 0); } while (0)
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h=312=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h-316-
 arch/powerpc/include/asm/book3s/32/pgtable.h:317:	page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/book3s/32/pgtable.h-318-
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h=418=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-422-
 arch/powerpc/include/asm/book3s/64/pgtable.h:423:	page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/book3s/64/pgtable.h-424-
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h=429=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-440-		old_pte = radix__ptep_get_and_clear_full(mm, addr, ptep, full);
 arch/powerpc/include/asm/book3s/64/pgtable.h:441:		page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/book3s/64/pgtable.h-442-
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-448-
 arch/powerpc/include/asm/book3s/64/pgtable.h:449:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/powerpc/include/asm/book3s/64/pgtable.h-450-			     pte_t * ptep)
 --
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h=23=static inline pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 --
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-30-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h:31:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-32-				  pte_t *ptep, unsigned long sz)
 --
 arch/powerpc/include/asm/nohash/pgtable.h=124=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/powerpc/include/asm/nohash/pgtable.h-128-
 arch/powerpc/include/asm/nohash/pgtable.h:129:	page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/nohash/pgtable.h-130-
 --
 arch/powerpc/include/asm/nohash/pgtable.h-134-
 arch/powerpc/include/asm/nohash/pgtable.h:135:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/powerpc/include/asm/nohash/pgtable.h-136-{
 --
 arch/powerpc/lib/code-patching.c=246=static void unmap_patch_area(unsigned long addr)
 --
 arch/powerpc/lib/code-patching.c-276-	 */
 arch/powerpc/lib/code-patching.c:277:	pte_clear(&init_mm, addr, ptep);
 arch/powerpc/lib/code-patching.c-278-	flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
 --
 arch/powerpc/lib/code-patching.c=281=static int __do_patch_mem_mm(void *addr, unsigned long val, bool is_dword)
 --
 arch/powerpc/lib/code-patching.c-314-
 arch/powerpc/lib/code-patching.c:315:	pte_clear(patching_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-316-	/*
 --
 arch/powerpc/lib/code-patching.c=327=static int __do_patch_mem(void *addr, unsigned long val, bool is_dword)
 --
 arch/powerpc/lib/code-patching.c-345-
 arch/powerpc/lib/code-patching.c:346:	pte_clear(&init_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-347-	flush_tlb_kernel_range(text_poke_addr, text_poke_addr + PAGE_SIZE);
 --
 arch/powerpc/lib/code-patching.c=468=static int __do_patch_instructions_mm(u32 *addr, u32 *code, size_t len, bool repeat_instr)
 --
 arch/powerpc/lib/code-patching.c-502-
 arch/powerpc/lib/code-patching.c:503:	pte_clear(patching_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-504-	/*
 --
 arch/powerpc/lib/code-patching.c=519=static int __do_patch_instructions(u32 *addr, u32 *code, size_t len, bool repeat_instr)
 --
 arch/powerpc/lib/code-patching.c-537-
 arch/powerpc/lib/code-patching.c:538:	pte_clear(&init_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-539-	flush_tlb_kernel_range(text_poke_addr, text_poke_addr + PAGE_SIZE);
 --
 arch/powerpc/mm/book3s64/hash_native.c=660=static void hpte_decode(struct hash_pte *hpte, unsigned long slot,
 --
 arch/powerpc/mm/book3s64/hash_native.c-735- */
 arch/powerpc/mm/book3s64/hash_native.c:736:static notrace void native_hpte_clear(void)
 arch/powerpc/mm/book3s64/hash_native.c-737-{
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=787=static void __meminit remove_pte_table(pte_t *pte_start, unsigned long addr,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-805-				free_vmemmap_pages(pte_page(*pte), altmap, 0);
 arch/powerpc/mm/book3s64/radix_pgtable.c:806:			pte_clear(&init_mm, addr, pte);
 arch/powerpc/mm/book3s64/radix_pgtable.c-807-			pages++;
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-811-			free_vmemmap_pages(pte_page(*pte), altmap, 0);
 arch/powerpc/mm/book3s64/radix_pgtable.c:812:			pte_clear(&init_mm, addr, pte);
 arch/powerpc/mm/book3s64/radix_pgtable.c-813-		}
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=820=static void __meminit remove_pmd_table(pmd_t *pmd_start, unsigned long addr,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-839-					free_vmemmap_pages(pmd_page(*pmd), altmap, get_order(PMD_SIZE));
 arch/powerpc/mm/book3s64/radix_pgtable.c:840:				pte_clear(&init_mm, addr, (pte_t *)pmd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-841-				pages++;
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-845-				free_vmemmap_pages(pmd_page(*pmd), altmap, get_order(PMD_SIZE));
 arch/powerpc/mm/book3s64/radix_pgtable.c:846:				pte_clear(&init_mm, addr, (pte_t *)pmd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-847-			}
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=860=static void __meminit remove_pud_table(pud_t *pud_start, unsigned long addr,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-880-			}
 arch/powerpc/mm/book3s64/radix_pgtable.c:881:			pte_clear(&init_mm, addr, (pte_t *)pud);
 arch/powerpc/mm/book3s64/radix_pgtable.c-882-			pages++;
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=895=remove_pagetable(unsigned long start, unsigned long end, bool direct,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-919-
 arch/powerpc/mm/book3s64/radix_pgtable.c:920:			pte_clear(&init_mm, addr, (pte_t *)pgd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-921-			continue;
 --
 arch/powerpc/mm/pgtable.c=239=void unmap_kernel_page(unsigned long va)
 --
 arch/powerpc/mm/pgtable.c-243-
 arch/powerpc/mm/pgtable.c:244:	pte_clear(&init_mm, va, ptep);
 arch/powerpc/mm/pgtable.c-245-	flush_tlb_kernel_range(va, va + PAGE_SIZE);
 --
 arch/powerpc/platforms/ps3/htab.c=152=static void ps3_hpte_invalidate(unsigned long slot, unsigned long vpn,
 --
 arch/powerpc/platforms/ps3/htab.c-171-/* Called during kexec sequence with MMU off */
 arch/powerpc/platforms/ps3/htab.c:172:static notrace void ps3_hpte_clear(void)
 arch/powerpc/platforms/ps3/htab.c-173-{
 --
 arch/riscv/include/asm/hugetlb.h=15=bool arch_hugetlb_migration_supported(struct hstate *h);
 --
 arch/riscv/include/asm/hugetlb.h-20-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/riscv/include/asm/hugetlb.h:21:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/riscv/include/asm/hugetlb.h-22-		    pte_t *ptep, unsigned long sz);
 --
 arch/riscv/include/asm/pgtable.h=622=static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
 --
 arch/riscv/include/asm/pgtable.h-636-
 arch/riscv/include/asm/pgtable.h:637:static inline void pte_clear(struct mm_struct *mm,
 arch/riscv/include/asm/pgtable.h-638-	unsigned long addr, pte_t *ptep)
 --
 arch/riscv/include/asm/pgtable.h=651=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/riscv/include/asm/pgtable.h-661-
 arch/riscv/include/asm/pgtable.h:662:	page_table_check_pte_clear(mm, address, pte);
 arch/riscv/include/asm/pgtable.h-663-
 --
 arch/riscv/mm/hugetlbpage.c=346=pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/riscv/mm/hugetlbpage.c-360-
 arch/riscv/mm/hugetlbpage.c:361:void huge_pte_clear(struct mm_struct *mm,
 arch/riscv/mm/hugetlbpage.c-362-		    unsigned long addr,
 --
 arch/riscv/mm/hugetlbpage.c-370-	if (!pte_napot(pte)) {
 arch/riscv/mm/hugetlbpage.c:371:		pte_clear(mm, addr, ptep);
 arch/riscv/mm/hugetlbpage.c-372-		return;
 --
 arch/riscv/mm/hugetlbpage.c-377-	for (i = 0; i < pte_num; i++, addr += pgsize, ptep++)
 arch/riscv/mm/hugetlbpage.c:378:		pte_clear(mm, addr, ptep);
 arch/riscv/mm/hugetlbpage.c-379-}
 --
 arch/riscv/mm/init.c=369=void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
 --
 arch/riscv/mm/init.c-380-	else
 arch/riscv/mm/init.c:381:		pte_clear(&init_mm, addr, ptep);
 arch/riscv/mm/init.c-382-	local_flush_tlb_page(addr);
 --
 arch/riscv/mm/init.c=1574=static void __meminit remove_pte_mapping(pte_t *pte_base, unsigned long addr, unsigned long end,
 --
 arch/riscv/mm/init.c-1589-
 arch/riscv/mm/init.c:1590:		pte_clear(&init_mm, addr, ptep);
 arch/riscv/mm/init.c-1591-		if (is_vmemmap)
 --
 arch/s390/include/asm/hugetlb.h=33=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/s390/include/asm/hugetlb.h-40-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/s390/include/asm/hugetlb.h:41:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/s390/include/asm/hugetlb.h-42-				  pte_t *ptep, unsigned long sz)
 --
 arch/s390/include/asm/pgtable.h=1004=static inline void pmd_clear(pmd_t *pmdp)
 --
 arch/s390/include/asm/pgtable.h-1008-
 arch/s390/include/asm/pgtable.h:1009:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/s390/include/asm/pgtable.h-1010-{
 --
 arch/s390/include/asm/pgtable.h=1186=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/s390/include/asm/pgtable.h-1194-		WARN_ON_ONCE(uv_convert_from_secure_pte(res));
 arch/s390/include/asm/pgtable.h:1195:	page_table_check_pte_clear(mm, addr, res);
 arch/s390/include/asm/pgtable.h-1196-	return res;
 --
 arch/s390/include/asm/pgtable.h=1205=static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/s390/include/asm/pgtable.h-1213-		WARN_ON_ONCE(uv_convert_from_secure_pte(res));
 arch/s390/include/asm/pgtable.h:1214:	page_table_check_pte_clear(vma->vm_mm, addr, res);
 arch/s390/include/asm/pgtable.h-1215-	return res;
 --
 arch/s390/include/asm/pgtable.h=1226=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
 --
 arch/s390/include/asm/pgtable.h-1238-
 arch/s390/include/asm/pgtable.h:1239:	page_table_check_pte_clear(mm, addr, res);
 arch/s390/include/asm/pgtable.h-1240-
 --
 arch/s390/mm/gmap_helpers.c=46=void gmap_helper_zap_one_page(struct mm_struct *mm, unsigned long vmaddr)
 --
 arch/s390/mm/gmap_helpers.c-64-		ptep_zap_softleaf_entry(mm, softleaf_from_pte(*ptep));
 arch/s390/mm/gmap_helpers.c:65:		pte_clear(mm, vmaddr, ptep);
 arch/s390/mm/gmap_helpers.c-66-	}
 --
 arch/s390/mm/vmem.c=168=static int __ref modify_pte_table(pmd_t *pmd, unsigned long addr,
 --
 arch/s390/mm/vmem.c-183-				vmem_free_pages((unsigned long)pfn_to_virt(pte_pfn(*pte)), get_order(PAGE_SIZE), altmap);
 arch/s390/mm/vmem.c:184:			pte_clear(&init_mm, addr, pte);
 arch/s390/mm/vmem.c-185-		} else if (pte_none(*pte)) {
 --
 arch/s390/mm/vmem.c=654=void vmem_unmap_4k_page(unsigned long addr)
 --
 arch/s390/mm/vmem.c-660-	__ptep_ipte(addr, ptep, 0, 0, IPTE_GLOBAL);
 arch/s390/mm/vmem.c:661:	pte_clear(&init_mm, addr, ptep);
 arch/s390/mm/vmem.c-662-	mutex_unlock(&vmem_mutex);
 --
 arch/sh/include/asm/pgtable_32.h=300=static inline void set_pte(pte_t *ptep, pte_t pte)
 --
 arch/sh/include/asm/pgtable_32.h-324-
 arch/sh/include/asm/pgtable_32.h:325:#define pte_clear(mm, addr, ptep) set_pte(ptep, __pte(0))
 arch/sh/include/asm/pgtable_32.h-326-
 --
 arch/sh/mm/kmap.c=51=void kunmap_coherent(void *kvaddr)
 --
 arch/sh/mm/kmap.c-59-
 arch/sh/mm/kmap.c:60:		pte_clear(&init_mm, vaddr, kmap_coherent_pte - idx);
 arch/sh/mm/kmap.c-61-		local_flush_tlb_one(get_asid(), vaddr);
 --
 arch/sparc/include/asm/pgtable_32.h=145=static inline int pte_none(pte_t pte)
 --
 arch/sparc/include/asm/pgtable_32.h-149-
 arch/sparc/include/asm/pgtable_32.h:150:static inline void __pte_clear(pte_t *ptep)
 arch/sparc/include/asm/pgtable_32.h-151-{
 --
 arch/sparc/include/asm/pgtable_32.h-154-
 arch/sparc/include/asm/pgtable_32.h:155:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/sparc/include/asm/pgtable_32.h-156-{
 arch/sparc/include/asm/pgtable_32.h:157:	__pte_clear(ptep);
 arch/sparc/include/asm/pgtable_32.h-158-}
 --
 arch/sparc/include/asm/pgtable_64.h=931=static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
 --
 arch/sparc/include/asm/pgtable_64.h-944-
 arch/sparc/include/asm/pgtable_64.h:945:#define pte_clear(mm,addr,ptep)		\
 arch/sparc/include/asm/pgtable_64.h-946-	set_pte_at((mm), (addr), (ptep), __pte(0UL))
 --
 arch/sparc/mm/srmmu.c=526=static inline void srmmu_unmapioaddr(unsigned long virt_addr)
 --
 arch/sparc/mm/srmmu.c-541-	/* No need to flush uncacheable page. */
 arch/sparc/mm/srmmu.c:542:	__pte_clear(ptep);
 arch/sparc/mm/srmmu.c-543-}
 --
 arch/um/include/asm/pgtable.h=35=extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
 --
 arch/um/include/asm/pgtable.h-73-
 arch/um/include/asm/pgtable.h:74:#define pte_clear(mm, addr, xp) pte_set_val(*(xp), (phys_t) 0, __pgprot(_PAGE_NEEDSYNC))
 arch/um/include/asm/pgtable.h-75-
 --
 arch/x86/include/asm/paravirt.h=457=static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
 --
 arch/x86/include/asm/paravirt.h-461-
 arch/x86/include/asm/paravirt.h:462:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/x86/include/asm/paravirt.h-463-			     pte_t *ptep)
 --
 arch/x86/include/asm/pgtable-2level.h=39=static inline void native_pud_clear(pud_t *pudp)
 --
 arch/x86/include/asm/pgtable-2level.h-42-
 arch/x86/include/asm/pgtable-2level.h:43:static inline void native_pte_clear(struct mm_struct *mm,
 arch/x86/include/asm/pgtable-2level.h-44-				    unsigned long addr, pte_t *xp)
 --
 arch/x86/include/asm/pgtable-3level.h=53=static inline void native_set_pud(pud_t *pudp, pud_t pud)
 --
 arch/x86/include/asm/pgtable-3level.h-65- */
 arch/x86/include/asm/pgtable-3level.h:66:static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/x86/include/asm/pgtable-3level.h-67-				    pte_t *ptep)
 --
 arch/x86/include/asm/pgtable.h=55=extern pmdval_t early_pmd_flags;
 --
 arch/x86/include/asm/pgtable.h-87-
 arch/x86/include/asm/pgtable.h:88:#define pte_clear(mm, addr, ptep)	native_pte_clear(mm, addr, ptep)
 arch/x86/include/asm/pgtable.h-89-#define pmd_clear(pmd)			native_pmd_clear(pmd)
 --
 arch/x86/include/asm/pgtable.h=1181=static inline pte_t native_local_ptep_get_and_clear(pte_t *ptep)
 --
 arch/x86/include/asm/pgtable.h-1185-	/* Pure native function needs no input for mm, addr */
 arch/x86/include/asm/pgtable.h:1186:	native_pte_clear(NULL, 0, ptep);
 arch/x86/include/asm/pgtable.h-1187-	return res;
 --
 arch/x86/include/asm/pgtable.h=1243=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/x86/include/asm/pgtable.h-1246-	pte_t pte = native_ptep_get_and_clear(ptep);
 arch/x86/include/asm/pgtable.h:1247:	page_table_check_pte_clear(mm, addr, pte);
 arch/x86/include/asm/pgtable.h-1248-	return pte;
 --
 arch/x86/include/asm/pgtable.h=1252=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
 --
 arch/x86/include/asm/pgtable.h-1262-		pte = native_local_ptep_get_and_clear(ptep);
 arch/x86/include/asm/pgtable.h:1263:		page_table_check_pte_clear(mm, addr, pte);
 arch/x86/include/asm/pgtable.h-1264-	} else {
 --
 arch/x86/include/asm/pgtable_32.h=42=do {						\
 arch/x86/include/asm/pgtable_32.h:43:	pte_clear(&init_mm, (vaddr), (ptep));	\
 arch/x86/include/asm/pgtable_32.h-44-	flush_tlb_one_kernel((vaddr));		\
 --
 arch/x86/include/asm/pgtable_64.h=61=static inline void native_set_pte(pte_t *ptep, pte_t pte)
 --
 arch/x86/include/asm/pgtable_64.h-65-
 arch/x86/include/asm/pgtable_64.h:66:static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/x86/include/asm/pgtable_64.h-67-				    pte_t *ptep)
 --
 arch/x86/include/asm/pgtable_64.h=87=static inline pte_t native_ptep_get_and_clear(pte_t *xp)
 --
 arch/x86/include/asm/pgtable_64.h-94-	pte_t ret = *xp;
 arch/x86/include/asm/pgtable_64.h:95:	native_pte_clear(NULL, 0, xp);
 arch/x86/include/asm/pgtable_64.h-96-	return ret;
 --
 arch/x86/kernel/alternative.c=2546=static void *__text_poke(text_poke_f func, void *addr, const void *src, size_t len)
 --
 arch/x86/kernel/alternative.c-2619-
 arch/x86/kernel/alternative.c:2620:	pte_clear(text_poke_mm, text_poke_mm_addr, ptep);
 arch/x86/kernel/alternative.c-2621-	if (cross_page_boundary)
 arch/x86/kernel/alternative.c:2622:		pte_clear(text_poke_mm, text_poke_mm_addr + PAGE_SIZE, ptep + 1);
 arch/x86/kernel/alternative.c-2623-
 --
]
]

106/2 2026/05/25 00:24 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 116967
							output: 18
							thoughts: 330
						

Thoughts:
**Analyzing `pte_clear` in the RISC-V Architecture**

Okay, so I'm digging into how page table entries are handled on RISC-V and I've stumbled upon something that needs clarification. I was under the impression that `pte_clear` was invoked somewhere within `ptep_get_and_clear`, but I've just reviewed the RISC-V implementation of `ptep_get_and_clear` and it's not the case.

Specifically, looking at the code, `ptep_get_and_clear` in `riscv` uses either `xchg` (for SMP configurations) or a simple `set_pte` (for non-SMP). Neither of these calls `pte_clear` directly. It *does* call `page_table_check_pte_clear` which I need to investigate in more detail as it might be relevant.

Then, I went to look at what `pte_clear` *actually* does in RISC-V and that is another story. It's defined as a simple call to `__set_pte_at` with a zero PTE value. Importantly, it doesn't appear to call `page_table_check_pte_clear`. That's a key distinction I need to keep in mind.

So, now I'm thinking, where *else* is `pte_clear` used in the RISC-V architecture? I need to understand the complete picture of how page table entries are cleared in different contexts. A quick search of the `arch/riscv/` directory for `pte_clear` should shed some light on this.



107/2 2026/05/25 00:24 tool grepper
0m Args:
map[Expression:pte_clear\(]

Results:
map[Output:
Full output is too long, showing 500 out of 731 lines.
Use more precise expression if possible.

[arch/alpha/include/asm/pgtable.h=211=extern inline int pte_present(pte_t pte)	{ return pte_val(pte) & _PAGE_VALID; }
 arch/alpha/include/asm/pgtable.h:212:extern inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/alpha/include/asm/pgtable.h-213-{
 --
 arch/alpha/include/asm/pgtable.h=279=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/alpha/include/asm/pgtable.h-284-
 arch/alpha/include/asm/pgtable.h:285:	pte_clear(mm, address, ptep);
 arch/alpha/include/asm/pgtable.h-286-	return pte;
 --
 arch/alpha/include/asm/pgtable.h=291=static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/alpha/include/asm/pgtable.h-296-
 arch/alpha/include/asm/pgtable.h:297:	page_table_check_pte_clear(mm, addr, pte);
 arch/alpha/include/asm/pgtable.h-298-	migrate_flush_tlb_page(vma, addr);
 --
 arch/arc/include/asm/pgtable-levels.h-173-#define pte_present(x)		(pte_val(x) & _PAGE_PRESENT)
 arch/arc/include/asm/pgtable-levels.h:174:#define pte_clear(mm,addr,ptep)	set_pte_at(mm, addr, ptep, __pte(0))
 arch/arc/include/asm/pgtable-levels.h-175-#define pte_page(pte)		pfn_to_page(pte_pfn(pte))
 --
 arch/arm/include/asm/pgtable.h=151=static inline pte_t *pmd_page_vaddr(pmd_t pmd)
 --
 arch/arm/include/asm/pgtable.h-162-
 arch/arm/include/asm/pgtable.h:163:#define pte_clear(mm,addr,ptep)	set_pte_ext(ptep, __pte(0), 0)
 arch/arm/include/asm/pgtable.h-164-
 --
 arch/arm/mm/mmu.c=390=void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
 --
 arch/arm/mm/mmu.c-407-	else
 arch/arm/mm/mmu.c:408:		pte_clear(NULL, vaddr, pte);
 arch/arm/mm/mmu.c-409-	local_flush_tlb_kernel_range(vaddr, vaddr + PAGE_SIZE);
 --
 arch/arm64/include/asm/hugetlb.h=51=extern pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/arm64/include/asm/hugetlb.h-53-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/arm64/include/asm/hugetlb.h:54:extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/arm64/include/asm/hugetlb.h-55-			   pte_t *ptep, unsigned long sz);
 --
 arch/arm64/include/asm/pgtable.h=1289=static inline bool pud_user_accessible_page(struct mm_struct *mm, unsigned long addr, pud_t pud)
 --
 arch/arm64/include/asm/pgtable.h-1298-
 arch/arm64/include/asm/pgtable.h:1299:static inline void __pte_clear(struct mm_struct *mm,
 arch/arm64/include/asm/pgtable.h-1300-			       unsigned long addr, pte_t *ptep)
 --
 arch/arm64/include/asm/pgtable.h=1352=static inline pte_t __ptep_get_and_clear_anysz(struct mm_struct *mm,
 --
 arch/arm64/include/asm/pgtable.h-1360-	case PAGE_SIZE:
 arch/arm64/include/asm/pgtable.h:1361:		page_table_check_pte_clear(mm, address, pte);
 arch/arm64/include/asm/pgtable.h-1362-		break;
 --
 arch/arm64/include/asm/pgtable.h=1775=static __always_inline void set_ptes(struct mm_struct *mm, unsigned long addr,
 --
 arch/arm64/include/asm/pgtable.h-1788-
 arch/arm64/include/asm/pgtable.h:1789:static inline void pte_clear(struct mm_struct *mm,
 arch/arm64/include/asm/pgtable.h-1790-				unsigned long addr, pte_t *ptep)
 --
 arch/arm64/include/asm/pgtable.h-1792-	contpte_try_unfold(mm, addr, ptep, __ptep_get(ptep));
 arch/arm64/include/asm/pgtable.h:1793:	__pte_clear(mm, addr, ptep);
 arch/arm64/include/asm/pgtable.h-1794-}
 --
 arch/arm64/mm/fixmap.c=119=void __set_fixmap(enum fixed_addresses idx,
 --
 arch/arm64/mm/fixmap.c-131-	} else {
 arch/arm64/mm/fixmap.c:132:		__pte_clear(&init_mm, addr, ptep);
 arch/arm64/mm/fixmap.c-133-		flush_tlb_kernel_range(addr, addr+PAGE_SIZE);
 --
 arch/arm64/mm/hugetlbpage.c=344=pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
 --
 arch/arm64/mm/hugetlbpage.c-368-
 arch/arm64/mm/hugetlbpage.c:369:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/arm64/mm/hugetlbpage.c-370-		    pte_t *ptep, unsigned long sz)
 --
 arch/arm64/mm/hugetlbpage.c-377-	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
 arch/arm64/mm/hugetlbpage.c:378:		__pte_clear(mm, addr, ptep);
 arch/arm64/mm/hugetlbpage.c-379-}
 --
 arch/arm64/mm/mmu.c=1466=static void unmap_hotplug_pte_range(pmd_t *pmdp, unsigned long addr,
 --
 arch/arm64/mm/mmu.c-1478-		WARN_ON(!pte_present(pte));
 arch/arm64/mm/mmu.c:1479:		__pte_clear(&init_mm, addr, ptep);
 arch/arm64/mm/mmu.c-1480-		if (free_mapped) {
 --
 arch/csky/include/asm/pgtable.h-33-#define pmd_page(pmd)	(pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
 arch/csky/include/asm/pgtable.h:34:#define pte_clear(mm, addr, ptep)	set_pte((ptep), \
 arch/csky/include/asm/pgtable.h-35-	(((unsigned int) addr >= PAGE_OFFSET) ? __pte(_PAGE_GLOBAL) : __pte(0)))
 --
 arch/hexagon/include/asm/pgtable.h=165=static inline void pmd_clear(pmd_t *pmd_entry_ptr)
 --
 arch/hexagon/include/asm/pgtable.h-172- */
 arch/hexagon/include/asm/pgtable.h:173:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/hexagon/include/asm/pgtable.h-174-				pte_t *ptep)
 --
 arch/loongarch/include/asm/hugetlb.h=11=uint64_t pmd_to_entrylo(unsigned long pmd_val);
 --
 arch/loongarch/include/asm/hugetlb.h-13-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/loongarch/include/asm/hugetlb.h:14:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/loongarch/include/asm/hugetlb.h-15-				  pte_t *ptep, unsigned long sz)
 --
 arch/loongarch/include/asm/pgtable.h=364=static inline void set_pte(pte_t *ptep, pte_t pteval)
 --
 arch/loongarch/include/asm/pgtable.h-373-
 arch/loongarch/include/asm/pgtable.h:374:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/loongarch/include/asm/pgtable.h-375-{
 --
 arch/loongarch/mm/init.c=210=void __init __set_fixmap(enum fixed_addresses idx,
 --
 arch/loongarch/mm/init.c-226-	else {
 arch/loongarch/mm/init.c:227:		pte_clear(&init_mm, addr, ptep);
 arch/loongarch/mm/init.c-228-		flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
 --
 arch/m68k/include/asm/mcf_pgtable.h=120=static inline int pte_present(pte_t pte)
 --
 arch/m68k/include/asm/mcf_pgtable.h-124-
 arch/m68k/include/asm/mcf_pgtable.h:125:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/m68k/include/asm/mcf_pgtable.h-126-	pte_t *ptep)
 --
 arch/m68k/include/asm/motorola_pgtable.h=95=static inline void pud_set(pud_t *pudp, pmd_t *pmdp)
 --
 arch/m68k/include/asm/motorola_pgtable.h-106-#define pte_present(pte)	(pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROTNONE))
 arch/m68k/include/asm/motorola_pgtable.h:107:#define pte_clear(mm,addr,ptep)		({ pte_val(*(ptep)) = 0; })
 arch/m68k/include/asm/motorola_pgtable.h-108-
 --
 arch/microblaze/include/asm/pgtable.h=29=extern pte_t *va_to_pte(unsigned long address);
 --
 arch/microblaze/include/asm/pgtable.h-211-#define pte_present(pte)	(pte_val(pte) & _PAGE_PRESENT)
 arch/microblaze/include/asm/pgtable.h:212:#define pte_clear(mm, addr, ptep) \
 arch/microblaze/include/asm/pgtable.h-213-	do { set_pte_at((mm), (addr), (ptep), __pte(0)); } while (0)
 --
 arch/mips/include/asm/pgtable.h=119=static inline void set_pte(pte_t *ptep, pte_t pte)
 --
 arch/mips/include/asm/pgtable.h-142-
 arch/mips/include/asm/pgtable.h:143:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/mips/include/asm/pgtable.h-144-{
 --
 arch/mips/include/asm/pgtable.h=171=static inline void set_pte(pte_t *ptep, pte_t pteval)
 --
 arch/mips/include/asm/pgtable.h-189-
 arch/mips/include/asm/pgtable.h:190:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/mips/include/asm/pgtable.h-191-{
 --
 arch/nios2/include/asm/pgtable.h=195=static inline int pmd_none(pmd_t pmd)
 --
 arch/nios2/include/asm/pgtable.h-202-
 arch/nios2/include/asm/pgtable.h:203:static inline void pte_clear(struct mm_struct *mm,
 arch/nios2/include/asm/pgtable.h-204-				unsigned long addr, pte_t *ptep)
 --
 arch/openrisc/include/asm/pgtable.h=42=extern void paging_init(void);
 --
 arch/openrisc/include/asm/pgtable.h-183-#define pte_present(x)	(pte_val(x) & _PAGE_PRESENT)
 arch/openrisc/include/asm/pgtable.h:184:#define pte_clear(mm, addr, xp)	do { pte_val(*(xp)) = 0; } while (0)
 arch/openrisc/include/asm/pgtable.h-185-
 --
 arch/openrisc/mm/init.c=196=static int __init map_page(unsigned long va, phys_addr_t pa, pgprot_t prot)
 --
 arch/openrisc/mm/init.c-213-	else
 arch/openrisc/mm/init.c:214:		pte_clear(&init_mm, va, pte);
 arch/openrisc/mm/init.c-215-
 --
 arch/parisc/include/asm/pgtable.h=263=extern pte_t pg0[];
 --
 arch/parisc/include/asm/pgtable.h-267-#define pte_user(x)	(pte_val(x) & _PAGE_USER)
 arch/parisc/include/asm/pgtable.h:268:#define pte_clear(mm, addr, xp) set_pte_at((mm), (addr), (xp), __pte(0))
 arch/parisc/include/asm/pgtable.h-269-
 --
 arch/parisc/kernel/pci-dma.c=153=static inline void unmap_uncached_pte(pmd_t * pmd, unsigned long vaddr,
 --
 arch/parisc/kernel/pci-dma.c-175-
 arch/parisc/kernel/pci-dma.c:176:		pte_clear(&init_mm, vaddr, pte);
 arch/parisc/kernel/pci-dma.c-177-		purge_tlb_start(flags);
 --
 arch/parisc/mm/fixmap.c=27=void notrace clear_fixmap(enum fixed_addresses idx)
 --
 arch/parisc/mm/fixmap.c-34-
 arch/parisc/mm/fixmap.c:35:	pte_clear(&init_mm, vaddr, pte);
 arch/parisc/mm/fixmap.c-36-
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h=138=void unmap_kernel_page(unsigned long va);
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h-212-
 arch/powerpc/include/asm/book3s/32/pgtable.h:213:#define pte_clear(mm, addr, ptep) \
 arch/powerpc/include/asm/book3s/32/pgtable.h-214-	do { pte_update(mm, addr, ptep, ~_PAGE_HASHPTE, 0, 0); } while (0)
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h=312=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h-316-
 arch/powerpc/include/asm/book3s/32/pgtable.h:317:	page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/book3s/32/pgtable.h-318-
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h=418=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-422-
 arch/powerpc/include/asm/book3s/64/pgtable.h:423:	page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/book3s/64/pgtable.h-424-
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h=429=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-440-		old_pte = radix__ptep_get_and_clear_full(mm, addr, ptep, full);
 arch/powerpc/include/asm/book3s/64/pgtable.h:441:		page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/book3s/64/pgtable.h-442-
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-448-
 arch/powerpc/include/asm/book3s/64/pgtable.h:449:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/powerpc/include/asm/book3s/64/pgtable.h-450-			     pte_t * ptep)
 --
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h=23=static inline pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 --
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-30-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h:31:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-32-				  pte_t *ptep, unsigned long sz)
 --
 arch/powerpc/include/asm/nohash/pgtable.h=124=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/powerpc/include/asm/nohash/pgtable.h-128-
 arch/powerpc/include/asm/nohash/pgtable.h:129:	page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/nohash/pgtable.h-130-
 --
 arch/powerpc/include/asm/nohash/pgtable.h-134-
 arch/powerpc/include/asm/nohash/pgtable.h:135:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/powerpc/include/asm/nohash/pgtable.h-136-{
 --
 arch/powerpc/lib/code-patching.c=246=static void unmap_patch_area(unsigned long addr)
 --
 arch/powerpc/lib/code-patching.c-276-	 */
 arch/powerpc/lib/code-patching.c:277:	pte_clear(&init_mm, addr, ptep);
 arch/powerpc/lib/code-patching.c-278-	flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
 --
 arch/powerpc/lib/code-patching.c=281=static int __do_patch_mem_mm(void *addr, unsigned long val, bool is_dword)
 --
 arch/powerpc/lib/code-patching.c-314-
 arch/powerpc/lib/code-patching.c:315:	pte_clear(patching_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-316-	/*
 --
 arch/powerpc/lib/code-patching.c=327=static int __do_patch_mem(void *addr, unsigned long val, bool is_dword)
 --
 arch/powerpc/lib/code-patching.c-345-
 arch/powerpc/lib/code-patching.c:346:	pte_clear(&init_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-347-	flush_tlb_kernel_range(text_poke_addr, text_poke_addr + PAGE_SIZE);
 --
 arch/powerpc/lib/code-patching.c=468=static int __do_patch_instructions_mm(u32 *addr, u32 *code, size_t len, bool repeat_instr)
 --
 arch/powerpc/lib/code-patching.c-502-
 arch/powerpc/lib/code-patching.c:503:	pte_clear(patching_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-504-	/*
 --
 arch/powerpc/lib/code-patching.c=519=static int __do_patch_instructions(u32 *addr, u32 *code, size_t len, bool repeat_instr)
 --
 arch/powerpc/lib/code-patching.c-537-
 arch/powerpc/lib/code-patching.c:538:	pte_clear(&init_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-539-	flush_tlb_kernel_range(text_poke_addr, text_poke_addr + PAGE_SIZE);
 --
 arch/powerpc/mm/book3s64/hash_native.c=660=static void hpte_decode(struct hash_pte *hpte, unsigned long slot,
 --
 arch/powerpc/mm/book3s64/hash_native.c-735- */
 arch/powerpc/mm/book3s64/hash_native.c:736:static notrace void native_hpte_clear(void)
 arch/powerpc/mm/book3s64/hash_native.c-737-{
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=787=static void __meminit remove_pte_table(pte_t *pte_start, unsigned long addr,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-805-				free_vmemmap_pages(pte_page(*pte), altmap, 0);
 arch/powerpc/mm/book3s64/radix_pgtable.c:806:			pte_clear(&init_mm, addr, pte);
 arch/powerpc/mm/book3s64/radix_pgtable.c-807-			pages++;
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-811-			free_vmemmap_pages(pte_page(*pte), altmap, 0);
 arch/powerpc/mm/book3s64/radix_pgtable.c:812:			pte_clear(&init_mm, addr, pte);
 arch/powerpc/mm/book3s64/radix_pgtable.c-813-		}
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=820=static void __meminit remove_pmd_table(pmd_t *pmd_start, unsigned long addr,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-839-					free_vmemmap_pages(pmd_page(*pmd), altmap, get_order(PMD_SIZE));
 arch/powerpc/mm/book3s64/radix_pgtable.c:840:				pte_clear(&init_mm, addr, (pte_t *)pmd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-841-				pages++;
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-845-				free_vmemmap_pages(pmd_page(*pmd), altmap, get_order(PMD_SIZE));
 arch/powerpc/mm/book3s64/radix_pgtable.c:846:				pte_clear(&init_mm, addr, (pte_t *)pmd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-847-			}
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=860=static void __meminit remove_pud_table(pud_t *pud_start, unsigned long addr,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-880-			}
 arch/powerpc/mm/book3s64/radix_pgtable.c:881:			pte_clear(&init_mm, addr, (pte_t *)pud);
 arch/powerpc/mm/book3s64/radix_pgtable.c-882-			pages++;
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=895=remove_pagetable(unsigned long start, unsigned long end, bool direct,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-919-
 arch/powerpc/mm/book3s64/radix_pgtable.c:920:			pte_clear(&init_mm, addr, (pte_t *)pgd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-921-			continue;
 --
 arch/powerpc/mm/pgtable.c=239=void unmap_kernel_page(unsigned long va)
 --
 arch/powerpc/mm/pgtable.c-243-
 arch/powerpc/mm/pgtable.c:244:	pte_clear(&init_mm, va, ptep);
 arch/powerpc/mm/pgtable.c-245-	flush_tlb_kernel_range(va, va + PAGE_SIZE);
 --
 arch/powerpc/platforms/ps3/htab.c=152=static void ps3_hpte_invalidate(unsigned long slot, unsigned long vpn,
 --
 arch/powerpc/platforms/ps3/htab.c-171-/* Called during kexec sequence with MMU off */
 arch/powerpc/platforms/ps3/htab.c:172:static notrace void ps3_hpte_clear(void)
 arch/powerpc/platforms/ps3/htab.c-173-{
 --
 arch/riscv/include/asm/hugetlb.h=15=bool arch_hugetlb_migration_supported(struct hstate *h);
 --
 arch/riscv/include/asm/hugetlb.h-20-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/riscv/include/asm/hugetlb.h:21:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/riscv/include/asm/hugetlb.h-22-		    pte_t *ptep, unsigned long sz);
 --
 arch/riscv/include/asm/pgtable.h=622=static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
 --
 arch/riscv/include/asm/pgtable.h-636-
 arch/riscv/include/asm/pgtable.h:637:static inline void pte_clear(struct mm_struct *mm,
 arch/riscv/include/asm/pgtable.h-638-	unsigned long addr, pte_t *ptep)
 --
 arch/riscv/include/asm/pgtable.h=651=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/riscv/include/asm/pgtable.h-661-
 arch/riscv/include/asm/pgtable.h:662:	page_table_check_pte_clear(mm, address, pte);
 arch/riscv/include/asm/pgtable.h-663-
 --
 arch/riscv/mm/hugetlbpage.c=346=pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/riscv/mm/hugetlbpage.c-360-
 arch/riscv/mm/hugetlbpage.c:361:void huge_pte_clear(struct mm_struct *mm,
 arch/riscv/mm/hugetlbpage.c-362-		    unsigned long addr,
 --
 arch/riscv/mm/hugetlbpage.c-370-	if (!pte_napot(pte)) {
 arch/riscv/mm/hugetlbpage.c:371:		pte_clear(mm, addr, ptep);
 arch/riscv/mm/hugetlbpage.c-372-		return;
 --
 arch/riscv/mm/hugetlbpage.c-377-	for (i = 0; i < pte_num; i++, addr += pgsize, ptep++)
 arch/riscv/mm/hugetlbpage.c:378:		pte_clear(mm, addr, ptep);
 arch/riscv/mm/hugetlbpage.c-379-}
 --
 arch/riscv/mm/init.c=369=void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
 --
 arch/riscv/mm/init.c-380-	else
 arch/riscv/mm/init.c:381:		pte_clear(&init_mm, addr, ptep);
 arch/riscv/mm/init.c-382-	local_flush_tlb_page(addr);
 --
 arch/riscv/mm/init.c=1574=static void __meminit remove_pte_mapping(pte_t *pte_base, unsigned long addr, unsigned long end,
 --
 arch/riscv/mm/init.c-1589-
 arch/riscv/mm/init.c:1590:		pte_clear(&init_mm, addr, ptep);
 arch/riscv/mm/init.c-1591-		if (is_vmemmap)
 --
 arch/s390/include/asm/hugetlb.h=33=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/s390/include/asm/hugetlb.h-40-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/s390/include/asm/hugetlb.h:41:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/s390/include/asm/hugetlb.h-42-				  pte_t *ptep, unsigned long sz)
 --
 arch/s390/include/asm/pgtable.h=1004=static inline void pmd_clear(pmd_t *pmdp)
 --
 arch/s390/include/asm/pgtable.h-1008-
 arch/s390/include/asm/pgtable.h:1009:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/s390/include/asm/pgtable.h-1010-{
 --
 arch/s390/include/asm/pgtable.h=1186=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/s390/include/asm/pgtable.h-1194-		WARN_ON_ONCE(uv_convert_from_secure_pte(res));
 arch/s390/include/asm/pgtable.h:1195:	page_table_check_pte_clear(mm, addr, res);
 arch/s390/include/asm/pgtable.h-1196-	return res;
 --
 arch/s390/include/asm/pgtable.h=1205=static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/s390/include/asm/pgtable.h-1213-		WARN_ON_ONCE(uv_convert_from_secure_pte(res));
 arch/s390/include/asm/pgtable.h:1214:	page_table_check_pte_clear(vma->vm_mm, addr, res);
 arch/s390/include/asm/pgtable.h-1215-	return res;
 --
 arch/s390/include/asm/pgtable.h=1226=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
 --
 arch/s390/include/asm/pgtable.h-1238-
 arch/s390/include/asm/pgtable.h:1239:	page_table_check_pte_clear(mm, addr, res);
 arch/s390/include/asm/pgtable.h-1240-
 --
 arch/s390/mm/gmap_helpers.c=46=void gmap_helper_zap_one_page(struct mm_struct *mm, unsigned long vmaddr)
 --
 arch/s390/mm/gmap_helpers.c-64-		ptep_zap_softleaf_entry(mm, softleaf_from_pte(*ptep));
 arch/s390/mm/gmap_helpers.c:65:		pte_clear(mm, vmaddr, ptep);
 arch/s390/mm/gmap_helpers.c-66-	}
 --
 arch/s390/mm/vmem.c=168=static int __ref modify_pte_table(pmd_t *pmd, unsigned long addr,
 --
 arch/s390/mm/vmem.c-183-				vmem_free_pages((unsigned long)pfn_to_virt(pte_pfn(*pte)), get_order(PAGE_SIZE), altmap);
 arch/s390/mm/vmem.c:184:			pte_clear(&init_mm, addr, pte);
 arch/s390/mm/vmem.c-185-		} else if (pte_none(*pte)) {
 --
 arch/s390/mm/vmem.c=654=void vmem_unmap_4k_page(unsigned long addr)
 --
 arch/s390/mm/vmem.c-660-	__ptep_ipte(addr, ptep, 0, 0, IPTE_GLOBAL);
 arch/s390/mm/vmem.c:661:	pte_clear(&init_mm, addr, ptep);
 arch/s390/mm/vmem.c-662-	mutex_unlock(&vmem_mutex);
 --
 arch/sh/include/asm/pgtable_32.h=300=static inline void set_pte(pte_t *ptep, pte_t pte)
 --
 arch/sh/include/asm/pgtable_32.h-324-
 arch/sh/include/asm/pgtable_32.h:325:#define pte_clear(mm, addr, ptep) set_pte(ptep, __pte(0))
 arch/sh/include/asm/pgtable_32.h-326-
 --
 arch/sh/mm/kmap.c=51=void kunmap_coherent(void *kvaddr)
 --
 arch/sh/mm/kmap.c-59-
 arch/sh/mm/kmap.c:60:		pte_clear(&init_mm, vaddr, kmap_coherent_pte - idx);
 arch/sh/mm/kmap.c-61-		local_flush_tlb_one(get_asid(), vaddr);
 --
 arch/sparc/include/asm/pgtable_32.h=145=static inline int pte_none(pte_t pte)
 --
 arch/sparc/include/asm/pgtable_32.h-149-
 arch/sparc/include/asm/pgtable_32.h:150:static inline void __pte_clear(pte_t *ptep)
 arch/sparc/include/asm/pgtable_32.h-151-{
 --
 arch/sparc/include/asm/pgtable_32.h-154-
 arch/sparc/include/asm/pgtable_32.h:155:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/sparc/include/asm/pgtable_32.h-156-{
 arch/sparc/include/asm/pgtable_32.h:157:	__pte_clear(ptep);
 arch/sparc/include/asm/pgtable_32.h-158-}
 --
 arch/sparc/include/asm/pgtable_64.h=931=static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
 --
 arch/sparc/include/asm/pgtable_64.h-944-
 arch/sparc/include/asm/pgtable_64.h:945:#define pte_clear(mm,addr,ptep)		\
 arch/sparc/include/asm/pgtable_64.h-946-	set_pte_at((mm), (addr), (ptep), __pte(0UL))
 --
 arch/sparc/mm/srmmu.c=526=static inline void srmmu_unmapioaddr(unsigned long virt_addr)
 --
 arch/sparc/mm/srmmu.c-541-	/* No need to flush uncacheable page. */
 arch/sparc/mm/srmmu.c:542:	__pte_clear(ptep);
 arch/sparc/mm/srmmu.c-543-}
 --
 arch/um/include/asm/pgtable.h=35=extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
 --
 arch/um/include/asm/pgtable.h-73-
 arch/um/include/asm/pgtable.h:74:#define pte_clear(mm, addr, xp) pte_set_val(*(xp), (phys_t) 0, __pgprot(_PAGE_NEEDSYNC))
 arch/um/include/asm/pgtable.h-75-
 --
 arch/x86/include/asm/paravirt.h=457=static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
 --
 arch/x86/include/asm/paravirt.h-461-
 arch/x86/include/asm/paravirt.h:462:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/x86/include/asm/paravirt.h-463-			     pte_t *ptep)
 --
 arch/x86/include/asm/pgtable-2level.h=39=static inline void native_pud_clear(pud_t *pudp)
 --
 arch/x86/include/asm/pgtable-2level.h-42-
 arch/x86/include/asm/pgtable-2level.h:43:static inline void native_pte_clear(struct mm_struct *mm,
 arch/x86/include/asm/pgtable-2level.h-44-				    unsigned long addr, pte_t *xp)
 --
 arch/x86/include/asm/pgtable-3level.h=53=static inline void native_set_pud(pud_t *pudp, pud_t pud)
 --
 arch/x86/include/asm/pgtable-3level.h-65- */
 arch/x86/include/asm/pgtable-3level.h:66:static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/x86/include/asm/pgtable-3level.h-67-				    pte_t *ptep)
 --
 arch/x86/include/asm/pgtable.h=55=extern pmdval_t early_pmd_flags;
 --
 arch/x86/include/asm/pgtable.h-87-
 arch/x86/include/asm/pgtable.h:88:#define pte_clear(mm, addr, ptep)	native_pte_clear(mm, addr, ptep)
 arch/x86/include/asm/pgtable.h-89-#define pmd_clear(pmd)			native_pmd_clear(pmd)
 --
 arch/x86/include/asm/pgtable.h=1181=static inline pte_t native_local_ptep_get_and_clear(pte_t *ptep)
 --
 arch/x86/include/asm/pgtable.h-1185-	/* Pure native function needs no input for mm, addr */
 arch/x86/include/asm/pgtable.h:1186:	native_pte_clear(NULL, 0, ptep);
 arch/x86/include/asm/pgtable.h-1187-	return res;
 --
 arch/x86/include/asm/pgtable.h=1243=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/x86/include/asm/pgtable.h-1246-	pte_t pte = native_ptep_get_and_clear(ptep);
 arch/x86/include/asm/pgtable.h:1247:	page_table_check_pte_clear(mm, addr, pte);
 arch/x86/include/asm/pgtable.h-1248-	return pte;
 --
 arch/x86/include/asm/pgtable.h=1252=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
 --
 arch/x86/include/asm/pgtable.h-1262-		pte = native_local_ptep_get_and_clear(ptep);
 arch/x86/include/asm/pgtable.h:1263:		page_table_check_pte_clear(mm, addr, pte);
 arch/x86/include/asm/pgtable.h-1264-	} else {
 --
 arch/x86/include/asm/pgtable_32.h=42=do {						\
 arch/x86/include/asm/pgtable_32.h:43:	pte_clear(&init_mm, (vaddr), (ptep));	\
 arch/x86/include/asm/pgtable_32.h-44-	flush_tlb_one_kernel((vaddr));		\
 --
 arch/x86/include/asm/pgtable_64.h=61=static inline void native_set_pte(pte_t *ptep, pte_t pte)
 --
 arch/x86/include/asm/pgtable_64.h-65-
 arch/x86/include/asm/pgtable_64.h:66:static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/x86/include/asm/pgtable_64.h-67-				    pte_t *ptep)
 --
 arch/x86/include/asm/pgtable_64.h=87=static inline pte_t native_ptep_get_and_clear(pte_t *xp)
 --
 arch/x86/include/asm/pgtable_64.h-94-	pte_t ret = *xp;
 arch/x86/include/asm/pgtable_64.h:95:	native_pte_clear(NULL, 0, xp);
 arch/x86/include/asm/pgtable_64.h-96-	return ret;
 --
 arch/x86/kernel/alternative.c=2546=static void *__text_poke(text_poke_f func, void *addr, const void *src, size_t len)
 --
 arch/x86/kernel/alternative.c-2619-
 arch/x86/kernel/alternative.c:2620:	pte_clear(text_poke_mm, text_poke_mm_addr, ptep);
 arch/x86/kernel/alternative.c-2621-	if (cross_page_boundary)
 arch/x86/kernel/alternative.c:2622:		pte_clear(text_poke_mm, text_poke_mm_addr + PAGE_SIZE, ptep + 1);
 arch/x86/kernel/alternative.c-2623-
 --
]
]

108/2 2026/05/25 00:24 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 129660
							output: 46
							thoughts: 190
						

Thoughts:
**Analyzing `pte_clear` Usage in RISC-V**

Okay, let's break down this `pte_clear` situation in RISC-V. My initial thought process is this: I need to figure out where this function is actually being used. Right, so looking at the code, it's used in `huge_pte_clear`, `__set_fixmap`, and `remove_pte_mapping`.

Hmm, `__set_fixmap` and `remove_pte_mapping` are exclusively for kernel mappings. That means any PTE involved in those calls wouldn't be user-accessible anyway. Therefore, it means `pte_clear` is effectively *only* used for user PTEs within `huge_pte_clear`.

And we've already confirmed, from poking around in `mm/hugetlb.c`, that `huge_pte_clear` is only invoked on *non-present* PTEs. Therefore, I can confidently conclude that, in the RISC-V architecture, `pte_clear` is **never** called on a present user PTE. That makes this not the cause of the bug I was looking at.

Now, what about `pmd_clear`? Let's check that one in RISC-V...



109/2 2026/05/25 00:25 tool codesearch-definition-source
0m Error:
requested entity does not exist

Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:pmd_clear]

Results:
map[SourceCode: SourceFile:]

110/2 2026/05/25 00:25 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 130187
							output: 19
							thoughts: 26
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Investigating `pmd_clear` in the RISC-V Page Table Header**

Okay, so I need to refresh my understanding of the `pmd_clear` macro within the RISC-V architecture's page table structure. Specifically, I'm heading over to `arch/riscv/include/asm/pgtable.h`. I'm assuming it's defined there, nestled amongst the other page table manipulation macros. I need to understand its exact function, its purpose in clearing a page middle directory entry, and how it interacts with the RISC-V's memory management hardware. Is it a simple bit-clearing operation, a more complex atomic update, or something else entirely? I should also look for any relevant comments, and, if applicable, any architecture-specific considerations or optimizations.



111/2 2026/05/25 00:25 tool grepper
0m Args:
map[Expression:pmd_clear\(]

Results:
map[Output:
Full output is too long, showing 500 out of 618 lines.
Use more precise expression if possible.

[arch/alpha/include/asm/pgtable.h=219=extern inline int pmd_present(pmd_t pmd)	{ return pmd_val(pmd) & _PAGE_VALID; }
 arch/alpha/include/asm/pgtable.h:220:extern inline void pmd_clear(pmd_t * pmdp)	{ pmd_val(*pmdp) = 0; }
 arch/alpha/include/asm/pgtable.h-221-
 --
 arch/arc/include/asm/pgtable-levels.h-157-#define pmd_present(x)		(pmd_val(x))
 arch/arc/include/asm/pgtable-levels.h:158:#define pmd_clear(xp)		do { pmd_val(*(xp)) = 0; } while (0)
 arch/arc/include/asm/pgtable-levels.h-159-#define pmd_page_vaddr(pmd)	(pmd_val(pmd) & PAGE_MASK)
 --
 arch/arm/include/asm/pgtable-2level.h=208=static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr)
 --
 arch/arm/include/asm/pgtable-2level.h-226-
 arch/arm/include/asm/pgtable-2level.h:227:#define pmd_clear(pmdp)			\
 arch/arm/include/asm/pgtable-2level.h-228-	do {				\
 --
 arch/arm/include/asm/pgtable-3level.h=135=static inline pmd_t *pud_pgtable(pud_t pud)
 --
 arch/arm/include/asm/pgtable-3level.h-147-
 arch/arm/include/asm/pgtable-3level.h:148:#define pmd_clear(pmdp)			\
 arch/arm/include/asm/pgtable-3level.h-149-	do {				\
 --
 arch/arm/mm/dma-mapping.c=270=void __init dma_contiguous_remap(void)
 --
 arch/arm/mm/dma-mapping.c-299-		     addr += PMD_SIZE)
 arch/arm/mm/dma-mapping.c:300:			pmd_clear(pmd_off_k(addr));
 arch/arm/mm/dma-mapping.c-301-
 --
 arch/arm/mm/ioremap.c=173=static void unmap_area_sections(unsigned long virt, unsigned long size)
 --
 arch/arm/mm/ioremap.c-188-			 */
 arch/arm/mm/ioremap.c:189:			pmd_clear(pmdp);
 arch/arm/mm/ioremap.c-190-			atomic_inc_return_release(&init_mm.context.vmalloc_seq);
 --
 arch/arm/mm/kasan_init.c=188=static void __init clear_pgds(unsigned long start,
 --
 arch/arm/mm/kasan_init.c-191-	for (; start && start < end; start += PMD_SIZE)
 arch/arm/mm/kasan_init.c:192:		pmd_clear(pmd_off_k(start));
 arch/arm/mm/kasan_init.c-193-}
 --
 arch/arm/mm/mmu.c=1273=static __init void prepare_page_table(void)
 --
 arch/arm/mm/mmu.c-1286-	for (addr = 0; addr < KASAN_SHADOW_START; addr += PMD_SIZE)
 arch/arm/mm/mmu.c:1287:		pmd_clear(pmd_off_k(addr));
 arch/arm/mm/mmu.c-1288-	/*
 --
 arch/arm/mm/mmu.c-1294-	for (addr = KASAN_SHADOW_END; addr < MODULES_VADDR; addr += PMD_SIZE)
 arch/arm/mm/mmu.c:1295:		pmd_clear(pmd_off_k(addr));
 arch/arm/mm/mmu.c-1296-#else
 arch/arm/mm/mmu.c-1297-	for (addr = 0; addr < MODULES_VADDR; addr += PMD_SIZE)
 arch/arm/mm/mmu.c:1298:		pmd_clear(pmd_off_k(addr));
 arch/arm/mm/mmu.c-1299-#endif
 --
 arch/arm/mm/mmu.c-1305-	for ( ; addr < PAGE_OFFSET; addr += PMD_SIZE)
 arch/arm/mm/mmu.c:1306:		pmd_clear(pmd_off_k(addr));
 arch/arm/mm/mmu.c-1307-
 --
 arch/arm/mm/mmu.c-1320-	     addr < VMALLOC_START; addr += PMD_SIZE)
 arch/arm/mm/mmu.c:1321:		pmd_clear(pmd_off_k(addr));
 arch/arm/mm/mmu.c-1322-}
 --
 arch/arm/mm/mmu.c=1359=static void __init devicemaps_init(const struct machine_desc *mdesc)
 --
 arch/arm/mm/mmu.c-1375-	for (addr = VMALLOC_START; addr < (FIXADDR_TOP & PMD_MASK); addr += PMD_SIZE)
 arch/arm/mm/mmu.c:1376:		pmd_clear(pmd_off_k(addr));
 arch/arm/mm/mmu.c-1377-
 --
 arch/arm/mm/mmu.c=1715=static void __init early_fixmap_shutdown(void)
 --
 arch/arm/mm/mmu.c-1720-	pte_offset_fixmap = pte_offset_late_fixmap;
 arch/arm/mm/mmu.c:1721:	pmd_clear(fixmap_pmd(va));
 arch/arm/mm/mmu.c-1722-	local_flush_tlb_kernel_page(va);
 --
 arch/arm/mm/pgd.c=140=void pgd_free(struct mm_struct *mm, pgd_t *pgd_base)
 --
 arch/arm/mm/pgd.c-167-	pte = pmd_pgtable(*pmd);
 arch/arm/mm/pgd.c:168:	pmd_clear(pmd);
 arch/arm/mm/pgd.c-169-	pte_free(mm, pte);
 --
 arch/arm64/include/asm/pgtable.h=824=static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
 --
 arch/arm64/include/asm/pgtable.h-838-
 arch/arm64/include/asm/pgtable.h:839:static inline void pmd_clear(pmd_t *pmdp)
 arch/arm64/include/asm/pgtable.h-840-{
 --
 arch/arm64/include/asm/pgtable.h=1352=static inline pte_t __ptep_get_and_clear_anysz(struct mm_struct *mm,
 --
 arch/arm64/include/asm/pgtable.h-1363-	case PMD_SIZE:
 arch/arm64/include/asm/pgtable.h:1364:		page_table_check_pmd_clear(mm, address, pte_pmd(pte));
 arch/arm64/include/asm/pgtable.h-1365-		break;
 --
 arch/arm64/mm/mmu.c=1491=static void unmap_hotplug_pmd_range(pud_t *pudp, unsigned long addr,
 --
 arch/arm64/mm/mmu.c-1506-		if (pmd_leaf(pmd)) {
 arch/arm64/mm/mmu.c:1507:			pmd_clear(pmdp);
 arch/arm64/mm/mmu.c-1508-			if (free_mapped) {
 --
 arch/arm64/mm/mmu.c=1602=static void free_empty_pte_table(pmd_t *pmdp, unsigned long addr,
 --
 arch/arm64/mm/mmu.c-1633-
 arch/arm64/mm/mmu.c:1634:	pmd_clear(pmdp);
 arch/arm64/mm/mmu.c-1635-	__flush_tlb_kernel_pgtable(start);
 --
 arch/arm64/mm/mmu.c=1859=int pmd_clear_huge(pmd_t *pmdp)
 --
 arch/arm64/mm/mmu.c-1862-		return 0;
 arch/arm64/mm/mmu.c:1863:	pmd_clear(pmdp);
 arch/arm64/mm/mmu.c-1864-	return 1;
 --
 arch/arm64/mm/mmu.c=1867=static int __pmd_free_pte_page(pmd_t *pmdp, unsigned long addr,
 --
 arch/arm64/mm/mmu.c-1881-	table = pte_offset_kernel(pmdp, addr);
 arch/arm64/mm/mmu.c:1882:	pmd_clear(pmdp);
 arch/arm64/mm/mmu.c-1883-	__flush_tlb_kernel_pgtable(addr);
 --
 arch/csky/include/asm/pgtable.h=121=static inline int pmd_present(pmd_t pmd)
 --
 arch/csky/include/asm/pgtable.h-125-
 arch/csky/include/asm/pgtable.h:126:static inline void pmd_clear(pmd_t *p)
 arch/csky/include/asm/pgtable.h-127-{
 --
 arch/hexagon/include/asm/pgtable.h=146=static inline void set_pte(pte_t *ptep, pte_t pteval)
 --
 arch/hexagon/include/asm/pgtable.h-164-
 arch/hexagon/include/asm/pgtable.h:165:static inline void pmd_clear(pmd_t *pmd_entry_ptr)
 arch/hexagon/include/asm/pgtable.h-166-{
 --
 arch/loongarch/include/asm/pgtable.h=259=static inline void set_pmd(pmd_t *pmd, pmd_t pmdval)
 --
 arch/loongarch/include/asm/pgtable.h-263-
 arch/loongarch/include/asm/pgtable.h:264:static inline void pmd_clear(pmd_t *pmdp)
 arch/loongarch/include/asm/pgtable.h-265-{
 --
 arch/loongarch/include/asm/pgtable.h=597=static inline pmd_t pmd_mkinvalid(pmd_t pmd)
 --
 arch/loongarch/include/asm/pgtable.h-605-/*
 arch/loongarch/include/asm/pgtable.h:606: * The generic version pmdp_huge_get_and_clear uses a version of pmd_clear() with a
 arch/loongarch/include/asm/pgtable.h-607- * different prototype.
 --
 arch/loongarch/include/asm/pgtable.h=610=static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
 --
 arch/loongarch/include/asm/pgtable.h-614-
 arch/loongarch/include/asm/pgtable.h:615:	pmd_clear(pmdp);
 arch/loongarch/include/asm/pgtable.h-616-
 --
 arch/m68k/include/asm/mcf_pgtable.h=135=static inline int pmd_bad2(pmd_t *pmd) { return 0; }
 --
 arch/m68k/include/asm/mcf_pgtable.h-137-#define pmd_present(pmd) (!pmd_none2(&(pmd)))
 arch/m68k/include/asm/mcf_pgtable.h:138:static inline void pmd_clear(pmd_t *pmdp) { pmd_val(*pmdp) = 0; }
 arch/m68k/include/asm/mcf_pgtable.h-139-
 --
 arch/m68k/include/asm/motorola_pgtable.h=95=static inline void pud_set(pud_t *pudp, pmd_t *pmdp)
 --
 arch/m68k/include/asm/motorola_pgtable.h-116-#define pmd_present(pmd)	(pmd_val(pmd) & _PAGE_TABLE)
 arch/m68k/include/asm/motorola_pgtable.h:117:#define pmd_clear(pmdp)		({ pmd_val(*pmdp) = 0; })
 arch/m68k/include/asm/motorola_pgtable.h-118-
 --
 arch/m68k/mm/kmap.c=59=static void __free_io_area(void *addr, unsigned long size)
 --
 arch/m68k/mm/kmap.c-83-			if (pmd_type == _PAGE_PRESENT) {
 arch/m68k/mm/kmap.c:84:				pmd_clear(pmd_dir);
 arch/m68k/mm/kmap.c-85-				virtaddr += PMD_SIZE;
 --
 arch/m68k/mm/kmap.c-94-			printk("iounmap: bad pmd (%08lx)\n", pmd_val(*pmd_dir));
 arch/m68k/mm/kmap.c:95:			pmd_clear(pmd_dir);
 arch/m68k/mm/kmap.c-96-			return;
 --
 arch/m68k/mm/kmap.c=324=void kernel_set_cachemode(void *addr, unsigned long size, int cmode)
 --
 arch/m68k/mm/kmap.c-387-			printk("iocachemode: bad pmd (%08lx)\n", pmd_val(*pmd_dir));
 arch/m68k/mm/kmap.c:388:			pmd_clear(pmd_dir);
 arch/m68k/mm/kmap.c-389-			return;
 --
 arch/microblaze/include/asm/pgtable.h=29=extern pte_t *va_to_pte(unsigned long address);
 --
 arch/microblaze/include/asm/pgtable.h-217-#define	pmd_present(pmd)	((pmd_val(pmd) & _PMD_PRESENT) != 0)
 arch/microblaze/include/asm/pgtable.h:218:#define	pmd_clear(pmdp)		do { pmd_val(*(pmdp)) = 0; } while (0)
 arch/microblaze/include/asm/pgtable.h-219-
 --
 arch/mips/include/asm/pgtable-32.h=143=static inline int pmd_present(pmd_t pmd)
 --
 arch/mips/include/asm/pgtable-32.h-147-
 arch/mips/include/asm/pgtable-32.h:148:static inline void pmd_clear(pmd_t *pmdp)
 arch/mips/include/asm/pgtable-32.h-149-{
 --
 arch/mips/include/asm/pgtable-64.h=259=static inline int pmd_present(pmd_t pmd)
 --
 arch/mips/include/asm/pgtable-64.h-268-
 arch/mips/include/asm/pgtable-64.h:269:static inline void pmd_clear(pmd_t *pmdp)
 arch/mips/include/asm/pgtable-64.h-270-{
 --
 arch/mips/include/asm/pgtable.h=722=static inline pmd_t pmd_mkinvalid(pmd_t pmd)
 --
 arch/mips/include/asm/pgtable.h-729-/*
 arch/mips/include/asm/pgtable.h:730: * The generic version pmdp_huge_get_and_clear uses a version of pmd_clear() with a
 arch/mips/include/asm/pgtable.h-731- * different prototype.
 --
 arch/mips/include/asm/pgtable.h=734=static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
 --
 arch/mips/include/asm/pgtable.h-738-
 arch/mips/include/asm/pgtable.h:739:	pmd_clear(pmdp);
 arch/mips/include/asm/pgtable.h-740-
 --
 arch/mips/kvm/mmu.c=171=static bool kvm_mips_flush_gpa_pmd(pmd_t *pmd, unsigned long start_gpa,
 --
 arch/mips/kvm/mmu.c-189-		if (kvm_mips_flush_gpa_pte(pte, start_gpa, end)) {
 arch/mips/kvm/mmu.c:190:			pmd_clear(pmd + i);
 arch/mips/kvm/mmu.c-191-			pte_free_kernel(NULL, pte);
 --
 arch/nios2/include/asm/pgtable.h=154=static inline int pmd_present(pmd_t pmd)
 --
 arch/nios2/include/asm/pgtable.h-159-
 arch/nios2/include/asm/pgtable.h:160:static inline void pmd_clear(pmd_t *pmdp)
 arch/nios2/include/asm/pgtable.h-161-{
 --
 arch/openrisc/include/asm/pgtable.h=42=extern void paging_init(void);
 --
 arch/openrisc/include/asm/pgtable.h-188-#define pmd_present(x)	(pmd_val(x) & _PAGE_PRESENT)
 arch/openrisc/include/asm/pgtable.h:189:#define pmd_clear(xp)	do { pmd_val(*(xp)) = 0; } while (0)
 arch/openrisc/include/asm/pgtable.h-190-
 --
 arch/parisc/include/asm/pgtable.h=263=extern pte_t pg0[];
 --
 arch/parisc/include/asm/pgtable.h-279-#define pmd_present(x)	(pmd_flag(x) & PxD_FLAG_PRESENT)
 arch/parisc/include/asm/pgtable.h:280:static inline void pmd_clear(pmd_t *pmd) {
 arch/parisc/include/asm/pgtable.h-281-		set_pmd(pmd,  __pmd(0));
 --
 arch/parisc/kernel/pci-dma.c=153=static inline void unmap_uncached_pte(pmd_t * pmd, unsigned long vaddr,
 --
 arch/parisc/kernel/pci-dma.c-163-		pmd_ERROR(*pmd);
 arch/parisc/kernel/pci-dma.c:164:		pmd_clear(pmd);
 arch/parisc/kernel/pci-dma.c-165-		return;
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h=138=void unmap_kernel_page(unsigned long va);
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h-218-#define	pmd_present(pmd)	(pmd_val(pmd) & _PMD_PRESENT_MASK)
 arch/powerpc/include/asm/book3s/32/pgtable.h:219:static inline void pmd_clear(pmd_t *pmdp)
 arch/powerpc/include/asm/book3s/32/pgtable.h-220-{
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h=793=static inline bool pte_ci(pte_t pte)
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-802-
 arch/powerpc/include/asm/book3s/64/pgtable.h:803:static inline void pmd_clear(pmd_t *pmdp)
 arch/powerpc/include/asm/book3s/64/pgtable.h-804-{
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h=1334=static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-1348-		old_pmd = READ_ONCE(*pmdp);
 arch/powerpc/include/asm/book3s/64/pgtable.h:1349:		pmd_clear(pmdp);
 arch/powerpc/include/asm/book3s/64/pgtable.h-1350-		goto out;
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-1359-out:
 arch/powerpc/include/asm/book3s/64/pgtable.h:1360:	page_table_check_pmd_clear(mm, addr, old_pmd);
 arch/powerpc/include/asm/book3s/64/pgtable.h-1361-
 --
 arch/powerpc/include/asm/nohash/32/pgtable.h-154-#define	pmd_present(pmd)	(pmd_val(pmd) & _PMD_PRESENT_MASK)
 arch/powerpc/include/asm/nohash/32/pgtable.h:155:static inline void pmd_clear(pmd_t *pmdp)
 arch/powerpc/include/asm/nohash/32/pgtable.h-156-{
 --
 arch/powerpc/include/asm/nohash/64/pgtable.h=86=static inline void pmd_set(pmd_t *pmdp, unsigned long val)
 --
 arch/powerpc/include/asm/nohash/64/pgtable.h-90-
 arch/powerpc/include/asm/nohash/64/pgtable.h:91:static inline void pmd_clear(pmd_t *pmdp)
 arch/powerpc/include/asm/nohash/64/pgtable.h-92-{
 --
 arch/powerpc/kvm/book3s_64_mmu_radix.c=497=static void kvmppc_unmap_free_pmd(struct kvm *kvm, pmd_t *pmd, bool full,
 --
 arch/powerpc/kvm/book3s_64_mmu_radix.c-507-			if (full) {
 arch/powerpc/kvm/book3s_64_mmu_radix.c:508:				pmd_clear(p);
 arch/powerpc/kvm/book3s_64_mmu_radix.c-509-			} else {
 --
 arch/powerpc/kvm/book3s_64_mmu_radix.c-519-			kvmppc_unmap_free_pte(kvm, pte, full, lpid);
 arch/powerpc/kvm/book3s_64_mmu_radix.c:520:			pmd_clear(p);
 arch/powerpc/kvm/book3s_64_mmu_radix.c-521-		}
 --
 arch/powerpc/kvm/book3s_64_mmu_radix.c=574=static void kvmppc_unmap_free_pmd_entry_table(struct kvm *kvm, pmd_t *pmd,
 --
 arch/powerpc/kvm/book3s_64_mmu_radix.c-583-	 */
 arch/powerpc/kvm/book3s_64_mmu_radix.c:584:	pmd_clear(pmd);
 arch/powerpc/kvm/book3s_64_mmu_radix.c-585-	kvmppc_radix_flush_pwc(kvm, lpid);
 --
 arch/powerpc/mm/book3s64/hash_pgtable.c=245=pmd_t hash__pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long address,
 --
 arch/powerpc/mm/book3s64/hash_pgtable.c-253-	pmd = *pmdp;
 arch/powerpc/mm/book3s64/hash_pgtable.c:254:	pmd_clear(pmdp);
 arch/powerpc/mm/book3s64/hash_pgtable.c-255-
 arch/powerpc/mm/book3s64/hash_pgtable.c:256:	page_table_check_pmd_clear(vma->vm_mm, address, pmd);
 arch/powerpc/mm/book3s64/hash_pgtable.c-257-
 --
 arch/powerpc/mm/book3s64/pgtable.c=155=pmd_t pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
 --
 arch/powerpc/mm/book3s64/pgtable.c-162-	flush_pmd_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
 arch/powerpc/mm/book3s64/pgtable.c:163:	page_table_check_pmd_clear(vma->vm_mm, address, old_pmd);
 arch/powerpc/mm/book3s64/pgtable.c-164-
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=693=static void free_pte_table(pte_t *pte_start, pmd_t *pmd)
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-704-	pte_free_kernel(&init_mm, pte_start);
 arch/powerpc/mm/book3s64/radix_pgtable.c:705:	pmd_clear(pmd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-706-}
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=1464=pmd_t radix__pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long address,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-1475-	pmd = *pmdp;
 arch/powerpc/mm/book3s64/radix_pgtable.c:1476:	pmd_clear(pmdp);
 arch/powerpc/mm/book3s64/radix_pgtable.c-1477-
 arch/powerpc/mm/book3s64/radix_pgtable.c:1478:	page_table_check_pmd_clear(vma->vm_mm, address, pmd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-1479-
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=1675=int pmd_clear_huge(pmd_t *pmd)
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-1677-	if (pmd_leaf(*pmd)) {
 arch/powerpc/mm/book3s64/radix_pgtable.c:1678:		pmd_clear(pmd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-1679-		return 1;
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=1685=int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-1689-	pte = (pte_t *)pmd_page_vaddr(*pmd);
 arch/powerpc/mm/book3s64/radix_pgtable.c:1690:	pmd_clear(pmd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-1691-
 --
 arch/riscv/include/asm/pgtable.h=230=static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
 --
 arch/riscv/include/asm/pgtable.h-234-
 arch/riscv/include/asm/pgtable.h:235:static inline void pmd_clear(pmd_t *pmdp)
 arch/riscv/include/asm/pgtable.h-236-{
 --
 arch/riscv/include/asm/pgtable.h=1010=static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
 --
 arch/riscv/include/asm/pgtable.h-1017-
 arch/riscv/include/asm/pgtable.h:1018:	pmd_clear(pmdp);
 arch/riscv/include/asm/pgtable.h-1019-#endif
 arch/riscv/include/asm/pgtable.h-1020-
 arch/riscv/include/asm/pgtable.h:1021:	page_table_check_pmd_clear(mm, address, pmd);
 arch/riscv/include/asm/pgtable.h-1022-
 --
 arch/riscv/mm/init.c=1491=static void __meminit free_pte_table(pte_t *pte_start, pmd_t *pmd)
 --
 arch/riscv/mm/init.c-1508-		pagetable_free(ptdesc);
 arch/riscv/mm/init.c:1509:	pmd_clear(pmd);
 arch/riscv/mm/init.c-1510-}
 --
 arch/riscv/mm/init.c=1596=static void __meminit remove_pmd_mapping(pmd_t *pmd_base, unsigned long addr, unsigned long end,
 --
 arch/riscv/mm/init.c-1610-		if (pmd_leaf(pmd)) {
 arch/riscv/mm/init.c:1611:			pmd_clear(pmdp);
 arch/riscv/mm/init.c-1612-			if (is_vmemmap)
 --
 arch/riscv/mm/pgtable.c=117=int pmd_clear_huge(pmd_t *pmd)
 --
 arch/riscv/mm/pgtable.c-120-		return 0;
 arch/riscv/mm/pgtable.c:121:	pmd_clear(pmd);
 arch/riscv/mm/pgtable.c-122-	return 1;
 --
 arch/riscv/mm/pgtable.c=125=int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)
 --
 arch/riscv/mm/pgtable.c-128-
 arch/riscv/mm/pgtable.c:129:	pmd_clear(pmd);
 arch/riscv/mm/pgtable.c-130-
 --
 arch/s390/include/asm/pgtable.h=998=static inline void pud_clear(pud_t *pud)
 --
 arch/s390/include/asm/pgtable.h-1003-
 arch/s390/include/asm/pgtable.h:1004:static inline void pmd_clear(pmd_t *pmdp)
 arch/s390/include/asm/pgtable.h-1005-{
 --
 arch/s390/include/asm/pgtable.h=1726=static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
 --
 arch/s390/include/asm/pgtable.h-1731-	pmd = pmdp_xchg_direct(mm, addr, pmdp, __pmd(_SEGMENT_ENTRY_EMPTY));
 arch/s390/include/asm/pgtable.h:1732:	page_table_check_pmd_clear(mm, addr, pmd);
 arch/s390/include/asm/pgtable.h-1733-	return pmd;
 --
 arch/s390/include/asm/pgtable.h=1737=static inline pmd_t pmdp_huge_get_and_clear_full(struct vm_area_struct *vma,
 --
 arch/s390/include/asm/pgtable.h-1745-		set_pmd(pmdp, __pmd(_SEGMENT_ENTRY_EMPTY));
 arch/s390/include/asm/pgtable.h:1746:		page_table_check_pmd_clear(vma->vm_mm, addr, pmd);
 arch/s390/include/asm/pgtable.h-1747-		return pmd;
 --
 arch/s390/include/asm/pgtable.h-1749-	pmd = pmdp_xchg_lazy(vma->vm_mm, addr, pmdp, __pmd(_SEGMENT_ENTRY_EMPTY));
 arch/s390/include/asm/pgtable.h:1750:	page_table_check_pmd_clear(vma->vm_mm, addr, pmd);
 arch/s390/include/asm/pgtable.h-1751-	return pmd;
 --
 arch/s390/mm/vmem.c=207=static void try_free_pte_table(pmd_t *pmd, unsigned long start)
 --
 arch/s390/mm/vmem.c-218-	vmem_pte_free((unsigned long *) pmd_deref(*pmd));
 arch/s390/mm/vmem.c:219:	pmd_clear(pmd);
 arch/s390/mm/vmem.c-220-}
 --
 arch/s390/mm/vmem.c=223=static int __ref modify_pmd_table(pud_t *pud, unsigned long addr,
 --
 arch/s390/mm/vmem.c-243-						vmem_free_pages(pmd_deref(*pmd), get_order(PMD_SIZE), altmap);
 arch/s390/mm/vmem.c:244:					pmd_clear(pmd);
 arch/s390/mm/vmem.c-245-					pages++;
 --
 arch/s390/mm/vmem.c-247-					vmem_free_pages(pmd_deref(*pmd), get_order(PMD_SIZE), altmap);
 arch/s390/mm/vmem.c:248:					pmd_clear(pmd);
 arch/s390/mm/vmem.c-249-				}
 --
 arch/sh/include/asm/pgtable_32.h=300=static inline void set_pte(pte_t *ptep, pte_t pte)
 --
 arch/sh/include/asm/pgtable_32.h-328-#define pmd_present(x)	(pmd_val(x))
 arch/sh/include/asm/pgtable_32.h:329:#define pmd_clear(xp)	do { set_pmd(xp, __pmd(0)); } while (0)
 arch/sh/include/asm/pgtable_32.h-330-#define	pmd_bad(x)	(pmd_val(x) & ~PAGE_MASK)
 --
 arch/sparc/include/asm/pgtable_32.h=170=static inline int pmd_none(pmd_t pmd)
 --
 arch/sparc/include/asm/pgtable_32.h-174-
 arch/sparc/include/asm/pgtable_32.h:175:static inline void pmd_clear(pmd_t *pmdp)
 arch/sparc/include/asm/pgtable_32.h-176-{
 --
 arch/sparc/include/asm/pgtable_64.h=843=static inline pmd_t *pud_pgtable(pud_t pud)
 --
 arch/sparc/include/asm/pgtable_64.h-854-#define pud_page(pud)			virt_to_page((void *)pud_pgtable(pud))
 arch/sparc/include/asm/pgtable_64.h:855:#define pmd_clear(pmdp)			(pmd_val(*(pmdp)) = 0UL)
 arch/sparc/include/asm/pgtable_64.h-856-#define pud_present(pud)		(pud_val(pud) != 0U)
 --
 arch/um/include/asm/pgtable.h=35=extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
 --
 arch/um/include/asm/pgtable.h-79-#define pmd_present(x)	(pmd_val(x) & _PAGE_PRESENT)
 arch/um/include/asm/pgtable.h:80:#define pmd_clear(xp)	do { pmd_val(*(xp)) = _PAGE_NEEDSYNC; } while (0)
 arch/um/include/asm/pgtable.h-81-
 --
 arch/x86/include/asm/paravirt.h=462=static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/x86/include/asm/paravirt.h-467-
 arch/x86/include/asm/paravirt.h:468:static inline void pmd_clear(pmd_t *pmdp)
 arch/x86/include/asm/paravirt.h-469-{
 --
 arch/x86/include/asm/pgtable-2level.h=29=static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
 --
 arch/x86/include/asm/pgtable-2level.h-33-
 arch/x86/include/asm/pgtable-2level.h:34:static inline void native_pmd_clear(pmd_t *pmdp)
 arch/x86/include/asm/pgtable-2level.h-35-{
 --
 arch/x86/include/asm/pgtable-3level.h=66=static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/x86/include/asm/pgtable-3level.h-73-
 arch/x86/include/asm/pgtable-3level.h:74:static inline void native_pmd_clear(pmd_t *pmdp)
 arch/x86/include/asm/pgtable-3level.h-75-{
 --
 arch/x86/include/asm/pgtable.h=55=extern pmdval_t early_pmd_flags;
 --
 arch/x86/include/asm/pgtable.h-88-#define pte_clear(mm, addr, ptep)	native_pte_clear(mm, addr, ptep)
 arch/x86/include/asm/pgtable.h:89:#define pmd_clear(pmd)			native_pmd_clear(pmd)
 arch/x86/include/asm/pgtable.h-90-
 --
 arch/x86/include/asm/pgtable.h=1190=static inline pmd_t native_local_pmdp_get_and_clear(pmd_t *pmdp)
 --
 arch/x86/include/asm/pgtable.h-1193-
 arch/x86/include/asm/pgtable.h:1194:	native_pmd_clear(pmdp);
 arch/x86/include/asm/pgtable.h-1195-	return res;
 --
 arch/x86/include/asm/pgtable.h=1309=static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/x86/include/asm/pgtable.h-1313-
 arch/x86/include/asm/pgtable.h:1314:	page_table_check_pmd_clear(mm, addr, pmd);
 arch/x86/include/asm/pgtable.h-1315-
 --
 arch/x86/include/asm/pgtable_64.h=77=static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
 --
 arch/x86/include/asm/pgtable_64.h-81-
 arch/x86/include/asm/pgtable_64.h:82:static inline void native_pmd_clear(pmd_t *pmd)
 arch/x86/include/asm/pgtable_64.h-83-{
 --
 arch/x86/include/asm/pgtable_64.h=100=static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
 --
 arch/x86/include/asm/pgtable_64.h-107-	pmd_t ret = *xp;
 arch/x86/include/asm/pgtable_64.h:108:	native_pmd_clear(xp);
 arch/x86/include/asm/pgtable_64.h-109-	return ret;
 --
 arch/x86/mm/init_64.c=1040=static void __meminit free_pte_table(pte_t *pte_start, pmd_t *pmd)
 --
 arch/x86/mm/init_64.c-1053-	spin_lock(&init_mm.page_table_lock);
 arch/x86/mm/init_64.c:1054:	pmd_clear(pmd);
 arch/x86/mm/init_64.c-1055-	spin_unlock(&init_mm.page_table_lock);
 --
 arch/x86/mm/init_64.c=1138=remove_pmd_table(pmd_t *pmd_start, unsigned long addr, unsigned long end,
 --
 arch/x86/mm/init_64.c-1159-				spin_lock(&init_mm.page_table_lock);
 arch/x86/mm/init_64.c:1160:				pmd_clear(pmd);
 arch/x86/mm/init_64.c-1161-				spin_unlock(&init_mm.page_table_lock);
 --
 arch/x86/mm/init_64.c-1166-					spin_lock(&init_mm.page_table_lock);
 arch/x86/mm/init_64.c:1167:					pmd_clear(pmd);
 arch/x86/mm/init_64.c-1168-					spin_unlock(&init_mm.page_table_lock);
 --
 arch/x86/mm/pat/set_memory.c=1434=static bool unmap_pte_range(pmd_t *pmd, unsigned long start, unsigned long end)
 --
 arch/x86/mm/pat/set_memory.c-1445-	if (try_to_free_pte_page((pte_t *)pmd_page_vaddr(*pmd))) {
 arch/x86/mm/pat/set_memory.c:1446:		pmd_clear(pmd);
 arch/x86/mm/pat/set_memory.c-1447-		return true;
 --
 arch/x86/mm/pat/set_memory.c=1460=static void unmap_pmd_range(pud_t *pud, unsigned long start, unsigned long end)
 --
 arch/x86/mm/pat/set_memory.c-1481-		if (pmd_leaf(*pmd))
 arch/x86/mm/pat/set_memory.c:1482:			pmd_clear(pmd);
 arch/x86/mm/pat/set_memory.c-1483-		else
 --
 arch/x86/mm/pgtable.c=708=int pmd_clear_huge(pmd_t *pmd)
 --
 arch/x86/mm/pgtable.c-710-	if (pmd_leaf(*pmd)) {
 arch/x86/mm/pgtable.c:711:		pmd_clear(pmd);
]
]

112/2 2026/05/25 00:25 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 142271
							output: 40
							thoughts: 407
						

Thoughts:
**Investigating PMD Clearing in RISC-V Memory Management**

Okay, so I'm looking at how PMDs are cleared in the RISC-V implementation, specifically focusing on `pmd_clear`. The first thing I see is the straightforward definition of `pmd_clear`: it just sets the PMD to zero using `__pmd(0)`. Simple enough.

Then I get to `pmdp_huge_get_and_clear`. This function *also* calls `pmd_clear`, but it does so *after* getting and clearing the PMD itself via `pmdp_get_and_clear`. A key observation here is that `pmdp_huge_get_and_clear` *does* call `page_table_check_pmd_clear` *after* the initial `pmdp_get_and_clear`, but *before* `pmd_clear`. However, `pmd_clear` itself *doesn't* call this check. That raises a question: is there a difference in how these are used, and more importantly, is `pmd_clear` ever used directly on a user PMD, where such checks might be essential?

Digging deeper into the RISC-V architecture-specific code, I find `pmd_clear_huge`. This is interesting! It *conditionally* calls `pmd_clear`. The condition is that the PMD needs to be a leaf (a fully populated page).

Now the crucial piece: `pmd_clear_huge` is actually *used* in `free_pmd_range` in the core memory management code, which means it is used on user PMDs. This clarifies the concern. This means the `pmd_clear` that gets called within `pmd_clear_huge` *bypasses* the `page_table_check_pmd_clear` that is called after `pmdp_huge_get_and_clear`. I need to investigate the implications of this bypass. This warrants further investigation to understand why the check is omitted in this specific case, and whether this omission could potentially introduce subtle memory management bugs.



113/2 2026/05/25 00:25 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/memory.c IncludeLines:true Name:free_pmd_range]

Results:
map[SourceCode: 185:	static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
 186:					unsigned long addr, unsigned long end,
 187:					unsigned long floor, unsigned long ceiling)
 188:	{
 189:		pmd_t *pmd;
 190:		unsigned long next;
 191:		unsigned long start;
 192:	
 193:		start = addr;
 194:		pmd = pmd_offset(pud, addr);
 195:		do {
 196:			next = pmd_addr_end(addr, end);
 197:			if (pmd_none_or_clear_bad(pmd))
 198:				continue;
 199:			free_pte_range(tlb, pmd, addr);
 200:		} while (pmd++, addr = next, addr != end);
 201:	
 202:		start &= PUD_MASK;
 203:		if (start < floor)
 204:			return;
 205:		if (ceiling) {
 206:			ceiling &= PUD_MASK;
 207:			if (!ceiling)
 208:				return;
 209:		}
 210:		if (end - 1 > ceiling - 1)
 211:			return;
 212:	
 213:		pmd = pmd_offset(pud, start);
 214:		pud_clear(pud);
 215:		pmd_free_tlb(tlb, pmd, start);
 216:		mm_dec_nr_pmds(tlb->mm);
 217:	}
 SourceFile:mm/memory.c]

114/2 2026/05/25 00:25 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 143671
							output: 47
							thoughts: 51
						

Thoughts:
Here's my take on the thought process:

**Diving Deep into Page Table Management**

Hold on a second, something doesn't feel right with this function call chain. It seems like `pmd_none_or_clear_bad` is calling `pmd_clear_bad`, and that function then calls `pmd_clear_huge`? That seems a bit... indirect, doesn't it? I need to verify this sequence. I'll need to go and examine the implementation of `pmd_none_or_clear_bad` to confirm the code flow and confirm my suspicion. Let's see what's actually going on in there.



115/2 2026/05/25 00:25 tool codesearch-definition-source
0m Args:
map[ContextFile:include/linux/pgtable.h IncludeLines:true Name:pmd_none_or_clear_bad]

Results:
map[SourceCode:1517:	static inline int pmd_none_or_clear_bad(pmd_t *pmd)
1518:	{
1519:		if (pmd_none(*pmd))
1520:			return 1;
1521:		if (unlikely(pmd_bad(*pmd))) {
1522:			pmd_clear_bad(pmd);
1523:			return 1;
1524:		}
1525:		return 0;
1526:	}
 SourceFile:include/linux/pgtable.h]

116/2 2026/05/25 00:25 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 144084
							output: 40
							thoughts: 9
						

Thoughts:
Okay, here's my summary, in the first person, as an expert in the field would perceive the thought process:

**Internal Audit of `pmd_clear_bad` and Its Implications**

Alright, let's break this down. When I see `pmd_clear_bad`, my first instinct is to immediately think about the context of its use within the system's memory management or the page management domain. It's almost certain it's related to some kind of error handling or cleanup operation, specifically dealing with Page Table Entry (PTE) modifications within the kernel. The name "bad" suggests we're dealing with a PTE that, for some reason, is flagged as invalid or problematic.

Immediately I need to dive deeper to determine where and when it's called. What's the triggering event that results in a "bad" entry? Are we talking about a hardware issue? A software bug? Is this related to a specific architecture or system configuration? Does it pertain to a race condition or another concurrent access issue? And finally, what specific consequences follow when that particular PTE bit is marked as "bad?" Is this a potential security vulnerability? Is there a risk of memory corruption? What is the potential impact on performance?

My next thought is to examine where it's *used*, and the control flow that leads to it. Are we dealing with something that handles unexpected memory failures, or an intentional method for marking bad PTEs, perhaps after an error has been detected in the virtual memory mapping? Are there any associated locks or synchronization primitives used within this function to prevent concurrency issues? A proper review would include looking for the relevant stack traces, examining register values, and determining potential causes.

I’d want to know how this impacts the overall stability and integrity of the system. I would want to look at the system call stack in conjunction with `pmd_clear_bad`, and determine if it's potentially related to any known issues in memory management.

Finally, I'd consider how this function interacts with other page table manipulation functions. Are there dependencies or shared data structures that could lead to unexpected behavior if `pmd_clear_bad` isn't handled correctly? Are there any potential vulnerabilities, such as a double-free situation or a race condition that could be exploited by an attacker?



117/2 2026/05/25 00:25 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/memory.c IncludeLines:true Name:pmd_clear_bad]

Results:
map[SourceCode:  49:	/*
  50:	 * Note that the pmd variant below can't be stub'ed out just as for p4d/pud
  51:	 * above. pmd folding is special and typically pmd_* macros refer to upper
  52:	 * level even when folded
  53:	 */
  54:	void pmd_clear_bad(pmd_t *pmd)
  55:	{
  56:		pmd_ERROR(*pmd);
  57:		pmd_clear(pmd);
  58:	}
 SourceFile:mm/pgtable-generic.c]

118/2 2026/05/25 00:25 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 144788
							output: 24
							thoughts: 47
						

Thoughts:
Okay, let's see. Here's my understanding, as if these were my thoughts:

**Analyzing PMD Clearing Functions**

Alright, so I'm thinking about these page table management functions, specifically the `pmd_clear_bad` function. I see that it calls `pmd_clear`, which is the standard way to clear a page map directory entry. That makes sense, but then it hits me. The `pmd_bad` flag, that condition for running `pmd_clear_bad`, it only gets set if the PMD is corrupted, right? So, what's the deal with `pmd_clear_huge` then? Is this function clearing potentially huge pages? Does this relationship to corruption make sense in this context? I'm missing something, or maybe I am looking too hard!



119/2 2026/05/25 00:25 tool codesearch-find-references
0m Args:
map[Name:pmd_clear_huge]

Results:
map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:pmd_huge_tests SourceFile:mm/debug_vm_pgtable.c SourceLine:450] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:vunmap_pmd_range SourceFile:mm/vmalloc.c SourceLine:408]] TruncatedOutput:false]

120/2 2026/05/25 00:25 llm expert
1m Model:
gemini-3.1-pro-preview

Tokens:
							input: 145158
							output: 39
							thoughts: 115
						

Thoughts:
**Investigating the Usage of `pmd_clear_huge`**

Okay, so `pmd_clear_huge` seems pretty specialized, only showing up in `vunmap_pmd_range` and the `pmd_huge_tests`. That strongly suggests it's not involved in handling user-space PMDs, which is good to know. But let me just pause and consider this a little more carefully.

Hang on... what about `pte_clear_not_present_full`? I need to make sure I'm not missing anything. I know that `exit_mmap` in `mm/mmap.c` is crucial, that calls `unmap_vmas`, which then calls `unmap_page_range`, and this in turn, calls `zap_pte_range`. So, I'll need to check the calls within `zap_pte_range` to clarify if there is any overlap. Let me dive into that function and see what's going on within.



121/2 2026/05/25 00:26 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/memory.c IncludeLines:true Name:zap_pte_range]

Results:
map[SourceCode:1884:	static unsigned long zap_pte_range(struct mmu_gather *tlb,
1885:					struct vm_area_struct *vma, pmd_t *pmd,
1886:					unsigned long addr, unsigned long end,
1887:					struct zap_details *details)
1888:	{
1889:		bool can_reclaim_pt = pte_table_reclaim_possible(addr, end, details);
1890:		bool force_flush = false, force_break = false;
1891:		struct mm_struct *mm = tlb->mm;
1892:		int rss[NR_MM_COUNTERS];
1893:		spinlock_t *ptl;
1894:		pte_t *start_pte;
1895:		pte_t *pte;
1896:		pmd_t pmdval;
1897:		unsigned long start = addr;
1898:		bool direct_reclaim = true;
1899:		int nr;
1900:	
1901:	retry:
1902:		tlb_change_page_size(tlb, PAGE_SIZE);
1903:		init_rss_vec(rss);
1904:		start_pte = pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
1905:		if (!pte)
1906:			return addr;
1907:	
1908:		flush_tlb_batched_pending(mm);
1909:		lazy_mmu_mode_enable();
1910:		do {
1911:			bool any_skipped = false;
1912:	
1913:			if (need_resched()) {
1914:				direct_reclaim = false;
1915:				break;
1916:			}
1917:	
1918:			nr = do_zap_pte_range(tlb, vma, pte, addr, end, details, rss,
1919:					      &force_flush, &force_break, &any_skipped);
1920:			if (any_skipped)
1921:				can_reclaim_pt = false;
1922:			if (unlikely(force_break)) {
1923:				addr += nr * PAGE_SIZE;
1924:				direct_reclaim = false;
1925:				break;
1926:			}
1927:		} while (pte += nr, addr += PAGE_SIZE * nr, addr != end);
1928:	
1929:		/*
1930:		 * Fast path: try to hold the pmd lock and unmap the PTE page.
1931:		 *
1932:		 * If the pte lock was released midway (retry case), or if the attempt
1933:		 * to hold the pmd lock failed, then we need to recheck all pte entries
1934:		 * to ensure they are still none, thereby preventing the pte entries
1935:		 * from being repopulated by another thread.
1936:		 */
1937:		if (can_reclaim_pt && direct_reclaim && addr == end)
1938:			direct_reclaim = zap_empty_pte_table(mm, pmd, ptl, &pmdval);
1939:	
1940:		add_mm_rss_vec(mm, rss);
1941:		lazy_mmu_mode_disable();
1942:	
1943:		/* Do the actual TLB flush before dropping ptl */
1944:		if (force_flush) {
1945:			tlb_flush_mmu_tlbonly(tlb);
1946:			tlb_flush_rmaps(tlb, vma);
1947:		}
1948:		pte_unmap_unlock(start_pte, ptl);
1949:	
1950:		/*
1951:		 * If we forced a TLB flush (either due to running out of
1952:		 * batch buffers or because we needed to flush dirty TLB
1953:		 * entries before releasing the ptl), free the batched
1954:		 * memory too. Come back again if we didn't do everything.
1955:		 */
1956:		if (force_flush)
1957:			tlb_flush_mmu(tlb);
1958:	
1959:		if (addr != end) {
1960:			cond_resched();
1961:			force_flush = false;
1962:			force_break = false;
1963:			goto retry;
1964:		}
1965:	
1966:		if (can_reclaim_pt) {
1967:			if (direct_reclaim || zap_pte_table_if_empty(mm, pmd, start, &pmdval)) {
1968:				pte_free_tlb(tlb, pmd_pgtable(pmdval), addr);
1969:				mm_dec_nr_ptes(mm);
1970:			}
1971:		}
1972:	
1973:		return addr;
1974:	}
 SourceFile:mm/memory.c]

122/2 2026/05/25 00:26 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 146952
							output: 41
							thoughts: 10
						

Thoughts:
Okay, here's my interpretation of that code, summarized as if it's my own thought process, assuming I'm an expert in this field.

**Deep Dive into `do_zap_pte_range`**

Alright, let's break this down. We're looking at `do_zap_pte_range`. This function is likely the heart of a pretty critical operation: tearing down a range of page table entries (PTEs). Think "cleanup" after a memory region is no longer needed, maybe during a process termination, memory unmapping, or some kind of virtual memory manipulation.

I immediately start thinking about the context. What's the surrounding architecture? x86? ARM? Something custom? The specific PTE structure will vary, but the fundamental *purpose* is the same: to invalidate, deallocate, and potentially flush any cached data associated with those virtual addresses. This is low-level stuff, right in the memory management unit's (MMU) sweet spot.

I know I have to be extremely careful with concurrency. If we’re dealing with a multi-threaded system, which is almost guaranteed in any modern environment, we've got to ensure atomicity. We can't have one CPU removing a PTE while another is trying to access the same virtual address. This screams "locks" and "memory barriers." Are we taking the appropriate locks around the page table structure? Are we using proper atomic instructions to update the PTEs themselves? Are memory barriers in place to guarantee that these changes are visible to all cores? These are critical questions.

Then there's the issue of TLB (Translation Lookaside Buffer) invalidation. This is where the real fun begins. Simply invalidating the PTE in the page table itself isn't enough. The MMU has a cache, the TLB, which stores recent translations. This function *has* to flush those entries from the TLB, or we're going to have stale translations persisting, which can lead to the worst kind of bugs: subtle, intermittent, and hard to debug memory errors. Do we have the correct TLB shootdown mechanisms in place? Are we sending the necessary IPIs (Inter-Processor Interrupts) to other CPUs to invalidate their TLB entries? It all depends on the underlying architecture. What about the L1 and L2 caches - how are they handled?

I'm considering the potential impact on performance, too. This operation is probably time-sensitive. The quicker we can zap these PTEs, the better. Any unnecessary overhead, extra locking, or inefficient TLB invalidation could become a bottleneck. We need to find the right balance between correctness and performance, and the details of this implementation will dictate how successful that balance is.



123/2 2026/05/25 00:26 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/memory.c IncludeLines:true Name:do_zap_pte_range]

Results:
map[SourceCode:1790:	static inline int do_zap_pte_range(struct mmu_gather *tlb,
1791:					   struct vm_area_struct *vma, pte_t *pte,
1792:					   unsigned long addr, unsigned long end,
1793:					   struct zap_details *details, int *rss,
1794:					   bool *force_flush, bool *force_break,
1795:					   bool *any_skipped)
1796:	{
1797:		pte_t ptent = ptep_get(pte);
1798:		int max_nr = (end - addr) / PAGE_SIZE;
1799:		int nr = 0;
1800:	
1801:		/* Skip all consecutive none ptes */
1802:		if (pte_none(ptent)) {
1803:			for (nr = 1; nr < max_nr; nr++) {
1804:				ptent = ptep_get(pte + nr);
1805:				if (!pte_none(ptent))
1806:					break;
1807:			}
1808:			max_nr -= nr;
1809:			if (!max_nr)
1810:				return nr;
1811:			pte += nr;
1812:			addr += nr * PAGE_SIZE;
1813:		}
1814:	
1815:		if (pte_present(ptent))
1816:			nr += zap_present_ptes(tlb, vma, pte, ptent, max_nr, addr,
1817:					       details, rss, force_flush, force_break,
1818:					       any_skipped);
1819:		else
1820:			nr += zap_nonpresent_ptes(tlb, vma, pte, ptent, max_nr, addr,
1821:						  details, rss, any_skipped);
1822:	
1823:		return nr;
1824:	}
 SourceFile:mm/memory.c]

124/2 2026/05/25 00:26 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 148145
							output: 40
							thoughts: 9
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:

**Analyzing `zap_present_ptes` Functionality**

Alright, let's break down this `zap_present_ptes` function, because that's where the critical stuff is happening. My initial thought process is to look for the input variables, because from there I can better understand what's coming in and therefore what should be coming out. It's safe to assume from the name that this handles present PTEs (Page Table Entries), whatever *present* means in context. From here, I need to know the architecture it is dealing with. Is it x86, ARM, or something else? Understanding the target architecture is crucial for interpreting bitfields and memory layouts. I'm immediately interested in:

*   **PTE Structure:** What's the fundamental layout of a PTE on this architecture? Is it multi-level? What bits represent presence, write permissions, user/kernel access, dirty, accessed, page frame number, etc.? I'm going to want to know, in detail, what the PTE field structure is and what the various bit configurations will mean in the context of the present function.

*   **Address Space:** How is the virtual address space organized? Is there a segmentation system? Is this a flat memory model? What are the implications for page table walking? This will influence how the logic handles virtual addresses and their corresponding physical addresses.

*   **Caching and TLB:** How does caching (L1, L2, etc.) come into play? How does the Translation Lookaside Buffer (TLB) interact with PTE updates? Are there any cache coherence issues to consider? What TLB invalidation mechanisms are being used? I need to understand if the function is handling cache flushes or TLB invalidations after PTE modifications.

*   **Concurrency:** Is this function thread-safe? Does it handle any locking mechanisms to protect the PTE data structures from concurrent access? This is really a must-know.

In essence, I need a deep dive into the underlying architecture and memory management details to truly grasp what `zap_present_ptes` is doing, and if it's doing it correctly and efficiently. I need to figure out what it's supposed to achieve in the overall memory management strategy. Is this for handling memory reclamation, demand paging, memory hotplug, or something else entirely? Then I need to see if it's following proper conventions, as well as if it's free of race conditions.

Finally, I need to know how it's being *called*. What's the calling context? What other code interacts with the PTEs modified by this function? I'll look for any pre-conditions. Are there any post-conditions that are assumed to be true when the function returns? What errors can happen? If exceptions can occur during this function, how are they handled?

Once I have a firm grasp on these foundational details, only then can I assess the actual code with a critical eye, and really understand its function and if there might be bugs or optimizations that I could spot.



125/2 2026/05/25 00:26 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/memory.c IncludeLines:true Name:zap_present_ptes]

Results:
map[SourceCode:1667:	/*
1668:	 * Zap or skip at least one present PTE, trying to batch-process subsequent
1669:	 * PTEs that map consecutive pages of the same folio.
1670:	 *
1671:	 * Returns the number of processed (skipped or zapped) PTEs (at least 1).
1672:	 */
1673:	static inline int zap_present_ptes(struct mmu_gather *tlb,
1674:			struct vm_area_struct *vma, pte_t *pte, pte_t ptent,
1675:			unsigned int max_nr, unsigned long addr,
1676:			struct zap_details *details, int *rss, bool *force_flush,
1677:			bool *force_break, bool *any_skipped)
1678:	{
1679:		struct mm_struct *mm = tlb->mm;
1680:		struct folio *folio;
1681:		struct page *page;
1682:		int nr;
1683:	
1684:		page = vm_normal_page(vma, addr, ptent);
1685:		if (!page) {
1686:			/* We don't need up-to-date accessed/dirty bits. */
1687:			ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm);
1688:			arch_check_zapped_pte(vma, ptent);
1689:			tlb_remove_tlb_entry(tlb, pte, addr);
1690:			if (userfaultfd_pte_wp(vma, ptent))
1691:				*any_skipped = zap_install_uffd_wp_if_needed(vma, addr,
1692:							pte, 1, details, ptent);
1693:			ksm_might_unmap_zero_page(mm, ptent);
1694:			return 1;
1695:		}
1696:	
1697:		folio = page_folio(page);
1698:		if (unlikely(!should_zap_folio(details, folio))) {
1699:			*any_skipped = true;
1700:			return 1;
1701:		}
1702:	
1703:		/*
1704:		 * Make sure that the common "small folio" case is as fast as possible
1705:		 * by keeping the batching logic separate.
1706:		 */
1707:		if (unlikely(folio_test_large(folio) && max_nr != 1)) {
1708:			nr = folio_pte_batch(folio, pte, ptent, max_nr);
1709:			zap_present_folio_ptes(tlb, vma, folio, page, pte, ptent, nr,
1710:					       addr, details, rss, force_flush,
1711:					       force_break, any_skipped);
1712:			return nr;
1713:		}
1714:		zap_present_folio_ptes(tlb, vma, folio, page, pte, ptent, 1, addr,
1715:				       details, rss, force_flush, force_break, any_skipped);
1716:		return 1;
1717:	}
 SourceFile:mm/memory.c]

126/2 2026/05/25 00:26 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 149773
							output: 42
							thoughts: 11
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:

**Analyzing `zap_present_folio_ptes`**

Alright, let's break down this function, `zap_present_folio_ptes`. My initial thought is to immediately consider the context. What is "folio"? Is this a financial term, a document format, a versioning system, or something else entirely? The "present" suggests display or representation, and "ptes"... that's the key. Are we talking about page table entries? Are we working with memory management, a virtual address space, or maybe some form of data structure management related to this folio?

My next line of thinking will explore some assumptions. I will hypothesize based on the "present" aspect that this is likely related to how the folio is being displayed, made available, or presented to a higher level. The "zap" prefix implies removal, erasure, or invalidation of whatever is being represented. So my suspicion is it is a routine to invalidate or clear up these entries associated with the folio. The "folio" itself probably houses a chunk of data, and the `ptes` are then responsible for presenting it. This is based on my experience and domain knowledge.

I would then focus on where the function is located in the codebase. Is this in the kernel? Is it in user space? What other modules call this function? Knowing the origin is key to properly understanding its function and intended impact. I’ll need to cross-reference this with the related data structures to confirm if `ptes` are, indeed, the presentation medium in this case.

I’m immediately wondering about concurrency and locking. If this function is dealing with page table entries, there will be implications for concurrent access and potential race conditions. I need to know how it interacts with other parts of the system and how it handles potential conflicts. Does it use spinlocks, mutexes, atomic operations, or some other mechanism? Are there any obvious potential deadlocks or data corruption issues that jump out?

Finally, what are the error conditions and edge cases? What happens if the folio is already "zapped"? What happens if the PTEs are invalid? Is there any graceful error handling, or does it trigger a panic or assertion? Knowing the error behavior will be critical. I'd then begin a formal and rigorous code inspection of the actual implementation.



127/2 2026/05/25 00:27 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/memory.c IncludeLines:true Name:zap_present_folio_ptes]

Results:
map[SourceCode:1622:	static __always_inline void zap_present_folio_ptes(struct mmu_gather *tlb,
1623:			struct vm_area_struct *vma, struct folio *folio,
1624:			struct page *page, pte_t *pte, pte_t ptent, unsigned int nr,
1625:			unsigned long addr, struct zap_details *details, int *rss,
1626:			bool *force_flush, bool *force_break, bool *any_skipped)
1627:	{
1628:		struct mm_struct *mm = tlb->mm;
1629:		bool delay_rmap = false;
1630:	
1631:		if (!folio_test_anon(folio)) {
1632:			ptent = get_and_clear_full_ptes(mm, addr, pte, nr, tlb->fullmm);
1633:			if (pte_dirty(ptent)) {
1634:				folio_mark_dirty(folio);
1635:				if (tlb_delay_rmap(tlb)) {
1636:					delay_rmap = true;
1637:					*force_flush = true;
1638:				}
1639:			}
1640:			if (pte_young(ptent) && likely(vma_has_recency(vma)))
1641:				folio_mark_accessed(folio);
1642:			rss[mm_counter(folio)] -= nr;
1643:		} else {
1644:			/* We don't need up-to-date accessed/dirty bits. */
1645:			clear_full_ptes(mm, addr, pte, nr, tlb->fullmm);
1646:			rss[MM_ANONPAGES] -= nr;
1647:		}
1648:		/* Checking a single PTE in a batch is sufficient. */
1649:		arch_check_zapped_pte(vma, ptent);
1650:		tlb_remove_tlb_entries(tlb, pte, nr, addr);
1651:		if (unlikely(userfaultfd_pte_wp(vma, ptent)))
1652:			*any_skipped = zap_install_uffd_wp_if_needed(vma, addr, pte,
1653:								     nr, details, ptent);
1654:	
1655:		if (!delay_rmap) {
1656:			folio_remove_rmap_ptes(folio, page, nr, vma);
1657:	
1658:			if (unlikely(folio_mapcount(folio) < 0))
1659:				print_bad_pte(vma, addr, ptent, page);
1660:		}
1661:		if (unlikely(__tlb_remove_folio_pages(tlb, page, nr, delay_rmap))) {
1662:			*force_flush = true;
1663:			*force_break = true;
1664:		}
1665:	}
 SourceFile:mm/memory.c]

128/2 2026/05/25 00:27 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 151165
							output: 48
							thoughts: 103
						

Thoughts:
**Analyzing Anonymous Page Clearing in RISC-V**

Okay, so `clear_full_ptes` is definitely getting called for anonymous pages. Makes sense, given the context. The code snippet clearly shows that if we're dealing with anonymous memory (indicated by the `else` block), we're calling `clear_full_ptes`. We don't care about up-to-date accessed/dirty bits in this case. The key here is the `fullmm` argument passed to `clear_full_ptes`. I should probably double-check that this is correct on the RISC-V architecture. I need to understand how RISC-V handles these PTE bits when clearing them, how it interacts with the TLB, and why we're subtracting `nr` (number of pages) from `rss[MM_ANONPAGES]`. I'm guessing this accounts for the pages being freed. Time to dive into the RISC-V implementation of `clear_full_ptes` to verify the assumptions about dirty/accessed bits are accurate for this particular case. Need to ensure the TLB is invalidated correctly, too, to make sure there's no stale data floating around.



129/2 2026/05/25 00:27 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:clear_full_ptes]

Results:
map[SourceCode: 883:	/**
 884:	 * clear_full_ptes - Clear present PTEs that map consecutive pages of the same
 885:	 *		     folio.
 886:	 * @mm: Address space the pages are mapped into.
 887:	 * @addr: Address the first page is mapped at.
 888:	 * @ptep: Page table pointer for the first entry.
 889:	 * @nr: Number of entries to clear.
 890:	 * @full: Whether we are clearing a full mm.
 891:	 *
 892:	 * May be overridden by the architecture; otherwise, implemented as a simple
 893:	 * loop over ptep_get_and_clear_full().
 894:	 *
 895:	 * Note that PTE bits in the PTE range besides the PFN can differ. For example,
 896:	 * some PTEs might be write-protected.
 897:	 *
 898:	 * Context: The caller holds the page table lock.  The PTEs map consecutive
 899:	 * pages that belong to the same folio.  The PTEs are all in the same PMD.
 900:	 */
 901:	static inline void clear_full_ptes(struct mm_struct *mm, unsigned long addr,
 902:			pte_t *ptep, unsigned int nr, int full)
 903:	{
 904:		for (;;) {
 905:			ptep_get_and_clear_full(mm, addr, ptep, full);
 906:			if (--nr == 0)
 907:				break;
 908:			ptep++;
 909:			addr += PAGE_SIZE;
 910:		}
 911:	}
 SourceFile:include/linux/pgtable.h]

130/2 2026/05/25 00:27 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 152068
							output: 21
							thoughts: 30
						

Thoughts:
Okay, here's my interpretation of those thoughts, tailored for an expert audience:

**Investigating `clear_full_ptes` in the RISC-V context**

Alright, I'm diving into this. The initial thought immediately points me to `clear_full_ptes`. I know that function is defined in `include/linux/pgtable.h`, standard Linux kernel stuff for page table manipulation. But, the crucial question pops up immediately: does the RISC-V architecture implement its own version, potentially overriding the generic definition? That's what I *really* need to know. Understanding the exact behavior of `clear_full_ptes` in this specific architecture is critical for debugging or optimizing whatever code I'm working on right now. A generic implementation might not be optimal, or even correct, given the RISC-V's unique features, particularly its memory management and page table structures, or any custom extensions the implementer has used. I need to track down the definitive answer on whether there's a RISC-V-specific implementation or if the generic one is being used.



131/2 2026/05/25 00:27 tool grepper
0m Args:
map[Expression:define clear_full_ptes]

Results:
map[Output:arch/arm64/include/asm/pgtable.h=1789=static inline void pte_clear(struct mm_struct *mm,
--
arch/arm64/include/asm/pgtable.h-1795-
arch/arm64/include/asm/pgtable.h:1796:#define clear_full_ptes clear_full_ptes
arch/arm64/include/asm/pgtable.h-1797-static inline void clear_full_ptes(struct mm_struct *mm, unsigned long addr,
--
arch/arm64/include/asm/pgtable.h=1919=static inline void clear_young_dirty_ptes(struct vm_area_struct *vma,
--
arch/arm64/include/asm/pgtable.h-1934-#define pte_clear				__pte_clear
arch/arm64/include/asm/pgtable.h:1935:#define clear_full_ptes				__clear_full_ptes
arch/arm64/include/asm/pgtable.h-1936-#define get_and_clear_full_ptes			__get_and_clear_full_ptes
]

132/2 2026/05/25 00:27 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 152657
							output: 26
							thoughts: 58
						

Thoughts:
**Examining the Memory Management Implementation**

Okay, so the RISC-V architecture doesn't have a specific override for `clear_full_ptes`. That means it's relying on the default implementation. That brings us to `ptep_get_and_clear_full`. Right, that's the one we need to scrutinize in the RISC-V context. Time to dive into the RISC-V implementation of that function and see what's happening at the hardware level. We need to confirm how it's interacting with the page table entries, any potential atomic operations, and ensure that it's all aligned with the RISC-V memory model. Let's see if there's anything interesting there.



133/2 2026/05/25 00:27 tool grepper
0m Error:
no matches

Args:
map[Expression:define ptep_get_and_clear_full]

Results:
map[Output:]

134/2 2026/05/25 00:27 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 152910
							output: 47
							thoughts: 28
						

Thoughts:
Okay, here's my interpretation of that thought process, from an expert's perspective:

**Diving into Page Table Operations**

Alright, time to dig into the guts of how the kernel manages its page tables. I need to understand what's happening with `ptep_get_and_clear_full`. My gut tells me this is a low-level operation, likely dealing with retrieving and atomically clearing a Page Table Entry (PTE). The "full" part probably indicates that it's designed to clear everything within the PTE in one go. I'm going to jump straight to the source – I'll start by searching in `include/linux/pgtable.h`. That's where all the fundamental definitions for these structures and functions should reside. That's the best place to start. Let's see what's what.



135/2 2026/05/25 00:27 tool codesearch-definition-source
0m Args:
map[ContextFile:include/linux/pgtable.h IncludeLines:true Name:ptep_get_and_clear_full]

Results:
map[SourceCode:1252:	static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
1253:						    unsigned long addr, pte_t *ptep,
1254:						    int full)
1255:	{
1256:		pte_t pte;
1257:		if (full) {
1258:			/*
1259:			 * Full address destruction in progress; paravirt does not
1260:			 * care about updates and native needs no locking
1261:			 */
1262:			pte = native_local_ptep_get_and_clear(ptep);
1263:			page_table_check_pte_clear(mm, addr, pte);
1264:		} else {
1265:			pte = ptep_get_and_clear(mm, addr, ptep);
1266:		}
1267:		return pte;
1268:	}
 SourceFile:arch/x86/include/asm/pgtable.h]

136/2 2026/05/25 00:27 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 153461
							output: 47
							thoughts: 40
						

Thoughts:
Okay, here's my interpretation of those thoughts, tailored for an expert audience:

**Memory Management Deep Dive - Initial Observation**

Hmm, so that definition I was looking for, that's in the x86-specific architecture include directory, `arch/x86/include/asm/pgtable.h`. That's a good starting point, but it immediately raises a question. Now, is the architecture-specific variant where the core logic resides, or is it merely an implementation of a broader more general approach?

What does the default, generic page table implementation defined in `include/linux/pgtable.h` do? Is this x86 header specializing an interface, extending a structure, or providing a complete, self-contained implementation? Understanding the interplay and inheritance (or lack thereof) between these two headers is crucial. I need to quickly determine the levels of abstraction involved and assess how the x86-specific code integrates with the kernel's overall memory management framework. This is important to fully understand the implication of this definition.



137/2 2026/05/25 00:27 tool codesearch-definition-source
0m Args:
map[ContextFile:include/linux/pgtable.h IncludeLines:true Name:ptep_get_and_clear_full]

Results:
map[SourceCode:1252:	static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
1253:						    unsigned long addr, pte_t *ptep,
1254:						    int full)
1255:	{
1256:		pte_t pte;
1257:		if (full) {
1258:			/*
1259:			 * Full address destruction in progress; paravirt does not
1260:			 * care about updates and native needs no locking
1261:			 */
1262:			pte = native_local_ptep_get_and_clear(ptep);
1263:			page_table_check_pte_clear(mm, addr, pte);
1264:		} else {
1265:			pte = ptep_get_and_clear(mm, addr, ptep);
1266:		}
1267:		return pte;
1268:	}
 SourceFile:arch/x86/include/asm/pgtable.h]

138/2 2026/05/25 00:27 llm expert
1m Model:
gemini-3.1-pro-preview

Tokens:
							input: 154064
							output: 25
							thoughts: 30
						

Thoughts:
Here's my thought process, summarized as you requested:

**Navigating the Page Table Maze**

Okay, before I go any further, I need to pinpoint the exact function definitions related to page table entry manipulation, specifically the part where we're retrieving and potentially clearing the full page table entry. I need to be precise, so I'm going to jump into the source code – specifically, the include directory where we define core data structures and functions. I'm thinking `include/linux/pgtable.h` is the prime location for these sorts of low-level definitions. Let me search directly for `ptep_get_and_clear_full` within that file. This should give me the exact signature and behavior I'm after, and hopefully clarify its interactions with related structures like `pte_t`. I'm expecting this function to be critical for the atomic retrieval and clearing of page table entries.



139/2 2026/05/25 00:28 tool grepper
0m Args:
map[Expression:ptep_get_and_clear_full\(]

Results:
map[Output:arch/powerpc/include/asm/book3s/64/pgtable.h=418=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
--
arch/powerpc/include/asm/book3s/64/pgtable.h-428-#define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
arch/powerpc/include/asm/book3s/64/pgtable.h:429:static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
arch/powerpc/include/asm/book3s/64/pgtable.h-430-					    unsigned long addr,
--
arch/powerpc/include/asm/book3s/64/pgtable.h-439-		 */
arch/powerpc/include/asm/book3s/64/pgtable.h:440:		old_pte = radix__ptep_get_and_clear_full(mm, addr, ptep, full);
arch/powerpc/include/asm/book3s/64/pgtable.h-441-		page_table_check_pte_clear(mm, addr, old_pte);
--
arch/powerpc/include/asm/book3s/64/radix.h=172=static inline unsigned long radix__pte_update(struct mm_struct *mm,
--
arch/powerpc/include/asm/book3s/64/radix.h-186-
arch/powerpc/include/asm/book3s/64/radix.h:187:static inline pte_t radix__ptep_get_and_clear_full(struct mm_struct *mm,
arch/powerpc/include/asm/book3s/64/radix.h-188-						   unsigned long addr,
--
arch/s390/include/asm/pgtable.h=1205=static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
--
arch/s390/include/asm/pgtable.h-1225-#define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
arch/s390/include/asm/pgtable.h:1226:static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
arch/s390/include/asm/pgtable.h-1227-					    unsigned long addr,
--
arch/x86/include/asm/pgtable.h=1243=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
--
arch/x86/include/asm/pgtable.h-1251-#define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
arch/x86/include/asm/pgtable.h:1252:static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
arch/x86/include/asm/pgtable.h-1253-					    unsigned long addr, pte_t *ptep,
--
include/linux/pgtable.h=802=static inline pud_t pudp_huge_get_and_clear_full(struct vm_area_struct *vma,
--
include/linux/pgtable.h-811-#ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
include/linux/pgtable.h:812:static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
include/linux/pgtable.h-813-					    unsigned long address, pte_t *ptep,
--
include/linux/pgtable.h-830- * May be overridden by the architecture; otherwise, implemented as a simple
include/linux/pgtable.h:831: * loop over ptep_get_and_clear_full(), merging dirty/accessed bits into the
include/linux/pgtable.h-832- * returned PTE.
--
include/linux/pgtable.h=840=static inline pte_t get_and_clear_full_ptes(struct mm_struct *mm,
--
include/linux/pgtable.h-844-
include/linux/pgtable.h:845:	pte = ptep_get_and_clear_full(mm, addr, ptep, full);
include/linux/pgtable.h-846-	while (--nr) {
--
include/linux/pgtable.h-848-		addr += PAGE_SIZE;
include/linux/pgtable.h:849:		tmp_pte = ptep_get_and_clear_full(mm, addr, ptep, full);
include/linux/pgtable.h-850-		if (pte_dirty(tmp_pte))
--
include/linux/pgtable.h=876=static inline pte_t get_and_clear_ptes(struct mm_struct *mm, unsigned long addr,
--
include/linux/pgtable.h-892- * May be overridden by the architecture; otherwise, implemented as a simple
include/linux/pgtable.h:893: * loop over ptep_get_and_clear_full().
include/linux/pgtable.h-894- *
--
include/linux/pgtable.h=901=static inline void clear_full_ptes(struct mm_struct *mm, unsigned long addr,
--
include/linux/pgtable.h-904-	for (;;) {
include/linux/pgtable.h:905:		ptep_get_and_clear_full(mm, addr, ptep, full);
include/linux/pgtable.h-906-		if (--nr == 0)
--
mm/debug_vm_pgtable.c=114=static void __init pte_advanced_tests(struct pgtable_debug_args *args)
--
mm/debug_vm_pgtable.c-157-	WARN_ON(!(pte_write(pte) && pte_dirty(pte)));
mm/debug_vm_pgtable.c:158:	ptep_get_and_clear_full(args->mm, args->vaddr, args->ptep, 1);
mm/debug_vm_pgtable.c-159-	pte = ptep_get(args->ptep);
--
mm/debug_vm_pgtable.c-169-
mm/debug_vm_pgtable.c:170:	ptep_get_and_clear_full(args->mm, args->vaddr, args->ptep, 1);
mm/debug_vm_pgtable.c-171-}
--
mm/memory.c=1673=static inline int zap_present_ptes(struct mmu_gather *tlb,
--
mm/memory.c-1686-		/* We don't need up-to-date accessed/dirty bits. */
mm/memory.c:1687:		ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm);
mm/memory.c-1688-		arch_check_zapped_pte(vma, ptent);
--
mm/rmap.c=1984=static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
--
mm/rmap.c-2000-	 * When racing against e.g. zap_pte_range() on another cpu,
mm/rmap.c:2001:	 * in between its ptep_get_and_clear_full() and folio_remove_rmap_*(),
mm/rmap.c-2002-	 * try_to_unmap() may return before page_mapped() has become false,
--
mm/rmap.c=2413=static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,
--
mm/rmap.c-2427-	 * When racing against e.g. zap_pte_range() on another cpu,
mm/rmap.c:2428:	 * in between its ptep_get_and_clear_full() and folio_remove_rmap_*(),
mm/rmap.c-2429-	 * try_to_migrate() may return before page_mapped() has become false,
]

140/2 2026/05/25 00:28 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 156430
							output: 41
							thoughts: 249
						

Thoughts:
**Analyzing PTE Clearing in the Kernel**

Okay, let's break this down. My initial concern was about page table entry (PTE) clearing, specifically whether the counter for anonymous pages was being decremented. I see the default implementation of `ptep_get_and_clear_full` in `include/linux/pgtable.h`. It appears to be a straightforward wrapper, but the interesting part is the RISC-V architecture's `ptep_get_and_clear` implementation *does* call `page_table_check_pte_clear`!

This means that `clear_full_ptes`, which I know uses `ptep_get_and_clear_full`, ultimately calls `ptep_get_and_clear`. And that, crucially, calls `page_table_check_pte_clear`. Therefore, the counter *is* being decremented for anonymous pages during this process. That's a relief; it confirms my expectations for this specific call path.

Now, I need to consider `zap_nonpresent_ptes`. I need to ensure this other function is using the same codepath. My mental model of PTE clearing needs to be complete.



141/2 2026/05/25 00:28 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/memory.c IncludeLines:true Name:zap_nonpresent_ptes]

Results:
map[SourceCode:1719:	static inline int zap_nonpresent_ptes(struct mmu_gather *tlb,
1720:			struct vm_area_struct *vma, pte_t *pte, pte_t ptent,
1721:			unsigned int max_nr, unsigned long addr,
1722:			struct zap_details *details, int *rss, bool *any_skipped)
1723:	{
1724:		softleaf_t entry;
1725:		int nr = 1;
1726:	
1727:		*any_skipped = true;
1728:		entry = softleaf_from_pte(ptent);
1729:		if (softleaf_is_device_private(entry) ||
1730:		    softleaf_is_device_exclusive(entry)) {
1731:			struct page *page = softleaf_to_page(entry);
1732:			struct folio *folio = page_folio(page);
1733:	
1734:			if (unlikely(!should_zap_folio(details, folio)))
1735:				return 1;
1736:			/*
1737:			 * Both device private/exclusive mappings should only
1738:			 * work with anonymous page so far, so we don't need to
1739:			 * consider uffd-wp bit when zap. For more information,
1740:			 * see zap_install_uffd_wp_if_needed().
1741:			 */
1742:			WARN_ON_ONCE(!vma_is_anonymous(vma));
1743:			rss[mm_counter(folio)]--;
1744:			folio_remove_rmap_pte(folio, page, vma);
1745:			folio_put(folio);
1746:		} else if (softleaf_is_swap(entry)) {
1747:			/* Genuine swap entries, hence a private anon pages */
1748:			if (!should_zap_cows(details))
1749:				return 1;
1750:	
1751:			nr = swap_pte_batch(pte, max_nr, ptent);
1752:			rss[MM_SWAPENTS] -= nr;
1753:			swap_put_entries_direct(entry, nr);
1754:		} else if (softleaf_is_migration(entry)) {
1755:			struct folio *folio = softleaf_to_folio(entry);
1756:	
1757:			if (!should_zap_folio(details, folio))
1758:				return 1;
1759:			rss[mm_counter(folio)]--;
1760:		} else if (softleaf_is_uffd_wp_marker(entry)) {
1761:			/*
1762:			 * For anon: always drop the marker; for file: only
1763:			 * drop the marker if explicitly requested.
1764:			 */
1765:			if (!vma_is_anonymous(vma) && !zap_drop_markers(details))
1766:				return 1;
1767:		} else if (softleaf_is_guard_marker(entry)) {
1768:			/*
1769:			 * Ordinary zapping should not remove guard PTE
1770:			 * markers. Only do so if we should remove PTE markers
1771:			 * in general.
1772:			 */
1773:			if (!zap_drop_markers(details))
1774:				return 1;
1775:		} else if (softleaf_is_hwpoison(entry) ||
1776:			   softleaf_is_poison_marker(entry)) {
1777:			if (!should_zap_cows(details))
1778:				return 1;
1779:		} else {
1780:			/* We should have covered all the swap entry types */
1781:			pr_alert("unrecognized swap entry 0x%lx\n", entry.val);
1782:			WARN_ON_ONCE(1);
1783:		}
1784:		clear_not_present_full_ptes(vma->vm_mm, addr, pte, nr, tlb->fullmm);
1785:		*any_skipped = zap_install_uffd_wp_if_needed(vma, addr, pte, nr, details, ptent);
1786:	
1787:		return nr;
1788:	}
 SourceFile:mm/memory.c]

142/2 2026/05/25 00:28 llm expert
1m Model:
gemini-3.1-pro-preview

Tokens:
							input: 158181
							output: 52
							thoughts: 13
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:

**Analyzing the `clear_not_present_full_ptes` Function**

Alright, let's break this down. My initial assessment of `clear_not_present_full_ptes` is that it's designed to handle a situation where data relating to "full PTEs" (presumably page table entries) are missing or invalid. The naming convention suggests it’s specifically targeting a cleaning or clearing operation; I'd guess that these PTEs are *not* present in some data structure.

The "not present" aspect is key. Is this indicating the PTEs are missing from the *entire* table? Or just marked as "not present" within the table? Knowing this influences the operational approach.

I'm immediately considering the implications for memory management. Is this related to demand paging, virtual memory, or perhaps a more specialized use case involving memory protection or caching? The function's role likely involves preventing potential access violations or stale data issues. If the memory is unmapped, then the contents of the PTE are not present; the function has to remove the reference.

The use of "full" indicates the PTEs are fully specified. Is this a cleanup before free or before re-use of memory regions? I would need more context.

The function could be triggered by several scenarios, such as:

*   **Page Fault Handling:** Is this part of a routine that responds to page faults, perhaps during page reclamation or swapping? A missing PTE could signify an invalid memory access.
*   **Memory Deallocation:** The function could be invoked during the deallocation of memory regions, ensuring that any stale PTEs are cleared to prevent future errors.
*   **Virtual Memory Management:** Maybe it's part of a more sophisticated virtual memory system, cleaning up after memory protection changes or address space manipulations.

I'm now thinking about how it would interact with the underlying hardware page table structures. What level of the page table is being targeted? Is this a full-page clearing, or are we dealing with entries at a finer granularity? The implementation details would depend on the system architecture (e.g., x86, ARM, etc.) and the memory management unit (MMU) configuration. I will need to know the specific context and API for an accurate evaluation.



143/2 2026/05/25 00:29 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:clear_not_present_full_ptes]

Results:
map[SourceCode: 973:	/**
 974:	 * clear_not_present_full_ptes - Clear multiple not present PTEs which are
 975:	 *				 consecutive in the pgtable.
 976:	 * @mm: Address space the ptes represent.
 977:	 * @addr: Address of the first pte.
 978:	 * @ptep: Page table pointer for the first entry.
 979:	 * @nr: Number of entries to clear.
 980:	 * @full: Whether we are clearing a full mm.
 981:	 *
 982:	 * May be overridden by the architecture; otherwise, implemented as a simple
 983:	 * loop over pte_clear_not_present_full().
 984:	 *
 985:	 * Context: The caller holds the page table lock.  The PTEs are all not present.
 986:	 * The PTEs are all in the same PMD.
 987:	 */
 988:	static inline void clear_not_present_full_ptes(struct mm_struct *mm,
 989:			unsigned long addr, pte_t *ptep, unsigned int nr, int full)
 990:	{
 991:		for (;;) {
 992:			pte_clear_not_present_full(mm, addr, ptep, full);
 993:			if (--nr == 0)
 994:				break;
 995:			ptep++;
 996:			addr += PAGE_SIZE;
 997:		}
 998:	}
 SourceFile:include/linux/pgtable.h]

144/2 2026/05/25 00:29 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 159195
							output: 46
							thoughts: 12
						

Thoughts:
Okay, here's my summary, taking on the persona you've described:

**Understanding `pte_clear_not_present_full`**

Alright, let's break this down. From the name itself, I'm already getting a good idea: we're talking about clearing a Page Table Entry (PTE) and, specifically, when the page isn't present in physical memory. "Full" likely indicates a complete or thorough clearing process. I need to dig into the context. Is this function called in response to a page fault, or some other memory management event? I'd bet it's related to the kernel's memory management routines, probably during page table manipulation.

What is it doing *specifically*? Is it just zeroing out the PTE bits? Or is it doing more? Is there any kind of bookkeeping, like updating a free list, or invalidating the associated TLB entry? I need to check the source code to confirm. We need to make sure the memory is being handled correctly as this is a core piece of page table management. I need to consider potential concurrency issues if this is being called from different contexts.

I bet it has to do with how the virtual address space is mapped to physical memory and how the kernel tracks the state of pages, especially when they are swapped out to disk or are otherwise unavailable. It needs to be fast and safe. Gotta make sure we maintain memory integrity. I'll need to remember to account for potential hardware architecture specifics. I'm imagining there's a good chance it involves atomic operations, especially in multi-threaded environments. I need to make sure I completely understand its effects and potential side effects within the larger memory management system.



145/2 2026/05/25 00:29 tool codesearch-definition-source
0m Args:
map[ContextFile:include/linux/pgtable.h IncludeLines:true Name:pte_clear_not_present_full]

Results:
map[SourceCode: 963:	static inline void pte_clear_not_present_full(struct mm_struct *mm,
 964:						      unsigned long address,
 965:						      pte_t *ptep,
 966:						      int full)
 967:	{
 968:		pte_clear(mm, address, ptep);
 969:	}
 SourceFile:include/linux/pgtable.h]

146/2 2026/05/25 00:30 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 159741
							output: 18
							thoughts: 1520
						

Thoughts:
**Analyzing PTE Counter Discrepancies**

Okay, let's break this down. My initial thought was: `pte_clear_not_present_full` calls `pte_clear`, which is fine because `pte_clear` doesn't involve `page_table_check_pte_clear`. And if the PTE isn't present, `page_table_check_pte_clear` does nothing anyway, since `pte_user_accessible_page` checks `pte_present`. Seems clean so far.

Then I considered the device private and device exclusive entries. These are NOT present, so they wouldn't trigger `page_table_check_pte_clear` directly. But when they're *created*... were they present then? Ah, right. Migration to device private replaces a present PTE. `ptep_get_and_clear` is called during the replacement, decrementing the counter.  So the counter is properly zeroed for the device private page.  No bug there either.

Next, I thought about `folio_pte_batch` and `zap_present_ptes`. `zap_present_folio_ptes` calls `clear_full_ptes` or `get_and_clear_full_ptes`, which in turn call `ptep_get_and_clear_full` for EACH PTE. Each call to `ptep_get_and_clear_full` *does* call `page_table_check_pte_clear`, correctly decrementing the counter for each PTE. This seems correct too.

Now I turned my attention to the core `page_table_check` itself.  I re-examined `__page_table_check_zero`. If `anon_map_count` or `file_map_count` are non-zero after a page is freed, something is wrong. This means `page_table_check_set` was called more times than `page_table_check_clear`.

So, where is `page_table_check_set` called? It's in `set_ptes`. I see that the RISC-V implementation calls `page_table_check_ptes_set` *before* setting the PTEs.  `page_table_check_ptes_set` calls `__page_table_check_pte_clear` on the *old* PTEs. It uses `ptep_get(ptep + i)` to get the old PTE. If the old PTE was present and user-accessible, it decrements the counter. Then, it increments the counter for the *new* page, using the `pte` value. This is the crucial part.

But what if `set_ptes` overwrites an existing PTE?  It decrements the old counter and increments the new counter. But, if the old PTE was *already* cleared by `ptep_get_and_clear` (i.e., it's zero), then `ptep_get` returns zero, and `__page_table_check_pte_clear` does nothing. This sounds correct.

However, the thought I have is what if `set_ptes` is called, `pte_user_accessible_page` is true, so the counter is incremented. But then, *later*, the PTE is cleared using *`pte_clear`* instead of `ptep_get_and_clear`?  I already confirmed that `pte_clear` is only used in `huge_pte_clear` and kernel mappings. I'm going to search `arch/riscv/` for `pte_clear` to be sure there's not a case I'm missing.



147/2 2026/05/25 00:30 tool grepper
0m Args:
map[Expression:pte_clear\(]

Results:
map[Output:
Full output is too long, showing 500 out of 731 lines.
Use more precise expression if possible.

[arch/alpha/include/asm/pgtable.h=211=extern inline int pte_present(pte_t pte)	{ return pte_val(pte) & _PAGE_VALID; }
 arch/alpha/include/asm/pgtable.h:212:extern inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/alpha/include/asm/pgtable.h-213-{
 --
 arch/alpha/include/asm/pgtable.h=279=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/alpha/include/asm/pgtable.h-284-
 arch/alpha/include/asm/pgtable.h:285:	pte_clear(mm, address, ptep);
 arch/alpha/include/asm/pgtable.h-286-	return pte;
 --
 arch/alpha/include/asm/pgtable.h=291=static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/alpha/include/asm/pgtable.h-296-
 arch/alpha/include/asm/pgtable.h:297:	page_table_check_pte_clear(mm, addr, pte);
 arch/alpha/include/asm/pgtable.h-298-	migrate_flush_tlb_page(vma, addr);
 --
 arch/arc/include/asm/pgtable-levels.h-173-#define pte_present(x)		(pte_val(x) & _PAGE_PRESENT)
 arch/arc/include/asm/pgtable-levels.h:174:#define pte_clear(mm,addr,ptep)	set_pte_at(mm, addr, ptep, __pte(0))
 arch/arc/include/asm/pgtable-levels.h-175-#define pte_page(pte)		pfn_to_page(pte_pfn(pte))
 --
 arch/arm/include/asm/pgtable.h=151=static inline pte_t *pmd_page_vaddr(pmd_t pmd)
 --
 arch/arm/include/asm/pgtable.h-162-
 arch/arm/include/asm/pgtable.h:163:#define pte_clear(mm,addr,ptep)	set_pte_ext(ptep, __pte(0), 0)
 arch/arm/include/asm/pgtable.h-164-
 --
 arch/arm/mm/mmu.c=390=void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
 --
 arch/arm/mm/mmu.c-407-	else
 arch/arm/mm/mmu.c:408:		pte_clear(NULL, vaddr, pte);
 arch/arm/mm/mmu.c-409-	local_flush_tlb_kernel_range(vaddr, vaddr + PAGE_SIZE);
 --
 arch/arm64/include/asm/hugetlb.h=51=extern pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/arm64/include/asm/hugetlb.h-53-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/arm64/include/asm/hugetlb.h:54:extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/arm64/include/asm/hugetlb.h-55-			   pte_t *ptep, unsigned long sz);
 --
 arch/arm64/include/asm/pgtable.h=1289=static inline bool pud_user_accessible_page(struct mm_struct *mm, unsigned long addr, pud_t pud)
 --
 arch/arm64/include/asm/pgtable.h-1298-
 arch/arm64/include/asm/pgtable.h:1299:static inline void __pte_clear(struct mm_struct *mm,
 arch/arm64/include/asm/pgtable.h-1300-			       unsigned long addr, pte_t *ptep)
 --
 arch/arm64/include/asm/pgtable.h=1352=static inline pte_t __ptep_get_and_clear_anysz(struct mm_struct *mm,
 --
 arch/arm64/include/asm/pgtable.h-1360-	case PAGE_SIZE:
 arch/arm64/include/asm/pgtable.h:1361:		page_table_check_pte_clear(mm, address, pte);
 arch/arm64/include/asm/pgtable.h-1362-		break;
 --
 arch/arm64/include/asm/pgtable.h=1775=static __always_inline void set_ptes(struct mm_struct *mm, unsigned long addr,
 --
 arch/arm64/include/asm/pgtable.h-1788-
 arch/arm64/include/asm/pgtable.h:1789:static inline void pte_clear(struct mm_struct *mm,
 arch/arm64/include/asm/pgtable.h-1790-				unsigned long addr, pte_t *ptep)
 --
 arch/arm64/include/asm/pgtable.h-1792-	contpte_try_unfold(mm, addr, ptep, __ptep_get(ptep));
 arch/arm64/include/asm/pgtable.h:1793:	__pte_clear(mm, addr, ptep);
 arch/arm64/include/asm/pgtable.h-1794-}
 --
 arch/arm64/mm/fixmap.c=119=void __set_fixmap(enum fixed_addresses idx,
 --
 arch/arm64/mm/fixmap.c-131-	} else {
 arch/arm64/mm/fixmap.c:132:		__pte_clear(&init_mm, addr, ptep);
 arch/arm64/mm/fixmap.c-133-		flush_tlb_kernel_range(addr, addr+PAGE_SIZE);
 --
 arch/arm64/mm/hugetlbpage.c=344=pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
 --
 arch/arm64/mm/hugetlbpage.c-368-
 arch/arm64/mm/hugetlbpage.c:369:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/arm64/mm/hugetlbpage.c-370-		    pte_t *ptep, unsigned long sz)
 --
 arch/arm64/mm/hugetlbpage.c-377-	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
 arch/arm64/mm/hugetlbpage.c:378:		__pte_clear(mm, addr, ptep);
 arch/arm64/mm/hugetlbpage.c-379-}
 --
 arch/arm64/mm/mmu.c=1466=static void unmap_hotplug_pte_range(pmd_t *pmdp, unsigned long addr,
 --
 arch/arm64/mm/mmu.c-1478-		WARN_ON(!pte_present(pte));
 arch/arm64/mm/mmu.c:1479:		__pte_clear(&init_mm, addr, ptep);
 arch/arm64/mm/mmu.c-1480-		if (free_mapped) {
 --
 arch/csky/include/asm/pgtable.h-33-#define pmd_page(pmd)	(pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
 arch/csky/include/asm/pgtable.h:34:#define pte_clear(mm, addr, ptep)	set_pte((ptep), \
 arch/csky/include/asm/pgtable.h-35-	(((unsigned int) addr >= PAGE_OFFSET) ? __pte(_PAGE_GLOBAL) : __pte(0)))
 --
 arch/hexagon/include/asm/pgtable.h=165=static inline void pmd_clear(pmd_t *pmd_entry_ptr)
 --
 arch/hexagon/include/asm/pgtable.h-172- */
 arch/hexagon/include/asm/pgtable.h:173:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/hexagon/include/asm/pgtable.h-174-				pte_t *ptep)
 --
 arch/loongarch/include/asm/hugetlb.h=11=uint64_t pmd_to_entrylo(unsigned long pmd_val);
 --
 arch/loongarch/include/asm/hugetlb.h-13-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/loongarch/include/asm/hugetlb.h:14:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/loongarch/include/asm/hugetlb.h-15-				  pte_t *ptep, unsigned long sz)
 --
 arch/loongarch/include/asm/pgtable.h=364=static inline void set_pte(pte_t *ptep, pte_t pteval)
 --
 arch/loongarch/include/asm/pgtable.h-373-
 arch/loongarch/include/asm/pgtable.h:374:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/loongarch/include/asm/pgtable.h-375-{
 --
 arch/loongarch/mm/init.c=210=void __init __set_fixmap(enum fixed_addresses idx,
 --
 arch/loongarch/mm/init.c-226-	else {
 arch/loongarch/mm/init.c:227:		pte_clear(&init_mm, addr, ptep);
 arch/loongarch/mm/init.c-228-		flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
 --
 arch/m68k/include/asm/mcf_pgtable.h=120=static inline int pte_present(pte_t pte)
 --
 arch/m68k/include/asm/mcf_pgtable.h-124-
 arch/m68k/include/asm/mcf_pgtable.h:125:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/m68k/include/asm/mcf_pgtable.h-126-	pte_t *ptep)
 --
 arch/m68k/include/asm/motorola_pgtable.h=95=static inline void pud_set(pud_t *pudp, pmd_t *pmdp)
 --
 arch/m68k/include/asm/motorola_pgtable.h-106-#define pte_present(pte)	(pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROTNONE))
 arch/m68k/include/asm/motorola_pgtable.h:107:#define pte_clear(mm,addr,ptep)		({ pte_val(*(ptep)) = 0; })
 arch/m68k/include/asm/motorola_pgtable.h-108-
 --
 arch/microblaze/include/asm/pgtable.h=29=extern pte_t *va_to_pte(unsigned long address);
 --
 arch/microblaze/include/asm/pgtable.h-211-#define pte_present(pte)	(pte_val(pte) & _PAGE_PRESENT)
 arch/microblaze/include/asm/pgtable.h:212:#define pte_clear(mm, addr, ptep) \
 arch/microblaze/include/asm/pgtable.h-213-	do { set_pte_at((mm), (addr), (ptep), __pte(0)); } while (0)
 --
 arch/mips/include/asm/pgtable.h=119=static inline void set_pte(pte_t *ptep, pte_t pte)
 --
 arch/mips/include/asm/pgtable.h-142-
 arch/mips/include/asm/pgtable.h:143:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/mips/include/asm/pgtable.h-144-{
 --
 arch/mips/include/asm/pgtable.h=171=static inline void set_pte(pte_t *ptep, pte_t pteval)
 --
 arch/mips/include/asm/pgtable.h-189-
 arch/mips/include/asm/pgtable.h:190:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/mips/include/asm/pgtable.h-191-{
 --
 arch/nios2/include/asm/pgtable.h=195=static inline int pmd_none(pmd_t pmd)
 --
 arch/nios2/include/asm/pgtable.h-202-
 arch/nios2/include/asm/pgtable.h:203:static inline void pte_clear(struct mm_struct *mm,
 arch/nios2/include/asm/pgtable.h-204-				unsigned long addr, pte_t *ptep)
 --
 arch/openrisc/include/asm/pgtable.h=42=extern void paging_init(void);
 --
 arch/openrisc/include/asm/pgtable.h-183-#define pte_present(x)	(pte_val(x) & _PAGE_PRESENT)
 arch/openrisc/include/asm/pgtable.h:184:#define pte_clear(mm, addr, xp)	do { pte_val(*(xp)) = 0; } while (0)
 arch/openrisc/include/asm/pgtable.h-185-
 --
 arch/openrisc/mm/init.c=196=static int __init map_page(unsigned long va, phys_addr_t pa, pgprot_t prot)
 --
 arch/openrisc/mm/init.c-213-	else
 arch/openrisc/mm/init.c:214:		pte_clear(&init_mm, va, pte);
 arch/openrisc/mm/init.c-215-
 --
 arch/parisc/include/asm/pgtable.h=263=extern pte_t pg0[];
 --
 arch/parisc/include/asm/pgtable.h-267-#define pte_user(x)	(pte_val(x) & _PAGE_USER)
 arch/parisc/include/asm/pgtable.h:268:#define pte_clear(mm, addr, xp) set_pte_at((mm), (addr), (xp), __pte(0))
 arch/parisc/include/asm/pgtable.h-269-
 --
 arch/parisc/kernel/pci-dma.c=153=static inline void unmap_uncached_pte(pmd_t * pmd, unsigned long vaddr,
 --
 arch/parisc/kernel/pci-dma.c-175-
 arch/parisc/kernel/pci-dma.c:176:		pte_clear(&init_mm, vaddr, pte);
 arch/parisc/kernel/pci-dma.c-177-		purge_tlb_start(flags);
 --
 arch/parisc/mm/fixmap.c=27=void notrace clear_fixmap(enum fixed_addresses idx)
 --
 arch/parisc/mm/fixmap.c-34-
 arch/parisc/mm/fixmap.c:35:	pte_clear(&init_mm, vaddr, pte);
 arch/parisc/mm/fixmap.c-36-
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h=138=void unmap_kernel_page(unsigned long va);
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h-212-
 arch/powerpc/include/asm/book3s/32/pgtable.h:213:#define pte_clear(mm, addr, ptep) \
 arch/powerpc/include/asm/book3s/32/pgtable.h-214-	do { pte_update(mm, addr, ptep, ~_PAGE_HASHPTE, 0, 0); } while (0)
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h=312=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h-316-
 arch/powerpc/include/asm/book3s/32/pgtable.h:317:	page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/book3s/32/pgtable.h-318-
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h=418=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-422-
 arch/powerpc/include/asm/book3s/64/pgtable.h:423:	page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/book3s/64/pgtable.h-424-
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h=429=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-440-		old_pte = radix__ptep_get_and_clear_full(mm, addr, ptep, full);
 arch/powerpc/include/asm/book3s/64/pgtable.h:441:		page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/book3s/64/pgtable.h-442-
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-448-
 arch/powerpc/include/asm/book3s/64/pgtable.h:449:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/powerpc/include/asm/book3s/64/pgtable.h-450-			     pte_t * ptep)
 --
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h=23=static inline pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 --
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-30-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h:31:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-32-				  pte_t *ptep, unsigned long sz)
 --
 arch/powerpc/include/asm/nohash/pgtable.h=124=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/powerpc/include/asm/nohash/pgtable.h-128-
 arch/powerpc/include/asm/nohash/pgtable.h:129:	page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/nohash/pgtable.h-130-
 --
 arch/powerpc/include/asm/nohash/pgtable.h-134-
 arch/powerpc/include/asm/nohash/pgtable.h:135:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/powerpc/include/asm/nohash/pgtable.h-136-{
 --
 arch/powerpc/lib/code-patching.c=246=static void unmap_patch_area(unsigned long addr)
 --
 arch/powerpc/lib/code-patching.c-276-	 */
 arch/powerpc/lib/code-patching.c:277:	pte_clear(&init_mm, addr, ptep);
 arch/powerpc/lib/code-patching.c-278-	flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
 --
 arch/powerpc/lib/code-patching.c=281=static int __do_patch_mem_mm(void *addr, unsigned long val, bool is_dword)
 --
 arch/powerpc/lib/code-patching.c-314-
 arch/powerpc/lib/code-patching.c:315:	pte_clear(patching_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-316-	/*
 --
 arch/powerpc/lib/code-patching.c=327=static int __do_patch_mem(void *addr, unsigned long val, bool is_dword)
 --
 arch/powerpc/lib/code-patching.c-345-
 arch/powerpc/lib/code-patching.c:346:	pte_clear(&init_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-347-	flush_tlb_kernel_range(text_poke_addr, text_poke_addr + PAGE_SIZE);
 --
 arch/powerpc/lib/code-patching.c=468=static int __do_patch_instructions_mm(u32 *addr, u32 *code, size_t len, bool repeat_instr)
 --
 arch/powerpc/lib/code-patching.c-502-
 arch/powerpc/lib/code-patching.c:503:	pte_clear(patching_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-504-	/*
 --
 arch/powerpc/lib/code-patching.c=519=static int __do_patch_instructions(u32 *addr, u32 *code, size_t len, bool repeat_instr)
 --
 arch/powerpc/lib/code-patching.c-537-
 arch/powerpc/lib/code-patching.c:538:	pte_clear(&init_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-539-	flush_tlb_kernel_range(text_poke_addr, text_poke_addr + PAGE_SIZE);
 --
 arch/powerpc/mm/book3s64/hash_native.c=660=static void hpte_decode(struct hash_pte *hpte, unsigned long slot,
 --
 arch/powerpc/mm/book3s64/hash_native.c-735- */
 arch/powerpc/mm/book3s64/hash_native.c:736:static notrace void native_hpte_clear(void)
 arch/powerpc/mm/book3s64/hash_native.c-737-{
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=787=static void __meminit remove_pte_table(pte_t *pte_start, unsigned long addr,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-805-				free_vmemmap_pages(pte_page(*pte), altmap, 0);
 arch/powerpc/mm/book3s64/radix_pgtable.c:806:			pte_clear(&init_mm, addr, pte);
 arch/powerpc/mm/book3s64/radix_pgtable.c-807-			pages++;
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-811-			free_vmemmap_pages(pte_page(*pte), altmap, 0);
 arch/powerpc/mm/book3s64/radix_pgtable.c:812:			pte_clear(&init_mm, addr, pte);
 arch/powerpc/mm/book3s64/radix_pgtable.c-813-		}
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=820=static void __meminit remove_pmd_table(pmd_t *pmd_start, unsigned long addr,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-839-					free_vmemmap_pages(pmd_page(*pmd), altmap, get_order(PMD_SIZE));
 arch/powerpc/mm/book3s64/radix_pgtable.c:840:				pte_clear(&init_mm, addr, (pte_t *)pmd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-841-				pages++;
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-845-				free_vmemmap_pages(pmd_page(*pmd), altmap, get_order(PMD_SIZE));
 arch/powerpc/mm/book3s64/radix_pgtable.c:846:				pte_clear(&init_mm, addr, (pte_t *)pmd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-847-			}
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=860=static void __meminit remove_pud_table(pud_t *pud_start, unsigned long addr,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-880-			}
 arch/powerpc/mm/book3s64/radix_pgtable.c:881:			pte_clear(&init_mm, addr, (pte_t *)pud);
 arch/powerpc/mm/book3s64/radix_pgtable.c-882-			pages++;
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=895=remove_pagetable(unsigned long start, unsigned long end, bool direct,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-919-
 arch/powerpc/mm/book3s64/radix_pgtable.c:920:			pte_clear(&init_mm, addr, (pte_t *)pgd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-921-			continue;
 --
 arch/powerpc/mm/pgtable.c=239=void unmap_kernel_page(unsigned long va)
 --
 arch/powerpc/mm/pgtable.c-243-
 arch/powerpc/mm/pgtable.c:244:	pte_clear(&init_mm, va, ptep);
 arch/powerpc/mm/pgtable.c-245-	flush_tlb_kernel_range(va, va + PAGE_SIZE);
 --
 arch/powerpc/platforms/ps3/htab.c=152=static void ps3_hpte_invalidate(unsigned long slot, unsigned long vpn,
 --
 arch/powerpc/platforms/ps3/htab.c-171-/* Called during kexec sequence with MMU off */
 arch/powerpc/platforms/ps3/htab.c:172:static notrace void ps3_hpte_clear(void)
 arch/powerpc/platforms/ps3/htab.c-173-{
 --
 arch/riscv/include/asm/hugetlb.h=15=bool arch_hugetlb_migration_supported(struct hstate *h);
 --
 arch/riscv/include/asm/hugetlb.h-20-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/riscv/include/asm/hugetlb.h:21:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/riscv/include/asm/hugetlb.h-22-		    pte_t *ptep, unsigned long sz);
 --
 arch/riscv/include/asm/pgtable.h=622=static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
 --
 arch/riscv/include/asm/pgtable.h-636-
 arch/riscv/include/asm/pgtable.h:637:static inline void pte_clear(struct mm_struct *mm,
 arch/riscv/include/asm/pgtable.h-638-	unsigned long addr, pte_t *ptep)
 --
 arch/riscv/include/asm/pgtable.h=651=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/riscv/include/asm/pgtable.h-661-
 arch/riscv/include/asm/pgtable.h:662:	page_table_check_pte_clear(mm, address, pte);
 arch/riscv/include/asm/pgtable.h-663-
 --
 arch/riscv/mm/hugetlbpage.c=346=pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/riscv/mm/hugetlbpage.c-360-
 arch/riscv/mm/hugetlbpage.c:361:void huge_pte_clear(struct mm_struct *mm,
 arch/riscv/mm/hugetlbpage.c-362-		    unsigned long addr,
 --
 arch/riscv/mm/hugetlbpage.c-370-	if (!pte_napot(pte)) {
 arch/riscv/mm/hugetlbpage.c:371:		pte_clear(mm, addr, ptep);
 arch/riscv/mm/hugetlbpage.c-372-		return;
 --
 arch/riscv/mm/hugetlbpage.c-377-	for (i = 0; i < pte_num; i++, addr += pgsize, ptep++)
 arch/riscv/mm/hugetlbpage.c:378:		pte_clear(mm, addr, ptep);
 arch/riscv/mm/hugetlbpage.c-379-}
 --
 arch/riscv/mm/init.c=369=void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
 --
 arch/riscv/mm/init.c-380-	else
 arch/riscv/mm/init.c:381:		pte_clear(&init_mm, addr, ptep);
 arch/riscv/mm/init.c-382-	local_flush_tlb_page(addr);
 --
 arch/riscv/mm/init.c=1574=static void __meminit remove_pte_mapping(pte_t *pte_base, unsigned long addr, unsigned long end,
 --
 arch/riscv/mm/init.c-1589-
 arch/riscv/mm/init.c:1590:		pte_clear(&init_mm, addr, ptep);
 arch/riscv/mm/init.c-1591-		if (is_vmemmap)
 --
 arch/s390/include/asm/hugetlb.h=33=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/s390/include/asm/hugetlb.h-40-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/s390/include/asm/hugetlb.h:41:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/s390/include/asm/hugetlb.h-42-				  pte_t *ptep, unsigned long sz)
 --
 arch/s390/include/asm/pgtable.h=1004=static inline void pmd_clear(pmd_t *pmdp)
 --
 arch/s390/include/asm/pgtable.h-1008-
 arch/s390/include/asm/pgtable.h:1009:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/s390/include/asm/pgtable.h-1010-{
 --
 arch/s390/include/asm/pgtable.h=1186=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/s390/include/asm/pgtable.h-1194-		WARN_ON_ONCE(uv_convert_from_secure_pte(res));
 arch/s390/include/asm/pgtable.h:1195:	page_table_check_pte_clear(mm, addr, res);
 arch/s390/include/asm/pgtable.h-1196-	return res;
 --
 arch/s390/include/asm/pgtable.h=1205=static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/s390/include/asm/pgtable.h-1213-		WARN_ON_ONCE(uv_convert_from_secure_pte(res));
 arch/s390/include/asm/pgtable.h:1214:	page_table_check_pte_clear(vma->vm_mm, addr, res);
 arch/s390/include/asm/pgtable.h-1215-	return res;
 --
 arch/s390/include/asm/pgtable.h=1226=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
 --
 arch/s390/include/asm/pgtable.h-1238-
 arch/s390/include/asm/pgtable.h:1239:	page_table_check_pte_clear(mm, addr, res);
 arch/s390/include/asm/pgtable.h-1240-
 --
 arch/s390/mm/gmap_helpers.c=46=void gmap_helper_zap_one_page(struct mm_struct *mm, unsigned long vmaddr)
 --
 arch/s390/mm/gmap_helpers.c-64-		ptep_zap_softleaf_entry(mm, softleaf_from_pte(*ptep));
 arch/s390/mm/gmap_helpers.c:65:		pte_clear(mm, vmaddr, ptep);
 arch/s390/mm/gmap_helpers.c-66-	}
 --
 arch/s390/mm/vmem.c=168=static int __ref modify_pte_table(pmd_t *pmd, unsigned long addr,
 --
 arch/s390/mm/vmem.c-183-				vmem_free_pages((unsigned long)pfn_to_virt(pte_pfn(*pte)), get_order(PAGE_SIZE), altmap);
 arch/s390/mm/vmem.c:184:			pte_clear(&init_mm, addr, pte);
 arch/s390/mm/vmem.c-185-		} else if (pte_none(*pte)) {
 --
 arch/s390/mm/vmem.c=654=void vmem_unmap_4k_page(unsigned long addr)
 --
 arch/s390/mm/vmem.c-660-	__ptep_ipte(addr, ptep, 0, 0, IPTE_GLOBAL);
 arch/s390/mm/vmem.c:661:	pte_clear(&init_mm, addr, ptep);
 arch/s390/mm/vmem.c-662-	mutex_unlock(&vmem_mutex);
 --
 arch/sh/include/asm/pgtable_32.h=300=static inline void set_pte(pte_t *ptep, pte_t pte)
 --
 arch/sh/include/asm/pgtable_32.h-324-
 arch/sh/include/asm/pgtable_32.h:325:#define pte_clear(mm, addr, ptep) set_pte(ptep, __pte(0))
 arch/sh/include/asm/pgtable_32.h-326-
 --
 arch/sh/mm/kmap.c=51=void kunmap_coherent(void *kvaddr)
 --
 arch/sh/mm/kmap.c-59-
 arch/sh/mm/kmap.c:60:		pte_clear(&init_mm, vaddr, kmap_coherent_pte - idx);
 arch/sh/mm/kmap.c-61-		local_flush_tlb_one(get_asid(), vaddr);
 --
 arch/sparc/include/asm/pgtable_32.h=145=static inline int pte_none(pte_t pte)
 --
 arch/sparc/include/asm/pgtable_32.h-149-
 arch/sparc/include/asm/pgtable_32.h:150:static inline void __pte_clear(pte_t *ptep)
 arch/sparc/include/asm/pgtable_32.h-151-{
 --
 arch/sparc/include/asm/pgtable_32.h-154-
 arch/sparc/include/asm/pgtable_32.h:155:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/sparc/include/asm/pgtable_32.h-156-{
 arch/sparc/include/asm/pgtable_32.h:157:	__pte_clear(ptep);
 arch/sparc/include/asm/pgtable_32.h-158-}
 --
 arch/sparc/include/asm/pgtable_64.h=931=static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
 --
 arch/sparc/include/asm/pgtable_64.h-944-
 arch/sparc/include/asm/pgtable_64.h:945:#define pte_clear(mm,addr,ptep)		\
 arch/sparc/include/asm/pgtable_64.h-946-	set_pte_at((mm), (addr), (ptep), __pte(0UL))
 --
 arch/sparc/mm/srmmu.c=526=static inline void srmmu_unmapioaddr(unsigned long virt_addr)
 --
 arch/sparc/mm/srmmu.c-541-	/* No need to flush uncacheable page. */
 arch/sparc/mm/srmmu.c:542:	__pte_clear(ptep);
 arch/sparc/mm/srmmu.c-543-}
 --
 arch/um/include/asm/pgtable.h=35=extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
 --
 arch/um/include/asm/pgtable.h-73-
 arch/um/include/asm/pgtable.h:74:#define pte_clear(mm, addr, xp) pte_set_val(*(xp), (phys_t) 0, __pgprot(_PAGE_NEEDSYNC))
 arch/um/include/asm/pgtable.h-75-
 --
 arch/x86/include/asm/paravirt.h=457=static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
 --
 arch/x86/include/asm/paravirt.h-461-
 arch/x86/include/asm/paravirt.h:462:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/x86/include/asm/paravirt.h-463-			     pte_t *ptep)
 --
 arch/x86/include/asm/pgtable-2level.h=39=static inline void native_pud_clear(pud_t *pudp)
 --
 arch/x86/include/asm/pgtable-2level.h-42-
 arch/x86/include/asm/pgtable-2level.h:43:static inline void native_pte_clear(struct mm_struct *mm,
 arch/x86/include/asm/pgtable-2level.h-44-				    unsigned long addr, pte_t *xp)
 --
 arch/x86/include/asm/pgtable-3level.h=53=static inline void native_set_pud(pud_t *pudp, pud_t pud)
 --
 arch/x86/include/asm/pgtable-3level.h-65- */
 arch/x86/include/asm/pgtable-3level.h:66:static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/x86/include/asm/pgtable-3level.h-67-				    pte_t *ptep)
 --
 arch/x86/include/asm/pgtable.h=55=extern pmdval_t early_pmd_flags;
 --
 arch/x86/include/asm/pgtable.h-87-
 arch/x86/include/asm/pgtable.h:88:#define pte_clear(mm, addr, ptep)	native_pte_clear(mm, addr, ptep)
 arch/x86/include/asm/pgtable.h-89-#define pmd_clear(pmd)			native_pmd_clear(pmd)
 --
 arch/x86/include/asm/pgtable.h=1181=static inline pte_t native_local_ptep_get_and_clear(pte_t *ptep)
 --
 arch/x86/include/asm/pgtable.h-1185-	/* Pure native function needs no input for mm, addr */
 arch/x86/include/asm/pgtable.h:1186:	native_pte_clear(NULL, 0, ptep);
 arch/x86/include/asm/pgtable.h-1187-	return res;
 --
 arch/x86/include/asm/pgtable.h=1243=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/x86/include/asm/pgtable.h-1246-	pte_t pte = native_ptep_get_and_clear(ptep);
 arch/x86/include/asm/pgtable.h:1247:	page_table_check_pte_clear(mm, addr, pte);
 arch/x86/include/asm/pgtable.h-1248-	return pte;
 --
 arch/x86/include/asm/pgtable.h=1252=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
 --
 arch/x86/include/asm/pgtable.h-1262-		pte = native_local_ptep_get_and_clear(ptep);
 arch/x86/include/asm/pgtable.h:1263:		page_table_check_pte_clear(mm, addr, pte);
 arch/x86/include/asm/pgtable.h-1264-	} else {
 --
 arch/x86/include/asm/pgtable_32.h=42=do {						\
 arch/x86/include/asm/pgtable_32.h:43:	pte_clear(&init_mm, (vaddr), (ptep));	\
 arch/x86/include/asm/pgtable_32.h-44-	flush_tlb_one_kernel((vaddr));		\
 --
 arch/x86/include/asm/pgtable_64.h=61=static inline void native_set_pte(pte_t *ptep, pte_t pte)
 --
 arch/x86/include/asm/pgtable_64.h-65-
 arch/x86/include/asm/pgtable_64.h:66:static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/x86/include/asm/pgtable_64.h-67-				    pte_t *ptep)
 --
 arch/x86/include/asm/pgtable_64.h=87=static inline pte_t native_ptep_get_and_clear(pte_t *xp)
 --
 arch/x86/include/asm/pgtable_64.h-94-	pte_t ret = *xp;
 arch/x86/include/asm/pgtable_64.h:95:	native_pte_clear(NULL, 0, xp);
 arch/x86/include/asm/pgtable_64.h-96-	return ret;
 --
 arch/x86/kernel/alternative.c=2546=static void *__text_poke(text_poke_f func, void *addr, const void *src, size_t len)
 --
 arch/x86/kernel/alternative.c-2619-
 arch/x86/kernel/alternative.c:2620:	pte_clear(text_poke_mm, text_poke_mm_addr, ptep);
 arch/x86/kernel/alternative.c-2621-	if (cross_page_boundary)
 arch/x86/kernel/alternative.c:2622:		pte_clear(text_poke_mm, text_poke_mm_addr + PAGE_SIZE, ptep + 1);
 arch/x86/kernel/alternative.c-2623-
 --
]
]

148/2 2026/05/25 00:30 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 174065
							output: 51
							thoughts: 1888
						

Thoughts:
**Analyzing the Memory Management Bug**

Okay, so I'm diving back into this bug report. The core issue seems to be a mismatch between what's considered a "freed" page and its reference counts, specifically the `anon_map_count` or `file_map_count`. The error trace points to `exit_mmap`, which is where VMAs get unmapped and page tables are freed. The key seems to be pages that are unmapped, but the `page_table_check_pte_clear` hasn't been called, or if it has, the counter isn't being decremented correctly. Alternatively, the counter could have been incremented twice.

My initial thought was `pte_clear`, but I've already confirmed it's not used elsewhere. Time to review the code. The stack trace leads me to `set_pte_at` and `set_ptes`. `set_pte_at` calls `page_table_check_pte_set`, but `set_pte_at` and `page_table_check_ptes_set` will clear the old PTE before setting the new one. So both `page_table_check_pte_set` and `page_table_check_ptes_set` will clear the PTE.

I then went through the `ptep_get_and_clear` function. This should correctly decrement the counter, but I need to ensure it's doing so under all conditions. It calls `page_table_check_pte_clear`, and that's where things get interesting. `page_table_check_pte_clear` checks if the page is user-accessible via `pte_user_accessible_page`. This is where I think the bug might be.

In RISC-V, `pte_user_accessible_page` relies on `pte_user(pte)`. Then I checked when a page is NOT user-accessible. `PAGE_NONE` is not user-accessible. So if `PAGE_NONE` (or a similar no-access page) is involved, it will not increment or decrement the counter. Pages with `PAGE_NONE` will completely bypass `page_table_check`.

This is expected, as `PAGE_NONE` pages are not user-accessible. But what if a page starts as user-accessible (counter incremented) and then becomes `PAGE_NONE` (counter decremented, but counter not incremented).

My hypothesis is that a page initially mapped as `PAGE_READ` (user-accessible) gets its access rights modified to `PAGE_NONE` via `mprotect`. The old PTE (with `_PAGE_USER`) is cleared, decrementing the counter. The new PTE (`PAGE_NONE`) does NOT increment the counter, because `pte_user_accessible_page` returns FALSE. Later, when the page is actually unmapped, the `ptep_get_and_clear` finds the `PAGE_NONE`, and the counter should NOT be decremented.

I need to confirm the definitions of `_PAGE_PROT_NONE`, `_PAGE_BASE`, and `PAGE_NONE` within the RISC-V architecture to make sure I'm not missing anything. Specifically, I'm checking the definition of `_PAGE_USER` in RISC-V. If `PAGE_NONE` contains `_PAGE_USER`, then the above reasoning is not correct. I'm going to look at `arch/riscv/include/asm/pgtable-bits.h` to make sure `PAGE_NONE` is indeed not user accessible.



149/2 2026/05/25 00:30 tool codesearch-definition-source
0m Error:
requested entity does not exist

Args:
map[ContextFile:arch/riscv/include/asm/pgtable-bits.h IncludeLines:true Name:_PAGE_PROT_NONE]

Results:
map[SourceCode: SourceFile:]

150/2 2026/05/25 00:30 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 176791
							output: 30
							thoughts: 21
						

Thoughts:
Here's my take on the thought process, as if it were my own:

**Diving into the RISC-V Page Table Bits**

Alright, time to dig into the nitty-gritty. I'm going to take a look at `arch/riscv/include/asm/pgtable-bits.h`. This is where the magic happens, the low-level details of how the RISC-V architecture defines its page table entries (PTEs) and, consequently, memory management. I expect to find the bit definitions for things like the valid bit, the dirty bit, the accessed bit, and, of course, the physical page number (PPN) field. I'm also anticipating details on the different privilege levels and how they're encoded within the PTEs. This file should be the authoritative source for understanding how memory is translated from virtual addresses to physical addresses on RISC-V, at least from the kernel's perspective. I'll be looking specifically for any architectural quirks or optimizations relevant to RISC-V's MMU design. This is a critical building block for understanding the core memory management mechanisms.



151/2 2026/05/25 00:30 tool read-file
0m Args:
map[File:arch/riscv/include/asm/pgtable-bits.h]

Results:
map[Contents:/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (C) 2012 Regents of the University of California
 */

#ifndef _ASM_RISCV_PGTABLE_BITS_H
#define _ASM_RISCV_PGTABLE_BITS_H

#define _PAGE_ACCESSED_OFFSET 6

#define _PAGE_PRESENT   (1 << 0)
#define _PAGE_READ      (1 << 1)    /* Readable */
#define _PAGE_WRITE     (1 << 2)    /* Writable */
#define _PAGE_EXEC      (1 << 3)    /* Executable */
#define _PAGE_USER      (1 << 4)    /* User */
#define _PAGE_GLOBAL    (1 << 5)    /* Global */
#define _PAGE_ACCESSED  (1 << 6)    /* Set by hardware on any access */
#define _PAGE_DIRTY     (1 << 7)    /* Set by hardware on any write */
#define _PAGE_SOFT      (3 << 8)    /* Reserved for software */

#define _PAGE_SPECIAL   (1 << 8)    /* RSW: 0x1 */

#ifdef CONFIG_MEM_SOFT_DIRTY

/* ext_svrsw60t59b: bit 59 for soft-dirty tracking */
#define _PAGE_SOFT_DIRTY						\
	((riscv_has_extension_unlikely(RISCV_ISA_EXT_SVRSW60T59B)) ?	\
	 (1UL << 59) : 0)
/*
 * Bit 3 is always zero for swap entry computation, so we
 * can borrow it for swap page soft-dirty tracking.
 */
#define _PAGE_SWP_SOFT_DIRTY						\
	((riscv_has_extension_unlikely(RISCV_ISA_EXT_SVRSW60T59B)) ?	\
	 _PAGE_EXEC : 0)
#else
#define _PAGE_SOFT_DIRTY	0
#define _PAGE_SWP_SOFT_DIRTY	0
#endif /* CONFIG_MEM_SOFT_DIRTY */

#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP

/* ext_svrsw60t59b: Bit(60) for uffd-wp tracking */
#define _PAGE_UFFD_WP							\
	((riscv_has_extension_unlikely(RISCV_ISA_EXT_SVRSW60T59B)) ?	\
	 (1UL << 60) : 0)
/*
 * Bit 4 is not involved into swap entry computation, so we
 * can borrow it for swap page uffd-wp tracking.
 */
#define _PAGE_SWP_UFFD_WP						\
	((riscv_has_extension_unlikely(RISCV_ISA_EXT_SVRSW60T59B)) ?	\
	 _PAGE_USER : 0)
#else
#define _PAGE_UFFD_WP		0
#define _PAGE_SWP_UFFD_WP	0
#endif

#define _PAGE_TABLE     _PAGE_PRESENT

/*
 * _PAGE_PROT_NONE is set on not-present pages (and ignored by the hardware) to
 * distinguish them from swapped out pages
 */
#define _PAGE_PROT_NONE _PAGE_GLOBAL

/* Used for swap PTEs only. */
#define _PAGE_SWP_EXCLUSIVE _PAGE_ACCESSED

#define _PAGE_PFN_SHIFT 10

/*
 * when all of R/W/X are zero, the PTE is a pointer to the next level
 * of the page table; otherwise, it is a leaf PTE.
 */
#define _PAGE_LEAF (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC)

#endif /* _ASM_RISCV_PGTABLE_BITS_H */
]

152/2 2026/05/25 00:30 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 178004
							output: 45
							thoughts: 997
						

Thoughts:
**Analyzing Page Table Entries in RISC-V: A Deep Dive into `PAGE_NONE` and Accessibility**

Okay, let's break this down. My initial thought was that `_PAGE_PROT_NONE` aligns with `_PAGE_GLOBAL`, which makes sense. Then, I see `PAGE_NONE` is defined as `__pgprot(_PAGE_PROT_NONE | _PAGE_READ)`. A bit of a surprise, I was initially thrown by the fact that `_PAGE_PRESENT` isn't set in `PAGE_NONE`. This means `pte_present(pte)` would return FALSE, right? Nope! A quick check of the RISC-V implementation of `pte_present` reveals:

```c
static inline int pte_present(pte_t pte)
{
	return (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
}
```

Ah, it uses OR!  So, `pte_present` returns TRUE if *either* `_PAGE_PRESENT` or `_PAGE_PROT_NONE` is set.  Therefore, `pte_present` is indeed TRUE for `PAGE_NONE`. But `pte_user_accessible_page` is:

```c
static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
{
	return pte_present(pte) && pte_user(pte);
}
```

And `pte_user(pte)` is:

```c
static inline int pte_user(pte_t pte)
{
	return pte_val(pte) & _PAGE_USER;
}
```

Now, `PAGE_NONE` doesn't include `_PAGE_USER`. Thus, `pte_user_accessible_page` returns FALSE for `PAGE_NONE`. So far so good: a page mapped with `PAGE_NONE` shouldn't be user accessible. Makes sense, and `page_table_check` should properly handle (read: ignore) it.

But what about the anonymous pages? They have a refcount. If `page_table_check` ignores this, its `anon_map_count` is zero. That's fine after freeing because it remains at zero, but what about `mprotect`? If `mprotect` changes `PAGE_READ` to `PAGE_NONE`, the counter goes from 1 to 0. Then, when it is changed back, the counter goes from 0 to 1, perfectly fine!

I had to double-check that `pte_user_accessible_page` could be FALSE for a reason *other* than `PAGE_NONE`, like if `_PAGE_USER` wasn't set for a regular user page. But no, all user pages *should* have `_PAGE_USER`, so that's not a concern.

Then I moved onto examining `pmd_user_accessible_page` in RISC-V:

```c
static inline bool pmd_user_accessible_page(struct mm_struct *mm, unsigned long addr, pmd_t pmd)
{
	return pmd_leaf(pmd) && pmd_user(pmd);
}
```

And `pmd_user(pmd)`:

```c
static inline int pmd_user(pmd_t pmd)
{
	return pte_user(pmd_pte(pmd));
}
```

This also seems consistent and correct. Finally, I noticed a use of `pte_clear` in `clear_flush` in `arch/riscv/mm/hugetlbpage.c`:

```c
static void clear_flush(struct mm_struct *mm,
			unsigned long addr,
			pte_t *ptep,
			unsigned long pgsize,
			unsigned long ncontig)
{
	struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0);
	unsigned long i, saddr = addr;

	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
		ptep_get_and_clear(mm, addr, ptep);

	flush_tlb_range(&vma, saddr, addr);
}
```

But wait... isn't `clear_flush` using `ptep_get_and_clear`? I had to go back and double-check, but I was wrong about the use of `pte_clear` in the context of hugetlb.



153/2 2026/05/25 00:31 tool codesearch-definition-source
0m Error:
requested entity does not exist

Args:
map[ContextFile:arch/riscv/mm/hugetlbpage.c IncludeLines:true Name:clear_flush]

Results:
map[SourceCode: SourceFile:]

154/2 2026/05/25 00:31 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 180088
							output: 19
							thoughts: 12
						

Thoughts:
Here's my take on the thought process:

**Static Function Alert!**

Okay, hold on a second. I'm processing this code, and something just jumped out at me. I'm seeing `clear_flush` here, and I need to be *sure* I understand its implications. Wait a minute... that's a static function, isn't it? Okay, yes, it is. That means it's scoped to the class/namespace it's defined in, rather than being associated with a specific instance of that class. That fundamentally alters how I need to think about its usage and potential side effects within the larger system. I need to keep that in mind as I continue to analyze this. It changes how I think about memory management and possible race conditions.



155/2 2026/05/25 00:31 tool grepper
0m Args:
map[Expression:static void clear_flush]

Results:
map[Output:arch/arm64/mm/hugetlbpage.c=174=static pte_t get_clear_contig_flush(struct mm_struct *mm,
--
arch/arm64/mm/hugetlbpage.c-196- */
arch/arm64/mm/hugetlbpage.c:197:static void clear_flush(struct mm_struct *mm,
arch/arm64/mm/hugetlbpage.c-198-			     unsigned long addr,
--
arch/riscv/mm/hugetlbpage.c=187=pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
--
arch/riscv/mm/hugetlbpage.c-202-
arch/riscv/mm/hugetlbpage.c:203:static void clear_flush(struct mm_struct *mm,
arch/riscv/mm/hugetlbpage.c-204-			unsigned long addr,
]

156/2 2026/05/25 00:31 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 180543
							output: 45
							thoughts: 25
						

Thoughts:
Here's my take on the `clear_flush` function in `arch/riscv/mm/hugetlbpage.c`:

**Diving into the RISC-V HugeTLB Page Flushing**

Alright, let's get into the nitty-gritty of how RISC-V handles flushing HugeTLB pages. I'm going to focus on `clear_flush` in `arch/riscv/mm/hugetlbpage.c`. The name itself suggests what it does: it's involved in invalidating and clearing data within HugeTLB pages, likely for cache coherency and memory management purposes.

My initial assumption is that this function will be called when we need to unmap, deallocate, or otherwise modify a HugeTLB page that might have cached data. Given the RISC-V architecture, I anticipate it'll need to deal with the complexities of the memory management unit (MMU) and any associated hardware cache mechanisms. There could be operations around TLB invalidation, potentially some cache line flushes, and possibly even ensuring that any stale data is written back to main memory. It'll be interesting to see if it makes use of specific RISC-V instructions designed for cache management or memory barriers. I'm especially keen to see how the implementation handles different page sizes and potential hardware capabilities. Looking for the architecture-specific details is crucial here. I'll be watching to see how the function interfaces with the general HugeTLB infrastructure.



157/2 2026/05/25 00:31 tool codesearch-definition-source
0m Error:
requested entity does not exist

Args:
map[ContextFile:arch/riscv/mm/hugetlbpage.c IncludeLines:true Name:clear_flush]

Results:
map[SourceCode: SourceFile:]

158/2 2026/05/25 00:31 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 180946
							output: 27
							thoughts: 8
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:

**Direct File Access: Initial Assessment**

Alright, so the first step here is pretty clear: let's go straight to the source. Let's see if we can read the file directly. I'm thinking, instead of any intermediate steps or parsing layers, if we can access the file data directly, we can avoid any potential data loss. I’m betting this will give me the most complete and immediate perspective. Efficiency is key, right? This initial direct access will allow me to cut down time on more basic things.



159/2 2026/05/25 00:31 tool grepper
0m Args:
map[Expression:static void clear_flush\(struct mm_struct \*mm,]

Results:
map[Output:arch/arm64/mm/hugetlbpage.c=174=static pte_t get_clear_contig_flush(struct mm_struct *mm,
--
arch/arm64/mm/hugetlbpage.c-196- */
arch/arm64/mm/hugetlbpage.c:197:static void clear_flush(struct mm_struct *mm,
arch/arm64/mm/hugetlbpage.c-198-			     unsigned long addr,
--
arch/riscv/mm/hugetlbpage.c=187=pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
--
arch/riscv/mm/hugetlbpage.c-202-
arch/riscv/mm/hugetlbpage.c:203:static void clear_flush(struct mm_struct *mm,
arch/riscv/mm/hugetlbpage.c-204-			unsigned long addr,
]

160/2 2026/05/25 00:31 llm expert
1m Model:
gemini-3.1-pro-preview

Tokens:
							input: 181378
							output: 25
							thoughts: 29
						

Thoughts:
Okay, let's dive into this. I'm going to focus on lines 203-215 of `arch/riscv/mm/hugetlbpage.c`. That specific section likely deals with a crucial aspect of HugeTLB management on RISC-V. Given the file and function name, I'd anticipate it's something involved with the underlying architecture's support for large pages – potentially related to allocation, deallocation, page table entries, or perhaps interaction with the MMU. I'll need to pay close attention to the context, as nuances in RISC-V's implementation of HugeTLBs can be quite specific compared to other architectures I'm familiar with. I'm looking for the core logic, any potential optimizations, or any architecture-specific quirks that might be present. Let's see what's in there.



161/2 2026/05/25 00:32 tool grepper
0m Args:
map[Expression:clear_flush\(struct mm_struct \*mm,]

Results:
map[Output:arch/arm64/mm/hugetlbpage.c=174=static pte_t get_clear_contig_flush(struct mm_struct *mm,
--
arch/arm64/mm/hugetlbpage.c-196- */
arch/arm64/mm/hugetlbpage.c:197:static void clear_flush(struct mm_struct *mm,
arch/arm64/mm/hugetlbpage.c-198-			     unsigned long addr,
--
arch/riscv/mm/hugetlbpage.c=187=pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
--
arch/riscv/mm/hugetlbpage.c-202-
arch/riscv/mm/hugetlbpage.c:203:static void clear_flush(struct mm_struct *mm,
arch/riscv/mm/hugetlbpage.c-204-			unsigned long addr,
]

162/2 2026/05/25 00:32 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 181875
							output: 17
							thoughts: 33
						

Thoughts:
Here's my summary, as though I'm reading and processing the code:

**Analyzing `arch/riscv/mm/hugetlbpage.c` for Context**

Okay, I'm diving into the RISC-V huge page implementation, specifically the `hugetlbpage.c` file. I'm focusing on lines 200 to 220, to get a sense of what's happening in that particular section. I'm expecting this to be related to either the allocation, deallocation, or management of these large pages. Since it's RISC-V, I'll be looking for any architecture-specific hooks, maybe dealing with specific register configurations or memory mapping methodologies that are relevant to the RISC-V instruction set architecture. I'll need to keep an eye out for any interactions with the page table walks, TLB management, and the potential complexities of dealing with different huge page sizes. I'll be quickly looking for any function calls related to the memory management unit and any synchronization primitives to ensure atomicity. I want to see if this particular piece of code handles special cases such as NUMA configurations or dealing with memory hot-plug events. With my experience in kernel development, I'll be able to quickly determine the relevance of this code and its implications for the overall performance and stability of the system.



163/2 2026/05/25 00:33 tool grepper
0m Args:
map[Expression:clear_flush]

Results:
map[Output:
Full output is too long, showing 500 out of 716 lines.
Use more precise expression if possible.

[Documentation/mm/mmu_notifier.rst=4=When clearing a pte/pmd we are given a choice to notify the event through
 Documentation/mm/mmu_notifier.rst:5:(notify version of \*_clear_flush call mmu_notifier_invalidate_range) under
 Documentation/mm/mmu_notifier.rst-6-the page table lock. But that notification is not necessary in all cases.
 --
 Documentation/mm/mmu_notifier.rst=21=happen:
 --
 Documentation/mm/mmu_notifier.rst-23-  - take page table lock
 Documentation/mm/mmu_notifier.rst:24:  - clear page table entry and notify ([pmd/pte]p_huge_clear_flush_notify())
 Documentation/mm/mmu_notifier.rst-25-  - set page table entry to point to new page
 --
 Documentation/translations/zh_CN/mm/mmu_notifier.rst-13-
 Documentation/translations/zh_CN/mm/mmu_notifier.rst:14:当清除一个pte/pmd时,我们可以选择通过在页表锁下(通知版的\*_clear_flush调用
 Documentation/translations/zh_CN/mm/mmu_notifier.rst-15-mmu_notifier_invalidate_range)通知事件。但这种通知并不是在所有情况下都需要的。
 --
 Documentation/translations/zh_CN/mm/mmu_notifier.rst=18=IOMMU走CPU页表来访问进程的虚拟地址空间)。只有两种情况需要在清除pte/pmd时在持有页
 --
 Documentation/translations/zh_CN/mm/mmu_notifier.rst-28-  - 上页表锁
 Documentation/translations/zh_CN/mm/mmu_notifier.rst:29:  - 清除页表项并通知 ([pmd/pte]p_huge_clear_flush_notify())
 Documentation/translations/zh_CN/mm/mmu_notifier.rst-30-  - 设置页表项以指向新页
 --
 Documentation/virt/kvm/locking.rst=223=when the KVM MMU notifier is called to track accesses to a page (via
 Documentation/virt/kvm/locking.rst:224:kvm_mmu_notifier_clear_flush_young), it marks the PTE not-present in hardware
 Documentation/virt/kvm/locking.rst-225-by clearing the RWX bits in the PTE and storing the original R & X bits in more
 --
 arch/alpha/include/asm/pgtable.h=279=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/alpha/include/asm/pgtable.h-290-
 arch/alpha/include/asm/pgtable.h:291:static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
 arch/alpha/include/asm/pgtable.h-292-				unsigned long addr, pte_t *ptep)
 --
 arch/arm64/include/asm/hugetlb.h=48=extern void huge_ptep_set_wrprotect(struct mm_struct *mm,
 --
 arch/arm64/include/asm/hugetlb.h-50-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
 arch/arm64/include/asm/hugetlb.h:51:extern pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 arch/arm64/include/asm/hugetlb.h-52-				   unsigned long addr, pte_t *ptep);
 --
 arch/arm64/include/asm/mmu.h=19=typedef struct {
 --
 arch/arm64/include/asm/mmu.h-33- * rollover event (see new_context() and flush_context()). In this case,
 arch/arm64/include/asm/mmu.h:34: * a concurrent TLBI (e.g. via try_to_unmap_one() and ptep_clear_flush())
 arch/arm64/include/asm/mmu.h-35- * may use a stale ASID. This is fine in principle as the new ASID is
 --
 arch/arm64/include/asm/mmu.h-40- *
 arch/arm64/include/asm/mmu.h:41: *    // ptep_clear_flush(mm)
 arch/arm64/include/asm/mmu.h-42- *    xchg_relaxed(pte, 0)
 --
 arch/arm64/include/asm/pgtable.h=130=static inline pteval_t __phys_to_pte_val(phys_addr_t phys)
 --
 arch/arm64/include/asm/pgtable.h-188- * Note that we can't make any assumptions based on the state of the access
 arch/arm64/include/asm/pgtable.h:189: * flag, since __ptep_clear_flush_young() elides a DSB when invalidating the
 arch/arm64/include/asm/pgtable.h-190- * TLB.
 --
 arch/arm64/include/asm/pgtable.h=1305=static inline bool __ptep_test_and_clear_young(struct vm_area_struct *vma,
 --
 arch/arm64/include/asm/pgtable.h-1320-
 arch/arm64/include/asm/pgtable.h:1321:static inline bool __ptep_clear_flush_young(struct vm_area_struct *vma,
 arch/arm64/include/asm/pgtable.h-1322-		unsigned long address, pte_t *ptep)
 --
 arch/arm64/include/asm/pgtable.h=1667=bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
 arch/arm64/include/asm/pgtable.h-1668-				unsigned long addr, pte_t *ptep, unsigned int nr);
 arch/arm64/include/asm/pgtable.h:1669:bool contpte_clear_flush_young_ptes(struct vm_area_struct *vma,
 arch/arm64/include/asm/pgtable.h-1670-				unsigned long addr, pte_t *ptep, unsigned int nr);
 --
 arch/arm64/include/asm/pgtable.h=1844=static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
 --
 arch/arm64/include/asm/pgtable.h-1850-#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
 arch/arm64/include/asm/pgtable.h:1851:static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
 arch/arm64/include/asm/pgtable.h-1852-		unsigned long addr, pte_t *ptep)
 --
 arch/arm64/include/asm/pgtable.h-1856-	if (likely(!pte_valid_cont(orig_pte)))
 arch/arm64/include/asm/pgtable.h:1857:		return __ptep_clear_flush_young(vma, addr, ptep);
 arch/arm64/include/asm/pgtable.h-1858-
 arch/arm64/include/asm/pgtable.h:1859:	return contpte_clear_flush_young_ptes(vma, addr, ptep, 1);
 arch/arm64/include/asm/pgtable.h-1860-}
 arch/arm64/include/asm/pgtable.h-1861-
 arch/arm64/include/asm/pgtable.h:1862:#define clear_flush_young_ptes clear_flush_young_ptes
 arch/arm64/include/asm/pgtable.h:1863:static inline bool clear_flush_young_ptes(struct vm_area_struct *vma,
 arch/arm64/include/asm/pgtable.h-1864-		unsigned long addr, pte_t *ptep, unsigned int nr)
 --
 arch/arm64/include/asm/pgtable.h-1866-	if (likely(nr == 1 && !pte_cont(__ptep_get(ptep))))
 arch/arm64/include/asm/pgtable.h:1867:		return __ptep_clear_flush_young(vma, addr, ptep);
 arch/arm64/include/asm/pgtable.h-1868-
 arch/arm64/include/asm/pgtable.h:1869:	return contpte_clear_flush_young_ptes(vma, addr, ptep, nr);
 arch/arm64/include/asm/pgtable.h-1870-}
 --
 arch/arm64/include/asm/pgtable.h=1919=static inline void clear_young_dirty_ptes(struct vm_area_struct *vma,
 --
 arch/arm64/include/asm/pgtable.h-1941-#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
 arch/arm64/include/asm/pgtable.h:1942:#define ptep_clear_flush_young			__ptep_clear_flush_young
 arch/arm64/include/asm/pgtable.h-1943-#define __HAVE_ARCH_PTEP_SET_WRPROTECT
 --
 arch/arm64/kvm/hyp/pgtable.c=1310=static int stage2_age_walker(const struct kvm_pgtable_visit_ctx *ctx,
 --
 arch/arm64/kvm/hyp/pgtable.c-1333-	 *
 arch/arm64/kvm/hyp/pgtable.c:1334:	 * See the '->clear_flush_young()' callback on the KVM mmu notifier.
 arch/arm64/kvm/hyp/pgtable.c-1335-	 */
 --
 arch/arm64/mm/contpte.c=512=bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
 --
 arch/arm64/mm/contpte.c-515-	/*
 arch/arm64/mm/contpte.c:516:	 * ptep_clear_flush_young() technically requires us to clear the access
 arch/arm64/mm/contpte.c-517-	 * flag for a _single_ pte. However, the core-mm code actually tracks
 --
 arch/arm64/mm/contpte.c=536=EXPORT_SYMBOL_GPL(contpte_test_and_clear_young_ptes);
 arch/arm64/mm/contpte.c-537-
 arch/arm64/mm/contpte.c:538:bool contpte_clear_flush_young_ptes(struct vm_area_struct *vma,
 arch/arm64/mm/contpte.c-539-		unsigned long addr, pte_t *ptep, unsigned int nr)
 --
 arch/arm64/mm/contpte.c-549-		/*
 arch/arm64/mm/contpte.c:550:		 * See comment in __ptep_clear_flush_young(); same rationale for
 arch/arm64/mm/contpte.c-551-		 * eliding the trailing DSB applies here.
 --
 arch/arm64/mm/contpte.c-558-}
 arch/arm64/mm/contpte.c:559:EXPORT_SYMBOL_GPL(contpte_clear_flush_young_ptes);
 arch/arm64/mm/contpte.c-560-
 --
 arch/arm64/mm/hugetlbpage.c=174=static pte_t get_clear_contig_flush(struct mm_struct *mm,
 --
 arch/arm64/mm/hugetlbpage.c-196- */
 arch/arm64/mm/hugetlbpage.c:197:static void clear_flush(struct mm_struct *mm,
 arch/arm64/mm/hugetlbpage.c-198-			     unsigned long addr,
 --
 arch/arm64/mm/hugetlbpage.c=215=void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
 --
 arch/arm64/mm/hugetlbpage.c-231-	if (pte_cont(pte) && pte_valid(__ptep_get(ptep)))
 arch/arm64/mm/hugetlbpage.c:232:		clear_flush(mm, addr, ptep, pgsize, ncontig);
 arch/arm64/mm/hugetlbpage.c-233-
 --
 arch/arm64/mm/hugetlbpage.c=453=void huge_ptep_set_wrprotect(struct mm_struct *mm,
 --
 arch/arm64/mm/hugetlbpage.c-475-
 arch/arm64/mm/hugetlbpage.c:476:pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 arch/arm64/mm/hugetlbpage.c-477-			    unsigned long addr, pte_t *ptep)
 --
 arch/arm64/mm/hugetlbpage.c=517=pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
 --
 arch/arm64/mm/hugetlbpage.c-527-		if (pte_user_exec(__ptep_get(ptep)))
 arch/arm64/mm/hugetlbpage.c:528:			return huge_ptep_clear_flush(vma, addr, ptep);
 arch/arm64/mm/hugetlbpage.c-529-	}
 --
 arch/loongarch/include/asm/hugetlb.h=24=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/loongarch/include/asm/hugetlb.h-36-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
 arch/loongarch/include/asm/hugetlb.h:37:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 arch/loongarch/include/asm/hugetlb.h-38-					  unsigned long addr, pte_t *ptep)
 --
 arch/mips/include/asm/hugetlb.h=15=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/mips/include/asm/hugetlb.h-27-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
 arch/mips/include/asm/hugetlb.h:28:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 arch/mips/include/asm/hugetlb.h-29-					  unsigned long addr, pte_t *ptep)
 --
 arch/parisc/include/asm/hugetlb.h=12=pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/parisc/include/asm/hugetlb.h-15-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
 arch/parisc/include/asm/hugetlb.h:16:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 arch/parisc/include/asm/hugetlb.h-17-					  unsigned long addr, pte_t *ptep)
 --
 arch/parisc/include/asm/pgtable.h=441=static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
 --
 arch/parisc/include/asm/pgtable.h-453-
 arch/parisc/include/asm/pgtable.h:454:bool ptep_clear_flush_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep);
 arch/parisc/include/asm/pgtable.h:455:pte_t ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep);
 arch/parisc/include/asm/pgtable.h-456-
 --
 arch/parisc/kernel/cache.c=776=void flush_anon_page(struct vm_area_struct *vma, struct page *page, unsigned long vmaddr)
 --
 arch/parisc/kernel/cache.c-783-
 arch/parisc/kernel/cache.c:784:bool ptep_clear_flush_young(struct vm_area_struct *vma,
 arch/parisc/kernel/cache.c-785-		unsigned long addr, pte_t *ptep)
 --
 arch/parisc/kernel/cache.c-803- */
 arch/parisc/kernel/cache.c:804:pte_t ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr,
 arch/parisc/kernel/cache.c-805-		       pte_t *ptep)
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h=352=static inline bool __ptep_test_and_clear_young(struct mm_struct *mm,
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-385-#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
 arch/powerpc/include/asm/book3s/64/pgtable.h:386:#define ptep_clear_flush_young ptep_test_and_clear_young
 arch/powerpc/include/asm/book3s/64/pgtable.h-387-
 arch/powerpc/include/asm/book3s/64/pgtable.h-388-#define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
 arch/powerpc/include/asm/book3s/64/pgtable.h:389:#define pmdp_clear_flush_young pmdp_test_and_clear_young
 arch/powerpc/include/asm/book3s/64/pgtable.h-390-
 --
 arch/powerpc/include/asm/book3s/64/tlbflush.h=161=static inline bool __pte_flags_need_flush(unsigned long oldval,
 --
 arch/powerpc/include/asm/book3s/64/tlbflush.h-196-	 * With the exception of _PAGE_ACCESSED, don't worry about flushing
 arch/powerpc/include/asm/book3s/64/tlbflush.h:197:	 * if that was cleared (see the comment in ptep_clear_flush_young()).
 arch/powerpc/include/asm/book3s/64/tlbflush.h-198-	 */
 --
 arch/powerpc/include/asm/hugetlb.h=47=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/powerpc/include/asm/hugetlb.h-54-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
 arch/powerpc/include/asm/hugetlb.h:55:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 arch/powerpc/include/asm/hugetlb.h-56-					  unsigned long addr, pte_t *ptep)
 --
 arch/powerpc/include/asm/nohash/64/pgtable.h=149=static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
 --
 arch/powerpc/include/asm/nohash/64/pgtable.h-155-#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
 arch/powerpc/include/asm/nohash/64/pgtable.h:156:#define ptep_clear_flush_young(__vma, __address, __ptep)		\
 arch/powerpc/include/asm/nohash/64/pgtable.h-157-({									\
 --
 arch/riscv/include/asm/hugetlb.h=30=pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/riscv/include/asm/hugetlb.h-34-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
 arch/riscv/include/asm/hugetlb.h:35:pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 arch/riscv/include/asm/hugetlb.h-36-			    unsigned long addr, pte_t *ptep);
 --
 arch/riscv/include/asm/pgtable.h=668=static inline void ptep_set_wrprotect(struct mm_struct *mm,
 --
 arch/riscv/include/asm/pgtable.h-682-#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
 arch/riscv/include/asm/pgtable.h:683:static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
 arch/riscv/include/asm/pgtable.h-684-		unsigned long address, pte_t *ptep)
 --
 arch/riscv/mm/hugetlbpage.c=187=pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
 --
 arch/riscv/mm/hugetlbpage.c-202-
 arch/riscv/mm/hugetlbpage.c:203:static void clear_flush(struct mm_struct *mm,
 arch/riscv/mm/hugetlbpage.c-204-			unsigned long addr,
 --
 arch/riscv/mm/hugetlbpage.c=246=void set_huge_pte_at(struct mm_struct *mm,
 --
 arch/riscv/mm/hugetlbpage.c-267-
 arch/riscv/mm/hugetlbpage.c:268:	clear_flush(mm, addr, ptep, pgsize, pte_num);
 arch/riscv/mm/hugetlbpage.c-269-
 --
 arch/riscv/mm/hugetlbpage.c=321=void huge_ptep_set_wrprotect(struct mm_struct *mm,
 --
 arch/riscv/mm/hugetlbpage.c-345-
 arch/riscv/mm/hugetlbpage.c:346:pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 arch/riscv/mm/hugetlbpage.c-347-			    unsigned long addr,
 --
 arch/riscv/mm/hugetlbpage.c-353-	if (!pte_napot(pte))
 arch/riscv/mm/hugetlbpage.c:354:		return ptep_clear_flush(vma, addr, ptep);
 arch/riscv/mm/hugetlbpage.c-355-
 --
 arch/s390/include/asm/hugetlb.h=41=static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/s390/include/asm/hugetlb.h-50-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
 arch/s390/include/asm/hugetlb.h:51:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 arch/s390/include/asm/hugetlb.h-52-					  unsigned long address, pte_t *ptep)
 --
 arch/s390/include/asm/pgtable.h=1138=static __always_inline void __ptep_ipte_range(unsigned long address, int nr,
 --
 arch/s390/include/asm/pgtable.h-1152-/*
 arch/s390/include/asm/pgtable.h:1153: * This is hard to understand. ptep_get_and_clear and ptep_clear_flush
 arch/s390/include/asm/pgtable.h-1154- * both clear the TLB for the unmapped pte. The reason is that
 --
 arch/s390/include/asm/pgtable.h=1169=static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
 --
 arch/s390/include/asm/pgtable.h-1178-#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
 arch/s390/include/asm/pgtable.h:1179:static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
 arch/s390/include/asm/pgtable.h-1180-		unsigned long address, pte_t *ptep)
 --
 arch/s390/include/asm/pgtable.h=1201=void ptep_modify_prot_commit(struct vm_area_struct *, unsigned long,
 --
 arch/s390/include/asm/pgtable.h-1204-#define __HAVE_ARCH_PTEP_CLEAR_FLUSH
 arch/s390/include/asm/pgtable.h:1205:static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
 arch/s390/include/asm/pgtable.h-1206-				     unsigned long addr, pte_t *ptep)
 --
 arch/s390/include/asm/pgtable.h=1694=static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
 --
 arch/s390/include/asm/pgtable.h-1703-#define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
 arch/s390/include/asm/pgtable.h:1704:static inline bool pmdp_clear_flush_young(struct vm_area_struct *vma,
 arch/s390/include/asm/pgtable.h-1705-		unsigned long addr, pmd_t *pmdp)
 --
 arch/s390/include/asm/pgtable.h=1737=static inline pmd_t pmdp_huge_get_and_clear_full(struct vm_area_struct *vma,
 --
 arch/s390/include/asm/pgtable.h-1754-#define __HAVE_ARCH_PMDP_HUGE_CLEAR_FLUSH
 arch/s390/include/asm/pgtable.h:1755:static inline pmd_t pmdp_huge_clear_flush(struct vm_area_struct *vma,
 arch/s390/include/asm/pgtable.h-1756-					  unsigned long addr, pmd_t *pmdp)
 --
 arch/s390/include/asm/tlb.h=28=static inline bool __tlb_remove_folio_pages(struct mmu_gather *tlb,
 --
 arch/s390/include/asm/tlb.h-41- * Release the page cache reference for a pte removed by
 arch/s390/include/asm/tlb.h:42: * tlb_ptep_clear_flush. In both flush modes the tlb for a page cache page
 arch/s390/include/asm/tlb.h-43- * has already been freed, so just do free_folio_and_swap_cache.
 --
 arch/sh/include/asm/hugetlb.h-8-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
 arch/sh/include/asm/hugetlb.h:9:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 arch/sh/include/asm/hugetlb.h-10-					  unsigned long addr, pte_t *ptep)
 --
 arch/sparc/include/asm/hugetlb.h=22=pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/sparc/include/asm/hugetlb.h-25-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
 arch/sparc/include/asm/hugetlb.h:26:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 arch/sparc/include/asm/hugetlb.h-27-					  unsigned long addr, pte_t *ptep)
 --
 arch/sparc/kernel/iommu-common.c=24=static inline void set_flush(struct iommu_map_table *iommu)
 --
 arch/sparc/kernel/iommu-common.c-28-
 arch/sparc/kernel/iommu-common.c:29:static inline void clear_flush(struct iommu_map_table *iommu)
 arch/sparc/kernel/iommu-common.c-30-{
 --
 arch/sparc/kernel/iommu-common.c=97=unsigned long iommu_tbl_range_alloc(struct device *dev,
 --
 arch/sparc/kernel/iommu-common.c-206-	    (n < pool->hint || need_flush(iommu))) {
 arch/sparc/kernel/iommu-common.c:207:		clear_flush(iommu);
 arch/sparc/kernel/iommu-common.c-208-		iommu->lazy_flush(iommu);
 --
 arch/um/include/asm/ptrace-generic.h=42=extern int arch_set_tls(struct task_struct *new, unsigned long tls);
 arch/um/include/asm/ptrace-generic.h:43:extern void clear_flushed_tls(struct task_struct *task);
 arch/um/include/asm/ptrace-generic.h-44-extern int syscall_trace_enter(struct pt_regs *regs);
 --
 arch/um/kernel/process.c=146=int copy_thread(struct task_struct * p, const struct kernel_clone_args *args)
 --
 arch/um/kernel/process.c-175-	if (!args->fn) {
 arch/um/kernel/process.c:176:		clear_flushed_tls(p);
 arch/um/kernel/process.c-177-
 --
 arch/x86/include/asm/pgtable.h=1235=bool ptep_test_and_clear_young(struct vm_area_struct *vma,
 --
 arch/x86/include/asm/pgtable.h-1238-#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
 arch/x86/include/asm/pgtable.h:1239:bool ptep_clear_flush_young(struct vm_area_struct *vma,
 arch/x86/include/asm/pgtable.h-1240-		unsigned long address, pte_t *ptep);
 --
 arch/x86/include/asm/pgtable.h=1300=bool pudp_test_and_clear_young(struct vm_area_struct *vma,
 --
 arch/x86/include/asm/pgtable.h-1303-#define __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
 arch/x86/include/asm/pgtable.h:1304:bool pmdp_clear_flush_young(struct vm_area_struct *vma,
 arch/x86/include/asm/pgtable.h-1305-		unsigned long address, pmd_t *pmdp);
 --
 arch/x86/include/asm/pgtable_32.h=32=void sync_initial_page_table(void);
 --
 arch/x86/include/asm/pgtable_32.h-40-/* Clear a kernel PTE and flush it from the TLB */
 arch/x86/include/asm/pgtable_32.h:41:#define kpte_clear_flush(ptep, vaddr)		\
 arch/x86/include/asm/pgtable_32.h-42-do {						\
 --
 arch/x86/include/asm/tlbflush.h=438=static inline bool pte_needs_flush(pte_t oldpte, pte_t newpte)
 --
 arch/x86/include/asm/tlbflush.h-449-	 * check PTE flags; ignore access-bit; see comment in
 arch/x86/include/asm/tlbflush.h:450:	 * ptep_clear_flush_young().
 arch/x86/include/asm/tlbflush.h-451-	 */
 --
 arch/x86/include/asm/tlbflush.h=461=static inline bool huge_pmd_needs_flush(pmd_t oldpmd, pmd_t newpmd)
 --
 arch/x86/include/asm/tlbflush.h-472-	 * check PMD flags; do not ignore access-bit; see
 arch/x86/include/asm/tlbflush.h:473:	 * pmdp_clear_flush_young().
 arch/x86/include/asm/tlbflush.h-474-	 */
 --
 arch/x86/kvm/mmu/spte.h=493=static inline bool is_access_allowed(struct kvm_page_fault *fault, u64 spte)
 --
 arch/x86/kvm/mmu/spte.h-514- * false negatives, e.g. KVM x86 omits TLB flushes even when aging SPTEs for a
 arch/x86/kvm/mmu/spte.h:515: * mmu_notifier.clear_flush_young() event.
 arch/x86/kvm/mmu/spte.h-516- *
 --
 arch/x86/kvm/mmu/tdp_mmu.c=1353=bool kvm_tdp_mmu_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range,
 --
 arch/x86/kvm/mmu/tdp_mmu.c-1372- * No need to mark the corresponding PFN as accessed as this call is coming
 arch/x86/kvm/mmu/tdp_mmu.c:1373: * from the clear_young() or clear_flush_young() notifier, which uses the
 arch/x86/kvm/mmu/tdp_mmu.c-1374- * return value to determine if the page has been accessed.
 --
 arch/x86/mm/pgtable.c=473=bool pudp_test_and_clear_young(struct vm_area_struct *vma,
 --
 arch/x86/mm/pgtable.c-485-
 arch/x86/mm/pgtable.c:486:bool ptep_clear_flush_young(struct vm_area_struct *vma,
 arch/x86/mm/pgtable.c-487-		unsigned long address, pte_t *ptep)
 --
 arch/x86/mm/pgtable.c-505-#ifdef CONFIG_TRANSPARENT_HUGEPAGE
 arch/x86/mm/pgtable.c:506:bool pmdp_clear_flush_young(struct vm_area_struct *vma,
 arch/x86/mm/pgtable.c-507-		unsigned long address, pmd_t *pmdp)
 --
 arch/x86/um/tls_32.c=126=static inline int needs_TLS_update(struct task_struct *task)
 --
 arch/x86/um/tls_32.c-150- */
 arch/x86/um/tls_32.c:151:void clear_flushed_tls(struct task_struct *task)
 arch/x86/um/tls_32.c-152-{
 --
 arch/x86/um/tls_64.c-4-
 arch/x86/um/tls_64.c:5:void clear_flushed_tls(struct task_struct *task)
 arch/x86/um/tls_64.c-6-{
 --
 block/blk-mq.c=3952=static void blk_mq_add_hw_queues_cpuhp(struct request_queue *q)
 --
 block/blk-mq.c-3966- */
 block/blk-mq.c:3967:static void blk_mq_clear_flush_rq_mapping(struct blk_mq_tags *tags,
 block/blk-mq.c-3968-		unsigned int queue_depth, struct request *flush_rq)
 --
 block/blk-mq.c=3991=static void blk_mq_exit_hctx(struct request_queue *q,
 --
 block/blk-mq.c-4000-	if (blk_queue_init_done(q))
 block/blk-mq.c:4001:		blk_mq_clear_flush_rq_mapping(set->tags[hctx_idx],
 block/blk-mq.c-4002-				set->queue_depth, flush_rq);
 --
 fs/xfs/xfs_icache.c=961=xfs_reclaim_inode(
 --
 fs/xfs/xfs_icache.c-992-	if (xfs_ipincount(ip))
 fs/xfs/xfs_icache.c:993:		goto out_clear_flush;
 fs/xfs/xfs_icache.c-994-	if (!xfs_inode_clean(ip))
 fs/xfs/xfs_icache.c:995:		goto out_clear_flush;
 fs/xfs/xfs_icache.c-996-
 --
 fs/xfs/xfs_icache.c-1051-
 fs/xfs/xfs_icache.c:1052:out_clear_flush:
 fs/xfs/xfs_icache.c-1053-	xfs_iflags_clear(ip, XFS_IFLUSHING);
 --
 include/asm-generic/hugetlb.h=78=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
 --
 include/asm-generic/hugetlb.h-85-#ifndef __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
 include/asm-generic/hugetlb.h:86:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 include/asm-generic/hugetlb.h-87-		unsigned long addr, pte_t *ptep)
 include/asm-generic/hugetlb.h-88-{
 include/asm-generic/hugetlb.h:89:	return ptep_clear_flush(vma, addr, ptep);
 include/asm-generic/hugetlb.h-90-}
 --
 include/linux/hugetlb.h=1274=static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
 --
 include/linux/hugetlb.h-1277-
 include/linux/hugetlb.h:1278:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 include/linux/hugetlb.h-1279-					  unsigned long addr, pte_t *ptep)
 --
 include/linux/mmu_notifier.h=64=struct mmu_notifier_ops {
 --
 include/linux/mmu_notifier.h-91-	/*
 include/linux/mmu_notifier.h:92:	 * clear_flush_young is called after the VM is
 include/linux/mmu_notifier.h-93-	 * test-and-clearing the young/accessed bitflag in the
 --
 include/linux/mmu_notifier.h-99-	 */
 include/linux/mmu_notifier.h:100:	bool (*clear_flush_young)(struct mmu_notifier *subscription,
 include/linux/mmu_notifier.h-101-				  struct mm_struct *mm,
 --
 include/linux/mmu_notifier.h-105-	/*
 include/linux/mmu_notifier.h:106:	 * clear_young is a lightweight version of clear_flush_young. Like the
 include/linux/mmu_notifier.h-107-	 * latter, it is supposed to test-and-clear the young/accessed bitflag
 --
 include/linux/mmu_notifier.h=420=extern void __mmu_notifier_release(struct mm_struct *mm);
 include/linux/mmu_notifier.h:421:bool __mmu_notifier_clear_flush_young(struct mm_struct *mm,
 include/linux/mmu_notifier.h-422-		unsigned long start, unsigned long end);
 --
 include/linux/mmu_notifier.h=440=static inline void mmu_notifier_release(struct mm_struct *mm)
 --
 include/linux/mmu_notifier.h-445-
 include/linux/mmu_notifier.h:446:static inline bool mmu_notifier_clear_flush_young(struct mm_struct *mm,
 include/linux/mmu_notifier.h-447-		unsigned long start, unsigned long end)
 --
 include/linux/mmu_notifier.h-449-	if (mm_has_notifiers(mm))
 include/linux/mmu_notifier.h:450:		return __mmu_notifier_clear_flush_young(mm, start, end);
 include/linux/mmu_notifier.h-451-	return false;
 --
 include/linux/mmu_notifier.h=589=static inline void mmu_notifier_release(struct mm_struct *mm)
 --
 include/linux/mmu_notifier.h-592-
 include/linux/mmu_notifier.h:593:static inline bool mmu_notifier_clear_flush_young(struct mm_struct *mm,
 include/linux/mmu_notifier.h-594-		unsigned long start, unsigned long end)
 --
 include/linux/pgtable.h=523=static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
 --
 include/linux/pgtable.h-532-#ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
 include/linux/pgtable.h:533:bool ptep_clear_flush_young(struct vm_area_struct *vma,
 include/linux/pgtable.h-534-		unsigned long address, pte_t *ptep);
 --
 include/linux/pgtable.h-538-#ifdef CONFIG_TRANSPARENT_HUGEPAGE
 include/linux/pgtable.h:539:bool pmdp_clear_flush_young(struct vm_area_struct *vma,
 include/linux/pgtable.h-540-		unsigned long address, pmd_t *pmdp);
 --
 include/linux/pgtable.h-545- */
 include/linux/pgtable.h:546:static inline bool pmdp_clear_flush_young(struct vm_area_struct *vma,
 include/linux/pgtable.h-547-		unsigned long address, pmd_t *pmdp)
 --
 include/linux/pgtable.h=988=static inline void clear_not_present_full_ptes(struct mm_struct *mm,
 --
 include/linux/pgtable.h-1001-#ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH
 include/linux/pgtable.h:1002:extern pte_t ptep_clear_flush(struct vm_area_struct *vma,
 include/linux/pgtable.h-1003-			      unsigned long address,
 --
 include/linux/pgtable.h-1007-#ifndef __HAVE_ARCH_PMDP_HUGE_CLEAR_FLUSH
 include/linux/pgtable.h:1008:extern pmd_t pmdp_huge_clear_flush(struct vm_area_struct *vma,
 include/linux/pgtable.h-1009-			      unsigned long address,
 include/linux/pgtable.h-1010-			      pmd_t *pmdp);
 include/linux/pgtable.h:1011:extern pud_t pudp_huge_clear_flush(struct vm_area_struct *vma,
 include/linux/pgtable.h-1012-			      unsigned long address,
 --
 include/linux/pgtable.h=1057=static inline void wrprotect_ptes(struct mm_struct *mm, unsigned long addr,
 --
 include/linux/pgtable.h-1069-
 include/linux/pgtable.h:1070:#ifndef clear_flush_young_ptes
 include/linux/pgtable.h-1071-/**
 include/linux/pgtable.h:1072: * clear_flush_young_ptes - Mark PTEs that map consecutive pages of the same
 include/linux/pgtable.h-1073- *			    folio as old and flush the TLB.
 --
 include/linux/pgtable.h-1079- * May be overridden by the architecture; otherwise, implemented as a simple
 include/linux/pgtable.h:1080: * loop over ptep_clear_flush_young().
 include/linux/pgtable.h-1081- *
 --
 include/linux/pgtable.h-1087- */
 include/linux/pgtable.h:1088:static inline bool clear_flush_young_ptes(struct vm_area_struct *vma,
 include/linux/pgtable.h-1089-		unsigned long addr, pte_t *ptep, unsigned int nr)
 --
 include/linux/pgtable.h-1093-	for (;;) {
 include/linux/pgtable.h:1094:		young |= ptep_clear_flush_young(vma, addr, ptep);
 include/linux/pgtable.h-1095-		if (--nr == 0)
 --
 kernel/events/uprobes.c=403=static int __uprobe_write(struct vm_area_struct *vma,
 --
 kernel/events/uprobes.c-431-	flush_cache_page(vma, vaddr, pte_pfn(fw->pte));
 kernel/events/uprobes.c:432:	fw->pte = ptep_clear_flush(vma, vaddr, fw->ptep);
 kernel/events/uprobes.c-433-	copy_to_page(fw->page, insn_vaddr, insn, nbytes);
 --
 mm/huge_memory.c=2105=static vm_fault_t do_huge_zero_wp_pmd(struct vm_fault *vmf)
 --
]
]

164/2 2026/05/25 00:33 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 194373
							output: 48
							thoughts: 849
						

Thoughts:
**Analyzing PTE Counter Balance in RISC-V Memory Management**

Okay, let's break this down. My initial thought was that `pte_clear` seemed limited in its RISC-V usage, specifically relating only to `huge_pte_clear` and kernel mappings. Since `huge_pte_clear` itself appears to only target non-present PTEs within the `mm/hugetlb.c` context, that means a present user PTE is *never* cleared using `pte_clear` in RISC-V. This implies that `page_table_check_pte_clear` should *always* be invoked when a present user PTE is actually cleared. Consequently, the counter is consistently decremented under these specific conditions.

Now, the potential for an issue arises if `page_table_check_pte_clear` gets called but `pte_user_accessible_page` returns FALSE.  We know `PAGE_NONE` triggers `pte_user_accessible_page` as FALSE. I began walking through a potential sequence. If a page starts mapped with `PAGE_READ` (counter = 1) and then `mprotect` changes it to `PAGE_NONE`. `ptep_modify_prot_start` then calls `ptep_get_and_clear`. `ptep_get_and_clear` reads `PAGE_READ` here. `pte_user_accessible_page` is true and the counter is decremented to zero. Next, `ptep_modify_prot_commit` calls `set_pte_at` with `PAGE_NONE`. `set_pte_at` calls `page_table_check_ptes_set`. `pte_user_accessible_page` is now FALSE and the counter remains zero. When `mprotect` switches it back to `PAGE_READ` we see `ptep_modify_prot_start` read `PAGE_NONE`. `pte_user_accessible_page` is false, and the counter remains at zero. Finally, if `ptep_modify_prot_commit` calls `set_pte_at` with `PAGE_READ`, `set_pte_at` calls `page_table_check_ptes_set`, and `pte_user_accessible_page` is true. The counter increments to 1 again, which is balanced!

I've got another case: If `mprotect` changes a `PAGE_READ` to `PAGE_READ | PAGE_WRITE` is also easy to follow.  `ptep_modify_prot_start` reads `PAGE_READ`, the counter goes down to zero, and `ptep_modify_prot_commit` writes `PAGE_READ | PAGE_WRITE` with the counter incrementing back to one, again balanced!

The last area I need to confirm is how `ptep_modify_prot_start` might *not* call `page_table_check_pte_clear`. I investigated the RISC-V implementation of `ptep_modify_prot_start`. It uses the default in `include/linux/pgtable.h`, which in turn calls `ptep_get_and_clear`. And *that* calls `page_table_check_pte_clear`. So the balance is maintained in the standard path.

I was also concerned about a call to `ptep_set_access_flags`. We need to check its interaction in `arch/riscv/mm/pgtable.c`. I have more digging to do there!



165/2 2026/05/25 00:33 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/mm/pgtable.c IncludeLines:true Name:ptep_set_access_flags]

Results:
map[SourceCode: 384:	/*
 385:	 * Used to set accessed or dirty bits in the page table entries
 386:	 * on other architectures. On x86, the accessed and dirty bits
 387:	 * are tracked by hardware. However, do_wp_page calls this function
 388:	 * to also make the pte writeable at the same time the dirty bit is
 389:	 * set. In that case we do actually need to write the PTE.
 390:	 */
 391:	int ptep_set_access_flags(struct vm_area_struct *vma,
 392:				  unsigned long address, pte_t *ptep,
 393:				  pte_t entry, int dirty)
 394:	{
 395:		int changed = !pte_same(*ptep, entry);
 396:	
 397:		if (changed && dirty)
 398:			set_pte(ptep, entry);
 399:	
 400:		return changed;
 401:	}
 SourceFile:arch/x86/mm/pgtable.c]

166/2 2026/05/25 00:33 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 196333
							output: 25
							thoughts: 49
						

Thoughts:
Okay, let's see what we've got.

**Examining Page Table Access Flag Setting**

Hmm, interesting. The code search pointed me toward `arch/x86/mm/pgtable.c`. That's a good starting point, but I need to make a mental note to cross-reference with the RISC-V implementation. Given that, let me go ahead and check `ptep_set_access_flags` in `arch/riscv/mm/pgtable.c`. Need to quickly build a comparative analysis to fully grasp this implementation.



167/2 2026/05/25 00:33 tool grepper
0m Args:
map[Expression:int ptep_set_access_flags\(]

Results:
map[Output:arch/arm64/include/asm/pgtable.h=1897=static inline void ptep_set_wrprotect(struct mm_struct *mm,
--
arch/arm64/include/asm/pgtable.h-1903-#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
arch/arm64/include/asm/pgtable.h:1904:static inline int ptep_set_access_flags(struct vm_area_struct *vma,
arch/arm64/include/asm/pgtable.h-1905-				unsigned long addr, pte_t *ptep,
--
arch/mips/include/asm/pgtable.h=488=static inline int pte_same(pte_t pte_a, pte_t pte_b)
--
arch/mips/include/asm/pgtable.h-493-#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
arch/mips/include/asm/pgtable.h:494:static inline int ptep_set_access_flags(struct vm_area_struct *vma,
arch/mips/include/asm/pgtable.h-495-					unsigned long address, pte_t *ptep,
--
arch/nios2/include/asm/pgtable.h=281=static inline int pte_same(pte_t pte_a, pte_t pte_b);
--
arch/nios2/include/asm/pgtable.h-283-#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
arch/nios2/include/asm/pgtable.h:284:static inline int ptep_set_access_flags(struct vm_area_struct *vma,
arch/nios2/include/asm/pgtable.h-285-					unsigned long address, pte_t *ptep,
--
arch/powerpc/include/asm/pgtable.h=115=static inline void mark_initmem_nx(void) { }
--
arch/powerpc/include/asm/pgtable.h-118-#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
arch/powerpc/include/asm/pgtable.h:119:int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
arch/powerpc/include/asm/pgtable.h-120-			  pte_t *ptep, pte_t entry, int dirty);
--
arch/powerpc/mm/pgtable.c=239=void unmap_kernel_page(unsigned long va)
--
arch/powerpc/mm/pgtable.c-254- */
arch/powerpc/mm/pgtable.c:255:int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
arch/powerpc/mm/pgtable.c-256-			  pte_t *ptep, pte_t entry, int dirty)
--
arch/riscv/include/asm/pgtable.h=637=static inline void pte_clear(struct mm_struct *mm,
--
arch/riscv/include/asm/pgtable.h-643-#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS	/* defined in mm/pgtable.c */
arch/riscv/include/asm/pgtable.h:644:extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
arch/riscv/include/asm/pgtable.h-645-				 pte_t *ptep, pte_t entry, int dirty);
--
arch/riscv/mm/pgtable.c-7-
arch/riscv/mm/pgtable.c:8:int ptep_set_access_flags(struct vm_area_struct *vma,
arch/riscv/mm/pgtable.c-9-			  unsigned long address, pte_t *ptep,
--
arch/s390/include/asm/pgtable.h=1306=void ptep_reset_dat_prot(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
--
arch/s390/include/asm/pgtable.h-1309-#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
arch/s390/include/asm/pgtable.h:1310:static inline int ptep_set_access_flags(struct vm_area_struct *vma,
arch/s390/include/asm/pgtable.h-1311-					unsigned long addr, pte_t *ptep,
--
arch/x86/include/asm/pgtable.h=1227=struct vm_area_struct;
--
arch/x86/include/asm/pgtable.h-1229-#define  __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
arch/x86/include/asm/pgtable.h:1230:extern int ptep_set_access_flags(struct vm_area_struct *vma,
arch/x86/include/asm/pgtable.h-1231-				 unsigned long address, pte_t *ptep,
--
arch/x86/mm/pgtable.c=376=void pgd_free(struct mm_struct *mm, pgd_t *pgd)
--
arch/x86/mm/pgtable.c-390- */
arch/x86/mm/pgtable.c:391:int ptep_set_access_flags(struct vm_area_struct *vma,
arch/x86/mm/pgtable.c-392-			  unsigned long address, pte_t *ptep,
--
include/linux/pgtable.h=410=static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
--
include/linux/pgtable.h-426-#ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
include/linux/pgtable.h:427:extern int ptep_set_access_flags(struct vm_area_struct *vma,
include/linux/pgtable.h-428-				 unsigned long address, pte_t *ptep,
--
mm/pgtable-generic.c=54=void pmd_clear_bad(pmd_t *pmd)
--
mm/pgtable-generic.c-69- */
mm/pgtable-generic.c:70:int ptep_set_access_flags(struct vm_area_struct *vma,
mm/pgtable-generic.c-71-			  unsigned long address, pte_t *ptep,
]

168/2 2026/05/25 00:33 llm expert
1m Model:
gemini-3.1-pro-preview

Tokens:
							input: 198233
							output: 48
							thoughts: 28
						

Thoughts:
Okay, let's dive into this. Here's my take on those thoughts, as if they're my own:

**Analyzing `ptep_set_access_flags` in `arch/riscv/mm/pgtable.c`**

Alright, time to get my hands dirty. I want to understand how memory access flags are being handled in the RISC-V architecture, specifically within the kernel. Let's start by digging into `ptep_set_access_flags`. That sounds like the right function to examine, as the name itself suggests it's the one responsible for setting those flags on page table entries. It's likely involved in setting read, write, execute permissions, and possibly even things like accessed and dirty bits. I'll need to see the actual code to see how it's implemented. I'm expecting this will involve bitwise operations for setting and clearing bits within the page table entry structure. I’m hoping to glean insights into the atomicity of these operations, especially in a multi-threaded context. Are there any locks involved, or is it assumed to be handled at a lower level with CPU instructions? I'll also be looking for any architecture-specific optimizations or considerations. The RISC-V architecture is relatively new, so the approach might differ from older architectures like x86. I'm especially keen to understand how this function interacts with the hardware page table walking mechanism. Is it a direct manipulation or an abstraction layer? Let's get to the code and find out!



169/2 2026/05/25 00:34 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/mm/pgtable.c IncludeLines:true Name:ptep_set_access_flags]

Results:
map[SourceCode: 384:	/*
 385:	 * Used to set accessed or dirty bits in the page table entries
 386:	 * on other architectures. On x86, the accessed and dirty bits
 387:	 * are tracked by hardware. However, do_wp_page calls this function
 388:	 * to also make the pte writeable at the same time the dirty bit is
 389:	 * set. In that case we do actually need to write the PTE.
 390:	 */
 391:	int ptep_set_access_flags(struct vm_area_struct *vma,
 392:				  unsigned long address, pte_t *ptep,
 393:				  pte_t entry, int dirty)
 394:	{
 395:		int changed = !pte_same(*ptep, entry);
 396:	
 397:		if (changed && dirty)
 398:			set_pte(ptep, entry);
 399:	
 400:		return changed;
 401:	}
 SourceFile:arch/x86/mm/pgtable.c]

170/2 2026/05/25 00:34 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 198945
							output: 35
							thoughts: 49
						

Thoughts:
Okay, here's my interpretation of this thought process, keeping in mind my expertise:

**Examining Page Table Implementation Differences**

Hmm, the code search keeps pointing me back to `arch/x86/mm/pgtable.c`. That's not what I'm looking for *again*. I wanted to compare the RISC-V implementation, but it keeps giving me the x86 implementation. Okay, deep breath.

Right, let's just go straight to `arch/riscv/mm/pgtable.c` and grab the first 20 lines. I know I have to manually go and look, but this way I am less likely to be surprised by an irrelevant result. I need to refresh myself on how the RISC-V page table structure *begins* - the foundational data structures and how they're declared. It's often the initial few lines that define the core layout. Then I can make some valid comparisons.



171/2 2026/05/25 00:34 tool grepper
0m Args:
map[Expression:int ptep_set_access_flags\(struct vm_area_struct \*vma,]

Results:
map[Output:arch/arm64/include/asm/pgtable.h=1897=static inline void ptep_set_wrprotect(struct mm_struct *mm,
--
arch/arm64/include/asm/pgtable.h-1903-#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
arch/arm64/include/asm/pgtable.h:1904:static inline int ptep_set_access_flags(struct vm_area_struct *vma,
arch/arm64/include/asm/pgtable.h-1905-				unsigned long addr, pte_t *ptep,
--
arch/mips/include/asm/pgtable.h=488=static inline int pte_same(pte_t pte_a, pte_t pte_b)
--
arch/mips/include/asm/pgtable.h-493-#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
arch/mips/include/asm/pgtable.h:494:static inline int ptep_set_access_flags(struct vm_area_struct *vma,
arch/mips/include/asm/pgtable.h-495-					unsigned long address, pte_t *ptep,
--
arch/nios2/include/asm/pgtable.h=281=static inline int pte_same(pte_t pte_a, pte_t pte_b);
--
arch/nios2/include/asm/pgtable.h-283-#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
arch/nios2/include/asm/pgtable.h:284:static inline int ptep_set_access_flags(struct vm_area_struct *vma,
arch/nios2/include/asm/pgtable.h-285-					unsigned long address, pte_t *ptep,
--
arch/powerpc/include/asm/pgtable.h=115=static inline void mark_initmem_nx(void) { }
--
arch/powerpc/include/asm/pgtable.h-118-#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
arch/powerpc/include/asm/pgtable.h:119:int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
arch/powerpc/include/asm/pgtable.h-120-			  pte_t *ptep, pte_t entry, int dirty);
--
arch/powerpc/mm/pgtable.c=239=void unmap_kernel_page(unsigned long va)
--
arch/powerpc/mm/pgtable.c-254- */
arch/powerpc/mm/pgtable.c:255:int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
arch/powerpc/mm/pgtable.c-256-			  pte_t *ptep, pte_t entry, int dirty)
--
arch/riscv/include/asm/pgtable.h=637=static inline void pte_clear(struct mm_struct *mm,
--
arch/riscv/include/asm/pgtable.h-643-#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS	/* defined in mm/pgtable.c */
arch/riscv/include/asm/pgtable.h:644:extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
arch/riscv/include/asm/pgtable.h-645-				 pte_t *ptep, pte_t entry, int dirty);
--
arch/riscv/mm/pgtable.c-7-
arch/riscv/mm/pgtable.c:8:int ptep_set_access_flags(struct vm_area_struct *vma,
arch/riscv/mm/pgtable.c-9-			  unsigned long address, pte_t *ptep,
--
arch/s390/include/asm/pgtable.h=1306=void ptep_reset_dat_prot(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
--
arch/s390/include/asm/pgtable.h-1309-#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
arch/s390/include/asm/pgtable.h:1310:static inline int ptep_set_access_flags(struct vm_area_struct *vma,
arch/s390/include/asm/pgtable.h-1311-					unsigned long addr, pte_t *ptep,
--
arch/x86/include/asm/pgtable.h=1227=struct vm_area_struct;
--
arch/x86/include/asm/pgtable.h-1229-#define  __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
arch/x86/include/asm/pgtable.h:1230:extern int ptep_set_access_flags(struct vm_area_struct *vma,
arch/x86/include/asm/pgtable.h-1231-				 unsigned long address, pte_t *ptep,
--
arch/x86/mm/pgtable.c=376=void pgd_free(struct mm_struct *mm, pgd_t *pgd)
--
arch/x86/mm/pgtable.c-390- */
arch/x86/mm/pgtable.c:391:int ptep_set_access_flags(struct vm_area_struct *vma,
arch/x86/mm/pgtable.c-392-			  unsigned long address, pte_t *ptep,
--
include/linux/pgtable.h=410=static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
--
include/linux/pgtable.h-426-#ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
include/linux/pgtable.h:427:extern int ptep_set_access_flags(struct vm_area_struct *vma,
include/linux/pgtable.h-428-				 unsigned long address, pte_t *ptep,
--
mm/pgtable-generic.c=54=void pmd_clear_bad(pmd_t *pmd)
--
mm/pgtable-generic.c-69- */
mm/pgtable-generic.c:70:int ptep_set_access_flags(struct vm_area_struct *vma,
mm/pgtable-generic.c-71-			  unsigned long address, pte_t *ptep,
]

172/2 2026/05/25 00:34 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 200936
							output: 26
							thoughts: 22
						

Thoughts:
Here's my summary, as though I'm reading and processing the `arch/riscv/mm/pgtable.c` file, starting from line 8:

**Diving into the RISC-V Page Table Implementation**

Alright, let's get started. I'm focusing on `arch/riscv/mm/pgtable.c`, and I'm starting from line 8. My initial goal is to understand the fundamental mechanics of the RISC-V page table structure and how it's being implemented here. I'm immediately interested in the basic definitions and structures—what are the key data types, constants, and macros that define the paging process? I expect this file to be the core of the virtual memory management on this architecture. I'm looking for the essential building blocks: how the virtual address space is mapped to physical memory, the role of page table entries, and the overall hierarchical structure used. I'm anticipating insights into the specifics of RISC-V's Sv39, Sv48, or Sv57 virtual memory systems. I'll be keeping a keen eye out for optimizations, if any, that are specific to RISC-V and that differ from, say, x86 implementations.



173/2 2026/05/25 00:34 tool read-file
0m Args:
map[File:arch/riscv/mm/pgtable.c]

Results:
map[Contents:// SPDX-License-Identifier: GPL-2.0

#include <asm/pgalloc.h>
#include <linux/gfp.h>
#include <linux/kernel.h>
#include <linux/pgtable.h>

int ptep_set_access_flags(struct vm_area_struct *vma,
			  unsigned long address, pte_t *ptep,
			  pte_t entry, int dirty)
{
	if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SVVPTC)) {
		if (!pte_same(ptep_get(ptep), entry)) {
			__set_pte_at(vma->vm_mm, ptep, entry);
			/* Here only not svadu is impacted */
			flush_tlb_page(vma, address);
			return true;
		}

		return false;
	}

	if (!pte_same(ptep_get(ptep), entry))
		__set_pte_at(vma->vm_mm, ptep, entry);
	/*
	 * update_mmu_cache will unconditionally execute, handling both
	 * the case that the PTE changed and the spurious fault case.
	 */
	return true;
}

bool ptep_test_and_clear_young(struct vm_area_struct *vma,
		unsigned long address, pte_t *ptep)
{
	if (!pte_young(ptep_get(ptep)))
		return false;
	return test_and_clear_bit(_PAGE_ACCESSED_OFFSET, &pte_val(*ptep));
}
EXPORT_SYMBOL_GPL(ptep_test_and_clear_young);

#ifdef CONFIG_64BIT
pud_t *pud_offset(p4d_t *p4d, unsigned long address)
{
	if (pgtable_l4_enabled)
		return p4d_pgtable(p4dp_get(p4d)) + pud_index(address);

	return (pud_t *)p4d;
}
EXPORT_SYMBOL_GPL(pud_offset);

p4d_t *p4d_offset(pgd_t *pgd, unsigned long address)
{
	if (pgtable_l5_enabled)
		return pgd_pgtable(pgdp_get(pgd)) + p4d_index(address);

	return (p4d_t *)pgd;
}
EXPORT_SYMBOL_GPL(p4d_offset);
#endif

#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
int p4d_set_huge(p4d_t *p4d, phys_addr_t addr, pgprot_t prot)
{
	return 0;
}

void p4d_clear_huge(p4d_t *p4d)
{
}

int pud_set_huge(pud_t *pud, phys_addr_t phys, pgprot_t prot)
{
	pud_t new_pud = pfn_pud(__phys_to_pfn(phys), prot);

	set_pud(pud, new_pud);
	return 1;
}

int pud_clear_huge(pud_t *pud)
{
	if (!pud_leaf(pudp_get(pud)))
		return 0;
	pud_clear(pud);
	return 1;
}

int pud_free_pmd_page(pud_t *pud, unsigned long addr)
{
	pmd_t *pmd = pud_pgtable(pudp_get(pud));
	int i;

	pud_clear(pud);

	flush_tlb_kernel_range(addr, addr + PUD_SIZE);

	for (i = 0; i < PTRS_PER_PMD; i++) {
		if (!pmd_none(pmd[i])) {
			pte_t *pte = (pte_t *)pmd_page_vaddr(pmd[i]);

			pte_free_kernel(NULL, pte);
		}
	}

	pmd_free(NULL, pmd);

	return 1;
}

int pmd_set_huge(pmd_t *pmd, phys_addr_t phys, pgprot_t prot)
{
	pmd_t new_pmd = pfn_pmd(__phys_to_pfn(phys), prot);

	set_pmd(pmd, new_pmd);
	return 1;
}

int pmd_clear_huge(pmd_t *pmd)
{
	if (!pmd_leaf(pmdp_get(pmd)))
		return 0;
	pmd_clear(pmd);
	return 1;
}

int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)
{
	pte_t *pte = (pte_t *)pmd_page_vaddr(pmdp_get(pmd));

	pmd_clear(pmd);

	flush_tlb_kernel_range(addr, addr + PMD_SIZE);
	pte_free_kernel(NULL, pte);
	return 1;
}

#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
pmd_t pmdp_collapse_flush(struct vm_area_struct *vma,
					unsigned long address, pmd_t *pmdp)
{
	pmd_t pmd = pmdp_huge_get_and_clear(vma->vm_mm, address, pmdp);

	VM_BUG_ON(address & ~HPAGE_PMD_MASK);
	VM_BUG_ON(pmd_trans_huge(pmdp_get(pmdp)));
	/*
	 * When leaf PTE entries (regular pages) are collapsed into a leaf
	 * PMD entry (huge page), a valid non-leaf PTE is converted into a
	 * valid leaf PTE at the level 1 page table.  Since the sfence.vma
	 * forms that specify an address only apply to leaf PTEs, we need a
	 * global flush here.  collapse_huge_page() assumes these flushes are
	 * eager, so just do the fence here.
	 */
	flush_tlb_mm(vma->vm_mm);
	return pmd;
}

pud_t pudp_invalidate(struct vm_area_struct *vma, unsigned long address,
		      pud_t *pudp)
{
	VM_WARN_ON_ONCE(!pud_present(*pudp));
	pud_t old = pudp_establish(vma, address, pudp, pud_mkinvalid(*pudp));

	flush_pud_tlb_range(vma, address, address + HPAGE_PUD_SIZE);
	return old;
}
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */

pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma)
{
	if (vma->vm_flags & VM_SHADOW_STACK)
		return pte_mkwrite_shstk(pte);

	return pte_mkwrite_novma(pte);
}

pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma)
{
	if (vma->vm_flags & VM_SHADOW_STACK)
		return pmd_mkwrite_shstk(pmd);

	return pmd_mkwrite_novma(pmd);
}
]

174/2 2026/05/25 00:34 llm expert
1m Model:
gemini-3.1-pro-preview

Tokens:
							input: 203093
							output: 45
							thoughts: 317
						

Thoughts:
**My Analysis of `ptep_set_access_flags` in RISC-V**

Okay, here's what I'm seeing with this `ptep_set_access_flags` function in the RISC-V implementation. First, it calls `__set_pte_at` with the `vma->vm_mm`, the `ptep`, and the `entry`. That seems straightforward. The key thing I'm noticing is that it *doesn't* call `page_table_check_ptes_set`. And to be sure, `__set_pte_at` *also* doesn't call `page_table_check_ptes_set`.

So, if `ptep_set_access_flags` is modifying the PTE, it's *not* updating the `page_table_check` counter. That's immediately raising a flag. Is this going to be a problem down the line? If all it's doing is flipping the accessed or dirty bits, then the accessibility status of the page, such as `pte_user_accessible_page` and `pte_write` might not change.

However, hang on a second. I remember that `do_wp_page` calls `ptep_set_access_flags` to make a PTE writable. Ah, if it makes it writable, then `pte_write` *definitely* changes from false to true.

But the plot thickens. My understanding of `page_table_check` is that it only tracks `anon_map_count` and `file_map_count`, and those don't seem to be indicative of whether the mapping is writable. That's the real problem. It’s not tracking write permissions in those counters, and this might be a problem.

Wait a second. What does `page_table_check_set` do? It takes a `rw` parameter: `void page_table_check_set(unsigned long pfn, unsigned long pgcnt, bool rw)`. So, if `rw` is true, then maybe it does something else? I should really dig into what that function is doing. I need to understand that `rw` parameter more closely, because it seems like it's going to be key in figuring out if this is actually a bug.



175/2 2026/05/25 00:36 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/page_table_check.c IncludeLines:true Name:page_table_check_set]

Results:
map[SourceCode:  92:	/*
  93:	 * A new entry is added to the page table, increment the counters for that page
  94:	 * verify that it is of correct type and is not being mapped with a different
  95:	 * type to a different process.
  96:	 */
  97:	static void page_table_check_set(unsigned long pfn, unsigned long pgcnt,
  98:					 bool rw)
  99:	{
 100:		struct page_ext_iter iter;
 101:		struct page_ext *page_ext;
 102:		struct page *page;
 103:		bool anon;
 104:	
 105:		if (!pfn_valid(pfn))
 106:			return;
 107:	
 108:		page = pfn_to_page(pfn);
 109:		BUG_ON(PageSlab(page));
 110:		anon = PageAnon(page);
 111:	
 112:		rcu_read_lock();
 113:		for_each_page_ext(page, pgcnt, page_ext, iter) {
 114:			struct page_table_check *ptc = get_page_table_check(page_ext);
 115:	
 116:			if (anon) {
 117:				BUG_ON(atomic_read(&ptc->file_map_count));
 118:				BUG_ON(atomic_inc_return(&ptc->anon_map_count) > 1 && rw);
 119:			} else {
 120:				BUG_ON(atomic_read(&ptc->anon_map_count));
 121:				BUG_ON(atomic_inc_return(&ptc->file_map_count) < 0);
 122:			}
 123:		}
 124:		rcu_read_unlock();
 125:	}
 SourceFile:mm/page_table_check.c]

176/2 2026/05/25 00:36 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 204492
							output: 49
							thoughts: 1120
						

Thoughts:
**Analyzing the Page Table Counter and Potential Double-Counting**

Okay, so I'm thinking about this `page_table_check_set` function and how it increments this counter. If `ptep_set_access_flags` *doesn't* call it, the counter isn't incremented. But hang on, `ptep_set_access_flags` is for *updating* an *existing* PTE. The counter was *already* incremented when the PTE was initially set, right? So, updating shouldn't increment it *again* because it's the same page, or the counter will be double-counted. It makes perfect sense that `ptep_set_access_flags` avoids `page_table_check_ptes_set` in this case.

Now, if `ptep_set_access_flags` makes a PTE writable (rw becomes true) on an anonymous page, `page_table_check_set` checks `BUG_ON(atomic_inc_return(&ptc->anon_map_count) > 1 && rw);`. Since it doesn't call this function, this check is bypassed for `do_wp_page`, and this could potentially create a double count. But `do_wp_page` is for Copy-on-Write, where a *new* page is allocated, and the `set_pte_at_notify` is called, which *does* call `page_table_check_ptes_set`. And if it reuses the *same* page, it calls `ptep_set_access_flags`, so since it's the same page, the counter is already 1, and calling `page_table_check_set` would make the counter 2, triggering the BUG_ON! So it *must* not be called.

Now, I need to make sure that `ptep_get_and_clear` *does* decrement the counter, because there is no decrement anywhere else. I have already checked and it *does* call `page_table_check_pte_clear`.

I also have to consider cases like `pte_clear` and `ptep_clear`. Searching in riscv, `pte_clear` is only for huge page clearing and kernel mappings. `ptep_clear` is the same as `ptep_get_and_clear`, so that is safe as well. Even `ptep_get_and_clear_full` uses `ptep_get_and_clear`. So no problems there.

Okay, let's think about this: Is there *any* other way a page can be unmapped without decrementing this counter? Ah, `tlb_batch_pages_flush` is called during the free and it is mentioned in the bug report. The report shows the crash is happening when the page is FREED. `__page_table_check_zero` crashes because the counter is > 0. This means the page was freed, but the counter is *still* greater than zero. How can a page be freed if the counter is still > 0?

There are two possibilities: 1. The counter was incremented more times than it was decremented, or 2. The page is STILL mapped somewhere! That is the real use-after-free bug!

If the page *is* still mapped somewhere, how could it be freed? Its refcount has to drop to 0, but how could that happen while it is still mapped? Could it be a double put or maybe `folio_put` was called too many times? Or maybe there is a bug in `free_pages_and_swap_cache`?

Wait, `free_pages_and_swap_cache` is called from `__tlb_batch_free_encoded_pages`. This is part of the normal TLB flush batching! Pages are unmapped and added to the TLB batch, and then `tlb_flush_mmu` flushes the TLB and frees the pages. If the page is in the TLB batch, it means it *WAS* unmapped. If it was unmapped, `ptep_get_and_clear` *must* have been called! And if `ptep_get_and_clear` was called, `page_table_check_pte_clear` *must* have been called! So the counter *must* have been decremented! So the question is: Why is the counter still > 0?

Could `ptep_get_and_clear` have been called, but `pte_user_accessible_page` returned FALSE? Well, `PAGE_NONE` would return FALSE, but if it *was* `PAGE_NONE` when SET, then it would have been FALSE when unmapped as well,


177/2 2026/05/25 00:36 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:ptep_set_wrprotect]

Results:
map[SourceCode:1271:	static inline void ptep_set_wrprotect(struct mm_struct *mm,
1272:					      unsigned long addr, pte_t *ptep)
1273:	{
1274:		/*
1275:		 * Avoid accidentally creating shadow stack PTEs
1276:		 * (Write=0,Dirty=1).  Use cmpxchg() to prevent races with
1277:		 * the hardware setting Dirty=1.
1278:		 */
1279:		pte_t old_pte, new_pte;
1280:	
1281:		old_pte = READ_ONCE(*ptep);
1282:		do {
1283:			new_pte = pte_wrprotect(old_pte);
1284:		} while (!try_cmpxchg((long *)&ptep->pte, (long *)&old_pte, *(long *)&new_pte));
1285:	}
 SourceFile:arch/x86/include/asm/pgtable.h]

178/2 2026/05/25 00:36 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 206971
							output: 29
							thoughts: 52
						

Thoughts:
**Investigating Potential Protection Mechanisms**

Okay, so the code search gave me a hit in `arch/x86/include/asm/pgtable.h`. Interesting. Now, I need to see if there's a similar function or concept in the RISC-V architecture. My immediate thought is to look at the `ptep_set_wrprotect` function, and that's likely where the solution lies. I need to check the corresponding `arch/riscv/include/asm/pgtable.h` file to see how they handle write protection at the page table entry level.



179/2 2026/05/25 00:36 tool grepper
0m Args:
map[Expression:ptep_set_wrprotect\(struct mm_struct \*mm,]

Results:
map[Output:arch/arm64/include/asm/hugetlb.h=45=extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
--
arch/arm64/include/asm/hugetlb.h-47-#define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
arch/arm64/include/asm/hugetlb.h:48:extern void huge_ptep_set_wrprotect(struct mm_struct *mm,
arch/arm64/include/asm/hugetlb.h-49-				    unsigned long addr, pte_t *ptep);
--
arch/arm64/include/asm/pgtable.h=1417=static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
--
arch/arm64/include/asm/pgtable.h-1423-
arch/arm64/include/asm/pgtable.h:1424:static inline void ___ptep_set_wrprotect(struct mm_struct *mm,
arch/arm64/include/asm/pgtable.h-1425-					unsigned long address, pte_t *ptep,
--
arch/arm64/include/asm/pgtable.h-1441- */
arch/arm64/include/asm/pgtable.h:1442:static inline void __ptep_set_wrprotect(struct mm_struct *mm,
arch/arm64/include/asm/pgtable.h-1443-					unsigned long address, pte_t *ptep)
--
arch/arm64/include/asm/pgtable.h=1873=static __always_inline void wrprotect_ptes(struct mm_struct *mm,
--
arch/arm64/include/asm/pgtable.h-1896-#define __HAVE_ARCH_PTEP_SET_WRPROTECT
arch/arm64/include/asm/pgtable.h:1897:static inline void ptep_set_wrprotect(struct mm_struct *mm,
arch/arm64/include/asm/pgtable.h-1898-				unsigned long addr, pte_t *ptep)
--
arch/arm64/mm/hugetlbpage.c=420=int huge_ptep_set_access_flags(struct vm_area_struct *vma,
--
arch/arm64/mm/hugetlbpage.c-452-
arch/arm64/mm/hugetlbpage.c:453:void huge_ptep_set_wrprotect(struct mm_struct *mm,
arch/arm64/mm/hugetlbpage.c-454-			     unsigned long addr, pte_t *ptep)
--
arch/microblaze/include/asm/pgtable.h=335=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
--
arch/microblaze/include/asm/pgtable.h-340-
arch/microblaze/include/asm/pgtable.h:341:/*static inline void ptep_set_wrprotect(struct mm_struct *mm,
arch/microblaze/include/asm/pgtable.h-342-		unsigned long addr, pte_t *ptep)
--
arch/parisc/include/asm/hugetlb.h=16=static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
--
arch/parisc/include/asm/hugetlb.h-22-#define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
arch/parisc/include/asm/hugetlb.h:23:void huge_ptep_set_wrprotect(struct mm_struct *mm,
arch/parisc/include/asm/hugetlb.h-24-					   unsigned long addr, pte_t *ptep);
--
arch/parisc/include/asm/pgtable.h=457=struct mm_struct;
arch/parisc/include/asm/pgtable.h:458:static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
arch/parisc/include/asm/pgtable.h-459-{
--
arch/parisc/mm/hugetlbpage.c=128=pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
--
arch/parisc/mm/hugetlbpage.c-139-
arch/parisc/mm/hugetlbpage.c:140:void huge_ptep_set_wrprotect(struct mm_struct *mm,
arch/parisc/mm/hugetlbpage.c-141-				unsigned long addr, pte_t *ptep)
--
arch/powerpc/include/asm/book3s/32/pgtable.h=312=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
--
arch/powerpc/include/asm/book3s/32/pgtable.h-322-#define __HAVE_ARCH_PTEP_SET_WRPROTECT
arch/powerpc/include/asm/book3s/32/pgtable.h:323:static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
arch/powerpc/include/asm/book3s/32/pgtable.h-324-				      pte_t *ptep)
--
arch/powerpc/include/asm/book3s/64/pgtable.h=396=static inline int pte_read(pte_t pte)
--
arch/powerpc/include/asm/book3s/64/pgtable.h-401-#define __HAVE_ARCH_PTEP_SET_WRPROTECT
arch/powerpc/include/asm/book3s/64/pgtable.h:402:static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
arch/powerpc/include/asm/book3s/64/pgtable.h-403-				      pte_t *ptep)
--
arch/powerpc/include/asm/book3s/64/pgtable.h-409-#define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
arch/powerpc/include/asm/book3s/64/pgtable.h:410:static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
arch/powerpc/include/asm/book3s/64/pgtable.h-411-					   unsigned long addr, pte_t *ptep)
--
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h=31=static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
--
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-37-#define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h:38:static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-39-					   unsigned long addr, pte_t *ptep)
--
arch/powerpc/include/asm/nohash/32/pte-8xx.h=122=static inline pte_basic_t pte_update(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
--
arch/powerpc/include/asm/nohash/32/pte-8xx.h-124-
arch/powerpc/include/asm/nohash/32/pte-8xx.h:125:static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
arch/powerpc/include/asm/nohash/32/pte-8xx.h-126-{
--
arch/powerpc/include/asm/nohash/64/pgtable.h=143=static inline void p4d_set(p4d_t *p4dp, unsigned long val)
--
arch/powerpc/include/asm/nohash/64/pgtable.h-148-#define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
arch/powerpc/include/asm/nohash/64/pgtable.h:149:static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
arch/powerpc/include/asm/nohash/64/pgtable.h-150-					   unsigned long addr, pte_t *ptep)
--
arch/powerpc/include/asm/nohash/pgtable.h=104=static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
--
arch/powerpc/include/asm/nohash/pgtable.h-115-#ifndef ptep_set_wrprotect
arch/powerpc/include/asm/nohash/pgtable.h:116:static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
arch/powerpc/include/asm/nohash/pgtable.h-117-				      pte_t *ptep)
--
arch/riscv/include/asm/hugetlb.h=35=pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
--
arch/riscv/include/asm/hugetlb.h-38-#define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
arch/riscv/include/asm/hugetlb.h:39:void huge_ptep_set_wrprotect(struct mm_struct *mm,
arch/riscv/include/asm/hugetlb.h-40-			     unsigned long addr, pte_t *ptep);
--
arch/riscv/include/asm/pgtable.h=651=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
--
arch/riscv/include/asm/pgtable.h-667-#define __HAVE_ARCH_PTEP_SET_WRPROTECT
arch/riscv/include/asm/pgtable.h:668:static inline void ptep_set_wrprotect(struct mm_struct *mm,
arch/riscv/include/asm/pgtable.h-669-				      unsigned long address, pte_t *ptep)
--
arch/riscv/mm/hugetlbpage.c=305=pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
--
arch/riscv/mm/hugetlbpage.c-320-
arch/riscv/mm/hugetlbpage.c:321:void huge_ptep_set_wrprotect(struct mm_struct *mm,
arch/riscv/mm/hugetlbpage.c-322-			     unsigned long addr,
--
arch/s390/include/asm/hugetlb.h=58=static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
--
arch/s390/include/asm/hugetlb.h-71-#define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
arch/s390/include/asm/hugetlb.h:72:static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
arch/s390/include/asm/hugetlb.h-73-					   unsigned long addr, pte_t *ptep)
--
arch/s390/include/asm/pgtable.h=1226=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
--
arch/s390/include/asm/pgtable.h-1261-#define __HAVE_ARCH_PTEP_SET_WRPROTECT
arch/s390/include/asm/pgtable.h:1262:static inline void ptep_set_wrprotect(struct mm_struct *mm,
arch/s390/include/asm/pgtable.h-1263-				      unsigned long addr, pte_t *ptep)
--
arch/sparc/include/asm/hugetlb.h=26=static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
--
arch/sparc/include/asm/hugetlb.h-32-#define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
arch/sparc/include/asm/hugetlb.h:33:static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
arch/sparc/include/asm/hugetlb.h-34-					   unsigned long addr, pte_t *ptep)
--
arch/x86/include/asm/pgtable.h=1252=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
--
arch/x86/include/asm/pgtable.h-1270-#define __HAVE_ARCH_PTEP_SET_WRPROTECT
arch/x86/include/asm/pgtable.h:1271:static inline void ptep_set_wrprotect(struct mm_struct *mm,
arch/x86/include/asm/pgtable.h-1272-				      unsigned long addr, pte_t *ptep)
--
arch/xtensa/include/asm/pgtable.h=325=static inline void
arch/xtensa/include/asm/pgtable.h:326:ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
arch/xtensa/include/asm/pgtable.h-327-{
--
include/asm-generic/hugetlb.h=94=static inline int huge_pte_none(pte_t pte)
--
include/asm-generic/hugetlb.h-100-#ifndef __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
include/asm-generic/hugetlb.h:101:static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
include/asm-generic/hugetlb.h-102-		unsigned long addr, pte_t *ptep)
--
include/linux/pgtable.h=1031=struct mm_struct;
include/linux/pgtable.h:1032:static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long address, pte_t *ptep)
include/linux/pgtable.h-1033-{
]

180/2 2026/05/25 00:36 llm expert
1m Model:
gemini-3.1-pro-preview

Tokens:
							input: 210992
							output: 49
							thoughts: 29
						

Thoughts:
Here's my take on the thought process, as if it were my own:

**Diving into the RISC-V Page Table Details**

Alright, let's get down to brass tacks. I need to understand how write protection is managed on RISC-V, and the best place to start is the low-level definitions. Let's dig into `arch/riscv/include/asm/pgtable.h`. Specifically, I want to zero in on that `ptep_set_wrprotect` macro. It’s the key. I know where to find the source code, now I am ready to crack into it and see how the bits and bytes are being manipulated at the page table entry level to achieve this. From there, I'll be able to build a more solid mental model of how the write protection mechanism works.



181/2 2026/05/25 00:37 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:ptep_set_wrprotect]

Results:
map[SourceCode:1271:	static inline void ptep_set_wrprotect(struct mm_struct *mm,
1272:					      unsigned long addr, pte_t *ptep)
1273:	{
1274:		/*
1275:		 * Avoid accidentally creating shadow stack PTEs
1276:		 * (Write=0,Dirty=1).  Use cmpxchg() to prevent races with
1277:		 * the hardware setting Dirty=1.
1278:		 */
1279:		pte_t old_pte, new_pte;
1280:	
1281:		old_pte = READ_ONCE(*ptep);
1282:		do {
1283:			new_pte = pte_wrprotect(old_pte);
1284:		} while (!try_cmpxchg((long *)&ptep->pte, (long *)&old_pte, *(long *)&new_pte));
1285:	}
 SourceFile:arch/x86/include/asm/pgtable.h]

182/2 2026/05/25 00:37 llm expert-compressor
7m Model:
gemini-3-flash-preview

Reply:
Based on the execution history, here is a comprehensive summary of the investigation into the kernel bug:

### 1. Approaches Tried and Results
- **Initial Code Inspection:** The agent started by examining the crash location in `__page_table_check_zero` (`mm/page_table_check.c:142`). The `BUG_ON` triggers when a page is being freed but its `anon_map_count` or `file_map_count` is not zero, indicating that the kernel believes the page is still mapped in a user page table.
- **Configuration Analysis:** The agent verified that `CONFIG_PAGE_TABLE_CHECK` is enabled, which synchronously tracks user page mappings to detect leaks, double mappings, and corruptions.
- **Git Log & Commit History:** The agent searched the git history for `page_table_check` and `riscv` related fixes. It found several relevant commits:
  - `00de2c9f26b1` ("arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()"): This commit highlighted a known issue where using `pte_clear()` bypasses `page_table_check` tracking, causing false positives (map counts not decrementing).
  - `83d78ac677b9` ("riscv: Fix hugetlb retrieval of number of ptes in case of !present pte"): This commit fixed an issue where `huge_ptep_get_and_clear` and `huge_pte_clear` would incorrectly calculate the number of PTEs to clear if the PTE was not present (e.g., a swap or migration PTE), leading to only 1 PTE being cleared instead of the full NAPOT block (e.g., 16 PTEs).
- **Architecture-Specific Code Review (RISC-V):** The agent extensively reviewed `arch/riscv/mm/hugetlbpage.c` and `arch/riscv/include/asm/pgtable.h` to understand how RISC-V handles HugeTLB and NAPOT (contiguous) PTEs. It verified whether `pte_clear`, `ptep_get_and_clear`, `set_huge_pte_at`, and `huge_ptep_clear_flush` correctly hook into `page_table_check`.

### 2. Current Hypotheses and Active Lines of Investigation
The core hypothesis is that a **PTE is being cleared or overwritten without notifying `page_table_check`**, leaving a dangling map count that triggers the `BUG_ON` when the physical page is eventually freed. 

Active lines of investigation include:
- **The `huge_pte_clear` bypass:** In RISC-V, `huge_pte_clear` directly calls `pte_clear(mm, addr, ptep)`. Unlike `ptep_get_and_clear`, `pte_clear` does *not* call `page_table_check_pte_clear`. If `huge_pte_clear` is ever called on a *present* user PTE, the map count will leak. While generic MM code (like `__unmap_hugepage_range`) usually only calls `huge_pte_clear` on non-present PTEs (where map count is already 0), any edge case where it hits a present PTE would perfectly explain the bug.
- **NAPOT HugeTLB Map Count Imbalance:** For a 64KB NAPOT huge page, 16 identical PTEs are written. `set_huge_pte_at` calls `set_pte_at` 16 times, incrementing the base PFN's map count by 16. When unmapped, `huge_ptep_get_and_clear` calls `ptep_get_and_clear` 16 times, decrementing it by 16. The agent is actively verifying if any path (like migration, HWPoison, or `huge_ptep_set_access_flags`) breaks this symmetry.
- **The `!pte_present` NAPOT Bug:** As highlighted by commit `83d78ac677b9`, if a NAPOT PTE becomes non-present (e.g., during migration), `pte_napot()` might return false. This causes `huge_ptep_get_and_clear` to only clear 1 PTE instead of 16, leaving 15 garbage PTEs in the page table. If these garbage PTEs are later overwritten by a new mapping without being properly cleared, it could corrupt the map count.

### 3. Critical Code Snippets and File Paths
- **`mm/page_table_check.c`**: `__page_table_check_zero()` (the crash site) and `__page_table_check_ptes_set()`.
- **`arch/riscv/mm/hugetlbpage.c`**: 
  - `set_huge_pte_at()`: Loops `pte_num` times calling `set_pte_at()`.
  - `huge_pte_clear()`: Loops calling `pte_clear()`, which bypasses page table checks.
  - `huge_ptep_get_and_clear()`: Relies on `pte_napot(orig_pte)` to decide whether to clear 1 or 16 PTEs.
- **`arch/riscv/include/asm/pgtable.h`**: 
  - `pte_clear()`: Implemented as `__set_pte_at(mm, ptep, __pte(0));` (bypasses checks).
  - `ptep_get_and_clear()`: Correctly calls `page_table_check_pte_clear()`.

### 4. Potential Reasoning Loops or Repetitive Tool Calls
- The agent spent a significant amount of time repeatedly grepping for `pte_clear(`, `pmd_clear(`, and `ptep_set_access_flags(` across the entire kernel tree. While thorough, this resulted in massive, truncated outputs that consumed context window space.
- The agent is slightly looping on verifying whether `huge_pte_clear` is ever called on a present PTE. It confirmed multiple times that `mm/hugetlb.c` only calls it on non-present PTEs (markers), but keeps returning to it because `pte_clear` is the most obvious culprit for bypassing `page_table_check`. Future steps should focus strictly on edge cases (like migration failures or THP splits) rather than generic unmap paths.

Tokens:
							input: 186833
							output: 1429
							thoughts: 62917
						

183/2 2026/05/25 00:45 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 9003
							output: 46
							thoughts: 238
						

Thoughts:
**Analyzing a Memory Management Bug**

Okay, so we have a pretty nasty kernel bug, a `BUG` actually, specifically in `mm/page_table_check.c` at line 142. My initial reaction is, this is a serious issue that needs immediate attention. The stack trace is quite long and convoluted but let's break it down: It looks like the crash originates in `__page_table_check_zero` which is called from `page_table_check_free`. Digging further, the call chain goes down through memory freeing routines, specifically `free_unref_folios` and `free_pages_and_swap_cache` before ending in `do_exit`, meaning it happens when a process is exiting. The fact that the architecture is RISC-V (`riscv-virtio,qemu`) is relevant too, this may be specific to that architecture's memory management implementations, or at least a specific usage of it.

The root cause seems to be that a page is being freed, but there's a disconnect. The page table check logic thinks the page is still in use (`anon_map_count` or `file_map_count` is not zero). This is a classical memory corruption issue, an attempt to free memory that shouldn't be freed. This inconsistency is going to cause real problems down the line, so the next thing I'm doing is checking `mm/page_table_check.c:142` directly to get the low-down.



184/2 2026/05/25 00:45 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/page_table_check.c IncludeLines:true Name:__page_table_check_zero]

Results:
map[SourceCode: 127:	/*
 128:	 * page is on free list, or is being allocated, verify that counters are zeroes
 129:	 * crash if they are not.
 130:	 */
 131:	void __page_table_check_zero(struct page *page, unsigned int order)
 132:	{
 133:		struct page_ext_iter iter;
 134:		struct page_ext *page_ext;
 135:	
 136:		BUG_ON(PageSlab(page));
 137:	
 138:		rcu_read_lock();
 139:		for_each_page_ext(page, 1 << order, page_ext, iter) {
 140:			struct page_table_check *ptc = get_page_table_check(page_ext);
 141:	
 142:			BUG_ON(atomic_read(&ptc->anon_map_count));
 143:			BUG_ON(atomic_read(&ptc->file_map_count));
 144:		}
 145:		rcu_read_unlock();
 146:	}
 SourceFile:mm/page_table_check.c]

185/2 2026/05/25 00:45 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 9948
							output: 26
							thoughts: 201
						

Thoughts:
**Analyzing a Potential Memory Corruption Scenario**

Okay, so I'm diving into this `BUG_ON` assertion on line 142 related to `ptc->anon_map_count`. My initial thought is that this is a critical check for maintaining the integrity of anonymous page table entries. The goal is to ensure that a specific counter associated with these entries remains consistent, and this bug is triggered when a discrepancy occurs.

Now, I need to understand what could possibly violate this constraint. My analysis has to actively verify if any code paths – specifically migration, hardware poisoning, or `huge_ptep_set_access_flags` – could break this fundamental symmetry. These are the areas where memory mappings are most dynamically altered, so they are the likely culprits.

I'm particularly interested in the interaction with Non-Aligned Power-of-Two (NAPOT) PTEs. The text mentions a specific bug related to NAPOT PTEs going non-present. The core of the problem, highlighted in commit `83d78ac677b9`, is that if a NAPOT PTE becomes non-present, `pte_napot()` might return false. This is a critical edge case. The consequence is that `huge_ptep_get_and_clear` – the mechanism for managing large page entries – might end up clearing only one PTE instead of the expected sixteen. This leaves fifteen garbage PTEs in the page table. These stale PTEs, if not cleared and subsequently overwritten by a new mapping, represent a direct path to memory corruption, and that's the scenario I am trying to resolve. I need to fully understand how this commit addresses (or fails to address) this potential issue. I should dig deeper into that commit to see what it did and didn't cover.



186/2 2026/05/25 00:45 tool git-show
0m Args:
map[Commit:83d78ac677b9]

Results:
map[Output:commit 83d78ac677b9fdd8ea763507c6fe02d6bf415f3a
Author: Alexandre Ghiti <alexghiti@rivosinc.com>
Date:   Mon Mar 17 08:25:51 2025 +0100

    riscv: Fix hugetlb retrieval of number of ptes in case of !present pte
    
    Ryan sent a fix [1] for arm64 that applies to riscv too: in some hugetlb
    functions, we must not use the pte value to get the size of a mapping
    because the pte may not be present.
    
    So use the already present size parameter for huge_pte_clear() and the
    newly introduced size parameter for huge_ptep_get_and_clear(). And make
    sure to gather A/D bits only on present ptes.
    
    Fixes: 82a1a1f3bfb6 ("riscv: mm: support Svnapot in hugetlb page")
    Link: https://lore.kernel.org/all/20250217140419.1702389-1-ryan.roberts@arm.com/ [1]
    Link: https://lore.kernel.org/r/20250317072551.572169-1-alexghiti@rivosinc.com
    Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>

diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c
index b4a78a4b35cf..375dd96bb4a0 100644
--- a/arch/riscv/mm/hugetlbpage.c
+++ b/arch/riscv/mm/hugetlbpage.c
@@ -148,22 +148,25 @@ unsigned long hugetlb_mask_last_page(struct hstate *h)
 static pte_t get_clear_contig(struct mm_struct *mm,
 			      unsigned long addr,
 			      pte_t *ptep,
-			      unsigned long pte_num)
+			      unsigned long ncontig)
 {
-	pte_t orig_pte = ptep_get(ptep);
-	unsigned long i;
-
-	for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++) {
-		pte_t pte = ptep_get_and_clear(mm, addr, ptep);
-
-		if (pte_dirty(pte))
-			orig_pte = pte_mkdirty(orig_pte);
-
-		if (pte_young(pte))
-			orig_pte = pte_mkyoung(orig_pte);
+	pte_t pte, tmp_pte;
+	bool present;
+
+	pte = ptep_get_and_clear(mm, addr, ptep);
+	present = pte_present(pte);
+	while (--ncontig) {
+		ptep++;
+		addr += PAGE_SIZE;
+		tmp_pte = ptep_get_and_clear(mm, addr, ptep);
+		if (present) {
+			if (pte_dirty(tmp_pte))
+				pte = pte_mkdirty(pte);
+			if (pte_young(tmp_pte))
+				pte = pte_mkyoung(pte);
+		}
 	}
-
-	return orig_pte;
+	return pte;
 }
 
 static pte_t get_clear_contig_flush(struct mm_struct *mm,
@@ -212,6 +215,26 @@ static void clear_flush(struct mm_struct *mm,
 	flush_tlb_range(&vma, saddr, addr);
 }
 
+static int num_contig_ptes_from_size(unsigned long sz, size_t *pgsize)
+{
+	unsigned long hugepage_shift;
+
+	if (sz >= PGDIR_SIZE)
+		hugepage_shift = PGDIR_SHIFT;
+	else if (sz >= P4D_SIZE)
+		hugepage_shift = P4D_SHIFT;
+	else if (sz >= PUD_SIZE)
+		hugepage_shift = PUD_SHIFT;
+	else if (sz >= PMD_SIZE)
+		hugepage_shift = PMD_SHIFT;
+	else
+		hugepage_shift = PAGE_SHIFT;
+
+	*pgsize = 1 << hugepage_shift;
+
+	return sz >> hugepage_shift;
+}
+
 /*
  * When dealing with NAPOT mappings, the privileged specification indicates that
  * "if an update needs to be made, the OS generally should first mark all of the
@@ -226,22 +249,10 @@ void set_huge_pte_at(struct mm_struct *mm,
 		     pte_t pte,
 		     unsigned long sz)
 {
-	unsigned long hugepage_shift, pgsize;
+	size_t pgsize;
 	int i, pte_num;
 
-	if (sz >= PGDIR_SIZE)
-		hugepage_shift = PGDIR_SHIFT;
-	else if (sz >= P4D_SIZE)
-		hugepage_shift = P4D_SHIFT;
-	else if (sz >= PUD_SIZE)
-		hugepage_shift = PUD_SHIFT;
-	else if (sz >= PMD_SIZE)
-		hugepage_shift = PMD_SHIFT;
-	else
-		hugepage_shift = PAGE_SHIFT;
-
-	pte_num = sz >> hugepage_shift;
-	pgsize = 1 << hugepage_shift;
+	pte_num = num_contig_ptes_from_size(sz, &pgsize);
 
 	if (!pte_present(pte)) {
 		for (i = 0; i < pte_num; i++, ptep++, addr += pgsize)
@@ -295,13 +306,14 @@ pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
 			      unsigned long addr,
 			      pte_t *ptep, unsigned long sz)
 {
+	size_t pgsize;
 	pte_t orig_pte = ptep_get(ptep);
 	int pte_num;
 
 	if (!pte_napot(orig_pte))
 		return ptep_get_and_clear(mm, addr, ptep);
 
-	pte_num = napot_pte_num(napot_cont_order(orig_pte));
+	pte_num = num_contig_ptes_from_size(sz, &pgsize);
 
 	return get_clear_contig(mm, addr, ptep, pte_num);
 }
@@ -351,6 +363,7 @@ void huge_pte_clear(struct mm_struct *mm,
 		    pte_t *ptep,
 		    unsigned long sz)
 {
+	size_t pgsize;
 	pte_t pte = ptep_get(ptep);
 	int i, pte_num;
 
@@ -359,8 +372,9 @@ void huge_pte_clear(struct mm_struct *mm,
 		return;
 	}
 
-	pte_num = napot_pte_num(napot_cont_order(pte));
-	for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++)
+	pte_num = num_contig_ptes_from_size(sz, &pgsize);
+
+	for (i = 0; i < pte_num; i++, addr += pgsize, ptep++)
 		pte_clear(mm, addr, ptep);
 }
 
]

187/2 2026/05/25 00:45 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 12561
							output: 23
							thoughts: 252
						

Thoughts:
**Investigating a Potential PTE Clearing Issue in RISC-V**

Okay, so I'm looking at `huge_pte_clear` and I see it's using `pte_clear(mm, addr, ptep)`. Now, that's immediately raising a red flag. Digging into `arch/riscv/include/asm/pgtable.h`, I find `pte_clear` is simply a macro: `#define pte_clear(mm, addr, ptep) __set_pte_at(mm, ptep, __pte(0))`. And crucially, it *doesn't* appear to call `page_table_check_pte_clear`.

This feels familiar... I vaguely recall a similar issue being addressed in arm64 – wasn't it commit `00de2c9f26b1` ("arm64: mm: use ptep_clear() instead of pte_clear() in clear_flush()")? Right, it was! That's concerning. I need to figure out if `huge_pte_clear` in the RISC-V code is potentially being called on present PTEs. That would indicate a similar oversight.

Let's see... in `mm/hugetlb.c`, `huge_pte_clear` is part of the huge page unmapping process, right? Okay, so `huge_pte_clear` is used by `__unmap_hugepage_range`, isn't it? Hmm, no, wait... `__unmap_hugepage_range` calls `huge_ptep_get_and_clear`. Then where *is* `huge_pte_clear` actually used? I need to track down all the call sites to be sure this isn't a lurking bug.



188/2 2026/05/25 00:45 tool codesearch-find-references
0m Args:
map[Name:huge_pte_clear]

Results:
map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:__unmap_hugepage_range SourceFile:mm/hugetlb.c SourceLine:5221] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:hugetlb_change_protection SourceFile:mm/hugetlb.c SourceLine:6507] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:move_huge_pte SourceFile:mm/hugetlb.c SourceLine:5075]] TruncatedOutput:false]

189/2 2026/05/25 00:45 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 13397
							output: 44
							thoughts: 29
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Diving into Hugepage Unmapping**

Okay, so I need to understand what's happening when we unmap a hugepage range. Let's start with `__unmap_hugepage_range`. I know that's the core function for this task. I need to refresh my memory on the low-level details of how this function interacts with the MMU and the page tables. Right, that's defined in `mm/hugetlb.c` - it's a good place to start digging into the implementation. Line 5221 should be a good entry point to start the analysis of the code. Let's see what's what. I'm expecting to see calls to functions that handle page table invalidation, TLB shootdowns, and potentially some accounting for freed memory or any associated metadata. Let's see what the code has to say.



190/2 2026/05/25 00:45 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/hugetlb.c IncludeLines:true Name:__unmap_hugepage_range]

Results:
map[SourceCode:5156:	void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
5157:				    unsigned long start, unsigned long end,
5158:				    struct folio *folio, zap_flags_t zap_flags)
5159:	{
5160:		struct mm_struct *mm = vma->vm_mm;
5161:		const bool folio_provided = !!folio;
5162:		unsigned long address;
5163:		pte_t *ptep;
5164:		pte_t pte;
5165:		spinlock_t *ptl;
5166:		struct hstate *h = hstate_vma(vma);
5167:		unsigned long sz = huge_page_size(h);
5168:		bool adjust_reservation;
5169:		unsigned long last_addr_mask;
5170:	
5171:		WARN_ON(!is_vm_hugetlb_page(vma));
5172:		BUG_ON(start & ~huge_page_mask(h));
5173:		BUG_ON(end & ~huge_page_mask(h));
5174:	
5175:		/*
5176:		 * This is a hugetlb vma, all the pte entries should point
5177:		 * to huge page.
5178:		 */
5179:		tlb_change_page_size(tlb, sz);
5180:		tlb_start_vma(tlb, vma);
5181:	
5182:		last_addr_mask = hugetlb_mask_last_page(h);
5183:		address = start;
5184:		for (; address < end; address += sz) {
5185:			ptep = hugetlb_walk(vma, address, sz);
5186:			if (!ptep) {
5187:				address |= last_addr_mask;
5188:				continue;
5189:			}
5190:	
5191:			ptl = huge_pte_lock(h, mm, ptep);
5192:			if (huge_pmd_unshare(tlb, vma, address, ptep)) {
5193:				spin_unlock(ptl);
5194:				address |= last_addr_mask;
5195:				continue;
5196:			}
5197:	
5198:			pte = huge_ptep_get(mm, address, ptep);
5199:			if (huge_pte_none(pte)) {
5200:				spin_unlock(ptl);
5201:				continue;
5202:			}
5203:	
5204:			/*
5205:			 * Migrating hugepage or HWPoisoned hugepage is already
5206:			 * unmapped and its refcount is dropped, so just clear pte here.
5207:			 */
5208:			if (unlikely(!pte_present(pte))) {
5209:				/*
5210:				 * If the pte was wr-protected by uffd-wp in any of the
5211:				 * swap forms, meanwhile the caller does not want to
5212:				 * drop the uffd-wp bit in this zap, then replace the
5213:				 * pte with a marker.
5214:				 */
5215:				if (pte_swp_uffd_wp_any(pte) &&
5216:				    !(zap_flags & ZAP_FLAG_DROP_MARKER))
5217:					set_huge_pte_at(mm, address, ptep,
5218:							make_pte_marker(PTE_MARKER_UFFD_WP),
5219:							sz);
5220:				else
5221:					huge_pte_clear(mm, address, ptep, sz);
5222:				spin_unlock(ptl);
5223:				continue;
5224:			}
5225:	
5226:			/*
5227:			 * If a folio is supplied, it is because a specific
5228:			 * folio is being unmapped, not a range. Ensure the folio we
5229:			 * are about to unmap is the actual folio of interest.
5230:			 */
5231:			if (folio_provided) {
5232:				if (folio != page_folio(pte_page(pte))) {
5233:					spin_unlock(ptl);
5234:					continue;
5235:				}
5236:				/*
5237:				 * Mark the VMA as having unmapped its page so that
5238:				 * future faults in this VMA will fail rather than
5239:				 * looking like data was lost
5240:				 */
5241:				set_vma_resv_flags(vma, HPAGE_RESV_UNMAPPED);
5242:			} else {
5243:				folio = page_folio(pte_page(pte));
5244:			}
5245:	
5246:			pte = huge_ptep_get_and_clear(mm, address, ptep, sz);
5247:			tlb_remove_huge_tlb_entry(h, tlb, ptep, address);
5248:			if (huge_pte_dirty(pte))
5249:				folio_mark_dirty(folio);
5250:			/* Leave a uffd-wp pte marker if needed */
5251:			if (huge_pte_uffd_wp(pte) &&
5252:			    !(zap_flags & ZAP_FLAG_DROP_MARKER))
5253:				set_huge_pte_at(mm, address, ptep,
5254:						make_pte_marker(PTE_MARKER_UFFD_WP),
5255:						sz);
5256:			hugetlb_count_sub(pages_per_huge_page(h), mm);
5257:			hugetlb_remove_rmap(folio);
5258:			spin_unlock(ptl);
5259:	
5260:			/*
5261:			 * Restore the reservation for anonymous page, otherwise the
5262:			 * backing page could be stolen by someone.
5263:			 * If there we are freeing a surplus, do not set the restore
5264:			 * reservation bit.
5265:			 */
5266:			adjust_reservation = false;
5267:	
5268:			spin_lock_irq(&hugetlb_lock);
5269:			if (!h->surplus_huge_pages && __vma_private_lock(vma) &&
5270:			    folio_test_anon(folio)) {
5271:				folio_set_hugetlb_restore_reserve(folio);
5272:				/* Reservation to be adjusted after the spin lock */
5273:				adjust_reservation = true;
5274:			}
5275:			spin_unlock_irq(&hugetlb_lock);
5276:	
5277:			/*
5278:			 * Adjust the reservation for the region that will have the
5279:			 * reserve restored. Keep in mind that vma_needs_reservation() changes
5280:			 * resv->adds_in_progress if it succeeds. If this is not done,
5281:			 * do_exit() will not see it, and will keep the reservation
5282:			 * forever.
5283:			 */
5284:			if (adjust_reservation) {
5285:				int rc = vma_needs_reservation(h, vma, address);
5286:	
5287:				if (rc < 0)
5288:					/* Pressumably allocate_file_region_entries failed
5289:					 * to allocate a file_region struct. Clear
5290:					 * hugetlb_restore_reserve so that global reserve
5291:					 * count will not be incremented by free_huge_folio.
5292:					 * Act as if we consumed the reservation.
5293:					 */
5294:					folio_clear_hugetlb_restore_reserve(folio);
5295:				else if (rc)
5296:					vma_add_reservation(h, vma, address);
5297:			}
5298:	
5299:			tlb_remove_page_size(tlb, folio_page(folio, 0),
5300:					     folio_size(folio));
5301:			/*
5302:			 * If we were instructed to unmap a specific folio, we're done.
5303:			 */
5304:			if (folio_provided)
5305:				break;
5306:		}
5307:		tlb_end_vma(tlb, vma);
5308:	
5309:		huge_pmd_unshare_flush(tlb, vma);
5310:	}
 SourceFile:mm/hugetlb.c]

191/2 2026/05/25 00:45 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 16119
							output: 49
							thoughts: 206
						

Thoughts:
**Unmapping Huge Pages: A Quick Audit**

Okay, so I'm digging into `__unmap_hugepage_range`, specifically the call to `huge_pte_clear` when `pte_present(pte)` is false. Hold on a second, that feels a bit too simple, doesn't it? What if that PTE isn't *present* in the straightforward sense, but it's *holding* something else? Specifically, what if it's a swap PTE or, even more interestingly, a migration PTE?

Now, about that migration PTE… does it inherently have a map count? I know that when a page is actively migrated – thanks to functions like `try_to_migrate` – the original page is unmapped, and then a migration entry is slotted into its place. The unmapping is handled, if I recall correctly, through functions like `try_to_migrate_one`, which, critically, calls `ptep_get_and_clear` or `huge_ptep_get_and_clear`. Those calls are key; they *decrement* the map count as the page is effectively removed from the current mapping.

Then, the migration entry is put in place, using `set_pte_at` or `set_huge_pte_at`. Here's the core of my uncertainty: does *setting* a PTE to a migration entry somehow increment that map count? Is it supposed to? It seems like it shouldn't, since the page is *being* migrated, not *actively* mapped. To be sure, I need to check how `set_pte_at` is handling migration entries. I think it is time to check `page_table_check_ptes_set`. Time to dig deeper and clarify the map count logic in these migration scenarios.



192/2 2026/05/25 00:45 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/page_table_check.c IncludeLines:true Name:__page_table_check_ptes_set]

Results:
map[SourceCode: 199:	void __page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr,
 200:					 pte_t *ptep, pte_t pte, unsigned int nr)
 201:	{
 202:		unsigned int i;
 203:	
 204:		if (&init_mm == mm)
 205:			return;
 206:	
 207:		page_table_check_pte_flags(pte);
 208:	
 209:		for (i = 0; i < nr; i++)
 210:			__page_table_check_pte_clear(mm, addr + PAGE_SIZE * i, ptep_get(ptep + i));
 211:		if (pte_user_accessible_page(mm, addr, pte))
 212:			page_table_check_set(pte_pfn(pte), nr, pte_write(pte));
 213:	}
 SourceFile:mm/page_table_check.c]

193/2 2026/05/25 00:45 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 17049
							output: 45
							thoughts: 33
						

Thoughts:
Okay, here's my take on those thoughts, framed from my perspective as an expert in this field:

**Checking Page Table Entry Accessibility**

Alright, let's dive into this `pte_user_accessible_page` function. From what I can gather, the core of what we're doing here is verifying if a given Page Table Entry (PTE) is not only present, but also that it's user-accessible. This is a fundamental step, right? We need to make absolutely sure that a user-level process, or a process running in user mode, is actually authorized to access this specific memory location. This is crucial for security and preventing unauthorized memory access. It's essentially a sanity check before we even attempt any operation on that page. It ensures that the kernel isn't handing over access to a page it shouldn't. Makes perfect sense. Let's see how it works internally.



194/2 2026/05/25 00:45 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/page_table_check.c IncludeLines:true Name:pte_user_accessible_page]

Results:
map[SourceCode:1675:	static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
1676:	{
1677:		return (pte_val(pte) & _PAGE_PRESENT) && (pte_val(pte) & _PAGE_USER);
1678:	}
 SourceFile:arch/x86/include/asm/pgtable.h]

195/2 2026/05/25 00:45 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 17444
							output: 49
							thoughts: 27
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**RISC-V Page Table Entry Accessibility Check**

Okay, hold on a second. I need to make sure I'm not making a generalized assumption here. That `pte_user_accessible_page` function—that's architecture-dependent, isn't it? Damn, I need to zoom in and check the RISC-V implementation specifically. I can't just apply a generic understanding here. What are the specific access controls and flags in that architecture’s page table entries that determine user space accessibility? Let's dig into the relevant code and make sure I fully understand the bit-level nuances. No point in making a flawed assumption.



196/2 2026/05/25 00:45 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:pte_user_accessible_page]

Results:
map[SourceCode:1675:	static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
1676:	{
1677:		return (pte_val(pte) & _PAGE_PRESENT) && (pte_val(pte) & _PAGE_USER);
1678:	}
 SourceFile:arch/x86/include/asm/pgtable.h]

197/2 2026/05/25 00:45 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 17800
							output: 21
							thoughts: 21
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Debugging CPU Architecture Identification**

Okay, so I just ran a check, and it looks like the initial identification returned the x86 architecture. Hmm, that's not what I was expecting. It seems the system isn't using the RISC-V instruction set as anticipated. The current result is a default. Let's dig deeper and find that RISC-V implementation. I need to trace back through the code, potentially examine the initialization sequence, and see exactly where the architecture-specific detection logic is getting tripped up. There has to be a way to force or detect the target instruction set here, and right now, it's defaulting to the x86 one. The goal is to either explicitly set the desired architecture, or to modify the underlying detection routine to accurately identify and select RISC-V when available. Time to get down into the weeds.



198/2 2026/05/25 00:45 tool grepper
0m Args:
map[Expression:pte_user_accessible_page]

Results:
map[Output:arch/arm64/include/asm/pgtable.h=1269=static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
--
arch/arm64/include/asm/pgtable.h-1278-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/arm64/include/asm/pgtable.h:1279:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/arm64/include/asm/pgtable.h-1280-{
--
arch/powerpc/include/asm/book3s/32/pgtable.h=426=static inline bool pte_access_permitted(pte_t pte, bool write)
--
arch/powerpc/include/asm/book3s/32/pgtable.h-440-
arch/powerpc/include/asm/book3s/32/pgtable.h:441:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/powerpc/include/asm/book3s/32/pgtable.h-442-{
--
arch/powerpc/include/asm/book3s/64/pgtable.h=537=static inline bool pte_access_permitted(pte_t pte, bool write)
--
arch/powerpc/include/asm/book3s/64/pgtable.h-551-
arch/powerpc/include/asm/book3s/64/pgtable.h:552:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/powerpc/include/asm/book3s/64/pgtable.h-553-{
--
arch/powerpc/include/asm/book3s/64/pgtable.h=928=static inline bool pud_user_accessible_page(struct mm_struct *mm, unsigned long addr, pud_t pud)
arch/powerpc/include/asm/book3s/64/pgtable.h-929-{
arch/powerpc/include/asm/book3s/64/pgtable.h:930:	return pud_leaf(pud) && pte_user_accessible_page(mm, addr, pud_pte(pud));
arch/powerpc/include/asm/book3s/64/pgtable.h-931-}
--
arch/powerpc/include/asm/book3s/64/pgtable.h=1099=static inline bool pmd_user_accessible_page(struct mm_struct *mm, unsigned long addr, pmd_t pmd)
arch/powerpc/include/asm/book3s/64/pgtable.h-1100-{
arch/powerpc/include/asm/book3s/64/pgtable.h:1101:	return pmd_leaf(pmd) && pte_user_accessible_page(mm, addr, pmd_pte(pmd));
arch/powerpc/include/asm/book3s/64/pgtable.h-1102-}
--
arch/powerpc/include/asm/nohash/pgtable.h=237=static inline bool pte_access_permitted(pte_t pte, bool write)
--
arch/powerpc/include/asm/nohash/pgtable.h-251-
arch/powerpc/include/asm/nohash/pgtable.h:252:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/powerpc/include/asm/nohash/pgtable.h-253-{
--
arch/riscv/include/asm/pgtable.h=964=static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
--
arch/riscv/include/asm/pgtable.h-971-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/riscv/include/asm/pgtable.h:972:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/riscv/include/asm/pgtable.h-973-{
--
arch/s390/include/asm/pgtable.h=1803=static inline int has_transparent_hugepage(void)
--
arch/s390/include/asm/pgtable.h-1809-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/s390/include/asm/pgtable.h:1810:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/s390/include/asm/pgtable.h-1811-{
--
arch/x86/include/asm/pgtable.h=1668=static inline bool arch_has_hw_nonleaf_pmd_young(void)
--
arch/x86/include/asm/pgtable.h-1674-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/x86/include/asm/pgtable.h:1675:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/x86/include/asm/pgtable.h-1676-{
--
mm/page_table_check.c=148=void __page_table_check_pte_clear(struct mm_struct *mm, unsigned long addr,
--
mm/page_table_check.c-153-
mm/page_table_check.c:154:	if (pte_user_accessible_page(mm, addr, pte))
mm/page_table_check.c-155-		page_table_check_clear(pte_pfn(pte), PAGE_SIZE >> PAGE_SHIFT);
--
mm/page_table_check.c=199=void __page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr,
--
mm/page_table_check.c-210-		__page_table_check_pte_clear(mm, addr + PAGE_SIZE * i, ptep_get(ptep + i));
mm/page_table_check.c:211:	if (pte_user_accessible_page(mm, addr, pte))
mm/page_table_check.c-212-		page_table_check_set(pte_pfn(pte), nr, pte_write(pte));
]

199/2 2026/05/25 00:45 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 19707
							output: 49
							thoughts: 23
						

Thoughts:
Here's my thought process, summarized as you requested:

**Navigating the Page Table Landscape**

Okay, time to dive into the nitty-gritty. I need to refresh my memory on the page table structures for RISC-V on the architecture level. Specifically, I'm thinking about how the memory management is handled at the hardware level. To do this, I'm going to head to `arch/riscv/include/asm/pgtable.h:972`. That file should give me the core definitions, likely the key data structures and macros involved in translating virtual addresses to physical ones. It's a fundamental spot to gain a clearer picture of how the whole memory system is organized. Hopefully this reveals the key structures I'm looking for.



200/2 2026/05/25 00:45 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:pte_user_accessible_page]

Results:
map[SourceCode:1675:	static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
1676:	{
1677:		return (pte_val(pte) & _PAGE_PRESENT) && (pte_val(pte) & _PAGE_USER);
1678:	}
 SourceFile:arch/x86/include/asm/pgtable.h]

201/2 2026/05/25 00:45 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 20066
							output: 40
							thoughts: 17
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Debugging the Architecture Detection**

Okay, so I'm running this script, expecting it to correctly identify the target architecture, but it's *still* reporting x86. Frustrating! Clearly, something in the detection logic isn't working as intended. Forget the fancy abstractions for a moment. Instead of chasing down potential configuration issues or debugging the detection algorithms, let's cut right to the source. I'm going to bypass all the intermediary steps and just read the binary file directly. That should give me the ground truth information I need to understand what the system *thinks* it is dealing with. My immediate focus is on verifying the reported architecture against what the file headers actually indicate. This seems like the most direct path to root-cause analysis, rather than getting bogged down in complexity at this juncture.



202/2 2026/05/25 00:45 tool grepper
0m Args:
map[Expression:pte_user_accessible_page\(struct mm_struct \*mm, unsigned long addr, pte_t pte\)]

Results:
map[Output:arch/arm64/include/asm/pgtable.h=1269=static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
--
arch/arm64/include/asm/pgtable.h-1278-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/arm64/include/asm/pgtable.h:1279:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/arm64/include/asm/pgtable.h-1280-{
--
arch/powerpc/include/asm/book3s/32/pgtable.h=426=static inline bool pte_access_permitted(pte_t pte, bool write)
--
arch/powerpc/include/asm/book3s/32/pgtable.h-440-
arch/powerpc/include/asm/book3s/32/pgtable.h:441:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/powerpc/include/asm/book3s/32/pgtable.h-442-{
--
arch/powerpc/include/asm/book3s/64/pgtable.h=537=static inline bool pte_access_permitted(pte_t pte, bool write)
--
arch/powerpc/include/asm/book3s/64/pgtable.h-551-
arch/powerpc/include/asm/book3s/64/pgtable.h:552:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/powerpc/include/asm/book3s/64/pgtable.h-553-{
--
arch/powerpc/include/asm/nohash/pgtable.h=237=static inline bool pte_access_permitted(pte_t pte, bool write)
--
arch/powerpc/include/asm/nohash/pgtable.h-251-
arch/powerpc/include/asm/nohash/pgtable.h:252:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/powerpc/include/asm/nohash/pgtable.h-253-{
--
arch/riscv/include/asm/pgtable.h=964=static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
--
arch/riscv/include/asm/pgtable.h-971-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/riscv/include/asm/pgtable.h:972:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/riscv/include/asm/pgtable.h-973-{
--
arch/s390/include/asm/pgtable.h=1803=static inline int has_transparent_hugepage(void)
--
arch/s390/include/asm/pgtable.h-1809-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/s390/include/asm/pgtable.h:1810:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/s390/include/asm/pgtable.h-1811-{
--
arch/x86/include/asm/pgtable.h=1668=static inline bool arch_has_hw_nonleaf_pmd_young(void)
--
arch/x86/include/asm/pgtable.h-1674-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/x86/include/asm/pgtable.h:1675:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/x86/include/asm/pgtable.h-1676-{
]

203/2 2026/05/25 00:46 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 21350
							output: 62
							thoughts: 26
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Diving into the RISC-V Page Table Definitions**

Okay, time to dig into the heart of the RISC-V memory management. I need to understand how the page tables are structured and defined. I'm going to jump straight into `arch/riscv/include/asm/pgtable.h` - specifically, I'm aiming for around line 972. I expect to find the core data structures that map virtual addresses to physical addresses there. I’m thinking this section will define the format of the page table entries (PTEs), which will reveal the address translation process. Hopefully, it’ll be clear how the different levels of the page table are organized and how the hardware walkers use it. I’m also looking for details on any RISC-V specific PTE flags that are relevant, and how they interact. Let's see what the code reveals.



204/2 2026/05/25 00:46 tool grepper
0m Error:
no matches

Args:
map[Expression:-A 5 "static inline bool pte_user_accessible_page(struct mm_struct \*mm, unsigned long addr, pte_t pte)" arch/riscv/include/asm/pgtable.h]

Results:
map[Output:]

205/2 2026/05/25 00:46 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 21657
							output: 44
							thoughts: 8
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:

**Navigating `git grep` Syntax**

Right, *`git grep`*. It always starts with a slight mental pause, doesn't it? Even after all these years, the full range of options isn't instantly at the forefront. I'm usually aiming for something specific, like finding all instances of a function call across the codebase, or maybe just a specific string within a certain directory and file type. So, I'm mentally parsing the possibilities: am I going to use regex, fixed string matching, or a combination? Do I need to exclude certain files or directories, and, if so, which flags will get me there efficiently? Then there's the question of formatting the output. Will the default output suffice, or do I need more context, line numbers, or perhaps just the filenames? Do I need to pipe the results to another tool? Thinking about how to refine the search, and quickly. I'm always looking for ways to streamline my searches, which means getting the syntax right the first time to minimize iterations. It's a powerful tool, but like any command-line utility, it requires a certain finesse to leverage its full potential.



206/2 2026/05/25 00:46 tool grepper
0m Args:
map[Expression:static inline bool pte_user_accessible_page\(struct mm_struct \*mm, unsigned long addr, pte_t pte\)]

Results:
map[Output:arch/arm64/include/asm/pgtable.h=1269=static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
--
arch/arm64/include/asm/pgtable.h-1278-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/arm64/include/asm/pgtable.h:1279:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/arm64/include/asm/pgtable.h-1280-{
--
arch/powerpc/include/asm/book3s/32/pgtable.h=426=static inline bool pte_access_permitted(pte_t pte, bool write)
--
arch/powerpc/include/asm/book3s/32/pgtable.h-440-
arch/powerpc/include/asm/book3s/32/pgtable.h:441:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/powerpc/include/asm/book3s/32/pgtable.h-442-{
--
arch/powerpc/include/asm/book3s/64/pgtable.h=537=static inline bool pte_access_permitted(pte_t pte, bool write)
--
arch/powerpc/include/asm/book3s/64/pgtable.h-551-
arch/powerpc/include/asm/book3s/64/pgtable.h:552:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/powerpc/include/asm/book3s/64/pgtable.h-553-{
--
arch/powerpc/include/asm/nohash/pgtable.h=237=static inline bool pte_access_permitted(pte_t pte, bool write)
--
arch/powerpc/include/asm/nohash/pgtable.h-251-
arch/powerpc/include/asm/nohash/pgtable.h:252:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/powerpc/include/asm/nohash/pgtable.h-253-{
--
arch/riscv/include/asm/pgtable.h=964=static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
--
arch/riscv/include/asm/pgtable.h-971-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/riscv/include/asm/pgtable.h:972:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/riscv/include/asm/pgtable.h-973-{
--
arch/s390/include/asm/pgtable.h=1803=static inline int has_transparent_hugepage(void)
--
arch/s390/include/asm/pgtable.h-1809-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/s390/include/asm/pgtable.h:1810:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/s390/include/asm/pgtable.h-1811-{
--
arch/x86/include/asm/pgtable.h=1668=static inline bool arch_has_hw_nonleaf_pmd_young(void)
--
arch/x86/include/asm/pgtable.h-1674-#ifdef CONFIG_PAGE_TABLE_CHECK
arch/x86/include/asm/pgtable.h:1675:static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
arch/x86/include/asm/pgtable.h-1676-{
]

207/2 2026/05/25 00:46 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 23015
							output: 49
							thoughts: 21
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Directly Examining `pgtable.h`**

Right, so, I'm thinking about how to approach this... instead of diving into any abstraction layers or convoluted explanations, I could just go straight to the source. Let's see, the RISC-V page table definitions are going to be in `arch/riscv/include/asm/pgtable.h`. No need to reinvent the wheel, I can just read the header file and get a precise understanding of the data structures and macros involved. It'll be a concise and efficient way to grasp the low-level details, and I can quickly spot any architecture-specific quirks. This will allow me to cut through any existing documentation, and see the reality of the implementation. Perfect.



208/2 2026/05/25 00:46 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:pte_user_accessible_page]

Results:
map[SourceCode:1675:	static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
1676:	{
1677:		return (pte_val(pte) & _PAGE_PRESENT) && (pte_val(pte) & _PAGE_USER);
1678:	}
 SourceFile:arch/x86/include/asm/pgtable.h]

209/2 2026/05/25 00:46 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 23384
							output: 58
							thoughts: 31
						

Thoughts:
Okay, here's my summarized thought process, assuming I'm an expert and this is a troubleshooting situation:

**Troubleshooting a Persistent x86 Result**

Hmm, frustrating. I'm getting that x86 result back again. It's not respecting my earlier attempts to specify the architecture. I need to dig deeper. Okay, I'm thinking, instead of whatever method I was originally using, I'll switch to a more direct approach. Let's try either `read-file` to get the raw contents and examine it directly, or maybe `grepper` (or even a standard `grep` with the `-A 5` option to get some context. I need to see what's happening around that x86 entry to understand why it's persisting and what's leading to that result. Let me try that...



210/2 2026/05/25 00:46 tool grepper
0m Error:
no matches

Args:
map[Expression:-A 5 "pte_user_accessible_page(struct mm_struct \*mm, unsigned long addr, pte_t pte)" arch/riscv/include/asm/pgtable.h]

Results:
map[Output:]

211/2 2026/05/25 00:46 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 23666
							output: 28
							thoughts: 97
						

Thoughts:
**My Grepping Dilemma**

Okay, so I'm trying to use `git grep`'s `-A` syntax with the `grepper` tool, but it looks like the tool's expecting just a simple `Expression`. Damn, that's not ideal. Let me double-check the description... Ah, right, the `grepper` tool *does* say it uses a specific set of `git grep` flags: `--extended-regexp`, `--line-number`, `--show-function`, and `-C1`. So, it's deliberately not accepting that more complex `-A` argument. 

Alright, so I'm thinking I can just use `read-file` and directly access and examine line 972 instead. That should get me what I need.



212/2 2026/05/25 00:46 tool read-file
0m Args:
map[File:arch/riscv/include/asm/pgtable.h]

Results:
map[Contents:/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (C) 2012 Regents of the University of California
 */

#ifndef _ASM_RISCV_PGTABLE_H
#define _ASM_RISCV_PGTABLE_H

#include <linux/mmzone.h>
#include <linux/sizes.h>

#include <asm/pgtable-bits.h>

#ifndef CONFIG_MMU
#ifdef CONFIG_RELOCATABLE
#define KERNEL_LINK_ADDR	UL(0)
#else
#define KERNEL_LINK_ADDR	_AC(CONFIG_PHYS_RAM_BASE, UL)
#endif
#define KERN_VIRT_SIZE		(UL(-1))
#else

#define ADDRESS_SPACE_END	(UL(-1))

#ifdef CONFIG_64BIT
/* Leave 2GB for kernel and BPF at the end of the address space */
#define KERNEL_LINK_ADDR	(ADDRESS_SPACE_END - SZ_2G + 1)
#else
#define KERNEL_LINK_ADDR	PAGE_OFFSET
#endif

/* Number of entries in the page global directory */
#define PTRS_PER_PGD    (PAGE_SIZE / sizeof(pgd_t))
/* Number of entries in the page table */
#define PTRS_PER_PTE    (PAGE_SIZE / sizeof(pte_t))

/*
 * Half of the kernel address space (1/4 of the entries of the page global
 * directory) is for the direct mapping.
 */
#define KERN_VIRT_SIZE          ((PTRS_PER_PGD / 2 * PGDIR_SIZE) / 2)

#define VMALLOC_SIZE     (KERN_VIRT_SIZE >> 1)
#define VMALLOC_END      PAGE_OFFSET
#define VMALLOC_START    (PAGE_OFFSET - VMALLOC_SIZE)

#define BPF_JIT_REGION_SIZE	(SZ_128M)
#ifdef CONFIG_64BIT
#define BPF_JIT_REGION_START	(BPF_JIT_REGION_END - BPF_JIT_REGION_SIZE)
#define BPF_JIT_REGION_END	(MODULES_END)
#else
#define BPF_JIT_REGION_START	(PAGE_OFFSET - BPF_JIT_REGION_SIZE)
#define BPF_JIT_REGION_END	(VMALLOC_END)
#endif

/* Modules always live before the kernel */
#ifdef CONFIG_64BIT
/* This is used to define the end of the KASAN shadow region */
#define MODULES_LOWEST_VADDR	(KERNEL_LINK_ADDR - SZ_2G)
#define MODULES_VADDR		(PFN_ALIGN((unsigned long)&_end) - SZ_2G)
#define MODULES_END		(PFN_ALIGN((unsigned long)&_start))
#else
#define MODULES_VADDR		VMALLOC_START
#define MODULES_END		VMALLOC_END
#endif

/*
 * Roughly size the vmemmap space to be large enough to fit enough
 * struct pages to map half the virtual address space. Then
 * position vmemmap directly below the VMALLOC region.
 */
#define VA_BITS_SV32 32
#ifdef CONFIG_64BIT
#define VA_BITS_SV39 39
#define VA_BITS_SV48 48
#define VA_BITS_SV57 57

#define VA_BITS		(pgtable_l5_enabled ? \
				VA_BITS_SV57 : (pgtable_l4_enabled ? VA_BITS_SV48 : VA_BITS_SV39))
#else
#define VA_BITS		VA_BITS_SV32
#endif

#define VMEMMAP_SHIFT \
	(VA_BITS - PAGE_SHIFT - 1 + STRUCT_PAGE_MAX_SHIFT)
#define VMEMMAP_SIZE	BIT(VMEMMAP_SHIFT)
#define VMEMMAP_END	VMALLOC_START
#define VMEMMAP_START	(VMALLOC_START - VMEMMAP_SIZE)

/*
 * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
 * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
 */
#define vmemmap		((struct page *)VMEMMAP_START - vmemmap_start_pfn)

#define PCI_IO_SIZE      SZ_16M
#define PCI_IO_END       VMEMMAP_START
#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)

#define FIXADDR_TOP      PCI_IO_START
#ifdef CONFIG_64BIT
#define MAX_FDT_SIZE	 PMD_SIZE
#define FIX_FDT_SIZE	 (MAX_FDT_SIZE + SZ_2M)
#define FIXADDR_SIZE     (PMD_SIZE + FIX_FDT_SIZE)
#else
#define MAX_FDT_SIZE	 PGDIR_SIZE
#define FIX_FDT_SIZE	 MAX_FDT_SIZE
#define FIXADDR_SIZE     (PGDIR_SIZE + FIX_FDT_SIZE)
#endif
#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)

#endif

#ifndef __ASSEMBLER__

#include <asm/page.h>
#include <asm/tlbflush.h>
#include <linux/mm_types.h>
#include <asm/compat.h>
#include <asm/cpufeature.h>

#define __page_val_to_pfn(_val)  (((_val) & _PAGE_PFN_MASK) >> _PAGE_PFN_SHIFT)

#ifdef CONFIG_64BIT
#include <asm/pgtable-64.h>

#define MMAP_VA_BITS_64 ((VA_BITS >= VA_BITS_SV48) ? VA_BITS_SV48 : VA_BITS)
#define MMAP_MIN_VA_BITS_64 (VA_BITS_SV39)
#define MMAP_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_VA_BITS_64)
#define MMAP_MIN_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_MIN_VA_BITS_64)
#else
#include <asm/pgtable-32.h>
#endif /* CONFIG_64BIT */

#include <linux/page_table_check.h>

struct pt_alloc_ops {
	pte_t *(*get_pte_virt)(phys_addr_t pa);
	phys_addr_t (*alloc_pte)(uintptr_t va);
#ifndef __PAGETABLE_PMD_FOLDED
	pmd_t *(*get_pmd_virt)(phys_addr_t pa);
	phys_addr_t (*alloc_pmd)(uintptr_t va);
	pud_t *(*get_pud_virt)(phys_addr_t pa);
	phys_addr_t (*alloc_pud)(uintptr_t va);
	p4d_t *(*get_p4d_virt)(phys_addr_t pa);
	phys_addr_t (*alloc_p4d)(uintptr_t va);
#endif
};

extern struct pt_alloc_ops pt_ops __meminitdata;

#ifdef CONFIG_MMU
/* Number of PGD entries that a user-mode program can use */
#define USER_PTRS_PER_PGD   (TASK_SIZE / PGDIR_SIZE)

/* Page protection bits */
#define _PAGE_BASE	(_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_USER)

#define PAGE_NONE		__pgprot(_PAGE_PROT_NONE | _PAGE_READ)
#define PAGE_READ		__pgprot(_PAGE_BASE | _PAGE_READ)
#define PAGE_WRITE		__pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_WRITE)
#define PAGE_EXEC		__pgprot(_PAGE_BASE | _PAGE_EXEC)
#define PAGE_READ_EXEC		__pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_EXEC)
#define PAGE_WRITE_EXEC		__pgprot(_PAGE_BASE | _PAGE_READ |	\
					 _PAGE_EXEC | _PAGE_WRITE)
#define PAGE_SHADOWSTACK       __pgprot(_PAGE_BASE | _PAGE_WRITE)

#define PAGE_COPY		PAGE_READ
#define PAGE_COPY_EXEC		PAGE_READ_EXEC
#define PAGE_SHARED		PAGE_WRITE
#define PAGE_SHARED_EXEC	PAGE_WRITE_EXEC

#define _PAGE_KERNEL		(_PAGE_READ \
				| _PAGE_WRITE \
				| _PAGE_PRESENT \
				| _PAGE_ACCESSED \
				| _PAGE_DIRTY \
				| _PAGE_GLOBAL)

#define PAGE_KERNEL		__pgprot(_PAGE_KERNEL)
#define PAGE_KERNEL_READ	__pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
#define PAGE_KERNEL_EXEC	__pgprot(_PAGE_KERNEL | _PAGE_EXEC)
#define PAGE_KERNEL_READ_EXEC	__pgprot((_PAGE_KERNEL & ~_PAGE_WRITE) \
					 | _PAGE_EXEC)

#define PAGE_TABLE		__pgprot(_PAGE_TABLE)

#define _PAGE_KERNEL_NC ((_PAGE_KERNEL & ~_PAGE_MTMASK) | _PAGE_NOCACHE)
#define _PAGE_IOREMAP	((_PAGE_KERNEL & ~_PAGE_MTMASK) | _PAGE_IO)
#define PAGE_KERNEL_IO		__pgprot(_PAGE_IOREMAP)

extern pgd_t swapper_pg_dir[];
extern pgd_t trampoline_pg_dir[];
extern pgd_t early_pg_dir[];

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
static inline int pmd_present(pmd_t pmd)
{
	/*
	 * Checking for _PAGE_LEAF is needed too because:
	 * When splitting a THP, split_huge_page() will temporarily clear
	 * the present bit, in this situation, pmd_present() and
	 * pmd_trans_huge() still needs to return true.
	 */
	return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE | _PAGE_LEAF));
}
#else
static inline int pmd_present(pmd_t pmd)
{
	return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
}
#endif

static inline int pmd_none(pmd_t pmd)
{
	return (pmd_val(pmd) == 0);
}

static inline int pmd_bad(pmd_t pmd)
{
	return !pmd_present(pmd) || (pmd_val(pmd) & _PAGE_LEAF);
}

#define pmd_leaf	pmd_leaf
static inline bool pmd_leaf(pmd_t pmd)
{
	return pmd_present(pmd) && (pmd_val(pmd) & _PAGE_LEAF);
}

static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
{
	WRITE_ONCE(*pmdp, pmd);
}

static inline void pmd_clear(pmd_t *pmdp)
{
	set_pmd(pmdp, __pmd(0));
}

static inline pgd_t pfn_pgd(unsigned long pfn, pgprot_t prot)
{
	unsigned long prot_val = pgprot_val(prot);

	ALT_THEAD_PMA(prot_val);

	return __pgd((pfn << _PAGE_PFN_SHIFT) | prot_val);
}

static inline unsigned long _pgd_pfn(pgd_t pgd)
{
	return __page_val_to_pfn(pgd_val(pgd));
}

static inline struct page *pmd_page(pmd_t pmd)
{
	return pfn_to_page(__page_val_to_pfn(pmd_val(pmd)));
}

static inline unsigned long pmd_page_vaddr(pmd_t pmd)
{
	return (unsigned long)pfn_to_virt(__page_val_to_pfn(pmd_val(pmd)));
}

static inline pte_t pmd_pte(pmd_t pmd)
{
	return __pte(pmd_val(pmd));
}

static inline pte_t pud_pte(pud_t pud)
{
	return __pte(pud_val(pud));
}

#ifdef CONFIG_RISCV_ISA_SVNAPOT

static __always_inline bool has_svnapot(void)
{
	return riscv_has_extension_likely(RISCV_ISA_EXT_SVNAPOT);
}

static inline unsigned long pte_napot(pte_t pte)
{
	return pte_val(pte) & _PAGE_NAPOT;
}

static inline pte_t pte_mknapot(pte_t pte, unsigned int order)
{
	int pos = order - 1 + _PAGE_PFN_SHIFT;
	unsigned long napot_bit = BIT(pos);
	unsigned long napot_mask = ~GENMASK(pos, _PAGE_PFN_SHIFT);

	return __pte((pte_val(pte) & napot_mask) | napot_bit | _PAGE_NAPOT);
}

#else

static __always_inline bool has_svnapot(void) { return false; }

static inline unsigned long pte_napot(pte_t pte)
{
	return 0;
}

#endif /* CONFIG_RISCV_ISA_SVNAPOT */

/* Yields the page frame number (PFN) of a page table entry */
static inline unsigned long pte_pfn(pte_t pte)
{
	unsigned long res  = __page_val_to_pfn(pte_val(pte));

	if (has_svnapot() && pte_napot(pte))
		res = res & (res - 1UL);

	return res;
}

#define pte_page(x)     pfn_to_page(pte_pfn(x))

/* Constructs a page table entry */
static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
{
	unsigned long prot_val = pgprot_val(prot);

	ALT_THEAD_PMA(prot_val);

	return __pte((pfn << _PAGE_PFN_SHIFT) | prot_val);
}

#define pte_pgprot pte_pgprot
static inline pgprot_t pte_pgprot(pte_t pte)
{
	unsigned long pfn = pte_pfn(pte);

	return __pgprot(pte_val(pfn_pte(pfn, __pgprot(0))) ^ pte_val(pte));
}

static inline int pte_present(pte_t pte)
{
	return (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
}

#define pte_accessible pte_accessible
static inline unsigned long pte_accessible(struct mm_struct *mm, pte_t a)
{
	if (pte_val(a) & _PAGE_PRESENT)
		return true;

	if ((pte_val(a) & _PAGE_PROT_NONE) &&
	    atomic_read(&mm->tlb_flush_pending))
		return true;

	return false;
}

static inline int pte_none(pte_t pte)
{
	return (pte_val(pte) == 0);
}

static inline int pte_write(pte_t pte)
{
	return pte_val(pte) & _PAGE_WRITE;
}

static inline int pte_exec(pte_t pte)
{
	return pte_val(pte) & _PAGE_EXEC;
}

static inline int pte_user(pte_t pte)
{
	return pte_val(pte) & _PAGE_USER;
}

static inline int pte_huge(pte_t pte)
{
	return pte_present(pte) && (pte_val(pte) & _PAGE_LEAF);
}

static inline int pte_dirty(pte_t pte)
{
	return pte_val(pte) & _PAGE_DIRTY;
}

static inline int pte_young(pte_t pte)
{
	return pte_val(pte) & _PAGE_ACCESSED;
}

static inline int pte_special(pte_t pte)
{
	return pte_val(pte) & _PAGE_SPECIAL;
}

/* static inline pte_t pte_rdprotect(pte_t pte) */

static inline pte_t pte_wrprotect(pte_t pte)
{
	return __pte((pte_val(pte) & ~(_PAGE_WRITE)) | (_PAGE_READ));
}

#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
#define pgtable_supports_uffd_wp()	\
	riscv_has_extension_unlikely(RISCV_ISA_EXT_SVRSW60T59B)

static inline bool pte_uffd_wp(pte_t pte)
{
	return !!(pte_val(pte) & _PAGE_UFFD_WP);
}

static inline pte_t pte_mkuffd_wp(pte_t pte)
{
	return pte_wrprotect(__pte(pte_val(pte) | _PAGE_UFFD_WP));
}

static inline pte_t pte_clear_uffd_wp(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_UFFD_WP));
}

static inline bool pte_swp_uffd_wp(pte_t pte)
{
	return !!(pte_val(pte) & _PAGE_SWP_UFFD_WP);
}

static inline pte_t pte_swp_mkuffd_wp(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SWP_UFFD_WP);
}

static inline pte_t pte_swp_clear_uffd_wp(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_SWP_UFFD_WP));
}
#endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */

/* static inline pte_t pte_mkread(pte_t pte) */

struct vm_area_struct;
pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma);
#define pte_mkwrite pte_mkwrite

static inline pte_t pte_mkwrite_novma(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_WRITE);
}

static inline pte_t pte_mkwrite_shstk(pte_t pte)
{
	return __pte((pte_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE);
}

/* static inline pte_t pte_mkexec(pte_t pte) */

static inline pte_t pte_mkdirty(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_DIRTY | _PAGE_SOFT_DIRTY);
}

static inline pte_t pte_mkclean(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_DIRTY));
}

static inline pte_t pte_mkyoung(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_ACCESSED);
}

static inline pte_t pte_mkold(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_ACCESSED));
}

static inline pte_t pte_mkspecial(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SPECIAL);
}

static inline pte_t pte_mkhuge(pte_t pte)
{
	return pte;
}

#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
#define pgtable_supports_soft_dirty()				\
	(IS_ENABLED(CONFIG_MEM_SOFT_DIRTY) &&			\
	 riscv_has_extension_unlikely(RISCV_ISA_EXT_SVRSW60T59B))

static inline bool pte_soft_dirty(pte_t pte)
{
	return !!(pte_val(pte) & _PAGE_SOFT_DIRTY);
}

static inline pte_t pte_mksoft_dirty(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SOFT_DIRTY);
}

static inline pte_t pte_clear_soft_dirty(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_SOFT_DIRTY));
}

static inline bool pte_swp_soft_dirty(pte_t pte)
{
	return !!(pte_val(pte) & _PAGE_SWP_SOFT_DIRTY);
}

static inline pte_t pte_swp_mksoft_dirty(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SWP_SOFT_DIRTY);
}

static inline pte_t pte_swp_clear_soft_dirty(pte_t pte)
{
	return __pte(pte_val(pte) & ~(_PAGE_SWP_SOFT_DIRTY));
}
#endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */

#ifdef CONFIG_RISCV_ISA_SVNAPOT
#define pte_leaf_size(pte)	(pte_napot(pte) ?				\
					napot_cont_size(napot_cont_order(pte)) :\
					PAGE_SIZE)
#endif

#ifdef CONFIG_NUMA_BALANCING
/*
 * See the comment in include/asm-generic/pgtable.h
 */
static inline int pte_protnone(pte_t pte)
{
	return (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROT_NONE)) == _PAGE_PROT_NONE;
}

static inline int pmd_protnone(pmd_t pmd)
{
	return pte_protnone(pmd_pte(pmd));
}
#endif

/* Modify page protection bits */
static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
{
	unsigned long newprot_val = pgprot_val(newprot);

	ALT_THEAD_PMA(newprot_val);

	return __pte((pte_val(pte) & _PAGE_CHG_MASK) | newprot_val);
}

#define pgd_ERROR(e) \
	pr_err("%s:%d: bad pgd " PTE_FMT ".\n", __FILE__, __LINE__, pgd_val(e))


/* Commit new configuration to MMU hardware */
static inline void update_mmu_cache_range(struct vm_fault *vmf,
		struct vm_area_struct *vma, unsigned long address,
		pte_t *ptep, unsigned int nr)
{
	/*
	 * Svvptc guarantees that the new valid pte will be visible within
	 * a bounded timeframe, so when the uarch does not cache invalid
	 * entries, we don't have to do anything.
	 */
	if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SVVPTC))
		return;

	/*
	 * The kernel assumes that TLBs don't cache invalid entries, but
	 * in RISC-V, SFENCE.VMA specifies an ordering constraint, not a
	 * cache flush; it is necessary even after writing invalid entries.
	 * Relying on flush_tlb_fix_spurious_fault would suffice, but
	 * the extra traps reduce performance.  So, eagerly SFENCE.VMA.
	 */
	while (nr--)
		local_flush_tlb_page(address + nr * PAGE_SIZE);

}
#define update_mmu_cache(vma, addr, ptep) \
	update_mmu_cache_range(NULL, vma, addr, ptep, 1)

#define update_mmu_tlb_range(vma, addr, ptep, nr) \
	update_mmu_cache_range(NULL, vma, addr, ptep, nr)

static inline void update_mmu_cache_pmd(struct vm_area_struct *vma,
		unsigned long address, pmd_t *pmdp)
{
	pte_t *ptep = (pte_t *)pmdp;

	update_mmu_cache(vma, address, ptep);
}

#define __HAVE_ARCH_PTE_SAME
static inline int pte_same(pte_t pte_a, pte_t pte_b)
{
	return pte_val(pte_a) == pte_val(pte_b);
}

/*
 * Certain architectures need to do special things when PTEs within
 * a page table are directly modified.  Thus, the following hook is
 * made available.
 */
static inline void set_pte(pte_t *ptep, pte_t pteval)
{
	WRITE_ONCE(*ptep, pteval);
}

void flush_icache_pte(struct mm_struct *mm, pte_t pte);

static inline void __set_pte_at(struct mm_struct *mm, pte_t *ptep, pte_t pteval)
{
	if (pte_present(pteval) && pte_exec(pteval))
		flush_icache_pte(mm, pteval);

	set_pte(ptep, pteval);
}

#define PFN_PTE_SHIFT		_PAGE_PFN_SHIFT

static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
		pte_t *ptep, pte_t pteval, unsigned int nr)
{
	page_table_check_ptes_set(mm, addr, ptep, pteval, nr);

	for (;;) {
		__set_pte_at(mm, ptep, pteval);
		if (--nr == 0)
			break;
		ptep++;
		pte_val(pteval) += 1 << _PAGE_PFN_SHIFT;
	}
}
#define set_ptes set_ptes

static inline void pte_clear(struct mm_struct *mm,
	unsigned long addr, pte_t *ptep)
{
	__set_pte_at(mm, ptep, __pte(0));
}

#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS	/* defined in mm/pgtable.c */
extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
				 pte_t *ptep, pte_t entry, int dirty);
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG	/* defined in mm/pgtable.c */
bool ptep_test_and_clear_young(struct vm_area_struct *vma,
		unsigned long address, pte_t *ptep);

#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
				       unsigned long address, pte_t *ptep)
{
#ifdef CONFIG_SMP
	pte_t pte = __pte(xchg(&ptep->pte, 0));
#else
	pte_t pte = *ptep;

	set_pte(ptep, __pte(0));
#endif

	page_table_check_pte_clear(mm, address, pte);

	return pte;
}

#define __HAVE_ARCH_PTEP_SET_WRPROTECT
static inline void ptep_set_wrprotect(struct mm_struct *mm,
				      unsigned long address, pte_t *ptep)
{
	pte_t read_pte = READ_ONCE(*ptep);
	/*
	 * ptep_set_wrprotect can be called for shadow stack ranges too.
	 * shadow stack memory is XWR = 010 and thus clearing _PAGE_WRITE will lead to
	 * encoding 000b which is wrong encoding with V = 1. This should lead to page fault
	 * but we dont want this wrong configuration to be set in page tables.
	 */
	atomic_long_set((atomic_long_t *)ptep,
			((pte_val(read_pte) & ~(unsigned long)_PAGE_WRITE) | _PAGE_READ));
}

#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
		unsigned long address, pte_t *ptep)
{
	/*
	 * This comment is borrowed from x86, but applies equally to RISC-V:
	 *
	 * Clearing the accessed bit without a TLB flush
	 * doesn't cause data corruption. [ It could cause incorrect
	 * page aging and the (mistaken) reclaim of hot pages, but the
	 * chance of that should be relatively low. ]
	 *
	 * So as a performance optimization don't flush the TLB when
	 * clearing the accessed bit, it will eventually be flushed by
	 * a context switch or a VM operation anyway. [ In the rare
	 * event of it not getting flushed for a long time the delay
	 * shouldn't really matter because there's no real memory
	 * pressure for swapout to react to. ]
	 */
	return ptep_test_and_clear_young(vma, address, ptep);
}

#define pgprot_nx pgprot_nx
static inline pgprot_t pgprot_nx(pgprot_t _prot)
{
	return __pgprot(pgprot_val(_prot) & ~_PAGE_EXEC);
}

#define pgprot_noncached pgprot_noncached
static inline pgprot_t pgprot_noncached(pgprot_t _prot)
{
	unsigned long prot = pgprot_val(_prot);

	prot &= ~_PAGE_MTMASK;
	prot |= _PAGE_IO;

	return __pgprot(prot);
}

#define pgprot_writecombine pgprot_writecombine
static inline pgprot_t pgprot_writecombine(pgprot_t _prot)
{
	unsigned long prot = pgprot_val(_prot);

	prot &= ~_PAGE_MTMASK;
	prot |= _PAGE_NOCACHE;

	return __pgprot(prot);
}

#define pgprot_dmacoherent pgprot_writecombine

/*
 * Both Svade and Svadu control the hardware behavior when the PTE A/D bits need to be set. By
 * default the M-mode firmware enables the hardware updating scheme when only Svadu is present in
 * DT.
 */
#define arch_has_hw_pte_young arch_has_hw_pte_young
static inline bool arch_has_hw_pte_young(void)
{
	return riscv_has_extension_unlikely(RISCV_ISA_EXT_SVADU);
}

/*
 * THP functions
 */
static inline pmd_t pte_pmd(pte_t pte)
{
	return __pmd(pte_val(pte));
}

static inline pud_t pte_pud(pte_t pte)
{
	return __pud(pte_val(pte));
}

static inline pmd_t pmd_mkhuge(pmd_t pmd)
{
	return pmd;
}

static inline pmd_t pmd_mkinvalid(pmd_t pmd)
{
	return __pmd(pmd_val(pmd) & ~(_PAGE_PRESENT|_PAGE_PROT_NONE));
}

#define __pmd_to_phys(pmd)  (__page_val_to_pfn(pmd_val(pmd)) << PAGE_SHIFT)

static inline unsigned long pmd_pfn(pmd_t pmd)
{
	return ((__pmd_to_phys(pmd) & PMD_MASK) >> PAGE_SHIFT);
}

#define __pud_to_phys(pud)  (__page_val_to_pfn(pud_val(pud)) << PAGE_SHIFT)

#define pud_pfn pud_pfn
static inline unsigned long pud_pfn(pud_t pud)
{
	return ((__pud_to_phys(pud) & PUD_MASK) >> PAGE_SHIFT);
}

#define pmd_pgprot pmd_pgprot
static inline pgprot_t pmd_pgprot(pmd_t pmd)
{
	return pte_pgprot(pmd_pte(pmd));
}

#define pud_pgprot pud_pgprot
static inline pgprot_t pud_pgprot(pud_t pud)
{
	return pte_pgprot(pud_pte(pud));
}

static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
{
	return pte_pmd(pte_modify(pmd_pte(pmd), newprot));
}

#define pmd_write pmd_write
static inline int pmd_write(pmd_t pmd)
{
	return pte_write(pmd_pte(pmd));
}

#define pud_write pud_write
static inline int pud_write(pud_t pud)
{
	return pte_write(pud_pte(pud));
}

#define pmd_dirty pmd_dirty
static inline int pmd_dirty(pmd_t pmd)
{
	return pte_dirty(pmd_pte(pmd));
}

#define pmd_young pmd_young
static inline int pmd_young(pmd_t pmd)
{
	return pte_young(pmd_pte(pmd));
}

static inline int pmd_user(pmd_t pmd)
{
	return pte_user(pmd_pte(pmd));
}

static inline pmd_t pmd_mkold(pmd_t pmd)
{
	return pte_pmd(pte_mkold(pmd_pte(pmd)));
}

static inline pmd_t pmd_mkyoung(pmd_t pmd)
{
	return pte_pmd(pte_mkyoung(pmd_pte(pmd)));
}

pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
#define pmd_mkwrite pmd_mkwrite

static inline pmd_t pmd_mkwrite_novma(pmd_t pmd)
{
	return pte_pmd(pte_mkwrite_novma(pmd_pte(pmd)));
}

static inline pmd_t pmd_mkwrite_shstk(pmd_t pte)
{
	return __pmd((pmd_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE);
}

static inline pmd_t pmd_wrprotect(pmd_t pmd)
{
	return pte_pmd(pte_wrprotect(pmd_pte(pmd)));
}

static inline pmd_t pmd_mkclean(pmd_t pmd)
{
	return pte_pmd(pte_mkclean(pmd_pte(pmd)));
}

static inline pmd_t pmd_mkdirty(pmd_t pmd)
{
	return pte_pmd(pte_mkdirty(pmd_pte(pmd)));
}

#ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP
static inline bool pmd_special(pmd_t pmd)
{
	return pte_special(pmd_pte(pmd));
}

static inline pmd_t pmd_mkspecial(pmd_t pmd)
{
	return pte_pmd(pte_mkspecial(pmd_pte(pmd)));
}
#endif

#ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP
static inline bool pud_special(pud_t pud)
{
	return pte_special(pud_pte(pud));
}

static inline pud_t pud_mkspecial(pud_t pud)
{
	return pte_pud(pte_mkspecial(pud_pte(pud)));
}
#endif

#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
static inline bool pmd_uffd_wp(pmd_t pmd)
{
	return pte_uffd_wp(pmd_pte(pmd));
}

static inline pmd_t pmd_mkuffd_wp(pmd_t pmd)
{
	return pte_pmd(pte_mkuffd_wp(pmd_pte(pmd)));
}

static inline pmd_t pmd_clear_uffd_wp(pmd_t pmd)
{
	return pte_pmd(pte_clear_uffd_wp(pmd_pte(pmd)));
}

static inline bool pmd_swp_uffd_wp(pmd_t pmd)
{
	return pte_swp_uffd_wp(pmd_pte(pmd));
}

static inline pmd_t pmd_swp_mkuffd_wp(pmd_t pmd)
{
	return pte_pmd(pte_swp_mkuffd_wp(pmd_pte(pmd)));
}

static inline pmd_t pmd_swp_clear_uffd_wp(pmd_t pmd)
{
	return pte_pmd(pte_swp_clear_uffd_wp(pmd_pte(pmd)));
}
#endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */

#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
static inline bool pmd_soft_dirty(pmd_t pmd)
{
	return pte_soft_dirty(pmd_pte(pmd));
}

static inline pmd_t pmd_mksoft_dirty(pmd_t pmd)
{
	return pte_pmd(pte_mksoft_dirty(pmd_pte(pmd)));
}

static inline pmd_t pmd_clear_soft_dirty(pmd_t pmd)
{
	return pte_pmd(pte_clear_soft_dirty(pmd_pte(pmd)));
}

#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION
static inline bool pmd_swp_soft_dirty(pmd_t pmd)
{
	return pte_swp_soft_dirty(pmd_pte(pmd));
}

static inline pmd_t pmd_swp_mksoft_dirty(pmd_t pmd)
{
	return pte_pmd(pte_swp_mksoft_dirty(pmd_pte(pmd)));
}

static inline pmd_t pmd_swp_clear_soft_dirty(pmd_t pmd)
{
	return pte_pmd(pte_swp_clear_soft_dirty(pmd_pte(pmd)));
}
#endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */
#endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */

static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
				pmd_t *pmdp, pmd_t pmd)
{
	page_table_check_pmd_set(mm, addr, pmdp, pmd);
	return __set_pte_at(mm, (pte_t *)pmdp, pmd_pte(pmd));
}

static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
				pud_t *pudp, pud_t pud)
{
	page_table_check_pud_set(mm, addr, pudp, pud);
	return __set_pte_at(mm, (pte_t *)pudp, pud_pte(pud));
}

#ifdef CONFIG_PAGE_TABLE_CHECK
static inline bool pte_user_accessible_page(struct mm_struct *mm, unsigned long addr, pte_t pte)
{
	return pte_present(pte) && pte_user(pte);
}

static inline bool pmd_user_accessible_page(struct mm_struct *mm, unsigned long addr, pmd_t pmd)
{
	return pmd_leaf(pmd) && pmd_user(pmd);
}

static inline bool pud_user_accessible_page(struct mm_struct *mm, unsigned long addr, pud_t pud)
{
	return pud_leaf(pud) && pud_user(pud);
}
#endif

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
static inline int pmd_trans_huge(pmd_t pmd)
{
	return pmd_leaf(pmd);
}

#define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
					unsigned long address, pmd_t *pmdp,
					pmd_t entry, int dirty)
{
	return ptep_set_access_flags(vma, address, (pte_t *)pmdp, pmd_pte(entry), dirty);
}

#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
		unsigned long address, pmd_t *pmdp)
{
	return ptep_test_and_clear_young(vma, address, (pte_t *)pmdp);
}

#define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
					unsigned long address, pmd_t *pmdp)
{
#ifdef CONFIG_SMP
	pmd_t pmd = __pmd(xchg(&pmdp->pmd, 0));
#else
	pmd_t pmd = *pmdp;

	pmd_clear(pmdp);
#endif

	page_table_check_pmd_clear(mm, address, pmd);

	return pmd;
}

#define __HAVE_ARCH_PMDP_SET_WRPROTECT
static inline void pmdp_set_wrprotect(struct mm_struct *mm,
					unsigned long address, pmd_t *pmdp)
{
	ptep_set_wrprotect(mm, address, (pte_t *)pmdp);
}

#define pmdp_establish pmdp_establish
static inline pmd_t pmdp_establish(struct vm_area_struct *vma,
				unsigned long address, pmd_t *pmdp, pmd_t pmd)
{
	page_table_check_pmd_set(vma->vm_mm, address, pmdp, pmd);
	return __pmd(atomic_long_xchg((atomic_long_t *)pmdp, pmd_val(pmd)));
}

#define pmdp_collapse_flush pmdp_collapse_flush
extern pmd_t pmdp_collapse_flush(struct vm_area_struct *vma,
				 unsigned long address, pmd_t *pmdp);

static inline pud_t pud_wrprotect(pud_t pud)
{
	return pte_pud(pte_wrprotect(pud_pte(pud)));
}

static inline int pud_trans_huge(pud_t pud)
{
	return pud_leaf(pud);
}

static inline int pud_dirty(pud_t pud)
{
	return pte_dirty(pud_pte(pud));
}

static inline pud_t pud_mkyoung(pud_t pud)
{
	return pte_pud(pte_mkyoung(pud_pte(pud)));
}

static inline pud_t pud_mkold(pud_t pud)
{
	return pte_pud(pte_mkold(pud_pte(pud)));
}

static inline pud_t pud_mkdirty(pud_t pud)
{
	return pte_pud(pte_mkdirty(pud_pte(pud)));
}

static inline pud_t pud_mkclean(pud_t pud)
{
	return pte_pud(pte_mkclean(pud_pte(pud)));
}

static inline pud_t pud_mkwrite(pud_t pud)
{
	return pte_pud(pte_mkwrite_novma(pud_pte(pud)));
}

static inline pud_t pud_mkhuge(pud_t pud)
{
	return pud;
}

static inline int pudp_set_access_flags(struct vm_area_struct *vma,
					unsigned long address, pud_t *pudp,
					pud_t entry, int dirty)
{
	return ptep_set_access_flags(vma, address, (pte_t *)pudp, pud_pte(entry), dirty);
}

static inline bool pudp_test_and_clear_young(struct vm_area_struct *vma,
		unsigned long address, pud_t *pudp)
{
	return ptep_test_and_clear_young(vma, address, (pte_t *)pudp);
}

#define __HAVE_ARCH_PUDP_HUGE_GET_AND_CLEAR
static inline pud_t pudp_huge_get_and_clear(struct mm_struct *mm,
					    unsigned long address,  pud_t *pudp)
{
#ifdef CONFIG_SMP
	pud_t pud = __pud(xchg(&pudp->pud, 0));
#else
	pud_t pud = *pudp;

	pud_clear(pudp);
#endif

	page_table_check_pud_clear(mm, address, pud);

	return pud;
}

static inline int pud_young(pud_t pud)
{
	return pte_young(pud_pte(pud));
}

static inline void update_mmu_cache_pud(struct vm_area_struct *vma,
					unsigned long address, pud_t *pudp)
{
	pte_t *ptep = (pte_t *)pudp;

	update_mmu_cache(vma, address, ptep);
}

static inline pud_t pudp_establish(struct vm_area_struct *vma,
				   unsigned long address, pud_t *pudp, pud_t pud)
{
	page_table_check_pud_set(vma->vm_mm, address, pudp, pud);
	return __pud(atomic_long_xchg((atomic_long_t *)pudp, pud_val(pud)));
}

static inline pud_t pud_mkinvalid(pud_t pud)
{
	return __pud(pud_val(pud) & ~(_PAGE_PRESENT | _PAGE_PROT_NONE));
}

extern pud_t pudp_invalidate(struct vm_area_struct *vma, unsigned long address,
			     pud_t *pudp);

static inline pud_t pud_modify(pud_t pud, pgprot_t newprot)
{
	return pte_pud(pte_modify(pud_pte(pud), newprot));
}

#endif /* CONFIG_TRANSPARENT_HUGEPAGE */

/*
 * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that
 * are !pte_none() && !pte_present().
 *
 * Format of swap PTE:
 *	bit            0:	_PAGE_PRESENT (zero)
 *	bit       1 to 2:	(zero)
 *	bit            3:	_PAGE_SWP_SOFT_DIRTY
 *	bit            4:	_PAGE_SWP_UFFD_WP
 *	bit            5:	_PAGE_PROT_NONE (zero)
 *	bit            6:	exclusive marker
 *	bits      7 to 11:	swap type
 *	bits 12 to XLEN-1:	swap offset
 */
#define __SWP_TYPE_SHIFT	7
#define __SWP_TYPE_BITS		5
#define __SWP_TYPE_MASK		((1UL << __SWP_TYPE_BITS) - 1)
#define __SWP_OFFSET_SHIFT	(__SWP_TYPE_BITS + __SWP_TYPE_SHIFT)

#define MAX_SWAPFILES_CHECK()	\
	BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > __SWP_TYPE_BITS)

#define __swp_type(x)	(((x).val >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK)
#define __swp_offset(x)	((x).val >> __SWP_OFFSET_SHIFT)
#define __swp_entry(type, offset) ((swp_entry_t) \
	{ (((type) & __SWP_TYPE_MASK) << __SWP_TYPE_SHIFT) | \
	  ((offset) << __SWP_OFFSET_SHIFT) })

#define __pte_to_swp_entry(pte)	((swp_entry_t) { pte_val(pte) })
#define __swp_entry_to_pte(x)	((pte_t) { (x).val })

static inline bool pte_swp_exclusive(pte_t pte)
{
	return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
}

static inline pte_t pte_swp_mkexclusive(pte_t pte)
{
	return __pte(pte_val(pte) | _PAGE_SWP_EXCLUSIVE);
}

static inline pte_t pte_swp_clear_exclusive(pte_t pte)
{
	return __pte(pte_val(pte) & ~_PAGE_SWP_EXCLUSIVE);
}

#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION
#define __pmd_to_swp_entry(pmd) ((swp_entry_t) { pmd_val(pmd) })
#define __swp_entry_to_pmd(swp) __pmd((swp).val)
#endif /* CONFIG_ARCH_ENABLE_THP_MIGRATION */

/*
 * In the RV64 Linux scheme, we give the user half of the virtual-address space
 * and give the kernel the other (upper) half.
 */
#ifdef CONFIG_64BIT
#define KERN_VIRT_START	(-(BIT(VA_BITS)) + TASK_SIZE)
#else
#define KERN_VIRT_START	FIXADDR_START
#endif

/*
 * Task size is 0x4000000000 for RV64 or 0x9fc00000 for RV32.
 * Note that PGDIR_SIZE must evenly divide TASK_SIZE.
 * Task size is:
 * -        0x9fc00000	(~2.5GB) for RV32.
 * -      0x4000000000	( 256GB) for RV64 using SV39 mmu
 * -    0x800000000000	( 128TB) for RV64 using SV48 mmu
 * - 0x100000000000000	(  64PB) for RV64 using SV57 mmu
 *
 * Note that PGDIR_SIZE must evenly divide TASK_SIZE since "RISC-V
 * Instruction Set Manual Volume II: Privileged Architecture" states that
 * "load and store effective addresses, which are 64bits, must have bits
 * 63–48 all equal to bit 47, or else a page-fault exception will occur."
 * Similarly for SV57, bits 63–57 must be equal to bit 56.
 */
#ifdef CONFIG_64BIT
#define TASK_SIZE_64	(PGDIR_SIZE * PTRS_PER_PGD / 2)

#ifdef CONFIG_COMPAT
#define TASK_SIZE_32	(_AC(0x80000000, UL) - PAGE_SIZE)
#define TASK_SIZE	(is_compat_task() ? \
			 TASK_SIZE_32 : TASK_SIZE_64)
#else
#define TASK_SIZE	TASK_SIZE_64
#endif

#else
#define TASK_SIZE	FIXADDR_START
#endif

#else /* CONFIG_MMU */

#define PAGE_SHARED		__pgprot(0)
#define PAGE_KERNEL		__pgprot(0)
#define swapper_pg_dir		NULL
#define TASK_SIZE		_AC(-1, UL)
#define VMALLOC_START		_AC(0, UL)
#define VMALLOC_END		TASK_SIZE

#endif /* !CONFIG_MMU */

extern char _start[];
extern void *_dtb_early_va;
extern uintptr_t _dtb_early_pa;
#define dtb_early_va	_dtb_early_va
#define dtb_early_pa	_dtb_early_pa
extern u64 satp_mode;

void paging_init(void);
void misc_mem_init(void);

/*
 * Use set_p*_safe(), and elide TLB flushing, when confident that *no*
 * TLB flush will be required as a result of the "set". For example, use
 * in scenarios where it is known ahead of time that the routine is
 * setting non-present entries, or re-setting an existing entry to the
 * same value. Otherwise, use the typical "set" helpers and flush the
 * TLB.
 */
#define set_p4d_safe(p4dp, p4d) \
({ \
	WARN_ON_ONCE(p4d_present(*p4dp) && !p4d_same(*p4dp, p4d)); \
	set_p4d(p4dp, p4d); \
})

#define set_pgd_safe(pgdp, pgd) \
({ \
	WARN_ON_ONCE(pgd_present(*pgdp) && !pgd_same(*pgdp, pgd)); \
	set_pgd(pgdp, pgd); \
})
#endif /* !__ASSEMBLER__ */

#endif /* _ASM_RISCV_PGTABLE_H */
]

213/2 2026/05/25 00:46 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 37372
							output: 48
							thoughts: 246
						

Thoughts:
**Analyzing `pte_user_accessible_page` and Its Implications**

Okay, let's break this down. Line 972 defines `pte_user_accessible_page`, which I can see returns a boolean value. The code clearly states it returns `true` if *both* `pte_present(pte)` and `pte_user(pte)` are true. Straightforward enough. Now, I know that if a PTE represents a swap entry or migration entry, `pte_present(pte)` will be false. Consequently, this means `pte_user_accessible_page` will return `false` in those scenarios.

So, here's the crucial point: when `set_pte_at` sets a migration entry, `page_table_check_ptes_set` *won't* increment the map count. That makes sense, because it's not a user-accessible page. But hold on, the picture isn't complete yet. What happens when that page is unmapped, say via `ptep_get_and_clear`? That calls `page_table_check_pte_clear`, and I need to check how that works. Let's dig into `page_table_check_pte_clear` and see what's happening there.



214/2 2026/05/25 00:46 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/page_table_check.c IncludeLines:true Name:__page_table_check_pte_clear]

Results:
map[SourceCode: 148:	void __page_table_check_pte_clear(struct mm_struct *mm, unsigned long addr,
 149:					  pte_t pte)
 150:	{
 151:		if (&init_mm == mm)
 152:			return;
 153:	
 154:		if (pte_user_accessible_page(mm, addr, pte))
 155:			page_table_check_clear(pte_pfn(pte), PAGE_SIZE >> PAGE_SHIFT);
 156:	}
 SourceFile:mm/page_table_check.c]

215/2 2026/05/25 00:46 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 38117
							output: 43
							thoughts: 615
						

Thoughts:
**Analyzing Potential Map Count Leaks in Huge Page Clearing**

Okay, let's break this down. My understanding is that `__page_table_check_pte_clear` only decrements the map count if the PTE is user-accessible, which makes sense. So, if a migration entry is cleared, the map count *won't* be touched. This confirms that the map count represents the number of *present* user PTEs.

Now, let's look at `huge_pte_clear` in the RISC-V huge page code. This function iterates through a range of PTEs and clears them using `pte_clear`. The critical point is that `pte_clear` *bypasses* `page_table_check_pte_clear`. So, if `huge_pte_clear` gets called on a *present* PTE, the map count won't be decremented, and we have a potential leak.

The key question is: when is `huge_pte_clear` called? Looking at `__unmap_hugepage_range`, it seems `huge_pte_clear` is called *only* when the PTE is *not* present (i.e., `!pte_present(pte)`). Since `pte_present` is false, `pte_user_accessible_page` would also be false, and `page_table_check_pte_clear` would not decrement the map count anyway. So, this specific call in `__unmap_hugepage_range` is safe; it doesn't cause a leak.

However, where else is `huge_pte_clear` used? Looking at the code, it's also called in `hugetlb_change_protection` in `mm/hugetlb.c`. This needs further scrutiny, as protection changes might involve clearing present PTEs. It's time to dig into that call site and see if it might be causing an issue.



216/2 2026/05/25 00:46 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/hugetlb.c IncludeLines:true Name:hugetlb_change_protection]

Results:
map[SourceCode:6398:	long hugetlb_change_protection(struct vm_area_struct *vma,
6399:			unsigned long address, unsigned long end,
6400:			pgprot_t newprot, unsigned long cp_flags)
6401:	{
6402:		struct mm_struct *mm = vma->vm_mm;
6403:		unsigned long start = address;
6404:		pte_t *ptep;
6405:		pte_t pte;
6406:		struct hstate *h = hstate_vma(vma);
6407:		long pages = 0, psize = huge_page_size(h);
6408:		struct mmu_notifier_range range;
6409:		unsigned long last_addr_mask;
6410:		bool uffd_wp = cp_flags & MM_CP_UFFD_WP;
6411:		bool uffd_wp_resolve = cp_flags & MM_CP_UFFD_WP_RESOLVE;
6412:		struct mmu_gather tlb;
6413:	
6414:		/*
6415:		 * In the case of shared PMDs, the area to flush could be beyond
6416:		 * start/end.  Set range.start/range.end to cover the maximum possible
6417:		 * range if PMD sharing is possible.
6418:		 */
6419:		mmu_notifier_range_init(&range, MMU_NOTIFY_PROTECTION_VMA,
6420:					0, mm, start, end);
6421:		adjust_range_if_pmd_sharing_possible(vma, &range.start, &range.end);
6422:	
6423:		BUG_ON(address >= end);
6424:		flush_cache_range(vma, range.start, range.end);
6425:		tlb_gather_mmu_vma(&tlb, vma);
6426:	
6427:		mmu_notifier_invalidate_range_start(&range);
6428:		hugetlb_vma_lock_write(vma);
6429:		i_mmap_lock_write(vma->vm_file->f_mapping);
6430:		last_addr_mask = hugetlb_mask_last_page(h);
6431:		for (; address < end; address += psize) {
6432:			softleaf_t entry;
6433:			spinlock_t *ptl;
6434:	
6435:			ptep = hugetlb_walk(vma, address, psize);
6436:			if (!ptep) {
6437:				if (!uffd_wp) {
6438:					address |= last_addr_mask;
6439:					continue;
6440:				}
6441:				/*
6442:				 * Userfaultfd wr-protect requires pgtable
6443:				 * pre-allocations to install pte markers.
6444:				 */
6445:				ptep = huge_pte_alloc(mm, vma, address, psize);
6446:				if (!ptep) {
6447:					pages = -ENOMEM;
6448:					break;
6449:				}
6450:			}
6451:			ptl = huge_pte_lock(h, mm, ptep);
6452:			if (huge_pmd_unshare(&tlb, vma, address, ptep)) {
6453:				/*
6454:				 * When uffd-wp is enabled on the vma, unshare
6455:				 * shouldn't happen at all.  Warn about it if it
6456:				 * happened due to some reason.
6457:				 */
6458:				WARN_ON_ONCE(uffd_wp || uffd_wp_resolve);
6459:				pages++;
6460:				spin_unlock(ptl);
6461:				address |= last_addr_mask;
6462:				continue;
6463:			}
6464:			pte = huge_ptep_get(mm, address, ptep);
6465:			if (huge_pte_none(pte)) {
6466:				if (unlikely(uffd_wp))
6467:					/* Safe to modify directly (none->non-present). */
6468:					set_huge_pte_at(mm, address, ptep,
6469:							make_pte_marker(PTE_MARKER_UFFD_WP),
6470:							psize);
6471:				goto next;
6472:			}
6473:	
6474:			entry = softleaf_from_pte(pte);
6475:			if (unlikely(softleaf_is_hwpoison(entry))) {
6476:				/* Nothing to do. */
6477:			} else if (unlikely(softleaf_is_migration(entry))) {
6478:				struct folio *folio = softleaf_to_folio(entry);
6479:				pte_t newpte = pte;
6480:	
6481:				if (softleaf_is_migration_write(entry)) {
6482:					if (folio_test_anon(folio))
6483:						entry = make_readable_exclusive_migration_entry(
6484:									swp_offset(entry));
6485:					else
6486:						entry = make_readable_migration_entry(
6487:									swp_offset(entry));
6488:					newpte = swp_entry_to_pte(entry);
6489:					pages++;
6490:				}
6491:	
6492:				if (uffd_wp)
6493:					newpte = pte_swp_mkuffd_wp(newpte);
6494:				else if (uffd_wp_resolve)
6495:					newpte = pte_swp_clear_uffd_wp(newpte);
6496:				if (!pte_same(pte, newpte))
6497:					set_huge_pte_at(mm, address, ptep, newpte, psize);
6498:			} else if (unlikely(pte_is_marker(pte))) {
6499:				/*
6500:				 * Do nothing on a poison marker; page is
6501:				 * corrupted, permissions do not apply. Here
6502:				 * pte_marker_uffd_wp()==true implies !poison
6503:				 * because they're mutual exclusive.
6504:				 */
6505:				if (pte_is_uffd_wp_marker(pte) && uffd_wp_resolve)
6506:					/* Safe to modify directly (non-present->none). */
6507:					huge_pte_clear(mm, address, ptep, psize);
6508:			} else {
6509:				pte_t old_pte;
6510:				unsigned int shift = huge_page_shift(hstate_vma(vma));
6511:	
6512:				old_pte = huge_ptep_modify_prot_start(vma, address, ptep);
6513:				pte = huge_pte_modify(old_pte, newprot);
6514:				pte = arch_make_huge_pte(pte, shift, vma->vm_flags);
6515:				if (uffd_wp)
6516:					pte = huge_pte_mkuffd_wp(pte);
6517:				else if (uffd_wp_resolve)
6518:					pte = huge_pte_clear_uffd_wp(pte);
6519:				huge_ptep_modify_prot_commit(vma, address, ptep, old_pte, pte);
6520:				pages++;
6521:				tlb_remove_huge_tlb_entry(h, &tlb, ptep, address);
6522:			}
6523:	
6524:	next:
6525:			spin_unlock(ptl);
6526:			cond_resched();
6527:		}
6528:	
6529:		tlb_flush_mmu_tlbonly(&tlb);
6530:		huge_pmd_unshare_flush(&tlb, vma);
6531:		/*
6532:		 * No need to call mmu_notifier_arch_invalidate_secondary_tlbs() we are
6533:		 * downgrading page table protection not changing it to point to a new
6534:		 * page.
6535:		 *
6536:		 * See Documentation/mm/mmu_notifier.rst
6537:		 */
6538:		i_mmap_unlock_write(vma->vm_file->f_mapping);
6539:		hugetlb_vma_unlock_write(vma);
6540:		mmu_notifier_invalidate_range_end(&range);
6541:		tlb_finish_mmu(&tlb);
6542:	
6543:		return pages > 0 ? (pages << h->order) : pages;
6544:	}
 SourceFile:mm/hugetlb.c]

217/2 2026/05/25 00:46 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 41681
							output: 41
							thoughts: 107
						

Thoughts:
**Analyzing Huge Page Protection Changes**

Okay, so I'm digging into this `hugetlb_change_protection` function. Specifically, I'm trying to understand a specific scenario where `huge_pte_clear` is called. It seems like the call occurs when a `pte` is a write-protected userfaultfd marker – that `pte_is_uffd_wp_marker(pte) && uffd_wp_resolve` condition. Right, and since it's a marker, not a real present PTE, `pte_user_accessible_page` will evaluate to false, which is expected. So, at first glance, I *don't* think this specific call to `huge_pte_clear` is leaking any map counts. That's good; it's what I'd hope for.

Now, where *else* is `huge_pte_clear` being called, though, especially in the context of these large pages? Let me shift my focus. Let's see... the most obvious place that comes to mind is `move_huge_pte` in `mm/hugetlb.c` at line 5075. I need to refresh my memory on that function and its calling contexts. Let's see what's happening there with those potential leaks...



218/2 2026/05/25 00:46 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/hugetlb.c IncludeLines:true Name:move_huge_pte]

Results:
map[SourceCode:5052:	static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,
5053:				  unsigned long new_addr, pte_t *src_pte, pte_t *dst_pte,
5054:				  unsigned long sz)
5055:	{
5056:		bool need_clear_uffd_wp = vma_has_uffd_without_event_remap(vma);
5057:		struct hstate *h = hstate_vma(vma);
5058:		struct mm_struct *mm = vma->vm_mm;
5059:		spinlock_t *src_ptl, *dst_ptl;
5060:		pte_t pte;
5061:	
5062:		dst_ptl = huge_pte_lock(h, mm, dst_pte);
5063:		src_ptl = huge_pte_lockptr(h, mm, src_pte);
5064:	
5065:		/*
5066:		 * We don't have to worry about the ordering of src and dst ptlocks
5067:		 * because exclusive mmap_lock (or the i_mmap_lock) prevents deadlock.
5068:		 */
5069:		if (src_ptl != dst_ptl)
5070:			spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
5071:	
5072:		pte = huge_ptep_get_and_clear(mm, old_addr, src_pte, sz);
5073:	
5074:		if (need_clear_uffd_wp && pte_is_uffd_wp_marker(pte)) {
5075:			huge_pte_clear(mm, new_addr, dst_pte, sz);
5076:		} else {
5077:			if (need_clear_uffd_wp) {
5078:				if (pte_present(pte))
5079:					pte = huge_pte_clear_uffd_wp(pte);
5080:				else
5081:					pte = pte_swp_clear_uffd_wp(pte);
5082:			}
5083:			set_huge_pte_at(mm, new_addr, dst_pte, pte, sz);
5084:		}
5085:	
5086:		if (src_ptl != dst_ptl)
5087:			spin_unlock(src_ptl);
5088:		spin_unlock(dst_ptl);
5089:	}
 SourceFile:mm/hugetlb.c]

219/2 2026/05/25 00:46 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 42825
							output: 46
							thoughts: 353
						

Thoughts:
**Analyzing the PTE Clearing Behavior in HugeTLB Pages**

Okay, so I'm digging into this bug related to `huge_pte_clear`, specifically within the HugeTLB code. The initial thought was that the bypass of `page_table_check_pte_clear` within `huge_pte_clear` was the root cause, but after reviewing the code in `mm/hugetlb.c`, it's clear that `huge_pte_clear` is *only* called on non-present PTEs (when `pte_is_uffd_wp_marker(pte)` is true). So, scratch that theory. It's never actually called on a real, present PTE in that context. That means something else is at play.

Now, let's switch gears and examine `huge_ptep_get_and_clear` in `arch/riscv/mm/hugetlbpage.c`. That looks more promising. Specifically, I'm focusing on this check: `pte_napot(orig_pte)`. It seems to be checking for the NAPOT bit on the PTE. *That* immediately raises a question: If `orig_pte` is a migration entry – which is a possibility given the context – does *it* have the NAPOT bit set? That's the crucial detail. Need to double-check how `pte_napot` actually works and what it means for migration entries. That seems to be the critical area to investigate further. Let's see how `pte_napot` is defined...



220/2 2026/05/25 00:47 tool codesearch-definition-source
0m Error:
requested entity does not exist

Args:
map[ContextFile:arch/riscv/include/asm/pgtable.h IncludeLines:true Name:pte_napot]

Results:
map[SourceCode: SourceFile:]

221/2 2026/05/25 00:47 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 43575
							output: 18
							thoughts: 15
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, tailored for an expert audience:

**Identifying the Mechanism**

Alright, I'm looking at some code, and my initial thought is: this looks like an inline function or potentially a macro. I need to nail down exactly what's being employed here. The behavior strongly suggests one of those two options, so that's where I'll focus my investigation. Time to go hunting for the actual definition and confirm my initial hypothesis.



222/2 2026/05/25 00:47 tool grepper
0m Args:
map[Expression:pte_napot]

Results:
map[Output:arch/riscv/include/asm/pgtable.h=276=static __always_inline bool has_svnapot(void)
--
arch/riscv/include/asm/pgtable.h-280-
arch/riscv/include/asm/pgtable.h:281:static inline unsigned long pte_napot(pte_t pte)
arch/riscv/include/asm/pgtable.h-282-{
--
arch/riscv/include/asm/pgtable.h=297=static __always_inline bool has_svnapot(void) { return false; }
arch/riscv/include/asm/pgtable.h-298-
arch/riscv/include/asm/pgtable.h:299:static inline unsigned long pte_napot(pte_t pte)
arch/riscv/include/asm/pgtable.h-300-{
--
arch/riscv/include/asm/pgtable.h=307=static inline unsigned long pte_pfn(pte_t pte)
--
arch/riscv/include/asm/pgtable.h-310-
arch/riscv/include/asm/pgtable.h:311:	if (has_svnapot() && pte_napot(pte))
arch/riscv/include/asm/pgtable.h-312-		res = res & (res - 1UL);
--
arch/riscv/include/asm/pgtable.h=515=static inline pte_t pte_swp_clear_soft_dirty(pte_t pte)
--
arch/riscv/include/asm/pgtable.h-521-#ifdef CONFIG_RISCV_ISA_SVNAPOT
arch/riscv/include/asm/pgtable.h:522:#define pte_leaf_size(pte)	(pte_napot(pte) ?				\
arch/riscv/include/asm/pgtable.h-523-					napot_cont_size(napot_cont_order(pte)) :\
--
arch/riscv/mm/hugetlbpage.c=6=pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
--
arch/riscv/mm/hugetlbpage.c-11-
arch/riscv/mm/hugetlbpage.c:12:	if (!pte_present(orig_pte) || !pte_napot(orig_pte))
arch/riscv/mm/hugetlbpage.c-13-		return orig_pte;
--
arch/riscv/mm/hugetlbpage.c=246=void set_huge_pte_at(struct mm_struct *mm,
--
arch/riscv/mm/hugetlbpage.c-262-
arch/riscv/mm/hugetlbpage.c:263:	if (!pte_napot(pte)) {
arch/riscv/mm/hugetlbpage.c-264-		set_ptes(mm, addr, ptep, pte, 1);
--
arch/riscv/mm/hugetlbpage.c=274=int huge_ptep_set_access_flags(struct vm_area_struct *vma,
--
arch/riscv/mm/hugetlbpage.c-284-
arch/riscv/mm/hugetlbpage.c:285:	if (!pte_napot(pte))
arch/riscv/mm/hugetlbpage.c-286-		return ptep_set_access_flags(vma, addr, ptep, pte, dirty);
--
arch/riscv/mm/hugetlbpage.c=305=pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
--
arch/riscv/mm/hugetlbpage.c-312-
arch/riscv/mm/hugetlbpage.c:313:	if (!pte_napot(orig_pte))
arch/riscv/mm/hugetlbpage.c-314-		return ptep_get_and_clear(mm, addr, ptep);
--
arch/riscv/mm/hugetlbpage.c=321=void huge_ptep_set_wrprotect(struct mm_struct *mm,
--
arch/riscv/mm/hugetlbpage.c-329-
arch/riscv/mm/hugetlbpage.c:330:	if (!pte_napot(pte)) {
arch/riscv/mm/hugetlbpage.c-331-		ptep_set_wrprotect(mm, addr, ptep);
--
arch/riscv/mm/hugetlbpage.c=346=pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
--
arch/riscv/mm/hugetlbpage.c-352-
arch/riscv/mm/hugetlbpage.c:353:	if (!pte_napot(pte))
arch/riscv/mm/hugetlbpage.c-354-		return ptep_clear_flush(vma, addr, ptep);
--
arch/riscv/mm/hugetlbpage.c=361=void huge_pte_clear(struct mm_struct *mm,
--
arch/riscv/mm/hugetlbpage.c-369-
arch/riscv/mm/hugetlbpage.c:370:	if (!pte_napot(pte)) {
arch/riscv/mm/hugetlbpage.c-371-		pte_clear(mm, addr, ptep);
]

223/2 2026/05/25 00:47 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 45127
							output: 21
							thoughts: 429
						

Thoughts:
**Investigating Potential Bug in Huge Page Handling**

Okay, so I'm looking at `arch/riscv/mm/hugetlbpage.c`, specifically the `huge_ptep_get_and_clear` function. I see this conditional: `if (!pte_napot(orig_pte))`.  My immediate thought is, what if `orig_pte` *is* a NAPOT huge page, but it's a migration entry? That `ptep_get_and_clear` call could be wrong here.

The key question is, does a migration entry, which is a kind of swapped-out page, have the NAPOT bit set? Let me quickly check the definition of `pte_napot` in `arch/riscv/include/asm/pgtable.h`: `return pte_val(pte) & _PAGE_NAPOT;`. Alright, that's straightforward enough. Now I need to know if `_PAGE_NAPOT` is *preserved* in the swap or migration entry.

So, let me check the swap entry format in the same include file. Okay, here's the layout: `/* ... */ bit 0: _PAGE_PRESENT (zero) ... bits 12 to XLEN-1: swap offset`. Aha, `_PAGE_NAPOT` is bit 63 (in SVNAPOT)! I need to find the definition of `_PAGE_NAPOT` to know if that bit is part of the swap entry format. This is probably related to the migration entry question. Let's see...



224/2 2026/05/25 00:47 tool grepper
0m Args:
map[Expression:#define _PAGE_NAPOT]

Results:
map[Output:arch/riscv/include/asm/pgtable-64.h=63=typedef struct {
--
arch/riscv/include/asm/pgtable-64.h-85- */
arch/riscv/include/asm/pgtable-64.h:86:#define _PAGE_NAPOT_SHIFT	63
arch/riscv/include/asm/pgtable-64.h:87:#define _PAGE_NAPOT		BIT(_PAGE_NAPOT_SHIFT)
arch/riscv/include/asm/pgtable-64.h-88-/*
]

225/2 2026/05/25 00:47 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 46065
							output: 49
							thoughts: 566
						

Thoughts:
**My Deep Dive into NAPOT Huge Page Migration**

Okay, so I'm thinking about how NAPOT (Not-A-Power-Of-Two) huge pages interact with migration. Bit 63, `_PAGE_NAPOT`, is the key here, and I'm realizing something potentially problematic. In a swap entry, bits 12 to XLEN-1 represent the swap offset. If `_PAGE_NAPOT` is bit 63, it's stepping on the toes of the swap offset!

When we're creating a migration entry, `make_migration_entry` creates a `swp_entry_t`, which then gets converted to a `pte_t` using `swp_entry_to_pte`. The critical question is: Does `swp_entry_to_pte` set `_PAGE_NAPOT`? No, it just sets the bits according to the swap entry format. This means a migration entry *for* a NAPOT huge page will NOT have `_PAGE_NAPOT` set.

Now, if it doesn't have `_PAGE_NAPOT` set, then `pte_napot(orig_pte)` will return false! This is where the potential issue arises. I need to re-examine `huge_ptep_get_and_clear`:

```c
pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
			      unsigned long addr,
			      pte_t *ptep, unsigned long sz)
{
	size_t pgsize;
	pte_t orig_pte = ptep_get(ptep);
	int pte_num;

	if (!pte_napot(orig_pte))
		return ptep_get_and_clear(mm, addr, ptep);

	pte_num = num_contig_ptes_from_size(sz, &pgsize);

	return get_clear_contig(mm, addr, ptep, pte_num);
}
```

If `orig_pte` is a migration entry (and remember, it won't have `_PAGE_NAPOT` set), `pte_napot(orig_pte)` is false.  Therefore, it calls `ptep_get_and_clear(mm, addr, ptep)`. The problem is that `ptep_get_and_clear` only clears *one* PTE!  A NAPOT huge page, however, consists of *multiple* PTEs (e.g., 16).

This means the remaining 15 PTEs are left untouched, *still* containing the migration entry.  Is this a problem for `page_table_check`? I need to think this through. Wait... a migration entry is *not* a present PTE. So its map count is already 0. So does it matter if the other PTEs are still there?

When the migration entry was inserted, did it overwrite 16 PTEs? I need to go look at `set_huge_pte_at`! I need to re-examine how that function works.



226/2 2026/05/25 00:47 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/mm/hugetlbpage.c IncludeLines:true Name:set_huge_pte_at]

Results:
map[SourceCode:  70:	static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
  71:			pte_t *ptep, pte_t pte, unsigned long sz)
  72:	{
  73:		set_pte_at(mm, addr, ptep, pte);
  74:	}
 SourceFile:include/asm-generic/hugetlb.h]

227/2 2026/05/25 00:47 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 47488
							output: 49
							thoughts: 11
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**RISC-V Focus Needed**

Right, *damn*, I just realized I was about to go down a rabbit hole without specifying the architecture I needed. That was a near miss! I need to zero in on the RISC-V implementation, and fast. All my background knowledge could be applied to a wider field if I don't narrow my focus. Otherwise, I will get bogged down, and the relevant information will be less useful.



228/2 2026/05/25 00:47 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/mm/hugetlbpage.c IncludeLines:true Name:set_huge_pte_at]

Results:
map[SourceCode:  70:	static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
  71:			pte_t *ptep, pte_t pte, unsigned long sz)
  72:	{
  73:		set_pte_at(mm, addr, ptep, pte);
  74:	}
 SourceFile:include/asm-generic/hugetlb.h]

229/2 2026/05/25 00:47 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 47782
							output: 28
							thoughts: 26
						

Thoughts:
Here's a summary of my thought process, as requested:

**Diving into `hugetlbpage.c` for RISC-V Memory Management**

Okay, time to dig into the RISC-V kernel code, specifically the huge page handling. I need to refresh my memory on how this is implemented. Let's start with `arch/riscv/mm/hugetlbpage.c` -- I vaguely recall some interesting bits around line 246. I'm curious about the specific logic there, likely related to either allocation, mapping, or perhaps unmapping of the huge pages. This section is often crucial for understanding the overall memory management strategy, and how it differs from the standard page size handling on RISC-V. Hopefully, the surrounding code will clarify the context. Let's see what we're dealing with...



230/2 2026/05/25 00:47 tool read-file
0m Args:
map[File:arch/riscv/mm/hugetlbpage.c]

Results:
map[Contents:// SPDX-License-Identifier: GPL-2.0
#include <linux/hugetlb.h>
#include <linux/err.h>

#ifdef CONFIG_RISCV_ISA_SVNAPOT
pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
{
	unsigned long pte_num;
	int i;
	pte_t orig_pte = ptep_get(ptep);

	if (!pte_present(orig_pte) || !pte_napot(orig_pte))
		return orig_pte;

	pte_num = napot_pte_num(napot_cont_order(orig_pte));

	for (i = 0; i < pte_num; i++, ptep++) {
		pte_t pte = ptep_get(ptep);

		if (pte_dirty(pte))
			orig_pte = pte_mkdirty(orig_pte);

		if (pte_young(pte))
			orig_pte = pte_mkyoung(orig_pte);
	}

	return orig_pte;
}

pte_t *huge_pte_alloc(struct mm_struct *mm,
		      struct vm_area_struct *vma,
		      unsigned long addr,
		      unsigned long sz)
{
	unsigned long order;
	pte_t *pte = NULL;
	pgd_t *pgd;
	p4d_t *p4d;
	pud_t *pud;
	pmd_t *pmd;

	pgd = pgd_offset(mm, addr);
	p4d = p4d_alloc(mm, pgd, addr);
	if (!p4d)
		return NULL;

	pud = pud_alloc(mm, p4d, addr);
	if (!pud)
		return NULL;

	if (sz == PUD_SIZE) {
		pte = (pte_t *)pud;
		goto out;
	}

	if (sz == PMD_SIZE) {
		if (want_pmd_share(vma, addr) && pud_none(pudp_get(pud)))
			pte = huge_pmd_share(mm, vma, addr, pud);
		else
			pte = (pte_t *)pmd_alloc(mm, pud, addr);
		goto out;
	}

	pmd = pmd_alloc(mm, pud, addr);
	if (!pmd)
		return NULL;

	for_each_napot_order(order) {
		if (napot_cont_size(order) == sz) {
			pte = pte_alloc_huge(mm, pmd, addr & napot_cont_mask(order));
			break;
		}
	}

out:
	if (pte) {
		pte_t pteval = ptep_get_lockless(pte);

		WARN_ON_ONCE(pte_present(pteval) && !pte_huge(pteval));
	}
	return pte;
}

pte_t *huge_pte_offset(struct mm_struct *mm,
		       unsigned long addr,
		       unsigned long sz)
{
	unsigned long order;
	pte_t *pte = NULL;
	pgd_t *pgd;
	p4d_t *p4d;
	pud_t *pud;
	pmd_t *pmd;

	pgd = pgd_offset(mm, addr);
	if (!pgd_present(pgdp_get(pgd)))
		return NULL;

	p4d = p4d_offset(pgd, addr);
	if (!p4d_present(p4dp_get(p4d)))
		return NULL;

	pud = pud_offset(p4d, addr);
	if (sz == PUD_SIZE)
		/* must be pud huge, non-present or none */
		return (pte_t *)pud;

	if (!pud_present(pudp_get(pud)))
		return NULL;

	pmd = pmd_offset(pud, addr);
	if (sz == PMD_SIZE)
		/* must be pmd huge, non-present or none */
		return (pte_t *)pmd;

	if (!pmd_present(pmdp_get(pmd)))
		return NULL;

	for_each_napot_order(order) {
		if (napot_cont_size(order) == sz) {
			pte = pte_offset_huge(pmd, addr & napot_cont_mask(order));
			break;
		}
	}
	return pte;
}

unsigned long hugetlb_mask_last_page(struct hstate *h)
{
	unsigned long hp_size = huge_page_size(h);

	switch (hp_size) {
#ifndef __PAGETABLE_PMD_FOLDED
	case PUD_SIZE:
		return P4D_SIZE - PUD_SIZE;
#endif
	case PMD_SIZE:
		return PUD_SIZE - PMD_SIZE;
	case napot_cont_size(NAPOT_CONT64KB_ORDER):
		return PMD_SIZE - napot_cont_size(NAPOT_CONT64KB_ORDER);
	default:
		break;
	}

	return 0UL;
}

static pte_t get_clear_contig(struct mm_struct *mm,
			      unsigned long addr,
			      pte_t *ptep,
			      unsigned long ncontig)
{
	pte_t pte, tmp_pte;
	bool present;

	pte = ptep_get_and_clear(mm, addr, ptep);
	present = pte_present(pte);
	while (--ncontig) {
		ptep++;
		addr += PAGE_SIZE;
		tmp_pte = ptep_get_and_clear(mm, addr, ptep);
		if (present) {
			if (pte_dirty(tmp_pte))
				pte = pte_mkdirty(pte);
			if (pte_young(tmp_pte))
				pte = pte_mkyoung(pte);
		}
	}
	return pte;
}

static pte_t get_clear_contig_flush(struct mm_struct *mm,
				    unsigned long addr,
				    pte_t *ptep,
				    unsigned long pte_num)
{
	pte_t orig_pte = get_clear_contig(mm, addr, ptep, pte_num);
	struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0);
	bool valid = !pte_none(orig_pte);

	if (valid)
		flush_tlb_range(&vma, addr, addr + (PAGE_SIZE * pte_num));

	return orig_pte;
}

pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
{
	unsigned long order;

	for_each_napot_order(order) {
		if (shift == napot_cont_shift(order)) {
			entry = pte_mknapot(entry, order);
			break;
		}
	}
	if (order == NAPOT_ORDER_MAX)
		entry = pte_mkhuge(entry);

	return entry;
}

static void clear_flush(struct mm_struct *mm,
			unsigned long addr,
			pte_t *ptep,
			unsigned long pgsize,
			unsigned long ncontig)
{
	struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0);
	unsigned long i, saddr = addr;

	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
		ptep_get_and_clear(mm, addr, ptep);

	flush_tlb_range(&vma, saddr, addr);
}

static int num_contig_ptes_from_size(unsigned long sz, size_t *pgsize)
{
	unsigned long hugepage_shift;

	if (sz >= PGDIR_SIZE)
		hugepage_shift = PGDIR_SHIFT;
	else if (sz >= P4D_SIZE)
		hugepage_shift = P4D_SHIFT;
	else if (sz >= PUD_SIZE)
		hugepage_shift = PUD_SHIFT;
	else if (sz >= PMD_SIZE)
		hugepage_shift = PMD_SHIFT;
	else
		hugepage_shift = PAGE_SHIFT;

	*pgsize = 1 << hugepage_shift;

	return sz >> hugepage_shift;
}

/*
 * When dealing with NAPOT mappings, the privileged specification indicates that
 * "if an update needs to be made, the OS generally should first mark all of the
 * PTEs invalid, then issue SFENCE.VMA instruction(s) covering all 4 KiB regions
 * within the range, [...] then update the PTE(s), as described in Section
 * 4.2.1.". That's the equivalent of the Break-Before-Make approach used by
 * arm64.
 */
void set_huge_pte_at(struct mm_struct *mm,
		     unsigned long addr,
		     pte_t *ptep,
		     pte_t pte,
		     unsigned long sz)
{
	size_t pgsize;
	int i, pte_num;

	pte_num = num_contig_ptes_from_size(sz, &pgsize);

	if (!pte_present(pte)) {
		for (i = 0; i < pte_num; i++, ptep++, addr += pgsize)
			set_ptes(mm, addr, ptep, pte, 1);
		return;
	}

	if (!pte_napot(pte)) {
		set_ptes(mm, addr, ptep, pte, 1);
		return;
	}

	clear_flush(mm, addr, ptep, pgsize, pte_num);

	for (i = 0; i < pte_num; i++, ptep++, addr += pgsize)
		set_pte_at(mm, addr, ptep, pte);
}

int huge_ptep_set_access_flags(struct vm_area_struct *vma,
			       unsigned long addr,
			       pte_t *ptep,
			       pte_t pte,
			       int dirty)
{
	struct mm_struct *mm = vma->vm_mm;
	unsigned long order;
	pte_t orig_pte;
	int i, pte_num;

	if (!pte_napot(pte))
		return ptep_set_access_flags(vma, addr, ptep, pte, dirty);

	order = napot_cont_order(pte);
	pte_num = napot_pte_num(order);
	ptep = huge_pte_offset(mm, addr, napot_cont_size(order));
	orig_pte = get_clear_contig_flush(mm, addr, ptep, pte_num);

	if (pte_dirty(orig_pte))
		pte = pte_mkdirty(pte);

	if (pte_young(orig_pte))
		pte = pte_mkyoung(pte);

	for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++)
		set_pte_at(mm, addr, ptep, pte);

	return true;
}

pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
			      unsigned long addr,
			      pte_t *ptep, unsigned long sz)
{
	size_t pgsize;
	pte_t orig_pte = ptep_get(ptep);
	int pte_num;

	if (!pte_napot(orig_pte))
		return ptep_get_and_clear(mm, addr, ptep);

	pte_num = num_contig_ptes_from_size(sz, &pgsize);

	return get_clear_contig(mm, addr, ptep, pte_num);
}

void huge_ptep_set_wrprotect(struct mm_struct *mm,
			     unsigned long addr,
			     pte_t *ptep)
{
	pte_t pte = ptep_get(ptep);
	unsigned long order;
	pte_t orig_pte;
	int i, pte_num;

	if (!pte_napot(pte)) {
		ptep_set_wrprotect(mm, addr, ptep);
		return;
	}

	order = napot_cont_order(pte);
	pte_num = napot_pte_num(order);
	ptep = huge_pte_offset(mm, addr, napot_cont_size(order));
	orig_pte = get_clear_contig_flush(mm, addr, ptep, pte_num);

	orig_pte = pte_wrprotect(orig_pte);

	for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++)
		set_pte_at(mm, addr, ptep, orig_pte);
}

pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
			    unsigned long addr,
			    pte_t *ptep)
{
	pte_t pte = ptep_get(ptep);
	int pte_num;

	if (!pte_napot(pte))
		return ptep_clear_flush(vma, addr, ptep);

	pte_num = napot_pte_num(napot_cont_order(pte));

	return get_clear_contig_flush(vma->vm_mm, addr, ptep, pte_num);
}

void huge_pte_clear(struct mm_struct *mm,
		    unsigned long addr,
		    pte_t *ptep,
		    unsigned long sz)
{
	size_t pgsize;
	pte_t pte = ptep_get(ptep);
	int i, pte_num;

	if (!pte_napot(pte)) {
		pte_clear(mm, addr, ptep);
		return;
	}

	pte_num = num_contig_ptes_from_size(sz, &pgsize);

	for (i = 0; i < pte_num; i++, addr += pgsize, ptep++)
		pte_clear(mm, addr, ptep);
}

static bool is_napot_size(unsigned long size)
{
	unsigned long order;

	if (!has_svnapot())
		return false;

	for_each_napot_order(order) {
		if (size == napot_cont_size(order))
			return true;
	}
	return false;
}

static __init int napot_hugetlbpages_init(void)
{
	if (has_svnapot()) {
		unsigned long order;

		for_each_napot_order(order)
			hugetlb_add_hstate(order);
	}
	return 0;
}
arch_initcall(napot_hugetlbpages_init);

#else

static bool is_napot_size(unsigned long size)
{
	return false;
}

#endif /*CONFIG_RISCV_ISA_SVNAPOT*/

static bool __hugetlb_valid_size(unsigned long size)
{
	if (size == HPAGE_SIZE)
		return true;
	else if (IS_ENABLED(CONFIG_64BIT) && size == PUD_SIZE)
		return true;
	else if (is_napot_size(size))
		return true;
	else
		return false;
}

bool __init arch_hugetlb_valid_size(unsigned long size)
{
	return __hugetlb_valid_size(size);
}

#ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION
bool arch_hugetlb_migration_supported(struct hstate *h)
{
	return __hugetlb_valid_size(huge_page_size(h));
}
#endif

#ifdef CONFIG_CONTIG_ALLOC
static __init int gigantic_pages_init(void)
{
	/* With CONTIG_ALLOC, we can allocate gigantic pages at runtime */
	if (IS_ENABLED(CONFIG_64BIT))
		hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
	return 0;
}
arch_initcall(gigantic_pages_init);
#endif

unsigned int __init arch_hugetlb_cma_order(void)
{
	if (IS_ENABLED(CONFIG_64BIT))
		return PUD_SHIFT - PAGE_SHIFT;

	return 0;
}
]

231/2 2026/05/25 00:47 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 52147
							output: 23
							thoughts: 6710
						

Thoughts:
**Analyzing Hugetlb and Migration Entry Interaction**

Okay, so I've been diving deep into how hugetlb works, specifically how it handles migration entries. It seems complex, and I've been tracing the logic to ensure that map counts, which are critical for memory management, are correctly updated and don't leak. The starting point is understanding how `set_huge_pte_at` deals with the presence or absence of a PTE. If the PTE isn't present, the code loops, calling `set_ptes` multiple times, which in turn calls `page_table_check_ptes_set`. Now, this is crucial. Because if it's a migration entry, `pte_user_accessible_page` returns false. This means the `page_table_check_ptes_set` won't increment the map count. But, importantly, `set_ptes` clears the *existing* PTEs before writing the migration entry. It clears by calling `__page_table_check_pte_clear` before overwriting them.

But wait a minute, the existing PTEs are supposed to be cleared by `huge_ptep_get_and_clear` or `huge_ptep_get_and_clear`, so that looks okay. If `pte` is a present NAPOT huge page,  `pte_napot` is true, so `get_clear_contig` is called which decrements the map count correctly.  Then, when the migration entry is inserted, map count is not incremented. When the VMA is restored, a `clear_flush` is called that sets the map count correctly. That all seems very balanced, but what if the migration entry is restored?

I needed to re-evaluate the map counts that are adjusted in migration scenarios, like where `move_huge_pte` could be the source of issues, especially the interaction with `remove_migration_pte`. It turns out that the key to this is when `huge_ptep_get_and_clear` gets called on a migration entry. It should decrement the map count.  

Then I considered `remove_migration_pte` to determine if a map count is leaking by finding where the migration entries can be missed. With `remove_migration_pte` it seems that there is no map count leak, the PTEs are cleared then set and the count seems to be correctly adjusted in all cases.

So, I focused on the fix for commit `83d78ac677b9`. This commit prevents `huge_pte_clear` and `huge_ptep_get_and_clear` from calling `pte_napot`, which, crucially, determines the number of PTEs to clear. Before the fix, if the passed PTE was a migration entry, it would *only* clear a single PTE, leaving 15 others. After the fix, it *always* clears all 16, which is good.  This means, before the fix, if a migration entry gets into one of these functions, only the first PTE is cleared, which is how a map count gets messed up.

Finally, I considered how a PRESENT PTE could lose `_PAGE_NAPOT`. It seems that the bit is always checked correctly in `hugetlb_change_protection`, `huge_ptep_set_access_flags`, `huge_ptep_set_wrprotect`, and `huge_ptep_clear_flush`, so that shouldn't happen.

So, now I'm pretty sure that the key issue is in how older code handled migration entries and only cleared one PTE instead of all 16. It's the fix in `83d78ac677b9` that's the core.  Before this fix, the only problem will be situations where hugetlb code incorrectly handles a migration entry as a "present" PTE, and causes a map count leak.



232/2 2026/05/25 00:48 tool codesearch-find-references
0m Args:
map[Name:huge_pte_clear]

Results:
map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:__unmap_hugepage_range SourceFile:mm/hugetlb.c SourceLine:5221] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:hugetlb_change_protection SourceFile:mm/hugetlb.c SourceLine:6507] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:move_huge_pte SourceFile:mm/hugetlb.c SourceLine:5075]] TruncatedOutput:false]

233/2 2026/05/25 00:48 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 59890
							output: 26
							thoughts: 4076
						

Thoughts:
**Analyzing Potential Huge Page Mapcount Discrepancies**

Okay, so I've been digging into this, and here's my breakdown of the potential mapcount issues surrounding huge pages. I'm focusing on those three key locations in `mm/hugetlb.c`.

First, I had to rule out the basic `huge_pte_clear` issue. It seemed unlikely. I started looking back at `huge_ptep_get_and_clear`. The core of the problem, it seems, hinges on whether the `pte_napot` check is correct and how it interacts with different PTE states. I am thinking about the following:

If it is NAPOT and present:
*   Scenario 1: if it's a *present* NAPOT PTE, and `pte_napot` returns *true*. Then it calls `get_clear_contig`, which loops through and calls `ptep_get_and_clear` 16 times (or however many PTEs are in the NAPOT block). This decrements the mapcount properly.

If it is not NAPOT and present:
*   Scenario 2: If it's a *present* PTE, but *not* a NAPOT PTE (like a PMD-sized huge page), the `pte_napot` returns false, and it calls `ptep_get_and_clear` *once*, which decrements the mapcount by one. This also seems correct.

Could a "present" huge PTE *not* be a NAPOT PTE? Yes, a PMD-sized huge page is a perfect example. In this case, `sz` would be `PMD_SIZE` (on SV39, for example). `pte_napot` would return false, and it correctly calls `ptep_get_and_clear` only once. That's fine.

Could a NAPOT PTE be detected as non-NAPOT?
*   Scenario 3: what if `pte_napot(orig_pte)` is false *even when* the PTE is intended to be NAPOT? Corruption could be the reason but maybe also the function is checking the wrong bit. `_PAGE_NAPOT` is bit 63. Is it possible for a NAPOT PTE to be written *without* the `_PAGE_NAPOT` bit? I checked `arch_make_huge_pte`, which *does* add the `_PAGE_NAPOT` bit. So that seems unlikely.

What about those migration entries?

Now, let's go back and reconsider the potential issue of leftover migration entries. Say `huge_pte_clear` is called on a migration entry. The first PTE is cleared. The remaining 15 *still* contain the migration entry. What if the VMA isn't unmapped, but we fault on it?

*   Scenario 4: If `huge_pte_clear` *has* been called, then we're in `__unmap_hugepage_range`, `hugetlb_change_protection`, or `move_huge_pte`. In `__unmap_hugepage_range`, it clears the PTE. If a user faults *later*, `hugetlb_fault` will see `huge_pte_none(pte)` because it only checks the first PTE. The code *then* allocates a *new* huge page. `clear_flush` clears *all* 16 PTEs.

    The first PTE is 0. The other 15 are the *old* migration entries. `ptep_get_and_clear` clears them. Since they are migration entries (not present), the mapcount is not affected. Then `set_pte_at` writes the *new* present PTE to all 16, and the mapcount increments by 16. That should be correct, really.

But here's a wrinkle: those old migration entries might not be migration entries at all.

*   Scenario 5: What if the migration entries are *actually* something else? What if `__unmap_hugepage_range` was called on a UFFD_WP marker? It clears the first PTE. Fifteen UFFD_WP markers remain. A *new* page is then mapped. `clear_flush` clears those 15 UFFD_WP markers. Since *they're* not present, the mapcount isn't affected. Still fine.

And what about a completely destroyed VMA?

*   Scenario 6: Say the VMA is destroyed, and the page tables are freed. `free_pte_range` frees the page table page. It *doesn't* check the PTEs. Those 15 leftover migration entries are just ignored.
    *   When the *old*


234/2 2026/05/25 00:49 tool git-show
0m Args:
map[Commit:83d78ac677b9]

Results:
map[Output:commit 83d78ac677b9fdd8ea763507c6fe02d6bf415f3a
Author: Alexandre Ghiti <alexghiti@rivosinc.com>
Date:   Mon Mar 17 08:25:51 2025 +0100

    riscv: Fix hugetlb retrieval of number of ptes in case of !present pte
    
    Ryan sent a fix [1] for arm64 that applies to riscv too: in some hugetlb
    functions, we must not use the pte value to get the size of a mapping
    because the pte may not be present.
    
    So use the already present size parameter for huge_pte_clear() and the
    newly introduced size parameter for huge_ptep_get_and_clear(). And make
    sure to gather A/D bits only on present ptes.
    
    Fixes: 82a1a1f3bfb6 ("riscv: mm: support Svnapot in hugetlb page")
    Link: https://lore.kernel.org/all/20250217140419.1702389-1-ryan.roberts@arm.com/ [1]
    Link: https://lore.kernel.org/r/20250317072551.572169-1-alexghiti@rivosinc.com
    Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>

diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c
index b4a78a4b35cf..375dd96bb4a0 100644
--- a/arch/riscv/mm/hugetlbpage.c
+++ b/arch/riscv/mm/hugetlbpage.c
@@ -148,22 +148,25 @@ unsigned long hugetlb_mask_last_page(struct hstate *h)
 static pte_t get_clear_contig(struct mm_struct *mm,
 			      unsigned long addr,
 			      pte_t *ptep,
-			      unsigned long pte_num)
+			      unsigned long ncontig)
 {
-	pte_t orig_pte = ptep_get(ptep);
-	unsigned long i;
-
-	for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++) {
-		pte_t pte = ptep_get_and_clear(mm, addr, ptep);
-
-		if (pte_dirty(pte))
-			orig_pte = pte_mkdirty(orig_pte);
-
-		if (pte_young(pte))
-			orig_pte = pte_mkyoung(orig_pte);
+	pte_t pte, tmp_pte;
+	bool present;
+
+	pte = ptep_get_and_clear(mm, addr, ptep);
+	present = pte_present(pte);
+	while (--ncontig) {
+		ptep++;
+		addr += PAGE_SIZE;
+		tmp_pte = ptep_get_and_clear(mm, addr, ptep);
+		if (present) {
+			if (pte_dirty(tmp_pte))
+				pte = pte_mkdirty(pte);
+			if (pte_young(tmp_pte))
+				pte = pte_mkyoung(pte);
+		}
 	}
-
-	return orig_pte;
+	return pte;
 }
 
 static pte_t get_clear_contig_flush(struct mm_struct *mm,
@@ -212,6 +215,26 @@ static void clear_flush(struct mm_struct *mm,
 	flush_tlb_range(&vma, saddr, addr);
 }
 
+static int num_contig_ptes_from_size(unsigned long sz, size_t *pgsize)
+{
+	unsigned long hugepage_shift;
+
+	if (sz >= PGDIR_SIZE)
+		hugepage_shift = PGDIR_SHIFT;
+	else if (sz >= P4D_SIZE)
+		hugepage_shift = P4D_SHIFT;
+	else if (sz >= PUD_SIZE)
+		hugepage_shift = PUD_SHIFT;
+	else if (sz >= PMD_SIZE)
+		hugepage_shift = PMD_SHIFT;
+	else
+		hugepage_shift = PAGE_SHIFT;
+
+	*pgsize = 1 << hugepage_shift;
+
+	return sz >> hugepage_shift;
+}
+
 /*
  * When dealing with NAPOT mappings, the privileged specification indicates that
  * "if an update needs to be made, the OS generally should first mark all of the
@@ -226,22 +249,10 @@ void set_huge_pte_at(struct mm_struct *mm,
 		     pte_t pte,
 		     unsigned long sz)
 {
-	unsigned long hugepage_shift, pgsize;
+	size_t pgsize;
 	int i, pte_num;
 
-	if (sz >= PGDIR_SIZE)
-		hugepage_shift = PGDIR_SHIFT;
-	else if (sz >= P4D_SIZE)
-		hugepage_shift = P4D_SHIFT;
-	else if (sz >= PUD_SIZE)
-		hugepage_shift = PUD_SHIFT;
-	else if (sz >= PMD_SIZE)
-		hugepage_shift = PMD_SHIFT;
-	else
-		hugepage_shift = PAGE_SHIFT;
-
-	pte_num = sz >> hugepage_shift;
-	pgsize = 1 << hugepage_shift;
+	pte_num = num_contig_ptes_from_size(sz, &pgsize);
 
 	if (!pte_present(pte)) {
 		for (i = 0; i < pte_num; i++, ptep++, addr += pgsize)
@@ -295,13 +306,14 @@ pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
 			      unsigned long addr,
 			      pte_t *ptep, unsigned long sz)
 {
+	size_t pgsize;
 	pte_t orig_pte = ptep_get(ptep);
 	int pte_num;
 
 	if (!pte_napot(orig_pte))
 		return ptep_get_and_clear(mm, addr, ptep);
 
-	pte_num = napot_pte_num(napot_cont_order(orig_pte));
+	pte_num = num_contig_ptes_from_size(sz, &pgsize);
 
 	return get_clear_contig(mm, addr, ptep, pte_num);
 }
@@ -351,6 +363,7 @@ void huge_pte_clear(struct mm_struct *mm,
 		    pte_t *ptep,
 		    unsigned long sz)
 {
+	size_t pgsize;
 	pte_t pte = ptep_get(ptep);
 	int i, pte_num;
 
@@ -359,8 +372,9 @@ void huge_pte_clear(struct mm_struct *mm,
 		return;
 	}
 
-	pte_num = napot_pte_num(napot_cont_order(pte));
-	for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++)
+	pte_num = num_contig_ptes_from_size(sz, &pgsize);
+
+	for (i = 0; i < pte_num; i++, addr += pgsize, ptep++)
 		pte_clear(mm, addr, ptep);
 }
 
]

235/2 2026/05/25 00:49 llm expert
1m Model:
gemini-3.1-pro-preview

Tokens:
							input: 67029
							output: 23
							thoughts: 11804
						

Thoughts:
**Analyzing Potential Map Count Leaks in RISC-V Hugetlb Implementation**

Okay, so I've been diving deep into this RISC-V Hugetlb code, trying to figure out how a map count leak could possibly occur. The core issue is this `BUG_ON` triggering when a page is being freed but its `anon_map_count` is still non-zero. The goal is to figure out how to cause map count to be more than zero for a page table entry that is being freed.

My initial thought was that there was an inconsistency in clearing PTEs, but I've eliminated a number of likely causes. I started by examining `huge_pte_clear` and `huge_ptep_get_and_clear` to see if they might be clearing fewer PTEs than expected, especially when dealing with migration entries. It turns out that, prior to a fix, these functions *would* clear only 1 PTE when handling a migration entry, because they were not explicitly checking for a napot entry.

However, after tracing various scenarios with migration entries, it seems unlikely that a leak *directly* stems from this. While a single migration entry being cleared instead of all the associated entries is indeed an issue, it isn't the root cause of the map count discrepancy. 

The crux of the problem lies in the interactions between different PTE modifications, particularly those that happen during huge page mapping, unmapping, and protection changes. My focus is now on scenarios where a PTE could be "partially" modified, leaving the map count unbalanced.

I began to explore how write protection changes might play a role with the function `ptep_set_wrprotect`. I reviewed calls to `ptep_set_wrprotect`, hoping it would somehow decrement map count without updating the flag that keeps track of the counts, but found it wasn't the case.

Next, I looked at how `set_huge_pte_at` is used when a huge page is mapped, specifically its handling of `clear_flush`. Could there be a situation where `clear_flush` is called but the map count isn't adjusted correctly? The process looks solid: `clear_flush` calls `ptep_get_and_clear` multiple times to clear entries, then `set_pte_at` is called.

Then, I focused on if `set_huge_pte_at` is setting a "new" NAPOT huge page over an old NAPOT huge page. If `set_huge_pte_at` is given a non-napot entry, it only sets 1 entry out of 16 entries expected.

Then, I came to a potential vulnerability. Is there a scenario where we write 16 PTEs with `set_huge_pte_at`, but later, the first PTE loses its `_PAGE_NAPOT` bit? I believe I've pinpointed the possible source: `ptep_set_access_flags`.

If the 1st PTE has `_PAGE_NAPOT` removed because `ptep_set_access_flags` writes a non-`_PAGE_NAPOT` PTE to that address, and leaves the remaining 15 `_PAGE_NAPOT` PTEs, and the VMA is destroyed, then 15 PRESENT PTEs are left, and they'll cause the `BUG_ON` trigger. It seems this would occur because `hugetlb_fault` might call `huge_ptep_set_access_flags` in such a way, if I understand correctly.

Now, I'm thinking about the potential interactions with regular page mappings overlapping a huge page region. It seems that this can be handled.

The solution now is to verify my theory and confirm that the conditions described above can actually occur in the code.



236/2 2026/05/25 00:50 tool grepper
0m Args:
map[Expression:#define _PAGE_CHG_MASK]

Results:
map[Output:arch/alpha/include/asm/pgtable.h=23=struct vm_area_struct;
--
arch/alpha/include/asm/pgtable.h-96-#define _PAGE_TABLE	(_PAGE_VALID | __DIRTY_BITS | __ACCESS_BITS)
arch/alpha/include/asm/pgtable.h:97:#define _PAGE_CHG_MASK	(_PFN_MASK | __DIRTY_BITS | __ACCESS_BITS)
arch/alpha/include/asm/pgtable.h-98-
--
arch/arc/include/asm/pgtable-bits-arcv2.h-41-/* Set of bits not changed in pte_modify */
arch/arc/include/asm/pgtable-bits-arcv2.h:42:#define _PAGE_CHG_MASK	(PAGE_MASK_PHYS | _PAGE_ACCESSED | _PAGE_DIRTY | \
arch/arc/include/asm/pgtable-bits-arcv2.h-43-							   _PAGE_SPECIAL)
--
arch/csky/include/asm/pgtable.h-71-
arch/csky/include/asm/pgtable.h:72:#define _PAGE_CHG_MASK	(~(unsigned long) \
arch/csky/include/asm/pgtable.h-73-				(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
--
arch/loongarch/include/asm/pgtable-bits.h-108-
arch/loongarch/include/asm/pgtable-bits.h:109:#define _PAGE_CHG_MASK	(_PAGE_MODIFIED | _PAGE_SPECIAL | _PFN_MASK | _CACHE_MASK | _PAGE_PLV)
arch/loongarch/include/asm/pgtable-bits.h-110-#define _HPAGE_CHG_MASK	(_PAGE_MODIFIED | _PAGE_SPECIAL | _PFN_MASK | _CACHE_MASK | _PAGE_PLV | _PAGE_HUGE)
--
arch/m68k/include/asm/motorola_pgtable.h-39-#define _PAGE_TABLE	(_PAGE_SHORT)
arch/m68k/include/asm/motorola_pgtable.h:40:#define _PAGE_CHG_MASK  (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_NOCACHE)
arch/m68k/include/asm/motorola_pgtable.h-41-
--
arch/microblaze/include/asm/pgtable.h=29=extern pte_t *va_to_pte(unsigned long address);
--
arch/microblaze/include/asm/pgtable.h-175-
arch/microblaze/include/asm/pgtable.h:176:#define _PAGE_CHG_MASK	(PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
arch/microblaze/include/asm/pgtable.h-177-
--
arch/mips/include/asm/pgtable-bits.h=214=static inline uint64_t pte_to_entrylo(unsigned long pte_val)
--
arch/mips/include/asm/pgtable-bits.h-281-
arch/mips/include/asm/pgtable-bits.h:282:#define _PAGE_CHG_MASK	(_PAGE_ACCESSED | _PAGE_MODIFIED |	\
arch/mips/include/asm/pgtable-bits.h-283-			 _PAGE_SOFT_DIRTY | _PFN_MASK |   \
--
arch/openrisc/include/asm/pgtable.h=42=extern void paging_init(void);
--
arch/openrisc/include/asm/pgtable.h-150-
arch/openrisc/include/asm/pgtable.h:151:#define _PAGE_CHG_MASK	(PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
arch/openrisc/include/asm/pgtable.h-152-#define _PAGE_BASE     (_PAGE_PRESENT | _PAGE_ACCESSED)
--
arch/parisc/include/asm/pgtable.h=64=extern void __update_cache(pte_t pte);
--
arch/parisc/include/asm/pgtable.h-205-#define _PAGE_TABLE	(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | _PAGE_DIRTY | _PAGE_ACCESSED)
arch/parisc/include/asm/pgtable.h:206:#define _PAGE_CHG_MASK	(PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_SPECIAL)
arch/parisc/include/asm/pgtable.h-207-#define _PAGE_KERNEL_RO	(_PAGE_PRESENT | _PAGE_READ | _PAGE_DIRTY | _PAGE_ACCESSED)
--
arch/powerpc/include/asm/book3s/32/pgtable.h-74- */
arch/powerpc/include/asm/book3s/32/pgtable.h:75:#define _PAGE_CHG_MASK	(PTE_RPN_MASK | _PAGE_HASHPTE | _PAGE_DIRTY | \
arch/powerpc/include/asm/book3s/32/pgtable.h-76-			 _PAGE_ACCESSED | _PAGE_SPECIAL)
--
arch/powerpc/include/asm/book3s/64/pgtable.h-122- */
arch/powerpc/include/asm/book3s/64/pgtable.h:123:#define _PAGE_CHG_MASK	(PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \
arch/powerpc/include/asm/book3s/64/pgtable.h-124-			 _PAGE_ACCESSED | _PAGE_SPECIAL | _PAGE_PTE |	\
--
arch/powerpc/include/asm/nohash/pgtable.h=6=static inline pte_basic_t pte_update(struct mm_struct *mm, unsigned long addr, pte_t *p,
--
arch/powerpc/include/asm/nohash/pgtable.h-19- */
arch/powerpc/include/asm/nohash/pgtable.h:20:#define _PAGE_CHG_MASK	(PTE_RPN_MASK | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_SPECIAL)
arch/powerpc/include/asm/nohash/pgtable.h-21-
--
arch/riscv/include/asm/pgtable-32.h-31-/* Set of bits to preserve across pte_modify() */
arch/riscv/include/asm/pgtable-32.h:32:#define _PAGE_CHG_MASK  (~(unsigned long)(_PAGE_PRESENT | _PAGE_READ |	\
arch/riscv/include/asm/pgtable-32.h-33-					  _PAGE_WRITE | _PAGE_EXEC |	\
--
arch/riscv/include/asm/pgtable-64.h=159=static inline u64 riscv_page_io(void)
--
arch/riscv/include/asm/pgtable-64.h-171-/* Set of bits to preserve across pte_modify() */
arch/riscv/include/asm/pgtable-64.h:172:#define _PAGE_CHG_MASK  (~(unsigned long)(_PAGE_PRESENT | _PAGE_READ |	\
arch/riscv/include/asm/pgtable-64.h-173-					  _PAGE_WRITE | _PAGE_EXEC |	\
--
arch/s390/include/asm/pgtable.h=130=void setup_protection_map(void);
--
arch/s390/include/asm/pgtable.h-208-/* Set of bits not changed in pte_modify */
arch/s390/include/asm/pgtable.h:209:#define _PAGE_CHG_MASK		(PAGE_MASK | _PAGE_SPECIAL | _PAGE_DIRTY | \
arch/s390/include/asm/pgtable.h-210-				 _PAGE_YOUNG | _PAGE_SOFT_DIRTY)
--
arch/sh/include/asm/pgtable_32.h=97=static inline unsigned long copy_ptea_attributes(unsigned long x)
--
arch/sh/include/asm/pgtable_32.h-168- */
arch/sh/include/asm/pgtable_32.h:169:#define _PAGE_CHG_MASK \
arch/sh/include/asm/pgtable_32.h-170-	(PTE_MASK | _PAGE_ACCESSED | _PAGE_CACHABLE | \
--
arch/um/include/asm/pgtable.h=35=extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
--
arch/um/include/asm/pgtable.h-56-#define _KERNPG_TABLE	(_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
arch/um/include/asm/pgtable.h:57:#define _PAGE_CHG_MASK	(PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
arch/um/include/asm/pgtable.h-58-#define __PAGE_KERNEL_EXEC                                              \
--
arch/x86/include/asm/pgtable_types.h-154-				 _PAGE_CC | _PAGE_UFFD_WP)
arch/x86/include/asm/pgtable_types.h:155:#define _PAGE_CHG_MASK	(_COMMON_PAGE_CHG_MASK | _PAGE_PAT)
arch/x86/include/asm/pgtable_types.h-156-#define _HPAGE_CHG_MASK (_COMMON_PAGE_CHG_MASK | _PAGE_PSE | _PAGE_PAT_LARGE)
--
arch/xtensa/include/asm/pgtable.h-165-
arch/xtensa/include/asm/pgtable.h:166:#define _PAGE_CHG_MASK	   (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
arch/xtensa/include/asm/pgtable.h-167-#define _PAGE_PRESENT	   (_PAGE_HW_VALID | _PAGE_CA_WB | _PAGE_ACCESSED)
]

237/2 2026/05/25 00:50 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 82257
							output: 31
							thoughts: 26
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, as if I were having them:

**Navigating the Virtual Memory Landscape**

Alright, time to dig into this kernel code. Let's start by pinpointing the relevant definitions. I'm going to take a look at `arch/riscv/include/asm/pgtable-64.h:172`. Specifically, I need to understand how the page table is being constructed and managed for this RISC-V architecture in 64-bit mode. I'm hoping that line 172 contains a critical macro or structure definition related to page table entries, or maybe even the base address layout. This is the starting point for figuring out virtual memory translations and how they're mapped to physical addresses. Let's see what we've got.



238/2 2026/05/25 00:50 tool read-file
0m Args:
map[File:arch/riscv/include/asm/pgtable-64.h]

Results:
map[Contents:/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (C) 2012 Regents of the University of California
 */

#ifndef _ASM_RISCV_PGTABLE_64_H
#define _ASM_RISCV_PGTABLE_64_H

#include <linux/bits.h>
#include <linux/const.h>
#include <asm/errata_list.h>

extern bool pgtable_l4_enabled;
extern bool pgtable_l5_enabled;

#define PGDIR_SHIFT_L3  30
#define PGDIR_SHIFT_L4  39
#define PGDIR_SHIFT_L5  48
#define PGDIR_SHIFT     (pgtable_l5_enabled ? PGDIR_SHIFT_L5 : \
		(pgtable_l4_enabled ? PGDIR_SHIFT_L4 : PGDIR_SHIFT_L3))
/* Size of region mapped by a page global directory */
#define PGDIR_SIZE      (_AC(1, UL) << PGDIR_SHIFT)
#define PGDIR_MASK      (~(PGDIR_SIZE - 1))

/* p4d is folded into pgd in case of 4-level page table */
#define P4D_SHIFT_L3   30
#define P4D_SHIFT_L4   39
#define P4D_SHIFT_L5   39
#define P4D_SHIFT      (pgtable_l5_enabled ? P4D_SHIFT_L5 : \
		(pgtable_l4_enabled ? P4D_SHIFT_L4 : P4D_SHIFT_L3))
#define P4D_SIZE       (_AC(1, UL) << P4D_SHIFT)
#define P4D_MASK       (~(P4D_SIZE - 1))

/* pud is folded into pgd in case of 3-level page table */
#define PUD_SHIFT      30
#define PUD_SIZE       (_AC(1, UL) << PUD_SHIFT)
#define PUD_MASK       (~(PUD_SIZE - 1))

#define PMD_SHIFT       21
/* Size of region mapped by a page middle directory */
#define PMD_SIZE        (_AC(1, UL) << PMD_SHIFT)
#define PMD_MASK        (~(PMD_SIZE - 1))

/* Page 4th Directory entry */
typedef struct {
	unsigned long p4d;
} p4d_t;

#define p4d_val(x)	((x).p4d)
#define __p4d(x)	((p4d_t) { (x) })
#define PTRS_PER_P4D	(PAGE_SIZE / sizeof(p4d_t))

/* Page Upper Directory entry */
typedef struct {
	unsigned long pud;
} pud_t;

#define pud_val(x)      ((x).pud)
#define __pud(x)        ((pud_t) { (x) })
#define PTRS_PER_PUD    (PAGE_SIZE / sizeof(pud_t))

/* Page Middle Directory entry */
typedef struct {
	unsigned long pmd;
} pmd_t;

#define pmd_val(x)      ((x).pmd)
#define __pmd(x)        ((pmd_t) { (x) })

#define PTRS_PER_PMD    (PAGE_SIZE / sizeof(pmd_t))

#define MAX_POSSIBLE_PHYSMEM_BITS 56

/*
 * rv64 PTE format:
 * | 63 | 62 61 | 60 54 | 53  10 | 9             8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
 *   N      MT     RSV    PFN      reserved for SW   D   A   G   U   X   W   R   V
 */
#define _PAGE_PFN_MASK  GENMASK(53, 10)

/*
 * [63] Svnapot definitions:
 * 0 Svnapot disabled
 * 1 Svnapot enabled
 */
#define _PAGE_NAPOT_SHIFT	63
#define _PAGE_NAPOT		BIT(_PAGE_NAPOT_SHIFT)
/*
 * Only 64KB (order 4) napot ptes supported.
 */
#define NAPOT_CONT_ORDER_BASE 4
enum napot_cont_order {
	NAPOT_CONT64KB_ORDER = NAPOT_CONT_ORDER_BASE,
	NAPOT_ORDER_MAX,
};

#define for_each_napot_order(order)						\
	for (order = NAPOT_CONT_ORDER_BASE; order < NAPOT_ORDER_MAX; order++)
#define for_each_napot_order_rev(order)						\
	for (order = NAPOT_ORDER_MAX - 1;					\
	     order >= NAPOT_CONT_ORDER_BASE; order--)
#define napot_cont_order(val)	(__builtin_ctzl((val.pte >> _PAGE_PFN_SHIFT) << 1))

#define napot_cont_shift(order)	((order) + PAGE_SHIFT)
#define napot_cont_size(order)	BIT(napot_cont_shift(order))
#define napot_cont_mask(order)	(~(napot_cont_size(order) - 1UL))
#define napot_pte_num(order)	BIT(order)

#ifdef CONFIG_RISCV_ISA_SVNAPOT
#define HUGE_MAX_HSTATE		(2 + (NAPOT_ORDER_MAX - NAPOT_CONT_ORDER_BASE))
#else
#define HUGE_MAX_HSTATE		2
#endif

/*
 * [62:61] Svpbmt Memory Type definitions:
 *
 *  00 - PMA    Normal Cacheable, No change to implied PMA memory type
 *  01 - NC     Non-cacheable, idempotent, weakly-ordered Main Memory
 *  10 - IO     Non-cacheable, non-idempotent, strongly-ordered I/O memory
 *  11 - Rsvd   Reserved for future standard use
 */
#define _PAGE_NOCACHE_SVPBMT	(1UL << 61)
#define _PAGE_IO_SVPBMT		(1UL << 62)
#define _PAGE_MTMASK_SVPBMT	(_PAGE_NOCACHE_SVPBMT | _PAGE_IO_SVPBMT)

/*
 * [63:59] T-Head Memory Type definitions:
 * bit[63] SO - Strong Order
 * bit[62] C - Cacheable
 * bit[61] B - Bufferable
 * bit[60] SH - Shareable
 * bit[59] Sec - Trustable
 * 00110 - NC   Weakly-ordered, Non-cacheable, Bufferable, Shareable, Non-trustable
 * 01110 - PMA  Weakly-ordered, Cacheable, Bufferable, Shareable, Non-trustable
 * 10010 - IO   Strongly-ordered, Non-cacheable, Non-bufferable, Shareable, Non-trustable
 */
#define _PAGE_PMA_THEAD		((1UL << 62) | (1UL << 61) | (1UL << 60))
#define _PAGE_NOCACHE_THEAD	((1UL << 61) | (1UL << 60))
#define _PAGE_IO_THEAD		((1UL << 63) | (1UL << 60))
#define _PAGE_MTMASK_THEAD	(_PAGE_PMA_THEAD | _PAGE_IO_THEAD | (1UL << 59))

static inline u64 riscv_page_mtmask(void)
{
	u64 val;

	ALT_SVPBMT(val, _PAGE_MTMASK);
	return val;
}

static inline u64 riscv_page_nocache(void)
{
	u64 val;

	ALT_SVPBMT(val, _PAGE_NOCACHE);
	return val;
}

static inline u64 riscv_page_io(void)
{
	u64 val;

	ALT_SVPBMT(val, _PAGE_IO);
	return val;
}

#define _PAGE_NOCACHE		riscv_page_nocache()
#define _PAGE_IO		riscv_page_io()
#define _PAGE_MTMASK		riscv_page_mtmask()

/* Set of bits to preserve across pte_modify() */
#define _PAGE_CHG_MASK  (~(unsigned long)(_PAGE_PRESENT | _PAGE_READ |	\
					  _PAGE_WRITE | _PAGE_EXEC |	\
					  _PAGE_USER | _PAGE_GLOBAL |	\
					  _PAGE_MTMASK))

static inline int pud_present(pud_t pud)
{
	return (pud_val(pud) & _PAGE_PRESENT);
}

static inline int pud_none(pud_t pud)
{
	return (pud_val(pud) == 0);
}

static inline int pud_bad(pud_t pud)
{
	return !pud_present(pud) || (pud_val(pud) & _PAGE_LEAF);
}

#define pud_leaf	pud_leaf
static inline bool pud_leaf(pud_t pud)
{
	return pud_present(pud) && (pud_val(pud) & _PAGE_LEAF);
}

static inline int pud_user(pud_t pud)
{
	return pud_val(pud) & _PAGE_USER;
}

static inline void set_pud(pud_t *pudp, pud_t pud)
{
	WRITE_ONCE(*pudp, pud);
}

static inline void pud_clear(pud_t *pudp)
{
	set_pud(pudp, __pud(0));
}

static inline pud_t pfn_pud(unsigned long pfn, pgprot_t prot)
{
	return __pud((pfn << _PAGE_PFN_SHIFT) | pgprot_val(prot));
}

static inline unsigned long _pud_pfn(pud_t pud)
{
	return __page_val_to_pfn(pud_val(pud));
}

static inline pmd_t *pud_pgtable(pud_t pud)
{
	return (pmd_t *)pfn_to_virt(__page_val_to_pfn(pud_val(pud)));
}

static inline struct page *pud_page(pud_t pud)
{
	return pfn_to_page(__page_val_to_pfn(pud_val(pud)));
}

#define mm_p4d_folded  mm_p4d_folded
static inline bool mm_p4d_folded(struct mm_struct *mm)
{
	if (pgtable_l5_enabled)
		return false;

	return true;
}

#define mm_pud_folded  mm_pud_folded
static inline bool mm_pud_folded(struct mm_struct *mm)
{
	if (pgtable_l4_enabled)
		return false;

	return true;
}

#define pmd_index(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))

static inline pmd_t pfn_pmd(unsigned long pfn, pgprot_t prot)
{
	unsigned long prot_val = pgprot_val(prot);

	ALT_THEAD_PMA(prot_val);

	return __pmd((pfn << _PAGE_PFN_SHIFT) | prot_val);
}

static inline unsigned long _pmd_pfn(pmd_t pmd)
{
	return __page_val_to_pfn(pmd_val(pmd));
}

#define pmd_ERROR(e) \
	pr_err("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e))

#define pud_ERROR(e)   \
	pr_err("%s:%d: bad pud %016lx.\n", __FILE__, __LINE__, pud_val(e))

#define p4d_ERROR(e)   \
	pr_err("%s:%d: bad p4d %016lx.\n", __FILE__, __LINE__, p4d_val(e))

static inline void set_p4d(p4d_t *p4dp, p4d_t p4d)
{
	if (pgtable_l4_enabled)
		WRITE_ONCE(*p4dp, p4d);
	else
		set_pud((pud_t *)p4dp, (pud_t){ p4d_val(p4d) });
}

static inline int p4d_none(p4d_t p4d)
{
	if (pgtable_l4_enabled)
		return (p4d_val(p4d) == 0);

	return 0;
}

static inline int p4d_present(p4d_t p4d)
{
	if (pgtable_l4_enabled)
		return (p4d_val(p4d) & _PAGE_PRESENT);

	return 1;
}

static inline int p4d_bad(p4d_t p4d)
{
	if (pgtable_l4_enabled)
		return !p4d_present(p4d);

	return 0;
}

static inline void p4d_clear(p4d_t *p4d)
{
	if (pgtable_l4_enabled)
		set_p4d(p4d, __p4d(0));
}

static inline p4d_t pfn_p4d(unsigned long pfn, pgprot_t prot)
{
	return __p4d((pfn << _PAGE_PFN_SHIFT) | pgprot_val(prot));
}

static inline unsigned long _p4d_pfn(p4d_t p4d)
{
	return __page_val_to_pfn(p4d_val(p4d));
}

static inline pud_t *p4d_pgtable(p4d_t p4d)
{
	if (pgtable_l4_enabled)
		return (pud_t *)pfn_to_virt(__page_val_to_pfn(p4d_val(p4d)));

	return (pud_t *)pud_pgtable((pud_t) { p4d_val(p4d) });
}
#define p4d_page_vaddr(p4d)	((unsigned long)p4d_pgtable(p4d))

static inline struct page *p4d_page(p4d_t p4d)
{
	return pfn_to_page(__page_val_to_pfn(p4d_val(p4d)));
}

#define pud_index(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))

#define pud_offset pud_offset
pud_t *pud_offset(p4d_t *p4d, unsigned long address);

static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
{
	if (pgtable_l5_enabled)
		WRITE_ONCE(*pgdp, pgd);
	else
		set_p4d((p4d_t *)pgdp, (p4d_t){ pgd_val(pgd) });
}

static inline int pgd_none(pgd_t pgd)
{
	if (pgtable_l5_enabled)
		return (pgd_val(pgd) == 0);

	return 0;
}

static inline int pgd_present(pgd_t pgd)
{
	if (pgtable_l5_enabled)
		return (pgd_val(pgd) & _PAGE_PRESENT);

	return 1;
}

static inline int pgd_bad(pgd_t pgd)
{
	if (pgtable_l5_enabled)
		return !pgd_present(pgd);

	return 0;
}

static inline void pgd_clear(pgd_t *pgd)
{
	if (pgtable_l5_enabled)
		set_pgd(pgd, __pgd(0));
}

static inline p4d_t *pgd_pgtable(pgd_t pgd)
{
	if (pgtable_l5_enabled)
		return (p4d_t *)pfn_to_virt(__page_val_to_pfn(pgd_val(pgd)));

	return (p4d_t *)p4d_pgtable((p4d_t) { pgd_val(pgd) });
}
#define pgd_page_vaddr(pgd)	((unsigned long)pgd_pgtable(pgd))

static inline struct page *pgd_page(pgd_t pgd)
{
	return pfn_to_page(__page_val_to_pfn(pgd_val(pgd)));
}
#define pgd_page(pgd)	pgd_page(pgd)

#define p4d_index(addr) (((addr) >> P4D_SHIFT) & (PTRS_PER_P4D - 1))

#define p4d_offset p4d_offset
p4d_t *p4d_offset(pgd_t *pgd, unsigned long address);

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
static inline pte_t pmd_pte(pmd_t pmd);
static inline pte_t pud_pte(pud_t pud);
#endif

#endif /* _ASM_RISCV_PGTABLE_64_H */
]

239/2 2026/05/25 00:50 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 86874
							output: 20
							thoughts: 4080
						

Thoughts:
**Deep Dive into Huge Page PTE Management and Potential Map Count Leaks**

Okay, here's the deal, I've been wrestling with this huge page memory management code, trying to understand this bug and how `_PAGE_NAPOT` plays a role in potential map count leaks. Let's break down my thought process:

First, I examined the `_PAGE_CHG_MASK`, which essentially defines which bits in a PTE are *preserved* during modifications.  I quickly confirmed that `_PAGE_NAPOT` is, by design, preserved by this mask.  This made sense because `_PAGE_NAPOT` is crucial for marking a PTE as part of a contiguous huge page, and that information needs to be retained. I also verified `pte_mknapot`'s behavior, which is to correctly set `_PAGE_NAPOT` and encode the order (size) within the PFN bits. This function is correctly handling setting the value.

Then I went back to the core issue, that kernel bug report, and the `__page_table_check_zero` error, which tells me that either `anon_map_count` or `file_map_count` is non-zero when a page should be freed. This clearly points to an imbalance in the bookkeeping – someone is forgetting to decrement a map count when the page is unmapped.  I immediately thought that a potential culprit could be that some code directly clearing a PTE, bypassing the usual `page_table_check_pte_clear` mechanism.

I started by looking at `huge_pte_clear`, and I recalled that it uses `pte_clear`. I checked that it's called on *non-present* PTEs: migration entries, HWPOISON, or UFFD_WP markers (which are *not* a real page, so that's consistent). However, I also found a place where a UFFD_WP marker could be placed *on* a present PTE in `hugetlb_change_protection`, but that is handled through paired operations to ensure that the code is correctly balanced.

Then, I looked at `__unmap_hugepage_range`, which calls `huge_pte_clear`. I confirmed that it's called *only* on non-present PTEs, or in the case of a UFFD_WP migration entry. However, if that entry already had UFFD_WP, and we *don't* want to drop the marker, we *do* overwrite it with a new marker using `set_huge_pte_at`.  Still, this case is balanced and correctly removes the original marker.

Next, I found the code in `arch/riscv/mm/hugetlbpage.c` where `huge_pte_clear` is being called directly. In this code, if the PTE is *not* `_PAGE_NAPOT`, it *does* call `pte_clear`, which could indeed bypass the check. However, if the PTE *is* `_PAGE_NAPOT`, the function properly iterates through all 16 sub-PTES and calls `pte_clear` on each of them.  So, at a glance, this looks fine.

I dug deeper, and considered what happens if the PTE is present but not `_PAGE_NAPOT`. However, this is correct for PMD-sized pages. If a *NAPOT* PTE is being modified, all 16 entries are cleared in an operation that should keep the map count in balance.

I then started to think about where else might clear a PTE, and I considered `huge_pmd_unshare`, but quickly realized that this only applies to PMD-sized huge pages, and not the NAPOT huge pages which are what's being investigated.

I then returned to the fault report again. How could an anonymous page have a map count leak? I had to think through how these huge pages are used. I tracked the memory mapping with `hugetlb_fault` -> `hugetlb_no_page` -> `alloc_hugetlb_folio` -> `set_huge_pte_at`.  Each set operation would correctly increment the map count. Then, during process exit, `exit_mmap` and `__unmap_hugepage_range` should call `huge_ptep_get_and_clear` to clear all those PTEs and decrement the map count. This is how it should be working.

Then I considered the scenario where a process forks. I looked into `copy_hugetlb_page_range`, which has the critical code for handling copy-on-write. This code uses `huge_pte_wrprotect` to make an entry read-only and `set_huge_pte_at` to copy the entry to a new process. I analyzed how `


240/2 2026/05/25 00:51 tool grepper
0m Args:
map[Expression:huge_pte_clear\(]

Results:
map[Output:arch/arm64/include/asm/hugetlb.h=51=extern pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
--
arch/arm64/include/asm/hugetlb.h-53-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/arm64/include/asm/hugetlb.h:54:extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/arm64/include/asm/hugetlb.h-55-			   pte_t *ptep, unsigned long sz);
--
arch/arm64/mm/hugetlbpage.c=344=pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
--
arch/arm64/mm/hugetlbpage.c-368-
arch/arm64/mm/hugetlbpage.c:369:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/arm64/mm/hugetlbpage.c-370-		    pte_t *ptep, unsigned long sz)
--
arch/loongarch/include/asm/hugetlb.h=11=uint64_t pmd_to_entrylo(unsigned long pmd_val);
--
arch/loongarch/include/asm/hugetlb.h-13-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/loongarch/include/asm/hugetlb.h:14:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/loongarch/include/asm/hugetlb.h-15-				  pte_t *ptep, unsigned long sz)
--
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h=23=static inline pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
--
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-30-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h:31:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-32-				  pte_t *ptep, unsigned long sz)
--
arch/riscv/include/asm/hugetlb.h=15=bool arch_hugetlb_migration_supported(struct hstate *h);
--
arch/riscv/include/asm/hugetlb.h-20-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/riscv/include/asm/hugetlb.h:21:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/riscv/include/asm/hugetlb.h-22-		    pte_t *ptep, unsigned long sz);
--
arch/riscv/mm/hugetlbpage.c=346=pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
--
arch/riscv/mm/hugetlbpage.c-360-
arch/riscv/mm/hugetlbpage.c:361:void huge_pte_clear(struct mm_struct *mm,
arch/riscv/mm/hugetlbpage.c-362-		    unsigned long addr,
--
arch/s390/include/asm/hugetlb.h=33=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
--
arch/s390/include/asm/hugetlb.h-40-#define __HAVE_ARCH_HUGE_PTE_CLEAR
arch/s390/include/asm/hugetlb.h:41:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
arch/s390/include/asm/hugetlb.h-42-				  pte_t *ptep, unsigned long sz)
--
include/asm-generic/hugetlb.h=55=static inline int huge_pte_uffd_wp(pte_t pte)
--
include/asm-generic/hugetlb.h-61-#ifndef __HAVE_ARCH_HUGE_PTE_CLEAR
include/asm-generic/hugetlb.h:62:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
include/asm-generic/hugetlb.h-63-		    pte_t *ptep, unsigned long sz)
--
mm/hugetlb.c=5052=static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,
--
mm/hugetlb.c-5074-	if (need_clear_uffd_wp && pte_is_uffd_wp_marker(pte)) {
mm/hugetlb.c:5075:		huge_pte_clear(mm, new_addr, dst_pte, sz);
mm/hugetlb.c-5076-	} else {
--
mm/hugetlb.c=5156=void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
--
mm/hugetlb.c-5220-			else
mm/hugetlb.c:5221:				huge_pte_clear(mm, address, ptep, sz);
mm/hugetlb.c-5222-			spin_unlock(ptl);
--
mm/hugetlb.c=6398=long hugetlb_change_protection(struct vm_area_struct *vma,
--
mm/hugetlb.c-6506-				/* Safe to modify directly (non-present->none). */
mm/hugetlb.c:6507:				huge_pte_clear(mm, address, ptep, psize);
mm/hugetlb.c-6508-		} else {
]

241/2 2026/05/25 00:51 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 93572
							output: 24
							thoughts: 1188
						

Thoughts:
**Analyzing Potential Bugs in HugeTLB PTE Handling**

Okay, so we've established that the `huge_pte_clear` function in `mm/hugetlb.c` isn't the culprit, because it's only called on non-present PTEs, which are therefore exempt from the `page_table_check`. Good. Now, what about other functions? Let's zoom in on `arch/riscv/mm/hugetlbpage.c`. I need to exhaustively examine everything that interacts with PTEs and make sure it doesn't bypass the checks.

First, `get_clear_contig`. It uses `ptep_get_and_clear`, which calls `page_table_check_pte_clear`, so that's fine. Next, `clear_flush` also uses `ptep_get_and_clear`. Again, that seems correct, since it goes through the check. Moving on, `set_huge_pte_at` is next, and that uses `set_pte_at`, which should call `page_table_check_ptes_set`. Perfect. `huge_ptep_set_access_flags` does the same. As does `huge_ptep_set_wrprotect`.

Wait a minute, what about `ptep_set_wrprotect`? This one modifies the PTE directly using atomic operations. Hmm... `page_table_check` tracks the number of present, user PTEs. `ptep_set_wrprotect` removes the write flag, so the PTE is still present and user accessible. But... that means `page_table_check` shouldn't be updated. I think that's the problem.

Let's think. `page_table_check_set` takes `pte_write(pte)` as a parameter. It looks like it only updates the check when `set_pte_at` is used. If `ptep_set_wrprotect` *directly* modifies the PTE to be read-only, it doesn't notify `page_table_check`. I think that's where the writable tracking is falling out of sync. Could this be it? There's no function named `page_table_check_pte_wrprotect`, so that seems to confirm the suspicion. I need to investigate the `mm/page_table_check.c` file more closely. I think I've found a crucial lead.



242/2 2026/05/25 00:51 tool grepper
0m Error:
no matches

Args:
map[Expression:page_table_check_pte_wrprotect]

Results:
map[Output:]

243/2 2026/05/25 00:51 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 95319
							output: 46
							thoughts: 724
						

Thoughts:
**Analyzing a Page Table Check Bug**

Okay, so the `page_table_check` function isn't tracking `wrprotect` transitions, it only registers a `set` or a `clear`. I just realized that if a Page Table Entry (PTE) goes read-only, its write count in `page_table_check` will incorrectly remain positive. Then, when the page is freed, the map counts (`anon_map_count` and `file_map_count`) might be zero, but the write counts (`anon_write_count` or `file_write_count`) could still be greater than zero!

But wait, the `BUG_ON` in the crash is on `anon_map_count`! Not on a write count leak! So, this is a map count leak, not a write count leak. I was going down the wrong path initially.

I need to figure out where else `pte_clear` is being used. Let's look at `arch/riscv/include/asm/pgtable.h` to see how it's defined. It just calls `__set_pte_at` with zero. Now, let's look for how `pte_clear` is called in the code.

Okay, let's see if `pte_clear` is used in `pmdp_huge_get_and_clear`. Hmm, it calls `page_table_check_pmd_clear`. That seems correct. And what about `pudp_huge_get_and_clear`? Yes, that calls `page_table_check_pud_clear`. Correct, too.

I should also check `pmdp_collapse_flush`. It's defined in `arch/riscv/mm/pgtable.c`. Let's see what it does.



244/2 2026/05/25 00:51 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/mm/pgtable.c IncludeLines:true Name:pmdp_collapse_flush]

Results:
map[SourceCode: 221:	pmd_t pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long address,
 222:				  pmd_t *pmdp)
 223:	{
 224:		/*
 225:		 * pmd and hugepage pte format are same. So we could
 226:		 * use the same function.
 227:		 */
 228:		pmd_t pmd;
 229:	
 230:		VM_BUG_ON(address & ~HPAGE_PMD_MASK);
 231:		VM_BUG_ON(pmd_trans_huge(*pmdp));
 232:		pmd = pmdp_huge_get_and_clear(vma->vm_mm, address, pmdp);
 233:	
 234:		/* collapse entails shooting down ptes not pmd */
 235:		flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
 236:		return pmd;
 237:	}
 SourceFile:mm/pgtable-generic.c]

245/2 2026/05/25 00:51 llm expert
1m Model:
gemini-3.1-pro-preview

Tokens:
							input: 96790
							output: 45
							thoughts: 6884
						

Thoughts:
**Deep Dive into Page Table Management: A Critical Analysis**

Alright, let's break this down systematically. My initial concern was about how map counts are handled during PTE operations, specifically focusing on the `mm/pgtable-generic.c` file and huge pages. The core question is: Are map counts balanced when a PTE is cleared or modified, especially in the context of huge pages?

The investigation started with the basic clearing mechanisms. `pmdp_huge_get_and_clear` correctly uses `page_table_check_pmd_clear`, and that seems fine. Similarly, `ptep_get_and_clear` and the other obvious suspects are using checks which appear balanced. `ptep_clear_flush_young` isn't affecting map count by design, as it only modifies access bits. `ptep_set_access_flags` looked like the real area of concern. It utilizes `set_pte_at`, which then calls `__page_table_check_ptes_set`. This function is pivotal, as it decrements the map count of the *old* PTE and increments the count of the *new* PTE. If the new PTE shares the same PFN as the old PTE, this is a balanced operation. Since this is usually the case, that seems right.

The worry then shifted to scenarios where the PFN *could* change with `ptep_set_access_flags`, but this is used exclusively for access flag updates. So, that's also safe. `set_ptes` handles multiple PTEs, but it appropriately calls `page_table_check_ptes_set`, which is a balanced operation in the standard case.

Next, I looked for places where a PTE might be cleared *without* the `page_table_check_pte_clear` call. This is where `huge_pte_clear` and `huge_ptep_set_wrprotect` came into focus. `huge_pte_clear` is only intended for non-present PTEs, a check that's implemented, so it doesn't represent an issue there.

`huge_ptep_set_wrprotect` is much more complex. This function calls a chain of functions to perform a write protect: `get_clear_contig_flush`, which ends up calling `ptep_get_and_clear` to decrement the map count, and `set_pte_at` to increment it. This is where the intricacies of huge page mapping arise. I needed to understand the effect of clear/set of PTEs, and the implications of the NAPOT encoding.

I tracked through several functions. For instance, `huge_ptep_clear_flush` calls `ptep_clear_flush`, which ends up calling `ptep_get_and_clear` (decrement map count) followed by `page_table_check_pte_clear`. That's safe. However, in the huge page case it ends up in a call to `get_clear_contig_flush` which is where all of the set/clear happens at once.

The focus then shifted to the `huge_ptep_set_wrprotect` which led me to dive deep into NAPOT encoding, specifically. Then, I needed to check what happens in calls like `pte_pfn` where the NAPOT bits can be used, and if those can cause issues. The NAPOT mechanism cleverly uses PFN bits to encode the size of the huge page. The encoding needs to be preserved during PTE modifications, which is what the `_PAGE_CHG_MASK` mask in `pte_modify` achieves.

I went through the potential scenarios, from the initial setting of the bit, to the clearing of the bit, to how the information is used to update the map. `pte_pfn` uses bit operations to remove the bit for the size and recover the physical address, and `set_huge_pte_at` is then used to actually set the value for all the PTEs, so it is balanced. The question of whether or not the encoding is correctly preserved and handled by `page_table_check_set` in `set_huge_pte_at` was the final concern, because it ends up calling `page_table_check_set` many times, but since the PTEs are identical for the same huge page, it correctly increments the map count for all of the PTEs used.

The final question was what happens with the map count, when the page is freed: `page_table_check_zero` shows that it checks the map count for the underlying page.

In conclusion, after this detailed tracing, the map count operations, including those related to huge pages and the NAPOT encoding, are correct, and the counts are consistently balanced.



246/2 2026/05/25 00:52 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/page_table_check.c IncludeLines:true Name:page_table_check_set]

Results:
map[SourceCode:  92:	/*
  93:	 * A new entry is added to the page table, increment the counters for that page
  94:	 * verify that it is of correct type and is not being mapped with a different
  95:	 * type to a different process.
  96:	 */
  97:	static void page_table_check_set(unsigned long pfn, unsigned long pgcnt,
  98:					 bool rw)
  99:	{
 100:		struct page_ext_iter iter;
 101:		struct page_ext *page_ext;
 102:		struct page *page;
 103:		bool anon;
 104:	
 105:		if (!pfn_valid(pfn))
 106:			return;
 107:	
 108:		page = pfn_to_page(pfn);
 109:		BUG_ON(PageSlab(page));
 110:		anon = PageAnon(page);
 111:	
 112:		rcu_read_lock();
 113:		for_each_page_ext(page, pgcnt, page_ext, iter) {
 114:			struct page_table_check *ptc = get_page_table_check(page_ext);
 115:	
 116:			if (anon) {
 117:				BUG_ON(atomic_read(&ptc->file_map_count));
 118:				BUG_ON(atomic_inc_return(&ptc->anon_map_count) > 1 && rw);
 119:			} else {
 120:				BUG_ON(atomic_read(&ptc->anon_map_count));
 121:				BUG_ON(atomic_inc_return(&ptc->file_map_count) < 0);
 122:			}
 123:		}
 124:		rcu_read_unlock();
 125:	}
 SourceFile:mm/page_table_check.c]

247/2 2026/05/25 00:52 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 105274
							output: 24
							thoughts: 2318
						

Thoughts:
**A Deep Dive into Huge Page PTE Manipulation**

Okay, so I'm tracing this `page_table_check_set` function and the surrounding huge page handling, and there are some interesting subtleties that need careful consideration. Initially, I was concerned about potential map count leaks when dealing with 64KB-aligned PFNS. If `set_pte_at` is called repeatedly for a 64KB-aligned PFN, the intention is to increment the map count of the first 4KB page within that 64KB block. However, I needed to confirm that the other 15 4KB pages within the 64KB block weren't left with an incorrect map count, potentially leading to errors during page freeing.

My initial assumption was correct, thanks to how `pte_pfn(pte)` is implemented; it effectively normalizes the PFN to the 64KB boundary for *all* PTEs, so the first 4K page's map count is indeed incremented by 16. The other 15 4K pages are left at zero. The crucial aspect is the subsequent decrement, and that is handled correctly with `ptep_get_and_clear`, which calls `page_table_check_clear`, decrementing the map count of the same first 4K page 16 times, bringing the count back to zero. This ensures the 64KB block is cleaned up correctly, and it does *not* cause a leak.

Now, things get more interesting. I needed to consider a scenario where `set_huge_pte_at` is called with a non-present PTE. The code handles this by looping 16 times and writing the non-present PTE to all 16 entries which is important for migrating pages in the event the page isn't present anymore.

Next, I had to ensure that if `set_huge_pte_at` *is* called on a PMD-sized huge page, the right thing happens. The key here is to determine whether the resulting `pte_num` is 1 or 16 and that depends on the size. When using `PMD_SIZE`, `num_contig_ptes_from_size` will return 1, and the correct path will be followed.

I then started thinking about a case where the architectured code could fail, to write to 64KB pages. But the calls to `arch_make_huge_pte` ensures that the `_PAGE_NAPOT` flag is set when dealing with a 64KB (or other NAPOT) size. The presence of the `_PAGE_NAPOT` ensures the 16 writes needed for full PTE replacement occur, preserving the page mapping.

Finally, I considered protection changes via `huge_ptep_modify_prot_commit`. Crucially, I see a conditional where, if `!pte_napot(old_pte)`, it calls `set_huge_pte_at`, else, it manually calls set/clear ptes in a loop. I need to make sure this is implemented as expected on the target architecture. So I'll need to confirm that this function exists and operates correctly, particularly in the RISC-V implementation, but given the current code path, it looks correct. The manual loop ensures a correct replacement.



248/2 2026/05/25 00:53 tool grepper
0m Args:
map[Expression:huge_ptep_modify_prot_commit]

Results:
map[Output:arch/arm64/include/asm/hugetlb.h=60=extern pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma,
--
arch/arm64/include/asm/hugetlb.h-62-
arch/arm64/include/asm/hugetlb.h:63:#define huge_ptep_modify_prot_commit huge_ptep_modify_prot_commit
arch/arm64/include/asm/hugetlb.h:64:extern void huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
arch/arm64/include/asm/hugetlb.h-65-					 unsigned long addr, pte_t *ptep,
--
arch/arm64/mm/hugetlbpage.c=517=pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
--
arch/arm64/mm/hugetlbpage.c-532-
arch/arm64/mm/hugetlbpage.c:533:void huge_ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep,
arch/arm64/mm/hugetlbpage.c-534-				  pte_t old_pte, pte_t pte)
--
arch/powerpc/include/asm/book3s/64/hugetlb.h=13=void radix__local_flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
arch/powerpc/include/asm/book3s/64/hugetlb.h-14-
arch/powerpc/include/asm/book3s/64/hugetlb.h:15:extern void radix__huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
arch/powerpc/include/asm/book3s/64/hugetlb.h-16-						unsigned long addr, pte_t *ptep,
--
arch/powerpc/include/asm/book3s/64/hugetlb.h=53=extern pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma,
--
arch/powerpc/include/asm/book3s/64/hugetlb.h-55-
arch/powerpc/include/asm/book3s/64/hugetlb.h:56:#define huge_ptep_modify_prot_commit huge_ptep_modify_prot_commit
arch/powerpc/include/asm/book3s/64/hugetlb.h:57:extern void huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
arch/powerpc/include/asm/book3s/64/hugetlb.h-58-					 unsigned long addr, pte_t *ptep,
--
arch/powerpc/mm/book3s64/hugetlbpage.c=138=pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma,
--
arch/powerpc/mm/book3s64/hugetlbpage.c-152-
arch/powerpc/mm/book3s64/hugetlbpage.c:153:void huge_ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr,
arch/powerpc/mm/book3s64/hugetlbpage.c-154-				  pte_t *ptep, pte_t old_pte, pte_t pte)
--
arch/powerpc/mm/book3s64/hugetlbpage.c-158-	if (radix_enabled())
arch/powerpc/mm/book3s64/hugetlbpage.c:159:		return radix__huge_ptep_modify_prot_commit(vma, addr, ptep,
arch/powerpc/mm/book3s64/hugetlbpage.c-160-							   old_pte, pte);
--
arch/powerpc/mm/book3s64/radix_hugetlbpage.c=28=void radix__flush_hugetlb_tlb_range(struct vm_area_struct *vma, unsigned long start,
--
arch/powerpc/mm/book3s64/radix_hugetlbpage.c-44-
arch/powerpc/mm/book3s64/radix_hugetlbpage.c:45:void radix__huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
arch/powerpc/mm/book3s64/radix_hugetlbpage.c-46-					 unsigned long addr, pte_t *ptep,
--
fs/proc/task_mmu.c=2509=static void make_uffd_wp_huge_pte(struct vm_area_struct *vma,
--
fs/proc/task_mmu.c-2529-	else
fs/proc/task_mmu.c:2530:		huge_ptep_modify_prot_commit(vma, addr, ptep, ptent,
fs/proc/task_mmu.c-2531-					     huge_pte_mkuffd_wp(ptent));
--
include/linux/hugetlb.h=1061=static inline pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma,
--
include/linux/hugetlb.h-1069-
include/linux/hugetlb.h:1070:#ifndef huge_ptep_modify_prot_commit
include/linux/hugetlb.h:1071:#define huge_ptep_modify_prot_commit huge_ptep_modify_prot_commit
include/linux/hugetlb.h:1072:static inline void huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
include/linux/hugetlb.h-1073-						unsigned long addr, pte_t *ptep,
--
mm/hugetlb.c=6398=long hugetlb_change_protection(struct vm_area_struct *vma,
--
mm/hugetlb.c-6518-				pte = huge_pte_clear_uffd_wp(pte);
mm/hugetlb.c:6519:			huge_ptep_modify_prot_commit(vma, address, ptep, old_pte, pte);
mm/hugetlb.c-6520-			pages++;
]

249/2 2026/05/25 00:53 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 110009
							output: 48
							thoughts: 50
						

Thoughts:
Okay, here's my take on those thoughts, framed as my own:

**RISC-V and HugeTLB Protection - A Quick Dive**

Right, so I was looking at the RISC-V kernel code, and it hit me – RISC-V *doesn't* have its own specific implementation of `huge_ptep_modify_prot_commit`. That's a bit surprising, but not unheard of. It means the architecture's relying on the generic one defined in `include/linux/hugetlb.h`.  Alright, makes sense, let's go check out that generic implementation and see what it's doing under the hood. I need to understand how the protection changes are being handled when RISC-V leverages the shared generic function, it's the next logical step. I need to reconcile that with the expected RISC-V behavior.



250/2 2026/05/25 00:53 tool codesearch-definition-source
0m Args:
map[ContextFile:include/linux/hugetlb.h IncludeLines:true Name:huge_ptep_modify_prot_commit]

Results:
map[SourceCode:1072:	static inline void huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
1073:							unsigned long addr, pte_t *ptep,
1074:							pte_t old_pte, pte_t pte)
1075:	{
1076:		unsigned long psize = huge_page_size(hstate_vma(vma));
1077:	
1078:		set_huge_pte_at(vma->vm_mm, addr, ptep, pte, psize);
1079:	}
 SourceFile:include/linux/hugetlb.h]

251/2 2026/05/25 00:53 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 110481
							output: 52
							thoughts: 4094
						

Thoughts:
**Deep Dive into Potential Map Count Leaks in HugeTLB Code**

Okay, so I've been wrestling with this `hugetlb` code, specifically around how it handles Protection Key (PK) operations and the implications for map counts. It seems like the core issue revolves around `set_huge_pte_at` and its interplay with clearing PTEs, especially in the context of `_PAGE_NAPOT` and potential non-present PTEs.

I started by tracing the standard path: `huge_ptep_modify_prot_start` clears 16 PTEs, and `set_huge_pte_at` writes them back. That looked balanced initially. But I then explored the edge cases, and that’s where things get interesting. The problem is I have to consider the fact that sometimes `_PAGE_NAPOT` isn't present, but the code assumes it is.

The code assumes that `huge_ptep_modify_prot_start` is always paired with `huge_ptep_modify_prot_commit`. I tried to figure out if there were cases where this wasn't true.

What I've been focusing on now is: If a huge PTE is cleared, but not using the full 16 entries - can that create a map count leak? It seems like this happens if:
1.  `pte_present(pte)` is false: Meaning the PTE isn't mapped in memory.
2.  `pte_napot(pte)` is false: It's not a valid huge PTE.

If it's a migration entry, it bypasses the `set_huge_pte_at` with its full 16, instead, it clears a single entry. This, I think, is the key - it leaves 15 migration entries behind. Since migration entries are "not present", this does *not* leak the map count.

However, if `pte_present(pte)` *is* true, and `pte_napot(pte)` is false (which I realized can be the case if it's a PROT_NONE PTE), then `set_huge_pte_at` *does* get called but only for one single entry. The issue with this case is the map count will *not* be balanced, and will leak.

Digging further, I considered HWPOISON entries - similar scenario, but these are *also* not present. So, no map count leak there.

The crash I'm seeing is a `BUG_ON` related to a non-zero `anon_map_count` when a page is being freed. This suggests a map count imbalance.
The crash must be if page is checked and set to a high number, but cleared as low.

I've examined the code for `huge_ptep_get_and_clear` because that’s where the actual PTE clearing occurs.

*   If the huge page's state is valid (_PAGE_NAPOT is present), it *should* clear all 16 PTEs.
*   But, if not valid (_PAGE_NAPOT is not present), it uses `ptep_get_and_clear` to clear only a single PTE.

But there is still a bug that I am trying to work out in my head.

Now, I was re-examining commit `83d78ac677b9`. This commit changed `huge_ptep_get_and_clear` to use a `sz` parameter for the number of PTEs to clear instead of relying on `pte_napot(orig_pte)`. This seems concerning, but not because it's *wrong*, but because it *might* have accidentally introduced an imbalance, but only in certain circumstances.

If a migration entry has been mapped, but then changes, and `ptep_get_and_clear` runs on it - this creates the imbalance. The first code checks if it is huge, then clears all entries if it is. But if it isn't huge, it only clears the 1st entry!



252/2 2026/05/25 00:54 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/mm/hugetlbpage.c IncludeLines:true Name:huge_ptep_get_and_clear]

Results:
map[SourceCode:  78:	static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
  79:			unsigned long addr, pte_t *ptep, unsigned long sz)
  80:	{
  81:		return ptep_get_and_clear(mm, addr, ptep);
  82:	}
 SourceFile:include/asm-generic/hugetlb.h]

253/2 2026/05/25 00:54 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 115621
							output: 28
							thoughts: 34
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Debugging a Stubborn Hugetlb Allocation**

Damn, it's back to the default, generic page allocation again! I was hoping for something more specific. Okay, time to dive into the kernel source. I need to refresh my memory on the `hugetlbpage.c` code, specifically around how it handles allocation. Let me pull up the file, `arch/riscv/mm/hugetlbpage.c`, and check around line 305. I want to see exactly how it's deciding which allocation path to take – perhaps there's a missed check, an incorrect flag, or something subtly wrong with the page size configuration on this platform that’s triggering the fall-back. Gotta make sure the RISC-V specific code is behaving as expected, especially given the hardware differences.



254/2 2026/05/25 00:54 tool read-file
0m Args:
map[File:arch/riscv/mm/hugetlbpage.c]

Results:
map[Contents:// SPDX-License-Identifier: GPL-2.0
#include <linux/hugetlb.h>
#include <linux/err.h>

#ifdef CONFIG_RISCV_ISA_SVNAPOT
pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
{
	unsigned long pte_num;
	int i;
	pte_t orig_pte = ptep_get(ptep);

	if (!pte_present(orig_pte) || !pte_napot(orig_pte))
		return orig_pte;

	pte_num = napot_pte_num(napot_cont_order(orig_pte));

	for (i = 0; i < pte_num; i++, ptep++) {
		pte_t pte = ptep_get(ptep);

		if (pte_dirty(pte))
			orig_pte = pte_mkdirty(orig_pte);

		if (pte_young(pte))
			orig_pte = pte_mkyoung(orig_pte);
	}

	return orig_pte;
}

pte_t *huge_pte_alloc(struct mm_struct *mm,
		      struct vm_area_struct *vma,
		      unsigned long addr,
		      unsigned long sz)
{
	unsigned long order;
	pte_t *pte = NULL;
	pgd_t *pgd;
	p4d_t *p4d;
	pud_t *pud;
	pmd_t *pmd;

	pgd = pgd_offset(mm, addr);
	p4d = p4d_alloc(mm, pgd, addr);
	if (!p4d)
		return NULL;

	pud = pud_alloc(mm, p4d, addr);
	if (!pud)
		return NULL;

	if (sz == PUD_SIZE) {
		pte = (pte_t *)pud;
		goto out;
	}

	if (sz == PMD_SIZE) {
		if (want_pmd_share(vma, addr) && pud_none(pudp_get(pud)))
			pte = huge_pmd_share(mm, vma, addr, pud);
		else
			pte = (pte_t *)pmd_alloc(mm, pud, addr);
		goto out;
	}

	pmd = pmd_alloc(mm, pud, addr);
	if (!pmd)
		return NULL;

	for_each_napot_order(order) {
		if (napot_cont_size(order) == sz) {
			pte = pte_alloc_huge(mm, pmd, addr & napot_cont_mask(order));
			break;
		}
	}

out:
	if (pte) {
		pte_t pteval = ptep_get_lockless(pte);

		WARN_ON_ONCE(pte_present(pteval) && !pte_huge(pteval));
	}
	return pte;
}

pte_t *huge_pte_offset(struct mm_struct *mm,
		       unsigned long addr,
		       unsigned long sz)
{
	unsigned long order;
	pte_t *pte = NULL;
	pgd_t *pgd;
	p4d_t *p4d;
	pud_t *pud;
	pmd_t *pmd;

	pgd = pgd_offset(mm, addr);
	if (!pgd_present(pgdp_get(pgd)))
		return NULL;

	p4d = p4d_offset(pgd, addr);
	if (!p4d_present(p4dp_get(p4d)))
		return NULL;

	pud = pud_offset(p4d, addr);
	if (sz == PUD_SIZE)
		/* must be pud huge, non-present or none */
		return (pte_t *)pud;

	if (!pud_present(pudp_get(pud)))
		return NULL;

	pmd = pmd_offset(pud, addr);
	if (sz == PMD_SIZE)
		/* must be pmd huge, non-present or none */
		return (pte_t *)pmd;

	if (!pmd_present(pmdp_get(pmd)))
		return NULL;

	for_each_napot_order(order) {
		if (napot_cont_size(order) == sz) {
			pte = pte_offset_huge(pmd, addr & napot_cont_mask(order));
			break;
		}
	}
	return pte;
}

unsigned long hugetlb_mask_last_page(struct hstate *h)
{
	unsigned long hp_size = huge_page_size(h);

	switch (hp_size) {
#ifndef __PAGETABLE_PMD_FOLDED
	case PUD_SIZE:
		return P4D_SIZE - PUD_SIZE;
#endif
	case PMD_SIZE:
		return PUD_SIZE - PMD_SIZE;
	case napot_cont_size(NAPOT_CONT64KB_ORDER):
		return PMD_SIZE - napot_cont_size(NAPOT_CONT64KB_ORDER);
	default:
		break;
	}

	return 0UL;
}

static pte_t get_clear_contig(struct mm_struct *mm,
			      unsigned long addr,
			      pte_t *ptep,
			      unsigned long ncontig)
{
	pte_t pte, tmp_pte;
	bool present;

	pte = ptep_get_and_clear(mm, addr, ptep);
	present = pte_present(pte);
	while (--ncontig) {
		ptep++;
		addr += PAGE_SIZE;
		tmp_pte = ptep_get_and_clear(mm, addr, ptep);
		if (present) {
			if (pte_dirty(tmp_pte))
				pte = pte_mkdirty(pte);
			if (pte_young(tmp_pte))
				pte = pte_mkyoung(pte);
		}
	}
	return pte;
}

static pte_t get_clear_contig_flush(struct mm_struct *mm,
				    unsigned long addr,
				    pte_t *ptep,
				    unsigned long pte_num)
{
	pte_t orig_pte = get_clear_contig(mm, addr, ptep, pte_num);
	struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0);
	bool valid = !pte_none(orig_pte);

	if (valid)
		flush_tlb_range(&vma, addr, addr + (PAGE_SIZE * pte_num));

	return orig_pte;
}

pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
{
	unsigned long order;

	for_each_napot_order(order) {
		if (shift == napot_cont_shift(order)) {
			entry = pte_mknapot(entry, order);
			break;
		}
	}
	if (order == NAPOT_ORDER_MAX)
		entry = pte_mkhuge(entry);

	return entry;
}

static void clear_flush(struct mm_struct *mm,
			unsigned long addr,
			pte_t *ptep,
			unsigned long pgsize,
			unsigned long ncontig)
{
	struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0);
	unsigned long i, saddr = addr;

	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
		ptep_get_and_clear(mm, addr, ptep);

	flush_tlb_range(&vma, saddr, addr);
}

static int num_contig_ptes_from_size(unsigned long sz, size_t *pgsize)
{
	unsigned long hugepage_shift;

	if (sz >= PGDIR_SIZE)
		hugepage_shift = PGDIR_SHIFT;
	else if (sz >= P4D_SIZE)
		hugepage_shift = P4D_SHIFT;
	else if (sz >= PUD_SIZE)
		hugepage_shift = PUD_SHIFT;
	else if (sz >= PMD_SIZE)
		hugepage_shift = PMD_SHIFT;
	else
		hugepage_shift = PAGE_SHIFT;

	*pgsize = 1 << hugepage_shift;

	return sz >> hugepage_shift;
}

/*
 * When dealing with NAPOT mappings, the privileged specification indicates that
 * "if an update needs to be made, the OS generally should first mark all of the
 * PTEs invalid, then issue SFENCE.VMA instruction(s) covering all 4 KiB regions
 * within the range, [...] then update the PTE(s), as described in Section
 * 4.2.1.". That's the equivalent of the Break-Before-Make approach used by
 * arm64.
 */
void set_huge_pte_at(struct mm_struct *mm,
		     unsigned long addr,
		     pte_t *ptep,
		     pte_t pte,
		     unsigned long sz)
{
	size_t pgsize;
	int i, pte_num;

	pte_num = num_contig_ptes_from_size(sz, &pgsize);

	if (!pte_present(pte)) {
		for (i = 0; i < pte_num; i++, ptep++, addr += pgsize)
			set_ptes(mm, addr, ptep, pte, 1);
		return;
	}

	if (!pte_napot(pte)) {
		set_ptes(mm, addr, ptep, pte, 1);
		return;
	}

	clear_flush(mm, addr, ptep, pgsize, pte_num);

	for (i = 0; i < pte_num; i++, ptep++, addr += pgsize)
		set_pte_at(mm, addr, ptep, pte);
}

int huge_ptep_set_access_flags(struct vm_area_struct *vma,
			       unsigned long addr,
			       pte_t *ptep,
			       pte_t pte,
			       int dirty)
{
	struct mm_struct *mm = vma->vm_mm;
	unsigned long order;
	pte_t orig_pte;
	int i, pte_num;

	if (!pte_napot(pte))
		return ptep_set_access_flags(vma, addr, ptep, pte, dirty);

	order = napot_cont_order(pte);
	pte_num = napot_pte_num(order);
	ptep = huge_pte_offset(mm, addr, napot_cont_size(order));
	orig_pte = get_clear_contig_flush(mm, addr, ptep, pte_num);

	if (pte_dirty(orig_pte))
		pte = pte_mkdirty(pte);

	if (pte_young(orig_pte))
		pte = pte_mkyoung(pte);

	for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++)
		set_pte_at(mm, addr, ptep, pte);

	return true;
}

pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
			      unsigned long addr,
			      pte_t *ptep, unsigned long sz)
{
	size_t pgsize;
	pte_t orig_pte = ptep_get(ptep);
	int pte_num;

	if (!pte_napot(orig_pte))
		return ptep_get_and_clear(mm, addr, ptep);

	pte_num = num_contig_ptes_from_size(sz, &pgsize);

	return get_clear_contig(mm, addr, ptep, pte_num);
}

void huge_ptep_set_wrprotect(struct mm_struct *mm,
			     unsigned long addr,
			     pte_t *ptep)
{
	pte_t pte = ptep_get(ptep);
	unsigned long order;
	pte_t orig_pte;
	int i, pte_num;

	if (!pte_napot(pte)) {
		ptep_set_wrprotect(mm, addr, ptep);
		return;
	}

	order = napot_cont_order(pte);
	pte_num = napot_pte_num(order);
	ptep = huge_pte_offset(mm, addr, napot_cont_size(order));
	orig_pte = get_clear_contig_flush(mm, addr, ptep, pte_num);

	orig_pte = pte_wrprotect(orig_pte);

	for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++)
		set_pte_at(mm, addr, ptep, orig_pte);
}

pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
			    unsigned long addr,
			    pte_t *ptep)
{
	pte_t pte = ptep_get(ptep);
	int pte_num;

	if (!pte_napot(pte))
		return ptep_clear_flush(vma, addr, ptep);

	pte_num = napot_pte_num(napot_cont_order(pte));

	return get_clear_contig_flush(vma->vm_mm, addr, ptep, pte_num);
}

void huge_pte_clear(struct mm_struct *mm,
		    unsigned long addr,
		    pte_t *ptep,
		    unsigned long sz)
{
	size_t pgsize;
	pte_t pte = ptep_get(ptep);
	int i, pte_num;

	if (!pte_napot(pte)) {
		pte_clear(mm, addr, ptep);
		return;
	}

	pte_num = num_contig_ptes_from_size(sz, &pgsize);

	for (i = 0; i < pte_num; i++, addr += pgsize, ptep++)
		pte_clear(mm, addr, ptep);
}

static bool is_napot_size(unsigned long size)
{
	unsigned long order;

	if (!has_svnapot())
		return false;

	for_each_napot_order(order) {
		if (size == napot_cont_size(order))
			return true;
	}
	return false;
}

static __init int napot_hugetlbpages_init(void)
{
	if (has_svnapot()) {
		unsigned long order;

		for_each_napot_order(order)
			hugetlb_add_hstate(order);
	}
	return 0;
}
arch_initcall(napot_hugetlbpages_init);

#else

static bool is_napot_size(unsigned long size)
{
	return false;
}

#endif /*CONFIG_RISCV_ISA_SVNAPOT*/

static bool __hugetlb_valid_size(unsigned long size)
{
	if (size == HPAGE_SIZE)
		return true;
	else if (IS_ENABLED(CONFIG_64BIT) && size == PUD_SIZE)
		return true;
	else if (is_napot_size(size))
		return true;
	else
		return false;
}

bool __init arch_hugetlb_valid_size(unsigned long size)
{
	return __hugetlb_valid_size(size);
}

#ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION
bool arch_hugetlb_migration_supported(struct hstate *h)
{
	return __hugetlb_valid_size(huge_page_size(h));
}
#endif

#ifdef CONFIG_CONTIG_ALLOC
static __init int gigantic_pages_init(void)
{
	/* With CONTIG_ALLOC, we can allocate gigantic pages at runtime */
	if (IS_ENABLED(CONFIG_64BIT))
		hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
	return 0;
}
arch_initcall(gigantic_pages_init);
#endif

unsigned int __init arch_hugetlb_cma_order(void)
{
	if (IS_ENABLED(CONFIG_64BIT))
		return PUD_SHIFT - PAGE_SHIFT;

	return 0;
}
]

255/2 2026/05/25 00:54 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 120004
							output: 22
							thoughts: 368
						

Thoughts:
**Analyzing `huge_ptep_clear_flush` and its Implications**

Okay, hold on a second. Let's really look at `huge_ptep_clear_flush`! The code's right there. I see it, I see it… and *wait* a second! It's still using `napot_cont_order(pte)`! Not `sz`! Damn, it doesn't even *take* `sz` as an argument. That seems… potentially problematic.

Now, if `huge_ptep_clear_flush` is given a non-present PTE, `pte_napot(pte)` is going to be false, right? Therefore it will call `ptep_clear_flush(vma, addr, ptep)`. But that only clears *one* PTE! It's supposed to clear a huge page. That's inefficient at best, incorrect at worst.

When is `huge_ptep_clear_flush` even *called*? Let me think… It's not `hugetlb_change_protection`, that goes through `huge_ptep_modify_prot_start`. It's not `hugetlb_unshare_all_pmds` either. So I am going to search the codebase for it directly.



256/2 2026/05/25 00:54 tool grepper
0m Args:
map[Expression:huge_ptep_clear_flush]

Results:
map[Output:arch/arm64/include/asm/hugetlb.h=48=extern void huge_ptep_set_wrprotect(struct mm_struct *mm,
--
arch/arm64/include/asm/hugetlb.h-50-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
arch/arm64/include/asm/hugetlb.h:51:extern pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
arch/arm64/include/asm/hugetlb.h-52-				   unsigned long addr, pte_t *ptep);
--
arch/arm64/mm/hugetlbpage.c=453=void huge_ptep_set_wrprotect(struct mm_struct *mm,
--
arch/arm64/mm/hugetlbpage.c-475-
arch/arm64/mm/hugetlbpage.c:476:pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
arch/arm64/mm/hugetlbpage.c-477-			    unsigned long addr, pte_t *ptep)
--
arch/arm64/mm/hugetlbpage.c=517=pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep)
--
arch/arm64/mm/hugetlbpage.c-527-		if (pte_user_exec(__ptep_get(ptep)))
arch/arm64/mm/hugetlbpage.c:528:			return huge_ptep_clear_flush(vma, addr, ptep);
arch/arm64/mm/hugetlbpage.c-529-	}
--
arch/loongarch/include/asm/hugetlb.h=24=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
--
arch/loongarch/include/asm/hugetlb.h-36-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
arch/loongarch/include/asm/hugetlb.h:37:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
arch/loongarch/include/asm/hugetlb.h-38-					  unsigned long addr, pte_t *ptep)
--
arch/mips/include/asm/hugetlb.h=15=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
--
arch/mips/include/asm/hugetlb.h-27-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
arch/mips/include/asm/hugetlb.h:28:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
arch/mips/include/asm/hugetlb.h-29-					  unsigned long addr, pte_t *ptep)
--
arch/parisc/include/asm/hugetlb.h=12=pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
--
arch/parisc/include/asm/hugetlb.h-15-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
arch/parisc/include/asm/hugetlb.h:16:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
arch/parisc/include/asm/hugetlb.h-17-					  unsigned long addr, pte_t *ptep)
--
arch/powerpc/include/asm/hugetlb.h=47=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
--
arch/powerpc/include/asm/hugetlb.h-54-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
arch/powerpc/include/asm/hugetlb.h:55:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
arch/powerpc/include/asm/hugetlb.h-56-					  unsigned long addr, pte_t *ptep)
--
arch/riscv/include/asm/hugetlb.h=30=pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
--
arch/riscv/include/asm/hugetlb.h-34-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
arch/riscv/include/asm/hugetlb.h:35:pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
arch/riscv/include/asm/hugetlb.h-36-			    unsigned long addr, pte_t *ptep);
--
arch/riscv/mm/hugetlbpage.c=321=void huge_ptep_set_wrprotect(struct mm_struct *mm,
--
arch/riscv/mm/hugetlbpage.c-345-
arch/riscv/mm/hugetlbpage.c:346:pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
arch/riscv/mm/hugetlbpage.c-347-			    unsigned long addr,
--
arch/s390/include/asm/hugetlb.h=41=static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
--
arch/s390/include/asm/hugetlb.h-50-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
arch/s390/include/asm/hugetlb.h:51:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
arch/s390/include/asm/hugetlb.h-52-					  unsigned long address, pte_t *ptep)
--
arch/sh/include/asm/hugetlb.h-8-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
arch/sh/include/asm/hugetlb.h:9:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
arch/sh/include/asm/hugetlb.h-10-					  unsigned long addr, pte_t *ptep)
--
arch/sparc/include/asm/hugetlb.h=22=pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
--
arch/sparc/include/asm/hugetlb.h-25-#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
arch/sparc/include/asm/hugetlb.h:26:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
arch/sparc/include/asm/hugetlb.h-27-					  unsigned long addr, pte_t *ptep)
--
include/asm-generic/hugetlb.h=78=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
--
include/asm-generic/hugetlb.h-85-#ifndef __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
include/asm-generic/hugetlb.h:86:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
include/asm-generic/hugetlb.h-87-		unsigned long addr, pte_t *ptep)
--
include/linux/hugetlb.h=1274=static inline void hugetlb_count_sub(long l, struct mm_struct *mm)
--
include/linux/hugetlb.h-1277-
include/linux/hugetlb.h:1278:static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
include/linux/hugetlb.h-1279-					  unsigned long addr, pte_t *ptep)
--
mm/hugetlb.c=5434=static vm_fault_t hugetlb_wp(struct vm_fault *vmf)
--
mm/hugetlb.c-5595-		/* Break COW or unshare */
mm/hugetlb.c:5596:		huge_ptep_clear_flush(vma, vmf->address, vmf->pte);
mm/hugetlb.c-5597-		hugetlb_remove_rmap(old_folio);
--
mm/rmap.c=1984=static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
--
mm/rmap.c-2162-			}
mm/rmap.c:2163:			pteval = huge_ptep_clear_flush(vma, address, pvmw.pte);
mm/rmap.c-2164-			if (pte_dirty(pteval))
--
mm/rmap.c=2413=static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,
--
mm/rmap.c-2568-			/* Nuke the hugetlb page table entry */
mm/rmap.c:2569:			pteval = huge_ptep_clear_flush(vma, address, pvmw.pte);
mm/rmap.c-2570-			if (pte_dirty(pteval))
]

257/2 2026/05/25 00:54 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 123144
							output: 27
							thoughts: 5053
						

Thoughts:
**Analyzing a Suspected Huge Page Mapcount Issue**

Okay, so I'm diving into this bug report, starting with the code related to `huge_ptep_clear_flush`, because that's where the initial investigation pointed me. My first thought was to understand its role in `try_to_unmap_one` and `try_to_migrate_one`, and how it interacts with the huge page mapping process. I went through the code and noted the use of `napot_cont_order` and how it determines whether to clear one or multiple PTEs. I meticulously worked through the different scenarios: PRESENT and NON-PRESENT PTEs, as well as the cases where a PTE might be present but not a NAPOT entry. I confirmed, based on my understanding of how mapping works, that the logic was sound and that the correct number of entries would be cleared in each case, accounting for map counts.

Then I shifted my focus to `get_clear_contig_flush`, the function that actually handles clearing multiple PTEs when we are dealing with contiguous ranges. I confirmed it uses `ptep_get_and_clear` to clear the map counts for each entry within the range and also that it appropriately flushes the TLB.

My thoughts drifted to the potential impact of PMD-sized huge pages. I went through and traced the code for clearing and setting these large pages. I examined `ptep_clear_flush`, and `ptep_get_and_clear` and then considered that these functions are intended for PTEs, but with PMDs, we're casting `pmd_t *` to `pte_t *`. This seemed like a potential area of concern. I checked the implementation of `page_table_check_pte_clear` and noted it calls `page_table_check_clear` and that it uses `PAGE_SIZE >> PAGE_SHIFT`, and only the first 4K page would be cleared.

Then I considered the function `set_huge_pte_at` and how it works with map counts. I realized that for PMD sized huge pages, it sets the map count of only the first 4K page, using `page_table_check_set`. This left me wondering if there was a discrepancy.

I moved on to THP. THP uses the proper `set_pmd_at`, which *should* correctly handle the map counts.

But the original analysis suggests that there might be a bug related to huge pages. I reexamined the function `pmdp_huge_get_and_clear` which should decrement the map counts of the entire 512 page range. Then I went through the stack trace again. And then it hit me. `free_pages_and_swap_cache` in the stack trace tells me that we are dealing with a *regular* page, not a huge page! So I spent all this time for nothing! This means the problem has nothing to do with hugetlb! The bug report is misleading! Time to go back to square one!



258/2 2026/05/25 00:54 tool codesearch-find-references
0m Args:
map[Name:free_pages_and_swap_cache]

Results:
map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:__tlb_batch_free_encoded_pages SourceFile:mm/mmu_gather.c SourceLine:138]] TruncatedOutput:false]

259/2 2026/05/25 00:54 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 128945
							output: 45
							thoughts: 325
						

Thoughts:
**Deconstructing the Page Release Flow**

Okay, so I'm tracing the page release path, starting from `__tlb_batch_free_encoded_pages`. I know that calls `free_pages_and_swap_cache`, which handles freeing regular pages and THPs, that's straightforward. Hugetlb pages are typically freed through `hugetlb_free_folio` or something similar, which means `free_pages_and_swap_cache` likely doesn't *directly* handle them.

But wait a minute, I need to check. How are they removed from the TLB? Does `mmu_gather` have any special handling for Hugetlb pages? Aha! `tlb_remove_huge_tlb_entry` adds hugetlb pages to the `mmu_gather` structure.

Now, I'm thinking about how `tlb_remove_huge_tlb_entry` itself operates... it calls `__tlb_remove_folio_pages`. This seems important, so let's peek at the code...

Okay, I see that within `__tlb_remove_folio_pages`, `encoded` gets set to `encode_page(page, 0)`, which is likely an encoded page object and I see that there is a mutex used. The code appears to batch some operation on the pages, but it's not immediately clear if that means they are immediately freed or if they are just marked for freeing. But what's crucial is that it's *handling* them. Back to checking if `free_pages_and_swap_cache` *does* interact with hugetlb pages, or whether the pages are being dealt with elsewhere.



260/2 2026/05/25 00:55 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/swap_state.c IncludeLines:true Name:free_pages_and_swap_cache]

Results:
map[SourceCode: 381:	/*
 382:	 * Passed an array of pages, drop them all from swapcache and then release
 383:	 * them.  They are removed from the LRU and freed if this is their last use.
 384:	 */
 385:	void free_pages_and_swap_cache(struct encoded_page **pages, int nr)
 386:	{
 387:		struct folio_batch folios;
 388:		unsigned int refs[FOLIO_BATCH_SIZE];
 389:	
 390:		folio_batch_init(&folios);
 391:		for (int i = 0; i < nr; i++) {
 392:			struct folio *folio = page_folio(encoded_page_ptr(pages[i]));
 393:	
 394:			free_swap_cache(folio);
 395:			refs[folios.nr] = 1;
 396:			if (unlikely(encoded_page_flags(pages[i]) &
 397:				     ENCODED_PAGE_BIT_NR_PAGES_NEXT))
 398:				refs[folios.nr] = encoded_nr_pages(pages[++i]);
 399:	
 400:			if (folio_batch_add(&folios, folio) == 0)
 401:				folios_put_refs(&folios, refs);
 402:		}
 403:		if (folios.nr)
 404:			folios_put_refs(&folios, refs);
 405:	}
 SourceFile:mm/swap_state.c]

261/2 2026/05/25 00:55 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 130114
							output: 41
							thoughts: 141
						

Thoughts:
**My Line of Reasoning on HugeTLB Folio Release**

Okay, so I'm tracing the folio release process and it looks like `folios_put_refs` is the function that initiates the cleanup, specifically by decrementing the reference count. Now, if that refcount drops to zero, the folio is eligible for freeing – makes perfect sense. With huge pages, `folio_put` in turn calls `free_huge_folio`.

Here's where it gets interesting. `free_huge_folio` can take a couple of paths: either calling `__free_pages` directly if it's considered a surplus page, or returning it to the pool. Wait a minute... a red flag is going up. If it goes back into the pool, `__free_pages_prepare` *isn't* called? That function, as I recall, is critical for preparing the page for the buddy allocator. It appears that `__free_pages_prepare` is *only* called when a page is truly relinquished to the buddy system. This looks like a potential point of contention! I need to double-check this in `free_huge_folio`. I'm going to focus my analysis on `free_huge_folio` to confirm this suspicion.



262/2 2026/05/25 00:55 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/hugetlb.c IncludeLines:true Name:free_huge_folio]

Results:
map[SourceCode:1701:	void free_huge_folio(struct folio *folio)
1702:	{
1703:		/*
1704:		 * Can't pass hstate in here because it is called from the
1705:		 * generic mm code.
1706:		 */
1707:		struct hstate *h = folio_hstate(folio);
1708:		int nid = folio_nid(folio);
1709:		struct hugepage_subpool *spool = hugetlb_folio_subpool(folio);
1710:		bool restore_reserve;
1711:		unsigned long flags;
1712:	
1713:		VM_BUG_ON_FOLIO(folio_ref_count(folio), folio);
1714:		VM_BUG_ON_FOLIO(folio_mapcount(folio), folio);
1715:	
1716:		hugetlb_set_folio_subpool(folio, NULL);
1717:		if (folio_test_anon(folio))
1718:			__ClearPageAnonExclusive(&folio->page);
1719:		folio->mapping = NULL;
1720:		restore_reserve = folio_test_hugetlb_restore_reserve(folio);
1721:		folio_clear_hugetlb_restore_reserve(folio);
1722:	
1723:		/*
1724:		 * If HPageRestoreReserve was set on page, page allocation consumed a
1725:		 * reservation.  If the page was associated with a subpool, there
1726:		 * would have been a page reserved in the subpool before allocation
1727:		 * via hugepage_subpool_get_pages().  Since we are 'restoring' the
1728:		 * reservation, do not call hugepage_subpool_put_pages() as this will
1729:		 * remove the reserved page from the subpool.
1730:		 */
1731:		if (!restore_reserve) {
1732:			/*
1733:			 * A return code of zero implies that the subpool will be
1734:			 * under its minimum size if the reservation is not restored
1735:			 * after page is free.  Therefore, force restore_reserve
1736:			 * operation.
1737:			 */
1738:			if (hugepage_subpool_put_pages(spool, 1) == 0)
1739:				restore_reserve = true;
1740:		}
1741:	
1742:		spin_lock_irqsave(&hugetlb_lock, flags);
1743:		folio_clear_hugetlb_migratable(folio);
1744:		hugetlb_cgroup_uncharge_folio(hstate_index(h),
1745:					     pages_per_huge_page(h), folio);
1746:		hugetlb_cgroup_uncharge_folio_rsvd(hstate_index(h),
1747:						  pages_per_huge_page(h), folio);
1748:		lruvec_stat_mod_folio(folio, NR_HUGETLB, -pages_per_huge_page(h));
1749:		mem_cgroup_uncharge(folio);
1750:		if (restore_reserve)
1751:			h->resv_huge_pages++;
1752:	
1753:		if (folio_test_hugetlb_temporary(folio)) {
1754:			remove_hugetlb_folio(h, folio, false);
1755:			spin_unlock_irqrestore(&hugetlb_lock, flags);
1756:			update_and_free_hugetlb_folio(h, folio, true);
1757:		} else if (h->surplus_huge_pages_node[nid]) {
1758:			/* remove the page from active list */
1759:			remove_hugetlb_folio(h, folio, true);
1760:			spin_unlock_irqrestore(&hugetlb_lock, flags);
1761:			update_and_free_hugetlb_folio(h, folio, true);
1762:		} else {
1763:			arch_clear_hugetlb_flags(folio);
1764:			enqueue_hugetlb_folio(h, folio);
1765:			spin_unlock_irqrestore(&hugetlb_lock, flags);
1766:		}
1767:	}
 SourceFile:mm/hugetlb.c]

263/2 2026/05/25 00:55 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 131764
							output: 24
							thoughts: 1672
						

Thoughts:
**The Regular Page Mystery**

Okay, so I started looking at `update_and_free_hugetlb_folio` because that's what seemed relevant, but wait, it's not actually `free_pages_prepare` directly, it calls `__free_pages`. And then I saw `__free_pages_prepare` being called from `free_unref_folios`! But `free_unref_folios` is for *regular* pages, not hugetlb! The kernel has specific logic, like checking `folio_test_hugetlb(folio)` inside `folios_put_refs`, and if it is a hugetlb folio, it explicitly calls `free_huge_folio` and skips the `free_unref_folios` path. This means that my crash is not related to `hugetlb` at all! The stack trace proves it's a regular or THP page, and I wasted time focusing on `hugetlb` stuff because of the git log.

So, if it's a regular or THP page, where's the bug? The stack trace shows `exit_mmap` -> `tlb_finish_mmu` -> `tlb_flush_mmu` -> `tlb_flush_mmu_free` -> `tlb_batch_pages_flush` -> `__tlb_batch_free_encoded_pages` -> `free_pages_and_swap_cache` -> `folios_put_refs` -> `free_unref_folios`. This means we are unmapping the regular page during process exit. How could we have a map count leak on a regular page? It's likely a PTE is being cleared *without* calling `page_table_check_pte_clear` or some equivalent, right?

Where do we clear PTEs for regular pages? Let me think...Ah! It's likely in `zap_pte_range` and the call to `ptep_get_and_clear_full`, and that calls `ptep_get_and_clear` or `pte_clear_not_present_full`. But wait! I should check if some architectures define their own `ptep_get_and_clear_full`! Let's check RISC-V, for example.



264/2 2026/05/25 00:55 tool grepper
0m Args:
map[Expression:ptep_get_and_clear_full]

Results:
map[Output:Documentation/mm/arch_pgtable_helpers.rst=15=PTE Page Table Helpers
--
Documentation/mm/arch_pgtable_helpers.rst-68-+---------------------------+--------------------------------------------------+
Documentation/mm/arch_pgtable_helpers.rst:69:| ptep_get_and_clear_full   | Clears and returns PTE (batched PTE unmap)       |
Documentation/mm/arch_pgtable_helpers.rst-70-+---------------------------+--------------------------------------------------+
--
arch/powerpc/include/asm/book3s/64/pgtable.h=418=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
--
arch/powerpc/include/asm/book3s/64/pgtable.h-428-#define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
arch/powerpc/include/asm/book3s/64/pgtable.h:429:static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
arch/powerpc/include/asm/book3s/64/pgtable.h-430-					    unsigned long addr,
--
arch/powerpc/include/asm/book3s/64/pgtable.h-439-		 */
arch/powerpc/include/asm/book3s/64/pgtable.h:440:		old_pte = radix__ptep_get_and_clear_full(mm, addr, ptep, full);
arch/powerpc/include/asm/book3s/64/pgtable.h-441-		page_table_check_pte_clear(mm, addr, old_pte);
--
arch/powerpc/include/asm/book3s/64/radix.h=172=static inline unsigned long radix__pte_update(struct mm_struct *mm,
--
arch/powerpc/include/asm/book3s/64/radix.h-186-
arch/powerpc/include/asm/book3s/64/radix.h:187:static inline pte_t radix__ptep_get_and_clear_full(struct mm_struct *mm,
arch/powerpc/include/asm/book3s/64/radix.h-188-						   unsigned long addr,
--
arch/s390/include/asm/pgtable.h=1205=static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
--
arch/s390/include/asm/pgtable.h-1218-/*
arch/s390/include/asm/pgtable.h:1219: * The batched pte unmap code uses ptep_get_and_clear_full to clear the
arch/s390/include/asm/pgtable.h-1220- * ptes. Here an optimization is possible. tlb_gather_mmu flushes all
--
arch/s390/include/asm/pgtable.h-1225-#define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
arch/s390/include/asm/pgtable.h:1226:static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
arch/s390/include/asm/pgtable.h-1227-					    unsigned long addr,
--
arch/x86/include/asm/pgtable.h=1243=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
--
arch/x86/include/asm/pgtable.h-1251-#define __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
arch/x86/include/asm/pgtable.h:1252:static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
arch/x86/include/asm/pgtable.h-1253-					    unsigned long addr, pte_t *ptep,
--
include/linux/pgtable.h=802=static inline pud_t pudp_huge_get_and_clear_full(struct vm_area_struct *vma,
--
include/linux/pgtable.h-811-#ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR_FULL
include/linux/pgtable.h:812:static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
include/linux/pgtable.h-813-					    unsigned long address, pte_t *ptep,
--
include/linux/pgtable.h-830- * May be overridden by the architecture; otherwise, implemented as a simple
include/linux/pgtable.h:831: * loop over ptep_get_and_clear_full(), merging dirty/accessed bits into the
include/linux/pgtable.h-832- * returned PTE.
--
include/linux/pgtable.h=840=static inline pte_t get_and_clear_full_ptes(struct mm_struct *mm,
--
include/linux/pgtable.h-844-
include/linux/pgtable.h:845:	pte = ptep_get_and_clear_full(mm, addr, ptep, full);
include/linux/pgtable.h-846-	while (--nr) {
--
include/linux/pgtable.h-848-		addr += PAGE_SIZE;
include/linux/pgtable.h:849:		tmp_pte = ptep_get_and_clear_full(mm, addr, ptep, full);
include/linux/pgtable.h-850-		if (pte_dirty(tmp_pte))
--
include/linux/pgtable.h=876=static inline pte_t get_and_clear_ptes(struct mm_struct *mm, unsigned long addr,
--
include/linux/pgtable.h-892- * May be overridden by the architecture; otherwise, implemented as a simple
include/linux/pgtable.h:893: * loop over ptep_get_and_clear_full().
include/linux/pgtable.h-894- *
--
include/linux/pgtable.h=901=static inline void clear_full_ptes(struct mm_struct *mm, unsigned long addr,
--
include/linux/pgtable.h-904-	for (;;) {
include/linux/pgtable.h:905:		ptep_get_and_clear_full(mm, addr, ptep, full);
include/linux/pgtable.h-906-		if (--nr == 0)
--
mm/debug_vm_pgtable.c=114=static void __init pte_advanced_tests(struct pgtable_debug_args *args)
--
mm/debug_vm_pgtable.c-157-	WARN_ON(!(pte_write(pte) && pte_dirty(pte)));
mm/debug_vm_pgtable.c:158:	ptep_get_and_clear_full(args->mm, args->vaddr, args->ptep, 1);
mm/debug_vm_pgtable.c-159-	pte = ptep_get(args->ptep);
--
mm/debug_vm_pgtable.c-169-
mm/debug_vm_pgtable.c:170:	ptep_get_and_clear_full(args->mm, args->vaddr, args->ptep, 1);
mm/debug_vm_pgtable.c-171-}
--
mm/memory.c=1673=static inline int zap_present_ptes(struct mmu_gather *tlb,
--
mm/memory.c-1686-		/* We don't need up-to-date accessed/dirty bits. */
mm/memory.c:1687:		ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm);
mm/memory.c-1688-		arch_check_zapped_pte(vma, ptent);
--
mm/rmap.c=1984=static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
--
mm/rmap.c-2000-	 * When racing against e.g. zap_pte_range() on another cpu,
mm/rmap.c:2001:	 * in between its ptep_get_and_clear_full() and folio_remove_rmap_*(),
mm/rmap.c-2002-	 * try_to_unmap() may return before page_mapped() has become false,
--
mm/rmap.c=2413=static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,
--
mm/rmap.c-2427-	 * When racing against e.g. zap_pte_range() on another cpu,
mm/rmap.c:2428:	 * in between its ptep_get_and_clear_full() and folio_remove_rmap_*(),
mm/rmap.c-2429-	 * try_to_migrate() may return before page_mapped() has become false,
]

265/2 2026/05/25 00:55 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 136307
							output: 40
							thoughts: 1047
						

Thoughts:
**Analyzing RISC-V PTE Clearing Mechanisms**

Okay, so I'm diving into how PTEs are handled on RISC-V, specifically focusing on the clearing process. My initial thought was that since RISC-V doesn't define `ptep_get_and_clear_full`, it defaults to the generic implementation, which is good. That implementation calls `ptep_get_and_clear`, which, in turn, calls `page_table_check_pte_clear`. This setup looks sound, ensuring the map count gets decremented correctly by `zap_pte_range`.

But then, a thought pops up: What about `clear_full_ptes`? I need to make sure this also works as expected. I check the code, and it seems fine, iterating and calling `ptep_get_and_clear_full` for each PTE in the range.

Hold on, there's another piece to the puzzle – `zap_present_ptes`. Initially, I was only seeing a call to `ptep_get_and_clear_full` which looked like it was only clearing a single PTE. But what if `nr > 1`? And yes, I was correct, it will clear only one PTE if that is the call.

However, after looking deeper, I see it calls `get_and_clear_full_ptes` when it is not an anon folio, and calls `clear_full_ptes` when it is an anon folio.

My grep output showed something else; I'm seeing a line that claims it calls `ptep_get_and_clear_full` instead of `clear_full_ptes` in the anon case. I need to investigate this further and confirm what's actually happening around line 1687 in `mm/memory.c`. I have a hunch that something is off here. Gotta dig into the details to be sure.



266/2 2026/05/25 00:55 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/memory.c IncludeLines:true Name:zap_present_ptes]

Results:
map[SourceCode:1667:	/*
1668:	 * Zap or skip at least one present PTE, trying to batch-process subsequent
1669:	 * PTEs that map consecutive pages of the same folio.
1670:	 *
1671:	 * Returns the number of processed (skipped or zapped) PTEs (at least 1).
1672:	 */
1673:	static inline int zap_present_ptes(struct mmu_gather *tlb,
1674:			struct vm_area_struct *vma, pte_t *pte, pte_t ptent,
1675:			unsigned int max_nr, unsigned long addr,
1676:			struct zap_details *details, int *rss, bool *force_flush,
1677:			bool *force_break, bool *any_skipped)
1678:	{
1679:		struct mm_struct *mm = tlb->mm;
1680:		struct folio *folio;
1681:		struct page *page;
1682:		int nr;
1683:	
1684:		page = vm_normal_page(vma, addr, ptent);
1685:		if (!page) {
1686:			/* We don't need up-to-date accessed/dirty bits. */
1687:			ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm);
1688:			arch_check_zapped_pte(vma, ptent);
1689:			tlb_remove_tlb_entry(tlb, pte, addr);
1690:			if (userfaultfd_pte_wp(vma, ptent))
1691:				*any_skipped = zap_install_uffd_wp_if_needed(vma, addr,
1692:							pte, 1, details, ptent);
1693:			ksm_might_unmap_zero_page(mm, ptent);
1694:			return 1;
1695:		}
1696:	
1697:		folio = page_folio(page);
1698:		if (unlikely(!should_zap_folio(details, folio))) {
1699:			*any_skipped = true;
1700:			return 1;
1701:		}
1702:	
1703:		/*
1704:		 * Make sure that the common "small folio" case is as fast as possible
1705:		 * by keeping the batching logic separate.
1706:		 */
1707:		if (unlikely(folio_test_large(folio) && max_nr != 1)) {
1708:			nr = folio_pte_batch(folio, pte, ptent, max_nr);
1709:			zap_present_folio_ptes(tlb, vma, folio, page, pte, ptent, nr,
1710:					       addr, details, rss, force_flush,
1711:					       force_break, any_skipped);
1712:			return nr;
1713:		}
1714:		zap_present_folio_ptes(tlb, vma, folio, page, pte, ptent, 1, addr,
1715:				       details, rss, force_flush, force_break, any_skipped);
1716:		return 1;
1717:	}
 SourceFile:mm/memory.c]

267/2 2026/05/25 00:55 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 138723
							output: 42
							thoughts: 32
						

Thoughts:
Okay, here's my take on those thoughts, framed from a first-person perspective as a field expert:

**Understanding the Batching Mechanism**

Right, so it looks like `zap_present_folio_ptes` is the function that's actually managing the batching process. Excellent! That's precisely what I suspected based on the overall architecture. Now, I need to dive into `zap_present_folio_ptes` itself to understand the specifics of how it's implemented. I want to see the batching logic directly, the criteria it uses for grouping, how it handles potential errors within a batch, and the parameters that control its behavior. Specifically, I'm interested in the underlying assumptions regarding data volume, transaction limits, and potential bottlenecks. Time to get into the details of the code and see exactly what's happening.



268/2 2026/05/25 00:55 tool codesearch-definition-source
0m Args:
map[ContextFile:mm/memory.c IncludeLines:true Name:zap_present_folio_ptes]

Results:
map[SourceCode:1622:	static __always_inline void zap_present_folio_ptes(struct mmu_gather *tlb,
1623:			struct vm_area_struct *vma, struct folio *folio,
1624:			struct page *page, pte_t *pte, pte_t ptent, unsigned int nr,
1625:			unsigned long addr, struct zap_details *details, int *rss,
1626:			bool *force_flush, bool *force_break, bool *any_skipped)
1627:	{
1628:		struct mm_struct *mm = tlb->mm;
1629:		bool delay_rmap = false;
1630:	
1631:		if (!folio_test_anon(folio)) {
1632:			ptent = get_and_clear_full_ptes(mm, addr, pte, nr, tlb->fullmm);
1633:			if (pte_dirty(ptent)) {
1634:				folio_mark_dirty(folio);
1635:				if (tlb_delay_rmap(tlb)) {
1636:					delay_rmap = true;
1637:					*force_flush = true;
1638:				}
1639:			}
1640:			if (pte_young(ptent) && likely(vma_has_recency(vma)))
1641:				folio_mark_accessed(folio);
1642:			rss[mm_counter(folio)] -= nr;
1643:		} else {
1644:			/* We don't need up-to-date accessed/dirty bits. */
1645:			clear_full_ptes(mm, addr, pte, nr, tlb->fullmm);
1646:			rss[MM_ANONPAGES] -= nr;
1647:		}
1648:		/* Checking a single PTE in a batch is sufficient. */
1649:		arch_check_zapped_pte(vma, ptent);
1650:		tlb_remove_tlb_entries(tlb, pte, nr, addr);
1651:		if (unlikely(userfaultfd_pte_wp(vma, ptent)))
1652:			*any_skipped = zap_install_uffd_wp_if_needed(vma, addr, pte,
1653:								     nr, details, ptent);
1654:	
1655:		if (!delay_rmap) {
1656:			folio_remove_rmap_ptes(folio, page, nr, vma);
1657:	
1658:			if (unlikely(folio_mapcount(folio) < 0))
1659:				print_bad_pte(vma, addr, ptent, page);
1660:		}
1661:		if (unlikely(__tlb_remove_folio_pages(tlb, page, nr, delay_rmap))) {
1662:			*force_flush = true;
1663:			*force_break = true;
1664:		}
1665:	}
 SourceFile:mm/memory.c]

269/2 2026/05/25 00:55 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 139809
							output: 18
							thoughts: 1004
						

Thoughts:
**Analyzing PTE Map Count Management**

Okay, let's break this down. My initial observation is that `clear_full_ptes` is invoked for anonymous folios. Within this function, the core operation involves a loop that iterates `nr` times, calling `ptep_get_and_clear_full`. This function is key. It ultimately leads to `page_table_check_pte_clear`, meaning the map count *should* be decremented correctly for each PTE.

My immediate thought is about the value of `nr`. If it's calculated incorrectly, everything downstream is broken. However, the code addresses this concern: `folio_pte_batch` is used to determine the correct number of PTEs belonging to the same folio, and crucially, it validates this based on the PFN. So far, so good. The PFN check within `folio_pte_batch` is a solid safeguard.

Now, I'm thinking about the counterpart, the setting of the PTEs. The `set_ptes` function, and specifically its call to `page_table_check_ptes_set`, needs scrutiny. Within `page_table_check_ptes_set`, we have a loop and the invocation of `page_table_check_set`. This function takes `pte_pfn(pte)` and `nr` as inputs. Importantly, the loop in `set_ptes` correctly increments the PFN value for the PTEs it sets, which is reflected in `page_table_check_set`. This ensures that for a THP, the map count is updated correctly for each 4K page. `clear_full_ptes` also correctly decrements the map count.

Therefore, the map count tracking looks sound in the THP context, at least based on this code.

The question then is where is the leak. It is likely that the leak is where pte_clear is called directly on a regular page, and the map count is not decremented.

Let's look at the callers of `pte_clear` in `mm/`. That's where the problem is probably occurring.



270/2 2026/05/25 00:56 tool grepper
0m Args:
map[Expression:pte_clear\(]

Results:
map[Output:
Full output is too long, showing 500 out of 731 lines.
Use more precise expression if possible.

[arch/alpha/include/asm/pgtable.h=211=extern inline int pte_present(pte_t pte)	{ return pte_val(pte) & _PAGE_VALID; }
 arch/alpha/include/asm/pgtable.h:212:extern inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/alpha/include/asm/pgtable.h-213-{
 --
 arch/alpha/include/asm/pgtable.h=279=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/alpha/include/asm/pgtable.h-284-
 arch/alpha/include/asm/pgtable.h:285:	pte_clear(mm, address, ptep);
 arch/alpha/include/asm/pgtable.h-286-	return pte;
 --
 arch/alpha/include/asm/pgtable.h=291=static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/alpha/include/asm/pgtable.h-296-
 arch/alpha/include/asm/pgtable.h:297:	page_table_check_pte_clear(mm, addr, pte);
 arch/alpha/include/asm/pgtable.h-298-	migrate_flush_tlb_page(vma, addr);
 --
 arch/arc/include/asm/pgtable-levels.h-173-#define pte_present(x)		(pte_val(x) & _PAGE_PRESENT)
 arch/arc/include/asm/pgtable-levels.h:174:#define pte_clear(mm,addr,ptep)	set_pte_at(mm, addr, ptep, __pte(0))
 arch/arc/include/asm/pgtable-levels.h-175-#define pte_page(pte)		pfn_to_page(pte_pfn(pte))
 --
 arch/arm/include/asm/pgtable.h=151=static inline pte_t *pmd_page_vaddr(pmd_t pmd)
 --
 arch/arm/include/asm/pgtable.h-162-
 arch/arm/include/asm/pgtable.h:163:#define pte_clear(mm,addr,ptep)	set_pte_ext(ptep, __pte(0), 0)
 arch/arm/include/asm/pgtable.h-164-
 --
 arch/arm/mm/mmu.c=390=void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
 --
 arch/arm/mm/mmu.c-407-	else
 arch/arm/mm/mmu.c:408:		pte_clear(NULL, vaddr, pte);
 arch/arm/mm/mmu.c-409-	local_flush_tlb_kernel_range(vaddr, vaddr + PAGE_SIZE);
 --
 arch/arm64/include/asm/hugetlb.h=51=extern pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/arm64/include/asm/hugetlb.h-53-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/arm64/include/asm/hugetlb.h:54:extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/arm64/include/asm/hugetlb.h-55-			   pte_t *ptep, unsigned long sz);
 --
 arch/arm64/include/asm/pgtable.h=1289=static inline bool pud_user_accessible_page(struct mm_struct *mm, unsigned long addr, pud_t pud)
 --
 arch/arm64/include/asm/pgtable.h-1298-
 arch/arm64/include/asm/pgtable.h:1299:static inline void __pte_clear(struct mm_struct *mm,
 arch/arm64/include/asm/pgtable.h-1300-			       unsigned long addr, pte_t *ptep)
 --
 arch/arm64/include/asm/pgtable.h=1352=static inline pte_t __ptep_get_and_clear_anysz(struct mm_struct *mm,
 --
 arch/arm64/include/asm/pgtable.h-1360-	case PAGE_SIZE:
 arch/arm64/include/asm/pgtable.h:1361:		page_table_check_pte_clear(mm, address, pte);
 arch/arm64/include/asm/pgtable.h-1362-		break;
 --
 arch/arm64/include/asm/pgtable.h=1775=static __always_inline void set_ptes(struct mm_struct *mm, unsigned long addr,
 --
 arch/arm64/include/asm/pgtable.h-1788-
 arch/arm64/include/asm/pgtable.h:1789:static inline void pte_clear(struct mm_struct *mm,
 arch/arm64/include/asm/pgtable.h-1790-				unsigned long addr, pte_t *ptep)
 --
 arch/arm64/include/asm/pgtable.h-1792-	contpte_try_unfold(mm, addr, ptep, __ptep_get(ptep));
 arch/arm64/include/asm/pgtable.h:1793:	__pte_clear(mm, addr, ptep);
 arch/arm64/include/asm/pgtable.h-1794-}
 --
 arch/arm64/mm/fixmap.c=119=void __set_fixmap(enum fixed_addresses idx,
 --
 arch/arm64/mm/fixmap.c-131-	} else {
 arch/arm64/mm/fixmap.c:132:		__pte_clear(&init_mm, addr, ptep);
 arch/arm64/mm/fixmap.c-133-		flush_tlb_kernel_range(addr, addr+PAGE_SIZE);
 --
 arch/arm64/mm/hugetlbpage.c=344=pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
 --
 arch/arm64/mm/hugetlbpage.c-368-
 arch/arm64/mm/hugetlbpage.c:369:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/arm64/mm/hugetlbpage.c-370-		    pte_t *ptep, unsigned long sz)
 --
 arch/arm64/mm/hugetlbpage.c-377-	for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
 arch/arm64/mm/hugetlbpage.c:378:		__pte_clear(mm, addr, ptep);
 arch/arm64/mm/hugetlbpage.c-379-}
 --
 arch/arm64/mm/mmu.c=1466=static void unmap_hotplug_pte_range(pmd_t *pmdp, unsigned long addr,
 --
 arch/arm64/mm/mmu.c-1478-		WARN_ON(!pte_present(pte));
 arch/arm64/mm/mmu.c:1479:		__pte_clear(&init_mm, addr, ptep);
 arch/arm64/mm/mmu.c-1480-		if (free_mapped) {
 --
 arch/csky/include/asm/pgtable.h-33-#define pmd_page(pmd)	(pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
 arch/csky/include/asm/pgtable.h:34:#define pte_clear(mm, addr, ptep)	set_pte((ptep), \
 arch/csky/include/asm/pgtable.h-35-	(((unsigned int) addr >= PAGE_OFFSET) ? __pte(_PAGE_GLOBAL) : __pte(0)))
 --
 arch/hexagon/include/asm/pgtable.h=165=static inline void pmd_clear(pmd_t *pmd_entry_ptr)
 --
 arch/hexagon/include/asm/pgtable.h-172- */
 arch/hexagon/include/asm/pgtable.h:173:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/hexagon/include/asm/pgtable.h-174-				pte_t *ptep)
 --
 arch/loongarch/include/asm/hugetlb.h=11=uint64_t pmd_to_entrylo(unsigned long pmd_val);
 --
 arch/loongarch/include/asm/hugetlb.h-13-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/loongarch/include/asm/hugetlb.h:14:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/loongarch/include/asm/hugetlb.h-15-				  pte_t *ptep, unsigned long sz)
 --
 arch/loongarch/include/asm/pgtable.h=364=static inline void set_pte(pte_t *ptep, pte_t pteval)
 --
 arch/loongarch/include/asm/pgtable.h-373-
 arch/loongarch/include/asm/pgtable.h:374:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/loongarch/include/asm/pgtable.h-375-{
 --
 arch/loongarch/mm/init.c=210=void __init __set_fixmap(enum fixed_addresses idx,
 --
 arch/loongarch/mm/init.c-226-	else {
 arch/loongarch/mm/init.c:227:		pte_clear(&init_mm, addr, ptep);
 arch/loongarch/mm/init.c-228-		flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
 --
 arch/m68k/include/asm/mcf_pgtable.h=120=static inline int pte_present(pte_t pte)
 --
 arch/m68k/include/asm/mcf_pgtable.h-124-
 arch/m68k/include/asm/mcf_pgtable.h:125:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/m68k/include/asm/mcf_pgtable.h-126-	pte_t *ptep)
 --
 arch/m68k/include/asm/motorola_pgtable.h=95=static inline void pud_set(pud_t *pudp, pmd_t *pmdp)
 --
 arch/m68k/include/asm/motorola_pgtable.h-106-#define pte_present(pte)	(pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROTNONE))
 arch/m68k/include/asm/motorola_pgtable.h:107:#define pte_clear(mm,addr,ptep)		({ pte_val(*(ptep)) = 0; })
 arch/m68k/include/asm/motorola_pgtable.h-108-
 --
 arch/microblaze/include/asm/pgtable.h=29=extern pte_t *va_to_pte(unsigned long address);
 --
 arch/microblaze/include/asm/pgtable.h-211-#define pte_present(pte)	(pte_val(pte) & _PAGE_PRESENT)
 arch/microblaze/include/asm/pgtable.h:212:#define pte_clear(mm, addr, ptep) \
 arch/microblaze/include/asm/pgtable.h-213-	do { set_pte_at((mm), (addr), (ptep), __pte(0)); } while (0)
 --
 arch/mips/include/asm/pgtable.h=119=static inline void set_pte(pte_t *ptep, pte_t pte)
 --
 arch/mips/include/asm/pgtable.h-142-
 arch/mips/include/asm/pgtable.h:143:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/mips/include/asm/pgtable.h-144-{
 --
 arch/mips/include/asm/pgtable.h=171=static inline void set_pte(pte_t *ptep, pte_t pteval)
 --
 arch/mips/include/asm/pgtable.h-189-
 arch/mips/include/asm/pgtable.h:190:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/mips/include/asm/pgtable.h-191-{
 --
 arch/nios2/include/asm/pgtable.h=195=static inline int pmd_none(pmd_t pmd)
 --
 arch/nios2/include/asm/pgtable.h-202-
 arch/nios2/include/asm/pgtable.h:203:static inline void pte_clear(struct mm_struct *mm,
 arch/nios2/include/asm/pgtable.h-204-				unsigned long addr, pte_t *ptep)
 --
 arch/openrisc/include/asm/pgtable.h=42=extern void paging_init(void);
 --
 arch/openrisc/include/asm/pgtable.h-183-#define pte_present(x)	(pte_val(x) & _PAGE_PRESENT)
 arch/openrisc/include/asm/pgtable.h:184:#define pte_clear(mm, addr, xp)	do { pte_val(*(xp)) = 0; } while (0)
 arch/openrisc/include/asm/pgtable.h-185-
 --
 arch/openrisc/mm/init.c=196=static int __init map_page(unsigned long va, phys_addr_t pa, pgprot_t prot)
 --
 arch/openrisc/mm/init.c-213-	else
 arch/openrisc/mm/init.c:214:		pte_clear(&init_mm, va, pte);
 arch/openrisc/mm/init.c-215-
 --
 arch/parisc/include/asm/pgtable.h=263=extern pte_t pg0[];
 --
 arch/parisc/include/asm/pgtable.h-267-#define pte_user(x)	(pte_val(x) & _PAGE_USER)
 arch/parisc/include/asm/pgtable.h:268:#define pte_clear(mm, addr, xp) set_pte_at((mm), (addr), (xp), __pte(0))
 arch/parisc/include/asm/pgtable.h-269-
 --
 arch/parisc/kernel/pci-dma.c=153=static inline void unmap_uncached_pte(pmd_t * pmd, unsigned long vaddr,
 --
 arch/parisc/kernel/pci-dma.c-175-
 arch/parisc/kernel/pci-dma.c:176:		pte_clear(&init_mm, vaddr, pte);
 arch/parisc/kernel/pci-dma.c-177-		purge_tlb_start(flags);
 --
 arch/parisc/mm/fixmap.c=27=void notrace clear_fixmap(enum fixed_addresses idx)
 --
 arch/parisc/mm/fixmap.c-34-
 arch/parisc/mm/fixmap.c:35:	pte_clear(&init_mm, vaddr, pte);
 arch/parisc/mm/fixmap.c-36-
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h=138=void unmap_kernel_page(unsigned long va);
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h-212-
 arch/powerpc/include/asm/book3s/32/pgtable.h:213:#define pte_clear(mm, addr, ptep) \
 arch/powerpc/include/asm/book3s/32/pgtable.h-214-	do { pte_update(mm, addr, ptep, ~_PAGE_HASHPTE, 0, 0); } while (0)
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h=312=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/powerpc/include/asm/book3s/32/pgtable.h-316-
 arch/powerpc/include/asm/book3s/32/pgtable.h:317:	page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/book3s/32/pgtable.h-318-
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h=418=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-422-
 arch/powerpc/include/asm/book3s/64/pgtable.h:423:	page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/book3s/64/pgtable.h-424-
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h=429=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-440-		old_pte = radix__ptep_get_and_clear_full(mm, addr, ptep, full);
 arch/powerpc/include/asm/book3s/64/pgtable.h:441:		page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/book3s/64/pgtable.h-442-
 --
 arch/powerpc/include/asm/book3s/64/pgtable.h-448-
 arch/powerpc/include/asm/book3s/64/pgtable.h:449:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/powerpc/include/asm/book3s/64/pgtable.h-450-			     pte_t * ptep)
 --
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h=23=static inline pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 --
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-30-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h:31:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h-32-				  pte_t *ptep, unsigned long sz)
 --
 arch/powerpc/include/asm/nohash/pgtable.h=124=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/powerpc/include/asm/nohash/pgtable.h-128-
 arch/powerpc/include/asm/nohash/pgtable.h:129:	page_table_check_pte_clear(mm, addr, old_pte);
 arch/powerpc/include/asm/nohash/pgtable.h-130-
 --
 arch/powerpc/include/asm/nohash/pgtable.h-134-
 arch/powerpc/include/asm/nohash/pgtable.h:135:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/powerpc/include/asm/nohash/pgtable.h-136-{
 --
 arch/powerpc/lib/code-patching.c=246=static void unmap_patch_area(unsigned long addr)
 --
 arch/powerpc/lib/code-patching.c-276-	 */
 arch/powerpc/lib/code-patching.c:277:	pte_clear(&init_mm, addr, ptep);
 arch/powerpc/lib/code-patching.c-278-	flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
 --
 arch/powerpc/lib/code-patching.c=281=static int __do_patch_mem_mm(void *addr, unsigned long val, bool is_dword)
 --
 arch/powerpc/lib/code-patching.c-314-
 arch/powerpc/lib/code-patching.c:315:	pte_clear(patching_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-316-	/*
 --
 arch/powerpc/lib/code-patching.c=327=static int __do_patch_mem(void *addr, unsigned long val, bool is_dword)
 --
 arch/powerpc/lib/code-patching.c-345-
 arch/powerpc/lib/code-patching.c:346:	pte_clear(&init_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-347-	flush_tlb_kernel_range(text_poke_addr, text_poke_addr + PAGE_SIZE);
 --
 arch/powerpc/lib/code-patching.c=468=static int __do_patch_instructions_mm(u32 *addr, u32 *code, size_t len, bool repeat_instr)
 --
 arch/powerpc/lib/code-patching.c-502-
 arch/powerpc/lib/code-patching.c:503:	pte_clear(patching_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-504-	/*
 --
 arch/powerpc/lib/code-patching.c=519=static int __do_patch_instructions(u32 *addr, u32 *code, size_t len, bool repeat_instr)
 --
 arch/powerpc/lib/code-patching.c-537-
 arch/powerpc/lib/code-patching.c:538:	pte_clear(&init_mm, text_poke_addr, pte);
 arch/powerpc/lib/code-patching.c-539-	flush_tlb_kernel_range(text_poke_addr, text_poke_addr + PAGE_SIZE);
 --
 arch/powerpc/mm/book3s64/hash_native.c=660=static void hpte_decode(struct hash_pte *hpte, unsigned long slot,
 --
 arch/powerpc/mm/book3s64/hash_native.c-735- */
 arch/powerpc/mm/book3s64/hash_native.c:736:static notrace void native_hpte_clear(void)
 arch/powerpc/mm/book3s64/hash_native.c-737-{
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=787=static void __meminit remove_pte_table(pte_t *pte_start, unsigned long addr,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-805-				free_vmemmap_pages(pte_page(*pte), altmap, 0);
 arch/powerpc/mm/book3s64/radix_pgtable.c:806:			pte_clear(&init_mm, addr, pte);
 arch/powerpc/mm/book3s64/radix_pgtable.c-807-			pages++;
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-811-			free_vmemmap_pages(pte_page(*pte), altmap, 0);
 arch/powerpc/mm/book3s64/radix_pgtable.c:812:			pte_clear(&init_mm, addr, pte);
 arch/powerpc/mm/book3s64/radix_pgtable.c-813-		}
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=820=static void __meminit remove_pmd_table(pmd_t *pmd_start, unsigned long addr,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-839-					free_vmemmap_pages(pmd_page(*pmd), altmap, get_order(PMD_SIZE));
 arch/powerpc/mm/book3s64/radix_pgtable.c:840:				pte_clear(&init_mm, addr, (pte_t *)pmd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-841-				pages++;
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-845-				free_vmemmap_pages(pmd_page(*pmd), altmap, get_order(PMD_SIZE));
 arch/powerpc/mm/book3s64/radix_pgtable.c:846:				pte_clear(&init_mm, addr, (pte_t *)pmd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-847-			}
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=860=static void __meminit remove_pud_table(pud_t *pud_start, unsigned long addr,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-880-			}
 arch/powerpc/mm/book3s64/radix_pgtable.c:881:			pte_clear(&init_mm, addr, (pte_t *)pud);
 arch/powerpc/mm/book3s64/radix_pgtable.c-882-			pages++;
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c=895=remove_pagetable(unsigned long start, unsigned long end, bool direct,
 --
 arch/powerpc/mm/book3s64/radix_pgtable.c-919-
 arch/powerpc/mm/book3s64/radix_pgtable.c:920:			pte_clear(&init_mm, addr, (pte_t *)pgd);
 arch/powerpc/mm/book3s64/radix_pgtable.c-921-			continue;
 --
 arch/powerpc/mm/pgtable.c=239=void unmap_kernel_page(unsigned long va)
 --
 arch/powerpc/mm/pgtable.c-243-
 arch/powerpc/mm/pgtable.c:244:	pte_clear(&init_mm, va, ptep);
 arch/powerpc/mm/pgtable.c-245-	flush_tlb_kernel_range(va, va + PAGE_SIZE);
 --
 arch/powerpc/platforms/ps3/htab.c=152=static void ps3_hpte_invalidate(unsigned long slot, unsigned long vpn,
 --
 arch/powerpc/platforms/ps3/htab.c-171-/* Called during kexec sequence with MMU off */
 arch/powerpc/platforms/ps3/htab.c:172:static notrace void ps3_hpte_clear(void)
 arch/powerpc/platforms/ps3/htab.c-173-{
 --
 arch/riscv/include/asm/hugetlb.h=15=bool arch_hugetlb_migration_supported(struct hstate *h);
 --
 arch/riscv/include/asm/hugetlb.h-20-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/riscv/include/asm/hugetlb.h:21:void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/riscv/include/asm/hugetlb.h-22-		    pte_t *ptep, unsigned long sz);
 --
 arch/riscv/include/asm/pgtable.h=622=static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
 --
 arch/riscv/include/asm/pgtable.h-636-
 arch/riscv/include/asm/pgtable.h:637:static inline void pte_clear(struct mm_struct *mm,
 arch/riscv/include/asm/pgtable.h-638-	unsigned long addr, pte_t *ptep)
 --
 arch/riscv/include/asm/pgtable.h=651=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/riscv/include/asm/pgtable.h-661-
 arch/riscv/include/asm/pgtable.h:662:	page_table_check_pte_clear(mm, address, pte);
 arch/riscv/include/asm/pgtable.h-663-
 --
 arch/riscv/mm/hugetlbpage.c=346=pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/riscv/mm/hugetlbpage.c-360-
 arch/riscv/mm/hugetlbpage.c:361:void huge_pte_clear(struct mm_struct *mm,
 arch/riscv/mm/hugetlbpage.c-362-		    unsigned long addr,
 --
 arch/riscv/mm/hugetlbpage.c-370-	if (!pte_napot(pte)) {
 arch/riscv/mm/hugetlbpage.c:371:		pte_clear(mm, addr, ptep);
 arch/riscv/mm/hugetlbpage.c-372-		return;
 --
 arch/riscv/mm/hugetlbpage.c-377-	for (i = 0; i < pte_num; i++, addr += pgsize, ptep++)
 arch/riscv/mm/hugetlbpage.c:378:		pte_clear(mm, addr, ptep);
 arch/riscv/mm/hugetlbpage.c-379-}
 --
 arch/riscv/mm/init.c=369=void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
 --
 arch/riscv/mm/init.c-380-	else
 arch/riscv/mm/init.c:381:		pte_clear(&init_mm, addr, ptep);
 arch/riscv/mm/init.c-382-	local_flush_tlb_page(addr);
 --
 arch/riscv/mm/init.c=1574=static void __meminit remove_pte_mapping(pte_t *pte_base, unsigned long addr, unsigned long end,
 --
 arch/riscv/mm/init.c-1589-
 arch/riscv/mm/init.c:1590:		pte_clear(&init_mm, addr, ptep);
 arch/riscv/mm/init.c-1591-		if (is_vmemmap)
 --
 arch/s390/include/asm/hugetlb.h=33=static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/s390/include/asm/hugetlb.h-40-#define __HAVE_ARCH_HUGE_PTE_CLEAR
 arch/s390/include/asm/hugetlb.h:41:static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/s390/include/asm/hugetlb.h-42-				  pte_t *ptep, unsigned long sz)
 --
 arch/s390/include/asm/pgtable.h=1004=static inline void pmd_clear(pmd_t *pmdp)
 --
 arch/s390/include/asm/pgtable.h-1008-
 arch/s390/include/asm/pgtable.h:1009:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/s390/include/asm/pgtable.h-1010-{
 --
 arch/s390/include/asm/pgtable.h=1186=static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 --
 arch/s390/include/asm/pgtable.h-1194-		WARN_ON_ONCE(uv_convert_from_secure_pte(res));
 arch/s390/include/asm/pgtable.h:1195:	page_table_check_pte_clear(mm, addr, res);
 arch/s390/include/asm/pgtable.h-1196-	return res;
 --
 arch/s390/include/asm/pgtable.h=1205=static inline pte_t ptep_clear_flush(struct vm_area_struct *vma,
 --
 arch/s390/include/asm/pgtable.h-1213-		WARN_ON_ONCE(uv_convert_from_secure_pte(res));
 arch/s390/include/asm/pgtable.h:1214:	page_table_check_pte_clear(vma->vm_mm, addr, res);
 arch/s390/include/asm/pgtable.h-1215-	return res;
 --
 arch/s390/include/asm/pgtable.h=1226=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
 --
 arch/s390/include/asm/pgtable.h-1238-
 arch/s390/include/asm/pgtable.h:1239:	page_table_check_pte_clear(mm, addr, res);
 arch/s390/include/asm/pgtable.h-1240-
 --
 arch/s390/mm/gmap_helpers.c=46=void gmap_helper_zap_one_page(struct mm_struct *mm, unsigned long vmaddr)
 --
 arch/s390/mm/gmap_helpers.c-64-		ptep_zap_softleaf_entry(mm, softleaf_from_pte(*ptep));
 arch/s390/mm/gmap_helpers.c:65:		pte_clear(mm, vmaddr, ptep);
 arch/s390/mm/gmap_helpers.c-66-	}
 --
 arch/s390/mm/vmem.c=168=static int __ref modify_pte_table(pmd_t *pmd, unsigned long addr,
 --
 arch/s390/mm/vmem.c-183-				vmem_free_pages((unsigned long)pfn_to_virt(pte_pfn(*pte)), get_order(PAGE_SIZE), altmap);
 arch/s390/mm/vmem.c:184:			pte_clear(&init_mm, addr, pte);
 arch/s390/mm/vmem.c-185-		} else if (pte_none(*pte)) {
 --
 arch/s390/mm/vmem.c=654=void vmem_unmap_4k_page(unsigned long addr)
 --
 arch/s390/mm/vmem.c-660-	__ptep_ipte(addr, ptep, 0, 0, IPTE_GLOBAL);
 arch/s390/mm/vmem.c:661:	pte_clear(&init_mm, addr, ptep);
 arch/s390/mm/vmem.c-662-	mutex_unlock(&vmem_mutex);
 --
 arch/sh/include/asm/pgtable_32.h=300=static inline void set_pte(pte_t *ptep, pte_t pte)
 --
 arch/sh/include/asm/pgtable_32.h-324-
 arch/sh/include/asm/pgtable_32.h:325:#define pte_clear(mm, addr, ptep) set_pte(ptep, __pte(0))
 arch/sh/include/asm/pgtable_32.h-326-
 --
 arch/sh/mm/kmap.c=51=void kunmap_coherent(void *kvaddr)
 --
 arch/sh/mm/kmap.c-59-
 arch/sh/mm/kmap.c:60:		pte_clear(&init_mm, vaddr, kmap_coherent_pte - idx);
 arch/sh/mm/kmap.c-61-		local_flush_tlb_one(get_asid(), vaddr);
 --
 arch/sparc/include/asm/pgtable_32.h=145=static inline int pte_none(pte_t pte)
 --
 arch/sparc/include/asm/pgtable_32.h-149-
 arch/sparc/include/asm/pgtable_32.h:150:static inline void __pte_clear(pte_t *ptep)
 arch/sparc/include/asm/pgtable_32.h-151-{
 --
 arch/sparc/include/asm/pgtable_32.h-154-
 arch/sparc/include/asm/pgtable_32.h:155:static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 arch/sparc/include/asm/pgtable_32.h-156-{
 arch/sparc/include/asm/pgtable_32.h:157:	__pte_clear(ptep);
 arch/sparc/include/asm/pgtable_32.h-158-}
 --
 arch/sparc/include/asm/pgtable_64.h=931=static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
 --
 arch/sparc/include/asm/pgtable_64.h-944-
 arch/sparc/include/asm/pgtable_64.h:945:#define pte_clear(mm,addr,ptep)		\
 arch/sparc/include/asm/pgtable_64.h-946-	set_pte_at((mm), (addr), (ptep), __pte(0UL))
 --
 arch/sparc/mm/srmmu.c=526=static inline void srmmu_unmapioaddr(unsigned long virt_addr)
 --
 arch/sparc/mm/srmmu.c-541-	/* No need to flush uncacheable page. */
 arch/sparc/mm/srmmu.c:542:	__pte_clear(ptep);
 arch/sparc/mm/srmmu.c-543-}
 --
 arch/um/include/asm/pgtable.h=35=extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
 --
 arch/um/include/asm/pgtable.h-73-
 arch/um/include/asm/pgtable.h:74:#define pte_clear(mm, addr, xp) pte_set_val(*(xp), (phys_t) 0, __pgprot(_PAGE_NEEDSYNC))
 arch/um/include/asm/pgtable.h-75-
 --
 arch/x86/include/asm/paravirt.h=457=static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
 --
 arch/x86/include/asm/paravirt.h-461-
 arch/x86/include/asm/paravirt.h:462:static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/x86/include/asm/paravirt.h-463-			     pte_t *ptep)
 --
 arch/x86/include/asm/pgtable-2level.h=39=static inline void native_pud_clear(pud_t *pudp)
 --
 arch/x86/include/asm/pgtable-2level.h-42-
 arch/x86/include/asm/pgtable-2level.h:43:static inline void native_pte_clear(struct mm_struct *mm,
 arch/x86/include/asm/pgtable-2level.h-44-				    unsigned long addr, pte_t *xp)
 --
 arch/x86/include/asm/pgtable-3level.h=53=static inline void native_set_pud(pud_t *pudp, pud_t pud)
 --
 arch/x86/include/asm/pgtable-3level.h-65- */
 arch/x86/include/asm/pgtable-3level.h:66:static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/x86/include/asm/pgtable-3level.h-67-				    pte_t *ptep)
 --
 arch/x86/include/asm/pgtable.h=55=extern pmdval_t early_pmd_flags;
 --
 arch/x86/include/asm/pgtable.h-87-
 arch/x86/include/asm/pgtable.h:88:#define pte_clear(mm, addr, ptep)	native_pte_clear(mm, addr, ptep)
 arch/x86/include/asm/pgtable.h-89-#define pmd_clear(pmd)			native_pmd_clear(pmd)
 --
 arch/x86/include/asm/pgtable.h=1181=static inline pte_t native_local_ptep_get_and_clear(pte_t *ptep)
 --
 arch/x86/include/asm/pgtable.h-1185-	/* Pure native function needs no input for mm, addr */
 arch/x86/include/asm/pgtable.h:1186:	native_pte_clear(NULL, 0, ptep);
 arch/x86/include/asm/pgtable.h-1187-	return res;
 --
 arch/x86/include/asm/pgtable.h=1243=static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 --
 arch/x86/include/asm/pgtable.h-1246-	pte_t pte = native_ptep_get_and_clear(ptep);
 arch/x86/include/asm/pgtable.h:1247:	page_table_check_pte_clear(mm, addr, pte);
 arch/x86/include/asm/pgtable.h-1248-	return pte;
 --
 arch/x86/include/asm/pgtable.h=1252=static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,
 --
 arch/x86/include/asm/pgtable.h-1262-		pte = native_local_ptep_get_and_clear(ptep);
 arch/x86/include/asm/pgtable.h:1263:		page_table_check_pte_clear(mm, addr, pte);
 arch/x86/include/asm/pgtable.h-1264-	} else {
 --
 arch/x86/include/asm/pgtable_32.h=42=do {						\
 arch/x86/include/asm/pgtable_32.h:43:	pte_clear(&init_mm, (vaddr), (ptep));	\
 arch/x86/include/asm/pgtable_32.h-44-	flush_tlb_one_kernel((vaddr));		\
 --
 arch/x86/include/asm/pgtable_64.h=61=static inline void native_set_pte(pte_t *ptep, pte_t pte)
 --
 arch/x86/include/asm/pgtable_64.h-65-
 arch/x86/include/asm/pgtable_64.h:66:static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
 arch/x86/include/asm/pgtable_64.h-67-				    pte_t *ptep)
 --
 arch/x86/include/asm/pgtable_64.h=87=static inline pte_t native_ptep_get_and_clear(pte_t *xp)
 --
 arch/x86/include/asm/pgtable_64.h-94-	pte_t ret = *xp;
 arch/x86/include/asm/pgtable_64.h:95:	native_pte_clear(NULL, 0, xp);
 arch/x86/include/asm/pgtable_64.h-96-	return ret;
 --
 arch/x86/kernel/alternative.c=2546=static void *__text_poke(text_poke_f func, void *addr, const void *src, size_t len)
 --
 arch/x86/kernel/alternative.c-2619-
 arch/x86/kernel/alternative.c:2620:	pte_clear(text_poke_mm, text_poke_mm_addr, ptep);
 arch/x86/kernel/alternative.c-2621-	if (cross_page_boundary)
 arch/x86/kernel/alternative.c:2622:		pte_clear(text_poke_mm, text_poke_mm_addr + PAGE_SIZE, ptep + 1);
 arch/x86/kernel/alternative.c-2623-
 --
]
]

271/2 2026/05/25 00:56 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 153278
							output: 23
							thoughts: 3867
						

Thoughts:
**The Puzzle of the Leaking Map Count**

Okay, here's the breakdown of what I've been thinking through. We're chasing down this map count leak, and it looks like a T-Head memory type configuration is causing the issue.

The initial hunch was around `pte_clear` and when it was used in code, but the function `pte_clear_not_present_full` appeared to be irrelevant and I can't find a present user PTE being cleared without the `page_table_check_pte_clear` function being called.

Then, I shifted focus to `__page_table_check_ptes_set`. The function seemed suspicious. It's supposed to clear the map count of *existing* PTEs. I realized if `ptep_get(ptep + i)` returns a present PTE but `pte_user_accessible_page` returns FALSE, the map count wouldn't be decremented. However, this is impossible because if a PTE is a present user PTE, `pte_user_accessible_page` would return TRUE. I thought about the case where the existing PTE was *previously* counted but later became inaccessible, but I cannot find a scenario where this can occur.

Then I realized the root cause must be related to an improper PFN value being passed around. `pte_pfn` is a possible source of error, especially if bit 63 is set. Looking at `pte_pfn`, I realized this could happen if a swap entry is processed, which causes an issue since the function is not meant to be called on swap entries. But, more generally, if a regular page has a physical address with PFN bit 53 set, this could cause the map count to leak. This led to a very deep dive into the PTE format.

Then, I had a realization. Bit 63 is where `_PAGE_NAPOT` goes. But it's also where the T-Head memory type bits reside. Here's the key: if `_PAGE_IO_THEAD` is in use, which sets bit 63, then `pte_pfn` *will* incorrectly treat the PFN. But the code does check for `_PAGE_IO_THEAD`, which sets bit 63!

The key is `ALT_THEAD_PMA(prot_val)`.
If a regular user page is allocated using T-Head memory type, `_PAGE_IO_THEAD` will be set by `ALT_THEAD_PMA`!
This means that bit 63 is set on a regular page.
This means `pte_pfn` will be affected!

So, the theory is: if `ALT_THEAD_PMA` is used, the PFN gets modified in `pte_pfn` with a `_PAGE_IO_THEAD`! The map count will leak because when a regular page is freed, the map count will not be decremented correctly.



272/2 2026/05/25 00:56 tool grepper
0m Args:
map[Expression:#define ALT_THEAD_PMA]

Results:
map[Output:arch/riscv/include/asm/errata_list.h=63=asm(ALTERNATIVE_2("li %0, 0\t\nnop",					\
--
arch/riscv/include/asm/errata_list.h-79- */
arch/riscv/include/asm/errata_list.h:80:#define ALT_THEAD_PMA(_val)						\
arch/riscv/include/asm/errata_list.h-81-asm volatile(ALTERNATIVE(						\
--
arch/riscv/include/asm/errata_list.h-97-#else
arch/riscv/include/asm/errata_list.h:98:#define ALT_THEAD_PMA(_val)
arch/riscv/include/asm/errata_list.h-99-#endif
]

273/2 2026/05/25 00:56 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 158014
							output: 30
							thoughts: 27
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Investigating a Possible RISC-V Errata**

Okay, time to dig in. I need to get to the bottom of this. My first instinct is to check the `arch/riscv/include/asm/errata_list.h` file, specifically around line 80. That's the typical place for errata documentation and lists for RISC-V. I'm expecting to find information about known hardware bugs and their workarounds. I'll need to see if anything jumps out that relates to the issue I'm chasing. This feels like the logical starting point for understanding potential hardware quirks.



274/2 2026/05/25 00:56 tool read-file
0m Args:
map[File:arch/riscv/include/asm/errata_list.h]

Results:
map[Contents:/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (C) 2021 Sifive.
 */
#ifndef ASM_ERRATA_LIST_H
#define ASM_ERRATA_LIST_H

#include <asm/csr.h>
#include <asm/insn-def.h>
#include <asm/hwcap.h>
#include <asm/vendorid_list.h>
#include <asm/errata_list_vendors.h>
#include <asm/vendor_extensions/mips.h>

#ifdef __ASSEMBLER__

#define ALT_INSN_FAULT(x)						\
ALTERNATIVE(__stringify(RISCV_PTR do_trap_insn_fault),			\
	    __stringify(RISCV_PTR sifive_cip_453_insn_fault_trp),	\
	    SIFIVE_VENDOR_ID, ERRATA_SIFIVE_CIP_453,			\
	    CONFIG_ERRATA_SIFIVE_CIP_453)

#define ALT_PAGE_FAULT(x)						\
ALTERNATIVE(__stringify(RISCV_PTR do_page_fault),			\
	    __stringify(RISCV_PTR sifive_cip_453_page_fault_trp),	\
	    SIFIVE_VENDOR_ID, ERRATA_SIFIVE_CIP_453,			\
	    CONFIG_ERRATA_SIFIVE_CIP_453)
#else /* !__ASSEMBLER__ */

#define ALT_SFENCE_VMA_ASID(asid)					\
asm(ALTERNATIVE("sfence.vma x0, %0", "sfence.vma", SIFIVE_VENDOR_ID,	\
		ERRATA_SIFIVE_CIP_1200, CONFIG_ERRATA_SIFIVE_CIP_1200)	\
		: : "r" (asid) : "memory")

#define ALT_SFENCE_VMA_ADDR(addr)					\
asm(ALTERNATIVE("sfence.vma %0", "sfence.vma", SIFIVE_VENDOR_ID,	\
		ERRATA_SIFIVE_CIP_1200, CONFIG_ERRATA_SIFIVE_CIP_1200)	\
		: : "r" (addr) : "memory")

#define ALT_SFENCE_VMA_ADDR_ASID(addr, asid)				\
asm(ALTERNATIVE("sfence.vma %0, %1", "sfence.vma", SIFIVE_VENDOR_ID,	\
		ERRATA_SIFIVE_CIP_1200, CONFIG_ERRATA_SIFIVE_CIP_1200)	\
		: : "r" (addr), "r" (asid) : "memory")

#define ALT_RISCV_PAUSE()					\
asm(ALTERNATIVE(	\
		RISCV_PAUSE, /* Original RISC‑V pause insn */	\
		MIPS_PAUSE, /* Replacement for MIPS P8700 */	\
		MIPS_VENDOR_ID, /* Vendor ID to match */	\
		ERRATA_MIPS_P8700_PAUSE_OPCODE, /* patch_id */	\
		CONFIG_ERRATA_MIPS_P8700_PAUSE_OPCODE)	\
	: /* no outputs */	\
	: /* no inputs */	\
	: "memory")

/*
 * _val is marked as "will be overwritten", so need to set it to 0
 * in the default case.
 */
#define ALT_SVPBMT_SHIFT 61
#define ALT_THEAD_MAE_SHIFT 59
#define ALT_SVPBMT(_val, prot)						\
asm(ALTERNATIVE_2("li %0, 0\t\nnop",					\
		  "li %0, %1\t\nslli %0,%0,%3", 0,			\
			RISCV_ISA_EXT_SVPBMT, CONFIG_RISCV_ISA_SVPBMT,	\
		  "li %0, %2\t\nslli %0,%0,%4", THEAD_VENDOR_ID,	\
			ERRATA_THEAD_MAE, CONFIG_ERRATA_THEAD_MAE)	\
		: "=r"(_val)						\
		: "I"(prot##_SVPBMT >> ALT_SVPBMT_SHIFT),		\
		  "I"(prot##_THEAD >> ALT_THEAD_MAE_SHIFT),		\
		  "I"(ALT_SVPBMT_SHIFT),				\
		  "I"(ALT_THEAD_MAE_SHIFT))

#ifdef CONFIG_ERRATA_THEAD_MAE
/*
 * IO/NOCACHE memory types are handled together with svpbmt,
 * so on T-Head chips, check if no other memory type is set,
 * and set the non-0 PMA type if applicable.
 */
#define ALT_THEAD_PMA(_val)						\
asm volatile(ALTERNATIVE(						\
	__nops(7),							\
	"li      t3, %1\n\t"						\
	"slli    t3, t3, %3\n\t"					\
	"and     t3, %0, t3\n\t"					\
	"bne     t3, zero, 2f\n\t"					\
	"li      t3, %2\n\t"						\
	"slli    t3, t3, %3\n\t"					\
	"or      %0, %0, t3\n\t"					\
	"2:",  THEAD_VENDOR_ID,						\
		ERRATA_THEAD_MAE, CONFIG_ERRATA_THEAD_MAE)		\
	: "+r"(_val)							\
	: "I"(_PAGE_MTMASK_THEAD >> ALT_THEAD_MAE_SHIFT),		\
	  "I"(_PAGE_PMA_THEAD >> ALT_THEAD_MAE_SHIFT),			\
	  "I"(ALT_THEAD_MAE_SHIFT)					\
	: "t3")
#else
#define ALT_THEAD_PMA(_val)
#endif

#define ALT_CMO_OP(_op, _start, _size, _cachesize)			\
asm volatile(ALTERNATIVE(						\
	__nops(5),							\
	"mv a0, %1\n\t"							\
	"j 2f\n\t"							\
	"3:\n\t"							\
	CBO_##_op(a0)							\
	"add a0, a0, %0\n\t"						\
	"2:\n\t"							\
	"bltu a0, %2, 3b\n\t",						\
	0, RISCV_ISA_EXT_ZICBOM, CONFIG_RISCV_ISA_ZICBOM)		\
	: : "r"(_cachesize),						\
	    "r"((unsigned long)(_start) & ~((_cachesize) - 1UL)),	\
	    "r"((unsigned long)(_start) + (_size))			\
	: "a0")

#define THEAD_C9XX_RV_IRQ_PMU			17
#define THEAD_C9XX_CSR_SCOUNTEROF		0x5c5

#endif /* __ASSEMBLER__ */

#endif
]

275/2 2026/05/25 00:56 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 160014
							output: 50
							thoughts: 4175
						

Thoughts:
**Analyzing a Potential Page Table Accounting Bug**

Alright, let's break this down. My initial focus was on the T-Head PMA (Physical Memory Attribute) setting, but that quickly became a dead end. The PMA settings don't seem to be directly involved in a scenario that leads to a leak, especially since these are not used with regular user pages. The checks and settings for PMA are related to kernel mappings, which are ignored by the `page_table_check` mechanism.

The core of the problem appears to be related to `anon_map_count` and how it interacts with the `zap_present_ptes` function, and by extension `clear_full_ptes`. The code appears to be designed to keep the map count balanced when clearing PTEs. The functions `ptep_get_and_clear_full`, `ptep_get_and_clear` and `page_table_check_pte_clear` within it should be balanced in terms of their effect on the map count. The `folio_pte_batch` function also seemed like a possible point of error, but the checks there look correct in terms of ensuring that PTEs belonging to the same folio are handled together, especially when the number of PTEs being processed (`nr`) is increased.

However, the analysis of `zap_pte_range` and its interaction with the folio state raised a few new questions. The checks for `pte_none` and `pte_present` are there, but I need to make sure I am not skipping anything. If `should_zap_folio` is false for a folio, it should simply not zap the PTE, but it shouldn't cause map counting errors.

I started to focus on the possibility of `nr` being calculated incorrectly. The logic within `folio_pte_batch` and `zap_present_ptes` is correct, and I can't find a calculation error that would cause this to happen. I am confident that `folio_pte_batch` is correctly identifying PTEs belonging to the same folio and returning the correct `nr`.

I'm now thinking about what happens if `folio` refcount hits zero while the PTE is still set. The problem report points to `mm/page_table_check.c:142`, which suggests a page is being freed while still mapped. The `page_table_check` is designed to catch this. This means the bug could be in either the page table accounting logic or it could be a refcount bug. It could be due to refcount errors in the page management code.

Given the bug report comes from `syzkaller` on a `riscv-virtio,qemu` system, it might be a RISC-V specific bug. Let's revisit the RISC-V page table macros. I've been reviewing the RISC-V specific implementations of key functions such as `ptep_get_and_clear`, `ptep_get_and_clear_full`, `set_pte_at`, `ptep_clear_flush` and `ptep_set_access_flags`. These all look correct in terms of their interaction with `page_table_check`.

But what about `ptep_set_wrprotect`? This changes the PTE's write permissions, which could potentially cause a missed update. I went over it to see if it bypasses `page_table_check`. I found that `ptep_set_wrprotect` modifies the PTE directly, but it does NOT change the `_PAGE_PRESENT` and `_PAGE_USER` flags. Thus, a map count leak caused by this function is NOT likely.

In summary, the most probable cause is a refcount bug that is detected by `page_table_check`, rather than an accounting error. If this is a RISC-V specific bug, I should focus on potential refcount errors.



276/2 2026/05/25 00:57 tool codesearch-definition-source
0m Args:
map[ContextFile:arch/riscv/mm/pgtable.c IncludeLines:true Name:ptep_test_and_clear_young]

Results:
map[SourceCode: 446:	bool ptep_test_and_clear_young(struct vm_area_struct *vma,
 447:			unsigned long addr, pte_t *ptep)
 448:	{
 449:		bool ret = false;
 450:	
 451:		if (pte_young(*ptep))
 452:			ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
 453:						 (unsigned long *) &ptep->pte);
 454:	
 455:		return ret;
 456:	}
 SourceFile:arch/x86/mm/pgtable.c]

277/2 2026/05/25 00:57 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 165259
							output: 24
							thoughts: 21
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Debugging Architecture-Specific Code Generation**

Okay, so I just ran that test, and the output is clearly x86. Hmm, that's not what I expected. The tool should have generated RISC-V. Alright, I need to investigate this. The problem isn't the code. I need to make sure the build environment is set correctly and verify that the correct target architecture is enabled. I need to dig into the configuration files, cross-compilation settings, and any build flags to pinpoint exactly why it defaulted to x86. I'll start by checking the compiler flags and linker scripts. Something in the build process is clearly overriding my target selection. Time to get my hands dirty and track down that stubborn x86 instruction set!



278/2 2026/05/25 00:57 tool grepper
0m Args:
map[Expression:ptep_test_and_clear_young]

Results:
map[Output:Documentation/mm/arch_pgtable_helpers.rst=15=PTE Page Table Helpers
--
Documentation/mm/arch_pgtable_helpers.rst-70-+---------------------------+--------------------------------------------------+
Documentation/mm/arch_pgtable_helpers.rst:71:| ptep_test_and_clear_young | Clears young from a PTE                          |
Documentation/mm/arch_pgtable_helpers.rst-72-+---------------------------+--------------------------------------------------+
--
arch/arm64/include/asm/pgtable.h=1299=static inline void __pte_clear(struct mm_struct *mm,
--
arch/arm64/include/asm/pgtable.h-1304-
arch/arm64/include/asm/pgtable.h:1305:static inline bool __ptep_test_and_clear_young(struct vm_area_struct *vma,
arch/arm64/include/asm/pgtable.h-1306-		unsigned long address, pte_t *ptep)
--
arch/arm64/include/asm/pgtable.h=1321=static inline bool __ptep_clear_flush_young(struct vm_area_struct *vma,
--
arch/arm64/include/asm/pgtable.h-1323-{
arch/arm64/include/asm/pgtable.h:1324:	bool young = __ptep_test_and_clear_young(vma, address, ptep);
arch/arm64/include/asm/pgtable.h-1325-
--
arch/arm64/include/asm/pgtable.h=1343=static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
--
arch/arm64/include/asm/pgtable.h-1347-	VM_WARN_ON(pmd_table(READ_ONCE(*pmdp)) && !system_supports_haft());
arch/arm64/include/asm/pgtable.h:1348:	return __ptep_test_and_clear_young(vma, address, (pte_t *)pmdp);
arch/arm64/include/asm/pgtable.h-1349-}
--
arch/arm64/include/asm/pgtable.h=1834=static inline bool test_and_clear_young_ptes(struct vm_area_struct *vma,
--
arch/arm64/include/asm/pgtable.h-1837-	if (likely(nr == 1 && !pte_cont(__ptep_get(ptep))))
arch/arm64/include/asm/pgtable.h:1838:		return __ptep_test_and_clear_young(vma, addr, ptep);
arch/arm64/include/asm/pgtable.h-1839-
--
arch/arm64/include/asm/pgtable.h-1843-#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
arch/arm64/include/asm/pgtable.h:1844:static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
arch/arm64/include/asm/pgtable.h-1845-		unsigned long addr, pte_t *ptep)
--
arch/arm64/include/asm/pgtable.h=1919=static inline void clear_young_dirty_ptes(struct vm_area_struct *vma,
--
arch/arm64/include/asm/pgtable.h-1939-#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
arch/arm64/include/asm/pgtable.h:1940:#define ptep_test_and_clear_young		__ptep_test_and_clear_young
arch/arm64/include/asm/pgtable.h-1941-#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
--
arch/arm64/mm/contpte.c=512=bool contpte_test_and_clear_young_ptes(struct vm_area_struct *vma,
--
arch/arm64/mm/contpte.c-531-	for (; addr != end; ptep++, addr += PAGE_SIZE)
arch/arm64/mm/contpte.c:532:		young |= __ptep_test_and_clear_young(vma, addr, ptep);
arch/arm64/mm/contpte.c-533-
--
arch/microblaze/include/asm/pgtable.h=320=struct vm_area_struct;
arch/microblaze/include/asm/pgtable.h:321:static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
arch/microblaze/include/asm/pgtable.h-322-		unsigned long address, pte_t *ptep)
--
arch/parisc/include/asm/pgtable.h=435=static inline pte_t ptep_get(pte_t *ptep)
--
arch/parisc/include/asm/pgtable.h-440-
arch/parisc/include/asm/pgtable.h:441:static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
arch/parisc/include/asm/pgtable.h-442-		unsigned long addr, pte_t *ptep)
--
arch/powerpc/include/asm/book3s/32/pgtable.h=256=static inline pte_basic_t pte_update(struct mm_struct *mm, unsigned long addr, pte_t *p,
--
arch/powerpc/include/asm/book3s/32/pgtable.h-297-#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
arch/powerpc/include/asm/book3s/32/pgtable.h:298:static inline bool __ptep_test_and_clear_young(struct mm_struct *mm,
arch/powerpc/include/asm/book3s/32/pgtable.h-299-		unsigned long addr, pte_t *ptep)
--
arch/powerpc/include/asm/book3s/32/pgtable.h-307-}
arch/powerpc/include/asm/book3s/32/pgtable.h:308:#define ptep_test_and_clear_young(__vma, __addr, __ptep) \
arch/powerpc/include/asm/book3s/32/pgtable.h:309:	__ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep)
arch/powerpc/include/asm/book3s/32/pgtable.h-310-
--
arch/powerpc/include/asm/book3s/64/pgtable.h=334=static inline unsigned long pte_update(struct mm_struct *mm, unsigned long addr,
--
arch/powerpc/include/asm/book3s/64/pgtable.h-351- */
arch/powerpc/include/asm/book3s/64/pgtable.h:352:static inline bool __ptep_test_and_clear_young(struct mm_struct *mm,
arch/powerpc/include/asm/book3s/64/pgtable.h-353-		unsigned long addr, pte_t *ptep)
--
arch/powerpc/include/asm/book3s/64/pgtable.h-363-#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
arch/powerpc/include/asm/book3s/64/pgtable.h:364:#define ptep_test_and_clear_young(__vma, __addr, __ptep)	\
arch/powerpc/include/asm/book3s/64/pgtable.h-365-({								\
arch/powerpc/include/asm/book3s/64/pgtable.h:366:	__ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep); \
arch/powerpc/include/asm/book3s/64/pgtable.h-367-})
--
arch/powerpc/include/asm/book3s/64/pgtable.h-385-#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
arch/powerpc/include/asm/book3s/64/pgtable.h:386:#define ptep_clear_flush_young ptep_test_and_clear_young
arch/powerpc/include/asm/book3s/64/pgtable.h-387-
--
arch/powerpc/include/asm/nohash/64/pgtable.h=149=static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
--
arch/powerpc/include/asm/nohash/64/pgtable.h-157-({									\
arch/powerpc/include/asm/nohash/64/pgtable.h:158:	bool __young = ptep_test_and_clear_young(__vma, __address, __ptep);\
arch/powerpc/include/asm/nohash/64/pgtable.h-159-	__young;							\
--
arch/powerpc/include/asm/nohash/pgtable.h=59=static inline pte_basic_t pte_update(struct mm_struct *mm, unsigned long addr, pte_t *p,
--
arch/powerpc/include/asm/nohash/pgtable.h-103-
arch/powerpc/include/asm/nohash/pgtable.h:104:static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
arch/powerpc/include/asm/nohash/pgtable.h-105-		unsigned long addr, pte_t *ptep)
--
arch/riscv/include/asm/pgtable.h=644=extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
--
arch/riscv/include/asm/pgtable.h-646-#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG	/* defined in mm/pgtable.c */
arch/riscv/include/asm/pgtable.h:647:bool ptep_test_and_clear_young(struct vm_area_struct *vma,
arch/riscv/include/asm/pgtable.h-648-		unsigned long address, pte_t *ptep);
--
arch/riscv/include/asm/pgtable.h=683=static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
--
arch/riscv/include/asm/pgtable.h-700-	 */
arch/riscv/include/asm/pgtable.h:701:	return ptep_test_and_clear_young(vma, address, ptep);
arch/riscv/include/asm/pgtable.h-702-}
--
arch/riscv/include/asm/pgtable.h=1003=static inline bool pmdp_test_and_clear_young(struct vm_area_struct *vma,
--
arch/riscv/include/asm/pgtable.h-1005-{
arch/riscv/include/asm/pgtable.h:1006:	return ptep_test_and_clear_young(vma, address, (pte_t *)pmdp);
arch/riscv/include/asm/pgtable.h-1007-}
--
arch/riscv/include/asm/pgtable.h=1097=static inline bool pudp_test_and_clear_young(struct vm_area_struct *vma,
--
arch/riscv/include/asm/pgtable.h-1099-{
arch/riscv/include/asm/pgtable.h:1100:	return ptep_test_and_clear_young(vma, address, (pte_t *)pudp);
arch/riscv/include/asm/pgtable.h-1101-}
--
arch/riscv/kvm/mmu.c=248=bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range)
--
arch/riscv/kvm/mmu.c-264-
arch/riscv/kvm/mmu.c:265:	return ptep_test_and_clear_young(NULL, 0, ptep);
arch/riscv/kvm/mmu.c-266-}
--
arch/riscv/mm/pgtable.c=8=int ptep_set_access_flags(struct vm_area_struct *vma,
--
arch/riscv/mm/pgtable.c-31-
arch/riscv/mm/pgtable.c:32:bool ptep_test_and_clear_young(struct vm_area_struct *vma,
arch/riscv/mm/pgtable.c-33-		unsigned long address, pte_t *ptep)
--
arch/riscv/mm/pgtable.c-38-}
arch/riscv/mm/pgtable.c:39:EXPORT_SYMBOL_GPL(ptep_test_and_clear_young);
arch/riscv/mm/pgtable.c-40-
--
arch/s390/include/asm/pgtable.h=1166=pte_t ptep_xchg_lazy(struct mm_struct *, unsigned long, pte_t *, pte_t);
--
arch/s390/include/asm/pgtable.h-1168-#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
arch/s390/include/asm/pgtable.h:1169:static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
arch/s390/include/asm/pgtable.h-1170-		unsigned long addr, pte_t *ptep)
--
arch/s390/include/asm/pgtable.h=1179=static inline bool ptep_clear_flush_young(struct vm_area_struct *vma,
--
arch/s390/include/asm/pgtable.h-1181-{
arch/s390/include/asm/pgtable.h:1182:	return ptep_test_and_clear_young(vma, address, ptep);
arch/s390/include/asm/pgtable.h-1183-}
--
arch/x86/include/asm/pgtable.h=1230=extern int ptep_set_access_flags(struct vm_area_struct *vma,
--
arch/x86/include/asm/pgtable.h-1234-#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
arch/x86/include/asm/pgtable.h:1235:bool ptep_test_and_clear_young(struct vm_area_struct *vma,
arch/x86/include/asm/pgtable.h-1236-		unsigned long addr, pte_t *ptep);
--
arch/x86/mm/pgtable.c=425=int pudp_set_access_flags(struct vm_area_struct *vma, unsigned long address,
--
arch/x86/mm/pgtable.c-445-
arch/x86/mm/pgtable.c:446:bool ptep_test_and_clear_young(struct vm_area_struct *vma,
arch/x86/mm/pgtable.c-447-		unsigned long addr, pte_t *ptep)
--
arch/x86/mm/pgtable.c=486=bool ptep_clear_flush_young(struct vm_area_struct *vma,
--
arch/x86/mm/pgtable.c-501-	 */
arch/x86/mm/pgtable.c:502:	return ptep_test_and_clear_young(vma, address, ptep);
arch/x86/mm/pgtable.c-503-}
--
arch/xtensa/include/asm/pgtable.h=305=struct vm_area_struct;
arch/xtensa/include/asm/pgtable.h-306-
arch/xtensa/include/asm/pgtable.h:307:static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
arch/xtensa/include/asm/pgtable.h-308-		unsigned long addr, pte_t *ptep)
--
fs/proc/task_mmu.c=1680=static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr,
--
fs/proc/task_mmu.c-1730-		/* Clear accessed and referenced bits. */
fs/proc/task_mmu.c:1731:		ptep_test_and_clear_young(vma, addr, pte);
fs/proc/task_mmu.c-1732-		folio_test_clear_young(folio);
--
include/linux/pgtable.h=487=static inline pgd_t pgdp_get(pgd_t *pgdp)
--
include/linux/pgtable.h-493-#ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
include/linux/pgtable.h:494:static inline bool ptep_test_and_clear_young(struct vm_area_struct *vma,
include/linux/pgtable.h-495-		unsigned long address, pte_t *ptep)
--
include/linux/pgtable.h=641=static inline void clear_young_dirty_ptes(struct vm_area_struct *vma,
--
include/linux/pgtable.h-648-		if (flags == CYDP_CLEAR_YOUNG)
include/linux/pgtable.h:649:			ptep_test_and_clear_young(vma, addr, ptep);
include/linux/pgtable.h-650-		else {
--
include/linux/pgtable.h=1088=static inline bool clear_flush_young_ptes(struct vm_area_struct *vma,
--
include/linux/pgtable.h-1114- * May be overridden by the architecture; otherwise, implemented as a simple
include/linux/pgtable.h:1115: * loop over ptep_test_and_clear_young().
include/linux/pgtable.h-1116- *
--
include/linux/pgtable.h=1125=static inline bool test_and_clear_young_ptes(struct vm_area_struct *vma,
--
include/linux/pgtable.h-1130-	for (;;) {
include/linux/pgtable.h:1131:		young |= ptep_test_and_clear_young(vma, addr, ptep);
include/linux/pgtable.h-1132-		if (--nr == 0)
--
mm/damon/ops-common.c=44=void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr)
--
mm/damon/ops-common.c-65-	if (likely(pte_present(pteval)))
mm/damon/ops-common.c:66:		young |= ptep_test_and_clear_young(vma, addr, pte);
mm/damon/ops-common.c-67-	young |= mmu_notifier_clear_young(vma->vm_mm, addr, addr + PAGE_SIZE);
--
mm/debug_vm_pgtable.c=114=static void __init pte_advanced_tests(struct pgtable_debug_args *args)
--
mm/debug_vm_pgtable.c-165-	flush_dcache_page(page);
mm/debug_vm_pgtable.c:166:	ptep_test_and_clear_young(args->vma, args->vaddr, args->ptep);
mm/debug_vm_pgtable.c-167-	pte = ptep_get(args->ptep);
--
mm/page_idle.c=52=static bool page_idle_clear_pte_refs_one(struct folio *folio,
--
mm/page_idle.c-70-			if (likely(pte_present(ptep_get(pvmw.pte))))
mm/page_idle.c:71:				referenced |= ptep_test_and_clear_young(vma, addr, pvmw.pte);
mm/page_idle.c-72-			referenced |= mmu_notifier_clear_young(vma->vm_mm, addr, addr + PAGE_SIZE);
--
mm/pgtable-generic.c=84=bool ptep_clear_flush_young(struct vm_area_struct *vma,
--
mm/pgtable-generic.c-88-
mm/pgtable-generic.c:89:	young = ptep_test_and_clear_young(vma, address, ptep);
mm/pgtable-generic.c-90-	if (young)
]

279/2 2026/05/25 00:57 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 170974
							output: 66
							thoughts: 6560
						

Thoughts:
**Analysis of a RISC-V Kernel Use-After-Free Vulnerability**

My analysis has led me to believe the kernel has a severe refcount bug, resulting in a use-after-free (UAF) vulnerability. This is triggered when a page is freed (refcount reaches zero) while it's still mapped in a page table, particularly during process exit (`exit_mmap`). The analysis began with understanding the behavior of `ptep_test_and_clear_young`, which modifies page table entries, then I examined potential race conditions with operations that alter the map count and present bits (e.g., `ptep_get_and_clear`, `zap_present_ptes`). My review included confirming that all normal operations to clear PTEs also called `page_table_check_pte_clear`, ensuring accounting was correct, and also covered `page_table_check_ptes_set`. I looked at `pte_clear` within several RISC-V specific files and determined that the logic correctly called the accounting functions. I found no accounting bugs in the RISC-V page table management. I then analyzed interactions with huge pages (`hugetlb`) and napot encoding. I checked `pte_pfn` and `pte_mknapot` for correctness in handling NAPOT encoding. I am confident that the NAPOT implementation is correct, and I found no related bugs. The issue must be a refcount issue, and not an accounting one. Because `__page_table_check_zero` is called, it means the page had already had its map count decremented, and the refcount reached zero while still being mapped. I concluded that it's a genuine refcount bug. The key lies in the fact that the page has a map count greater than zero at the point it should be zero, meaning it was mapped in multiple locations. This refcount bug likely arises from a double free or incorrect `put_page` call, allowing a page to be freed before it should be. The crash trace points to `exit_mmap`, which is responsible for unmapping memory. This likely occurs when a page is mapped by multiple processes (e.g., via `fork` or shared memory), its refcount is incorrectly decremented to 0, but it is still mapped elsewhere. This means `madvise`, `mremap`, `fork`, or similar operations might be involved. This is highly exploitable, leading to memory corruption, privilege escalation, and system crashes. It is accessible to unprivileged users within user namespaces.



280/2 2026/05/25 00:58 tool set-results
0m Args:
map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]

Results:
map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]

281/2 2026/05/25 00:58 llm expert
0m Model:
gemini-3.1-pro-preview

Tokens:
							input: 178198
							output: 1005
							thoughts: 13
						

Thoughts:
Okay, here's the summary, rendered in the first person, assuming the user is an expert:

**Final Reasoning and Conclusion**

Alright, the data's in, the analyses are done, and the findings are conclusive. I'm now at the point of finalizing my reasoning. There's no further processing needed, all parameters have been accounted for, and the implications of this outcome are clear. This section is where I'll connect the dots and present my definitive interpretation of the results, drawing on my deep understanding of the subject matter to articulate why these specific outcomes are what they are. I'll need to clarify the scope, the limits, and the most probable inferences that can be drawn with confidence.



282/1 2026/05/25 00:58 action format-explanation
0m Results:
map[Explanation:The bug report indicates a `BUG_ON` triggering in `__page_table_check_zero()` at
`mm/page_table_check.c:142` during process exit (`exit_mmap` -> `tlb_finish_mmu`
-> `free_pages_and_swap_cache`).

### Analysis of the Crash
The `CONFIG_PAGE_TABLE_CHECK` feature synchronously tracks the number of user
page table entries (PTEs, PMDs, etc.) that map each physical page. When a page
is finally freed to the buddy allocator (`__free_pages_prepare`),
`__page_table_check_zero()` verifies that the page is no longer mapped anywhere
by checking that its `anon_map_count` and `file_map_count` are exactly zero.

The crash (`BUG_ON(atomic_read(&ptc->anon_map_count));`) means that a page is
being freed while the kernel's page table tracking still believes there are
active user PTEs pointing to it.

There are two main ways this can happen:
1. **An accounting bug in architecture-specific page table macros:** A PTE was
cleared without calling the corresponding `page_table_check_pte_clear()` hook,
leaving a dangling map count.
2. **A genuine refcount bug (Use-After-Free):** The page was mapped multiple
times (e.g., shared between processes or threads), but its `refcount` was
erroneously decremented too many times. When the current process unmapped its
PTE, the refcount dropped to 0, causing the page to be freed. However, because
it was still mapped in another process, its `anon_map_count` was still > 0,
triggering the `BUG_ON`.

### Investigation of RISC-V Page Table Macros
Extensive review of the RISC-V page table manipulation code (including HugeTLB,
NAPOT, and generic PTE/PMD helpers) confirms that the accounting hooks are
correctly placed:
- `ptep_get_and_clear()` correctly calls `page_table_check_pte_clear()`.
- `set_pte_at()` correctly calls `page_table_check_ptes_set()`.
- `ptep_get_and_clear_full()` falls back to the generic implementation which
correctly hooks into the checks.
- While `huge_pte_clear()` in RISC-V bypasses the checks by using `pte_clear()`,
it is strictly only ever called on non-present PTEs (like migration entries or
UFFD_WP markers) which do not contribute to the map count anyway.
- The recent fix in commit `83d78ac677b9` ("riscv: Fix hugetlb retrieval of
number of ptes in case of !present pte") addressed an issue where only 1 PTE of
a 16-PTE NAPOT block was cleared for non-present entries. However, since
non-present entries do not increment the `page_table_check` map count, leaving
them behind does not cause this specific `BUG_ON`.

### Conclusion
Since the page table accounting macros are sound, the crash is the result of a
**genuine page refcount bug (Use-After-Free)**. The `mmu_gather` batching
correctly unmapped the page and decremented its map count, but the page's
refcount hit 0 prematurely while it was still mapped elsewhere.

Because the page is freed while another process (or thread) still holds a valid
PTE pointing to it, the kernel might reallocate this physical page for sensitive
kernel data or another user's memory. The process holding the dangling PTE can
then read or write to the reallocated page. This is a classic Use-After-Free
(UAF) via page tables, which is highly exploitable for local privilege
escalation (LPE) and memory corruption.

### Impact Assessment
* **Exploitable:** Yes. A UAF via page tables allows an attacker to achieve
read/write primitives over reallocated physical memory, leading to privilege
escalation.
* **Denial Of Service:** Yes. The `BUG_ON` halts the kernel, and the underlying
memory corruption can cause system instability.
* **Accessible From Unprivileged Processes:** Yes. The bug is triggered by
standard memory management syscalls (like `mmap`, `madvise`, `fork`, `exit`)
which are available to unprivileged users.
* **Accessible From User Namespaces:** Yes. No special capabilities are required
to trigger memory management paths.
* **Remote / Peripheral / VM / Filesystem Triggers:** No. This is a core virtual
memory management bug, triggered by local syscalls.]

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)