From patchwork Tue Jun 18 22:45:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13703116 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 20205C2BA1A for ; Tue, 18 Jun 2024 22:45:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB7BA8D006F; Tue, 18 Jun 2024 18:45:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C640B8D0066; Tue, 18 Jun 2024 18:45:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB5488D006F; Tue, 18 Jun 2024 18:45:54 -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 8A4928D0066 for ; Tue, 18 Jun 2024 18:45:54 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 37A52C0B87 for ; Tue, 18 Jun 2024 22:45:54 +0000 (UTC) X-FDA: 82245493428.07.2E3B56A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 8FF301A000C for ; Tue, 18 Jun 2024 22:45:52 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=USfw6ppf; spf=pass (imf19.hostedemail.com: domain of andrii@kernel.org designates 139.178.84.217 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=1718750745; 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=4DLq9ym8WANs9W6MLuX03O5TPNH40reqTftu7FsAGddAANROYNAd7Zn2Dyj5uhyREflal6 Xxh9lkRkDPkd4G8aDknwPLqTnVMVIgqtIKWYdeqK7PrAbgu9q745dHNnb7hZxCAmX4D0AP z5g/1I2ekMgTsJuiKIocp0ZGyYQyP8Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718750745; a=rsa-sha256; cv=none; b=MbGTjdXOz8zk9nEvU+kPGpDWF2wVSsvNgIh5J1bZZMuVEioz0nXjij6Eml6eZaHq/Rxlxu +wrhtYkZnhG9NgtzHPwnrwhWy5p0QABJUKm+vFfsPEt/hAjLf/BEGremcNOrwZlDn1B+GN PyPZa1la/UBJhPas2J3YvB58tziVV4s= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=USfw6ppf; spf=pass (imf19.hostedemail.com: domain of andrii@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D2A1760EE1; Tue, 18 Jun 2024 22:45:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CAA0C3277B; Tue, 18 Jun 2024 22:45:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718750751; bh=UCwCLJEQqsSSL94rfskjH98zL7sdkNEm83V+CMuhWVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=USfw6ppfGIjNUTiuavW9dQC8gfdnNBuEaUjuH/boEbWAouvqA3H6Wij7krpHmGNjC gFDbQ13curSzlczjnfuHUlD1TM306vNjGcxfV2V10HLNBVss6k/MCUKnjYKlmXDuON IQsQ9pFnpwA3IqgqkaSdVsY6wPQGCzB8k8qyHMXveWyJ1SwN2hDeHQUdXoGry/fvS5 lZy97mchtRRMq1GBPVdaqyzENuy98w3ghDMHpdGNI7xsLBcJ+KB8YxEfldj3osaGVe qydpeVPPVt6f+MFriHe+gnjhGGypCqe4K5KMGNLMfo5kV2Idw1eEbXm1AMNFOBhD56 VkoHkjzIyXVbg== 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 v5 6/6] selftests/proc: add PROCMAP_QUERY ioctl tests Date: Tue, 18 Jun 2024 15:45:25 -0700 Message-ID: <20240618224527.3685213-7-andrii@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240618224527.3685213-1-andrii@kernel.org> References: <20240618224527.3685213-1-andrii@kernel.org> MIME-Version: 1.0 X-Stat-Signature: 75y6f5fdjdcz1bauskfe6ob47k76d14m X-Rspamd-Queue-Id: 8FF301A000C X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1718750752-42831 X-HE-Meta: U2FsdGVkX18tW6HqDzngYHS3ijrH5Dx927FZGIcJWC8oxyJF+P4Q/8vuYjX8KA2zq/4irYcqQbluWXHiUBiUKG+b/ecnwMyCz9xcbfT1AcEVFQsKKGm/ZxNs3WrsbCZSLLvlo2nKqc8ZdpzlhnRBae+76Q5JcYRPZdhfl+CDpQqfzcy9lC+cYO4feg19/WqKszoIs8o/E7JpCR0GUfLyjL2djlpyicFLn9X7uOCaX1sX80x6TE2QKz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2.4 Sender: owner-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