From patchwork Wed Dec 7 05:52:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 9463977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 316C06022E for ; Wed, 7 Dec 2016 05:57:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21378283F3 for ; Wed, 7 Dec 2016 05:57:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1607F28467; Wed, 7 Dec 2016 05:57:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B5A4A283F3 for ; Wed, 7 Dec 2016 05:57:53 +0000 (UTC) Received: from localhost ([::1]:36538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEVEm-0007AQ-Sy for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Dec 2016 00:57:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEVEQ-0007AG-Ha for qemu-devel@nongnu.org; Wed, 07 Dec 2016 00:57:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cEVEL-0001ri-NJ for qemu-devel@nongnu.org; Wed, 07 Dec 2016 00:57:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57444) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cEVEL-0001ra-H5 for qemu-devel@nongnu.org; Wed, 07 Dec 2016 00:57:25 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D68E3F21F for ; Wed, 7 Dec 2016 05:57:24 +0000 (UTC) Received: from pxdev.xzpeter.org (vpn1-4-188.pek2.redhat.com [10.72.4.188]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB75qlKF018900; Wed, 7 Dec 2016 00:52:52 -0500 From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 7 Dec 2016 13:52:44 +0800 Message-Id: <1481089965-3888-2-git-send-email-peterx@redhat.com> In-Reply-To: <1481089965-3888-1-git-send-email-peterx@redhat.com> References: <1481089965-3888-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 07 Dec 2016 05:57:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.9 1/2] intel_iommu: check validity for GAW bits in CE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jasowang@redhat.com, famz@redhat.com, peterx@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently vt-d Context Entry (CE) only allows 39/48 bits address width. If guest software configured more than that, we complain and force shrink to the maximum supported, which is 48bits. Signed-off-by: Peter Xu --- hw/i386/intel_iommu.c | 12 +++++++++++- hw/i386/intel_iommu_internal.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 5f3e351..98d45ef 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -601,7 +601,17 @@ static inline uint32_t vtd_get_level_from_context_entry(VTDContextEntry *ce) static inline uint32_t vtd_get_agaw_from_context_entry(VTDContextEntry *ce) { - return 30 + (ce->hi & VTD_CONTEXT_ENTRY_AW) * 9; + uint8_t aw = (ce->hi & VTD_CONTEXT_ENTRY_AW); + /* + * According to vt-d spec 10.4.2 bits 12:8, SAGAW only allows + * 39/48 bits. + */ + if (aw > VTD_CE_AW_48BIT) { + error_report("Context entry address width not supported (aw=%d), " + "Shrinking to maximum.", aw); + aw = VTD_CE_AW_48BIT; + } + return 30 + aw * 9; } static const uint64_t vtd_paging_entry_rsvd_field[] = { diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 11abfa2..e808c67 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -406,6 +406,8 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_CONTEXT_ENTRY_RSVD_LO (0xff0ULL | ~VTD_HAW_MASK) /* hi */ #define VTD_CONTEXT_ENTRY_AW 7ULL /* Adjusted guest-address-width */ +#define VTD_CE_AW_39BIT 1 +#define VTD_CE_AW_48BIT 2 #define VTD_CONTEXT_ENTRY_DID(val) (((val) >> 8) & VTD_DOMAIN_ID_MASK) #define VTD_CONTEXT_ENTRY_RSVD_HI 0xffffffffff000080ULL