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 74482C2BD09 for ; Mon, 24 Jun 2024 19:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:In-Reply-To:References:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=93K08id3WlPWZCbaDTxl1s8mdwmMc0r3Czi7G+8PDEU=; b=E5kKA0wGQcBMHGgIZ21W1qk+Kv /Q0udwG0Y4eufvuGpkc8pmafmEete4mM0WiKUMP+J1dW1+u08WBJAI5W9/CN28cW44jcDmmWstf0w 9W6d4SlQ/O5dzFDIIfG0tJ7jOmJ6RONWx6ks0ioOQyH7j0GMEn7J376PHc4by1HSyuHUH9Yqj+hFn vRiBfLJby31IomJXXk6xfxwzU95ZOzJ3g3XTm5HeJrU4X09C/WNuNIPOH37hPer9D8lyJrQD31Ire KXe2lyh3xs6D5lorYuvEx37V9vRWwBrR1R5hXWPZLcEvLgMHnln0fkfyP74HOZty30lIcMiR+wPD9 Y38KVNLg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLp8h-00000000ObJ-17ds; Mon, 24 Jun 2024 19:14:07 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLp8b-00000000OZY-1jND for linux-arm-kernel@lists.infradead.org; Mon, 24 Jun 2024 19:14:03 +0000 Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4W7HgP6qvKz6JB7Q; Tue, 25 Jun 2024 03:13:37 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id 31898140A9C; Tue, 25 Jun 2024 03:13:51 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (7.191.163.240) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 24 Jun 2024 20:13:50 +0100 Received: from lhrpeml500005.china.huawei.com ([7.191.163.240]) by lhrpeml500005.china.huawei.com ([7.191.163.240]) with mapi id 15.01.2507.039; Mon, 24 Jun 2024 20:13:50 +0100 From: Shameerali Kolothum Thodi To: Sean Christopherson , Jason Gunthorpe CC: "kvmarm@lists.linux.dev" , "iommu@lists.linux.dev" , "linux-arm-kernel@lists.infradead.org" , Linuxarm , "kevin.tian@intel.com" , "alex.williamson@redhat.com" , "maz@kernel.org" , "oliver.upton@linux.dev" , "will@kernel.org" , "robin.murphy@arm.com" , "jean-philippe@linaro.org" , Jonathan Cameron Subject: RE: [RFC PATCH v2 4/7] iommufd: Associate kvm pointer to iommufd ctx Thread-Topic: [RFC PATCH v2 4/7] iommufd: Associate kvm pointer to iommufd ctx Thread-Index: AQHaWqKlcIYRddkjikqD0bNybpIgU7EAlXwAgNdSbACAAAQhgIAADRaAgAAidCA= Date: Mon, 24 Jun 2024 19:13:50 +0000 Message-ID: <521e42c61230413c8160ecf370c41937@huawei.com> References: <20240208151837.35068-1-shameerali.kolothum.thodi@huawei.com> <20240208151837.35068-5-shameerali.kolothum.thodi@huawei.com> <20240208154210.GP31743@ziepe.ca> <20240624170747.GA1515249@ziepe.ca> In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.195.246.162] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240624_121401_795084_2F4072B7 X-CRM114-Status: GOOD ( 39.57 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org > -----Original Message----- > From: Sean Christopherson > Sent: Monday, June 24, 2024 6:55 PM > To: Jason Gunthorpe > Cc: Shameerali Kolothum Thodi ; > kvmarm@lists.linux.dev; iommu@lists.linux.dev; linux-arm- > kernel@lists.infradead.org; Linuxarm ; > kevin.tian@intel.com; alex.williamson@redhat.com; maz@kernel.org; > oliver.upton@linux.dev; will@kernel.org; robin.murphy@arm.com; jean- > philippe@linaro.org; Jonathan Cameron > Subject: Re: [RFC PATCH v2 4/7] iommufd: Associate kvm pointer to iommufd > ctx >=20 > On Mon, Jun 24, 2024, Jason Gunthorpe wrote: > > On Mon, Jun 24, 2024 at 09:53:00AM -0700, Sean Christopherson wrote: > > > If kvm_pinned_vmid_{get,put}() are implemented directly by KVM ARM, > then I don't > > > have any immediate concerns, as KVM ARM is a long, long way from > being able to > > > isolate KVM from the core kernel. > > > > I think that is a reasonable thing, I also don't really see VMID as > > being general. We will have to figure out how to ensure that the KVM > > FD we got is an ARM KVM FD.. >=20 > Isn't the caller in ARM specific code? I was assuming > kvm_pinned_vmid_{get,put}() > would simply not exist for non-ARM builds. The caller is in ARM specific code(SMMUv3 driver). But at present, the kvm = pointer is passed to it by IOMMUFD during nested domain allocation time. And IOMMUF= D gets the kvm pointer from VFIO during device bind operation. Not sure,, how this flow is going to be in the new IOMMUFD VIOMMU object m= odel Jason referred. If not through IOMMUFD, SMMUv3 has to have a way to figure = out the KVM associated with the device. =20 >=20 > > > That said, I find the on-demand pinning to be very odd. IIUC, if KVM= runs > out > > > of pinnable VMIDs, attaching a device to the KVM+iommu will fail. Fa= iling > an > > > iommufd operation because of a (potentially transient) KVM resource > issue is > > > rather unpleasant. > > > > It is kind of subtle, but the only thing that will consume VMIDs is > > IOMMUFD operations that are working with nested translation but not > > providing KVMs. This is a pretty small blast radius - ie a specific > > qemu will fail to start - that I think we can tolerate it. > > > > More normal iommu operation will not require VMIDs so things like > > driver attaching/etc is fine. > > > > > And assuming that pinnable VMIDs are a somewhat scarce resource, it > wouldn't > > > suprise me if someone wanted to add cgroup integration, e.g. similar = to > the > > > misc cgroup that's used to manage SEV(-ES) ASIDs on KVM AMD (IIUC, an > SEV ASID > > > is analagous to an ARM VMID). > > > > Yeah, but if someone is using such a cgroup then I expect they will > > also have an up to date VMM that doesn't trigger this VMID allocation > > in the first place... >=20 > I suspect we're talking about two different things. Either that, or I am= really > lost. >=20 > > > Rather than on-demand pinning, would it make sense to have KVM > provide an ioctl() > > > (or capability, or VM type) to let userspace pin a VM's VMID? That w= ould > allow > > > for a much saner failure mode, and I suspect would be cleaner in gene= ral > for iommufd. > > > > The point of this mechanism is to support using this iommufd feature > > without a KVM at all. We could instead prevent this directly 100% of > > the time, but it means that HW with this BTM capability would not run > > the legacy VMMs at all, so I'm not that keen on it.. > > > > When a KVM is present then the iommu needs to adopt the VMID of KVM, > > and that should have a mechanism to ensure the VMID is valid so long > > as the IOMMU is using it (eg because the KVM FD is open) >=20 > Right, and that's what I'm referring to as "on-demand pinning". For the > IOMMU > to adopt a KVM VMID, the VMID needs to be pinned (or KVM would need to > notify > the IOMMU every time the VMID changed), i.e. every KVM+IOMMU pair pins > a VMID > that is managed by KVM. >=20 > Hmm, kvm_arm_pinned_vmid_get() doesn't fail, it just falls back to VMID= =3D0. > Which > seems odd. See patch 3, kvm_arch_pinned_vmid_get() return -EINVAL if VMID =3D=3D 0. Fo= r ARM64/KVM VMID 0 is always reserved and never allocated for a Guest. Thanks, Shameer