Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4398238pxf; Tue, 23 Mar 2021 09:36:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwP0RvwOsoI5Ik6NFslxZxaYmDzZFFC8iWlXHQuv8a8eev3HuKC8BSKEUDzae4sOPnazRQf X-Received: by 2002:a17:907:10ce:: with SMTP id rv14mr5878148ejb.56.1616517417914; Tue, 23 Mar 2021 09:36:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616517417; cv=none; d=google.com; s=arc-20160816; b=ZjoPPo3ijD3cXrwx6CW6B3fs1z5ays9u0pvNrfMBXWCnMGM/Ycjhg4wsAXjeLyeVum ZVRxoMGJ0gQowJkWT7UdVGYOIZ1RNCno4mj7+1TJnGoQlVvUbf9Ay7oH4SCIHyr42p5G WIqpNab56VIj8q6MXnwjFJHqbdDg78Dq2/153eHnEDIGAoZVO7v1Ak7xUe/4dCZJc+ae 3iVaX4xKecKGVXx5JsQH2RaN6B597y2dtMxbX1RojjGxU1jDm5zuXylvRvUZpwnBcfht WWvUHVYfmMoLvLMocYhGwbEQwaKjdeDhZrlWn0EcAEv1Dr4OIbtlz1WK2vMWwH2GrszF tfHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject:dkim-signature; bh=Q7eKun1E1p4Tm6E6gqhtQD81smTOmDbNFzSvbeLZdmc=; b=ac6HUQ7PW4WukgNFL5pXfYi/i5RHjLzZqNdWn6ZgC3QZciLKVSUcFTWFbDDTo1VRod GJOb/8u1xuQLXdvuBTGe/qooaadoS1pH6mWnQl5AOxIMqOShiAk3hWpkvJcxB+JD0M1e MLPvIBsI1q7DTk0sJb6AWYQmiwRSfP1PJ7M5dzpgASKyqS+WvytDngM6moY0gWh/l0w0 wlhlS84bt1Rv31+s4okqFNaAb2nGkTWGkNuy39/6wpVRbfnWvnkFus8rhSHQRNgqs5xL lD3ybd052lDa3ku358PwzlbFRW3AEqs9TtXM/j4Ksr7wWxEJD/6ZtSAMKERy6FZd7Pmw hk0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@shipmail.org header.s=mail header.b=dWhU36oH; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rh9si14750900ejb.417.2021.03.23.09.36.34; Tue, 23 Mar 2021 09:36:57 -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=fail (test mode) header.i=@shipmail.org header.s=mail header.b=dWhU36oH; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233308AbhCWQf2 (ORCPT + 99 others); Tue, 23 Mar 2021 12:35:28 -0400 Received: from ste-pvt-msa2.bahnhof.se ([213.80.101.71]:21037 "EHLO ste-pvt-msa2.bahnhof.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233316AbhCWQe7 (ORCPT ); Tue, 23 Mar 2021 12:34:59 -0400 Received: from localhost (localhost [127.0.0.1]) by ste-pvt-msa2.bahnhof.se (Postfix) with ESMTP id AF9363FD99; Tue, 23 Mar 2021 17:34:57 +0100 (CET) Authentication-Results: ste-pvt-msa2.bahnhof.se; dkim=pass (1024-bit key; unprotected) header.d=shipmail.org header.i=@shipmail.org header.b=dWhU36oH; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at bahnhof.se X-Spam-Flag: NO X-Spam-Score: -2.1 X-Spam-Level: X-Spam-Status: No, score=-2.1 tagged_above=-999 required=6.31 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no Authentication-Results: ste-ftg-msa2.bahnhof.se (amavisd-new); dkim=pass (1024-bit key) header.d=shipmail.org Received: from ste-pvt-msa2.bahnhof.se ([127.0.0.1]) by localhost (ste-ftg-msa2.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9IherXCBi9lB; Tue, 23 Mar 2021 17:34:56 +0100 (CET) Received: by ste-pvt-msa2.bahnhof.se (Postfix) with ESMTPA id B899F3FD1E; Tue, 23 Mar 2021 17:34:54 +0100 (CET) Received: from [192.168.0.209] (unknown [192.198.151.43]) by mail1.shipmail.org (Postfix) with ESMTPSA id B711336062E; Tue, 23 Mar 2021 17:34:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shipmail.org; s=mail; t=1616517294; bh=gIwnz5YrpsvMLr1ZSuPnF+kvE+yWmQ+lrSIsK/yX9/I=; h=Subject:To:References:From:Date:In-Reply-To:From; b=dWhU36oHnZbX8U7bf7qWiXkbbDKceZ/x7UyGk/7i1aBzR0TvA9LH9lzV6kmq4XyQB wORqOco+jomxT/WEyvcBbXxqkpKtCF3gresSz/G8v8tlnZOC2JStyhn9LU9EPMB97v ISBy4xgjnQESYi2ph174xiD/L9m3ADfw4ZwHb+AI= Subject: Re: [RFC PATCH 1/2] mm,drm/ttm: Block fast GUP to TTM huge pages To: dri-devel@lists.freedesktop.org, Christian Koenig , David Airlie , Andrew Morton , Jason Gunthorpe , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20210321184529.59006-1-thomas_os@shipmail.org> <20210321184529.59006-2-thomas_os@shipmail.org> From: =?UTF-8?Q?Thomas_Hellstr=c3=b6m_=28Intel=29?= Message-ID: <314fc020-d243-dbf0-acb3-ecfcc9c2443c@shipmail.org> Date: Tue, 23 Mar 2021 17:34:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 3/23/21 12:34 PM, Daniel Vetter wrote: > On Sun, Mar 21, 2021 at 07:45:28PM +0100, Thomas Hellström (Intel) wrote: >> TTM sets up huge page-table-entries both to system- and device memory, >> and we don't want gup to assume there are always valid backing struct >> pages for these. For PTEs this is handled by setting the pte_special bit, >> but for the huge PUDs and PMDs, we have neither pmd_special nor >> pud_special. Normally, huge TTM entries are identified by looking at >> vma_is_special_huge(), but fast gup can't do that, so as an alternative >> define _devmap entries for which there are no backing dev_pagemap as >> special, update documentation and make huge TTM entries _devmap, after >> verifying that there is no backing dev_pagemap. >> >> One other alternative would be to block TTM huge page-table-entries >> completely, and while currently only vmwgfx use them, they would be >> beneficial to other graphis drivers moving forward as well. >> >> Cc: Christian Koenig >> Cc: David Airlie >> Cc: Daniel Vetter >> Cc: Andrew Morton >> Cc: Jason Gunthorpe >> Cc: linux-mm@kvack.org >> Cc: dri-devel@lists.freedesktop.org >> Cc: linux-kernel@vger.kernel.org >> Signed-off-by: Thomas Hellström (Intel) >> --- >> drivers/gpu/drm/ttm/ttm_bo_vm.c | 17 ++++++++++++++++- >> mm/gup.c | 21 +++++++++++---------- >> mm/memremap.c | 5 +++++ >> 3 files changed, 32 insertions(+), 11 deletions(-) >> >> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c >> index 6dc96cf66744..1c34983480e5 100644 >> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c >> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c >> @@ -195,6 +195,7 @@ static vm_fault_t ttm_bo_vm_insert_huge(struct vm_fault *vmf, >> pfn_t pfnt; >> struct ttm_tt *ttm = bo->ttm; >> bool write = vmf->flags & FAULT_FLAG_WRITE; >> + struct dev_pagemap *pagemap; >> >> /* Fault should not cross bo boundary. */ >> page_offset &= ~(fault_page_size - 1); >> @@ -210,6 +211,20 @@ static vm_fault_t ttm_bo_vm_insert_huge(struct vm_fault *vmf, >> if ((pfn & (fault_page_size - 1)) != 0) >> goto out_fallback; >> >> + /* >> + * Huge entries must be special, that is marking them as devmap >> + * with no backing device map range. If there is a backing >> + * range, Don't insert a huge entry. >> + * If this check turns out to be too much of a performance hit, >> + * we can instead have drivers indicate whether they may have >> + * backing device map ranges and if not, skip this lookup. >> + */ > I think we can do this statically: > - if it's system memory we know there's no devmap for it, and we do the > trick to block gup_fast Yes, that should work. > - if it's iomem, we know gup_fast wont work anyway if don't set PFN_DEV, > so might as well not do that I think gup_fast will unfortunately mistake a huge iomem page for an ordinary page and try to access a non-existant struct page for it, unless we do the devmap trick. And the lookup would then be for the rare case where a driver would have already registered a dev_pagemap for an iomem area which may also be mapped through TTM (like the patch from Felix a couple of weeks ago). If a driver can promise not to do that, then we can safely remove the lookup. /Thomas