From nobody Sun Nov 24 15:54:56 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=1722508723; cv=none; d=zohomail.com; s=zohoarc; b=XozlHI9AcF47PigwKYlxHVIbucUa5MkMMMcFlywiQihGNL5+vN+2rgn3OLR4Mr+qFP18DvZoljEfAd/ALPnC/cT+aI62RWkgNhoUxHsO2hSHlpaieGhKSU2K5EDPW9e4uNNTu0EYf2HVsMtvVzsieHrudjDmr13yFkzKmipzcB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722508723; 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=DU7KGa++gwwIicNjWXeVcClxHOVzOhaCuJuqsj2Fe7w=; b=lZMMKD81iTfx0LIert8ZO3ohI7C9Qp1mQbrvY5qLhh5ErW2enrl4ODDgGNNkTsUP8tHvENpa2qrctxG07z+lUYQ6Zpfr7JpUxwUpiq86pOTCIQxks7GWNOG8ji1fHtaQQAyrCmRPWCbaRFqfx/+VzafRsr57x235jaTROoqNPGc= 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 1722508723306145.67125982808238; Thu, 1 Aug 2024 03:38:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZTBj-0004KP-MG; Thu, 01 Aug 2024 06:37:39 -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 1sZTBa-0003V7-V8 for qemu-devel@nongnu.org; Thu, 01 Aug 2024 06:37:33 -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 1sZTBX-0001rU-Rp for qemu-devel@nongnu.org; Thu, 01 Aug 2024 06:37:30 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-575-Rx_PeyNjP9qwG9AlXwhU_g-1; Thu, 01 Aug 2024 06:37:26 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a7aa5885be3so605015866b.0 for ; Thu, 01 Aug 2024 03:37:25 -0700 (PDT) Received: from redhat.com ([2.55.44.248]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acab231f2sm876174866b.7.2024.08.01.03.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 03:37:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722508647; 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=DU7KGa++gwwIicNjWXeVcClxHOVzOhaCuJuqsj2Fe7w=; b=KDz2JVjwlr+8bTymPzToQoNzqico5ub2PtdV7HnIg88erGmIcA8q8mUcDs41sCQU3wiFFn q5H0ArZR+GIebH+Rvu5jwFDa6n9MPTyKNYHcgbKqS88NxCIj+GIeVHKfknwUMwL7AUJnwt 81X0g59ftBIY2WDKQowrEUZOcd8UrbI= X-MC-Unique: Rx_PeyNjP9qwG9AlXwhU_g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722508644; x=1723113444; 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=DU7KGa++gwwIicNjWXeVcClxHOVzOhaCuJuqsj2Fe7w=; b=viQBc/hNRqvvAOxLxA+bXb6cvwW7N2qeFaQk5kAT1K6V46WXw88oD+WEnDMeEa8E0W TvnwqkasjmqjcXoqWACbBS0ktoz4H94/cSwodPKVzpN+Z7EDMB51RcrThPLEUVsqdiDU Qs3ICM10zHp17ujGPjANVLTZZxOunqUlpL7UCy68AIBRWrzLqV2ZElDfXuvMj2swocKV JqvtY3nq5XfqYrCANB6SrGHo4oBOgQiXKV8BF7oclyUyvD4/iijthbbZJ+FQDNOGW2em HMPGiQKUylPiEenoc6Dh98UrS6E9/Km11YUl2SPS8ABjQJp5DRf6cB3hqVEqRBHg4RYs 5Lwg== X-Gm-Message-State: AOJu0Yx7aj5PjVUlkWRioPAWps07Uv/F7cgywDb6avOLSYlEbBw+WnPF FikjSD0TJXm3aI+9hMM5nVpBBHcDVD4dj/LvIo3Hzuhfitkp77rsgfI+06NMn4hzTFJyjmdIFIg 2jbCT0IWl0eoSarlLMSCVcJ0eNQ+r6U0oJoHucBZ5FXcskoLrd/ctnVl8Qq8nNwb9jUivOwDRI1 81FhBIzZni2ICzyGw30p6fl6Ny4WQLXQ== X-Received: by 2002:a17:906:caea:b0:a7d:a25b:31be with SMTP id a640c23a62f3a-a7daf51ccd8mr155638266b.39.1722508644608; Thu, 01 Aug 2024 03:37:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHm9R6o8hktFQi7D+CHwbuIk0rKKqyF/OtdLHMoscFAYnHfDKTsnT2hEUwJ6C6nK5RVj8s2Cg== X-Received: by 2002:a17:906:caea:b0:a7d:a25b:31be with SMTP id a640c23a62f3a-a7daf51ccd8mr155634466b.39.1722508643923; Thu, 01 Aug 2024 03:37:23 -0700 (PDT) Date: Thu, 1 Aug 2024 06:37:18 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , yeeli , Jason Wang , Yi Liu , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PULL 19/19] intel_iommu: Fix for IQA reg read dropped DW field Message-ID: <515457757ff8540c524ff39ea1d9564b251c6532.1722508478.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.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.131, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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: 1722508723921116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: yeeli If VT-D hardware supports scalable mode, Linux will set the IQA DW field (bit11). In qemu, the vtd_mem_write and vtd_update_iq_dw set DW field well. However, vtd_mem_read the DW field wrong because "& VTD_IQA_QS" dropped the value of DW. Replace "&VTD_IQA_QS" with "& (VTD_IQA_QS | VTD_IQA_DW_MASK)" could save the DW field. Test patch as below: config the "x-scalable-mode" option: "-device intel-iommu,caching-mode=3Don,x-scalable-mode=3Don,aw-bits=3D48" After Linux OS boot, check the IQA_REG DW Field by usage 1 or 2: 1. IOMMU_DEBUGFS: Before fix: cat /sys/kernel/debug/iommu/intel/iommu_regset |grep IQA IQA 0x90 0x00000001001da001 After fix: cat /sys/kernel/debug/iommu/intel/iommu_regset |grep IQA IQA 0x90 0x00000001001da801 Check DW field(bit11) is 1. 2. devmem2 read the IQA_REG (offset 0x90): Before fix: devmem2 0xfed90090 /dev/mem opened. Memory mapped at address 0x7f72c795b000. Value at address 0xFED90090 (0x7f72c795b090): 0x1DA001 After fix: devmem2 0xfed90090 /dev/mem opened. Memory mapped at address 0x7fc95281c000. Value at address 0xFED90090 (0x7fc95281c090): 0x1DA801 Check DW field(bit11) is 1. Signed-off-by: yeeli Message-Id: <20240725031858.1529902-1-seven.yi.lee@gmail.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/intel_iommu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 9a768f0b44..16d2885fcc 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2947,7 +2947,9 @@ static uint64_t vtd_mem_read(void *opaque, hwaddr add= r, unsigned size) =20 /* Invalidation Queue Address Register, 64-bit */ case DMAR_IQA_REG: - val =3D s->iq | (vtd_get_quad(s, DMAR_IQA_REG) & VTD_IQA_QS); + val =3D s->iq | + (vtd_get_quad(s, DMAR_IQA_REG) & + (VTD_IQA_QS | VTD_IQA_DW_MASK)); if (size =3D=3D 4) { val =3D val & ((1ULL << 32) - 1); } --=20 MST