From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vitaly Kuznetsov Date: Thu, 16 Apr 2020 07:03:47 +0000 Subject: Re: [PATCH v2] KVM: Optimize kvm_arch_vcpu_ioctl_run function Message-Id: <878sivx67g.fsf@vitty.brq.redhat.com> List-Id: References: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> In-Reply-To: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Tianjia Zhang Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, tianjia.zhang@linux.alibaba.com, pbonzini@redhat.com, tsbogend@alpha.franken.de, paulus@ozlabs.org, mpe@ellerman.id.au, benh@kernel.crashing.org, borntraeger@de.ibm.com, frankja@linux.ibm.com, david@redhat.com, cohuck@redhat.com, heiko.carstens@de.ibm.com, gor@linux.ibm.com, sean.j.christopherson@intel.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, christoffer.dall@arm.com, peterx@redhat.com, thuth@redhat.com Tianjia Zhang writes: > In earlier versions of kvm, 'kvm_run' is an independent structure > and is not included in the vcpu structure. At present, 'kvm_run' > is already included in the vcpu structure, so the parameter > 'kvm_run' is redundant. > > This patch simplify the function definition, removes the extra > 'kvm_run' parameter, and extract it from the 'kvm_vcpu' structure > if necessary. > > Signed-off-by: Tianjia Zhang > --- > > v2 change: > remove 'kvm_run' parameter and extract it from 'kvm_vcpu' > > arch/mips/kvm/mips.c | 3 ++- > arch/powerpc/kvm/powerpc.c | 3 ++- > arch/s390/kvm/kvm-s390.c | 3 ++- > arch/x86/kvm/x86.c | 11 ++++++----- > include/linux/kvm_host.h | 2 +- > virt/kvm/arm/arm.c | 6 +++--- > virt/kvm/kvm_main.c | 2 +- > 7 files changed, 17 insertions(+), 13 deletions(-) > > diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c > index 8f05dd0a0f4e..ec24adf4857e 100644 > --- a/arch/mips/kvm/mips.c > +++ b/arch/mips/kvm/mips.c > @@ -439,8 +439,9 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > return -ENOIOCTLCMD; > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int r = -EINTR; > > vcpu_load(vcpu); > diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c > index e15166b0a16d..7e24691e138a 100644 > --- a/arch/powerpc/kvm/powerpc.c > +++ b/arch/powerpc/kvm/powerpc.c > @@ -1764,8 +1764,9 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) > return r; > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int r; > > vcpu_load(vcpu); > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c > index 19a81024fe16..443af3ead739 100644 > --- a/arch/s390/kvm/kvm-s390.c > +++ b/arch/s390/kvm/kvm-s390.c > @@ -4333,8 +4333,9 @@ static void store_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > store_regs_fmt2(vcpu, kvm_run); > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *kvm_run = vcpu->run; > int rc; > > if (kvm_run->immediate_exit) > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 3bf2ecafd027..a0338e86c90f 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -8707,8 +8707,9 @@ static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu) > trace_kvm_fpu(0); > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *kvm_run = vcpu->run; > int r; > > vcpu_load(vcpu); > @@ -8726,18 +8727,18 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > r = -EAGAIN; > if (signal_pending(current)) { > r = -EINTR; > - vcpu->run->exit_reason = KVM_EXIT_INTR; > + kvm_run->exit_reason = KVM_EXIT_INTR; > ++vcpu->stat.signal_exits; > } > goto out; > } > > - if (vcpu->run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) { > + if (kvm_run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) { > r = -EINVAL; > goto out; > } > > - if (vcpu->run->kvm_dirty_regs) { > + if (kvm_run->kvm_dirty_regs) { > r = sync_regs(vcpu); > if (r != 0) > goto out; > @@ -8767,7 +8768,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > > out: > kvm_put_guest_fpu(vcpu); > - if (vcpu->run->kvm_valid_regs) > + if (kvm_run->kvm_valid_regs) > store_regs(vcpu); > post_kvm_run_save(vcpu); > kvm_sigset_deactivate(vcpu); > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 6d58beb65454..1e17ef719595 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -866,7 +866,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, > struct kvm_mp_state *mp_state); > int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > struct kvm_guest_debug *dbg); > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run); > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu); > > int kvm_arch_init(void *opaque); > void kvm_arch_exit(void); > diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c > index 48d0ec44ad77..f5390ac2165b 100644 > --- a/virt/kvm/arm/arm.c > +++ b/virt/kvm/arm/arm.c > @@ -639,7 +639,6 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) > /** > * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code > * @vcpu: The VCPU pointer > - * @run: The kvm_run structure pointer used for userspace state exchange > * > * This function is called through the VCPU_RUN ioctl called from user space. It > * will execute VM code in a loop until the time slice for the process is used > @@ -647,8 +646,9 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) > * return with return value 0 and with the kvm_run structure filled in with the > * required data for the requested emulation. > */ > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int ret; > > if (unlikely(!kvm_vcpu_initialized(vcpu))) > @@ -659,7 +659,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > return ret; > > if (run->exit_reason = KVM_EXIT_MMIO) { > - ret = kvm_handle_mmio_return(vcpu, vcpu->run); > + ret = kvm_handle_mmio_return(vcpu, run); I don't know much about ARM but this also seems redundant, kvm_handle_mmio_return() is also able to extruct 'struct kvm_run' from' 'struct kvm_vcpu'. This likely deserves it's own patch though. > if (ret) > return ret; > } > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 74bdb7bf3295..e18faea89146 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -3135,7 +3135,7 @@ static long kvm_vcpu_ioctl(struct file *filp, > synchronize_rcu(); > put_pid(oldpid); > } > - r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run); > + r = kvm_arch_vcpu_ioctl_run(vcpu); > trace_kvm_userspace_exit(vcpu->run->exit_reason, r); > break; > } Looked at non-x86 arches just briefly but there seems to be no controversy here, so Reviewed-by: Vitaly Kuznetsov -- Vitaly From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7059C2BB55 for ; Thu, 16 Apr 2020 11:10:23 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 6022D206E9 for ; Thu, 16 Apr 2020 11:10:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iIX1DYOW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6022D206E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 17F954B259; Thu, 16 Apr 2020 07:10:23 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@redhat.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sVq1qqiVmNTq; Thu, 16 Apr 2020 07:10:21 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 5F2A64B261; Thu, 16 Apr 2020 07:10:17 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 77A634B226 for ; Thu, 16 Apr 2020 03:03:56 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ztKgk+CBCp47 for ; Thu, 16 Apr 2020 03:03:54 -0400 (EDT) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mm01.cs.columbia.edu (Postfix) with ESMTP id A066C4B0F7 for ; Thu, 16 Apr 2020 03:03:54 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587020634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ycA+oaK7HnY0LCry275m8vvLJYLlqC5gRDJoT8fOj6s=; b=iIX1DYOWAXPgNxk6aF8CTQV6URQVWwBfXInDhlCMm+a2vtoT13nZArvWQnlv4J+28TY9lx TU9ISPw5612D7pPe2D2HSJcw4wc4jjuk4Th2wIXzvMzKItyTbuWnm4bmFzOSHF1PbxIt+J 4t9U97jEEKUJOP8p75CxM8g2Z+TcfAI= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-53-pFgjUwFbOA2Rmdn5Bh6oXQ-1; Thu, 16 Apr 2020 03:03:52 -0400 X-MC-Unique: pFgjUwFbOA2Rmdn5Bh6oXQ-1 Received: by mail-wr1-f71.google.com with SMTP id j22so1255714wrb.4 for ; Thu, 16 Apr 2020 00:03:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=u8Fe4HRBZIpxRs2mIcqmv3RiTnssjCSY9lhZeXvdF9I=; b=jfruO5oCj4wvBeh4BHejC2E3i+DiFboaBgaZ8wKv0hNFNTxbHw44SjBVKNjrsHSB47 lGCGwcy7utUX/uVTQIcCqcqzM/hzCMtAU8s9DFC+ahGFYrLYeMYzYMtGdNgT7DlBKM30 wWBt86v2dddN3sV2i/pmNaak2xSeVM+UFjSA5djhHKDp9b5UNkYCkjmcsJjX4HnmM/7R GvwYmIeICgTc74QdX3HF/lKBRXs3hOAt0J3bXRxeXblK5WC97go1a2Vkf+ZZBgf4flYa lsicGMiWdGMtKIl4bjh9K+W+Oj9mHtqvFsnwURZZBJhfTz+BxeRZO2SkozhyrBs2at6E fPvw== X-Gm-Message-State: AGi0Puba9RteUAr8LqFTDUfblA8UAtTHPIRVkUMuaHTrjZLIbdkJuRIj 6dCtlJ/bjLKVlVWBkP9cvWugYPjeeRGWgGbvWkehk3FyXXgpVjCrBJcHG96lRJDBgKdUaou2Lmd wghJmnj3aJQFTmYzBZfb51cDK X-Received: by 2002:a5d:4005:: with SMTP id n5mr7830151wrp.242.1587020631114; Thu, 16 Apr 2020 00:03:51 -0700 (PDT) X-Google-Smtp-Source: APiQypKzVfRYkQQjXNmPRmmEuweWR0AsvTUy66VIOLHRJ9IcCVXdD+fbCSvkQnkvtw8EzDw2iMvttg== X-Received: by 2002:a5d:4005:: with SMTP id n5mr7830094wrp.242.1587020630785; Thu, 16 Apr 2020 00:03:50 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id o16sm26785055wrs.44.2020.04.16.00.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Apr 2020 00:03:49 -0700 (PDT) From: Vitaly Kuznetsov To: Tianjia Zhang Subject: Re: [PATCH v2] KVM: Optimize kvm_arch_vcpu_ioctl_run function In-Reply-To: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> References: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> Date: Thu, 16 Apr 2020 09:03:47 +0200 Message-ID: <878sivx67g.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Mailman-Approved-At: Thu, 16 Apr 2020 07:10:16 -0400 Cc: wanpengli@tencent.com, kvm@vger.kernel.org, david@redhat.com, benh@kernel.crashing.org, heiko.carstens@de.ibm.com, linux-kernel@vger.kernel.org, paulus@ozlabs.org, hpa@zytor.com, kvmarm@lists.cs.columbia.edu, linux-s390@vger.kernel.org, frankja@linux.ibm.com, mpe@ellerman.id.au, joro@8bytes.org, x86@kernel.org, borntraeger@de.ibm.com, mingo@redhat.com, thuth@redhat.com, gor@linux.ibm.com, kvm-ppc@vger.kernel.org, bp@alien8.de, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, jmattson@google.com, tsbogend@alpha.franken.de, tianjia.zhang@linux.alibaba.com, cohuck@redhat.com, linux-mips@vger.kernel.org, sean.j.christopherson@intel.com, maz@kernel.org, pbonzini@redhat.com, linuxppc-dev@lists.ozlabs.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu Tianjia Zhang writes: > In earlier versions of kvm, 'kvm_run' is an independent structure > and is not included in the vcpu structure. At present, 'kvm_run' > is already included in the vcpu structure, so the parameter > 'kvm_run' is redundant. > > This patch simplify the function definition, removes the extra > 'kvm_run' parameter, and extract it from the 'kvm_vcpu' structure > if necessary. > > Signed-off-by: Tianjia Zhang > --- > > v2 change: > remove 'kvm_run' parameter and extract it from 'kvm_vcpu' > > arch/mips/kvm/mips.c | 3 ++- > arch/powerpc/kvm/powerpc.c | 3 ++- > arch/s390/kvm/kvm-s390.c | 3 ++- > arch/x86/kvm/x86.c | 11 ++++++----- > include/linux/kvm_host.h | 2 +- > virt/kvm/arm/arm.c | 6 +++--- > virt/kvm/kvm_main.c | 2 +- > 7 files changed, 17 insertions(+), 13 deletions(-) > > diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c > index 8f05dd0a0f4e..ec24adf4857e 100644 > --- a/arch/mips/kvm/mips.c > +++ b/arch/mips/kvm/mips.c > @@ -439,8 +439,9 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > return -ENOIOCTLCMD; > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int r = -EINTR; > > vcpu_load(vcpu); > diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c > index e15166b0a16d..7e24691e138a 100644 > --- a/arch/powerpc/kvm/powerpc.c > +++ b/arch/powerpc/kvm/powerpc.c > @@ -1764,8 +1764,9 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) > return r; > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int r; > > vcpu_load(vcpu); > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c > index 19a81024fe16..443af3ead739 100644 > --- a/arch/s390/kvm/kvm-s390.c > +++ b/arch/s390/kvm/kvm-s390.c > @@ -4333,8 +4333,9 @@ static void store_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > store_regs_fmt2(vcpu, kvm_run); > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *kvm_run = vcpu->run; > int rc; > > if (kvm_run->immediate_exit) > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 3bf2ecafd027..a0338e86c90f 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -8707,8 +8707,9 @@ static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu) > trace_kvm_fpu(0); > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *kvm_run = vcpu->run; > int r; > > vcpu_load(vcpu); > @@ -8726,18 +8727,18 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > r = -EAGAIN; > if (signal_pending(current)) { > r = -EINTR; > - vcpu->run->exit_reason = KVM_EXIT_INTR; > + kvm_run->exit_reason = KVM_EXIT_INTR; > ++vcpu->stat.signal_exits; > } > goto out; > } > > - if (vcpu->run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) { > + if (kvm_run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) { > r = -EINVAL; > goto out; > } > > - if (vcpu->run->kvm_dirty_regs) { > + if (kvm_run->kvm_dirty_regs) { > r = sync_regs(vcpu); > if (r != 0) > goto out; > @@ -8767,7 +8768,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > > out: > kvm_put_guest_fpu(vcpu); > - if (vcpu->run->kvm_valid_regs) > + if (kvm_run->kvm_valid_regs) > store_regs(vcpu); > post_kvm_run_save(vcpu); > kvm_sigset_deactivate(vcpu); > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 6d58beb65454..1e17ef719595 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -866,7 +866,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, > struct kvm_mp_state *mp_state); > int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > struct kvm_guest_debug *dbg); > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run); > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu); > > int kvm_arch_init(void *opaque); > void kvm_arch_exit(void); > diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c > index 48d0ec44ad77..f5390ac2165b 100644 > --- a/virt/kvm/arm/arm.c > +++ b/virt/kvm/arm/arm.c > @@ -639,7 +639,6 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) > /** > * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code > * @vcpu: The VCPU pointer > - * @run: The kvm_run structure pointer used for userspace state exchange > * > * This function is called through the VCPU_RUN ioctl called from user space. It > * will execute VM code in a loop until the time slice for the process is used > @@ -647,8 +646,9 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) > * return with return value 0 and with the kvm_run structure filled in with the > * required data for the requested emulation. > */ > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int ret; > > if (unlikely(!kvm_vcpu_initialized(vcpu))) > @@ -659,7 +659,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > return ret; > > if (run->exit_reason == KVM_EXIT_MMIO) { > - ret = kvm_handle_mmio_return(vcpu, vcpu->run); > + ret = kvm_handle_mmio_return(vcpu, run); I don't know much about ARM but this also seems redundant, kvm_handle_mmio_return() is also able to extruct 'struct kvm_run' from' 'struct kvm_vcpu'. This likely deserves it's own patch though. > if (ret) > return ret; > } > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 74bdb7bf3295..e18faea89146 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -3135,7 +3135,7 @@ static long kvm_vcpu_ioctl(struct file *filp, > synchronize_rcu(); > put_pid(oldpid); > } > - r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run); > + r = kvm_arch_vcpu_ioctl_run(vcpu); > trace_kvm_userspace_exit(vcpu->run->exit_reason, r); > break; > } Looked at non-x86 arches just briefly but there seems to be no controversy here, so Reviewed-by: Vitaly Kuznetsov -- Vitaly _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2ECCC352BE for ; Thu, 16 Apr 2020 07:04:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA43821655 for ; Thu, 16 Apr 2020 07:04:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y6W1E0B+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438189AbgDPHD7 (ORCPT ); Thu, 16 Apr 2020 03:03:59 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:46532 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2438227AbgDPHD4 (ORCPT ); Thu, 16 Apr 2020 03:03:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587020634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=u8Fe4HRBZIpxRs2mIcqmv3RiTnssjCSY9lhZeXvdF9I=; b=Y6W1E0B+Tb2OwSZEYOtbu9su6T+sc+Yc4JFuzDMZE1i3AYcGTbdmxLR+wtkTHg36fximfx L8Ytx2cMi0lX+vsVcrQhZkS+VYH63wZXLbedrc2pei2YuiIoiQvslReXtCDTqTZJIxrgXa za0tI/4GT7AYyBCCvpEeuY3jmijbF+Q= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-214-KBs1_tcpNiGsLprP_V6DwA-1; Thu, 16 Apr 2020 03:03:52 -0400 X-MC-Unique: KBs1_tcpNiGsLprP_V6DwA-1 Received: by mail-wr1-f71.google.com with SMTP id j16so1222495wrw.20 for ; Thu, 16 Apr 2020 00:03:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=u8Fe4HRBZIpxRs2mIcqmv3RiTnssjCSY9lhZeXvdF9I=; b=EtlssJD0VRHgHCG4in55KybAUM17a5vFI7kPFQMyTnJbL1zNWWl13zdtC4BRAVeAyn IGsPQOuxfhsHj3MPOV747yQ5RqAFTwQ2b4lzaQbDhGLe3eA3axhKVGnkbVxI3eyFdw/H 5+vwnxvKX+lQe9TkkNDEvZAm2don2z+nOHROmgo05RC0HfXAwSlXPbDYBnk5nKf916ik 8CA8KWMakKGY8fpy24QlKNRFYiRU8BuMtLl3jBvbpKOZxTbPpLxaUv7J8CDXfW32ulnb f/IhiXsQJ3ANV5bpuA7Grd4ivKivEevM1O3z6Aq5P80LOlmCvDJks+Cbi4e8fvyZ2h5Z NEEQ== X-Gm-Message-State: AGi0PuaKOS8v4MsIPQJVsE+ese3C/P6h8PQmAQxuH+OViZ3ifvFLQmvL nmF3e0qVJesmTneURSJeF/6bl6E6/N9BXV9ofvOW4uV/eQH801IG20qWQ9ycxra91ysdfTHvVtZ MZ9lQDMwCKHs5WUD7Ij7DQg== X-Received: by 2002:a5d:4005:: with SMTP id n5mr7830149wrp.242.1587020631100; Thu, 16 Apr 2020 00:03:51 -0700 (PDT) X-Google-Smtp-Source: APiQypKzVfRYkQQjXNmPRmmEuweWR0AsvTUy66VIOLHRJ9IcCVXdD+fbCSvkQnkvtw8EzDw2iMvttg== X-Received: by 2002:a5d:4005:: with SMTP id n5mr7830094wrp.242.1587020630785; Thu, 16 Apr 2020 00:03:50 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id o16sm26785055wrs.44.2020.04.16.00.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Apr 2020 00:03:49 -0700 (PDT) From: Vitaly Kuznetsov To: Tianjia Zhang Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, tianjia.zhang@linux.alibaba.com, pbonzini@redhat.com, tsbogend@alpha.franken.de, paulus@ozlabs.org, mpe@ellerman.id.au, benh@kernel.crashing.org, borntraeger@de.ibm.com, frankja@linux.ibm.com, david@redhat.com, cohuck@redhat.com, heiko.carstens@de.ibm.com, gor@linux.ibm.com, sean.j.christopherson@intel.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, christoffer.dall@arm.com, peterx@redhat.com, thuth@redhat.com Subject: Re: [PATCH v2] KVM: Optimize kvm_arch_vcpu_ioctl_run function In-Reply-To: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> References: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> Date: Thu, 16 Apr 2020 09:03:47 +0200 Message-ID: <878sivx67g.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Tianjia Zhang writes: > In earlier versions of kvm, 'kvm_run' is an independent structure > and is not included in the vcpu structure. At present, 'kvm_run' > is already included in the vcpu structure, so the parameter > 'kvm_run' is redundant. > > This patch simplify the function definition, removes the extra > 'kvm_run' parameter, and extract it from the 'kvm_vcpu' structure > if necessary. > > Signed-off-by: Tianjia Zhang > --- > > v2 change: > remove 'kvm_run' parameter and extract it from 'kvm_vcpu' > > arch/mips/kvm/mips.c | 3 ++- > arch/powerpc/kvm/powerpc.c | 3 ++- > arch/s390/kvm/kvm-s390.c | 3 ++- > arch/x86/kvm/x86.c | 11 ++++++----- > include/linux/kvm_host.h | 2 +- > virt/kvm/arm/arm.c | 6 +++--- > virt/kvm/kvm_main.c | 2 +- > 7 files changed, 17 insertions(+), 13 deletions(-) > > diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c > index 8f05dd0a0f4e..ec24adf4857e 100644 > --- a/arch/mips/kvm/mips.c > +++ b/arch/mips/kvm/mips.c > @@ -439,8 +439,9 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > return -ENOIOCTLCMD; > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int r = -EINTR; > > vcpu_load(vcpu); > diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c > index e15166b0a16d..7e24691e138a 100644 > --- a/arch/powerpc/kvm/powerpc.c > +++ b/arch/powerpc/kvm/powerpc.c > @@ -1764,8 +1764,9 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) > return r; > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int r; > > vcpu_load(vcpu); > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c > index 19a81024fe16..443af3ead739 100644 > --- a/arch/s390/kvm/kvm-s390.c > +++ b/arch/s390/kvm/kvm-s390.c > @@ -4333,8 +4333,9 @@ static void store_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > store_regs_fmt2(vcpu, kvm_run); > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *kvm_run = vcpu->run; > int rc; > > if (kvm_run->immediate_exit) > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 3bf2ecafd027..a0338e86c90f 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -8707,8 +8707,9 @@ static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu) > trace_kvm_fpu(0); > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *kvm_run = vcpu->run; > int r; > > vcpu_load(vcpu); > @@ -8726,18 +8727,18 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > r = -EAGAIN; > if (signal_pending(current)) { > r = -EINTR; > - vcpu->run->exit_reason = KVM_EXIT_INTR; > + kvm_run->exit_reason = KVM_EXIT_INTR; > ++vcpu->stat.signal_exits; > } > goto out; > } > > - if (vcpu->run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) { > + if (kvm_run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) { > r = -EINVAL; > goto out; > } > > - if (vcpu->run->kvm_dirty_regs) { > + if (kvm_run->kvm_dirty_regs) { > r = sync_regs(vcpu); > if (r != 0) > goto out; > @@ -8767,7 +8768,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > > out: > kvm_put_guest_fpu(vcpu); > - if (vcpu->run->kvm_valid_regs) > + if (kvm_run->kvm_valid_regs) > store_regs(vcpu); > post_kvm_run_save(vcpu); > kvm_sigset_deactivate(vcpu); > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 6d58beb65454..1e17ef719595 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -866,7 +866,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, > struct kvm_mp_state *mp_state); > int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > struct kvm_guest_debug *dbg); > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run); > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu); > > int kvm_arch_init(void *opaque); > void kvm_arch_exit(void); > diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c > index 48d0ec44ad77..f5390ac2165b 100644 > --- a/virt/kvm/arm/arm.c > +++ b/virt/kvm/arm/arm.c > @@ -639,7 +639,6 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) > /** > * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code > * @vcpu: The VCPU pointer > - * @run: The kvm_run structure pointer used for userspace state exchange > * > * This function is called through the VCPU_RUN ioctl called from user space. It > * will execute VM code in a loop until the time slice for the process is used > @@ -647,8 +646,9 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) > * return with return value 0 and with the kvm_run structure filled in with the > * required data for the requested emulation. > */ > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int ret; > > if (unlikely(!kvm_vcpu_initialized(vcpu))) > @@ -659,7 +659,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > return ret; > > if (run->exit_reason == KVM_EXIT_MMIO) { > - ret = kvm_handle_mmio_return(vcpu, vcpu->run); > + ret = kvm_handle_mmio_return(vcpu, run); I don't know much about ARM but this also seems redundant, kvm_handle_mmio_return() is also able to extruct 'struct kvm_run' from' 'struct kvm_vcpu'. This likely deserves it's own patch though. > if (ret) > return ret; > } > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 74bdb7bf3295..e18faea89146 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -3135,7 +3135,7 @@ static long kvm_vcpu_ioctl(struct file *filp, > synchronize_rcu(); > put_pid(oldpid); > } > - r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run); > + r = kvm_arch_vcpu_ioctl_run(vcpu); > trace_kvm_userspace_exit(vcpu->run->exit_reason, r); > break; > } Looked at non-x86 arches just briefly but there seems to be no controversy here, so Reviewed-by: Vitaly Kuznetsov -- Vitaly From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com ([207.211.31.81]:25436 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2438189AbgDPHD4 (ORCPT ); Thu, 16 Apr 2020 03:03:56 -0400 Received: by mail-wr1-f69.google.com with SMTP id f2so1243441wrm.9 for ; Thu, 16 Apr 2020 00:03:52 -0700 (PDT) From: Vitaly Kuznetsov Subject: Re: [PATCH v2] KVM: Optimize kvm_arch_vcpu_ioctl_run function In-Reply-To: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> References: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> Date: Thu, 16 Apr 2020 09:03:47 +0200 Message-ID: <878sivx67g.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-s390-owner@vger.kernel.org List-ID: To: Tianjia Zhang Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, tsbogend@alpha.franken.de, paulus@ozlabs.org, mpe@ellerman.id.au, benh@kernel.crashing.org, borntraeger@de.ibm.com, frankja@linux.ibm.com, david@redhat.com, cohuck@redhat.com, heiko.carstens@de.ibm.com, gor@linux.ibm.com, sean.j.christopherson@intel.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, christoffer.dall@arm.com, peterx@redhat.com, thuth@redhat.com Tianjia Zhang writes: > In earlier versions of kvm, 'kvm_run' is an independent structure > and is not included in the vcpu structure. At present, 'kvm_run' > is already included in the vcpu structure, so the parameter > 'kvm_run' is redundant. > > This patch simplify the function definition, removes the extra > 'kvm_run' parameter, and extract it from the 'kvm_vcpu' structure > if necessary. > > Signed-off-by: Tianjia Zhang > --- > > v2 change: > remove 'kvm_run' parameter and extract it from 'kvm_vcpu' > > arch/mips/kvm/mips.c | 3 ++- > arch/powerpc/kvm/powerpc.c | 3 ++- > arch/s390/kvm/kvm-s390.c | 3 ++- > arch/x86/kvm/x86.c | 11 ++++++----- > include/linux/kvm_host.h | 2 +- > virt/kvm/arm/arm.c | 6 +++--- > virt/kvm/kvm_main.c | 2 +- > 7 files changed, 17 insertions(+), 13 deletions(-) > > diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c > index 8f05dd0a0f4e..ec24adf4857e 100644 > --- a/arch/mips/kvm/mips.c > +++ b/arch/mips/kvm/mips.c > @@ -439,8 +439,9 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > return -ENOIOCTLCMD; > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int r = -EINTR; > > vcpu_load(vcpu); > diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c > index e15166b0a16d..7e24691e138a 100644 > --- a/arch/powerpc/kvm/powerpc.c > +++ b/arch/powerpc/kvm/powerpc.c > @@ -1764,8 +1764,9 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) > return r; > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int r; > > vcpu_load(vcpu); > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c > index 19a81024fe16..443af3ead739 100644 > --- a/arch/s390/kvm/kvm-s390.c > +++ b/arch/s390/kvm/kvm-s390.c > @@ -4333,8 +4333,9 @@ static void store_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > store_regs_fmt2(vcpu, kvm_run); > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *kvm_run = vcpu->run; > int rc; > > if (kvm_run->immediate_exit) > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 3bf2ecafd027..a0338e86c90f 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -8707,8 +8707,9 @@ static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu) > trace_kvm_fpu(0); > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *kvm_run = vcpu->run; > int r; > > vcpu_load(vcpu); > @@ -8726,18 +8727,18 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > r = -EAGAIN; > if (signal_pending(current)) { > r = -EINTR; > - vcpu->run->exit_reason = KVM_EXIT_INTR; > + kvm_run->exit_reason = KVM_EXIT_INTR; > ++vcpu->stat.signal_exits; > } > goto out; > } > > - if (vcpu->run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) { > + if (kvm_run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) { > r = -EINVAL; > goto out; > } > > - if (vcpu->run->kvm_dirty_regs) { > + if (kvm_run->kvm_dirty_regs) { > r = sync_regs(vcpu); > if (r != 0) > goto out; > @@ -8767,7 +8768,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > > out: > kvm_put_guest_fpu(vcpu); > - if (vcpu->run->kvm_valid_regs) > + if (kvm_run->kvm_valid_regs) > store_regs(vcpu); > post_kvm_run_save(vcpu); > kvm_sigset_deactivate(vcpu); > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 6d58beb65454..1e17ef719595 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -866,7 +866,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, > struct kvm_mp_state *mp_state); > int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > struct kvm_guest_debug *dbg); > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run); > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu); > > int kvm_arch_init(void *opaque); > void kvm_arch_exit(void); > diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c > index 48d0ec44ad77..f5390ac2165b 100644 > --- a/virt/kvm/arm/arm.c > +++ b/virt/kvm/arm/arm.c > @@ -639,7 +639,6 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) > /** > * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code > * @vcpu: The VCPU pointer > - * @run: The kvm_run structure pointer used for userspace state exchange > * > * This function is called through the VCPU_RUN ioctl called from user space. It > * will execute VM code in a loop until the time slice for the process is used > @@ -647,8 +646,9 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) > * return with return value 0 and with the kvm_run structure filled in with the > * required data for the requested emulation. > */ > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int ret; > > if (unlikely(!kvm_vcpu_initialized(vcpu))) > @@ -659,7 +659,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > return ret; > > if (run->exit_reason == KVM_EXIT_MMIO) { > - ret = kvm_handle_mmio_return(vcpu, vcpu->run); > + ret = kvm_handle_mmio_return(vcpu, run); I don't know much about ARM but this also seems redundant, kvm_handle_mmio_return() is also able to extruct 'struct kvm_run' from' 'struct kvm_vcpu'. This likely deserves it's own patch though. > if (ret) > return ret; > } > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 74bdb7bf3295..e18faea89146 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -3135,7 +3135,7 @@ static long kvm_vcpu_ioctl(struct file *filp, > synchronize_rcu(); > put_pid(oldpid); > } > - r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run); > + r = kvm_arch_vcpu_ioctl_run(vcpu); > trace_kvm_userspace_exit(vcpu->run->exit_reason, r); > break; > } Looked at non-x86 arches just briefly but there seems to be no controversy here, so Reviewed-by: Vitaly Kuznetsov -- Vitaly From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A004AC352BE for ; Thu, 16 Apr 2020 07:08:05 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 19DAE21569 for ; Thu, 16 Apr 2020 07:08:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iIX1DYOW"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="coN8qmYy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 19DAE21569 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 492r0L3GrMzDrMh for ; Thu, 16 Apr 2020 17:08:02 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=205.139.110.120; helo=us-smtp-1.mimecast.com; envelope-from=vkuznets@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iIX1DYOW; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=coN8qmYy; dkim-atps=neutral Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 492qy851YFzDrLj for ; Thu, 16 Apr 2020 17:06:04 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587020634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ycA+oaK7HnY0LCry275m8vvLJYLlqC5gRDJoT8fOj6s=; b=iIX1DYOWAXPgNxk6aF8CTQV6URQVWwBfXInDhlCMm+a2vtoT13nZArvWQnlv4J+28TY9lx TU9ISPw5612D7pPe2D2HSJcw4wc4jjuk4Th2wIXzvMzKItyTbuWnm4bmFzOSHF1PbxIt+J 4t9U97jEEKUJOP8p75CxM8g2Z+TcfAI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587020761; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ycA+oaK7HnY0LCry275m8vvLJYLlqC5gRDJoT8fOj6s=; b=coN8qmYyQBH/u1Xx39+z+as1C0EsD6oD7h4CQymideqanEzvnIm87Zh8KqbXOtu6/KBaZd HnAV6iL5wBTigSvQMToo+uKnKL8Rpv/rzOxuoPsaZNAP5H27VuyhWph5beFnuhGqXINxrE FfP6hc0wVwl4W8TyPmrs8Kh2uI3yz/4= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-180-H5cObrEhPQy19gvtOwRvDA-1; Thu, 16 Apr 2020 03:03:52 -0400 X-MC-Unique: H5cObrEhPQy19gvtOwRvDA-1 Received: by mail-wr1-f70.google.com with SMTP id j12so1226116wrr.18 for ; Thu, 16 Apr 2020 00:03:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=u8Fe4HRBZIpxRs2mIcqmv3RiTnssjCSY9lhZeXvdF9I=; b=a7/8xapMh63FZxwDZXwMRi6UotQNUbO4eG1HP4WkIjsZZpkS7T9xpSBhIZdeQjlXGq mUjgXtUyTQZf0NaYXr2YNyCW8tR4lulg0gua8M6EohLIXkd2UW8qwtjrgpvILaMHxx5q dqGNEh/Y87od/kKgPXIoLs+yybLFDEVl+zuTQ0xG0TcavcVbvjal85vqKkPX4JXUbPt1 lLiRh62u9E4oveOCmcgMUYfaLCIR4eFnyu6aLh85RnousYGFGr91Gp+z/eU8ow4kZp9z B0s5/Ixwiqygm9r58qA3rWa8FP2aD8sOzVvnHYeVfGkA5VNqCfFjVaQCUXewB0/Bs7CT XnCw== X-Gm-Message-State: AGi0PuaGrmAfoer4QBAY4bLlDisEgwFz78hmW37WcDiMSrvgeGn0bj7i NxL1oQ7gwzRSkw58SAZ0ktj2Fnvb4YrEbUDs0DVUMCUPIAYdSYeg5i1Z5x/UC4VowKJ6Or5uzv9 WPXDxt07cnBeJX9wwkfzB5LQ13A== X-Received: by 2002:a5d:4005:: with SMTP id n5mr7830147wrp.242.1587020631096; Thu, 16 Apr 2020 00:03:51 -0700 (PDT) X-Google-Smtp-Source: APiQypKzVfRYkQQjXNmPRmmEuweWR0AsvTUy66VIOLHRJ9IcCVXdD+fbCSvkQnkvtw8EzDw2iMvttg== X-Received: by 2002:a5d:4005:: with SMTP id n5mr7830094wrp.242.1587020630785; Thu, 16 Apr 2020 00:03:50 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id o16sm26785055wrs.44.2020.04.16.00.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Apr 2020 00:03:49 -0700 (PDT) From: Vitaly Kuznetsov To: Tianjia Zhang Subject: Re: [PATCH v2] KVM: Optimize kvm_arch_vcpu_ioctl_run function In-Reply-To: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> References: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> Date: Thu, 16 Apr 2020 09:03:47 +0200 Message-ID: <878sivx67g.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: christoffer.dall@arm.com, wanpengli@tencent.com, kvm@vger.kernel.org, david@redhat.com, heiko.carstens@de.ibm.com, peterx@redhat.com, linux-kernel@vger.kernel.org, hpa@zytor.com, kvmarm@lists.cs.columbia.edu, linux-s390@vger.kernel.org, frankja@linux.ibm.com, joro@8bytes.org, x86@kernel.org, borntraeger@de.ibm.com, mingo@redhat.com, julien.thierry.kdev@gmail.com, thuth@redhat.com, gor@linux.ibm.com, suzuki.poulose@arm.com, kvm-ppc@vger.kernel.org, bp@alien8.de, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, jmattson@google.com, tsbogend@alpha.franken.de, tianjia.zhang@linux.alibaba.com, cohuck@redhat.com, linux-mips@vger.kernel.org, sean.j.christopherson@intel.com, james.morse@arm.com, maz@kernel.org, pbonzini@redhat.com, linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Tianjia Zhang writes: > In earlier versions of kvm, 'kvm_run' is an independent structure > and is not included in the vcpu structure. At present, 'kvm_run' > is already included in the vcpu structure, so the parameter > 'kvm_run' is redundant. > > This patch simplify the function definition, removes the extra > 'kvm_run' parameter, and extract it from the 'kvm_vcpu' structure > if necessary. > > Signed-off-by: Tianjia Zhang > --- > > v2 change: > remove 'kvm_run' parameter and extract it from 'kvm_vcpu' > > arch/mips/kvm/mips.c | 3 ++- > arch/powerpc/kvm/powerpc.c | 3 ++- > arch/s390/kvm/kvm-s390.c | 3 ++- > arch/x86/kvm/x86.c | 11 ++++++----- > include/linux/kvm_host.h | 2 +- > virt/kvm/arm/arm.c | 6 +++--- > virt/kvm/kvm_main.c | 2 +- > 7 files changed, 17 insertions(+), 13 deletions(-) > > diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c > index 8f05dd0a0f4e..ec24adf4857e 100644 > --- a/arch/mips/kvm/mips.c > +++ b/arch/mips/kvm/mips.c > @@ -439,8 +439,9 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vc= pu *vcpu, > =09return -ENOIOCTLCMD; > } > =20 > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > +=09struct kvm_run *run =3D vcpu->run; > =09int r =3D -EINTR; > =20 > =09vcpu_load(vcpu); > diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c > index e15166b0a16d..7e24691e138a 100644 > --- a/arch/powerpc/kvm/powerpc.c > +++ b/arch/powerpc/kvm/powerpc.c > @@ -1764,8 +1764,9 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcp= u, struct kvm_one_reg *reg) > =09return r; > } > =20 > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > +=09struct kvm_run *run =3D vcpu->run; > =09int r; > =20 > =09vcpu_load(vcpu); > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c > index 19a81024fe16..443af3ead739 100644 > --- a/arch/s390/kvm/kvm-s390.c > +++ b/arch/s390/kvm/kvm-s390.c > @@ -4333,8 +4333,9 @@ static void store_regs(struct kvm_vcpu *vcpu, struc= t kvm_run *kvm_run) > =09=09store_regs_fmt2(vcpu, kvm_run); > } > =20 > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_r= un) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > +=09struct kvm_run *kvm_run =3D vcpu->run; > =09int rc; > =20 > =09if (kvm_run->immediate_exit) > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 3bf2ecafd027..a0338e86c90f 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -8707,8 +8707,9 @@ static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu= ) > =09trace_kvm_fpu(0); > } > =20 > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_r= un) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > +=09struct kvm_run *kvm_run =3D vcpu->run; > =09int r; > =20 > =09vcpu_load(vcpu); > @@ -8726,18 +8727,18 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu= , struct kvm_run *kvm_run) > =09=09r =3D -EAGAIN; > =09=09if (signal_pending(current)) { > =09=09=09r =3D -EINTR; > -=09=09=09vcpu->run->exit_reason =3D KVM_EXIT_INTR; > +=09=09=09kvm_run->exit_reason =3D KVM_EXIT_INTR; > =09=09=09++vcpu->stat.signal_exits; > =09=09} > =09=09goto out; > =09} > =20 > -=09if (vcpu->run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) { > +=09if (kvm_run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) { > =09=09r =3D -EINVAL; > =09=09goto out; > =09} > =20 > -=09if (vcpu->run->kvm_dirty_regs) { > +=09if (kvm_run->kvm_dirty_regs) { > =09=09r =3D sync_regs(vcpu); > =09=09if (r !=3D 0) > =09=09=09goto out; > @@ -8767,7 +8768,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, = struct kvm_run *kvm_run) > =20 > out: > =09kvm_put_guest_fpu(vcpu); > -=09if (vcpu->run->kvm_valid_regs) > +=09if (kvm_run->kvm_valid_regs) > =09=09store_regs(vcpu); > =09post_kvm_run_save(vcpu); > =09kvm_sigset_deactivate(vcpu); > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 6d58beb65454..1e17ef719595 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -866,7 +866,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *= vcpu, > =09=09=09=09 struct kvm_mp_state *mp_state); > int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > =09=09=09=09=09struct kvm_guest_debug *dbg); > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_r= un); > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu); > =20 > int kvm_arch_init(void *opaque); > void kvm_arch_exit(void); > diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c > index 48d0ec44ad77..f5390ac2165b 100644 > --- a/virt/kvm/arm/arm.c > +++ b/virt/kvm/arm/arm.c > @@ -639,7 +639,6 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu= ) > /** > * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest= code > * @vcpu:=09The VCPU pointer > - * @run:=09The kvm_run structure pointer used for userspace state exchan= ge > * > * This function is called through the VCPU_RUN ioctl called from user s= pace. It > * will execute VM code in a loop until the time slice for the process i= s used > @@ -647,8 +646,9 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu= ) > * return with return value 0 and with the kvm_run structure filled in w= ith the > * required data for the requested emulation. > */ > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > +=09struct kvm_run *run =3D vcpu->run; > =09int ret; > =20 > =09if (unlikely(!kvm_vcpu_initialized(vcpu))) > @@ -659,7 +659,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, st= ruct kvm_run *run) > =09=09return ret; > =20 > =09if (run->exit_reason =3D=3D KVM_EXIT_MMIO) { > -=09=09ret =3D kvm_handle_mmio_return(vcpu, vcpu->run); > +=09=09ret =3D kvm_handle_mmio_return(vcpu, run); I don't know much about ARM but this also seems redundant, kvm_handle_mmio_return() is also able to extruct 'struct kvm_run' from' 'struct kvm_vcpu'. This likely deserves it's own patch though. > =09=09if (ret) > =09=09=09return ret; > =09} > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 74bdb7bf3295..e18faea89146 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -3135,7 +3135,7 @@ static long kvm_vcpu_ioctl(struct file *filp, > =09=09=09=09synchronize_rcu(); > =09=09=09put_pid(oldpid); > =09=09} > -=09=09r =3D kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run); > +=09=09r =3D kvm_arch_vcpu_ioctl_run(vcpu); > =09=09trace_kvm_userspace_exit(vcpu->run->exit_reason, r); > =09=09break; > =09} Looked at non-x86 arches just briefly but there seems to be no controversy here, so Reviewed-by: Vitaly Kuznetsov --=20 Vitaly From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1990C2D0EF for ; Thu, 16 Apr 2020 07:04:47 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A3F9521582 for ; Thu, 16 Apr 2020 07:04:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="RhIWtkKz"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iIX1DYOW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A3F9521582 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:References :In-Reply-To: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=nNXJj20HfDF0zQwRYIPHD/vcc2m0TPJS3phRGuJP/3M=; b=RhIWtkKzpt8NdN 5KwjMl11zB2bTfae+xEh+k6te1s50tHcc2iY7EatWepdxCSzf5nbCyAfIwTVh2ctKMWp6RoJeDeTu jVlMNoKs+Rx8NOPZgn0g364g7GJ2dSGz57qTqbb4zQJ7JilwdoEN0mzJANCYV9SsMzvX/SsAlYHS9 vYHc8tKGLmYH8rz3DzhgKXbCB/q//jzc4K1q+GyMWo3+QjNLBZ0nmVwSmr2/yWaeT2FWPRXoYdOfe VWHbf5JuO3f4PHkceEy46DWUF+lgbjD/JYJvss88FWBvPYuAinbBLV706zANHT+F2+PsNfQnpT2sR l2fo72os5mHA6s+XwFsQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jOyZm-0000YN-3g; Thu, 16 Apr 2020 07:04:42 +0000 Received: from us-smtp-1.mimecast.com ([205.139.110.61]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jOyZ4-0008N9-32 for linux-arm-kernel@lists.infradead.org; Thu, 16 Apr 2020 07:04:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587020634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ycA+oaK7HnY0LCry275m8vvLJYLlqC5gRDJoT8fOj6s=; b=iIX1DYOWAXPgNxk6aF8CTQV6URQVWwBfXInDhlCMm+a2vtoT13nZArvWQnlv4J+28TY9lx TU9ISPw5612D7pPe2D2HSJcw4wc4jjuk4Th2wIXzvMzKItyTbuWnm4bmFzOSHF1PbxIt+J 4t9U97jEEKUJOP8p75CxM8g2Z+TcfAI= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-22-pVewUh73NoaKBQK7-d8FxA-1; Thu, 16 Apr 2020 03:03:52 -0400 X-MC-Unique: pVewUh73NoaKBQK7-d8FxA-1 Received: by mail-wr1-f69.google.com with SMTP id 11so1255476wrc.3 for ; Thu, 16 Apr 2020 00:03:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=u8Fe4HRBZIpxRs2mIcqmv3RiTnssjCSY9lhZeXvdF9I=; b=sjvnnQaY6N0K8ongEtJSsg4hcyymuZPvdCFGGnsRqrblM5tV5tk3uE/GJxL5klsdFD Zx717LD7b4Sr7Ms+iXjGJd/NUOg1iJZ1CZq7l/bkCq60GmBpMHbswJGgFqweEfagKrZp qDDXoiTLYbhaz2NTFvW99U1G/6vv5KIjiCdb1a5ZnW5+0UyJ83zFfnXwQU1GaMxkquPB 5HpRboS1O4pgXFxDSspQJilwXRdUvObGPKva5It26eIM9EdHdEzvSHIEHpTj3g+spc23 ZcHwXIEhuBbRI2UfSgpIYgJB87yUo9akE0eFVTIRAfqCr5EeqLiq/KGRluqKp2VyrDZ3 UMGg== X-Gm-Message-State: AGi0PuZCM7yLTfu8FvIulxQ12/SVlc0eeJiZis/wmY86RzRHTkJ3rA2W y9U4yAt7hFqpSg99HhiNESYeqoTucpvCaxQ2jmoSxBo6W5KItPfqtKVyhcmmcCHThGHSxpbsxvo KPFC/GorYZpgQQnvcKLpNqA1H/FGOP/DHPxQ= X-Received: by 2002:a5d:4005:: with SMTP id n5mr7830122wrp.242.1587020631086; Thu, 16 Apr 2020 00:03:51 -0700 (PDT) X-Google-Smtp-Source: APiQypKzVfRYkQQjXNmPRmmEuweWR0AsvTUy66VIOLHRJ9IcCVXdD+fbCSvkQnkvtw8EzDw2iMvttg== X-Received: by 2002:a5d:4005:: with SMTP id n5mr7830094wrp.242.1587020630785; Thu, 16 Apr 2020 00:03:50 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id o16sm26785055wrs.44.2020.04.16.00.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Apr 2020 00:03:49 -0700 (PDT) From: Vitaly Kuznetsov To: Tianjia Zhang Subject: Re: [PATCH v2] KVM: Optimize kvm_arch_vcpu_ioctl_run function In-Reply-To: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> References: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> Date: Thu, 16 Apr 2020 09:03:47 +0200 Message-ID: <878sivx67g.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200416_000358_211405_4DC7B4FD X-CRM114-Status: GOOD ( 18.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: christoffer.dall@arm.com, wanpengli@tencent.com, kvm@vger.kernel.org, david@redhat.com, benh@kernel.crashing.org, heiko.carstens@de.ibm.com, peterx@redhat.com, linux-kernel@vger.kernel.org, paulus@ozlabs.org, hpa@zytor.com, kvmarm@lists.cs.columbia.edu, linux-s390@vger.kernel.org, frankja@linux.ibm.com, mpe@ellerman.id.au, joro@8bytes.org, x86@kernel.org, borntraeger@de.ibm.com, mingo@redhat.com, julien.thierry.kdev@gmail.com, thuth@redhat.com, gor@linux.ibm.com, suzuki.poulose@arm.com, kvm-ppc@vger.kernel.org, bp@alien8.de, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, jmattson@google.com, tsbogend@alpha.franken.de, tianjia.zhang@linux.alibaba.com, cohuck@redhat.com, linux-mips@vger.kernel.org, sean.j.christopherson@intel.com, james.morse@arm.com, maz@kernel.org, pbonzini@redhat.com, linuxppc-dev@lists.ozlabs.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Tianjia Zhang writes: > In earlier versions of kvm, 'kvm_run' is an independent structure > and is not included in the vcpu structure. At present, 'kvm_run' > is already included in the vcpu structure, so the parameter > 'kvm_run' is redundant. > > This patch simplify the function definition, removes the extra > 'kvm_run' parameter, and extract it from the 'kvm_vcpu' structure > if necessary. > > Signed-off-by: Tianjia Zhang > --- > > v2 change: > remove 'kvm_run' parameter and extract it from 'kvm_vcpu' > > arch/mips/kvm/mips.c | 3 ++- > arch/powerpc/kvm/powerpc.c | 3 ++- > arch/s390/kvm/kvm-s390.c | 3 ++- > arch/x86/kvm/x86.c | 11 ++++++----- > include/linux/kvm_host.h | 2 +- > virt/kvm/arm/arm.c | 6 +++--- > virt/kvm/kvm_main.c | 2 +- > 7 files changed, 17 insertions(+), 13 deletions(-) > > diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c > index 8f05dd0a0f4e..ec24adf4857e 100644 > --- a/arch/mips/kvm/mips.c > +++ b/arch/mips/kvm/mips.c > @@ -439,8 +439,9 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > return -ENOIOCTLCMD; > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int r = -EINTR; > > vcpu_load(vcpu); > diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c > index e15166b0a16d..7e24691e138a 100644 > --- a/arch/powerpc/kvm/powerpc.c > +++ b/arch/powerpc/kvm/powerpc.c > @@ -1764,8 +1764,9 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) > return r; > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int r; > > vcpu_load(vcpu); > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c > index 19a81024fe16..443af3ead739 100644 > --- a/arch/s390/kvm/kvm-s390.c > +++ b/arch/s390/kvm/kvm-s390.c > @@ -4333,8 +4333,9 @@ static void store_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > store_regs_fmt2(vcpu, kvm_run); > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *kvm_run = vcpu->run; > int rc; > > if (kvm_run->immediate_exit) > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 3bf2ecafd027..a0338e86c90f 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -8707,8 +8707,9 @@ static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu) > trace_kvm_fpu(0); > } > > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *kvm_run = vcpu->run; > int r; > > vcpu_load(vcpu); > @@ -8726,18 +8727,18 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > r = -EAGAIN; > if (signal_pending(current)) { > r = -EINTR; > - vcpu->run->exit_reason = KVM_EXIT_INTR; > + kvm_run->exit_reason = KVM_EXIT_INTR; > ++vcpu->stat.signal_exits; > } > goto out; > } > > - if (vcpu->run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) { > + if (kvm_run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) { > r = -EINVAL; > goto out; > } > > - if (vcpu->run->kvm_dirty_regs) { > + if (kvm_run->kvm_dirty_regs) { > r = sync_regs(vcpu); > if (r != 0) > goto out; > @@ -8767,7 +8768,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) > > out: > kvm_put_guest_fpu(vcpu); > - if (vcpu->run->kvm_valid_regs) > + if (kvm_run->kvm_valid_regs) > store_regs(vcpu); > post_kvm_run_save(vcpu); > kvm_sigset_deactivate(vcpu); > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 6d58beb65454..1e17ef719595 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -866,7 +866,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, > struct kvm_mp_state *mp_state); > int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, > struct kvm_guest_debug *dbg); > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run); > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu); > > int kvm_arch_init(void *opaque); > void kvm_arch_exit(void); > diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c > index 48d0ec44ad77..f5390ac2165b 100644 > --- a/virt/kvm/arm/arm.c > +++ b/virt/kvm/arm/arm.c > @@ -639,7 +639,6 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) > /** > * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code > * @vcpu: The VCPU pointer > - * @run: The kvm_run structure pointer used for userspace state exchange > * > * This function is called through the VCPU_RUN ioctl called from user space. It > * will execute VM code in a loop until the time slice for the process is used > @@ -647,8 +646,9 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu) > * return with return value 0 and with the kvm_run structure filled in with the > * required data for the requested emulation. > */ > -int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > +int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > { > + struct kvm_run *run = vcpu->run; > int ret; > > if (unlikely(!kvm_vcpu_initialized(vcpu))) > @@ -659,7 +659,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) > return ret; > > if (run->exit_reason == KVM_EXIT_MMIO) { > - ret = kvm_handle_mmio_return(vcpu, vcpu->run); > + ret = kvm_handle_mmio_return(vcpu, run); I don't know much about ARM but this also seems redundant, kvm_handle_mmio_return() is also able to extruct 'struct kvm_run' from' 'struct kvm_vcpu'. This likely deserves it's own patch though. > if (ret) > return ret; > } > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 74bdb7bf3295..e18faea89146 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -3135,7 +3135,7 @@ static long kvm_vcpu_ioctl(struct file *filp, > synchronize_rcu(); > put_pid(oldpid); > } > - r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run); > + r = kvm_arch_vcpu_ioctl_run(vcpu); > trace_kvm_userspace_exit(vcpu->run->exit_reason, r); > break; > } Looked at non-x86 arches just briefly but there seems to be no controversy here, so Reviewed-by: Vitaly Kuznetsov -- Vitaly _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel