From patchwork Mon Mar 17 05:23:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 14018652 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5E84CC35FF3 for ; Mon, 17 Mar 2025 05:24:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tu2xJ-0006fc-Am; Mon, 17 Mar 2025 01:24:05 -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 1tu2x8-0006dV-Tx; Mon, 17 Mar 2025 01:23:56 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tu2x7-0007nF-FS; Mon, 17 Mar 2025 01:23:54 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2235189adaeso65380475ad.0; Sun, 16 Mar 2025 22:23:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742189031; x=1742793831; 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=Q1MB5EMdjVFVxNgGF88Q0t4+APTkh4DaVr1Cd/A8YJY=; b=cfIHsIt9DpVP2iRKCK0Dcuc+KDA3OYstLGlSbfi9ZkrHIjcSAje5wMqwlSeYpq5vDL B5h//H1WgjFFCKKVOzHxEZtHlxzJJsGRzsMsdyczYGkP9rPPDzBscBtJVrLTCgTALk3f j9j22xeUvmk0euNFZ/YzBp0mZhrvu9ZOLoDW4BBuwvtGNhHrF2uAYg0G5UeHmzzfcSZZ cW+eTlJx42hEai6dZVTexFMJ31BlAX6hUsY8ctKdVN3lKQAPgDHsJMJzhvjojdpZiWKc VrkRCc4cwyYI2HPwUnjdvW3AqcJ94v6IdpFQSuPYoEzcWtL/xbGPfQbDuz9YCCqYJ64f AkRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742189031; x=1742793831; 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=Q1MB5EMdjVFVxNgGF88Q0t4+APTkh4DaVr1Cd/A8YJY=; b=sgp5csP15CJ+Y0uPGcO5opvksY5RnD5PyLj0UZVRpIJNB4GhZRK0ko4fHsjNXwVBHW ezt2LMjMA/H7vL/iSj3jTa66tHBJgV4KsEQZretg6QhHVh+dAR9cDu5nxpnOXNqULYFg 8KmvTCGf6th+2JQnEa1BNeGrObd10wN0aubJBW/JQ3G8uEpvrNWVwmr1h2OeX/lU8Nsd H7S6hzABM8N9wicKzvPFspZRqVSqZV3cBLaVxJzDz5nTzzkr62kq1tqQHAsJf+jyXOPm 7ymX4mUQ+3NKrnRsYg+2UxJ4UL250swZvFoEqbwaJyKZ8pZAPU/BORF1K31AyGgC13pN BAOA== X-Forwarded-Encrypted: i=1; AJvYcCX3myxs9w8Qtfy6sk5SKkv19LHzd8GVArQNgVpzeYFiIjLkPhIl2qExbj1fhzSxd1vIdjS/PxCn+Q==@nongnu.org X-Gm-Message-State: AOJu0YwApI8wJ3+i9xadS7hcREj/1MLWWJDthuEuO/mNEEGmlm4GJsGB l2ULEejQmOj5SabBnAdqQ5UQBAN06BrclsRUpkYBQkVsP+pRAPCk/XiQUw== X-Gm-Gg: ASbGnctw+DdzeC3Kp5AgZlDXg/8364UabirBqz0y6kJWBWAnr7uDUirEwptz9+FSTHL LAvp8tz71OIyzvIWIVisN6rYApAErzEevSf5idbt/gn/jOz495ZvwL+UVhtnBCRqtbddvBxirk+ r83ERIqgT0TMetqvXYfVrsa1bUx6ks9BLbodlwnMo7snGFLAfC3kFIuvOK3D7kOWw3Xq1T98aBE ts5tQ2qC2egWGbb5Wp+MfuKLnJ12RRgjcywvFAGdiwBYTCYMOvXoChuU1SfEe6dw9ul1h646rdc 1c8WJevjNGpYw1VKzUjz8jcV1QLTKIVIMyXVKEK8yoQctzICLQ== X-Google-Smtp-Source: AGHT+IG4wYuVxZVKituNR6Ctui3omdzLfCBiSov8cpksGDEFvtQJUxY67UE795CY4SHBvLn5bM1FRQ== X-Received: by 2002:a17:902:f681:b0:21f:6f33:f96 with SMTP id d9443c01a7336-225c651f518mr179898465ad.6.1742189031357; Sun, 16 Mar 2025 22:23:51 -0700 (PDT) Received: from wheely.local0.net ([118.208.135.36]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73711695b6bsm6879495b3a.148.2025.03.16.22.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Mar 2025 22:23:51 -0700 (PDT) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , qemu-ppc@nongnu.org, Glenn Miles , Michael Kowal , Harsh Prateek Bora Subject: [PATCH 1/6] ppc/xive: Fix typo in crowd block level calculation Date: Mon, 17 Mar 2025 15:23:33 +1000 Message-ID: <20250317052339.1108322-2-npiggin@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250317052339.1108322-1-npiggin@gmail.com> References: <20250317052339.1108322-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=npiggin@gmail.com; helo=mail-pl1-x634.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org I introduced this bug when "tidying" the original patch, not Frederic. Paper bag for me. Fixes: 9cb7f6ebed60 ("ppc/xive2: Support group-matching when looking for target") Signed-off-by: Nicholas Piggin --- hw/intc/xive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/intc/xive.c b/hw/intc/xive.c index c77df2c1f8c..e86f2749328 100644 --- a/hw/intc/xive.c +++ b/hw/intc/xive.c @@ -1686,7 +1686,7 @@ static uint8_t xive_get_group_level(bool crowd, bool ignore, * Supported crowd sizes are 2^1, 2^2, and 2^4. 2^3 is not supported. * HW will encode level 4 as the value 3. See xive2_pgofnext(). */ - switch (level) { + switch (blk) { case 1: case 2: break; From patchwork Mon Mar 17 05:23:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 14018655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4CAFBC35FF3 for ; Mon, 17 Mar 2025 05:25:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tu2xE-0006eX-4t; Mon, 17 Mar 2025 01:24:00 -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 1tu2xC-0006eK-M0; Mon, 17 Mar 2025 01:23:58 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tu2xB-0007nW-2d; Mon, 17 Mar 2025 01:23:58 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-223594b3c6dso76633905ad.2; Sun, 16 Mar 2025 22:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742189035; x=1742793835; 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=gKory0aORXHwx2AW1UJ2qnqZAC9gkLCaJS83bjYZRC0=; b=GLZDdHe0eCEQrQ2rknTkySm2w0P5nXbxwp9uxHo374Iw7yc8bCMo9p2hJkNJZW6QYy Yph/twuhWRrEOk9An0e9A8dEZ3EuphBiMU/kjizf7pwVqtBhcxGe63C7f1LegpLJ8Dbf 8RLxE5XXFjz62IcrmpNNjGkkOMwTeS6dJ9lTzMm/TitHg1Hs3XOgFCpAFAYqiSQYpeCG oVqCPb1oLdKLG6/FpjxpX0hNAylQ1Q/7RiPmuLmBtGQRNn0yDYQv0Jilp6lkYtAfJ0t3 lWXo7Fow3QD4fyDhvLG8mpojfDUnwXihN/myfdxbN4iPdZRfXtv0DBsh9CurpeWrIHOU pzsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742189035; x=1742793835; 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=gKory0aORXHwx2AW1UJ2qnqZAC9gkLCaJS83bjYZRC0=; b=YMRp5N0KzLHIbzKZJ3IeC5GuxtbELB6XMx/suODE/mNmzMd5pvxJWTXlWIKay9wKmh 70xsaHMbv6oKIHx9+gJzp8ry2I0M6rUqwyjxQ2zazsr8utixaPbAsilN00Spn7OtHHhw Sv2P5nKgbicD2At/IMnwr/V7fU9kh2t98eBANtiaKFAIcdRXBYoosmfPDgvYc7OEbh9K A3izPvI/7XGTesbpTXgpgIiBtT7nzoSWeVp0Su8lLm/1Uc59LgAaN7jMkeCa0rRKu7Cq cK9CypFa3E0vlblip5dPz4k6EtCw9j4cM1XeiDyOhaYkrFFXWUxDRCKChARGlv/Hti80 7DKg== X-Forwarded-Encrypted: i=1; AJvYcCX2MzYBY3P397Gyd+iYVy6mY/TAb3tVmTAMFmon6fkJTILnbYAycNBea0YXOhDCtgwKpu6pMUeBNw==@nongnu.org X-Gm-Message-State: AOJu0Yyz/hlTo8k4f5sIpRp8T0hGYa+CZtEHZVSqgxEkIQFoqElbj92X AarIpozpOdpnB4GH6uZCEtwR9EmrkIl1hjeMXmGinBQ1jgX09xNG5VzWQQ== X-Gm-Gg: ASbGncu44QLtjJQnvkZY7pCVPHbTBu6qU/rgFFqDwZF/HxLiCFojzXuqcppK9gwO1UK vqplGUw5Ogm3CjWvZ1v18OkvbAs+CACB8Y3AstPYZ3IkSN5+Yx+PFQxx4OAP1ovn5vVpQcKmLZw aciMVJayTdRdBxNU1f3LloRLrMnBxbTQ9RpXTNQVN/6OrmmdRtsE3bzVM4mX/7fLFlPUvV9afKE jUQVhg4YBA/ujaCvCkiS1qITtGShq6TQoXqGk/BRIMx0ZDls4BFYKQhK3oeeynW2lLOrfq3c1dU yKqbUb2mT4LmzOcBjf2VMnzheflPhLGGZtrvYSkK3BuGgdh3pA== X-Google-Smtp-Source: AGHT+IFop+lMLtmUwqVSFMRq8l5cGwGRY2WDfGXMe7wtrRaCCwffHD4+Sad+KDzkiBxQ9m+AvrZvkQ== X-Received: by 2002:a05:6a00:808:b0:730:9502:d564 with SMTP id d2e1a72fcca58-7372238490dmr14020131b3a.14.1742189034947; Sun, 16 Mar 2025 22:23:54 -0700 (PDT) Received: from wheely.local0.net ([118.208.135.36]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73711695b6bsm6879495b3a.148.2025.03.16.22.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Mar 2025 22:23:54 -0700 (PDT) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , qemu-ppc@nongnu.org, Glenn Miles , Michael Kowal , Harsh Prateek Bora , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 2/6] pnv/xive: Fix possible undefined shift error in group size calculation Date: Mon, 17 Mar 2025 15:23:34 +1000 Message-ID: <20250317052339.1108322-3-npiggin@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250317052339.1108322-1-npiggin@gmail.com> References: <20250317052339.1108322-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=npiggin@gmail.com; helo=mail-pl1-x62b.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Coverity discovered a potential shift overflow in group size calculation in the case of a guest error. Add checks and logs to ensure a issues are caught. Make the group and crowd error checking code more similar to one another while here. Resolves: Coverity CID 1593724 Fixes: 9cb7f6ebed60 ("ppc/xive2: Support group-matching when looking for target") Cc: Cédric Le Goater Signed-off-by: Nicholas Piggin Reviewed-by: Cédric Le Goater --- hw/intc/xive.c | 27 ++++++++++++++++++++++++--- hw/intc/xive2.c | 19 ++++++++++++++----- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/hw/intc/xive.c b/hw/intc/xive.c index e86f2749328..3eb28c2265d 100644 --- a/hw/intc/xive.c +++ b/hw/intc/xive.c @@ -1662,12 +1662,20 @@ uint32_t xive_get_vpgroup_size(uint32_t nvp_index) * (starting with the least significant bits) in the NVP index * gives the size of the group. */ - return 1 << (ctz32(~nvp_index) + 1); + int first_zero = cto32(nvp_index); + if (first_zero >= 31) { + qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid group index 0x%08x", + nvp_index); + return 0; + } + + return 1U << (first_zero + 1); } static uint8_t xive_get_group_level(bool crowd, bool ignore, uint32_t nvp_blk, uint32_t nvp_index) { + int first_zero; uint8_t level; if (!ignore) { @@ -1675,12 +1683,25 @@ static uint8_t xive_get_group_level(bool crowd, bool ignore, return 0; } - level = (ctz32(~nvp_index) + 1) & 0b1111; + first_zero = cto32(nvp_index); + if (first_zero >= 31) { + qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid group index 0x%08x", + nvp_index); + return 0; + } + + level = (first_zero + 1) & 0b1111; if (crowd) { uint32_t blk; /* crowd level is bit position of first 0 from the right in nvp_blk */ - blk = ctz32(~nvp_blk) + 1; + first_zero = cto32(nvp_blk); + if (first_zero >= 31) { + qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid crowd block 0x%08x", + nvp_blk); + return 0; + } + blk = first_zero + 1; /* * Supported crowd sizes are 2^1, 2^2, and 2^4. 2^3 is not supported. diff --git a/hw/intc/xive2.c b/hw/intc/xive2.c index f8ef6154878..311b42e15d3 100644 --- a/hw/intc/xive2.c +++ b/hw/intc/xive2.c @@ -1153,13 +1153,15 @@ static bool xive2_vp_match_mask(uint32_t cam1, uint32_t cam2, static uint8_t xive2_get_vp_block_mask(uint32_t nvt_blk, bool crowd) { - uint8_t size, block_mask = 0b1111; + uint8_t block_mask = 0b1111; /* 3 supported crowd sizes: 2, 4, 16 */ if (crowd) { - size = xive_get_vpgroup_size(nvt_blk); - if (size == 8) { - qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid crowd size of 8n"); + uint32_t size = xive_get_vpgroup_size(nvt_blk); + + if (size != 2 && size != 4 && size != 16) { + qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid crowd size of %d", + size); return block_mask; } block_mask &= ~(size - 1); @@ -1172,7 +1174,14 @@ static uint32_t xive2_get_vp_index_mask(uint32_t nvt_index, bool cam_ignore) uint32_t index_mask = 0xFFFFFF; /* 24 bits */ if (cam_ignore) { - index_mask &= ~(xive_get_vpgroup_size(nvt_index) - 1); + uint32_t size = xive_get_vpgroup_size(nvt_index); + + if (size < 2) { + qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid group size of %d", + size); + return index_mask; + } + index_mask &= ~(size - 1); } return index_mask; } From patchwork Mon Mar 17 05:23:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 14018657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 55D99C282EC for ; Mon, 17 Mar 2025 05:26:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tu2xK-0006gn-ME; Mon, 17 Mar 2025 01:24:06 -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 1tu2xF-0006fB-KI; Mon, 17 Mar 2025 01:24:02 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tu2xE-0007no-68; Mon, 17 Mar 2025 01:24:01 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2232aead377so86267215ad.0; Sun, 16 Mar 2025 22:23:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742189038; x=1742793838; 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=rCQzO/RWV9mKGsPnnGRAGAxs7AhCxziXIi4niuyH6/o=; b=Mr9rRtd3EYa61+L8n01pdFg0rbBl9cYGPePNLYa7lJOpT+yVG58B4Ho5EySGmjgLbN OA2CLqc8bOur8TLn9v+88dpe8eIk9u+2pBPmURD7Z+ZO1o4o7bktae2dX8qXp887r9DF mZaYpY8+Oeoz4S3eOjOU6QrspiTUy5OvMgVMz6UcCCS8PDjBI1kA+mFz/MKgohSrXRWD Ying49Vg7ix7IjPE4BQIOsJNifQcnimg9gT6Fhq2dix6Oqarz2/LXO9MbPB5A9V8+PTN eZpcKzWUk5f/9PlZ4wIEUyPTL9xDfEs3aPV+TfK1vy+Rz4mo8PCf1+1AIp46KGz4fWmI B0tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742189038; x=1742793838; 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=rCQzO/RWV9mKGsPnnGRAGAxs7AhCxziXIi4niuyH6/o=; b=Bw6LAJ/p+o0IcI/ySLQ5Gatkq8jjYqQQJ3Db7uo5J0TaMWQqiEtKIKHdL7GzhD3cB0 cZwc3cR4BMDuor4sO5IjuNc+FjMFWA9zog1Hh0IAvrOGnvALLtkdTzuchw7mx2tX4v4e ++ok+lUQy3jEvsUQmCAQ6pgpICLCjxuCs198J2TPUB3WlaVNOt85kaC+LODsCBMcvqot XkOMF0pHSXDC0ejjQ7cnoD2KN5NCqTnV/X1KKnuq0oL1kIxbxYym9rThr2mslhos9FdV 8Nldb8F/lrg8qd/2jylRUrLMUdD71TverPePqbfrTN7/XzPgSCTkAgsgSgfce2IPSR/v 0LzA== X-Forwarded-Encrypted: i=1; AJvYcCW6VE9WdTp0/2T+chFK5kSRozL/U9hTzRcD3zQDmFB9MfLbv46nJCEpdu9/TdYE4xnn3tWs7ZfyIg==@nongnu.org X-Gm-Message-State: AOJu0YzrjwcA6Rb8P2r2kD7CKpFUt5yQO/jVvi7pu2lh/s5GpIVwLEb/ lOPfclosd1GqxFpTCeMnzVXROLHNnWptcStEL1f3VrbuTxfXRQc6NbwBsA== X-Gm-Gg: ASbGnctTj0nTP37IKPUObEdUBEM4TrGI/mRtSNzLtCO1iVv7MOvACxQf5BqEWMjOA67 HbU7UT5dBa6/PgqFhKOJayrkEl/SERYBEl135t0TUfYaMYVAQJq1t/Zxqa81rmEYvKceDbLuotB HY67ErqOJHgJr0eCdye4oui/MaoIOu0AkONZfCqcXL7cQrZdlNGJ+LnNQl3ZohSXoxvJHbLAg7e JDuoOA/mME/EyoZUoQIOelM1vWtTzI9lOL6f9Dei9zcCtYK2UjpuzuX/RvGi25917qJBcXe0afK shHRP4dLiat3HHJwiwcYTPDO3OoRmfAB/7smjK8BgEuyxvAZVn20HH3MNZBu X-Google-Smtp-Source: AGHT+IF5qNYq1eMrY99ebl6tU0UfyeHKpZgx3juxDS6gerqVLJCtDB4d2kkvMa7Y9q3ZDxyjt8FSPw== X-Received: by 2002:a05:6a20:d74d:b0:1f5:8eb1:d5d2 with SMTP id adf61e73a8af0-1f5c114b9a0mr14828867637.13.1742189038499; Sun, 16 Mar 2025 22:23:58 -0700 (PDT) Received: from wheely.local0.net ([118.208.135.36]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73711695b6bsm6879495b3a.148.2025.03.16.22.23.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Mar 2025 22:23:58 -0700 (PDT) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , qemu-ppc@nongnu.org, Glenn Miles , Michael Kowal , Harsh Prateek Bora , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 3/6] ppc/xive2: Fix logical / bitwise comparison typo Date: Mon, 17 Mar 2025 15:23:35 +1000 Message-ID: <20250317052339.1108322-4-npiggin@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250317052339.1108322-1-npiggin@gmail.com> References: <20250317052339.1108322-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=npiggin@gmail.com; helo=mail-pl1-x631.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The comparison as written is always false (perhaps confusingly, because the functions/macros are not really booleans but return 0 or the tested bit value). Change to use logical-and. Resolves: Coverity CID 1593721 Cc: Cédric Le Goater Signed-off-by: Nicholas Piggin Reviewed-by: Cédric Le Goater --- hw/intc/xive2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/intc/xive2.c b/hw/intc/xive2.c index 311b42e15d3..7d584dfafaf 100644 --- a/hw/intc/xive2.c +++ b/hw/intc/xive2.c @@ -1344,7 +1344,7 @@ static void xive2_router_end_notify(Xive2Router *xrtr, uint8_t end_blk, return; } - if (xive2_end_is_crowd(&end) & !xive2_end_is_ignore(&end)) { + if (xive2_end_is_crowd(&end) && !xive2_end_is_ignore(&end)) { qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid END, 'crowd' bit requires 'ignore' bit\n"); return; From patchwork Mon Mar 17 05:23:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 14018653 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1803EC35FF3 for ; Mon, 17 Mar 2025 05:25:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tu2xM-0006h7-3R; Mon, 17 Mar 2025 01:24:08 -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 1tu2xK-0006gB-87; Mon, 17 Mar 2025 01:24:06 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tu2xI-0007o5-L7; Mon, 17 Mar 2025 01:24:05 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-223a7065ff8so26316685ad.0; Sun, 16 Mar 2025 22:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742189042; x=1742793842; 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=KkPaY1ymYYgtxcx8c4vM0EvVZxyRLrUg4YxSDzdPJ34=; b=btVGsgSmIwrBgs3ElJmrXDRRqQvVWb5pM5LluIWPvLbusBmhfajfo3LGOk7j1xdO2H KiMzwo/Em4MIpm7X7NSIDZlUUbRN0cwz1QzsMJX0uMJ6sXLTxDgwmYuFpH3kPnzOFwUv Pl1R8mBktk4ZldzporWITXDX+ox0TYV2KacH1m1Ud08tvicBBHObzlITzR9x/+cla4BC dnG/4XSkmFiL+X32JviC6Fm+o06bTxSDy/I9NZ4dQnAkR5tfcZhgwKLWMxjRRtUBoYaT FtbqK0GjPEkJFuHrXzanGbRRf+o8uOja/OwdRq80FOFcef3mX8jQL3O+1L2Tfqkmz+LZ yn+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742189042; x=1742793842; 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=KkPaY1ymYYgtxcx8c4vM0EvVZxyRLrUg4YxSDzdPJ34=; b=HBvFhmlH1cKaW2Irax5H/dzoE+1mPHglJ525vik5uciblEVmwa8R/XH4Zr8ao6WnsA fu+kPVbJeYGmA97CkH2MVV7I1vlkWiom4XLZqWglTdrFTTIIO+evZvwlM5YWU3ibb+Np HJJS7Z5woWUbiKSIZJ2l5yP53aVkQK2Vf8PQP1Oqz1SqFYYpY/tZmlYd/R6Zhmj57wkH a0w/pJ4CzvfZBBHtzbusIA6eeFqQhCQFuBRkl9SREMpjsE1LF8ZvCzT+Dp7NfekSWEXZ 1Cw7eOy4j5jwb2qjTf/QfDum4ESRdrO62q6eUEfeTWPNkB70wK57W7saPHDWImV5IrhU m7sw== X-Forwarded-Encrypted: i=1; AJvYcCWxL5+PNpYnRbUQrWjBHHlZe2NJXUI7bqybhHUQ0lfdUjPipgzs9glH8Qd0aXLSuVkXZZuotpG9+Q==@nongnu.org X-Gm-Message-State: AOJu0YzjQrXv0HP5gGoqIRgBwsTqrCH9Qwo6NaqzyyZv5Dd0GRHmOFvW jDqaoS6xyuLy3nmpGvELHFwa4cKx6OoiYZRDkwY/TMYODMdOOaAdpZbfkg== X-Gm-Gg: ASbGncubscPy0uBcmRHn/0Q5a1dUQJ1a3Qb3/tjr4Nh77CQe26NfHVvWA4X46oyW78j HLSoRmiSTPUF4H34Vt5tB6jJXmV0ygxms6/gvYkYXP6lswcgU1o4fq2K4UzqgiORZZoPbv1np9A D+gAbi5jk9UDqq9k57NR0RWwDwFtYDHp6EljPatwITsIO7nhRvLu2GWrqA/sYufdzZOfqAm1CX7 s8RD7Hb/71m9qlp4Q76vMkp/e6PmtpuudTi8q8YgiMd1uFvi9qgO8xJmM1a5cD7UCMTLWaTobJc D3E0ffswgqaftSA5tBokBrsZrIWHfRDUJ0iqfCPWhk7Y5sx1yw== X-Google-Smtp-Source: AGHT+IGp5wvGM6WpWDTIDW43gLrf+bawLzKgIakpCyz2nXIT2c2cSKlPxSDkYg1/Tb9e78mO22LDtQ== X-Received: by 2002:a05:6a00:228e:b0:735:d89c:4b8e with SMTP id d2e1a72fcca58-7372236c644mr11966743b3a.5.1742189042351; Sun, 16 Mar 2025 22:24:02 -0700 (PDT) Received: from wheely.local0.net ([118.208.135.36]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73711695b6bsm6879495b3a.148.2025.03.16.22.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Mar 2025 22:24:01 -0700 (PDT) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , qemu-ppc@nongnu.org, Glenn Miles , Michael Kowal , Harsh Prateek Bora , Shivaprasad G Bhat , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 4/6] ppc/spapr: Fix possible pa_features memory overflow Date: Mon, 17 Mar 2025 15:23:36 +1000 Message-ID: <20250317052339.1108322-5-npiggin@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250317052339.1108322-1-npiggin@gmail.com> References: <20250317052339.1108322-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=npiggin@gmail.com; helo=mail-pl1-x630.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Coverity reports a possible memory overflow in spapr_dt_pa_features(). This should not be a true bug since DAWR1 cap is only be true for CPU_POWERPC_LOGICAL_3_10. Add an assertion to ensure any bug there is caught. Resolves: Coverity CID 1593722 Fixes: 5f361ea187ba ("ppc: spapr: Enable 2nd DAWR on Power10 pSeries machine") Cc: Shivaprasad G Bhat Cc: Cédric Le Goater Signed-off-by: Nicholas Piggin Reviewed-by: Cédric Le Goater Reviewed-By: Shivaprasad G Bhat --- hw/ppc/spapr.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index a415e51d077..9865d7147ff 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -296,6 +296,7 @@ static void spapr_dt_pa_features(SpaprMachineState *spapr, pa_features[40 + 2] &= ~0x80; /* Radix MMU */ } if (spapr_get_cap(spapr, SPAPR_CAP_DAWR1)) { + g_assert(pa_size > 66); pa_features[66] |= 0x80; } From patchwork Mon Mar 17 05:23:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 14018651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E57CC282EC for ; Mon, 17 Mar 2025 05:24:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tu2xP-0006iG-TP; Mon, 17 Mar 2025 01:24:11 -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 1tu2xN-0006hd-Oz; Mon, 17 Mar 2025 01:24:10 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tu2xM-0007oP-2h; Mon, 17 Mar 2025 01:24:09 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-223f4c06e9fso65832775ad.1; Sun, 16 Mar 2025 22:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742189046; x=1742793846; 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=pxaRFbncyxlnm7heC5LP05GgEcrs1GqHGHGwWOssd1s=; b=ZFElg1t6nvAbLXh0fYvRPqfjHA4U/Oey4sGAcdIXqkjSPjEnYhvjEsLm7EUsTYlzkl UHihm0S9zcVemkI+IR7NcNLaLEPUyjQ6+b9sDQpOeJl2Dsrxw3KgKOAtO8KEem9A2k7s lguEW8Rqzuh9OpiKgSDwTBYYqzYoihwER8m3NHXtTvlRSatrhz2Mig2N1+I2vU5U5iFW sRcGcKAQq3dXt3LVKGvKGl1vADz52BHFZLecW51/X1UqhSedxzas4q0tgLC7GheI471Z nYF836R+fNTcv06lnD1riDRrBGsNag18FgHP7K5zNHeog7nsDgcOs0/ZUPPwuLubIHZX eSsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742189046; x=1742793846; 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=pxaRFbncyxlnm7heC5LP05GgEcrs1GqHGHGwWOssd1s=; b=iSg2W+dWmxexKEZuYzjyUMDWU7fo9doZASQ8QGa+SKfz59GXA2X1f3H8c/GUNa38zE mp4t4J6MoxnafjHLfUmnoVqj9QqC7tXdgkjusa3qziOtKHAQYAIoOjb1KVXurjXeVZDA fClHqSjbKZD8tmt8O1EJU+HwtJ4kJNS9UJ+X8gAHEZz4VDS9XhaqWLz3KY563EhqdHFo TRcGHaNyA8mqCgVTeeUP44J7wb/rkrJCVhsBKfY4pNbkMVK3HjwHra5G3b7pTkOzdOJ3 zJyCAN6eqZk6v0FbueK/yL034/7a78hhyIjFjNj2EYySgK9R4ZN4SuaQdL3Y9oys94rd t37g== X-Forwarded-Encrypted: i=1; AJvYcCWEn58Rv9Z0g5UknyvpEDIvXyili1sDbBQ6N3FDLmQ+Q2JYwC5bS5ILlJaGOKxkFTSMob8N+Ge9OQ==@nongnu.org X-Gm-Message-State: AOJu0YwUvqg9en2i5OYELDvoLwPCj5v2wRUB+femavlzTY4TcXiv/+Kb RoGSHctXssnJJq7OJ7KtGCTBewnSzcAIKSwk2MA20PD0gQadDbs48tUYfg== X-Gm-Gg: ASbGncsbdog4EIZ/W+x2ZVI4U7GuwRn9LdGdnIzx/QIWvlQgTHchl0T9RYU1s3CSF7E VRbbCYgNVf4YcqU9D0q8Ix2lQzVsXeSMvTQB+lL6k9R6+2SPtfV5qUDdMBhrAFWAADh/3JPg2in q+ZF+DeNS0o9y2C841/86YsKCIG/gKs9i9WCh4uK+qJoFCMXI+1G0kLbw0Fw8vQEzXfD8URdn9J jgxijyHndat41VU3ZAQRfeEqMTfz5xqn1VfLNCOgNxApE/SWwCB8NAUBzRYTKiFp1cdhAP+3/B3 CRGFNQyiokitqBxJJYz8vRDvIRIQ7h7kx5+9Ki4pK1w95ih4UA== X-Google-Smtp-Source: AGHT+IH7FV73JLG0d04jqf3cEQMjr+Qd8mpByhshKLKE8F2vd4hDYYbHMXejcL5yXBJuR8s/02P87g== X-Received: by 2002:a17:902:dac1:b0:21f:6d63:6f4f with SMTP id d9443c01a7336-225c64f42bdmr181878175ad.2.1742189045903; Sun, 16 Mar 2025 22:24:05 -0700 (PDT) Received: from wheely.local0.net ([118.208.135.36]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73711695b6bsm6879495b3a.148.2025.03.16.22.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Mar 2025 22:24:05 -0700 (PDT) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , qemu-ppc@nongnu.org, Glenn Miles , Michael Kowal , Harsh Prateek Bora , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 5/6] ppc/pnv: Move the PNOR LPC address into struct PnvPnor Date: Mon, 17 Mar 2025 15:23:37 +1000 Message-ID: <20250317052339.1108322-6-npiggin@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250317052339.1108322-1-npiggin@gmail.com> References: <20250317052339.1108322-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=npiggin@gmail.com; helo=mail-pl1-x635.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Rather than use the hardcoded define throughout the tree for the PNOR LPC address, keep it within the PnvPnor object. This should solve a dead code issue in the BMC HIOMAP checks where Coverity (correctly) reported that the sanity checks are dead code. We would like to keep the sanity checks without turning them into a compile time assert in case we would like to make them configurable in future. Fixes: 4c84a0a4a6e5 ("ppc/pnv: Add a PNOR address and size sanity checks") Resolves: Coverity CID 1593723 Cc: Cédric Le Goater Signed-off-by: Nicholas Piggin Reviewed-by: Cédric Le Goater --- include/hw/ppc/pnv_pnor.h | 1 + hw/ppc/pnv.c | 2 +- hw/ppc/pnv_bmc.c | 4 ++-- hw/ppc/pnv_pnor.c | 2 ++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/hw/ppc/pnv_pnor.h b/include/hw/ppc/pnv_pnor.h index 19c2d642e82..b44cafe918d 100644 --- a/include/hw/ppc/pnv_pnor.h +++ b/include/hw/ppc/pnv_pnor.h @@ -28,6 +28,7 @@ struct PnvPnor { BlockBackend *blk; uint8_t *storage; + uint32_t lpc_address; /* Offset within LPC FW space */ int64_t size; MemoryRegion mmio; }; diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 59365370c37..63f2232f32f 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -1191,7 +1191,7 @@ static void pnv_init(MachineState *machine) * Since we can not reach the remote BMC machine with LPC memops, * map it always for now. */ - memory_region_add_subregion(pnv->chips[0]->fw_mr, PNOR_SPI_OFFSET, + memory_region_add_subregion(pnv->chips[0]->fw_mr, pnv->pnor->lpc_address, &pnv->pnor->mmio); /* diff --git a/hw/ppc/pnv_bmc.c b/hw/ppc/pnv_bmc.c index 811ba3d7a49..fb70a8c1f22 100644 --- a/hw/ppc/pnv_bmc.c +++ b/hw/ppc/pnv_bmc.c @@ -174,8 +174,8 @@ static void hiomap_cmd(IPMIBmcSim *ibs, uint8_t *cmd, unsigned int cmd_len, { PnvPnor *pnor = PNV_PNOR(object_property_get_link(OBJECT(ibs), "pnor", &error_abort)); + uint32_t pnor_addr = pnor->lpc_address; uint32_t pnor_size = pnor->size; - uint32_t pnor_addr = PNOR_SPI_OFFSET; bool readonly = false; rsp_buffer_push(rsp, cmd[2]); @@ -251,8 +251,8 @@ static const IPMINetfn hiomap_netfn = { void pnv_bmc_set_pnor(IPMIBmc *bmc, PnvPnor *pnor) { + uint32_t pnor_addr = pnor->lpc_address; uint32_t pnor_size = pnor->size; - uint32_t pnor_addr = PNOR_SPI_OFFSET; if (!pnv_bmc_is_simulator(bmc)) { return; diff --git a/hw/ppc/pnv_pnor.c b/hw/ppc/pnv_pnor.c index 863e2e70aca..9db44ca21d8 100644 --- a/hw/ppc/pnv_pnor.c +++ b/hw/ppc/pnv_pnor.c @@ -108,6 +108,8 @@ static void pnv_pnor_realize(DeviceState *dev, Error **errp) memset(s->storage, 0xFF, s->size); } + s->lpc_address = PNOR_SPI_OFFSET; + memory_region_init_io(&s->mmio, OBJECT(s), &pnv_pnor_ops, s, TYPE_PNV_PNOR, s->size); } From patchwork Mon Mar 17 05:23:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 14018654 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ABA8FC35FF3 for ; Mon, 17 Mar 2025 05:25:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tu2xU-0006jD-1n; Mon, 17 Mar 2025 01:24:16 -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 1tu2xS-0006ig-19; Mon, 17 Mar 2025 01:24:14 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tu2xQ-0007op-2T; Mon, 17 Mar 2025 01:24:13 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-2239c066347so77731905ad.2; Sun, 16 Mar 2025 22:24:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742189050; x=1742793850; 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=qHPO8QJN6uV1YuZzM8KiBcANdL4KZSwmj3dkmnjbsok=; b=X+E/B1FOCDIqh+WF/yB6QRwMvWOt/+VTw33w0hnlkWbsuCAsEYn+oimUyTlcUU7Vwx 0DSOmLFUO4DmS4o6OlpGlIa7XJSVghsAX5U0KXq6HMsCRr6ypJZoyqmvFI+TsArFyTyH GYAAk+cYtOsb25+w07xlJaLUKNiM3CqI2v21jPmU0SN9IkdYeUCFK4zI3sgn5nxR3NoT 1m1JwfyIoQXQp4poh4/iOFWcU+cxxuBhrC1V9+w+KP2HrG4hBImoAHzKthFQa8RXGRHb ywvAVIw5yfRB7e2a/BPRPNviITAWL363UPAprhO4Q94PNqHiRP/KW5djBDIAxVhDyQrz HyvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742189050; x=1742793850; 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=qHPO8QJN6uV1YuZzM8KiBcANdL4KZSwmj3dkmnjbsok=; b=lSDyOImRR7r5jtrX+h0EWHi3RjDCUOvVp7f4dB54z8In8slE2vJBZebHJY0yeTjEA3 6P8CMxpBUekPP/c4wNSvSwz828mq+uATs2AEG1pIUogto2oKCVPpEMaLVkVtoCtlXgQz L3LrreOPT2ZnVI+3enq0eLckAS8ezh7meetcKUxQaGgtAGQkUCmoKMJjED+7KcRQR77o hW+kxRPP0cB1aKKPxh7Zn5IWPQZqukjWEPUlf1+074aB8hNAe3Li4ewTu+SIfTNYwkuI N7G6JRMvBFBK+NhWIiCvTaXpKuXCR/secQFwnVE4PE42eDA0el9DGIsWEvNSZVPUCqwr f4Ww== X-Forwarded-Encrypted: i=1; AJvYcCUsdyvpc0FoAr1CjBU/lAhmZBwRkrORDsUoJf0ItqqAxtProouzXwYA2PTt/cjIJwPtc/6auYL/gA==@nongnu.org X-Gm-Message-State: AOJu0Yyb7D9GgIHPCW6QZ8L9/ujQjvNaW7RalA+qmPRshhtsbZYFJ6TB 34ZNyMOJsUnbd2JqahCpUuWdIxw2uYCzF1O35TiU5uRYrhUBbB1REhxkwg== X-Gm-Gg: ASbGncuSHCElxCtEdcMfwwwZWlN1IVB6QjcUzbXXDAYjJG5kMXDlJg5m9AZjTy4nWR+ CmBtTSd2za7MFu8/rmvSFRZIuCGOIzxbZHbVB5Kkv49MzDtR0VIGem23Ac16UUFt+yQKjEmvjRL kX7VGxDcFjQ/bGUhQsBEXhRaTFy5a9GAmJOw5GXBq0bf3xHadU8qgrVa+vmkHDw3ePlYUaipXzp t3SGb+XYBZLq4tN5L4YM4GFnKVBu9zT8+ihsBxmSDELdKJwGEZ20i1/lCjthkHqN9w5rDgDdopX +sd/1DkY7/YPZFrB5anNiztVkgvL11zvzHlJK1GSd9X6qNcrgQ== X-Google-Smtp-Source: AGHT+IFX0vYJLxJhOzWGShIZU9ko5C/MWk9RcE/Q6dsEO0bnuGrTCvH6v2ML8WM3Cvw8Zi44xX8kZQ== X-Received: by 2002:a05:6a20:2d08:b0:1f5:8714:8147 with SMTP id adf61e73a8af0-1f5c11c3c61mr16592957637.23.1742189050123; Sun, 16 Mar 2025 22:24:10 -0700 (PDT) Received: from wheely.local0.net ([118.208.135.36]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73711695b6bsm6879495b3a.148.2025.03.16.22.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Mar 2025 22:24:09 -0700 (PDT) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , qemu-ppc@nongnu.org, Glenn Miles , Michael Kowal , Harsh Prateek Bora , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Stefan Hajnoczi" Subject: [PATCH 6/6] ppc/pnv: Fix system symbols in HOMER structure definitions Date: Mon, 17 Mar 2025 15:23:38 +1000 Message-ID: <20250317052339.1108322-7-npiggin@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250317052339.1108322-1-npiggin@gmail.com> References: <20250317052339.1108322-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=npiggin@gmail.com; helo=mail-pl1-x62d.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org These definitions were taken from skiboot firmware. I naively thought it would be nicer to keep the code similar by using the preprocessor, but it was pointed out that system headers might still use those symbols and cause something unexpected. Also just nicer to keep the QEMU tree clean. Cc: Thomas Huth Cc: "Philippe Mathieu-Daudé" Cc: "Stefan Hajnoczi" Fixes: 70bc5c2498f46 ("ppc/pnv: Make HOMER memory a RAM region") Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- hw/ppc/pnv_occ.c | 201 ++++++++++++++++++++++------------------------- 1 file changed, 96 insertions(+), 105 deletions(-) diff --git a/hw/ppc/pnv_occ.c b/hw/ppc/pnv_occ.c index bda6b23ad3c..177c5e514b7 100644 --- a/hw/ppc/pnv_occ.c +++ b/hw/ppc/pnv_occ.c @@ -364,7 +364,12 @@ static void pnv_occ_register_types(void) type_init(pnv_occ_register_types); -/* From skiboot/hw/occ.c with tab to space conversion */ +/* + * From skiboot/hw/occ.c with following changes: + * - tab to space conversion + * - Type conversions u8->uint8_t s8->int8_t __be16->uint16_t etc + * - __packed -> QEMU_PACKED + */ /* OCC Communication Area for PStates */ #define OPAL_DYNAMIC_DATA_OFFSET 0x0B80 @@ -384,20 +389,6 @@ type_init(pnv_occ_register_types); #define FREQ_MAX_IN_DOMAIN 0 #define FREQ_MOST_RECENTLY_SET 1 -#define u8 uint8_t -#define s8 int8_t -#define u16 uint16_t -#define s16 int16_t -#define u32 uint32_t -#define s32 int32_t -#define u64 uint64_t -#define s64 int64_t -#define __be16 uint16_t -#define __be32 uint32_t -#ifndef __packed -#define __packed QEMU_PACKED -#endif /* !__packed */ - /** * OCC-OPAL Shared Memory Region * @@ -434,69 +425,69 @@ type_init(pnv_occ_register_types); * @spare/reserved/pad: Unused data */ struct occ_pstate_table { - u8 valid; - u8 version; - union __packed { - struct __packed { /* Version 0x01 and 0x02 */ - u8 throttle; - s8 pstate_min; - s8 pstate_nom; - s8 pstate_turbo; - s8 pstate_ultra_turbo; - u8 spare; - u64 reserved; - struct __packed { - s8 id; - u8 flags; - u8 vdd; - u8 vcs; - __be32 freq_khz; + uint8_t valid; + uint8_t version; + union QEMU_PACKED { + struct QEMU_PACKED { /* Version 0x01 and 0x02 */ + uint8_t throttle; + int8_t pstate_min; + int8_t pstate_nom; + int8_t pstate_turbo; + int8_t pstate_ultra_turbo; + uint8_t spare; + uint64_t reserved; + struct QEMU_PACKED { + int8_t id; + uint8_t flags; + uint8_t vdd; + uint8_t vcs; + uint32_t freq_khz; } pstates[MAX_PSTATES]; - s8 core_max[MAX_P8_CORES]; - u8 pad[100]; + int8_t core_max[MAX_P8_CORES]; + uint8_t pad[100]; } v2; - struct __packed { /* Version 0x90 */ - u8 occ_role; - u8 pstate_min; - u8 pstate_nom; - u8 pstate_turbo; - u8 pstate_ultra_turbo; - u8 spare; - u64 reserved1; - u64 reserved2; - struct __packed { - u8 id; - u8 flags; - u16 reserved; - __be32 freq_khz; + struct QEMU_PACKED { /* Version 0x90 */ + uint8_t occ_role; + uint8_t pstate_min; + uint8_t pstate_nom; + uint8_t pstate_turbo; + uint8_t pstate_ultra_turbo; + uint8_t spare; + uint64_t reserved1; + uint64_t reserved2; + struct QEMU_PACKED { + uint8_t id; + uint8_t flags; + uint16_t reserved; + uint32_t freq_khz; } pstates[MAX_PSTATES]; - u8 core_max[MAX_P9_CORES]; - u8 pad[56]; + uint8_t core_max[MAX_P9_CORES]; + uint8_t pad[56]; } v9; - struct __packed { /* Version 0xA0 */ - u8 occ_role; - u8 pstate_min; - u8 pstate_fixed_freq; - u8 pstate_base; - u8 pstate_ultra_turbo; - u8 pstate_fmax; - u8 minor; - u8 pstate_bottom_throttle; - u8 spare; - u8 spare1; - u32 reserved_32; - u64 reserved_64; - struct __packed { - u8 id; - u8 valid; - u16 reserved; - __be32 freq_khz; + struct QEMU_PACKED { /* Version 0xA0 */ + uint8_t occ_role; + uint8_t pstate_min; + uint8_t pstate_fixed_freq; + uint8_t pstate_base; + uint8_t pstate_ultra_turbo; + uint8_t pstate_fmax; + uint8_t minor; + uint8_t pstate_bottom_throttle; + uint8_t spare; + uint8_t spare1; + uint32_t reserved_32; + uint64_t reserved_64; + struct QEMU_PACKED { + uint8_t id; + uint8_t valid; + uint16_t reserved; + uint32_t freq_khz; } pstates[MAX_PSTATES]; - u8 core_max[MAX_P10_CORES]; - u8 pad[48]; + uint8_t core_max[MAX_P10_CORES]; + uint8_t pad[48]; } v10; }; -} __packed; +} QEMU_PACKED; /** * OPAL-OCC Command Response Interface @@ -531,13 +522,13 @@ struct occ_pstate_table { * @spare: Unused byte */ struct opal_command_buffer { - u8 flag; - u8 request_id; - u8 cmd; - u8 spare; - __be16 data_size; - u8 data[MAX_OPAL_CMD_DATA_LENGTH]; -} __packed; + uint8_t flag; + uint8_t request_id; + uint8_t cmd; + uint8_t spare; + uint16_t data_size; + uint8_t data[MAX_OPAL_CMD_DATA_LENGTH]; +} QEMU_PACKED; /** * OPAL-OCC Response Buffer @@ -571,13 +562,13 @@ struct opal_command_buffer { * @data: Response specific data */ struct occ_response_buffer { - u8 flag; - u8 request_id; - u8 cmd; - u8 status; - __be16 data_size; - u8 data[MAX_OCC_RSP_DATA_LENGTH]; -} __packed; + uint8_t flag; + uint8_t request_id; + uint8_t cmd; + uint8_t status; + uint16_t data_size; + uint8_t data[MAX_OCC_RSP_DATA_LENGTH]; +} QEMU_PACKED; /** * OCC-OPAL Shared Memory Interface Dynamic Data Vx90 @@ -608,31 +599,31 @@ struct occ_response_buffer { * @rsp: OCC Response Buffer */ struct occ_dynamic_data { - u8 occ_state; - u8 major_version; - u8 minor_version; - u8 gpus_present; - union __packed { - struct __packed { /* Version 0x90 */ - u8 spare1; + uint8_t occ_state; + uint8_t major_version; + uint8_t minor_version; + uint8_t gpus_present; + union QEMU_PACKED { + struct QEMU_PACKED { /* Version 0x90 */ + uint8_t spare1; } v9; - struct __packed { /* Version 0xA0 */ - u8 wof_enabled; + struct QEMU_PACKED { /* Version 0xA0 */ + uint8_t wof_enabled; } v10; }; - u8 cpu_throttle; - u8 mem_throttle; - u8 quick_pwr_drop; - u8 pwr_shifting_ratio; - u8 pwr_cap_type; - __be16 hard_min_pwr_cap; - __be16 max_pwr_cap; - __be16 cur_pwr_cap; - __be16 soft_min_pwr_cap; - u8 pad[110]; + uint8_t cpu_throttle; + uint8_t mem_throttle; + uint8_t quick_pwr_drop; + uint8_t pwr_shifting_ratio; + uint8_t pwr_cap_type; + uint16_t hard_min_pwr_cap; + uint16_t max_pwr_cap; + uint16_t cur_pwr_cap; + uint16_t soft_min_pwr_cap; + uint8_t pad[110]; struct opal_command_buffer cmd; struct occ_response_buffer rsp; -} __packed; +} QEMU_PACKED; enum occ_response_status { OCC_RSP_SUCCESS = 0x00,