Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4567992ybb; Tue, 14 Apr 2020 09:46:55 -0700 (PDT) X-Google-Smtp-Source: APiQypLvzqIVrfQsJO/pBvOG5nQQ3Me7uPyACo9EsHZ4Di24lBqW1ZCu4n92xsUB+FPlPvZ48+V8 X-Received: by 2002:a17:906:b253:: with SMTP id ce19mr1037545ejb.341.1586882814905; Tue, 14 Apr 2020 09:46:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586882814; cv=none; d=google.com; s=arc-20160816; b=as5SRfBxQs+SMJYKzRk1EGP/REj6Qwi1jvZOUGkgwD7PhqesRbar8XUgFdbGZrMeHJ rzjsT+tWTW2bv5gHl5yy8lg9DLmVpLssZGmTVWrrge5/2kUnLLnQS9vt6WEdaDoaE6sq Ea/8Ng/u7d7iIzojlQrjuvudtS+99nk8YWyWwVM2wYHQcfkHrFEANiAdfofw+tQyCPoE U5+2T/2zIJEPl2VUIjEU4LoxD7j+cNth8BVhILOwxn6s6yIwME2CU9YZcvq2jYHDtErj evj2UsbrjnkJWBV2vniQ2vpmJRGagwJtTLsi5C8YPucYcvYtK3NYkh/pO9JOS+Dtq7QL 4PpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=oQFaclXJcZ18GN/CxTEgak7w44eWrAL92ByRZ9j1osw=; b=ZyIkA52cNKtAbp+u32owNLG21MF0+HI2K9G+vdpcKfqMMV6ECUXQjYTUb4/b6268g4 dhTTxTb631j39FWJ9t5ZSMaID3C/8dmtin+GJILYxSs2+dGcSLjb4SbqUe5XnnSzmqb0 WjDzrk6PVXLQs5OpHmNzqvJvNkcV2g1eU3Qd64CvTXM/j7e0aomZMgHcHItnDzX1fUU6 GLz5cmSQUJ0/3088GK8ySkk9jZ3O1WlGJmHP675YYnXlGro82UHjKddQGCOKr2F6BsnA hqfcl1s8nK/CDrMDzh3Tg0JXCPW1w7eSLbtlDIL+hpIWa3kHwvHeMmKTQi1QcjLGGrlG FVEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Gj0939cV; spf=pass (google.com: best guess record for 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si3635512eje.107.2020.04.14.09.46.31; Tue, 14 Apr 2020 09:46:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for 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=@redhat.com header.s=mimecast20190719 header.b=Gj0939cV; spf=pass (google.com: best guess record for 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2440386AbgDNPYb (ORCPT + 99 others); Tue, 14 Apr 2020 11:24:31 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:47543 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2440370AbgDNPYL (ORCPT ); Tue, 14 Apr 2020 11:24:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586877849; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oQFaclXJcZ18GN/CxTEgak7w44eWrAL92ByRZ9j1osw=; b=Gj0939cVTvYaIQOrqiL7x6rWjB42urHGXzIUq0AP+0Yx1M97XyQ4+daCzvqvsPQQZp5L9s XJ3Agzr1uWvtNuSG/LcnQXe2vhiFBoE+sFu/EJ52hHQxAqhS4QRLF2Su3QQCLsykwXvKP9 N/gSEj3vPBzOKFNhqhum7oF5jyQFAv8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-137-9bfuwomlMXOWQZBrvv1r1A-1; Tue, 14 Apr 2020 11:24:05 -0400 X-MC-Unique: 9bfuwomlMXOWQZBrvv1r1A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D2388018A6; Tue, 14 Apr 2020 15:24:02 +0000 (UTC) Received: from w520.home (ovpn-112-162.phx2.redhat.com [10.3.112.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CEF9CFDF8; Tue, 14 Apr 2020 15:24:01 +0000 (UTC) Date: Tue, 14 Apr 2020 09:24:01 -0600 From: Alex Williamson To: "Tian, Kevin" Cc: "Raj, Ashok" , "Raj, Ashok" , "jean-philippe@linaro.org" , "kvm@vger.kernel.org" , "Tian, Jun J" , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , "Sun, Yi Y" , "Bjorn Helgaas" , "Wu, Hao" , Don Dutile Subject: Re: [PATCH v1 2/2] vfio/pci: Emulate PASID/PRI capability for VFs Message-ID: <20200414092401.039edef6@w520.home> In-Reply-To: References: <1584880394-11184-1-git-send-email-yi.l.liu@intel.com> <1584880394-11184-3-git-send-email-yi.l.liu@intel.com> <20200402165954.48d941ee@w520.home> <20200403112545.6c115ba3@w520.home> <20200407095801.648b1371@w520.home> <20200408040021.GS67127@otc-nc-03> <20200408101940.3459943d@w520.home> <20200413031043.GA18183@araj-mobl1.jf.intel.com> <20200413132122.46825849@w520.home> <20200413212836.117b4c86@x1.home> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 14 Apr 2020 03:42:42 +0000 "Tian, Kevin" wrote: > > From: Alex Williamson > > Sent: Tuesday, April 14, 2020 11:29 AM > > > > On Tue, 14 Apr 2020 02:40:58 +0000 > > "Tian, Kevin" wrote: > > > > > > From: Alex Williamson > > > > Sent: Tuesday, April 14, 2020 3:21 AM > > > > > > > > On Mon, 13 Apr 2020 08:05:33 +0000 > > > > "Tian, Kevin" wrote: > > > > > > > > > > From: Tian, Kevin > > > > > > Sent: Monday, April 13, 2020 3:55 PM > > > > > > > > > > > > > From: Raj, Ashok > > > > > > > Sent: Monday, April 13, 2020 11:11 AM > > > > > > > > > > > > > > On Wed, Apr 08, 2020 at 10:19:40AM -0600, Alex Williamson wrote: > > > > > > > > On Tue, 7 Apr 2020 21:00:21 -0700 > > > > > > > > "Raj, Ashok" wrote: > > > > > > > > > > > > > > > > > Hi Alex > > > > > > > > > > > > > > > > > > + Bjorn > > > > > > > > > > > > > > > > + Don > > > > > > > > > > > > > > > > > FWIW I can't understand why PCI SIG went different ways with > > ATS, > > > > > > > > > where its enumerated on PF and VF. But for PASID and PRI its > > only > > > > > > > > > in PF. > > > > > > > > > > > > > > > > > > I'm checking with our internal SIG reps to followup on that. > > > > > > > > > > > > > > > > > > On Tue, Apr 07, 2020 at 09:58:01AM -0600, Alex Williamson > > wrote: > > > > > > > > > > > Is there vendor guarantee that hidden registers will locate at > > the > > > > > > > > > > > same offset between PF and VF config space? > > > > > > > > > > > > > > > > > > > > I'm not sure if the spec really precludes hidden registers, but > > the > > > > > > > > > > fact that these registers are explicitly outside of the capability > > > > > > > > > > chain implies they're only intended for device specific use, so > > I'd > > > > say > > > > > > > > > > there are no guarantees about anything related to these > > registers. > > > > > > > > > > > > > > > > > > As you had suggested in the other thread, we could consider > > > > > > > > > using the same offset as in PF, but even that's a better guess > > > > > > > > > still not reliable. > > > > > > > > > > > > > > > > > > The other option is to maybe extend driver ops in the PF to > > expose > > > > > > > > > where the offsets should be. Sort of adding the quirk in the > > > > > > > > > implementation. > > > > > > > > > > > > > > > > > > I'm not sure how prevalent are PASID and PRI in VF devices. If > > SIG is > > > > > > > resisting > > > > > > > > > making VF's first class citizen, we might ask them to add some > > > > verbiage > > > > > > > > > to suggest leave the same offsets as PF open to help emulation > > > > software. > > > > > > > > > > > > > > > > Even if we know where to expose these capabilities on the VF, it's > > not > > > > > > > > clear to me how we can actually virtualize the capability itself. If > > > > > > > > the spec defines, for example, an enable bit as r/w then software > > that > > > > > > > > interacts with that register expects the bit is settable. There's no > > > > > > > > protocol for "try to set the bit and re-read it to see if the hardware > > > > > > > > accepted it". Therefore a capability with a fixed enable bit > > > > > > > > representing the state of the PF, not settable by the VF, is > > > > > > > > disingenuous to the spec. > > > > > > > > > > > > > > I think we are all in violent agreement. A lot of times the pci spec > > gets > > > > > > > defined several years ahead of real products and no one > > remembers > > > > > > > the justification on why they restricted things the way they did. > > > > > > > > > > > > > > Maybe someone early product wasn't quite exposing these features > > to > > > > the > > > > > > > VF > > > > > > > and hence the spec is bug compatible :-) > > > > > > > > > > > > > > > > > > > > > > > If what we're trying to do is expose that PASID and PRI are enabled > > on > > > > > > > > the PF to a VF driver, maybe duplicating the PF capabilities on the > > VF > > > > > > > > without the ability to control it is not the right approach. Maybe > > we > > > > > > > > > > > > > > As long as the capability enable is only provided when the PF has > > > > enabled > > > > > > > the feature. Then it seems the hardware seems to do the right thing. > > > > > > > > > > > > > > Assume we expose PASID/PRI only when PF has enabled it. It will be > > the > > > > > > > case since the PF driver needs to exist, and IOMMU would have set > > the > > > > > > > PASID/PRI/ATS on PF. > > > > > > > > > > > > > > If the emulation is purely spoofing the capability. Once vIOMMU > > driver > > > > > > > enables PASID, the context entries for the VF are completely > > > > independent > > > > > > > from the PF context entries. > > > > > > > > > > > > > > vIOMMU would enable PASID, and we just spoof the PASID > > capability. > > > > > > > > > > > > > > If vIOMMU or guest for some reason does disable_pasid(), then the > > > > > > > vIOMMU driver can disaable PASID on the VF context entries. So the > > VF > > > > > > > although the capability is blanket enabled on PF, IOMMU gaurantees > > > > the > > > > > > > transactions are blocked. > > > > > > > > > > > > > > > > > > > > > In the interim, it seems like the intent of the virtual capability > > > > > > > can be honored via help from the IOMMU for the controlling aspect.. > > > > > > > > > > > > > > Did i miss anything? > > > > > > > > > > > > Above works for emulating the enable bit (under the assumption that > > > > > > PF driver won't disable pasid when vf is assigned). However, there are > > > > > > also "Execute permission enable" and "Privileged mode enable" bits in > > > > > > PASID control registers. I don't know how those bits could be cleanly > > > > > > emulated when the guest writes a value different from PF's... > > > > > > > > > > sent too quick. the IOMMU also includes control bits for allowing/ > > > > > blocking execute requests and supervisor requests. We can rely on > > > > > IOMMU to block those requests to emulate the disabled cases of > > > > > all three control bits in the pasid cap. > > > > > > > > > > > > So if the emulation of the PASID capability takes into account the > > > > IOMMU configuration to back that emulation, shouldn't we do that > > > > emulation in the hypervisor, ie. QEMU, rather than the kernel vfio > > > > layer? Thanks, > > > > > > > > Alex > > > > > > We need enforce it in physical IOMMU, to ensure that even the > > > VF may send requests which violate the guest expectation those > > > requests are always blocked by IOMMU. Kernel vfio identifies > > > such need when emulating the pasid cap and then forward the > > > request to host iommu driver. > > > > Implementing this in the kernel would be necessary if we needed to > > protect from the guest device doing something bad to the host or > > other devices. Making sure the physical IOMMU is configured to meet > > guest expectations doesn't sound like it necessarily falls into that > > category. We do that on a regular basis to program the DMA mappings. > > Tell me more about why the hypervisor can't handle this piece of > > guest/host synchronization on top of all the other things it > > synchronizes to make a VM. Thanks, > > > > I care more about "execution permission" and "privileged mode". > It might be dangerous when the guest disallows the VF from sending "Dangerous" how? We're generally ok with the user managing their own consistency, it's when the user can affect other users/devices that we require vfio in the kernel to actively manage something. There's a very different scope to the vfio-pci kernel module implementing a fake capability and trying to make it behave indistinguishably from the real capability versus a userspace driver piecing together an emulation that's good enough for their purposes. Thanks, Alex > DMA requests which have the execute or privileged bit set while the VF > can still do so w/o proper protection in the IOMMU. This is all about > vSVA for vfio devices, where the guest page table is directly linked in > IOMMU and vfio doesn't participate in the specific DMA mappings. if > an emulated device includes a pasid cap, Qemu vIOMMU will handle > it for sure. > > Thanks > Kevin >