From patchwork Thu Feb 24 17:25:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759072 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 80C92C433F5 for ; Thu, 24 Feb 2022 17:29:00 +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=+YHzzGK7Dd/I/wtVGweA+y0o3Gq38jsjkFgxQAjep6Y=; b=gtP1tcvzStTY3Sgl02M7TZlRHh sl9zJd86DBJM7BD6giPi9z3i74lN4lJ5+5XXbmMG8yk0Yw/6BjPmhiwB+pISCl/KATa5n+sz1Feie LSNzDH6f3SFj1VjiFvo4WEm7UZgxC5WHUTzS/FrgYNuOEv+aouih/7wzPSl1hR4Pv0RuYg2LCElei S45vMSrJbd9DygjFo1garEidth6cS0NnxT2RsDWAt1MngWlLaMguG8Xr0XuphnZ1e+IEsiukqrxv0 MmIxdcYwfwedEyJix0D9S6BVifE2WgvBVggWg/UcR1O2Mh97GL5Wsr/lTEGD0h3br/Sf+OHRXwjOk HeWl/i9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHtx-001mj0-Rd; Thu, 24 Feb 2022 17:27:38 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsf-001m9w-MW for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:22 +0000 Received: by mail-pg1-x54a.google.com with SMTP id bj8-20020a056a02018800b0035ec8c16f0bso1415670pgb.11 for ; Thu, 24 Feb 2022 09:26:15 -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=OsZB1WQ6lcTDQc8TII8Z2w2H891AEk6o7uXrnU60Sz4=; b=n/F4ja1wwLJBW/ijXvomC0vFaa1Gbh0XTIQ72X/rtTtlaWrnWJVjVDVQnw0Chugj0j s8eGLxLruJTXlJ3udhRPkErT9dlaCCvq+4Pc/4AyP6fslw5wApjjMzXxR5JolWEo3Uhn /xF8xB+oMyZoF8zM+m9Y3UAvlg9Q5fezULZ3Z37nGxzJzBcGlg2zHbru5rcSqCNNtg96 iSGxIhYOowJ4KOjg8isnidQLFfTqDemO76gaoctt3D7t2fR4oP7+MifAHi8KKPk6R9uU ke+J+3OxaxPspS1mFy6prNU6GZzF3ophbL5sU3A7T9zPgk19vFCo7IozP+KWOWWnuJ5v YFJQ== 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=OsZB1WQ6lcTDQc8TII8Z2w2H891AEk6o7uXrnU60Sz4=; b=THsHQEMNbPFkBFZtJOslSOiPzyFvARFf1eOiYqEBVk1D2BZ4vf9zqTVOJV5MIOaZSw WNUa9LUWvtiKIZv4phvmYitz1edy43li1sXikRFvRHvlsdia2m8TVaI340cj6rbhy9/6 +HqcM+9L7HX7Z4FtbKlzGBabueibMauNnbrkItefEHkOghNJnCtTKdKhOmwluPLRx/lw BBrSbBqVxavmI9aJ3HC7quIS8FmZnQyvuG1bjNgmzOwmmDt7NasDGB7GX3A7CrCg5lqv Ce0C8pN3en+svuYGzyIv8ILm9RTc9/wl9AxS3yq6LteAO/jONZ6hJTPgtvLp5pFnozvR DVYw== X-Gm-Message-State: AOAM531TyG5FypJCDbpsFSzcjkyfAQOTztflToX1uoesbJbxc/JznREL 6bQmMA/fSKCnWDwapliB4j7DsavKoICZ X-Google-Smtp-Source: ABdhPJwNVZA2Yo1/QQAgM2dA9o//8LsSbVv/DS6uJksGu0XtYEWfniXtgFLtkwUsjMzINEE1xgsyTvGjlEWP X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:90a:2c0c:b0:1b9:fa47:1caf with SMTP id m12-20020a17090a2c0c00b001b9fa471cafmr3880202pjd.34.1645723575490; Thu, 24 Feb 2022 09:26:15 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:50 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-5-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 04/13] KVM: arm64: Capture VM's first run From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092617_775932_11C19EBB X-CRM114-Status: GOOD ( 11.75 ) 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 Capture the first run of the KVM VM, which is basically the first KVM_RUN issued for any vCPU. This state of the VM is helpful in the upcoming patches to prevent user-space from configuring certain VM features, such as the feature bitmap exposed by the psuedo-firmware registers, after the VM has started running. Signed-off-by: Raghavendra Rao Ananta --- arch/arm64/include/asm/kvm_host.h | 9 +++++++++ arch/arm64/kvm/arm.c | 2 ++ 2 files changed, 11 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 657733554d98..e823571e50cc 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -139,6 +139,9 @@ struct kvm_arch { /* Register scoping enabled for KVM registers */ bool reg_scope_enabled; + + /* Capture first run of the VM */ + bool has_run_once; }; struct kvm_vcpu_fault_info { @@ -796,6 +799,12 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu); int kvm_trng_call(struct kvm_vcpu *vcpu); int kvm_arm_reg_id_encode_scope(struct kvm_vcpu *vcpu, u64 *reg_id); void kvm_arm_reg_id_clear_scope(struct kvm_vcpu *vcpu, u64 *reg_id); + +static inline bool kvm_arm_vm_has_run_once(struct kvm_arch *kvm_arch) +{ + return kvm_arch->has_run_once; +} + #ifdef CONFIG_KVM extern phys_addr_t hyp_mem_base; extern phys_addr_t hyp_mem_size; diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 107977c82c6c..f61cd8d57eae 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -635,6 +635,8 @@ int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu) if (kvm_vm_is_protected(kvm)) kvm_call_hyp_nvhe(__pkvm_vcpu_init_traps, vcpu); + kvm->arch.has_run_once = true; + return ret; }