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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DC8D4C4167B for ; Wed, 6 Dec 2023 18:59:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=M7W9HUzCemZwrD51nUhLeI09C7wySq2WsVVXlRU5vko=; b=3GszwspvBR4GWi +yLtl1U30/KoEFeFrLwexQzMOOkTwJUSNxMV/DvxoVxiLFoZsJ7zHiwVfb3m2FYRG1D6TWNpv0ZGj KtWUZFovDgvBWcTpMVa9qeraHxo5VfwP4x6RadqdevOUpblEH0i5ZMT5NFEQ+FGmkyWteActc6xWd zHLDYfrOmCOXBHH9yqZTxK+42YeG/4phhlXnP04Fjf0ie/+PuHLttBpmQcVFplb+PnX5WZv7mysZu IzuhVldd26s9Tfy29oWP+e7CVfWX/Lcyid/mhDdVxe2NtnMBLrHPaTqzOU3uMzvh0ExmeQMwTyJCI J8txLghtQpQgs2JKuScg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rAx6l-00B5ig-2Z; Wed, 06 Dec 2023 18:58:55 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rAx6j-00B5i0-0N for linux-arm-kernel@lists.infradead.org; Wed, 06 Dec 2023 18:58:54 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BADD861E3D; Wed, 6 Dec 2023 18:58:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19114C433C8; Wed, 6 Dec 2023 18:58:46 +0000 (UTC) Date: Wed, 6 Dec 2023 18:58:44 +0000 From: Catalin Marinas To: Jason Gunthorpe Cc: Marc Zyngier , ankita@nvidia.com, Shameerali Kolothum Thodi , oliver.upton@linux.dev, suzuki.poulose@arm.com, yuzenghui@huawei.com, will@kernel.org, ardb@kernel.org, akpm@linux-foundation.org, gshan@redhat.com, aniketa@nvidia.com, cjia@nvidia.com, kwankhede@nvidia.com, targupta@nvidia.com, vsethi@nvidia.com, acurrid@nvidia.com, apopple@nvidia.com, jhubbard@nvidia.com, danw@nvidia.com, mochs@nvidia.com, kvmarm@lists.linux.dev, kvm@vger.kernel.org, lpieralisi@kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2 1/1] KVM: arm64: allow the VM to select DEVICE_* and NORMAL_NC for IO memory Message-ID: References: <20231205164318.GG2692119@nvidia.com> <86bkb4bn2v.wl-maz@kernel.org> <86a5qobkt8.wl-maz@kernel.org> <868r67blwo.wl-maz@kernel.org> <20231206151603.GR2692119@nvidia.com> <20231206172035.GU2692119@nvidia.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231206172035.GU2692119@nvidia.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231206_105853_256547_7C34E434 X-CRM114-Status: GOOD ( 30.26 ) 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 Wed, Dec 06, 2023 at 01:20:35PM -0400, Jason Gunthorpe wrote: > On Wed, Dec 06, 2023 at 04:31:48PM +0000, Catalin Marinas wrote: > > > This would be fine, as would a VMA flag. Please pick one :) > > > > > > I think a VMA flag is simpler than messing with pgprot. > > > > I guess one could write a patch and see how it goes ;). > > A lot of patches have been sent on this already :( But not one with a VM_* flag. I guess we could also add a VM_VFIO flag which implies KVM has less restrictions on the memory type. I think that's more bike-shedding. The key point is that we don't want to relax this for whatever KVM may map in the guest but only for certain devices. Just having a vma may not be sufficient, we can't tell where that vma came from. So for the vfio bits, completely untested: -------------8<---------------------------- diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 1929103ee59a..b89d2dfcd534 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -1863,7 +1863,7 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, 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. */ - vm_flags_set(vma, VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP); + vm_flags_set(vma, VM_VFIO | VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP); vma->vm_ops = &vfio_pci_mmap_ops; return 0; diff --git a/include/linux/mm.h b/include/linux/mm.h index 418d26608ece..6df46fd7836a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -391,6 +391,13 @@ extern unsigned int kobjsize(const void *objp); # define VM_UFFD_MINOR VM_NONE #endif /* CONFIG_HAVE_ARCH_USERFAULTFD_MINOR */ +#ifdef CONFIG_64BIT +#define VM_VFIO_BIT 39 +#define VM_VFIO BIT(VM_VFIO_BIT) +#else +#define VM_VFIO VM_NONE +#endif + /* Bits set in the VMA until the stack is in its final location */ #define VM_STACK_INCOMPLETE_SETUP (VM_RAND_READ | VM_SEQ_READ | VM_STACK_EARLY) -------------8<---------------------------- In KVM, Akita's patch would take this into account, not just rely on "device==true". > > > > If we want the VMM to drive this entirely, we could add a new mmap() > > > > flag like MAP_WRITECOMBINE or PROT_WRITECOMBINE. They do feel a bit > > > > > > As in the other thread, we cannot unconditionally map NORMAL_NC into > > > the VMM. > > > > I'm not suggesting this but rather the VMM map portions of the BAR with > > either Device or Normal-NC, concatenate them (MAP_FIXED) and pass this > > range as a memory slot (or multiple if a slot doesn't allow multiple > > vmas). > > The VMM can't know what to do. We already talked about this. The VMM > cannot be involved in the decision to make pages NORMAL_NC or > not. That idea ignores how actual devices work. [...] > > Are the Device/Normal offsets within a BAR fixed, documented in e.g. the > > spec or this is something configurable via some MMIO that the guest > > does. > > No, it is fully dynamic on demand with firmware RPCs. I think that's a key argument. The VMM cannot, on its own, configure the BAR and figure a way to communicate this to the guest. We could invent some para-virtualisation/trapping mechanism but that's unnecessarily complicated. In the DPDK case, DPDK both configures and interacts with the device. In the VMM/VM case, we need the VM to do this, we can't split the configuration in VMM and interaction with the device in the VM. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel