From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3E4AC433C1 for ; Fri, 26 Mar 2021 09:08:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2F4C961A18 for ; Fri, 26 Mar 2021 09:08:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F4C961A18 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shipmail.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A41EF6B0070; Fri, 26 Mar 2021 05:08:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F0A86B0071; Fri, 26 Mar 2021 05:08:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 891326B0072; Fri, 26 Mar 2021 05:08:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0217.hostedemail.com [216.40.44.217]) by kanga.kvack.org (Postfix) with ESMTP id 6E5E06B0070 for ; Fri, 26 Mar 2021 05:08:16 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 30FEC4403 for ; Fri, 26 Mar 2021 09:08:16 +0000 (UTC) X-FDA: 77961448992.03.151CCC6 Received: from ste-pvt-msa2.bahnhof.se (ste-pvt-msa2.bahnhof.se [213.80.101.71]) by imf29.hostedemail.com (Postfix) with ESMTP id 950EFE7 for ; Fri, 26 Mar 2021 09:08:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by ste-pvt-msa2.bahnhof.se (Postfix) with ESMTP id 1DC413F710; Fri, 26 Mar 2021 10:08:13 +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=XBiIKNzS; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at bahnhof.se 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 W3vNEgFD6zst; Fri, 26 Mar 2021 10:08:12 +0100 (CET) Received: by ste-pvt-msa2.bahnhof.se (Postfix) with ESMTPA id B94233F700; Fri, 26 Mar 2021 10:08:09 +0100 (CET) Received: from [192.168.0.209] (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) by mail1.shipmail.org (Postfix) with ESMTPSA id 73A8036038A; Fri, 26 Mar 2021 10:08:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shipmail.org; s=mail; t=1616749689; bh=zuYrGAApGngho8MEJbXBz9G6vYyoZHyySgz3/3ORMQg=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=XBiIKNzShcuFNlOrfx5XWTTyCmrpSeuD7Tdp27rmjgCY4aXPbiI7T3sGtpi8R5XJY ilZ3CxoRblu83kVm0bfs6NmsWN7lbKWbGqv28HLgxd5bBeaPEWrfoDKo8ZtHAR5mRb cQ84orgrJJg7gUzVFywLdqxBS6OmKSUftw7e+UQ0= Subject: Re: [RFC PATCH 1/2] mm,drm/ttm: Block fast GUP to TTM huge pages To: Jason Gunthorpe Cc: Dave Hansen , "Williams, Dan J" , "dri-devel@lists.freedesktop.org" , "christian.koenig@amd.com" , "airlied@linux.ie" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "akpm@linux-foundation.org" References: <75423f64-adef-a2c4-8e7d-2cb814127b18@intel.com> <6b0de827-738d-b3c5-fc79-8ca9047bad35@intel.com> <9f789d64-940f-c728-8d5e-aab74d562fb6@shipmail.org> <20210325175504.GH2356281@nvidia.com> <1ed48d99-1cd9-d87b-41dd-4169afc77f70@shipmail.org> <20210325182442.GI2356281@nvidia.com> From: =?UTF-8?Q?Thomas_Hellstr=c3=b6m_=28Intel=29?= Message-ID: <1eda588b-ae51-9b69-4bd4-da37b2aa1e4b@shipmail.org> Date: Fri, 26 Mar 2021 10:08:09 +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: <20210325182442.GI2356281@nvidia.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Stat-Signature: h3g77c4i5hzpyhu7bjxu3957e51rhfj9 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 950EFE7 Received-SPF: none (shipmail.org>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=ste-pvt-msa2.bahnhof.se; client-ip=213.80.101.71 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616749693-560951 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 3/25/21 7:24 PM, Jason Gunthorpe wrote: > On Thu, Mar 25, 2021 at 07:13:33PM +0100, Thomas Hellstr=C3=B6m (Intel)= wrote: >> On 3/25/21 6:55 PM, Jason Gunthorpe wrote: >>> On Thu, Mar 25, 2021 at 06:51:26PM +0100, Thomas Hellstr=C3=B6m (Inte= l) wrote: >>>> On 3/24/21 9:25 PM, Dave Hansen wrote: >>>>> On 3/24/21 1:22 PM, Thomas Hellstr=C3=B6m (Intel) wrote: >>>>>>> We also have not been careful at *all* about how _PAGE_BIT_SOFTW*= are >>>>>>> used.=C2=A0 It's quite possible we can encode another use even in= the >>>>>>> existing bits. >>>>>>> >>>>>>> Personally, I'd just try: >>>>>>> >>>>>>> #define _PAGE_BIT_SOFTW5=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= 57=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* available for programmer */ >>>>>>> >>>>>> OK, I'll follow your advise here. FWIW I grepped for SW1 and it se= ems >>>>>> used in a selftest, but only for PTEs AFAICT. >>>>>> >>>>>> Oh, and we don't care about 32-bit much anymore? >>>>> On x86, we have 64-bit PTEs when running 32-bit kernels if PAE is >>>>> enabled. IOW, we can handle the majority of 32-bit CPUs out there. >>>>> >>>>> But, yeah, we don't care about 32-bit. :) >>>> Hmm, >>>> >>>> Actually it makes some sense to use SW1, to make it end up in the sa= me dword >>>> as the PSE bit, as from what I can tell, reading of a 64-bit pmd_t o= n 32-bit >>>> PAE is not atomic, so in theory a huge pmd could be modified while r= eading >>>> the pmd_t making the dwords inconsistent.... How does that work with= fast >>>> gup anyway? >>> It loops to get an atomic 64 bit value if the arch can't provide an >>> atomic 64 bit load >> Hmm, ok, I see a READ_ONCE() in gup_pmd_range(), and then the resultin= g pmd >> is dereferenced either in try_grab_compound_head() or __gup_device_hug= e(), >> before the pmd is compared to the value the pointer is currently point= ing >> to. Couldn't those dereferences be on invalid pointers? > Uhhhhh.. That does look questionable, yes. Unless there is some tricky > reason why a 64 bit pmd entry on a 32 bit arch either can't exist or > has a stable upper 32 bits.. > > The pte does it with ptep_get_lockless(), we probably need the same > for the other levels too instead of open coding a READ_ONCE? > > Jason TBH, ptep_get_lockless() also looks a bit fishy. it says "it will not switch to a completely different present page without a TLB=20 flush in between". What if the following happens: processor 1: Reads lower dword of PTE. processor 2: Zaps PTE. Gets stuck waiting to do TLB flush processor 1: Reads upper dword of PTE, which is now zero. processor 3: Hits a TLB miss, reads an unpopulated PTE and faults in a=20 new PTE value which happens to be the same as the original one before=20 the zap. processor 1: Reads the newly faulted in lower dword, compares to the old=20 one, gives an OK and returns a bogus PTE. /Thomas