From patchwork Sun Jul 3 08:24:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 586838 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp2933669mab; Sun, 3 Jul 2022 02:15:04 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vxui94FPn7fyHphEhoXqamsjpXLjbiJbk3aDOfGUKR43WOzz0GsQoSDfuptJT4jMziqIgo X-Received: by 2002:a81:928c:0:b0:31c:7c9b:9ff2 with SMTP id j134-20020a81928c000000b0031c7c9b9ff2mr7813628ywg.490.1656839704390; Sun, 03 Jul 2022 02:15:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656839704; cv=none; d=google.com; s=arc-20160816; b=lxdH/iBYzlRrcOcHg8cNucoKoebklzP+3bladE8ujqLa/9eC8qk+i5BOFMIlbda1Xj cy2ccuua1oMk1ZEFIGrgIXFD07cYvV3KZGU6UL377SCMcNmMDcjf3dUKTEFn9zj5iANP HGffDms5EHavd9TojTyCBODJbrRGZK+8OKRFAip0aRZ1x2mnjbvHsu6zs9hbMUsciITm Pnr7Q71dCijJKuQ1uBhyEv2ZOSqShPykPsCYhYjoyx9GcjYG0j/BpRde3rOc+x7j8TlI 4ZRvUb/BhhsZ5okoERHAI2wt/u5Sj6Uy7bF1y+yJ5MY4h5dSXf6QRfLpcJz+dms2xDbr GhhQ== 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=czDINC237o/2raNbHTOaskPo+9bv5Oqa4q6sEcK6I78=; b=TLAdLEE18CZaQgv1u8GyNLYJrQvvxK2nWlNnfDvZf0PBULSvp8xFv8NhhxN0gZXh8a hNd+WCiL+1vXnwpWJTsM+aGyUZS0xtUi12ACTgaaGV9jpOahdGqHuqWUilDYwuG1xkL5 oD1otno/zqWaeTXq+1rjCesLwXPaCqK4/MuNHBSfmkdJ5Fiiz6oJ1dSBfMNKaBg8e8ax dZGM3pnq4657+VnqQWGAWxeiBX8aAy98ptkGftgdoHTvcCVZQVGT8es78BLhK7+wMQSU VbgXInCVXsNOC+hzzZS6XI7kNEkNX9FY+cgUE1f+c8nto/Xt3zrpMrP9CVymFluZiLi2 /biQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hj7o0Y3r; 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 13-20020a810f0d000000b0031c8c52ab76si1290610ywp.30.2022.07.03.02.15.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 03 Jul 2022 02:15:04 -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=Hj7o0Y3r; 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]:33498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7vh1-0002ld-QE for patch@linaro.org; Sun, 03 Jul 2022 05:15:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7uzD-0000P6-Bw for qemu-devel@nongnu.org; Sun, 03 Jul 2022 04:29:47 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:53803) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o7uz6-0006fs-Jo for qemu-devel@nongnu.org; Sun, 03 Jul 2022 04:29:47 -0400 Received: by mail-pj1-x1035.google.com with SMTP id ju17so1431280pjb.3 for ; Sun, 03 Jul 2022 01:29:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=czDINC237o/2raNbHTOaskPo+9bv5Oqa4q6sEcK6I78=; b=Hj7o0Y3r0lqvTyK2CYq3RAtYEkMqg5+A2HjmDvajpOo51ezGApVpCreR0ukp+GfmLu qF51M3RIYa2xn+n+52SoShWRg8l+8R4sY3WQP/mjvJttVW5ymSOcq7dco9OL1VlPNkJH gdgbD8posTwN6G+zLGMhYAlbqed9aQQpX8IMAMEdkGjGatchparTbVYDLnxcoD8pk1A7 MQ2sEX20DzMsDOGQm0w6FzwZKrVc+RCO6CozZXe+EMdmT2WEEwKO8KxnKgd+IQDlv79S W5TpZyjYLi5WUkpWm8V7xUqAKqG+H1epEe06JuXtL20AZnLbPbdQAAMQ3pDoHDrx/YnM Tlgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=czDINC237o/2raNbHTOaskPo+9bv5Oqa4q6sEcK6I78=; b=5H8h1dh4J0s4n/zw8P0r+ieH+fRfKGtYQXRzqY+0/NYnLWFOUt1dnT8peOU/l2G/fq KnyNpclqb8QaUMDAE6jlR31x8Q4VMpB9y3O9S6LxzUxh0wxwbFfQsS7v6vYXi51Hykqs ad5MFGhr61M+XpoEohavBLtfZrwEPhg2Pugl2NlEPlo537YedMa3i0iEUt5lE8o4YYiQ XgHsxBmGzQgTC68lJ5JHs2N91C+yhEkeRAcs1E/68332OjLFKXsXhDCyi//9DU341EVP wQXNOcbMEoVehl5eJmBnMc81BEd0GIKlJJfF7MCo/OMpsAwWP68UI88Rfn/C6dbbAcH8 fhZg== X-Gm-Message-State: AJIora/hbWMlQsASIxnRhlrMCG3rTNqQMBCx6VjRIU7z299iMqRp++rN i2YiJ8g3hb0qHtqddmr0HDIPO0FbXd9t5zrn X-Received: by 2002:a17:902:9046:b0:168:b8ee:8164 with SMTP id w6-20020a170902904600b00168b8ee8164mr28932579plz.159.1656836979283; Sun, 03 Jul 2022 01:29:39 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id g6-20020a1709026b4600b0016788487357sm18574523plt.132.2022.07.03.01.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Jul 2022 01:29:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 43/62] target/arm: Reorg get_phys_addr_disabled Date: Sun, 3 Jul 2022 13:54:00 +0530 Message-Id: <20220703082419.770989-44-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220703082419.770989-1-richard.henderson@linaro.org> References: <20220703082419.770989-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.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=unavailable 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" Use a switch. Do not apply memattr or shareability for Stage2 translations. Make sure to apply HCR_{DC,DCT} only to Regime_EL10, per the pseudocode in AArch64.S1DisabledOutput. Signed-off-by: Richard Henderson --- target/arm/ptw.c | 115 +++++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 48 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 0f4b9b0166..3a098882a6 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -2278,64 +2278,83 @@ static bool get_phys_addr_disabled(CPUARMState *env, target_ulong address, GetPhysAddrResult *result, ARMMMUFaultInfo *fi) { - uint64_t hcr; - uint8_t memattr; + uint64_t hcr = arm_hcr_el2_eff_secstate(env, is_secure); + uint8_t memattr, shareability; - if (mmu_idx != ARMMMUIdx_Stage2 && mmu_idx != ARMMMUIdx_Stage2_S) { - int r_el = regime_el(env, mmu_idx); - if (arm_el_is_aa64(env, r_el)) { - int pamax = arm_pamax(env_archcpu(env)); - uint64_t tcr = env->cp15.tcr_el[r_el].raw_tcr; - int addrtop, tbi; + switch (mmu_idx) { + case ARMMMUIdx_Stage2: + case ARMMMUIdx_Stage2_S: + memattr = 0x00; /* unused, but Device, nGnRnE */ + shareability = 0; /* unused, but non-shareable */ + break; - tbi = aa64_va_parameter_tbi(tcr, mmu_idx); - if (access_type == MMU_INST_FETCH) { - tbi &= ~aa64_va_parameter_tbid(tcr, mmu_idx); + case ARMMMUIdx_E10_0: + case ARMMMUIdx_E10_1: + case ARMMMUIdx_E10_1_PAN: + if (hcr & HCR_DC) { + if (hcr & HCR_DCT) { + memattr = 0xf0; /* Tagged, Normal, WB, RWA */ + } else { + memattr = 0xff; /* Normal, WB, RWA */ } - tbi = (tbi >> extract64(address, 55, 1)) & 1; - addrtop = (tbi ? 55 : 63); - - if (extract64(address, pamax, addrtop - pamax + 1) != 0) { - fi->type = ARMFault_AddressSize; - fi->level = 0; - fi->stage2 = false; - return 1; - } - - /* - * When TBI is disabled, we've just validated that all of the - * bits above PAMax are zero, so logically we only need to - * clear the top byte for TBI. But it's clearer to follow - * the pseudocode set of addrdesc.paddress. - */ - address = extract64(address, 0, 52); + shareability = 0; /* non-shareable */ + goto check_range; } + /* fall through */ + + default: + if (access_type == MMU_INST_FETCH) { + if (regime_sctlr(env, mmu_idx) & SCTLR_I) { + memattr = 0xee; /* Normal, WT, RA, NT */ + } else { + memattr = 0x44; /* Normal, NC, No */ + } + shareability = 2; /* Outer sharable */ + } else { + memattr = 0x00; /* unused, but Device, nGnRnE */ + shareability = 0; /* non-shareable */ + } + /* fall through */ + + check_range: + { + int r_el = regime_el(env, mmu_idx); + if (arm_el_is_aa64(env, r_el)) { + int pamax = arm_pamax(env_archcpu(env)); + uint64_t tcr = env->cp15.tcr_el[r_el].raw_tcr; + int addrtop, tbi; + + tbi = aa64_va_parameter_tbi(tcr, mmu_idx); + if (access_type == MMU_INST_FETCH) { + tbi &= ~aa64_va_parameter_tbid(tcr, mmu_idx); + } + tbi = (tbi >> extract64(address, 55, 1)) & 1; + addrtop = (tbi ? 55 : 63); + + if (extract64(address, pamax, addrtop - pamax + 1) != 0) { + fi->type = ARMFault_AddressSize; + fi->level = 0; + fi->stage2 = false; + return 1; + } + + /* + * When TBI is disabled, we've just validated that all of + * the bits above PAMax are zero, so logically we only + * need to clear the top byte for TBI. But it's clearer + * to follow the pseudocode set of addrdesc.paddress. + */ + address = extract64(address, 0, 52); + } + } + break; } result->phys = address; result->prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; result->page_size = TARGET_PAGE_SIZE; - - /* Fill in cacheattr a-la AArch64.TranslateAddressS1Off. */ - hcr = arm_hcr_el2_eff_secstate(env, is_secure); - result->cacheattrs.shareability = 0; result->cacheattrs.is_s2_format = false; - if (hcr & HCR_DC) { - if (hcr & HCR_DCT) { - memattr = 0xf0; /* Tagged, Normal, WB, RWA */ - } else { - memattr = 0xff; /* Normal, WB, RWA */ - } - } else if (access_type == MMU_INST_FETCH) { - if (regime_sctlr(env, mmu_idx) & SCTLR_I) { - memattr = 0xee; /* Normal, WT, RA, NT */ - } else { - memattr = 0x44; /* Normal, NC, No */ - } - result->cacheattrs.shareability = 2; /* outer sharable */ - } else { - memattr = 0x00; /* Device, nGnRnE */ - } + result->cacheattrs.shareability = shareability; result->cacheattrs.attrs = memattr; return 0; }