From patchwork Fri Sep 3 06:49:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Pan, Xinhui" X-Patchwork-Id: 12473727 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.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 0954CC433F5 for ; Fri, 3 Sep 2021 06:49:11 +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 BA3E36101A for ; Fri, 3 Sep 2021 06:49:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BA3E36101A Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DD36F6E847; Fri, 3 Sep 2021 06:49:09 +0000 (UTC) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2059.outbound.protection.outlook.com [40.107.92.59]) by gabe.freedesktop.org (Postfix) with ESMTPS id 299376E846; Fri, 3 Sep 2021 06:49:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gju8j/wqOTDlYXYxARtXpru2P4LbpgzRZlgaQ8W0YpnCpQy0eo2FiEI9Mi5K4mzfa1tGA/qMcM2nxnOMxS+8tOrrRc7XRufsE85VII7AWOyukHKlWFcokMqBCclU5SZoG7hNRyXlfy3PnPi9B+/MwnRSuwoZvlE91rw7CnesrI/UpZtZRdiQTbtG8RLyUl1+PAQMGB/AkE9V9PMDVqIVkc2y4AS25m0A2AVefBGjNFFcAYy7+/Omh6IXOw1aacJFNuomSBQbzP/w2QCrEMQDvpigxVEo9EeGozM9PZjrG/ByuvlqRduvYj7AF9E70dVGMJqFbPMDH8ttVgtCWB0EoQ== 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; bh=BAE6Dsjd4KurK1AUaBh4q9/MK3J4QYUbaNaDGNNA76w=; b=Ck71ULIMX7f5iTv+Kwn2wtN8uR/HEZ+105rMnh6IvTU6YpIvHvelPgCmHofXKRvtfx1QyFvsxiGvEJQCyke/C+4YT7YO+FmWaasCokeHdJYti/Z/lleJ6bvQyZZEyohBsWxc8LxIVsXrufKSfRtXRjxAfXkWlmAHMamAlia8QDpZWPmPvJy4ky8EjOaS+XvbLVoxsegAn4MsP7XvdC6qA8EFmcxpC/0f2n0CAE1Cm4ecIqppA35Z8fBJvkDH6lEUpegNv26IZl8h1xIPpwno6W1vmy8KztXe1LxNIsQVFk46aNwsOzJrm3ez67RSpao0EM9byMNsGFZ8R9cExaCPfg== 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=BAE6Dsjd4KurK1AUaBh4q9/MK3J4QYUbaNaDGNNA76w=; b=JzHNQmKy6Pes6jkIuQinQk9vnr3lDV9/jnJmmQfVr1DyjBee5YKgyDb0S+8hcTBRkPgViM6zu44jhX1P45GeVu5p3oX5OnEA0niL6Au/aINSlTMcPKmDLfMHCoz2bjfvfs7jkisU+axtOWZq07cZUK7Lp655WcHL/+S2qvcPYws= Received: from DM4PR12MB5165.namprd12.prod.outlook.com (2603:10b6:5:394::9) by DM4PR12MB5200.namprd12.prod.outlook.com (2603:10b6:5:397::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17; Fri, 3 Sep 2021 06:49:05 +0000 Received: from DM4PR12MB5165.namprd12.prod.outlook.com ([fe80::79d6:3902:9bcd:37ca]) by DM4PR12MB5165.namprd12.prod.outlook.com ([fe80::79d6:3902:9bcd:37ca%9]) with mapi id 15.20.4478.022; Fri, 3 Sep 2021 06:49:05 +0000 From: "Pan, Xinhui" To: amd-gfx , "dri-devel@lists.freedesktop.org" CC: "Koenig, Christian" , "Deucher, Alexander" , "Grodzovsky, Andrey" , "daniel@ffwll.ch" Subject: [PATCH 1/2] drm/ttm: Fix a deadlock if the target BO is not idle during swap Thread-Topic: [PATCH 1/2] drm/ttm: Fix a deadlock if the target BO is not idle during swap Thread-Index: AQHXoI/JwHjULHp1EE+WUl2cADH7PQ== Date: Fri, 3 Sep 2021 06:49:05 +0000 Message-ID: <88E16111-86C0-41BC-90F9-A0A517894B5B@amd.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Microsoft-MacOutlook/10.1f.0.191110 authentication-results: lists.freedesktop.org; dkim=none (message not signed) header.d=none; lists.freedesktop.org; dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e58017f4-60b6-4c59-896f-08d96ea6ec13 x-ms-traffictypediagnostic: DM4PR12MB5200: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5797; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: hjxl1Ug+8p8Gbq8vg/eKcIZvNIuA2Nm8WwfcuBSxTwL6r/t2aVoZZeR7T3qAtNAeNxshLiUK49CHaWFpqUvJVOQImsGmlbxGw6yrLxQeMzWWrWBwCPNRPlZ1PBSK9H89t0OsluHW4CywXjO3S2UwrJEIWW0+HtnU3/fddIkKPWnU1KpE3z+Ok1afKLi95ZpFg5k/U96V4eU8kJNi4EtPN57MWUa5rKwBTQuudvaWKUL9gPu4ZLreXKqJ+SQMU4H/nZbCcwxHua33FDf7drIaL9Ra4QJIUW79udytGlPEkHgFRWFjHM9XGtBG7xBono7Bf2t/olJV743EKwjXzM4WHE90ZbTFf0SstacKn27wFCLh7/uX6otriU2qgeGRUwqn//sWWLnA/q7UjhbnUjoiuT9sr2WnkAVo1rVFCupNNLHkxMljxkWRteCcRES3TTjNwQU+ZIpnECAlsoYlczcJd91uQnRkagZyFTBHAR2ZlhsEhZkq+Xm5FB637BttoK58+TEfPDGq7h/3mOW0CEx3kLmiWRTUwB7HJQv55Ubh3vjCjzb+z4ymXqpvKVFXus0WKuc9mIXB0Yszrge3DjBlpBJf0s6q9/uplVvUHxHnAJSqDLsoH+c4VtHged1KKiZrdWp2nzYA4rRm45t2t7bco82vINCZYZcYNpkoMDvADt+dMWNBAe3wZ2OLTzuIIAGxTC4gPsY0SeeFOQVjJFQCaSqr6pybqGAnJQ/yeOdvX4k= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR12MB5165.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(39860400002)(346002)(136003)(396003)(366004)(4326008)(8936002)(122000001)(71200400001)(8676002)(54906003)(91956017)(76116006)(64756008)(66476007)(66556008)(66946007)(2616005)(478600001)(83380400001)(5660300002)(66446008)(26005)(36756003)(86362001)(186003)(316002)(38070700005)(4743002)(6486002)(110136005)(6506007)(2906002)(38100700002)(6512007)(33656002)(45980500001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?vc4J4NkJrOf/7y8YO/rN7mwLJdEV?= =?utf-8?q?tF97OVUCgQv8/MFFP3/PCDxQWvVnQ0MxMl25sdk3S01I4+HC4EcQzioiZLRmzyX/J?= =?utf-8?q?DxVt7ZfBZB5LUrplNfzqGy7oOlTBCyq2leX8aalYTuCdH8qoI1uC7WCZvp/PRmbvR?= =?utf-8?q?NifX9UwbIPFXV+qCfHPtgj2d0NLa/sr0gptWG8v8hyxiGbHN+9Y2P+XmkpSIXe6o3?= =?utf-8?q?rwTPZU/eotBL3Y0CQMokOcmj+5+rCGm8aG0FyqPIcpgbBBHi1ZAs0GPM1WKWsV9wv?= =?utf-8?q?MuRZJDQNQh26wTLPXnSYgkAsTzkRCn1I+jGdNispdt20UuzhE4YkM0TOPID8paDEC?= =?utf-8?q?if8I5e8OuLjdHB+Hed1FM5sHegr+QlrWP6dnJrMXBrPw/oQNJ7sv/qeUl+iFwCOze?= =?utf-8?q?CUqwPzulNoH+IyuwWVUdmnm98eoCmg37ipSnq5NrqRu4VdTBMnx33B+ClVR8X2MIp?= =?utf-8?q?3MWzgAYwK5sHB4VdxlkZkvlmM/DDKVRHtwTuUHjLXbBqIFqIFBj/GRonIFU9b+64k?= =?utf-8?q?5nvvGRH3AWnqInmTNcj0nl6KYsDtQOtlHWsk/iitUdku5MMLSYPvkFY2jTgPwt7AS?= =?utf-8?q?2m2xTF/eW9vNV0bt2nuxv2B9XCPKQfm8+tFUYTihxXOIpdDbtF58kOMG5Doi0GKF7?= =?utf-8?q?TC7zvEWP0bX3TyCt9Kfun8ehwaTbqfGbh9aaG4E5ufvVNX3BxmyAHrLf1KqY4xNPN?= =?utf-8?q?dcOLc3joqMoSt7r0MjZ2DEwMH/Cdb5XGQr4PNXiYghP0xNfJ4fLHO5eb58UOBzh7G?= =?utf-8?q?WW/kMpWXSWbrIjJbEnyCJT8zBSdrqC1iArBDgveMB42htdY3Q/RAgsV4Hh0kbbcY7?= =?utf-8?q?h1UHkvrXwyeMX4kVoE1Sjz1WUtRsi7dJYhxE4nQeg5uNca4e33hQXGwFwQqsM5mov?= =?utf-8?q?pKsjYux3XLTDDL/bVJUBLJ3FG6kesM/i11RCdugRvzs/9q6ywkfKJFvzVxlWph+wD?= =?utf-8?q?yFP80BEbN1JQ7toYZhNtyONALAEM8dximcKacrZbC07t/IuR18Kp4/h2WFVI/w7Pv?= =?utf-8?q?WOCXwOjpZ4tl+LsrWsRaxrW7RgdFWVUNlkwJFm5vLtxqRJCLlA3CvB8sReiBciTmU?= =?utf-8?q?oYN5O2FH2SVVfHRl638JLJN3R158W/SjbVDJRBhGjSfGQzxFjPpASo7s6wfdTzMQp?= =?utf-8?q?5mSGDylY7kd60wfL1cfB2MRfhrWWMoJ/LDA0E9DYHJLyFywwDszSGF3u4vB9+JWyJ?= =?utf-8?q?u9t4g0eZNOb5J8TOPs/G8e2Ma04m5twisHFfptEVvvdT1gsv1mRhjI9JY5eObqAm7?= =?utf-8?q?TXPDRTr4J6LgFp5G?= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5165.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e58017f4-60b6-4c59-896f-08d96ea6ec13 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Sep 2021 06:49:05.2193 (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: jO+ICZV+UQSekd6AORSDXTu8g0CktPUdKBzdRNom+FYuII7CQMSsQeL/FsXnr3f5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5200 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The ret value might be -EBUSY, caller will think lru lock is still locked but actually NOT. So return -ENOSPC instead. Otherwise we hit list corruption. ttm_bo_cleanup_refs might fail too if BO is not idle. If we return 0, caller(ttm_tt_populate -> ttm_global_swapout ->ttm_device_swapout) will be stuck as we actually did not free any BO memory. This usually happens when the fence is not signaled for a long time. Signed-off-by: xinhui pan Reviewed-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 1fedd0eb67ba..f1367107925b 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -1159,9 +1159,9 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx, } if (bo->deleted) { - ttm_bo_cleanup_refs(bo, false, false, locked); + ret = ttm_bo_cleanup_refs(bo, false, false, locked); ttm_bo_put(bo); - return 0; + return ret == -EBUSY ? -ENOSPC : ret; } ttm_bo_move_to_pinned(bo); @@ -1215,7 +1215,7 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx, if (locked) dma_resv_unlock(bo->base.resv); ttm_bo_put(bo); - return ret; + return ret == -EBUSY ? -ENOSPC : ret; } void ttm_bo_tt_destroy(struct ttm_buffer_object *bo)