From patchwork Mon Jul 2 15:10:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 10501919 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2B31A60545 for ; Mon, 2 Jul 2018 15:30:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A38A28CDD for ; Mon, 2 Jul 2018 15:30:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0EB1828CE6; Mon, 2 Jul 2018 15:30:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A460628CED for ; Mon, 2 Jul 2018 15:30:12 +0000 (UTC) Received: from localhost ([::1]:33551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa0mJ-0002rV-Q2 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 02 Jul 2018 11:30:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48877) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa0U2-0004Jq-G9 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 11:11:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa0U0-00086d-SU for qemu-devel@nongnu.org; Mon, 02 Jul 2018 11:11:18 -0400 Received: from mail-pl0-x22c.google.com ([2607:f8b0:400e:c01::22c]:40263) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fa0U0-000865-MA for qemu-devel@nongnu.org; Mon, 02 Jul 2018 11:11:16 -0400 Received: by mail-pl0-x22c.google.com with SMTP id t6-v6so8097754plo.7 for ; Mon, 02 Jul 2018 08:11:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XP26Su5f4Z0Z60ApQh47OEXkTrqSOl00r2acJz/P8YI=; b=Ypqt1811Yk498sRu7vWSZSManDzBCd+9PVMTttDhGlWLhXX3YnUQviyNV2APaC7r0y 6+fBkFLvmhtZM1kdwOKPSet7y3hZvVKp2+FPyNnrLe3POQvPY2YAExKR14EaVH02dseC Nf4VdDQb8cd/kG8UprcJNYLkJlmyY5hjlUSLgRfWRG9JSX4LCE0LWzTi3C1isKHIwEOs EWn2lUmtp0zOCykxVbraB4o45kVszT79L22xk7PzX9C7K+ZcgoZc2yHv/AJLyS6blCxR Ljl7V+9ZetKmRFAVdg/c7bDhavJ2Y3BevnAcayw8lO/j9QFL3X28pLkO3fA1yLZNvqSR d4fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XP26Su5f4Z0Z60ApQh47OEXkTrqSOl00r2acJz/P8YI=; b=EY2aBtwd5nJtPkytTN3AshJ/BaZCCf6ovBwofr96mlvzdjdgP5dhfgKSmlBiuhh4Ha nR+CdrR2EtbbeyLhzXXiyz2k95JYx8//3ZISKjKSl9xsqn0gwNl3VWTpjfLkHj723Gvz HB1KUu/IQvdcFD88RoYnt3UvkGvkuIZzYQw+3puG50im+R4XpfXdob2wrdTM7A0p9jmS wY48vLWXBIj34X2CiFCo3rweO81+EqlBoaC2YjJwABISuPhIL42eJWNPOD7UQA9Efxs0 ux2T9nH1HdupAPz+TeF+Fkc93L23lKnWwQsLYn8+jQ9xTw+st9inFiAmOBmICfkm37qu nMiQ== X-Gm-Message-State: APt69E0oInxpDhAXv9lmxwL4REaWIcuItlkksyYWehKRhA9UeBi8dqdm I481K9F8eN7BhPd0hNRO0h8= X-Google-Smtp-Source: AAOMgpdzTlafqpQNaJe8ZLXVn3ny3sywn/iB2VZ/BWmABaqHSkeLH/c5SCFDP9Vr3Y2MjT82gqh6tQ== X-Received: by 2002:a17:902:7798:: with SMTP id o24-v6mr9252570pll.165.1530544275877; Mon, 02 Jul 2018 08:11:15 -0700 (PDT) Received: from localhost (g90.124-44-6.ppp.wakwak.ne.jp. [124.44.6.90]) by smtp.gmail.com with ESMTPSA id x63-v6sm7858171pfi.40.2018.07.02.08.11.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 02 Jul 2018 08:11:15 -0700 (PDT) From: Stafford Horne To: Peter Maydell Date: Tue, 3 Jul 2018 00:10:13 +0900 Message-Id: <20180702151023.24532-16-shorne@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180702151023.24532-1-shorne@gmail.com> References: <20180702151023.24532-1-shorne@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::22c Subject: [Qemu-devel] [PULL v2 15/25] target/openrisc: Fix tlb flushing in mtspr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stafford Horne , Richard Henderson , QEMU Development Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Richard Henderson The previous code was confused, avoiding the flush of the old entry if the new entry is invalid. We need to flush the old page if the old entry is valid and the new page if the new entry is valid. This bug was masked by over-flushing elsewhere. Signed-off-by: Richard Henderson Signed-off-by: Stafford Horne --- target/openrisc/sys_helper.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/target/openrisc/sys_helper.c b/target/openrisc/sys_helper.c index 7f458b0d17..c9702cd26c 100644 --- a/target/openrisc/sys_helper.c +++ b/target/openrisc/sys_helper.c @@ -32,6 +32,7 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb) #ifndef CONFIG_USER_ONLY OpenRISCCPU *cpu = openrisc_env_get_cpu(env); CPUState *cs = CPU(cpu); + target_ulong mr; int idx; switch (spr) { @@ -85,12 +86,15 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb) case TO_SPR(1, 512) ... TO_SPR(1, 512+DTLB_SIZE-1): /* DTLBW0MR 0-127 */ idx = spr - TO_SPR(1, 512); - if (!(rb & 1)) { - tlb_flush_page(cs, env->tlb.dtlb[idx].mr & TARGET_PAGE_MASK); + mr = env->tlb.dtlb[idx].mr; + if (mr & 1) { + tlb_flush_page(cs, mr & TARGET_PAGE_MASK); + } + if (rb & 1) { + tlb_flush_page(cs, rb & TARGET_PAGE_MASK); } env->tlb.dtlb[idx].mr = rb; break; - case TO_SPR(1, 640) ... TO_SPR(1, 640+DTLB_SIZE-1): /* DTLBW0TR 0-127 */ idx = spr - TO_SPR(1, 640); env->tlb.dtlb[idx].tr = rb; @@ -102,14 +106,18 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb) case TO_SPR(1, 1280) ... TO_SPR(1, 1407): /* DTLBW3MR 0-127 */ case TO_SPR(1, 1408) ... TO_SPR(1, 1535): /* DTLBW3TR 0-127 */ break; + case TO_SPR(2, 512) ... TO_SPR(2, 512+ITLB_SIZE-1): /* ITLBW0MR 0-127 */ idx = spr - TO_SPR(2, 512); - if (!(rb & 1)) { - tlb_flush_page(cs, env->tlb.itlb[idx].mr & TARGET_PAGE_MASK); + mr = env->tlb.itlb[idx].mr; + if (mr & 1) { + tlb_flush_page(cs, mr & TARGET_PAGE_MASK); + } + if (rb & 1) { + tlb_flush_page(cs, rb & TARGET_PAGE_MASK); } env->tlb.itlb[idx].mr = rb; break; - case TO_SPR(2, 640) ... TO_SPR(2, 640+ITLB_SIZE-1): /* ITLBW0TR 0-127 */ idx = spr - TO_SPR(2, 640); env->tlb.itlb[idx].tr = rb; @@ -121,6 +129,7 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb) case TO_SPR(2, 1280) ... TO_SPR(2, 1407): /* ITLBW3MR 0-127 */ case TO_SPR(2, 1408) ... TO_SPR(2, 1535): /* ITLBW3TR 0-127 */ break; + case TO_SPR(5, 1): /* MACLO */ env->mac = deposit64(env->mac, 0, 32, rb); break;