From patchwork Wed Oct 23 13:24:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Karas X-Patchwork-Id: 13847100 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 88335CF5386 for ; Wed, 23 Oct 2024 13:24:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 18E8D10E7A4; Wed, 23 Oct 2024 13:24:30 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="JaTwP27P"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id B6F6910E7A4 for ; Wed, 23 Oct 2024 13:24:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729689868; x=1761225868; h=date:from:to:cc:subject:message-id:mime-version; bh=8mr7Og8q6DkZbna7PCYO4zO8yCaqKhW6Cb8SxlTfm8Y=; b=JaTwP27PLsMJ1mGgkuzmUxxRONaWrDlmnfXjpjORGe3pUlPsDVyAA4zF q4WNomnjZgLx0MeaLAGxh0mGfwD+XuLqDCjuwzUjtC3AVWJL8JpVHXOnn 5OLZA1uasbuiWkNAbTwsHHySR7A1aRQRn9oxgNWCK5/nXMSiKocT4BH9a 8OBICF+DrEDa9QdVI+scLZrNiXQd6vbdj9pZiGp7+2Y4VQm+DDtKQ2F8t 8j2HvjByBGE0xa3XTSTcEOwJgiAHDIiJ3qO0Dg4ATzVsVIEYKQcGRxmqR jHb9P5F6vUXsJbXUjmPNILXZWe+rw3oD0hF77RJp57zRaueIAcuT4EwT8 A==; X-CSE-ConnectionGUID: gfeMGZ+mR9a3jioaHmRqmw== X-CSE-MsgGUID: ZN0mIocESQ+bQfp1xsSWWg== X-IronPort-AV: E=McAfee;i="6700,10204,11234"; a="33194843" X-IronPort-AV: E=Sophos;i="6.11,226,1725346800"; d="scan'208";a="33194843" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2024 06:24:28 -0700 X-CSE-ConnectionGUID: ub7ty6B7T9in5l3ATyoMuQ== X-CSE-MsgGUID: ROTenOxoTlCWYKtg2bgRfw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,226,1725346800"; d="scan'208";a="80612133" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orviesa007.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 23 Oct 2024 06:24:29 -0700 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 23 Oct 2024 06:24:27 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Wed, 23 Oct 2024 06:24:27 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.172) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 23 Oct 2024 06:24:27 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ThB+Urv0BINLKl9MALqT3QmhHvVAheR3jYWJ8yOZn3QhTecWsdXilxpxs1KFc1aWA/5tiSkU0xPGZZHv8PcKwz3oBRj9YHP5UG28dq7jc0/DQGlg0xYFIP9clVllwll4mcPpVVMKXa/Xwk9cL3hMs0sElPLabvC3OiB38RptakxQfAxKuz8oeQnVz7zsOQqIR7/6rS9A4Cqwqp6EkScmXxCFuBQZGQao+GEibhLp/d5ValJUA/ABlp4udIsmCb3aqftQb0ngdEyPmWDtvtdY/vFKPSNSb/XVsFyxtrea7B/L9Zk131/PriQxPMQH84bOlFwQUA9F+1hvtN888D5f2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=d/oJDNTTgSpyvjevWkwe7Pjx/NXPlPJj4VyH4p8ouzc=; b=Rtq41jTMKJpnJsRBQrXRkNeC1+lcakr57i5aw9RHddBNWJgnCqeziw1MrqWmVCxv+TanjgWqDByILKug5sglWUilvGCzF4cKhzVEldH6pXHm9PTJO8r0g92YZkiXEeIc1na3a9acofc5OaP4NndVgTy2cxieYDirV2zcEPIKKlpuIqyaDvev8zbKei+mu84i6x/EwKN3qfZPV2zFs15MqbORa7OLeMPeJCX8fvE7czv1LaEEnUaZgBUckJviITfGcioUDiLv8uIGOgwNAjEwds/fMHTpm/25deTWd+bhuRoRqmH17B/bfAXEwY9ffawKPb3/o8TLE3bMj0GwKONyEg== 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 CO1PR11MB5057.namprd11.prod.outlook.com (2603:10b6:303:6c::15) by SN7PR11MB8026.namprd11.prod.outlook.com (2603:10b6:806:2dd::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Wed, 23 Oct 2024 13:24:25 +0000 Received: from CO1PR11MB5057.namprd11.prod.outlook.com ([fe80::4610:6d6c:9af6:2548]) by CO1PR11MB5057.namprd11.prod.outlook.com ([fe80::4610:6d6c:9af6:2548%7]) with mapi id 15.20.8093.018; Wed, 23 Oct 2024 13:24:25 +0000 Date: Wed, 23 Oct 2024 13:24:19 +0000 From: Krzysztof Karas To: CC: Andi Shyti , Nirmoy Das Subject: [PATCH v2] drm/i915: ensure segment offset never exceeds allowed max Message-ID: "Organization: Intel Technology Poland sp. z o.o. - ul. Slowackiego 173, 80-298 Gdansk - KRS 101882 - NIP 957-07-52-316" Content-Disposition: inline X-ClientProxiedBy: ZR0P278CA0131.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::10) To CO1PR11MB5057.namprd11.prod.outlook.com (2603:10b6:303:6c::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR11MB5057:EE_|SN7PR11MB8026:EE_ X-MS-Office365-Filtering-Correlation-Id: 5366c12f-6732-4b65-63c1-08dcf3660357 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?utf-8?q?me4vuifvdog9hJ6LeO8px8BseDIfID0?= =?utf-8?q?zuBFQDmPxnbzvxw7+37I+/vt7k+FJSTSKlh6sXSthDRm1upa7EkLfn4hXDEqJZqto?= =?utf-8?q?qckbu5nR/hlrL5+DgVb5EZ3LDO4ESOW4IG+M0R8+fcsx13ziP5XIfv/9W49t5OKyi?= =?utf-8?q?2pByWvY2XjT8+MIMs2txDtc5YQbeeIV0640UKmFVWegQuY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Yog9s0gilZFAZwu?= =?utf-8?q?BPrL2do0UZlMiRHCt5EjStczYtRhonoYwmat0VYCt/c36LXE2hc4AYvR7jSI5I/Yf?= =?utf-8?q?0W1/lPOz5vE9Pya7gTuOSc1J7WGIBIO1GsjsRQCsviWu1dMYQ1Y2D6wc3MFPwYxx5?= =?utf-8?q?o0XHFKuUNlMmI35d9ygoZPb0z1/mKk0GPxQKfGqjX8KAz3XXIv7OrfHp4=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO1PR11MB5057.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?G3yXbOsGZo3OX22zwCrd5n3dr+64?= =?utf-8?q?sPsvzvbqrLIUI7JKXgmDBsetP6hY7f/BrGRQLPNnqzYlJH46IBmdNsnTo2mcTxasL?= =?utf-8?q?1akVX0CHCv1yisODK0eSQxfIu6UC8DHYcuoX7mnc5jsCXXQ+rKG9nUHdPSOSsCjui?= =?utf-8?q?OWwxQwGlpEBNxX5yA0xHeWjSxuyinp36mvXvwct+k9IYYjt+9gTAxcR3yYQ8dgFZd?= =?utf-8?q?21gzD//J96hC5DQyODfV0ZFYdlGKLhAKmN7hvaeh6ScK59K/ZOW3zXi1hwRejAa8y?= =?utf-8?q?Xdex9C1KDw/dQx1KBHjl3pylncaFrfJDv2tt4fsDewu8EDZHkdinvcRjRd3k1LRDV?= =?utf-8?q?wXo14ht7ha5Tpf9xE6E7j1d0PQY9/n9TS3hVUAoAZC3WEYDOCVOtHR9hZxwyTZoYU?= =?utf-8?q?/tPua8BDixXwW9yz/BU/6M1Ih9ouLNrQEsYMXh2Qyax2yJEqzB0qRTDt+cNVyQ7Zq?= =?utf-8?q?LHAVM0XH7TQldMYY1oOJCQdbdLI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VOaVRpNMLIPlGKkCjiEMiXDwVZuYbad1mnuJn?= =?utf-8?q?rdloYMBpAoUuk/NqbtrWfTB3XgwDlqqRpQOaGrHEItYVogjcEZpSBCVnDGNj7sy48?= =?utf-8?q?VYcnQFvYrtZ0cySEW8x6wB5Yttm7bGG9xjSIXvUGvoEvq0gWDN20LJJG1rl4ioS4D?= =?utf-8?q?0e5etAQEZO8nAsy1t5OA3r882BoiRfztsg=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 5366c12f-6732-4b65-63c1-08dcf3660357 X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB5057.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2024 13:24:25.1099 (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: 0wCjq5wxrYnmxD2qPGQg3DWi0QZyfP/O8+z7oezOeOdFHZ1bZjQiS8sB80zbXgum1annB3MCRrainwyQWC45WcZmiSd/ZHAEe/2rcDKQHcQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR11MB8026 X-OriginatorOrg: intel.com X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Commit 255fc1703e42 ("drm/i915/gem: Calculate object page offset for partial memory mapping") introduced a new offset that affects r.sgt.curr value. This field is used in remap_sg() function, in set_pte_at() call and changing its value causes page table entry to also be affected (see set_ptes() description). Example: 1) upon entering remap_sg() r.sgt.curr could have already been changed to a value equal to or greater than r.sgt.max, 2) set_pte_at() uses r.sgt.curr to map a page entry from another segment to the current one, 3) r->sgt pointer is moved to the next entry returned from __sg_iter() only once, 3) the memory of the mismapped page might become unavailabe (accessing some addresses causes -EFAULT). This patch makes sure we never exceed the allowed segment maximum. v2: - instead of moving segment offset added checking if offset + current segment offset exceed allowed segment max offset before setting new current offset for that segment - changed the patch title from "move segment iterator to match current offset" to "ensure segment offset never exceeds allowed max" Signed-off-by: Krzysztof Karas --- drivers/gpu/drm/i915/i915_mm.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_mm.c b/drivers/gpu/drm/i915/i915_mm.c index f5c97a620962..ba022afc624c 100644 --- a/drivers/gpu/drm/i915/i915_mm.c +++ b/drivers/gpu/drm/i915/i915_mm.c @@ -143,13 +143,15 @@ int remap_io_sg(struct vm_area_struct *vma, /* We rely on prevalidation of the io-mapping to skip track_pfn(). */ GEM_BUG_ON((vma->vm_flags & EXPECTED_FLAGS) != EXPECTED_FLAGS); - while (offset >= sg_dma_len(r.sgt.sgp) >> PAGE_SHIFT) { - offset -= sg_dma_len(r.sgt.sgp) >> PAGE_SHIFT; - r.sgt = __sgt_iter(__sg_next(r.sgt.sgp), use_dma(iobase)); - if (!r.sgt.sgp) - return -EINVAL; + if (r.sgt.curr + (offset << PAGE_SHIFT) < r.sgt.max) { + while (offset >= sg_dma_len(r.sgt.sgp) >> PAGE_SHIFT) { + offset -= sg_dma_len(r.sgt.sgp) >> PAGE_SHIFT; + r.sgt = __sgt_iter(__sg_next(r.sgt.sgp), use_dma(iobase)); + if (!r.sgt.sgp) + return -EINVAL; + } + r.sgt.curr = offset << PAGE_SHIFT; } - r.sgt.curr = offset << PAGE_SHIFT; if (!use_dma(iobase)) flush_cache_range(vma, addr, size);