From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 2002:a05:6512:3aa:0:0:0:0 with SMTP id v10csp2204960lfp; Fri, 14 Feb 2020 09:58:31 -0800 (PST) X-Google-Smtp-Source: APXvYqy9xsl1Ni7vgSq+NMD0y6RLaTcFg2Otzvpvtn7MW+TzVOYdCyVF1j15Zx4U3+fzEVRCk3cD X-Received: by 2002:a0c:8d0a:: with SMTP id r10mr3072293qvb.7.1581703111793; Fri, 14 Feb 2020 09:58:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581703111; cv=none; d=google.com; s=arc-20160816; b=FTA5uiGh2vNzwFd3UsnedLEpKdYKdAHTnuLlxQOFB18nq65u5KaSU1VUUBLg2Mzf7V 2AJh4p6tUV9qHoaEVleMZkfkjhvGaOoBBvSGq81hWLeHhfy3fJVIM51E6xiRgv32cm+O CdtcX/uX9Pf3xx+LSGauAAiIAJwtq0EBkQ/uoWlNNI+hBQpelI8FNztFYk2xifYGSqHX I50kEBxVPhX5y2l4zzdxXQvTMYzEsHhxRsfLnP5IE9nHdUEv4wJYBMHGVWXqKI2MBUvK pcvvYNRlfM2jNtt4rtDfIdauekCmQDQZ/hH9axbzB4g0m57ETzlPJJS6zgHgddFfC/Jv 0xHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=xVgyB/ZnMXDEzGcspXK1d/y3x9zIzwGPMhddTki8nJw=; b=SsaYCOkqDhz0zGHN6jKJ0WhMaT+jS6sf+49PP0qidr2HexQiHLDsbVWY3Xz0MWlULe 5P0xFl69C9md5jCNL4xRE+7APIGOSqfdtJljTbvqfV/rSWRRiL39DNp6wUtqmG6oAADk biMVvdDsm89xtMuYN7AWx4Nu5xjz/TE5Aq2vKsK01VppTQrPgPaw8+2bDEhZ3F2BFoPB BabSh4VmGtXxDBVu/L+RQdwSabm5IJjpyl+JDGEae0g3Q0aNleYJ/a7lmXHcWIJK7a/h hZyFBMliiwWNcvF2+y48EGIYPa07YTcAur9U5ybaVIkWYY4Cxr2qGq6fgP2h9mDiSUGb U7TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wMB5gPIe; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (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 l90si3014287qtd.153.2020.02.14.09.58.31 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Feb 2020 09:58:31 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wMB5gPIe; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2fEV-00030N-7L for alex.bennee@linaro.org; Fri, 14 Feb 2020 12:58:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56134) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2f7t-0005zY-IV for qemu-devel@nongnu.org; Fri, 14 Feb 2020 12:51:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2f7s-0000tJ-5p for qemu-devel@nongnu.org; Fri, 14 Feb 2020 12:51:41 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:51700) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j2f7r-0000qT-BZ for qemu-devel@nongnu.org; Fri, 14 Feb 2020 12:51:39 -0500 Received: by mail-wm1-x344.google.com with SMTP id t23so10844421wmi.1 for ; Fri, 14 Feb 2020 09:51:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xVgyB/ZnMXDEzGcspXK1d/y3x9zIzwGPMhddTki8nJw=; b=wMB5gPIeIBSbzlWph6ShtV/PNXzq8bXUx0A7jxEzpExrFvZHZ75yikbukDUu2FgTeB Yte4fS0s+KULHfzRy+GZeD0kmUdCvUn/HSqgevlg28BrSUaIaTj64IoAUxuN38aMvJfT wluZ9eeBOXLw0HdjzhFVtlmurvUjfFUUH+u7x0SH0Ve5oH91tJsPY6423qebavtL85p7 eEiO4OjEwKXxwLCbLuxlmoibYf4yhQJSVIJ+NSD+h0P2u+gAAnw8pLI9VPi/XOmKNOwp 0psbaZ7mxhR/3THr39f6NQjF39kvnMq9/MYo68ERpOGmj1SO53cHr7r8gHuGsv5wAJ9g 6EDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xVgyB/ZnMXDEzGcspXK1d/y3x9zIzwGPMhddTki8nJw=; b=fUnmuG9oprKGrRfqsjia2vimw6WmMg4iC3FC3mBYw8uf6T/CJW96slS3cU0I5ZEhKV ORfkwVpGnvt85DnIRh7FNRqfZj1sDUBRD+u2yxRSlknrF0PgJ0Q7QqLdnTzO85Ki85WZ fhPPZjXYj2vGCeeCAfbBaEw8EU8thSoDbF/qux0b2PwG7UFBteZDbaV8P0pyJbEhHBXI Vj5qjNzGOXkrR5U8NwbWABQulM6L/fHDgsRiJHgBT5Rdxu9KJfKNu9nJXemj6fje31Xg XY6lHDgjrg+pKozFu1ijP7K07rLu+EbABjVRFoKDfzhgHKEk18EE3PEvrXvgDZNSikx3 I8bA== X-Gm-Message-State: APjAAAX1QVnXeQNGC0BT/AsKskmWete4q/DI2BdNNp9BStTexrGJyQmy EXrJduroZGeDRKTIWqvQFw0UJogCMj0= X-Received: by 2002:a1c:6645:: with SMTP id a66mr6124713wmc.121.1581702696443; Fri, 14 Feb 2020 09:51:36 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id v8sm8001857wrw.2.2020.02.14.09.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 09:51:35 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 12/21] target/arm: Read debug-related ID registers from KVM Date: Fri, 14 Feb 2020 17:51:07 +0000 Message-Id: <20200214175116.9164-13-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214175116.9164-1-peter.maydell@linaro.org> References: <20200214175116.9164-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eric Auger , Aaron Lindsay , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-devel" X-TUID: T+L1XiqpIEEG Now we have isar_feature test functions that look at fields in the ID_AA64DFR0_EL1 and ID_DFR0 ID registers, add the code that reads these register values from KVM so that the checks behave correctly when we're using KVM. No isar_feature function tests ID_AA64DFR1_EL1 or DBGDIDR yet, but we add it to maintain the invariant that every field in the ARMISARegisters struct is populated for a KVM CPU and can be relied on. This requirement isn't actually written down yet, so add a note to the relevant comment. Signed-off-by: Peter Maydell --- target/arm/cpu.h | 5 +++++ target/arm/kvm32.c | 8 ++++++++ target/arm/kvm64.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 3c996db3e45..e043932fcb1 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -853,6 +853,11 @@ struct ARMCPU { * prefix means a constant register. * Some of these registers are split out into a substructure that * is shared with the translators to control the ISA. + * + * Note that if you add an ID register to the ARMISARegisters struct + * you need to also update the 32-bit and 64-bit versions of the + * kvm_arm_get_host_cpu_features() function to correctly populate the + * field by reading the value from the KVM vCPU. */ struct ARMISARegisters { uint32_t id_isar0; diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c index 3a8b437eef0..bca02553b25 100644 --- a/target/arm/kvm32.c +++ b/target/arm/kvm32.c @@ -97,6 +97,9 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) ahcf->isar.id_isar6 = 0; } + err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_dfr0, + ARM_CP15_REG32(0, 0, 1, 2)); + err |= read_sys_reg32(fdarray[2], &ahcf->isar.mvfr0, KVM_REG_ARM | KVM_REG_SIZE_U32 | KVM_REG_ARM_VFP | KVM_REG_ARM_VFP_MVFR0); @@ -108,6 +111,11 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) * Fortunately there is not yet anything in there that affects migration. */ + /* + * There is no way to read DBGDIDR, because currently 32-bit KVM + * doesn't implement debug at all. Leave it at zero. + */ + kvm_arm_destroy_scratch_host_vcpu(fdarray); if (err < 0) { diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index 3bae9e4a663..527532f2b37 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -541,6 +541,10 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) } else { err |= read_sys_reg64(fdarray[2], &ahcf->isar.id_aa64pfr1, ARM64_SYS_REG(3, 0, 0, 4, 1)); + err |= read_sys_reg64(fdarray[2], &ahcf->isar.id_aa64dfr0, + ARM64_SYS_REG(3, 0, 0, 5, 0)); + err |= read_sys_reg64(fdarray[2], &ahcf->isar.id_aa64dfr1, + ARM64_SYS_REG(3, 0, 0, 5, 1)); err |= read_sys_reg64(fdarray[2], &ahcf->isar.id_aa64isar0, ARM64_SYS_REG(3, 0, 0, 6, 0)); err |= read_sys_reg64(fdarray[2], &ahcf->isar.id_aa64isar1, @@ -559,6 +563,8 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) * than skipping the reads and leaving 0, as we must avoid * considering the values in every case. */ + err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_dfr0, + ARM64_SYS_REG(3, 0, 0, 1, 2)); err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_isar0, ARM64_SYS_REG(3, 0, 0, 2, 0)); err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_isar1, @@ -580,6 +586,36 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) ARM64_SYS_REG(3, 0, 0, 3, 1)); err |= read_sys_reg32(fdarray[2], &ahcf->isar.mvfr2, ARM64_SYS_REG(3, 0, 0, 3, 2)); + + /* + * DBGDIDR is a bit complicated because the kernel doesn't + * provide an accessor for it in 64-bit mode, which is what this + * scratch VM is in, and there's no architected "64-bit sysreg + * which reads the same as the 32-bit register" the way there is + * for other ID registers. Instead we synthesize a value from the + * AArch64 ID_AA64DFR0, the same way the kernel code in + * arch/arm64/kvm/sys_regs.c:trap_dbgidr() does. + * We only do this if the CPU supports AArch32 at EL1. + */ + if (FIELD_EX32(ahcf->isar.id_aa64pfr0, ID_AA64PFR0, EL1) >= 2) { + int wrps = FIELD_EX64(ahcf->isar.id_aa64dfr0, ID_AA64DFR0, WRPS); + int brps = FIELD_EX64(ahcf->isar.id_aa64dfr0, ID_AA64DFR0, BRPS); + int ctx_cmps = + FIELD_EX64(ahcf->isar.id_aa64dfr0, ID_AA64DFR0, CTX_CMPS); + int version = 6; /* ARMv8 debug architecture */ + bool has_el3 = + !!FIELD_EX32(ahcf->isar.id_aa64pfr0, ID_AA64PFR0, EL3); + uint32_t dbgdidr = 0; + + dbgdidr = FIELD_DP32(dbgdidr, DBGDIDR, WRPS, wrps); + dbgdidr = FIELD_DP32(dbgdidr, DBGDIDR, BRPS, brps); + dbgdidr = FIELD_DP32(dbgdidr, DBGDIDR, CTX_CMPS, ctx_cmps); + dbgdidr = FIELD_DP32(dbgdidr, DBGDIDR, VERSION, version); + dbgdidr = FIELD_DP32(dbgdidr, DBGDIDR, NSUHD_IMP, has_el3); + dbgdidr = FIELD_DP32(dbgdidr, DBGDIDR, SE_IMP, has_el3); + dbgdidr |= (1 << 16); /* RES1 bit */ + ahcf->isar.dbgdidr = dbgdidr; + } } sve_supported = ioctl(fdarray[0], KVM_CHECK_EXTENSION, KVM_CAP_ARM_SVE) > 0; -- 2.20.1