Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp375263pxx; Wed, 28 Oct 2020 07:01:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx77AE7ff8YYWFvfCKTt5IgggA8eVhX9c3rdRzqTBRw8WMpcy7LaXX3cootjDmCqIOp8eOK X-Received: by 2002:a17:907:9604:: with SMTP id gb4mr7855777ejc.336.1603893686812; Wed, 28 Oct 2020 07:01:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603893686; cv=none; d=google.com; s=arc-20160816; b=PGqQ81zOGJoylTGmpfoSPtUPE0Ba8tmJ/9x5siBBH63bAFoh9XycFGQQaYbEFg4CRm 3JGoXS2fahfjc46HPuC2ENDlMjkA1j6yKEAeirc6x2ajiTyzSs1Vz0SX/zXH/bcFebSq zyL2LcgCvnmHpxMWe1h8CYm7q/gu6nqebZf7dx9OVFT1l/s+daXyzV3mCMz0m4QgVJNy waCTbhiPYw3W78NK5lq/xQBr0Pkhe7nQYwdJdruj+BZzJdMRuNsdsfi8cVCvr+ptAYy7 PAskX+0TfrtjA3cKJ2rKBBPs2mbDfMM+JB48qUoxPiBKI04JrLpx3z6LcfXDuRqlSCAF 7Raw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Fj7NYGKIRN/ahAU4aqH/enCoAl4r180trnQlRUZioIs=; b=mW/Y2/S5/EbPJ2AVfMS2gc2MRE1vwJjzUQx5k1WohDmbCV1uYvwEpF0HPxkPLmv6Jy +rge87MO+X8o6InN36USGxLwR/n634OnTRLzd4fmxc7zfkA/WF89XRCYV7hlk0gzzw5j I6XmUL68rbdvSXhVJYDWkIXgD2ZANx3cAhXPQgl+DNgGtuEXAdYOpqLJOg2Hc25DTxN5 mtr5ehLPgpKcNUQ7RzRT6DtCqJjD8kgUZw/ZpuOq7NGM5sBzYCL7bxQ+yfqvS+Aak9dm dgt0g1camPQrSqWIUhWVmbE0Od5ZpBidFwF5pixlpFG7C2VrTZHheir542NMWrEzJM82 ZhpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=q5h34fRF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b29si2827715edn.354.2020.10.28.07.01.04; Wed, 28 Oct 2020 07:01:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=q5h34fRF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1803691AbgJ0PxU (ORCPT + 99 others); Tue, 27 Oct 2020 11:53:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:44088 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2902169AbgJ0P2M (ORCPT ); Tue, 27 Oct 2020 11:28:12 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 69CDC20780; Tue, 27 Oct 2020 15:28:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603812492; bh=4e9p/9RGJecZjzwk6cILIlPkuo81AdEUtggPfb+TCXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q5h34fRFk2ayP/VhHrh+qoeR91BqP8HtUdq7LjuteaUA/1sZOyu1m1sx4ftuIPbr+ NbDko7vJKWuuiU48g8LnIPi8TLbSbX1Zq9cctszjv8prMbw2pYb5cLTkyCwTdRw+85 mCf1iuU6jH7FYFJlEo2QCgMWGAb3/Ng8HeW2yKwM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Christian=20K=C3=B6nig?= , xinhui pan , Alex Deucher , Sasha Levin Subject: [PATCH 5.9 228/757] drm/amdgpu: fix max_entries calculation v4 Date: Tue, 27 Oct 2020 14:47:58 +0100 Message-Id: <20201027135501.302889854@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christian König [ Upstream commit ee354ff1c7c210fb41952ebf0a820fb714eae7b1 ] Calculate the correct value for max_entries or we might run after the page_address array. v2: Xinhui pointed out we don't need the shift v3: use local copy of start and simplify some calculation v4: fix the case that we map less VA range than BO size Signed-off-by: Christian König Fixes: 1e691e244487 drm/amdgpu: stop allocating dummy GTT nodes Reviewed-by: xinhui pan Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 71e005cf29522..479735c448478 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -1691,13 +1691,13 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, uint64_t max_entries; uint64_t addr, last; + max_entries = mapping->last - start + 1; if (nodes) { addr = nodes->start << PAGE_SHIFT; - max_entries = (nodes->size - pfn) * - AMDGPU_GPU_PAGES_IN_CPU_PAGE; + max_entries = min((nodes->size - pfn) * + AMDGPU_GPU_PAGES_IN_CPU_PAGE, max_entries); } else { addr = 0; - max_entries = S64_MAX; } if (pages_addr) { @@ -1727,7 +1727,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, addr += pfn << PAGE_SHIFT; } - last = min((uint64_t)mapping->last, start + max_entries - 1); + last = start + max_entries - 1; r = amdgpu_vm_bo_update_mapping(adev, vm, false, false, resv, start, last, flags, addr, dma_addr, fence); -- 2.25.1