Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4916090pxy; Tue, 27 Apr 2021 15:56:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwELf2oaabrFMdvpQN9V+3psFLRU2YTr9Ef4Ac1SamoxlCxZounEPGCC7r+LN+VJjveYDX2 X-Received: by 2002:aa7:cd83:: with SMTP id x3mr6990841edv.373.1619564201083; Tue, 27 Apr 2021 15:56:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619564201; cv=none; d=google.com; s=arc-20160816; b=BrJB88xr4e8Jl6sV7xj+Pnxe27glb+8mKY9y1iCwc0jIkAgPVOBh6VAH3WczBHEVdX w7H5mq+JQMM9cVp5skXZvX8pkyfL0wXjV54TNcWH46IYR2XPLQp7U+tSc3E94wQFNb+T MJ+7rdctxDa73AX5EJVFSXg4SB6Omt8LYCdwYUi17Zsfj5lYcRDRYetaEW/sMG2Biegi Pa6NOb4j8MEvdC8JHQSpoOVmnNXE3I/f2KT81Stmliz43i6fXoXZKxJRU/ZPh4a7Y/cQ Y0RpdaMkMfXdBYjPyk2jQ9xKWdd4lKiUvNgbKEdxNiUSV5+IgfSXp9CzlIOXEgL0J9nh s+4A== 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=0MvC5tupusYzhdgaolaLRpQ8PyV4lZ/ImbJZgGlOabs=; b=unjlr9XG/uHAWwsMoR+up3lcIbUmW2Titm3dizbCeIGkZZvVx8xANTEOgQJnn6WYb/ TzrIe0F8dmjLyZB+zECZ0w38viEiNaYGiZd0OXN8VScuo+f6Wq2EoMPZPquZQfzrWeLK u4h2LN0qMCEldAzjsMjK3g5vZt81l462CtonCiwtxIiejNCIBlkubD4rCGxafXkLFQRs FfuO5mDAx+rxnJoFgidjMAzK5X7gAqxaU6ixlW8jn6bT6VEz3Ys+Yv075cejV5e+9ysf BRV6Q8x7aK9V4NuoGfPOTJ4vrmXO2ikKryyQ9py0dfKWxP5cYyZ8TJ+oQR5Q6hB9XhP/ OljQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UD9B1PD9; 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 nb11si942992ejc.133.2021.04.27.15.56.17; Tue, 27 Apr 2021 15:56:41 -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=UD9B1PD9; 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 S239437AbhD0Wxw (ORCPT + 99 others); Tue, 27 Apr 2021 18:53:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239435AbhD0Wxr (ORCPT ); Tue, 27 Apr 2021 18:53:47 -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 D6586C061348 for ; Tue, 27 Apr 2021 15:53:03 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id z8-20020a2566480000b02904e0f6f67f42so39943004ybm.15 for ; Tue, 27 Apr 2021 15:53:03 -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=0MvC5tupusYzhdgaolaLRpQ8PyV4lZ/ImbJZgGlOabs=; b=UD9B1PD9EF4/Bwq85aduxwK7rowJYh6r/31d4maWYo5P/jjmN0NPvIR56qWNSkcgYZ SRRQiyuZiULPRrCrqdwVtCmh1xFyGGmSSnB9MR2SjbBTaK2X/uP9m7mb+ncyj+F93/Bc hHZhSwvEzOPWN19Ln+Gy+ck0uEww6TkRxo1d5b3oOyf510VtVuMzmFZOgpixt58g5xTs lyYroeYU8goBXIB0bYg6JfXqEhnFgH0Ti+2Ncc97l0dhq3zh5/9s0VjJQqtuTw2GsKjB hz5taWikfbWCuRzvH7pUlPsOj+0L6zLSq0ETsBeJqgXig+Uepra47c9ho4nyjIVOFnu7 ulHQ== 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=0MvC5tupusYzhdgaolaLRpQ8PyV4lZ/ImbJZgGlOabs=; b=cDbb/h9zGuUar5gwnwnYZVnjU1cd+HI7v98tvh056yNZNp27+0Y1HveOVFvcfk0gR7 kgTDnnpfSBxEZbCTXKYZ5tuIUJrKrrWOpl7GUStLUvokUAmyfhkjZXs/8kiMLWT17qlP 2G/SXD6hXTLrQQfGj4qegA2uBwwThr/UwxXPI1IvB7EuSpHIPGBkiVlpWK5hiQlGIC0U MYitGdTsj7Jixqlv0KszqnEAmh2Z4guAxuyX5oC0tHT1iZ1VhweeJBXNqlJD7ff/fgmF FYnKFv9oyXceTO6aTn5VWL1KwEVsojuEHE6TQUYxNenHy5bKq03tR9YbWnyodTXVVReN XeRQ== X-Gm-Message-State: AOAM531PAdtVKDWirHxZeLf7+r55eysSc4VdgNRf4ElUEHGGHX+0006P jRLMm8bYcX+tkwQSZVSQpxcUVkLyGlLAR3jirPuQ X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:c423:570b:b823:c33e]) (user=axelrasmussen job=sendgmr) by 2002:a25:870b:: with SMTP id a11mr39561417ybl.498.1619563983153; Tue, 27 Apr 2021 15:53:03 -0700 (PDT) Date: Tue, 27 Apr 2021 15:52:42 -0700 In-Reply-To: <20210427225244.4326-1-axelrasmussen@google.com> Message-Id: <20210427225244.4326-9-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210427225244.4326-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog Subject: [PATCH v5 08/10] userfaultfd/selftests: create alias mappings in the shmem test From: Axel Rasmussen To: Alexander Viro , Andrea Arcangeli , Andrew Morton , 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. Reviewed-by: Peter Xu 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 fc40831f818f..1f65c4ab7994 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -278,13 +278,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 { @@ -314,7 +330,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.498.g6c1eba8ee3d-goog