From patchwork Mon May 16 23:14:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sierra Guiza, Alejandro (Alex)" X-Patchwork-Id: 12851686 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 03B61C433FE for ; Mon, 16 May 2022 23:15:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6B79310EAB6; Mon, 16 May 2022 23:15:11 +0000 (UTC) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2077.outbound.protection.outlook.com [40.107.96.77]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6D2E410E6CE; Mon, 16 May 2022 23:15:10 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hWSgUfLnhE3Xe+qWBcIROmTeq6SJHum/YFTFRXiCwEPbIuQZE5bqZA6dITACXdzhQrj8Qp7wr6PXpoxMjbVfMo8Tr8CKVw8pkD9XzGVsvmlG7MKX2VDZBk1OaEPNNEiGI6TDIpXfkjQNLNfWkAY/ORyGI15cO8lGXY5w3ZTVUhBR0xXTiiWTC6ZJjxRUP2I29cxSo3ntqdK8r3JHkXi8m/zdOm3XbKJ3lrhr/j6elYuKIP2B11Rm+WDaLEqPbPmmTcGm8H++XAOZq51UXKrxkSBvOUbztXNMeLKFkls7W2XlKt4ZuEYwHR5d21z0udzRbMgLmY83Jf7010oauGEhQA== 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=FDtE0UiWruDuhx3PGoXdolkeW/K0qLVDBaC3nvm9Xp8=; b=aFfyXoIPrS/+RtcVUHVwsqstl7RWZv0DBu/UAOlMPmEI/bvU9ORUl8DPhZfzRoR5roGYo4IZUVUBmHo52ojmNpVdjg9b0RgCj5X9BU8lMUng6FEek+I16ntcxOWR62AsLXnf3BSMQ/VtWWSIiSnyVWFTsr4dWIPVjEAkpwQygtkP/wTFEE5dM/2A8g6ztIXPQxAIh3kt6hLI/n/Pu9ukWFV8oe5tzH1JEwF+unsMKbXwqA/Pab9QvclyaNmhi63/kUAwwyXgMffN6Hf1jZym20VvjN6Dfts4nl1WgNbosu1QQwl/GDE7a8u+qVqm9FFLrxahVwo1T+6S88vJrIZ4OA== 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=FDtE0UiWruDuhx3PGoXdolkeW/K0qLVDBaC3nvm9Xp8=; b=UVp4ehEefTRoPSl4ohQ+0oDyjwcSailyVaCaBVx4TpdcW6MeAXpBpTVOgIt9hDbgVQ7XT3sF+xhl4AwJ6RsZEat12KeWxHj3YjbA07Oh+KLFTr8rcxSvFPl6755pS4kSaga8ocb9EqEtkPwLoBqSCtNz8gJEDx5wO62GOJbl/b4= Received: from BN9PR03CA0713.namprd03.prod.outlook.com (2603:10b6:408:ef::28) by SN1PR12MB2591.namprd12.prod.outlook.com (2603:10b6:802:30::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.15; Mon, 16 May 2022 23:15:06 +0000 Received: from BN8NAM11FT041.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ef:cafe::f1) by BN9PR03CA0713.outlook.office365.com (2603:10b6:408:ef::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.13 via Frontend Transport; Mon, 16 May 2022 23:15:06 +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 BN8NAM11FT041.mail.protection.outlook.com (10.13.177.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5250.13 via Frontend Transport; Mon, 16 May 2022 23:15:06 +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; Mon, 16 May 2022 18:15:04 -0500 From: Alex Sierra To: Subject: [PATCH v2 12/13] tools: add hmm gup tests for device coherent type Date: Mon, 16 May 2022 18:14:31 -0500 Message-ID: <20220516231432.20200-13-alex.sierra@amd.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220516231432.20200-1-alex.sierra@amd.com> References: <20220516231432.20200-1-alex.sierra@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1a60e5f1-fb84-45ba-2bb6-08da3791e9f5 X-MS-TrafficTypeDiagnostic: SN1PR12MB2591: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: wJthxU2+zshA6r/5EE74K0pBPoYw54kherCC0lTKiY81MFsQv8kz0rbLNwPSg+XnJsq5bTGca0PnmJW18YOVifCtVQB8FFE/2jRADhAIN4JsCfzM5FnaJ1RwiOBM6iAH89abl6b7jatxSdrGouLWwq8PnZBmS2B2UDMsnfE3jeMP6cVCUCFsuhAqHJWigiwlzl6a6Vf8gbXhRsrH0pJEAw59Y137cbcMpVolU0h0y87x/toM5SZlbP5cc+nNbAc9+PkqXH2zIpU6Cv1YS5UNIwkpLNGY0uYz39Ga5NrnnRlFUQD+oLWu8Tuty+ZqjFRmWL770ndLXmDYadRuwfl0vecRZcK0m/ra9JBpcYLxHLEpbxcCErEyHv6ZOekwi3HO/vbJXdTq/XRlxOEluEih3Nu9nv/+brWH3mDnMNhi/inf7cDFrf/+m3HJH9UVcOAMhyy7YNNPssnOK0ZsFz9AlkCey0l8PgN98+UC0AqamqzMmafMoKVFAVODZmUPJ/syOVRTpq9KGOdcISkOqS8BZMfIPkwmPvBy3Wg+rsXq2bf5GZsai6CTtdhTfRFnYsviRJcN7HOAmmEWWZRvow9Cjkt2sjh8ZkDxpD4QF+aRAGepqZ+13AqM4T09VtkxGpOZPCsqOc+sbhnVf2A3Dmc3RxXEg5Zzx1QaPkJCt6BUbff7q7+MJK5Sm1sMbeQeNPqXpl9MKOvl8I4aPAXMq//nMA== 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)(46966006)(40470700004)(36840700001)(44832011)(7416002)(5660300002)(508600001)(8936002)(4326008)(8676002)(70206006)(70586007)(86362001)(40460700003)(26005)(36756003)(2616005)(7696005)(54906003)(186003)(1076003)(16526019)(426003)(356005)(336012)(47076005)(6666004)(81166007)(2906002)(36860700001)(83380400001)(82310400005)(6916009)(316002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2022 23:15:06.0665 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a60e5f1-fb84-45ba-2bb6-08da3791e9f5 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: BN8NAM11FT041.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2591 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: rcampbell@nvidia.com, willy@infradead.org, david@redhat.com, Felix.Kuehling@amd.com, apopple@nvidia.com, amd-gfx@lists.freedesktop.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, jglisse@redhat.com, dri-devel@lists.freedesktop.org, akpm@linux-foundation.org, linux-ext4@vger.kernel.org, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 Reviewed-by: Alistair Popple Reviewed-by: Felix Kuehling --- tools/testing/selftests/vm/hmm-tests.c | 105 +++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 84ec8c4a1dc7..61a02a6a3dea 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,106 @@ 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