From nobody Wed May 15 19:31:12 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1689629815; cv=none; d=zohomail.com; s=zohoarc; b=QRaFyRc4lz+E51icrOfpsDN6dC7oZza5Hvo1quCd3A3Z3Fcgo5ES8TpN4qCSmLKuNkSYAkdOBocnIXbeP0+Hl5xcOtO/XFpBYY2usNwLzGzT7SIFK+qYErMPkbU3IkJ2cpCUQIl4KKqq8SmKCSOIP0XC+IgX37vNhCUu9mIW3Ls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689629815; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jzW4mOsCZL10lJkMKofhQQ9/QED2aRg9yunhluc/VfA=; b=ZHJ6o8U2aVXTjP18dOWKdeCVNKqcraF+c87Pg+w1HRa9VDDDF2V0BUWn3VdnSLv7ToTxT/SAYbvowBssJMf2dzHu9z94b8NinFQNekv9rCwo+Bpfpr22hwHMOs6qoptGN3aV0JYnpvECLb00QoVxtDyRG8pN8CDxUKfEtMwlf1I= 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 1689629815004484.92340100984677; Mon, 17 Jul 2023 14:36:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qLVsH-0001y4-AP; Mon, 17 Jul 2023 17:35:21 -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 1qLVsF-0001xk-5I for qemu-devel@nongnu.org; Mon, 17 Jul 2023 17:35:19 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qLVsD-0007vT-Co for qemu-devel@nongnu.org; Mon, 17 Jul 2023 17:35:18 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-314319c0d3eso5169548f8f.0 for ; Mon, 17 Jul 2023 14:35:16 -0700 (PDT) Received: from localhost.localdomain ([176.176.144.39]) by smtp.gmail.com with ESMTPSA id w17-20020adfde91000000b00315a57f1128sm447031wrl.115.2023.07.17.14.35.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 17 Jul 2023 14:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689629715; x=1692221715; 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=jzW4mOsCZL10lJkMKofhQQ9/QED2aRg9yunhluc/VfA=; b=wZzHGckTZWXBxsu/RvFsRphoBU80S0kjVkP/IQjMwCeo152CyLh7/ePWIySvP6kZG5 1VXQRwi1/wxOiKkBZ1mQHUeJtg4XMPfSw2Hekv9489+GmWc3r8zCw+HgeAg7ZlmWXVKp fz4wvck5hdZkczQnDAoXEweoRnURsCI3I7QUNYafbj4W/T2GZ2NWan1dKZ2B/sJzxqHZ nZ9QDuC3E+/IxIyBpLzoLt1CRWZMzktlgAr6gemwS9cTbZmE7MkMW5u1wc/0nuHywdLP dsgZhkzMNCB2BHJ2cTx7Pp+Q9+vttVil3/jC4APwjApyL2RDMGk3D9qldXtkduFmmoPL guGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689629715; x=1692221715; 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=jzW4mOsCZL10lJkMKofhQQ9/QED2aRg9yunhluc/VfA=; b=TjhaX8FRhmxiW33BwC6ENgQbooMy6NGTW7C1blhtWR9EoAY/xZpnPioXt6T7ytGm// 9305JeTMjF5jlpVrmMyXyoDOQslDrXIhGJdefivzFm3P1iw+Dh9ZcyNVTojKhXzA2mLh qm26yJvom5xtdZFHUkvg60F7jnVkYdauXRL9IZvWIpUE4Ltj+7bmRM9/vUY+ZHjZJ3L+ EY2MN/iwe3WGVIdgmb0U8H3+XswWupeTznqJJveA8YVLodx7VcgMGvG5L883qfMccIjR I7UgPV05ng3KMHXv0ZK6Jm0ol1GfdXpCaR28OD79bN1zJYlLGET+PBfwcz0T+BjE0GPq cr1Q== X-Gm-Message-State: ABy/qLaexj804MxtL0erJb9oap4shX1KKoeTNs3EZCe6yixjyT93fbjO 8pvpcM9BZ9d5PFDJkE20JoziI7wYCuwtO9VGMXo= X-Google-Smtp-Source: APBJJlFpOnGNwpcaVflN9IjgCal9fW6OFfP0IwTAlRCrl2Ym+zKmoT4blEmu9ik3MyaXepA9CqZfFA== X-Received: by 2002:a5d:5682:0:b0:314:37a9:f225 with SMTP id f2-20020a5d5682000000b0031437a9f225mr13309767wrv.40.1689629715493; Mon, 17 Jul 2023 14:35:15 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jiaxun Yang , Aleksandar Rikalo , Aurelien Jarno Subject: [PATCH for-8.1 v2 1/2] target/mips: Pass directory/leaf shift values to walk_directory() Date: Mon, 17 Jul 2023 23:35:03 +0200 Message-Id: <20230717213504.24777-2-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230717213504.24777-1-philmd@linaro.org> References: <20230717213504.24777-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::435; envelope-from=philmd@linaro.org; helo=mail-wr1-x435.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, T_SCC_BODY_TEXT_LINE=-0.01 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 @linaro.org) X-ZM-MESSAGEID: 1689629816091100001 We already evaluated directory_shift and leaf_shift in page_table_walk_refill(), no need to do that again: pass as argument. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Maydell --- target/mips/tcg/sysemu/tlb_helper.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/target/mips/tcg/sysemu/tlb_helper.c b/target/mips/tcg/sysemu/t= lb_helper.c index e5e1e9dd3f..e7be649b02 100644 --- a/target/mips/tcg/sysemu/tlb_helper.c +++ b/target/mips/tcg/sysemu/tlb_helper.c @@ -623,18 +623,13 @@ static uint64_t get_tlb_entry_layout(CPUMIPSState *en= v, uint64_t entry, =20 static int walk_directory(CPUMIPSState *env, uint64_t *vaddr, int directory_index, bool *huge_page, bool *hgpg_directory_hit, - uint64_t *pw_entrylo0, uint64_t *pw_entrylo1) + uint64_t *pw_entrylo0, uint64_t *pw_entrylo1, + int directory_shift, int leaf_shift) { int dph =3D (env->CP0_PWCtl >> CP0PC_DPH) & 0x1; int psn =3D (env->CP0_PWCtl >> CP0PC_PSN) & 0x3F; int hugepg =3D (env->CP0_PWCtl >> CP0PC_HUGEPG) & 0x1; int pf_ptew =3D (env->CP0_PWField >> CP0PF_PTEW) & 0x3F; - int ptew =3D (env->CP0_PWSize >> CP0PS_PTEW) & 0x3F; - int native_shift =3D (((env->CP0_PWSize >> CP0PS_PS) & 1) =3D=3D 0) ? = 2 : 3; - int directory_shift =3D (ptew > 1) ? -1 : - (hugepg && (ptew =3D=3D 1)) ? native_shift + 1 : native_shift; - int leaf_shift =3D (ptew > 1) ? -1 : - (ptew =3D=3D 1) ? native_shift + 1 : native_shift; uint32_t direntry_size =3D 1 << (directory_shift + 3); uint32_t leafentry_size =3D 1 << (leaf_shift + 3); uint64_t entry; @@ -779,7 +774,8 @@ static bool page_table_walk_refill(CPUMIPSState *env, v= addr address, if (gdw > 0) { vaddr |=3D goffset; switch (walk_directory(env, &vaddr, pf_gdw, &huge_page, &hgpg_gdhi= t, - &pw_entrylo0, &pw_entrylo1)) + &pw_entrylo0, &pw_entrylo1, + directory_shift, leaf_shift)) { case 0: return false; @@ -795,7 +791,8 @@ static bool page_table_walk_refill(CPUMIPSState *env, v= addr address, if (udw > 0) { vaddr |=3D uoffset; switch (walk_directory(env, &vaddr, pf_udw, &huge_page, &hgpg_udhi= t, - &pw_entrylo0, &pw_entrylo1)) + &pw_entrylo0, &pw_entrylo1, + directory_shift, leaf_shift)) { case 0: return false; @@ -811,7 +808,8 @@ static bool page_table_walk_refill(CPUMIPSState *env, v= addr address, if (mdw > 0) { vaddr |=3D moffset; switch (walk_directory(env, &vaddr, pf_mdw, &huge_page, &hgpg_mdhi= t, - &pw_entrylo0, &pw_entrylo1)) + &pw_entrylo0, &pw_entrylo1, + directory_shift, leaf_shift)) { case 0: return false; --=20 2.38.1 From nobody Wed May 15 19:31:12 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1689629850; cv=none; d=zohomail.com; s=zohoarc; b=cwFRYxE9DJiAVYXZXtLR5/J+5HFQTJsKwuf4C8juXmQpTb6KGj2LSqC2z5hUjO7vilYKx9rJpDQdbKMs4PvbcVtJa6MTGwigVbzBLYaGNbq2LBFcVoXb7E06d499zRKT4WeRH6M0LW59+Qr3BFljROrd6hBtttzkEc+vKUxR3Z4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689629850; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4UWwa1uuZikYOyZrtVyQHLSGe/yJoGLD5CEgAH5+Sh8=; b=BkD5MkJEH+Txq+p1e96aKCe/uAcD+0LE5V2Y0whIbUGh+ZOG0cnPGmQ6ackc3OOgVlcMRfw75rrvp6U9P9SjX92HaTmKxmYEyaoKfCOrlnMN5wjFYFoDvEPN6E5qI0jtZ6l6JJLDlTyTK+noTncRtR9J4xVssdrN8c3sr44wEY4= 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 1689629850085365.5334934346823; Mon, 17 Jul 2023 14:37:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qLVsN-0001yo-4X; Mon, 17 Jul 2023 17:35:27 -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 1qLVsL-0001ye-C1 for qemu-devel@nongnu.org; Mon, 17 Jul 2023 17:35:25 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qLVsJ-0007zl-NT for qemu-devel@nongnu.org; Mon, 17 Jul 2023 17:35:25 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-31590e4e27aso4523991f8f.1 for ; Mon, 17 Jul 2023 14:35:23 -0700 (PDT) Received: from localhost.localdomain ([176.176.144.39]) by smtp.gmail.com with ESMTPSA id n16-20020a5d4850000000b00313e4d02be8sm475148wrs.55.2023.07.17.14.35.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 17 Jul 2023 14:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689629722; x=1692221722; 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=4UWwa1uuZikYOyZrtVyQHLSGe/yJoGLD5CEgAH5+Sh8=; b=PAvLYQZ7rjAmuseppjocnQrUuVjQO05jar+REvDJa4waB3eIlKi6Mvk80jY9dP1Cwu gLx7T6AMEZqGKhakOIgE68Pa/Qb6OvPaCl/q5UoxpA0ttMR2+GDL1wP2pwruCnnQhE15 u3MZKuaL02YVjxgA97fKtBxztIzAXOWTqR4slj4hAvyTd/I9VYdEqXUmz8+t8S7UsO+L sbJKShP5PxYBrhDLupidqMlBLWo6izOpLPk7tTlqOSrmJv9CZ74uT2Vy1fQqRogkBNbY lfoeTu+EELCMLo34i34ak2ZPgwecTADHkFihgBFMhqMBBKwUS+SKbsJ4hV1q5aVxKPzL kXVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689629722; x=1692221722; 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=4UWwa1uuZikYOyZrtVyQHLSGe/yJoGLD5CEgAH5+Sh8=; b=e3VQAS30Nw7qxN+xAug9t3fFVaqS8RktxmRvVhNVh6aob+hgoMqmZFRjJswS/Ee6hK BxiTvEnusg7hX83vHGtocfkwPVYNFpkFhkmWyDsBQU318h7Ce8YgDq1wbRlprOLijqxq Dz6cHpWbP/mZtRDMuVYc54Y+0TQEXlOJBQxTYXbUWgZKbU0xolOC2a6mzDoDA1AZrtI1 hQmwr5Y90BPpo/xlub+n2w7eXij1TvKMDGHqizNqsKRpzVGfmCSGIvv7lBxXi+dG7vag u+9swABX1oTVTqlKEj7Gro1DVsEahPwXkgxJwI49QzzFgtTXvVgI2/jS20hU6R3TO9hm o5yA== X-Gm-Message-State: ABy/qLb4n3l1n7dZjEcIWTqGXlGBu5FOdhpk9H9k5XG6Kd5ihOiviB+4 pCIo7xBoYFXhxNv0dyHI412jXRtai00tNPzr7X0= X-Google-Smtp-Source: APBJJlGLgSYtHg+d8UKceGcpXoAgDOZhhiLNW5W7hy7aQxylwPKhAR2hliynwgfd6vbVz6RvfUWKig== X-Received: by 2002:adf:d092:0:b0:314:220d:7 with SMTP id y18-20020adfd092000000b00314220d0007mr272277wrh.45.1689629722084; Mon, 17 Jul 2023 14:35:22 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jiaxun Yang , Aleksandar Rikalo , Aurelien Jarno , Peter Maydell Subject: [PATCH for-8.1 v2 2/2] target/mips: Avoid shift by negative number in page_table_walk_refill() Date: Mon, 17 Jul 2023 23:35:04 +0200 Message-Id: <20230717213504.24777-3-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230717213504.24777-1-philmd@linaro.org> References: <20230717213504.24777-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::430; envelope-from=philmd@linaro.org; helo=mail-wr1-x430.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, T_SCC_BODY_TEXT_LINE=-0.01 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 @linaro.org) X-ZM-MESSAGEID: 1689629850430100005 Coverity points out that in page_table_walk_refill() we can shift by a negative number, which is undefined behaviour (CID 1452918, 1452920, 1452922). We already catch the negative directory_shift and leaf_shift as being a "bail out early" case, but not until we've already used them to calculated some offset values. Move the calculation of the offset values to after we've done the "return early if ptew > 1" check. Signed-off-by: Peter Maydell [PMD: Check for ptew > 1, use unsigned type] Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Maydell --- target/mips/tcg/sysemu/tlb_helper.c | 32 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/target/mips/tcg/sysemu/tlb_helper.c b/target/mips/tcg/sysemu/t= lb_helper.c index e7be649b02..7dbc2e24c4 100644 --- a/target/mips/tcg/sysemu/tlb_helper.c +++ b/target/mips/tcg/sysemu/tlb_helper.c @@ -624,7 +624,7 @@ static uint64_t get_tlb_entry_layout(CPUMIPSState *env,= uint64_t entry, static int walk_directory(CPUMIPSState *env, uint64_t *vaddr, int directory_index, bool *huge_page, bool *hgpg_directory_hit, uint64_t *pw_entrylo0, uint64_t *pw_entrylo1, - int directory_shift, int leaf_shift) + unsigned directory_shift, unsigned leaf_shift) { int dph =3D (env->CP0_PWCtl >> CP0PC_DPH) & 0x1; int psn =3D (env->CP0_PWCtl >> CP0PC_PSN) & 0x3F; @@ -730,21 +730,11 @@ static bool page_table_walk_refill(CPUMIPSState *env,= vaddr address, =20 /* Other HTW configs */ int hugepg =3D (env->CP0_PWCtl >> CP0PC_HUGEPG) & 0x1; - - /* HTW Shift values (depend on entry size) */ - int directory_shift =3D (ptew > 1) ? -1 : - (hugepg && (ptew =3D=3D 1)) ? native_shift + 1 : native_shift; - int leaf_shift =3D (ptew > 1) ? -1 : - (ptew =3D=3D 1) ? native_shift + 1 : native_shift; + unsigned directory_shift, leaf_shift; =20 /* Offsets into tables */ - int goffset =3D gindex << directory_shift; - int uoffset =3D uindex << directory_shift; - int moffset =3D mindex << directory_shift; - int ptoffset0 =3D (ptindex >> 1) << (leaf_shift + 1); - int ptoffset1 =3D ptoffset0 | (1 << (leaf_shift)); - - uint32_t leafentry_size =3D 1 << (leaf_shift + 3); + unsigned goffset, uoffset, moffset, ptoffset0, ptoffset1; + uint32_t leafentry_size; =20 /* Starting address - Page Table Base */ uint64_t vaddr =3D env->CP0_PWBase; @@ -766,10 +756,22 @@ static bool page_table_walk_refill(CPUMIPSState *env,= vaddr address, /* no structure to walk */ return false; } - if ((directory_shift =3D=3D -1) || (leaf_shift =3D=3D -1)) { + if (ptew > 1) { return false; } =20 + /* HTW Shift values (depend on entry size) */ + directory_shift =3D (hugepg && (ptew =3D=3D 1)) ? native_shift + 1 : n= ative_shift; + leaf_shift =3D (ptew =3D=3D 1) ? native_shift + 1 : native_shift; + + goffset =3D gindex << directory_shift; + uoffset =3D uindex << directory_shift; + moffset =3D mindex << directory_shift; + ptoffset0 =3D (ptindex >> 1) << (leaf_shift + 1); + ptoffset1 =3D ptoffset0 | (1 << (leaf_shift)); + + leafentry_size =3D 1 << (leaf_shift + 3); + /* Global Directory */ if (gdw > 0) { vaddr |=3D goffset; --=20 2.38.1