From patchwork Fri Mar 11 04:48:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 12777431 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A50EC433EF for ; Fri, 11 Mar 2022 04:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7EnihVbqNoGiBjxlSZZmlRriKexL8naLux5G5lWy6lI=; b=pFsWj+LaN8nsE1w6Rg77ne0sm5 +rebgc95+Ko729dFiPx7l+xD1LnrcJyLsrxQua/RoYBHb5pHiYkcsjXYuxpKVxXFYKq9W20d9WuhK bomFgFdjfqQ1RNM0KI9fLSKz0BWpBkfYtlHolSizUxPpvPFa04EmjlIKF4ROidGppfZporZWoF0+B kVRQ1AAVkLQi3YI0mPONJja+wX2Dcbtpbp3TVRsAeJxaIdTclDno209J/433n+G10E6dKRSeT7gef wi9SfL5WbSxHCKr6whcBbFE1mhNitCOn1fITbPEOUaEcqktMWkuS4v03MMtVWaNSSg9RavWqOED3u yA4FhZJw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSXKF-00F34L-Is; Fri, 11 Mar 2022 04:56:29 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSXD3-00EzmR-6m for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2022 04:49:03 +0000 Received: by mail-pg1-x549.google.com with SMTP id v8-20020a654608000000b0037d5ef9cfa0so4138887pgq.8 for ; Thu, 10 Mar 2022 20:49:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=1OjK12i8EHB/xwmjswIl10AW6opGSFSXfAnin19ncrs=; b=Tdy0kI2iOENeYBXZpnjdLxKm/NPobNxKkPJR9u/6q42CzYhQZEaE/LQc/5FRsQ3FfG ojeXDADTFgC8S8KFlBe/K02Y6o5Byrfy9ta14+clKCipnKNi/fezer13gf4ZqtnGW79f tQJXvO22EdVEL9lz3gTA5pNvXZ/AlfGLHG3v2+PEtGUFEMU9j/6EvuzOrnK80WvJSmKp S60X842JGTTlJs/1/myvyVspgbxKE+t+CO6r7Ld/qWojdNI2V6fLiCC0iheIfup1T+/7 mlAyd8Y8YOGikoxV4P24cz0jvIL03rl/pI5kltxUzJZVay8x0/qyIY5Uhb3S4/ZJHmw9 VcWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1OjK12i8EHB/xwmjswIl10AW6opGSFSXfAnin19ncrs=; b=6py1tFCJTQdfs0BNQE3eF/V+a22rkEBJujYPCYWMzKzSw4x5VdC+IGOgO5z//hi1m+ D3uPHD7vhGawV0ymZ+eMBBU/1KOiyVMERFQcX0EngPLzk4TTOgDHShgbmUSDPqIut67T DoDbi4duKjmCSP6THkb5WrFzIo7wQqR9ScVf1VgTRYwC1G+E/mVWX8blDDm7bEq6knDl uFzAdEriFukNSST+laZW9GDwpAozTMxIFgb4AMufAibviwda5R74HdNCSd8qmzkkzPOF oV14beYXK46O1X2gXz+Pb5kmrTLnkGuJ7L1j1niVNP91K+nQfbcxes3tHwqfvd2cIZGT dG0g== X-Gm-Message-State: AOAM532SA6tIQmIoFG22HSs16Wqt2TVFmDJPq8wOqPQTLYU+WqQn9RDY mfZf8GgJD0AWKmQHQJvM91PDbTMkSPo= X-Google-Smtp-Source: ABdhPJwcy43pnB6CMBNwp379nzYspjgrnPnrO7sxcJb9fAltkiOVzV8VIs9j+AIeZj6u7qs/OCe8irdFCCg= X-Received: from reiji-vws-sp.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3d59]) (user=reijiw job=sendgmr) by 2002:a17:90b:1e10:b0:1bf:6c78:54a9 with SMTP id pg16-20020a17090b1e1000b001bf6c7854a9mr434960pjb.1.1646974139406; Thu, 10 Mar 2022 20:48:59 -0800 (PST) Date: Thu, 10 Mar 2022 20:48:03 -0800 In-Reply-To: <20220311044811.1980336-1-reijiw@google.com> Message-Id: <20220311044811.1980336-18-reijiw@google.com> Mime-Version: 1.0 References: <20220311044811.1980336-1-reijiw@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v6 17/25] KVM: arm64: Use vcpu->arch.mdcr_el2 to track value of mdcr_el2 From: Reiji Watanabe To: Marc Zyngier , kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Will Deacon , Andrew Jones , Fuad Tabba , Peng Liang , Peter Shier , Ricardo Koller , Oliver Upton , Jing Zhang , Raghavendra Rao Anata , Reiji Watanabe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220310_204901_315464_0A9443B9 X-CRM114-Status: GOOD ( 15.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Track the baseline guest value for mdcr_el2 in struct kvm_vcpu_arch. Use this value when setting mdcr_el2 for the guest. Currently this value is unchanged, but the following patches will set trapping bits based on features supported for the guest. No functional change intended. Signed-off-by: Reiji Watanabe --- arch/arm64/include/asm/kvm_arm.h | 16 ++++++++++++++++ arch/arm64/kvm/arm.c | 1 + arch/arm64/kvm/debug.c | 13 ++++--------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index 8ab6ea038721..4b2ac9e32a36 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -333,6 +333,22 @@ BIT(18) | \ GENMASK(16, 15)) +/* + * The default value for the guest below also clears MDCR_EL2_E2PB_MASK + * and MDCR_EL2_E2TB_MASK to disable guest access to the profiling and + * trace buffers. + */ +#define MDCR_GUEST_FLAGS_DEFAULT \ + (MDCR_EL2_TPM | MDCR_EL2_TPMS | MDCR_EL2_TTRF | \ + MDCR_EL2_TPMCR | MDCR_EL2_TDRA | MDCR_EL2_TDOSA) + +/* Bits that are copied from vcpu->arch.mdcr_el2 to set mdcr_el2 for guest. */ +#define MDCR_GUEST_FLAGS_TRACKED_MASK \ + (MDCR_EL2_TPM | MDCR_EL2_TPMS | MDCR_EL2_TTRF | \ + MDCR_EL2_TPMCR | MDCR_EL2_TDRA | MDCR_EL2_TDOSA | \ + (MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT)) + + /* For compatibility with fault code shared with 32-bit */ #define FSC_FAULT ESR_ELx_FSC_FAULT #define FSC_ACCESS ESR_ELx_FSC_ACCESS diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 7bb744bb23ce..ce7229010a78 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1182,6 +1182,7 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, } vcpu_reset_hcr(vcpu); + vcpu->arch.mdcr_el2 = MDCR_GUEST_FLAGS_DEFAULT; if (has_vhe()) vcpu->arch.cptr_el2 = CPTR_EL2_VHE_GUEST_DEFAULT; else diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c index db9361338b2a..83330968a411 100644 --- a/arch/arm64/kvm/debug.c +++ b/arch/arm64/kvm/debug.c @@ -84,16 +84,11 @@ void kvm_arm_init_debug(void) static void kvm_arm_setup_mdcr_el2(struct kvm_vcpu *vcpu) { /* - * This also clears MDCR_EL2_E2PB_MASK and MDCR_EL2_E2TB_MASK - * to disable guest access to the profiling and trace buffers + * Keep the vcpu->arch.mdcr_el2 bits that are specified by + * MDCR_GUEST_FLAGS_TRACKED_MASK. */ - vcpu->arch.mdcr_el2 = __this_cpu_read(mdcr_el2) & MDCR_EL2_HPMN_MASK; - vcpu->arch.mdcr_el2 |= (MDCR_EL2_TPM | - MDCR_EL2_TPMS | - MDCR_EL2_TTRF | - MDCR_EL2_TPMCR | - MDCR_EL2_TDRA | - MDCR_EL2_TDOSA); + vcpu->arch.mdcr_el2 &= MDCR_GUEST_FLAGS_TRACKED_MASK; + vcpu->arch.mdcr_el2 |= __this_cpu_read(mdcr_el2) & MDCR_EL2_HPMN_MASK; /* Is the VM being debugged by userspace? */ if (vcpu->guest_debug)