From patchwork Fri Mar 1 20:41:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777072 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1555482wrn; Fri, 1 Mar 2024 12:43:20 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVVsLzLdOcbXvNs1oZaxvaz1hG2aW3G/WLqtLRIV+Xwhn+t9PnYKpMm2bWrpLqm3nzZXV/5knRt1nCNSnzqyBFF X-Google-Smtp-Source: AGHT+IGbFekDBndUWetbaLolEQo+XxFrzDCd2rOk2HoNrBCZ2xdZueHkg402+HteYCrHxfXP4bSX X-Received: by 2002:ad4:4815:0:b0:690:182c:d398 with SMTP id qd21-20020ad44815000000b00690182cd398mr3419846qvb.0.1709325800249; Fri, 01 Mar 2024 12:43:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709325800; cv=none; d=google.com; s=arc-20160816; b=txdqE+c71K0gBJ4wQBZy2gKegASmeiGHQ1Gv3FYlfVENdd5RblmA6AHR2m/ksLm3aS 4UPsFqfaBmB6bMlW4yBKQwDg/Gs+QAt/wOiQ2RqWUYkO6raomp+mxdTJGOG7zRIAoa2a JrH+XD9/6IrJvb5S9UVIXZlYPq4dWcD/dB3AvCS1j7ONhpmpBV1Q4iiuxdWGQmk6+01s 8zksvIEHBpl7jRtb2ImoDMwJm1qjaEgEOfs+MYHYoP2XRA+fcdaxDFsm4fTwVUkCJ2rr tf/igisf5Oi4sodZRDZeVr4jM11+hinN9NONggxlZd6TV6OkXZgvpET/Cqvy99tg7ijd ggBg== 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=9Kev1JbGsH8SPuVfwyjwv2zI6xwvmoOl1CfSqGhDN5g=; fh=X6WeDsGLRGf50j0Uf29WVs/9IAwsZZZhxH8c0rS+hfU=; b=dzeuZJ5y1zNLtEBDhs/ageM58MZ18E5uEH6aUNzrszA3IDlvoKdSM4P/GEoP8jbuBL oRt8lMg11FevSlBLcbZXoJzXG7BHnAwoSG/GImzZsDHnN3nGSOPSIxkqwnoJyk5BDqbc W2ubv4gZ83hhOrD9tQUrW0w7CyiXXNtekZhNpfeVsYw728VILDP0Xu6ovzU8Vki5wTG7 8oMDuU8aEWqAzt/1fdKpwL2AcLCSyXMUalWvoofBBkDgWsHJbj76iiX/MKxhUW3GYFO5 qm24AVrlZTKfdnbp0V01X+YF1O6s6PrAL70eBZpo8OS1KpaeIqDnh8iQzsXyCjGSTZs+ sitQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AD0X293s; 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 pi18-20020a0562144a9200b0068caccd5f77si4270591qvb.214.2024.03.01.12.43.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 12:43:20 -0800 (PST) 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=AD0X293s; 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 1rg9h8-000200-Ga; Fri, 01 Mar 2024 15:41:26 -0500 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 1rg9h6-0001yz-NI for qemu-devel@nongnu.org; Fri, 01 Mar 2024 15:41:24 -0500 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rg9h5-0006zk-3b for qemu-devel@nongnu.org; Fri, 01 Mar 2024 15:41:24 -0500 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5bdbe2de25fso2048025a12.3 for ; Fri, 01 Mar 2024 12:41:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709325681; x=1709930481; 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=9Kev1JbGsH8SPuVfwyjwv2zI6xwvmoOl1CfSqGhDN5g=; b=AD0X293sR33vul23ICEgKF0ZARYgH6FiQECEvBIRq98p45Ug5WG8Ts9ftxF4Wplmqg JiyZ12OTPent3DOId430dDaH2kIO7dqOpU4qzGXjglc9kXwI1HUIS9FsQiyDp8J6PVPn sc3tPu5alDsLE15z9bDpcFN4LXgWcKDn5bHzCMhh2Kjn16BPUJKYrBH9pMSWWcpIKLD+ B6b1cLohHaXTvL8epL4y9y/hkn5OJVinhqi8d7O36yEWH3ofY0r7Cmj7xsdhatBxSFLn +TFc71oY+1qeBo1Hz5xMAhMkEblR72cQBDocFgMp2Y+spBynRVy0gZbRcJVFvb0SN5JB WuyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709325681; x=1709930481; 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=9Kev1JbGsH8SPuVfwyjwv2zI6xwvmoOl1CfSqGhDN5g=; b=Rlv7EVwTRSk0rsmx3KZf2ofIFke0G4Qo3HeqDKJcgKywNZAjLnl7btBFLpI134WnfL q2CWFHm8w0tSrWT2UXtms4ZyoUgMCeqDVwjNmgF1K73htneT9hkxZ0j2CBS+LmUtm7Fn SP7dXSMt8Ij6gHcGHmM6oiy+5sF6YgNxJE0t4Jqvi5jHRsNlUpWFNmVbwW2uxGOlzfGJ m04TEqMAKB1hT15M0XiBhxF9/50MgSMqS0G0xgotX88nP1EixwEhouhynE38i3SGbN0s IMatx8CTYSUqEeRUofkQozlzw8R3db0I2Q1ILnVvLkd0y+lan151T/j0jl/0WVmxYNtj SN0Q== X-Gm-Message-State: AOJu0YwqdcAqxf161C+nHhHn2c3m4hHuUUwTa2MstQ81d6FibHQutRLY LJiPfWkg9zVgp4FW751YfbsvMccIu6yj5Rp1+yFiZ/TnDji+kXw9+chDtBimWPP+8c72M/MSxQt S X-Received: by 2002:a17:90a:4a0e:b0:29b:1073:c038 with SMTP id e14-20020a17090a4a0e00b0029b1073c038mr2745323pjh.32.1709325680787; Fri, 01 Mar 2024 12:41:20 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id l3-20020a17090ac58300b0029b2e00359esm681947pjt.36.2024.03.01.12.41.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 12:41:20 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Idan Horowitz Subject: [PATCH v3 5/6] target/arm: Do memory type alignment check when translation disabled Date: Fri, 1 Mar 2024 10:41:09 -1000 Message-Id: <20240301204110.656742-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301204110.656742-1-richard.henderson@linaro.org> References: <20240301204110.656742-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.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 If translation is disabled, the default memory type is Device, which requires alignment checking. This is more optimally done early via the MemOp given to the TCG memory operation. Reviewed-by: Philippe Mathieu-Daudé Reported-by: Idan Horowitz Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1204 Signed-off-by: Richard Henderson --- target/arm/tcg/hflags.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/target/arm/tcg/hflags.c b/target/arm/tcg/hflags.c index 8e5d35d922..5da1b0fc1d 100644 --- a/target/arm/tcg/hflags.c +++ b/target/arm/tcg/hflags.c @@ -26,6 +26,35 @@ static inline bool fgt_svc(CPUARMState *env, int el) FIELD_EX64(env->cp15.fgt_exec[FGTREG_HFGITR], HFGITR_EL2, SVC_EL1); } +/* Return true if memory alignment should be enforced. */ +static bool aprofile_require_alignment(CPUARMState *env, int el, uint64_t sctlr) +{ +#ifdef CONFIG_USER_ONLY + return false; +#else + /* Check the alignment enable bit. */ + if (sctlr & SCTLR_A) { + return true; + } + + /* + * If translation is disabled, then the default memory type is + * Device(-nGnRnE) instead of Normal, which requires that alignment + * be enforced. Since this affects all ram, it is most efficient + * to handle this during translation. + */ + if (sctlr & SCTLR_M) { + /* Translation enabled: memory type in PTE via MAIR_ELx. */ + return false; + } + if (el < 2 && (arm_hcr_el2_eff(env) & (HCR_DC | HCR_VM))) { + /* Stage 2 translation enabled: memory type in PTE. */ + return false; + } + return true; +#endif +} + static CPUARMTBFlags rebuild_hflags_common(CPUARMState *env, int fp_el, ARMMMUIdx mmu_idx, CPUARMTBFlags flags) @@ -121,8 +150,9 @@ static CPUARMTBFlags rebuild_hflags_a32(CPUARMState *env, int fp_el, { CPUARMTBFlags flags = {}; int el = arm_current_el(env); + uint64_t sctlr = arm_sctlr(env, el); - if (arm_sctlr(env, el) & SCTLR_A) { + if (aprofile_require_alignment(env, el, sctlr)) { DP_TBFLAG_ANY(flags, ALIGN_MEM, 1); } @@ -223,7 +253,7 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, sctlr = regime_sctlr(env, stage1); - if (sctlr & SCTLR_A) { + if (aprofile_require_alignment(env, el, sctlr)) { DP_TBFLAG_ANY(flags, ALIGN_MEM, 1); }