From patchwork Fri Jul 2 22:57:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 12356783 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=-17.1 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, URIBL_BLOCKED,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 B68EDC07E95 for ; Fri, 2 Jul 2021 22:59:59 +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 670316140E for ; Fri, 2 Jul 2021 22:59:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 670316140E 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=JyfkW7f3ZonFoSFTYPo61/rATT rNaEvetU8W7YMD2EMRRNCa1SSJyFD+HNTsAwMnzVCzo5VsBYlTjXT5dkUL3ZvD3u6Nnd9s3eHnLV7 aUE9ScjNPMz+tPMAweVT7rkwDTEe50MZBeJ2FubYp8ukitBI8qnR7EJJX1LfE/hUQJUh7r8tFnTPL cKk9bHUEPtluBzFzRDph5WPTl/lq7XwYLypu14he6MoFhTRN9ItYFvn+goBpCqEXt/PB7dJv/lKfs G0A8KtNqzytf6XvudYIQ2hN6guqEcAap/XBfn/KI09Qb3brX8kpk2jMqdt7IuwUG4uxqE0veBaHEG NmUB/n9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzS6k-004E7h-PI; Fri, 02 Jul 2021 22:58:03 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzS65-004Dwj-Co for linux-arm-kernel@lists.infradead.org; Fri, 02 Jul 2021 22:57:23 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id r5-20020a0569021545b0290557963aad97so12104128ybu.12 for ; Fri, 02 Jul 2021 15:57:20 -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=jP6e9IO3/r9FhSoIPdfURhKoRHCxT5xQUApYE6/gUGXLM9a9PTNU03v1AG559/Oef1 qO+fMjuAi8sY6Xu2HRAFiWeqoQqEmrp20Mpwk2FgWTvkBVY7Uq998kduzXbHsgnR1MoG u4fYb8fR+Y5g6i7kRfqIGioY/zPUsFgjjhSgtC5EvnXeXK8WK66RpzdSez1lDSj6eruC 1KCLWTzA02yNr119sCJPBnRLG7YdIhIOCmwVLxoXVSVVV6acel8/KcfcDRICED+6h28b IrL3bMSyW/1GEeH5CiLHWZxMwtvg6zrRRpr415PD7D6gHoX/JblLaw66SGkJ03zU0CVx HXew== 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=lkjAibPjq5sG67UqhkHu09OxrP/CdKY1wmfPiz0l42PCJ47Vb2WkYQOqTmTbqmeZ1p zIXZf8qwah8Pfp6Omsks+PPmh7wXnqWxCfA24UOveAs8mpRkKW5mP9KQNQUL+CXvhhr2 sUotlQO1MQ/Kd8xgJ1VjlLvwqR4v103VAaBVWbZLhDwVYGoLPw+GetLQYXZ41iiPaDjm +igfAd5H3sTpQGi0yOIZcAP7NiT9TTGIZJyFHSl1wI6MR8kXFVzb3dmejWhb4gpKJAgR WVriV38IqEydvkR289Rt5H476cQCWzLmRu7D+eFZ8LmBrvcjSPMjPatuZBZSVDoMQfgE 45UQ== X-Gm-Message-State: AOAM532bAgNELHR0Qxd5qc8D0ZyRTJrilDg5kM4SFTv5w5JvRb/4EyxU x9vo6tkdzFsaoRrxlR9xghLmATM= X-Google-Smtp-Source: ABdhPJyIch8GVJL4w7nrHJMHGWxgT6FV0mQw9ZNNo6Ko0q38HKIAU5ZDqISC3Io0os18G3/Bc2grOV4= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2ce:200:7c5b:5407:a2db:c8fb]) (user=pcc job=sendgmr) by 2002:a25:abf3:: with SMTP id v106mr2304897ybi.299.1625266639324; Fri, 02 Jul 2021 15:57:19 -0700 (PDT) Date: Fri, 2 Jul 2021 15:57:05 -0700 In-Reply-To: <20210702225705.2477947-1-pcc@google.com> Message-Id: <20210702225705.2477947-3-pcc@google.com> Mime-Version: 1.0 References: <20210702225705.2477947-1-pcc@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v3 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-20210702_155721_483036_F7283E82 X-CRM114-Status: GOOD ( 13.80 ) 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 --- 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; } }