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 A0E87E936E6 for ; Wed, 4 Oct 2023 21:34:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 35DED10E3B9; Wed, 4 Oct 2023 21:34:47 +0000 (UTC) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20611.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e88::611]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5C24510E3B9 for ; Wed, 4 Oct 2023 21:34:45 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mms8sAg7pTZesLt47o6CBEtcbtWMqhS3wr+laZsN6y9a1Kmyftw+4yHt8T7Whv/wzukUFtg2o3SkR47kHulpNLziBoPRiucgnhGUJaEZdRA8PXZrfQKXF1yJxcAEB1bLJq/hBo42d3PPSYi4kx3yCZKDUtWJ763X+xv4eGLZELPvMRnbW7POOMExxKuPAn6wsfwOHjVZTJYbH+cDc0WSQzzellcVcToDSVLs1VjNBKGmETQXGOps2HbIXY/5coOx7EKHXadUZx406HPsFcXI19HYi9n2DEVu1fz5NtE/HaWoWefYj6BbhUz6Fvnn9l7ZkaqR6xRlZasiVXIqS2BIAg== 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=Tssh9tUMaRWi5bV29u1VCWM81LHhcF+TGaWtxG3Ag5s=; b=YGxQR8zoR4cI7TZIZGjM2wAgyg4gjtLOTPFryVWKk/QYSJS7Qe80wfWuVskfIbCFjXltAfe1z82l49bYeMyNIZhLfttmWTBuVqqgJsKcB08qv8kXF6kftbhHuDWypD/6kZMx/2wPmwq5yAa+bddwPXvMjgIQFTUecZA8DXy3MazdpX4Ws75eBAk61LKrVlOvMreQF5GDovznkAZ8P1yQdbl7TSxCn2Br/l0uAkazRkEgrVxrOIVulVFIzCHEIFMiIBozCtfU6oeIUh2lW8yAt1oAnHbsM9k+7RqxPmF2PL77j5qNC6l2TznROb6d//SFpYx4RxPexe1zkZSIxI4d1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=Tssh9tUMaRWi5bV29u1VCWM81LHhcF+TGaWtxG3Ag5s=; b=DtASAKm+EYVNR0tzTxJgFOKoho4ph7oKsyHzEwnO9wTjZN3P6fN1dyBb45JD6k48mNa1NLCeNwjrpqX7lHNyLFr3Pggmgxs7xaGZKrjuGWn8a403HI9tiVcxqB8LtLOmgZ5TD5yD/b17ENjlyqGl4coIu3Xxrws0Xr0LpcgNJko= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN9PR12MB5115.namprd12.prod.outlook.com (2603:10b6:408:118::14) by BL3PR12MB6378.namprd12.prod.outlook.com (2603:10b6:208:3b1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.37; Wed, 4 Oct 2023 21:34:43 +0000 Received: from BN9PR12MB5115.namprd12.prod.outlook.com ([fe80::2e40:ffd7:e752:644f]) by BN9PR12MB5115.namprd12.prod.outlook.com ([fe80::2e40:ffd7:e752:644f%6]) with mapi id 15.20.6838.033; Wed, 4 Oct 2023 21:34:42 +0000 Message-ID: <816ed7f8-9a22-4b17-ae0e-27701ea51557@amd.com> Date: Wed, 4 Oct 2023 17:34:40 -0400 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 7/9] drm/amdgpu: map wptr BO into GART Content-Language: en-US To: =?UTF-8?Q?Christian_K=C3=B6nig?= , Shashank Sharma , amd-gfx@lists.freedesktop.org References: <20230908160446.2188-1-shashank.sharma@amd.com> <20230908160446.2188-8-shashank.sharma@amd.com> <022fbf02-b9f6-1286-bd25-dd150384047e@gmail.com> From: Felix Kuehling Organization: AMD Inc. In-Reply-To: <022fbf02-b9f6-1286-bd25-dd150384047e@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: YQXPR0101CA0043.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c00:14::20) To BN9PR12MB5115.namprd12.prod.outlook.com (2603:10b6:408:118::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN9PR12MB5115:EE_|BL3PR12MB6378:EE_ X-MS-Office365-Filtering-Correlation-Id: 207c0e90-2ba6-4451-bb77-08dbc521b8c1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iEx7/RtLof+JWTT5wx61zex+lCpFV/WM/S+NCeJEm+IDJZEsf2NCnZfkA0PthwwwV4vV9nn9z2mq6o0oZZXLxOKMr6kml3tsof0S1dWZ/4z71jTYXYZCQSxiRiZG8a6/3aWf4yFPpBnZ+zTq3KDWseKkpzEq/byQ2bvlS2tFpCRXSi/bQhEMu4817MMimrO6ThVSajwdmfmgQlqkMXEqm4a8RHNTzBdSAFrKGJp1YYq/QN5KESUrbX3tEVsZLrBKyhAx/ympMd9+p+GcxmQ5hQg7y+x4wNvSF0lQMrWhjXuh37exfmbRj9/BhWAq82vMbyEni9YQeqxx1XFYc6V7+YO596Yj65ETJLzUjAcRkkoCAY4ZD2AgGX2jfFBsVpQZy+Kopf9+TYgraAKX4dAh2qBWSbmm2uMFRF93g96NUIaNhgnoWqOkZBc8I63K4cN4UmMmdPXq6H1G6OdCkWgtiHmxyp8RLza+CnuFV6RlFWSfrEoG33SOXvBndvL/ouHwA4i/jRFl8xpZkAkOi5fwQAaMh3rwV6nlJqd4mqdnPu/M7qOkOTYP52f31/ghPwAmOrK8cGL+T/qEpxPqUaEA65ZXxVGRPB/u3sZHXfsBIQC8U/bBjeDVXdik9RLPx7MHVDKga8jNmhW7LCU5z/EBGQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN9PR12MB5115.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(39860400002)(396003)(366004)(376002)(346002)(136003)(230922051799003)(1800799009)(64100799003)(451199024)(186009)(44832011)(5660300002)(8676002)(31686004)(2906002)(4326008)(8936002)(41300700001)(316002)(66946007)(66476007)(66556008)(110136005)(66574015)(26005)(36916002)(36756003)(6506007)(53546011)(2616005)(6512007)(83380400001)(86362001)(31696002)(38100700002)(478600001)(6486002)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Nmp0YUFHVnE0Y3pESGREK015c1hUL2RoZ0dVeXA0KzJiVGlFQ2IzSUFJTlk4?= =?utf-8?B?UXNGM2Z4T3hQbFFHQXF3dkRna0lvbWdKclZtaGVmMUgzdDZhd0k2K1BzV1Ur?= =?utf-8?B?dys4YlVuamdhTVhra0NYOFkxcEVieTVFTy9QN1JRM0RKczdVU295R3IwRTlr?= =?utf-8?B?WEFJSFMvMDJldGsxZWZZSzFKNXhuQzIwSHFNNnBHTFdrbFdmZ2lybjBhN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ZE1Fd1dhaWtYaGFTQS9Ma25QQkJaVW5tS2FoaHBkdThG?= =?utf-8?B?ZkNFOEFFUmc3UU1OdE1VTFU4ZjBjeWNmb1Q5eHpQeFhCK2hBbUJQQ09JLzRa?= =?utf-8?Q?rW5lWn5PoIbIIHNfvzhCxlD5+?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 207c0e90-2ba6-4451-bb77-08dbc521b8c1 X-MS-Exchange-CrossTenant-AuthSource: BN9PR12MB5115.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2023 21:34:42.8790 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vwWEkp6keXZNdPOpX3y82jURC8yKAQ6sVnf13mWh2RK1v7uHqKjJPuk1s8FXT6W346q3z0ObtmXfp/H4TP+itg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6378 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alex Deucher , arvind.yadav@amd.com Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" On 2023-09-18 06:32, Christian König wrote: > Am 08.09.23 um 18:04 schrieb Shashank Sharma: >> To support oversubscription, MES FW expects WPTR BOs to >> be mapped into GART, before they are submitted to usermode >> queues. This patch adds a function for the same. >> >> V4: fix the wptr value before mapping lookup (Bas, Christian). >> V5: Addressed review comments from Christian: >>      - Either pin object or allocate from GART, but not both. >>      - All the handling must be done with the VM locks held. >> >> Cc: Alex Deucher >> Cc: Christian Koenig >> Signed-off-by: Shashank Sharma >> Signed-off-by: Arvind Yadav >> --- >>   drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        | 81 +++++++++++++++++++ >>   .../gpu/drm/amd/include/amdgpu_userqueue.h    |  1 + >>   2 files changed, 82 insertions(+) >> >> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c >> b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c >> index e266674e0d44..c0eb622dfc37 100644 >> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c >> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c >> @@ -6427,6 +6427,79 @@ const struct amdgpu_ip_block_version >> gfx_v11_0_ip_block = >>       .funcs = &gfx_v11_0_ip_funcs, >>   }; >>   +static int >> +gfx_v11_0_map_gtt_bo_to_gart(struct amdgpu_device *adev, struct >> amdgpu_bo *bo) >> +{ >> +    int ret; >> + >> +    ret = amdgpu_bo_reserve(bo, true); >> +    if (ret) { >> +        DRM_ERROR("Failed to reserve bo. ret %d\n", ret); >> +        goto err_reserve_bo_failed; >> +    } >> + >> +    ret = amdgpu_ttm_alloc_gart(&bo->tbo); >> +    if (ret) { >> +        DRM_ERROR("Failed to bind bo to GART. ret %d\n", ret); >> +        goto err_map_bo_gart_failed; >> +    } >> + >> +    amdgpu_bo_unreserve(bo); > > The GART mapping can become invalid as soon as you unlock the BOs. > > You need to attach an eviction fence for this to work correctly. Don't you need an eviction fence on the WPTR BO regardless of the GTT mapping? Regards,   Felix > >> +    bo = amdgpu_bo_ref(bo); >> + >> +    return 0; >> + >> +err_map_bo_gart_failed: >> +    amdgpu_bo_unreserve(bo); >> +err_reserve_bo_failed: >> +    return ret; >> +} >> + >> +static int >> +gfx_v11_0_create_wptr_mapping(struct amdgpu_device *adev, >> +                  struct amdgpu_usermode_queue *queue, >> +                  uint64_t wptr) >> +{ >> +    struct amdgpu_bo_va_mapping *wptr_mapping; >> +    struct amdgpu_vm *wptr_vm; >> +    struct amdgpu_bo *wptr_bo = NULL; >> +    int ret; >> + >> +    mutex_lock(&queue->vm->eviction_lock); > > Never ever touch the eviction lock outside of the VM code! That lock > is completely unrelated to what you do here. > >> +    wptr_vm = queue->vm; >> +    ret = amdgpu_bo_reserve(wptr_vm->root.bo, false); >> +    if (ret) >> +        goto unlock; >> + >> +    wptr &= AMDGPU_GMC_HOLE_MASK; >> +    wptr_mapping = amdgpu_vm_bo_lookup_mapping(wptr_vm, wptr >> >> PAGE_SHIFT); >> +    amdgpu_bo_unreserve(wptr_vm->root.bo); >> +    if (!wptr_mapping) { >> +        DRM_ERROR("Failed to lookup wptr bo\n"); >> +        ret = -EINVAL; >> +        goto unlock; >> +    } >> + >> +    wptr_bo = wptr_mapping->bo_va->base.bo; >> +    if (wptr_bo->tbo.base.size > PAGE_SIZE) { >> +        DRM_ERROR("Requested GART mapping for wptr bo larger than >> one page\n"); >> +        ret = -EINVAL; >> +        goto unlock; >> +    } > > We probably also want to enforce that this BO is a per VM BO. > >> + >> +    ret = gfx_v11_0_map_gtt_bo_to_gart(adev, wptr_bo); >> +    if (ret) { >> +        DRM_ERROR("Failed to map wptr bo to GART\n"); >> +        goto unlock; >> +    } >> + >> +    queue->wptr_mc_addr = wptr_bo->tbo.resource->start << PAGE_SHIFT; > > This needs to be amdgpu_bo_gpu_offset() instead. > > Regards, > Christian. > >> + >> +unlock: >> +    mutex_unlock(&queue->vm->eviction_lock); >> +    return ret; >> +} >> + >>   static void gfx_v11_0_userq_unmap(struct amdgpu_userq_mgr *uq_mgr, >>                     struct amdgpu_usermode_queue *queue) >>   { >> @@ -6475,6 +6548,7 @@ static int gfx_v11_0_userq_map(struct >> amdgpu_userq_mgr *uq_mgr, >>       queue_input.queue_size = userq_props->queue_size >> 2; >>       queue_input.doorbell_offset = userq_props->doorbell_index; >>       queue_input.page_table_base_addr = >> amdgpu_gmc_pd_addr(queue->vm->root.bo); >> +    queue_input.wptr_mc_addr = queue->wptr_mc_addr; >>         amdgpu_mes_lock(&adev->mes); >>       r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input); >> @@ -6601,6 +6675,13 @@ static int gfx_v11_0_userq_mqd_create(struct >> amdgpu_userq_mgr *uq_mgr, >>           goto free_mqd; >>       } >>   +    /* FW expects WPTR BOs to be mapped into GART */ >> +    r = gfx_v11_0_create_wptr_mapping(adev, queue, >> userq_props.wptr_gpu_addr); >> +    if (r) { >> +        DRM_ERROR("Failed to create WPTR mapping\n"); >> +        goto free_ctx; >> +    } >> + >>       /* Map userqueue into FW using MES */ >>       r = gfx_v11_0_userq_map(uq_mgr, queue, &userq_props); >>       if (r) { >> diff --git a/drivers/gpu/drm/amd/include/amdgpu_userqueue.h >> b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h >> index 34e20daa06c8..ae155de62560 100644 >> --- a/drivers/gpu/drm/amd/include/amdgpu_userqueue.h >> +++ b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h >> @@ -39,6 +39,7 @@ struct amdgpu_usermode_queue { >>       int            queue_type; >>       uint64_t        doorbell_handle; >>       uint64_t        doorbell_index; >> +    uint64_t        wptr_mc_addr; >>       uint64_t        flags; >>       struct amdgpu_mqd_prop    *userq_prop; >>       struct amdgpu_userq_mgr *userq_mgr; >