From patchwork Thu Mar 30 16:08:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13194502 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 79E2DC6FD1D for ; Thu, 30 Mar 2023 16:08:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17336900004; Thu, 30 Mar 2023 12:08:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 122636B009C; Thu, 30 Mar 2023 12:08:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F04E3900004; Thu, 30 Mar 2023 12:08:23 -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 DECE26B009B for ; Thu, 30 Mar 2023 12:08:23 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A3C0E1C66CB for ; Thu, 30 Mar 2023 16:08:23 +0000 (UTC) X-FDA: 80626046886.17.A5F038F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 29710120027 for ; Thu, 30 Mar 2023 16:08:20 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UYmtNtjR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192501; 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=fazvJ2yoVQ3FbqTtLeeKqsLvxYRtSAddCup9lQnAU9I=; b=QAlmUEOfG4TJWOFFUfNqFlrgaA4vTrgTaSF/4egNWGu63GSQZZHcRjhNDcIiBQ+IICtJSv 8sABaN4VQztkkk8OYQyWoT+mr7QjdSh2kEBuLeEujFKt7+DgM9IrDCKFkpQ4CQ8NBWy5Xv 0RIn+jqxP75rIEr62Hq1TmwQFVEyc6o= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UYmtNtjR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192501; a=rsa-sha256; cv=none; b=evB42I8cdvD0E3eaETZyLYvz/P4Q26A+EMlBFjbisrEk3NrpnCfBGvSHcZi5L3ajTJTICM x3iGGwwIFDkS95Gw3gVSPadhcv40Zag1AnK8ZXQKB+Hpu5Oc3fmD62oFki7PGLH0LKpSBb nlTJLdQDAZCP7wdoUlI9IeJGGhKBLP4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192500; 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=fazvJ2yoVQ3FbqTtLeeKqsLvxYRtSAddCup9lQnAU9I=; b=UYmtNtjRR0UZQLsv1afgK/flgHdmWf1o/gjDK/ZFeV/QuA+I6NNN3Rd64L9f2/YoeS56Eb dyXMBWCMeqzak+yn5GnuDKcpzIRPBe3/dIIEhx0QWCzNB5c1mx2LPAag7/WPNlcHdvMRWg r1/GD2xrNHrrdKcJnKLExiMOtQCtETI= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-qBN9V3nVOYSy_PtxPcIPyQ-1; Thu, 30 Mar 2023 12:08:19 -0400 X-MC-Unique: qBN9V3nVOYSy_PtxPcIPyQ-1 Received: by mail-qv1-f72.google.com with SMTP id m3-20020a0cbf03000000b005de7233ca79so6267576qvi.3 for ; Thu, 30 Mar 2023 09:08:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192499; x=1682784499; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fazvJ2yoVQ3FbqTtLeeKqsLvxYRtSAddCup9lQnAU9I=; b=lUmfg2h9X3s92To8VBZMauBS7Lx/ex7e6U2jrLabjvCHyS35CAtOXDR7YnyvyfZ20a PSqbYxND3x32CP7yD/Zukftkmqs+3qWWm2JqjA8bN3Ts/wT8sFKEksKoT+fzZGCOFK+I RITYCQr8C+H0tYu5pUDTFda4nWXHbRHY8Zf3xeGW0Wp2g5qEQIkdROMMf+H57uCDwrKo f1JaDBJsVn4HBjPs5QyixluXNkKJ69E4r2ZqlHoCysqmjnYkm+OYAK9rsSJy9J+cy7oY MITexIId20TKSRdWcwcdciks6MLhu22nMw/qx9QK83f2GJfrqR6Ia6o+741ieDw7BYrg T0Kg== X-Gm-Message-State: AAQBX9co0rVP8o5+94YZRyNnFnFZ25RvDDcmZxjzv1KjEcmtyvVIEavp tEKndukH1nigt+F8UGSnoJNQAU97u3LcnTl6PfxREs3FHb/dpTF3SMV9WNJeSttr+g7OLkPZmZI oeZNlmOvpTM0= X-Received: by 2002:a05:6214:509b:b0:5af:3a13:202d with SMTP id kk27-20020a056214509b00b005af3a13202dmr3927543qvb.4.1680192498768; Thu, 30 Mar 2023 09:08:18 -0700 (PDT) X-Google-Smtp-Source: AKy350acTLaMKvkjgA5o3kANLnUneMIVx+Sq4WzW6L7IohGdoOjgIBbl1U95wQXN6zpuQKJP6h7ekA== X-Received: by 2002:a05:6214:509b:b0:5af:3a13:202d with SMTP id kk27-20020a056214509b00b005af3a13202dmr3927505qvb.4.1680192498409; Thu, 30 Mar 2023 09:08:18 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id nh12-20020a056214390c00b005dd8b9345cbsm5546921qvb.99.2023.03.30.09.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:08:17 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Mike Rapoport , Andrea Arcangeli , peterx@redhat.com, Leonardo Bras Soares Passos , Andrew Morton , David Hildenbrand , Axel Rasmussen , Nadav Amit Subject: [PATCH 20/29] selftests/mm: Allow allocate_area() to fail properly Date: Thu, 30 Mar 2023 12:08:15 -0400 Message-Id: <20230330160815.3107534-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 29710120027 X-Stat-Signature: fneanozw5apzfyp1h1ebd1tc8rkwkd4p X-HE-Tag: 1680192500-924257 X-HE-Meta: U2FsdGVkX18DAAfKcmKiY1QUlgEwd/TG0SdHI1Up9MWrBGhfVdzSx8Bct0FylJ4Ir4eheGkwNcNCDO7FLNz8bShn5ZporwPJS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FLQesipm7p1+IYBQMbHTihBdOoaYdeo268dcOkL++Q8Ja7TrGhpPy0Za85kWozHHUPnxx7xFyS15xveNbHpzvoiOxV/piQOX3+jPEa87qc/7eVQq5m/C/cN3v9XUJZ/TaNoEuCn11phZdSFwGHLIkykN7Ygk9LfwmW+129ugbXag7R18U5g2Pd3CZLHBCXECy5tW8JRihPCb4NcAUA1P2+24hRJ68ibgUrbKwL2v/KhVxtJHu8HJ1FdDaJ3OmfK3SBUdFXlJqU4fzpiqtgyijpLhXhCAlyDoip+tTgw0vpKtzBm9Dntl89A+rQbIPgLNH5fTGq2RmMqixLuXUF0SVJUM= 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: Mostly to detect hugetlb allocation errors and skip hugetlb tests when pages are not allocated. Signed-off-by: Peter Xu --- tools/testing/selftests/mm/uffd-common.c | 32 +++++++++++++++++------- tools/testing/selftests/mm/uffd-common.h | 4 +-- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index 92b7e00efa8a..ae6b61144b53 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -44,10 +44,13 @@ static void anon_release_pages(char *rel_area) err("madvise(MADV_DONTNEED) failed"); } -static void anon_allocate_area(void **alloc_area, bool is_src) +static int anon_allocate_area(void **alloc_area, bool is_src) { *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (*alloc_area == MAP_FAILED) + err("ENOMEM"); + return 0; } static void noop_alias_mapping(__u64 *start, size_t len, unsigned long offset) @@ -65,7 +68,7 @@ static void hugetlb_release_pages(char *rel_area) } } -static void hugetlb_allocate_area(void **alloc_area, bool is_src) +static int hugetlb_allocate_area(void **alloc_area, bool is_src) { off_t size = nr_pages * page_size; off_t offset = is_src ? 0 : size; @@ -77,14 +80,16 @@ static void hugetlb_allocate_area(void **alloc_area, bool is_src) (map_shared ? MAP_SHARED : MAP_PRIVATE) | (is_src ? 0 : MAP_NORESERVE), mem_fd, offset); - if (*alloc_area == MAP_FAILED) - err("mmap of hugetlbfs file failed"); + if (*alloc_area == MAP_FAILED) { + *alloc_area = NULL; + return -errno; + } if (map_shared) { area_alias = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, offset); if (area_alias == MAP_FAILED) - err("mmap of hugetlb file alias failed"); + return -errno; } if (is_src) { @@ -96,6 +101,7 @@ static void hugetlb_allocate_area(void **alloc_area, bool is_src) *alloc_area_alias = area_alias; close(mem_fd); + return 0; } static void hugetlb_alias_mapping(__u64 *start, size_t len, unsigned long offset) @@ -112,7 +118,7 @@ static void shmem_release_pages(char *rel_area) err("madvise(MADV_REMOVE) failed"); } -static void shmem_allocate_area(void **alloc_area, bool is_src) +static int shmem_allocate_area(void **alloc_area, bool is_src) { void *area_alias = NULL; size_t bytes = nr_pages * page_size, hpage_size = read_pmd_pagesize(); @@ -150,6 +156,7 @@ static void shmem_allocate_area(void **alloc_area, bool is_src) area_dst_alias = area_alias; close(mem_fd); + return 0; } static void shmem_alias_mapping(__u64 *start, size_t len, unsigned long offset) @@ -282,14 +289,19 @@ static void uffd_test_ctx_clear(void) munmap_area((void **)&area_remap); } -void uffd_test_ctx_init(uint64_t features) +int uffd_test_ctx_init(uint64_t features) { unsigned long nr, cpu; + int ret; uffd_test_ctx_clear(); - uffd_test_ops->allocate_area((void **)&area_src, true); - uffd_test_ops->allocate_area((void **)&area_dst, false); + ret = uffd_test_ops->allocate_area((void **)&area_src, true); + if (ret) + return ret; + ret = uffd_test_ops->allocate_area((void **)&area_dst, false); + if (ret) + return ret; userfaultfd_open(&features); @@ -337,6 +349,8 @@ void uffd_test_ctx_init(uint64_t features) for (cpu = 0; cpu < nr_cpus; cpu++) if (pipe2(&pipefd[cpu * 2], O_CLOEXEC | O_NONBLOCK)) err("pipe"); + + return 0; } void wp_range(int ufd, __u64 start, __u64 len, bool wp) diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index f4bc73ce3b48..51ec75f6d0c1 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -80,7 +80,7 @@ struct uffd_stats { }; struct uffd_test_ops { - void (*allocate_area)(void **alloc_area, bool is_src); + int (*allocate_area)(void **alloc_area, bool is_src); void (*release_pages)(char *rel_area); void (*alias_mapping)(__u64 *start, size_t len, unsigned long offset); void (*check_pmd_mapping)(void *p, int expect_nr_hpages); @@ -101,7 +101,7 @@ extern uffd_test_ops_t hugetlb_uffd_test_ops; extern uffd_test_ops_t *uffd_test_ops; void uffd_stats_report(struct uffd_stats *stats, int n_cpus); -void uffd_test_ctx_init(uint64_t features); +int uffd_test_ctx_init(uint64_t features); void userfaultfd_open(uint64_t *features); int uffd_read_msg(int ufd, struct uffd_msg *msg); void wp_range(int ufd, __u64 start, __u64 len, bool wp);