Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp663827pxj; Thu, 10 Jun 2021 09:41:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfvEQ31O56+x1QiqaIru5ik3wcwzdtUaqEDF4n4nYiYFrWmvbB9TOMYz9AgNBeOEyJm4Ur X-Received: by 2002:a17:907:f9b:: with SMTP id kb27mr507884ejc.44.1623343303980; Thu, 10 Jun 2021 09:41:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623343303; cv=none; d=google.com; s=arc-20160816; b=ExdQJ1vI12+2oRdcc1yd7QN7+x7Jhpmhz1TZFpnV6uRuj/1avXDvadjQJypWgsr7uO GwGiKwm/xkjEPmCvcHHWRTE2IHyaesDz2QkE7DcBAqIdl+LiTNNz7BCcd9tT0vdy3Pkb gAV65fkx3VqQsKH0h5aB5J5alCjqZK4mQxEDFXzRP0FVOttytMOHNPi6Lo2/GZP9rMtj jXGd1A9PyFEJYLlXCwhh5PzQTXPAkcrtGqN22nEUZi/OFmolBa2avH8rAO0XUXHironj UD/v1XHdt72p9AZZvtFLVtRWkens0MSKWlc7bb2KT3LYJMMb7QTKMXmCIS+blx0vnXLo gcKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=f8rhLdT0RKsyrunOn+7eaHkk+cg4cuRYRCg5AglwD7I=; b=Q296gFWbOqbWwi6zxADQ9OcAD4zVRq3G8iCsVJqo+PmBgubDauAG3M89yQQha4q021 WYhd42AKy7vSCPLRnen5WCT72MPSLBx/uo0EIT3K8v0wJl6tREp3NeuYGPH/ct6Rw7K1 80CYrr63BhcH9GMbTTWnDp2v73lBRu/GvVrmPkxSxuf4H7Z++/CR6DA9KkfvhmME+BBR HLINX19bu4HEouXCpF8EQZD6TPbxaFweeCaxv4lDsRFYr+slO+IGqMJ0I5/1DU7YoopV s3R8/kQKU0OeRaWxdk/FCps6pJUX09sF3jLJIN/16xo9VqPXevvV985jrl3RbVKzwIVs Gi1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="pU/ofema"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c3si3429385edd.398.2021.06.10.09.41.20; Thu, 10 Jun 2021 09:41:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="pU/ofema"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231178AbhFJQlE (ORCPT + 99 others); Thu, 10 Jun 2021 12:41:04 -0400 Received: from mail-wm1-f41.google.com ([209.85.128.41]:43876 "EHLO mail-wm1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229823AbhFJQlC (ORCPT ); Thu, 10 Jun 2021 12:41:02 -0400 Received: by mail-wm1-f41.google.com with SMTP id 3-20020a05600c0243b029019f2f9b2b8aso6824654wmj.2 for ; Thu, 10 Jun 2021 09:38:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=f8rhLdT0RKsyrunOn+7eaHkk+cg4cuRYRCg5AglwD7I=; b=pU/ofemaNwl6En1anEcPanaJr5czdL+/043dbE3PYDPOwBdaT5TUOt349W02sZi+sv t6ODWBuf4ZgX3HNJe92GOr3030uvz4FkjbWakVSnf99CKsqpL3DVtansnRfHB18lhGdn pgUN6VViDGoqTWYV4BYZsE4KWHTXLZ/TX4L6hgVPJUyrI1D28PZhCgt+Hrwv5Jt6KZxe gnsazP38W0WBiNsAw+NRcC5C0xWBjhApsTDqhw9qyQD5Eo6XJmza/uwiG/7esq66b3kF 8AVHa8vtfDehBAP2nPcUMj0thcLICnFWxKCLWqb4aFnNLnPzI1hIi1jZv/a1ZTlU+RX7 4OPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=f8rhLdT0RKsyrunOn+7eaHkk+cg4cuRYRCg5AglwD7I=; b=n4a7oXmi/iiDHcIKa3ck8auR8kFxr8CQ/HKZcz4RvUnSc8A4pwLCn5thafyL8vr6Op k4LycGEhqLEzKdziy/2TDnuSsSCovRAwsk7t0gsBaMlW2q5F2rfOAlVfa4Z7Xo/1aHez A6vNQ7Tz2GVZIjQEdAia1+mSHTmxRmh/Cz6ulVyBjey7fTxq/GrrDkheo5I+NygLvTwt Sk2rFX+hqYVQ+qfipqYrx+E6Ir+ZOWN1+CJvVUDwi+pAxAYm75oAXaeMSlAnIniVs7MX w72HxT2tfXt4aMKCnZD3qPysD0vKPlhfad7yN3LbI0jFZG65q0G7rjo0ZVnDyrQ4ihaa g6nw== X-Gm-Message-State: AOAM530o3H3AtbtF5/iLeQ2QD7V1nHEghyn66w8jEh2WA09C3FIPzp18 VyMP534ToZsGWWu86yM05sUJzQ== X-Received: by 2002:a05:600c:4148:: with SMTP id h8mr15886906wmm.176.1623343070684; Thu, 10 Jun 2021 09:37:50 -0700 (PDT) Received: from myrica (adsl-84-226-111-173.adslplus.ch. [84.226.111.173]) by smtp.gmail.com with ESMTPSA id f13sm4039814wrt.86.2021.06.10.09.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:37:49 -0700 (PDT) Date: Thu, 10 Jun 2021 18:37:31 +0200 From: Jean-Philippe Brucker To: David Gibson Cc: Jason Gunthorpe , "Tian, Kevin" , LKML , Joerg Roedel , Lu Baolu , David Woodhouse , "iommu@lists.linux-foundation.org" , "kvm@vger.kernel.org" , "Alex Williamson (alex.williamson@redhat.com)" , Jason Wang , Eric Auger , Jonathan Corbet , "Raj, Ashok" , "Liu, Yi L" , "Wu, Hao" , "Jiang, Dave" , Jacob Pan , Kirti Wankhede , Robin Murphy Subject: Re: [RFC] /dev/ioasid uAPI proposal Message-ID: References: <20210528195839.GO1002214@nvidia.com> <20210602165838.GA1002214@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 08, 2021 at 04:31:50PM +1000, David Gibson wrote: > For the qemu case, I would imagine a two stage fallback: > > 1) Ask for the exact IOMMU capabilities (including pagetable > format) that the vIOMMU has. If the host can supply, you're > good > > 2) If not, ask for a kernel managed IOAS. Verify that it can map > all the IOVA ranges the guest vIOMMU needs, and has an equal or > smaller pagesize than the guest vIOMMU presents. If so, > software emulate the vIOMMU by shadowing guest io pagetable > updates into the kernel managed IOAS. > > 3) You're out of luck, don't start. > > For both (1) and (2) I'd expect it to be asking this question *after* > saying what devices are attached to the IOAS, based on the virtual > hardware configuration. That doesn't cover hotplug, of course, for > that you have to just fail the hotplug if the new device isn't > supportable with the IOAS you already have. Yes. So there is a point in time when the IOAS is frozen, and cannot take in new incompatible devices. I think that can support the usage I had in mind. If the VMM (non-QEMU, let's say) wanted to create one IOASID FD per feature set it could bind the first device, freeze the features, then bind the second device. If the second bind fails it creates a new FD, allowing to fall back to (2) for the second device while keeping (1) for the first device. A paravirtual IOMMU like virtio-iommu could easily support this as it describes pIOMMU properties for each device to the guest. An emulated vIOMMU could also support some hybrid cases as you describe below. > One can imagine optimizations where for certain intermediate cases you > could do a lighter SW emu if the host supports a model that's close to > the vIOMMU one, and you're able to trap and emulate the differences. > In practice I doubt anyone's going to have time to look for such cases > and implement the logic for it. > > > For example depending whether the hardware IOMMU is SMMUv2 or SMMUv3, that > > completely changes the capabilities offered to the guest (some v2 > > implementations support nesting page tables, but never PASID nor PRI > > unlike v3.) The same vIOMMU could support either, presenting different > > capabilities to the guest, even multiple page table formats if we wanted > > to be exhaustive (SMMUv2 supports the older 32-bit descriptor), but it > > needs to know early on what the hardware is precisely. Then some new page > > table format shows up and, although the vIOMMU can support that in > > addition to older ones, QEMU will have to pick a single one, that it > > assumes the guest knows how to drive? > > > > I think once it binds a device to an IOASID fd, QEMU will want to probe > > what hardware features are available before going further with the vIOMMU > > setup (is there PASID, PRI, which page table formats are supported, > > address size, page granule, etc). Obtaining precise information about the > > hardware would be less awkward than trying different configurations until > > one succeeds. Binding an additional device would then fail if its pIOMMU > > doesn't support exactly the features supported for the first device, > > because we don't know which ones the guest will choose. QEMU will have to > > open a new IOASID fd for that device. > > No, this fundamentally misunderstands the qemu model. The user > *chooses* the guest visible platform, and qemu supplies it or fails. > There is no negotiation with the guest, because this makes managing > migration impossibly difficult. I'd like to understand better where the difficulty lies, with migration. Is the problem, once we have a guest running on physical machine A, to make sure that physical machine B supports the same IOMMU properties before migrating the VM over to B? Why can't QEMU (instead of the user) select a feature set on machine A, then when time comes to migrate, query all information from the host kernel on machine B and check that it matches what was picked for machine A? Or is it only trying to accommodate different sets of features between A and B, that would be too difficult? Thanks, Jean > > -cpu host is an exception, which is used because it is so useful, but > it's kind of a pain on the qemu side. Virt management systems like > oVirt/RHV almost universally *do not use* -cpu host, precisely because > it cannot support predictable migration. > > -- > David Gibson | I'll have my music baroque, and my code > david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ > | _way_ _around_! > http://www.ozlabs.org/~dgibson