From patchwork Mon Oct 28 16:00:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Karas, Krzysztof" X-Patchwork-Id: 13853722 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 B1144D3399B for ; Mon, 28 Oct 2024 16:03:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5D3C810E519; Mon, 28 Oct 2024 16:03:27 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="KzfQeOh7"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5535010E510 for ; Mon, 28 Oct 2024 16:03:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730131406; x=1761667406; h=date:from:to:cc:subject:message-id:mime-version; bh=PxJVOSetLGeMFuBaXF22MiYIRUXePUL07NqPK3wcCgw=; b=KzfQeOh7xL4CdVzNMzfimBvbeT+OWk9nr3SXVo3oCXpsGQ7NAq0H35qp ZPGqZxfeIMvd0h80o/GfcA6vcPwwCg+0zmA+BE88VsTNPzduILHyLpzBg WA4tPt+oXQ+zHSxZ8PQPKuReVQXv1b8dOQUgsB+3oXYdzv+7YQ+cIDkCd gDBdHqH3W4+ul7PPIPyh6/EuJ3RJCPytV0t5mhCbOzigLpOopVc4RIC/Z XfShJGDekzKuI9DLhjEJlkHSfENXeq52k8hs4EIO7GSvK9M0EMm+M642A xyQy17+6wglgCpXM/jEXjJT94dUbxxF3Ae41hmhpV9O5i44wD+85Ay2bH Q==; X-CSE-ConnectionGUID: qCw7GQLWQhCIewsQEk1IzQ== X-CSE-MsgGUID: 6fLUlGdZTHeVbkLlrI8C/w== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="47195373" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="47195373" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2024 09:01:07 -0700 X-CSE-ConnectionGUID: 4RUExR0wSqmVEAOjo8RO+g== X-CSE-MsgGUID: B222NQwYSJONsWxuz1N/Zg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,239,1725346800"; d="scan'208";a="82081050" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orviesa007.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 28 Oct 2024 09:01:07 -0700 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 28 Oct 2024 09:01:06 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) 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; Mon, 28 Oct 2024 09:01:06 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.47) 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.2507.39; Mon, 28 Oct 2024 09:01:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IetCkAw/jMTezg6Xek8as5cBkAA8PsrP2I+VY4dYcWHmbh7EZDNqy8mJtTLx9Q+3Z/Z6FOvRJa5H9iPRSN0WJnIOEVpTZ587Zn5Rf6VUeIqpnLJ29fGyOlIrW+VRZp0UziWyPOnLHKJJ9l18bm1aHMZIDIXTYreCkRwpRFUqH4ZlPs+ASLptWL8GqvguUS0xY7FVStkKEbzmCKl/YayYDt4cTlgPXD0fr3jtJ3zHL7rFm7gfC5VLf4mAm94v6yyQbWJv2PBmo2Kp2oOErYXZ/SH9I0CtTh0czWAvquWw0CI4ovD77gMmSB3ij2BNE1J58ZaSUUeX0UPtlkPaNvxzIg== 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=71kUaU3lLFrJ1aSQWUJVBWjDni/kn6rtJbxXZ51MnzA=; b=vycYeuptWUQXe4cSPjNuvpRKjrY3mjkMPw1P6dYoyk9aOg3NPgclzEd0pmwC+wP/VNwCj3Ls4HQJupCR9tFHPKCBhKtf5j8P7bL0LocSEQC4O0dFpxyS88EnxmqW7LAVfIZ4Phk8y6sIzn59dle+zbMWPHaSKfSn5svdJoSJ5ZdGRUqwv7mAgsrc23W5oc88fufj/cfbhVWBbvENTPIZcEbKODuFQhoyDaUwmSTkEslaJ1d6xTdpG42JKSy7cxwJAEVbF9UWrv/KWc5g6oaorFoysS7As6/Npa2NFcGvjwN5dtuJvt7XGRgx0XlOi14EhWgKYfxEKfOwS7wTO+rE0g== 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 PH8PR11MB7990.namprd11.prod.outlook.com (2603:10b6:510:259::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.27; Mon, 28 Oct 2024 16:00:57 +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.023; Mon, 28 Oct 2024 16:00:57 +0000 Date: Mon, 28 Oct 2024 16:00:48 +0000 From: "Karas, Krzysztof" To: CC: Andi Shyti Subject: [PATCH v4] 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: DUZPR01CA0175.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b3::19) To CO1PR11MB5057.namprd11.prod.outlook.com (2603:10b6:303:6c::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR11MB5057:EE_|PH8PR11MB7990:EE_ X-MS-Office365-Filtering-Correlation-Id: caa4481b-550e-465e-602d-08dcf769b5f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?+wP41211FqSC9QrqS+B6L+T0be6iwAl?= =?utf-8?q?2cN9PnJi/mVdWqj2ir8jGIuYuQTlbu1azdq1zksFrtBBKXN/tPzpOUMFF/aLLO0L/?= =?utf-8?q?hOoSYUCm7qJVy6CotQNf5+INuIua7ks6CrdkxEX3zuOLxaWiCb2Zk2mYVGuoNBq6S?= =?utf-8?q?WIaUI8BOvMHwATtpNLrbvi7RK6KyD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Hjyqn5KvAjgpzFrjG3N1PsQ0qf?= =?utf-8?q?0mpvDhXFOK3iW+gGgRisO2AZHrjc1Lb9cJLYOf/vbIh9WSla0mC3Gbx8er2Rd898R?= =?utf-8?q?Yh6ug1NZrPChzUQnp0lfvfHEABCM7lO/KAMmaWRuYfMKx2jn3dffaG0c/k3fC1gEn?= =?utf-8?q?v/bc/cZo1lFBPQ0698AZ4u9Vd0ZMNifL2aZogPxENVbz9QV1EGIBPBuRY=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)(366016)(1800799024)(376014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?B6g7DJem/G2Qrk8jo8zjJgmBiZn8?= =?utf-8?q?b9bNo3bUV3jE6U03WV1V33Et25BsfoN6YDOEsyTHjlHE5N7BoDxSQKC0RZRMwiMPA?= =?utf-8?q?a66t8z8BkUwhqxAgFq2JVFyLj1ET/xI6PsIG8bSJDT2zbe5fD7IC4JpXYzC7u3kd/?= =?utf-8?q?Fkm7BfKMe/v6fLNhJSj+fAGmyBaCWnHzswdgdTswE1H/+drj9MKkc42uw8K6wTK+I?= =?utf-8?q?PrWtqXDNVDbI6GD+EB0d99kXVIip3O8dggyU/KEnFygx5R88OpE4G/3offtQT2e9e?= =?utf-8?q?JC8TIqc8wi/nDpQZ7iUSqLI9+RBSaTOPX9GE+KnNCXE0jPvnCxiOdg+sCAuNsyOph?= =?utf-8?q?mAeS/SR8Av8D5ny7bv2ZMIvou0p9EZlLfsfcSzsZ5lTP5qU8MSrHkZQeWeOQOtpv9?= =?utf-8?q?VMnPgG/hyYTOzRMqZqAxjvenz/6WQnmseGwq7hM6W+anLnvK7zOtHIiAIuTPrT/TA?= =?utf-8?q?IDmbMZKIApv4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FSN6BV1iR5cF9vJE46f7AJ4Daj4px9DAItUy8E?= =?utf-8?q?ppbr1Q8txvK5Jj6Hsdc6vVAAfvxvRylIzWOV/5jihc7QIYt7Atg1pwV+d0sLYKf8r?= =?utf-8?q?fuEQBrrFFI+idNnargVYz0r940/BcWq00XPDWHxCjMqr+cA0JUq/ULEdxYuot5KHp?= =?utf-8?q?56/XCTG0V41CpmUaeN59UB21lxeTb49FjQ=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: caa4481b-550e-465e-602d-08dcf769b5f3 X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB5057.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 16:00:57.7219 (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: 6g2ouXKunfVo2dmwF7L3uVTgqBoYWhKJ120SdKmYG0GvlHAe1zxjcSkuAWZ4oAqGLNdEC+b1HSDExSQqUlC9JRg7/DN18A8u2hNOHhGx2ug= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR11MB7990 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 is compared to sg_dma_len(r.sgt.sgp) in remap_io_sg() function. However, later in remap_sg() the offset (which at that point resides in r->sgt.curr) is compared to r->sgt.max. Scatter-gather list's max relies on one of two values (see i915_scatterlist.h): a) sg_dma_len(s.sgp) when `dma` is true, b) s.sgp->length otherwise. This suggests that in cases where `dma` is false, we should use s.sgp->length to determine the max value instead of sg_dma_len(), which is used regardless in remap_io_sg() (use_dma(iobase) might return false there). This patch uses r.sgt.max to check if offset is within allowed bounds, because that max value is already set according to the `dma` value. v3: - instead of checking if r.sgt.curr would exceed allowed max, changed the value in the while loop to be aligned with `dma` value. v4: - remove unnecessary parent relation Signed-off-by: Krzysztof Karas --- drivers/gpu/drm/i915/i915_mm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_mm.c b/drivers/gpu/drm/i915/i915_mm.c index f5c97a620962..76e2801619f0 100644 --- a/drivers/gpu/drm/i915/i915_mm.c +++ b/drivers/gpu/drm/i915/i915_mm.c @@ -143,8 +143,8 @@ 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; + while (offset >= r.sgt.max >> PAGE_SHIFT) { + offset -= r.sgt.max >> PAGE_SHIFT; r.sgt = __sgt_iter(__sg_next(r.sgt.sgp), use_dma(iobase)); if (!r.sgt.sgp) return -EINVAL;