From mboxrd@z Thu Jan 1 00:00:00 1970 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=-26.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 ED9D6C07E95 for ; Fri, 2 Jul 2021 22:57:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4E7061423 for ; Fri, 2 Jul 2021 22:57:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230020AbhGBW7x (ORCPT ); Fri, 2 Jul 2021 18:59:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbhGBW7x (ORCPT ); Fri, 2 Jul 2021 18:59:53 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25F30C061762 for ; Fri, 2 Jul 2021 15:57:20 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id l16-20020a25cc100000b0290558245b7eabso14918832ybf.10 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=Pk/AB+rMt3ToAOPCLQeOmzcGEhgKsSSnmeqXhsluv0Wak7gAQdCmpvvnf8DPeUpzgn xMvo96aH/aXgcG2kRjXg4SQp7tsrwsGUzdqv08oTBhBssc00tmH2fDSEJ+WCg9q5hI1Y jYS3FEqjqiTSn75uXwcjarIYxAoAK7fH9MR1rR3TZwhTTSU5w+89Rp+tpeo+lSOcYmdu yffUwByndJTk/ACss0RmqOLUNGQSKl00YjGO2GJa4rm68Kqz5Fv4oAZhuTSqaod3KU5m h3ZZoRaEuwL8KscGkjb7zSCt9Ao4OjGsFDLYBy5fM61Hk/ZLBrPJ0Oetft+qAY6fdL21 O8VQ== X-Gm-Message-State: AOAM530uSrTHVClQxgMz3wJp5MoEotKRNxR4lSVaGRRdpFaVpvIlCA5G nGgl9egntyssKlVFND3vBgtq0nI= 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.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; } } -- 2.32.0.93.g670b81a890-goog From mboxrd@z Thu Jan 1 00:00:00 1970 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=-26.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 C4FEFC07E97 for ; Fri, 2 Jul 2021 22:57:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6B08B61416 for ; Fri, 2 Jul 2021 22:57:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B08B61416 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 131EB6B0087; Fri, 2 Jul 2021 18:57:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 109238D0007; Fri, 2 Jul 2021 18:57:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F161A8D0005; Fri, 2 Jul 2021 18:57:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0179.hostedemail.com [216.40.44.179]) by kanga.kvack.org (Postfix) with ESMTP id C992F6B0087 for ; Fri, 2 Jul 2021 18:57:20 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6E468181BA3E1 for ; Fri, 2 Jul 2021 22:57:20 +0000 (UTC) X-FDA: 78319160640.30.0D7D551 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf13.hostedemail.com (Postfix) with ESMTP id 2C531100828E for ; Fri, 2 Jul 2021 22:57:20 +0000 (UTC) Received: by mail-yb1-f202.google.com with SMTP id 67-20020a2514460000b029053a9edba2a6so14971655ybu.7 for ; Fri, 02 Jul 2021 15:57:19 -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=tLMKjbWtIUeEUV2fzda8TNSAFi5v30nHA0H3yRTCk3DiaJKcpt7AuQ4NfnixhCg0ZK qmNX7A2BAqW3Y1795aMcns1PXpKa7a1md/Vv+7XM3dcloXGBk+Ifel3kEqyWwdrrrTkv r4d95Y52KRT8RJL8o+wTZ+SRESm/Umd1HBxW0nPcsw8/Ztl0nRXehf2iFcScIW/xeIJY XBHv8WjZyMvGyIH5prnPBtjdwfwvzgiPssvgPGa+3wUzTxvE05N7z9Be+tSH2+AZ5b7U N4w399cd0KfBotS8OYZtGc+PiUNaTONKOEc6LSnj/w/CFtFuHw2h5yavXq9RxgLMHmHi x+pA== X-Gm-Message-State: AOAM530oexmkdrECJ7RimWkFYdvAOZKvzyUlIqfRDCqpqw5pcl4n1eZ4 XQjA94Ypt1d+4wdGqMbpK1I2Jec= 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 Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2C531100828E Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=jP6e9IO3; spf=pass (imf13.hostedemail.com: domain of 3z5nfYAMKCI47uuy66y3w.u64305CF-442Dsu2.69y@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3z5nfYAMKCI47uuy66y3w.u64305CF-442Dsu2.69y@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: 4qnous4kxn8fe88iduwpao9eewerjeho X-HE-Tag: 1625266640-107397 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: 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; } } -- 2.32.0.93.g670b81a890-goog From mboxrd@z Thu Jan 1 00:00:00 1970 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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; } } -- 2.32.0.93.g670b81a890-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel