From patchwork Mon Dec 4 20:35:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10091479 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 57FA860327 for ; Mon, 4 Dec 2017 20:36:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BBF6290AA for ; Mon, 4 Dec 2017 20:36:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40A28293F1; Mon, 4 Dec 2017 20:36:31 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA4C0290AA for ; Mon, 4 Dec 2017 20:36:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752711AbdLDUg2 (ORCPT ); Mon, 4 Dec 2017 15:36:28 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:40217 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752500AbdLDUgL (ORCPT ); Mon, 4 Dec 2017 15:36:11 -0500 Received: by mail-wm0-f65.google.com with SMTP id f206so10420419wmf.5 for ; Mon, 04 Dec 2017 12:36:10 -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=ZmUolxszHLEISu3ZCcad6hveUOgpZrBDUcufGrh29MM=; b=BWZOtAiw74nC4Aw7zNCxXliCOmljsMPrESGG+AliK4NGWRgCEbrBagi5kGShWhauXb +NgATAcrJP7plzBT+9aw6u+bx1qUHmV9GMa8oalViIaYnCMOAi5KH80gAZ3ShBCr/NPw 6kLd4gfzEy/shZEl4MfSw5/tNCeOAQmGiBhxnEzCaJ6yeTBC2JWg6yTFn7qo0aCTW/lO urfOVp3IZ1zjKgZWTer0S3jcRdNh5RJoIMWuDHtTlmDb3gv0J1kW091YArl/jULfLxMI pH+k4XVk0K17wPQpB6Qio1iXRBrHDfVThdQYrXaaPKGINsmbwnruq4yTWRymKLWKneWm Aj3w== 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=ZmUolxszHLEISu3ZCcad6hveUOgpZrBDUcufGrh29MM=; b=EEv3zj4ohgEBWWZRYWa5uO6qkMANlRAxwfFqkZpD2XPkQvFTzMWJW4NH7ZKmu12cQa BSZtE+UcxYxcWEIDqpf00mlbmAPgJbK6DRHFTUnsaIv6kBx2RhxBmAlDu9xVTghMQ6F3 jhfk1vR56df7R6VEj42lrlZwPMDMQLpUp+gqhX8HLOJt+H5j9+1qimaXNpXI6vEa/wnU LyJC8bVksIPVctMRDEaLcaYrQOAN6OeZhd/djnm4FYnXL2I6URRNpiniQDr+y+j59b/t grRcYn85Fydu/PGpAyrjc7kbchx7C8QHtG0Krd/9HG4/gT8BXWFIwJfC700sfL0foCZ1 9S1g== X-Gm-Message-State: AJaThX6/aa4IGHm7p8IJ49raq6UirHDMKoTVVnXee5/3ut5NymKG4F0F IJi/uBzLZNUDB0s5fh7SbLv8h2XvlzNQ8g== X-Google-Smtp-Source: AGs4zMZ6RQMSK9ZZHPcHqXGZEVSH5h6Btv7MZMLsYoV2/qLrjYNMM4UZL5FJ2Vv36wQGmcUDiPVlfQ== X-Received: by 10.80.166.34 with SMTP id d31mr32321894edc.96.1512419769523; Mon, 04 Dec 2017 12:36:09 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id k42sm8434943edb.94.2017.12.04.12.36.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Dec 2017 12:36:08 -0800 (PST) From: Christoffer Dall To: kvm@vger.kernel.org Cc: Andrew Jones , Christoffer Dall , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Marc Zyngier , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, James Hogan , linux-mips@linux-mips.org, Paul Mackerras , kvm-ppc@vger.kernel.org, Christian Borntraeger , Cornelia Huck , linux-s390@vger.kernel.org Subject: [PATCH v3 15/16] KVM: arm/arm64: Avoid vcpu_load for other vcpu ioctls than KVM_RUN Date: Mon, 4 Dec 2017 21:35:37 +0100 Message-Id: <20171204203538.8370-16-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171204203538.8370-1-cdall@kernel.org> References: <20171204203538.8370-1-cdall@kernel.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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. 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 8223c59be507..a760ef1803be 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -381,14 +381,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; } @@ -397,8 +394,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; @@ -410,7 +405,6 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, ret = -EINVAL; } - vcpu_put(vcpu); return ret; } @@ -1003,8 +997,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; @@ -1081,7 +1073,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp, r = -EINVAL; } - vcpu_put(vcpu); return r; }