From patchwork Wed Jul 14 19:54:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 12378065 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.4 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 5D416C12002 for ; Wed, 14 Jul 2021 23:26:47 +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 2D057613CF for ; Wed, 14 Jul 2021 23:26:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D057613CF 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=esXfqCn9JT7CcJ5Ar5vACdQ8QcGAot3aKqXmTSMKmT4=; b=HTMUNUp1txQT3RGe53h+IurJP1 BUnj5+tt3vr9qre2zpCB56NIvkMs8/5b8fzbsz0nuvXDf5ZpOlZuKDS9xwrZgqUarTAzyTmaMSAno WCg/Xvo1asxmKxfWc33gSCcz0XzHAycum7OYxBw1w0HYVbBqmORcRpiZiFR7cAZ3yU+vzs6nT2ibN GfETVCg0YEv24uIJ3iIeMg2CpRD52uFqriZRLXPdhPZnW/Inewes2G4JjWHUJcSOw8IxO6j4c9SsF ZiL6Z7fdPO5o/tR03JV2TT5FYCHpeZvwThg71Jcxm6P8NbHFpZT7EykV1Og/+btmwi+u1VV7pVaYd yGaxfz/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3oEo-00GG0x-9n; Wed, 14 Jul 2021 23:24:22 +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 1m3ky0-00EkIV-Jc for linux-arm-kernel@lists.infradead.org; Wed, 14 Jul 2021 19:54:50 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id a4-20020a25f5040000b029054df41d5cceso4227040ybe.18 for ; Wed, 14 Jul 2021 12:54:46 -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=B2T/QoILMvWNJwGEC8KUZ3dRqSE7FSHo/f6R3sq7KQ0=; b=XZsShrzrStmjVySs21Gzk2A2FMCDoAPRdGrEO2gWNOpRoYsuDg8nW1yTSHBtW/k5lr qtwJsxcGpiaqdZLPzbgcwOuod9AVtpIpJ9JGbyVnZ7C85SNBdB7CRkXBY442pdSdx3Ji VjTkW53yAnDvSJUGrSRXLw2zrOgNRXsMHn9lkeEl+tjAw9jAz/6DhNvgBEarrZybI8gr bk8n1dUNlf9vKF27JWWt7aMSl7rZf3fZaVz2+7l/HMtvjCKTYIkGw/jQBryZQYpaAmSH UKvID81ySSnv9WulZYDkG3dWXTWeQsexbhyMo3JKuIlM6nSuE4Mtgkh0icAlJ4k/OurB 9dXQ== 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=B2T/QoILMvWNJwGEC8KUZ3dRqSE7FSHo/f6R3sq7KQ0=; b=D0JWeWXBOHlVd5VBpCIyPBGIfeScdTNH2x2AfyUKb7JYIeS2Dg7f4ppKVxw4mmWBGA aEOawByFM89XUWGsJGaOuOPYSeHdS4VIZ0r8rLF+MkCD1EBsurA514sJfs86fbkk/TZh +Qhwx+yzoquVnIS18apQQn394hPefiGoBQvnJQLZkkkdhbOdPd8KF0YFWZsvmESVn6dU HHinRm3tIZu860BMmDaF8jqpDmR3BMTM2x0XFv43snsiOlEP27WicgzvFckJ0k8iOUS3 GZRTy8R5EQ524oKPOE89uiZvvoknfo+PSCzxbUV4d1KeeJ5PpezGemFCMyMQDbr8t68u ZW0Q== X-Gm-Message-State: AOAM533qdMeutQ8jVz1X/ZluNbdEIFUrFxOVaoybi1QW36vXgPfrFn+1 6kMQ/HsesQfQ0EWnVxRDM8LzqgA= X-Google-Smtp-Source: ABdhPJxHHuofGRrNpyWOKcdgFFhfd4tvNc6mNmwkGOkCIjfVdw6REnbEpqsPyP88Cl2HzCm8oQINk34= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2ce:200:a993:4290:ae1e:51db]) (user=pcc job=sendgmr) by 2002:a25:2651:: with SMTP id m78mr15159674ybm.372.1626292485613; Wed, 14 Jul 2021 12:54:45 -0700 (PDT) Date: Wed, 14 Jul 2021 12:54:37 -0700 In-Reply-To: <20210714195437.118982-1-pcc@google.com> Message-Id: <20210714195437.118982-3-pcc@google.com> Mime-Version: 1.0 References: <20210714195437.118982-1-pcc@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [PATCH v5 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-20210714_125448_684412_D531D3BF X-CRM114-Status: GOOD ( 13.08 ) 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 Reviewed-by: Catalin Marinas Fixes: c47174fc362a ("userfaultfd: selftest") Cc: # 5.4 Link: https://linux-review.googlesource.com/id/Icac91064fcd923f77a83e8e133f8631c5b8fc241 --- v5: - rebase to 5.14rc1 N.B. when backporting to stable branches, please use the v4 of this patch: https://lore.kernel.org/linux-mm/20210707184313.3697385-3-pcc@google.com/ 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 e363bdaff59d..2ea438e6b8b1 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -210,8 +210,10 @@ static void 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)) - err("posix_memalign() failed"); + *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (*alloc_area == MAP_FAILED) + err("mmap of anonymous memory failed"); } static void noop_alias_mapping(__u64 *start, size_t len, unsigned long offset)