Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1675374ybz; Thu, 16 Apr 2020 13:27:29 -0700 (PDT) X-Google-Smtp-Source: APiQypLcyFtZPhhggt+tzuPevC2IUvyq5FlqCTLWCxFnG9g1uEGy8nCR3a07DYfN8tValUqukVje X-Received: by 2002:a17:907:41b3:: with SMTP id na3mr4807535ejb.250.1587068849445; Thu, 16 Apr 2020 13:27:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587068849; cv=none; d=google.com; s=arc-20160816; b=pe6frgPdKg5ODvndmPD4ltg5Un3+EAgWTblDeXyTB3Yi8t9W5rwLtek0zwEyqn6wbC vP4akfi3CZ3YZ15SUjdB1+IheGEptxy+ddIlnLZy0WcS9RlOtv+TCGXzpNPLra+yavpW na0N2Akfk/ykP1cDeqFEb4EUyTaHPpE3dTYB+x56C3e1KrsWu+zSm/lqfg3UXaCkEAjO aWoBihM0E3hym5bAMDVEnqyRfpoEmbsKx261GtP2N2iD/YBb+m4coktcGlLinC9WPpmd 2JnwEPBUgd3yUUlQt/bbyDH6WMspw6AG88etaGwaTSDpmUndoGGwLNolcaB9FpubJoS7 8JJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=7hnF0DDKrlu0/wsAOrUaDsyzDUw85QJZaEcoKNO3lxk=; b=Ox3dmpCjggbbsaAEMsAoRDgz3Vt/8B6+B/9nntoZOl4NOFMF1jX7xKwoLmoODAEvvW dusmhlVhJEBhY2PNKuA+IggXoRfh9T0S1ena9bJZs5pgodyyq9+e/iQJ+yFk7N9fZQJo i49PD+NnGQa/sJpNdXTdqlDJRy6d+zVeSFrAFli2518rIKGTVcqTAM66ZBoEcG1wn3NG 2uYkOIP3hWCFcddPOdyCtxyT2+1pDUz5V7zH4ZiE6apBVJGPj29ZnYkHpvGWzEMEgfR0 dgZnoYUfXRxlCRHMGkqhJP9lIaY/N96YN4o3320Sj7k33StUoVIaUlosFefMU1lYYIIH LDjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SvYdGZ3a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p6si12600327ejj.173.2020.04.16.13.27.06; Thu, 16 Apr 2020 13:27:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SvYdGZ3a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731181AbgDPOf7 (ORCPT + 99 others); Thu, 16 Apr 2020 10:35:59 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:33408 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2393845AbgDPOQx (ORCPT ); Thu, 16 Apr 2020 10:16:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587046611; 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=7hnF0DDKrlu0/wsAOrUaDsyzDUw85QJZaEcoKNO3lxk=; b=SvYdGZ3aB2HM4vGJZC4IJZMI5Ghn/QhCJUyzgirtfYUn5edLNd94S0dQ7aJT23gG+tZb/N hQgrpphHu1TUJukhuqbxXYToC1nH3oYw1m/FEd2eb7wdlaf+LB+wgs4ROE0hMnt4dL/yE8 oXFWXd0CXJxn6pIHQrrTEQXC4E23Vew= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-423-pPv6Si5HPcWKv6XL_H4bZA-1; Thu, 16 Apr 2020 10:16:49 -0400 X-MC-Unique: pPv6Si5HPcWKv6XL_H4bZA-1 Received: by mail-wr1-f72.google.com with SMTP id e5so1754555wrs.23 for ; Thu, 16 Apr 2020 07:16:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=7hnF0DDKrlu0/wsAOrUaDsyzDUw85QJZaEcoKNO3lxk=; b=CR8a4vFEr2tSuTIdZucn0CDTGFp4no21yE86lbqlI6OlmeLGm5zV8etdMMGLpFs28n yjTMHYkP7QmoibqXjsUlXS2loWzv1E4rd9vDhXC9CddMHmX4jvEuUzl0iS31MX2u97G9 qQKSrQfyec39sm/wF3gJfkVnziPi9iBSwKKi+N2A2vJQOvP+Dx6kukBOiP4xLfsUnhjw Gvx818YniTMQt711n57h++sV1CsuVEtLXdRnyrxKxD6mE1n8WccOTUGphEjEIustCn96 nHre4vf494eOmfH0S3IrB+6Y1tVfi8s6/ZMGw+dBQbaPJksAhmo4bN4h5rcI1HDRt6iT 289A== X-Gm-Message-State: AGi0PuZzHLt30ZVsq+jGmSFhwmR8xnS2tquXtHAkixfD04SxLVdbNUKa 1Y1NQaI1Hh4qltkUxOVVfSmqEL0WV7mx+8I6zl9fua5Y75onNnY7jgqoRQR1z0MIv6erQchBus5 9ZRNy0oGtXXHvjKIKtHobAaVt X-Received: by 2002:a5d:6584:: with SMTP id q4mr24139441wru.403.1587046608291; Thu, 16 Apr 2020 07:16:48 -0700 (PDT) X-Received: by 2002:a5d:6584:: with SMTP id q4mr24139399wru.403.1587046607973; Thu, 16 Apr 2020 07:16:47 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:399d:3ef7:647c:b12d? ([2001:b07:6468:f312:399d:3ef7:647c:b12d]) by smtp.gmail.com with ESMTPSA id d133sm4118344wmc.27.2020.04.16.07.16.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Apr 2020 07:16:47 -0700 (PDT) Subject: Re: [PATCH v2] KVM: Optimize kvm_arch_vcpu_ioctl_run function To: Tianjia Zhang , 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, vkuznets@redhat.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 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 References: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> From: Paolo Bonzini Message-ID: Date: Thu, 16 Apr 2020 16:16:44 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200416051057.26526-1-tianjia.zhang@linux.alibaba.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/04/20 07:10, Tianjia Zhang wrote: > 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); > 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; > } > Queued, thanks. Paolo