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: 119922 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1853480vqm; Thu, 13 Jul 2023 07:13:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlFD4qdZWfnpgiP1XBy1Md3cIq6/LmQCO0I0O52omEZFjBSpovwIsp13xyJgLZb108X+7Orf X-Received: by 2002:a05:6512:3d22:b0:4f8:5dd2:21f5 with SMTP id d34-20020a0565123d2200b004f85dd221f5mr1567675lfv.67.1689257583570; Thu, 13 Jul 2023 07:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689257583; cv=none; d=google.com; s=arc-20160816; b=kt9MbRa5BZwozjSXjc/3aonAau/PwMgkCRr2+c7sr//5fE5P8RzZpCAeZ1/GGm7RpN txZHmyL8Od8yJM9Y7WG4kY+5a9WHzHa0dFNsd9Ado/wbHZZtmlq7zq/FcRGW/pvfFave jsvRckDJ/DVKhuQoXxH4eGXj6kdqjw+gi9GThgDgyPsneO9W78CVQ7Xy7YbkX9Qu6KWB X6eN0wZeBRuE4es8wOq3dzTVLK0mLSkWEuSfZvlfCRl/K+XDgiYRpjwho01bhi2C1N5g QS//NxzXfcZjGWVZKIuVKAwz+lM/H4r2zoZWBBXEbqnmUCnDrzzhorGQQwyDO7cbg+UZ 2WlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=EOmj+hjrtgQIQSn4ZRGZjPSIqR/XjaDog302aSVz6lM=; fh=PBHZcfMfFxGGBVmDESRU6Gjyj3qxzeiTc8DMNv9diCw=; b=rclkK28TE5+XM7ivEZbKbloVF2OQ3NjFQJMycoedDpNA0i/ueGbopzCDs6UOlKgjmR fb6fK5q+kFU601Z6h0w6cVwYWtKw0LewjZ2VvwS5o2guW6VAIOlC8RaUAhz33s1W0Ajg IdkZb3KOo6s1U/K1auvNzvxUYvMjP3LAs9CBAvcEP+ZjuSOyGyzJP8ug5uo9QxJCQyK5 je1OurE9KKZnDlpCas/k2Lv1rYF6Erzjx43hR07zfEQImDiYfUoyKxuZrbJD9X7O/OS/ MlewLELjzJhALwH8d1BVJ+QkSIw/4aC/FN/iM9enJKXp9UffJoQlRZa1gHKTjOpkxQIj OEvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n22-20020a056402515600b0051e0fc05591si7083122edd.526.2023.07.13.07.12.39; Thu, 13 Jul 2023 07:13:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231905AbjGMNzE (ORCPT + 99 others); Thu, 13 Jul 2023 09:55:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231617AbjGMNy5 (ORCPT ); Thu, 13 Jul 2023 09:54:57 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E71781BB; Thu, 13 Jul 2023 06:54:55 -0700 (PDT) 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771314820006044300 X-GMAIL-MSGID: 1771314959824911884 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);