Received: by 10.223.185.116 with SMTP id b49csp610515wrg; Fri, 23 Feb 2018 04:06:38 -0800 (PST) X-Google-Smtp-Source: AH8x2265+9TXkeVdHDGgdJaqydZktJNafZu4LbiXsEyr75ki0Kyypwd9IZs/M+/T12zAuDahoP01 X-Received: by 10.99.116.22 with SMTP id p22mr1306277pgc.132.1519387598086; Fri, 23 Feb 2018 04:06:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519387598; cv=none; d=google.com; s=arc-20160816; b=s4ZP9COzXOGjjj5a7vJYVSI6H/OXyuJ8rXn39t+qxio99CmpVBUVZ3R9gVqrO3nG8B z1KDuGw3a5ivnVlZ7VQFwCDd7XRjSAS2pDjNHnUMnUH6fdChcTgi8Ls6s74qRbgwQs0M yOvGBN5awWjI0z4TauLThDSzR4X+NB0dJWfQiqAQXWKGQjXeYlvmNCSIez7+gZXjBxbp k/h4VAFKLZi+5xSnuETAA6Jhdug5GjHlZfGT5ULlsPHmJrHuA8kQKZZtJesockl8/k09 fc+O8lQQ/UOTwiLicLouFeWPS18UjF1CPmzzTu2IRDBxsX+RgENzxCMW9nOydv6sRK/2 7g+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:reply-to:dkim-signature :arc-authentication-results; bh=2lVbnL0iRcXVgh8LbbRkPrNU4/55k8/xwKzvL6PBrY8=; b=k5Xw2VBkCyedtuEPOYOFA/PISCdOf9JpPJ5H+on+PAkacydvDUUp6Zyys+FczOh9ee BxaM3lqOVHrr14NhnrTUG+UMlIMVP43vGznmhiNg3xswDwjK2HGHAWZzeKr26xObPsH7 C7t5nZo/FC89hyOFlIsc0SAko62o7vqQqkR81AqieYcYNgojtDggR7IDmlS77QElW3jA IEiQEyCr7QhEUbneVKk33SKLYoDCjaVHULMbpDr6olNe3FV/UC1VsCkAZtl9DNVHcTvL rlNova+9FR/HouJSLcgdXZFwGMS79ilbIzrB1YFveLKkmASWJD9abq8ilmg0yvawC/4V SOSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WO3Ql6eK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c12-v6si1689918plo.278.2018.02.23.04.06.23; Fri, 23 Feb 2018 04:06:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WO3Ql6eK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751378AbeBWMFn (ORCPT + 99 others); Fri, 23 Feb 2018 07:05:43 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35236 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750903AbeBWMFm (ORCPT ); Fri, 23 Feb 2018 07:05:42 -0500 Received: by mail-wm0-f66.google.com with SMTP id x7so1887944wmc.0 for ; Fri, 23 Feb 2018 04:05:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=reply-to:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=2lVbnL0iRcXVgh8LbbRkPrNU4/55k8/xwKzvL6PBrY8=; b=WO3Ql6eK3eyB+CvOlfsQ0xowlzPy5qOf+HUoeppjzph0zE0G3xusIfV+Ku2UiPZSG0 YMCqQsRwX90n8KQFbhHlZUJgeD5f7xI3iNp6DLQ4joUf36ceN6Glw9H5AjSfauRlP3YT hsU7QRO/yqqNM51wOTdgSXzRHpw3b7BEB1JI1Ww+JOiXjFjKyPn4BTxFQvdPcKtAURQz 68StFBZ7e0JkxRGxLrU5e7WAUoj4pRmVBUnj6doZydZhck0OOinrebqS3b+1ZmLX1QKT z4JLoDG5B7hXpE5sD1U6V01S83yWXyvpenyHM+UX0LMVQqwmZZPbvpzP7yTwlMvzwCnv 8YDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=2lVbnL0iRcXVgh8LbbRkPrNU4/55k8/xwKzvL6PBrY8=; b=Wxw1SYmTZhbw7Z44BbD+NuV4FEG2DaAHLBdv0npbsHw5R/lANJ6w5Y4gnKu7J+S6YZ YUfm7xHAPXN+kSkU5VOExMGMoX3/L9et4dI16S7LmhPQO0I9o91J5C90Qa9XP98JoTBD eMutPwWC5DeoGN+gTP4n11ls+7rNBsDNtnl7ye4PIFKtX9L9qzsQ5Xcohqsym9gANBM2 ZU7GATYBeasW1iIJ1/gHHjDVXSvr71lQ5pxg35ygLmZ79xgntzHAv3vaLozIKqtot+eI S2pYREPVdQhnV81kuE0IfKUNYv/qBIzSBv4GSywtUSFW8doGoDO3m9+FKbNli5/5ozak GrhQ== X-Gm-Message-State: APf1xPCIkBCjhy3+vuubPoZpxMVt35H1TZkk3SglSh0kRT96xdfUGJpG W2E3uHKR+YlA0LefnMSDyLoySPs/ X-Received: by 10.28.96.65 with SMTP id u62mr1508066wmb.82.1519387540865; Fri, 23 Feb 2018 04:05:40 -0800 (PST) Received: from ?IPv6:2a02:908:1251:8fc0:4c6d:7233:b7e1:3b88? ([2a02:908:1251:8fc0:4c6d:7233:b7e1:3b88]) by smtp.gmail.com with ESMTPSA id s9sm2133345wra.4.2018.02.23.04.05.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Feb 2018 04:05:40 -0800 (PST) Reply-To: christian.koenig@amd.com Subject: Re: [PATCH 3/4] drm/ttm: handle already locked BOs during eviction and swapout. To: "He, Roger" , "amd-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" References: <20180220125829.27060-1-christian.koenig@amd.com> <20180220125829.27060-3-christian.koenig@amd.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: <6eadbbea-8eca-a1ab-93bb-d37ae6e5f29d@gmail.com> Date: Fri, 23 Feb 2018 13:05:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 23.02.2018 um 10:46 schrieb He, Roger: > > -----Original Message----- > From: dri-devel [mailto:dri-devel-bounces@lists.freedesktop.org] On Behalf Of Christian K?nig > Sent: Tuesday, February 20, 2018 8:58 PM > To: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org > Subject: [PATCH 3/4] drm/ttm: handle already locked BOs during eviction and swapout. > > This solves the problem that when we swapout a BO from a domain we sometimes couldn't make room for it because holding the lock blocks all other BOs with this reservation object. > > Signed-off-by: Christian König > --- > drivers/gpu/drm/ttm/ttm_bo.c | 33 ++++++++++++++++----------------- > 1 file changed, 16 insertions(+), 17 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index d90b1cf10b27..3a44c2ee4155 100644 > --- a/drivers/gpu/drm/ttm/ttm_bo.c > +++ b/drivers/gpu/drm/ttm/ttm_bo.c > @@ -713,31 +713,30 @@ bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, EXPORT_SYMBOL(ttm_bo_eviction_valuable); > > /** > - * Check the target bo is allowable to be evicted or swapout, including cases: > - * > - * a. if share same reservation object with ctx->resv, have assumption > - * reservation objects should already be locked, so not lock again and > - * return true directly when either the opreation allow_reserved_eviction > - * or the target bo already is in delayed free list; > - * > - * b. Otherwise, trylock it. > + * Check if the target bo is allowed to be evicted or swapedout. > */ > static bool ttm_bo_evict_swapout_allowable(struct ttm_buffer_object *bo, > - struct ttm_operation_ctx *ctx, bool *locked) > + struct ttm_operation_ctx *ctx, > + bool *locked) > { > - bool ret = false; > + /* First check if we can lock it */ > + *locked = reservation_object_trylock(bo->resv); > + if (*locked) > + return true; > > - *locked = false; > + /* Check if it's locked because it is part of the current operation */ > if (bo->resv == ctx->resv) { > reservation_object_assert_held(bo->resv); > - if (ctx->allow_reserved_eviction || !list_empty(&bo->ddestroy)) > - ret = true; > - } else { > - *locked = reservation_object_trylock(bo->resv); > - ret = *locked; > + return ctx->allow_reserved_eviction || > + !list_empty(&bo->ddestroy); > } > > - return ret; > + /* Check if it's locked because it was already evicted */ > + if (ww_mutex_is_owned_by(&bo->resv->lock, NULL)) > + return true; > > For the special case: when command submission with Per-VM-BO enabled, > All BOs a/b/c are always valid BO. After the validation of BOs a and b, > when validation of BO c, is it possible to return true and then evict BO a and b by mistake ? > Because a/b/c share same task_struct. No, that's why I check the context as well. BOs explicitly reserved have a non NULL context while BOs trylocked for swapout have a NULL context. Christian. > > Thanks > Roger(Hongbo.He) > > + /* Some other thread is using it, don't touch it */ > + return false; > } > > static int ttm_mem_evict_first(struct ttm_bo_device *bdev, > -- > 2.14.1 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel