From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F39F46426 for ; Fri, 6 Dec 2024 11:24:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733484256; cv=none; b=Y4Eo3EJaqQyIbLAfI3LLMIGC7PUEBtS3juOF79bB7QFuLtIrzNhOQ+288mR2d5hS9m11FWVPXXNOfvayy7Lkjcmg6xbfaS82OuaI1nD63eOnBw/7/95wUfZmppR+r4Nc00qK2wEIwqUgBp/TgLCcmsLWQ15AIQl3tXo+hXoj1IE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733484256; c=relaxed/simple; bh=/V4lUuAdv7MX5Lrr7QpeXYmVCNJ9TEP/8bc8SHaY0Gg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=MvtpzLhBtpnxqVCBZv42lelwPDKGpgng0IldbrCLeDGSiJvKO1WmiY1bevUIt68jevUazs2a16/Y6674LTvkkCVacL/o/qO8XwYG7MLyT7PLz+v/fNR7BIgp1ACVzYhrosVYMVQ6j4YHRwHKgqiPrdWZtiev8VMaT7g/646jSuU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SMtbzGeE; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SMtbzGeE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733484253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lFWn0G2Z/v7JVK2itFan8SiYF0Cp3PsLypgq8Fk6Lqk=; b=SMtbzGeEnDFnUyQsieEkrYvOuhI4lwIF0vqGB0+GOZXYZ3HqrwIrwlHc4xH3tmGxWbi/zi Rl4lYfB+o6mDyjdFoKJJS4arW36CFbY2MKi16MzKZOJ0vW4eSC7zGM1bzczJWcgWDoUiyl OukuGqiYzbiSM+FIX5a8URP/nn+Mvsw= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-145-GdQTn2BbMV65ulZhsKL94A-1; Fri, 06 Dec 2024 06:24:10 -0500 X-MC-Unique: GdQTn2BbMV65ulZhsKL94A-1 X-Mimecast-MFC-AGG-ID: GdQTn2BbMV65ulZhsKL94A Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3686E1955F40; Fri, 6 Dec 2024 11:24:09 +0000 (UTC) Received: from gondolin.str.redhat.com (dhcp-192-244.str.redhat.com [10.33.192.244]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BC7FC19560A2; Fri, 6 Dec 2024 11:24:03 +0000 (UTC) From: Cornelia Huck To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, kvmarm@lists.linux.dev, peter.maydell@linaro.org, richard.henderson@linaro.org, alex.bennee@linaro.org, maz@kernel.org, oliver.upton@linux.dev, sebott@redhat.com, shameerali.kolothum.thodi@huawei.com, armbru@redhat.com, berrange@redhat.com, abologna@redhat.com, jdenemar@redhat.com Cc: shahuang@redhat.com, mark.rutland@arm.com, philmd@linaro.org, pbonzini@redhat.com, Cornelia Huck Subject: [PATCH RFCv2 17/20] arm/kvm: write back modified ID regs to KVM Date: Fri, 6 Dec 2024 12:22:10 +0100 Message-ID: <20241206112213.88394-18-cohuck@redhat.com> In-Reply-To: <20241206112213.88394-1-cohuck@redhat.com> References: <20241206112213.88394-1-cohuck@redhat.com> Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 From: Eric Auger We want to give a chance to override the value of host ID regs. In a previous patch we made sure all their values could be fetched through kvm_get_one_reg() calls before their modification. After their potential modification we need to make sure we write back the values through kvm_set_one_reg() calls. Make sure the cpreg_list is modified with updated values and transfer those values back to kvm. Signed-off-by: Eric Auger Signed-off-by: Cornelia Huck --- target/arm/kvm.c | 36 +++++++++++++++++++++++++++++++++++- target/arm/trace-events | 1 + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 4bb8094e846f..3b2f98041484 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -1061,6 +1061,31 @@ void kvm_arm_cpu_post_load(ARMCPU *cpu) } } +static void kvm_arm_writable_idregs_to_cpreg_list(ARMCPU *cpu) +{ + for (int i = 0; i < NR_ID_REGS; i++) { + uint64_t writable_mask = cpu->writable_map->regs[i]; + uint64_t *cpreg; + + if (writable_mask) { + uint64_t regidx; + uint64_t previous, new; + ARM64SysReg *sysregdesc = &arm64_id_regs[i]; + ARMSysReg *sr = sysregdesc->sysreg; + + regidx = ARM64_SYS_REG(sr->op0, sr->op1, sr->crn, sr->crm, sr->op2); + cpreg = kvm_arm_get_cpreg_ptr(cpu, regidx); + previous = *cpreg; + new = cpu->isar.idregs.regs[i]; + if (previous != new) { + *cpreg = new; + trace_kvm_arm_writable_idregs_to_cpreg_list(sysregdesc->name, + previous, new); + } + } + } +} + void kvm_arm_reset_vcpu(ARMCPU *cpu) { int ret; @@ -2028,7 +2053,16 @@ int kvm_arch_init_vcpu(CPUState *cs) } cpu->mp_affinity = mpidr & ARM64_AFFINITY_MASK; - return kvm_arm_init_cpreg_list(cpu); + ret = kvm_arm_init_cpreg_list(cpu); + if (ret) { + return ret; + } + /* overwrite writable ID regs with their updated property values */ + kvm_arm_writable_idregs_to_cpreg_list(cpu); + + write_list_to_kvmstate(cpu, 3); + + return 0; } int kvm_arch_destroy_vcpu(CPUState *cs) diff --git a/target/arm/trace-events b/target/arm/trace-events index 0df3bfafffcc..668acf94ab60 100644 --- a/target/arm/trace-events +++ b/target/arm/trace-events @@ -14,3 +14,4 @@ arm_gt_update_irq(int timer, int irqstate) "gt_update_irq: timer %d irqstate %d" # kvm.c kvm_arm_fixup_msi_route(uint64_t iova, uint64_t gpa) "MSI iova = 0x%"PRIx64" is translated into 0x%"PRIx64 get_host_cpu_idregs(const char *name, uint64_t value) "scratch vcpu gost value for %s is 0x%"PRIx64 +kvm_arm_writable_idregs_to_cpreg_list(const char *name, uint64_t previous, uint64_t new) "%s overwrite default 0x%"PRIx64" with 0x%"PRIx64 -- 2.47.0