From patchwork Tue Oct 25 16:39:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 618143 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3527442pvb; Tue, 25 Oct 2022 10:02:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7s50hwELOpQoe7UaEY9d5d4SN0zZFtU0NXyQrcd4FXyVp/RtYrzs+bwZRgyUWoqhCwqeT9 X-Received: by 2002:ac8:5a45:0:b0:39b:ef52:ac1d with SMTP id o5-20020ac85a45000000b0039bef52ac1dmr33229258qta.419.1666717355327; Tue, 25 Oct 2022 10:02:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666717355; cv=none; d=google.com; s=arc-20160816; b=sCanMxa3+URjSG4ybcEKLMzqsaizgiN5K9rRoADhTFmve/oCPpEPzUHrVWvYWgLAO9 +kHG3vFIcawWamvxeR/0mZy1GQMw/a5aZkU3ThY4TEkdRekmaHwrlZAT7t5zE6KFHUPG YEChKJWkc5hbPjH1d1ysL6tlVQ4X5RaDdyiTRLWniWLFY/uTx+WWVHoxSfbbJ1QKH8R/ fWWqdBSH3g9HHcTSd22mqtM04gF2T47dNhKGL49PkKGSfosn5rZngM/YqedACfO7DY/X YMrURyHE1NYbGMwEtxOqPa/E4IH5YwtlZ0lhYTgVltLRtRBCk4qAiFXEXEoGS32dE4BY 9J0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender: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:to:from :dkim-signature; bh=v7FsAg0HK2uUkzX8X5S4y/tawsKHcfFIVqGsDHnAE08=; b=pdl50cmm3tMKSIc59qNAmM69MH4iTKXXmzzf0ZYk4b3eFbsICQuCPIrQE48Bk+a0z5 dYTzUuDK/9OVfISoMtUNjURmREGXLWpz7BYIwfqbuYsfxIdrvgySaQCAV0+pxPTccnJP ija6hN/7C5QUs6rNrf18C6Bth2WZuU4sJWpzmXuQbx3zJyZY9nSP/GA1+chvRVpP1iA7 FifDZx159LH9CbzfcncjqKFtkjIrSlX0Woer4gGe37oB1rxcLhhNXTdDkFc7hA1simmB GSLb80VVRucaxwSz32Xic8QoEb1yeRfo9xgefCWTkcImLNIivKbIcxwnWaRlJlHh8GO7 Y3WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E1btpO2t; 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 o2-20020ac85a42000000b0039cbf67b278si2372287qta.309.2022.10.25.10.02.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Oct 2022 10:02:35 -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=E1btpO2t; 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 1onMye-000696-VO; Tue, 25 Oct 2022 12:40:32 -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 1onMyR-0005lH-Ua for qemu-devel@nongnu.org; Tue, 25 Oct 2022 12:40:19 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1onMyM-0001cR-Go for qemu-devel@nongnu.org; Tue, 25 Oct 2022 12:40:18 -0400 Received: by mail-wr1-x436.google.com with SMTP id bp11so21528064wrb.9 for ; Tue, 25 Oct 2022 09:40:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=v7FsAg0HK2uUkzX8X5S4y/tawsKHcfFIVqGsDHnAE08=; b=E1btpO2tArXJ3d3rcojJ9KDEh664HfH2OLNnSxGefQRHKvAOpsmY9jPwpmXL1Rs3D4 fAqDynnYu5ioQhX/6OseXAKOe77oaOGOF0HbENfAdegTU1d3t2Xs/g/vUXJReGhQju++ nRF+ZFwR2JbyIs6iGh9XoPVdueXBHGOuYFyfpvQ1N1Mrp9VwOaHpjqltaNL8zqCp5dYi M1AcOMIQDtOCO3X2C8UgYD+uvtsk8zg7dQLjmDbs1Eg5E8IrCNQEg8vd1b1/T7a6XDA3 junE+rpKWOVK1lALdNgdfAC4CYljCiL2eNXISBL3F+f0q+Ety9wK9hctVs/7anJwcPA6 nt9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v7FsAg0HK2uUkzX8X5S4y/tawsKHcfFIVqGsDHnAE08=; b=n9agsCGE2ojYSac6g20xoB3KYXnOfmbZJTL7hLp2FjOHUB8Prvi/KhEuKFOYCOSI6X EL9iGTatkp7c11X76YpFs39ep73+Mmz/jRjOIogSujpOZHApPw8nD+Sq0vhAL9WoDbTc 6w4ilLfn5U1XI0DqFk4wnT0Xv8rW+DTh7kKkUWT2Xze7N5eA5Iqo5UGONiqumFhEQ8QV 0RhQEsnz3MR8T8mYPAOV3al308gKgfyBDA/TVQGLB3vzk13mKGhXjrnqASS8rYATmIVO 2ZbQNwwhuIIC99v0hgvuc126b4ifWt86QaqV96G4d882jXLQqD6PyrQCVV48E9trxBDU XCAQ== X-Gm-Message-State: ACrzQf1++and+KsaWika2HdXbk4maW27uO1Tc8WmnAucLT2GNmHrGMB5 tE5BAlsXlaETPgA/fMa8gASRWkQ7fVZ17w== X-Received: by 2002:adf:d1ca:0:b0:236:737f:8dfa with SMTP id b10-20020adfd1ca000000b00236737f8dfamr7229293wrd.588.1666716013222; Tue, 25 Oct 2022 09:40:13 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id z12-20020a05600c220c00b003cd9c26a0basm2971084wml.40.2022.10.25.09.40.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 09:40:12 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 15/30] target/arm: Don't shift attrs in get_phys_addr_lpae Date: Tue, 25 Oct 2022 17:39:37 +0100 Message-Id: <20221025163952.4131046-16-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221025163952.4131046-1-peter.maydell@linaro.org> References: <20221025163952.4131046-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x436.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 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson Leave the upper and lower attributes in the place they originate from in the descriptor. Shifting them around is confusing, since one cannot read the bit numbers out of the manual. Also, new attributes have been added which would alter the shifts. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-id: 20221024051851.3074715-10-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/ptw.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 3302376e42e..691110f70c0 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1050,7 +1050,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, hwaddr descaddr, indexmask, indexmask_grainsize; uint32_t tableattrs; target_ulong page_size; - uint32_t attrs; + uint64_t attrs; int32_t stride; int addrsize, inputsize, outputsize; uint64_t tcr = regime_tcr(env, mmu_idx); @@ -1324,49 +1324,48 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, descaddr &= ~(hwaddr)(page_size - 1); descaddr |= (address & (page_size - 1)); /* Extract attributes from the descriptor */ - attrs = extract64(descriptor, 2, 10) - | (extract64(descriptor, 52, 12) << 10); + attrs = descriptor & (MAKE_64BIT_MASK(2, 10) | MAKE_64BIT_MASK(52, 12)); if (regime_is_stage2(mmu_idx)) { /* Stage 2 table descriptors do not include any attribute fields */ goto skip_attrs; } /* Merge in attributes from table descriptors */ - attrs |= nstable << 3; /* NS */ + attrs |= nstable << 5; /* NS */ guarded = extract64(descriptor, 50, 1); /* GP */ if (param.hpd) { /* HPD disables all the table attributes except NSTable. */ goto skip_attrs; } - attrs |= extract32(tableattrs, 0, 2) << 11; /* XN, PXN */ + attrs |= extract64(tableattrs, 0, 2) << 53; /* XN, PXN */ /* * The sense of AP[1] vs APTable[0] is reversed, as APTable[0] == 1 * means "force PL1 access only", which means forcing AP[1] to 0. */ - attrs &= ~(extract32(tableattrs, 2, 1) << 4); /* !APT[0] => AP[1] */ - attrs |= extract32(tableattrs, 3, 1) << 5; /* APT[1] => AP[2] */ + attrs &= ~(extract64(tableattrs, 2, 1) << 6); /* !APT[0] => AP[1] */ + attrs |= extract32(tableattrs, 3, 1) << 7; /* APT[1] => AP[2] */ skip_attrs: /* * Here descaddr is the final physical address, and attributes * are all in attrs. */ - if ((attrs & (1 << 8)) == 0) { + if ((attrs & (1 << 10)) == 0) { /* Access flag */ fi->type = ARMFault_AccessFlag; goto do_fault; } - ap = extract32(attrs, 4, 2); + ap = extract32(attrs, 6, 2); if (regime_is_stage2(mmu_idx)) { ns = mmu_idx == ARMMMUIdx_Stage2; - xn = extract32(attrs, 11, 2); + xn = extract64(attrs, 53, 2); result->f.prot = get_S2prot(env, ap, xn, s1_is_el0); } else { - ns = extract32(attrs, 3, 1); - xn = extract32(attrs, 12, 1); - pxn = extract32(attrs, 11, 1); + ns = extract32(attrs, 5, 1); + xn = extract64(attrs, 54, 1); + pxn = extract64(attrs, 53, 1); result->f.prot = get_S1prot(env, mmu_idx, aarch64, ap, ns, xn, pxn); } @@ -1391,10 +1390,10 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, if (regime_is_stage2(mmu_idx)) { result->cacheattrs.is_s2_format = true; - result->cacheattrs.attrs = extract32(attrs, 0, 4); + result->cacheattrs.attrs = extract32(attrs, 2, 4); } else { /* Index into MAIR registers for cache attributes */ - uint8_t attrindx = extract32(attrs, 0, 3); + uint8_t attrindx = extract32(attrs, 2, 3); uint64_t mair = env->cp15.mair_el[regime_el(env, mmu_idx)]; assert(attrindx <= 7); result->cacheattrs.is_s2_format = false; @@ -1409,7 +1408,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, if (param.ds) { result->cacheattrs.shareability = param.sh; } else { - result->cacheattrs.shareability = extract32(attrs, 6, 2); + result->cacheattrs.shareability = extract32(attrs, 8, 2); } result->f.phys_addr = descaddr;