From nobody Mon Nov 25 03:57:54 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=1718640895; cv=none; d=zohomail.com; s=zohoarc; b=ERuwDMcHbnZlfBzANB5CyBsaxshvwULwaWWrrjWQdDfcXuKv4qo+f9Dv579UjrAgthd6ifswybBMrdMx536l6QEf1dsiu6xy6iS7HPivKtml50dP+IeKbGA4k/1dNV1OBuGXnkHywvHk+/jc06vyqn520F85jTuHBwX1VuwX7UA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718640895; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RU8dA+BndeNrGR5fmXLNETHnH3CX1uGkm7Et/jlHqU4=; b=cSGdN6RhKRvWbo+Ij1Zb1J0pjraepC/BLOIKh5w84LgvdMpoxIh8PVwHvRB6tDP7HQLfHKwTthosJlG1eAMOOwZ5vpre9owZbYoqNNlzb/g69URaa0PWrFKYL/A9aEgCK8yBwLue9hyirCuZT2k3Nm0Np/tmMTQb5mWpOOidSFQ= 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 1718640894900552.9585575620715; Mon, 17 Jun 2024 09:14:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJExx-0005ED-FC; Mon, 17 Jun 2024 12:12: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 1sJExt-0005DH-Dr for qemu-devel@nongnu.org; Mon, 17 Jun 2024 12:12:18 -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 1sJExq-00089j-4G for qemu-devel@nongnu.org; Mon, 17 Jun 2024 12:12:16 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1f4a5344ec7so31732275ad.1 for ; Mon, 17 Jun 2024 09:12:13 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855ee8317sm80829285ad.145.2024.06.17.09.12.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 09:12:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718640732; x=1719245532; 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=RU8dA+BndeNrGR5fmXLNETHnH3CX1uGkm7Et/jlHqU4=; b=ixvzRaxiCLUDbC+0dEFLceP11No3+ZsmKGwJrV/dqxS2MR6li7VGCINHQQTzLngfEj KaoKdssUQ1zLN39+NXUOsGORAzbyfJMNEajk+Lp5Kq6yRSkaC6NJhGddHRMEh9L1ppI1 PPwUUeDT3ZPQTGH8Y9MIyITH4HDGxOuVdo4qrE1ZKdmik2BkVQR39zyVLLXamKSIIdhR VNS/x0lfpRZzJPzhp9rWSRremWtRCeqdkYVFFUYEU5a4iDfufN+yfCVpYIbfjWyjtcAX DghUuwt9QsvKnukqaVUHlXdylMX2nNkgScFBm2O3CEm8zQXgsuxIi4NId9KYn/BIVEyg qAeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718640732; x=1719245532; 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=RU8dA+BndeNrGR5fmXLNETHnH3CX1uGkm7Et/jlHqU4=; b=XY8CpQh69Bh8+7i5fpLxbz8sZDuSN8S6waBc/qIasGYm24FdDwu4xYnXU8otND8X43 S8gS1NGLxCcILnD2LClgrR+IRkp6EAG0W3u7QyZSxD7RRLv6pYWqVBaDJQ2YTeDYwViZ 3nSi2hEwfEF8CCzyWL4ks8QAYxrx13kiy6q7ISjnk0sanYt8wDWJUNzWj/95EnVpXsnK u6nWK4mWDDch1Po+US00psGpT5ZzCOMlzwV0E1An4Kh49/BYAisOPtYZ4DW4UWpJ0SIv 7/kmVSsZuGg1s8rBDbJvXfBoaVkN8g6WEgV0JHB3Z49d5ADTYUkrtNQWYhO1xsdF61MZ XffA== X-Gm-Message-State: AOJu0Yxlod7ug8jY5LtCuD0S4G8FAma7ZOQjV8FMdb/O3ynNAa8FuyUY uDZ0TdoATnek6JHYnYjoIkw6rWlB4mryPYLvxKOMfi+c0HiNY3Zg/muwKfBW4PVtg3ubeHBQ2gL u X-Google-Smtp-Source: AGHT+IF/qsnKg/4aTfAIl2gtKghIQ4ppenJ+kMkp5nLfVZ6fdjFLs1STDROPOYDkatlT7ewlhrnOww== X-Received: by 2002:a17:902:d492:b0:1f6:6a94:76c5 with SMTP id d9443c01a7336-1f98b23f6e5mr1392295ad.20.1718640732423; Mon, 17 Jun 2024 09:12:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH 1/3] target/i386: Introduce x86_mmu_index_{kernel_,}pl Date: Mon, 17 Jun 2024 09:12:08 -0700 Message-Id: <20240617161210.4639-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617161210.4639-1-richard.henderson@linaro.org> References: <20240617161210.4639-1-richard.henderson@linaro.org> MIME-Version: 1.0 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=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; 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, 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: 1718640895521100001 Content-Type: text/plain; charset="utf-8" Disconnect mmu index computation from the current pl as stored in env->hflags. Signed-off-by: Richard Henderson --- target/i386/cpu.h | 12 +++--------- target/i386/cpu.c | 27 ++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 8fe28b67e0..a528c30616 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2432,15 +2432,9 @@ static inline bool is_mmu_index_32(int mmu_index) return mmu_index & 1; } =20 -static inline int cpu_mmu_index_kernel(CPUX86State *env) -{ - int mmu_index_32 =3D (env->hflags & HF_LMA_MASK) ? 0 : 1; - int mmu_index_base =3D - !(env->hflags & HF_SMAP_MASK) ? MMU_KNOSMAP64_IDX : - ((env->hflags & HF_CPL_MASK) < 3 && (env->eflags & AC_MASK)) ? MMU= _KNOSMAP64_IDX : MMU_KSMAP64_IDX; - - return mmu_index_base + mmu_index_32; -} +int x86_mmu_index_pl(CPUX86State *env, unsigned pl); +int x86_mmu_index_kernel_pl(CPUX86State *env, unsigned pl); +int cpu_mmu_index_kernel(CPUX86State *env); =20 #define CC_DST (env->cc_dst) #define CC_SRC (env->cc_src) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 7466217d5e..ee7767046d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8107,18 +8107,39 @@ static bool x86_cpu_has_work(CPUState *cs) return x86_cpu_pending_interrupt(cs, cs->interrupt_request) !=3D 0; } =20 -static int x86_cpu_mmu_index(CPUState *cs, bool ifetch) +int x86_mmu_index_pl(CPUX86State *env, unsigned pl) { - CPUX86State *env =3D cpu_env(cs); int mmu_index_32 =3D (env->hflags & HF_CS64_MASK) ? 0 : 1; int mmu_index_base =3D - (env->hflags & HF_CPL_MASK) =3D=3D 3 ? MMU_USER64_IDX : + pl =3D=3D 3 ? MMU_USER64_IDX : !(env->hflags & HF_SMAP_MASK) ? MMU_KNOSMAP64_IDX : (env->eflags & AC_MASK) ? MMU_KNOSMAP64_IDX : MMU_KSMAP64_IDX; =20 return mmu_index_base + mmu_index_32; } =20 +static int x86_cpu_mmu_index(CPUState *cs, bool ifetch) +{ + CPUX86State *env =3D cpu_env(cs); + return x86_mmu_index_pl(env, env->hflags & HF_CPL_MASK); +} + +int x86_mmu_index_kernel_pl(CPUX86State *env, unsigned pl) +{ + int mmu_index_32 =3D (env->hflags & HF_LMA_MASK) ? 0 : 1; + int mmu_index_base =3D + !(env->hflags & HF_SMAP_MASK) ? MMU_KNOSMAP64_IDX : + (pl < 3 && (env->eflags & AC_MASK) + ? MMU_KNOSMAP64_IDX : MMU_KSMAP64_IDX); + + return mmu_index_base + mmu_index_32; +} + +int cpu_mmu_index_kernel(CPUX86State *env) +{ + return x86_mmu_index_kernel_pl(env, env->hflags & HF_CPL_MASK); +} + static void x86_disas_set_info(CPUState *cs, disassemble_info *info) { X86CPU *cpu =3D X86_CPU(cs); --=20 2.34.1