From nobody Thu Dec 18 13:34:35 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1733206099; cv=none; d=zohomail.com; s=zohoarc; b=IEL7DybF7InAo0kUfEOgRJspyAbnpfbRxttOt9jiiAXqpDmJge1Z8pmORotPpdIGsdM7Ayz3t163l17C+acIjmqL4t3KNIMFoccbe5Lv3Tk8cyV10sWMPitMbBtR81pZWakgEW3NJY1TrbsNxTyrT6dtoGGtOjig9AI+qgmi7yA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733206099; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=njl64GlmxR1Yi1La0DjJl6kmD+HNmU+XtFJgaFoqXe0=; b=YwckEkIWw3zG+v9V0lTpcPfiNz2LK6P92mJolCUma22LEBkBf7eH0n2bIY1seZuYZS8H2nuYtS+gF9ryhR6t3WvqjV/+Hi9GHuqjXAdm5JbEEkXffOx1SN07oGbi72mfRCVamzulrHlxstfd49HRaIwvThhvFGxqQBoRvKgUOpA= 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 1733206099112304.7051619215995; Mon, 2 Dec 2024 22:08:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIM4L-0005T7-Gx; Tue, 03 Dec 2024 01:07:33 -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 1tIM4G-0005SX-8L; Tue, 03 Dec 2024 01:07:28 -0500 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIM4E-0004yi-Oa; Tue, 03 Dec 2024 01:07:28 -0500 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-724e1b08fc7so4516548b3a.0; Mon, 02 Dec 2024 22:07:25 -0800 (PST) Received: from wheely.local0.net (124-171-72-210.tpgi.com.au. [124.171.72.210]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7254177d0b4sm9583601b3a.83.2024.12.02.22.07.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 22:07:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733206043; x=1733810843; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=njl64GlmxR1Yi1La0DjJl6kmD+HNmU+XtFJgaFoqXe0=; b=mHyj4dNmSEecQmw9gM2Z2kbtbe50XEGWoXt4dz8dLL9Wck08g8OPSh7/FWJ2C/G6ca ToOPVg5MOl/su9hZHPDesA1oqWYrAdk8Sm0Qy8cCXRAGjLQC9eaVAdG/0Sd1PhMSvl50 EdSLGCfC3Je/q0bk/HlVIWtVu6DQMvGBYnwYFrZYm6FctDeM6RNTPNP8wcKWActuQ1oo kQr1zcfzCr3CU276YWhjSurMA8lve1JBejO7D23+2BqeRAqP5R7U5AFB+vKU7dekKD8f PffpibgcKp8SDAKg0myq6oouAngS9q6LNo8TbS9+dALyGUm2P5Fw27sWdmHJDqsktp+W 7B5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733206043; x=1733810843; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=njl64GlmxR1Yi1La0DjJl6kmD+HNmU+XtFJgaFoqXe0=; b=LtlfLNtGQ3jZnX88GBrRL74kLq8dYDY7xbQdwnaikCc7EwoD9m4bMzZM03cqkLDptW yZ+etTDIX61grZxJ7IuK0PmgJdqKXDsYxnGC+aIbmzU/r8cQ5iN5jepcDUtw/UsdpzBF 4q+zSG5fbDTK7IJLqbfZQ/SLeyqaC5aJt97HN3/qHcreDqz8iVO8o8I8izTM+UG9LA4P J8zQbO/5r4caUmQXz1taGqT3s1jyYI8b2Hy6J+XBCBJ+4miKIqUJHpEyaNVHA+LANkXW a0yPhs9npK247caGphSfOmED6JCO8VoYdSJXvd7+rsSAqeY/x89hCFQHKI8mbtIUlX5N Zjrg== X-Forwarded-Encrypted: i=1; AJvYcCV4rGnLwqqvxVNvsZdxOzQVlkZ8LkZSDrW0BJ4znAUXGj1LYbcHr4dD6oObzeXWt2jgSLWul1pVvqFc@nongnu.org X-Gm-Message-State: AOJu0Yw5RdK93Hh47FgHzVoJkvChirQx99/K5osBCTeeBrwGYBFIMyVF kb+0iKAiX/QVSm+LJU2ncSU6ETZ3Q3FTmYNay2eTYiHrEMFVB2d7Grh9tg== X-Gm-Gg: ASbGncsbEOet4q+lmsyFCp89Uo0bdqwPgnLlZwpi3L4Qd5ary0q5Ivm283rCgcY8Fl4 Xmre0G2xyn1C5V2RtEIjhCQ4GB4PR9edvu+c+XD/2Yb5fuIfFITT3DhPYBSf3WGsaR526wLAoSd ecRBn8XVIvTjBy3RcF0Hd8Asq2zZ6mR33OqKNGfXNm5lH58l+18NYgJyy6TWjFaYrthhRs8W4nP p6Nb0aN0sI9cyjIA9uZ1jguOqvlmmegWLoM6vtcecGA4tWnkyyOTYCdc0OXpV6X7X1e8shVyQdG fld3Sw== X-Google-Smtp-Source: AGHT+IEjzO5OpWGvimE/X+2/cre/QIHejaaJnjc3EFdVFjaCu6GuiMrHLFN7m+SD2zJH8mhF9Aeh3g== X-Received: by 2002:a05:6a00:2e25:b0:71e:4196:ddb2 with SMTP id d2e1a72fcca58-7257fa63975mr1483767b3a.9.1733206043499; Mon, 02 Dec 2024 22:07:23 -0800 (PST) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , qemu-devel@nongnu.org, =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Barrat?= , Saif Abrar Subject: [PATCH] hw/pci-host/pnv_phb4: Fix LSI irq source calculation overrun Date: Tue, 3 Dec 2024 16:07:14 +1000 Message-ID: <20241203060715.1149886-1-npiggin@gmail.com> X-Mailer: git-send-email 2.45.2 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::433; envelope-from=npiggin@gmail.com; helo=mail-pf1-x433.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1733206100309116600 Content-Type: text/plain; charset="utf-8" PHB5 has big and small PHBs, that have 4k and 2k interrupt sources respective. The LSI interrupt sources are set with a 9-bit register field, that selects the aligned block of 8 irqs, giving a 4k range. This is initialized by hardware to 0x1ff in order to select the last 8 irq sources. The small PHB is meant to ignore the MSB of the source ID, so the LSI default would select the last 8 of 2k irqs. The PHB model does not mask this bit consistently, which can cause the irq to be miscalculated and the source irq array to be overrun. Move the lsi_base calculation into a helper function that does the masking and some extra checking. Signed-off-by: Nicholas Piggin --- hw/pci-host/pnv_phb4.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c index fb129f3266..5486ef44ea 100644 --- a/hw/pci-host/pnv_phb4.c +++ b/hw/pci-host/pnv_phb4.c @@ -458,6 +458,27 @@ static void pnv_phb4_update_all_msi_regions(PnvPHB4 *p= hb) } } =20 +static int pnv_phb4_get_lsi_base(PnvPHB4 *phb) +{ + int lsi_base, nr_irqs; + + lsi_base =3D GETFIELD(PHB_LSI_SRC_ID, phb->regs[PHB_LSI_SOURCE_ID >> 3= ]); + if (!phb->big_phb) { + /* Small PHBs ignore the top bit of the source ID */ + lsi_base &=3D ~0x100; + } + lsi_base <<=3D 3; + + if (phb->big_phb) { + nr_irqs =3D PNV_PHB4_MAX_INTs; + } else { + nr_irqs =3D PNV_PHB4_MAX_INTs >> 1; + } + g_assert(lsi_base + 8 <=3D nr_irqs); + + return lsi_base; +} + static void pnv_phb4_update_xsrc(PnvPHB4 *phb) { int shift, flags, i, lsi_base; @@ -487,9 +508,7 @@ static void pnv_phb4_update_xsrc(PnvPHB4 *phb) phb->xsrc.esb_shift =3D shift; phb->xsrc.esb_flags =3D flags; =20 - lsi_base =3D GETFIELD(PHB_LSI_SRC_ID, phb->regs[PHB_LSI_SOURCE_ID >> 3= ]); - lsi_base <<=3D 3; - lsi_base &=3D (xsrc->nr_irqs - 1); + lsi_base =3D pnv_phb4_get_lsi_base(phb); =20 /* TODO: need a xive_source_irq_reset_lsi() */ bitmap_zero(xsrc->lsi_map, xsrc->nr_irqs); @@ -1597,8 +1616,7 @@ static void pnv_phb4_set_irq(void *opaque, int irq_nu= m, int level) if (irq_num > 3) { phb_error(phb, "IRQ %x is not an LSI", irq_num); } - lsi_base =3D GETFIELD(PHB_LSI_SRC_ID, phb->regs[PHB_LSI_SOURCE_ID >> 3= ]); - lsi_base <<=3D 3; + lsi_base =3D pnv_phb4_get_lsi_base(phb); qemu_set_irq(phb->qirqs[lsi_base + irq_num], level); } =20 --=20 2.45.2