Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp357239pxb; Thu, 17 Feb 2022 05:47:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwVmL6/kfwjIiRdDwdM1RytvqH5ZNfFqQEztQY5MnsayhgLeW0solEOIO2WYOvrXIlpwXav X-Received: by 2002:a17:906:2ed1:b0:6b6:bb09:178c with SMTP id s17-20020a1709062ed100b006b6bb09178cmr2397769eji.382.1645105637284; Thu, 17 Feb 2022 05:47:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1645105637; cv=pass; d=google.com; s=arc-20160816; b=yxK5d78DMVWaI7EiZ8o0VSDEXhnQn+CHX0/Xsd4/yI54P3WQxVDccUl2NVIFd0lOF1 8GaLFDzAxa54fZHGhMsIPMKahvZS3h0eCeLRpe1k0wLf8wCBg29x+R6Lpev9MOxwUQHr DWk2hEQdzRQvirRYnsqpMG/w7YH61LZwZHLFagcIZlxQyBm8y6cJ8I0dl2QNVcnkpeq5 eT2rweuTm6jz+42pOdrTaHcpZoEB4GDxJ3lfU8BEXIFjJBiClL0R9W5xFUu36C32f330 HsnkDTFKHZ0OFIhMr5+foiQv5onjrlSIbwr1tEWNR25mB70yDjzQHByg3whuVPwaNVAq 8VaA== 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=q3zcdJPCJOstr98GMCTNjmDXCHX9DFbXjseFSjDGSj4=; b=ysguvRhWRfgrOlQzJ7Ha6AA0MbT6qu/I38qAjssCyKgu17Ytl6485G9LNiQLDgL+ZU f1E8kWGd4jq7xLGPcFtthFqB8d94AFrWAj1NosBk1z6p/of3fP3OIsSWmHmYv/T13OI4 iGdIsq3bnmyeXM0b4jWBPLodwc/kevGsOTJkRY+Y8buXIExriI9rgbpvTiwKJVW3Lwoz lU3wBkrkdrsNdkoDI5WJABI4v7sxal1kNzGHb/3TBRTLaSfYD15VLZTh+OS0LLQxfLdz +2uaF9EJv6Nd/Ztp9dlHhItses4VaiI2vBQbEzP8cXqM56Eua465MshK+GVAb8TzYMRS xSEw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=kH0f5jyP; 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 f7si1734368ejc.626.2022.02.17.05.46.50; Thu, 17 Feb 2022 05:47:17 -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=kH0f5jyP; 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 S240378AbiBQMWw (ORCPT + 99 others); Thu, 17 Feb 2022 07:22:52 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232805AbiBQMWu (ORCPT ); Thu, 17 Feb 2022 07:22:50 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2055.outbound.protection.outlook.com [40.107.96.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 781F41CC287; Thu, 17 Feb 2022 04:22:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R155Mwu9aZdcf+55UJqme94HxyiR5NOD19F4lacdHqMZ/k+/lq3BrPIrsj7TlVbCVgt11M+C1dPfI1n1e1ECQN/wlf0DtnhiAANdAnWkeTvqYWXuSSC/F5SakmiZpdY8aiuKjO8H2o0fgSnXozCXj5dgvKkJKcujaKB9V3eIPxL0LCsqJxhcrqmq8jUQ1Y+FrRNwj4aBFFyP9kwPU+k78S55aazQg1cE27OYcJMqvljPJ0kkwnUrMfq4NGLdbrcrHhB9M8wtO8ARqGYDWwAt0Cw2RAK/AVc+wS6VWq/XouR4u16yj9kQa5M4Fs9/2OBrhWYYje7HsKaNS5QPnGHfAg== 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=q3zcdJPCJOstr98GMCTNjmDXCHX9DFbXjseFSjDGSj4=; b=ItWyLyV/IxZ0ai1um0ef9tM4ManGUxXP11BaKHHjxAvGBT1m3tbfGDkqw3Q/sPCoCZtRk2XPAdek1kuW6/kDArukDD60mRkQUZGhf88lTore9kl9ckjRwGw5oq6b3BNCTYLl+Ntg0gCOZQi5D1semiKdSIPTIeS5z4DldNqi6mJk6ZqnKZ3OMm4bBqysKpekJs6wgYcIKJ0QDvqYEE5Qf0McEmUdex50Av9Q9lS1zh/0sDbdSgd0JIQqDkBdTdhvhlTmNcopia7yaSRB0Ud7faqne6rxNOPWJFQMnVz5kBBN+tsVd1YlPqrUrk1eycMzu+SqUMxWMPQBb3S8YSScRg== 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=q3zcdJPCJOstr98GMCTNjmDXCHX9DFbXjseFSjDGSj4=; b=kH0f5jyPmAqgYrNMubOn6li3FcOdTC8Q9nGhjOo9fNkhehlsHpWbIxhvcr1Ym/v/V+T2/IX3Rr2WFrC5UQpVvNm8hs89gMzPlCuOnluHso8p/2Py0sEc5NlqFbyQKUxvch5XiXt8KySAggpUyhNpu6g368uXeb765igldSV0LFQ= 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 DM5PR12MB1146.namprd12.prod.outlook.com (2603:10b6:3:73::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.16; Thu, 17 Feb 2022 12:22:29 +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.018; Thu, 17 Feb 2022 12:22:29 +0000 Message-ID: <6711073b-8771-5750-33f7-b72333b411c6@amd.com> Date: Thu, 17 Feb 2022 13:22:21 +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 Cc: Qiang Yu , Alex Deucher , "Pan, Xinhui" , David Airlie , Daniel Vetter , Sumit Semwal , linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, dri-devel , amd-gfx@lists.freedesktop.org, Linux Kernel Mailing List References: <20220217090440.4468-1-qiang.yu@amd.com> <5d3fdd2c-e74a-49f4-2b28-32c06483236f@amd.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: AS9PR06CA0308.eurprd06.prod.outlook.com (2603:10a6:20b:45b::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: 2be9605a-a226-44dc-dbce-08d9f2102a1e X-MS-TrafficTypeDiagnostic: DM5PR12MB1146:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eKi6BcOTnRzMQRi2jWxt7ffOpirWmtWdDmffcmNEuwMRneJT8YvVNI0bEy7L0STQ+gbBqRazwwe00NJ4+VEMpk92K8dFRKgky5Agj/gDEwb11H2ufbvnlizR6XXwlJSFtbXdFaGoRG5hOdF64V+FnCyOLlo2sJK7t3SW9h2WK9Q+/z43Zhb1LmIIgeLP+vx4ovtqQc5dFoTGS7ejDKxLRsTAGr8ECFXlJUzij20EFbnGST2DBxGo19s5udTNYsY3jj7d7RVNY4jqMNBoQUd1atAlpYigpmJrOFzfBmXfkfDDoup6hsPbReSms7JiB1owoLZdvpjQqpOdKjytBaHpnnXk463yf6S50mjxV80cwoJaaMXKJiIu178BM7d2fFZcJaXCW8IgOu9e7zyoyZ0OtgFEG3v9c3TU8HWYzd/dhZoEqbNvrVmCB39UR8WgsTcXHraMEblzM5wge2Z+WRxSiDOfLgWDfr7HEb0Cd/Q/uYlBqYSqJm2kR1YCUghipEQjqC3wbKao9YQ4vwqTqyiBMkNG/D7+CBWE1kxeGkykOu6ZbHOgVxEwtMa3AyGdwz8MXknhAhBJxK0uAsjjdl8+jgUTNlMVJxJ5rhoM9uSHLPsCQSl1BhpvFuof2dupQMy6B+43AsiI7eiaCN6vF8EyTbzDFbS1yJstPopwPg8WjJQFbRd2WZWVC6Cq+2bsRxIsNCGq8KcMSbZbpXsJZ5G8Aym42SraA80KTI61eV4kIDU= 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)(36756003)(66476007)(66574015)(66946007)(6916009)(83380400001)(66556008)(8676002)(4326008)(53546011)(6512007)(86362001)(31686004)(6506007)(38100700002)(6666004)(2906002)(5660300002)(31696002)(6486002)(186003)(2616005)(8936002)(508600001)(316002)(54906003)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?YXRUc0RvU3p2TUozYVpwS25OTTBEL3MyVnh3Z3ljWkJ1ZUFFRTNDK3cxRnMx?= =?utf-8?B?Q1ZTSlhHSTdVNTJ5cnVhaWFlNm5mNjFtTEJyTEZJMG5GaVorcUxpNEd4VW5L?= =?utf-8?B?RVYvelVwQmNSYnZNSmRHdGI1RWhXREtnMENhU2NkeEN6RHh2M00vNndrT0t6?= =?utf-8?B?UEhhaEk0T3ZPRnhsRGpGR2Y0UEVkVERiamhOU1hZWjNSRHNhdWtmS2w0T1Na?= =?utf-8?B?S3I3b1JsWm9TanhhL0NmcGFOOVk1S0VaVytDL3BjN1I4K2NucFE2VHhNbXg5?= =?utf-8?B?RHl5ajlUK2doRytzOUJTbVdqMEdnRHdsS1hzTnZVWVRTUVB3SGJDQldVQ2FC?= =?utf-8?B?K2lCekhSZWdSdmdrMkllSGVoWTRjbXVXMkxsKzE5YUo2dC8zYkZqWVJOOEEx?= =?utf-8?B?Q3lPY2llUkluWlpUcDR1WHV6Szd0aUNpZ21ZL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a-a226-44dc-dbce-08d9f2102a1e X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3587.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 12:22:29.2824 (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: Pvzjqc+M37MD5gHfMmLj5meTcObIcvaD88fMFz9GJZZZEXj8J4wc2rbl6Whj9AkB X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1146 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 17.02.22 um 11:58 schrieb Qiang Yu: > On Thu, Feb 17, 2022 at 6:39 PM Christian König > wrote: >> >> >> Am 17.02.22 um 11:13 schrieb Qiang Yu: >>> On Thu, Feb 17, 2022 at 5:46 PM Christian König >>> wrote: >>>> Am 17.02.22 um 10:40 schrieb Qiang Yu: >>>>> On Thu, Feb 17, 2022 at 5:15 PM Christian König >>>>> wrote: >>>>>> Am 17.02.22 um 10:04 schrieb Qiang Yu: >>>>>>> Workstation application ANSA/META get this error dmesg: >>>>>>> [drm:amdgpu_gem_va_ioctl [amdgpu]] *ERROR* Couldn't update BO_VA (-16) >>>>>>> >>>>>>> This is caused by: >>>>>>> 1. create a 256MB buffer in invisible VRAM >>>>>>> 2. CPU map the buffer and access it causes vm_fault and try to move >>>>>>> it to visible VRAM >>>>>>> 3. force visible VRAM space and traverse all VRAM bos to check if >>>>>>> evicting this bo is valuable >>>>>>> 4. when checking a VM bo (in invisible VRAM), amdgpu_vm_evictable() >>>>>>> will set amdgpu_vm->evicting, but latter due to not in visible >>>>>>> VRAM, won't really evict it so not add it to amdgpu_vm->evicted >>>>>>> 5. before next CS to clear the amdgpu_vm->evicting, user VM ops >>>>>>> ioctl will pass amdgpu_vm_ready() (check amdgpu_vm->evicted) >>>>>>> but fail in amdgpu_vm_bo_update_mapping() (check >>>>>>> amdgpu_vm->evicting) and get this error log >>>>>>> >>>>>>> This error won't affect functionality as next CS will finish the >>>>>>> waiting VM ops. But we'd better make the amdgpu_vm->evicting >>>>>>> correctly reflact the vm status and clear the error log. >>>>>> Well NAK, that is intentional behavior. >>>>>> >>>>>> The VM page tables where considered for eviction, so setting the flag is >>>>>> correct even when the page tables later on are not actually evicted. >>>>>> >>>>> But this will unnecessarily stop latter user VM ops in ioctl before CS >>>>> even when the VM bos are not evicted. >>>>> Won't this have any negative effect when could do better? >>>> No, this will have a positive effect. See the VM was already considered >>>> for eviction because it is idle. >>>> >>>> Updating it immediately doesn't necessarily make sense, we should wait >>>> with that until its next usage. >>>> >>>> Additional to that this patch doesn't really fix the problem, it just >>>> mitigates it. >>>> >>>> Eviction can fail later on for a couple of reasons and we absolutely >>>> need to check the flag instead of the list in amdgpu_vm_ready(). >>> The flag only for both flag and list? Looks like should be both as >>> the list indicate some vm page table need to be updated and could >>> delay the user update with the same logic as you described above. >> I think checking the flag should be enough. The issue is that the list >> was there initially, but to avoid race conditions we added the flag with >> separate lock protection later on. >> > But list and flag does not align always, there are cases like > list-empty/flag-set (this problem) and list-non-empty/flag-unset (non-vm bo > eviction). If only check flag list-non-empty/flag-unset change behavior. Yeah, but I think that the flag unset list-non-empty case would be correctly handled if we only test the flag. In other words we can update the page tables as long as they are not partially or fully evicted and that's not the case when non-vm BOs are evicted. 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,