From patchwork Tue Apr 26 16:51:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Vivekanandan, Balasubramani" X-Patchwork-Id: 12827555 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 2BBCCC433EF for ; Tue, 26 Apr 2022 16:50:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6A43F10E8C1; Tue, 26 Apr 2022 16:50:23 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 48DAC10E8C1; Tue, 26 Apr 2022 16:50:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650991822; x=1682527822; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=vsvsPqBsA2virfWAOHmkON3/lzwKrck4Co760IHJPro=; b=P9yX2jnqQqCmZLutf0muFqGvQQh1QIMS2lyFDjShh4CrJIvEHXBVmML7 107VLA/k7kzBRqkitJlB5xyJu2YlpF1MQYxuguVRBxgL1XD93sVP3rOXk fTdQFjFnvrXH4scV3jRWadxle2DJJmzII3r//5BAJp2roHobuEF0+GCvz vGfu7Q1Ihqu0k0fI8ZpnEoOelHloNs5SCxFN2GtA96z0vKTVznpc/Orik lgLa5ZmsZQyVJm+eMCY1w5fd9G5YexO2kRlCQDq+KI9iYHY1wLWYsm6zH Bj7dr62G2avJmMaVQW+sUsff/+E/gnDRJvHfGlaFYDqTPU6OHDQpPrP/h w==; X-IronPort-AV: E=McAfee;i="6400,9594,10329"; a="253028169" X-IronPort-AV: E=Sophos;i="5.90,291,1643702400"; d="scan'208";a="253028169" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 09:50:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,291,1643702400"; d="scan'208";a="650292550" Received: from fmsmsx605.amr.corp.intel.com ([10.18.126.85]) by FMSMGA003.fm.intel.com with ESMTP; 26 Apr 2022 09:50:21 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx605.amr.corp.intel.com (10.18.126.85) 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:21 -0700 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx610.amr.corp.intel.com (10.18.126.90) 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:20 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx603.amr.corp.intel.com (10.18.126.83) 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:20 -0700 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (104.47.74.42) 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:20 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GA+cBgvJucvXt247guIBIyq7tlOWu0xNwQwkU9VAUDwg1YZgcZ0J8Xs3xxbrLtoFtBsS3FMhCrZi2rOvinlzermI6MvXvzXL6Bq2Waj3wDJNOf2ogP/xXpSy9LzMJ8GKue3t7i1w/4hxadLt0thLzci73s2Sc8YCDWmD4GAm2YLuk3ryjGVgYlTqt/PGFJJN1dOrQYsXTqz2qnfy994lmTzA+K3rrqulsNQSgr0CTgf4ayA+iVU1+jt44J7zDSvfFtJJLVzwqPzb0z4DOq22nMAcqpChnXrZXYU0PpWwHQ//N4YTJns0ovDLIXxr1+roP4TqIMsW8XTKnO4SEcUYqQ== 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=zJJXTEs2YbxS0wDG/NHU5ZGxxcxvqXoiuZioj14kiL4=; b=BtJJ6kRFB4jDHzSQOvHmcQrJwnIONwIgtizf52QKE1BZ1EOCSeXLghNWIW7Q0ELvydZKbfrXCiwglql2f7p3twGw2xAeiXczgd4JyQ8UjEplpv31cVqMgiPh1ubStPhAqmpTMOwYK++goYMono9Tym5CNdMQP3XakdFmQjjSrwDn9CLGegdmhc22gA/2jsI1K8gGs5FrcKiHvhs8jKtcr7JMFkwFpyz8q0WnIBIRAhwAErdWJY9Dq1BVN//iYhgnR1F7geFhOI/DgBvT9cCOkCPO6Nzu0s/s5V3iTGyCMkhTjuRA/dbi2sG3ClxYUiS448ff16ml23UpUE9jfhxvrQ== 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:17 +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:17 +0000 From: Balasubramani Vivekanandan To: , Subject: [PATCH v3 6/7] drm/i915/gt: Avoid direct dereferencing of io memory Date: Tue, 26 Apr 2022 22:21:47 +0530 Message-ID: <20220426165148.1784-7-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: PN3PR01CA0074.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:9a::18) 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: 0a6a9d0c-0747-48bd-38b5-08da27a4d7cd 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: EoFwU3/nEIjnK1vc/tfx4jtEl9QjjRwIZ3LR/KlpzDDTRVD7GBCQUc3X5cA+7T7wjK+O22h+be56nZK3ROD83ckJN80kkYApC1lYnlwvrxSI05BuEdF1LrMvvhBTEaaKgmLlJ77Tyr4CIFPFkCASi5wGDuUm5siCkKrO1yn3+1cb2sZeLs+aOZuPLr4OkgTqzmEsqyy41v0AKvlMbW5Dj0kw0nQAwN0xNSu3dXUBr/OzsBjZOQMiDazmWPEBeIfpUhS4JbVyrEUz+1P4Ub1xQ7oog/+G+tWodc3KkkDmvxfWit3ZZAw1ljfeAxatbWRaSp1vVxlx10J2kmuJ/rk+oHEIYZ1rHHBPu16Zp8DzYdgShjjyURiwI8Z9+DkxdHco0jlMLEDFn4Ugq2CfEf8sKA8gZAmxgLKgj/zaKr4328ZJuCoD4eWGnpvqBQiRwRd8+Ozogp9dKHpTUZ559SZyNMtEBkyLsrMQ+Ml40uVARIcl4rfCea1WAWBTm7vymtvHe3Orm8wCCQkyabnLB/24Ah6yX2whWjqppAXQjDAQQcHLLwEtJnGDHg+Qv91AXU+0phcCr9gn9aYeptA3Og4XyQfoWSLqNATED90bU3whEZ3cUOAuQ84IgGcaVDQLUPtnTJv4cLGQmP899GJeGlWuvQ== 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: =?utf-8?q?ZZo8VM1Ffo8J7oZ8JFcDaWXF9+GH?= =?utf-8?q?5mv+NAlO1wavs7kEnbZUr4JhbdYmiXOwD6iDlw5VyudpMXMKyp6dU5TnCPklEYD/u?= =?utf-8?q?QYCW09x9wVJctgylbYIzyRZiivBad4W6s0BZUOBxj7GreO6+sXitvBYb1u0kjYkbo?= =?utf-8?q?mIafjf1ZP3TnnLRZ0zK71rGSAU9ecjKBlfOaNW1vXZYLruwMa6Hj9Yo2dZbhURA/+?= =?utf-8?q?v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q?d70yD2DoFXwswy5xnMhHTr0437HhoR6UhdO7TmtLNAHFJ+kanfG0RBc3fkNt2yqqS?= =?utf-8?q?hfTlqvGY1ENNyAI+ck7bQ5G6G5fzjf513RRTZcc1hHwJuBEVcOVfrLY4ZPGsH/rKT?= =?utf-8?q?GmHWLrBNCCzO+fsvMMLdoR1nP1cwzSqAwRQVd3VPzQ3W1HQEBEuu/GOwDGmr1D3xo?= =?utf-8?q?bpFGYPCNrpkF4xXSmYgE59q6B/Sm1FjnHFD4FW7H2NtT3v+paWapRKFb6A7IQHMkh?= =?utf-8?q?Ya5wxan+PtN1CfGTj9RRWr5ylhx+UWYhHTYGOHq7pO4ZllAA0ycCiR4bVnQ6tDyv2?= =?utf-8?q?FQfxzpgJndrQDW3PTg0sg7vjk1dYo48+Lt2zlPKiiGM9cOS06DNDyNdzZvO1gNY6M?= =?utf-8?q?sE56CFV2jB+/4zwcEt80z75bWwZILxSZxvPyw3hKJYXtiZcd51Y4/HSpliTcn7clS?= =?utf-8?q?fJGWGOBE3/wFTtsg4T2KEhshqqrmOg1kYXIlfqm5L5Hlbku0plkchUVtJnvKO0chl?= =?utf-8?q?Zb/U0YFRiga+9Rp5ScfPYzdfTXgSwjda9WyL4vU+fg0OnOkIuSazm+8GP3d+x1TWq?= =?utf-8?q?NAH1b8QnpzTdDA/Gaf3K6THUwe6jLnXkIHpzArqRxXdHCSaYlwKIb5Ri8yPN9okhD?= =?utf-8?q?eRokfGR4q?= X-MS-Exchange-CrossTenant-Network-Message-Id: 0a6a9d0c-0747-48bd-38b5-08da27a4d7cd 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:17.5954 (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: wqaaQ+DoIZwEcatpzEmaZVM5D5XE3i91VVcic6SZxmH38fU/YbJ6uWeMR3cXh3j7B3W9nR75EmXVhDWs9pUIxmo0JwV5xuesLnCoVIY2PTqaIWAe8T4cEA5d51qPdG/C 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: Matthew Brost , =?utf-8?q?Micha=C5=82_Winiarski?= , Balasubramani Vivekanandan , lucas.demarchi@intel.com, siva.mullati@intel.com, Nirmoy Das Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" io mapped memory should not be directly dereferenced to ensure portability. io memory should be read/written/copied using helper functions. i915_memcpy_from_wc() function was used to copy the data from io memory to a temporary buffer and pointer to the temporary buffer was passed to CRC calculation function. But i915_memcpy_from_wc() only does a copy if the platform supports fast copy using non-temporal instructions. Otherwise the pointer to io memory was passed for CRC calculation. CRC function will directly dereference io memory and would not work properly on non-x86 platforms. To make it portable, it should be ensured always temporary buffer is used for CRC and not io memory. 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 but uses memcpy_fromio as fallback for copying. Cc: Matthew Brost Cc: Michał Winiarski Signed-off-by: Balasubramani Vivekanandan Acked-by: Nirmoy Das --- drivers/gpu/drm/i915/gt/selftest_reset.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/selftest_reset.c b/drivers/gpu/drm/i915/gt/selftest_reset.c index 37c38bdd5f47..7a455583c687 100644 --- a/drivers/gpu/drm/i915/gt/selftest_reset.c +++ b/drivers/gpu/drm/i915/gt/selftest_reset.c @@ -3,6 +3,7 @@ * Copyright © 2018 Intel Corporation */ +#include #include #include "gem/i915_gem_stolen.h" @@ -82,7 +83,7 @@ __igt_reset_stolen(struct intel_gt *gt, for (page = 0; page < num_pages; page++) { dma_addr_t dma = (dma_addr_t)dsm->start + (page << PAGE_SHIFT); void __iomem *s; - void *in; + struct iosys_map src_map; ggtt->vm.insert_page(&ggtt->vm, dma, ggtt->error_capture.start, @@ -98,10 +99,9 @@ __igt_reset_stolen(struct intel_gt *gt, ((page + 1) << PAGE_SHIFT) - 1)) memset_io(s, STACK_MAGIC, PAGE_SIZE); - in = (void __force *)s; - if (i915_memcpy_from_wc(tmp, in, PAGE_SIZE)) - in = tmp; - crc[page] = crc32_le(0, in, PAGE_SIZE); + iosys_map_set_vaddr_iomem(&src_map, s); + drm_memcpy_from_wc_vaddr(tmp, &src_map, 0, PAGE_SIZE); + crc[page] = crc32_le(0, tmp, PAGE_SIZE); io_mapping_unmap(s); } @@ -122,7 +122,7 @@ __igt_reset_stolen(struct intel_gt *gt, for (page = 0; page < num_pages; page++) { dma_addr_t dma = (dma_addr_t)dsm->start + (page << PAGE_SHIFT); void __iomem *s; - void *in; + struct iosys_map src_map; u32 x; ggtt->vm.insert_page(&ggtt->vm, dma, @@ -134,10 +134,9 @@ __igt_reset_stolen(struct intel_gt *gt, ggtt->error_capture.start, PAGE_SIZE); - in = (void __force *)s; - if (i915_memcpy_from_wc(tmp, in, PAGE_SIZE)) - in = tmp; - x = crc32_le(0, in, PAGE_SIZE); + iosys_map_set_vaddr_iomem(&src_map, s); + drm_memcpy_from_wc_vaddr(tmp, &src_map, 0, PAGE_SIZE); + x = crc32_le(0, tmp, PAGE_SIZE); if (x != crc[page] && !__drm_mm_interval_first(>->i915->mm.stolen, @@ -146,7 +145,7 @@ __igt_reset_stolen(struct intel_gt *gt, pr_debug("unused stolen page %pa modified by GPU reset\n", &page); if (count++ == 0) - igt_hexdump(in, PAGE_SIZE); + igt_hexdump(tmp, PAGE_SIZE); max = page; }