From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoffer Dall Subject: Re: [RFC v2 PATCH 2/7] KVM: Track the pid of the VM process Date: Tue, 6 Sep 2016 12:25:42 +0200 Message-ID: <20160906102542.GG30513@cbox> References: <1473093097-30932-1-git-send-email-punit.agrawal@arm.com> <1473093097-30932-3-git-send-email-punit.agrawal@arm.com> <20160906062252.GA30513@cbox> <87poohjqzk.fsf@e105922-lin.cambridge.arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Return-path: Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id E32F849B49 for ; Tue, 6 Sep 2016 06:14:52 -0400 (EDT) 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 nWqje3BbDqdq for ; Tue, 6 Sep 2016 06:14:50 -0400 (EDT) Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 9809349B3F for ; Tue, 6 Sep 2016 06:14:50 -0400 (EDT) Received: by mail-wm0-f41.google.com with SMTP id w12so82954836wmf.0 for ; Tue, 06 Sep 2016 03:23:14 -0700 (PDT) Content-Disposition: inline In-Reply-To: <87poohjqzk.fsf@e105922-lin.cambridge.arm.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu To: Punit Agrawal Cc: kvm@vger.kernel.org, Marc Zyngier , Will Deacon , linux-kernel@vger.kernel.org, Steven Rostedt , Ingo Molnar , Paolo Bonzini , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org List-Id: kvmarm@lists.cs.columbia.edu T24gVHVlLCBTZXAgMDYsIDIwMTYgYXQgMTA6NTE6MjdBTSArMDEwMCwgUHVuaXQgQWdyYXdhbCB3 c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u ZyBmb3IgYWxsIHZjcHUgdGhyZWFkcyBhbmQgdGhhdCB0aGUgdGdpZCBkb2Vzbid0IHdvcmsKaW4g dGhpcyBjYXNlPwoKVGhhbmtzLAotQ2hyaXN0b2ZmZXIKX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX18Ka3ZtYXJtIG1haWxpbmcgbGlzdAprdm1hcm1AbGlzdHMu Y3MuY29sdW1iaWEuZWR1Cmh0dHBzOi8vbGlzdHMuY3MuY29sdW1iaWEuZWR1L21haWxtYW4vbGlz dGluZm8va3ZtYXJtCg== From mboxrd@z Thu Jan 1 00:00:00 1970 From: christoffer.dall@linaro.org (Christoffer Dall) Date: Tue, 6 Sep 2016 12:25:42 +0200 Subject: [RFC v2 PATCH 2/7] KVM: Track the pid of the VM process In-Reply-To: <87poohjqzk.fsf@e105922-lin.cambridge.arm.com> References: <1473093097-30932-1-git-send-email-punit.agrawal@arm.com> <1473093097-30932-3-git-send-email-punit.agrawal@arm.com> <20160906062252.GA30513@cbox> <87poohjqzk.fsf@e105922-lin.cambridge.arm.com> Message-ID: <20160906102542.GG30513@cbox> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Tue, Sep 06, 2016 at 10:51:27AM +0100, Punit Agrawal wrote: > Hi Christoffer, > > Christoffer Dall writes: > > > On Mon, Sep 05, 2016 at 05:31:32PM +0100, Punit Agrawal wrote: > >> Userspace tools such as perf can be used to profile individual > >> processes. > >> > >> Track the PID of the virtual machine process to match profiling requests > >> targeted at it. This can be used to take appropriate action to enable > >> the requested profiling operations for the VMs of interest. > >> > >> Signed-off-by: Punit Agrawal > >> Cc: Paolo Bonzini > >> Cc: "Radim Kr?m??" > >> Cc: Christoffer Dall > >> Cc: Marc Zyngier > >> --- > >> include/linux/kvm_host.h | 1 + > >> virt/kvm/kvm_main.c | 2 ++ > >> 2 files changed, 3 insertions(+) > >> > >> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > >> index 9c28b4d..7c42c94 100644 > >> --- a/include/linux/kvm_host.h > >> +++ b/include/linux/kvm_host.h > >> @@ -374,6 +374,7 @@ struct kvm_memslots { > >> struct kvm { > >> spinlock_t mmu_lock; > >> struct mutex slots_lock; > >> + struct pid *pid; > >> struct mm_struct *mm; /* userspace tied to this vm */ > >> struct kvm_memslots *memslots[KVM_ADDRESS_SPACE_NUM]; > >> struct srcu_struct srcu; > >> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > >> index 1950782..ab2535a 100644 > >> --- a/virt/kvm/kvm_main.c > >> +++ b/virt/kvm/kvm_main.c > >> @@ -613,6 +613,7 @@ static struct kvm *kvm_create_vm(unsigned long type) > >> spin_lock_init(&kvm->mmu_lock); > >> atomic_inc(¤t->mm->mm_count); > >> kvm->mm = current->mm; > >> + kvm->pid = get_task_pid(current, PIDTYPE_PID); > > > > How dooes this deal with threading? Is the idea that the user by > > specifying the main thread's pid will enable trapping for all vcpu > > threads belonging to that VM? > > Yes that's correct - specifying the main thread PID will enable trapping > for the VM (all vcpus). > > I am happy to move to a more suitable identifier if available. > What is the 'main thread' ? Does something mandate that the VM is created by the thread group leader? If not, is it not a bit strange from a user perspective, that you have to find the specific subthread pid that created the vm to enable this tracing for all vcpu threads and that the tgid doesn't work in this case? Thanks, -Christoffer From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934909AbcIFKXS (ORCPT ); Tue, 6 Sep 2016 06:23:18 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:38584 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934882AbcIFKXP (ORCPT ); Tue, 6 Sep 2016 06:23:15 -0400 Date: Tue, 6 Sep 2016 12:25:42 +0200 From: Christoffer Dall To: Punit Agrawal Cc: kvm@vger.kernel.org, Marc Zyngier , Will Deacon , linux-kernel@vger.kernel.org, Steven Rostedt , Ingo Molnar , Paolo Bonzini , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: Re: [RFC v2 PATCH 2/7] KVM: Track the pid of the VM process Message-ID: <20160906102542.GG30513@cbox> References: <1473093097-30932-1-git-send-email-punit.agrawal@arm.com> <1473093097-30932-3-git-send-email-punit.agrawal@arm.com> <20160906062252.GA30513@cbox> <87poohjqzk.fsf@e105922-lin.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87poohjqzk.fsf@e105922-lin.cambridge.arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 06, 2016 at 10:51:27AM +0100, Punit Agrawal wrote: > Hi Christoffer, > > Christoffer Dall writes: > > > On Mon, Sep 05, 2016 at 05:31:32PM +0100, Punit Agrawal wrote: > >> Userspace tools such as perf can be used to profile individual > >> processes. > >> > >> Track the PID of the virtual machine process to match profiling requests > >> targeted at it. This can be used to take appropriate action to enable > >> the requested profiling operations for the VMs of interest. > >> > >> Signed-off-by: Punit Agrawal > >> Cc: Paolo Bonzini > >> Cc: "Radim Krčmář" > >> Cc: Christoffer Dall > >> Cc: Marc Zyngier > >> --- > >> include/linux/kvm_host.h | 1 + > >> virt/kvm/kvm_main.c | 2 ++ > >> 2 files changed, 3 insertions(+) > >> > >> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > >> index 9c28b4d..7c42c94 100644 > >> --- a/include/linux/kvm_host.h > >> +++ b/include/linux/kvm_host.h > >> @@ -374,6 +374,7 @@ struct kvm_memslots { > >> struct kvm { > >> spinlock_t mmu_lock; > >> struct mutex slots_lock; > >> + struct pid *pid; > >> struct mm_struct *mm; /* userspace tied to this vm */ > >> struct kvm_memslots *memslots[KVM_ADDRESS_SPACE_NUM]; > >> struct srcu_struct srcu; > >> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > >> index 1950782..ab2535a 100644 > >> --- a/virt/kvm/kvm_main.c > >> +++ b/virt/kvm/kvm_main.c > >> @@ -613,6 +613,7 @@ static struct kvm *kvm_create_vm(unsigned long type) > >> spin_lock_init(&kvm->mmu_lock); > >> atomic_inc(¤t->mm->mm_count); > >> kvm->mm = current->mm; > >> + kvm->pid = get_task_pid(current, PIDTYPE_PID); > > > > How dooes this deal with threading? Is the idea that the user by > > specifying the main thread's pid will enable trapping for all vcpu > > threads belonging to that VM? > > Yes that's correct - specifying the main thread PID will enable trapping > for the VM (all vcpus). > > I am happy to move to a more suitable identifier if available. > What is the 'main thread' ? Does something mandate that the VM is created by the thread group leader? If not, is it not a bit strange from a user perspective, that you have to find the specific subthread pid that created the vm to enable this tracing for all vcpu threads and that the tgid doesn't work in this case? Thanks, -Christoffer