From patchwork Tue Apr 26 16:51:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vivekanandan, Balasubramani" X-Patchwork-Id: 12827557 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3FA6BC4332F for ; Tue, 26 Apr 2022 16:50:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5ECED10E8AE; Tue, 26 Apr 2022 16:50:36 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 66CF810E1A2; Tue, 26 Apr 2022 16:50:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650991834; x=1682527834; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=hFIyWXO5Fk4RSCOFUltPrE0ZuK9WfH61NqbS2AfTyIo=; b=ekN3eY061fizzEhNPN1raHvOJI1NodB48b4Q38YE266hnbx+MuHnnmDG fmpQpsq4/qjMpIRpx4g7vO2ak+z8CnpY4U68r9S9XI8ey7U0zP/a3UMCi WAbgw5oYXtXO/oTlKfRVwKQLAnQForqTMKEoRiAHIER9b52RxM0vWZqVh rUskOxy8v0wWK7nyCxSh/lc135Z43OHwduy4zUmQ80nykZ6DGfEMsEa35 3rbMZ/pHpozMksB19EkIgHgaPYRvbs9hATp1yfNIeKWQ5p5Q+aMO4XgzX S8TkozITD2fjLk1RtBYb2DG+c1nlHE2j73iPJwgU9N7yC7fJqvSZq5Yg+ Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10329"; a="247581913" X-IronPort-AV: E=Sophos;i="5.90,291,1643702400"; d="scan'208";a="247581913" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 09:50:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,291,1643702400"; d="scan'208";a="580034562" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by orsmga008.jf.intel.com with ESMTP; 26 Apr 2022 09:50:33 -0700 Received: from fmsmsx606.amr.corp.intel.com (10.18.126.86) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Tue, 26 Apr 2022 09:50:33 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx606.amr.corp.intel.com (10.18.126.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Tue, 26 Apr 2022 09:50:33 -0700 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (104.47.74.48) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.27; Tue, 26 Apr 2022 09:50:32 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HZ769Wb9EONGZpBtKLYL9d8r73x4iddKXvzFqd1QsoUGHLMKhpyXJ9HmciS3KDhXDWrwZU/s3VzXeWxdW3xTMgfRz44740gTQhQvVNsr/Qzb4IW45IvuLZ9xQSj53S1oX+tAWqSKra8QgvogvZdObIickOHUaAGbknqwQwJPsL+lvwJLPoAuckSr9F5GvLLoCCHCLsxp0xCBJcQxsX/PgaX8pcvtYTrOS1uS80Lcl8lzu5+YU3OyiDT+a+s+ZiQboJz5tvUZXgmCmNtmml+zExRnIgrBPWARaC5UbKEEnT53rnNjbK6S/Q783ps/05YLSnkayk/f374+N68k0AlNkw== 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=/bdLQRIVNNXWh8ngcRa7sgwrI4C3A9gMhN3czoh9EvI=; b=BxAs7S2wplnfjDOwZgerFeXqXSg9PMiT/TcI6sA6ACPtSWgMZeSqmRzoVeRd+fX7yrHrcjocxA2bNMbVAC5Uz4RtqbSkqD4zrWccvGiMBQKenm+iwfeS7skRV1JNirDj2Z+BigMONi+mHij+T3r3fZR2BrbuUjK30PZWrFnhXew4CbfFjDo8If4ZI1VNXK6EnL84w6DqTQiK6LgHVxdc9p907odbpZ5mhvCoYNlWCHdcBFLXp7kP5ydGuZkRpTxSUiGEr382+vwvfXZ0zbpc8xvXhUIkbm7TmU1ATJzukPoBtBmttkSmo966IaE8nni1A2MkAquLDf/hJMyAF84UCw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from SJ0PR11MB4894.namprd11.prod.outlook.com (2603:10b6:a03:2d4::5) by MN2PR11MB4366.namprd11.prod.outlook.com (2603:10b6:208:190::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Tue, 26 Apr 2022 16:50:25 +0000 Received: from SJ0PR11MB4894.namprd11.prod.outlook.com ([fe80::3d83:3af5:c95f:e062]) by SJ0PR11MB4894.namprd11.prod.outlook.com ([fe80::3d83:3af5:c95f:e062%7]) with mapi id 15.20.5186.021; Tue, 26 Apr 2022 16:50:25 +0000 From: Balasubramani Vivekanandan To: , Subject: [PATCH v3 7/7] drm/i915: Avoid dereferencing io mapped memory Date: Tue, 26 Apr 2022 22:21:48 +0530 Message-ID: <20220426165148.1784-8-balasubramani.vivekanandan@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220426165148.1784-1-balasubramani.vivekanandan@intel.com> References: <20220426165148.1784-1-balasubramani.vivekanandan@intel.com> X-ClientProxiedBy: BMXPR01CA0092.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:54::32) To SJ0PR11MB4894.namprd11.prod.outlook.com (2603:10b6:a03:2d4::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fbf06cdc-e615-4488-c1b1-08da27a4dc8a X-MS-TrafficTypeDiagnostic: MN2PR11MB4366:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtFwd,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0ibwKaWztwZVg1p8cXdzxRZNa4PZkBRZRvmjHPVvs1k8QXp6CM63HDuQ6HDloLY/9tf5McKdjhX/7PJ3MaE32HtqS0IAB4xtBY6zbt4lpcynMtqpAhBJH3Q3HD2hBWxdtAdM1s4gLpXmsX9Jp/2lE+yYKtFesWJcdG9lPJZNFSqCCknacNVL8wyab4gAtqR9W2SWGBuXmlecG6ZEWQzci/xzhyR1nuKorgLlBulRI7is5O+5MLLXGoGJbQFwpgapsUFM76wQgOSoYWm2EbBgiclNC38uFlSOhEw9R8NSFpUua6OQarQAh6dMjkSSY3Hzt8aLXIpMBLCeAclvrE+6WfpVffxQEyqCNk4UAfihMkoMDJClS8ZOLi0HJMiAh4RgMPUrCZF+HolYlxnheKiQpfOgL78pq9eOmHr66B04YaJdpMhL+jnBZjcXZJl0MCFeqnox3EYyuhuwezelVNSr48D2v6/5TvyifFIezHRLLtk5rj3f1aZCtTVvuUzlI7OgdPHwNRLTU6Jp4llQ6BR2pIJHLNaSdFtyO85JNtILRgDQq6kUFOMOE28hNZTKXdU1ovNMqWgTFGPg66NKsi2/4lEMb7f3D7MtWvkHlR914nIi7UEoLl+2lPHPRxzJUDMRNHVsm+yTWQQ+tdrrFd/hEQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR11MB4894.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6666004)(2616005)(66946007)(6512007)(5660300002)(107886003)(82960400001)(450100002)(26005)(8936002)(66556008)(54906003)(316002)(86362001)(2906002)(1076003)(38100700002)(44832011)(6486002)(508600001)(4326008)(8676002)(66476007)(83380400001)(186003)(6506007)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6+Qfw3f9piRCywR+/eLkDQT3FCTKnv6VrkNwU6JUZOxuyKU9PPpv2BvlEy3+5DLXhKbPRWkFCEDAH69BLbGE4D72IPYfZIFp+VbJk7esFBd4Jq8Zn369LhZW4oz8FECDTQvRgv6ZRhq8asqPb7x0DFRAECMFTO7CSH42/tWzJTXNTVTafiRSn2/wsMhEonLba/U2PZB741UAiHBAVrzm83xlhzVAwoIXbx4VKSmXHR087HcUkLeV7OyvQlYWl04p8wG0ovuKElj/vVtDa7BinXk0iGHr7T1lBzTYFgChHN5MhmDl+hUpi2f4XeQMc9KtiGG6JCVcV5xYpQ3lWdojSGCr3IktfhC4+Ho/+rsgaKqZ2uG/JK+5LgI0q3TjhnC9RK6Etk6KEcovRHdCHfnU8QdyQ/+LGXogBtyG2lI9KwHNTCto7i9ovitHVLbhBgTRSpnsYISF1i059BgauvajW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ARLImgQjhULVTzE4LuBx80cOHabGapaqEbtE2fIebbGDNdGRwvudR9B9gKR1e6gMjBI1nkM/gYoCoe0keex9ecN+1zok9rG0uhqkiQZkggdB5Ghn3D+19zqnJ//2hnQNXgRJfZIjrorYqhOjI9IFmsfNEXmnUVXHfA0Hr65wHIeagxRoyUGC6PVmtCGlafnbWpIxbovqS9m2vsSv7w0IsWuVCT1MfowQnjef3bRLbKrvB0z8pQ X-MS-Exchange-CrossTenant-Network-Message-Id: fbf06cdc-e615-4488-c1b1-08da27a4dc8a X-MS-Exchange-CrossTenant-AuthSource: SJ0PR11MB4894.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2022 16:50:25.6422 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cTq3ClfgTm6/vZG8NNjaRnofD+VQlSraQ8s5ag+1tK8wzEpBSlgNX0s22PDgeE4xpOmpMSt+mPdmz4WH1MjzJmIaG7hnTIK1n9D2U2UBiRUqDQGdoWLNImRWhWzSYgt4 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4366 X-OriginatorOrg: intel.com 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: siva.mullati@intel.com, lucas.demarchi@intel.com, Balasubramani Vivekanandan , Nirmoy Das Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Pointer passed to zlib_deflate() for compression could point to io mapped memory and might end up in direct derefencing. io mapped memory is copied to a temporary buffer, which is then shared to zlib_deflate(), only for the case where platform supports fast copy using non-temporal instructions. If the platform lacks support, then io mapped memory is directly used. Direct dereferencing of io memory makes driver not portable outside x86 and should be avoided. With this patch, io memory is always copied to a temporary buffer irrespective of platform support for fast copy. The i915_has_memcpy_from_wc() check is removed. And drm_memcpy_from_wc_vaddr() is now used for copying instead of i915_memcpy_from_wc() for 2 reasons. - i915_memcpy_from_wc() will be deprecated. - drm_memcpy_from_wc_vaddr() will not fail if the fast copy is not supported instead continues copying using memcpy_fromio as fallback. Signed-off-by: Balasubramani Vivekanandan Acked-by: Nirmoy Das --- drivers/gpu/drm/i915/i915_gpu_error.c | 45 +++++++++++++++------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c index 0512c66fa4f3..9cafacb4ceb6 100644 --- a/drivers/gpu/drm/i915/i915_gpu_error.c +++ b/drivers/gpu/drm/i915/i915_gpu_error.c @@ -262,9 +262,12 @@ static bool compress_init(struct i915_vma_compress *c) return false; } - c->tmp = NULL; - if (i915_has_memcpy_from_wc()) - c->tmp = pool_alloc(&c->pool, ALLOW_FAIL); + c->tmp = pool_alloc(&c->pool, ALLOW_FAIL); + if (!c->tmp) { + kfree(zstream->workspace); + pool_fini(&c->pool); + return false; + } return true; } @@ -296,15 +299,17 @@ static void *compress_next_page(struct i915_vma_compress *c, } static int compress_page(struct i915_vma_compress *c, - void *src, - struct i915_vma_coredump *dst, - bool wc) + struct iosys_map *src, + struct i915_vma_coredump *dst) { struct z_stream_s *zstream = &c->zstream; - zstream->next_in = src; - if (wc && c->tmp && i915_memcpy_from_wc(c->tmp, src, PAGE_SIZE)) + if (src->is_iomem) { + drm_memcpy_from_wc_vaddr(c->tmp, src, 0, PAGE_SIZE); zstream->next_in = c->tmp; + } else { + zstream->next_in = src->vaddr; + } zstream->avail_in = PAGE_SIZE; do { @@ -393,9 +398,8 @@ static bool compress_start(struct i915_vma_compress *c) } static int compress_page(struct i915_vma_compress *c, - void *src, - struct i915_vma_coredump *dst, - bool wc) + struct iosys_map *src, + struct i915_vma_coredump *dst) { void *ptr; @@ -403,8 +407,7 @@ static int compress_page(struct i915_vma_compress *c, if (!ptr) return -ENOMEM; - if (!(wc && i915_memcpy_from_wc(ptr, src, PAGE_SIZE))) - memcpy(ptr, src, PAGE_SIZE); + drm_memcpy_from_wc_vaddr(ptr, src, 0, PAGE_SIZE); list_add_tail(&virt_to_page(ptr)->lru, &dst->page_list); cond_resched(); @@ -1092,6 +1095,7 @@ i915_vma_coredump_create(const struct intel_gt *gt, if (drm_mm_node_allocated(&ggtt->error_capture)) { void __iomem *s; dma_addr_t dma; + struct iosys_map src; for_each_sgt_daddr(dma, iter, vma_res->bi.pages) { mutex_lock(&ggtt->error_mutex); @@ -1100,9 +1104,8 @@ i915_vma_coredump_create(const struct intel_gt *gt, mb(); s = io_mapping_map_wc(&ggtt->iomap, slot, PAGE_SIZE); - ret = compress_page(compress, - (void __force *)s, dst, - true); + iosys_map_set_vaddr_iomem(&src, s); + ret = compress_page(compress, &src, dst); io_mapping_unmap(s); mb(); @@ -1114,6 +1117,7 @@ i915_vma_coredump_create(const struct intel_gt *gt, } else if (vma_res->bi.lmem) { struct intel_memory_region *mem = vma_res->mr; dma_addr_t dma; + struct iosys_map src; for_each_sgt_daddr(dma, iter, vma_res->bi.pages) { void __iomem *s; @@ -1121,15 +1125,15 @@ i915_vma_coredump_create(const struct intel_gt *gt, s = io_mapping_map_wc(&mem->iomap, dma - mem->region.start, PAGE_SIZE); - ret = compress_page(compress, - (void __force *)s, dst, - true); + iosys_map_set_vaddr_iomem(&src, s); + ret = compress_page(compress, &src, dst); io_mapping_unmap(s); if (ret) break; } } else { struct page *page; + struct iosys_map src; for_each_sgt_page(page, iter, vma_res->bi.pages) { void *s; @@ -1137,7 +1141,8 @@ i915_vma_coredump_create(const struct intel_gt *gt, drm_clflush_pages(&page, 1); s = kmap(page); - ret = compress_page(compress, s, dst, false); + iosys_map_set_vaddr(&src, s); + ret = compress_page(compress, &src, dst); kunmap(page); drm_clflush_pages(&page, 1);