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 X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B782C4338F for ; Fri, 23 Jul 2021 08:29:39 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 667A460E77 for ; Fri, 23 Jul 2021 08:29:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 667A460E77 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:MIME-Version: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=+lZAZ4McGwxCq2/K/yV//azVagt3L4SebWR+HRxeUzc=; b=Z2NQitS6M49Uk5 vypEMsQqVN64tF6ejtemyD3qKdyrKFWyujLXEdmoLDL0bS14+66wa9LBk0OcrYhL/YfK3sQIMAj42 S7U61MDYYRHfZLVvb6tHfACn6yTt1oJFyw18zVdJw1AYr/MqPpad6AN0AJZwrFZA2QoUntEfhAXMa /rzKKh1SfmeP1gQu+yh+YzDgsVnNQEd/AVaqLNkyMrSSpmi+hjLUOCu3ZvH6v65TuwzHv+7E9YcEq BKf5/1yG0oSePRnYU/e0P7QAVTU5Y8ZY0wta/lxtVEVZn6shWYthzs10QARmQI0Aq3iDXZ7tyvmLP +Cp15b3wEOeRHhtNsWFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6qXV-003vkE-Ox; Fri, 23 Jul 2021 08:28:13 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6qXR-003viA-Fu for linux-arm-kernel@lists.infradead.org; Fri, 23 Jul 2021 08:28:11 +0000 Received: from fraeml744-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GWMfY0lnfz6G9D9; Fri, 23 Jul 2021 16:19:01 +0800 (CST) Received: from lhreml712-chm.china.huawei.com (10.201.108.63) by fraeml744-chm.china.huawei.com (10.206.15.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 23 Jul 2021 10:27:58 +0200 Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by lhreml712-chm.china.huawei.com (10.201.108.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 23 Jul 2021 09:27:58 +0100 Received: from lhreml710-chm.china.huawei.com ([169.254.81.184]) by lhreml710-chm.china.huawei.com ([169.254.81.184]) with mapi id 15.01.2176.012; Fri, 23 Jul 2021 09:27:58 +0100 From: Shameerali Kolothum Thodi To: Jean-Philippe Brucker CC: "linux-arm-kernel@lists.infradead.org" , "iommu@lists.linux-foundation.org" , "kvmarm@lists.cs.columbia.edu" , "maz@kernel.org" , "alex.williamson@redhat.com" , "eric.auger@redhat.com" , "zhangfei.gao@linaro.org" , Jonathan Cameron , "Zengtao (B)" , "linuxarm@openeuler.org" , Linuxarm Subject: RE: [Linuxarm] Re: [RFC PATCH 4/5] iommu/arm-smmu-v3: Use pinned VMID for NESTED stage with BTM Thread-Topic: [Linuxarm] Re: [RFC PATCH 4/5] iommu/arm-smmu-v3: Use pinned VMID for NESTED stage with BTM Thread-Index: AQHXERlrJofV4Zjw70Ci8icDpSKnl6tN8a9ggAINboCAAQu/4A== Date: Fri, 23 Jul 2021 08:27:57 +0000 Message-ID: <55ca7f7d8ffc4e05a512252b75d111b7@huawei.com> References: <20210222155338.26132-1-shameerali.kolothum.thodi@huawei.com> <20210222155338.26132-5-shameerali.kolothum.thodi@huawei.com> <903a06a9db8c45fe88158e1c35f38c25@huawei.com> 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.47.86.132] MIME-Version: 1.0 X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210723_012809_871792_128F81B5 X-CRM114-Status: GOOD ( 38.04 ) 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 > -----Original Message----- > From: Jean-Philippe Brucker [mailto:jean-philippe@linaro.org] > Sent: 22 July 2021 17:46 > To: Shameerali Kolothum Thodi > Cc: linux-arm-kernel@lists.infradead.org; iommu@lists.linux-foundation.org; > kvmarm@lists.cs.columbia.edu; maz@kernel.org; > alex.williamson@redhat.com; eric.auger@redhat.com; > zhangfei.gao@linaro.org; Jonathan Cameron > ; Zengtao (B) ; > linuxarm@openeuler.org; Linuxarm > Subject: [Linuxarm] Re: [RFC PATCH 4/5] iommu/arm-smmu-v3: Use pinned > VMID for NESTED stage with BTM > > Hi Shameer, > > On Wed, Jul 21, 2021 at 08:54:00AM +0000, Shameerali Kolothum Thodi > wrote: > > > More generally I think this pinned VMID set conflicts with that of > > > stage-2-only domains (which is the default state until a guest attaches a > > > PASID table). Say you have one guest using DOMAIN_NESTED without > PASID > > > table, just DMA to IPA using VMID 0x8000. Now another guest attaches a > > > PASID table and obtains the same VMID from KVM. The stage-2 translation > > > might use TLB entries from the other guest, no? They'll both create > > > stage-2 TLB entries with {StreamWorld=NS-EL1, VMID=0x8000} > > > > Now that we are trying to align the KVM VMID allocation algorithm similar > to > > that of the ASID allocator [1], I attempted to use that for the SMMU pinned > > VMID allocation. But the issue you have mentioned above is still valid. > > > > And as a solution what I have tried now is follow what pinned ASID is doing > > in SVA, > > -Use xarray for private VMIDs > > -Get pinned VMID from KVM for DOMAIN_NESTED with PASID table > > -If the new pinned VMID is in use by private, then update the private > > VMID(VMID update to a live STE). > > > > This seems to work, but still need to run more tests with this though. > > > > > It's tempting to allocate all VMIDs through KVM instead, but that will > > > force a dependency on KVM to use VFIO_TYPE1_NESTING_IOMMU and > might > > > break > > > existing users of that extension (though I'm not sure there are any). > > > Instead we might need to restrict the SMMU VMID bitmap to match the > > > private VMID set in KVM. > > > > Another solution I have in mind is, make the new KVM VMID allocator > common > > between SMMUv3 and KVM. This will help to avoid all the private and > shared > > VMID splitting, also no need for live updates to STE VMID. One possible > drawback > > is less number of available KVM VMIDs but with 16 bit VMID space I am not > sure > > how much that is a concern. > > Yes I think that works too. In practice there shouldn't be many VMIDs on > the SMMU side, the feature's only enabled when a user wants to assign > devices with nesting translation (unlike ASIDs where each device in the > system gets a private ASID by default). Ok. What about implementations that supports only stage 2? Do we need a private VMID allocator for those or can use the same common KVM VMID allocator? > Note that you still need to pin all VMIDs used by the SMMU, otherwise > you'll have to update the STE after rollover. Sure. > The problem we have with VFIO_TYPE1_NESTING_IOMMU might be solved by > the > upcoming deprecation of VFIO_*_IOMMU [2]. We need a specific sequence > from > userspace: > 1. Attach VFIO group to KVM (KVM_DEV_VFIO_GROUP_ADD) > 2. Create nesting IOMMU domain and attach the group to it > (VFIO_GROUP_SET_CONTAINER, VFIO_SET_IOMMU becomes > IOMMU_IOASID_ALLOC, VFIO_DEVICE_ATTACH_IOASID) > Currently QEMU does 2 then 1, which would cause the SMMU to allocate a > separate VMID. Yes. I have observed this with my current implementation. I have a check to see the private S2 config VMID belongs to the same domain s2_cfg, then skip the live update to the STE VMID. > If we wanted to extend VFIO_TYPE1_NESTING_IOMMU with > PASID > tables we'd need to mandate 1-2 and may break existing users. In the new > design we can require from the start that creating a nesting IOMMU > container through /dev/iommu *must* come with a KVM context, that way > we're sure to reuse the existing VMID. Ok. That helps. Thanks, Shameer _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel