From patchwork Wed Jul 17 05:03:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 812972 Delivered-To: patch@linaro.org Received: by 2002:a5d:42c4:0:b0:367:895a:4699 with SMTP id t4csp627417wrr; Tue, 16 Jul 2024 22:07:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXze4Ba89ufgxym9WttAoVvRsKV+Ly06G1fC8qgEIOh5DguNUwFRIM5IXJkAam0+YVkCVZdDaCzEHFd/zwen3k6 X-Google-Smtp-Source: AGHT+IFTsmIzlzqLNbk5eikQS+FtNpMpx7YP21A5g20kiLESqwl3GWy0fHwEcZ3tzjgBiMTKcwdD X-Received: by 2002:a05:620a:4607:b0:79f:17e6:fe8a with SMTP id af79cd13be357-7a18745c52amr60690985a.20.1721192821263; Tue, 16 Jul 2024 22:07:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721192821; cv=none; d=google.com; s=arc-20160816; b=z12DR9C4UZTgcUzuA51sZFBt45scaTmJQsITuw8Yin2Ui3Vjep1T9BWjStcOmnwLJt x71WWIJJdtw2eZbHP9Sgbb51PNsruAv2HpGa23LtbosYkQqJpZtDeIMFHTHIw6kYOt89 B9az0P0UmUuHLvhEzQqF7lY11e1/U5AeM8QG+dG34cJkgdUP25oSM8+F1V6VqGmEHFMe XHMRJr5ICww0Fjhk/J9RjUjubWRaupWb8gzqyKWB45z0Ga7dbVzu8c467fpiZwdgZPgM 35j3542sI+VDsAdnh3RTkGcFE2Mj62X3PTLmldhHeOiR/B+dqghC4nZPbYZAkRhqJwuV D2pw== 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=yKHaLhM9UAuURgVWP4GssGjRnYIMl9btSsv/NKhFweE=; fh=mN+7zamMqtxpbv5qGNGIO/QHsXnjUAqHW/yN5gisKlY=; b=VPzP2FWI9R4dK2kxyynGlmr7ejD2NSs1+lFytWs+vyWjTvV/ZS+5S3mi78dfUkPY8O I+9ds5UHqKsjC2y0JxtyO+ywZ7tHt7xdB3VlgrkqMgXGngv/VJ+sIy4oCOB0PaRhHLZM k57WWbyrcSm4OrVt2dZFqUfHXYznuxN7mPgqULos7EzomZXrfXth57Y3O5Ny5MOWhXpr Tx6wA1UqAPktDmf1YZzGwjxVUSNy0ftAX/NiSpw0zUWGBuUtsZisC/6fADbi9+9nDQbP UvOGvfAPbym/ga9l7Se0Cy0JO8240tu3dw4HxvfRyPOlcMlZYHVEcHmSUQwJvR8ARu1x zc/g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WXoaf+nU; 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7a160c69202si917811385a.422.2024.07.16.22.07.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Jul 2024 22:07:01 -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=@redhat.com header.s=mimecast20190719 header.b=WXoaf+nU; 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=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTwq7-0002hn-S9; Wed, 17 Jul 2024 01:04:31 -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 1sTwpu-0001vg-07 for qemu-devel@nongnu.org; Wed, 17 Jul 2024 01:04:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTwpr-00022s-Uy for qemu-devel@nongnu.org; Wed, 17 Jul 2024 01:04:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721192655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yKHaLhM9UAuURgVWP4GssGjRnYIMl9btSsv/NKhFweE=; b=WXoaf+nUGM0yOOz2FKuov91eFX5OzbtZU0y5gAh7il/AVI4ICW/wUikMqF+MDT97P/6ILH dM0g6i1zda0wMVjcBX0rE+OIdGLmCQosu4vUJWOHZ2SLY4r3NmKCA7fK3/vAS1dz2fzS5M +qwVi//gEypXxqOO5Yi2kaWcRSaWqEs= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-371-I-BKg60pMmS67cezwKZthQ-1; Wed, 17 Jul 2024 01:04:12 -0400 X-MC-Unique: I-BKg60pMmS67cezwKZthQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-426d316a96cso45214095e9.0 for ; Tue, 16 Jul 2024 22:04:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721192651; x=1721797451; 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=yKHaLhM9UAuURgVWP4GssGjRnYIMl9btSsv/NKhFweE=; b=tBnR5DRbmHZz0jE5WSfoZc2PpZwlservFDaPaza0OVOQKdVVZgX3xAfoxIuD8T8z+n wdvEBljTA0wpSJzRQ7yRPyhXhJLuff27ZAlIKV05YAIRbq4f3JAupOfem0PUCvogM6ft Lmc6SWinS6BlTu/7b0xS8tqvIr/Om3NiTw9XK5vTYlg80lAWoxBnEYNxFlIIZ5aU6UY2 s9l1I0paDN7j6Q+zwlQMu6IEW0PxHhDUmTmQqHL/Sa9i+BCUUmOgLgpThaaqlzDCYGEn EnJnbnBo17ledOafDcsbqyXUkYY74JlDKGB1jg+aoaFHVYbwQEQMGNMTP0jxVNAbQJTN EfTg== X-Gm-Message-State: AOJu0YzpGKIhchPMV5RtwHaN6CBm6pyJid/IYiwoDAUKWW1GDb185zAn 67IbGej2So9ZycsANxSrisXTXdFMQWPzEpKuHXqoySTmKV/z2eUyMejojCJO/qHBf6KVTSdr+cL u/av5E9z7FnRYaVIFnHGZC85J1cpbVLTXJl5+xNfENIReBLgFM2Ct48fOc7+nYzVFwaLcPQG041 BfrNF6G2gkkqCngAsxoqzMSTbH912f9DFOXda0 X-Received: by 2002:a05:6000:1449:b0:367:9224:9621 with SMTP id ffacd0b85a97d-36831652dbemr560831f8f.31.1721192650830; Tue, 16 Jul 2024 22:04:10 -0700 (PDT) X-Received: by 2002:a05:6000:1449:b0:367:9224:9621 with SMTP id ffacd0b85a97d-36831652dbemr560814f8f.31.1721192650507; Tue, 16 Jul 2024 22:04:10 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3680dafbe5dsm10661527f8f.81.2024.07.16.22.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 22:04:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PULL 16/20] target/i386/tcg: Introduce x86_mmu_index_{kernel_,}pl Date: Wed, 17 Jul 2024 07:03:26 +0200 Message-ID: <20240717050331.295371-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240717050331.295371-1-pbonzini@redhat.com> References: <20240717050331.295371-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 From: Richard Henderson Disconnect mmu index computation from the current pl as stored in env->hflags. Signed-off-by: Richard Henderson Link: https://lore.kernel.org/r/20240617161210.4639-2-richard.henderson@linaro.org Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 11 ++--------- target/i386/cpu.c | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index c43ac01c794..1e121acef54 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2445,15 +2445,8 @@ 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 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 c05765eeafc..4688d140c2d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8122,18 +8122,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); +} + +static 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);