From patchwork Thu Mar 2 05:50:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13156740 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 1B7F7C6FA8E for ; Thu, 2 Mar 2023 05:52:19 +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:Message-ID: References:Mime-Version: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=Mg4UIbBBFT4iZ/waNJSdinZIcIs4ncmMG5dBhAs+8ds=; b=rjmSE0j6xDqtPolStPm8KCHUZy 76lPxl3Cs2HMzDAh9KXkLZBY6cPzSV7upJirtnnRJa+qij7EHhbwTO8uoqYhBUMll3024BszFppAR nsJ0qmvDkK/5+E/1uXcrT/X+FwtGCLpfA+4YjXvizqX+dj8LU/7XmTxmXu0el/rm6B2AhjB43vA+9 Rj16oIgJzvynSXhvRuPXcpLokMnseHtPwW7hTmYWbPQhTebzjq+gsKDwZWdXqqT1bNphfpxNEoNMC 4ahFE+bHfny4K92acww2AJnLhMpLn50l+JIvrSD2212anckoe4G/4N8xVr9QRNvCN5UPB6Mqr4Tnw usti5/Qg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXbqi-000w8j-Q9; Thu, 02 Mar 2023 05:51:28 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXbqe-000w6Q-Vp for linux-arm-kernel@lists.infradead.org; Thu, 02 Mar 2023 05:51:26 +0000 Received: by mail-yb1-xb49.google.com with SMTP id d7-20020a25adc7000000b00953ffdfbe1aso3046991ybe.23 for ; Wed, 01 Mar 2023 21:51:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hAeigAPYX6PnR/b5lR1z3A0Ou4mZhyXw4iE+Gul5d2w=; b=S1M+msyVuazCZC1jdDkuyZB99/+UoLVYJNPhJKpNeE44O4EuVXwpeh9BnXm61qBeb9 ApoySJ5SBBEcy/KXGkwEeq0SsgXOtPv24dFS8dfs4hEu/GVyxpF0rkDbrhn3MajXaChC MC+9c9RB10yvKep1RFvNhhOF9UI3T6u37HtD9hTwGH/DPMQpgpSm1MMRumJJC3olWXN7 Ch/125Oj7tyI+1HZEP+OLDDxPUNBYg//+JhMCtEedg/mGQ2QvweA4h4Cq4+w6lxsHs/F KCGVJg9WVPz8VneF8B+hhahBoOZfB/yGsUsOzGPiDPNVizsbuLwSVtclrHAtjDUmKRD3 IFWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hAeigAPYX6PnR/b5lR1z3A0Ou4mZhyXw4iE+Gul5d2w=; b=6GHpSks/X8K8HuKdIisE9MQYz0GkMIdVAkjCVOqeOT/7iZI9xRL8vyW/zY1BAx3/c5 bGgr6IobDuOEB3FjxZdXRM2FSRUjlo2SkqmV8bKNmWBqCmEwi4a6i+A5ig3Rjp9Qt5zp iHsahjLtQrVD+N+ii0CoKDfrdMMaQ9YdwKhHLujMEL1ceL9QoaNjH5YLqevH2DJ609ET 5hzoqPemPIOrSisToGKOmu1SkVO9KQsPAGQ50HqC8LMcCXg6SBwXGYFF0FoeuJYc8Ql3 Eo+kFPZzGkGbxzbfu0pfghFPyXqZLNTpzFai1BrLd92wKGWD8ndctHfAxHgjQWqd4b50 VglA== X-Gm-Message-State: AO0yUKWWazq+vATvTGMONJvrmbad195S6u7UHpRMT7W3rk/7+uFg/h9a DqHnIo5IHGYr2HJ4K/js+lbiF68tqu4= X-Google-Smtp-Source: AK7set8SIN82F7pX/7DIs31aOFCLmpZGlyZYmaWI9McxHHG3QjtT/R2ncOCELjAhdRqJsIDoAk0eWd1GuTg= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:9112:0:b0:9fe:1493:8bb with SMTP id v18-20020a259112000000b009fe149308bbmr3722651ybl.13.1677736283390; Wed, 01 Mar 2023 21:51:23 -0800 (PST) Date: Wed, 1 Mar 2023 21:50:33 -0800 In-Reply-To: <20230302055033.3081456-1-reijiw@google.com> Mime-Version: 1.0 References: <20230302055033.3081456-1-reijiw@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230302055033.3081456-3-reijiw@google.com> Subject: [PATCH 2/2] KVM: arm64: PMU: Don't save PMCR_EL0.{C,P} for the vCPU From: Reiji Watanabe To: Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Zenghui Yu , Suzuki K Poulose , Paolo Bonzini , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , Will Deacon , Reiji Watanabe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230301_215125_066709_963E65DA X-CRM114-Status: GOOD ( 13.09 ) 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 Presently, when a guest writes 1 to PMCR_EL0.{C,P}, which is WO/RAZ, KVM saves the register value, including these bits. When userspace reads the register using KVM_GET_ONE_REG, KVM returns the saved register value as it is (the saved value might have these bits set). This could result in userspace setting these bits on the destination during migration. Consequently, KVM may end up resetting the vPMU counter registers (PMCCNTR_EL0 and/or PMEVCNTR_EL0) to zero on the first KVM_RUN after migration. Fix this by not saving those bits when a guest writes 1 to those bits. Signed-off-by: Reiji Watanabe Reviewed-by: Marc Zyngier --- arch/arm64/kvm/pmu-emul.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index 24908400e190..a5a0a9811ddb 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -538,7 +538,9 @@ void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val) if (!kvm_pmu_is_3p5(vcpu)) val &= ~ARMV8_PMU_PMCR_LP; - __vcpu_sys_reg(vcpu, PMCR_EL0) = val; + /* The reset bits don't indicate any state, and shouldn't be saved. */ + __vcpu_sys_reg(vcpu, PMCR_EL0) = + val & ~(ARMV8_PMU_PMCR_C | ARMV8_PMU_PMCR_P); if (val & ARMV8_PMU_PMCR_E) { kvm_pmu_enable_counter_mask(vcpu,