From patchwork Fri Mar 11 17:57:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12778502 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 18906C433F5 for ; Fri, 11 Mar 2022 17:59:30 +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=pbNUTtV9hKu+6nUxJl2AdkGbEQLOrYc6+B9/1sCPAPk=; b=FBzIK5tNBCFzEDXfCMXFygu7Jw A8QkhOZBCo5bsSxlnWelJymsyQC9zFSwhs2/3FOqmmDBOPLIYUolTozG6fAy0zSuHP0hi/lkOrMiP 3w+Gn0ZGy+h56VyrvcK/brInCblOglKyhwfv28YM0ROpGmnxsUADW3WZN1VrtspYa6WZGzWADUbO8 +XCzysq2Rxp5DqEh9MHcP22hkjeeGQYIIE3YiqLJ6zHp5KxN79Khq74iU5oxx3PCfvYheHUstiMfm xXBNaiw8Sw3RUnJwOs14M25KYN095i/zz9lO5Wu7p3GJ4FCBE1W6MvI9YBxVbbmmhasb65feSaOCu znCiC/NA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjWy-00HYat-6S; Fri, 11 Mar 2022 17:58:24 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSjWM-00HYJ5-8G for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2022 17:57:47 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2d726bd83a2so74672277b3.20 for ; Fri, 11 Mar 2022 09:57:45 -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=iMUX4p8oYYdLskY6YlQfUR43FNfUoWfkZJK4wIrDvVI=; b=kbWvR7NSwT//jyD2uA/WkBGtSra3OAWNZLtQDDPfNKfREZh2jH89JBDrkrpTgQ+YNv BUozf2+Uo6ONunKNVgwoR5E9m7HxiNyKMvg/WGnR+sSX0XuH3X6nfPaGNxi3vJ37o/lM d+e2mKjeL9oPXKYywZpE/b7Xl/51yZO7v1R8Wc8yzsnBcH7u1/IxQKScxbUdOYyJ2EmK LOX+JHVm4kFAdEXVqPovN8vrY7fDTjstsHEv/kIjboyaWqWt/BP/PCBTiUiUXfkaA2m/ FTSD1xnG8bA32t2Mx3cnmlZRYON6s8EvQNUCszZAool1frje4oMd6fFK+SEr9nABWojl +9xQ== 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=iMUX4p8oYYdLskY6YlQfUR43FNfUoWfkZJK4wIrDvVI=; b=sdMAM98SolcKwxFLCydW/mtgciE+rKyPYOZDSLOgjk2RVCm/AhWRJzFsNVXzE6Nfih tMrwCK7C3DKRxrTKNOIn7/jAUMWd8pw3qZYdrtLnGE0qjSb+DTqMzWB2isBP6nLhKvSq UfUQ3dGRmInZkUnvAzu+OuyLYVfFTgSMD0pHTuvnld3zTIkQaCGf9tNbP9EHs74FAKO5 jAhrLCbKxBae85sF1VXepPMyB1aVPQfanYHwNCoSt+kYsWI0hVSkNRU07prBmxEmF5Ok EvrwxtDKA58qAfMmaQ/zhhrwkHO16eBhnGd3B4DGs/j3vqs/N8Yk91b7f8i+CBTyz93r z0cg== X-Gm-Message-State: AOAM530HwBrmB7JBPlCRIycK57xGrv2BTnA/nuXn6gez+D+1TZ/JZfZl Ct0AHN6nxyau6Ys9vwx9XMMxrNWfFS4= X-Google-Smtp-Source: ABdhPJzPRbWq+blf3W5J139AGKxE7e6TJnEjyAP/74A7vawiP9FcCu7oAu7fi1c5ZnCuQttujGbnOdDK+/Y= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a81:d847:0:b0:2d8:1c55:942a with SMTP id n7-20020a81d847000000b002d81c55942amr9375589ywl.260.1647021464480; Fri, 11 Mar 2022 09:57:44 -0800 (PST) Date: Fri, 11 Mar 2022 17:57:16 +0000 In-Reply-To: <20220311175717.616958-1-oupton@google.com> Message-Id: <20220311175717.616958-5-oupton@google.com> Mime-Version: 1.0 References: <20220311174001.605719-1-oupton@google.com> <20220311175717.616958-1-oupton@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [RFC PATCH kvmtool 4/5] ARM: Add a helper to re-init a vCPU From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Peter Shier , Ricardo Koller , Reiji Watanabe , Will Deacon , Julien Thierry , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220311_095746_320704_49389092 X-CRM114-Status: GOOD ( 12.02 ) 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 Create a helper that can be called to reinitialize a particular vCPU, or in other words issue the KVM_ARM_VCPU_INIT and KVM_ARM_VCPU_FINALIZE ioctls accordingly. Make use of the helper from kvm_cpu__arch_init() after the correct target/feature set have been identified. Calling KVM_ARM_VCPU_INIT with the same target more than once is benign. Signed-off-by: Oliver Upton --- arm/kvm-cpu.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c index 1ea56bb..164e399 100644 --- a/arm/kvm-cpu.c +++ b/arm/kvm-cpu.c @@ -35,6 +35,15 @@ int kvm_cpu__register_kvm_arm_target(struct kvm_arm_target *target) return -ENOSPC; } +static void kvm_cpu__arch_reinit(struct kvm_cpu *vcpu) +{ + if (ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu->init) < 0) + die("KVM_ARM_VCPU_INIT failed"); + + if (kvm_cpu__configure_features(vcpu)) + die("Unable to configure requested vcpu features"); +} + struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) { struct kvm_arm_target *target; @@ -132,8 +141,7 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) vcpu->cpu_compatible = target->compatible; vcpu->is_running = true; - if (kvm_cpu__configure_features(vcpu)) - die("Unable to configure requested vcpu features"); + kvm_cpu__arch_reinit(vcpu); return vcpu; }