From patchwork Tue Feb 27 11:33:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10244885 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 05B5660208 for ; Tue, 27 Feb 2018 11:36:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED27028843 for ; Tue, 27 Feb 2018 11:36:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1DF428848; Tue, 27 Feb 2018 11:36:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6177928843 for ; Tue, 27 Feb 2018 11:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=HZ45DE4hnr383S+sCMWiy8eYn+sWmssfIHQL3w3l95s=; b=uSRykROBPyNUiUv39Mknrt8wr7 Tft6N1+Jv9e8aRZJvhSGFhCerPeDTa34et75Y3oPZa9ztMlnzPVM51JCync1j/0plH5KHzeXpDLf3 YHCVuTMXXWNPZqda+ZSuXgRWUYfLFsJxABFY8QkdGbiybtQ8o1glkLy0c0djXA+E9/2H4kpwN0DVe UkOJr5Dp80x4b47hRaYoeNHk4ri3EY9ACZIbnh5W6kpVEWZjHIZnQzf3y5VXsV14k+k3HWBu8yizl 9H9PJv0OUo2Vj0qi2+53fzu30zZ4Rz/dSIfvEoqPFkHBy3C9JyVh6lSbKKc2R8Dcs1sbHgqb9FBMO q1S22JXw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eqdY4-0008R8-I3; Tue, 27 Feb 2018 11:35:56 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqdWv-0006Ve-JZ for linux-arm-kernel@lists.infradead.org; Tue, 27 Feb 2018 11:34:51 +0000 Received: by mail-wm0-x243.google.com with SMTP id h21so23398497wmd.1 for ; Tue, 27 Feb 2018 03:34:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=QCByNYUslTdKwE7kdgWLnsD6SwxCwsL1px9ckz61hJw=; b=mN/8f2dy5ZHDxXL9U4LF+sZP+hHU/7BcglonX+e0mlYAV3uZ8p/+OOwkIjzPw/8VZQ DmVzxsOMcbwD1SmZdBYgu9CuUMiqHmJSZ2Kn8IrVBTeR0Nl+lwe4Wks2xJC1k6AzZbWZ KjOQ9US4OFeUT1dSkyPbZORYgMCf4Jabvd5M2wQhc48LbfPzN05X/lW+olAvqOAA/JqM p7cofoQovJ3PyFFSql0huzzTTdUX/ooj1l/pEm12IkKaUkGZYmzNgltLSRydqzLeUfCS V2/HGA8f5zC8K1iVyaHvWzDyaMa70FZgvR9iazBcNmjmg5E3pERe20z7Y5SBvHnrMOUs u1rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=QCByNYUslTdKwE7kdgWLnsD6SwxCwsL1px9ckz61hJw=; b=VHy+BmUsVZm9LqrSAtbbozENOux49vMNITK/VNF+xrvFlhhUo4pcrJ2hA2ocboGa5e W8+MfwigRYB/RL5j3W6FVviI57GTw+47sriI4U3e9mGatf+XYIwcSlxv2ebsJx1GD5b4 HbPzo4etgd8pqEduh6yxClv2ziNZn6rU4ds0lxbc1JlM74JtQqLo6Rg74gEJFzjIhyBZ 2cYi6MhBRqmA6QoRWX5KrgYoj98pD9rCuBwvUT1swN3XqucrhJ+egpKQiDGw9zNNMvkW wMXJYc3PYwLShBIb/mS0gC6x+Gqnu9HK1P7VnLYejL5ursiaVRNhVlJC8d6kiS4l3sqf awLA== X-Gm-Message-State: APf1xPACsK/60FAQ5XZ+gBdsEtn75vHrq++ZBFvIgmz3MeoEdrautY0i 8yKH/cuE8q3HhVNPKM7uLSiyUw== X-Google-Smtp-Source: AG47ELutUyHAFRMQKu3HYrSadFO3yLpmNkt0Fyl4xEdyx2vbxqn+TS+a4Tr3hAxXQwOECLaQ8rH3WQ== X-Received: by 10.80.182.71 with SMTP id c7mr2752071ede.57.1519731273429; Tue, 27 Feb 2018 03:34:33 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id m1sm9176786ede.39.2018.02.27.03.34.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 03:34:32 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 01/40] KVM: arm/arm64: Avoid vcpu_load for other vcpu ioctls than KVM_RUN Date: Tue, 27 Feb 2018 12:33:50 +0100 Message-Id: <20180227113429.637-2-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180227113429.637-1-cdall@kernel.org> References: <20180227113429.637-1-cdall@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180227_033445_849851_F8FD37F0 X-CRM114-Status: GOOD ( 14.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jones , kvm@vger.kernel.org, Marc Zyngier , Tomasz Nowicki , Julien Grall , Yury Norov , Dave Martin , Shih-Wei Li MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christoffer Dall Calling vcpu_load() registers preempt notifiers for this vcpu and calls kvm_arch_vcpu_load(). The latter will soon be doing a lot of heavy lifting on arm/arm64 and will try to do things such as enabling the virtual timer and setting us up to handle interrupts from the timer hardware. Loading state onto hardware registers and enabling hardware to signal interrupts can be problematic when we're not actually about to run the VCPU, because it makes it difficult to establish the right context when handling interrupts from the timer, and it makes the register access code difficult to reason about. Luckily, now when we call vcpu_load in each ioctl implementation, we can simply remove the call from the non-KVM_RUN vcpu ioctls, and our kvm_arch_vcpu_load() is only used for loading vcpu content to the physical CPU when we're actually going to run the vcpu. Reviewed-by: Julien Grall Reviewed-by: Marc Zyngier Reviewed-by: Andrew Jones Signed-off-by: Christoffer Dall --- arch/arm64/kvm/guest.c | 3 --- virt/kvm/arm/arm.c | 9 --------- 2 files changed, 12 deletions(-) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index d7e3299a7734..959e50d2588c 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -363,8 +363,6 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, { int ret = 0; - vcpu_load(vcpu); - trace_kvm_set_guest_debug(vcpu, dbg->control); if (dbg->control & ~KVM_GUESTDBG_VALID_MASK) { @@ -386,7 +384,6 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, } out: - vcpu_put(vcpu); return ret; } diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index 86941f6181bb..53572304843b 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -384,14 +384,11 @@ static void vcpu_power_off(struct kvm_vcpu *vcpu) int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, struct kvm_mp_state *mp_state) { - vcpu_load(vcpu); - if (vcpu->arch.power_off) mp_state->mp_state = KVM_MP_STATE_STOPPED; else mp_state->mp_state = KVM_MP_STATE_RUNNABLE; - vcpu_put(vcpu); return 0; } @@ -400,8 +397,6 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, { int ret = 0; - vcpu_load(vcpu); - switch (mp_state->mp_state) { case KVM_MP_STATE_RUNNABLE: vcpu->arch.power_off = false; @@ -413,7 +408,6 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, ret = -EINVAL; } - vcpu_put(vcpu); return ret; } @@ -1036,8 +1030,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp, struct kvm_device_attr attr; long r; - vcpu_load(vcpu); - switch (ioctl) { case KVM_ARM_VCPU_INIT: { struct kvm_vcpu_init init; @@ -1114,7 +1106,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp, r = -EINVAL; } - vcpu_put(vcpu); return r; }