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=-2.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 9F0BEC3F68F for ; Wed, 4 Dec 2019 15:29:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 58D6520865 for ; Wed, 4 Dec 2019 15:29:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=shipmail.org header.i=@shipmail.org header.b="Rzdema0g" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 58D6520865 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 05FFB6B0B3D; Wed, 4 Dec 2019 10:29:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 010FC6B0B3E; Wed, 4 Dec 2019 10:29:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E41096B0B3F; Wed, 4 Dec 2019 10:29:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0078.hostedemail.com [216.40.44.78]) by kanga.kvack.org (Postfix) with ESMTP id C70316B0B3D for ; Wed, 4 Dec 2019 10:29:18 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 6CBF5181AC9CC for ; Wed, 4 Dec 2019 15:29:18 +0000 (UTC) X-FDA: 76227842796.04.cent18_33dd335686402 X-HE-Tag: cent18_33dd335686402 X-Filterd-Recvd-Size: 7125 Received: from ste-pvt-msa1.bahnhof.se (ste-pvt-msa1.bahnhof.se [213.80.101.70]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Wed, 4 Dec 2019 15:29:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by ste-pvt-msa1.bahnhof.se (Postfix) with ESMTP id 7270D3F8F3; Wed, 4 Dec 2019 16:29:14 +0100 (CET) Authentication-Results: ste-pvt-msa1.bahnhof.se; dkim=pass (1024-bit key; unprotected) header.d=shipmail.org header.i=@shipmail.org header.b=Rzdema0g; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at bahnhof.se Received: from ste-pvt-msa1.bahnhof.se ([127.0.0.1]) by localhost (ste-pvt-msa1.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LxC5UGT91HcE; Wed, 4 Dec 2019 16:29:13 +0100 (CET) Received: from mail1.shipmail.org (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) (Authenticated sender: mb878879) by ste-pvt-msa1.bahnhof.se (Postfix) with ESMTPA id 111443F8A2; Wed, 4 Dec 2019 16:29:10 +0100 (CET) Received: from localhost.localdomain (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) by mail1.shipmail.org (Postfix) with ESMTPSA id 4081F360608; Wed, 4 Dec 2019 16:29:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shipmail.org; s=mail; t=1575473350; bh=yHBICBBNQ0xElpVdR6AIUN8r0Xt8fA+KemiJ+/fl3xo=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=Rzdema0gbT4sovNyPVOJezOySXEW3YILI0pE4CjzAeyAuHOWqcJbymOFlOqPY2adU EBEAuAiIOZ52jwTe8zy/g3MMIbv2bv1j3OIW7Ls9NxtMFOyvsmNNSOIF6AnTMFXLl9 +WWSDCbGDRd76MwdlkHEzVuWOQ2msjKXixkIN7cw= Subject: Re: [PATCH v2 2/2] drm/ttm: Fix vm page protection handling To: Michal Hocko Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, pv-drivers@vmware.com, linux-graphics-maintainer@vmware.com, Thomas Hellstrom , Andrew Morton , "Matthew Wilcox (Oracle)" , "Kirill A. Shutemov" , Ralph Campbell , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , =?UTF-8?Q?Christian_K=c3=b6nig?= References: <20191203104853.4378-1-thomas_os@shipmail.org> <20191203104853.4378-3-thomas_os@shipmail.org> <20191204135219.GH25242@dhcp22.suse.cz> <20191204143521.GJ25242@dhcp22.suse.cz> <5c2658b6-b5ec-5747-c360-fada54d759ed@shipmail.org> <20191204144248.GK25242@dhcp22.suse.cz> <20191204152644.GL25242@dhcp22.suse.cz> From: =?UTF-8?Q?Thomas_Hellstr=c3=b6m_=28VMware=29?= Organization: VMware Inc. Message-ID: <70d8fe46-2703-d0d4-d70e-abccf07e64b5@shipmail.org> Date: Wed, 4 Dec 2019 16:29:08 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20191204152644.GL25242@dhcp22.suse.cz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US 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 12/4/19 4:26 PM, Michal Hocko wrote: > On Wed 04-12-19 16:19:27, Thomas Hellstr=C3=B6m (VMware) wrote: >> On 12/4/19 3:42 PM, Michal Hocko wrote: >>> On Wed 04-12-19 15:36:58, Thomas Hellstr=C3=B6m (VMware) wrote: >>>> On 12/4/19 3:35 PM, Michal Hocko wrote: >>>>> On Wed 04-12-19 15:16:09, Thomas Hellstr=C3=B6m (VMware) wrote: >>>>>> On 12/4/19 2:52 PM, Michal Hocko wrote: >>>>>>> On Tue 03-12-19 11:48:53, Thomas Hellstr=C3=B6m (VMware) wrote: >>>>>>>> From: Thomas Hellstrom >>>>>>>> >>>>>>>> TTM graphics buffer objects may, transparently to user-space, m= ove >>>>>>>> between IO and system memory. When that happens, all PTEs pointi= ng to the >>>>>>>> old location are zapped before the move and then faulted in agai= n if >>>>>>>> needed. When that happens, the page protection caching mode- and >>>>>>>> encryption bits may change and be different from those of >>>>>>>> struct vm_area_struct::vm_page_prot. >>>>>>>> >>>>>>>> We were using an ugly hack to set the page protection correctly. >>>>>>>> Fix that and instead use vmf_insert_mixed_prot() and / or >>>>>>>> vmf_insert_pfn_prot(). >>>>>>>> Also get the default page protection from >>>>>>>> struct vm_area_struct::vm_page_prot rather than using vm_get_pag= e_prot(). >>>>>>>> This way we catch modifications done by the vm system for driver= s that >>>>>>>> want write-notification. >>>>>>> So essentially this should have any new side effect on functional= ity it >>>>>>> is just making a hacky/ugly code less so? >>>>>> Functionality is unchanged. The use of a on-stack vma copy was sev= erely >>>>>> frowned upon in an earlier thread, which also points to another si= milar >>>>>> example using vmf_insert_pfn_prot(). >>>>>> >>>>>> https://lore.kernel.org/lkml/20190905103541.4161-2-thomas_os@shipm= ail.org/ >>>>>> >>>>>>> In other words what are the >>>>>>> consequences of having page protection inconsistent from vma's? >>>>>> During the years, it looks like the caching- and encryption flags = of >>>>>> vma::vm_page_prot have been largely removed from usage. From what = I can >>>>>> tell, there are no more places left that can affect TTM. We discus= sed >>>>>> __split_huge_pmd_locked() towards the end of that thread, but that= doesn't >>>>>> affect TTM even with huge page-table entries. >>>>> Please state all those details/assumptions you are operating on in = the >>>>> changelog. >>>> Thanks. I'll update the patchset and add that. >>> And thinking about that this also begs for a comment in the code to >>> explain that some (which?) mappings might have a mismatch and the >>> generic code have to be careful. Because as things stand now this see= ms >>> to be really subtle and happen to work _now_ and might break in the f= uture. >>> Or what does prevent a generic code to stumble over this discrepancy? >> Yes we had that discussion in the thread I pointed to. I initially sug= gested >> and argued for updating the vma::vm_page_prot using a WRITE_ONCE() (we= only >> have the mmap_sem in read mode), there seems to be other places in gen= eric >> code that does the same. >> >> But I was convinced by Andy that this was the right way and also was u= sed >> elsewhere. >> >> (See also https://elixir.bootlin.com/linux/latest/source/arch/x86/entr= y/vdso/vma.c#L116) >> >> I guess to have this properly formulated, what's required is that gene= ric >> code doesn't build page-table entries using vma::vm_page_prot for VM_P= FNMAP >> and VM_MIXEDMAP outside of driver control. > Let me repeat that this belongs to a code somewhere everybody can see i= t > rather than a "random" discussion at mailing list. > > Thanks! Yes, I agree. I'll of course follow up with the comments added to the cod= e. Thomas