mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
synced 2026-04-25 00:52:45 -04:00
tools/testing: add PROCMAP_QUERY helper functions in mm self tests
The PROCMAP_QUERY ioctl() is very useful - it allows for binary access to /proc/$pid/[s]maps data and thus convenient lookup of data contained there. This patch exposes this for convenient use by mm self tests so the state of VMAs can easily be queried. Link: https://lkml.kernel.org/r/ce83d877093d1fc594762cf4b82f0c27963030ee.1744104124.git.lorenzo.stoakes@oracle.com Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com> Reviewed-by: Wei Yang <richard.weiyang@gmail.com> Cc: David Hildenbrand <david@redhat.com> Cc: Jann Horn <jannh@google.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Rik van Riel <riel@surriel.com> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
879bca0a2c
commit
bd23f293a0
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <inttypes.h>
|
||||
@@ -424,3 +425,64 @@ bool check_vmflag_io(void *addr)
|
||||
flags += flaglen;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Open an fd at /proc/$pid/maps and configure procmap_out ready for
|
||||
* PROCMAP_QUERY query. Returns 0 on success, or an error code otherwise.
|
||||
*/
|
||||
int open_procmap(pid_t pid, struct procmap_fd *procmap_out)
|
||||
{
|
||||
char path[256];
|
||||
int ret = 0;
|
||||
|
||||
memset(procmap_out, '\0', sizeof(*procmap_out));
|
||||
sprintf(path, "/proc/%d/maps", pid);
|
||||
procmap_out->query.size = sizeof(procmap_out->query);
|
||||
procmap_out->fd = open(path, O_RDONLY);
|
||||
if (procmap_out < 0)
|
||||
ret = -errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Perform PROCMAP_QUERY. Returns 0 on success, or an error code otherwise. */
|
||||
int query_procmap(struct procmap_fd *procmap)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (ioctl(procmap->fd, PROCMAP_QUERY, &procmap->query) == -1)
|
||||
ret = -errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to find the VMA at specified address, returns true if found, false if not
|
||||
* found, and the test is failed if any other error occurs.
|
||||
*
|
||||
* On success, procmap->query is populated with the results.
|
||||
*/
|
||||
bool find_vma_procmap(struct procmap_fd *procmap, void *address)
|
||||
{
|
||||
int err;
|
||||
|
||||
procmap->query.query_flags = 0;
|
||||
procmap->query.query_addr = (unsigned long)address;
|
||||
err = query_procmap(procmap);
|
||||
if (!err)
|
||||
return true;
|
||||
|
||||
if (err != -ENOENT)
|
||||
ksft_exit_fail_msg("%s: Error %d on ioctl(PROCMAP_QUERY)\n",
|
||||
__func__, err);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Close fd used by PROCMAP_QUERY mechanism. Returns 0 on success, or an error
|
||||
* code otherwise.
|
||||
*/
|
||||
int close_procmap(struct procmap_fd *procmap)
|
||||
{
|
||||
return close(procmap->fd);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user