From patchwork Thu May 27 23:08:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Kuehling X-Patchwork-Id: 12285577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA0CAC4708B for ; Thu, 27 May 2021 23:09:43 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6A5BE613D4 for ; Thu, 27 May 2021 23:09:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6A5BE613D4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BD6AA6F414; Thu, 27 May 2021 23:09:42 +0000 (UTC) Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by gabe.freedesktop.org (Postfix) with ESMTPS id EB6B06EE51; Thu, 27 May 2021 23:09:41 +0000 (UTC) Received: by mail-il1-x132.google.com with SMTP id j30so1761739ila.5; Thu, 27 May 2021 16:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1vTFumJbcjlC9H58za7civP9oS0BxFYnQlOIDDd8vSU=; b=HAIg1uSz4RBzsZCtp4d4QdB9b8SdCfGZGGkYyjQJ1gpqJOsXAvP98PnBrf2z4CMtNU QzSbafdmDgr4kszEaSkqeJcgdmzAvYEqqA5a70bmnambeDgQ0u4GM/6R/nmp3dJKVRo3 0bYjKH8I1+oipkfzOoA8chQFIQBF4MCZYCzKAekcY98QcSsEjbLAaoqZmOtHzPgcAvih KhwHdE9VI6bNbwHYvNtiWHV/Fk4zWs4Rv9xiflD+lQBLlEgjrCBraoaU//SEG3Z84rEv uUoYXnEnBbhbG9dgYvBhC8qb51RDUrreN+AAApT6iYh9ivrPx97e76JBAO9+apO1gsEa F0ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1vTFumJbcjlC9H58za7civP9oS0BxFYnQlOIDDd8vSU=; b=fY40y0NI40YqQ4PG1csryxWR3Qk57TXGM0g6WtHL1VSYsZRVJ++Hu65alDcfyAM4G+ GuyGdA0SJkRoGTnhiQQKh1F7ahF4/JwakGFeG6Z+rU9KDfPr5vQpkasC/6HQOlF2LW8I iIQaSCYKFPJL47+ElzV+Tj9pPS95vbUUXpaNvSmbDcBK2nQqsKRkS7MqqScZWEP29G+O S2tDmqBCMoh8NDwhoKOWvCpgHPU82R3BM/NREplORKigOpmb80jvrz1RpCbh8/oLHH+h 6pK5ioX3PwQaNK4M/nJAfBzmS7dvaLk3TpERHlpYS5sTpRHgFDDN/z8icbCkPHRHcstv 9/rA== X-Gm-Message-State: AOAM533FE6mgrcUU6xFe1JmMXkeFUWMED3JRjoPPdt9a9SkvyVBKpuE0 /V33DL3V3IAjsX7Ky1jlltfVsb9W9R+QIGgd X-Google-Smtp-Source: ABdhPJxGyk+/fitlH3T/Ywo0Dq9sm0GcM01SIGfE1kwmfZ4Tql9lUnIKyyNl5J+eQtri+AKvK9GjAg== X-Received: by 2002:a92:3302:: with SMTP id a2mr4869468ilf.62.1622156981342; Thu, 27 May 2021 16:09:41 -0700 (PDT) Received: from Harpoon.amd.com ([165.204.55.251]) by smtp.gmail.com with ESMTPSA id r5sm1860014ilb.1.2021.05.27.16.09.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 16:09:32 -0700 (PDT) From: Felix Kuehling X-Google-Original-From: Felix Kuehling To: felix.kuehling@amd.com, akpm@linux-foundation.org, linux-mm@kvack.org Subject: [RFC PATCH 1/5] drm/amdkfd: add SPM support for SVM Date: Thu, 27 May 2021 19:08:05 -0400 Message-Id: <20210527230809.3701-2-Felix.Kuehling@amd.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210527230809.3701-1-Felix.Kuehling@amd.com> References: <20210527230809.3701-1-Felix.Kuehling@amd.com> MIME-Version: 1.0 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: Alex Sierra , dri-devel@lists.freedesktop.org, jglisse@redhat.com, amd-gfx@lists.freedesktop.org, jgg@nvidia.com, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Alex Sierra When CPU is connected throug XGMI, it has coherent access to VRAM resource. In this case that resource is taken from a table in the device gmc aperture base. This resource is used along with the device type, which could be DEVICE_PRIVATE or DEVICE_GENERIC to create the device page map region. Signed-off-by: Alex Sierra --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 12 +++++++++--- drivers/gpu/drm/amd/amdkfd/kfd_svm.h | 1 - kernel/resource.c | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index c8ca3252cbc2..f5939449a99f 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -895,6 +895,7 @@ int svm_migrate_init(struct amdgpu_device *adev) struct resource *res; unsigned long size; void *r; + bool xgmi_connected_to_cpu = adev->gmc.xgmi.connected_to_cpu; /* Page migration works on Vega10 or newer */ if (kfddev->device_info->asic_family < CHIP_VEGA10) @@ -907,17 +908,22 @@ int svm_migrate_init(struct amdgpu_device *adev) * should remove reserved size */ size = ALIGN(adev->gmc.real_vram_size, 2ULL << 20); - res = devm_request_free_mem_region(adev->dev, &iomem_resource, size); + if (xgmi_connected_to_cpu) + res = lookup_resource(&iomem_resource, adev->gmc.aper_base); + else + res = devm_request_free_mem_region(adev->dev, &iomem_resource, size); + if (IS_ERR(res)) return -ENOMEM; - pgmap->type = MEMORY_DEVICE_PRIVATE; pgmap->nr_range = 1; pgmap->range.start = res->start; pgmap->range.end = res->end; + pgmap->type = xgmi_connected_to_cpu ? + MEMORY_DEVICE_GENERIC : MEMORY_DEVICE_PRIVATE; pgmap->ops = &svm_migrate_pgmap_ops; pgmap->owner = SVM_ADEV_PGMAP_OWNER(adev); - pgmap->flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; + pgmap->flags = 0; r = devm_memremap_pages(adev->dev, pgmap); if (IS_ERR(r)) { pr_err("failed to register HMM device memory\n"); diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.h b/drivers/gpu/drm/amd/amdkfd/kfd_svm.h index 21f693767a0d..3881a93192ed 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.h @@ -38,7 +38,6 @@ #define SVM_RANGE_VRAM_DOMAIN (1UL << 0) #define SVM_ADEV_PGMAP_OWNER(adev)\ ((adev)->hive ? (void *)(adev)->hive : (void *)(adev)) - struct svm_range_bo { struct amdgpu_bo *bo; struct kref kref; diff --git a/kernel/resource.c b/kernel/resource.c index 627e61b0c124..da137553b83e 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -783,7 +783,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start) return res; } - +EXPORT_SYMBOL(lookup_resource); /* * Insert a resource into the resource tree. If successful, return NULL, * otherwise return the conflicting resource (compare to __request_resource()) From patchwork Thu May 27 23:08:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Kuehling X-Patchwork-Id: 12285579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0530FC4708A for ; Thu, 27 May 2021 23:10:00 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B5B80613D4 for ; Thu, 27 May 2021 23:09:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B5B80613D4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 09BA86F4EB; Thu, 27 May 2021 23:09:59 +0000 (UTC) Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by gabe.freedesktop.org (Postfix) with ESMTPS id 45C006F4EA; Thu, 27 May 2021 23:09:58 +0000 (UTC) Received: by mail-io1-xd2e.google.com with SMTP id n10so2248645ion.8; Thu, 27 May 2021 16:09:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rXMEJXZjUbtBJkh2+REg2+RPpXku92/vdnGkFUqmhuc=; b=Ay93GmLCUIM7OteWbUa90Gw5fkekkkBc+XOVdI8G84UMUZ/kuiX/h2Ao2PW5vHiFB6 hQZPvmdGX7vzVDQMkXNpkSEkc/zmFtCmCRxDII/7InR6IyjNW/4f/uZ5OZ7xZqyO4a89 stoaqe9D38iucOA8h8bF8IbwTqqroGwp4KG5inSRTrKAvQa2KQjMiKzzKmk+xIFqRIKX daGZ65vuyKaYYpcK5mJB9vWsr9S8x2sXLjTXqTFQjQkajyxjMBNZuToZ7/0S4T/4dsXI FG9HLXMIthbY0L9GMsDBQWF3QNGmGO6su0wuZlxkjAPLI/ZxjKUxstdPY0bwKHceGX2x SAmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rXMEJXZjUbtBJkh2+REg2+RPpXku92/vdnGkFUqmhuc=; b=QhGlGH70xDLo54m+6X7jGBO1jpGeSLFK9IbhVjtER94LEVI0wIDK5U1MH2XD67DPPD CQUlchKqBzCznh/w4w/R1K/91o5Zqhj2peN9+qXVk0vho5+5+XUgI4os33WxTyK/CAbJ icefYpxlHKEH17+QjqJGEBRE2vuSJmTkFgp1m6SaPE2w77hfnq9m0tEMuvgl85YR64dh nLVA3o+wyT6iWmjrIlrfSwbgiFNYcT9xdTLc3HgXzvYRaujeVsroMIdm21SKeW6G27XS YeFF/aNcG6sqtfydsArL0JgxZECjZ2Q/6QwsXsHRRuQh50UBIPW6VBtO1MTdgSKdcZOK aeGA== X-Gm-Message-State: AOAM530O+DpojpD8xfIFl/kYJxTTwG/02hBC/Q7Ii6DKCSJ54rXZv35E rtwyWhwIy7D6HnP8lr/jIdPa+U4JYDSG2zoc X-Google-Smtp-Source: ABdhPJyzp92hDnF8efLXJm+0tvdMSeJf8uS6fJ+jMitfdarllFRWiq1kbTXZrJAJlWHy2hx5t+p1uw== X-Received: by 2002:a6b:5015:: with SMTP id e21mr4817176iob.104.1622156997727; Thu, 27 May 2021 16:09:57 -0700 (PDT) Received: from Harpoon.amd.com ([165.204.55.251]) by smtp.gmail.com with ESMTPSA id r5sm1860014ilb.1.2021.05.27.16.09.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 16:09:48 -0700 (PDT) From: Felix Kuehling X-Google-Original-From: Felix Kuehling To: felix.kuehling@amd.com, akpm@linux-foundation.org, linux-mm@kvack.org Subject: [RFC PATCH 2/5] drm/amdkfd: generic type as sys mem on migration to ram Date: Thu, 27 May 2021 19:08:06 -0400 Message-Id: <20210527230809.3701-3-Felix.Kuehling@amd.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210527230809.3701-1-Felix.Kuehling@amd.com> References: <20210527230809.3701-1-Felix.Kuehling@amd.com> MIME-Version: 1.0 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: Alex Sierra , dri-devel@lists.freedesktop.org, jglisse@redhat.com, amd-gfx@lists.freedesktop.org, jgg@nvidia.com, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Alex Sierra Generic device type memory on VRAM to RAM migration, has similar access as System RAM from the CPU. This flag sets the source from the sender. Which in Generic type case, should be set as SYSTEM. Signed-off-by: Alex Sierra --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c index f5939449a99f..7b41006c1164 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -653,8 +653,9 @@ svm_migrate_vma_to_ram(struct amdgpu_device *adev, struct svm_range *prange, migrate.vma = vma; migrate.start = start; migrate.end = end; - migrate.flags = MIGRATE_VMA_SELECT_DEVICE_PRIVATE; migrate.pgmap_owner = SVM_ADEV_PGMAP_OWNER(adev); + migrate.flags = adev->gmc.xgmi.connected_to_cpu ? + MIGRATE_VMA_SELECT_SYSTEM : MIGRATE_VMA_SELECT_DEVICE_PRIVATE; size = 2 * sizeof(*migrate.src) + sizeof(uint64_t) + sizeof(dma_addr_t); size *= npages; From patchwork Thu May 27 23:08:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Kuehling X-Patchwork-Id: 12285581 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2819C4707F for ; Thu, 27 May 2021 23:10:29 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 764F9613D4 for ; Thu, 27 May 2021 23:10:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 764F9613D4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D04E86F4F1; Thu, 27 May 2021 23:10:28 +0000 (UTC) Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by gabe.freedesktop.org (Postfix) with ESMTPS id 921096F4F0; Thu, 27 May 2021 23:10:27 +0000 (UTC) Received: by mail-io1-xd30.google.com with SMTP id b81so2283032iof.2; Thu, 27 May 2021 16:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Nfy2IfPBB1SzRRj1M8FEyKWIiZqz+B359r93DqSZMBU=; b=EIxTA24bC6jvrwGt7a6INUPZdEOCMUS/1wV3tWyvWq7RG8odSBOoO6bRwkqtNUdWkX imZoSeaVdxkqMuqGRxZalIEm0dSVhabr+IeAIyu3ZpQ6zus++vi7+EAc+7CeRWpuOKm+ kvlVhSxyRLH/GuxmK3Wh1mnfZGdDtshlwPG/ghWkxX8tsazVmTq9Mh4iYS8mF8Kukklk l0339XlDI0e6JLDK394lOtRN5gCMkKOqkh4p0ZlptgEYfF2IPy3w0or3HoTGZxh+8Sh0 tW1bGrkTw3IDy6KROQzGYQPxxPRlLMc+ewwddj+Nk+XbhLtjHgr3IjdTW3CFnAy/3vHN CsbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Nfy2IfPBB1SzRRj1M8FEyKWIiZqz+B359r93DqSZMBU=; b=HFUG0o1ZPPP/JIprVWAqx8SZrPnmgJzxepwy4BTzd260j/krZHNqs8tJmzo8BjK0RJ 9p77iP6dEigw1FtxmhrWbe/Y1H34xXeF9ILliqMoQFcBfG4P/RK/oiVu88SqYPk6TlQ7 i598IlWnfZtTcimdxExSg/69kPE5I7E20yiP00P9+cRjrZ9T2AhNcPwNvsakfEHqDUOE SL+0uPT/1N8v90UAMLwEpjUcLUJqj3QxB9yr3HCAOBf5zfUlsks6xvyS3HtTKx1oEGyd h10KR8uJZ2SVQEEQtHbppMZxHhJCSAcuSD5O7GvtDt08ZNVe3tjdD+sT3elmTPPVXlfX ybyQ== X-Gm-Message-State: AOAM531SRpIFVzlNDsY/xufJmoJBDB7MhsjblSVcOwlCtsYupcLaR6Uw cxnlBDgtlD2f+NNLwHgGlZo= X-Google-Smtp-Source: ABdhPJzzDrfBqzx1tvMKp22i200oopXJtvSuhCpPS4llgK9p8ZzFsOXk94lGGj2reSJ7a36ZyYRM1g== X-Received: by 2002:a5e:c744:: with SMTP id g4mr4783689iop.26.1622157027022; Thu, 27 May 2021 16:10:27 -0700 (PDT) Received: from Harpoon.amd.com ([165.204.55.251]) by smtp.gmail.com with ESMTPSA id r5sm1860014ilb.1.2021.05.27.16.09.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 16:10:04 -0700 (PDT) From: Felix Kuehling X-Google-Original-From: Felix Kuehling To: felix.kuehling@amd.com, akpm@linux-foundation.org, linux-mm@kvack.org Subject: [RFC PATCH 3/5] include/linux/mm.h: helper to check zone device generic type Date: Thu, 27 May 2021 19:08:07 -0400 Message-Id: <20210527230809.3701-4-Felix.Kuehling@amd.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210527230809.3701-1-Felix.Kuehling@amd.com> References: <20210527230809.3701-1-Felix.Kuehling@amd.com> MIME-Version: 1.0 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: Alex Sierra , dri-devel@lists.freedesktop.org, jglisse@redhat.com, amd-gfx@lists.freedesktop.org, jgg@nvidia.com, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Alex Sierra Helper to check if zone device page is generic type. Signed-off-by: Alex Sierra --- include/linux/mm.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index c9900aedc195..1af7b9b76948 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1158,6 +1158,13 @@ static inline bool is_device_private_page(const struct page *page) page->pgmap->type == MEMORY_DEVICE_PRIVATE; } +static inline bool is_device_generic_page(const struct page *page) +{ + return IS_ENABLED(CONFIG_DEV_PAGEMAP_OPS) && + is_zone_device_page(page) && + page->pgmap->type == MEMORY_DEVICE_GENERIC; +} + static inline bool is_pci_p2pdma_page(const struct page *page) { return IS_ENABLED(CONFIG_DEV_PAGEMAP_OPS) && From patchwork Thu May 27 23:08:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Kuehling X-Patchwork-Id: 12285583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4011C4708A for ; Thu, 27 May 2021 23:11:00 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 9AB04613D8 for ; Thu, 27 May 2021 23:11:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9AB04613D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AF6396F4F5; Thu, 27 May 2021 23:10:59 +0000 (UTC) Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by gabe.freedesktop.org (Postfix) with ESMTPS id F35796F4F3; Thu, 27 May 2021 23:10:58 +0000 (UTC) Received: by mail-io1-xd33.google.com with SMTP id e17so2258856iol.7; Thu, 27 May 2021 16:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hyMnVQT3uILhsayUiB51yYlscbJXei219nOcfMZbk0g=; b=ndasi/1WhYCH93Zprui/GY40/sn19ao3HLj2XT2v9EbazWcigmdEugKPhYF0n+yT6/ r90yLFnoxKRv4zHSeUCR6aRAK2G4JXu9lCBMk2OC7M3y5j41ApJyGGWLSEiZvYr+/Iw7 EoWG/0tcEi1Za1aImy3BIlTABk7lIRYgfs1f5Vf5EbQamG8Ga/Z7fqRphGxadI9PWZtZ j9ZmGl+5QTm3SB8QXpLXxAnznbsX8v9BJ8T9BFTvTdbYVGnTZhs6qn32xzJQfOOa6+sj zR36KQWCvD8Tz/MU1YxGj7IYqhLJRSPt7aoffgsDK8WEG5sLd/t4whHwulfZG+3RNdbM ldYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hyMnVQT3uILhsayUiB51yYlscbJXei219nOcfMZbk0g=; b=bbw+6URBkqtNlmXS7lWH/Ztovq/8oLWse87lQfWAe2hWTHErQTha9n/0UbrEZzmLmq Xv91NWORR/TceEMM16bEfleXnn+3eRGccgPYSjgsqRS+ljvMeISiJGNnum0cADB8AhLv OPhc2GRx+LfcAnmDSC7rDhlTnIhZMZfn7MkbCnIQTUuregaIG4tv1/+Qzrri4+pgrhui sM9tZsdmkOy+W8u1fFHwnwpAzNZtb8g9Xj4rSj3DglINrzOCKe30iGzZEeu4eJjAaj1y EuKNNFMhdIH11vzBtM+PS4ukDthjfLlOYiqQj9b0WH/YkyFAxJ0vNJ7+G0nkWcGAB5Vw H1gA== X-Gm-Message-State: AOAM53026JcF85tti0Z4/JktTC51mVL0qHnzDU4+SLjasNP//Qv/vaLZ /4sUDsLWn4S1w48TCQftyqs= X-Google-Smtp-Source: ABdhPJy41x9vuWRCqnDRM6SkBRLwhShGggcTKxx9ubB3k12ssllC99aPqznxBEX133FPxW+i4upInQ== X-Received: by 2002:a05:6602:2ccf:: with SMTP id j15mr4777023iow.56.1622157058325; Thu, 27 May 2021 16:10:58 -0700 (PDT) Received: from Harpoon.amd.com ([165.204.55.251]) by smtp.gmail.com with ESMTPSA id r5sm1860014ilb.1.2021.05.27.16.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 16:10:40 -0700 (PDT) From: Felix Kuehling X-Google-Original-From: Felix Kuehling To: felix.kuehling@amd.com, akpm@linux-foundation.org, linux-mm@kvack.org Subject: [RFC PATCH 4/5] mm: add generic type support for device zone page migration Date: Thu, 27 May 2021 19:08:08 -0400 Message-Id: <20210527230809.3701-5-Felix.Kuehling@amd.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210527230809.3701-1-Felix.Kuehling@amd.com> References: <20210527230809.3701-1-Felix.Kuehling@amd.com> MIME-Version: 1.0 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: Alex Sierra , dri-devel@lists.freedesktop.org, jglisse@redhat.com, amd-gfx@lists.freedesktop.org, jgg@nvidia.com, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Alex Sierra This support is only for generic type anonymous memory. Generic type with zone device pages require to take an extra reference, as it's done with device private type. Also, support added to migrate pages meta-data for generic device type. Signed-off-by: Alex Sierra --- mm/migrate.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 20ca887ea769..33e573a992e5 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -380,7 +380,8 @@ static int expected_page_refs(struct address_space *mapping, struct page *page) * Device private pages have an extra refcount as they are * ZONE_DEVICE pages. */ - expected_count += is_device_private_page(page); + expected_count += + (is_device_private_page(page) || is_device_generic_page(page)); if (mapping) expected_count += thp_nr_pages(page) + page_has_private(page); @@ -2607,7 +2608,7 @@ static bool migrate_vma_check_page(struct page *page) * FIXME proper solution is to rework migration_entry_wait() so * it does not need to take a reference on page. */ - return is_device_private_page(page); + return is_device_private_page(page) | is_device_generic_page(page); } /* For file back page */ @@ -3069,10 +3070,12 @@ void migrate_vma_pages(struct migrate_vma *migrate) mapping = page_mapping(page); if (is_zone_device_page(newpage)) { - if (is_device_private_page(newpage)) { + if (is_device_private_page(newpage) || + is_device_generic_page(newpage)) { /* - * For now only support private anonymous when - * migrating to un-addressable device memory. + * For now only support private and devdax/generic + * anonymous when migrating to un-addressable + * device memory. */ if (mapping) { migrate->src[i] &= ~MIGRATE_PFN_MIGRATE; From patchwork Thu May 27 23:08:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Kuehling X-Patchwork-Id: 12285585 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CA69C47089 for ; Thu, 27 May 2021 23:11:13 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 29D5E613D4 for ; Thu, 27 May 2021 23:11:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29D5E613D4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AA5236F4F6; Thu, 27 May 2021 23:11:12 +0000 (UTC) Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5A97F6F4F6; Thu, 27 May 2021 23:11:12 +0000 (UTC) Received: by mail-io1-xd2a.google.com with SMTP id e17so2259309iol.7; Thu, 27 May 2021 16:11:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+fnXZ/6nvmXOv34c4RRw63958oJli0u/lIVwH76TfVs=; b=hfsWP/9+JPpVyYC9O3ojjoSJgCVa8bg3ZxS8juUlu3nvrnQa1FDwqPHFiW7Wq1FFmL ILWXJk8rzcTa4KRswm4pXmJB+49rU98TN4ZkYCTQXtDevKsG0VUzsfAZ+VgXi5v2V2z6 br8VB8OP9GF+MpfgShzjNvZF+o4rtD8nnnIkPLsY9T2PeLX7b8qySpRzCRn4yrGrJbQN n49lox+UZw6fKMZgz5uCdzEvhyO7JY/CVfdfc67IRcEvH8E6dkt6lcuC4SMqOrj1a1nb 9XnyOq+IBtpMPCU0nMcRhEn/d+SYQkcG/Q1L3J6P7bj0eq09etW3Ka4Hw+8doA5no8zw eipQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+fnXZ/6nvmXOv34c4RRw63958oJli0u/lIVwH76TfVs=; b=ork8Ldi3PIg4owhgM/O3eH0wDV5C466ncUhTe2kNCyKF2PMKZ2KMdRNIbQ2GFaRKO3 /WJVxyWzlf7AZmrvHc7GFxIw3jrutkCuWmGx9loorpvWJhSl/RBQlg2is8I6CbCLgw62 hCHnZFOmONOPaMXs2MBgV2c06kXob7hkbrfRoIMsQGW7d6wGOAaMjP1eHyUrNV1ueFRh gpZyy9S6XOAnCRhrR7hlyQc/lb9/VdJvlf8e24LTAQUY34Rg/1Jno1tvri6FyJJD6/ph kLhx2m0GAsslvBIAnCiODpWOxhOEUvJHon+Em4q+j9OXjDTD906wG/fvN0zGwazi9jCa +y/g== X-Gm-Message-State: AOAM531bkK8Er52HxiJWQYV9qsSDJvfOtHdTDeVSPgwLvXwexQar6gWl dqJ7TpJEvqZf+SDeapaX0x5TEl3bNz/d/wBW X-Google-Smtp-Source: ABdhPJxhTAtS0KfJXNAGDVbVTIZAdKf4Y0VwXKHDCbpaIaFnpP8Peruryw244ygyruPJzPvmeqvEhQ== X-Received: by 2002:a5d:8d87:: with SMTP id b7mr4546232ioj.46.1622157071809; Thu, 27 May 2021 16:11:11 -0700 (PDT) Received: from Harpoon.amd.com ([165.204.55.251]) by smtp.gmail.com with ESMTPSA id r5sm1860014ilb.1.2021.05.27.16.10.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 16:11:03 -0700 (PDT) From: Felix Kuehling X-Google-Original-From: Felix Kuehling To: felix.kuehling@amd.com, akpm@linux-foundation.org, linux-mm@kvack.org Subject: [RFC PATCH 5/5] mm: changes to unref pages with Generic type Date: Thu, 27 May 2021 19:08:09 -0400 Message-Id: <20210527230809.3701-6-Felix.Kuehling@amd.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210527230809.3701-1-Felix.Kuehling@amd.com> References: <20210527230809.3701-1-Felix.Kuehling@amd.com> MIME-Version: 1.0 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: Alex Sierra , dri-devel@lists.freedesktop.org, jglisse@redhat.com, amd-gfx@lists.freedesktop.org, jgg@nvidia.com, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Alex Sierra pages in device mapping refcounts are 1-based, instead of 0-based. If refcount 1, means it can be freed. This logic is not set for Generic memory type. Therefore, its release is threated as a normal page, instead of the callback device driver release it. Signed-off-by: Alex Sierra --- include/linux/mm.h | 1 + mm/memremap.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 1af7b9b76948..83bd2f3e111b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1130,6 +1130,7 @@ static inline bool page_is_devmap_managed(struct page *page) switch (page->pgmap->type) { case MEMORY_DEVICE_PRIVATE: case MEMORY_DEVICE_FS_DAX: + case MEMORY_DEVICE_GENERIC: return true; default: break; diff --git a/mm/memremap.c b/mm/memremap.c index 16b2fb482da1..d2563fbcf987 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -44,6 +44,7 @@ EXPORT_SYMBOL(devmap_managed_key); static void devmap_managed_enable_put(struct dev_pagemap *pgmap) { if (pgmap->type == MEMORY_DEVICE_PRIVATE || + pgmap->type == MEMORY_DEVICE_GENERIC || pgmap->type == MEMORY_DEVICE_FS_DAX) static_branch_dec(&devmap_managed_key); } @@ -51,6 +52,7 @@ static void devmap_managed_enable_put(struct dev_pagemap *pgmap) static void devmap_managed_enable_get(struct dev_pagemap *pgmap) { if (pgmap->type == MEMORY_DEVICE_PRIVATE || + pgmap->type == MEMORY_DEVICE_GENERIC || pgmap->type == MEMORY_DEVICE_FS_DAX) static_branch_inc(&devmap_managed_key); } @@ -480,7 +482,8 @@ EXPORT_SYMBOL_GPL(get_dev_pagemap); void free_devmap_managed_page(struct page *page) { /* notify page idle for dax */ - if (!is_device_private_page(page)) { + if (!(is_device_private_page(page) || + is_device_generic_page(page))) { wake_up_var(&page->_refcount); return; }