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=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 E7757C432C3 for ; Tue, 3 Dec 2019 10:49:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A348E206DF for ; Tue, 3 Dec 2019 10:49:16 +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="q+D96kC0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A348E206DF 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 DACB96B039B; Tue, 3 Dec 2019 05:49:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D34666B039C; Tue, 3 Dec 2019 05:49:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD6A56B039D; Tue, 3 Dec 2019 05:49:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id 9B78E6B039B for ; Tue, 3 Dec 2019 05:49:13 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 5CFF0180AD815 for ; Tue, 3 Dec 2019 10:49:13 +0000 (UTC) X-FDA: 76223508186.06.toys53_162ac05b9922b X-HE-Tag: toys53_162ac05b9922b X-Filterd-Recvd-Size: 6228 Received: from pio-pvt-msa2.bahnhof.se (pio-pvt-msa2.bahnhof.se [79.136.2.41]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Tue, 3 Dec 2019 10:49:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTP id BE682413DF; Tue, 3 Dec 2019 11:49:10 +0100 (CET) Authentication-Results: pio-pvt-msa2.bahnhof.se; dkim=pass (1024-bit key; unprotected) header.d=shipmail.org header.i=@shipmail.org header.b=q+D96kC0; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at bahnhof.se Received: from pio-pvt-msa2.bahnhof.se ([127.0.0.1]) by localhost (pio-pvt-msa2.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id O1Phm5sjhJf1; Tue, 3 Dec 2019 11:49:08 +0100 (CET) Received: from mail1.shipmail.org (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) (Authenticated sender: mb878879) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTPA id 0BB2B413CC; Tue, 3 Dec 2019 11:49:05 +0100 (CET) Received: from localhost.localdomain.localdomain (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) by mail1.shipmail.org (Postfix) with ESMTPSA id 6C4F136159C; Tue, 3 Dec 2019 11:49:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shipmail.org; s=mail; t=1575370145; bh=uTN4ic4eeS1L6Fw/mV08DD+v/r8WpmY+v3FL99RylaM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q+D96kC0olg7qmojQqZo2RGwOSWcx8AsT4UxE81PKkdLpaLjaBHAcJp4Mx5jV9NF4 /KFH3xD+dczwrU6flDs7w/BSB7o7ktd64OEbSc+JqQbdLjlHurYE7387HrPED+aT48 7uGPLTapP4EAWR2jSMqoWo4EjWYhW/Hn18aPu6lU= From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m=20=28VMware=29?= To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: pv-drivers@vmware.com, linux-graphics-maintainer@vmware.com, Thomas Hellstrom , Andrew Morton , Michal Hocko , "Matthew Wilcox (Oracle)" , "Kirill A. Shutemov" , Ralph Campbell , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , =?UTF-8?q?Christian=20K=C3=B6nig?= Subject: [PATCH v2 2/2] drm/ttm: Fix vm page protection handling Date: Tue, 3 Dec 2019 11:48:53 +0100 Message-Id: <20191203104853.4378-3-thomas_os@shipmail.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191203104853.4378-1-thomas_os@shipmail.org> References: <20191203104853.4378-1-thomas_os@shipmail.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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: From: Thomas Hellstrom TTM graphics buffer objects may, transparently to user-space, move between IO and system memory. When that happens, all PTEs pointing 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. 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_page_prot(). This way we catch modifications done by the vm system for drivers that want write-notification. Cc: Andrew Morton Cc: Michal Hocko Cc: "Matthew Wilcox (Oracle)" Cc: "Kirill A. Shutemov" Cc: Ralph Campbell Cc: "J=C3=A9r=C3=B4me Glisse" Cc: "Christian K=C3=B6nig" Signed-off-by: Thomas Hellstrom Reviewed-by: Christian K=C3=B6nig --- drivers/gpu/drm/ttm/ttm_bo_vm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo= _vm.c index e6495ca2630b..2098f8d4dfc5 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c @@ -173,7 +173,6 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *= vmf, pgoff_t num_prefault) { struct vm_area_struct *vma =3D vmf->vma; - struct vm_area_struct cvma =3D *vma; struct ttm_buffer_object *bo =3D vma->vm_private_data; struct ttm_bo_device *bdev =3D bo->bdev; unsigned long page_offset; @@ -244,7 +243,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *= vmf, goto out_io_unlock; } =20 - cvma.vm_page_prot =3D ttm_io_prot(bo->mem.placement, prot); + prot =3D ttm_io_prot(bo->mem.placement, prot); if (!bo->mem.bus.is_iomem) { struct ttm_operation_ctx ctx =3D { .interruptible =3D false, @@ -260,7 +259,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *= vmf, } } else { /* Iomem should not be marked encrypted */ - cvma.vm_page_prot =3D pgprot_decrypted(cvma.vm_page_prot); + prot =3D pgprot_decrypted(prot); } =20 /* @@ -284,10 +283,11 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault= *vmf, } =20 if (vma->vm_flags & VM_MIXEDMAP) - ret =3D vmf_insert_mixed(&cvma, address, - __pfn_to_pfn_t(pfn, PFN_DEV)); + ret =3D vmf_insert_mixed_prot(vma, address, + __pfn_to_pfn_t(pfn, PFN_DEV), + prot); else - ret =3D vmf_insert_pfn(&cvma, address, pfn); + ret =3D vmf_insert_pfn_prot(vma, address, pfn, prot); =20 /* Never error on prefaulted PTEs */ if (unlikely((ret & VM_FAULT_ERROR))) { @@ -319,7 +319,7 @@ vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf) if (ret) return ret; =20 - prot =3D vm_get_page_prot(vma->vm_flags); + prot =3D vma->vm_page_prot; ret =3D ttm_bo_vm_fault_reserved(vmf, prot, TTM_BO_VM_NUM_PREFAULT); if (ret =3D=3D VM_FAULT_RETRY && !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT= )) return ret; --=20 2.21.0