cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

devmem_is_allowed.c (683B)


      1// SPDX-License-Identifier: GPL-2.0-only
      2/*
      3 * A generic version of devmem_is_allowed.
      4 *
      5 * Based on arch/arm64/mm/mmap.c
      6 *
      7 * Copyright (C) 2020 Google, Inc.
      8 * Copyright (C) 2012 ARM Ltd.
      9 */
     10
     11#include <linux/mm.h>
     12#include <linux/ioport.h>
     13
     14/*
     15 * devmem_is_allowed() checks to see if /dev/mem access to a certain address
     16 * is valid. The argument is a physical page number.  We mimic x86 here by
     17 * disallowing access to system RAM as well as device-exclusive MMIO regions.
     18 * This effectively disable read()/write() on /dev/mem.
     19 */
     20int devmem_is_allowed(unsigned long pfn)
     21{
     22	if (iomem_is_exclusive(PFN_PHYS(pfn)))
     23		return 0;
     24	if (!page_is_ram(pfn))
     25		return 1;
     26	return 0;
     27}