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.5 required=3.0 tests=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 5CF0BC43603 for ; Wed, 4 Dec 2019 15:26:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1B0362073B for ; Wed, 4 Dec 2019 15:26:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B0362073B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BD6156B0B38; Wed, 4 Dec 2019 10:26:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B5D196B0B3A; Wed, 4 Dec 2019 10:26:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D7C16B0B3B; Wed, 4 Dec 2019 10:26:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0009.hostedemail.com [216.40.44.9]) by kanga.kvack.org (Postfix) with ESMTP id 85B736B0B38 for ; Wed, 4 Dec 2019 10:26:48 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 33340582A for ; Wed, 4 Dec 2019 15:26:48 +0000 (UTC) X-FDA: 76227836496.18.cause65_1e379b994822f X-HE-Tag: cause65_1e379b994822f X-Filterd-Recvd-Size: 6901 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Wed, 4 Dec 2019 15:26:47 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id y23so5109312wma.0 for ; Wed, 04 Dec 2019 07:26:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=6KFJXpSjk2QbKXOKeYkEGlVAuJTKJ9X2wspCF7AiQVk=; b=mIqwEwgncQnJu3cDhtXS183XNPYGq5RHEKlmeU4yNCUby3S5ziybWuJ/v+2QTaVuxA SqlshL0lO/Lct69ihLwX40GEu4eYVxsuVNCSuF4iDhAvb0sBxUHTiU+MZFABvmGDlOjB 5mh1QpsgA71jmw8TmfA+N+eQIor8BJA+xOJabvr1rpJVxTk/Fa5UjMYVNO8T5bXTRc6H c196ofHIeYQw5LYqDupRyKQeX1YHLpyhpifrzgS7Dy/sgcOBpnrXiceYpBX/CMmvzizy rrP62pVWEN8B/lfCZBGR/TCkWEQsfsmTlED94YoAc4XhdG1z77c5wj0zbCF8EMemK7Mb GebA== X-Gm-Message-State: APjAAAU/cyrfs6jUrHoPRUKDouEDRqMcQPEodnIAKTIyIcQL9P0k4UAy S7rikgGD1qgw8wfM8lfkF6s= X-Google-Smtp-Source: APXvYqxkvyNs0giQOgDDIyCpxleWqDCEQnJO3Cr+vGWYu5oEaWn1ij1PW1TJG8ulikMieYCHh+fAPg== X-Received: by 2002:a7b:cd83:: with SMTP id y3mr36232wmj.168.1575473206330; Wed, 04 Dec 2019 07:26:46 -0800 (PST) Received: from localhost (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id n188sm8207781wme.14.2019.12.04.07.26.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2019 07:26:45 -0800 (PST) Date: Wed, 4 Dec 2019 16:26:44 +0100 From: Michal Hocko To: Thomas =?iso-8859-1?Q?Hellstr=F6m_=28VMware=29?= 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 , =?iso-8859-1?B?Suly9G1l?= Glisse , Christian =?iso-8859-1?Q?K=F6nig?= Subject: Re: [PATCH v2 2/2] drm/ttm: Fix vm page protection handling Message-ID: <20191204152644.GL25242@dhcp22.suse.cz> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) 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 Wed 04-12-19 16:19:27, Thomas Hellstr=F6m (VMware) wrote: > On 12/4/19 3:42 PM, Michal Hocko wrote: > > On Wed 04-12-19 15:36:58, Thomas Hellstr=F6m (VMware) wrote: > > > On 12/4/19 3:35 PM, Michal Hocko wrote: > > > > On Wed 04-12-19 15:16:09, Thomas Hellstr=F6m (VMware) wrote: > > > > > On 12/4/19 2:52 PM, Michal Hocko wrote: > > > > > > On Tue 03-12-19 11:48:53, Thomas Hellstr=F6m (VMware) wrote: > > > > > > > From: Thomas Hellstrom > > > > > > >=20 > > > > > > > TTM graphics buffer objects may, transparently to user-spac= e, move > > > > > > > between IO and system memory. When that happens, all PTEs p= ointing to the > > > > > > > old location are zapped before the move and then faulted in= again 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. > > > > > > >=20 > > > > > > > We were using an ugly hack to set the page protection corre= ctly. > > > > > > > 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_ge= t_page_prot(). > > > > > > > This way we catch modifications done by the vm system for d= rivers that > > > > > > > want write-notification. > > > > > > So essentially this should have any new side effect on functi= onality it > > > > > > is just making a hacky/ugly code less so? > > > > > Functionality is unchanged. The use of a on-stack vma copy was = severely > > > > > frowned upon in an earlier thread, which also points to another= similar > > > > > example using vmf_insert_pfn_prot(). > > > > >=20 > > > > > https://lore.kernel.org/lkml/20190905103541.4161-2-thomas_os@sh= ipmail.org/ > > > > >=20 > > > > > > 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 fla= gs of > > > > > vma::vm_page_prot have been largely removed from usage. From wh= at I can > > > > > tell, there are no more places left that can affect TTM. We dis= cussed > > > > > __split_huge_pmd_locked() towards the end of that thread, but t= hat doesn't > > > > > affect TTM even with huge page-table entries. > > > > Please state all those details/assumptions you are operating on i= n 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? >=20 > Yes we had that discussion in the thread I pointed to. I initially sugg= ested > 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 gene= ric > code that does the same. >=20 > But I was convinced by Andy that this was the right way and also was us= ed > elsewhere. >=20 > (See also https://elixir.bootlin.com/linux/latest/source/arch/x86/entry= /vdso/vma.c#L116) >=20 > I guess to have this properly formulated, what's required is that gener= ic > code doesn't build page-table entries using vma::vm_page_prot for VM_PF= NMAP > and VM_MIXEDMAP outside of driver control. Let me repeat that this belongs to a code somewhere everybody can see it rather than a "random" discussion at mailing list. Thanks! --=20 Michal Hocko SUSE Labs