From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 7E50DC2B9F7 for ; Fri, 28 May 2021 13:06:58 +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 398FF6112F for ; Fri, 28 May 2021 13:06:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 398FF6112F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.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 A72C56F5BB; Fri, 28 May 2021 13:06:57 +0000 (UTC) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by gabe.freedesktop.org (Postfix) with ESMTPS id 77FAA6F5BB for ; Fri, 28 May 2021 13:06:56 +0000 (UTC) IronPort-SDR: hF1cxPC2tJC0jok5FAfRBBEpfCEVDzHobSfwKDlHgXQ06rJu0AUQ6qDb0mGkLq2v2r/+e/SftX uXxVECBo7vOA== X-IronPort-AV: E=McAfee;i="6200,9189,9997"; a="288548707" X-IronPort-AV: E=Sophos;i="5.83,229,1616482800"; d="scan'208";a="288548707" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2021 06:06:51 -0700 IronPort-SDR: wx3VRz31g6+qMCnMFzT3CdWP9lWy/q74GB57uqvRYj/s6F8uXNB5hIMwvoeWQXX6N8k9Yt6stU lFljBs0opI5w== X-IronPort-AV: E=Sophos;i="5.83,229,1616482800"; d="scan'208";a="443991902" Received: from jdahlin-mobl1.ger.corp.intel.com (HELO [10.249.254.92]) ([10.249.254.92]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2021 06:06:49 -0700 Subject: Re: [PATCH] drm/ttm: fix deref of bo->ttm without holding the lock v2 To: =?UTF-8?Q?Christian_K=c3=b6nig?= , dri-devel@lists.freedesktop.org References: <20210528130041.1683-1-christian.koenig@amd.com> From: =?UTF-8?Q?Thomas_Hellstr=c3=b6m?= Message-ID: Date: Fri, 28 May 2021 15:06:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210528130041.1683-1-christian.koenig@amd.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US 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: Xinhui.Pan@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On 5/28/21 3:00 PM, Christian König wrote: > We need to grab the resv lock first before doing that check. > > v2 (chk): simplify the change for -fixes > > Signed-off-by: Christian König > Signed-off-by: Thomas Hellström Hmm, OK, but this doesn't fix the swapped-bo-not-on-lru and unpopulating from swap_notify issues. Are you planning a follow up patch for those? Thanks, Thomas > --- > drivers/gpu/drm/ttm/ttm_bo.c | 5 ++++- > drivers/gpu/drm/ttm/ttm_device.c | 8 +------- > 2 files changed, 5 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c > index cfd0b9292397..ebcffe794adb 100644 > --- a/drivers/gpu/drm/ttm/ttm_bo.c > +++ b/drivers/gpu/drm/ttm/ttm_bo.c > @@ -1172,7 +1172,10 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx, > if (!ttm_bo_evict_swapout_allowable(bo, ctx, &locked, NULL)) > return -EBUSY; > > - if (!ttm_bo_get_unless_zero(bo)) { > + if (!bo->ttm || !ttm_tt_is_populated(bo->ttm) || > + bo->ttm->page_flags & TTM_PAGE_FLAG_SG || > + bo->ttm->page_flags & TTM_PAGE_FLAG_SWAPPED || > + !ttm_bo_get_unless_zero(bo)) { > if (locked) > dma_resv_unlock(bo->base.resv); > return -EBUSY; > diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c > index a1dcf7d55c90..3d9c62b93e29 100644 > --- a/drivers/gpu/drm/ttm/ttm_device.c > +++ b/drivers/gpu/drm/ttm/ttm_device.c > @@ -143,14 +143,8 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx, > > for (j = 0; j < TTM_MAX_BO_PRIORITY; ++j) { > list_for_each_entry(bo, &man->lru[j], lru) { > - uint32_t num_pages; > + uint32_t num_pages = PFN_UP(bo->base.size); > > - if (!bo->ttm || !ttm_tt_is_populated(bo->ttm) || > - bo->ttm->page_flags & TTM_PAGE_FLAG_SG || > - bo->ttm->page_flags & TTM_PAGE_FLAG_SWAPPED) > - continue; > - > - num_pages = bo->ttm->num_pages; > ret = ttm_bo_swapout(bo, ctx, gfp_flags); > /* ttm_bo_swapout has dropped the lru_lock */ > if (!ret)