From patchwork Tue Oct 20 13:52:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11847057 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 168D31580 for ; Tue, 20 Oct 2020 13:54:33 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 CD93122240 for ; Tue, 20 Oct 2020 13:54:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="uD9eaGvg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD93122240 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.9636.25297 (Exim 4.92) (envelope-from ) id 1kUs4V-0007XE-G4; Tue, 20 Oct 2020 13:53:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 9636.25297; Tue, 20 Oct 2020 13:53:03 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kUs4V-0007X7-C4; Tue, 20 Oct 2020 13:53:03 +0000 Received: by outflank-mailman (input) for mailman id 9636; Tue, 20 Oct 2020 13:53:02 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kUs4U-0007X2-Oy for xen-devel@lists.xenproject.org; Tue, 20 Oct 2020 13:53:02 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c6eaa1f2-b3da-41c5-b272-ccffa42e1654; Tue, 20 Oct 2020 13:53:01 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C6C9BB2A1; Tue, 20 Oct 2020 13:53:00 +0000 (UTC) Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kUs4U-0007X2-Oy for xen-devel@lists.xenproject.org; Tue, 20 Oct 2020 13:53:02 +0000 X-Inumbo-ID: c6eaa1f2-b3da-41c5-b272-ccffa42e1654 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c6eaa1f2-b3da-41c5-b272-ccffa42e1654; Tue, 20 Oct 2020 13:53:01 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1603201980; 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; bh=Qw9DdLlTTRCZ41LkBf5W6P/I4UyBKlxJ/5Koa8Aym5M=; b=uD9eaGvggrXjd/5iMNhKtudPbBweYTK0gPxxaRBPCvGy2CItogPjgsU+H0cmg3u8Cc0m07 fwQADUANEXGICwgJ1pE7TLBs2o6hnhiYsHXHmmJ4nrYd8ajasCaw/JW/HdCVvZ99AQ3m7Z BstQu+kh/GBTP8KHEmjAhsObnFApJbw= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C6C9BB2A1; Tue, 20 Oct 2020 13:53:00 +0000 (UTC) To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Wei Liu , Stefano Stabellini , Kevin Tian , Jun Nakajima , Paul Durrant From: Jan Beulich Subject: [PATCH] IOMMU: avoid double flushing in shared page table case Message-ID: Date: Tue, 20 Oct 2020 15:52:59 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 Content-Language: en-US While the flush coalescing optimization has been helping the non-shared case, it has actually lead to double flushes in the shared case (which ought to be the more common one nowadays at least): Once from *_set_entry() and a second time up the call tree from wherever the overriding flag gets played with. In alignment with XSA-346 suppress flushing in this case. Similarly avoid excessive setting of IOMMU_FLUSHF_added on the batched flushes: "idx" hasn't been added a new mapping for. Signed-off-by: Jan Beulich Reviewed-by: Kevin Tian --- TBD: The Arm part really is just for completeness (and hence could also be dropped) - the affected mapping spaces aren't currently supported there. --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1045,7 +1045,7 @@ static int __p2m_set_entry(struct p2m_do p2m->lowest_mapped_gfn = gfn_min(p2m->lowest_mapped_gfn, sgfn); } - if ( is_iommu_enabled(p2m->domain) && + if ( is_iommu_enabled(p2m->domain) && !this_cpu(iommu_dont_flush_iotlb) && (lpae_is_valid(orig_pte) || lpae_is_valid(*entry)) ) { unsigned int flush_flags = 0; --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -842,7 +842,7 @@ out: if ( rc == 0 && p2m_is_hostp2m(p2m) && need_modify_vtd_table ) { - if ( iommu_use_hap_pt(d) ) + if ( iommu_use_hap_pt(d) && !this_cpu(iommu_dont_flush_iotlb) ) rc = iommu_iotlb_flush(d, _dfn(gfn), 1ul << order, (iommu_flags ? IOMMU_FLUSHF_added : 0) | (vtd_pte_present ? IOMMU_FLUSHF_modified --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -870,7 +870,7 @@ int xenmem_add_to_physmap(struct domain this_cpu(iommu_dont_flush_iotlb) = 0; ret = iommu_iotlb_flush(d, _dfn(xatp->idx - done), done, - IOMMU_FLUSHF_added | IOMMU_FLUSHF_modified); + IOMMU_FLUSHF_modified); if ( unlikely(ret) && rc >= 0 ) rc = ret;