From patchwork Mon Jun 17 16:12:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 804894 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp629428wrr; Mon, 17 Jun 2024 09:14:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVW6uubUgWx2shsdsSyhMS/yZ6YnKNO1zPveDZYeoLhYsKY51XguHfjbnTfo3BpW6XIzIBHqCNPGtkYxbfvJGWr X-Google-Smtp-Source: AGHT+IG8hxPuF+C+ZLWhdsOInus5NTrJmg0AFeQLDr2zZQlcX9zMjjszLwDc2jDIwVpbXVE115g4 X-Received: by 2002:a05:6512:b1c:b0:52b:88c3:b2bc with SMTP id 2adb3069b0e04-52ca6e90630mr7509440e87.48.1718640895029; Mon, 17 Jun 2024 09:14:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718640894; cv=none; d=google.com; s=arc-20160816; b=igZ98JeBVoguHkQlSJEWUtYe+yRdyrr6QyeDf4K94UbaB5lsIS38C0d0Lhksyiqzks KNB8GF65fDYU9uoTs8p4bxUcHBH6yOHGEro/Cln/gix/dLBDlG/5L2BX+5T3DmqT2lKv N9HXGgc4hO2p+It/IoI8JFt/6fATrespyvFou2nbQwXvwrjpeDsXxiceDtlJ1e0k63qn 5Q0Yh94SNoTB8gk9tZtbU7OaC3msSSQy8em25QzsQLwwqPLKwjiVxVYVNP9OD0uhPONM rDg/0mXZ2P+bl1H6UJV5h64QF/ud643YjuuIyOa4o1wmjjqqptZ4vAExMGhwdzAz68Cy 2z0g== 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=RU8dA+BndeNrGR5fmXLNETHnH3CX1uGkm7Et/jlHqU4=; fh=3mEp7FusppN5Drq2PN08R8D/9xXM9YdbtG5TkJxJBiE=; b=ufKxBvl9kV2Ej7YSpfJJDIz3QdaV5jBjYyeoqdIa8FUcc5XVIKC75w7CoNJlRNt/1b LP6MPNYXUdWBiGxMJ1NXD+Fh2BppwTMwVexyNMWRKePPbDA4LT5ZJxEQRGy9zedC+GIf ahnk0hNv8XqIHCUTvu5knAMpTHcW62AA1MlSNJmGgUl7V1QRf0/7ru9iVZs+IMcJz58T FxzO89KS/CmbckJideBckIEygAw1VVgHpPRwYtk8sqwfubX3SVmuK/8BO3D6vSbd7as0 Z6xvFlTpTAWYWrg2qPmydoGvMVwg5YvFmoiY4y4hGKfPovwXGf3ns/T0A4U1MsKZWzij frZw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ixvzRaxi; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ffacd0b85a97d-360750b6394si6224490f8f.188.2024.06.17.09.14.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 17 Jun 2024 09:14:54 -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=ixvzRaxi; 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 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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; } -static inline int cpu_mmu_index_kernel(CPUX86State *env) -{ - int mmu_index_32 = (env->hflags & HF_LMA_MASK) ? 0 : 1; - int mmu_index_base = - !(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); #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) != 0; } -static int x86_cpu_mmu_index(CPUState *cs, bool ifetch) +int x86_mmu_index_pl(CPUX86State *env, unsigned pl) { - CPUX86State *env = cpu_env(cs); int mmu_index_32 = (env->hflags & HF_CS64_MASK) ? 0 : 1; int mmu_index_base = - (env->hflags & HF_CPL_MASK) == 3 ? MMU_USER64_IDX : + pl == 3 ? MMU_USER64_IDX : !(env->hflags & HF_SMAP_MASK) ? MMU_KNOSMAP64_IDX : (env->eflags & AC_MASK) ? MMU_KNOSMAP64_IDX : MMU_KSMAP64_IDX; return mmu_index_base + mmu_index_32; } +static int x86_cpu_mmu_index(CPUState *cs, bool ifetch) +{ + CPUX86State *env = 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 = (env->hflags & HF_LMA_MASK) ? 0 : 1; + int mmu_index_base = + !(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 = X86_CPU(cs);