From nobody Sun May 19 01:42:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1690984759; cv=none; d=zohomail.com; s=zohoarc; b=EgCYlKX91UvGRGMqGUwI+L6EaI4ZPLgRedMvBgyY/njmbEj7dBoiU2/E29g0j1KXGti6mHofDuvUDkmFqzQW+m8iXQbOvk3JW5upCwKcWYygnPOwPtHVL4Jelgf72Wt3aZR7+aqJhtU1KfUrvLkr0NCdazLw6hjwulc3UrJnbl4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690984759; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f+QED4Tq4XnPioa13QRpxi8srcldyyizEwfC5kFPupI=; b=gcHAC2ZQAhxwoYNUeGVaayspDJuk0SHJeqBDrQsD8eYMaKnSblHPzqlIuF0nLpx6pAIh4J9rwkuD2RIgzkIYMw2tW24wlcRRKx2Q2YA4YLqipq4C2ITZ5/FRM6c76dg+mU8L9m/oGwDXCMDhQvBVgtfUXsjxvIUCbJZTW/ObQjo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690984759290646.3963093744176; Wed, 2 Aug 2023 06:59:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRCM5-0006MU-FJ; Wed, 02 Aug 2023 09:57:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRCM4-0006Lh-C3 for qemu-devel@nongnu.org; Wed, 02 Aug 2023 09:57:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRCM3-00073U-1o for qemu-devel@nongnu.org; Wed, 02 Aug 2023 09:57:36 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-F-RsgOHiNZuHduEslF6xWQ-1; Wed, 02 Aug 2023 09:57:29 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C21F5900824; Wed, 2 Aug 2023 13:57:28 +0000 (UTC) Received: from thuth.com (unknown [10.39.195.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A6CE2166B26; Wed, 2 Aug 2023 13:57:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690984654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f+QED4Tq4XnPioa13QRpxi8srcldyyizEwfC5kFPupI=; b=gqEH63B+I2G1yAwIIVFypiODL4yM68Pyt+z+LnqbZPuCTjcGdk9751k25GZr2LZdZ2nckS hNiozWwn9JtDAdnnmfFB1xXo5keYBS9+KDXQqh948v5/XwIX7IXRraMWmW8p4N9t6v1ny+ alg8bdIx/4hzB3M4sFFFjxpX3melyiI= X-MC-Unique: F-RsgOHiNZuHduEslF6xWQ-1 From: Thomas Huth To: "Michael S. Tsirkin" , Peter Xu Cc: Jason Wang , Richard Henderson , qemu-devel@nongnu.org, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , qemu-stable@nongnu.org, Paolo Bonzini Subject: [PATCH 1/6] hw/i386/intel_iommu: Fix trivial endianness problems Date: Wed, 2 Aug 2023 15:57:18 +0200 Message-Id: <20230802135723.178083-2-thuth@redhat.com> In-Reply-To: <20230802135723.178083-1-thuth@redhat.com> References: <20230802135723.178083-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1690984760551100006 Content-Type: text/plain; charset="utf-8" After reading the guest memory with dma_memory_read(), we have to make sure that we byteswap the little endian data to the host's byte order. Signed-off-by: Thomas Huth Reviewed-by: Peter Xu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/i386/intel_iommu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index dcc334060c..13fcde8e91 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -756,6 +756,8 @@ static int vtd_get_pdire_from_pdir_table(dma_addr_t pas= id_dir_base, return -VTD_FR_PASID_TABLE_INV; } =20 + pdire->val =3D le64_to_cpu(pdire->val); + return 0; } =20 @@ -780,6 +782,9 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUSta= te *s, pe, entry_size, MEMTXATTRS_UNSPECIFIED)) { return -VTD_FR_PASID_TABLE_INV; } + for (size_t i =3D 0; i < ARRAY_SIZE(pe->val); i++) { + pe->val[i] =3D le64_to_cpu(pe->val[i]); + } =20 /* Do translation type check */ if (!vtd_pe_type_check(x86_iommu, pe)) { --=20 2.39.3 From nobody Sun May 19 01:42:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1690984745; cv=none; d=zohomail.com; s=zohoarc; b=m8WqtUxcMHkD0z83AHiOPxfMj/aEAWYukWg8KKWCcdXEXN/wAEpDP514hSGq+0mgJRNgnPg/HI0jHlxy3POTQsTEOZvdJ55DqrQ1oHtBf+6ZFcvVeXUp76cqHuUurR9cvGY62Es9fMi72z+Z9tXKQ6VWGTA7tD3n11u1uR18ZxU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690984745; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qDiUNSzXkInN6UCpsF+BwjwjMhDmrMLmyhYTJw0Q0RA=; b=hpPcYHISys2HcsQIOa6VWnlzoUWJfhQigkjNg1eEZ66sey9NYbr7t/RiJoEw7xrLXBO2oNavsntetfm1ifkMeEjBTM7mnvGSkpTOeeNPCEw4PTNbQTBgiZCqSBoTTx7VNbrhpux9tiDNx/Ebxq/S82vdIJueHYO4L/5a4UsU+q0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690984745771279.6454822762496; Wed, 2 Aug 2023 06:59:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRCM4-0006Lc-8y; Wed, 02 Aug 2023 09:57:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRCM2-0006L6-Qo for qemu-devel@nongnu.org; Wed, 02 Aug 2023 09:57:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRCM1-00072t-0t for qemu-devel@nongnu.org; Wed, 02 Aug 2023 09:57:34 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-422-RbFiN9kAN0mzZ7NSU3Zumg-1; Wed, 02 Aug 2023 09:57:30 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6A9B1800B35; Wed, 2 Aug 2023 13:57:30 +0000 (UTC) Received: from thuth.com (unknown [10.39.195.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1208D2166B25; Wed, 2 Aug 2023 13:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690984652; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qDiUNSzXkInN6UCpsF+BwjwjMhDmrMLmyhYTJw0Q0RA=; b=Kea6//ZA0euxppw/awhzyROsoHrUc1o0mrS+nm23DcA9uxD+F6gY61NFfHTu8BhsNAlms9 dAq3eOL8MZCmJC7fUa3wBbueGQl51GkLmhVMyda4pjHZ3xXkoDY4vhR1/e23cg9RvSr9D1 0yTVv8p4mhHrhiF4jRUrug+boY0erbA= X-MC-Unique: RbFiN9kAN0mzZ7NSU3Zumg-1 From: Thomas Huth To: "Michael S. Tsirkin" , Peter Xu Cc: Jason Wang , Richard Henderson , qemu-devel@nongnu.org, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , qemu-stable@nongnu.org, Paolo Bonzini Subject: [PATCH 2/6] hw/i386/intel_iommu: Fix endianness problems related to VTD_IR_TableEntry Date: Wed, 2 Aug 2023 15:57:19 +0200 Message-Id: <20230802135723.178083-3-thuth@redhat.com> In-Reply-To: <20230802135723.178083-1-thuth@redhat.com> References: <20230802135723.178083-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1690984747127100008 Content-Type: text/plain; charset="utf-8" The code already tries to do some endianness handling here, but currently fails badly: - While it already swaps the data when logging errors / tracing, it fails to byteswap the value before e.g. accessing entry->irte.present - entry->irte.source_id is swapped with le32_to_cpu(), though this is a 16-bit value - The whole union is apparently supposed to be swapped via the 64-bit data[2] array, but the struct is a mixture between 32 bit values (the first 8 bytes) and 64 bit values (the second 8 bytes), so this cannot work as expected. Fix it by converting the struct to two proper 64-bit bitfields, and by swapping the values only once for everybody right after reading the data from memory. Signed-off-by: Thomas Huth Reviewed-by: Peter Xu --- include/hw/i386/intel_iommu.h | 50 ++++++++++++++++++----------------- hw/i386/intel_iommu.c | 16 +++++------ 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 89dcbc5e1e..7fa0a695c8 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -178,37 +178,39 @@ enum { union VTD_IR_TableEntry { struct { #if HOST_BIG_ENDIAN - uint32_t __reserved_1:8; /* Reserved 1 */ - uint32_t vector:8; /* Interrupt Vector */ - uint32_t irte_mode:1; /* IRTE Mode */ - uint32_t __reserved_0:3; /* Reserved 0 */ - uint32_t __avail:4; /* Available spaces for software */ - uint32_t delivery_mode:3; /* Delivery Mode */ - uint32_t trigger_mode:1; /* Trigger Mode */ - uint32_t redir_hint:1; /* Redirection Hint */ - uint32_t dest_mode:1; /* Destination Mode */ - uint32_t fault_disable:1; /* Fault Processing Disable */ - uint32_t present:1; /* Whether entry present/available */ + uint64_t dest_id:32; /* Destination ID */ + uint64_t __reserved_1:8; /* Reserved 1 */ + uint64_t vector:8; /* Interrupt Vector */ + uint64_t irte_mode:1; /* IRTE Mode */ + uint64_t __reserved_0:3; /* Reserved 0 */ + uint64_t __avail:4; /* Available spaces for software */ + uint64_t delivery_mode:3; /* Delivery Mode */ + uint64_t trigger_mode:1; /* Trigger Mode */ + uint64_t redir_hint:1; /* Redirection Hint */ + uint64_t dest_mode:1; /* Destination Mode */ + uint64_t fault_disable:1; /* Fault Processing Disable */ + uint64_t present:1; /* Whether entry present/available */ #else - uint32_t present:1; /* Whether entry present/available */ - uint32_t fault_disable:1; /* Fault Processing Disable */ - uint32_t dest_mode:1; /* Destination Mode */ - uint32_t redir_hint:1; /* Redirection Hint */ - uint32_t trigger_mode:1; /* Trigger Mode */ - uint32_t delivery_mode:3; /* Delivery Mode */ - uint32_t __avail:4; /* Available spaces for software */ - uint32_t __reserved_0:3; /* Reserved 0 */ - uint32_t irte_mode:1; /* IRTE Mode */ - uint32_t vector:8; /* Interrupt Vector */ - uint32_t __reserved_1:8; /* Reserved 1 */ + uint64_t present:1; /* Whether entry present/available */ + uint64_t fault_disable:1; /* Fault Processing Disable */ + uint64_t dest_mode:1; /* Destination Mode */ + uint64_t redir_hint:1; /* Redirection Hint */ + uint64_t trigger_mode:1; /* Trigger Mode */ + uint64_t delivery_mode:3; /* Delivery Mode */ + uint64_t __avail:4; /* Available spaces for software */ + uint64_t __reserved_0:3; /* Reserved 0 */ + uint64_t irte_mode:1; /* IRTE Mode */ + uint64_t vector:8; /* Interrupt Vector */ + uint64_t __reserved_1:8; /* Reserved 1 */ + uint64_t dest_id:32; /* Destination ID */ #endif - uint32_t dest_id; /* Destination ID */ - uint16_t source_id; /* Source-ID */ #if HOST_BIG_ENDIAN uint64_t __reserved_2:44; /* Reserved 2 */ uint64_t sid_vtype:2; /* Source-ID Validation Type */ uint64_t sid_q:2; /* Source-ID Qualifier */ + uint64_t source_id:16; /* Source-ID */ #else + uint64_t source_id:16; /* Source-ID */ uint64_t sid_q:2; /* Source-ID Qualifier */ uint64_t sid_vtype:2; /* Source-ID Validation Type */ uint64_t __reserved_2:44; /* Reserved 2 */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 13fcde8e91..4028e32701 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3328,14 +3328,15 @@ static int vtd_irte_get(IntelIOMMUState *iommu, uin= t16_t index, return -VTD_FR_IR_ROOT_INVAL; } =20 - trace_vtd_ir_irte_get(index, le64_to_cpu(entry->data[1]), - le64_to_cpu(entry->data[0])); + entry->data[0] =3D le64_to_cpu(entry->data[0]); + entry->data[1] =3D le64_to_cpu(entry->data[1]); + + trace_vtd_ir_irte_get(index, entry->data[1], entry->data[0]); =20 if (!entry->irte.present) { error_report_once("%s: detected non-present IRTE " "(index=3D%u, high=3D0x%" PRIx64 ", low=3D0x%" P= RIx64 ")", - __func__, index, le64_to_cpu(entry->data[1]), - le64_to_cpu(entry->data[0])); + __func__, index, entry->data[1], entry->data[0]); return -VTD_FR_IR_ENTRY_P; } =20 @@ -3343,14 +3344,13 @@ static int vtd_irte_get(IntelIOMMUState *iommu, uin= t16_t index, entry->irte.__reserved_2) { error_report_once("%s: detected non-zero reserved IRTE " "(index=3D%u, high=3D0x%" PRIx64 ", low=3D0x%" P= RIx64 ")", - __func__, index, le64_to_cpu(entry->data[1]), - le64_to_cpu(entry->data[0])); + __func__, index, entry->data[1], entry->data[0]); return -VTD_FR_IR_IRTE_RSVD; } =20 if (sid !=3D X86_IOMMU_SID_INVALID) { /* Validate IRTE SID */ - source_id =3D le32_to_cpu(entry->irte.source_id); + source_id =3D entry->irte.source_id; switch (entry->irte.sid_vtype) { case VTD_SVT_NONE: break; @@ -3404,7 +3404,7 @@ static int vtd_remap_irq_get(IntelIOMMUState *iommu, = uint16_t index, irq->trigger_mode =3D irte.irte.trigger_mode; irq->vector =3D irte.irte.vector; irq->delivery_mode =3D irte.irte.delivery_mode; - irq->dest =3D le32_to_cpu(irte.irte.dest_id); + irq->dest =3D irte.irte.dest_id; if (!iommu->intr_eime) { #define VTD_IR_APIC_DEST_MASK (0xff00ULL) #define VTD_IR_APIC_DEST_SHIFT (8) --=20 2.39.3 From nobody Sun May 19 01:42:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1690984757; cv=none; d=zohomail.com; s=zohoarc; b=KniJUInhoh/FEq/sTxsN11VSfNkMXs8KRJnBNkLjctV4u5iPPH7v+mJTg6PjnmhZ2GrSlifCTJQmdSg2QTeGr96uujdOIHLu22TxjQcmJtVU7R5zOKGGwOqBW00ZKcS8gNNb6luNuwodzKvAVGYQbH/wSlLfIF5KKlT+JNnuuxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690984757; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tC+DnvIXXhc061pn81v7KyxaCnhw0iKUBiHRIit2C4c=; b=TzDXb6dmIIzsJ/CIaAAX5I6hXFV6DaIzK0f11q12R7lA6JZOwXYqZN4PAit7QVWPmmuZc5okINofhEu3uyCv7bclhWELrz3P/aYh5l3t9E4jyJJdJYaO0S22z0bhf+y97BEvemGTb4F4lr9DX2RCM0iUZIT6G4snotj/dKF82S8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690984757495216.53480288198455; Wed, 2 Aug 2023 06:59:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRCM8-0006Nl-SC; Wed, 02 Aug 2023 09:57:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRCM8-0006NA-10 for qemu-devel@nongnu.org; Wed, 02 Aug 2023 09:57:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRCM5-000741-6I for qemu-devel@nongnu.org; Wed, 02 Aug 2023 09:57:39 -0400 Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-157--vtkqXBINx-hD5mVaArmvA-1; Wed, 02 Aug 2023 09:57:33 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1BD002834764; Wed, 2 Aug 2023 13:57:32 +0000 (UTC) Received: from thuth.com (unknown [10.39.195.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0C002166B25; Wed, 2 Aug 2023 13:57:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690984656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tC+DnvIXXhc061pn81v7KyxaCnhw0iKUBiHRIit2C4c=; b=W73t3NwIrN1wQvhMpFqa4YKnWCGuNvBmmB5VA6qfCk1Mbv/kpkZTFLhYkGNgVV0Bc3w0i/ TI5KD708gGA7j0qFrlsJgwmQFz3ukIDac8xGfCwRPC9E37FLLdwnqSq6qfeyGTe5nmdQi5 IAXmhSaWGlP9sA7prqo6ZF/F4ZEgXyU= X-MC-Unique: -vtkqXBINx-hD5mVaArmvA-1 From: Thomas Huth To: "Michael S. Tsirkin" , Peter Xu Cc: Jason Wang , Richard Henderson , qemu-devel@nongnu.org, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , qemu-stable@nongnu.org, Paolo Bonzini Subject: [PATCH 3/6] hw/i386/intel_iommu: Fix struct VTDInvDescIEC on big endian hosts Date: Wed, 2 Aug 2023 15:57:20 +0200 Message-Id: <20230802135723.178083-4-thuth@redhat.com> In-Reply-To: <20230802135723.178083-1-thuth@redhat.com> References: <20230802135723.178083-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1690984758877100003 Content-Type: text/plain; charset="utf-8" On big endian hosts, we need to reverse the bitfield order in the struct VTDInvDescIEC, just like it is already done for the other bitfields in the various structs of the intel-iommu device. Signed-off-by: Thomas Huth Reviewed-by: Peter Xu --- hw/i386/intel_iommu_internal.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 2e61eec2f5..e1450c5cfe 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -321,12 +321,21 @@ typedef enum VTDFaultReason { =20 /* Interrupt Entry Cache Invalidation Descriptor: VT-d 6.5.2.7. */ struct VTDInvDescIEC { +#if HOST_BIG_ENDIAN + uint64_t reserved_2:16; + uint64_t index:16; /* Start index to invalidate */ + uint64_t index_mask:5; /* 2^N for continuous int invalidation */ + uint64_t resved_1:22; + uint64_t granularity:1; /* If set, it's global IR invalidation */ + uint64_t type:4; /* Should always be 0x4 */ +#else uint32_t type:4; /* Should always be 0x4 */ uint32_t granularity:1; /* If set, it's global IR invalidation */ uint32_t resved_1:22; uint32_t index_mask:5; /* 2^N for continuous int invalidation */ uint32_t index:16; /* Start index to invalidate */ uint32_t reserved_2:16; +#endif }; typedef struct VTDInvDescIEC VTDInvDescIEC; =20 --=20 2.39.3 From nobody Sun May 19 01:42:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1690984783; cv=none; d=zohomail.com; s=zohoarc; b=OGdMonbSgQ5txIiraU9TNIxKlybT+uqHcUvF9triCUbFCQ6aCNQLNCmc9KdNx6z3uge3uyFhKPH14QCD9zUdz1cd8tWuTKiI+RZe3CJxtK9IB/dAjDDzB7guIra0GyOQzNtslFcAEdkUrQokWJrEmxLFZpJ5P+jvk3kF0x9T3GM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690984783; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LSZvMs2xZuGZiAo08FeJlJQteWbBSt4IoZPkpkn9hIM=; b=V33Kv24lgyjTCdHombMEjZrAjX2fqxKZLGFnBPYnWmNsPchkj2GqpljWBla4/rcZW2COjeJlPUE0t+UpnuzSiod/C3jTm8ly0p6P19fhkO1+akPOVzvKBHxFIli7WFHSzrBbDdfSGblSFt+covhb8VHZs9rXm/ByaIC3hgQ5gzA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16909847832421013.2331023000843; Wed, 2 Aug 2023 06:59:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRCMA-0006PL-OG; Wed, 02 Aug 2023 09:57:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRCM8-0006NC-2E for qemu-devel@nongnu.org; Wed, 02 Aug 2023 09:57:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRCM5-00074H-Sq for qemu-devel@nongnu.org; Wed, 02 Aug 2023 09:57:39 -0400 Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-347-a5ypojoANz-G3JWvS1FnHg-1; Wed, 02 Aug 2023 09:57:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C38723815F6E; Wed, 2 Aug 2023 13:57:33 +0000 (UTC) Received: from thuth.com (unknown [10.39.195.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 627392166B25; Wed, 2 Aug 2023 13:57:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690984657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LSZvMs2xZuGZiAo08FeJlJQteWbBSt4IoZPkpkn9hIM=; b=NDjP/sEPKIYynTHUEJl+z9CUU0g3G57CfCDSwVlRUVMUBoMRSMwDv+5UkU6cyPAJFdjHKH bN+hb6KpnRb4nLWvITLbFM5szX7Ji4Qw1JSyAKa+tQqqtP1PVoBFhqGU34N+EacRxxfJRP owd4jOU06fhx7FFMnGNVwqaiQ0JnqSo= X-MC-Unique: a5ypojoANz-G3JWvS1FnHg-1 From: Thomas Huth To: "Michael S. Tsirkin" , Peter Xu Cc: Jason Wang , Richard Henderson , qemu-devel@nongnu.org, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , qemu-stable@nongnu.org, Paolo Bonzini Subject: [PATCH 4/6] hw/i386/intel_iommu: Fix index calculation in vtd_interrupt_remap_msi() Date: Wed, 2 Aug 2023 15:57:21 +0200 Message-Id: <20230802135723.178083-5-thuth@redhat.com> In-Reply-To: <20230802135723.178083-1-thuth@redhat.com> References: <20230802135723.178083-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1690984785044100003 Content-Type: text/plain; charset="utf-8" The values in "addr" are populated locally in this function in host endian byte order, so we must not swap the index_l field here. Signed-off-by: Thomas Huth Reviewed-by: Peter Xu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/i386/intel_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 4028e32701..3ca71df369 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3459,7 +3459,7 @@ static int vtd_interrupt_remap_msi(IntelIOMMUState *i= ommu, goto out; } =20 - index =3D addr.addr.index_h << 15 | le16_to_cpu(addr.addr.index_l); + index =3D addr.addr.index_h << 15 | addr.addr.index_l; =20 #define VTD_IR_MSI_DATA_SUBHANDLE (0x0000ffff) #define VTD_IR_MSI_DATA_RESERVED (0xffff0000) --=20 2.39.3 From nobody Sun May 19 01:42:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1690984745; cv=none; d=zohomail.com; s=zohoarc; b=NbFKYDbrY21eRIMARgaywxWF7Q5yS7UjFCBT8kiviX3VZ79WrdZ/dL4ItHL4S2BmU04blqPZyK3miTFgM9HB+aObQlaKU5mSls7AC7vz8Kf8LQTixg2a38umfoUNZWvEP7CSeNGpXutCQEd7Iqc4SXmUEEMrPSVP6rpYKl4WoCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690984745; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y9pQWNjcU3bZo8x7eF8Sem28W5KjYgEpYf8vSBcek6A=; b=AgSt9LTnoXAaRjy0dkJu8z3idciTtBpXgP4myHwKYkBPxNn+HNjJhnaK7hWSoWA9008Pc2yAwqyWgYh/y53InWY8SZZKqkVHpgeO4SLg4xOKeDPBI8kK65ydnSaX/XkWk4F7C9yEFfkbo2Ed4Ie/HNbT5PF3ueFIeVLW0niPfjo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16909847457701019.6202591345484; Wed, 2 Aug 2023 06:59:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRCMD-0006QJ-AJ; Wed, 02 Aug 2023 09:57:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRCMB-0006PN-EZ for qemu-devel@nongnu.org; Wed, 02 Aug 2023 09:57:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRCMA-000756-6F for qemu-devel@nongnu.org; Wed, 02 Aug 2023 09:57:43 -0400 Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-689-bbS8jJkxPDKj_sigZYmIdw-1; Wed, 02 Aug 2023 09:57:36 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 74DF11C3408F; Wed, 2 Aug 2023 13:57:35 +0000 (UTC) Received: from thuth.com (unknown [10.39.195.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11EBE2166B25; Wed, 2 Aug 2023 13:57:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690984661; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y9pQWNjcU3bZo8x7eF8Sem28W5KjYgEpYf8vSBcek6A=; b=XPBzSL5k1hfx5EcDcjdwWUBsWgjkE3V+Qvqe0/vPR6jZ2blpjq0pRxKL4yY5uJexIcW4Rp RU3O5pghBKArDIpkB/P+0Ks8lDbPaXyzkcI9qIAx7hxHftrs/SS+PDRnuU8jXmqKxva+Dc PTJrY9fCL0ZqGwyZqGTcJtRo4o+9Icc= X-MC-Unique: bbS8jJkxPDKj_sigZYmIdw-1 From: Thomas Huth To: "Michael S. Tsirkin" , Peter Xu Cc: Jason Wang , Richard Henderson , qemu-devel@nongnu.org, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , qemu-stable@nongnu.org, Paolo Bonzini Subject: [PATCH 5/6] hw/i386/x86-iommu: Fix endianness issue in x86_iommu_irq_to_msi_message() Date: Wed, 2 Aug 2023 15:57:22 +0200 Message-Id: <20230802135723.178083-6-thuth@redhat.com> In-Reply-To: <20230802135723.178083-1-thuth@redhat.com> References: <20230802135723.178083-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1690984747120100007 Content-Type: text/plain; charset="utf-8" The values in "msg" are assembled in host endian byte order (the other field are also not swapped), so we must not swap the __addr_head here. Signed-off-by: Thomas Huth Reviewed-by: Peter Xu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/i386/x86-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i386/x86-iommu.c b/hw/i386/x86-iommu.c index 01d11325a6..726e9e1d16 100644 --- a/hw/i386/x86-iommu.c +++ b/hw/i386/x86-iommu.c @@ -63,7 +63,7 @@ void x86_iommu_irq_to_msi_message(X86IOMMUIrq *irq, MSIMe= ssage *msg_out) msg.redir_hint =3D irq->redir_hint; msg.dest =3D irq->dest; msg.__addr_hi =3D irq->dest & 0xffffff00; - msg.__addr_head =3D cpu_to_le32(0xfee); + msg.__addr_head =3D 0xfee; /* Keep this from original MSI address bits */ msg.__not_used =3D irq->msi_addr_last_bits; =20 --=20 2.39.3 From nobody Sun May 19 01:42:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1690984752; cv=none; d=zohomail.com; s=zohoarc; b=cZuuP+uUZt06HbIN9Cj0dS3/TR0oHacO9+ILGosG5bVEjg9IJxxfrcYQN11kAX0mQ2BrWfcU9Uk2xiKprCDPEPuUakFnvhe6n9y99TfHxytRKUGUk7/ZEl3Zv2QXoWKikbxqwGAvQZjr3AXoYrM7NcV8KpqhgUmI8zua1HnS9Ek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690984752; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y58QJ+HM5AUg9VJaPlDysLRwUH90Md2RzqdmDtVUpOY=; b=bYBKn3L7rDocVRIpEBTZh0j6tvJfZt23gAAKwh7PemSQWoHziM6e64Yk0m3b5LWRyQcQaiXZaklAKUC1OnYKuQp+1x73FHFz2HLQWzcSK2ky7Re4sQZ8/zstulMh445RSXnidHTGkgAU+rYMd52pZK98StygF3OS8ISlnJRD0IM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690984752733794.3264107071832; Wed, 2 Aug 2023 06:59:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRCMQ-0006Rr-PU; Wed, 02 Aug 2023 09:57:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRCMO-0006Rf-ER for qemu-devel@nongnu.org; Wed, 02 Aug 2023 09:57:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRCM9-00074x-E7 for qemu-devel@nongnu.org; Wed, 02 Aug 2023 09:57:55 -0400 Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-121-oDdnLQx_Mn-jzFhcnFZx3Q-1; Wed, 02 Aug 2023 09:57:37 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2092D29AA3B7; Wed, 2 Aug 2023 13:57:37 +0000 (UTC) Received: from thuth.com (unknown [10.39.195.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA2CC2166B25; Wed, 2 Aug 2023 13:57:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690984660; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y58QJ+HM5AUg9VJaPlDysLRwUH90Md2RzqdmDtVUpOY=; b=NNLV+JrJ5cYgQicOBb5+5Z+i4ih0AYKmLbR0bOc+s9kx0s7CJh6ZbN696X+x7dghGtGvAz aKZLs2pER1qhuEJ1yKWFU8+l1Hovy5x7g1rbhxfTQlFlWzbWET7Ng5hSfqPpsszzkjWzdt e+qmnxfSZjpEqhW1o9KNowLKiBYG5Ig= X-MC-Unique: oDdnLQx_Mn-jzFhcnFZx3Q-1 From: Thomas Huth To: "Michael S. Tsirkin" , Peter Xu Cc: Jason Wang , Richard Henderson , qemu-devel@nongnu.org, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , qemu-stable@nongnu.org, Paolo Bonzini Subject: [PATCH 6/6] include/hw/i386/x86-iommu: Fix struct X86IOMMU_MSIMessage for big endian hosts Date: Wed, 2 Aug 2023 15:57:23 +0200 Message-Id: <20230802135723.178083-7-thuth@redhat.com> In-Reply-To: <20230802135723.178083-1-thuth@redhat.com> References: <20230802135723.178083-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1690984754480100003 Content-Type: text/plain; charset="utf-8" The first bitfield here is supposed to be used as a 64-bit equivalent to the "uint64_t msi_addr" in the union. To make this work correctly on big endian hosts, too, the __addr_hi field has to be part of the bitfield, and the the bitfield members must be declared with "uint64_t" instead of "uint32_t" - otherwise the values are placed in the wrong bytes on big endian hosts. Same applies to the 32-bit "msi_data" field: __resved1 must be part of the bitfield, and the members must be declared with "uint32_t" instead of "uint16_t". Signed-off-by: Thomas Huth Reviewed-by: Peter Xu --- include/hw/i386/x86-iommu.h | 50 +++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/include/hw/i386/x86-iommu.h b/include/hw/i386/x86-iommu.h index 8d8d53b18b..bfd21649d0 100644 --- a/include/hw/i386/x86-iommu.h +++ b/include/hw/i386/x86-iommu.h @@ -87,40 +87,42 @@ struct X86IOMMU_MSIMessage { union { struct { #if HOST_BIG_ENDIAN - uint32_t __addr_head:12; /* 0xfee */ - uint32_t dest:8; - uint32_t __reserved:8; - uint32_t redir_hint:1; - uint32_t dest_mode:1; - uint32_t __not_used:2; + uint64_t __addr_hi:32; + uint64_t __addr_head:12; /* 0xfee */ + uint64_t dest:8; + uint64_t __reserved:8; + uint64_t redir_hint:1; + uint64_t dest_mode:1; + uint64_t __not_used:2; #else - uint32_t __not_used:2; - uint32_t dest_mode:1; - uint32_t redir_hint:1; - uint32_t __reserved:8; - uint32_t dest:8; - uint32_t __addr_head:12; /* 0xfee */ + uint64_t __not_used:2; + uint64_t dest_mode:1; + uint64_t redir_hint:1; + uint64_t __reserved:8; + uint64_t dest:8; + uint64_t __addr_head:12; /* 0xfee */ + uint64_t __addr_hi:32; #endif - uint32_t __addr_hi; } QEMU_PACKED; uint64_t msi_addr; }; union { struct { #if HOST_BIG_ENDIAN - uint16_t trigger_mode:1; - uint16_t level:1; - uint16_t __resved:3; - uint16_t delivery_mode:3; - uint16_t vector:8; + uint32_t __resved1:16; + uint32_t trigger_mode:1; + uint32_t level:1; + uint32_t __resved:3; + uint32_t delivery_mode:3; + uint32_t vector:8; #else - uint16_t vector:8; - uint16_t delivery_mode:3; - uint16_t __resved:3; - uint16_t level:1; - uint16_t trigger_mode:1; + uint32_t vector:8; + uint32_t delivery_mode:3; + uint32_t __resved:3; + uint32_t level:1; + uint32_t trigger_mode:1; + uint32_t __resved1:16; #endif - uint16_t __resved1; } QEMU_PACKED; uint32_t msi_data; }; --=20 2.39.3