diff --git a/.gitignore b/.gitignore index 47cf365..3a3ca64 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ test/** +.gdb_history \ No newline at end of file diff --git a/src/aarch64-linux-flush-dcache/.gitignore b/src/aarch64-linux-flush-dcache/.gitignore new file mode 100644 index 0000000..98274e1 --- /dev/null +++ b/src/aarch64-linux-flush-dcache/.gitignore @@ -0,0 +1,171 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# NOTE! Don't add files that are generated in specific +# subdirectories here. Add them in the ".gitignore" file +# in that subdirectory instead. +# +# NOTE! Please use 'git ls-files -i -c --exclude-per-directory=.gitignore' +# command after changing this file, to see if there are +# any tracked files which get ignored after the change. +# +# Normal rules (sorted alphabetically) +# +.* +*.a +*.asn1.[ch] +*.bin +*.bz2 +*.c.[012]*.* +*.dt.yaml +*.dtb +*.dtbo +*.dtb.S +*.dtbo.S +*.dwo +*.elf +*.gcno +*.gz +*.i +*.ko +*.lex.c +*.ll +*.lst +*.lz4 +*.lzma +*.lzo +*.mod +*.mod.c +*.o +*.o.* +*.patch +*.rmeta +*.rpm +*.rsi +*.s +*.so +*.so.dbg +*.su +*.symtypes +*.symversions +*.tab.[ch] +*.tar +*.xz +*.zst +Module.symvers +modules.order + +# +# Top-level generic files +# +/linux +/modules-only.symvers +/vmlinux +/vmlinux.32 +/vmlinux.map +/vmlinux.symvers +/vmlinux-gdb.py +/vmlinuz +/System.map +/Module.markers +/modules.builtin +/modules.builtin.modinfo +/modules.nsdeps + +# +# RPM spec file (make rpm-pkg) +# +/rpmbuild/ + +# +# Debian directory (make deb-pkg) +# +/debian/ + +# +# Snap directory (make snap-pkg) +# +/snap/ + +# +# tar directory (make tar*-pkg) +# +/tar-install/ + +# +# We don't want to ignore the following even if they are dot-files +# +!.clang-format +!.cocciconfig +!.get_maintainer.ignore +!.gitattributes +!.gitignore +!.kunitconfig +!.mailmap +!.rustfmt.toml + +# +# Generated include files +# +/include/config/ +/include/generated/ +/arch/*/include/generated/ + +# stgit generated dirs +patches-* + +# quilt's files +patches +series + +# ctags files +tags +TAGS + +# cscope files +cscope.* +ncscope.* + +# gnu global files +GPATH +GRTAGS +GSYMS +GTAGS + +# id-utils files +ID + +*.orig +*~ +\#*# + +# +# Leavings from module signing +# +extra_certificates +signing_key.pem +signing_key.priv +signing_key.x509 +x509.genkey + +# Kconfig presets +/all.config +/alldef.config +/allmod.config +/allno.config +/allrandom.config +/allyes.config + +# Kconfig savedefconfig output +/defconfig + +# Kdevelop4 +*.kdev4 + +# Clang's compilation database file +/compile_commands.json + +# Documentation toolchain +sphinx_*/ + +# Rust analyzer configuration +/rust-project.json diff --git a/src/aarch64-linux-flush-dcache/my_shmem.c b/src/aarch64-linux-flush-dcache/my_shmem.c index 0f232a3..e1301f8 100644 --- a/src/aarch64-linux-flush-dcache/my_shmem.c +++ b/src/aarch64-linux-flush-dcache/my_shmem.c @@ -77,8 +77,10 @@ static vm_fault_t my_shmem_vmops_fault(struct vm_fault *vmf) mutex_lock(&my_shmem_pages_mtx); if (nr_pages_from_vm_start < my_shmem_page_count) { /* Offset in range, return existing page */ - pr_info("[%s] Found remappable page nr: %lu, offset: %lu.\n", - __func__, nr_pages_from_vm_start, _dbg_offset_from_page); + pr_info("[%s] Found remappable page nr: %lu, offset: %lu. " + "Total pages allocated: %ld.\n", + __func__, nr_pages_from_vm_start, _dbg_offset_from_page, + my_shmem_page_count); // We won't delete elements from list here! struct my_shmem_page *page_entry; diff --git a/src/aarch64-linux-flush-dcache/userspace/writer_addr.c b/src/aarch64-linux-flush-dcache/userspace/writer_addr.c new file mode 100644 index 0000000..d249252 --- /dev/null +++ b/src/aarch64-linux-flush-dcache/userspace/writer_addr.c @@ -0,0 +1,59 @@ +#include // sysconf +#include // printf +#include // exit +#include // O_RDWR +#include // mmap +#include // strlen +#include // errno + +#define eprintf(args...) fprintf(stderr, ##args) + +const char *DEVICE_PATH = "/dev/my_shmem"; + +int main(int argc, char *argv[]) +{ + /* Have: + * - Different mm => different address space + * - Different virtual address + */ + void *addr = (void *) 0x10000000; + + const long PAGE_SIZE = sysconf(_SC_PAGESIZE); + if (PAGE_SIZE == -1) { + eprintf("Error retrieving page size: %d.\n", errno); + exit(EXIT_FAILURE); + } + + // open device file w/ RW perms + FILE *fp = fopen(DEVICE_PATH, "r+"); + if (!fp) { + eprintf("Error opening device %s: %d.\n", DEVICE_PATH, errno); + exit(EXIT_FAILURE); + } + int fd = fileno(fp); + if (fd == -1) { + eprintf("Error retrieving file descriptor: %d.\n", errno); + exit(EXIT_FAILURE); + } + + // mmap device + void *buf = mmap(addr, PAGE_SIZE * 2, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (!buf) { + eprintf("Error mmap-ing: %d.\n", errno); + exit(EXIT_FAILURE); + } + + // Write to mmap-ed device + char to_write[] = {0x88, 0x77, 0x66, 0x55, 0x00}; + memcpy(buf, to_write, strlen(to_write)); + + // Unmap device + munmap(buf, PAGE_SIZE * 2); + + // Close device + fclose(fp); + + printf("Finished!\n"); + exit(EXIT_SUCCESS); +} diff --git a/src/aarch64-linux-flush-dcache/userspace/userspace.c b/src/aarch64-linux-flush-dcache/userspace/writer_null.c similarity index 100% rename from src/aarch64-linux-flush-dcache/userspace/userspace.c rename to src/aarch64-linux-flush-dcache/userspace/writer_null.c