From patchwork Thu Jul 13 13:54:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13312255 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 401FFC001DF for ; Thu, 13 Jul 2023 13:55:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBD79900018; Thu, 13 Jul 2023 09:54:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C472090000B; Thu, 13 Jul 2023 09:54:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE8BE900018; Thu, 13 Jul 2023 09:54:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 91D1990000B for ; Thu, 13 Jul 2023 09:54:58 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 678CAB027F for ; Thu, 13 Jul 2023 13:54:58 +0000 (UTC) X-FDA: 81006734676.03.E233827 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf18.hostedemail.com (Postfix) with ESMTP id 7F8661C0025 for ; Thu, 13 Jul 2023 13:54:56 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf18.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689256496; a=rsa-sha256; cv=none; b=gtOcHIv0J+fMm54bnsAW5RVoNKYnUsdiWNZTTrE1JlH7YXu/yebS+oth8y2rPZI1vBWonP uoMtC8MLezm+H32ziiK0pTp7arFRyP/XJ2rViY5TTRO9o9Ih1AnuA2mnA2zq7OgXawAlx1 4EYo5HYckaCronTKi+FxRTpXMIKOEiw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf18.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689256496; 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; bh=EOmj+hjrtgQIQSn4ZRGZjPSIqR/XjaDog302aSVz6lM=; b=Fnzv9YCZZXn2p4NPg6DTSUdmQgKw+7uu+Jtu3k4jCOsRvHcb4WhfOpjlclZhY4UiMlHH03 dFUeNdfVFZgnCVAw5/dW2Qlm3MxrzmpwySY/PwlUCMxBQOz8LGO/WDVRT9jVwV+cLrpPu1 ChkCS8e2cryLGX2GtwWGrRzS4XZEBL4= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3B9D61570; Thu, 13 Jul 2023 06:55:38 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2F5A53F73F; Thu, 13 Jul 2023 06:54:54 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Shuah Khan , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , David Hildenbrand , Mark Brown , John Hubbard , Florent Revest , "Liam R. Howlett" Cc: Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 3/9] selftests/mm: Skip soft-dirty tests on arm64 Date: Thu, 13 Jul 2023 14:54:34 +0100 Message-Id: <20230713135440.3651409-4-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230713135440.3651409-1-ryan.roberts@arm.com> References: <20230713135440.3651409-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 7F8661C0025 X-Stat-Signature: tktnqp4daogq4hsky3yxx7pm6rhu4u45 X-Rspam-User: X-HE-Tag: 1689256496-229659 X-HE-Meta: U2FsdGVkX1+7AygCg/2rLkUxxwgaLnagiB7GQ7c6RJUQi5T1wh1UiqjyatzLNEHdTvjoGH6O46kJ2RkhZJuPvB2R6Mr+KijCExEmmo1XyCzldGyRzAPdMkD7aGwiyeT+z1nexqPCBcLKcTEO5psEfjP2ObN/QZjK4TDlRbRuG1vqTtV3mna/z+SGoWR5bYVi8PT2xa2WwOJt8wADrvGTvhRxaOI/o1hkQsvxyGHsZhrXVI8JfFcKjXrJejyQUqmMkLsrrrupirujzHqIHe/UOsbnU7TlyQrbpEmdojI2A9okI6b9laRxSdBthqijyp6Nxh61zBpu6kcTQVUYcph2updAPUfPpI2NCOPiUOt7e0tVZL9VxNJmfPFrBBfkINY2XAndYfxXMtSG1u/rLDZ0jkOjgzdujEe74a0s+y4pEVsJUH8M85LqehsuCNWHzdwDGy20n+X8C4+u6hbfT2ifjNU4ipfmHp77GerwYt4ZVWmZyfAZKr6Gairv+zouvCULw/y0v2A0XDge6TmJuGJgiRGOhCWoyj5L4MHMeeM+f+oDNETLo+krnXzPH0Rd0+YNftW0XuHUSDZhux/pEqslKo8YN7HYxKo7eGp67iG8r5ByX6expYUv613dmlW8Hu9uJQ2GZxIPt57rXYp2+LeYYYzEQ5I3EsdXtiFwEN/AJsNaJDcAqheTOzmw+ObiXj+VRsB7n/YMPc7zCoTNL4/DxozAimDBRmecRj4Ks8g4UF5nWg77JOp1frBUMg5X1RFTamyfHjyEP6WubNjt0pbnPoGlinFPy8W8hwPfEj0Y9rHgGpOLh0qPH91kMpmVTTPYd1s0TcZywEH86V532szdL1M0dN5s1DeE76wPsIU9U2xSzNwDSPYey7F+w7nUzEaQLFqLv9JlPHK+mh/oDRUEeuSSEBs2E1RFQmHtVUcg6pAywIapeOU4z8i/rdP14xdGzPgV7WaYB9CALWoYo2W 3/Kz4DE0 pfj9mckNovX8hepQM53meI+4hfH8rg9hvXB3ib4P7nd/gHz1TaOw/dl483DLeDSlhcWLg+8+AKR0r/213SdqHuF8N+EgUHumbev7lgvfl4a514vZjk+0MCcIg8gimaxc0PIhvVp5XogLj8h7qth83LwDm7+5cpperrCDv 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: arm64 does not support the soft-dirty PTE bit. However there are tests in `madv_populate` and `soft-dirty` which assume it is supported and cause spurious failures to be reported when preferred behaviour would be to mark the tests as skipped. Unfortunately, the only way to determine if the soft-dirty dirty bit is supported is to write to a page, then see if the bit is set in /proc/self/pagemap. But the tests that we want to conditionally execute are testing precicesly this. So if we introduced this feature check, we could accedentally turn a real failure (on a system that claims to support soft-dirty) into a skip. So instead, do the check based on architecture; for arm64, we report that soft-dirty is not supported. This is wrapped up into a utility function `system_has_softdirty()`, which is used to skip the whole `soft-dirty` suite, and mark the soft-dirty tests in the `madv_populate` suite as skipped. Signed-off-by: Ryan Roberts --- tools/testing/selftests/mm/madv_populate.c | 18 +++++++++++++----- tools/testing/selftests/mm/soft-dirty.c | 3 +++ tools/testing/selftests/mm/vm_util.c | 17 +++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 1 + 4 files changed, 34 insertions(+), 5 deletions(-) -- 2.25.1 diff --git a/tools/testing/selftests/mm/madv_populate.c b/tools/testing/selftests/mm/madv_populate.c index 60547245e479..5a8c176d7fec 100644 --- a/tools/testing/selftests/mm/madv_populate.c +++ b/tools/testing/selftests/mm/madv_populate.c @@ -232,6 +232,14 @@ static bool range_is_not_softdirty(char *start, ssize_t size) return ret; } +#define ksft_test_result_if_softdirty(cond, ...) \ +do { \ + if (system_has_softdirty()) \ + ksft_test_result(cond, __VA_ARGS__); \ + else \ + ksft_test_result_skip(__VA_ARGS__); \ +} while (0) + static void test_softdirty(void) { char *addr; @@ -246,19 +254,19 @@ static void test_softdirty(void) /* Clear any softdirty bits. */ clear_softdirty(); - ksft_test_result(range_is_not_softdirty(addr, SIZE), + ksft_test_result_if_softdirty(range_is_not_softdirty(addr, SIZE), "range is not softdirty\n"); /* Populating READ should set softdirty. */ ret = madvise(addr, SIZE, MADV_POPULATE_READ); - ksft_test_result(!ret, "MADV_POPULATE_READ\n"); - ksft_test_result(range_is_not_softdirty(addr, SIZE), + ksft_test_result_if_softdirty(!ret, "MADV_POPULATE_READ\n"); + ksft_test_result_if_softdirty(range_is_not_softdirty(addr, SIZE), "range is not softdirty\n"); /* Populating WRITE should set softdirty. */ ret = madvise(addr, SIZE, MADV_POPULATE_WRITE); - ksft_test_result(!ret, "MADV_POPULATE_WRITE\n"); - ksft_test_result(range_is_softdirty(addr, SIZE), + ksft_test_result_if_softdirty(!ret, "MADV_POPULATE_WRITE\n"); + ksft_test_result_if_softdirty(range_is_softdirty(addr, SIZE), "range is softdirty\n"); munmap(addr, SIZE); diff --git a/tools/testing/selftests/mm/soft-dirty.c b/tools/testing/selftests/mm/soft-dirty.c index cc5f144430d4..8a2cd161ec4d 100644 --- a/tools/testing/selftests/mm/soft-dirty.c +++ b/tools/testing/selftests/mm/soft-dirty.c @@ -192,6 +192,9 @@ int main(int argc, char **argv) int pagemap_fd; int pagesize; + if (!system_has_softdirty()) + return KSFT_SKIP; + ksft_print_header(); ksft_set_plan(15); diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 558c9cd8901c..f014fafbd2d3 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -53,6 +53,23 @@ unsigned long pagemap_get_pfn(int fd, char *start) return -1ul; } +int system_has_softdirty(void) +{ + /* + * There is no way to check if the kernel supports soft-dirty, other + * than by writing to a page and seeing if the bit was set. But the + * tests are intended to check that the bit gets set when it should, so + * doing that check would turn a potentially legitimate fail into a + * skip. Fortunately, we know for sure that arm64 does not support + * soft-dirty. So for now, let's just use the arch as a corse guide. + */ +#if defined(__aarch64__) + return 0; +#else + return 1; +#endif +} + void clear_softdirty(void) { int ret; diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index c7fa61f0dff8..5a57314d428a 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -36,6 +36,7 @@ bool pagemap_is_softdirty(int fd, char *start); bool pagemap_is_swapped(int fd, char *start); bool pagemap_is_populated(int fd, char *start); unsigned long pagemap_get_pfn(int fd, char *start); +int system_has_softdirty(void); void clear_softdirty(void); bool check_for_pattern(FILE *fp, const char *pattern, char *buf, size_t len); uint64_t read_pmd_pagesize(void);