Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp931573pxb; Wed, 3 Mar 2021 21:31:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7KrrkmmdMKjvHQr0jv3+EWfoLLWSg1wg3dd7c0BLiYZkfAxk3zTyd9cju8VLV6+mTnqQ+ X-Received: by 2002:a05:6402:3552:: with SMTP id f18mr2469497edd.23.1614835911277; Wed, 03 Mar 2021 21:31:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614835911; cv=none; d=google.com; s=arc-20160816; b=Kq8S0ROIQVfV6CcoXFnkyLJ+51gV+9+Q73w0PswYuN+aIMpaSkqQO48j2p3uG6zKJ7 b82a4zXuWd4WTnYbpQ8MeLYcd7BH+lR/MiV07VrwiX8ZHDqBDtKS61yXDsLx/2TZXnOQ VCD5oQx1z2sY3CRK9/O1rln4YDkuDAsRW78uR5wHUlADdbLjzvhesdu4nmuDg9ELQgDF 1d/ZdfIqhRa9z42cMXfVobok815AylkZRU2DqDemIpPyfCjPxQV7I87TgMhLMvopWdCC lKK13O+ZyfrX2jvT8y9PJNFzeCw6IID4FFE/loKK7wlzmQuFYhsXB/ulXUSgNl4xUajv vHgQ== 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:sender:dkim-signature; bh=ga+3+HU/1O4PWNGcBy73JW1dDRIoBKvdkJlksQhtYJk=; b=en/tq2NHlzZHlVEgaYnqgBO4IMchM7aG8iMrXErB9sgogrSZLOVI7NCKElBhPWSAeU p14HfBJiM/urutZJVDWq6dlXKejp/OV0ASLZ/bBUzhlKdFMc1qh3MAvRSltJOoXM1+Q+ KFTNKOa4oo4tZkF7Svp/IQ0VgeuinKnAXW1ZBlkQtjFbH33naY0MSnws7so5YcgomgOu X0lWamzzDE4/KZmjgwv3RisAODZjNxZ01mUERSuWX8gfnyiHMUGF/4GvlMgqSr9hVCLg LqSQfDJrqTrukX0EjIo6NEDzCt2NuThrzjJvp9/O4rjl9jeSAAIVCgV62dfTTHmunF2r 9cCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uZhxFptR; 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 z2si16115588ejn.577.2021.03.03.21.31.28; Wed, 03 Mar 2021 21:31:51 -0800 (PST) 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=uZhxFptR; 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 S1381075AbhCBEUV (ORCPT + 99 others); Mon, 1 Mar 2021 23:20:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238483AbhCBADT (ORCPT ); Mon, 1 Mar 2021 19:03:19 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05D6AC0617AB for ; Mon, 1 Mar 2021 16:01:44 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id v196so20663379ybv.3 for ; Mon, 01 Mar 2021 16:01:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=ga+3+HU/1O4PWNGcBy73JW1dDRIoBKvdkJlksQhtYJk=; b=uZhxFptRedsgKaKz9OLDGSC/FW+v3PDlF/1VW4uc6WxsSJPdzbOnoaHonj62Tpf2Rp 9djnZP2FZSRaquC1Z35N7BlgMdnQY+YTOj3lSji670HF0XsnEilodOWgZ3y0Yvz7azqc eIHFdcTK0ubG29dgJPKjYXW95boO5NDDIZNy3ZMda6PAMjQisn6LfG1k0JI/gvy0ieab aMZ7kckpt2US41i92QXtYfdDShOJJt9G65y9cAbQsCU72ljS2chnl690UVfwkIad3wzM G3ENscyoG3eNGlEckLNaECjJMKHGCwPlGDY56IqtzEaKnYAi//P0StXf2J3gu3PcFcnW /S7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ga+3+HU/1O4PWNGcBy73JW1dDRIoBKvdkJlksQhtYJk=; b=rWwo03AeYlxueIijvnIAtuBZd7PtV/E5B9wTtixUhmk57pt6R1MsB88K//lKDYyFuE Rf2Y7zXHcy5LdI6aFTuAIwDS1v2SsC6AAP7zlOx0+oWZ0N4hzPkXzFdcslHwhxksJx3Q XvS0CSlIeZCHFu2cUUmrpfJWGTHoOkBHHiFv4Oc5Bcea/SZnOoE+BW6YPNPRfgkT0g2U F0+Cus1Vpi04Ym+6bRUfnKSiWLjkWpv0TRmy9fGhcO71zAbJatIDUG5TuxiQWXVXgjTz jbotg2RuxZ9zsB4daLeuGigYYJHx3KU1uX/2aDxNCxf4oCOBILPXsKx1wdGVEPiE4u9n 7yIA== X-Gm-Message-State: AOAM5321xpswDFO8p6fNlsCUWvYVMo363x8RJqtOPKQEBEbSU6M/L+yg G6sIZq41FY5kUJiahqCAFXU0ZyE9zudh9FdD5sZa Sender: "axelrasmussen via sendgmr" X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:1998:8165:ca50:ab8d]) (user=axelrasmussen job=sendgmr) by 2002:a25:aae2:: with SMTP id t89mr29309195ybi.63.1614643303192; Mon, 01 Mar 2021 16:01:43 -0800 (PST) Date: Mon, 1 Mar 2021 16:01:31 -0800 In-Reply-To: <20210302000133.272579-1-axelrasmussen@google.com> Message-Id: <20210302000133.272579-4-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210302000133.272579-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v2 3/5] 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 Rapoport , Peter Xu , Shaohua Li , Shuah Khan , Wang Qing Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Axel Rasmussen , Brian Geffon , Cannon Matthews , "Dr . David Alan Gilbert" , David Rientjes , Michel Lespinasse , 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 | 29 +++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 859398efb4fe..4a18590fe0f8 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -298,8 +298,9 @@ static int 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); @@ -308,12 +309,34 @@ static void shmem_allocate_area(void **alloc_area) goto fail; } + area_alias = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE, + MAP_SHARED, shm_fd, offset); + if (area_alias == MAP_FAILED) { + perror("mmap of memfd alias failed"); + goto fail_munmap; + } + + if (is_src) + area_src_alias = area_alias; + else + area_dst_alias = area_alias; + return; +fail_munmap: + if (munmap(*alloc_area, nr_pages * page_size) < 0) { + perror("munmap of memfd failed\n"); + exit(1); + } fail: *alloc_area = NULL; } +static void shmem_alias_mapping(__u64 *start, size_t len, unsigned long offset) +{ + *start = (unsigned long)area_dst_alias + offset; +} + struct uffd_test_ops { unsigned long expected_ioctls; void (*allocate_area)(void **alloc_area); @@ -341,7 +364,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.30.1.766.gb4fecdf3b7-goog