From patchwork Tue Oct 11 03:18:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614145 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2368667pvb; Mon, 10 Oct 2022 20:23:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6RCd9z6hFplftPqxhQNQ0gBDBlV2UfL5ToJajgYkdHWVPzNIQvJ4aE2bB1/lm+hvibPL68 X-Received: by 2002:a05:622a:34d:b0:35d:4338:463e with SMTP id r13-20020a05622a034d00b0035d4338463emr17568936qtw.559.1665458584777; Mon, 10 Oct 2022 20:23:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665458584; cv=none; d=google.com; s=arc-20160816; b=GZrl96LNXMHGKtCemYH/Va90zBXCW2VktmZXxsVchmywWYgiPa64jzKBN8Rqk1Nv4C HY+PPt3Cfb7414qA+R3dQ5wP0GFMVU17hrBAU8WgOKokdSYSUAtAl/xz8gSVofXyJAZj 0BvrtNtdXwjHVm9JYSDxf15wg67xKKxioahHYbAsHWziONpXUBP5qNWx7flvrwuN5RTF iu0P4aZIHwt+I/f26wEyOsVm3yNgDKxH8yWGiij/T21vEzKFNVwJ+7jprjtCr1skWWix +B1H//agsF8K96c1ZxWOd4b/6rsQ3ePVvZpqlD0o8sLyhVedJYWWVsvAGPdhFoJ0O7kB N3vg== 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=sfKD/zCeIYRQKq3df3kFwiCr1YlgQpiKDEPmo1WYAa8=; b=p0zcX2Gb2BHmJUkaAvL7rH5vhEwK/F93dLdqj2fdl80Tg7DcMQpxi2cmmW7YyZGpTK k0W2Dyd0HC/070yoRGIUlxZLNqQbC0F1e5+6txANZm25lrgs0k5kZiakvzz2jz2a+9lc WTKDcs9PedjU7c+xMW0O4I994/83ymgbC342o7ozS/B3369Ua0x9ngqRVnK9mBjh1DGi BLC/BFsG6LR+eFGp5imXLrSU3k1NFReYnAr2R3RLsIBi5cxrZJ2pi/VeqNHWtShIoU/u 9eMGO00QI22MnMKPGij7TrAXqPXfqOTLiAaL/fzSge5WVrndC0aP4xEYuAOm2QtX6EZQ k5rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q4Kh+Ofq; 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 6-20020ad45ba6000000b004ad1ff65311si5797980qvq.586.2022.10.10.20.23.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:23: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=Q4Kh+Ofq; 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]:59348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi5rE-0004n9-9M for patch@linaro.org; Mon, 10 Oct 2022 23:23:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5nr-0002Mq-Lh for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:35 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:51978) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5nc-0002zP-Vu for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:34 -0400 Received: by mail-pj1-x1035.google.com with SMTP id b15so11375604pje.1 for ; Mon, 10 Oct 2022 20:19:16 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sfKD/zCeIYRQKq3df3kFwiCr1YlgQpiKDEPmo1WYAa8=; b=Q4Kh+OfqNBXwng1azAIntY1pAvDIHMjnS2eC0EHHYt65A/Kf+28QHRAuE9SHWYKsUZ 971fd0G1QiQjr1u/+O4OziUJDZRwGyVddapTadoeh2tbrJ2VmjEs2XH8YRtujbBw/Kwb jLgCmYoPtUgFkKCbSgZNK6gbYvzbXgb3N9pVME5yl9fPb2C3ljzj9EfR58EgcQW1LF2F f+Ad3x2+12ss248p6BT7qXRGlBCsH4EcMeY91Hh0YnC3Y3gkHEmNpHb7HrkV6BxWxQFu O9JQjfc5KYrgjZ/m36UPWIdHC6OfvMupzqDqAE4MqYacFQYgquYMOsvVSy18r5eMi95l E2yQ== 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=sfKD/zCeIYRQKq3df3kFwiCr1YlgQpiKDEPmo1WYAa8=; b=eRqYVYZ6uEPyrMVdIfh4pGWDmPZJvL2Sm7GX8XMNVw1aj0CqVRrh5ZojsN2uHfOskB xXM12BGfZym7p9WYJ+zP4o3UWlE4JrlI/Xkms2oDmFIZdkA0MoD+W0QQUyTkDldwCs6g +Ccvbtpouy7g/nHKrDnhe2LwjgQxsgrFixxu4Zq3HMMpIbh5MdN4KEgaarlWYvD15gTc xNjUeK2B1MpmWSN9oP5BwoBpz/cjChzKdxmHj0xBRtAmBTZRVlJcxWu76BrVbeU983u6 mpE9n1UvhHR6vA7wEqJdqIYd06Km2zhQ+Ew1bWIk0kEuBiBish8jqzKQwp/HDP7qlgzQ +w+w== X-Gm-Message-State: ACrzQf37Qb+NwAiRIcaaS0aQdUAvy2qlcGp/14/LyO3UqtXd09rT6Cmj 9uvedO+NSmAsRUp5KjgHD0kOG2t+dsrDTg== X-Received: by 2002:a17:902:f7cf:b0:17f:9081:a3f7 with SMTP id h15-20020a170902f7cf00b0017f9081a3f7mr21742207plw.3.1665458355565; Mon, 10 Oct 2022 20:19:15 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 01/24] target/arm: Enable TARGET_PAGE_ENTRY_EXTRA Date: Mon, 10 Oct 2022 20:18:48 -0700 Message-Id: <20221011031911.2408754-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-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, 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" Copy attrs and shareability, into the TLB. This will eventually be used by S1_ptw_translate to report stage1 translation failures, and by do_ats_write to fill in PAR_EL1. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu-param.h | 12 ++++++++++++ target/arm/tlb_helper.c | 3 +++ 2 files changed, 15 insertions(+) diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h index 08681828ac..38347b0d20 100644 --- a/target/arm/cpu-param.h +++ b/target/arm/cpu-param.h @@ -30,6 +30,18 @@ */ # define TARGET_PAGE_BITS_VARY # define TARGET_PAGE_BITS_MIN 10 + +/* + * Cache the attrs and shareability fields from the page table entry. + * + * For ARMMMUIdx_Stage2*, pte_attrs is the S2 descriptor bits [5:2]. + * Otherwise, pte_attrs is the same as the MAIR_EL1 8-bit format. + * For shareability, as in the SH field of the VMSAv8-64 PTEs. + */ +# define TARGET_PAGE_ENTRY_EXTRA \ + uint8_t pte_attrs; \ + uint8_t shareability; + #endif #define NB_MMU_MODES 8 diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c index 49601394ec..353edbeb1d 100644 --- a/target/arm/tlb_helper.c +++ b/target/arm/tlb_helper.c @@ -236,6 +236,9 @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size, arm_tlb_mte_tagged(&res.f.attrs) = true; } + res.f.pte_attrs = res.cacheattrs.attrs; + res.f.shareability = res.cacheattrs.shareability; + tlb_set_page_full(cs, mmu_idx, address, &res.f); return true; } else if (probe) { From patchwork Tue Oct 11 03:18:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614143 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2368373pvb; Mon, 10 Oct 2022 20:21:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5iLIs+HwNWgayHH5E8EOK6/QViTquwicCbaHNDkGabKL6gOM+UZ42NhJSLJn5lN2M7+Idd X-Received: by 2002:a05:6214:2402:b0:4b1:85ab:489f with SMTP id fv2-20020a056214240200b004b185ab489fmr17146046qvb.108.1665458519830; Mon, 10 Oct 2022 20:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665458519; cv=none; d=google.com; s=arc-20160816; b=EfaeHODmMbMp45Q5HLwkwSC4l4YfXr3xwzgOQSGS5GiK3KMzRG4u4Job1MzhA1Md7M ZHF0cD+0hFuMZw7dD2bJXUM62DDb7Uge9pXEudQ0I4UEZ6M4JwNap4NTxqIEigTMdgve zm+7oaDm5NAkh3QeXbsY6YZBFTTaww4Rln0ps+TwpgHX7FLAfcAaO4tuWktX9abULZGM mDIR5GOF07BeNvEvdL6ArsUiw2FkzvGq1A94mGajyrjQ4sLdxa9xnQ9QihjP/26cEmWt jcYctz0e72qtpUIhdZ5KycI724D1JLoH7ybqo/T6fNft8elGcek3Xxh0+zEV617mq/7x YMuQ== 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=fY8yhQpot0821zpGNnQAKGBDxiudNh30O/yfChIFj6w=; b=1JlVxta5iUPdw/QaD8yGL4IomgN26hf/CqvRa/4v+53CJDFFiVaiEKRnKE3HSZDImh kUpinkcuu3xNIi3jmB5kKIUQVDD1XF7sTVyLYEIEjvQ6UPA0CvWmNNin02W9It8bZcGy qCCwCzr9ORwHK1ebIU1ZIRheGtOnhilsK3mGRl54r+mrFqj+tKe1s+7F1bIc2ORFy/VU nEo2NJoMslOVNrI7nR79f9j8DPfJbzxHVQiPnuJOZM/iFtA1kmUiUQHSQtGrXu8UOVl3 gQyjHmSymWLFtMDxEQkDqFKwVQmhkhyEkCsbl8X+OQLdgPN8g1sWdD+rS3kYLqdZjkUd hHJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rE1xLZuw; 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 gs12-20020a056214226c00b004a3789193c7si5837272qvb.144.2022.10.10.20.21.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:21:59 -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=rE1xLZuw; 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]:60294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi5qB-0003Is-9k for patch@linaro.org; Mon, 10 Oct 2022 23:21:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5nj-0002Ed-99 for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:27 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:39554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5nc-0002zo-Bj for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:26 -0400 Received: by mail-pj1-x1034.google.com with SMTP id v10-20020a17090a634a00b00205e48cf845so14724615pjs.4 for ; Mon, 10 Oct 2022 20:19:18 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fY8yhQpot0821zpGNnQAKGBDxiudNh30O/yfChIFj6w=; b=rE1xLZuw5r90I6HaqmWcnrmr+GjhQD95JUkb4LHHuaoaebp47FhMVQUO/F2a/A/nrA +G+JOhK8qh+OfSGGPQr+WTPtPecElXxr2xceGSBc2amyPJCqljOFUXdG+sBIWrXicRIn YnmzkzDDrl8uWGWBWmPNLb3yU9RVN1NhKn4J8PM4ntR9wMoHgP8CbGxzEIOiwOZs1+Pm mvv+5nvynvNJuK+gqAgdAYDLmQeFyik8Yk9zxGhRG9oVCy2CQm/yhfV40AzU+1clqtkH NhWnYBBFUpKUs3gQGEJfSAmWTz5OfHODdXTp2j7/uDf2s/3xI9Crhtl4XPrSflvXui7T DM1Q== 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=fY8yhQpot0821zpGNnQAKGBDxiudNh30O/yfChIFj6w=; b=FLHeF461e0bkBC8i6tpZo0fz4O3pgqPLWv3mlta3Ppvey2qDUsJo0gy8o+yRc4pk+I wXOLo9uhpP+t8LhQjgCHz7lznzdI/6wNidN6QY7aob8sTITFIxQpGOzpMsQR696YyLRD oVVrI0Pto3lcP96oocNASY4ncdfmRsSVn/EFLUmwIsNegZoOer6Qzy1x9K0qVtigWBAH ZqZ/BgewUuGJcexiMmT9Bn0t+3W9VVAqSf8sPTf/DcEkcc/4jZsHHUfbXQw33AeQcEQF fOzaSqzIik4QPMZSA4uRouc386Ym46c/jogFahk9JaF7CwCQwpIpagmlZgtZfYNhx8uS lfqg== X-Gm-Message-State: ACrzQf1YYsk2aQN+jJgYiw/EKUeeu3kJM+hsaKxmgroZbeeIamC9XyOR ugZmeQyi4QMN/yVcLwqe2vrFbA3cCP9Rvw== X-Received: by 2002:a17:90b:2246:b0:201:d6d6:9809 with SMTP id hk6-20020a17090b224600b00201d6d69809mr24503289pjb.159.1665458356963; Mon, 10 Oct 2022 20:19:16 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 02/24] target/arm: Use probe_access_full for MTE Date: Mon, 10 Oct 2022 20:18:49 -0700 Message-Id: <20221011031911.2408754-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1034.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" The CPUTLBEntryFull structure now stores the original pte attributes, as well as the physical address. Therefore, we no longer need a separate bit in MemTxAttrs, nor do we need to walk the tree of memory regions. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 1 - target/arm/sve_ldst_internal.h | 1 + target/arm/mte_helper.c | 62 ++++++++++------------------------ target/arm/sve_helper.c | 54 ++++++++++------------------- target/arm/tlb_helper.c | 4 --- 5 files changed, 36 insertions(+), 86 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 1a909a1b43..f09ec8aa03 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3400,7 +3400,6 @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) * generic target bits directly. */ #define arm_tlb_bti_gp(x) (typecheck_memtxattrs(x)->target_tlb_bit0) -#define arm_tlb_mte_tagged(x) (typecheck_memtxattrs(x)->target_tlb_bit1) /* * AArch64 usage of the PAGE_TARGET_* bits for linux-user. diff --git a/target/arm/sve_ldst_internal.h b/target/arm/sve_ldst_internal.h index b5c473fc48..4f159ec4ad 100644 --- a/target/arm/sve_ldst_internal.h +++ b/target/arm/sve_ldst_internal.h @@ -134,6 +134,7 @@ typedef struct { void *host; int flags; MemTxAttrs attrs; + bool tagged; } SVEHostPage; bool sve_probe_page(SVEHostPage *info, bool nofault, CPUARMState *env, diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c index fdd23ab3f8..e85208339e 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -105,10 +105,9 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, TARGET_PAGE_BITS - LOG2_TAG_GRANULE - 1); return tags + index; #else - uintptr_t index; CPUTLBEntryFull *full; + MemTxAttrs attrs; int in_page, flags; - ram_addr_t ptr_ra; hwaddr ptr_paddr, tag_paddr, xlat; MemoryRegion *mr; ARMASIdx tag_asi; @@ -124,30 +123,12 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, * valid. Indicate to probe_access_flags no-fault, then assert that * we received a valid page. */ - flags = probe_access_flags(env, ptr, ptr_access, ptr_mmu_idx, - ra == 0, &host, ra); + flags = probe_access_full(env, ptr, ptr_access, ptr_mmu_idx, + ra == 0, &host, &full, ra); assert(!(flags & TLB_INVALID_MASK)); - /* - * Find the CPUTLBEntryFull for ptr. This *must* be present in the TLB - * because we just found the mapping. - * TODO: Perhaps there should be a cputlb helper that returns a - * matching tlb entry + iotlb entry. - */ - index = tlb_index(env, ptr_mmu_idx, ptr); -# ifdef CONFIG_DEBUG_TCG - { - CPUTLBEntry *entry = tlb_entry(env, ptr_mmu_idx, ptr); - target_ulong comparator = (ptr_access == MMU_DATA_LOAD - ? entry->addr_read - : tlb_addr_write(entry)); - g_assert(tlb_hit(comparator, ptr)); - } -# endif - full = &env_tlb(env)->d[ptr_mmu_idx].fulltlb[index]; - /* If the virtual page MemAttr != Tagged, access unchecked. */ - if (!arm_tlb_mte_tagged(&full->attrs)) { + if (full->pte_attrs != 0xf0) { return NULL; } @@ -162,6 +143,14 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, return NULL; } + /* + * Remember these values across the second lookup below, + * which may invalidate this pointer via tlb resize. + */ + ptr_paddr = full->phys_addr; + attrs = full->attrs; + full = NULL; + /* * The Normal memory access can extend to the next page. E.g. a single * 8-byte access to the last byte of a page will check only the last @@ -170,9 +159,8 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, */ in_page = -(ptr | TARGET_PAGE_MASK); if (unlikely(ptr_size > in_page)) { - void *ignore; - flags |= probe_access_flags(env, ptr + in_page, ptr_access, - ptr_mmu_idx, ra == 0, &ignore, ra); + flags |= probe_access_full(env, ptr + in_page, ptr_access, + ptr_mmu_idx, ra == 0, &host, &full, ra); assert(!(flags & TLB_INVALID_MASK)); } @@ -180,33 +168,17 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, if (unlikely(flags & TLB_WATCHPOINT)) { int wp = ptr_access == MMU_DATA_LOAD ? BP_MEM_READ : BP_MEM_WRITE; assert(ra != 0); - cpu_check_watchpoint(env_cpu(env), ptr, ptr_size, - full->attrs, wp, ra); + cpu_check_watchpoint(env_cpu(env), ptr, ptr_size, attrs, wp, ra); } - /* - * Find the physical address within the normal mem space. - * The memory region lookup must succeed because TLB_MMIO was - * not set in the cputlb lookup above. - */ - mr = memory_region_from_host(host, &ptr_ra); - tcg_debug_assert(mr != NULL); - tcg_debug_assert(memory_region_is_ram(mr)); - ptr_paddr = ptr_ra; - do { - ptr_paddr += mr->addr; - mr = mr->container; - } while (mr); - /* Convert to the physical address in tag space. */ tag_paddr = ptr_paddr >> (LOG2_TAG_GRANULE + 1); /* Look up the address in tag space. */ - tag_asi = full->attrs.secure ? ARMASIdx_TagS : ARMASIdx_TagNS; + tag_asi = attrs.secure ? ARMASIdx_TagS : ARMASIdx_TagNS; tag_as = cpu_get_address_space(env_cpu(env), tag_asi); mr = address_space_translate(tag_as, tag_paddr, &xlat, NULL, - tag_access == MMU_DATA_STORE, - full->attrs); + tag_access == MMU_DATA_STORE, attrs); /* * Note that @mr will never be NULL. If there is nothing in the address diff --git a/target/arm/sve_helper.c b/target/arm/sve_helper.c index 9cae8fd352..3d0d2987cd 100644 --- a/target/arm/sve_helper.c +++ b/target/arm/sve_helper.c @@ -5351,8 +5351,19 @@ bool sve_probe_page(SVEHostPage *info, bool nofault, CPUARMState *env, */ addr = useronly_clean_ptr(addr); +#ifdef CONFIG_USER_ONLY flags = probe_access_flags(env, addr, access_type, mmu_idx, nofault, &info->host, retaddr); + memset(&info->attrs, 0, sizeof(info->attrs)); + /* Require both ANON and MTE; see allocation_tag_mem(). */ + info->tagged = (flags & PAGE_ANON) && (flags & PAGE_MTE); +#else + CPUTLBEntryFull *full; + flags = probe_access_full(env, addr, access_type, mmu_idx, nofault, + &info->host, &full, retaddr); + info->attrs = full->attrs; + info->tagged = full->pte_attrs == 0xf0; +#endif info->flags = flags; if (flags & TLB_INVALID_MASK) { @@ -5362,33 +5373,6 @@ bool sve_probe_page(SVEHostPage *info, bool nofault, CPUARMState *env, /* Ensure that info->host[] is relative to addr, not addr + mem_off. */ info->host -= mem_off; - -#ifdef CONFIG_USER_ONLY - memset(&info->attrs, 0, sizeof(info->attrs)); - /* Require both MAP_ANON and PROT_MTE -- see allocation_tag_mem. */ - arm_tlb_mte_tagged(&info->attrs) = - (flags & PAGE_ANON) && (flags & PAGE_MTE); -#else - /* - * Find the iotlbentry for addr and return the transaction attributes. - * This *must* be present in the TLB because we just found the mapping. - */ - { - uintptr_t index = tlb_index(env, mmu_idx, addr); - -# ifdef CONFIG_DEBUG_TCG - CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr); - target_ulong comparator = (access_type == MMU_DATA_LOAD - ? entry->addr_read - : tlb_addr_write(entry)); - g_assert(tlb_hit(comparator, addr)); -# endif - - CPUTLBEntryFull *full = &env_tlb(env)->d[mmu_idx].fulltlb[index]; - info->attrs = full->attrs; - } -#endif - return true; } @@ -5617,7 +5601,7 @@ void sve_cont_ldst_mte_check(SVEContLdSt *info, CPUARMState *env, intptr_t mem_off, reg_off, reg_last; /* Process the page only if MemAttr == Tagged. */ - if (arm_tlb_mte_tagged(&info->page[0].attrs)) { + if (info->page[0].tagged) { mem_off = info->mem_off_first[0]; reg_off = info->reg_off_first[0]; reg_last = info->reg_off_split; @@ -5638,7 +5622,7 @@ void sve_cont_ldst_mte_check(SVEContLdSt *info, CPUARMState *env, } mem_off = info->mem_off_first[1]; - if (mem_off >= 0 && arm_tlb_mte_tagged(&info->page[1].attrs)) { + if (mem_off >= 0 && info->page[1].tagged) { reg_off = info->reg_off_first[1]; reg_last = info->reg_off_last[1]; @@ -6017,7 +6001,7 @@ void sve_ldnfff1_r(CPUARMState *env, void *vg, const target_ulong addr, * Disable MTE checking if the Tagged bit is not set. Since TBI must * be set within MTEDESC for MTE, !mtedesc => !mte_active. */ - if (!arm_tlb_mte_tagged(&info.page[0].attrs)) { + if (!info.page[0].tagged) { mtedesc = 0; } @@ -6568,7 +6552,7 @@ void sve_ld1_z(CPUARMState *env, void *vd, uint64_t *vg, void *vm, cpu_check_watchpoint(env_cpu(env), addr, msize, info.attrs, BP_MEM_READ, retaddr); } - if (mtedesc && arm_tlb_mte_tagged(&info.attrs)) { + if (mtedesc && info.tagged) { mte_check(env, mtedesc, addr, retaddr); } if (unlikely(info.flags & TLB_MMIO)) { @@ -6585,7 +6569,7 @@ void sve_ld1_z(CPUARMState *env, void *vd, uint64_t *vg, void *vm, msize, info.attrs, BP_MEM_READ, retaddr); } - if (mtedesc && arm_tlb_mte_tagged(&info.attrs)) { + if (mtedesc && info.tagged) { mte_check(env, mtedesc, addr, retaddr); } tlb_fn(env, &scratch, reg_off, addr, retaddr); @@ -6786,9 +6770,7 @@ void sve_ldff1_z(CPUARMState *env, void *vd, uint64_t *vg, void *vm, (env_cpu(env), addr, msize) & BP_MEM_READ)) { goto fault; } - if (mtedesc && - arm_tlb_mte_tagged(&info.attrs) && - !mte_probe(env, mtedesc, addr)) { + if (mtedesc && info.tagged && !mte_probe(env, mtedesc, addr)) { goto fault; } @@ -6974,7 +6956,7 @@ void sve_st1_z(CPUARMState *env, void *vd, uint64_t *vg, void *vm, info.attrs, BP_MEM_WRITE, retaddr); } - if (mtedesc && arm_tlb_mte_tagged(&info.attrs)) { + if (mtedesc && info.tagged) { mte_check(env, mtedesc, addr, retaddr); } } diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c index 353edbeb1d..3462a6ea14 100644 --- a/target/arm/tlb_helper.c +++ b/target/arm/tlb_helper.c @@ -231,10 +231,6 @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size, res.f.phys_addr &= TARGET_PAGE_MASK; address &= TARGET_PAGE_MASK; } - /* Notice and record tagged memory. */ - if (cpu_isar_feature(aa64_mte, cpu) && res.cacheattrs.attrs == 0xf0) { - arm_tlb_mte_tagged(&res.f.attrs) = true; - } res.f.pte_attrs = res.cacheattrs.attrs; res.f.shareability = res.cacheattrs.shareability; From patchwork Tue Oct 11 03:18:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614144 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2368486pvb; Mon, 10 Oct 2022 20:22:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6pGHCHh9CWTM5dfyTc3mDUBFhAhwdufQygYEPMoevNn3A5Kzek9ctnq1yMk7q6qGqYOrRc X-Received: by 2002:a05:620a:191c:b0:6ed:88c5:e839 with SMTP id bj28-20020a05620a191c00b006ed88c5e839mr4208471qkb.627.1665458550101; Mon, 10 Oct 2022 20:22:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665458550; cv=none; d=google.com; s=arc-20160816; b=d+a3f7NQv/t7ReHbIjKccLHHZlfsTfKVIYZ34xPRXt2m/g2o91wEozn+7LpKv4vR++ ggzskATExafNz0SkgESG6LPLQ0c6dnZNLQOtiOouoxrmg338zF7SCtt3HSKw4VpS92yX YF221xT9oF+x0TMHm+7VQLZbTXBPefXZN37OwbpMbYSRctz0q1wJ4SMEnahY5Sbn8/+2 pk4Dg0V8ihSnwRERzuxZXW6z/vf+uhXqq5V31rD7EsjKod/mBgZm+KJeAresCZ46wm7i leJ1EwXoVuyhGh9EuIOgNzJbdv6pNiSIVzNkuFrp+FSk01xZP9/RuOgTklknUVIpzecy 3yxQ== 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=rJhyjafjgqKk8I6LVsm5b/FzC0MtOu7IjX7/w4ZcQiI=; b=b+bb9iw/jD+ZvbEsoYsyhpKA0OQw0qgogZ/GJaF3URnjHwLOz3FRR5eWA8kIyK6tbl KfujeqFLJtRdsqVCYU2ONxNuGSHsCX21O21ac3S8Wr2LQevxia1im3WXJ4q9amfiIH6A 2yamTADr0aD0kxYFJpDL08visUVlznRLxAEw9MMAfZwuhxDWlxfQs38px9prdCOKjstM JWvysCJ1WhDj1NyPbQv/JEl73c7L4FQrNypiWST/DhK+4Lj0P1aVcim2Z6z/N8TztKIt cbgM1U3oOmFWviSkcKiaj8okHhRt/RErtGMqkKd0ha5OQa/2NkeJPXzz8HyH1yNuL4Gr eQVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZOC0dIoz; 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 v124-20020a37dc82000000b006cea2e5a52csi6040597qki.347.2022.10.10.20.22.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:22:30 -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=ZOC0dIoz; 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]:36556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi5qf-0004Eu-Jv for patch@linaro.org; Mon, 10 Oct 2022 23:22:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5nk-0002FH-Td for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:30 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:46051) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5nc-0002zw-Vv for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:27 -0400 Received: by mail-pl1-x635.google.com with SMTP id i6so6958305pli.12 for ; Mon, 10 Oct 2022 20:19:19 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rJhyjafjgqKk8I6LVsm5b/FzC0MtOu7IjX7/w4ZcQiI=; b=ZOC0dIozl7SO6MERyNTvLIksE8337e+0QIxBWoS1YG++s/rRK/B/2cgYt6VROHhroD wOFG1yYsPWn2Joi4vSHHhnrV7YdTrAIq9F2zoEOZ8xDMvCce2g24XUbjDJ8YIUTwRi0z Www/fPKLPR4QC24m4w1IjzhGM9sZr4EszvQMU/LiDzKq+T64dZeM68EQDR5WRWz3BGp7 +MjlAKL/YeghgHbpztV5z3Asmc56yRGAgQ/BgmeQSpIryikeJs/1VFZjf3tcA3FGloAZ SI96Ey9s0JJsh+oCe/LDyWC4qWfXdxVpBe5oJBMvwDNwDerXOqoPh1Z/ZrswROM0mjas mrBQ== 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=rJhyjafjgqKk8I6LVsm5b/FzC0MtOu7IjX7/w4ZcQiI=; b=Wj258oyp2oOElomdAlTW42CcbvuzTBjcrmR9ObAuGDC3P/Es/xSmNmCS+AYvhPwZAt xLtuwPa4GaBajW5rIHFmfYwnMcs9mkvmW1qdpadkYdEH5X6OJv/2oeMAgHFl71Pj+IJB DjC07EdwjcMFOsp24UvN82d7ngwRwIxYGgpVSRKhV2tyd7WJHEaBXxTXGS6hopk5jGmR Kq91V9gUEKjKaZMC6paXsehHji7L3W9YgKBeaOMOpN2DE6kasVc1Ecmmn7+SAmKM60RW Jtd3ZXmPv+En/dS1IqeoeOJg13IZ43RdOR8JIOU2OamK3Ohc91uWWRuBBy0TTyPdFA2r H5jg== X-Gm-Message-State: ACrzQf0cwwNfflPMbyadpAvTBjhgaPHITPdQnCISxtl5qeBlUo68ed/b xFVlXu3/BqUa8N+FrP58WAKu5/kMtUfQyw== X-Received: by 2002:a17:902:da83:b0:17a:111:ebdf with SMTP id j3-20020a170902da8300b0017a0111ebdfmr22206155plx.149.1665458358387; Mon, 10 Oct 2022 20:19:18 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 03/24] target/arm: Use probe_access_full for BTI Date: Mon, 10 Oct 2022 20:18:50 -0700 Message-Id: <20221011031911.2408754-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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" Add a field to TARGET_PAGE_ENTRY_EXTRA to hold the guarded bit. In is_guarded_page, use probe_access_full instead of just guessing that the tlb entry is still present. Also handles the FIXME about executing from device memory. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu-param.h | 9 +++++---- target/arm/cpu.h | 13 ------------- target/arm/internals.h | 1 + target/arm/ptw.c | 7 ++++--- target/arm/translate-a64.c | 21 ++++++++++----------- 5 files changed, 20 insertions(+), 31 deletions(-) diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h index 38347b0d20..f4338fd10e 100644 --- a/target/arm/cpu-param.h +++ b/target/arm/cpu-param.h @@ -36,12 +36,13 @@ * * For ARMMMUIdx_Stage2*, pte_attrs is the S2 descriptor bits [5:2]. * Otherwise, pte_attrs is the same as the MAIR_EL1 8-bit format. - * For shareability, as in the SH field of the VMSAv8-64 PTEs. + * For shareability and guarded, as in the SH and GP fields respectively + * of the VMSAv8-64 PTEs. */ # define TARGET_PAGE_ENTRY_EXTRA \ - uint8_t pte_attrs; \ - uint8_t shareability; - + uint8_t pte_attrs; \ + uint8_t shareability; \ + bool guarded; #endif #define NB_MMU_MODES 8 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index f09ec8aa03..a34d496c5b 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3388,19 +3388,6 @@ static inline uint64_t *aa64_vfp_qreg(CPUARMState *env, unsigned regno) /* Shared between translate-sve.c and sve_helper.c. */ extern const uint64_t pred_esz_masks[5]; -/* Helper for the macros below, validating the argument type. */ -static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) -{ - return x; -} - -/* - * Lvalue macros for ARM TLB bits that we must cache in the TCG TLB. - * Using these should be a bit more self-documenting than using the - * generic target bits directly. - */ -#define arm_tlb_bti_gp(x) (typecheck_memtxattrs(x)->target_tlb_bit0) - /* * AArch64 usage of the PAGE_TARGET_* bits for linux-user. * Note that with the Linux kernel, PROT_MTE may not be cleared by mprotect diff --git a/target/arm/internals.h b/target/arm/internals.h index 9566364dca..c3c3920ded 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1095,6 +1095,7 @@ typedef struct ARMCacheAttrs { unsigned int attrs:8; unsigned int shareability:2; /* as in the SH field of the VMSAv8-64 PTEs */ bool is_s2_format:1; + bool guarded:1; /* guarded bit of the v8-64 PTE */ } ARMCacheAttrs; /* Fields that are valid upon success. */ diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 23f16f4ff7..2d182d62e5 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1313,9 +1313,10 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, */ result->f.attrs.secure = false; } - /* When in aarch64 mode, and BTI is enabled, remember GP in the IOTLB. */ - if (aarch64 && guarded && cpu_isar_feature(aa64_bti, cpu)) { - arm_tlb_bti_gp(&result->f.attrs) = true; + + /* When in aarch64 mode, and BTI is enabled, remember GP in the TLB. */ + if (aarch64 && cpu_isar_feature(aa64_bti, cpu)) { + result->f.guarded = guarded; } if (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) { diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 5b67375f4e..60ff753d81 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -14601,22 +14601,21 @@ static bool is_guarded_page(CPUARMState *env, DisasContext *s) #ifdef CONFIG_USER_ONLY return page_get_flags(addr) & PAGE_BTI; #else + CPUTLBEntryFull *full; + void *host; int mmu_idx = arm_to_core_mmu_idx(s->mmu_idx); - unsigned int index = tlb_index(env, mmu_idx, addr); - CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr); + int flags; /* * We test this immediately after reading an insn, which means - * that any normal page must be in the TLB. The only exception - * would be for executing from flash or device memory, which - * does not retain the TLB entry. - * - * FIXME: Assume false for those, for now. We could use - * arm_cpu_get_phys_page_attrs_debug to re-read the page - * table entry even for that case. + * that the TLB entry must be present and valid, and thus this + * access will never raise an exception. */ - return (tlb_hit(entry->addr_code, addr) && - arm_tlb_bti_gp(&env_tlb(env)->d[mmu_idx].fulltlb[index].attrs)); + flags = probe_access_full(env, addr, MMU_INST_FETCH, mmu_idx, + false, &host, &full, 0); + assert(!(flags & TLB_INVALID_MASK)); + + return full->guarded; #endif } From patchwork Tue Oct 11 03:18:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614147 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2369172pvb; Mon, 10 Oct 2022 20:24:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7FNxgOtLs+rF9NneQt6z6GNnjRHeP2milnFoCgWlI56QUnSJvBHXoeyAzVOxT4H8kJb2bF X-Received: by 2002:a05:6214:1d24:b0:4b1:8acb:b3bc with SMTP id f4-20020a0562141d2400b004b18acbb3bcmr17109450qvd.126.1665458678803; Mon, 10 Oct 2022 20:24:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665458678; cv=none; d=google.com; s=arc-20160816; b=Hlpokd7edJMseZBW2Nsu/0syqHEdhuFf2DxxHr/jZ4+z122NMShXvUs5tXry/9cOZq xzEwg+ARIXpALi9UT8GQGi4AoZdcBSgN/rfMzehbOPT4mxuasCcl56GVzWc/RHgPOfG9 U3qPEMAywdIanfPWIG5UJrGKyai17tM/H8DhqkO+eu6TC/t15k9oSbrRNGS4XCw2q27A cu3dS0fl/JnmuG8+P0s9ahqR4EOredbU0snfbVAs5UC+d2cI5OTaWsOj5RczvMbcJ6Bc TZSskIOBHjaDxmWrrhMSmTz0yoCz/3pokEdzZj+9xupFPqL9UQcFTm6PTONSTGJ5dc8l JkDQ== 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=mWDabj8SgVJfh97qu1fcwAspA+xawk95sTUJ2LXWBU0=; b=qS6z9MFVB+t6iuGuSPo131T6T7ROerX7oErbmuymlwUPyZns4dzVFzSLENZ6by+1z1 l7gNZJ7IBfwgTWvwXOm7JN/2qR2qrhOMcj55CXEw/SwxMVYDiWSETTK6oD+Ylj1TXNpS RSgIuk4CEBBeQZrfCzFqObl28lsCzKnW8Bv2ncTC4iDjWdYsaOt7+1qJn3C2SyltZz6J Z/dqcRcc1wzzGkRso4P1GpiyKn2IX9Gn2waldMZ7JTXQ5Xi5VmW2T7tQkW3AeI6N2BeH zUW7ICHFvM/PCJmhmuxpGnbmSApdWlsBMCkJHnI6QEddVzrTtk+ncxoRswhuPQZD4Xi+ HWSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xhwy+Zx7; 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 y15-20020a05620a25cf00b006ce4071eec5si6644495qko.639.2022.10.10.20.24.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:24:38 -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=Xhwy+Zx7; 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]:34236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi5sk-0000ac-8P for patch@linaro.org; Mon, 10 Oct 2022 23:24:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55012) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5nn-0002Fo-BJ for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:31 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:55196) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5ng-000303-Ny for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:29 -0400 Received: by mail-pj1-x1033.google.com with SMTP id 70so11340442pjo.4 for ; Mon, 10 Oct 2022 20:19:20 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mWDabj8SgVJfh97qu1fcwAspA+xawk95sTUJ2LXWBU0=; b=Xhwy+Zx7mB1Fo5Xh0Hs5juMXdyr0PvRVPOOeV9zCxYUuFgh8QcJCDSDOdxka634t73 KUaxzpi3kP5jQtZ6qcExrECAsehIXzwhUClvGGHsKkyHTWNuaMlVTTHrOhdmlCAysGWM A6tLEa4AKtDRPOla5EKuJr9NSMrLVE0X0cwld1B+vTIuZqpbo2JzJwupAkKl9ATew5lC 2h4v3YRN/B/dbcrSnBrQqYG3Cw/1HiYsi7nC627cBLSipjFwX8d4XSkoEioaGPotR/IB ba4tQya40ce7tHprv366XUuGh+4/Z8MHrdW0uGjdOCQbn9x+zq8FlJUqC1gc2v+D9AjO M+aA== 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=mWDabj8SgVJfh97qu1fcwAspA+xawk95sTUJ2LXWBU0=; b=cq013j9wmORCCn+XPYe8Oymh93GvLvUg7DhzItgYwb1ZImrKDRl4h0byMxxWm835uR WCUpJO2eHi/QdCEPX+QoXK6YT4E2di9mvNgCxhNY330o6heIflx1i4hT5xTgUajTW9Zl lWWk8hzEIEdX1DIU1mWM2q1iCJK7tsjD8LYm8bvfbNUK2YU40oQY1D+5H4ut/pX4rl+H uLkr/9JOQC9ZKjsKJZLfbYEY/BElO2JHMC7d43vDiDKIGbM/zPqbKsOUOVoPDzR2XAx+ VT6CDO4qAlBDjB+76YFkEbKRH/tXg+AXu+P+12oQnD04KqZvmm5jn6GDdGbejPnS526z dgww== X-Gm-Message-State: ACrzQf09/2hk5m36/AAOR5VWa1c1En9el0gmeD1ZATAdvjWNqtVNlm6X RoCQUZvruO4jW4mmwN6If+tJneYODk2b5A== X-Received: by 2002:a17:90a:a401:b0:20a:da56:b073 with SMTP id y1-20020a17090aa40100b0020ada56b073mr24874910pjp.1.1665458359771; Mon, 10 Oct 2022 20:19:19 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 04/24] target/arm: Add ARMMMUIdx_Phys_{S,NS} Date: Mon, 10 Oct 2022 20:18:51 -0700 Message-Id: <20221011031911.2408754-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.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" Not yet used, but add mmu indexes for 1-1 mapping to physical addresses. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu-param.h | 2 +- target/arm/cpu.h | 7 ++++++- target/arm/ptw.c | 19 +++++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h index f4338fd10e..a5b27db275 100644 --- a/target/arm/cpu-param.h +++ b/target/arm/cpu-param.h @@ -45,6 +45,6 @@ bool guarded; #endif -#define NB_MMU_MODES 8 +#define NB_MMU_MODES 10 #endif diff --git a/target/arm/cpu.h b/target/arm/cpu.h index a34d496c5b..f93060e6d6 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -2905,8 +2905,9 @@ bool write_cpustate_to_list(ARMCPU *cpu, bool kvm_sync); * EL2 EL2&0 +PAN * EL2 (aka NS PL2) * EL3 (aka S PL1) + * Physical (NS & S) * - * for a total of 8 different mmu_idx. + * for a total of 10 different mmu_idx. * * R profile CPUs have an MPU, but can use the same set of MMU indexes * as A profile. They only need to distinguish EL0 and EL1 (and @@ -2971,6 +2972,10 @@ typedef enum ARMMMUIdx { ARMMMUIdx_E2 = 6 | ARM_MMU_IDX_A, ARMMMUIdx_E3 = 7 | ARM_MMU_IDX_A, + /* TLBs with 1-1 mapping to the physical address spaces. */ + ARMMMUIdx_Phys_NS = 8 | ARM_MMU_IDX_A, + ARMMMUIdx_Phys_S = 9 | ARM_MMU_IDX_A, + /* * These are not allocated TLBs and are used only for AT system * instructions or for the first stage of an S12 page table walk. diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 2d182d62e5..a977d09c6d 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -179,6 +179,11 @@ static bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx, case ARMMMUIdx_E3: break; + case ARMMMUIdx_Phys_NS: + case ARMMMUIdx_Phys_S: + /* No translation for physical address spaces. */ + return true; + default: g_assert_not_reached(); } @@ -2280,10 +2285,17 @@ static bool get_phys_addr_disabled(CPUARMState *env, target_ulong address, { uint8_t memattr = 0x00; /* Device nGnRnE */ uint8_t shareability = 0; /* non-sharable */ + int r_el; - if (mmu_idx != ARMMMUIdx_Stage2 && mmu_idx != ARMMMUIdx_Stage2_S) { - int r_el = regime_el(env, mmu_idx); + switch (mmu_idx) { + case ARMMMUIdx_Stage2: + case ARMMMUIdx_Stage2_S: + case ARMMMUIdx_Phys_NS: + case ARMMMUIdx_Phys_S: + break; + default: + 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]; @@ -2332,6 +2344,7 @@ static bool get_phys_addr_disabled(CPUARMState *env, target_ulong address, shareability = 2; /* outer sharable */ } result->cacheattrs.is_s2_format = false; + break; } result->f.phys_addr = address; @@ -2536,6 +2549,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong address, is_secure = arm_is_secure_below_el3(env); break; case ARMMMUIdx_Stage2: + case ARMMMUIdx_Phys_NS: case ARMMMUIdx_MPrivNegPri: case ARMMMUIdx_MUserNegPri: case ARMMMUIdx_MPriv: @@ -2544,6 +2558,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong address, break; case ARMMMUIdx_E3: case ARMMMUIdx_Stage2_S: + case ARMMMUIdx_Phys_S: case ARMMMUIdx_MSPrivNegPri: case ARMMMUIdx_MSUserNegPri: case ARMMMUIdx_MSPriv: From patchwork Tue Oct 11 03:18:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614151 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2370273pvb; Mon, 10 Oct 2022 20:27:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ogz2oIk2tTiq4RRw4/oDrtOQQmx3F2d17r/xsYU7xMozngwf72kDjA/RCJ4NZykm9MFTF X-Received: by 2002:ae9:e013:0:b0:6ec:9961:4ead with SMTP id m19-20020ae9e013000000b006ec99614eadmr6230860qkk.582.1665458868016; Mon, 10 Oct 2022 20:27:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665458868; cv=none; d=google.com; s=arc-20160816; b=pUr75gXUUP/1Wbfo/gP/Pdki4TMy0dAqjWI8Ya4v9DQJfOg2LWeY99fEN9q13A76LH 4bxPwD/DUuszxjUHzIqeEAWhLuh3xByEMx8z5lfAyQRKEd46UollLi1FQeCcuRI+0rTy wrt9w1AuEk1Dyk51V1c6dpTWR+mpkhTXzz0V1JnyllXwvFDiYOIr1KagEw0Z6qDYUVWt 242C97qVozFH2C0ZYPB+y6qXnc3rFHygd9B+nf+EbOad8DRg2AGOSOweQ2qQZJWBdm5i mUPgrl85hPz+bBe91BeV/7TC9fzUW/vH9rdL5AtZ3FuDdKcN+Ha3Ft2amqGkaR1xXM+E kjFA== 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=K+hPffD7L96yEm/9u0Lj/D1XcxsUpspCEItgw0se0dM=; b=01sTelDFVgSzmr5XdDAFcGZ9Co7hAjVlgVXQiXTgKVMaZLJOwrLwJYyQ/UxsSUZelJ pdwttSjf2LncTLspF4dAGmYACc34trhLBV4IMXWlJEZmCm9pPJO4KST5FXWubDpaY+mU CnikAxousU4EMggT/AFixK+KeAgpsvZ+8+bEMsa+pW7DjHEIFfaRD+7lhHuhgzsqqf58 ge86V2qtw4GeT3+R2H7UNKAvcLHXFKUKryd0C4SNt6LQLKrpheIMxJ/tsSdjd1RzLAGf rmSutYBUuZ+PKnDLw0KslZnzePEaaQ8XApc6V89h7bD5CU/GzY/IMIxwdGRABbxIp481 xqrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hTKOQfTw; 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 q1-20020a056214194100b004b3dd79cc94si5307854qvk.532.2022.10.10.20.27.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:27:48 -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=hTKOQfTw; 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]:35090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi5vn-000705-HA for patch@linaro.org; Mon, 10 Oct 2022 23:27:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5no-0002Hv-I8 for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:32 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:37582) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5ng-00030Q-P7 for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:32 -0400 Received: by mail-pg1-x52e.google.com with SMTP id bh13so11785506pgb.4 for ; Mon, 10 Oct 2022 20:19:22 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K+hPffD7L96yEm/9u0Lj/D1XcxsUpspCEItgw0se0dM=; b=hTKOQfTw7LV7UZGsVEdonHZEOyK6NEDjKZdEKmWpF4avl0faGO3mPEk9rZ3h3ulYqH l6BauhLKPXBNstYwAm+3Xx0sZRIBnI8R39KmSJe2RcSdtmAWd8LX1nKobjtrBd2xqqEb 8klAIwthN5X9Pr1NqPpTkoLELglXvZOGWlxyoiEIyj+IVr8szLS0yjlVPYXzIVaCufXE bV95I/AB0WOwnHl44VjvLdlBKP6gj567X+Vayj7fcwPnQugqjqFCbm7gu/FComy3l//N rf/DcWfW2Fd+cPWFYM0nIHILW6S3AatlRkW0fbz5yp8i8oYKqxfTWA/27MtRsdb67uKq h72g== 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=K+hPffD7L96yEm/9u0Lj/D1XcxsUpspCEItgw0se0dM=; b=X0nsMAWbQDAT0Gbwt3SNrigNJ1KzcMU/+Kws7f/PbWPAyrHVJeexIFHMUB+RrSxwng jyW+a+Uwws2g1oqL/A5BEfknJWafBWmWrz9nVWUu9LQtfUaek/anPk4QIrtEN3N4bQVi ssOJi/+X81J4TtRp3xmGKuPm24BKDJmOlBdMUfdVe9ixC8UtHsC8r/gA8qld1VolQcK9 B0eOdULn//PEgdDKCfx7XIs7XigoKmqo6K9Em6SQphW6dtCld2i/o+hjw0BBNHVFTQD4 EHKY3ddijThz4CzMCasxzQmUCuEO8B0KoU1H8KBt2+SrBxD5ix7XBZPbfE2aTCqNN2HB G1WQ== X-Gm-Message-State: ACrzQf1FAIjqswygRS0amJGi63HdTeocWS2AjAiah5X32osudcyNN38p 9jlJJJUSRm0rY1Hcd5l0z+CiqcJOESEcvw== X-Received: by 2002:a63:4283:0:b0:457:dced:8ba3 with SMTP id p125-20020a634283000000b00457dced8ba3mr19207216pga.220.1665458361175; Mon, 10 Oct 2022 20:19:21 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v4 05/24] target/arm: Move ARMMMUIdx_Stage2 to a real tlb mmu_idx Date: Mon, 10 Oct 2022 20:18:52 -0700 Message-Id: <20221011031911.2408754-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.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" We had been marking this ARM_MMU_IDX_NOTLB, move it to a real tlb. Flush the tlb when invalidating stage 1+2 translations. Re-use alle1_tlbmask() for other instances of EL1&0 + Stage2. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- v4: Implement the IPAS2 and RIPAS2 tlb flushing insns; Reuse alle1_tlbmask to fix aa32 and vttbr flushing. --- target/arm/cpu-param.h | 2 +- target/arm/cpu.h | 23 ++++--- target/arm/helper.c | 151 ++++++++++++++++++++++++++++++----------- 3 files changed, 127 insertions(+), 49 deletions(-) diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h index a5b27db275..b7bde18986 100644 --- a/target/arm/cpu-param.h +++ b/target/arm/cpu-param.h @@ -45,6 +45,6 @@ bool guarded; #endif -#define NB_MMU_MODES 10 +#define NB_MMU_MODES 12 #endif diff --git a/target/arm/cpu.h b/target/arm/cpu.h index f93060e6d6..c94e289012 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -2906,8 +2906,9 @@ bool write_cpustate_to_list(ARMCPU *cpu, bool kvm_sync); * EL2 (aka NS PL2) * EL3 (aka S PL1) * Physical (NS & S) + * Stage2 (NS & S) * - * for a total of 10 different mmu_idx. + * for a total of 12 different mmu_idx. * * R profile CPUs have an MPU, but can use the same set of MMU indexes * as A profile. They only need to distinguish EL0 and EL1 (and @@ -2976,6 +2977,15 @@ typedef enum ARMMMUIdx { ARMMMUIdx_Phys_NS = 8 | ARM_MMU_IDX_A, ARMMMUIdx_Phys_S = 9 | ARM_MMU_IDX_A, + /* + * Used for second stage of an S12 page table walk, or for descriptor + * loads during first stage of an S1 page table walk. Note that both + * are in use simultaneously for SecureEL2: the security state for + * the S2 ptw is selected by the NS bit from the S1 ptw. + */ + ARMMMUIdx_Stage2 = 10 | ARM_MMU_IDX_A, + ARMMMUIdx_Stage2_S = 11 | ARM_MMU_IDX_A, + /* * These are not allocated TLBs and are used only for AT system * instructions or for the first stage of an S12 page table walk. @@ -2983,15 +2993,6 @@ typedef enum ARMMMUIdx { ARMMMUIdx_Stage1_E0 = 0 | ARM_MMU_IDX_NOTLB, ARMMMUIdx_Stage1_E1 = 1 | ARM_MMU_IDX_NOTLB, ARMMMUIdx_Stage1_E1_PAN = 2 | ARM_MMU_IDX_NOTLB, - /* - * Not allocated a TLB: used only for second stage of an S12 page - * table walk, or for descriptor loads during first stage of an S1 - * page table walk. Note that if we ever want to have a TLB for this - * then various TLB flush insns which currently are no-ops or flush - * only stage 1 MMU indexes will need to change to flush stage 2. - */ - ARMMMUIdx_Stage2 = 3 | ARM_MMU_IDX_NOTLB, - ARMMMUIdx_Stage2_S = 4 | ARM_MMU_IDX_NOTLB, /* * M-profile. @@ -3022,6 +3023,8 @@ typedef enum ARMMMUIdxBit { TO_CORE_BIT(E20_2), TO_CORE_BIT(E20_2_PAN), TO_CORE_BIT(E3), + TO_CORE_BIT(Stage2), + TO_CORE_BIT(Stage2_S), TO_CORE_BIT(MUser), TO_CORE_BIT(MPriv), diff --git a/target/arm/helper.c b/target/arm/helper.c index dde64a487a..18c51bb777 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -399,6 +399,21 @@ static void contextidr_write(CPUARMState *env, const ARMCPRegInfo *ri, raw_write(env, ri, value); } +static int alle1_tlbmask(CPUARMState *env) +{ + /* + * Note that the 'ALL' scope must invalidate both stage 1 and + * stage 2 translations, whereas most other scopes only invalidate + * stage 1 translations. + */ + return (ARMMMUIdxBit_E10_1 | + ARMMMUIdxBit_E10_1_PAN | + ARMMMUIdxBit_E10_0 | + ARMMMUIdxBit_Stage2 | + ARMMMUIdxBit_Stage2_S); +} + + /* IS variants of TLB operations must affect all cores */ static void tlbiall_is_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) @@ -501,10 +516,7 @@ static void tlbiall_nsnh_write(CPUARMState *env, const ARMCPRegInfo *ri, { CPUState *cs = env_cpu(env); - tlb_flush_by_mmuidx(cs, - ARMMMUIdxBit_E10_1 | - ARMMMUIdxBit_E10_1_PAN | - ARMMMUIdxBit_E10_0); + tlb_flush_by_mmuidx(cs, alle1_tlbmask(env)); } static void tlbiall_nsnh_is_write(CPUARMState *env, const ARMCPRegInfo *ri, @@ -512,10 +524,7 @@ static void tlbiall_nsnh_is_write(CPUARMState *env, const ARMCPRegInfo *ri, { CPUState *cs = env_cpu(env); - tlb_flush_by_mmuidx_all_cpus_synced(cs, - ARMMMUIdxBit_E10_1 | - ARMMMUIdxBit_E10_1_PAN | - ARMMMUIdxBit_E10_0); + tlb_flush_by_mmuidx_all_cpus_synced(cs, alle1_tlbmask(env)); } @@ -554,6 +563,24 @@ static void tlbimva_hyp_is_write(CPUARMState *env, const ARMCPRegInfo *ri, ARMMMUIdxBit_E2); } +static void tlbiipas2_hyp_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + CPUState *cs = env_cpu(env); + uint64_t pageaddr = (value & MAKE_64BIT_MASK(0, 28)) << 12; + + tlb_flush_page_by_mmuidx(cs, pageaddr, ARMMMUIdxBit_Stage2); +} + +static void tlbiipas2is_hyp_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + CPUState *cs = env_cpu(env); + uint64_t pageaddr = (value & MAKE_64BIT_MASK(0, 28)) << 12; + + tlb_flush_page_by_mmuidx_all_cpus_synced(cs, pageaddr, ARMMMUIdxBit_Stage2); +} + static const ARMCPRegInfo cp_reginfo[] = { /* Define the secure and non-secure FCSE identifier CP registers * separately because there is no secure bank in V8 (no _EL3). This allows @@ -3786,13 +3813,10 @@ static void vttbr_write(CPUARMState *env, const ARMCPRegInfo *ri, /* * A change in VMID to the stage2 page table (Stage2) invalidates - * the combined stage 1&2 tlbs (EL10_1 and EL10_0). + * the stage2 and combined stage 1&2 tlbs (EL10_1 and EL10_0). */ if (raw_read(env, ri) != value) { - uint16_t mask = ARMMMUIdxBit_E10_1 | - ARMMMUIdxBit_E10_1_PAN | - ARMMMUIdxBit_E10_0; - tlb_flush_by_mmuidx(cs, mask); + tlb_flush_by_mmuidx(cs, alle1_tlbmask(env)); raw_write(env, ri, value); } } @@ -4313,18 +4337,6 @@ static void tlbi_aa64_vmalle1_write(CPUARMState *env, const ARMCPRegInfo *ri, } } -static int alle1_tlbmask(CPUARMState *env) -{ - /* - * Note that the 'ALL' scope must invalidate both stage 1 and - * stage 2 translations, whereas most other scopes only invalidate - * stage 1 translations. - */ - return (ARMMMUIdxBit_E10_1 | - ARMMMUIdxBit_E10_1_PAN | - ARMMMUIdxBit_E10_0); -} - static int e2_tlbmask(CPUARMState *env) { return (ARMMMUIdxBit_E20_0 | @@ -4467,6 +4479,43 @@ static void tlbi_aa64_vae3is_write(CPUARMState *env, const ARMCPRegInfo *ri, ARMMMUIdxBit_E3, bits); } +static int ipas2e1_tlbmask(CPUARMState *env, int64_t value) +{ + /* + * The MSB of value is the NS field, which only applies if SEL2 + * is implemented and SCR_EL3.NS is not set (i.e. in secure mode). + */ + return (value >= 0 + && cpu_isar_feature(aa64_sel2, env_archcpu(env)) + && arm_is_secure_below_el3(env) + ? ARMMMUIdxBit_Stage2_S + : ARMMMUIdxBit_Stage2); +} + +static void tlbi_aa64_ipas2e1_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + CPUState *cs = env_cpu(env); + int mask = ipas2e1_tlbmask(env, value); + uint64_t pageaddr = sextract64(value << 12, 0, 56); + + if (tlb_force_broadcast(env)) { + tlb_flush_page_by_mmuidx_all_cpus_synced(cs, pageaddr, mask); + } else { + tlb_flush_page_by_mmuidx(cs, pageaddr, mask); + } +} + +static void tlbi_aa64_ipas2e1is_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + CPUState *cs = env_cpu(env); + int mask = ipas2e1_tlbmask(env, value); + uint64_t pageaddr = sextract64(value << 12, 0, 56); + + tlb_flush_page_by_mmuidx_all_cpus_synced(cs, pageaddr, mask); +} + #ifdef TARGET_AARCH64 typedef struct { uint64_t base; @@ -4652,6 +4701,20 @@ static void tlbi_aa64_rvae3is_write(CPUARMState *env, do_rvae_write(env, value, ARMMMUIdxBit_E3, true); } + +static void tlbi_aa64_ripas2e1_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + do_rvae_write(env, value, ipas2e1_tlbmask(env, value), + tlb_force_broadcast(env)); +} + +static void tlbi_aa64_ripas2e1is_write(CPUARMState *env, + const ARMCPRegInfo *ri, + uint64_t value) +{ + do_rvae_write(env, value, ipas2e1_tlbmask(env, value), true); +} #endif static CPAccessResult aa64_zva_access(CPUARMState *env, const ARMCPRegInfo *ri, @@ -4930,10 +4993,12 @@ static const ARMCPRegInfo v8_cp_reginfo[] = { .writefn = tlbi_aa64_vae1_write }, { .name = "TLBI_IPAS2E1IS", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 0, .opc2 = 1, - .access = PL2_W, .type = ARM_CP_NOP }, + .access = PL2_W, .type = ARM_CP_NO_RAW, + .writefn = tlbi_aa64_ipas2e1is_write }, { .name = "TLBI_IPAS2LE1IS", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 0, .opc2 = 5, - .access = PL2_W, .type = ARM_CP_NOP }, + .access = PL2_W, .type = ARM_CP_NO_RAW, + .writefn = tlbi_aa64_ipas2e1is_write }, { .name = "TLBI_ALLE1IS", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 3, .opc2 = 4, .access = PL2_W, .type = ARM_CP_NO_RAW, @@ -4944,10 +5009,12 @@ static const ARMCPRegInfo v8_cp_reginfo[] = { .writefn = tlbi_aa64_alle1is_write }, { .name = "TLBI_IPAS2E1", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 4, .opc2 = 1, - .access = PL2_W, .type = ARM_CP_NOP }, + .access = PL2_W, .type = ARM_CP_NO_RAW, + .writefn = tlbi_aa64_ipas2e1_write }, { .name = "TLBI_IPAS2LE1", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 4, .opc2 = 5, - .access = PL2_W, .type = ARM_CP_NOP }, + .access = PL2_W, .type = ARM_CP_NO_RAW, + .writefn = tlbi_aa64_ipas2e1_write }, { .name = "TLBI_ALLE1", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 7, .opc2 = 4, .access = PL2_W, .type = ARM_CP_NO_RAW, @@ -5028,16 +5095,20 @@ static const ARMCPRegInfo v8_cp_reginfo[] = { .writefn = tlbimva_hyp_is_write }, { .name = "TLBIIPAS2", .cp = 15, .opc1 = 4, .crn = 8, .crm = 4, .opc2 = 1, - .type = ARM_CP_NOP, .access = PL2_W }, + .type = ARM_CP_NO_RAW, .access = PL2_W, + .writefn = tlbiipas2_hyp_write }, { .name = "TLBIIPAS2IS", .cp = 15, .opc1 = 4, .crn = 8, .crm = 0, .opc2 = 1, - .type = ARM_CP_NOP, .access = PL2_W }, + .type = ARM_CP_NO_RAW, .access = PL2_W, + .writefn = tlbiipas2is_hyp_write }, { .name = "TLBIIPAS2L", .cp = 15, .opc1 = 4, .crn = 8, .crm = 4, .opc2 = 5, - .type = ARM_CP_NOP, .access = PL2_W }, + .type = ARM_CP_NO_RAW, .access = PL2_W, + .writefn = tlbiipas2_hyp_write }, { .name = "TLBIIPAS2LIS", .cp = 15, .opc1 = 4, .crn = 8, .crm = 0, .opc2 = 5, - .type = ARM_CP_NOP, .access = PL2_W }, + .type = ARM_CP_NO_RAW, .access = PL2_W, + .writefn = tlbiipas2is_hyp_write }, /* 32 bit cache operations */ { .name = "ICIALLUIS", .cp = 15, .opc1 = 0, .crn = 7, .crm = 1, .opc2 = 0, .type = ARM_CP_NOP, .access = PL1_W, .accessfn = aa64_cacheop_pou_access }, @@ -6694,10 +6765,12 @@ static const ARMCPRegInfo tlbirange_reginfo[] = { .writefn = tlbi_aa64_rvae1_write }, { .name = "TLBI_RIPAS2E1IS", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 0, .opc2 = 2, - .access = PL2_W, .type = ARM_CP_NOP }, + .access = PL2_W, .type = ARM_CP_NO_RAW, + .writefn = tlbi_aa64_ripas2e1is_write }, { .name = "TLBI_RIPAS2LE1IS", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 0, .opc2 = 6, - .access = PL2_W, .type = ARM_CP_NOP }, + .access = PL2_W, .type = ARM_CP_NO_RAW, + .writefn = tlbi_aa64_ripas2e1is_write }, { .name = "TLBI_RVAE2IS", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 2, .opc2 = 1, .access = PL2_W, .type = ARM_CP_NO_RAW | ARM_CP_EL3_NO_EL2_UNDEF, @@ -6708,10 +6781,12 @@ static const ARMCPRegInfo tlbirange_reginfo[] = { .writefn = tlbi_aa64_rvae2is_write }, { .name = "TLBI_RIPAS2E1", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 4, .opc2 = 2, - .access = PL2_W, .type = ARM_CP_NOP }, - { .name = "TLBI_RIPAS2LE1", .state = ARM_CP_STATE_AA64, + .access = PL2_W, .type = ARM_CP_NO_RAW, + .writefn = tlbi_aa64_ripas2e1_write }, + { .name = "TLBI_RIPAS2LE1", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 4, .opc2 = 6, - .access = PL2_W, .type = ARM_CP_NOP }, + .access = PL2_W, .type = ARM_CP_NO_RAW, + .writefn = tlbi_aa64_ripas2e1_write }, { .name = "TLBI_RVAE2OS", .state = ARM_CP_STATE_AA64, .opc0 = 1, .opc1 = 4, .crn = 8, .crm = 5, .opc2 = 1, .access = PL2_W, .type = ARM_CP_NO_RAW | ARM_CP_EL3_NO_EL2_UNDEF, From patchwork Tue Oct 11 03:18:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614146 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2369165pvb; Mon, 10 Oct 2022 20:24:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4qdoUh/2RoSKN8Pz9f4ZRoyojDHiva7LEzEFrSfTJ+fdoxcumUb4cO3+oc+pqs3457iD+I X-Received: by 2002:a05:620a:27cc:b0:6df:f651:79c9 with SMTP id i12-20020a05620a27cc00b006dff65179c9mr15046846qkp.28.1665458677702; Mon, 10 Oct 2022 20:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665458677; cv=none; d=google.com; s=arc-20160816; b=KbZVvfNRKRL+RskDav53XpwyHJjS74N7rBR7xC8gd0C1xghefDeDpgF3vadOstKoSv jtJXKTKKAs+s5GjU/t/SfQldYWd4ks/Amo8nv2DiS63DCCyP9WnmRW/dObEQ+E+xYJHY zWlyxZUclRTIBSek5pmBOV2cG+D8gUW363oqkq7Mfj7wsZ+NB+Yq08j6T5nKLpmIsmdH G8ExrUXcCLG6ZxpGlikUJhebZCmGaenzJTf3hNCMdKqh9J+maJybgBC4CcZmtWAOG3sa fZ9ktF7npQSgSHAwX1DO26zSOk1MFGST6Xp95PKEzSj25HWjNo0t2mW6MltTIh1mRQSR I0JQ== 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=b2ixa769MahWYdKSZ05XJ7WAaj+VfGkFP7b3KRkRK2I=; b=PHVTe8cLeINt2sjbFxEvs9nePDC/a6kuPcAQGuWH2IuPFlQqKAsOl5jY4lkIWSsqzj MT/tnKvM5FlPN8TjRmgyzSIhJWHYuWnmGexDkaC6My81g6zc0xjbWhG7M5d+DEW/Mb9H q2p2qSGhgULac/4VTZODNDoo8yKhMZxA9oUAxlSVGiGtFs3g4WcW892P0TPWK+pZ24Fo YVlxBsyo8dWU4id/Dfzn+ixdNUfYMe4WaBQnAAmA6bmjOADoLuh5F9NifVmdc0gGOhS5 LQVBlXokwQeOVgr+Xt+tYdamNvKU3ek6gk5MkVJUt3huly0GERDmEh3PHvsettyjMsIP 9daQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i+B8jp+F; 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 e16-20020ac85dd0000000b00396a3571da0si6002097qtx.409.2022.10.10.20.24.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:24:37 -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=i+B8jp+F; 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]:40636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi5sj-0000gM-8a for patch@linaro.org; Mon, 10 Oct 2022 23:24:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5no-0002Gs-6t for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:32 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:40544) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5ni-00030k-OF for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:31 -0400 Received: by mail-pf1-x42b.google.com with SMTP id h13so10915577pfr.7 for ; Mon, 10 Oct 2022 20:19:24 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=b2ixa769MahWYdKSZ05XJ7WAaj+VfGkFP7b3KRkRK2I=; b=i+B8jp+F0HOVS3raIzD4eIt5hxNTBWG9HO/1CWjnFbQuWw5fajvuH9uiZjUKMsKyhA LDWL71MyBXJs7K9EmzqFRRb7yGxUgmKK5yAfn9slXPJXe/C1FFxuFvy2BpvxS7ANbl0I W2rydIS9uyr3R+NKL8dALhLGICuJw6imPLH1OR+JnSaRsc6RuXAUrBOC+xdq1QTNNDzs xoP/Zzq/3Pu2mP/zXslE/Kf7XI8ojGxoRDc+lqdTx+0Yw9M//ymnC68AuUI83X4ixEla /scgo2ur/RTvAJjmPU6GvLIs1cJeE0+HAwDSZWk2lEMGpmzSeP+igi5VUN8i1R0aBUk5 UdWw== 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=b2ixa769MahWYdKSZ05XJ7WAaj+VfGkFP7b3KRkRK2I=; b=lYgNlprZ/4hel7ftW7j5yHHKOTpRb0TuYdYrsPbjCjUA25G6nY1PeqnW0GzAxyWXuB gmhr+cxHQKguvMcoQtDI+gIYvJUIkHefhe0nynuwTiIG4jGb+RYGQ8PvGlUiUQImwQpG N6L+WHo0JeObgRlJrSWNgeWdMROES5otx4MpankMlJgsG5nugBr+YqV0+Pv0JKxlIxxB bGn6OFPhPorQ/doubRNUI6i3r/bdgunaK+mXLIBNZaUjDAV/UUV8lLPWjo1wE8G3+Xbb 9DWz7FTapicVF/fwK1slP7B3yIm2cObhDcJVMUoTGXVsZdRHqryqPzrap6qTmgdSVV76 gQ1A== X-Gm-Message-State: ACrzQf1fLft0XSlwUejSuv2if+NrM8XIEZXDofnYtKC/EvB7S0i2iUOE 8Mj+pvj3seoCuoUYlD+gC33uJahwaBX4aA== X-Received: by 2002:a63:d51:0:b0:438:36d9:7fd8 with SMTP id 17-20020a630d51000000b0043836d97fd8mr18436428pgn.547.1665458362981; Mon, 10 Oct 2022 20:19:22 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v4 06/24] target/arm: Restrict tlb flush from vttbr_write to vmid change Date: Mon, 10 Oct 2022 20:18:53 -0700 Message-Id: <20221011031911.2408754-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.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" Compare only the VMID field when considering whether we need to flush. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 18c51bb777..c672903f43 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -3815,10 +3815,10 @@ static void vttbr_write(CPUARMState *env, const ARMCPRegInfo *ri, * A change in VMID to the stage2 page table (Stage2) invalidates * the stage2 and combined stage 1&2 tlbs (EL10_1 and EL10_0). */ - if (raw_read(env, ri) != value) { + if (extract64(raw_read(env, ri) ^ value, 48, 16) != 0) { tlb_flush_by_mmuidx(cs, alle1_tlbmask(env)); - raw_write(env, ri, value); } + raw_write(env, ri, value); } static const ARMCPRegInfo vmsa_pmsa_cp_reginfo[] = { From patchwork Tue Oct 11 03:18:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614148 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2369507pvb; Mon, 10 Oct 2022 20:25:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4qFnBCcV6r1zGVfEye226rv1cLa3sT+KuFJ+OJtlDVblk6BazQ+9MkN3t6XyN6D/4ajMl+ X-Received: by 2002:a05:6214:2461:b0:4b1:d15a:ce88 with SMTP id im1-20020a056214246100b004b1d15ace88mr17476161qvb.44.1665458728567; Mon, 10 Oct 2022 20:25:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665458728; cv=none; d=google.com; s=arc-20160816; b=Ng0iIHGzQUocEpgg5B8tp95MYanbxn+/Vs7I1XYiL7EOPsZyAgkaVEtGBErCLjugcZ XCJbs39VDHjwRNNyZDLFyhWT334+Xu7n5YoRGCyzAEtK9Z+fXulXRdZDCSDONCH1eYkN OdkQtyNN8j7SvndyZqSRqOCizp+S2gjn85xpBJ+dGmWWhTLl8b+jTBssOPmr1pl2e6st Uy/pSxARir8DY3y/ZdHPTpDPzPncpS4DyxSUMJQtnPeG6bznx0OvST+vlG730sLWJmHx F7XPTlGLwbO9pYQXbRPCVijvQsU1HYek5uQiF/V2/WJ5DR5QgD+TwGwx/HcHKUWeoSgc yY6Q== 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=Uov6oVHifc7Y1/3vFmJS1/CKnlYeQIOdKbWg1B/qhKM=; b=ojZFyvRgRIlF3uBj6CtzqWwiH1/hT5UlJ011BAZ4z1e7U0DEMaXZgDFEXcRcv6sUBv kObikzj2Uqhf9DM4GnsVY6wEZ4gSVvJRkzUpItfQ1g2KrEVnBfdUNg3Cg007Dq8wPxUn lzGeo1CvRF7eBij3+8p2tdeJJlhEw7hC2KTNaqKmJZ51mNiSvu+pJalWVCziMqkwLkCb aRN2fHGrrjiw8Hs9eDRpybjlMAEYREJj9FOBaQfxTv1VuP9jR6juDLGIbk6xzgH9QYo5 l3use26LiyaQZ1P5grAJNTrBZ0eQiKX4fvlKPXDN1vpNmCM+PFNo+pFciEzRVkda+Elj sAuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fuSYhDAs; 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 dm53-20020a05620a1d7500b006eb3a5ae77bsi4821206qkb.224.2022.10.10.20.25.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:25:28 -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=fuSYhDAs; 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]:44434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi5tY-000264-2x for patch@linaro.org; Mon, 10 Oct 2022 23:25:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5nq-0002J5-1o for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:34 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:41525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5ni-000312-OP for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:33 -0400 Received: by mail-pj1-x102a.google.com with SMTP id q10-20020a17090a304a00b0020b1d5f6975so10881635pjl.0 for ; Mon, 10 Oct 2022 20:19:26 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Uov6oVHifc7Y1/3vFmJS1/CKnlYeQIOdKbWg1B/qhKM=; b=fuSYhDAsb9kAKThJqbuKC9FTd9qkmJrOeVpfOl1cRRpBbip6HMmdOYXa6cd3i+5ydQ x08H7TrgLobdq3KfxGeg1AUJQIm8SQTWdyWrm9Z6vtONzC5ByQiypPSn8DLE62gRz/h7 ZgEI0BxXdz12bMBZk4AGZ4Pymbu8SQSNwVqmSsgNsU/Lu3zJu5Fyz45DnGNNlaIx3Ht+ ACYmvx5zOnLBUnrcJg9Q63DMKfKc+LKp0J7qkhYt131qIjpH+2nCC5Rdac3vVysYn8Lp 3GyHm47kA0CZ534kdSWAA38Zwak5uoNODjrnMKTAtWQUG7+4MGW3OZWN/txm59Uln+A8 zwYQ== 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=Uov6oVHifc7Y1/3vFmJS1/CKnlYeQIOdKbWg1B/qhKM=; b=Avp6xLGrcskGOByD1yJuZOxLPnUpP3jzOPuEGdgY7VBHLAW+djOdbdrrMPSz8CiLq+ rDpfuupK0Cw+whZJjYyMZAKEKW9DZYM7MmxpZWOUV0Pa+hPWItLPZFYVaTXEqg5NMZG5 8yyuxjFhnEAglL21/P/2laaQwPiB6s8fYK6SVioX0hyFs+zUX+7tvDRpzDyVmQwQ/4Sa a5FjcA7y1xLYU3gBCTQI0Melgk3Pea9LjvkqjC8PTXXwnn5V9R3VVTfFZfpvf0Jps1td I69zWfuOfU5TWey7HrICK4uXih+5Jj+f8Kwk/ym4KqqyuukrukFz9UpeDZvpn+eZ1u8B s2lw== X-Gm-Message-State: ACrzQf1TR65GvAaLZ8bh/rGbkkRFvma05GO+wIUimWIekn5hPr1L0E72 OK5LEUSSYx6Bo2PNtX8d4BkMaHSrjZ9JzQ== X-Received: by 2002:a17:90a:4216:b0:20d:2891:157 with SMTP id o22-20020a17090a421600b0020d28910157mr13882873pjg.47.1665458365176; Mon, 10 Oct 2022 20:19:25 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v4 07/24] target/arm: Split out S1Translate type Date: Mon, 10 Oct 2022 20:18:54 -0700 Message-Id: <20221011031911.2408754-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Consolidate most of the inputs and outputs of S1_ptw_translate into a single structure. Plumb this through arm_ld*_ptw from the controlling get_phys_addr_* routine. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- v4: Replaces a different S1TranslateResult patch, and plumbs the structure further out in the function call tree. --- target/arm/ptw.c | 140 ++++++++++++++++++++++++++--------------------- 1 file changed, 79 insertions(+), 61 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index a977d09c6d..dee69ee743 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -14,9 +14,16 @@ #include "idau.h" -static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - bool is_secure, bool s1_is_el0, +typedef struct S1Translate { + ARMMMUIdx in_mmu_idx; + bool in_secure; + bool out_secure; + hwaddr out_phys; +} S1Translate; + +static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, + uint64_t address, + MMUAccessType access_type, bool s1_is_el0, GetPhysAddrResult *result, ARMMMUFaultInfo *fi) __attribute__((nonnull)); @@ -211,28 +218,31 @@ static bool ptw_attrs_are_device(uint64_t hcr, ARMCacheAttrs cacheattrs) } /* Translate a S1 pagetable walk through S2 if needed. */ -static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx, - hwaddr addr, bool *is_secure_ptr, - ARMMMUFaultInfo *fi) +static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, + hwaddr addr, ARMMMUFaultInfo *fi) { - bool is_secure = *is_secure_ptr; + bool is_secure = ptw->in_secure; ARMMMUIdx s2_mmu_idx = is_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; - if (arm_mmu_idx_is_stage1_of_2(mmu_idx) && + if (arm_mmu_idx_is_stage1_of_2(ptw->in_mmu_idx) && !regime_translation_disabled(env, s2_mmu_idx, is_secure)) { GetPhysAddrResult s2 = {}; + S1Translate s2ptw = { + .in_mmu_idx = s2_mmu_idx, + .in_secure = is_secure, + }; uint64_t hcr; int ret; - ret = get_phys_addr_lpae(env, addr, MMU_DATA_LOAD, s2_mmu_idx, - is_secure, false, &s2, fi); + ret = get_phys_addr_lpae(env, &s2ptw, addr, MMU_DATA_LOAD, + false, &s2, fi); if (ret) { assert(fi->type != ARMFault_None); fi->s2addr = addr; fi->stage2 = true; fi->s1ptw = true; fi->s1ns = !is_secure; - return ~0; + return false; } hcr = arm_hcr_el2_eff_secstate(env, is_secure); @@ -246,7 +256,7 @@ static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx, fi->stage2 = true; fi->s1ptw = true; fi->s1ns = !is_secure; - return ~0; + return false; } if (arm_is_secure_below_el3(env)) { @@ -256,19 +266,21 @@ static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx, } else { is_secure = !(env->cp15.vtcr_el2 & VTCR_NSW); } - *is_secure_ptr = is_secure; } else { assert(!is_secure); } addr = s2.f.phys_addr; } - return addr; + + ptw->out_secure = is_secure; + ptw->out_phys = addr; + return true; } /* All loads done in the course of a page table walk go through here. */ -static uint32_t arm_ldl_ptw(CPUARMState *env, hwaddr addr, bool is_secure, - ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi) +static uint32_t arm_ldl_ptw(CPUARMState *env, S1Translate *ptw, hwaddr addr, + ARMMMUFaultInfo *fi) { CPUState *cs = env_cpu(env); MemTxAttrs attrs = {}; @@ -276,13 +288,13 @@ static uint32_t arm_ldl_ptw(CPUARMState *env, hwaddr addr, bool is_secure, AddressSpace *as; uint32_t data; - addr = S1_ptw_translate(env, mmu_idx, addr, &is_secure, fi); - attrs.secure = is_secure; - as = arm_addressspace(cs, attrs); - if (fi->s1ptw) { + if (!S1_ptw_translate(env, ptw, addr, fi)) { return 0; } - if (regime_translation_big_endian(env, mmu_idx)) { + addr = ptw->out_phys; + attrs.secure = ptw->out_secure; + as = arm_addressspace(cs, attrs); + if (regime_translation_big_endian(env, ptw->in_mmu_idx)) { data = address_space_ldl_be(as, addr, attrs, &result); } else { data = address_space_ldl_le(as, addr, attrs, &result); @@ -295,8 +307,8 @@ static uint32_t arm_ldl_ptw(CPUARMState *env, hwaddr addr, bool is_secure, return 0; } -static uint64_t arm_ldq_ptw(CPUARMState *env, hwaddr addr, bool is_secure, - ARMMMUIdx mmu_idx, ARMMMUFaultInfo *fi) +static uint64_t arm_ldq_ptw(CPUARMState *env, S1Translate *ptw, hwaddr addr, + ARMMMUFaultInfo *fi) { CPUState *cs = env_cpu(env); MemTxAttrs attrs = {}; @@ -304,13 +316,13 @@ static uint64_t arm_ldq_ptw(CPUARMState *env, hwaddr addr, bool is_secure, AddressSpace *as; uint64_t data; - addr = S1_ptw_translate(env, mmu_idx, addr, &is_secure, fi); - attrs.secure = is_secure; - as = arm_addressspace(cs, attrs); - if (fi->s1ptw) { + if (!S1_ptw_translate(env, ptw, addr, fi)) { return 0; } - if (regime_translation_big_endian(env, mmu_idx)) { + addr = ptw->out_phys; + attrs.secure = ptw->out_secure; + as = arm_addressspace(cs, attrs); + if (regime_translation_big_endian(env, ptw->in_mmu_idx)) { data = address_space_ldq_be(as, addr, attrs, &result); } else { data = address_space_ldq_le(as, addr, attrs, &result); @@ -431,10 +443,9 @@ static int simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, int ap) return simple_ap_to_rw_prot_is_user(ap, regime_is_user(env, mmu_idx)); } -static bool get_phys_addr_v5(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - bool is_secure, GetPhysAddrResult *result, - ARMMMUFaultInfo *fi) +static bool get_phys_addr_v5(CPUARMState *env, S1Translate *ptw, + uint32_t address, MMUAccessType access_type, + GetPhysAddrResult *result, ARMMMUFaultInfo *fi) { int level = 1; uint32_t table; @@ -448,18 +459,18 @@ static bool get_phys_addr_v5(CPUARMState *env, uint32_t address, /* Pagetable walk. */ /* Lookup l1 descriptor. */ - if (!get_level1_table_address(env, mmu_idx, &table, address)) { + if (!get_level1_table_address(env, ptw->in_mmu_idx, &table, address)) { /* Section translation fault if page walk is disabled by PD0 or PD1 */ fi->type = ARMFault_Translation; goto do_fault; } - desc = arm_ldl_ptw(env, table, is_secure, mmu_idx, fi); + desc = arm_ldl_ptw(env, ptw, table, fi); if (fi->type != ARMFault_None) { goto do_fault; } type = (desc & 3); domain = (desc >> 5) & 0x0f; - if (regime_el(env, mmu_idx) == 1) { + if (regime_el(env, ptw->in_mmu_idx) == 1) { dacr = env->cp15.dacr_ns; } else { dacr = env->cp15.dacr_s; @@ -491,7 +502,7 @@ static bool get_phys_addr_v5(CPUARMState *env, uint32_t address, /* Fine pagetable. */ table = (desc & 0xfffff000) | ((address >> 8) & 0xffc); } - desc = arm_ldl_ptw(env, table, is_secure, mmu_idx, fi); + desc = arm_ldl_ptw(env, ptw, table, fi); if (fi->type != ARMFault_None) { goto do_fault; } @@ -535,7 +546,7 @@ static bool get_phys_addr_v5(CPUARMState *env, uint32_t address, g_assert_not_reached(); } } - result->f.prot = ap_to_rw_prot(env, mmu_idx, ap, domain_prot); + result->f.prot = ap_to_rw_prot(env, ptw->in_mmu_idx, ap, domain_prot); result->f.prot |= result->f.prot ? PAGE_EXEC : 0; if (!(result->f.prot & (1 << access_type))) { /* Access permission fault. */ @@ -550,12 +561,12 @@ do_fault: return true; } -static bool get_phys_addr_v6(CPUARMState *env, uint32_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - bool is_secure, GetPhysAddrResult *result, - ARMMMUFaultInfo *fi) +static bool get_phys_addr_v6(CPUARMState *env, S1Translate *ptw, + uint32_t address, MMUAccessType access_type, + GetPhysAddrResult *result, ARMMMUFaultInfo *fi) { ARMCPU *cpu = env_archcpu(env); + ARMMMUIdx mmu_idx = ptw->in_mmu_idx; int level = 1; uint32_t table; uint32_t desc; @@ -576,7 +587,7 @@ static bool get_phys_addr_v6(CPUARMState *env, uint32_t address, fi->type = ARMFault_Translation; goto do_fault; } - desc = arm_ldl_ptw(env, table, is_secure, mmu_idx, fi); + desc = arm_ldl_ptw(env, ptw, table, fi); if (fi->type != ARMFault_None) { goto do_fault; } @@ -629,7 +640,7 @@ static bool get_phys_addr_v6(CPUARMState *env, uint32_t address, ns = extract32(desc, 3, 1); /* Lookup l2 entry. */ table = (desc & 0xfffffc00) | ((address >> 10) & 0x3fc); - desc = arm_ldl_ptw(env, table, is_secure, mmu_idx, fi); + desc = arm_ldl_ptw(env, ptw, table, fi); if (fi->type != ARMFault_None) { goto do_fault; } @@ -972,22 +983,25 @@ static bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level, * the WnR bit is never set (the caller must do this). * * @env: CPUARMState + * @ptw: Current and next stage parameters for the walk. * @address: virtual address to get physical address for * @access_type: MMU_DATA_LOAD, MMU_DATA_STORE or MMU_INST_FETCH - * @mmu_idx: MMU index indicating required translation regime - * @s1_is_el0: if @mmu_idx is ARMMMUIdx_Stage2 (so this is a stage 2 page - * table walk), must be true if this is stage 2 of a stage 1+2 + * @s1_is_el0: if @ptw->in_mmu_idx is ARMMMUIdx_Stage2 + * (so this is a stage 2 page table walk), + * must be true if this is stage 2 of a stage 1+2 * walk for an EL0 access. If @mmu_idx is anything else, * @s1_is_el0 is ignored. * @result: set on translation success, * @fi: set to fault info if the translation fails */ -static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - bool is_secure, bool s1_is_el0, +static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, + uint64_t address, + MMUAccessType access_type, bool s1_is_el0, GetPhysAddrResult *result, ARMMMUFaultInfo *fi) { ARMCPU *cpu = env_archcpu(env); + ARMMMUIdx mmu_idx = ptw->in_mmu_idx; + bool is_secure = ptw->in_secure; /* Read an LPAE long-descriptor translation table. */ ARMFaultType fault_type = ARMFault_Translation; uint32_t level; @@ -1204,7 +1218,8 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, descaddr |= (address >> (stride * (4 - level))) & indexmask; descaddr &= ~7ULL; nstable = extract32(tableattrs, 4, 1); - descriptor = arm_ldq_ptw(env, descaddr, !nstable, mmu_idx, fi); + ptw->in_secure = !nstable; + descriptor = arm_ldq_ptw(env, ptw, descaddr, fi); if (fi->type != ARMFault_None) { goto do_fault; } @@ -2361,6 +2376,7 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, ARMMMUFaultInfo *fi) { ARMMMUIdx s1_mmu_idx = stage_1_mmu_idx(mmu_idx); + S1Translate ptw; if (mmu_idx != s1_mmu_idx) { /* @@ -2373,7 +2389,6 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, int ret; bool ipa_secure, s2walk_secure; ARMCacheAttrs cacheattrs1; - ARMMMUIdx s2_mmu_idx; bool is_el0; uint64_t hcr; @@ -2398,8 +2413,9 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, s2walk_secure = false; } - s2_mmu_idx = (s2walk_secure - ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2); + ptw.in_mmu_idx = + s2walk_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; + ptw.in_secure = s2walk_secure; is_el0 = mmu_idx == ARMMMUIdx_E10_0; /* @@ -2411,8 +2427,8 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, cacheattrs1 = result->cacheattrs; memset(result, 0, sizeof(*result)); - ret = get_phys_addr_lpae(env, ipa, access_type, s2_mmu_idx, - s2walk_secure, is_el0, result, fi); + ret = get_phys_addr_lpae(env, &ptw, ipa, access_type, + is_el0, result, fi); fi->s2addr = ipa; /* Combine the S1 and S2 perms. */ @@ -2517,15 +2533,17 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, return get_phys_addr_disabled(env, address, access_type, mmu_idx, is_secure, result, fi); } + + ptw.in_mmu_idx = mmu_idx; + ptw.in_secure = is_secure; + if (regime_using_lpae_format(env, mmu_idx)) { - return get_phys_addr_lpae(env, address, access_type, mmu_idx, - is_secure, false, result, fi); + return get_phys_addr_lpae(env, &ptw, address, access_type, false, + result, fi); } else if (regime_sctlr(env, mmu_idx) & SCTLR_XP) { - return get_phys_addr_v6(env, address, access_type, mmu_idx, - is_secure, result, fi); + return get_phys_addr_v6(env, &ptw, address, access_type, result, fi); } else { - return get_phys_addr_v5(env, address, access_type, mmu_idx, - is_secure, result, fi); + return get_phys_addr_v5(env, &ptw, address, access_type, result, fi); } } From patchwork Tue Oct 11 03:18:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614153 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2370833pvb; Mon, 10 Oct 2022 20:29:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4DHBEIquXzzj2SO0SiX62Ru19Lgsej3R3OlalLKRcoKfEyuWypGiefmniv+iGzGQ1uEWM6 X-Received: by 2002:a05:620a:c85:b0:6ee:6fcf:cd45 with SMTP id q5-20020a05620a0c8500b006ee6fcfcd45mr2613562qki.595.1665458992485; Mon, 10 Oct 2022 20:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665458992; cv=none; d=google.com; s=arc-20160816; b=vh9Yzr75ET91758JeAkhej1HV6yqVyRxn6Gqnf/dxDYGTXnA5j68TsLFBvOcwZuN4n HfzRlsculJqESJwBNZR/4iAnBbM8HKyggMP2Aw31tlz1UUMVVDtapwMftiBTEF2fs9kn foWXmLtW0xM3NY4cGK/4KM2gEttDyakursLeGG7ytbUH64fKiFpJI7eflev2TeISpNx9 GHbLHsWLG0t4E+uFAq1qnSI8V2dkzDyoXkbsbLeviJp9J5T6PzGsMoKOV/LD/nT/vsDz wi93ZAJEetmWxt3bupRg007FkYDlXw2A9IKQEMSdIoRwHqAk4PbnAPO4tIC/Uq9vSMFt c7RQ== 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=xuiahaoEiVXlEWMWoZrC9RsYeFhfjxrmLG3QQS2jVro=; b=n4/DE20pqqhVO0WsMczslc4Lol38ArWRAMFBlvHY023WmCd/nTG7n/bFrZ+5hAqFu+ G8nk+jzfxJXw7m5VVurX+a/XtBTwTSqJ9XYHBqBcGv91ONsZZo5d2d/HhEQh6bER/qvO ResJP/xz/zIVY+vv7sRTqsykWlisCE552VBcFA69+myQg3cCTpnCCiavm5pXEHmbXR9g BfKLAuKDO64AKOUb4RRNlQuqJXryizLvDjFyTqziArNemIeBCkGRB39ONfoFaOytJo6V Scj4L+J+wjO/ekmcsB8gyppbO/RxMhW/S8iruYloQzplOuYoC3ewVeszQtXaAjirFgx5 xI/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GiM3QLQV; 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 h13-20020ac8514d000000b00342fa30095asi6101564qtn.55.2022.10.10.20.29.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:29:52 -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=GiM3QLQV; 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]:46724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi5xo-0002tM-0U for patch@linaro.org; Mon, 10 Oct 2022 23:29:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33670) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5nr-0002NT-Rk for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:38 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:44581) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5nk-00031I-MT for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:35 -0400 Received: by mail-pl1-x62c.google.com with SMTP id x6so11999983pll.11 for ; Mon, 10 Oct 2022 20:19:27 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xuiahaoEiVXlEWMWoZrC9RsYeFhfjxrmLG3QQS2jVro=; b=GiM3QLQVJoJRttJ8CKLTLc0SgJ7+E527/RkG+z2N+oeoz7/4LEpHKgCa3K4u+/aMGY esXyczKHzLHOsYxAgKk/pvGU8/O5noPw5KN9KlxlX0S/FMGNaCrLb8PxUo3KNCe862oe TNNnJSEQderXVV65LEFZptBXmhLk1cnbjKcv4ZoSmElD18ITH+mONAFj1nJA+WhRxEVJ sO4oMA0c+y78uaYOkggtR7Aw1w8HzV/IBe3SvD0NTtO3Tw5m+z1xp6OgJ9lbQxKBI1VP Ziav712riKXjoRZXX2iFkemKeTQb+jj6wbU6PSSltq3dZLmq9aW8EefOyZDStjBbnY9N bxvw== 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=xuiahaoEiVXlEWMWoZrC9RsYeFhfjxrmLG3QQS2jVro=; b=f3+geYeoGjlb25a2LK/Z9k9tBSSO4AUzKwU1I1qqsr93H6+kDgM7RyYtj4OdjS06on viQgBY/nCm9Mck2ODY87f0IxjLFIOOffoGecc9OBc7maTd/Urgdrli+chxhZ1VmEIAAG O39JH4stSqDv4DNScAdb0bC+QIzTjCtfM+2ETjoNBDH+8+aEv8k4MW/5dFqxjgB96y7A 88NZ3F95Hfc7t9EbAusgNMpfeMGDPKHq0setad2ESZEoIHhRUH7mPHXmVEA664BUhuS0 +D7jtMUsVwH5s2Y3CFP7QCC06Kd5tQkGME2Rp1q/9MXSc/qeFgOq3Th8Tko7+frb1O1F pqKQ== X-Gm-Message-State: ACrzQf1/6rpZtRLdqqTdyiL5vocUGYz8+AgGJsmAadHZhaDZ2/IKxtlU NcjN739gtdwL0r2B8UFvpfH9l3SdD7lJkA== X-Received: by 2002:a17:90a:e7cd:b0:20a:c658:c185 with SMTP id kb13-20020a17090ae7cd00b0020ac658c185mr24710531pjb.114.1665458366555; Mon, 10 Oct 2022 20:19:26 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 08/24] target/arm: Plumb debug into S1Translate Date: Mon, 10 Oct 2022 20:18:55 -0700 Message-Id: <20221011031911.2408754-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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" Before using softmmu page tables for the ptw, plumb down a debug parameter so that we can query page table entries from gdbstub without modifying cpu state. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v4: Add debug to S1Translate, and plumb the S1Translate structure down from the very outside. It means that S1Translate is now perhaps mis-named, but it also eliminates the "secure_debug" function name. --- target/arm/ptw.c | 55 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index dee69ee743..8fa0088d98 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -17,6 +17,7 @@ typedef struct S1Translate { ARMMMUIdx in_mmu_idx; bool in_secure; + bool in_debug; bool out_secure; hwaddr out_phys; } S1Translate; @@ -230,6 +231,7 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, S1Translate s2ptw = { .in_mmu_idx = s2_mmu_idx, .in_secure = is_secure, + .in_debug = ptw->in_debug, }; uint64_t hcr; int ret; @@ -2370,13 +2372,15 @@ static bool get_phys_addr_disabled(CPUARMState *env, target_ulong address, return 0; } -bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, - MMUAccessType access_type, ARMMMUIdx mmu_idx, - bool is_secure, GetPhysAddrResult *result, - ARMMMUFaultInfo *fi) +static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw, + target_ulong address, + MMUAccessType access_type, + GetPhysAddrResult *result, + ARMMMUFaultInfo *fi) { + ARMMMUIdx mmu_idx = ptw->in_mmu_idx; ARMMMUIdx s1_mmu_idx = stage_1_mmu_idx(mmu_idx); - S1Translate ptw; + bool is_secure = ptw->in_secure; if (mmu_idx != s1_mmu_idx) { /* @@ -2392,8 +2396,9 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, bool is_el0; uint64_t hcr; - ret = get_phys_addr_with_secure(env, address, access_type, - s1_mmu_idx, is_secure, result, fi); + ptw->in_mmu_idx = s1_mmu_idx; + ret = get_phys_addr_with_struct(env, ptw, address, access_type, + result, fi); /* If S1 fails or S2 is disabled, return early. */ if (ret || regime_translation_disabled(env, ARMMMUIdx_Stage2, @@ -2413,9 +2418,9 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, s2walk_secure = false; } - ptw.in_mmu_idx = + ptw->in_mmu_idx = s2walk_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; - ptw.in_secure = s2walk_secure; + ptw->in_secure = s2walk_secure; is_el0 = mmu_idx == ARMMMUIdx_E10_0; /* @@ -2427,7 +2432,7 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, cacheattrs1 = result->cacheattrs; memset(result, 0, sizeof(*result)); - ret = get_phys_addr_lpae(env, &ptw, ipa, access_type, + ret = get_phys_addr_lpae(env, ptw, ipa, access_type, is_el0, result, fi); fi->s2addr = ipa; @@ -2534,19 +2539,29 @@ bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, is_secure, result, fi); } - ptw.in_mmu_idx = mmu_idx; - ptw.in_secure = is_secure; - if (regime_using_lpae_format(env, mmu_idx)) { - return get_phys_addr_lpae(env, &ptw, address, access_type, false, + return get_phys_addr_lpae(env, ptw, address, access_type, false, result, fi); } else if (regime_sctlr(env, mmu_idx) & SCTLR_XP) { - return get_phys_addr_v6(env, &ptw, address, access_type, result, fi); + return get_phys_addr_v6(env, ptw, address, access_type, result, fi); } else { - return get_phys_addr_v5(env, &ptw, address, access_type, result, fi); + return get_phys_addr_v5(env, ptw, address, access_type, result, fi); } } +bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address, + MMUAccessType access_type, ARMMMUIdx mmu_idx, + bool is_secure, GetPhysAddrResult *result, + ARMMMUFaultInfo *fi) +{ + S1Translate ptw = { + .in_mmu_idx = mmu_idx, + .in_secure = is_secure, + }; + return get_phys_addr_with_struct(env, &ptw, address, access_type, + result, fi); +} + bool get_phys_addr(CPUARMState *env, target_ulong address, MMUAccessType access_type, ARMMMUIdx mmu_idx, GetPhysAddrResult *result, ARMMMUFaultInfo *fi) @@ -2595,12 +2610,16 @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr, { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; + S1Translate ptw = { + .in_mmu_idx = arm_mmu_idx(env), + .in_secure = arm_is_secure(env), + .in_debug = true, + }; GetPhysAddrResult res = {}; ARMMMUFaultInfo fi = {}; - ARMMMUIdx mmu_idx = arm_mmu_idx(env); bool ret; - ret = get_phys_addr(env, addr, MMU_DATA_LOAD, mmu_idx, &res, &fi); + ret = get_phys_addr_with_struct(env, &ptw, addr, MMU_DATA_LOAD, &res, &fi); *attrs = res.f.attrs; if (ret) { From patchwork Tue Oct 11 03:18:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614150 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2370209pvb; Mon, 10 Oct 2022 20:27:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4agcXL0EpdVcbFjq54ntDWao4r2kTlKqjIDkHJj92bIZQPnHilfux4ybQfeiACf8+Yf5T+ X-Received: by 2002:a05:620a:f03:b0:6cf:c0a1:20bc with SMTP id v3-20020a05620a0f0300b006cfc0a120bcmr15116037qkl.663.1665458853064; Mon, 10 Oct 2022 20:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665458853; cv=none; d=google.com; s=arc-20160816; b=T1ycD2YkWcSvANSST2eZ9Zm5OfO9pIxZSpMEQ7oerUJU15GQkDa9P3e3oXFipjEGNn VbOC94EyHI9KaaNy2mUHBnabY+LMEVV7g6t9Qj8EjHzP7wW5LPwLUDjb6wySFDBDpown rdwk/Y5pDeABRREft2UJ0SGG18Cucl3C2pXfSNT/jheRojDa5GGR7Euu+vzl/j9d8oDC /E5oMtGHRpPQrqGs3bJsXwM2jTX7+zLhf4RP7xLdLX3MPq8vijz/P5k6H/3lisdWKIIp i/Ri9bAI0PTrqJCXjkLaT2G8AsQn3r3tFYNwTQwAyQ6KBhNeWRoBsD7AmOIKAGuzFYrM Y+tw== 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=dJuTd0SPwgfrCTEDatav1bD/h1Bh2C4XRFMrqpA+5GE=; b=zG57Ibrk4eWxFGD9d9zJ1JAENF9238986OuV0cdn4jddghwOB+Od6NGZeDNzojynXU rcEObtfwQfSETBSXBlV4SBq94vGdzeTtUVBKnVT729ywLf0Blxe4B/TUA40XMVBPzHUN 9Ut25FmQUyndAbwKcZxb7QFv+2+fg02KuxngSBSb8N0aVCKbQTA9WO5c0TKqyPxJRiZ6 /Me9KKYy4WAd7X6xxqsp7ds2UkL5kT5+zodFttI98DSex7FmVoPmPoeLmyOnA7k0XfGD ym+iHj+4vyQJr88uKsZZfZYz6YiB9/IvAPQDlKnIHLQOa0A1FWxg3TLCRr8vuIzo5NaY yjAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zpmd92Cv; 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 dv3-20020ad44ee3000000b004b367101932si6239100qvb.23.2022.10.10.20.27.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:27:33 -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=zpmd92Cv; 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]:56850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi5vY-00068o-Hx for patch@linaro.org; Mon, 10 Oct 2022 23:27:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5nt-0002OJ-AO for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:38 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:36489) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5nm-00031l-TC for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:37 -0400 Received: by mail-pl1-x635.google.com with SMTP id c24so12036185plo.3 for ; Mon, 10 Oct 2022 20:19:29 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dJuTd0SPwgfrCTEDatav1bD/h1Bh2C4XRFMrqpA+5GE=; b=zpmd92Cvkk6YDZoie7K9QJDeyE8WWXtXCnW+EKJIXtW27KFZVnrgz3T3oL3ytifYU+ UGe9RFZYBDR7Iv3eGHitfUQy2YGBwoJxU0LdUxduEmMqjdSZ4APc9BWMs3DVC8mzXsAC RHdAGEJpIzpcYaQ+4QwFFeTeTuwlaRsAK60IvcKA5GENdo89ZlykR/m+/hlThwurOIP8 b96CNzfLQ4AhquU8/q2+L86baNci2IHlQcY7rBi5kZ8ZXgi8EfROnsoPo/ZGZ1XoEZOa k9495FB5vCrT1yyhG9o9dB3bNOyF8SeSHgdaBJI/4jTA6WRCsiti9KC7OLcAie0TUvdb r6Qg== 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=dJuTd0SPwgfrCTEDatav1bD/h1Bh2C4XRFMrqpA+5GE=; b=IxYu7SlalhvjNqkIT/0BQ2YGTaW+NM4qNBdMzG7MO+bfQnisaxe9a4GyceJjPDDF2v UROxo9am5PmgcTEFSJfLF3gauw1jj+ulfa/H7iL0ZdEXFRbuvg+ja92ZlRbtfr54N82V 4oXwtV6u3aDKThlpZGQJmscm01J0DQBxvaR2sMf8ElsaCVArBpK9spQzwaUVbgVqdkIN Gf8WmJ/mek/77xNH5vmMgd29Hk5h3sjUMKvUEi91UU3QwgPKmJSeske+hPMhdhd45l0y WpdX6offryNNAfE2OVGsH3eWgzDXtnyOl0WmckQv47xtVIVE4Bf5dEqGv+5PdsFRr4Hp l2sA== X-Gm-Message-State: ACrzQf02wWn19lf8qv0Pa0OfIWYAYmorJiIOP4JcZ+/Ci0pySD+u1WUr BUtJ3f2Hp3zFK19eUWc07+mbpFVBVfuQiA== X-Received: by 2002:a17:903:41ce:b0:182:a32f:4dde with SMTP id u14-20020a17090341ce00b00182a32f4ddemr7197864ple.47.1665458368864; Mon, 10 Oct 2022 20:19:28 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 09/24] target/arm: Move be test for regime into S1TranslateResult Date: Mon, 10 Oct 2022 20:18:56 -0700 Message-Id: <20221011031911.2408754-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Hoist this test out of arm_ld[lq]_ptw into S1_ptw_translate. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/ptw.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 8fa0088d98..c58788ac69 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -19,6 +19,7 @@ typedef struct S1Translate { bool in_secure; bool in_debug; bool out_secure; + bool out_be; hwaddr out_phys; } S1Translate; @@ -277,6 +278,7 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, ptw->out_secure = is_secure; ptw->out_phys = addr; + ptw->out_be = regime_translation_big_endian(env, ptw->in_mmu_idx); return true; } @@ -296,7 +298,7 @@ static uint32_t arm_ldl_ptw(CPUARMState *env, S1Translate *ptw, hwaddr addr, addr = ptw->out_phys; attrs.secure = ptw->out_secure; as = arm_addressspace(cs, attrs); - if (regime_translation_big_endian(env, ptw->in_mmu_idx)) { + if (ptw->out_be) { data = address_space_ldl_be(as, addr, attrs, &result); } else { data = address_space_ldl_le(as, addr, attrs, &result); @@ -324,7 +326,7 @@ static uint64_t arm_ldq_ptw(CPUARMState *env, S1Translate *ptw, hwaddr addr, addr = ptw->out_phys; attrs.secure = ptw->out_secure; as = arm_addressspace(cs, attrs); - if (regime_translation_big_endian(env, ptw->in_mmu_idx)) { + if (ptw->out_be) { data = address_space_ldq_be(as, addr, attrs, &result); } else { data = address_space_ldq_le(as, addr, attrs, &result); From patchwork Tue Oct 11 03:18:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614154 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2371261pvb; Mon, 10 Oct 2022 20:31:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5EhuFKtDgozinzMCauxjGIjTRO+IIYUUB0P232ejJjRkHNm4Ai1c6FVHhCqjxdznKIxLe6 X-Received: by 2002:a05:620a:45a0:b0:6ce:4ba5:2da8 with SMTP id bp32-20020a05620a45a000b006ce4ba52da8mr14529390qkb.244.1665459082132; Mon, 10 Oct 2022 20:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665459082; cv=none; d=google.com; s=arc-20160816; b=kl1dnvtc5n9JN402koDP810jH/QGGFdJ3Qu41HbioHcFeDGnDeuvgsFAfJ2z4ZdwTR mmq0BYBghZ2HjTQAgnfEnk7MyzrJN64W8ooCMxBnDFm7Y1lhsxXEcebBKEk1Ogq8+O5Z iMUjGwQHFdgLHn/34pVBhiy4bNN1nNJfh753HRZwyvexado/ULeQf7i6fk5UJ6ib2qUz mt9HqZDi0Z4Fgf2G9Q/pKHG+Y30B/q3X7wayJdzbwPAuTdolhvuilUyZam8VwbVd240a YdYSssu1PlunOWVd5he5ZgEivfId7L7UbLZ5o1+16hgM8vuVyffxhfso8jx6MPmSbVBn ut4Q== 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=pfoOzEF8z1y58sSX0+3veBaBG5ktJhjr7JEkqbUwE4g=; b=XnG0zPqdrgiVdv5gnWmD49R7W3emALY6B2WYH1Gpt4eEFWDos//C06Az0wi+InzPcd PbIGiS24PTSCLmmgQ/dqEhFyZEUnSEAF3VN89iUk2MnSfA7G6rM2TNTrJmP/P4zKdIFb NQXpaeBH1p77DJX1KJQkA6c5vo0s3R+LBwMby80yc81GANJ+DHGjbe3KX8VC4dObpwhw m0/O2h3on895+w83NjCX+P91NtI7doxCJ5zEH0TbWiUmUCFjzD0to0a4itEjracnkR3J 843QFQ7YcXPZll/HsqBuucZxle8EbcL9fMuLRorQzfsweeE1kiIePTPh8+fo2MvL1c0T bYyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=znMfUxuo; 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 q26-20020ac8411a000000b0039bd340f90fsi930795qtl.235.2022.10.10.20.31.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:31:22 -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=znMfUxuo; 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]:55076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi5zF-0004KP-Kk for patch@linaro.org; Mon, 10 Oct 2022 23:31:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5nu-0002OP-Cl for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:38 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:41875) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5no-00032I-O6 for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:38 -0400 Received: by mail-pf1-x42f.google.com with SMTP id g28so12344311pfk.8 for ; Mon, 10 Oct 2022 20:19:32 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pfoOzEF8z1y58sSX0+3veBaBG5ktJhjr7JEkqbUwE4g=; b=znMfUxuobBesxG5EqUB9Te7IwcpyqQR9yW3rrns6+B8t7jkKTmV0qZI7F6urfzJglH wTCu8pMJtZ9rDPHVINkaw6fA8KYWncUvhmby6MRrEn1lKew/Qvme0Dm8iISVML2mlIgt pxa8O11JJKOfmo1loTcvDDGr3LiNtLPzjoJDniD6GcT/FRMk5+6MJmcbn9616wNH5vRZ fLQ19MHPDdTLrGhKSBjrWrSnwSKtCq8ANvvMr+NgHp4nixQCF+ViEPaKbkOZ6yj3MxuZ m9l1L9PqxHo7uqi3qcF3CT31R1/MrSXd5h8yKM0USPhfZJ66PtJL+l0pg701J0QZDmaA sKpA== 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=pfoOzEF8z1y58sSX0+3veBaBG5ktJhjr7JEkqbUwE4g=; b=xaWNArvosnTzYF7WdZ/cnad8ID0ZtrpSE2KxWG4TVEwY9D49uDuC/GA3dgIcnbjSRB e3WIeiiPz2pxlcI04gSxgzt3qX6yi3GR+xnvtt9YyILrH3ktc2/pZFUUPE5CFs2eK6Mk 0T2kL3tBTbHvUIouSPm1f5JpkQ9XLUgiowi9iMAV7CsFbVw160PLRk3iBU2GFZFQ6tHn MgjE6CTQLS2DTqAkPSdp/utCsa/xosgSavLtTb4JN9sJjGDZQoiOG9k0YdVfwsk+Y483 N1bc+tvCIg8LjKwkpX03vBURrZ3XHI4XxQ3qNr9RR5XslJ3gAQl8hGCg0mSQXmQzJ9Ld gzSA== X-Gm-Message-State: ACrzQf2/oyLE9ObhOrH8xd+SomiKNP0xlSdxrUkzhlbLGuo+/MUIa/9d PrEqnr3dNmB6K9nFUC6Ufwtl2V4SozMf5Q== X-Received: by 2002:a05:6a00:1a0e:b0:547:1cf9:40e8 with SMTP id g14-20020a056a001a0e00b005471cf940e8mr22973273pfv.82.1665458371304; Mon, 10 Oct 2022 20:19:31 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 10/24] target/arm: Use softmmu tlbs for page table walking Date: Mon, 10 Oct 2022 20:18:57 -0700 Message-Id: <20221011031911.2408754-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" So far, limit the change to S1_ptw_translate, arm_ldl_ptw, and arm_ldq_ptw. Use probe_access_full to find the host address, and if so use a host load. If the probe fails, we've got our fault info already. On the off chance that page tables are not in RAM, continue to use the address_space_ld* functions. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v4: Put the host address into S1Translate immediately. --- target/arm/cpu.h | 5 + target/arm/ptw.c | 196 +++++++++++++++++++++++++--------------- target/arm/tlb_helper.c | 17 +++- 3 files changed, 144 insertions(+), 74 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index c94e289012..e9e77b7563 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -225,6 +225,8 @@ typedef struct CPUARMTBFlags { target_ulong flags2; } CPUARMTBFlags; +typedef struct ARMMMUFaultInfo ARMMMUFaultInfo; + typedef struct CPUArchState { /* Regs for current mode. */ uint32_t regs[16]; @@ -715,6 +717,9 @@ typedef struct CPUArchState { struct CPUBreakpoint *cpu_breakpoint[16]; struct CPUWatchpoint *cpu_watchpoint[16]; + /* Optional fault info across tlb lookup. */ + ARMMMUFaultInfo *tlb_fi; + /* Fields up to this point are cleared by a CPU reset */ struct {} end_reset_fields; diff --git a/target/arm/ptw.c b/target/arm/ptw.c index c58788ac69..8f41d285b7 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -9,6 +9,7 @@ #include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/range.h" +#include "exec/exec-all.h" #include "cpu.h" #include "internals.h" #include "idau.h" @@ -21,6 +22,7 @@ typedef struct S1Translate { bool out_secure; bool out_be; hwaddr out_phys; + void *out_host; } S1Translate; static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, @@ -200,7 +202,7 @@ static bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx, return (regime_sctlr(env, mmu_idx) & SCTLR_M) == 0; } -static bool ptw_attrs_are_device(uint64_t hcr, ARMCacheAttrs cacheattrs) +static bool S2_attrs_are_device(uint64_t hcr, uint8_t attrs) { /* * For an S1 page table walk, the stage 1 attributes are always @@ -211,11 +213,10 @@ static bool ptw_attrs_are_device(uint64_t hcr, ARMCacheAttrs cacheattrs) * With HCR_EL2.FWB == 1 this is when descriptor bit [4] is 0, ie * when cacheattrs.attrs bit [2] is 0. */ - assert(cacheattrs.is_s2_format); if (hcr & HCR_FWB) { - return (cacheattrs.attrs & 0x4) == 0; + return (attrs & 0x4) == 0; } else { - return (cacheattrs.attrs & 0xc) == 0; + return (attrs & 0xc) == 0; } } @@ -224,32 +225,65 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, hwaddr addr, ARMMMUFaultInfo *fi) { bool is_secure = ptw->in_secure; + ARMMMUIdx mmu_idx = ptw->in_mmu_idx; ARMMMUIdx s2_mmu_idx = is_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; + bool s2_phys = false; + uint8_t pte_attrs; + bool pte_secure; - if (arm_mmu_idx_is_stage1_of_2(ptw->in_mmu_idx) && - !regime_translation_disabled(env, s2_mmu_idx, is_secure)) { - GetPhysAddrResult s2 = {}; - S1Translate s2ptw = { - .in_mmu_idx = s2_mmu_idx, - .in_secure = is_secure, - .in_debug = ptw->in_debug, - }; - uint64_t hcr; - int ret; + if (!arm_mmu_idx_is_stage1_of_2(mmu_idx) + || regime_translation_disabled(env, s2_mmu_idx, is_secure)) { + s2_mmu_idx = is_secure ? ARMMMUIdx_Phys_S : ARMMMUIdx_Phys_NS; + s2_phys = true; + } - ret = get_phys_addr_lpae(env, &s2ptw, addr, MMU_DATA_LOAD, - false, &s2, fi); - if (ret) { - assert(fi->type != ARMFault_None); - fi->s2addr = addr; - fi->stage2 = true; - fi->s1ptw = true; - fi->s1ns = !is_secure; - return false; + if (unlikely(ptw->in_debug)) { + /* + * From gdbstub, do not use softmmu so that we don't modify the + * state of the cpu at all, including softmmu tlb contents. + */ + if (s2_phys) { + ptw->out_phys = addr; + pte_attrs = 0; + pte_secure = is_secure; + } else { + S1Translate s2ptw = { + .in_mmu_idx = s2_mmu_idx, + .in_secure = is_secure, + .in_debug = true, + }; + GetPhysAddrResult s2 = { }; + if (!get_phys_addr_lpae(env, &s2ptw, addr, MMU_DATA_LOAD, + false, &s2, fi)) { + goto fail; + } + ptw->out_phys = s2.f.phys_addr; + pte_attrs = s2.cacheattrs.attrs; + pte_secure = s2.f.attrs.secure; } + ptw->out_host = NULL; + } else { + CPUTLBEntryFull *full; + int flags; - hcr = arm_hcr_el2_eff_secstate(env, is_secure); - if ((hcr & HCR_PTW) && ptw_attrs_are_device(hcr, s2.cacheattrs)) { + env->tlb_fi = fi; + flags = probe_access_full(env, addr, MMU_DATA_LOAD, + arm_to_core_mmu_idx(s2_mmu_idx), + true, &ptw->out_host, &full, 0); + env->tlb_fi = NULL; + + if (unlikely(flags & TLB_INVALID_MASK)) { + goto fail; + } + ptw->out_phys = full->phys_addr; + pte_attrs = full->pte_attrs; + pte_secure = full->attrs.secure; + } + + if (!s2_phys) { + uint64_t hcr = arm_hcr_el2_eff_secstate(env, is_secure); + + if ((hcr & HCR_PTW) && S2_attrs_are_device(hcr, pte_attrs)) { /* * PTW set and S1 walk touched S2 Device memory: * generate Permission fault. @@ -261,25 +295,23 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, fi->s1ns = !is_secure; return false; } - - if (arm_is_secure_below_el3(env)) { - /* Check if page table walk is to secure or non-secure PA space. */ - if (is_secure) { - is_secure = !(env->cp15.vstcr_el2 & VSTCR_SW); - } else { - is_secure = !(env->cp15.vtcr_el2 & VTCR_NSW); - } - } else { - assert(!is_secure); - } - - addr = s2.f.phys_addr; } - ptw->out_secure = is_secure; - ptw->out_phys = addr; - ptw->out_be = regime_translation_big_endian(env, ptw->in_mmu_idx); + /* Check if page table walk is to secure or non-secure PA space. */ + ptw->out_secure = (is_secure + && !(pte_secure + ? env->cp15.vstcr_el2 & VSTCR_SW + : env->cp15.vtcr_el2 & VTCR_NSW)); + ptw->out_be = regime_translation_big_endian(env, mmu_idx); return true; + + fail: + assert(fi->type != ARMFault_None); + fi->s2addr = addr; + fi->stage2 = true; + fi->s1ptw = true; + fi->s1ns = !is_secure; + return false; } /* All loads done in the course of a page table walk go through here. */ @@ -287,56 +319,78 @@ static uint32_t arm_ldl_ptw(CPUARMState *env, S1Translate *ptw, hwaddr addr, ARMMMUFaultInfo *fi) { CPUState *cs = env_cpu(env); - MemTxAttrs attrs = {}; - MemTxResult result = MEMTX_OK; - AddressSpace *as; uint32_t data; if (!S1_ptw_translate(env, ptw, addr, fi)) { + /* Failure. */ + assert(fi->s1ptw); return 0; } - addr = ptw->out_phys; - attrs.secure = ptw->out_secure; - as = arm_addressspace(cs, attrs); - if (ptw->out_be) { - data = address_space_ldl_be(as, addr, attrs, &result); + + if (likely(ptw->out_host)) { + /* Page tables are in RAM, and we have the host address. */ + if (ptw->out_be) { + data = ldl_be_p(ptw->out_host); + } else { + data = ldl_le_p(ptw->out_host); + } } else { - data = address_space_ldl_le(as, addr, attrs, &result); + /* Page tables are in MMIO. */ + MemTxAttrs attrs = { .secure = ptw->out_secure }; + AddressSpace *as = arm_addressspace(cs, attrs); + MemTxResult result = MEMTX_OK; + + if (ptw->out_be) { + data = address_space_ldl_be(as, ptw->out_phys, attrs, &result); + } else { + data = address_space_ldl_le(as, ptw->out_phys, attrs, &result); + } + if (unlikely(result != MEMTX_OK)) { + fi->type = ARMFault_SyncExternalOnWalk; + fi->ea = arm_extabort_type(result); + return 0; + } } - if (result == MEMTX_OK) { - return data; - } - fi->type = ARMFault_SyncExternalOnWalk; - fi->ea = arm_extabort_type(result); - return 0; + return data; } static uint64_t arm_ldq_ptw(CPUARMState *env, S1Translate *ptw, hwaddr addr, ARMMMUFaultInfo *fi) { CPUState *cs = env_cpu(env); - MemTxAttrs attrs = {}; - MemTxResult result = MEMTX_OK; - AddressSpace *as; uint64_t data; if (!S1_ptw_translate(env, ptw, addr, fi)) { + /* Failure. */ + assert(fi->s1ptw); return 0; } - addr = ptw->out_phys; - attrs.secure = ptw->out_secure; - as = arm_addressspace(cs, attrs); - if (ptw->out_be) { - data = address_space_ldq_be(as, addr, attrs, &result); + + if (likely(ptw->out_host)) { + /* Page tables are in RAM, and we have the host address. */ + if (ptw->out_be) { + data = ldq_be_p(ptw->out_host); + } else { + data = ldq_le_p(ptw->out_host); + } } else { - data = address_space_ldq_le(as, addr, attrs, &result); + /* Page tables are in MMIO. */ + MemTxAttrs attrs = { .secure = ptw->out_secure }; + AddressSpace *as = arm_addressspace(cs, attrs); + MemTxResult result = MEMTX_OK; + + if (ptw->out_be) { + data = address_space_ldq_be(as, ptw->out_phys, attrs, &result); + } else { + data = address_space_ldq_le(as, ptw->out_phys, attrs, &result); + } + if (unlikely(result != MEMTX_OK)) { + fi->type = ARMFault_SyncExternalOnWalk; + fi->ea = arm_extabort_type(result); + return 0; + } } - if (result == MEMTX_OK) { - return data; - } - fi->type = ARMFault_SyncExternalOnWalk; - fi->ea = arm_extabort_type(result); - return 0; + return data; } static bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx, diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c index 3462a6ea14..69b0dc69df 100644 --- a/target/arm/tlb_helper.c +++ b/target/arm/tlb_helper.c @@ -208,10 +208,21 @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size, bool probe, uintptr_t retaddr) { ARMCPU *cpu = ARM_CPU(cs); - ARMMMUFaultInfo fi = {}; GetPhysAddrResult res = {}; + ARMMMUFaultInfo local_fi, *fi; int ret; + /* + * Allow S1_ptw_translate to see any fault generated here. + * Since this may recurse, read and clear. + */ + fi = cpu->env.tlb_fi; + if (fi) { + cpu->env.tlb_fi = NULL; + } else { + fi = memset(&local_fi, 0, sizeof(local_fi)); + } + /* * Walk the page table and (if the mapping exists) add the page * to the TLB. On success, return true. Otherwise, if probing, @@ -220,7 +231,7 @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size, */ ret = get_phys_addr(&cpu->env, address, access_type, core_to_arm_mmu_idx(&cpu->env, mmu_idx), - &res, &fi); + &res, fi); if (likely(!ret)) { /* * Map a single [sub]page. Regions smaller than our declared @@ -242,7 +253,7 @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size, } else { /* now we have a real cpu fault */ cpu_restore_state(cs, retaddr, true); - arm_deliver_fault(cpu, address, access_type, mmu_idx, &fi); + arm_deliver_fault(cpu, address, access_type, mmu_idx, fi); } } #else From patchwork Tue Oct 11 03:18:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614155 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2371836pvb; Mon, 10 Oct 2022 20:32:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM55tUajMxT7G9d8A+C7b74EUGxCBb8llBaY+YKoxNPBPbe0Ziduei6Amdo/0VN5LgoYoqKM X-Received: by 2002:a05:622a:308:b0:392:ab2d:895 with SMTP id q8-20020a05622a030800b00392ab2d0895mr17492159qtw.4.1665459168088; Mon, 10 Oct 2022 20:32:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665459168; cv=none; d=google.com; s=arc-20160816; b=xIRNB9LCByjr8Ym0RowduVbMzeFxxlkiGVHvnb8H+TLQCZJu/hQ/Jo0BCc2wqK+T6l jafUP2hPxTkvGLKslNWoGUVhCEvL7KkGot+MHevHW218PmkghLAzEongDoYCaAs49jAP ZIc4kPZxdb0fALAuNxjnGmDLw5midmBF33DpXJlCwuUrvnPgReFPJzjochS9cPl9YSOE vmgPr61pCcHw5y1ZLb0yomqkXfZNOcLV2xqPQQbXfAxVG2JTJ2cc6BEoVfaJTeAZfQEa 1FG93f6GNXtav0g2JsLjxRCqYuDrd+zXNn7r725bZzk551sqnpkWyw+s8SBx7E+IMaBJ J/Og== 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=6arXbE/EfddoNglUvqf08geiApKNWyNMEO6HKIy2RZ8=; b=V4V9sNUgWL0etKzhqfm5U06lWj0LV7M95+9CsIp/TRQBjYuOYF8H6NI1nOQvHR7R6R uaEBxirhmqb09aMvnOvuMmJw2EuNYmPQ7knSxuoHVHyWc47m19KvSRJzL4Te5xCVd4Ma JzVaIxHpa3UItxq9h9+Mrzq2t3tDWeuuw3zypxk8V9E6SQeTdIugGFOVclHI2zoZV7Er HHqPWQ3vmjqlLkhL9+CILdBv+R+GMa+caU83wiUZ20kKXHVOoA/9cdWQAd4hJbQZOwax LTmWhlFnwxeFrbGE0eOIBu4QAurjIOjIok1V+x8YzKarrlt7SoF14iSfa/L6mVbFX0Ki X2Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UQ3/bKlq"; 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 m11-20020a05622a054b00b0035d48149086si2889341qtx.378.2022.10.10.20.32.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:32:48 -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="UQ3/bKlq"; 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]:37368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi60d-0005kR-Bb for patch@linaro.org; Mon, 10 Oct 2022 23:32:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5nw-0002Rh-Mb for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:41 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:34761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5nq-00032t-BP for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:39 -0400 Received: by mail-pf1-x429.google.com with SMTP id f140so12377608pfa.1 for ; Mon, 10 Oct 2022 20:19:33 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6arXbE/EfddoNglUvqf08geiApKNWyNMEO6HKIy2RZ8=; b=UQ3/bKlq6QNwuSl766Two0OG/oOgVkaKSElEd9wtUhToAhJM8pb3L/1Lg8vzS/cWrx Q3nMxCaTq7pLQ4Nax7XhTlbk6m1LaTGvmyMQPtkR8kDA+BFzlBqB/n7OIQ1yUjSjb5IQ 8cFoh4iGvFhvV1RHH/VfQ5GzP4+b+xumi3gxf6WTqTLk3mwwFn0M4Vwf0IUBdC5MaDAA 1Zb8mMOTbAfrf/29jzRjmCkvh1FcHCFeSM+ofhYV/m0c3/h4Sd0cvU4cihISOT8lxXZD Ap4W/UvonegqYQZpvQxv+dwsZg5mWd+pznzvc3goYyEpWuAo4Drwm7qCyzynPWXuALtV DWoA== 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=6arXbE/EfddoNglUvqf08geiApKNWyNMEO6HKIy2RZ8=; b=AzdeUtUpoeP53i54CYa8ezFaLiINw7PNUcRT6DY+OXj6NPCIoLQwvPMOoBrL/sDGiM cnvdvkXcYE4WRbUAcM5agYe9zMotwswHOIGiupxT0fLkJbUErUsXVYuFVQk+RGVlSv2m FXDZUxZJIBf5RvMYLaHvtvyaVU5FXqqU6sWIiJYzWTPH74uL5vY6GwHAe5x77fdI0+2M NRvDV0cqfcbPqupsfHtJRbaLhYBDjyLXQMQez+C+i0051HDPRSieKTX86R0uzwjvfSB3 rp9mLWkxdL7pDoqHXkNtJh3+64ISc6W00tZqAvzXKouBCdCFGuDviO+4LMFUK3zcrAL5 mjSA== X-Gm-Message-State: ACrzQf0UQzfQs9xrxmQ5v7LLGbN+d8LFGRnQt9THHfxfItT/Oo66VhFO F14DBWe8VyZ3dduRouWTtqZgK/+w04Ddkw== X-Received: by 2002:a05:6a00:88f:b0:52c:6962:274f with SMTP id q15-20020a056a00088f00b0052c6962274fmr23807965pfj.12.1665458372992; Mon, 10 Oct 2022 20:19:32 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 11/24] target/arm: Split out get_phys_addr_twostage Date: Mon, 10 Oct 2022 20:18:58 -0700 Message-Id: <20221011031911.2408754-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/ptw.c | 191 +++++++++++++++++++++++++---------------------- 1 file changed, 100 insertions(+), 91 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 8f41d285b7..dd6556560a 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -31,6 +31,13 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, GetPhysAddrResult *result, ARMMMUFaultInfo *fi) __attribute__((nonnull)); +static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw, + target_ulong address, + MMUAccessType access_type, + GetPhysAddrResult *result, + ARMMMUFaultInfo *fi) + __attribute__((nonnull)); + /* This mapping is common between ID_AA64MMFR0.PARANGE and TCR_ELx.{I}PS. */ static const uint8_t pamax_map[] = { [0] = 32, @@ -2428,6 +2435,94 @@ static bool get_phys_addr_disabled(CPUARMState *env, target_ulong address, return 0; } +static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw, + target_ulong address, + MMUAccessType access_type, + GetPhysAddrResult *result, + ARMMMUFaultInfo *fi) +{ + hwaddr ipa; + int s1_prot; + int ret; + bool is_secure = ptw->in_secure; + bool ipa_secure, s2walk_secure; + ARMCacheAttrs cacheattrs1; + bool is_el0; + uint64_t hcr; + + ret = get_phys_addr_with_struct(env, ptw, address, access_type, result, fi); + + /* If S1 fails or S2 is disabled, return early. */ + if (ret || regime_translation_disabled(env, ARMMMUIdx_Stage2, is_secure)) { + return ret; + } + + ipa = result->f.phys_addr; + ipa_secure = result->f.attrs.secure; + if (is_secure) { + /* Select TCR based on the NS bit from the S1 walk. */ + s2walk_secure = !(ipa_secure + ? env->cp15.vstcr_el2 & VSTCR_SW + : env->cp15.vtcr_el2 & VTCR_NSW); + } else { + assert(!ipa_secure); + s2walk_secure = false; + } + + is_el0 = ptw->in_mmu_idx == ARMMMUIdx_Stage1_E0; + ptw->in_mmu_idx = s2walk_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; + ptw->in_secure = s2walk_secure; + + /* + * S1 is done, now do S2 translation. + * Save the stage1 results so that we may merge prot and cacheattrs later. + */ + s1_prot = result->f.prot; + cacheattrs1 = result->cacheattrs; + memset(result, 0, sizeof(*result)); + + ret = get_phys_addr_lpae(env, ptw, ipa, access_type, is_el0, result, fi); + fi->s2addr = ipa; + + /* Combine the S1 and S2 perms. */ + result->f.prot &= s1_prot; + + /* If S2 fails, return early. */ + if (ret) { + return ret; + } + + /* Combine the S1 and S2 cache attributes. */ + hcr = arm_hcr_el2_eff_secstate(env, is_secure); + if (hcr & HCR_DC) { + /* + * HCR.DC forces the first stage attributes to + * Normal Non-Shareable, + * Inner Write-Back Read-Allocate Write-Allocate, + * Outer Write-Back Read-Allocate Write-Allocate. + * Do not overwrite Tagged within attrs. + */ + if (cacheattrs1.attrs != 0xf0) { + cacheattrs1.attrs = 0xff; + } + cacheattrs1.shareability = 0; + } + result->cacheattrs = combine_cacheattrs(hcr, cacheattrs1, + result->cacheattrs); + + /* + * Check if IPA translates to secure or non-secure PA space. + * Note that VSTCR overrides VTCR and {N}SW overrides {N}SA. + */ + result->f.attrs.secure = + (is_secure + && !(env->cp15.vstcr_el2 & (VSTCR_SA | VSTCR_SW)) + && (ipa_secure + || !(env->cp15.vtcr_el2 & (VTCR_NSA | VTCR_NSW)))); + + return 0; +} + static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw, target_ulong address, MMUAccessType access_type, @@ -2441,99 +2536,13 @@ static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw, if (mmu_idx != s1_mmu_idx) { /* * Call ourselves recursively to do the stage 1 and then stage 2 - * translations if mmu_idx is a two-stage regime. + * translations if mmu_idx is a two-stage regime, and EL2 present. + * Otherwise, a stage1+stage2 translation is just stage 1. */ + ptw->in_mmu_idx = mmu_idx = s1_mmu_idx; if (arm_feature(env, ARM_FEATURE_EL2)) { - hwaddr ipa; - int s1_prot; - int ret; - bool ipa_secure, s2walk_secure; - ARMCacheAttrs cacheattrs1; - bool is_el0; - uint64_t hcr; - - ptw->in_mmu_idx = s1_mmu_idx; - ret = get_phys_addr_with_struct(env, ptw, address, access_type, - result, fi); - - /* If S1 fails or S2 is disabled, return early. */ - if (ret || regime_translation_disabled(env, ARMMMUIdx_Stage2, - is_secure)) { - return ret; - } - - ipa = result->f.phys_addr; - ipa_secure = result->f.attrs.secure; - if (is_secure) { - /* Select TCR based on the NS bit from the S1 walk. */ - s2walk_secure = !(ipa_secure - ? env->cp15.vstcr_el2 & VSTCR_SW - : env->cp15.vtcr_el2 & VTCR_NSW); - } else { - assert(!ipa_secure); - s2walk_secure = false; - } - - ptw->in_mmu_idx = - s2walk_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; - ptw->in_secure = s2walk_secure; - is_el0 = mmu_idx == ARMMMUIdx_E10_0; - - /* - * S1 is done, now do S2 translation. - * Save the stage1 results so that we may merge - * prot and cacheattrs later. - */ - s1_prot = result->f.prot; - cacheattrs1 = result->cacheattrs; - memset(result, 0, sizeof(*result)); - - ret = get_phys_addr_lpae(env, ptw, ipa, access_type, - is_el0, result, fi); - fi->s2addr = ipa; - - /* Combine the S1 and S2 perms. */ - result->f.prot &= s1_prot; - - /* If S2 fails, return early. */ - if (ret) { - return ret; - } - - /* Combine the S1 and S2 cache attributes. */ - hcr = arm_hcr_el2_eff_secstate(env, is_secure); - if (hcr & HCR_DC) { - /* - * HCR.DC forces the first stage attributes to - * Normal Non-Shareable, - * Inner Write-Back Read-Allocate Write-Allocate, - * Outer Write-Back Read-Allocate Write-Allocate. - * Do not overwrite Tagged within attrs. - */ - if (cacheattrs1.attrs != 0xf0) { - cacheattrs1.attrs = 0xff; - } - cacheattrs1.shareability = 0; - } - result->cacheattrs = combine_cacheattrs(hcr, cacheattrs1, - result->cacheattrs); - - /* - * Check if IPA translates to secure or non-secure PA space. - * Note that VSTCR overrides VTCR and {N}SW overrides {N}SA. - */ - result->f.attrs.secure = - (is_secure - && !(env->cp15.vstcr_el2 & (VSTCR_SA | VSTCR_SW)) - && (ipa_secure - || !(env->cp15.vtcr_el2 & (VTCR_NSA | VTCR_NSW)))); - - return 0; - } else { - /* - * For non-EL2 CPUs a stage1+stage2 translation is just stage 1. - */ - mmu_idx = stage_1_mmu_idx(mmu_idx); + return get_phys_addr_twostage(env, ptw, address, access_type, + result, fi); } } From patchwork Tue Oct 11 03:18:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614156 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2372193pvb; Mon, 10 Oct 2022 20:34:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7C9V2yFBUmrbs4PA/mtyoogmrGVEzozIGedBL7N6AnB8WCKjCVrgwD0H23dOOETf98SqGt X-Received: by 2002:a37:9244:0:b0:6e7:cb00:2795 with SMTP id u65-20020a379244000000b006e7cb002795mr13960694qkd.329.1665459245804; Mon, 10 Oct 2022 20:34:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665459245; cv=none; d=google.com; s=arc-20160816; b=wLs5bCEcmI2VbKA3kj2yqGpSC/9x7bayLw1+4mktYgG8cIiB4ajoZj20pyhlm8W2HJ tc2pi616nysCu7AeqqjVq4UsgvkNioxRMtLn5gaf6eeH9MNUdPzEY9hI6MSmLoSBhj/A aS3ceKRLjc4QaoyY+rKqwjJRzPM/qtdfkfSfI28ryWCapFIvhepptn8FwkZPXjlEWLS8 MVfe2FYzSR/KcXxdbY2DQlBz5kQpLLPlScdJvpfLBxUeo5y4fuFTrf0bQB3XZAEPwQ6s E9HhmqPqg0Hgt1iLFQ2Yz7fk5BpgtcmrjYrppg9QIZSifww3wHUr0eCvKFoIlOsRx9Ox lrHw== 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=igwDK2m9zhrQhVMJ/mwLsQLF4ZyzFm7+yLAGfvHZQnE=; b=YZgt5prIArATJPKnLbYG03Ir/bnJaD75KXGOBkniBWO6wsKDdruREG7Bo63PwRoXHP 44sniK5faP+LqvhzvfUuOwnzbg651lj3kaLTn+feNK72XqIs3uy+8aA5n88KTD88mRSj WHTq6jm3qjyUfHC7KcR6yCtWpn6OS2V2LMV5XI8U67OoUfs+8bkEZAqKOR9lWSVtBss/ heBNZBakKbGftxvn6S2DujYaJ312wN7eFQGaxf59aATV8QrzrNdmjxAABbGAiKHyVEeQ GonMftriW7Wit5Bbyzt72YabLpvywhV1slO8iu3n2Vfap/pt2btH3DsYqBQnfCZgYJq0 PisA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dx3siBOa; 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 w14-20020a05620a424e00b006b5fc817571si6690170qko.658.2022.10.10.20.34.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:34:05 -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=dx3siBOa; 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]:35326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi61t-0007ol-8W for patch@linaro.org; Mon, 10 Oct 2022 23:34:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5nw-0002Ri-MW for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:41 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:40544) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5nr-00030k-B0 for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:39 -0400 Received: by mail-pf1-x42b.google.com with SMTP id h13so10915861pfr.7 for ; Mon, 10 Oct 2022 20:19:34 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=igwDK2m9zhrQhVMJ/mwLsQLF4ZyzFm7+yLAGfvHZQnE=; b=dx3siBOaf9ACqd49zF6xyV67g7G2cZR/dcN5pnQjKakwWveZA3ruKMjlR6XpWquYqq QJLGkGGM0tI8qnMRddjjJqwrYWoZGRQ890WJM5tVSyZTL+h+KqbuSD//jA7vnzlwFnwa h0v4Rl7WFetgwmWVtmIoJas37D01i1qto94kOwPZ9oMpUUEtdHtWUWzNgRNl/uGA1c9H nctB3mycaiAT+R+oFBfW+QyLMyghlQbUxb+33Unjfro1RsGT2l6TnVlNEsWS7zmD05c8 1mby5gRHpZ/3M0DI7UdaHTIQa1hBktIvPGowAhBm1/dDjoc5E05qOqHWtyLEIVgXa9yT HeTw== 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=igwDK2m9zhrQhVMJ/mwLsQLF4ZyzFm7+yLAGfvHZQnE=; b=fw23t6jl/SntIqPzc2eleT4MFH5+DRUnbUk+8FMnsnZ1i3gw6mwQWaxebmAM9R2cVK kE5pX5X34H/kiUdtdQUb8nDNmUgZC+DwKaWU/CfKPVj6ME7uoEtDM8ASBld/+vtCNDEG OymFe/tjx+qcW8SABq6kQelAg4I6R9swRtcPfK/LsHzotcq6oZnIdOaYznbbZn9jNa28 YNCoyKOdEtf2sM/J1DnTWRcuuYyi2DZznT37h3S4hxYqXFQDa5jHwINPfLInw+cL0RsV JFIWx7A3dqoFuaxConL2p1mPPJ/oAhtJckdyODbArQOyHkKavGiuxTObNNjAZ+o3cLq3 bjqA== X-Gm-Message-State: ACrzQf2HhJjNUh+jL7Su8IFio+aEkAY6ABmZ4DXyOjtrfW2v5JSa2SQv EkHvefWsI3cQoJcjucv7tsHOgLHTrQ3oeQ== X-Received: by 2002:a63:5243:0:b0:43c:96a:8528 with SMTP id s3-20020a635243000000b0043c096a8528mr19112743pgl.47.1665458374580; Mon, 10 Oct 2022 20:19:34 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 12/24] target/arm: Use bool consistently for get_phys_addr subroutines Date: Mon, 10 Oct 2022 20:18:59 -0700 Message-Id: <20221011031911.2408754-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The return type of the functions is already bool, but in a few instances we used an integer type with the return statement. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/ptw.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index dd6556560a..6c5ed56a10 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -2432,7 +2432,7 @@ static bool get_phys_addr_disabled(CPUARMState *env, target_ulong address, result->f.lg_page_size = TARGET_PAGE_BITS; result->cacheattrs.shareability = shareability; result->cacheattrs.attrs = memattr; - return 0; + return false; } static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw, @@ -2443,9 +2443,8 @@ static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw, { hwaddr ipa; int s1_prot; - int ret; bool is_secure = ptw->in_secure; - bool ipa_secure, s2walk_secure; + bool ret, ipa_secure, s2walk_secure; ARMCacheAttrs cacheattrs1; bool is_el0; uint64_t hcr; @@ -2520,7 +2519,7 @@ static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw, && (ipa_secure || !(env->cp15.vtcr_el2 & (VTCR_NSA | VTCR_NSW)))); - return 0; + return false; } static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw, From patchwork Tue Oct 11 03:19: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: 614152 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2370493pvb; Mon, 10 Oct 2022 20:28:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM58YHwt4MPeFJrJMv0xeDPyu54MDM/lM9aNeZ0jlBDmmcZCU1znwmywam+WXl/BdhppHqeC X-Received: by 2002:a05:620a:27d2:b0:6cf:b644:f644 with SMTP id i18-20020a05620a27d200b006cfb644f644mr15376801qkp.35.1665458912538; Mon, 10 Oct 2022 20:28:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665458912; cv=none; d=google.com; s=arc-20160816; b=uJUtj1+aeETj3+nHgmFRuz+2qxABU8Q3o0M1p738Dwru0jGS3WQiYjgvTUyRKdLmcY NweBdVkINKELvLEe1E9tDzFjYbVa/OVfymCCZOTltG2mLdyl4d1iut+Jm1LxewjP3hkb N0DVPUdpXNXoAL30cuc3fndNYu0h1SFKpXzHQySGr1FcKBTT6qIWXJAaxt6pkeY761WB cxBpzE7f43VwDFUPk41i9kYAMkzfeem+Da7IXXnH7OiMFLwaOLYxfNQ4t0EpDBGcVy9A UWo4XT77HDy2e8USjL0c2ToTHoaqba4ZnSGkmFH1NkSskM74D66ZJ3TdlSA+z2lX/6OH 8iQw== 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=n9Z+kZUU1DH+gId3ANvvv1sspQkR6K8eMCHwpMHk7cU=; b=eTYBxHuIGHuMocSuRnbUVerJVE8PqIIfbSM90M/URNV3fB9PAyCqWs2v8Q5vnqbIKT E7+dgbKw5y3OoAyVmJuerti+KDtl5FI0pWOUa0VniXrzRNchy260w5ZNuWG00xrRh4bH zUr7FzDaGjUvOuvU+9dJzW3xUK9UEC48Pfil7WwLQ/lqfL2HAHskt9w6QtcaHKEbMIvk NS9fzg5qKYEwspdynt1BaW9Gmu5+973EWxRyfNBYU8bJ8JAFjFJ3BVZyOohLijgPRVvk yit/51/Uyce5K1v/VGKgWPqUIEvTx7SepLJ0cAFOieDefZpJAS1yYn4LwzREpuPsl5+n 3EpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rqhjFnVW; 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 iy15-20020a0562140f6f00b004b2f6f4bf83si6391549qvb.326.2022.10.10.20.28.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:28:32 -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=rqhjFnVW; 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]:55000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi5wW-0001Kv-2f for patch@linaro.org; Mon, 10 Oct 2022 23:28:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5nx-0002Rq-AD for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:41 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:33413) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5nu-00033r-L0 for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:41 -0400 Received: by mail-pl1-x62c.google.com with SMTP id 10so12090016pli.0 for ; Mon, 10 Oct 2022 20:19:38 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=n9Z+kZUU1DH+gId3ANvvv1sspQkR6K8eMCHwpMHk7cU=; b=rqhjFnVWtZoo9ZEIi2g/V+/xLiXbQjbvZTSIwOY5Q5Jov3LPxEiGZ4JeYTf0PvYIvp rbu6mX0iU3L0Q2bSq+loPSQ2A0x3OWXzKAgh+/FppLPzcrURF80DC8TeJkru+KVM1pw8 rKKqonjzyZ+l8qhI9TP/sLmecnmtrZpKvACKnXQx2StpRofNdF1dGZ5gauNm+J2SCN5T EpZYpeIpT2MXkVPDhYJAFu/y4NKShNDQ36IAMgKEE1GxqId5FVUz5XPke9ikvZ1D+PAS GgajYQkR3hCUZXfxjVfVh+a8xJ/cOy3/1IEAEJLSyuYUnaMg3oFbWpDWb7j/85iNYhzq JF+A== 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=n9Z+kZUU1DH+gId3ANvvv1sspQkR6K8eMCHwpMHk7cU=; b=aywjPPccVel0Ct58JNufssf5d1rBJ+thPTWKnX4ZexYlaKNQk1R8G9NMNKdyfmrRlq bVoSQXra7PzXOubySrYNgFnv2DBvkb9Ksj2bRC/JEQZEq87rMXd0u4clI9aGx5amNj3B KQ9xwZciwmHK0Itihc1OfcjPZkopGwrYF3ThZVlVTD668E0QMhYD6Eov5/+fNpnwSqsS Ph2bHOlvAM/6aFzpeEumf53N+irJDmMIpSOX7pTTjbz6cK6JWSl8tAdbtSCSuInTkcpm Eo3cgKsKHEBIjj9SKnUX+r4kTXCmcaLAwezAylquBS8Tgu4QVdoapOFEOmQ/0eeo5i3O KE4w== X-Gm-Message-State: ACrzQf1pS/+5N2DsaHolti52rPGUXSSWdxu5BA80iujR09ArmX5jK7GX BIMQiLnJfpwrTImw72v2h1zd146tvsvoaA== X-Received: by 2002:a17:902:ce12:b0:17a:3e76:8568 with SMTP id k18-20020a170902ce1200b0017a3e768568mr22405431plg.11.1665458377307; Mon, 10 Oct 2022 20:19:37 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v4 13/24] target/arm: Add ptw_idx to S1Translate Date: Mon, 10 Oct 2022 20:19:00 -0700 Message-Id: <20221011031911.2408754-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Hoist the computation of the mmu_idx for the ptw up to get_phys_addr_with_struct and get_phys_addr_twostage. This removes the duplicate check for stage2 disabled from the middle of the walk, performing it only once. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/ptw.c | 53 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 6c5ed56a10..b2bfcfde9a 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -17,6 +17,7 @@ typedef struct S1Translate { ARMMMUIdx in_mmu_idx; + ARMMMUIdx in_ptw_idx; bool in_secure; bool in_debug; bool out_secure; @@ -233,17 +234,12 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, { bool is_secure = ptw->in_secure; ARMMMUIdx mmu_idx = ptw->in_mmu_idx; - ARMMMUIdx s2_mmu_idx = is_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; - bool s2_phys = false; + ARMMMUIdx s2_mmu_idx = ptw->in_ptw_idx; + bool s2_phys = s2_mmu_idx == ARMMMUIdx_Phys_S || + s2_mmu_idx == ARMMMUIdx_Phys_NS; uint8_t pte_attrs; bool pte_secure; - if (!arm_mmu_idx_is_stage1_of_2(mmu_idx) - || regime_translation_disabled(env, s2_mmu_idx, is_secure)) { - s2_mmu_idx = is_secure ? ARMMMUIdx_Phys_S : ARMMMUIdx_Phys_NS; - s2_phys = true; - } - if (unlikely(ptw->in_debug)) { /* * From gdbstub, do not use softmmu so that we don't modify the @@ -256,10 +252,12 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, } else { S1Translate s2ptw = { .in_mmu_idx = s2_mmu_idx, + .in_ptw_idx = is_secure ? ARMMMUIdx_Phys_S : ARMMMUIdx_Phys_NS, .in_secure = is_secure, .in_debug = true, }; GetPhysAddrResult s2 = { }; + if (!get_phys_addr_lpae(env, &s2ptw, addr, MMU_DATA_LOAD, false, &s2, fi)) { goto fail; @@ -1283,7 +1281,11 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, descaddr |= (address >> (stride * (4 - level))) & indexmask; descaddr &= ~7ULL; nstable = extract32(tableattrs, 4, 1); - ptw->in_secure = !nstable; + if (!nstable) { + /* Stage2_S -> Stage2 or Phys_S -> Phys_NS */ + ptw->in_ptw_idx &= ~1; + ptw->in_secure = false; + } descriptor = arm_ldq_ptw(env, ptw, descaddr, fi); if (fi->type != ARMFault_None) { goto do_fault; @@ -2470,6 +2472,7 @@ static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw, is_el0 = ptw->in_mmu_idx == ARMMMUIdx_Stage1_E0; ptw->in_mmu_idx = s2walk_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; + ptw->in_ptw_idx = s2walk_secure ? ARMMMUIdx_Phys_S : ARMMMUIdx_Phys_NS; ptw->in_secure = s2walk_secure; /* @@ -2529,10 +2532,32 @@ static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw, ARMMMUFaultInfo *fi) { ARMMMUIdx mmu_idx = ptw->in_mmu_idx; - ARMMMUIdx s1_mmu_idx = stage_1_mmu_idx(mmu_idx); bool is_secure = ptw->in_secure; + ARMMMUIdx s1_mmu_idx; - if (mmu_idx != s1_mmu_idx) { + switch (mmu_idx) { + case ARMMMUIdx_Phys_S: + case ARMMMUIdx_Phys_NS: + /* Checking Phys early avoids special casing later vs regime_el. */ + return get_phys_addr_disabled(env, address, access_type, mmu_idx, + is_secure, result, fi); + + case ARMMMUIdx_Stage1_E0: + case ARMMMUIdx_Stage1_E1: + case ARMMMUIdx_Stage1_E1_PAN: + /* First stage lookup uses second stage for ptw. */ + ptw->in_ptw_idx = is_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2; + break; + + case ARMMMUIdx_E10_0: + s1_mmu_idx = ARMMMUIdx_Stage1_E0; + goto do_twostage; + case ARMMMUIdx_E10_1: + s1_mmu_idx = ARMMMUIdx_Stage1_E1; + goto do_twostage; + case ARMMMUIdx_E10_1_PAN: + s1_mmu_idx = ARMMMUIdx_Stage1_E1_PAN; + do_twostage: /* * Call ourselves recursively to do the stage 1 and then stage 2 * translations if mmu_idx is a two-stage regime, and EL2 present. @@ -2543,6 +2568,12 @@ static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw, return get_phys_addr_twostage(env, ptw, address, access_type, result, fi); } + /* fall through */ + + default: + /* Single stage and second stage uses physical for ptw. */ + ptw->in_ptw_idx = is_secure ? ARMMMUIdx_Phys_S : ARMMMUIdx_Phys_NS; + break; } /* From patchwork Tue Oct 11 03:19:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614149 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2369641pvb; Mon, 10 Oct 2022 20:25:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Fnbafq7siRSKdzlgReHIAEujhnXzFOIfJYZrbRcd4hUTsvSjdP4p6yCTE4l0EnxVA0B+y X-Received: by 2002:a05:620a:1aa0:b0:6e5:e017:e9d3 with SMTP id bl32-20020a05620a1aa000b006e5e017e9d3mr15422569qkb.490.1665458749888; Mon, 10 Oct 2022 20:25:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665458749; cv=none; d=google.com; s=arc-20160816; b=J5R7+/c8v8cwzWPfBGguUc8aUHZXdx2ZQQ5422zpO9JQdJLoasCJNDC6BKwT7cWIpo yys9RsHnuFwd4Xc1yDSYuxPTYmdvDMLhdjBJRt5A6pmLx8wjNxiGV9m5/cHVsAbfNQZK HcsP6QRs02f5epuBOh18EJ0kPTW89lrgMMtEwKKaaBrhIMY8zvR+cRofZGtu3/KczWdW EsiEghxjqV2HzCLJMKmHHVLLg2EC3D1w8lfa9OTH1YkDAUFxsfHof15wYWQlJvu8BO82 hnfzWdGS0oNxA034UIXcNqiQ1yGYPH36UiheoV9QV4THdeK1Pyj9ueiW7Qjf+YAT7owe gU/w== 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=Z0R2KmhXeUORlGWyUT5i12Xi4lPWlzT7EyIDQTN1DvA=; b=XZcRKT+trHKFbQnw5SCR9kz2UFIW6kUuOfoEYgIod4nuS4HXNplIkifbe+CyoO4eyc Ye+8OBc3W2w3p9g1Zr0NCFgkX6FUIyLFlKuOANXZf5X97s3H9bs2AchBOMNAuJwjLllT 5ePhg4DVnVIqJi+gESFHHMlOkWJEusGUCZeaWVMVQHxuhmCBMRNConBHN/K0SXGKPukk H06+g7wXjOkxLzhCGi0AqiF+AhMUBXIOdw1m+TxXc7fN7k3kJruGT9Wl4ARD8ndAw0Zd A6ObHccy7cpCp1M/6h+Tc1bX9TdJFwReuvBuANg+4mtyNl3E3M6N+07u5bLyWSZto6Dk 0bxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="KcMqU/Xc"; 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 gm4-20020a056214268400b004afa3c396a6si6039875qvb.219.2022.10.10.20.25.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:25:49 -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="KcMqU/Xc"; 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]:33166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi5tt-0002r7-ES for patch@linaro.org; Mon, 10 Oct 2022 23:25:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5ny-0002Ta-5b for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:42 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:37874) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5nw-00034U-LA for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:41 -0400 Received: by mail-pf1-x429.google.com with SMTP id 3so10807899pfw.4 for ; Mon, 10 Oct 2022 20:19:40 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z0R2KmhXeUORlGWyUT5i12Xi4lPWlzT7EyIDQTN1DvA=; b=KcMqU/Xcr2CHBCE2paYhzoNSizm9vQdhkyX/ZfGPOHF59yAEZ+nVT0N1g0rEFTGNOq BG8iaobKYuU/ByRbLfdF1fZq9Guq9ZujszQTg/ZgSNrBGcUn7eOD6+WfiRuZ/saQQ3jS 3HI804XfwoQtmiiDKsO7uwhPLjMb6mKm29i67MWqj7wpsIJbh87FqhC5k8J1o8ZhuLJ6 S6gAHN44Q+j/nqpIk4aBGieNfHaImM8YBgVTPrUgkK9gKvUcHOR37Vv6YxhHOZY2BsbR MpC+1OE7VxYFPW/QMQ9SR915CCaPqvlEejKpdjg+ngAv6DlNU+U1DCXvBD5ksgCBIKAM ThMw== 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=Z0R2KmhXeUORlGWyUT5i12Xi4lPWlzT7EyIDQTN1DvA=; b=QNvDzOXjaWbRGIjQiiiFHnnDG67zsBmOyGCNWs7xCDVKFTMNdyOmJEiFEQtCxKCEHH yGcyWVGB1ZCDHzek4vfir7bvjTu3v5mBWmnbG66ktiBKr7eUeJis/MCwdVdkiFft3F1s IfjVBlihJ7Y+breLJcqajSEq9vN9J5O4/yCVN2uhfr/UNgJLcJyZHOC4aGzxKItWGRLw x6k0CQJKIEWsI/OdPk9WthA2+N+2tveriAqVAiE7B6q2LkaI+u0VQkvGkpmrldgfDK2c P2IjI8zK0l4g/KYQhVkP561yvBhn0WzsrXvs6qWaLTvBVuaReKpVwJmtGKYPvpiboMnA oHsQ== X-Gm-Message-State: ACrzQf3Q8nR91CpQbSLi7FZY3wJujgaVd2Os43/q1t2gCgCoaUu7wG2s kAodO3omhsiEVFLh0iwr3yJTiIIgLe97Zg== X-Received: by 2002:a05:6a02:303:b0:458:1e4b:1e89 with SMTP id bn3-20020a056a02030300b004581e4b1e89mr18543551pgb.123.1665458379381; Mon, 10 Oct 2022 20:19:39 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 14/24] target/arm: Add isar predicates for FEAT_HAFDBS Date: Mon, 10 Oct 2022 20:19:01 -0700 Message-Id: <20221011031911.2408754-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The MMFR1 field may indicate support for hardware update of access flag alone, or access flag and dirty bit. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index e9e77b7563..cde4e86db2 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -4139,6 +4139,16 @@ static inline bool isar_feature_aa64_lva(const ARMISARegisters *id) return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, VARANGE) != 0; } +static inline bool isar_feature_aa64_hafs(const ARMISARegisters *id) +{ + return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, HAFDBS) != 0; +} + +static inline bool isar_feature_aa64_hdbs(const ARMISARegisters *id) +{ + return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, HAFDBS) >= 2; +} + static inline bool isar_feature_aa64_tts2uxn(const ARMISARegisters *id) { return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, XNX) != 0; From patchwork Tue Oct 11 03:19:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614157 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2372726pvb; Mon, 10 Oct 2022 20:35:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM78hD8wlBqUeXIw9G6WsuWT3WFR8nwx1fJT3C+/8KD6HxxOOlTjojg4jYHOLiuFiL5nmMYv X-Received: by 2002:a05:620a:2442:b0:6ce:d766:ca81 with SMTP id h2-20020a05620a244200b006ced766ca81mr14736680qkn.687.1665459330122; Mon, 10 Oct 2022 20:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665459330; cv=none; d=google.com; s=arc-20160816; b=xmOadhtxetLsh7IZ7+5zzSeeR6LoSNTSYWIA8Y+Pof7pSeBwXOxfB85OhWtWP+ijsq /6T+fW+ihaub92Q7vMv/i3sGtDq68VGOf8E5GEa51EZ8uMYcP6rxx7yU4zLvs3zxiwxF gfwLOR6ozFIlBC/Aq6yRMc7jNJtavTmL8T1mVI7KNrjxM/kIVNSzIHZ/WGpSLEEwE9no CMlQXpNk97oTqG35dfoUUbOEdapLM1mSUEh1tgq9IsskpYlYLvkOi5CUHKpMkE1rBkHu vpD1KreQxLojYMOqUcLKegWtSz/HpYNBGP5ezhzlFahyUGVPQKrPcBvQ8BXIATw7hPyV 1qpw== 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=keRR6yp16j9BQA6bMnZFN0sAd0rexZw5HE86te+F334=; b=rH8gyg+iMkvdn20K0nGQc1LEqsnuEpcL97DWx9waqeDV5i5xm7+Ahn3CkW51ntD4ps rC7oVYi4O34JCfndJkeuBSv7DQVUm3C1ciSJOiPRiVe38ZazybjxtauOTeb0OzEwZjjR QpAkCuy8PE+IEmOkVN9OqxO8CftdLznEw5w3dIP01ZphjTQ4IjVDFqJ2VTrCJAcjYoBr AVuQDMk36NBw9KqMXP+/50uMlxy7rdlPTNUF1UaOw16h6ds8E3WCL1ZM/5sE1tyPaSA+ TgeyJxdU5D5qEiAumriNtqsXP/pUyjmaYITY8GVFgwSZEdxwZTxcsxsYrY5wLwx6QAir LJAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yp2y9LT3; 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 q25-20020ac84519000000b0039863dc13afsi4076499qtn.279.2022.10.10.20.35.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:35:30 -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=yp2y9LT3; 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]:37478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi63F-0000uD-KN for patch@linaro.org; Mon, 10 Oct 2022 23:35:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5o0-0002YJ-Me for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:46 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:41767) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5ny-00035A-UH for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:44 -0400 Received: by mail-pl1-x634.google.com with SMTP id l4so12014771plb.8 for ; Mon, 10 Oct 2022 20:19:42 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=keRR6yp16j9BQA6bMnZFN0sAd0rexZw5HE86te+F334=; b=yp2y9LT3fCkE9987AaqC42D7jjLT5NB4f6cIg0JcVGw7PjLIKgXPbHg57zKskmT0J4 3C0+Ix6vsGMnyIRHStyMeYlCoQ3bNARz4tIwdVITumzoy+PbFQWY1zX8vqSGy665inCd NauQ3ipTgCY5wA1Mc4AbvVkjxN+HrYFkbyL7ZtppYHxUY4URZD0HR36bRAeFPYoNdk8B BxhRTinOW24HlrXt9ZKKcu62D1UctqMdsAg5yRJGTDEhyejB+dpOTDXMYmaiU6PDa53y SYQD2fLk1bRptLhqD9mzQc4xbFCu6HCbx+KIFBAbR+qkbuo/GsdqodWkY4s8PsYvluKk 4/kQ== 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=keRR6yp16j9BQA6bMnZFN0sAd0rexZw5HE86te+F334=; b=X1UP0SDEkQfdroovxmG5gy7gfsZEVkFhGQc+XJfQ862rA0zxYD38OzFm5pzlZtRzbN MvPi4dgKqUcqgcMTEmIt4HRhMo9lE90DLEC5JzPwmmTTMW1tW0QH6uBTpKnjh4tsti4E bDjpHGn2W4AUNqhafWAAJqPStxqLqL7Z/bPEaOuaHGNYTD6esOR1TRJr1PhowI7DADGD 5WfAoopxQSUGlbB4gcszhIrZPtclFwH3dQ+OQqjEukI2L/GmUEREYuXtdyJOtncAYhPP HAfklO2RjJWB+8ySvUfHOnc8pfcZ8EGUR3Q6/tfChTAhh+s9Kid7PF/Biie2P845P0Zs 1wgA== X-Gm-Message-State: ACrzQf3JKzMkDN8SjtgFdUvKHTFj9Cc3MZvKzx77oLazAHbI7WoTxFIR lrcVlc54u60ModVznlnmrN7FciqVqwgUQA== X-Received: by 2002:a17:902:f644:b0:17f:7f88:5f47 with SMTP id m4-20020a170902f64400b0017f7f885f47mr21873347plg.123.1665458381354; Mon, 10 Oct 2022 20:19:41 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 15/24] target/arm: Extract HA and HD in aa64_va_parameters Date: Mon, 10 Oct 2022 20:19:02 -0700 Message-Id: <20221011031911.2408754-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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" Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/internals.h | 2 ++ target/arm/helper.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/target/arm/internals.h b/target/arm/internals.h index c3c3920ded..76ec7ee8cc 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1041,6 +1041,8 @@ typedef struct ARMVAParameters { bool hpd : 1; bool tsz_oob : 1; /* tsz has been clamped to legal range */ bool ds : 1; + bool ha : 1; + bool hd : 1; ARMGranuleSize gran : 2; } ARMVAParameters; diff --git a/target/arm/helper.c b/target/arm/helper.c index c672903f43..4487957e5d 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10470,7 +10470,7 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, ARMMMUIdx mmu_idx, bool data) { uint64_t tcr = regime_tcr(env, mmu_idx); - bool epd, hpd, tsz_oob, ds; + bool epd, hpd, tsz_oob, ds, ha, hd; int select, tsz, tbi, max_tsz, min_tsz, ps, sh; ARMGranuleSize gran; ARMCPU *cpu = env_archcpu(env); @@ -10489,6 +10489,8 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, epd = false; sh = extract32(tcr, 12, 2); ps = extract32(tcr, 16, 3); + ha = extract32(tcr, 21, 1) && cpu_isar_feature(aa64_hafs, cpu); + hd = extract32(tcr, 22, 1) && cpu_isar_feature(aa64_hdbs, cpu); ds = extract64(tcr, 32, 1); } else { /* @@ -10510,6 +10512,8 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, hpd = extract64(tcr, 42, 1); } ps = extract64(tcr, 32, 3); + ha = extract64(tcr, 39, 1) && cpu_isar_feature(aa64_hafs, cpu); + hd = extract64(tcr, 40, 1) && cpu_isar_feature(aa64_hdbs, cpu); ds = extract64(tcr, 59, 1); } @@ -10581,6 +10585,8 @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, .hpd = hpd, .tsz_oob = tsz_oob, .ds = ds, + .ha = ha, + .hd = ha && hd, .gran = gran, }; } From patchwork Tue Oct 11 03:19:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614158 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2373252pvb; Mon, 10 Oct 2022 20:36:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4nQdF3oHNZtm3ZlzWYmLS3XKANVGJCCzgH3KhoHmzLnuh6rbfGRJCUEcFgPpybwqXbVKZD X-Received: by 2002:ac8:5a41:0:b0:35c:fa93:f227 with SMTP id o1-20020ac85a41000000b0035cfa93f227mr17530604qta.102.1665459415648; Mon, 10 Oct 2022 20:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665459415; cv=none; d=google.com; s=arc-20160816; b=OJuxAX+EqRe7ZRdPN2GJTg4l2Z2uCJXluO4gcjFXoRvcAp1nBu3L5s63ik6cVUY+an xUXPBXRMCHDVwp7q7e1vQY3UDWxaclNwVO5zKHaT5QksUtpr6/dcXMCg/lpxmcKq7sbW llIjqWvvxYYNYHPLwIE5q01YTz1hcAizCkURzIXr/ltFM5X1BHZ2sKQyBRokaWo1ZHrc LQOl1WKx+fphxoVxsCB4UTi4xJ9x/8pCKAY631GqKXmknotD2+7YklUkWRuyM27eMUZS hhP7beSnEEVq48P82kJKqUpKHla8QeZAC2U2eA185MqT93PyUh0ZTDteKEofCm0oYq45 G+7A== 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=IwIpTgEdJC+Uxc/pi8uZBNwBm2FWqdghmj+rTinUKMk=; b=Yi03BReOHB304LyHqzbbXrX6L4yqXRS+NzuvK8uEG6w6C+P3b16Jvoy/PaQsvRRQvm d07Q4e6zikL/WSrKLVMYhRPpp07MGfRDbtJ0z8gk7pbapGjxFCUdJ+Prp0ltir/p9Gms liAMVyhIZlMM3PxV2OWLoTq0NwLgU0ssRmfq4VdxGKmWpvuxAaGC1DjrBD3Zsql96FZP OYKdAZTKg+wIJAMALEihrv0WFXUw0+4256y2gcm+mj9JwJjYNJyerdhcllyV/F3ozRBb 07NhkwQO1odR+REIeu90jbyJMJfaT+elSUocbKp/qYNhD2rh3ocvkxLlgGVnscThZz6P dS9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ufn3j/f1"; 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 t20-20020a37ea14000000b006e7db1a5d7csi5782855qkj.220.2022.10.10.20.36.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:36:55 -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="Ufn3j/f1"; 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]:42576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi64d-00031p-4f for patch@linaro.org; Mon, 10 Oct 2022 23:36:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5o2-0002Z7-1D for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:46 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:45964) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5o0-00031J-7M for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:45 -0400 Received: by mail-pj1-x1029.google.com with SMTP id o9-20020a17090a0a0900b0020ad4e758b3so11947022pjo.4 for ; Mon, 10 Oct 2022 20:19:43 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IwIpTgEdJC+Uxc/pi8uZBNwBm2FWqdghmj+rTinUKMk=; b=Ufn3j/f14om1Tnf6mfy9yUPRVnn8vjia70YuhYrQiE4CkDYyhZoadYOe9XkDbm+u5F I6VhbZZrKod+zd0ecfHGkA8O3hKYumuxdQJKqgMrgs5u6CPQBJyn5VIjuppm7gBpTxER YtFh3Zc04Bkz5EGgVIAlOMQnzU4ef4/JD7aoo7RFGAKLZ2DWXv+Jz1jeQAJJizYdAhqb UuFwP8yugYofzoHDRXaDqvzgwgFphA6mjA6HQrB0l/QLItUXTuMJEBdqmWdKjtgGxE3F CG5ysHRUi+VgA3m2qAA3JW85/NZKRx9nOFgru50qN255Atvj9X//Uq3P6upaJ5PqAgNx nwAQ== 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=IwIpTgEdJC+Uxc/pi8uZBNwBm2FWqdghmj+rTinUKMk=; b=cRO0A6gGySjBaPPJuSl3kIlEyxbihV8GigLJ9bGPQBaqbxxc0VFkUzmOmxVyrosdgz RwtdqkNXUOjhy+AoozLJRv7Jl++6lYO2ahMAmwTImWKwt+a4ksS201bmv8SY+au3RthV ChR2um6o3kfU9asprT8DJUS+XBaUzljZ3CJRNP/tXWI+jA0vI7Bu3BVrADtgGraPQXv1 wnCsA0txl/33llU5ARvXJWMUrN12X0Sn/jo/AuqEZd/gA5No3lrzOB/VDPLQmseDmjq1 Oe5bArvcy/ImaEjQkbLMDkUzxUse+DAfzeAhpBXiADeH2GtW1za2IlhohleNv7zEiIXG PxBw== X-Gm-Message-State: ACrzQf35K6kxOjEpo+lO5DO10n9KIiM7yxmPSUCGqphqB1C5C1rpE8uH 97X/o/h1/C8ph/1/V96cIUmPUKjI59Bh5A== X-Received: by 2002:a17:902:f541:b0:181:83e4:4910 with SMTP id h1-20020a170902f54100b0018183e44910mr12923949plf.109.1665458383259; Mon, 10 Oct 2022 20:19:43 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 16/24] target/arm: Move S1_ptw_translate outside arm_ld[lq]_ptw Date: Mon, 10 Oct 2022 20:19:03 -0700 Message-Id: <20221011031911.2408754-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.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" Separate S1 translation from the actual lookup. Will enable lpae hardware updates. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/ptw.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index b2bfcfde9a..d54e6ca938 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -320,18 +320,12 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, } /* All loads done in the course of a page table walk go through here. */ -static uint32_t arm_ldl_ptw(CPUARMState *env, S1Translate *ptw, hwaddr addr, +static uint32_t arm_ldl_ptw(CPUARMState *env, S1Translate *ptw, ARMMMUFaultInfo *fi) { CPUState *cs = env_cpu(env); uint32_t data; - if (!S1_ptw_translate(env, ptw, addr, fi)) { - /* Failure. */ - assert(fi->s1ptw); - return 0; - } - if (likely(ptw->out_host)) { /* Page tables are in RAM, and we have the host address. */ if (ptw->out_be) { @@ -359,18 +353,12 @@ static uint32_t arm_ldl_ptw(CPUARMState *env, S1Translate *ptw, hwaddr addr, return data; } -static uint64_t arm_ldq_ptw(CPUARMState *env, S1Translate *ptw, hwaddr addr, +static uint64_t arm_ldq_ptw(CPUARMState *env, S1Translate *ptw, ARMMMUFaultInfo *fi) { CPUState *cs = env_cpu(env); uint64_t data; - if (!S1_ptw_translate(env, ptw, addr, fi)) { - /* Failure. */ - assert(fi->s1ptw); - return 0; - } - if (likely(ptw->out_host)) { /* Page tables are in RAM, and we have the host address. */ if (ptw->out_be) { @@ -527,7 +515,10 @@ static bool get_phys_addr_v5(CPUARMState *env, S1Translate *ptw, fi->type = ARMFault_Translation; goto do_fault; } - desc = arm_ldl_ptw(env, ptw, table, fi); + if (!S1_ptw_translate(env, ptw, table, fi)) { + goto do_fault; + } + desc = arm_ldl_ptw(env, ptw, fi); if (fi->type != ARMFault_None) { goto do_fault; } @@ -565,7 +556,10 @@ static bool get_phys_addr_v5(CPUARMState *env, S1Translate *ptw, /* Fine pagetable. */ table = (desc & 0xfffff000) | ((address >> 8) & 0xffc); } - desc = arm_ldl_ptw(env, ptw, table, fi); + if (!S1_ptw_translate(env, ptw, table, fi)) { + goto do_fault; + } + desc = arm_ldl_ptw(env, ptw, fi); if (fi->type != ARMFault_None) { goto do_fault; } @@ -650,7 +644,10 @@ static bool get_phys_addr_v6(CPUARMState *env, S1Translate *ptw, fi->type = ARMFault_Translation; goto do_fault; } - desc = arm_ldl_ptw(env, ptw, table, fi); + if (!S1_ptw_translate(env, ptw, table, fi)) { + goto do_fault; + } + desc = arm_ldl_ptw(env, ptw, fi); if (fi->type != ARMFault_None) { goto do_fault; } @@ -703,7 +700,10 @@ static bool get_phys_addr_v6(CPUARMState *env, S1Translate *ptw, ns = extract32(desc, 3, 1); /* Lookup l2 entry. */ table = (desc & 0xfffffc00) | ((address >> 10) & 0x3fc); - desc = arm_ldl_ptw(env, ptw, table, fi); + if (!S1_ptw_translate(env, ptw, table, fi)) { + goto do_fault; + } + desc = arm_ldl_ptw(env, ptw, fi); if (fi->type != ARMFault_None) { goto do_fault; } @@ -1286,7 +1286,10 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, ptw->in_ptw_idx &= ~1; ptw->in_secure = false; } - descriptor = arm_ldq_ptw(env, ptw, descaddr, fi); + if (!S1_ptw_translate(env, ptw, descaddr, fi)) { + goto do_fault; + } + descriptor = arm_ldq_ptw(env, ptw, fi); if (fi->type != ARMFault_None) { goto do_fault; } From patchwork Tue Oct 11 03:19:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614159 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2373530pvb; Mon, 10 Oct 2022 20:37:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7RUwxgqrgNUUaCP/DTHXc33P891/QNviWqqrmt52KdlI5Z8KCxVylqDglqPncz+jv2FfW8 X-Received: by 2002:ac8:5e0a:0:b0:39a:2960:d4a6 with SMTP id h10-20020ac85e0a000000b0039a2960d4a6mr6723916qtx.448.1665459465768; Mon, 10 Oct 2022 20:37:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665459465; cv=none; d=google.com; s=arc-20160816; b=OKtAXlNLvci7LTmLzZzn8r7ec+/ZxZyq8/C6NcPW6CV51AUAhZkFXp6WdhfhbxNm1e kV3d+nVYhmJX3QFDTb5fQcIZOEgtSVGIE+0cMPOAroeovLrHj0N/PGs2oEjeB7vvFrSY gPrY4+RPPPdsZghV9LP58FXKQQpCBv9EF/1koLG7WZeA3Mdgd2QbFrhIOb4GGQvO+1rQ UqxA7z4GIMNTn7tdY+sa7cveus5r1VhkElwUcICMUxLFEvCJASHtPFQ93Qdw+spZVGWn QTpMU8Bk9GD9Bs/AltwJUpeVkZ+kWiSd7XkgNUDHusk6X1haqSB+h92nGBP2ndPF6z4E +G+A== 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=eI+72a+zEZxV/Jolsa9Dnr52GdI9trlBieK7TxOdCAo=; b=JmJKdIMtsWvrkZ7SeHT+8O2gYagUjAlYyCy38OHs11+sqezuAd8K2mKBNLWPSHsLJ+ GtinV+gnIybXeTQHH+aOdVc31G1bvb2F1eeivS1OuunwJ29j2lj5XLswGuZx9WW6o/85 MGn9nebicl85ANaX9xBUKS93qOKGIeav9Kv6FZXhiIlORGZ1tUd8ATw/nqObbvuzw29/ xpNp1TO/ko2MEXLKpFAqlj7dkL4oJQeA8OaCtyRoPEDGDWWubAZNYDtmQuWrPgreePMG qUJWQrvRlcjE2vLjJAigmYpiBui361ZTwZHGqjlsBdRqlXoL7ov2Rx745M5vbxySxkfw gAaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EvvEwixP; 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 hf7-20020a0562140e8700b004afb621a445si6289764qvb.75.2022.10.10.20.37.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:37:45 -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=EvvEwixP; 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]:44758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi65R-0005K6-Au for patch@linaro.org; Mon, 10 Oct 2022 23:37:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5o4-0002dd-BZ for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:49 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:36502) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5o2-00037H-Sb for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:48 -0400 Received: by mail-pj1-x1034.google.com with SMTP id d7-20020a17090a2a4700b0020d268b1f02so5317921pjg.1 for ; Mon, 10 Oct 2022 20:19:46 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eI+72a+zEZxV/Jolsa9Dnr52GdI9trlBieK7TxOdCAo=; b=EvvEwixPpytt52H1US8QZnrl4ptv/e3tjqhY1PZhjdzyARkzS7F6Hg6lMhTAMKwRjZ PYgKRZ/Lb5JMx80fPtRgOBaon2N4Mi7nz8QT8++SUgaRWDBUERYCMXMdH6nQhldHI0Eh 5Z6LwRNEvh5OYcqBNmPhv1W4fmIbPozLd9fwpTje/6pG8BCeNqsDR6EgebV3XBqBv2ru 7C5rILNL9hACqIOqruoNoX/ESGq1vQdSeOe1+Q/YY6wqfB0xGHVcIEZnlraRB+s4k9N+ rDOwcPMzQKSo8zCkV+7d1NSTo32ylly2wvVw77QIrpX4irURekA8u1bdewCqGFWr/Olc tWlw== 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=eI+72a+zEZxV/Jolsa9Dnr52GdI9trlBieK7TxOdCAo=; b=L8MYbq0PCwEZxeWYEAQLqJMTB8Vs+4abX4c5b4O20JCtDrdaJRYxE3UQzJTvAumvCv ZWUSSZpWboapbMFgEYu6B+uQnwsmjxuNYlmbeSnOo6L2U09++IcgEa3uDlnogBHP+3s9 Mi22w/Z1fZOdWdPD/vD6ge5hvSKxg9ZmCHLkW8C9OhW4SI8zvEID5AF/5EbduXetDL70 ffeEDLZYKgj7FmEkPwoRFlu3hY1CKaUdwdLR12KedEfNPaJAqrj9N0+SikbNDPuGTilU 5PDQH0czLVeeX4YqOMqMf3nUeGUkRn6y+QSQCsxZGC+wRBlRkXvx0uF2keQLXfBijanu qRuw== X-Gm-Message-State: ACrzQf2TQq5imclVRCb3fxcTbabPGjVcW4be/GRL9eiE3s1So6OUMxkC OBlCuu/jjKKcGtMvNQSRWEyz1k/4lMgFEw== X-Received: by 2002:a17:902:724a:b0:177:fd96:37bf with SMTP id c10-20020a170902724a00b00177fd9637bfmr20897117pll.25.1665458385374; Mon, 10 Oct 2022 20:19:45 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 17/24] target/arm: Add ARMFault_UnsuppAtomicUpdate Date: Mon, 10 Oct 2022 20:19:04 -0700 Message-Id: <20221011031911.2408754-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1034.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This fault type is to be used with FEAT_HAFDBS when the guest enables hw updates, but places the tables in memory where atomic updates are unsupported. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/internals.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/arm/internals.h b/target/arm/internals.h index 76ec7ee8cc..e195d771e0 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -338,6 +338,7 @@ typedef enum ARMFaultType { ARMFault_AsyncExternal, ARMFault_Debug, ARMFault_TLBConflict, + ARMFault_UnsuppAtomicUpdate, ARMFault_Lockdown, ARMFault_Exclusive, ARMFault_ICacheMaint, @@ -524,6 +525,9 @@ static inline uint32_t arm_fi_to_lfsc(ARMMMUFaultInfo *fi) case ARMFault_TLBConflict: fsc = 0x30; break; + case ARMFault_UnsuppAtomicUpdate: + fsc = 0x31; + break; case ARMFault_Lockdown: fsc = 0x34; break; From patchwork Tue Oct 11 03:19:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614160 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2373628pvb; Mon, 10 Oct 2022 20:38:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5IJ5DwQOedZ327t0HrMD9hDliE8fjIBjQKZxt7d59pmRsOmnTWF70h5H0RMFwF3KW/TwMR X-Received: by 2002:a05:620a:3720:b0:6dd:beba:b3a1 with SMTP id de32-20020a05620a372000b006ddbebab3a1mr14954829qkb.138.1665459486890; Mon, 10 Oct 2022 20:38:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665459486; cv=none; d=google.com; s=arc-20160816; b=HSjEGIX7FVr0bz340OB0WallPP+xilKbSDowdUlCD5PD6mJVWLq6+gOLYDcSnmGB4Z Hwn1JEoO+vcjs8GARVZQ8x1hEBULwhtrYVxYTxyyqaUw5Bkf7Yce7Es092qJTlrOJFiB xC3FpxXjSGOPfmUTGnFJ49S50k55RyX04asQ543jkAK6bGZvPosnj7OOiW4nnLxSM/z8 b1RR2Bk0jketYXSlgrui43xo6Hwx0wazt4XH/tsv7wQBeZBMfbai9EDgLScnegFlrtfL sm946Q86ehlUQvABysMV1nBSYmfxgCdAc3M1qw4MYsChsKhRVUV3gFu6ysAU/n7q4ACT rTRA== 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=v5fZEsizLTBbzlQyMJApbEFH3hQ5MeBPh9aoDq+SKpQ=; b=rtdxCUrvzN9EhRJ8CJaiYAN6bRCI+R7Nv8EW8jC2/r335D6slMm+W+JvBkMVkJBU2b Mies5+1xBEpmdStsGk9zY2yVAFyhYcc2BIZ0M76E8rNZgAgdBMdTxjeYhVME/RxJdkFi VbUIIO/rI7cVnrqKbcLbOQQ/BaQVkswq9omnbff3Oz+1+A2Mz4JhpkwkObhe/9tHnW2Q 3lqtM4fwGyOW9/K0AIFhwrsSRVZRfCeB+jZLxMWXDTX8e0A1NTPOs+BiWlZt4+s50pjo iyfC/YxoV8YrNls87onT4ks06KMi/wzM41HXQljkTflsAymkehidoKeYkIyLFFRbJ0Dk sTGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ELe1O6vY; 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 v22-20020a05620a441600b006ed753846f3si2179283qkp.715.2022.10.10.20.38.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:38:06 -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=ELe1O6vY; 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]:59412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi65m-0006G9-D7 for patch@linaro.org; Mon, 10 Oct 2022 23:38:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5o7-0002f1-MI for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:51 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:36492) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5o5-000383-NH for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:51 -0400 Received: by mail-pj1-x1029.google.com with SMTP id d7-20020a17090a2a4700b0020d268b1f02so5317989pjg.1 for ; Mon, 10 Oct 2022 20:19:48 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v5fZEsizLTBbzlQyMJApbEFH3hQ5MeBPh9aoDq+SKpQ=; b=ELe1O6vYoT5wzrbqk8Cda3tezsb+8nu4BJ3nJq4Xsoovmy7EdwnI35DSz/pFjpSN0R RhjfH8MQMxje0u+M2TVATCh6Ned/PmhDpD5bIEiyyh8onMf97E+iuqaHv25jWtIDE9Wk oNHNRCMoH+P/AG6FO4p50O9ZEkVaCDOS3Y1v+8zlx3FazFH5D8xjE9ZpV2elriZgFxiF jzoRnqM7v6erRRDDYiv+dEoRfKHmXIosyn+zhMrEgvUw3S8JRnnD7+q40cVJMFLluhtf pRvIwyfQnHrTItuhBBcwfg0obR9tH4cI6dBYPO6IFwuICQ55jf1XtaOVagpisNVzm0Tf 7JkQ== 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=v5fZEsizLTBbzlQyMJApbEFH3hQ5MeBPh9aoDq+SKpQ=; b=C3US86ZEafZ4raAcESjhlN1zu2YeVy9B40qyzXVUnxokLIQ9RELSxYiNjvP5rv5/0R MhWujjCtV9ui9Ru1vD2+dXTxqBlCrxWVdA+RugdfaQ3wq2O2mhzsputJ4pksYwhdH7id M7U1rJaFEyxB+0teiK2SOWps+UH/iRmjyvZ7xbUPU5yGYnALxcAuzoOpOANCmSOZSFue lvIPtfhp0yot/QrbY51VOeuW04rUg1Pec4GymO5/THYd1t2pZDETJlf8fmUTH9gtf0o2 RSr5K/60tEsQ4nvvlj7urbVQ9svc1l5TQ0Y7ItBp/TBCUa15B8GRaWfiL0pRUluvWLS/ xgLA== X-Gm-Message-State: ACrzQf2oECVE2NJ44xx5iIlqUN5r9dAA9X9cYrQbBUuAab5Ko9OE86QT gegWZgtRqGwX+sYCoyvhMT9XCxMrENEnWQ== X-Received: by 2002:a17:902:bb86:b0:17c:4cac:eea4 with SMTP id m6-20020a170902bb8600b0017c4caceea4mr21433133pls.141.1665458387502; Mon, 10 Oct 2022 20:19:47 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 18/24] target/arm: Remove loop from get_phys_addr_lpae Date: Mon, 10 Oct 2022 20:19:05 -0700 Message-Id: <20221011031911.2408754-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The unconditional loop was used both to iterate over levels and to control parsing of attributes. Use an explicit goto in both cases. While this appears less clean for iterating over levels, we will need to jump back into the middle of this loop for atomic updates, which is even uglier. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/ptw.c | 182 +++++++++++++++++++++++------------------------ 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index d54e6ca938..9b767f8236 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1082,6 +1082,8 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, uint64_t descaddrmask; bool aarch64 = arm_el_is_aa64(env, el); bool guarded = false; + uint64_t descriptor; + bool nstable; /* TODO: This code does not support shareability levels. */ if (aarch64) { @@ -1274,99 +1276,97 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, * bits at each step. */ tableattrs = is_secure ? 0 : (1 << 4); - for (;;) { - uint64_t descriptor; - bool nstable; - descaddr |= (address >> (stride * (4 - level))) & indexmask; - descaddr &= ~7ULL; - nstable = extract32(tableattrs, 4, 1); - if (!nstable) { - /* Stage2_S -> Stage2 or Phys_S -> Phys_NS */ - ptw->in_ptw_idx &= ~1; - ptw->in_secure = false; - } - if (!S1_ptw_translate(env, ptw, descaddr, fi)) { - goto do_fault; - } - descriptor = arm_ldq_ptw(env, ptw, fi); - if (fi->type != ARMFault_None) { - goto do_fault; - } - - if (!(descriptor & 1) || - (!(descriptor & 2) && (level == 3))) { - /* Invalid, or the Reserved level 3 encoding */ - goto do_fault; - } - - descaddr = descriptor & descaddrmask; - - /* - * For FEAT_LPA and PS=6, bits [51:48] of descaddr are in [15:12] - * of descriptor. For FEAT_LPA2 and effective DS, bits [51:50] of - * descaddr are in [9:8]. Otherwise, if descaddr is out of range, - * raise AddressSizeFault. - */ - if (outputsize > 48) { - if (param.ds) { - descaddr |= extract64(descriptor, 8, 2) << 50; - } else { - descaddr |= extract64(descriptor, 12, 4) << 48; - } - } else if (descaddr >> outputsize) { - fault_type = ARMFault_AddressSize; - goto do_fault; - } - - if ((descriptor & 2) && (level < 3)) { - /* - * Table entry. The top five bits are attributes which may - * propagate down through lower levels of the table (and - * which are all arranged so that 0 means "no effect", so - * we can gather them up by ORing in the bits at each level). - */ - tableattrs |= extract64(descriptor, 59, 5); - level++; - indexmask = indexmask_grainsize; - continue; - } - /* - * Block entry at level 1 or 2, or page entry at level 3. - * These are basically the same thing, although the number - * of bits we pull in from the vaddr varies. Note that although - * descaddrmask masks enough of the low bits of the descriptor - * to give a correct page or table address, the address field - * in a block descriptor is smaller; so we need to explicitly - * clear the lower bits here before ORing in the low vaddr bits. - */ - page_size = (1ULL << ((stride * (4 - level)) + 3)); - 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); - - if (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) { - /* Stage 2 table descriptors do not include any attribute fields */ - break; - } - /* Merge in attributes from table descriptors */ - attrs |= nstable << 3; /* NS */ - guarded = extract64(descriptor, 50, 1); /* GP */ - if (param.hpd) { - /* HPD disables all the table attributes except NSTable. */ - break; - } - attrs |= extract32(tableattrs, 0, 2) << 11; /* 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] */ - break; + next_level: + descaddr |= (address >> (stride * (4 - level))) & indexmask; + descaddr &= ~7ULL; + nstable = extract32(tableattrs, 4, 1); + if (!nstable) { + /* Stage2_S -> Stage2 or Phys_S -> Phys_NS */ + ptw->in_ptw_idx &= ~1; + ptw->in_secure = false; } + if (!S1_ptw_translate(env, ptw, descaddr, fi)) { + goto do_fault; + } + descriptor = arm_ldq_ptw(env, ptw, fi); + if (fi->type != ARMFault_None) { + goto do_fault; + } + + if (!(descriptor & 1) || (!(descriptor & 2) && (level == 3))) { + /* Invalid, or the Reserved level 3 encoding */ + goto do_fault; + } + + descaddr = descriptor & descaddrmask; + + /* + * For FEAT_LPA and PS=6, bits [51:48] of descaddr are in [15:12] + * of descriptor. For FEAT_LPA2 and effective DS, bits [51:50] of + * descaddr are in [9:8]. Otherwise, if descaddr is out of range, + * raise AddressSizeFault. + */ + if (outputsize > 48) { + if (param.ds) { + descaddr |= extract64(descriptor, 8, 2) << 50; + } else { + descaddr |= extract64(descriptor, 12, 4) << 48; + } + } else if (descaddr >> outputsize) { + fault_type = ARMFault_AddressSize; + goto do_fault; + } + + if ((descriptor & 2) && (level < 3)) { + /* + * Table entry. The top five bits are attributes which may + * propagate down through lower levels of the table (and + * which are all arranged so that 0 means "no effect", so + * we can gather them up by ORing in the bits at each level). + */ + tableattrs |= extract64(descriptor, 59, 5); + level++; + indexmask = indexmask_grainsize; + goto next_level; + } + + /* + * Block entry at level 1 or 2, or page entry at level 3. + * These are basically the same thing, although the number + * of bits we pull in from the vaddr varies. Note that although + * descaddrmask masks enough of the low bits of the descriptor + * to give a correct page or table address, the address field + * in a block descriptor is smaller; so we need to explicitly + * clear the lower bits here before ORing in the low vaddr bits. + */ + page_size = (1ULL << ((stride * (4 - level)) + 3)); + 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); + + if (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) { + /* Stage 2 table descriptors do not include any attribute fields */ + goto skip_attrs; + } + /* Merge in attributes from table descriptors */ + attrs |= nstable << 3; /* 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 */ + /* + * 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] */ + skip_attrs: + /* * Here descaddr is the final physical address, and attributes * are all in attrs. From patchwork Tue Oct 11 03:19:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614163 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2374429pvb; Mon, 10 Oct 2022 20:40:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6pzQBcoqXT7IePaaYtaigMrLmDgdAdOGYquSmlEYwej41qiM2E64etPI5Bw3Xf0DorkuGo X-Received: by 2002:ad4:5cad:0:b0:4b1:c5e2:bf4d with SMTP id q13-20020ad45cad000000b004b1c5e2bf4dmr17235190qvh.15.1665459646925; Mon, 10 Oct 2022 20:40:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665459646; cv=none; d=google.com; s=arc-20160816; b=DweezJbOMJ7n+t5d7tgjbCdBiP9mQcc5LT/5aPpg7u4moRiGK2wo6bqCzqRafVNJ2u iN6aaxfNFD7aR5uF14aySyzBmuG6NtHorKcjd5IlTYVpZdXL0bAYW8u2/XR2lzy80Tpe Rs1VSIXSyHpNoNfGn3yJonKRUVvFf78seLgUoVbmzRTShuB3nWf1eQ7QD7bT9Ne4MwlD OlTtgpol2P9OvDsNAGdFWwnlEGTygLRGjIMiYh6UCBoZEHtzkr3A8op4uFK6UK3bZTH8 VMzhIqg40mkDiDWNmKe4BGMoU5ZaT2XHowu/d4VQnkTcJSEUUshtyZWEaFJRMO1I9XmN FZqQ== 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=JyqDFzcDDxaZLADzD0GCm51gPMwBsgamq3ZkxmoSGeA=; b=Dqxs6hGBNswQ/rGjyCGbGS3MRnXQ3GlM8yhgJe+FN83JUfipRLOfgDJ7XWYdWFiN+B iWzBXOb7zsxXAWWQl/W/IlKjZh/58XKqAWe8zpPE22MLKEQOWIXm4jLnt4MaVw65NfBV YbQ7kdX9S6wK4OWvn2scg0nueUbQ+hZWGsxxTH8/XkPw7sCJ3I7t0zqZev7b+I/x8DNe 0ZLMy1cb4bdlyqJ1ozUHtbiDYWEYDAcSYdFbk0T+kyCewLqnbxRMUeLW9FV4bJqAHUQM 8Mf0hE6QAxDolwjrZw++Q8mt5A1Y4wcxpAHb54l1HRq5mGurJpufq4cbU3X/KlShqemC Ys9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OE0TB5uL; 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 r11-20020a05620a298b00b006ce7dfdaf38si7192048qkp.551.2022.10.10.20.40.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:40:46 -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=OE0TB5uL; 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]:47116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi68M-00028n-Ay for patch@linaro.org; Mon, 10 Oct 2022 23:40:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5o9-0002hm-2C for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:53 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:33661) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5o7-00038P-Bw for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:52 -0400 Received: by mail-pg1-x52f.google.com with SMTP id f193so11830100pgc.0 for ; Mon, 10 Oct 2022 20:19:50 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JyqDFzcDDxaZLADzD0GCm51gPMwBsgamq3ZkxmoSGeA=; b=OE0TB5uLs6bj9+ksRf+VC0vrhDph/IcghoHXZ+0fe7Bpa37UwGcpOOOh4g+jr16yYr 1aUqITTHb0ncwSAlbcFHPewMfS0FR3q84+8AQuuuDHZKH0lUUVDIWNNzXCskWwkhOki4 ktt0zvqtgY9AXgwCind0tqnv3fwupMOKAXULW+V/5+v8KlHgTT8tWacUcwZgBwmH50Eu WukUXpkefB62D5K7X01LjU9CKfKve+LB6iiGEVZOxhfFkaLM/W2Nqmb4JloJjyp4DYm7 esfZB16nPRfzZxrJ+A+IQ0hs8KSBXEb/LvFLVUQ2yu5Pbz5eBNBguxk/8yisH0+N/TpB OuIQ== 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=JyqDFzcDDxaZLADzD0GCm51gPMwBsgamq3ZkxmoSGeA=; b=Uu1d6yHRyzEllXgW3dzlXUwDB48mySOb0tj0AsL4w/HLNQsvI9u21XT5/gKFeClNqA 8iIhFQr30fF50rIP0VkUr475hsNqfhyNAv5bPEMpNQxy+0oGBNTp4DVtwWPT+pIdrPal ndrg2ttdUV2xrA1zbQYuFwguYCt2Jqq8kdBQp/eX+UlbN8Mas5R+ohaKUZzjOeXg1jO7 jCUYgW3kiWybcdlOZm9WFeITp5TByFaJ0HEFfAg60KYRJGo+f986tGRRXmPIU93F+soH XGUwYq17NRJMArHUCHGlchma37iqYDqp63Jm8zmWFmJeqLyR7+JJpneVBzurVM5WMTtJ Qijg== X-Gm-Message-State: ACrzQf2VYGRj8kZPbZhVaRGwGmnCbWSeE0oWSWc8qZFhmpA7jpBiAp/B Lp3eCIhn3Fb5FlXHUaPK5vg0YByw0o+4DQ== X-Received: by 2002:a05:6a00:134f:b0:563:7aa8:5cea with SMTP id k15-20020a056a00134f00b005637aa85ceamr6098400pfu.69.1665458389473; Mon, 10 Oct 2022 20:19:49 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 19/24] target/arm: Fix fault reporting in get_phys_addr_lpae Date: Mon, 10 Oct 2022 20:19:06 -0700 Message-Id: <20221011031911.2408754-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.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" Always overriding fi->type was incorrect, as we would not properly propagate the fault type from S1_ptw_translate, or arm_ldq_ptw. Simplify things by providing a new label for a translation fault. For other faults, store into fi directly. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/ptw.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 9b767f8236..acbf09cce8 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1065,8 +1065,6 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, ARMCPU *cpu = env_archcpu(env); ARMMMUIdx mmu_idx = ptw->in_mmu_idx; bool is_secure = ptw->in_secure; - /* Read an LPAE long-descriptor translation table. */ - ARMFaultType fault_type = ARMFault_Translation; uint32_t level; ARMVAParameters param; uint64_t ttbr; @@ -1103,8 +1101,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, * so our choice is to always raise the fault. */ if (param.tsz_oob) { - fault_type = ARMFault_Translation; - goto do_fault; + goto do_translation_fault; } addrsize = 64 - 8 * param.tbi; @@ -1141,8 +1138,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, addrsize - inputsize); if (-top_bits != param.select) { /* The gap between the two regions is a Translation fault */ - fault_type = ARMFault_Translation; - goto do_fault; + goto do_translation_fault; } } @@ -1168,7 +1164,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, * Translation table walk disabled => Translation fault on TLB miss * Note: This is always 0 on 64-bit EL2 and EL3. */ - goto do_fault; + goto do_translation_fault; } if (mmu_idx != ARMMMUIdx_Stage2 && mmu_idx != ARMMMUIdx_Stage2_S) { @@ -1199,8 +1195,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, if (param.ds && stride == 9 && sl2) { if (sl0 != 0) { level = 0; - fault_type = ARMFault_Translation; - goto do_fault; + goto do_translation_fault; } startlevel = -1; } else if (!aarch64 || stride == 9) { @@ -1219,8 +1214,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, ok = check_s2_mmu_setup(cpu, aarch64, startlevel, inputsize, stride, outputsize); if (!ok) { - fault_type = ARMFault_Translation; - goto do_fault; + goto do_translation_fault; } level = startlevel; } @@ -1242,7 +1236,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, descaddr |= extract64(ttbr, 2, 4) << 48; } else if (descaddr >> outputsize) { level = 0; - fault_type = ARMFault_AddressSize; + fi->type = ARMFault_AddressSize; goto do_fault; } @@ -1296,7 +1290,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, if (!(descriptor & 1) || (!(descriptor & 2) && (level == 3))) { /* Invalid, or the Reserved level 3 encoding */ - goto do_fault; + goto do_translation_fault; } descaddr = descriptor & descaddrmask; @@ -1314,7 +1308,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, descaddr |= extract64(descriptor, 12, 4) << 48; } } else if (descaddr >> outputsize) { - fault_type = ARMFault_AddressSize; + fi->type = ARMFault_AddressSize; goto do_fault; } @@ -1371,9 +1365,9 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, * Here descaddr is the final physical address, and attributes * are all in attrs. */ - fault_type = ARMFault_AccessFlag; if ((attrs & (1 << 8)) == 0) { /* Access flag */ + fi->type = ARMFault_AccessFlag; goto do_fault; } @@ -1390,8 +1384,8 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, result->f.prot = get_S1prot(env, mmu_idx, aarch64, ap, ns, xn, pxn); } - fault_type = ARMFault_Permission; if (!(result->f.prot & (1 << access_type))) { + fi->type = ARMFault_Permission; goto do_fault; } @@ -1436,8 +1430,9 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, result->f.lg_page_size = ctz64(page_size); return false; -do_fault: - fi->type = fault_type; + do_translation_fault: + fi->type = ARMFault_Translation; + do_fault: fi->level = level; /* Tag the error as S2 for failed S1 PTW at S2 or ordinary S2. */ fi->stage2 = fi->s1ptw || (mmu_idx == ARMMMUIdx_Stage2 || From patchwork Tue Oct 11 03:19:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614162 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2374401pvb; Mon, 10 Oct 2022 20:40:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5LWiK5jkxfscmOxnikUyqALhahLx7YdHBMIz70oRnCUVNZPoRFhi3N1Aa6PmiXH+mhfB8X X-Received: by 2002:a05:620a:24cf:b0:6ee:6fb:4adf with SMTP id m15-20020a05620a24cf00b006ee06fb4adfmr3487454qkn.755.1665459640252; Mon, 10 Oct 2022 20:40:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665459640; cv=none; d=google.com; s=arc-20160816; b=ZpMjbi+EQQj6YSLxhk9cOQxc0/e3BSGwf1RwebF7fodm06DxdGLeBauM8dHHGhYAVy 8IA9jbkuhPKiiLr2Acc6hyFtTdfRKGNarWCs1vdnpBg4e/e/WoeBQy+b7sOPyM8m+p+d KP8xxnfydjVMQPhaviafQA7lHPYWvKAQh4BnKJ628Weg23y72GR7DilB42MnzrkIybiL n8oU/PEMNG2bn6isOOf3TSduX6OPqdTYGK6apXKFrwy2zhFViey1UOdaRP4+OsehLojR UWQuUERSUopSipERv061Qnc71kaS4jnZPjdJgZkB0U3RTmwJI6+GVOVJpw+BihMNmUCz XXMg== 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=gpVIvUSjcXxlKo9G6SyGwDfpHpkVNVoesHQX5YvP4p8=; b=JNb8rkxurkvnjlts2tQHKy/zWCtI6UuxszPe+xK7nVIBXnKm2DQtKsTNx2aNoT4hHA IHsPv9t0GaMbj9i2Bwj5jfRZtMsHaZbHPmXCbR7owLkrG8aYrzJJMpKOD84OybE8dcut 4DkOXpqpgl5yC8dXO4UG1Ct692C0ovTcHTe3HZPwhvLY/jsCw8wB6XZjk924qX5vMsUd 2443yze7SW48ePTRisRiesslIc3OIC+G+8orS5M7dX1SZNp53MQuAz4X+SlyjnJI26Ce /ZBKvUeeDclmrvLO2DF0tEBi8jT1vpwHCkHmkAqq7QdID/kazFRT5zK2wcRMPRtfjX7Y vx2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l0On0j8n; 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 fy21-20020a05622a5a1500b0039c71c28d01si230200qtb.13.2022.10.10.20.40.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:40:40 -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=l0On0j8n; 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]:47114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi68E-0001yC-My for patch@linaro.org; Mon, 10 Oct 2022 23:40:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5oE-0002vQ-Mu for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:58 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:33380) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5oB-00039A-Tw for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:57 -0400 Received: by mail-pf1-x431.google.com with SMTP id w2so12414632pfb.0 for ; Mon, 10 Oct 2022 20:19:55 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gpVIvUSjcXxlKo9G6SyGwDfpHpkVNVoesHQX5YvP4p8=; b=l0On0j8nJ1Qznf6Pt+v8hJrEu/SYiTAJoVPGA9aV+hT4pKbEyuzAuVq8gheVM3QYha wPqFPpkL5WmunUncybJm2NPG5h+aIzZJrCVVLkw3OqfoaoYfuBEzKRSbhse3pHQgKaIl 8kVuDdEYDXksoUcUTLpQJrl0EFysWWjK1Wf6FKd0SoUUCfG/BQHvNvbiovGxiOjmuPYH xKFkpnXVr9CVDVslfjiHoUwvhZDcN4EOKzpYhQN+fgbpvnaosTBlbGXbD/KDX3sOhqYU oK+/ufXXPFysp5TqFj5iI2BbSv5m3DEtiMI1miiz+59FYDU6mcOXhE7NGGLsdM9P3GzS J9aQ== 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=gpVIvUSjcXxlKo9G6SyGwDfpHpkVNVoesHQX5YvP4p8=; b=Ke3/D7U8O66xLGZd7PO5RCBfE4di/L9OdEFWOoInIQRBjjWjezX8bOFhO0Na0qWMWv QJpogquce1wwRwG7smP0demHCMXPweaubgOHG1GdLD4DJblO7qBavu/ri32obgBe0b0u d8occf4lpEnh86ONIE0WTnUg+1QotivGTf2BOuUJCz9Wq1U8UJSjwURv0SpUMcB7FBaE sRgaprjVTDdBN2yN5q1df304cDfHanDwjg9xI9UqngazASygBD35zKRid44uUmhlr5cG RKI+EufUjcngI4k6gI2p//RUMtZx7rZK/mf7nIdBtAAsDPepMnr2gk59vdeXKrklIw5t S3xA== X-Gm-Message-State: ACrzQf3aL6V8PxTosOrhptlDTIyVgaNeyOYZ7CMu2IBknqfjFhIw+1X7 1NEov3wGIpEAEj2UIcuPfsyBcKPTPNkQWg== X-Received: by 2002:a65:6b8e:0:b0:44f:ec0f:f684 with SMTP id d14-20020a656b8e000000b0044fec0ff684mr18686459pgw.25.1665458394569; Mon, 10 Oct 2022 20:19:54 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 20/24] target/arm: Don't shift attrs in get_phys_addr_lpae Date: Mon, 10 Oct 2022 20:19:07 -0700 Message-Id: <20221011031911.2408754-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.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" 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 --- 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 acbf09cce8..2227d2a2fd 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1071,7 +1071,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); @@ -1338,49 +1338,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 (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) { /* 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 (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) { ns = mmu_idx == ARMMMUIdx_Stage2; - xn = extract32(attrs, 11, 2); + xn = extract64(attrs, 54, 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); } @@ -1405,10 +1404,10 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, if (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) { 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; @@ -1423,7 +1422,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; From patchwork Tue Oct 11 03:19:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614165 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2375485pvb; Mon, 10 Oct 2022 20:44:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5q9C8ODgR6VpUd0vTZnviBp76mcoHgEyE1BBeJf07NR+/zSZhINQipeekeGCnf0Fbie2EQ X-Received: by 2002:a05:6214:29e7:b0:4b1:c8f7:5ec6 with SMTP id jv7-20020a05621429e700b004b1c8f75ec6mr17664377qvb.79.1665459860757; Mon, 10 Oct 2022 20:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665459860; cv=none; d=google.com; s=arc-20160816; b=I7vQRVWuLI6t1z8l/3abHaQlEK2wzy+AGA7BRm8ZOIcowTcLTy7y3efTcWQ8HD5xF3 EI7q/Y8iaLVap13OYhkAcipgppFHyEKiLMukvJoqmoker0QqrfojgmkN8En0w4vpsybf kgC/waLRDgDQeXrVFiIP8iHEDg/02xljVYm8PChwJroyaIJuc+0aWjgfiohNE0EK+vyv udg0G6fSPD8fe0VjyHBVUwjCFsIMLGeauEahUpV+h5P6DJEzwktAzyarJpLaroYkQEK6 hV5CCYX3ba6Keu5d/c6CfgsAWLkm0QTIU+NzeXLPmyyKc4Q/YVlW6o3OidIFmR3nICyw /wng== 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=yLLkCOK7bzChQB4VCn3LE0QgfibyZ4Lat7LyMKKGuQg=; b=MSIbPsue9jY1gfflcYlKmLl4/QLLCHTkoplIr4F5gK5KE03Y8XknOCdxCkGjpe+H2D n0cvSgJ/frEnY3onELJrTNAcmKp14ForDBNi0bwjYvmSA5pW9xI9j0kYzRobPX3MXxOT OOc5nNDS+y7gMZlGsRw8763/Ok6/etB5/xd7qMHLj+Y7MTtpJnJAESKPDaMsyKyo2kKy C7+RqGcuOZOD0hlpGcQzoUri6uFpW224dvcyjstUsRVCeB+TSFnxK7LrTS9UKGyvjQMf UHxwYgAAWogwqPheYJ3tTtnAYnK/41cusYdhn5aPHDj5LxTUkwn3EgzcGgefvn/aZXkd egmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bsWsWIg+; 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 gs12-20020a056214226c00b004afae3652c4si6109570qvb.81.2022.10.10.20.44.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:44:20 -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=bsWsWIg+; 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]:58130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi6Bo-0007Ti-BA for patch@linaro.org; Mon, 10 Oct 2022 23:44:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5oF-0002yw-GR for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:59 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:34761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5oD-00032t-Tv for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:19:59 -0400 Received: by mail-pf1-x429.google.com with SMTP id f140so12378175pfa.1 for ; Mon, 10 Oct 2022 20:19:57 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yLLkCOK7bzChQB4VCn3LE0QgfibyZ4Lat7LyMKKGuQg=; b=bsWsWIg+qvdmH6FWPNsiw35tXhii6WawZXObtX4Y9u38J9yJqYVoYz+gzgdc4uiOX3 lYkmgMIV+ah86H0FDuqZA0NraW+B1ZlBYNsyC5BuFpUzG9d+hyr4ok3VQViczYeyoSpA lVoApaw6T7Uwsa0AnkItZ191LCNsr17FgFZ4FU/KI4mBMwv+ndU7DfGd+oK/6uBje8/G YGu9jZR5g38NPfnMey+xBXk35EqBpZ7jASQgI1Op8iLfekFghhXklDurGbnNbptbKAIg GMXzsbNG9X4HJkkQ3tZPlVB7GgUx2Xq3vIIeVggl2r39xMnINnqfRuht46ADS5MDDKgo nsZA== 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=yLLkCOK7bzChQB4VCn3LE0QgfibyZ4Lat7LyMKKGuQg=; b=IftsFbX/GmL95Oful3yIYWnWLmwU39uhQnGgcwFf8ccK0LZoSLyBtgyp+XfOEOxcfB n0Kku67HU4ovYnHibd2/T/BwEJGysNRuKVgN7zm5MCfzL+4nH7gwYY83F++05y377Zjm YzEG4AI3Apu1LXHbtjrKTE46aluqMThG9a8X8PddHdZuXTdZN2pQn7sQu4Qc135PSFgp Xx0/O/nRUZ7o9OieXhrGUHXxvakHXZLE9lRljvH6folLpZOvEz9tE7vQfQVb0hysZsCN JjY3tymvljWo+92cYJga1b5DVS55YrXLtVBcRq7Zgj/uia0xdDLkcWf2U5Pqqpl/0gOm bHkg== X-Gm-Message-State: ACrzQf3byFFt88Y11TOZvEuQpu6ySYLUXtKuQUA6vONcU2MR9vV6qfnN EMCc6rKC1ddVAlkBQ/lp6srC16UnlT3biQ== X-Received: by 2002:a62:144b:0:b0:562:38de:9a0e with SMTP id 72-20020a62144b000000b0056238de9a0emr22981955pfu.78.1665458397156; Mon, 10 Oct 2022 20:19:57 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PATCH v4 21/24] target/arm: Consider GP an attribute in get_phys_addr_lpae Date: Mon, 10 Oct 2022 20:19:08 -0700 Message-Id: <20221011031911.2408754-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Both GP and DBM are in the upper attribute block. Extend the computation of attrs to include them, then simplify the setting of guarded. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/ptw.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 2227d2a2fd..8db635ca98 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1079,7 +1079,6 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, uint32_t el = regime_el(env, mmu_idx); uint64_t descaddrmask; bool aarch64 = arm_el_is_aa64(env, el); - bool guarded = false; uint64_t descriptor; bool nstable; @@ -1338,7 +1337,7 @@ 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 = descriptor & (MAKE_64BIT_MASK(2, 10) | MAKE_64BIT_MASK(52, 12)); + attrs = descriptor & (MAKE_64BIT_MASK(2, 10) | MAKE_64BIT_MASK(50, 14)); if (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) { /* Stage 2 table descriptors do not include any attribute fields */ @@ -1346,7 +1345,6 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, } /* Merge in attributes from table descriptors */ attrs |= nstable << 5; /* NS */ - guarded = extract64(descriptor, 50, 1); /* GP */ if (param.hpd) { /* HPD disables all the table attributes except NSTable. */ goto skip_attrs; @@ -1399,7 +1397,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, /* When in aarch64 mode, and BTI is enabled, remember GP in the TLB. */ if (aarch64 && cpu_isar_feature(aa64_bti, cpu)) { - result->f.guarded = guarded; + result->f.guarded = extract64(attrs, 50, 1); /* GP */ } if (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) { From patchwork Tue Oct 11 03:19:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614164 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2375467pvb; Mon, 10 Oct 2022 20:44:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4BW9m200Xcr40BoHU92k4RQY21txBUupBe1NIF7DXTySW9Ml9LtBkeOFMNoH7dBQLRf5tS X-Received: by 2002:a05:620a:4414:b0:6ee:76e4:1b6d with SMTP id v20-20020a05620a441400b006ee76e41b6dmr1841546qkp.360.1665459855726; Mon, 10 Oct 2022 20:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665459855; cv=none; d=google.com; s=arc-20160816; b=vIk8PGbmip6Xd1nktf5q0+Lltg1kD1bAeNZkwJqrKQxVykZfIh/9gA/UceNTwIfLgx U/iGGtpuHMxSgwLY20QNyzCfKsOAglDrfYimytIZSjPr4wt9R40fnLXA1h4UflNJD44O Z9mPTUhI8GYaRUtZUhsVd2/halr32pW2qr1+lNqnkqm7qjO3ga/FUvgJMyE5nUqgR31G rzJnVRdvpIcTACVKl8pRlHRpRD3abSsSbR4aN7jV0CY2D24tuA4HM9qFMAPzshu7hjrH +t1sop0eaRCoR+3j7vsNcMywlHiH4dXlGbKROeodvvhe6aQGzwH3qBgSrkJ9yharq0ft 8yvA== 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=bJPEC3BwoVIhsSgzWNhUHVugWdZpjXqWRjZ6hFgZtFg=; b=b83EyGSQKSx4/SkCCvmnegMoJTWwd3pBD763Rqfdr1UHVnj3pMT35uQWqASKnGuSsU 6FRvjmPqxQBmKmtJXB2pPhePL1lNPPlZ8l26BfRh3abRvZxgu7MO4eAr3sCyP018m1aF LIkMp78Ho3xCKQdDDzXkZd2m7HddYAcEiNpL/Qv1Nu7nNQGxb7MMKoasAshWyFw3NtNV tc5yB7JVw2rD7oqnVQ0k1QSyF7QaGOjRCvNipbum2NyG+Q0v+kAFGK4n4vsyo5orBy+F UecfFadK5WJaldsxb1TWRrxef+Sb0wQ8WtpTeEaGC9U0AZv1glIdYU8ZHzznuHJ6SFKK EEQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uBmYOatX; 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 71-20020a37034a000000b006ea81e7b8c1si4762735qkd.134.2022.10.10.20.44.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:44:15 -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=uBmYOatX; 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]:59770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi6Bi-0007JZ-8K for patch@linaro.org; Mon, 10 Oct 2022 23:44:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5oI-00037g-Nl for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:20:02 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:41875) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5oG-00032I-HO for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:20:02 -0400 Received: by mail-pf1-x42f.google.com with SMTP id g28so12344977pfk.8 for ; Mon, 10 Oct 2022 20:20:00 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bJPEC3BwoVIhsSgzWNhUHVugWdZpjXqWRjZ6hFgZtFg=; b=uBmYOatXBQ4Gq10m3eVqeul1KfHowje7VNuDaTSNvpgmzzfvTuL4v4vPE79uDIljyT RbG5/4QeEh1PBkiWHIxsZZn/QGNJMvAoly/RqMgqh38vc02DhfAhAifCEHtmSAyrulNb J3gmCxnikJngcbuOZrWdWvEs7dY4BoKL/O7MrDpq1XR4tmgCrvim16huIIMxS5b/o0Er LbL8FD3QwLKEQcCckAZn1plJkG5/dmPCnKJyJUszVXfnq6Q5aGyshX8VLhRWI6gx9XXQ sizszswFTpzEXbhbSrYULHWWaRsRu/5iISrTdyA4aEa46HAutjoLxR5ztxg8pj6bMHiR g6kA== 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=bJPEC3BwoVIhsSgzWNhUHVugWdZpjXqWRjZ6hFgZtFg=; b=bLSdJ/B5KNOUbvnZ+9OD+3fttey3UMOIg4mPRao+AVdFcMSWcKq9OeiLQO/+Jz2I5C uTIJAu3RvlZuSLEytfmZMAkOdQKxzMr1V0bURLRp1fKtRlqwAMP8Hg33O/ZbvqsXserv W4BdJyrGOlyFsvJoiWDNPy4PMdQqduY5nb5eh24+uEWc2Yb3Qmkvs4bjU6WlbUQeg01C Oerr+s5ll9PaJeEMEwnD3JUExMvoaydjRNLedhKpDbEk3Wmw6TyEQMDMc+zsssg8yczy z6L5p60WZRSA43YuuNaDKN8SQn9+STf8uzUbquVxxTQnJRUhatZCBXipxMIBTJf4SusC mrsA== X-Gm-Message-State: ACrzQf0+63rrUs3ngQw2hPoYrisBy7H1SM4hmVJLwMS21ZcBZn4+XCNh s0ACtPWMIt4DeHgrJWGwIe34PcQyduqAuw== X-Received: by 2002:aa7:8d57:0:b0:562:b63c:c2ba with SMTP id s23-20020aa78d57000000b00562b63cc2bamr21613982pfe.29.1665458399668; Mon, 10 Oct 2022 20:19:59 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:19:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v4 22/24] target/arm: Implement FEAT_HAFDBS, access flag portion Date: Mon, 10 Oct 2022 20:19:09 -0700 Message-Id: <20221011031911.2408754-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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" Perform the atomic update for hardware management of the access flag. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- v4: Raise permission fault if pte read-only and atomic update reqd. Split out dirty bit portion. Prepare for a single update for AF + DB. --- docs/system/arm/emulation.rst | 1 + target/arm/cpu64.c | 1 + target/arm/ptw.c | 147 +++++++++++++++++++++++++++++++--- 3 files changed, 138 insertions(+), 11 deletions(-) diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst index cfb4b0768b..580e67b190 100644 --- a/docs/system/arm/emulation.rst +++ b/docs/system/arm/emulation.rst @@ -32,6 +32,7 @@ the following architecture extensions: - FEAT_FlagM (Flag manipulation instructions v2) - FEAT_FlagM2 (Enhancements to flag manipulation instructions) - FEAT_GTG (Guest translation granule size) +- FEAT_HAFDBS (Hardware management of the access flag and dirty bit state) - FEAT_HCX (Support for the HCRX_EL2 register) - FEAT_HPDS (Hierarchical permission disables) - FEAT_I8MM (AArch64 Int8 matrix multiplication instructions) diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 85e0d1daf1..fe1369fe96 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -1165,6 +1165,7 @@ static void aarch64_max_initfn(Object *obj) cpu->isar.id_aa64mmfr0 = t; t = cpu->isar.id_aa64mmfr1; + t = FIELD_DP64(t, ID_AA64MMFR1, HAFDBS, 1); /* FEAT_HAFDBS, AF only */ t = FIELD_DP64(t, ID_AA64MMFR1, VMIDBITS, 2); /* FEAT_VMID16 */ t = FIELD_DP64(t, ID_AA64MMFR1, VH, 1); /* FEAT_VHE */ t = FIELD_DP64(t, ID_AA64MMFR1, HPDS, 1); /* FEAT_HPDS */ diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 8db635ca98..82b6ab029e 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -21,7 +21,9 @@ typedef struct S1Translate { bool in_secure; bool in_debug; bool out_secure; + bool out_rw; bool out_be; + hwaddr out_virt; hwaddr out_phys; void *out_host; } S1Translate; @@ -240,6 +242,8 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, uint8_t pte_attrs; bool pte_secure; + ptw->out_virt = addr; + if (unlikely(ptw->in_debug)) { /* * From gdbstub, do not use softmmu so that we don't modify the @@ -267,6 +271,7 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, pte_secure = s2.f.attrs.secure; } ptw->out_host = NULL; + ptw->out_rw = false; } else { CPUTLBEntryFull *full; int flags; @@ -281,6 +286,7 @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, goto fail; } ptw->out_phys = full->phys_addr; + ptw->out_rw = full->prot & PROT_WRITE; pte_attrs = full->pte_attrs; pte_secure = full->attrs.secure; } @@ -324,14 +330,16 @@ static uint32_t arm_ldl_ptw(CPUARMState *env, S1Translate *ptw, ARMMMUFaultInfo *fi) { CPUState *cs = env_cpu(env); + void *host = ptw->out_host; uint32_t data; - if (likely(ptw->out_host)) { + if (likely(host)) { /* Page tables are in RAM, and we have the host address. */ + data = qatomic_read((uint32_t *)host); if (ptw->out_be) { - data = ldl_be_p(ptw->out_host); + data = be32_to_cpu(data); } else { - data = ldl_le_p(ptw->out_host); + data = le32_to_cpu(data); } } else { /* Page tables are in MMIO. */ @@ -357,15 +365,25 @@ static uint64_t arm_ldq_ptw(CPUARMState *env, S1Translate *ptw, ARMMMUFaultInfo *fi) { CPUState *cs = env_cpu(env); + void *host = ptw->out_host; uint64_t data; - if (likely(ptw->out_host)) { + if (likely(host)) { /* Page tables are in RAM, and we have the host address. */ +#ifdef CONFIG_ATOMIC64 + data = qatomic_read__nocheck((uint64_t *)host); if (ptw->out_be) { - data = ldq_be_p(ptw->out_host); + data = be64_to_cpu(data); } else { - data = ldq_le_p(ptw->out_host); + data = le64_to_cpu(data); } +#else + if (ptw->out_be) { + data = ldq_be_p(host); + } else { + data = ldq_le_p(host); + } +#endif } else { /* Page tables are in MMIO. */ MemTxAttrs attrs = { .secure = ptw->out_secure }; @@ -386,6 +404,91 @@ static uint64_t arm_ldq_ptw(CPUARMState *env, S1Translate *ptw, return data; } +static uint64_t arm_casq_ptw(CPUARMState *env, uint64_t old_val, + uint64_t new_val, S1Translate *ptw, + ARMMMUFaultInfo *fi) +{ + uint64_t cur_val; + void *host = ptw->out_host; + + if (unlikely(!host)) { + fi->type = ARMFault_UnsuppAtomicUpdate; + fi->s1ptw = true; + return 0; + } + + /* + * Raising a stage2 Protection fault for an atomic update to a read-only + * page is delayed until it is certain that there is a change to make. + */ + if (unlikely(!ptw->out_rw)) { + int flags; + void *discard; + + env->tlb_fi = fi; + flags = probe_access_flags(env, ptw->out_virt, MMU_DATA_STORE, + arm_to_core_mmu_idx(ptw->in_ptw_idx), + true, &discard, 0); + env->tlb_fi = NULL; + + if (unlikely(flags & TLB_INVALID_MASK)) { + assert(fi->type != ARMFault_None); + fi->s2addr = ptw->out_virt; + fi->stage2 = true; + fi->s1ptw = true; + fi->s1ns = ptw->in_secure; + return 0; + } + + /* In case CAS mismatches and we loop, remember writability. */ + ptw->out_rw = true; + } + +#ifdef CONFIG_ATOMIC64 + if (ptw->out_be) { + old_val = cpu_to_be64(old_val); + new_val = cpu_to_be64(new_val); + cur_val = qatomic_cmpxchg__nocheck((uint64_t *)host, old_val, new_val); + cur_val = be64_to_cpu(cur_val); + } else { + old_val = cpu_to_le64(old_val); + new_val = cpu_to_le64(new_val); + cur_val = qatomic_cmpxchg__nocheck((uint64_t *)host, old_val, new_val); + cur_val = le64_to_cpu(cur_val); + } +#else + /* + * We can't support the full 64-bit atomic cmpxchg on the host. + * Because this is only used for FEAT_HAFDBS, which is only for AA64, + * we know that TCG_OVERSIZED_GUEST is set, which means that we are + * running in round-robin mode and could only race with dma i/o. + */ +#ifndef TCG_OVERSIZED_GUEST +# error "Unexpected configuration" +#endif + bool locked = qemu_mutex_iothread_locked(); + if (!locked) { + qemu_mutex_lock_iothread(); + } + if (ptw->out_be) { + cur_val = ldq_be_p(host); + if (cur_val == old_val) { + stq_be_p(host, new_val); + } + } else { + cur_val = ldq_le_p(host); + if (cur_val == old_val) { + stq_le_p(host, new_val); + } + } + if (!locked) { + qemu_mutex_unlock_iothread(); + } +#endif + + return cur_val; +} + static bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx, uint32_t *table, uint32_t address) { @@ -1079,7 +1182,7 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, uint32_t el = regime_el(env, mmu_idx); uint64_t descaddrmask; bool aarch64 = arm_el_is_aa64(env, el); - uint64_t descriptor; + uint64_t descriptor, new_descriptor; bool nstable; /* TODO: This code does not support shareability levels. */ @@ -1286,7 +1389,9 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, if (fi->type != ARMFault_None) { goto do_fault; } + new_descriptor = descriptor; + restart_atomic_update: if (!(descriptor & 1) || (!(descriptor & 2) && (level == 3))) { /* Invalid, or the Reserved level 3 encoding */ goto do_translation_fault; @@ -1362,10 +1467,18 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, * Here descaddr is the final physical address, and attributes * are all in attrs. */ - if ((attrs & (1 << 10)) == 0) { - /* Access flag */ - fi->type = ARMFault_AccessFlag; - goto do_fault; + if (!(attrs & (1 << 10)) && !ptw->in_debug) { + /* + * Access flag. + * If HA is enabled, prepare to update the descriptor below. + * Otherwise, pass the access fault on to software. + */ + if (param.ha) { + new_descriptor |= 1 << 10; /* AF */ + } else { + fi->type = ARMFault_AccessFlag; + goto do_fault; + } } ap = extract32(attrs, 6, 2); @@ -1381,6 +1494,18 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, result->f.prot = get_S1prot(env, mmu_idx, aarch64, ap, ns, xn, pxn); } + /* If FEAT_HAFDBS has made changes, update the PTE. */ + if (new_descriptor != descriptor) { + new_descriptor = arm_casq_ptw(env, descriptor, new_descriptor, ptw, fi); + if (fi->type != ARMFault_None) { + goto do_fault; + } + if (new_descriptor != descriptor) { + descriptor = new_descriptor; + goto restart_atomic_update; + } + } + if (!(result->f.prot & (1 << access_type))) { fi->type = ARMFault_Permission; goto do_fault; From patchwork Tue Oct 11 03:19:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614161 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2373966pvb; Mon, 10 Oct 2022 20:39:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5s35EXjXsG2q4k5qaEM0JTXMBLJdtCJtVbe7ZmQVlA3bO8XcdoplU5YAGBveOh7NHoGmPu X-Received: by 2002:ac8:7f8e:0:b0:35c:ff82:6290 with SMTP id z14-20020ac87f8e000000b0035cff826290mr17208677qtj.254.1665459552284; Mon, 10 Oct 2022 20:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665459552; cv=none; d=google.com; s=arc-20160816; b=MqDNdiSIBioaLFOp8sGiCZNgl7igbbENOwfKAqQhHXjSoP7OUio16QQJyx3ceErIEu EQ9O6xU5/zt5Pfnn6mOgGvaj8dtQtYsUVIJAUejG4bxlMUKEgqEGzkHrG+D8aVciOE84 Lstjm/g01ssXHmupeBLnSXhmsdkMyU/Z2l9D5wt730Mfgp9wlUMP2CEHIPOiHyrlO2Q6 toBn+RKGYNP+nv5NRrSwD2KjCykWFuxd3eLEK61Y1xn2OE57uPQ4MizzIXZp9JOA3Ad2 zYZiR03nwVOe0GC71kzrXX/wNlZ8cxmNSAwtVo1U3AScIP4sxciCs+Qecwpbf97RopWT P/vQ== 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=VLe0nDHpVS96XvP1AbTdyi1WQJxRc5tYeD+d8MqDnjY=; b=Pb1hhqqWqL/w5k3Xo8RzgACao7tzYUNgNEbKUwg/80CXHeqCx0fh8UlUwgykjoejmx W8YrBYkoU5A1ukODJFm/N6hlZkR/l8Qv8Socxs1Tg0FKg9J41M6JRa763VrsNX7R8fvX 0ozfkhuucAGgBXDOIaF71c5zHnE7zK221xHMHyTLJtL79Bpu+ELPcvVkExh1oCmsKHy1 sdFCybsyiI3MRDIEnj3hPjp26FUziMzr69fiPIFicrtq2iwoqH6NELK6Smv6ym5MFqEX ekGY3L893tLUhX51rw5+kIkCw14nCm4EtiAMHTV/Vch8bVIFmQR8wj3UKBUiDLYrgfA9 cL7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DUdS4FOF; 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 cm20-20020a05622a251400b00393767ebc39si3403712qtb.448.2022.10.10.20.39.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:39:12 -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=DUdS4FOF; 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]:57230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi66p-0000Rl-8C for patch@linaro.org; Mon, 10 Oct 2022 23:39:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5oJ-00038b-S9 for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:20:04 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]:44875) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5oI-00033L-6m for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:20:03 -0400 Received: by mail-pg1-x531.google.com with SMTP id q1so3434417pgl.11 for ; Mon, 10 Oct 2022 20:20:01 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VLe0nDHpVS96XvP1AbTdyi1WQJxRc5tYeD+d8MqDnjY=; b=DUdS4FOFPcPSBGQ6Zv64sPOYcwWK5FwQ7+X6mwkn3IoJpMuXJmxEnIsa05GAJ6dAXK zN1kGmdiaFSTXOp9ddq5/UF2KBF98s3R1HfznuNZwI7tstoEEaQPZ6EMuKxbF2oQjlVX zdR3++MGdd2xmy0i9Wn7+xPA4sNyIIdd4yZucB0XLMKOMCpzNuE0L4pO5IgeJluWvS0K gkHqwSWWuRfgdyl7kbJoNHw4+e1zbNwg3/IloXwPYgZpcZdSswA6RMQHg6Qwyx0c83tu UgczDbRFfj6VqtgYsxTA/Dfci7weFx4K+iV7QgMS/zvkD8D0OAgg17tXiEVb8vUdJvW2 unbw== 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=VLe0nDHpVS96XvP1AbTdyi1WQJxRc5tYeD+d8MqDnjY=; b=ROhPq0TiIiaJTzcsFp/RjdsUGRIntjLSwVkHWDDoc5b63+kjqonZWFEacLaC0rxs8I hRHbaetVlhKVXTNffbuIH93cnG91121//ZjJlrgqzQJYLVLpQZhW0mCbdAZRs0xwb0Hh EFJVfcDR0tJDFsPU2HFpu/M/YI2rEe1pz+u8Fz3AdEJRhzKltdy4ZkHXIQTWf+JKnjJM 9fjPsheTcfhuamq8mzHOynFqSE1mYlECr9O3HPzORzt0K/bcgc6YPG7n2sWXwPI8IXe1 xyH9UmLirPewgqp3yt8L8eM8v98Apiy9Cr5AE0fsXPW+8yY2npOETM2l6vHXOYFZlHKi Ha8Q== X-Gm-Message-State: ACrzQf2k6ZA5qTwJrDHfq6o1urCk+GTtvupqdp++ryuGRy+CLmmEukZ7 /wfd1+uNbmY9xR4gSZUG03VEO7QiY8AZQA== X-Received: by 2002:a65:5801:0:b0:45d:bbd8:e872 with SMTP id g1-20020a655801000000b0045dbbd8e872mr17915832pgr.343.1665458401361; Mon, 10 Oct 2022 20:20:01 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.19.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:20:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v4 23/24] target/arm: Implement FEAT_HAFDBS, dirty bit portion Date: Mon, 10 Oct 2022 20:19:10 -0700 Message-Id: <20221011031911.2408754-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x531.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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Perform the atomic update for hardware management of the dirty bit. Signed-off-by: Richard Henderson --- target/arm/cpu64.c | 2 +- target/arm/ptw.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index fe1369fe96..0732796559 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -1165,7 +1165,7 @@ static void aarch64_max_initfn(Object *obj) cpu->isar.id_aa64mmfr0 = t; t = cpu->isar.id_aa64mmfr1; - t = FIELD_DP64(t, ID_AA64MMFR1, HAFDBS, 1); /* FEAT_HAFDBS, AF only */ + t = FIELD_DP64(t, ID_AA64MMFR1, HAFDBS, 2); /* FEAT_HAFDBS */ t = FIELD_DP64(t, ID_AA64MMFR1, VMIDBITS, 2); /* FEAT_VMID16 */ t = FIELD_DP64(t, ID_AA64MMFR1, VH, 1); /* FEAT_VHE */ t = FIELD_DP64(t, ID_AA64MMFR1, HPDS, 1); /* FEAT_HPDS */ diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 82b6ab029e..0dbbb7d4d4 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1484,10 +1484,30 @@ static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw, ap = extract32(attrs, 6, 2); if (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) { + if (param.hd + && extract64(attrs, 51, 1) /* DBM */ + && access_type == MMU_DATA_STORE) { + /* + * Pre-emptively set S2AP[1], so that we compute EXEC properly. + * C.f. AArch64.S2ApplyOutputPerms, which does the same thing. + */ + ap |= 2; + new_descriptor |= 1ull << 7; + } ns = mmu_idx == ARMMMUIdx_Stage2; xn = extract64(attrs, 54, 2); result->f.prot = get_S2prot(env, ap, xn, s1_is_el0); } else { + if (param.hd + && extract64(attrs, 51, 1) /* DBM */ + && access_type == MMU_DATA_STORE) { + /* + * Pre-emptively clear AP[2], so that we compute EXEC properly. + * C.f. AArch64.S1ApplyOutputPerms, which does the same thing. + */ + ap &= ~2; + new_descriptor &= ~(1ull << 7); + } ns = extract32(attrs, 5, 1); xn = extract64(attrs, 54, 1); pxn = extract64(attrs, 53, 1); From patchwork Tue Oct 11 03:19:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 614166 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2376299pvb; Mon, 10 Oct 2022 20:47:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7fpcVWIxG+oXW6kaXhsW9X3mI+LyDdw/3PMKGIWK2gzgMYMJWkAxyj/z6oe6F7t16JrmI9 X-Received: by 2002:ae9:e895:0:b0:6ee:74f7:d0e6 with SMTP id a143-20020ae9e895000000b006ee74f7d0e6mr2298761qkg.398.1665460028016; Mon, 10 Oct 2022 20:47:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665460028; cv=none; d=google.com; s=arc-20160816; b=Xj9+U9EAZHESq3FxoTMUGcQN5w0aYVv3oLXtQS7ne2Ru14qoU17VVtgQKyCtzd33Or XiYvzRGXiGxAzPd2YFMPAxUJ0GlrdFQqWxb/BQnWR22FBAK62/W/rdXANv1NucMyQuk0 wcUP+W4nETXRFQRyepVMskZ5mwl+4QvOJA3Ie2NE0XVC2plDblsh73xYqFiwzsdXoeyJ 6p94eyWtFmLyHsVrbZMqCoI9iW5klwKbO+ZzOUJEAu7S/9es63TvsPoy59JnI80Zb5b+ WQp/5WHrHE73hIqwncN1+Jcr2hBUU+odY3eP2tPMaYW2z4AlepIW1AKdczv7emsj0XPc YV3A== 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=+7jRVgDoKz3lej+ZaMULQKKS6huX/14P3OCNEftnZ1M=; b=0b42DaiJdTBRED3ucH9l0Dq0Pzo89lFcPAFFwGC2zwhKYq0c0ovwFwx4frhhUioVei v3HSVftbb7o0yW7BjIa0XgJ43ytZhTEMgbbfoPp+KUnQxDZjMkIGgF8r4Jnz6pAf8Y6A 31fo5/8jQF9Pek+ObBTMT44ii4WKy8fO5HM8m2uZDtAY1bZCl+Xk+DH5seaMDtRpgkaM Av9IpSG7WdpgGA9hlrlhd5OZcO+OME/iT7UkEnY6vod1kTIyNrbZRbwYMgpA7NVRCp6I yDdAvnkveRloI301+WSxysdbx05iMRXze6rLQZM2/3gcYzzVPjPUB83i6ofuU7l8sdAz FvSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j4bYr2XK; 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 bq7-20020a05622a1c0700b00342f8bbd9d0si628981qtb.671.2022.10.10.20.47.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Oct 2022 20:47:08 -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=j4bYr2XK; 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]:44106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi6EV-000286-IT for patch@linaro.org; Mon, 10 Oct 2022 23:47:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi5oZ-0003Dd-Sc for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:20:24 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:50722) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oi5oM-0003Lk-BN for qemu-devel@nongnu.org; Mon, 10 Oct 2022 23:20:19 -0400 Received: by mail-pj1-x1036.google.com with SMTP id h12so5625002pjk.0 for ; Mon, 10 Oct 2022 20:20:04 -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:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+7jRVgDoKz3lej+ZaMULQKKS6huX/14P3OCNEftnZ1M=; b=j4bYr2XKuchTNZKteEefZpZt0QG45dJnXRNntSMEGb7Q5dbpJAOqHoUvnNJw4LkK7N VNCYqqQYVPYk95epRH9U4/Ixa2cc4yGg6xJMHGlvXzRIcNWlaVoXeydcMutHYyt4cmnO CNGVBqVjPcmoavwgFjG8FIfaa2uZVYu9FfFMsM9VnC+TOq9zaCYz0PNC340Kuu2LctOU UCEfHXcJgkqPysLi5lfHbyL17y2G2aIKffpIfLaA4ShbROtthk0vxiUQBl7W21vzqIW3 kEEiwkVd1cs3mHptz3oYsDSTa6w8AvoqgGs3FEiWDojv6bUPKadSDDtZpDEOPp9BrGXl sLeg== 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=+7jRVgDoKz3lej+ZaMULQKKS6huX/14P3OCNEftnZ1M=; b=MwP64wZgT2V/VEJMFOJSANVQijlLnxhsPU1RBYCnbk/70YqkUeCniXZBXzinkm2SNy +/d0iQFMdfWVOrG1HfoYBFgMiFD86rE/vMGBxEwRE1ZmYOj8uJ29D/eABl7vVWCIBZHU 7wWdMpxqQXlC81MaE83v/aAjBwN85fjosEMCLhGJKX9f2qxOYVNIh6gLl34/wuLzTW/S 2V8sKtdSUQ3rFeHpCyXgSa+659sqgE+XDxMgMOvQnEv2OdZt3TBYV1842zo6jp41KjVs DShpw8bWdHnQyubHZ3S9noFsplL7E6RgMv464gaZJiIq8cYzSiFYJpOteG4AwC79ssbU 30DA== X-Gm-Message-State: ACrzQf0nxScF9qHt4cI0Q+sFGO18zRqzROsz4L7GmbYL/bbycEDOsgdh fyQaD+XPDWt09AEUamahQjZBL3MkXFUtQw== X-Received: by 2002:a17:902:ab1d:b0:180:4030:757d with SMTP id ik29-20020a170902ab1d00b001804030757dmr18384506plb.155.1665458402989; Mon, 10 Oct 2022 20:20:02 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:5aa4:aba1:1c91:a9b7]) by smtp.gmail.com with ESMTPSA id o74-20020a62cd4d000000b0055f209690c0sm7663567pfg.50.2022.10.10.20.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 20:20:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Marc Zyngier , Peter Maydell Subject: [PATCH v4 24/24] target/arm: Use the max page size in a 2-stage ptw Date: Mon, 10 Oct 2022 20:19:11 -0700 Message-Id: <20221011031911.2408754-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221011031911.2408754-1-richard.henderson@linaro.org> References: <20221011031911.2408754-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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, 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" We had only been reporting the stage2 page size. This causes problems if stage1 is using a larger page size (16k, 2M, etc), but stage2 is using a smaller page size, because cputlb does not set large_page_{addr,mask} properly. Fix by using the max of the two page sizes. Reported-by: Marc Zyngier Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/ptw.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 0dbbb7d4d4..b8934765ec 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -2584,7 +2584,7 @@ static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw, ARMMMUFaultInfo *fi) { hwaddr ipa; - int s1_prot; + int s1_prot, s1_lgpgsz; bool is_secure = ptw->in_secure; bool ret, ipa_secure, s2walk_secure; ARMCacheAttrs cacheattrs1; @@ -2620,6 +2620,7 @@ static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw, * Save the stage1 results so that we may merge prot and cacheattrs later. */ s1_prot = result->f.prot; + s1_lgpgsz = result->f.lg_page_size; cacheattrs1 = result->cacheattrs; memset(result, 0, sizeof(*result)); @@ -2634,6 +2635,14 @@ static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw, return ret; } + /* + * Use the maximum of the S1 & S2 page size, so that invalidation + * of pages > TARGET_PAGE_SIZE works correctly. + */ + if (result->f.lg_page_size < s1_lgpgsz) { + result->f.lg_page_size = s1_lgpgsz; + } + /* Combine the S1 and S2 cache attributes. */ hcr = arm_hcr_el2_eff_secstate(env, is_secure); if (hcr & HCR_DC) {