From nobody Mon Nov 25 10:50:17 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1716505995; cv=none; d=zohomail.com; s=zohoarc; b=L0CQ62RgfjHuUd+EQ4d1b+s3qinTuWryVVIyxVp3VmD0a28lCe+t4rgvh28wc8nSCT0nIEPxqSl/x3WR9oExRwIo0xGrr7YJmrmQlKK3vOwkwFb1W9MQtJBnHU0if2ARi/Vp3xD7+dBXgjS/3I0aOJTJYVn+Mqa4y4I3D2bU98s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716505995; 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=xV/OOVxWsS3ja1Em0QI6JyY32EBBBDkiguccIgQftMc=; b=ZiGOHh0Scw5NKPGSq2VBzehvAf/TdPrUeoSJ7R1YUKzoRgr2N2hjLIMKJyklNliih60/GqyCsjh3PPPldtCCGZJJNrYUjUAcSCfvastGUQu3mPI5hF64fxUF8LK6TK0dX9xFPSTgMhnz9sbmC+KNVAqda5I6ToPKQ4F/MsNlrZE= 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 1716505995710442.8266506688142; Thu, 23 May 2024 16:13:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sAHaU-0006LU-Ad; Thu, 23 May 2024 19:11:06 -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 1sAHZb-0002Tq-5t; Thu, 23 May 2024 19:10:11 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sAHZY-00064T-1u; Thu, 23 May 2024 19:10:09 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1f33d84eaefso10375425ad.3; Thu, 23 May 2024 16:10:07 -0700 (PDT) Received: from wheely.local0.net (110-175-65-7.tpgi.com.au. [110.175.65.7]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-682227f1838sm87041a12.46.2024.05.23.16.10.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 16:10:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716505805; x=1717110605; 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=xV/OOVxWsS3ja1Em0QI6JyY32EBBBDkiguccIgQftMc=; b=iNsjyvD5Ns4Jdh7ukWTmT+P29H+Axy80/4oh3on5o8aLd2kKbMvlIVhsF4uKs6gsiZ m7MB4sDq3dOWIu2sNo21wk//N6tcW24R8XygbYsYywEAuEgF9dh6aIjuzgFMYNYpEf2e 5mosva56Rql3vlV4ecyXBpOPLXzkaBG12NiPhC+o32iXhr6wTgGNaGpiLW6W4CUEyP0j PpWKPesa2FGPMU8sjFxdtq7PxYX0PGPogZx55AwrNKMeeTjctqQc3fc8xfDWpav2uspr NR46fC9GRtftBuSJrTM5CVeT4hrbMLibLzuAnQ1psC3dhfFtFrr5+IbCdpIcyzXp63gQ PEOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716505805; x=1717110605; 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=xV/OOVxWsS3ja1Em0QI6JyY32EBBBDkiguccIgQftMc=; b=ae75Yyr0zyNe72EXXROdB3/ZuL+xM7wBRtJPVYD0JSAoQbUDzkvB7JepzbSEBVyxDe u7arDEUb8vtw7bGBIGOAFZqEfw5NHkiMTvykVNyVYfh9OX90T5o1XCs+bIhJjwGM2Rwf KBIopKPKXA6+bxhiMHD1ZdFTZIMn5yVZEUucbdsKl8+JXz2P/xPhymERAz/ikh1VWlXb m+9dylFm2lew3PxBoke75uIIGVXI8nZKgvg7N8WrsqJ7q1v0PmJpI8PW3FidQ45N0SW0 hD9+1ffTYD7amMMKW2ah9AFMucqkhJSR77gdcG3VlFKlPyqTbMaQNndfZZBapR6WfeCf bl9Q== X-Forwarded-Encrypted: i=1; AJvYcCXiEKRg3BjYZK2Xyep5hzWKDjLUf6WwH5ITZLJ0GhHUn+N3Xn77JCYAU3/z0hJw6/ir3kWOxfvVjyJ+OFVNRwQxqwTz X-Gm-Message-State: AOJu0YyabkTjybhqc69Zt/hCYUoGOZfRiejOw2MgaPXcjxuP3csnC9ks +NGbBGngQw5rIOnffM1kDZEGjdeBiXN88YMeVi+LobmrOMb2HeJ4ZbFjbw== X-Google-Smtp-Source: AGHT+IER3z/Cbykh2IjYXjm8nnj6r7elADTJPWhhCgHjGrh92SeMxzxR0OT/YgCgoHzjc5LUhlEv4Q== X-Received: by 2002:a17:902:d50e:b0:1e2:9066:4a8b with SMTP id d9443c01a7336-1f448701704mr11430175ad.26.1716505804693; Thu, 23 May 2024 16:10:04 -0700 (PDT) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , qemu-ppc@nongnu.org, BALATON Zoltan Subject: [PULL 41/72] target/ppc/mmu_common.c: Move calculation of a value closer to its usage Date: Fri, 24 May 2024 09:07:14 +1000 Message-ID: <20240523230747.45703-42-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240523230747.45703-1-npiggin@gmail.com> References: <20240523230747.45703-1-npiggin@gmail.com> 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::631; envelope-from=npiggin@gmail.com; helo=mail-pl1-x631.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1716505996843100002 Content-Type: text/plain; charset="utf-8" From: BALATON Zoltan In mmubooke_check_tlb() and mmubooke206_check_tlb() prot2 is calculated first but only used after an unrelated check that can return before tha value is used. Move the calculation after the check, closer to where it is used, to keep them together and avoid computing it when not needed. Reviewed-by: Nicholas Piggin Signed-off-by: BALATON Zoltan Signed-off-by: Nicholas Piggin --- target/ppc/mmu_common.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/target/ppc/mmu_common.c b/target/ppc/mmu_common.c index 4fde7fd3bf..f79e390306 100644 --- a/target/ppc/mmu_common.c +++ b/target/ppc/mmu_common.c @@ -635,12 +635,6 @@ static int mmubooke_check_tlb(CPUPPCState *env, ppcemb= _tlb_t *tlb, return -1; } =20 - if (FIELD_EX64(env->msr, MSR, PR)) { - prot2 =3D tlb->prot & 0xF; - } else { - prot2 =3D (tlb->prot >> 4) & 0xF; - } - /* Check the address space */ if ((access_type =3D=3D MMU_INST_FETCH ? FIELD_EX64(env->msr, MSR, IR) : @@ -649,6 +643,11 @@ static int mmubooke_check_tlb(CPUPPCState *env, ppcemb= _tlb_t *tlb, return -1; } =20 + if (FIELD_EX64(env->msr, MSR, PR)) { + prot2 =3D tlb->prot & 0xF; + } else { + prot2 =3D (tlb->prot >> 4) & 0xF; + } *prot =3D prot2; if (prot2 & prot_for_access_type(access_type)) { qemu_log_mask(CPU_LOG_MMU, "%s: good TLB!\n", __func__); @@ -830,6 +829,18 @@ static int mmubooke206_check_tlb(CPUPPCState *env, ppc= mas_tlb_t *tlb, =20 found_tlb: =20 + /* Check the address space and permissions */ + if (access_type =3D=3D MMU_INST_FETCH) { + /* There is no way to fetch code using epid load */ + assert(!use_epid); + as =3D FIELD_EX64(env->msr, MSR, IR); + } + + if (as !=3D ((tlb->mas1 & MAS1_TS) >> MAS1_TS_SHIFT)) { + qemu_log_mask(CPU_LOG_MMU, "%s: AS doesn't match\n", __func__); + return -1; + } + if (pr) { if (tlb->mas7_3 & MAS3_UR) { prot2 |=3D PAGE_READ; @@ -851,19 +862,6 @@ found_tlb: prot2 |=3D PAGE_EXEC; } } - - /* Check the address space and permissions */ - if (access_type =3D=3D MMU_INST_FETCH) { - /* There is no way to fetch code using epid load */ - assert(!use_epid); - as =3D FIELD_EX64(env->msr, MSR, IR); - } - - if (as !=3D ((tlb->mas1 & MAS1_TS) >> MAS1_TS_SHIFT)) { - qemu_log_mask(CPU_LOG_MMU, "%s: AS doesn't match\n", __func__); - return -1; - } - *prot =3D prot2; if (prot2 & prot_for_access_type(access_type)) { qemu_log_mask(CPU_LOG_MMU, "%s: good TLB!\n", __func__); --=20 2.43.0