Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3830083pxf; Mon, 29 Mar 2021 12:42:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwvxM7TEXciSh1VYBV0YDCOxY5qm8ofl9P9VpjeREcXNYcHnh+FhEzwEgrbNh8I5oq5H31 X-Received: by 2002:a17:906:3952:: with SMTP id g18mr30010135eje.104.1617046927157; Mon, 29 Mar 2021 12:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617046927; cv=none; d=google.com; s=arc-20160816; b=dQkgFGPL5brCxcYBP1M/j46JA0IDr1J3DDdvWpSlTAJfbVxn2QCVywFicToBvf81n0 J9uNyxfkbO1yh16ac3qb9lK/+e3hD930lPa9fJOAN7ArOGgbh9wGHW8yIzFNY2i3520C Ty8JCdGybRzXDoTNisu+zyRu0FyEgm4QMhAQVw62ucSsvHJlIGc+recG6b0I2mTurU6O f3ZVoK8XTd3Wl8z3RmMbk/nYnYS58p0nodxPXsyWXaypzVq3jKVvE1VgdIMVG7P7Jib/ 52Ev/zVvwHLGSXutezGOkBETUgjvsdFOGUBbWSZutp7ty6Bk8SoDvGfE8DZiJzChA4+o yINg== 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:date:cc:to:from:subject :message-id:dkim-signature; bh=687Ppfrnu+qUdbeUIYIFSXDsMzZ8iILj4Dx2KqtjW/U=; b=e+IOlO3Dmn/TVmrUCOZT9fqTsIBN2ow8VTxsyuogcXD1F6S9mO/BpgyBxkAvMsBi6E wYFsQlGoS9FZElAByeqAAaZ+Y7UBSacGjbyW4DEU5J59tFJz17VSOwNbRl4JCUEe6I6p top6JpPuUzLAkZ4vSeKYLmC7KVDVU43N9fTTKs9jq4BMMcoGnaXJuRQKJWVSQ8bLGNoJ tnaX3TiCwk3V2PbQgAk100t1rG0K6a7i1RLZ1vx7Lv+IPMw4dehzrzQti8Qq3Ma+Kz8S jMuLh0V19RuMUO7pVnEPoqd2BYk+U2c465tw+2seqi8uDKCNfRC5oz+9PtHMdejIfM72 9dDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mengyan1223.wang header.s=mail header.b=ZyKImvXe; 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=pass (p=NONE sp=NONE dis=NONE) header.from=mengyan1223.wang Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g7si12801391edb.286.2021.03.29.12.41.43; Mon, 29 Mar 2021 12:42:07 -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=@mengyan1223.wang header.s=mail header.b=ZyKImvXe; 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=pass (p=NONE sp=NONE dis=NONE) header.from=mengyan1223.wang Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231319AbhC2Tks (ORCPT + 99 others); Mon, 29 Mar 2021 15:40:48 -0400 Received: from mengyan1223.wang ([89.208.246.23]:54236 "EHLO mengyan1223.wang" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230346AbhC2Tk2 (ORCPT ); Mon, 29 Mar 2021 15:40:28 -0400 Received: from [IPv6:240e:35a:1037:8a00:70b2:e35d:833c:af3e] (unknown [IPv6:240e:35a:1037:8a00:70b2:e35d:833c:af3e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384)) (Client did not present a certificate) (Authenticated sender: xry111@mengyan1223.wang) by mengyan1223.wang (Postfix) with ESMTPSA id 4312765B2D; Mon, 29 Mar 2021 15:40:17 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mengyan1223.wang; s=mail; t=1617046827; bh=687Ppfrnu+qUdbeUIYIFSXDsMzZ8iILj4Dx2KqtjW/U=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ZyKImvXezPMBrMUDK328o5CRlvO1WgAh8QkuK2OCykIvMmTRr+oS1bLeC6W0MEP1J 5B9dudutLUFa2t6IaopBJqtO4LaB6K57CCJoMfMWsgD2gafm5wup9G/+yS5WbwD0lg PVZxAfRjQARxthGpJpDfw/g4d4CEornm6bquK5TNFtsAHQfbs6V0A1g56dPYx7xoXf K0IH4KlBINJuPCwsLFNFKe2Jn+WwfOmviM/KvHx5gmarPHTyFz3mkcdQ53d0Nf81K0 Vv+RAP3JgC3PJTrDfsUiTQj9KVA/QEqfkLaeq7eGM9X50KBnai7tsOchwRVH0P3VWb zexHnusJZ01KQ== Message-ID: <368b9b1b7343e35b446bb1028ccf0ae75dc2adc4.camel@mengyan1223.wang> Subject: Re: [PATCH] drm/amdgpu: fix an underflow on non-4KB-page systems From: Xi Ruoyao To: Christian =?ISO-8859-1?Q?K=F6nig?= , Alex Deucher , Christian =?ISO-8859-1?Q?K=F6nig?= Cc: David Airlie , Felix Kuehling , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Dan =?ISO-8859-1?Q?Hor=E1k?= , amd-gfx@lists.freedesktop.org, Daniel Vetter , stable@vger.kernel.org Date: Tue, 30 Mar 2021 03:40:04 +0800 In-Reply-To: <7701fb71-9243-2d90-e1e1-d347a53b7d77@gmail.com> References: <20210329175348.26859-1-xry111@mengyan1223.wang> <9a11c873-a362-b5d1-6d9c-e937034e267d@gmail.com> <84b3911173ad6beb246ba0a77f93d888ee6b393e.camel@mengyan1223.wang> <97c520ce107aa4d5fd96e2c380c8acdb63d45c37.camel@mengyan1223.wang> <7701fb71-9243-2d90-e1e1-d347a53b7d77@gmail.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-03-29 21:36 +0200, Christian König wrote: > Am 29.03.21 um 21:27 schrieb Xi Ruoyao: > > Hi Christian, > > > > I don't think there is any constraint implemented to ensure `num_entries % > > AMDGPU_GPU_PAGES_IN_CPU_PAGE == 0`.  For example, in `amdgpu_vm_bo_map()`: > > > >          /* validate the parameters */ > >          if (saddr & AMDGPU_GPU_PAGE_MASK || offset & AMDGPU_GPU_PAGE_MASK > > || > >              size == 0 || size & AMDGPU_GPU_PAGE_MASK) > >                  return -EINVAL; > > > > /* snip */ > > > >          saddr /= AMDGPU_GPU_PAGE_SIZE; > >          eaddr /= AMDGPU_GPU_PAGE_SIZE; > > > > /* snip */ > > > >          mapping->start = saddr; > >          mapping->last = eaddr; > > > > > > If we really want to ensure (mapping->last - mapping->start + 1) % > > AMDGPU_GPU_PAGES_IN_CPU_PAGE == 0, then we should replace > > "AMDGPU_GPU_PAGE_MASK" > > in "validate the parameters" with "PAGE_MASK". > > Yeah, good point. > > > I tried it and it broke userspace: Xorg startup fails with EINVAL with this > > change. > > Well in theory it is possible that we always fill the GPUVM on a 4k > basis while the native page size of the CPU is larger. Let me double > check the code. > > BTW: What code base are you based on? The code your post here is quite > outdated. Linus' tree. I'll go to sleep now (it's 03:39 here :( ), when I wake up I can try to fetch drm-next or something. -- Xi Ruoyao School of Aerospace Science and Technology, Xidian University