From nobody Tue Feb 10 11:55:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604878989; cv=none; d=zohomail.com; s=zohoarc; b=hBIqxnYj5Qkzsx9sZ+8Xsiy/OhvwHtO4a83S/N+ghy83TYyUTOcwFwADWpI0pYrkVsqKhdivqFjQuhDcfBD9TjrfmrygFFctZJ8RERu9oTlN2i1IG9NB9aaPOTDwq2JedUstM/RctwO0ldhsBv6ZwbMYkuAxYTIDsJJ7fj32lZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604878989; 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=MOQKSfuZ3WXnJIf1iQq//Z2ISnKXo6hb+zOBO4CmoII=; b=b7GNnHDq0cWbOWpskGsJO/lCktyo5EhN8WifBmC8D+kgkuXhB1nYVrPBcEGUyPgxmX8viU387XrnPsvn3nPJcz56QFKnKCkGOc+eqjGEa2zrLIkCnF957bAhAXj3Kc51sqBDy3cyosVAAh73BGr0t2KMUkGTH6JDejzlVendWHA= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1604878989850125.64629538296776; Sun, 8 Nov 2020 15:43:09 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-163-qBxKC2INOsqkH6fiEdTUUg-1; Sun, 08 Nov 2020 18:43:06 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6193757097; Sun, 8 Nov 2020 23:43:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E5915B4AD; Sun, 8 Nov 2020 23:43:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 06AD7922F1; Sun, 8 Nov 2020 23:43:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0A8NgvaN031628 for ; Sun, 8 Nov 2020 18:42:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9EC922166B44; Sun, 8 Nov 2020 23:42:57 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 998F32166B28 for ; Sun, 8 Nov 2020 23:42:55 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6D7BE185A790 for ; Sun, 8 Nov 2020 23:42:55 +0000 (UTC) Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-517-x3bbHquFNJ6q91bDfCvjPw-1; Sun, 08 Nov 2020 18:42:53 -0500 Received: by mail-wr1-f47.google.com with SMTP id 23so6897616wrc.8 for ; Sun, 08 Nov 2020 15:42:53 -0800 (PST) Received: from localhost.localdomain (234.red-83-42-66.dynamicip.rima-tde.net. [83.42.66.234]) by smtp.gmail.com with ESMTPSA id v12sm11741425wro.72.2020.11.08.15.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Nov 2020 15:42:51 -0800 (PST) X-MC-Unique: qBxKC2INOsqkH6fiEdTUUg-1 X-MC-Unique: x3bbHquFNJ6q91bDfCvjPw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=MOQKSfuZ3WXnJIf1iQq//Z2ISnKXo6hb+zOBO4CmoII=; b=SXA7yTI3iwZxs7R1Zw1lKpgimawg9tI4ppixFSJpoOyDASV9GMh6DGsEGBS6Qj/DAV x4SBUHp9Ibj8f28pQ8yKooedvPto49KANQjtuPQ/iFafyBOtmL1MNHqvWpESRxHIjg/D UGyBrPos8Yi4kTnp0gJTPbJs/f/tpc3xcwFAC2AgHIYpPWcMnmO9zc4dsP8vvzKWQRYD Jdi0M/fc2A/9dtCoPP0XGtLs/GC7Y0GS0zyNh5hcFEB6VTn956uZ+oKaA+NnP7OoVWD1 bDQQE5WmeSbNlwv9L7+afS1TvhgONZennps/qOyrrfkq67NXeqitFWsBzISWF+POxDH3 uGBA== X-Gm-Message-State: AOAM531Pzr4eUy9+CwRXJ4q7e5+xEpmwJ+Xu49liIZ7MviHHsiKvxoh7 oMsGERRo667bgI634O+NCMo= X-Google-Smtp-Source: ABdhPJwzmHuRWarpqHSrSBEOhOltq46x1N6ScvGfqN92q/FNHpKaiS4CDh+/jYo2eMCBzw2NabMwSQ== X-Received: by 2002:adf:9461:: with SMTP id 88mr14332374wrq.171.1604878972170; Sun, 08 Nov 2020 15:42:52 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 2/3] target/mips: Fix PageMask with variable page size Date: Mon, 9 Nov 2020 00:42:33 +0100 Message-Id: <20201108234234.2389789-3-f4bug@amsat.org> In-Reply-To: <20201108234234.2389789-1-f4bug@amsat.org> References: <20201108234234.2389789-1-f4bug@amsat.org> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Aleksandar Rikalo , Paul Burton , libvir-list@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jiaxun Yang , Huacai Chen , Aurelien Jarno X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Jiaxun Yang Our current code assumed the target page size is always 4k when handling PageMask and VPN2, however, variable page size was just added to mips target and that's no longer true. Fixes: ee3863b9d414 ("target/mips: Support variable page size") Signed-off-by: Jiaxun Yang Signed-off-by: Huacai Chen Message-Id: <1604636510-8347-2-git-send-email-chenhc@lemote.com> Tested-by: Philippe Mathieu-Daud=C3=A9 [PMD: Replaced find_first_zero_bit() by cto32()] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- target/mips/cpu.h | 1 + target/mips/cp0_helper.c | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/target/mips/cpu.h b/target/mips/cpu.h index d41579d44ae..23f8c6f96cd 100644 --- a/target/mips/cpu.h +++ b/target/mips/cpu.h @@ -619,6 +619,7 @@ struct CPUMIPSState { * CP0 Register 5 */ int32_t CP0_PageMask; +#define CP0PM_MASK 13 int32_t CP0_PageGrain_rw_bitmask; int32_t CP0_PageGrain; #define CP0PG_RIE 31 diff --git a/target/mips/cp0_helper.c b/target/mips/cp0_helper.c index 709cc9a7e3d..a1b5140ccaf 100644 --- a/target/mips/cp0_helper.c +++ b/target/mips/cp0_helper.c @@ -892,13 +892,28 @@ void helper_mtc0_memorymapid(CPUMIPSState *env, targe= t_ulong arg1) =20 void update_pagemask(CPUMIPSState *env, target_ulong arg1, int32_t *pagema= sk) { - uint64_t mask =3D arg1 >> (TARGET_PAGE_BITS + 1); - if (!(env->insn_flags & ISA_MIPS32R6) || (arg1 =3D=3D ~0) || - (mask =3D=3D 0x0000 || mask =3D=3D 0x0003 || mask =3D=3D 0x000F || - mask =3D=3D 0x003F || mask =3D=3D 0x00FF || mask =3D=3D 0x03FF || - mask =3D=3D 0x0FFF || mask =3D=3D 0x3FFF || mask =3D=3D 0xFFFF)) { - env->CP0_PageMask =3D arg1 & (0x1FFFFFFF & (TARGET_PAGE_MASK << 1)= ); + uint32_t mask; + int maskbits; + + /* Don't care MASKX as we don't support 1KB page */ + mask =3D extract32((uint32_t)arg1, CP0PM_MASK, 16); + maskbits =3D cto32(mask); + + /* Ensure no more set bit after first zero */ + if ((mask >> maskbits) !=3D 0) { + goto invalid; } + /* We don't support VTLB entry smaller than target page */ + if ((maskbits + 12) < TARGET_PAGE_BITS) { + goto invalid; + } + env->CP0_PageMask =3D mask << CP0PM_MASK; + + return; + +invalid: + /* When invalid, set to default target page size. */ + env->CP0_PageMask =3D (~TARGET_PAGE_MASK >> 12) << CP0PM_MASK; } =20 void helper_mtc0_pagemask(CPUMIPSState *env, target_ulong arg1) --=20 2.26.2