Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2367927iob; Fri, 6 May 2022 00:42:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVeWPmZ2dWZZpUfdEPREh7/EEtjmlyjDHTMISv8R8nbyCZXtBzo83VrOxZRigOz2J8J4Fb X-Received: by 2002:a17:906:eb82:b0:6f3:9044:5fba with SMTP id mh2-20020a170906eb8200b006f390445fbamr1746895ejb.715.1651822962479; Fri, 06 May 2022 00:42:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1651822962; cv=pass; d=google.com; s=arc-20160816; b=fOUG1F6odJIkxNHI3YN+LuSd+P3Tfvro4z3YClVG1mvYZx15zwNCpbeDFwkT16Q6Xx vB1Zkp+1pg6fqKihpr5wlO2fn7DDuiHnCkjWvS5PJKdVb9Xi2YUqCi11eNUuucOMoCF3 T//j7eH+azFyh6NezA1teStt7zoPIwRoRRaGZyxag00JQJIvNMuYxh4ASU84u71cF/62 CYo7CQlP+3JJtk9xqW+Uy9FMdizdEz8DL2LxcvSXYmIQC0Cc9FwNxxfti1LmVb9Ga6s+ sNa6I0v2kXfJFwKYzUD2OB4y1L4zead9Jjta42rCQWQSL297Go0bMyd/u/ZLvols6sw8 flpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VrS9HrUH1LeQW+9lM86CVpRR7dCkow2uCtC4hBLoPZY=; b=xagkcOmkU06bDJDdSBb4RjJmEbLNhNWWaGFVjIyfXCpet7JXMIspf8BwiBKOAVYpP4 eKdrIp+rjNJTIBxuSSYFj04wTqW40fzz6b1wEr3K52j2XzpP+pGOgcSRKXoeTcvbrv0V 5KEl4SaxJXUvU8XEFxphUvTr/pzKTQiWoVgkdCOlvYB4siRJfxh80C41H+eziMcaSr57 b1LLpPtsJdJdf3ClBrbpyjvx6E+OuE7x5nbALiaMcCA9yMWWM+S2ZEEdHidgmnV+9g/z 6EPC7pNi6FPv+m/kIcl3534l9tfAnYNc4UC984+JfHDxZDUaFCSP16evq5AxjuA51Ahe bKcA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="AWR/0KsP"; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l18-20020a1709062a9200b006f44b4b2029si4009609eje.226.2022.05.06.00.42.12; Fri, 06 May 2022 00:42:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b="AWR/0KsP"; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385959AbiEEVj2 (ORCPT + 99 others); Thu, 5 May 2022 17:39:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385958AbiEEViy (ORCPT ); Thu, 5 May 2022 17:38:54 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2068.outbound.protection.outlook.com [40.107.236.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 749E059308; Thu, 5 May 2022 14:35:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JZbfoJlBCLdTu0z6wRgbRKSzhziJpeeA9X8nkrR92ZZjZOSs06lBsY8MSrxNlR8Udu3EXZJL/QkC7viXebbadVRyPpcRO/WA5C5ngWlPgBdO+wMGc2isXrdKdsqh3BVzMepctm7W4srWFYT0l3zUwak9XiErcd+CThpMTECELyxOP/kfpOR019aDyN64iQQYgPH5N6h57C1ONrmec5W8CUXfQc45OwgJkhpgNfW91s+FhIwCW2Wcbs9I4s0wp51TPSP9gVvsojN5Yodnp7lCZfkaDcSJqtT30hk6+TmvIntQp/kAcS9GNifJ75Ek2ebFClx3aDWgrtWFbey4CSNi6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VrS9HrUH1LeQW+9lM86CVpRR7dCkow2uCtC4hBLoPZY=; b=R0RLm5VaENRPLZhqSU8aAi47QvoBDfc5V8BsxUIrTSSZFbCX1WBKQTIaixoHKuOc+wiVoBQAOanAp8wcT6ZdvDbSGK5aLfeYNhJ86+jSgMUB0opwkZqeO8Yn8MMAW/qusJ5X/mBHUdOyf5iEvPYU5gUauEJDlJTQkZkElAeo+nsqx6ezY9kb3fBJah6mFDpWSeEan3OP0evQy8srDUgHWV1BX5NTdJ+mBY7cwBBRlAsUagPS0S5Ijs+nwme5TLxRprPjVvBm5+hUjhOyEsj3HpBJ1e4xjxkzrz/tN6XFxl2/5urVfwJyI69HnT25btMBlknwC32qK1sTCdOjYBe0Yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nvidia.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VrS9HrUH1LeQW+9lM86CVpRR7dCkow2uCtC4hBLoPZY=; b=AWR/0KsP1gp1PlooUrsFdqI6tkUTPWkAmtcS8iZKQYYqDjtMBUKj4Hki3daR7vc5lp5c8DO6YiHKk+/0lgeR9yi7IO6DnDWgGPj3nq0bj5lFO9JYKBegTfsJoxh0FjkCcxu9m50eUaAG1pT30lmfRQ5h5DPHX2+a1DhF0ViPpv4= Received: from MW4P220CA0007.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::12) by DM6PR12MB3754.namprd12.prod.outlook.com (2603:10b6:5:1c4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 21:35:08 +0000 Received: from CO1NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::2b) by MW4P220CA0007.outlook.office365.com (2603:10b6:303:115::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13 via Frontend Transport; Thu, 5 May 2022 21:35:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT066.mail.protection.outlook.com (10.13.175.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 21:35:07 +0000 Received: from alex-MS-7B09.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 5 May 2022 16:35:04 -0500 From: Alex Sierra To: CC: , , , , , , , , , , , , Subject: [PATCH v1 14/15] tools: add hmm gup tests for device coherent type Date: Thu, 5 May 2022 16:34:37 -0500 Message-ID: <20220505213438.25064-15-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505213438.25064-1-alex.sierra@amd.com> References: <20220505213438.25064-1-alex.sierra@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f4422ace-138f-4185-401b-08da2edf2015 X-MS-TrafficTypeDiagnostic: DM6PR12MB3754:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2YUBEx2OQhABYoOxfepX95pGHs9nDBiLvT5CtRxA476Ci7el5YwS/uQ4Rf+/xcWW6SFu4mP8VZS4Z2j/+b/wViAC6K5KS1AdKE+EgC05Bb6K35lVhc/UbFEYAAwirLkGNcGSp/zihdtLpvWZxK4808Jh66nAEodp7Pagq7qM5kxz0RswJLvXO8ecLOSf4rxB8um8yoFcahvmU0BGCNq6/DD4m5V69CqO5RObaA4FAW2K2P1GAJL8s2OkH9URaT1hNRbjz273JgnZnWz4K3vsBfOmjaUc9G/6/47CaphuNmg7JHr5Fc3ZGDIc7pGgSDTxFAzxGRJQX2sQAGm+bYd3hNbOe/9jCKdL8PFGjh0MgcTSG2aAKqLDD/Y6RbLRKhOejj8LLlm1KlVt7iKbcl7y+SITxOi8uWTSXu8FRYZOVqxGRSK/P3jjib2Byq5Yk0QZxMCt4q+JsB7O+TkWbp1S/N77Fx0cM9itAhYjhpL7aUUxnRJaXhsfBY1+tpWC/7Z1FrLqKsX8cqdbEfc+INrtYWQ5X6hEl0D6EwM7xzd4UbcKwQIkjSI8SB7cxzOWk2Cs2D1a96xeib+DRZ7NvOouB3Sg+SnFY62+b4bmYD4GFjdByBSFZJDttU3DJG/Nyu9WBNFEuBizbClQVMEq213WSXGQ8Bn8k5wb309/lG+NfEQwcEEtEJuws7t5SFcHfbflXnwGaYLT6k9mxPTQCNvtjg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(7416002)(44832011)(356005)(40460700003)(6666004)(2906002)(6916009)(316002)(5660300002)(508600001)(36756003)(81166007)(82310400005)(36860700001)(47076005)(16526019)(83380400001)(86362001)(2616005)(186003)(336012)(426003)(7696005)(26005)(8936002)(8676002)(4326008)(70206006)(70586007)(1076003)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 21:35:07.5319 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f4422ace-138f-4185-401b-08da2edf2015 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3754 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org The intention is to test hmm device coherent type under different get user pages paths. Also, test gup with FOLL_LONGTERM flag set in device coherent pages. These pages should get migrated back to system memory. Signed-off-by: Alex Sierra --- tools/testing/selftests/vm/hmm-tests.c | 104 +++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 84ec8c4a1dc7..65e30ab6494c 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -36,6 +36,7 @@ * in the usual include/uapi/... directory. */ #include "../../../../lib/test_hmm_uapi.h" +#include "../../../../mm/gup_test.h" struct hmm_buffer { void *ptr; @@ -60,6 +61,8 @@ enum { #define NTIMES 10 #define ALIGN(x, a) (((x) + (a - 1)) & (~((a) - 1))) +/* Just the flags we need, copied from mm.h: */ +#define FOLL_WRITE 0x01 /* check pte is writable */ FIXTURE(hmm) { @@ -1766,4 +1769,105 @@ TEST_F(hmm, exclusive_cow) hmm_buffer_free(buffer); } +static int gup_test_exec(int gup_fd, unsigned long addr, + int cmd, int npages, int size) +{ + struct gup_test gup = { + .nr_pages_per_call = npages, + .addr = addr, + .gup_flags = FOLL_WRITE, + .size = size, + }; + + if (ioctl(gup_fd, cmd, &gup)) { + perror("ioctl on error\n"); + return errno; + } + + return 0; +} + +/* + * Test get user device pages through gup_test. Setting PIN_LONGTERM flag. + * This should trigger a migration back to system memory for both, private + * and coherent type pages. + * This test makes use of gup_test module. Make sure GUP_TEST_CONFIG is added + * to your configuration before you run it. + */ +TEST_F(hmm, hmm_gup_test) +{ + struct hmm_buffer *buffer; + int gup_fd; + unsigned long npages; + unsigned long size; + unsigned long i; + int *ptr; + int ret; + unsigned char *m; + + gup_fd = open("/sys/kernel/debug/gup_test", O_RDWR); + if (gup_fd == -1) + SKIP(return, "Skipping test, could not find gup_test driver"); + + npages = 3; + size = npages << self->page_shift; + + buffer = malloc(sizeof(*buffer)); + ASSERT_NE(buffer, NULL); + + buffer->fd = -1; + buffer->size = size; + buffer->mirror = malloc(size); + ASSERT_NE(buffer->mirror, NULL); + + buffer->ptr = mmap(NULL, size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + buffer->fd, 0); + ASSERT_NE(buffer->ptr, MAP_FAILED); + + /* Initialize buffer in system memory. */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ptr[i] = i; + + /* Migrate memory to device. */ + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + /* Check what the device read. */ + for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i], i); + + ASSERT_EQ(gup_test_exec(gup_fd, + (unsigned long)buffer->ptr, + GUP_BASIC_TEST, 1, self->page_size), 0); + ASSERT_EQ(gup_test_exec(gup_fd, + (unsigned long)buffer->ptr + 1 * self->page_size, + GUP_FAST_BENCHMARK, 1, self->page_size), 0); + ASSERT_EQ(gup_test_exec(gup_fd, + (unsigned long)buffer->ptr + 2 * self->page_size, + PIN_LONGTERM_BENCHMARK, 1, self->page_size), 0); + + /* Take snapshot to CPU pagetables */ + ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_SNAPSHOT, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + m = buffer->mirror; + if (hmm_is_coherent_type(variant->device_number)) { + ASSERT_EQ(HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL | HMM_DMIRROR_PROT_WRITE, m[0]); + ASSERT_EQ(HMM_DMIRROR_PROT_DEV_COHERENT_LOCAL | HMM_DMIRROR_PROT_WRITE, m[1]); + } else { + ASSERT_EQ(HMM_DMIRROR_PROT_WRITE, m[0]); + ASSERT_EQ(HMM_DMIRROR_PROT_WRITE, m[1]); + } + ASSERT_EQ(HMM_DMIRROR_PROT_WRITE, m[2]); + /* Check again the content on the pages. Make sure there's no + * corrupted data. + */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i], i); + + close(gup_fd); + hmm_buffer_free(buffer); +} TEST_HARNESS_MAIN -- 2.32.0