From nobody Sun Dec 14 05:52:19 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752535626; cv=none; d=zohomail.com; s=zohoarc; b=IXhDVG6hua56lI++lIbtFJavFxr1Zs0Jz18RJHUFI1Vxv5uS7Gv+ch+iX1OVkeVvuYCu/hv/swpwCzTwnuFgTkHSl89lYck1RGSP2c5pwKNdI/+30VNGlhoqM1p6CEKciRm5WvlswOOEhkjvcmrWDTyYCKE2mwIx9OXNgpS/+TU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752535626; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MOHStGMxU1OhGbAb8/Tgd5Xkkc+adSNHryY5YcQQ/VU=; b=cbrIxAR/BfxnnsYUDxB58GiwNRFEcNCe41YQEWDAmkPD9jN6Ok6u0KJSOAp+jt9Qzj9sGIRhUpUM1+ICNVh6jDjHvLwYYY67ZvqkbRgZ53yr4pwnUoAKNB05MqYBXQ5Mr8wgjwqjc6zd37ZXqNWvsT6vjpCI4e3iKGV/n6291hg= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752535626939205.364931310389; Mon, 14 Jul 2025 16:27:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubSI2-0001fQ-1m; Mon, 14 Jul 2025 19:08:54 -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 1ubSH3-000613-Me for qemu-devel@nongnu.org; Mon, 14 Jul 2025 19:08:04 -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 1ubSH1-0005bm-01 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 19:07:52 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-78-5EUp6dpaP_uKbUOBNXcSFQ-1; Mon, 14 Jul 2025 19:07:49 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-45359bfe631so29217785e9.0 for ; Mon, 14 Jul 2025 16:07:49 -0700 (PDT) Received: from redhat.com ([2a0d:6fc0:150d:fc00:de3:4725:47c6:6809]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b5e8dc217esm13158702f8f.28.2025.07.14.16.07.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 16:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752534470; 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: in-reply-to:in-reply-to:references:references; bh=MOHStGMxU1OhGbAb8/Tgd5Xkkc+adSNHryY5YcQQ/VU=; b=MBmIE1HLqHUdBlRqQeODXgvrYiXFc6+32uT2xfwJ8Ds2G9rLatMLSwt3ghJNTECTpn0/Is q892U/sYBnMQp+XbnIDYO3OggROpgVtMluhdjLauynWOVLkMwcXJflpWaUHfQTuFHZ9f9c ZGdxkk1PjOKLYaBJFvSNNfx6LIBICPs= X-MC-Unique: 5EUp6dpaP_uKbUOBNXcSFQ-1 X-Mimecast-MFC-AGG-ID: 5EUp6dpaP_uKbUOBNXcSFQ_1752534468 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752534468; x=1753139268; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=MOHStGMxU1OhGbAb8/Tgd5Xkkc+adSNHryY5YcQQ/VU=; b=BovObFTY8knJcX1F7fnfw5OJMROz9ulnXufh2gTKqrm3SkFaYkqj55+k/vk7U5QaF/ uXtsHowowCZ+17wASIXPWTjh69BsVzTnGdYvLyfLgpunPPMsAH2XCPfEK7Xa7qf13d8D 52sp4L9EFFRGh88Unm3bQNYMuGVLJsb9efEzCOWQgKrNcBRCDpMwH/6S1/0b3MwnnqMT dqeYJiGigvwHZH9c13w4GBxYA5Qp1KlIdG/9mYIlJI5nT01x4w+Myoz6YxHM+f6HNmR/ Q+RyWRIbE834aN4D5jU4ZeSUfqQB5UncPchUMAQwr+me7+v4MhZk2JNLUqQuUxOB//m0 tZow== X-Gm-Message-State: AOJu0YzF3PanBi9ePSMIoMEr1S9frZztcZ5CeowshFxSJdpieYIihcSR LESYe4T7MI/25qCS/A1DnaQR1FwOFP9jv6gokUdW6kAH0z6rhHnOB6JzlZk9tuDt7RBsKnUvgTZ 5+KGgFuuoxmyTvdCh8jdaighKeL/wxTvxd4N9DW3JL7P9CF7+CEn9XjPGiys9wgjVX1A7NNDMcJ o88xcGyVt4zXAEEFrb9BXU7JGO5N/giWZE+w== X-Gm-Gg: ASbGncuV5nEK2UHVbPjd/1ScBD9mUdfagztsFPIPVH0KVj3hm7ouQjHKh4DlAzmOsZy 5hopoZfdpueYerhSItg+6278VvWpn4Y0gMi0dliLYQ/vM/VVOnxFvgtvlZlj496lm9X/YhcBE6w pXTdWKhjFbh5XokV08saotct9LKP9TqmthD1+QSVQ6oEMhkNBAb2aOs19pVKyQ/DsyY2OsVBW2e lgK3bikvOyJKrd7h5GEu0bdumajph+GgK6t29RycJQX39X2lB3ZUc6SID6++K9zd3oMaMYi0KGI cZJvMgHdrb20GRXNGxPQGnlFTCs6Qt3Y X-Received: by 2002:a05:600c:4693:b0:456:496:2100 with SMTP id 5b1f17b1804b1-456049621efmr97626945e9.31.1752534467737; Mon, 14 Jul 2025 16:07:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXnSYpUdGR5XXR0qOkhLIh7FZghoxo7vTTlQfUrbgtPTAIFdT+2ahq+4TlkVGoIhKgfWI/tA== X-Received: by 2002:a05:600c:4693:b0:456:496:2100 with SMTP id 5b1f17b1804b1-456049621efmr97626725e9.31.1752534467324; Mon, 14 Jul 2025 16:07:47 -0700 (PDT) Date: Mon, 14 Jul 2025 19:07:44 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , CLEMENT MATHIEU--DRIF , Jason Wang , Yi Liu , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PULL 36/97] intel_iommu: Return page walk level even when the translation fails Message-ID: <4ecafbaec7c52c4d4ce88315766b9ad0be063a7c.1752534227.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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=mst@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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: 1752535628400116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: CLEMENT MATHIEU--DRIF We will use this information in vtd_do_iommu_translate to populate the IOMMUTLBEntry and indicate the correct page mask. This prevents ATS devices from sending many useless translation requests when a megapage or gigapage is not present. Signed-off-by: Clement Mathieu--Drif Message-Id: <20250628180226.133285-9-clement.mathieu--drif@eviden.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/intel_iommu.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 234c452849..bff307b9bc 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1987,9 +1987,9 @@ static int vtd_iova_to_flpte(IntelIOMMUState *s, VTDC= ontextEntry *ce, uint32_t pasid) { dma_addr_t addr =3D vtd_get_iova_pgtbl_base(s, ce, pasid); - uint32_t level =3D vtd_get_iova_level(s, ce, pasid); uint32_t offset; uint64_t flpte, flag_ad =3D VTD_FL_A; + *flpte_level =3D vtd_get_iova_level(s, ce, pasid); =20 if (!vtd_iova_fl_check_canonical(s, iova, ce, pasid)) { error_report_once("%s: detected non canonical IOVA (iova=3D0x%" PR= Ix64 "," @@ -1998,11 +1998,11 @@ static int vtd_iova_to_flpte(IntelIOMMUState *s, VT= DContextEntry *ce, } =20 while (true) { - offset =3D vtd_iova_level_offset(iova, level); + offset =3D vtd_iova_level_offset(iova, *flpte_level); flpte =3D vtd_get_pte(addr, offset); =20 if (flpte =3D=3D (uint64_t)-1) { - if (level =3D=3D vtd_get_iova_level(s, ce, pasid)) { + if (*flpte_level =3D=3D vtd_get_iova_level(s, ce, pasid)) { /* Invalid programming of pasid-entry */ return -VTD_FR_PASID_ENTRY_FSPTPTR_INV; } else { @@ -2028,15 +2028,15 @@ static int vtd_iova_to_flpte(IntelIOMMUState *s, VT= DContextEntry *ce, if (is_write && !(flpte & VTD_FL_RW)) { return -VTD_FR_SM_WRITE; } - if (vtd_flpte_nonzero_rsvd(flpte, level)) { + if (vtd_flpte_nonzero_rsvd(flpte, *flpte_level)) { error_report_once("%s: detected flpte reserved non-zero " "iova=3D0x%" PRIx64 ", level=3D0x%" PRIx32 "flpte=3D0x%" PRIx64 ", pasid=3D0x%" PRIX32 = ")", - __func__, iova, level, flpte, pasid); + __func__, iova, *flpte_level, flpte, pasid); return -VTD_FR_FS_PAGING_ENTRY_RSVD; } =20 - if (vtd_is_last_pte(flpte, level) && is_write) { + if (vtd_is_last_pte(flpte, *flpte_level) && is_write) { flag_ad |=3D VTD_FL_D; } =20 @@ -2044,14 +2044,13 @@ static int vtd_iova_to_flpte(IntelIOMMUState *s, VT= DContextEntry *ce, return -VTD_FR_FS_BIT_UPDATE_FAILED; } =20 - if (vtd_is_last_pte(flpte, level)) { + if (vtd_is_last_pte(flpte, *flpte_level)) { *flptep =3D flpte; - *flpte_level =3D level; return 0; } =20 addr =3D vtd_get_pte_addr(flpte, aw_bits); - level--; + (*flpte_level)--; } } =20 --=20 MST