Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp235504pxb; Thu, 25 Feb 2021 00:43:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJZdmAzUqXBF7KEAwB/O9/+tp7K4k1YL88OFjj5wHwWUtjkgcxkECCSWAQsiXTTdrK6ONK X-Received: by 2002:a05:6402:1b1a:: with SMTP id by26mr1809234edb.3.1614242584140; Thu, 25 Feb 2021 00:43:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614242584; cv=none; d=google.com; s=arc-20160816; b=KB0hlY6ClXn71746fyLQJ19HC68FI2UIi+x4LIaa2kdmCmVsRuRCp70bsfEE7KIg3q dPxAB82wMISI04TUbAk+790kUFBvl+eU569lqlZvP40Wn9+apmktHwSm0ORFhivIwUgh eeu1htNP5CO6z4EztQXWsvrgS3DcmtkBBZM2zoJbJ0zadUo6iinqPSJBTaxdrBDV37Jt lF6m/rS2O5WiBmqpW/QvWu3QyHfVmZjkPo9AVfVVXdU7shF0O8zWa1wuKe17+xA0owq+ ILad8TvEGZ8X7MY9hyPsT993Z26GXSdF2IiA2ag/UYEUEce2exDcfaa2n3qaCUIwxwDv 5YMg== 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=Wsf3wQJ6PA4c9ETePQNJDQHCAHI/WWgAnlx+OWV4bpw=; b=gYjqT070KVKpY5bgZhzKpgTHHqFpPQ2I6qKuVQbns83+R+lwfhA6OJtQWyOFDUeKF4 YYbltfSkKDk6NNsFB2Eyk7f+OeMXcU1VlN8ElUP4HYFHe8kimfotOs4lImXtOz24AXJC bpHl7l8e0Ts1+2u+6kz+f33Wm+ci74T5ZLWaR8U7KbMak3Lo8Jffhp2CnGJzeeHY3xVL AP3iVA99EarIsOKWAXupbGZZTgc6srA678VPqEN9kMRUgJNsIWPVLDf3j4Jt50KGCxNV 3bfT2YKI8Ra/ppSwctoh7B6RhYS6skQR6Do2bFLxWvYWf8lsJmJUb1qb80cOw9o0MPxv xE/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CbQ2rMmA; 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 s11si2866785edr.584.2021.02.25.00.42.41; Thu, 25 Feb 2021 00:43:04 -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=CbQ2rMmA; 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 S236733AbhBYCQx (ORCPT + 99 others); Wed, 24 Feb 2021 21:16:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236806AbhBYCQW (ORCPT ); Wed, 24 Feb 2021 21:16:22 -0500 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 D445FC0617A7 for ; Wed, 24 Feb 2021 18:14:46 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id u17so4457462ybi.10 for ; Wed, 24 Feb 2021 18:14:46 -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=Wsf3wQJ6PA4c9ETePQNJDQHCAHI/WWgAnlx+OWV4bpw=; b=CbQ2rMmAZMMcceblmx0O5IulyfBywI4yTEyAqBybQTjDK8thxsjxQ5f9jCCXbHHp97 F87FNrywOznuMwvpzHJvInBxFS4+87ErdGxwpVsX2n8kiQ6r8Ul/Zc7qY4617hLjgDIY Hc4qsl5dqHqU6QurW4LsfHGtmDEzqSHM+No0BZ96Dz7beOC4NmXeZELFJx6QT2GhnoGC 8JiC+pJ9M1Bc/vRShXszCtqO/FrSQaXKhkeFW6WIWO7sWQLuDmII7w/coUWpXl73awse AXk5aJvQqQqv2aGWwTiFn3aMLExVkkT8N/DYGn7e+g0e3dotdL555YZRpis8rEoizwZv JDMA== 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=Wsf3wQJ6PA4c9ETePQNJDQHCAHI/WWgAnlx+OWV4bpw=; b=gQVoAZN13xTA/amU868RFG9eylTaYf1oRxmnIb3IjBfw4r+GxYEhlmT2QU5iHgCyhI 71mY726yy2N4a/HyrfluP4m8Y/80mNKSPt46BpUfTNaHH3wwhcymihegUeyM+opukt/F BvZEUAfP1oOLu+adUa5mUoQ87PDGiMZxdlju4QfVCfAMfbcWObWalPUTDM6fkTgOyVJL soAm1ZWcl4djbMqowE+PS1+Om9sn/PiBbs96xG+Ik6G3Ymffr+GMObHPa0K9+1xX1riZ ITAsHvLnySiytY2H+lEL/RmfwIVDqmDYRrP7qnaOaDPOxHcd9+AZ0dcSxVmOoiTVPYvn z+Zw== X-Gm-Message-State: AOAM531La1j1R+Tjn5ILFU8hh+IxzkRYo59i6+48uvhLbaIAS6VQL/xY vyZPkThivHdz6FR+DtecV+JN32idMbNCp4c3godl Sender: "axelrasmussen via sendgmr" X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:a5fd:f848:2fdf:4651]) (user=axelrasmussen job=sendgmr) by 2002:a5b:9d2:: with SMTP id y18mr825166ybq.173.1614219286113; Wed, 24 Feb 2021 18:14:46 -0800 (PST) Date: Wed, 24 Feb 2021 18:14:18 -0800 In-Reply-To: <20210225021420.2290912-1-axelrasmussen@google.com> Message-Id: <20210225021420.2290912-4-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210225021420.2290912-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.0.617.g56c4b15f3c-goog Subject: [PATCH 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 , 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.0.617.g56c4b15f3c-goog