Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1018265pxb; Thu, 15 Apr 2021 11:49:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjhV3Eh4Bob6InBt292YPX0s1nSica8n8XQ/4egv8SCSBLywyh/Fnt3yARMS+qSgRgM1DI X-Received: by 2002:a63:5c0e:: with SMTP id q14mr4069484pgb.441.1618512554048; Thu, 15 Apr 2021 11:49:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618512554; cv=none; d=google.com; s=arc-20160816; b=S0js9lEJFZQOAEhBtyAV6IqfQjeyRbuZGoyuIgSGm5fNB0m3UXllmh0saJja/18NL3 dzT4dLgNNWRISRrU2oe4dZ9CCMHd3vOO8fsX/bXtg8eCJfk9Ke5kMofD1Hl64Rj7a2wr hBjFv1aPjiA+sWKWX0LYPGQiYXLZw8Ei/h9d7K9Fc0ot+w63+1ghffPcXnoyhaCjV33D d3z3u4q6s+tKtPXepATkN7NcBqGay9vdS9RGQ1Fb7asizLkOO7pkhOle0t+W29p68gwZ wx2pCXxbFHBqxYU3nbMj7TDFtIQ2B1E6jfDTjxQtV8RXKIEsAKuEfRQCf/g9rulQMCuA Tdiw== 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=kyyFN9AtGZG7sxPS2jLvKjxCRLZ+illjJVxTiN8fbrw=; b=yoaXTTdkAixzZ6dNX4GwymAWz99gbGaGMIpCqefsX1saUmVb0rEdJl7L65uZ4OvXax ff5UODhaMQ0+A4VhqrAg4zakuMSoDTS/mh5P+/+CM3CJLliSecobJykJVaLe7y8OuAcF CqDj9E//K2W0j8uLsZaEJfV1LuoSjuCc6cs46X4gpyPGYnFUx2W5avOTFH2hCMI8ppxS +V3WG7WY1o2/UeKnEAQQNwZNZ/DFsx6k0G3M72C7IwWQorKw6BrhMgUB0gIpJy1ss6KO RvrVau4Bm0tN66B82L6aBsgy+64CfqjR7R/WZyH4fJzUK5cGM7xgymLuQgwUB4jIDVNK RgpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="bEO/DKD/"; 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 m14si4327139pjq.134.2021.04.15.11.49.01; Thu, 15 Apr 2021 11:49:14 -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="bEO/DKD/"; 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 S234808AbhDOSsi (ORCPT + 99 others); Thu, 15 Apr 2021 14:48:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234690AbhDOSsS (ORCPT ); Thu, 15 Apr 2021 14:48:18 -0400 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 AC52DC061347 for ; Thu, 15 Apr 2021 11:47:47 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id e9so3416474ybq.22 for ; Thu, 15 Apr 2021 11:47:47 -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=kyyFN9AtGZG7sxPS2jLvKjxCRLZ+illjJVxTiN8fbrw=; b=bEO/DKD/YOTDKe4mprz2o/D25pBXvk5801YRzBcmlH29uJ7L3xw0LQeabTYhX1ZlgN Lw4e77/NBxGYXx1c1CWdXQlgp52Oi/tG7mccD2oT6Yhbwm4ef5UPHoCO4/ZslMvqvWf8 VR32W9PLDLs/IO7IOSPEhFvbwEvSl2hxfNx3PFupE4ltWdrsbUtXrgT9AAI58yiLgW+V NUOYj78f0D/V/Q5P8RM6KcsCIHPk9XuO0Ntj3NWMQAT3DQ4ouPoR4wt78n1hHibp7Rs4 /JAXARkjMuOyLTDNmJ3WOx4uRnizhdSBKLs5FWYGDJZFml7k+nPkfDGbyOL217bU+yYv /1+w== 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=kyyFN9AtGZG7sxPS2jLvKjxCRLZ+illjJVxTiN8fbrw=; b=t00mqW5c1SbhKtn1T7JjQXK42tcUt+gCNdLNVWEUcZitGBOnfjt36uGCW18siuHG9M fLfYHAcSVRWeSfbUtXyz9CmQUjiUzy685zDRM99ppXDLjgpQcUmK6xseD6Q6uidgX2lL BJKJdd5ZfO1andmEV63KfS+qNWyTNy+QijB3wrMJWnkNNNT18iAo8C3kplUdlYkLCJC0 6OateVgOGQeVYR12v2YYsROfErws/JzTkNrdM0EhgV+fk3igBPBafTCnD6+hCLfPSHYi xpTkSMMESNtE7DSOmggPAFqh9LdjGeCBmSzOIDFOHduWX/gLK2CY0CFIzEx3vX2TfDCY tQCQ== X-Gm-Message-State: AOAM5338ARxAQa9m2QJLm32rkniidngxyhwNoWRqK8xJqBTQ6tzWVh44 BIFML0Hgn8rqG0KsVLygp8G6CSCKNg3XJz778RN8 X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:21b1:6e5c:b371:7e3]) (user=axelrasmussen job=sendgmr) by 2002:a25:cf08:: with SMTP id f8mr7041943ybg.132.1618512466892; Thu, 15 Apr 2021 11:47:46 -0700 (PDT) Date: Thu, 15 Apr 2021 11:47:28 -0700 In-Reply-To: <20210415184732.3410521-1-axelrasmussen@google.com> Message-Id: <20210415184732.3410521-7-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210415184732.3410521-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog Subject: [PATCH v3 06/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.368.gbe11c130af-goog