Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3621432pxb; Mon, 21 Feb 2022 02:03:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwy3XCjNg9S19pajDxQ2/oxRWMgCcoHD57lP4Q7SnlBjhvHgwv7uc5HDIf21oPH898Gg5Wq X-Received: by 2002:a17:902:8482:b0:14d:6834:f899 with SMTP id c2-20020a170902848200b0014d6834f899mr18842896plo.58.1645437799882; Mon, 21 Feb 2022 02:03:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1645437799; cv=pass; d=google.com; s=arc-20160816; b=h7kVEt7OzTkoD3qLFl8S9Pl+DfqF4lNJcX9W60+NDlLNyTMY4yIeNgFuhsXtrUS1O1 RuAr/AV0PjHELpBBYvOMrAy2ZvHrDbRRvFirjaXXIJVaSbgS42+Nj6TajYU7irq5l10m KdzqEQ1uzKCUaPDQVgGI8/3hArixJzKAaTAdDNCt5fdjfn5BjHO/VJwRquX8fE2b6lCp O9e+XSn/oI+R9gLXkZWtiBxv2W6OhwtPv8cnYE4sxxuGvyobTSxU5og8L8Yx57MQwuZR fFE475wh32p1eK79N9Ti7XET31n39QnN3PuUVM774AL/IXaPnvLIUsEBgbbWWXqnATFq Byiw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=5OEVVJ/IdAuoLTgcNxL7S4kTR12vJyAKLaqR1j1/plQ=; b=WbX6tv+xAWW+QDNVqECiamnXNGhRVoz18hrObgYEzmO3sHxOlKhQlesRK5hbip6h/X fvs4eVVOcIqJ5enmkbkSdECGxINvpvL1ag/JQkhmbYkic1L6W4Gs67u4L+zyELxitGft 68jmVsw69ycUtokjUJOgW3GDRGd8CoKIZUBICRxZt8oTBJqVlKRoWhyqg81AxIEbZ4IF QU8+MJ4eEGX7FeLr+z55gwmW2NyTLYYiE/Pnn2dOa5ri2GWsVCYT2c70ShodYjdvTQKA ZmE5EwExwPm+j5qh7mPy3xb6glVoaRCcbnHNb8dPO8iGNM23MMVc+1lT8VcKrCAbgdP7 fHyg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=LdmzQHXB; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 v13si811655plo.176.2022.02.21.02.03.05; Mon, 21 Feb 2022 02:03:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=LdmzQHXB; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S244321AbiBUIZ2 (ORCPT + 99 others); Mon, 21 Feb 2022 03:25:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:38022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242262AbiBUIZ0 (ORCPT ); Mon, 21 Feb 2022 03:25:26 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2075.outbound.protection.outlook.com [40.107.236.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2FA1219B; Mon, 21 Feb 2022 00:25:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kcUb4351a4Ud51brDMuhbsmnlF/KBnIAVI2jpqiT67Vngzoz75ASuLL6INf3VzvfGOG8horivleZx6W8AV8duXs5qHykWHgkVMUHOyY6hP6o7grY6h9OUtkb2TDNSFhKk9i52BzHy7PCcuhCd4gRPXHPpGCpJV/+Apa4jjHbTV7ULZBnxGB+4UcZinx9reUDSJvzorCPi04qQwOnnl6DyNuY/4pMqCe5z7MMChCAy9Uc5zWTiK6lNdUQy19DFZEAZ1u8IGrGEJAug7PIMICGDqjb3Rh5wwTiSqhrJVcfLX6/BeOa1T84r9x2mcEoSoVnFdsrMahdKn4Srpw/tEzF5A== 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=5OEVVJ/IdAuoLTgcNxL7S4kTR12vJyAKLaqR1j1/plQ=; b=aDN4K5JDc2QXTeSv/XnPLLo3HfFbVlBs9cEN8yLUNahUGE2btGrO0Z8cU82LknALaXz6gqYjI4zKH400YTgputPha7bgqaGNrhHsbaOw2dM9HY4LoWyhwfE0n8UjF2f72ofLWJAa4r6PWR7NuA5lDWro/A6GvNeqRBEW5ehPwP2IxQJ/P/Y+c/IOycEc1H9dq1+Feu9VPl/pzehRZt2Mr9zihkoSZqwnJk/yOjAtMwPda+jAdyTjWLVmzmTeTRNlytuPZrNQyh5sbixYpxPjjQDydZLbzWNStJ04eVKyTCPdvM1/fLZ2xmG5GFpc/Q4C3Sbg9Pgr+Gxd4H7mzJ60Hg== 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=5OEVVJ/IdAuoLTgcNxL7S4kTR12vJyAKLaqR1j1/plQ=; b=LdmzQHXB3/hhySCNVR8oy5jQVPpRgY88kd099lAfzqjGXLxVQON8i++8hGV4uQlcHUaQOhm1msrVo4akOynDU6AwJlVdiiB5mHkM6vdx28Qg4OnWypQHKxwWgP/NtT9pq9AslT1MBWJXXYfHCgV5aIYdrBeDdUbZiogvUls23RQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) by BYAPR12MB4709.namprd12.prod.outlook.com (2603:10b6:a03:98::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.26; Mon, 21 Feb 2022 08:24:58 +0000 Received: from BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::e03f:901a:be6c:b581]) by BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::e03f:901a:be6c:b581%6]) with mapi id 15.20.4995.027; Mon, 21 Feb 2022 08:24:58 +0000 Message-ID: <25ffdb03-b767-9e64-a636-55df2edc0d4c@amd.com> Date: Mon, 21 Feb 2022 09:24:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] drm/amdgpu: check vm bo eviction valuable at last Content-Language: en-US To: Qiang Yu , =?UTF-8?Q?Christian_K=c3=b6nig?= Cc: David Airlie , "Pan, Xinhui" , Linux Kernel Mailing List , dri-devel , linaro-mm-sig@lists.linaro.org, Qiang Yu , amd-gfx@lists.freedesktop.org, Daniel Vetter , Alex Deucher , Sumit Semwal , linux-media@vger.kernel.org References: <20220217090440.4468-1-qiang.yu@amd.com> <5d3fdd2c-e74a-49f4-2b28-32c06483236f@amd.com> <6711073b-8771-5750-33f7-b72333b411c6@amd.com> <47c3a681-379e-18d4-86da-c48721081911@gmail.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: AM6P193CA0051.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:8e::28) To BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f0cad0cb-c090-42f7-7e9e-08d9f513a566 X-MS-TrafficTypeDiagnostic: BYAPR12MB4709: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: E1QNRDcBeZdKyzaalbgy5hH/yE0o6xnI8JeIhwiTqHipE+QX4vp9152u53N5yaLxyegIqBKHoT+OWQXfFjUNzllgtfz7OcJ+0AabZSrq14UR59nAaPbvr0DPD27vW+WJ5vx1iWBM9HZsYxeQfCgw7PPIBV/zMdOxbPk2wwQRCfmBPBBQm5kRcyp9uK60VD1cB3hVwc4CKPl6qg7BGnvf7Vv/QXUNhhy4zjRH3Vv/TummcrbCyvxYFHQduaTrKXaScr32NtYH+t8GIANhJbWcgzZQvMwNAQx8PWwvCJ5mbbIw/eN5Mrjw9SqLAnTKQDm+KFj3S9ie/DR1gLsB2D9/qK2YimxuZrVmIFBxTtERaYIoF2FnE1QrjzWnpOwuBAHmMJ1ccbmvWiDaU6Wq4VZWJYzKwVRbfkZXkqOL/nATnYHcq0TMs3yooRE0bgIf4ums0N8UTXzoTWJ4RIg2bkdZTOxEATrXxZWi3veSVVdfJRNsyiSTI6Q5KKi8X1fRL1dEgRcWod+ZBtddoH/TzkYa89TpGZSuVygwf7icrw6bnHstG4D7GaxX2t89hOaftkgq1inpQ2Lxk9jFC3HuO27z/KumdIeQ3Qjre8hKAddRVeGIOBqlqgoPKYPh5J9sJXYZ7enqGwIl5ErNcgucXbCbxPAXkpiNve01VTiFQZbdl7SMeoko2xJRvAISK6SkK8O6aG8nmGyMkRp5wQ+Y1N3zDJpPDarIgFeWlblYO0figSPexW2NVwMz5/f06vlp9xfe X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3587.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(6666004)(6512007)(31696002)(6486002)(508600001)(6506007)(86362001)(66574015)(83380400001)(38100700002)(53546011)(186003)(26005)(2616005)(5660300002)(7416002)(8936002)(30864003)(8676002)(66946007)(66476007)(66556008)(4326008)(36756003)(31686004)(54906003)(2906002)(316002)(110136005)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?dm9IaDRjbys4b3UvNmxYYkkvVmZQbUFERUs1TWNjbFlWdlRXOWprME1sL0lE?= =?utf-8?B?QkhNZ0c2eXJMa1Z1UXN6LzJBakc3cnJtVjVTbXBPSE1Mcjk0Z1lHemo4TmJN?= =?utf-8?B?MjdQeDRPMXBnczBYZE5UbnlHVUllN3RFZHd2bk1PSG1VN2JVVXZWVHNXY042?= =?utf-8?B?T1l5MlNqalo1YkwwaEtFeTRYb2g2b1h4bWU1TFBVZHBOTUptMDBleVNGQVBX?= =?utf-8?B?bzE3RUl3ek41d0c3dHMzU3RwaS9FMWhUNmdjSVFjNlZxT2k4L2MvbDRLazR6?= =?utf-8?B?Q3RvamMxSUFNU2VpU2x6QStJWGxDZWU1NzlKdDdPQk00N2pNNDI5dmRKSDc4?= =?utf-8?B?S1RlSHY3c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f0cad0cb-c090-42f7-7e9e-08d9f513a566 X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3587.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Feb 2022 08:24:58.0589 (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: I3FeNYtehwlqtVQCeb8WZTmeMR1Pcgxmynx+qu99BYLwe/sQgq73hPjGm4J5M7vR X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB4709 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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-kernel@vger.kernel.org Am 21.02.22 um 04:28 schrieb Qiang Yu: > On Fri, Feb 18, 2022 at 6:24 PM Christian König > wrote: >> Am 18.02.22 um 11:16 schrieb Qiang Yu: >>> [SNIP] >>>>> If amdgpu_vm_ready() use evicting flag, it's still not equivalent to check >>>>> vm idle: true -> vm idle, false -> vm may be idle or busy. >>>> Yeah, but why should that be relevant? >>>> >>>> The amdgpu_vm_ready() return if we can do page table updates or not. If >>>> the VM is idle or not is only relevant for eviction. >>>> >>>> In other words any CS or page table update makes the VM busy, but that >>>> only affects if the VM can be evicted or not. >>>> >>> My point is: we can't use amdgpu_vm_ready() to replace vm_is_busy(), so >>> currently we update vm even when vm is busy. So why not use: > Sorry, should be "vm is idle". > >>> if (!amdgpu_vm_ready() || vm_is_busy()) return; >>> in amdgpu_gem_va_update_vm(), as you mentioned we prefer to not >>> update vm when it's idle. >> Because updating the VM while it is busy is perfectly fine, we do it all >> the time. >> > Yeah, as above, my typo. > >> We should just not update it when it is already idle and was considered >> for eviction. > "and", not "or"? > >> In this situation it makes most of the time sense to keep >> it idle and postpone the update till the next command submission. >> >>>>>>> Then we can keep the evicting flag accurate (after solving your >>>>>>> concern for this patch that eviction may fail latter by further delay >>>>>>> the flag update after eviction success). >>>>>> That won't work. See we need to mark the VM as evicted before we >>>>>> actually evict them because otherwise somebody could use the VM in >>>>>> parallel and add another fence to it. >>>>>> >>>>> I see, make this too accurate should cost too much like holding the >>>>> eviction_lock when eviction. But just delay it in >>>>> amdgpu_ttm_bo_eviction_valuable() >>>>> could avoid most false positive case. >>>> Partially correct. Another fundamental problem is that we can't hold the >>>> eviction lock because that would result in lock inversion and potential >>>> deadlock. >>>> >>>> We could set the flag later on, but as I said before that when we set >>>> the evicted flag when the VM is already idle is a desired effect. >>>> >>> As above, this confuse me as we can explicitly check vm idle when >>> user update vm, why bother to embed it in evicting flag implicitly? >> Well as I said it's irrelevant for the update if the VM is idle or not. >> >> To summarize the rules once more: >> 1. When VM page tables are used by CS or page tables updates it is >> considered busy, e.g. not idle. >> >> 2. When we want to evict a VM it must be idle. As soon as we considered >> this we should set the evicted flag to make sure to keep it idle as much >> as possible. >> >> 3. When we want to update the page tables we just need to check if the >> VM is idle or not. >> > But now we does not check vm idle directly in amdgpu_gem_va_update_vm(). > If VM bo has not been considered for eviction, it could be either idle or busy. > > Just want to confirm if the fix should be only change amdgpu_vm_ready() > to use evicting flag or besides using evicting flag, also check vm_idle() in > amdgpu_gem_va_update_vm(). Only changing the amdgpu_vm_ready() should be enough. It can be that this then bubbles up more issue, but those need to be taken care of separately then. Regards, Christian. > > Regards, > Qiang > >> 4. When a CS happens we don't have another chance and make the VM busy >> again. And do all postponed page table updates. >> > Anyway, > >> Regards, >> Christian. >> >>> Check vm idle need to hold resv lock. Read your patch for adding >>> evicting flag is to update vm without resv lock. But user vm ops in >>> amdgpu_gem_va_update_vm() do hold the resv lock, so the difference >>> happens when calling amdgpu_vm_bo_update_mapping() from >>> svm_range_(un)map_to_gpu(). So embed vm idle in evicting flag >>> is for svm_range_(un)map_to_gpu() also do nothing when vm idle? >> >> >>> Regards, >>> Qiang >>> >>>> Regards, >>>> Christian. >>>> >>>>> Regards, >>>>> Qiang >>>>> >>>>>> Regards, >>>>>> Christian. >>>>>> >>>>>>> Regards, >>>>>>> Qiang >>>>>>> >>>>>>> >>>>>>>> Regards, >>>>>>>> Christian. >>>>>>>> >>>>>>>>> Regards, >>>>>>>>> Qiang >>>>>>>>> >>>>>>>>>> Regards, >>>>>>>>>> Christian. >>>>>>>>>> >>>>>>>>>>> Regards, >>>>>>>>>>> Qiang >>>>>>>>>>> >>>>>>>>>>>> Regards, >>>>>>>>>>>> Christian. >>>>>>>>>>>> >>>>>>>>>>>>> Regards, >>>>>>>>>>>>> Qiang >>>>>>>>>>>>> >>>>>>>>>>>>>> What we should rather do is to fix amdgpu_vm_ready() to take a look at >>>>>>>>>>>>>> the flag instead of the linked list. >>>>>>>>>>>>>> >>>>>>>>>>>>>> Regards, >>>>>>>>>>>>>> Christian. >>>>>>>>>>>>>> >>>>>>>>>>>>>>> Signed-off-by: Qiang Yu >>>>>>>>>>>>>>> --- >>>>>>>>>>>>>>> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 85 ++++++++++++++----------- >>>>>>>>>>>>>>> 1 file changed, 47 insertions(+), 38 deletions(-) >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c >>>>>>>>>>>>>>> index 5a32ee66d8c8..88a27911054f 100644 >>>>>>>>>>>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c >>>>>>>>>>>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c >>>>>>>>>>>>>>> @@ -1306,45 +1306,11 @@ uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm, >>>>>>>>>>>>>>> return flags; >>>>>>>>>>>>>>> } >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> -/* >>>>>>>>>>>>>>> - * amdgpu_ttm_bo_eviction_valuable - Check to see if we can evict a buffer >>>>>>>>>>>>>>> - * object. >>>>>>>>>>>>>>> - * >>>>>>>>>>>>>>> - * Return true if eviction is sensible. Called by ttm_mem_evict_first() on >>>>>>>>>>>>>>> - * behalf of ttm_bo_mem_force_space() which tries to evict buffer objects until >>>>>>>>>>>>>>> - * it can find space for a new object and by ttm_bo_force_list_clean() which is >>>>>>>>>>>>>>> - * used to clean out a memory space. >>>>>>>>>>>>>>> - */ >>>>>>>>>>>>>>> -static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, >>>>>>>>>>>>>>> - const struct ttm_place *place) >>>>>>>>>>>>>>> +static bool amdgpu_ttm_mem_eviction_valuable(struct ttm_buffer_object *bo, >>>>>>>>>>>>>>> + const struct ttm_place *place) >>>>>>>>>>>>>>> { >>>>>>>>>>>>>>> unsigned long num_pages = bo->resource->num_pages; >>>>>>>>>>>>>>> struct amdgpu_res_cursor cursor; >>>>>>>>>>>>>>> - struct dma_resv_list *flist; >>>>>>>>>>>>>>> - struct dma_fence *f; >>>>>>>>>>>>>>> - int i; >>>>>>>>>>>>>>> - >>>>>>>>>>>>>>> - /* Swapout? */ >>>>>>>>>>>>>>> - if (bo->resource->mem_type == TTM_PL_SYSTEM) >>>>>>>>>>>>>>> - return true; >>>>>>>>>>>>>>> - >>>>>>>>>>>>>>> - if (bo->type == ttm_bo_type_kernel && >>>>>>>>>>>>>>> - !amdgpu_vm_evictable(ttm_to_amdgpu_bo(bo))) >>>>>>>>>>>>>>> - return false; >>>>>>>>>>>>>>> - >>>>>>>>>>>>>>> - /* If bo is a KFD BO, check if the bo belongs to the current process. >>>>>>>>>>>>>>> - * If true, then return false as any KFD process needs all its BOs to >>>>>>>>>>>>>>> - * be resident to run successfully >>>>>>>>>>>>>>> - */ >>>>>>>>>>>>>>> - flist = dma_resv_shared_list(bo->base.resv); >>>>>>>>>>>>>>> - if (flist) { >>>>>>>>>>>>>>> - for (i = 0; i < flist->shared_count; ++i) { >>>>>>>>>>>>>>> - f = rcu_dereference_protected(flist->shared[i], >>>>>>>>>>>>>>> - dma_resv_held(bo->base.resv)); >>>>>>>>>>>>>>> - if (amdkfd_fence_check_mm(f, current->mm)) >>>>>>>>>>>>>>> - return false; >>>>>>>>>>>>>>> - } >>>>>>>>>>>>>>> - } >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> switch (bo->resource->mem_type) { >>>>>>>>>>>>>>> case AMDGPU_PL_PREEMPT: >>>>>>>>>>>>>>> @@ -1377,10 +1343,53 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, >>>>>>>>>>>>>>> return false; >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> default: >>>>>>>>>>>>>>> - break; >>>>>>>>>>>>>>> + return ttm_bo_eviction_valuable(bo, place); >>>>>>>>>>>>>>> } >>>>>>>>>>>>>>> +} >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> - return ttm_bo_eviction_valuable(bo, place); >>>>>>>>>>>>>>> +/* >>>>>>>>>>>>>>> + * amdgpu_ttm_bo_eviction_valuable - Check to see if we can evict a buffer >>>>>>>>>>>>>>> + * object. >>>>>>>>>>>>>>> + * >>>>>>>>>>>>>>> + * Return true if eviction is sensible. Called by ttm_mem_evict_first() on >>>>>>>>>>>>>>> + * behalf of ttm_bo_mem_force_space() which tries to evict buffer objects until >>>>>>>>>>>>>>> + * it can find space for a new object and by ttm_bo_force_list_clean() which is >>>>>>>>>>>>>>> + * used to clean out a memory space. >>>>>>>>>>>>>>> + */ >>>>>>>>>>>>>>> +static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, >>>>>>>>>>>>>>> + const struct ttm_place *place) >>>>>>>>>>>>>>> +{ >>>>>>>>>>>>>>> + struct dma_resv_list *flist; >>>>>>>>>>>>>>> + struct dma_fence *f; >>>>>>>>>>>>>>> + int i; >>>>>>>>>>>>>>> + >>>>>>>>>>>>>>> + /* Swapout? */ >>>>>>>>>>>>>>> + if (bo->resource->mem_type == TTM_PL_SYSTEM) >>>>>>>>>>>>>>> + return true; >>>>>>>>>>>>>>> + >>>>>>>>>>>>>>> + /* If bo is a KFD BO, check if the bo belongs to the current process. >>>>>>>>>>>>>>> + * If true, then return false as any KFD process needs all its BOs to >>>>>>>>>>>>>>> + * be resident to run successfully >>>>>>>>>>>>>>> + */ >>>>>>>>>>>>>>> + flist = dma_resv_shared_list(bo->base.resv); >>>>>>>>>>>>>>> + if (flist) { >>>>>>>>>>>>>>> + for (i = 0; i < flist->shared_count; ++i) { >>>>>>>>>>>>>>> + f = rcu_dereference_protected(flist->shared[i], >>>>>>>>>>>>>>> + dma_resv_held(bo->base.resv)); >>>>>>>>>>>>>>> + if (amdkfd_fence_check_mm(f, current->mm)) >>>>>>>>>>>>>>> + return false; >>>>>>>>>>>>>>> + } >>>>>>>>>>>>>>> + } >>>>>>>>>>>>>>> + >>>>>>>>>>>>>>> + /* Check by different mem type. */ >>>>>>>>>>>>>>> + if (!amdgpu_ttm_mem_eviction_valuable(bo, place)) >>>>>>>>>>>>>>> + return false; >>>>>>>>>>>>>>> + >>>>>>>>>>>>>>> + /* VM bo should be checked at last because it will mark VM evicting. */ >>>>>>>>>>>>>>> + if (bo->type == ttm_bo_type_kernel) >>>>>>>>>>>>>>> + return amdgpu_vm_evictable(ttm_to_amdgpu_bo(bo)); >>>>>>>>>>>>>>> + >>>>>>>>>>>>>>> + return true; >>>>>>>>>>>>>>> } >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> static void amdgpu_ttm_vram_mm_access(struct amdgpu_device *adev, loff_t pos,