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 6C7CCC2BD09 for ; Mon, 24 Jun 2024 17:54:57 +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:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/4EG5IaKeVOdRH+r7l7u/Do+csHa3snfvHiixcdXYGk=; b=VTTkDbINNGiFHA7bp272xzgI9i inIe2eXmhZrcnqQBBOXegA8wR13wvxJFcEye7G/Nj9P77wrlTFOBNUZC9o4z04j/1sFD/pWekl8aK B97hZt1JTnNgFmB2JfARoGXS9V9MG+w+FRifNiDT9vKz2GIYntVOndfYkSoTC3fv/WJ/OL+mJf44P T5waPp5+zkwyAENa89LSONCeJRSUpx+4pp4d6iRjy+TqqOeX+/g0mo7dVpb85qhIiUrubMtuwxDM+ vMQ3OpJti9pVc2LWOT/nm3PQhbLfDPl8a7L71QeE2GogLA4DovK3wocVPRrvnX30wlFg1w+s2F2SE Flaeie4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLntu-00000000BRM-2EcU; Mon, 24 Jun 2024 17:54:46 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLnto-00000000BPP-3QUP for linux-arm-kernel@lists.infradead.org; Mon, 24 Jun 2024 17:54:42 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-7065df788f7so2063198b3a.0 for ; Mon, 24 Jun 2024 10:54:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719251679; x=1719856479; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/4EG5IaKeVOdRH+r7l7u/Do+csHa3snfvHiixcdXYGk=; b=ECyQhfFKO5iZNYErAVoYH3fNd+0nnColUGIptaFL87ew3m3c/EA+jrUftfO+z8G591 Js+TT+s1FT2B3M00VpLX0LdOgBDfeldEG+PEcDv90gZPj6nd9vbv4En2gDNzCRYdHisw EhyRjU3vmvenzD7LmmT1EU7C9qZPKTdwwQPFfUZO8BulutWvohfVVStqLDW3wToxjVJ5 jqf5e0JQOeXzcmgIMZLA/eypO+ppBfiPT5RKqnc2o3j80wNmfpATr3YovBIf91HxMaWh xhAaMrIhRSbRTQa9zQpY7X7JAP+RXuyCksZKDIdYYgmwOLuDogaLchq44W/7i23x1jzu +aUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719251679; x=1719856479; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/4EG5IaKeVOdRH+r7l7u/Do+csHa3snfvHiixcdXYGk=; b=L/Zq2UCHtpF6CDVmithxVA1Wjf3/TLygYTRY9xEgTSoGhx/kxeNi6XoWbngJhoJ/AC dtYSkDIsSkIp28ubEjANUpzFpwl42Bug39fPIGV33RqLdE2WqmjTkOemu2IPmw6bOelm jqSvtuVbefODfiDqT1Ypr1TjkORcIcVc3JZkT3Jddo9VnBKFshJANlbXab4tBbaCFMXA 3NOnvNlBffUE3OJgfXa3TAHUwoONVGmsG6O8wroP8Jl4LCltXfuT0jNDDgIkmwyoy6pq eXEPUGiFX4fitPCK9SFjgvvDstETKi2tIAqLJVLzcT3PEWBDs6d36eXJIv1IE2NP7HiY lQrw== X-Forwarded-Encrypted: i=1; AJvYcCUQwsAEpi/CMWnu8mfzZrzPRIAW8OKTZXm/g8jfJ/eQQ17QwgUdKdtynBUhqnwO5XnwnItHLv6Si99u9MwbDX30Bpi7i/RSguIONtdU32MForksMyQ= X-Gm-Message-State: AOJu0YxUQPEVocYgGIZvCElaurXOba7GvMqfcG558/sluG22bbyv4iIN vQNWncw+gIaAeErY+ynjRGRfZpwycEVV3dzsQRcRLcE5qXIHcpF0+Rwe72pMZM88tuA0XPBJL6y O2g== X-Google-Smtp-Source: AGHT+IFwvxf3OsuvZYrUndYb77JYUI7kIwbwA1lAt8ypjyKZ5DTVmQAcQPWwexhhQL7MAR18AQ3i9Y8LGS4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:418b:b0:706:2948:a087 with SMTP id d2e1a72fcca58-70669f71011mr302391b3a.1.1719251678783; Mon, 24 Jun 2024 10:54:38 -0700 (PDT) Date: Mon, 24 Jun 2024 10:54:37 -0700 In-Reply-To: <20240624170747.GA1515249@ziepe.ca> Mime-Version: 1.0 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> Message-ID: Subject: Re: [RFC PATCH v2 4/7] iommufd: Associate kvm pointer to iommufd ctx From: Sean Christopherson To: Jason Gunthorpe Cc: Shameer Kolothum , kvmarm@lists.linux.dev, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linuxarm@huawei.com, 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@huawei.com Content-Type: text/plain; charset="us-ascii" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240624_105440_880400_ABB11EC1 X-CRM114-Status: GOOD ( 31.34 ) 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 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.. Isn't the caller in ARM specific code? I was assuming kvm_pinned_vmid_{get,put}() would simply not exist for non-ARM builds. > > 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. Failing 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... I suspect we're talking about two different things. Either that, or I am really lost. > > 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 would allow > > for a much saner failure mode, and I suspect would be cleaner in general 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) 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. Hmm, kvm_arm_pinned_vmid_get() doesn't fail, it just falls back to VMID=0. Which seems odd.