From patchwork Mon Jan 13 13:15:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13937336 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 7B3FBE7719F for ; Mon, 13 Jan 2025 13:17:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 18ABC6B00A0; Mon, 13 Jan 2025 08:17:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 04E116B00A2; Mon, 13 Jan 2025 08:17:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0DF16B00A1; Mon, 13 Jan 2025 08:17:16 -0500 (EST) 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 9647C6B00A0 for ; Mon, 13 Jan 2025 08:17:16 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4B57DADB60 for ; Mon, 13 Jan 2025 13:17:16 +0000 (UTC) X-FDA: 83002479672.07.9B9E03C Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf05.hostedemail.com (Postfix) with ESMTP id 60F4E10000A for ; Mon, 13 Jan 2025 13:17:14 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=JC9KfFs9; dkim=pass header.d=linutronix.de header.s=2020e header.b=akBV3Alj; spf=pass (imf05.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736774234; a=rsa-sha256; cv=none; b=mVZkiU7HKDi/C94tMFRjjClFzMq6AgXkYcN6rGONQMUgKnQ3yZHef6kMpH2VTBGdqz42DH zHAOuzsL6gdk7+Hwb3f6Jc04jZId5YyhDSpC8fx4aqHUJubr3+N/yNrxAWzS9kcFWPZ6kn NphLS6tg/jXaLyWarSBtD1fBIkbrOiU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=JC9KfFs9; dkim=pass header.d=linutronix.de header.s=2020e header.b=akBV3Alj; spf=pass (imf05.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736774234; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/blv4n22o4xwWzbzoYSZD2Qy5uJLVnQWfTrkFwx7l5I=; b=J5y5vNa3Au+gjYzK9x5Y9rzHzLSQjF+bF5QHYLAY6akd+mUA4uJQiZvfUeuITfOvebZJFR JeNzNOSNpWn+m2fl6qkksqljGWqhepUcVSn31zsdE/mTxHGHJTz5/Iedl8BTGBnhu2JdR5 rYwjtybHg+GrIlX2tsPeyKfmxTEJ8HM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736774232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/blv4n22o4xwWzbzoYSZD2Qy5uJLVnQWfTrkFwx7l5I=; b=JC9KfFs9JRXBreQf5tTCEIA1Ao/60W8ETgVULszb5IjAOS4XhzBsmguV0z4dqb+hhlDY31 ygcP4IHPscYdJkrpg4+LBOops94w8k6dI0FAJbVjF3w8M6KpOKt0DEyLu134egeSa7C2Df JHtRsIGBWHFvVUc0PKV5eTwoMgtldEQd/QqgoGI5SorvLXZbOKkyz7mLm7n+VsYBEKV9O5 84IN+p2CW6y1mKNX/bIXA/oKP9wWIIXVt+vJt6RCTA93NqX3a7jktamava233cQXNmtIyy AbXRuaVGSoytzsRu/kbfim8TpJLI06qRngTzJaXqf6nt+aa0NjzfB3AAkafHxg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736774232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/blv4n22o4xwWzbzoYSZD2Qy5uJLVnQWfTrkFwx7l5I=; b=akBV3AljlG0D1RueAA+llky0t1bUlT/ReAoBYz+3tA96RoxFhJdo/Ej4ttqRYBFASO9Vom JOqtMbCEWhwUxsCw== Date: Mon, 13 Jan 2025 14:15:37 +0100 Subject: [PATCH v3 3/4] selftests/mm: vm_util: Split up /proc/self/smaps parsing MIME-Version: 1.0 Message-Id: <20250113-virtual_address_range-tests-v3-3-f4a8e6b7feed@linutronix.de> References: <20250113-virtual_address_range-tests-v3-0-f4a8e6b7feed@linutronix.de> In-Reply-To: <20250113-virtual_address_range-tests-v3-0-f4a8e6b7feed@linutronix.de> To: Andrew Morton , Shuah Khan , Dev Jain , Thomas Gleixner , David Hildenbrand Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1736774229; l=2860; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=6BHmjOZjGkeOAxEqViu35ESnPzRfjS5CZ+5Ol52x1DA=; b=kpnruwzlgMo/dc08nb/9iPLsVW71YnBKUlSIi/oNgq/lXX5w4hmH5bzGI8CKBfFvq82kX/ZME L/MltRi86xRCLZc6e+9DcqmU/KPMVlsaDy6rFzqC8ID23MLQyvGI34P X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Rspamd-Queue-Id: 60F4E10000A X-Stat-Signature: u3x3homyhd8mu4roq66k3ygpbha7w71q X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1736774234-496595 X-HE-Meta: U2FsdGVkX19pE4AVL6xu1pol0G6RjuuIr0obT3sE2rp2XhhychzeegzZfdmRiHvyXDaoV5fJDAkQUukNJznrAYT4sz/vtdCbS73AL2sJZdBIQ4i69jOo2SNwzvN5KKB6tAYI/0gn3aRdnOmigs2sPCieybey4DfnbWXCsNz/5kfuj8IdNC8fQMyJjSQ+aXbZMiiVJp1J+izb8La8DB0UNSNjvirKIt5ZQZhqCyvIEZ04YKNWU4RTpxV0f1pgnIG+zvOFGo+WTKaqlXqi9kFHp5bmeKJaMNbp6t2S6vW42XkgQZ16puEHLZnBMnFQI/3E0lK8L7G5dyRD2DTGUtmS/Kk7FV+/U9TSRsScp81fvFVAc78448lme7ktRn0Qj7fg7pQPHCt1LR0QZ0yXMwAFFjIB+WZNw+UGtm7sahCdmPS5O1ozZohgxhyUVr6Ymq7h0ZNW95eBc2T1hXphJ+lvgEh8Z0VNz80PAGA6i967OGu8iTffc6aILQkisPp1FJOphma6yYy7P1K0PfrBXH/uzLuKqY1evfUC44VNCYdS60XoFk3yRxRLqlOU1P6LrQrq6b9We4KvWan+KAL0tyRy1M1Vn9cd55DPZYPqfBWDmAay/7gzeO7ZPbjUkOYtnVtfTwfTKaca82cM6onqiEpU3H5DOD1NN3Wxvms23qpw+7cKTfY4/tqZlklShEMW0BJtJEjBSDGDplxDH5Wmf8/TYpSqH2Eh/zh2dakkX5oeOQH2MV6dtG8voB01jqt5L60BSL3Sw7vy7FX9YRnn6qnO1eLzIhaf0ugDpbgA0yf0mtXsr6Odkg3gVH/hNknctt/RRtnWTSOv8D/XMaHc3MY1dgmO/j2wgi6g8hFR2egsNMWuUdtWhpM+rQ+sg4DMDS9pMA7enaIDaUydrp8vn5bEE/Tgdnjm8Jw3p2Riv7iNV5PVeoMa7NV1mFeyQRiIaMN9HVQmRRz9ajsoMN9zL4i DSZMWPQm g2Wq4S6NluZV4KNpY+uwhB8M/V4UvCMia3liMxiL4LLK6QP1+/mW2CFVh2L2Vtu64nM3Icgg+STlSXDfctcFP6axCUSnEU/IgzE61sDtbYLISSjHzP95zL8LWh9sa0ZTVBncG5/12DM8VbLIzyjp5OEXc+byxIEwJL/5oGYE0bFPKMU3YskIaxMTw8wNguyR7hwAVRG9gYE3rfa4dq0QJY6SjwyibQ1GmhCip56731KFrwRacziEB/0xvv7V9CeclD8fEaB8sc38htEdyzNU0kYTS6DcozHk5iLQ+ZP55/wnIkc/Jolxp0w2fmNByZLcX20IHHY0WAcFCYln4MXN3zfwQGM7ZNJjN5Twi9yfbRlKR76jNJdTpJI38Qe8hWkLwsen/vGXgC1qlqzoVmL/khb/gbS2NwIKEMiY9vlECOqRrvEuzWATAk9snPPBMJ6NZ9ARk X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Upcoming changes want to reuse the /proc/self/smaps parsing logic to parse the VmFlags field. As that works differently from the currently parsed HugePage counters, split up the logic so common functionality can be shared. While reworking this code, also use the correct sscanf placeholder for the "uint64_t thp" variable. Signed-off-by: Thomas Weißschuh Acked-by: David Hildenbrand --- tools/testing/selftests/mm/vm_util.c | 42 +++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index d8d0cf04bb57fd22bd7748fffec6a23c3103e35c..8468a19d6acca10c7e9228c03a935cdeb2402b5d 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -193,13 +194,11 @@ unsigned long rss_anon(void) return rss_anon; } -bool __check_huge(void *addr, char *pattern, int nr_hpages, - uint64_t hpage_size) +char *__get_smap_entry(void *addr, const char *pattern, char *buf, size_t len) { - uint64_t thp = -1; int ret; FILE *fp; - char buffer[MAX_LINE_LENGTH]; + char *entry; char addr_pattern[MAX_LINE_LENGTH]; ret = snprintf(addr_pattern, MAX_LINE_LENGTH, "%08lx-", @@ -211,23 +210,40 @@ bool __check_huge(void *addr, char *pattern, int nr_hpages, if (!fp) ksft_exit_fail_msg("%s: Failed to open file %s\n", __func__, SMAP_FILE_PATH); - if (!check_for_pattern(fp, addr_pattern, buffer, sizeof(buffer))) + if (!check_for_pattern(fp, addr_pattern, buf, len)) goto err_out; - /* - * Fetch the pattern in the same block and check the number of - * hugepages. - */ - if (!check_for_pattern(fp, pattern, buffer, sizeof(buffer))) + /* Fetch the pattern in the same block */ + if (!check_for_pattern(fp, pattern, buf, len)) goto err_out; - snprintf(addr_pattern, MAX_LINE_LENGTH, "%s%%9ld kB", pattern); + /* Trim trailing newline */ + entry = strchr(buf, '\n'); + if (entry) + *entry = '\0'; - if (sscanf(buffer, addr_pattern, &thp) != 1) - ksft_exit_fail_msg("Reading smap error\n"); + entry = buf + strlen(pattern); err_out: fclose(fp); + return entry; +} + +bool __check_huge(void *addr, char *pattern, int nr_hpages, + uint64_t hpage_size) +{ + char buffer[MAX_LINE_LENGTH]; + uint64_t thp = -1; + char *entry; + + entry = __get_smap_entry(addr, pattern, buffer, sizeof(buffer)); + if (!entry) + goto err_out; + + if (sscanf(entry, "%9" SCNu64 " kB", &thp) != 1) + ksft_exit_fail_msg("Reading smap error\n"); + +err_out: return thp == (nr_hpages * (hpage_size >> 10)); }