From patchwork Thu Feb 23 20:43:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655997 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp538915wrb; Thu, 23 Feb 2023 12:44:47 -0800 (PST) X-Google-Smtp-Source: AK7set8SGQAqHj+8/OPXgDPA7Sg+zQPQ4N5BnntEvBy8NGWn0JiRXkV7Rricu13TT4vxapHev+yQ X-Received: by 2002:a05:622a:15d2:b0:3b8:2c34:b9f2 with SMTP id d18-20020a05622a15d200b003b82c34b9f2mr23869161qty.63.1677185087226; Thu, 23 Feb 2023 12:44:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677185087; cv=none; d=google.com; s=arc-20160816; b=InmEDId5/wUZRdJXsBWscTwraSBZBS0gozQytbzd8QndC8QfAtr1jvqPLcLbJkoiFv tSu7DtUr1Id3jaJVz/aJCq61vnzsjZSkwCcc6cznmaj8fCfFhc7qWiLrHn8hl6B9hHeO 2x0FaBprDbx+MsQ7o9O2fbI6PlVB+43uYLaaGHQq4KhCdw/2Q7uuOU0Gz20oib/tMIwu WqtNrTE9ClLnkdZLpA5ztKRulvLaMeXzt1kVsnsguxmuasR+l5Ol8A2XqmQfq9h6V59h O79yMfubZONS8nl23Tide8D77SuGoYeiNA9rRoaMmmNihvy7mqR9jKZjbxjJJmnNGIVC 9MhQ== 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=4VpqcMOXVlrjqv2u2QyFnc/vNdrKfYNKBg4oxbaB+0Q=; b=UWi5Q8QbvU3WluBuHHzgo/hrj2ZTJWidNItOcxxrbRpnaXO+UsodE93TAEL8dKMCO4 U5wQpk7ICTG/TS1Q7GwvRRwRrVW6Bh9QGwcx5uSnmYAJMJxgfHM76aCDj1dk9R0mkiOz AIlstCkcrCW8QN1QqW0wvQfPXEVKQ0ZzBykY3MHA12nIQl8V8Bx0Ipe14H51VYTSSFp8 3uuhRgAy6ps7mk97w7GML+HYRi+ApWJgqRUxCSw0p1wjfROJ+eu1u3qjbm2BoPUlz3Uj JYgqprrI7o+MupdbTqyjz0DdR/qc4ukZf2bb+KTQxt/eyIOPGyWdEEb01FhrX7bJQRac GHuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="AeF+e/q1"; 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 u1-20020a05622a010100b003b852fc2c43si4334050qtw.434.2023.02.23.12.44.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Feb 2023 12:44:47 -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="AeF+e/q1"; 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 1pVIRn-0002yx-D5; Thu, 23 Feb 2023 15:44:11 -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 1pVIRl-0002yG-SF for qemu-devel@nongnu.org; Thu, 23 Feb 2023 15:44:09 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVIRk-0007UY-4D for qemu-devel@nongnu.org; Thu, 23 Feb 2023 15:44:09 -0500 Received: by mail-pl1-x644.google.com with SMTP id u14so10582589ple.7 for ; Thu, 23 Feb 2023 12:44:07 -0800 (PST) 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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4VpqcMOXVlrjqv2u2QyFnc/vNdrKfYNKBg4oxbaB+0Q=; b=AeF+e/q1u6JXtK32KfD1tGeD3rTzWOTE9LnYz4oGELCJM5mBGEI71BjB61EQKWLjTu GhaWy0x0Bugy1WnUIv7T7ixAT/3e4biWSymK2/bkfvPn2SbIa0rFcYKOtFv9JJTHUr6j 4MkdEkLBrZwLlEnxyV3aWx0WvofrodjuGgb8JnP8snXqf5XM9I5r2gynqw4NIOzOzj56 T/KZ5oeLtK+0r6hSe9uuZfBGKPsYOp5GQ5W1RXKHSP1aJMOkJgBxcjm71pvgClGFihXp opjHUO/9Hi5x5lCDOTqXJuOCGHw0ygw3uBVr7b5/vlnpLwxhoc+eXzsugl2sMwDsn/Sx Efkw== 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:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4VpqcMOXVlrjqv2u2QyFnc/vNdrKfYNKBg4oxbaB+0Q=; b=wQ0tbFYeZ7BWoWv6I/8ZxbBTZTsVClw165P0X0LPvB1ALY4IbBfPvFoM1Q5kA767Ec KWsqNaBmzDtKk6Pqe9qI7tt+RO1zA+fImbTX26lBBVq3iVMq2yWRUsxl0IEwTvkr2UuF 7qLCgv8+E+U5CjyXGq3fkO8L33+CYlAzrMP4gO/jBUEVpnJKFEC7X58XMRnPJkESl3pp TphBPkvVWAskwrJJYZlvHQPA2VkA/3KQpxFM1wzJ5JIiqtnptv6IP7iRkVFEkzVBKFQt GaOiMXno/vDJiaL3sw1TRbdrvZ2wOz6lGHJFq0u4yT7zXITynqQjkJisu3sD8EMCHoiV DisQ== X-Gm-Message-State: AO0yUKX882xrpSOVtkeE2ZmPH0qPxAfibivzxLtvwIcBjuggvThobHKd HrdWuac84hbtvLD+XVEylr53T5QZ6vBs4NIKgPOdrA== X-Received: by 2002:a05:6a20:6530:b0:cc:59a7:65ae with SMTP id n48-20020a056a20653000b000cc59a765aemr625929pzg.24.1677185046622; Thu, 23 Feb 2023 12:44:06 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id e187-20020a6369c4000000b004b1fef0bf16sm5992850pgc.73.2023.02.23.12.44.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 12:44:06 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Idan Horowitz Subject: [PATCH 12/13] target/arm: Do memory type alignment check when translation disabled Date: Thu, 23 Feb 2023 10:43:41 -1000 Message-Id: <20230223204342.1093632-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230223204342.1093632-1-richard.henderson@linaro.org> References: <20230223204342.1093632-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::644; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x644.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=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-bounces+patch=linaro.org@nongnu.org If translation is disabled, the default memory type is Device, which requires alignment checking. This is more optimially done early via the MemOp given to the TCG memory operation. Reported-by: Idan Horowitz Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1204 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- target/arm/helper.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 07d4100365..b1b664e0ad 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11867,6 +11867,37 @@ 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) @@ -11936,8 +11967,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); } @@ -12037,7 +12069,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); }