Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2432179rdf; Mon, 6 Nov 2023 14:11:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVBNdtGv345Uky+ZjfAxamkazoFWkpAHGiVmIrGw6AKCdJ2rzMm5fKs+w2XZ+CzLsNPVXJ X-Received: by 2002:a17:903:41ca:b0:1cc:4a66:7db3 with SMTP id u10-20020a17090341ca00b001cc4a667db3mr1095363ple.4.1699308667211; Mon, 06 Nov 2023 14:11:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699308667; cv=none; d=google.com; s=arc-20160816; b=y+CBekZgoX3n9N1n6p8VliuuC42ikS7BdVKo7tHQunshFh/BbJKOR+X8Z8OxLm7agB FCOILw//mEp6/Go220AvJ/SrRTZz++9MOfdwaPwdF9PPK9xkzDgECs62WJ70/cvyskee nsvhxuhoVVN+hk+sJ69lHj72qXTAKdbUE6qjkVl+vYSHWF2pTRde3ntC72B35dgsSu9O FexDd9KkjuLMTL9FtlYNwgSlM8pvhHBux2xTu8bcS7loINBv3P8+RMBLCqPTM7Td1mVB ARKQXokTmf9lNt8SssgFsp9+pYO958vsBs6aCz7zcKe3mjiwfYjP7Ai6wPr/p//L15Wq aocg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=V+0IXrXyLnBASTyaRkaW02XkIlMLQTt/pd2sX4XzHqI=; fh=3ymJ9mlOCdojR6Bm4vWHpij7Jp94gvsUwmvvD68L634=; b=Ov1VFbYCr/fI9x7DtrKbbIJVhWCBIA44zMSs1Y8C39cPMudSeAJ2bE7yNKUFyc+7A1 pZcS1V+IEX6MOAU0QZRrhd0wR4x2hXVm3UPElqkR6ZNmQPuiLvoMQe0p9EVyQ6UfYaCj 1pgeKnzlq57vqV1Eu1dq8SOn7sVPRiikHRQWULSPHtj0uJWo6Lzo1rQB+/5hPNnWO5re lzq1gDf0box98S2OTdCGkYiKy17PH0XCV8rLCtka3bXOW+ZGaF5ssTl3PgCwlRDjJRi1 3JDg8S95izwXTpe/LXG1OWPwqF9SnoCTC14eWXBg5H2A4ghgXOE3qHF2NjXLYRHAMeZ+ tebw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RTeZZBV5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id b17-20020a170902d51100b001cc54202425si9773876plg.409.2023.11.06.14.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:11:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RTeZZBV5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id BF959807833D; Mon, 6 Nov 2023 14:11:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233270AbjKFWKL (ORCPT + 99 others); Mon, 6 Nov 2023 17:10:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233257AbjKFWKJ (ORCPT ); Mon, 6 Nov 2023 17:10:09 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7022D57 for ; Mon, 6 Nov 2023 14:10:05 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-5b99999614bso3033114a12.0 for ; Mon, 06 Nov 2023 14:10:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699308605; x=1699913405; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=V+0IXrXyLnBASTyaRkaW02XkIlMLQTt/pd2sX4XzHqI=; b=RTeZZBV5KJMi88V1yakPqTgIZp7zvggW6cNAw9k/H1v5/O7/3cUrpjfRuKn8VGjqWy W7XlpJPN+1LrvsKN1uP7QkS0k//P5RKsbBdklqoGXE8dcrpxuRoDGNvq+8aAtz7ECfM+ JekPvFyBxgzXeFNXwm2xnMPuD9cs0AFKr61ZaTZIfWr/PMPRZzB1AkSB+EcXxT/smY+I B/K9S4SugkuESDXm74EMxqO7oxX8ol2oMdE4g48J6zSuTwrLJazY5jhtV70I2dd7fYE6 0OCz+c4OcPPzjTU2/Qu+1F00Hekf8sbmbR3/kHGJfSPgTup0Nw1V0hg+4/bAS5TsnzkZ 6psQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308605; x=1699913405; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=V+0IXrXyLnBASTyaRkaW02XkIlMLQTt/pd2sX4XzHqI=; b=NAh59NyCqG4bf8raVjDADpix5JqZ+KJyvXiJTVIvo1XE+2eecgxCXbBucbf0TNyNkr iO6LeOZhsAVV0CFDKi38fKCeeYVIFKql5YnND01XVOTf3bLpYt4aaDWv7LJIP2hItsWY NtwvBZK9sFJRmVfW7Emqzj9e/I5lP4jKFSkw72olKvTKZVatj5kkZVUxUNOPoedmJ1c0 sqah+XvoRAmpFZsjC1S/cdSqMZFLvSL8lP/tmNTuQxykR0kTb8n6jcLua7UMg4fbNub9 TmdI4YXIBAbDujK2rFqC0RF3sKzCW5p1o6GpJ+5XyDPxICFJvjCCzihpj/jsNG0txWqB dr0g== X-Gm-Message-State: AOJu0YyEkDHWpDt+0orczzFuJwaGA8IlA7qHMrwqfKwcrDe04Qf4oVTj afHN4IcTL9ZfeJ9aoF/p/qmkKaDw38U= X-Received: from avagin.kir.corp.google.com ([2620:0:1008:10:b187:459d:af36:db4c]) (user=avagin job=sendgmr) by 2002:a63:7018:0:b0:589:8df1:7eb1 with SMTP id l24-20020a637018000000b005898df17eb1mr537436pgc.4.1699308605331; Mon, 06 Nov 2023 14:10:05 -0800 (PST) Date: Mon, 6 Nov 2023 14:09:59 -0800 In-Reply-To: <20231106220959.296568-1-avagin@google.com> Mime-Version: 1.0 References: <20231106220959.296568-1-avagin@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231106220959.296568-2-avagin@google.com> Subject: [PATCH 2/2] selftests/mm: check that PAGEMAP_SCAN returns correct categories From: Andrei Vagin To: Andrew Morton , Muhammad Usama Anjum Cc: linux-kernel@vger.kernel.org, Andrei Vagin Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 06 Nov 2023 14:11:04 -0800 (PST) Right now, tests read page flags from /proc/pid/pagemap files. With this change, tests will check that PAGEMAP_SCAN return correct information too. Signed-off-by: Andrei Vagin --- tools/testing/selftests/mm/vm_util.c | 53 ++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 3082b40492dd..ec3478b96e4c 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include "../kselftest.h" @@ -28,19 +29,65 @@ uint64_t pagemap_get_entry(int fd, char *start) return entry; } +static uint64_t pagemap_scan_get_categories(int fd, char *start) +{ + struct pm_scan_arg arg; + struct page_region r; + long ret; + + arg.start = (uintptr_t)start; + arg.end = (uintptr_t)(start + psize()); + arg.vec = (uintptr_t)&r; + arg.vec_len = 1; + arg.flags = 0; + arg.size = sizeof(struct pm_scan_arg); + arg.max_pages = 0; + arg.category_inverted = 0; + arg.category_mask = 0; + arg.category_anyof_mask = PAGE_IS_WPALLOWED | PAGE_IS_WRITTEN | PAGE_IS_FILE | + PAGE_IS_PRESENT | PAGE_IS_SWAPPED | PAGE_IS_PFNZERO | + PAGE_IS_HUGE | PAGE_IS_SOFT_DIRTY; + arg.return_mask = arg.category_anyof_mask; + + ret = ioctl(fd, PAGEMAP_SCAN, &arg); + if (ret < 0) + ksft_exit_fail_msg("PAGEMAP_SCAN failed: %s\n", strerror(errno)); + if (ret == 0) + return 0; + return r.categories; +} + +static bool page_entry_is(int fd, char *start, char *desc, + uint64_t pagemap_flags, uint64_t pagescan_flags) +{ + bool m, s; + + m = pagemap_get_entry(fd, start) & pagemap_flags; + s = pagemap_scan_get_categories(fd, start) & pagescan_flags; + if (m == s) + return m; + + ksft_exit_fail_msg( + "read and ioctl return unmatched results for %s: %d %d", desc, m, s); + return m; +} + bool pagemap_is_softdirty(int fd, char *start) { - return pagemap_get_entry(fd, start) & PM_SOFT_DIRTY; + return page_entry_is(fd, start, "soft-dirty", + PM_SOFT_DIRTY, PAGE_IS_SOFT_DIRTY); } bool pagemap_is_swapped(int fd, char *start) { - return pagemap_get_entry(fd, start) & PM_SWAP; + return page_entry_is(fd, start, "swap", PM_SWAP, PAGE_IS_SWAPPED); } bool pagemap_is_populated(int fd, char *start) { - return pagemap_get_entry(fd, start) & (PM_PRESENT | PM_SWAP); + return page_entry_is(fd, start, "populated", + PM_PRESENT | PM_SWAP, + PAGE_IS_PRESENT | PAGE_IS_SWAPPED); } unsigned long pagemap_get_pfn(int fd, char *start) -- 2.42.0.869.gea05f2083d-goog