From patchwork Tue Feb 22 14:52:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Vivekanandan, Balasubramani" X-Patchwork-Id: 12755261 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 DC386C433EF for ; Tue, 22 Feb 2022 14:51:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B6C0210E883; Tue, 22 Feb 2022 14:51:58 +0000 (UTC) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by gabe.freedesktop.org (Postfix) with ESMTPS id DFE4B10E8DA; Tue, 22 Feb 2022 14:51:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645541517; x=1677077517; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=XuACy3dh4LXalFHQsmoyfA/3HxkUIuEncSlter9HMdg=; b=egrrLgGhy9Uyj17bJ7v9Lkjs04zFACaDrgkAMDL5k+0jUs96o/6gvliI gdwmzJvfWQD0Hgwg1arVi7xFyYl5ZYDcApu6ooYUzEfYrwtSY7w0+ojPu 6fkusxmoI7bOxw81rEsY9gsL7zf9/mVG+EE/kdf0IV9PDdD9FziCFbN7q olHHdYc7M4939xwAHHue5iGsAtuKArtItu5s7uw48TRYxwGpuSLyLuHNC fXqNwkJvnwZ9q0NEB758Umvnvw0U7idnrWJx5LvgLgkT4xLwoBIEzAp+7 D/qVty0DjpVT7GRZFVMc/hF/J1AbAqWLZ4PDzWvLjmcsYlXT5suI+U4TZ g==; X-IronPort-AV: E=McAfee;i="6200,9189,10265"; a="338153205" X-IronPort-AV: E=Sophos;i="5.88,387,1635231600"; d="scan'208";a="338153205" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2022 06:51:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,387,1635231600"; d="scan'208";a="683541140" Received: from orsmsx606.amr.corp.intel.com ([10.22.229.19]) by fmsmga001.fm.intel.com with ESMTP; 22 Feb 2022 06:51:57 -0800 Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) by ORSMSX606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Tue, 22 Feb 2022 06:51:57 -0800 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx609.amr.corp.intel.com (10.22.229.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20 via Frontend Transport; Tue, 22 Feb 2022 06:51:57 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.109) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Tue, 22 Feb 2022 06:51:56 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jz3V7K03eyDjL/V1MinSaVoeQQDnMN4lW+wRZF+5GMnWhRH3ZaGaB6EunS5a0Bh5riVmqUzjvQGMBKy5ljHs/Dk7Hlx7/8zRH5/4I2MLqIgFWJH+HMZng6NxetwreP8uoAq4QKADVhbDtKAJ08dT7WJRgQ7J2QfdrDKY/24DHKdlAlibTQdoptvQAvSQiYcQVQtZbZUx7zu104SSzQyh7+ebb18p4Q6/kaQOLbkUd3tGv3P8nF3UkAe6bQ5ALINU7kP0tD575JVDSK4NOXb4KvPixXGw/wGkb//zEGkt5FP6AZ+4dS0g+npigImR5Y2wivTBNM3b9MS2bdGsYn4VMA== 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=yi4z+uAe9t/1S1OUBMjXcaY8sZ5dKyGDNhqsy+3v7m4=; b=Hodb4VpBc7J+NN2a6yR9GwmJ2tgcHSu038slMI5HuMrL1IcJ/GGsPLO9V5CaO10xUJI40HqC2lWwdInrjc29qKfzdCo41pXrOddtlmOCNW722uiaJIzXgCh2hoE7z22cKc1hYOPVSD4t6phQ7LGCbLxr+9TXvzWMhmF5LR/KD1lYuGRnlZPyN0ukovV8niFg3SOEJqrF3iGwxtjFAmc47mYu5iL2RJoqHeWpKqiMAbFoqPZPSSirGpPFzc6Ki+kg4gU1a8Xb4ORYaGgZx1Iv0ovdwCiG7Qm61gZ829osdqOyTrtDSLGZk6sUmXBmd+DxvK6nl9BEfu7qrhjAH3q10g== 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 BYAPR11MB3221.namprd11.prod.outlook.com (2603:10b6:a03:1c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Tue, 22 Feb 2022 14:51:55 +0000 Received: from SJ0PR11MB4894.namprd11.prod.outlook.com ([fe80::d67:8a16:f4cd:b475]) by SJ0PR11MB4894.namprd11.prod.outlook.com ([fe80::d67:8a16:f4cd:b475%9]) with mapi id 15.20.4995.027; Tue, 22 Feb 2022 14:51:55 +0000 From: Balasubramani Vivekanandan To: , Subject: [PATCH 6/7] drm/i915/gt: Avoid direct dereferencing of io memory Date: Tue, 22 Feb 2022 20:22:05 +0530 Message-ID: <20220222145206.76118-7-balasubramani.vivekanandan@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220222145206.76118-1-balasubramani.vivekanandan@intel.com> References: <20220222145206.76118-1-balasubramani.vivekanandan@intel.com> X-ClientProxiedBy: BM1PR01CA0080.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:1::20) 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: 385c5e73-0916-4e1a-4706-08d9f612de62 X-MS-TrafficTypeDiagnostic: BYAPR11MB3221:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,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: AKwTa0wQT5gw5pBhvxskPt1JdPuw73ET7Z2dujUT5kEodZvrmC6cQ3Tk2fcHKkmLBcxPgzJGSIV1l1c694ZvOi91bmRPvxbGvih3tgpaoNeQXHot+Da62FGUWjbVfvBbK4tMoVRwMOCEo4pNVlcsDRDYeATGQbDeWyPog7Pv99bhdN96mHWpMjo41DL2d98IrJf3JqfIQv7IBRfjMufMw16mg3IVhTi/v7JHe0w0e0/OgsCBaQvviHt7MH/kLQWlf2E++lTeua4tcsfVNK6Z/nY97wVi4r+N7WZzqoBlNzVf7fp9q6yiV76Oslb7BfLB8Hqvq9o0JQuLf77t6a7ZdlKGabLBPHloa1THPjmQh0qrUeJCkedNP6HSbWHlLUGbv4xOmxjV7dDtS7Vd2xZo5/v45/siVaWv+9bZHx2QAfuZg7WqaTgTVhVp/uDS8jsaoxnR/55e7eEQadaeLvWY+IcYnceea+CShmiyFVNMAuxJtqj8Mk/NrxzF9Mktve4Fex9PImawNaaz/q0Xb731wtcyw5Ajjpc88F35CwRFjcPfxiGbpAC+ZCbISwj1TQ6zsRDsqkK/e9/q+f7CKb0Fs2/23wnrZcte4BbA1BhbDLln+L2TTKnxf3vt8FpbrBb1putT350Hf5Hns+Y4nr0A4Q== 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)(6486002)(2616005)(316002)(66946007)(54906003)(83380400001)(4326008)(450100002)(8676002)(186003)(1076003)(66476007)(38100700002)(66556008)(26005)(6666004)(6512007)(6506007)(82960400001)(5660300002)(44832011)(8936002)(36756003)(2906002)(508600001)(86362001)(107886003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?xpHty2U3zU8TE+jGYAvhmfFaXBto?= =?utf-8?q?mcfC6dZAwXn/x0IH9sHFREA1ycaqN6ZzdG3RvWGv/k8Nh1cCDh6LD8viXESMaIF7d?= =?utf-8?q?V7myFbJDnPEAGkV3q2GJCxtaqL/TJKxZoR43PUIBQpL3K8C2YzAm0OdxtLopGeeRa?= =?utf-8?q?hhnOJZtbnJUI3Z9icVNxdPBVm052qhp3sq29CYQ7FAse9oZeWKbagSqpyTx1mjHQb?= =?utf-8?q?nvd/OlKnYGmF3dakbkuDrsATiMbZN2MQ59NUSvp1IVZw4SPbEIiA1Wk0d/rl/4jHt?= =?utf-8?q?IC6BieUl9ACmP1xoft7S3DBYwiSFRTMJyqtC7/IRxtT3yUufqfokecrPkvCwIP/zl?= =?utf-8?q?BTTA0rcbHKKpFnjYnkSSU8Sy4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ir6QpPugoRIAPXtLBFKLcEuVK6VSiVJI+4uCjBY5?= =?utf-8?q?ewWrnCBK81StRk7lsRKLX0BRCpPJT+yEt6D1yj4IWscH94ZYVzm1WeLImwXZOfTgH?= =?utf-8?q?HQ8japhy06LjFVktUdsCujw8hdtpQIsIU2B+udE9Tnm3j5N4ExQtZdXpItODrARpN?= =?utf-8?q?cJxjBlRtZix+Sluun/1LW2YjuZ4lehLD+9qc/m3/0C5uxM3liNWjAyosdMPGN/sNM?= =?utf-8?q?cS7uWEqgHqRVExICis8oeR3hhil+TIYswpyb7bfwWurYpIq69slAGXKE2gqXvjKsl?= =?utf-8?q?DkugUPAmeDX5sWyZ4+FTDiAxJmaS7wuJgO2ivbGRqHxl7/ZGCQDdLh8K0XLMjH8Cf?= =?utf-8?q?3iWBfMSGqqTsacTfYqknMukgz4FhBKPUGOnSRx0BEp9EzzbSKr8NPRviCxzHbHaxg?= =?utf-8?q?PEGxdVk4UU2MwND7UsyZm+O9EDS3QsIQ=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 385c5e73-0916-4e1a-4706-08d9f612de62 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR11MB4894.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Feb 2022 14:51:55.1400 (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: ikRinPxjPGlrmIKc0uz6LUa4L45bPJKFkRVL8rCw0Dv9zghMh/TgSnoAQTo3oUNoRbrGaALoQgZmEYNtcQ5xYUAW/EHToyucizanNrGDWBS6jmmCB6Xc38Gn5uhPngFW X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3221 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: michael.cheng@intel.com, Balasubramani Vivekanandan , wayne.boyer@intel.com, casey.g.bowman@intel.com, lucas.demarchi@intel.com, siva.mullati@intel.com, =?utf-8?q?Micha=C5=82_Winiarski?= 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 Signed-off-by: Balasubramani Vivekanandan --- 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..79d2bd7ef3b9 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, 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, 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; }