From patchwork Wed Feb 15 16:14:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 13141857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0FE9C636D4 for ; Wed, 15 Feb 2023 16:15:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 392B36B0099; Wed, 15 Feb 2023 11:15:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 341D06B0098; Wed, 15 Feb 2023 11:15:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E49F6B0099; Wed, 15 Feb 2023 11:15:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 058C46B0096 for ; Wed, 15 Feb 2023 11:15:56 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 506DD160471 for ; Wed, 15 Feb 2023 16:15:55 +0000 (UTC) X-FDA: 80470027470.30.C3A6739 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf22.hostedemail.com (Postfix) with ESMTP id E3BC3C001F for ; Wed, 15 Feb 2023 16:15:52 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=RoTmJrHW; spf=none (imf22.hostedemail.com: domain of thomas.hellstrom@linux.intel.com has no SPF policy when checking 134.134.136.31) smtp.mailfrom=thomas.hellstrom@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676477753; a=rsa-sha256; cv=none; b=II8ZWYbtPDsPBqwd9UxxyiY6C+0nhQspe2/ZzdQCtbMb+3HfLmjM+8mYkRkPcuvvggXfEx 51eJ9Bq/didc+AHSYVB2HPqMbBiN7FCtkJ8rJL+yODiLKRvegpffbyAyNYJNT5SD2TZ1RG 2Rix98ivRX+cBOPXuY4ai1/934aeUDs= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=RoTmJrHW; spf=none (imf22.hostedemail.com: domain of thomas.hellstrom@linux.intel.com has no SPF policy when checking 134.134.136.31) smtp.mailfrom=thomas.hellstrom@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676477753; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7ZKdQxBxcxXmShpAP4LBRAsmRDfh9DJQcUedEIJ56TE=; b=gHGwy6i3TweygN9hn1E4NXsoPhlY7xwiHWaDX03p7VB6RRWdV0hFGLRQubX6/YHh1VefW3 CgoJlIvKPzZ1QHaAx9c3ed6R3+2iSG0z5aCQ/Cz8juTSJTp95q6fY+ZcNoJIhRe58T60yq S7T4CL6hpEuxPXCkODU9ffMWt9op3w8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676477753; x=1708013753; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lg54Wj3Uus7sgYkxzG0fkQLBuUlNaWkXXIuWPp8+ayM=; b=RoTmJrHWTBtaV4udPdRgl+YbzkNkogS5Wex+Wehv0UudBL0fcqzxUtLH OdNpUbtQT76/Lk8/maVaxEIsKrKB6NmJJ1yDUSVMltwBlpOMtt8bZstED NClpzTGqTeE/SCK3jg5caDwRL1akKjs4ZX8emeHLG3qhYdmJ3XIaFanNm GSiX6OclLjJBo2Pb6EpTccrGE0uSWYb8UILm2jPZjh3dnmxdPJmJwpQ2X j9BnsvqagY7Xgjbn8quMlJc10AplFEuTX1veeF1ff64iNaFCwYpvknPsw RLvl2Ro2XU0qy4kCmqKY3nxLo+1mb/2zLcnzZgCYY215I0/nKAbJTSEPC A==; X-IronPort-AV: E=McAfee;i="6500,9779,10622"; a="393871153" X-IronPort-AV: E=Sophos;i="5.97,300,1669104000"; d="scan'208";a="393871153" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2023 08:15:46 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10622"; a="758472824" X-IronPort-AV: E=Sophos;i="5.97,300,1669104000"; d="scan'208";a="758472824" Received: from auliel-mobl1.ger.corp.intel.com (HELO thellstr-mobl1.intel.com) ([10.249.254.14]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2023 08:15:41 -0800 From: =?utf-8?q?Thomas_Hellstr=C3=B6m?= To: dri-devel@lists.freedesktop.org Cc: =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Andrew Morton , "Matthew Wilcox (Oracle)" , Miaohe Lin , David Hildenbrand , Johannes Weiner , Peter Xu , NeilBrown , Daniel Vetter , Christian Koenig , Dave Airlie , Dave Hansen , Matthew Auld , linux-graphics-maintainer@vmware.com, linux-mm@kvack.org, intel-gfx@lists.freedesktop.org Subject: [RFC PATCH 15/16] drm/ttm: Use fault-injection to test error paths Date: Wed, 15 Feb 2023 17:14:04 +0100 Message-Id: <20230215161405.187368-16-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230215161405.187368-1-thomas.hellstrom@linux.intel.com> References: <20230215161405.187368-1-thomas.hellstrom@linux.intel.com> MIME-Version: 1.0 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R/FEXEuf1Yle1z6wG5pR7tQrAMM/P RE03GtEL VvHRjEaF5N0af75cR78MFiY4deQvOIpepaxYjRojvgv9igYcmLWwZYujpy5ok0Ll9C4V6w8YFpahsaaVhhRJfO/PQBw0c3wGfuhNdbA/MXxN6Iu6T3qkjgD8n6DlpdUjXDr91z99QKPhnJmxT20RYCS6SZT/nHOxx1SqEggD2ZNJpk+UgSpExDsZJu57NnNHOLqHA X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use fault-injection to test partial TTM swapout and interrupted swapin. Return -EINTR for swapin to test the callers ability to handle and restart the swapin, and on swapout perform a partial swapout to test that the swapin and release_shrunken functionality. Signed-off-by: Thomas Hellström --- drivers/gpu/drm/Kconfig | 10 ++++++++++ drivers/gpu/drm/ttm/ttm_pool.c | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 1efd33411a92..a78eed9af2c1 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -202,6 +202,16 @@ config DRM_TTM GPU memory types. Will be enabled automatically if a device driver uses it. +config DRM_TTM_SHRINK_FAULT_INJECT + bool "Enable fault injection during TTM shrinking" + depends on DRM_TTM + default n + help + Inject recoverable failures during TTM shrinking and recovery of + shrunken objects. For DRM driver developers only. + + If in doubt, choose N. + config DRM_BUDDY tristate depends on DRM diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c index 319998b4a325..d7c604593689 100644 --- a/drivers/gpu/drm/ttm/ttm_pool.c +++ b/drivers/gpu/drm/ttm/ttm_pool.c @@ -453,6 +453,7 @@ static bool ttm_pool_restore_valid(const struct ttm_pool_tt_restore *restore) static int ttm_pool_swapin(struct ttm_pool_tt_restore *restore, struct ttm_operation_ctx *ctx) { + static unsigned long __maybe_unused swappedin; unsigned int i, nr = 1 << restore->order; int ret = 0; @@ -468,6 +469,13 @@ static int ttm_pool_swapin(struct ttm_pool_tt_restore *restore, if (swap.val == 0) continue; + if (IS_ENABLED(CONFIG_DRM_TTM_SHRINK_FAULT_INJECT) && + ctx->interruptible && + ++swappedin % 100 == 0) { + ret = -EINTR; + break; + } + ret = swap_copy_folio(swap, restore->first_page[i], 0, ctx->interruptible); if (ret) @@ -905,7 +913,14 @@ long ttm_pool_shrink_tt(struct ttm_pool *pool, struct ttm_tt *ttm) if (current_is_kswapd()) alloc_gfp |= __GFP_NOMEMALLOC; - for (i = 0; i < ttm->num_pages; ++i) { + num_pages = ttm->num_pages; + + /* Pretend doing fault injection by shrinking only half of the pages. */ + + if (IS_ENABLED(CONFIG_DRM_TTM_SHRINK_FAULT_INJECT)) + num_pages = DIV_ROUND_UP(num_pages, 2); + + for (i = 0; i < num_pages; ++i) { page = ttm->pages[i]; if (unlikely(!page)) continue;