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=-4.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 F231AC433B4 for ; Thu, 22 Apr 2021 06:52:06 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5017F6145A for ; Thu, 22 Apr 2021 06:52:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5017F6145A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Subject:Cc:To: From:Message-ID:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=92zuelC1iQQpgEXoddoWFDMisVu9H+fLNF3euI+4sQw=; b=jwTbeYcFPcGS/Kqd3l1vp2+ju pF8NFUbXCQiCaavLKvjbKuyeFZ6UUrecx93l3imOcRwAmcLxP8KmAXWOSDDU36gI7GvyiKTrq69wG ++PqG9ynAGnRwTzms856TjKpqyhfmRo+XDGQWdpOvYvSEK+L5DHr4LujrdRsrBbc9naa6n4I8coD7 cUDUQzffgi3M508zCxs3R0uWrEsCoFMI5ZhRDA2qApYGaLmxZUDfvpbvK/3MzVhrERTnbdCgkb0AM s1vpJl0oemDzbaEodozvgiFnnPJYm2lXegdOeC7Yoe02tvPgnyUsLGNKyBgcPLGstZY9hJWlo/ZQP mrbBR/hHA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZTAB-00G3dm-Q8; Thu, 22 Apr 2021 06:50:12 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZTA8-00G3dA-H0 for linux-arm-kernel@desiato.infradead.org; Thu, 22 Apr 2021 06:50:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:MIME-Version:References: In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Kc4Zcw+EX0GLKoMtw3odn5ugd6Cdnmkk+RfTB+7wncA=; b=QEEeu0+JWCyyABpvI3MZg8+y0y LUe5QTOdurC5c8oWBT4t/7YYwd5fCxwuHBFiUor0hE5dawLCOIULaK3eMmt/SeGZhNjxRVTXaXA+1 qykvB9gqR2SPzn1Cjk+sdC1pFFcOpNDbit1F60JATQZUPONjYKzaEakP8iQCEic3PJ0NnmvGacwP4 z/BGYowf3oiiJm5xmcWMpIYyBq7eQct/vejUFzxDebJTN4O03xASwDRCYBHzVKx/NrmHUkMgkJYcw ho+GudGP7cMekpm8hbdxBBq7RuCtM1az17TRhJ3QIeuwqoCf0VApcA/STYh7PbKm1BsfhfE9MwoKh zXOKg2Ag==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZTA5-00DQIj-TB for linux-arm-kernel@lists.infradead.org; Thu, 22 Apr 2021 06:50:07 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 54CC561448; Thu, 22 Apr 2021 06:50:05 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lZTA3-008paW-5p; Thu, 22 Apr 2021 07:50:03 +0100 Date: Thu, 22 Apr 2021 07:50:02 +0100 Message-ID: <87v98eq0dh.wl-maz@kernel.org> From: Marc Zyngier To: Gavin Shan Cc: Keqian Zhu , kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, cjia@nvidia.com, linux-arm-kernel@lists.infradead.org, "Wanghaibin (D)" Subject: Re: [PATCH] KVM: arm64: Correctly handle the mmio faulting In-Reply-To: References: <1603297010-18787-1-git-send-email-sashukla@nvidia.com> <8b20dfc0-3b5e-c658-c47d-ebc50d20568d@huawei.com> <2e23aaa7-0c8d-13ba-2eae-9e6ab2adc587@redhat.com> <871rb3rgpl.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: gshan@redhat.com, zhukeqian1@huawei.com, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, cjia@nvidia.com, linux-arm-kernel@lists.infradead.org, wanghaibin.wang@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210421_235006_018574_7AE6707C X-CRM114-Status: GOOD ( 36.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 22 Apr 2021 03:02:00 +0100, Gavin Shan wrote: > > Hi Marc, > > On 4/21/21 9:59 PM, Marc Zyngier wrote: > > On Wed, 21 Apr 2021 07:17:44 +0100, > > Keqian Zhu wrote: > >> On 2021/4/21 14:20, Gavin Shan wrote: > >>> On 4/21/21 12:59 PM, Keqian Zhu wrote: > >>>> On 2020/10/22 0:16, Santosh Shukla wrote: > >>>>> The Commit:6d674e28 introduces a notion to detect and handle the > >>>>> device mapping. The commit checks for the VM_PFNMAP flag is set > >>>>> in vma->flags and if set then marks force_pte to true such that > >>>>> if force_pte is true then ignore the THP function check > >>>>> (/transparent_hugepage_adjust()). > >>>>> > >>>>> There could be an issue with the VM_PFNMAP flag setting and checking. > >>>>> For example consider a case where the mdev vendor driver register's > >>>>> the vma_fault handler named vma_mmio_fault(), which maps the > >>>>> host MMIO region in-turn calls remap_pfn_range() and maps > >>>>> the MMIO's vma space. Where, remap_pfn_range implicitly sets > >>>>> the VM_PFNMAP flag into vma->flags. > >>>> Could you give the name of the mdev vendor driver that triggers this issue? > >>>> I failed to find one according to your description. Thanks. > >>>> > >>> > >>> I think it would be fixed in driver side to set VM_PFNMAP in > >>> its mmap() callback (call_mmap()), like vfio PCI driver does. > >>> It means it won't be delayed until page fault is issued and > >>> remap_pfn_range() is called. It's determined from the beginning > >>> that the vma associated the mdev vendor driver is serving as > >>> PFN remapping purpose. So the vma should be populated completely, > >>> including the VM_PFNMAP flag before it becomes visible to user > >>> space. > > > > Why should that be a requirement? Lazy populating of the VMA should be > > perfectly acceptable if the fault can only happen on the CPU side. > > > > It isn't a requirement and the drivers needn't follow strictly. I checked > several drivers before looking into the patch and found almost all the > drivers have VM_PFNMAP set at mmap() time. In drivers/vfio/vfio-pci.c, > there is a comment as below, but it doesn't reveal too much about why > we can't set VM_PFNMAP at fault time. > > static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma) > { > : > /* > * See remap_pfn_range(), called from vfio_pci_fault() but we can't > * change vm_flags within the fault handler. Set them now. > */ > vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP; > vma->vm_ops = &vfio_pci_mmap_ops; > > return 0; > } > > To set these flags in advance does have advantages. For example, > VM_DONTEXPAND prevents the vma to be merged with another > one. VM_DONTDUMP make this vma isn't eligible for > coredump. Otherwise, the address space, which is associated with the > vma is accessed and unnecessary page faults are triggered on > coredump. VM_IO and VM_PFNMAP avoids to walk the page frames > associated with the vma since we don't have valid PFN in the > mapping. But PCI clearly isn't the case we are dealing with here, and not everything is VFIO either. I can *today* create a driver that implements a mmap+fault handler, call mmap() on it, pass the result to a memslot, and get to the exact same result Santosh describes. No PCI, no VFIO, just a random driver. We are *required* to handle that. M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel