From nobody Thu Nov 6 10:24:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540338646622203.46126745105892; Tue, 23 Oct 2018 16:50:46 -0700 (PDT) Received: from localhost ([::1]:44768 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gF6Rd-0002ZH-RD for importer@patchew.org; Tue, 23 Oct 2018 19:50:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gF6JG-0003DV-Pr for qemu-devel@nongnu.org; Tue, 23 Oct 2018 19:42:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gF6JD-0008Aq-Nf for qemu-devel@nongnu.org; Tue, 23 Oct 2018 19:42:02 -0400 Received: from [185.30.24.106] (port=13438 helo=hotspot.internet-for-guests.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gF6JC-00084l-N6 for qemu-devel@nongnu.org; Tue, 23 Oct 2018 19:41:59 -0400 Received: from redhat.com (unknown [172.29.18.113]) by hotspot.internet-for-guests.com (Postfix) with SMTP id C6C336402FB; Wed, 24 Oct 2018 00:41:30 +0100 (BST) Date: Tue, 23 Oct 2018 19:41:31 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20181023234112.188140-10-mst@redhat.com> References: <20181023234112.188140-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20181023234112.188140-1-mst@redhat.com> X-Mailer: git-send-email 2.17.1.1206.gb667731e2e.dirty X-Mutt-Fcc: =sent X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.30.24.106 Subject: [Qemu-devel] [PULL 09/28] x86_iommu/amd: remove V=1 check from amdvi_validate_dte() 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: Peter Maydell , "Singh, Brijesh" , Eduardo Habkost , Tom Lendacky , Peter Xu , Paolo Bonzini , Suravee Suthikulpanit , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Singh, Brijesh" Currently, the amdvi_validate_dte() assumes that a valid DTE will always have V=3D1. This is not true. The V=3D1 means that bit[127:1] are valid. A valid DTE can have IV=3D1 and V=3D0 (i.e address translation disabled and interrupt remapping enabled) Remove the V=3D1 check from amdvi_validate_dte(), make the caller responsible to check for V or IV bits. This also fixes a bug in existing code that when error is detected during the translation we'll fail the translation instead of assuming a passthrough mode. Signed-off-by: Brijesh Singh Reviewed-by: Peter Xu Cc: Peter Xu Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: Tom Lendacky Cc: Suravee Suthikulpanit Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/amd_iommu.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 1fd669fef8..7206bb09c2 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -807,7 +807,7 @@ static inline uint64_t amdvi_get_perms(uint64_t entry) AMDVI_DEV_PERM_SHIFT; } =20 -/* a valid entry should have V =3D 1 and reserved bits honoured */ +/* validate that reserved bits are honoured */ static bool amdvi_validate_dte(AMDVIState *s, uint16_t devid, uint64_t *dte) { @@ -820,7 +820,7 @@ static bool amdvi_validate_dte(AMDVIState *s, uint16_t = devid, return false; } =20 - return dte[0] & AMDVI_DEV_VALID; + return true; } =20 /* get a device table entry given the devid */ @@ -966,8 +966,12 @@ static void amdvi_do_translate(AMDVIAddressSpace *as, = hwaddr addr, return; } =20 - /* devices with V =3D 0 are not translated */ if (!amdvi_get_dte(s, devid, entry)) { + return; + } + + /* devices with V =3D 0 are not translated */ + if (!(entry[0] & AMDVI_DEV_VALID)) { goto out; } =20 --=20 MST