From patchwork Wed Jul 7 18:43:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 12363775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61A25C07E95 for ; Wed, 7 Jul 2021 18:44:56 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3561560720 for ; Wed, 7 Jul 2021 18:44:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3561560720 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=f3SC5kKSzgLzPTcMBUKgSerOKM8N46NfEm5sQzw6lQ4=; b=UBHC9AR4a3Gsrn0sEWPfSRLeCX Ys0NYn2UsE3VXCqV6IZcfj7jdDC8S257wMz4xOy0zUg97En9hwdVFcnsvT/kAF7VqQcuBlyw4Zd1G TuWQhSe9Rkxh8CDr06J87iQpUYuwD/2i5k7ZH8kxhafn+tdg696nTCsnd2Wf3te5dE6To1zEZWEEn 4K+1mgOY2VojuO3fgCjwFUZpwqwsMbPLn++upwexKVMXsLcx4oBj7i9cxcJsyWEiD/hcVsVlYC0K6 awg5XPCHCtXrx+0Rok+2TGmYPvtDXyisxwJ0ft07jSOyGXyGw55fnkJXRZh/1yeyxl5om5RbfHlOV HtuG8Y/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m1CWQ-00FWyP-52; Wed, 07 Jul 2021 18:43:46 +0000 Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m1CW5-00FWtI-8H for linux-arm-kernel@lists.infradead.org; Wed, 07 Jul 2021 18:43:26 +0000 Received: by mail-qt1-x84a.google.com with SMTP id e9-20020ac859890000b0290250be770d0fso1823209qte.15 for ; Wed, 07 Jul 2021 11:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Rhp3BKIpjKyJeRxRqWuyTX92X8tONQf5DKJFV9GgdPE=; b=c/OqeybiDBJu1t6JnaImpv47tr2Ob0KDl0V73uPNIXEH2QZYKXxQnns6XmMwV5PLxM 8Lj2jF4NV17b4XKzFfqhxNVcR7ovkTKc/cy3lE3VBcvEvyrNtzEVl9w2WePyv2qJ7xss r+NQ7UzBdNLrW20P13Hq36xiS59Vb0/nM4mGlpqbdvQWHIDPM2Ur18UNSrdYL6ABJmDd KTd/IBgRuVkWgYVsc5gcK0EP2CvWtT2yg4LciWdSb2dj6y9C3u6TO1QKShMays8o2JA9 FTyErolmjpvcq1GyTfiDU7whOe/7OuHlEWgIa0n1jJ1p+kHfmTIoPn++tjr88p9OOv9t 5omw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Rhp3BKIpjKyJeRxRqWuyTX92X8tONQf5DKJFV9GgdPE=; b=gcb65JgKaH1FLWo2Zi3PTo4VnCgGoI+CJRO55jODIkpzNAwFqjSXOwlHf2FTlwSpD4 itRIdhLSk46cjEsf7Ax7bBr8rBp6sOBWTlQ627+E/JRTzFromVQ8QnI2RHODkLZ3m0lz yFS1rM+BhX7av2eOEjY5DVoiS+OvXI+u7pKN/S0jCXeZmjSw630atoqn3OXH8JPgcb1I uGePgVHBPQmb160zve5Rd8dytJ4WE0ckrl42bxj4BltmiHp8S9XweO93I3YNfvFQ1gWS /f+JktkfKJqG6Qwxns2i4wKi8Vh/TCzbH3CUOAjilF7qpbXLxKtGJtY58DKEL06BMyHZ KViA== X-Gm-Message-State: AOAM531ZSYgFHYWiCgTrAC40OjkgRVn4n0eNkUtokHJ3FYM6v5yW/rD6 7syvuVTZcsJUxB2+HBhyEiE9ugI= X-Google-Smtp-Source: ABdhPJyek+w3/MK5+sdPwSDQnHlLoCSmddNfmUwmGCeqLHtiM1vO19K+SGLQtSdYi7FObRgFloXl5m0= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2ce:200:3b71:8b83:5f3c:e3df]) (user=pcc job=sendgmr) by 2002:a05:6214:1087:: with SMTP id o7mr3739459qvr.27.1625683403337; Wed, 07 Jul 2021 11:43:23 -0700 (PDT) Date: Wed, 7 Jul 2021 11:43:13 -0700 In-Reply-To: <20210707184313.3697385-1-pcc@google.com> Message-Id: <20210707184313.3697385-3-pcc@google.com> Mime-Version: 1.0 References: <20210707184313.3697385-1-pcc@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v4 2/2] selftest: use mmap instead of posix_memalign to allocate memory From: Peter Collingbourne To: Catalin Marinas , Vincenzo Frascino , Dave Martin , Will Deacon , Andrew Morton , Andrea Arcangeli Cc: Peter Collingbourne , Alistair Delva , Lokesh Gidra , William McVicker , Evgenii Stepanov , Mitch Phillips , Linux ARM , linux-mm@kvack.org, Andrey Konovalov , stable@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210707_114325_342750_2E72E27E X-CRM114-Status: GOOD ( 14.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This test passes pointers obtained from anon_allocate_area to the userfaultfd and mremap APIs. This causes a problem if the system allocator returns tagged pointers because with the tagged address ABI the kernel rejects tagged addresses passed to these APIs, which would end up causing the test to fail. To make this test compatible with such system allocators, stop using the system allocator to allocate memory in anon_allocate_area, and instead just use mmap. Co-developed-by: Lokesh Gidra Signed-off-by: Lokesh Gidra Signed-off-by: Peter Collingbourne Fixes: c47174fc362a ("userfaultfd: selftest") Cc: # 5.4 Link: https://linux-review.googlesource.com/id/Icac91064fcd923f77a83e8e133f8631c5b8fc241 Reviewed-by: Catalin Marinas --- tools/testing/selftests/vm/userfaultfd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index f5ab5e0312e7..d0f802053dfd 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -197,8 +197,10 @@ static int anon_release_pages(char *rel_area) static void anon_allocate_area(void **alloc_area) { - if (posix_memalign(alloc_area, page_size, nr_pages * page_size)) { - fprintf(stderr, "out of memory\n"); + *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (*alloc_area == MAP_FAILED) { + fprintf(stderr, "anon memory mmap failed\n"); *alloc_area = NULL; } }