From nobody Wed Mar 5 18:26:39 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=reject dis=none) header.from=sifive.com ARC-Seal: i=1; a=rsa-sha256; t=1740906820; cv=none; d=zohomail.com; s=zohoarc; b=MQGa8aucNLeECGg6d5L8ODTfHCvz9kL1fVdQBO6REF/ZS8c1MlPARho3ADDLTiEzhUMeKQG1zHkpPzHs2nuHwmdjbMSkAifOF16NQruZ0ENDbOuO5LKEb9qSrJ+wVXGegVIihAT7LfFvnvukt3QKnpgKQfsKiXAFvEwLs+j2U2A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1740906820; h=Content-Transfer-Encoding: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=6wEnkpxsHEbI0fxfUeUBSWHfWq/aVMmkApj4LVSqQuY=; b=aNcml+0BUC6ZfusdTkB2GrimeEafvBVHX0/cvsAziateVwMUZVnvtNUcX3wcsEItoRMxHLPWHNOOue3HUtYFdZoZxcg6vKiPFu6BlayQorekmkhNdAp5WVaWL5vxho1vWyU03yUiF9Hzd8kmbN3/uwjA97s1yR3haWtgSQgxwq8= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1740906820000346.3891829664061; Sun, 2 Mar 2025 01:13:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tofNC-0001Df-Ab; Sun, 02 Mar 2025 04:12:34 -0500 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 1tofN6-0001CI-MW for qemu-devel@nongnu.org; Sun, 02 Mar 2025 04:12:28 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tofN5-0003JU-68 for qemu-devel@nongnu.org; Sun, 02 Mar 2025 04:12:28 -0500 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-223a3c035c9so3241945ad.1 for ; Sun, 02 Mar 2025 01:12:26 -0800 (PST) Received: from hsinchu16.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-736310abc8csm2952616b3a.77.2025.03.02.01.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Mar 2025 01:12:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1740906744; x=1741511544; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6wEnkpxsHEbI0fxfUeUBSWHfWq/aVMmkApj4LVSqQuY=; b=Nb+z6ck1x5c3SgukdRZjtpfDOzWLTEGh8n5aG25xd0o/HWrDSnlsVNrGBx4kERYxHR rfp0XGOIsG0grJbTmsVMk3ivmDVXgvEDMMJ6u6qXbNbyFH3K36EyiOTlQ6p+1gurt9o/ uoYeuzyuXjS7RPrMpMMNK54v5gG3TkqRqf0Bvc/tjBbZjhZYOmwPuTTLArKLnUpvRjkm xapU+c9G10ShJDHNyTAekNWNuJ3QhqYOjod1+BbRsNs3+jFiXVLmXQzkn+ZN3295x+8z SuWaAR9i1QMcLea1KO+u15IOa1kkArkTC2uEkN10kxOxA4JfixAoGJ2DLIKPbneNWB8s NDNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740906744; x=1741511544; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6wEnkpxsHEbI0fxfUeUBSWHfWq/aVMmkApj4LVSqQuY=; b=Wu8J6juBIVju9rU4jCj4uZ3qmnkIlUss3ctg8k0rIBPBBAZeGHhnhlQ9LswI+ECISC Nlqg0jFJty7hyxNDXcnHIKBYh5QFemYXNEkg+rY+Dw2mVayozvcnEfSkhN3zvFcS8h2C E7rEoVh3wrW3J0e3AIeqolpAXZTNxLm+H5UuGwwPz9qj5KBOD6JrBVlAeCzv68lEijJP nPtspmZg0GUzhsYwHrOzK7qdvgHeQuQg6Uk7v/9qCfBE0x09zhRbVWXlCVLnx97Bf59+ shwtarlEUz3FF/iBZajY2zA/DWrc8c89tj+RbZrFi5Nyq09OP7/tB5STcBZeaAcysnec Hh0w== X-Gm-Message-State: AOJu0Yxn1WL0uSVqaHl5vfhhsO8YA2nGiLCGgwVrixSBr1IVa4Ev2DDE Hbej2Q2zDw3/8TRLc7zj76u3nw6xoKUxGMuozDdJwZ7xklPnU9FNpLeeBB7sUnkEZ21D+jM82SJ NwhjBBczhfMJxAIVm93ZEw4EEXIKktVFi0Mn1/7b+f8f9VQR4fCqRGunskyWPTr9roJH3AGAmYN qGD8WCnRwx6E0iEv1uRt61S/VL9b6FJ+Wo8/6ydmw= X-Gm-Gg: ASbGncuRfcIxeXL1v2SW5EJ1AxziplwOihYN4BVT1AVRiX6+1hdgFAphvwZ9dUEJ+lq z3MO/r2WTAR9HBeRy2jt4SWId0BeNSF93s1Oo+17W7+5HFImazaiCCw94yNM94oHM20EScEC+If QkRiMViYhy8UAmDUtho7SFoSUKx8XC5KDnkiUZyf/tmqPEHNa7BjqX0qjDxUZs/+lIdm2+5Bc0/ xb8TzT8PoNGOrTUlStws7EaElKYM/WXt9HtFpZffyrvAOyyUqtQlYnUisMKjMa08rHgk2X41JpR ufHx721N/BR4AF9niYaEAALuaGNAvLv4fGINqdtARkQAb3OffLyZPfYUTd50ZsqQsjhBzViw X-Google-Smtp-Source: AGHT+IGu9d8sMF19BXEBKgHsCQ4kvaVpecX4e62+Ankya6235bqvZXneOq260SIi0aYPU9CFt4EO2w== X-Received: by 2002:a17:902:e947:b0:223:807f:7f92 with SMTP id d9443c01a7336-223807f8110mr83898835ad.20.1740906744360; Sun, 02 Mar 2025 01:12:24 -0800 (PST) From: Jason Chien To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , "Michael S. Tsirkin" , Marcel Apfelbaum , Jason Chien Subject: [PATCH 2/3] hw/riscv/riscv-iommu: Obtain Device IDs from Memory Attributes Date: Sun, 2 Mar 2025 17:12:08 +0800 Message-ID: <20250302091209.20063-3-jason.chien@sifive.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20250302091209.20063-1-jason.chien@sifive.com> References: <20250302091209.20063-1-jason.chien@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::636; envelope-from=jason.chien@sifive.com; helo=mail-pl1-x636.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @sifive.com) X-ZM-MESSAGEID: 1740906821710019000 Content-Type: text/plain; charset="utf-8" The bus number of a PCIe endpoint may change after PCIe re-enumeration, potentially causing the device ID stored in RISCVIOMMUSpace to become outdated. This can lead to an incorrect Device Directory Table walk. This commit ensures that the IOMMU dynamically retrieves the latest device IDs from the memory attributes of the requester devices, ensuring accuracy. Signed-off-by: Jason Chien --- hw/riscv/riscv-iommu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index d46beb2d64..b72ce8e6d0 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -2644,7 +2644,13 @@ void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *io= mmu, PCIBus *bus, static int riscv_iommu_memory_region_index(IOMMUMemoryRegion *iommu_mr, MemTxAttrs attrs) { - return attrs.unspecified ? RISCV_IOMMU_NOPROCID : (int)attrs.pid; + RISCVIOMMUSpace *as =3D container_of(iommu_mr, RISCVIOMMUSpace, iova_m= r); + + /* Requesters must attach its device ID. */ + g_assert(attrs.unspecified =3D=3D 0); + + as->devid =3D attrs.requester_id; + return attrs.pid; } =20 static int riscv_iommu_memory_region_index_len(IOMMUMemoryRegion *iommu_mr) --=20 2.43.2