From patchwork Mon Aug 19 22:51:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 820298 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c8:0:b0:367:895a:4699 with SMTP id m8csp1653856wrb; Mon, 19 Aug 2024 15:55:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV9Rs8mR1WHlENwkdTPJ9X+QHuWnA4VFWopnu7l2Lp7TkDxn9D4c3KSH62MXkHNWxOs37BiZKaKmPOyumg9AHnI X-Google-Smtp-Source: AGHT+IF6xSJXrvRwQbzYl8fY7cJTIbWRHkjHcui11XGYuQXDDQqnSZEhV9QTWdkxQD9L7p4MGbjp X-Received: by 2002:a05:6808:2212:b0:3d5:5f32:e51e with SMTP id 5614622812f47-3dd3ad5f6f0mr13661865b6e.26.1724108144685; Mon, 19 Aug 2024 15:55:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724108144; cv=none; d=google.com; s=arc-20160816; b=y5eI+h0JNxJhTEJ9TOBr1M49ib+OgCFO9XL5i6bPgSW9pN16facmmMHe9u82tQiz0J lf3MCRx2sdNqRDkSjXp822rucbohn1FmH8F/9cLJ/ZhZ4d6Xzl5zmdPM0arB+1I/LJkO KviVFcq4DqEZhCXd6iF7sqP1MklrwyBe0y/RTWFa8awybcsVDsYnKTNQm90ZJFqM/Goo x5t8f7PrdnVftf9VSJ+ppzi+SlM1HcgP6SgPpjkHdsBpZS3+/kH6zvS53z19R/UdD7vj WTfIRzOOsOCVxXY8hM300BsKXYEGJfFhVMFCKPFelDrwC4bx18Ze0J9HbtD1R8fPZ4qT 9pyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nd77jbfvrLILzXcHedj2gSAGQaYl7M6K1uhrf65ne10=; fh=E4WdZeNP6TdcksgNcgN79EUPi+/pgtAx/ehfkdgAVtE=; b=JUcnoOxZlyhfx+sIx6IABU+mH3KNX9JI0cqHMXOnBpVc4SQvyEIdhi4g1H0IJwAdRY zU7Pe29EvuFKsb7bhJR+/Gcm9RJA0RkMBabhGZO8gsbXzC2gSy/EEVSBvLBi5kGU3km9 BqONwSm+pV75q3EJAVwrdTmdAggqdL5mwD6QSyaSgUckKJS0fR90sgR1ZFomt+xWJKAf icE40qYms67xxnVhS7tDZ663xxa4Q/sj16g70JiTLbveHn11bl+GLLJ0BifI2gtxEk0P UoRkn/Yn+I/2z01jSmnfInlORLOz6Fjf5vyRHYWTdW2B5ygb9+jXQR67P8Qnrq1zgTXs pQQg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=URbGPzgX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4536a0726bbsi9851391cf.271.2024.08.19.15.55.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Aug 2024 15:55:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=URbGPzgX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sgBF7-0002Ox-Dt; Mon, 19 Aug 2024 18:52:55 -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 1sgBE2-0000T2-FS for qemu-devel@nongnu.org; Mon, 19 Aug 2024 18:51:49 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sgBE0-0000gV-LF for qemu-devel@nongnu.org; Mon, 19 Aug 2024 18:51:46 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-37182eee02dso2551230f8f.1 for ; Mon, 19 Aug 2024 15:51:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724107902; x=1724712702; 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=nd77jbfvrLILzXcHedj2gSAGQaYl7M6K1uhrf65ne10=; b=URbGPzgX/DJiRLTIYSW46iqzl+KtpGiXlJXGkLKmmErHWJBWm8jqUrDT1p0uSVa2VD NnhC+BPFuV14sAJF/BYbvhewCYwc8EY3oh7oluVPIvQ+M9Ka00ssmiN++Z2V4mhLk/R+ 7iei8FR6jDSTHkSCvHuXDQy28yPIkIaXd8iuGQXXx2JdrOJkJbb9rlaf8b8h9DKRHqbn q04+Dig69KtNJNoct8ye3XVKnHCjFdWWF/NH6V640A/wOtIP093xeK0qX+rWeWaOKffa bTqiaB7bQtSLsI5IQvttnYFrEAn8RFPiDFZbSe3Vt9nCuWz1lvYBdwcraPDgnyEOQJFo ZXjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724107902; x=1724712702; 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=nd77jbfvrLILzXcHedj2gSAGQaYl7M6K1uhrf65ne10=; b=kW3iCoSkbo2/2eB7hcnMk8fOrDVhQAjgSR7lRyym9XjkpHlzTnbg8dsCZ5Ne0g71jc nrcwJq+sLgutvGQJhvYS7maFU+QFqMZmhApf8IEeIVRT9lH7kktEtPyUdlS/Fy3FPdJ4 sDtE9g5pMyZN+79WMBlrK2z1zhmVc153Ywjv1HB2KmMUgJCoFMCDCikkeVH7MxKoC7PL rW95g8Nbxmy8w6z3gRQGnTkyn3tJ0eMNjYRcPtyp01yO/pvPVsImtR8QmgYaB7l30YBk sGtxiwAlvfoo7NhMafmi23YoUxBO/p6ugEIC/4OdsLlVM//4dARlFl0LHGpynxzN7AiL BWJg== X-Gm-Message-State: AOJu0YySaKmawEzka+ls467WLzOA6qsox+1oJOqwdcZZTBjt86n1kd4n DUjNYyc/sUdaVKq+Rf52PsakJUu6GPUHOcvN9X8vi4kX3xeoN/TQb0xLEZjWP7pwyXhWjMz+nup AQYg= X-Received: by 2002:a5d:5e04:0:b0:366:dfc4:3790 with SMTP id ffacd0b85a97d-371c4a63393mr463587f8f.0.1724107902137; Mon, 19 Aug 2024 15:51:42 -0700 (PDT) Received: from localhost.localdomain (88-178-97-237.subs.proxad.net. [88.178.97.237]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3718983a38csm11705599f8f.6.2024.08.19.15.51.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 19 Aug 2024 15:51:41 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Thomas Petazzoni , Waldemar Brodkorb , Richard Henderson Subject: [PULL 05/20] target/mips: Use correct MMU index in get_pte() Date: Tue, 20 Aug 2024 00:51:01 +0200 Message-ID: <20240819225116.17928-6-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240819225116.17928-1-philmd@linaro.org> References: <20240819225116.17928-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=philmd@linaro.org; helo=mail-wr1-x42d.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org When refactoring page_table_walk_refill() in commit 4e999bf419 we missed the indirect call to cpu_mmu_index() in get_pte(): page_table_walk_refill() -> get_pte() -> cpu_ld[lq]_code() -> cpu_mmu_index() Since we don't mask anymore the modes in hflags, cpu_mmu_index() can return UM or SM, while we only expect KM or ERL. Fix by propagating ptw_mmu_idx to get_pte(), and use the cpu_ld/st_code_mmu() API with the correct MemOpIdx. Reported-by: Thomas Petazzoni Reported-by: Waldemar Brodkorb Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2470 Fixes: 4e999bf419 ("target/mips: Pass ptw_mmu_idx down from mips_cpu_tlb_fill") Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-ID: <20240814090452.2591-3-philmd@linaro.org> --- target/mips/tcg/sysemu/tlb_helper.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/target/mips/tcg/sysemu/tlb_helper.c b/target/mips/tcg/sysemu/tlb_helper.c index 60147ba0af..0e94e00a5f 100644 --- a/target/mips/tcg/sysemu/tlb_helper.c +++ b/target/mips/tcg/sysemu/tlb_helper.c @@ -593,16 +593,21 @@ static void raise_mmu_exception(CPUMIPSState *env, target_ulong address, */ static bool get_pte(CPUMIPSState *env, uint64_t vaddr, MemOp op, - uint64_t *pte) + uint64_t *pte, unsigned ptw_mmu_idx) { + MemOpIdx oi; + if ((vaddr & (memop_size(op) - 1)) != 0) { return false; } + + oi = make_memop_idx(op | MO_TE, ptw_mmu_idx); if (op == MO_64) { - *pte = cpu_ldq_code(env, vaddr); + *pte = cpu_ldq_code_mmu(env, vaddr, oi, 0); } else { - *pte = cpu_ldl_code(env, vaddr); + *pte = cpu_ldl_code_mmu(env, vaddr, oi, 0); } + return true; } @@ -642,7 +647,7 @@ static int walk_directory(CPUMIPSState *env, uint64_t *vaddr, /* wrong base address */ return 0; } - if (!get_pte(env, *vaddr, directory_mop, &entry)) { + if (!get_pte(env, *vaddr, directory_mop, &entry, ptw_mmu_idx)) { return 0; } @@ -668,7 +673,7 @@ static int walk_directory(CPUMIPSState *env, uint64_t *vaddr, ptw_mmu_idx) != TLBRET_MATCH) { return 0; } - if (!get_pte(env, vaddr2, leaf_mop, &entry)) { + if (!get_pte(env, vaddr2, leaf_mop, &entry, ptw_mmu_idx)) { return 0; } entry = get_tlb_entry_layout(env, entry, leaf_mop, pf_ptew); @@ -823,7 +828,7 @@ static bool page_table_walk_refill(CPUMIPSState *env, vaddr address, ptw_mmu_idx) != TLBRET_MATCH) { return false; } - if (!get_pte(env, vaddr, leaf_mop, &dir_entry)) { + if (!get_pte(env, vaddr, leaf_mop, &dir_entry, ptw_mmu_idx)) { return false; } dir_entry = get_tlb_entry_layout(env, dir_entry, leaf_mop, pf_ptew); @@ -835,7 +840,7 @@ static bool page_table_walk_refill(CPUMIPSState *env, vaddr address, ptw_mmu_idx) != TLBRET_MATCH) { return false; } - if (!get_pte(env, vaddr, leaf_mop, &dir_entry)) { + if (!get_pte(env, vaddr, leaf_mop, &dir_entry, ptw_mmu_idx)) { return false; } dir_entry = get_tlb_entry_layout(env, dir_entry, leaf_mop, pf_ptew);