From patchwork Thu Jun 27 17:08:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13714880 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DB48C2BD09 for ; Thu, 27 Jun 2024 17:09:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B97AC6B00A9; Thu, 27 Jun 2024 13:09:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B2BD96B00AA; Thu, 27 Jun 2024 13:09:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94E9F6B00AB; Thu, 27 Jun 2024 13:09:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 71C0B6B00A9 for ; Thu, 27 Jun 2024 13:09:29 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2F19540D03 for ; Thu, 27 Jun 2024 17:09:29 +0000 (UTC) X-FDA: 82277304858.18.A687DA2 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf22.hostedemail.com (Postfix) with ESMTP id ED92BC0011 for ; Thu, 27 Jun 2024 17:09:26 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UR7h+SFI; spf=pass (imf22.hostedemail.com: domain of andrii@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719508159; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YE47zTswLtVm2nHY1MKC88+b4jDA3vOIJ0oDH/6LR9U=; b=USfkGCgYHLTn1kgRkP3qt0cIdes3NemzbCS3WxLCGC313P4sAv69hobR+NC+jF8pXVM/6i fime2HVb8JF0+sLpqPNLVTxOc9F/LXqIoF2J/SqhqdxQ9aoqOQG+WximAgErojqds6aEYP fQPJB3SUJhG1NY6aY6hWV8bUwCSAMbc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UR7h+SFI; spf=pass (imf22.hostedemail.com: domain of andrii@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719508159; a=rsa-sha256; cv=none; b=Ze+tOiePgq0lBjShjcdVv96e6CpiNv8vh9X3yDVkocTYUQyGYwcP++zxg+fEAkixfoCFGj YSu4M4RQ+kFniqsmNl0N/ayaxApg/rqiBmLm8L3eEnD28ESa++g7tE/3yOT1BdfW7cyki/ 3Ufh91p78CcVpnn3Bprvy/NMvGvTVWg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 19ED1CE3377; Thu, 27 Jun 2024 17:09:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BC84C2BBFC; Thu, 27 Jun 2024 17:09:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719508163; bh=UCwCLJEQqsSSL94rfskjH98zL7sdkNEm83V+CMuhWVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UR7h+SFIAeDssN9Yd1k3TBkGRgLtfj2sQPBGN2OlUxlh1q1ZxiDntpTkFtxOhtyZV 2qE5ePOJvfOKb6ER6fIAlKaVrHzMj81EfOw6Ciyox+OgZZV+F29CRbykU+ttAhN/1F fwID8x9Mk1rlmwGxemy51dhDUSQhCk28NlJfqIWHQhAUN386ENUEO3PDWyhHvaSXJg A2fbh3K86f5J1fBgTvckpafBZ9pC0Z5E9sykAFddIECSazhNuE/GP1S8yRw/c/Gktx sQC5EdEQ7PzLd+4Sm53UHpyhO5DXZEfKHpqaMqJfjc5varHjIGprsSNMK/Pmb6wrt/ 70GdVpHmM1jTw== From: Andrii Nakryiko To: linux-fsdevel@vger.kernel.org, brauner@kernel.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, gregkh@linuxfoundation.org, linux-mm@kvack.org, liam.howlett@oracle.com, surenb@google.com, rppt@kernel.org, adobriyan@gmail.com, Andrii Nakryiko Subject: [PATCH v6 6/6] selftests/proc: add PROCMAP_QUERY ioctl tests Date: Thu, 27 Jun 2024 10:08:58 -0700 Message-ID: <20240627170900.1672542-7-andrii@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240627170900.1672542-1-andrii@kernel.org> References: <20240627170900.1672542-1-andrii@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: ED92BC0011 X-Stat-Signature: 5i6dcxrbaefaku47qb34p7au6z1f7e31 X-HE-Tag: 1719508166-200911 X-HE-Meta: U2FsdGVkX1+XkhWBTobFvNYBarwnBJGU5YI4Ndkug1bPTLXXtuv10WXsphc6oKwlplPrL81dUyfZot/qe4cgHDYU7xDLL7ezBjqCtnJZxmI3q9qEmPcy2HCql22tpyLEwkElDA+2OAJucbMZObebnjsQl46dtvA0Xz9UmebCsiDg3r+nI2lpmKBna6l7CSxT+6uGLo/yPxevwRp+NVNkBf0blzmxVLKmQgEYThQpLekPNb3hUc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-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Extend existing proc-pid-vm.c tests with PROCMAP_QUERY ioctl() API. Test a few successful and negative cases, validating querying filtering and exact vs next VMA logic works as expected. Signed-off-by: Andrii Nakryiko --- tools/testing/selftests/proc/Makefile | 1 + tools/testing/selftests/proc/proc-pid-vm.c | 86 ++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/tools/testing/selftests/proc/Makefile b/tools/testing/selftests/proc/Makefile index cd95369254c0..291e7087f1b3 100644 --- a/tools/testing/selftests/proc/Makefile +++ b/tools/testing/selftests/proc/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only CFLAGS += -Wall -O2 -Wno-unused-function CFLAGS += -D_GNU_SOURCE +CFLAGS += $(TOOLS_INCLUDES) LDFLAGS += -pthread TEST_GEN_PROGS := diff --git a/tools/testing/selftests/proc/proc-pid-vm.c b/tools/testing/selftests/proc/proc-pid-vm.c index cacbd2a4aec9..d04685771952 100644 --- a/tools/testing/selftests/proc/proc-pid-vm.c +++ b/tools/testing/selftests/proc/proc-pid-vm.c @@ -45,6 +45,7 @@ #include #include #include +#include #include "../kselftest.h" @@ -492,6 +493,91 @@ int main(void) assert(buf[13] == '\n'); } + /* Test PROCMAP_QUERY ioctl() for /proc/$PID/maps */ + { + char path_buf[256], exp_path_buf[256]; + struct procmap_query q; + int fd, err; + + snprintf(path_buf, sizeof(path_buf), "/proc/%u/maps", pid); + fd = open(path_buf, O_RDONLY); + if (fd == -1) + return 1; + + /* CASE 1: exact MATCH at VADDR */ + memset(&q, 0, sizeof(q)); + q.size = sizeof(q); + q.query_addr = VADDR; + q.query_flags = 0; + q.vma_name_addr = (__u64)(unsigned long)path_buf; + q.vma_name_size = sizeof(path_buf); + + err = ioctl(fd, PROCMAP_QUERY, &q); + assert(err == 0); + + assert(q.query_addr == VADDR); + assert(q.query_flags == 0); + + assert(q.vma_flags == (PROCMAP_QUERY_VMA_READABLE | PROCMAP_QUERY_VMA_EXECUTABLE)); + assert(q.vma_start == VADDR); + assert(q.vma_end == VADDR + PAGE_SIZE); + assert(q.vma_page_size == PAGE_SIZE); + + assert(q.vma_offset == 0); + assert(q.inode == st.st_ino); + assert(q.dev_major == MAJOR(st.st_dev)); + assert(q.dev_minor == MINOR(st.st_dev)); + + snprintf(exp_path_buf, sizeof(exp_path_buf), + "/tmp/#%llu (deleted)", (unsigned long long)st.st_ino); + assert(q.vma_name_size == strlen(exp_path_buf) + 1); + assert(strcmp(path_buf, exp_path_buf) == 0); + + /* CASE 2: NO MATCH at VADDR-1 */ + memset(&q, 0, sizeof(q)); + q.size = sizeof(q); + q.query_addr = VADDR - 1; + q.query_flags = 0; /* exact match */ + + err = ioctl(fd, PROCMAP_QUERY, &q); + err = err < 0 ? -errno : 0; + assert(err == -ENOENT); + + /* CASE 3: MATCH COVERING_OR_NEXT_VMA at VADDR - 1 */ + memset(&q, 0, sizeof(q)); + q.size = sizeof(q); + q.query_addr = VADDR - 1; + q.query_flags = PROCMAP_QUERY_COVERING_OR_NEXT_VMA; + + err = ioctl(fd, PROCMAP_QUERY, &q); + assert(err == 0); + + assert(q.query_addr == VADDR - 1); + assert(q.query_flags == PROCMAP_QUERY_COVERING_OR_NEXT_VMA); + assert(q.vma_start == VADDR); + assert(q.vma_end == VADDR + PAGE_SIZE); + + /* CASE 4: NO MATCH at VADDR + PAGE_SIZE */ + memset(&q, 0, sizeof(q)); + q.size = sizeof(q); + q.query_addr = VADDR + PAGE_SIZE; /* point right after the VMA */ + q.query_flags = PROCMAP_QUERY_COVERING_OR_NEXT_VMA; + + err = ioctl(fd, PROCMAP_QUERY, &q); + err = err < 0 ? -errno : 0; + assert(err == -ENOENT); + + /* CASE 5: NO MATCH WRITABLE at VADDR */ + memset(&q, 0, sizeof(q)); + q.size = sizeof(q); + q.query_addr = VADDR; + q.query_flags = PROCMAP_QUERY_VMA_WRITABLE; + + err = ioctl(fd, PROCMAP_QUERY, &q); + err = err < 0 ? -errno : 0; + assert(err == -ENOENT); + } + return 0; } #else