Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp926155pxf; Thu, 8 Apr 2021 16:45:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzn2Uw3yCcieNVjqbE/cwjVbvNjXHHGPqWQ5nExFQj06L3znPo+kzM4pyJTDacwnB7oAJQ X-Received: by 2002:a17:90a:bf10:: with SMTP id c16mr10785580pjs.93.1617925558418; Thu, 08 Apr 2021 16:45:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617925558; cv=none; d=google.com; s=arc-20160816; b=vfYfhprgoduqky1R8PJ34b+JtGeWcIvmCjWcDoKnlc4wuQfaFYus4x2GOtdqiPBXg8 Olv6vO2ve8LIm/23iNG7FeAabYiEbSwQ3Yas0AzVQRvHMJ2B9hqaKRdAuhZCH3C2Pkk/ tsipY5M+SNtxlnYe1oeQrrUUdpFP5a6tnWoTSYF/t5vaTzUnt+lc4TZl7Sftou/CTJl5 kE087It+ld6merut//YwnH2MbHi/vxEuBfwVLPJFBmGAlf3ialq4moSE+3+PHbVvwxit gg4pBqi9HFnDtholENZ6AJ8M2pkgVhWKRcyw5G1qp/GdQXDSCvFUT1JU97+lYnwmGTOP DuwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=y+JvwE75GgC5IEnxBEL5JZdrd4moWn3oGAIMC9oxZzA=; b=XWT513MfuWw8+dqp2CRGdem3J+D35hintWv1MrwjGY5oAs8N8va9cj5Tts684P9HZO cr7F1U96UhMTgGgKLNivKvKvZp08t3YWytF6jWRfWKBnH/4puyBgO4zZ1LZhKsvbgT60 dM4lwMIVkrl2w3XFuHbZLx3sZ/3B99aroAj9JpcXkOAMBq/vOpKEqLfyTwLqdxyhNHV1 BlBJNCc+q2isFN5j5NwDiV7Q+GYjSPgDQe+ihBihCqvnVJb37oVjFOoX42yQCe69/GJh yoEPNWzHhhM0R6jPrhQKi0+4ffOPe/i8F03mjZsP3bNw4iPh84XJU70oIc0AX0XAHU/8 FSIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="b/Wf0aWC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q11si888301pfj.39.2021.04.08.16.45.46; Thu, 08 Apr 2021 16:45:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="b/Wf0aWC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233064AbhDHXoC (ORCPT + 99 others); Thu, 8 Apr 2021 19:44:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233070AbhDHXnz (ORCPT ); Thu, 8 Apr 2021 19:43:55 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4CAAC0613DC for ; Thu, 8 Apr 2021 16:43:42 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id y9so2305685qki.14 for ; Thu, 08 Apr 2021 16:43:42 -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=y+JvwE75GgC5IEnxBEL5JZdrd4moWn3oGAIMC9oxZzA=; b=b/Wf0aWC0cG4uYtiJ9VGNFi97zqNT9Ig+q0z8hJw5s/xOlRJa684gjh0V8qqomB2hT WZjORDQCX/pDQ55Cwv1jH16lar+FcyZ2vaPUk0rh2HvTC7b8YB5MmaF//T3tfeb+x2td JMnCPZB4qJdEjs7H2ZkHdPqpk7dnjRmmNhaw+6Ew6iWTJj8i+SIvUDgPZOmKroyePa89 1NgNFkaKLMIY1jrnTGDVjJe8QDstJmISDtvNakCMHgwf6XY8hHdhFknhKyzHFyDdmLUS ypL/ntHQIoQFWGz93HcNIfHYekI5Lx0IpVSxBIjd97QoazXIugagpeCJW95g1Zqq9kuA ew7g== 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=y+JvwE75GgC5IEnxBEL5JZdrd4moWn3oGAIMC9oxZzA=; b=K3fV0Io/ZRY91YWxwNNBFi6/zBSMVjC7p9CEtVfr4LUIDv155vyBAZHolEiWgVrVzh 19r7X3K/mO5kKvnkhFBwWq6Uvkem9YdAuty6paFySU3yWk5T0eDOHNtnwEwfiR2e/oM+ pkfaGyCh9U5ienOYg/2FblEPK8riBO1oLLtkzt29Rn3i6qpc312VGwrk7W3p3sYL3Mml /QlLbnxhru89TGQkIGjOvSHvVO0a8X/gJxI1MhqaFGK+o4ZGuwkpSLnyCGsRYFvqhJnW cYVPULo2Tct5f7a9RoPtGMm/9sflK1J/vU3b3qgMF6K2k6uhePwcIlnYPDfI8CzD6l4f xtGA== X-Gm-Message-State: AOAM532Ydyidv8MOMm4JWpW7Y0IG3H4vBvs6r/SqSNXaau6MBC0AHG4L TpdMQyBW1ITnp+j2KEIyz3gVDWGZEzAGk7Ryr6f9 X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:3d06:d00f:a626:675a]) (user=axelrasmussen job=sendgmr) by 2002:a05:6214:7e4:: with SMTP id bp4mr11257020qvb.5.1617925422072; Thu, 08 Apr 2021 16:43:42 -0700 (PDT) Date: Thu, 8 Apr 2021 16:43:24 -0700 In-Reply-To: <20210408234327.624367-1-axelrasmussen@google.com> Message-Id: <20210408234327.624367-7-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210408234327.624367-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog Subject: [PATCH 6/9] userfaultfd/selftests: create alias mappings in the shmem test From: Axel Rasmussen To: Alexander Viro , Andrea Arcangeli , Andrew Morton , Daniel Colascione , Hugh Dickins , Jerome Glisse , Joe Perches , Lokesh Gidra , Mike Kravetz , Mike Rapoport , Peter Xu , Shaohua Li , Shuah Khan , Stephen Rothwell , Wang Qing Cc: linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Axel Rasmussen , Brian Geffon , "Dr . David Alan Gilbert" , Mina Almasry , Oliver Upton Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Previously, we just allocated two shm areas: area_src and area_dst. With this commit, change this so we also allocate area_src_alias, and area_dst_alias. area_*_alias and area_* (respectively) point to the same underlying physical pages, but are different VMAs. In a future commit in this series, we'll leverage this setup to exercise minor fault handling support for shmem, just like we do in the hugetlb_shared test. Signed-off-by: Axel Rasmussen --- tools/testing/selftests/vm/userfaultfd.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index b0af88b258d7..4b49b2cf9819 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -279,13 +279,29 @@ static void shmem_release_pages(char *rel_area) static void shmem_allocate_area(void **alloc_area) { - unsigned long offset = - alloc_area == (void **)&area_src ? 0 : nr_pages * page_size; + void *area_alias = NULL; + bool is_src = alloc_area == (void **)&area_src; + unsigned long offset = is_src ? 0 : nr_pages * page_size; *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, offset); if (*alloc_area == MAP_FAILED) err("mmap of memfd failed"); + + area_alias = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, shm_fd, offset); + if (area_alias == MAP_FAILED) + err("mmap of memfd alias failed"); + + if (is_src) + area_src_alias = area_alias; + else + area_dst_alias = area_alias; +} + +static void shmem_alias_mapping(__u64 *start, size_t len, unsigned long offset) +{ + *start = (unsigned long)area_dst_alias + offset; } struct uffd_test_ops { @@ -315,7 +331,7 @@ static struct uffd_test_ops shmem_uffd_test_ops = { .expected_ioctls = SHMEM_EXPECTED_IOCTLS, .allocate_area = shmem_allocate_area, .release_pages = shmem_release_pages, - .alias_mapping = noop_alias_mapping, + .alias_mapping = shmem_alias_mapping, }; static struct uffd_test_ops hugetlb_uffd_test_ops = { -- 2.31.1.295.g9ea45b61b8-goog