Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2202156ioo; Mon, 23 May 2022 12:33:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsbkDN6BvCu6vA8HiTgoWLizn62H1ukBZPaczwAMwLuNp5EnrQZxoiMfMJHkALruS7WbBW X-Received: by 2002:a63:6c2:0:b0:3fa:9372:bc75 with SMTP id 185-20020a6306c2000000b003fa9372bc75mr1983801pgg.568.1653334392707; Mon, 23 May 2022 12:33:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653334392; cv=none; d=google.com; s=arc-20160816; b=DbPxyaNJ4bPmhF/hbBrR58ZDYR0Wn1kGoneMKZx1usR381hVOdXmStg0xVr1FQ4Y6X DET8/3jDZUOpvHituUWxPYmj15NnMPsBmAaYEKOY2enSTNu48gfvg5wvfw1DTpwDlp1h ZZ/+DlKBbDhECz2rTiakNae+XjRUJXp4NkMIZqptCp/g/B2HanplSa+OJYx0lh4LkS79 V1X+uSVbpvTiZ53rgRTkqbDS9jHWVjDowZz1VtkaDeyVA5sHRh+rk5xUIqeQzswXTkU7 cpZDxlMpW6sg4kqbF/CX2eY8g/ubKFTnmKIl3DcyJXGmeP/MoLbeF/3IveTFx4cfs3ME VTbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=HHNIPUsJDbBFJZh22t/jyDNYIOXLs4DuR2SaQZ0oOdk=; b=y3XPR7ipGgzKL6A0+6mavDCm1+mcNy0lYwxcFn2TlSLTp6yiqCD+0msHzs4MPM4gxb BYaOGinhqDBIQe/lRCvbFAzuKOLpMgQ4EK0ABZcaq6+U36uethQWtBxDJ4L9Ul5gtl5B IT21ym6qJolywjIV7nvRtZbunPj7uFazQ2q9ikxOSVBXp7cTtdtweD025P/KnoEit2nC ZQFj0wLNkBjnLmcV0TBmdruOBhdOnVwx2aS66Q2u1nvp6Cjl5vNfFwjmeroU68zONcSr IfJE8m2pojpEhniep3ESCJ50kUIdeEcsplm05Zz2AU0GyaIYMV1/nQAgo1NaGy7WXiyz UStA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bitbyteword.org header.s=google header.b=OHGWjxZ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m16-20020a17090a7f9000b001caa43d9645si186402pjl.95.2022.05.23.12.33.00; Mon, 23 May 2022 12:33:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bitbyteword.org header.s=google header.b=OHGWjxZ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229706AbiEWTYz (ORCPT + 99 others); Mon, 23 May 2022 15:24:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbiEWTYZ (ORCPT ); Mon, 23 May 2022 15:24:25 -0400 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDFAB16F365 for ; Mon, 23 May 2022 12:03:32 -0700 (PDT) Received: by mail-qv1-xf36.google.com with SMTP id l1so12778843qvh.1 for ; Mon, 23 May 2022 12:03:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitbyteword.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HHNIPUsJDbBFJZh22t/jyDNYIOXLs4DuR2SaQZ0oOdk=; b=OHGWjxZ43RVGglH0ZBaek/zekCwJXQ2me+plJ95APbCUPJDRlsu/w2lrn8zTe4mHJv TeX2VBxIgthP+O3K/6u3vFvFZL3kFGXQT0PePQ3yBvaoCsECP/6etaACqtkWm9m+yE/N 1pmilsdldoHfCzImdAfScR2AeKtXiX68NUU4XE0eMvp9L0p+UUdjctazUkl0Ud9FwMZT L71eJv3qSP2F1gmdjI+8Lf9SPqVXWScvEgOQd6QA8o5hMM5YMtZaBUeQAismPhJ8BQ2V P4IVMVLLUtrSNXp4zJgsaGSk849FwhVe/D+dVKnMG+oDEK+e7BNh5WsgeYn3WcMWHJuU tJag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HHNIPUsJDbBFJZh22t/jyDNYIOXLs4DuR2SaQZ0oOdk=; b=osfbXJNY8pqkNFa7SZLOzXrTaylxfniGLZNIpqmR319fS0jxjObGijplXDGhAvU0Us ouWJbQoO763RCb1Lvf8MvV1402Ev0QAZR+9wZ9WQo/QC+x2DNzkHnx91nVGcdT+jH0BA VIOsxMpC7pwet5kV/ojPBnxkbrTljtsChX1kLhYJYBKDOLzGLeowPXo5xathiWQ26A85 +R7cecXBAewdh+Slnm1ZDrfTmbyOlP7IhGTU5T7gYY8P1Hrp1+nIA/27UE5rxX8L1gmq O8CeGfJrsIj/PfowaQ7YLUhDmNGxYp81pE6pKiYfu4NSXXstHZNTN1LKzF/vf8yRZvWQ d8qQ== X-Gm-Message-State: AOAM533nK6YaO9wEViYMWPZTthnutfvsnPj5uZrzTwyuj60fpeuKJlsN 0fYet3ZMbGOSvtq+eSQ4UHXU47HFhNObIw== X-Received: by 2002:a05:6214:ac3:b0:461:c492:d628 with SMTP id g3-20020a0562140ac300b00461c492d628mr18287853qvi.68.1653332611240; Mon, 23 May 2022 12:03:31 -0700 (PDT) Received: from vinmini.lan (c-73-38-52-84.hsd1.vt.comcast.net. [73.38.52.84]) by smtp.gmail.com with ESMTPSA id q10-20020ac8450a000000b002f3ca56e6edsm4809279qtn.8.2022.05.23.12.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 12:03:30 -0700 (PDT) From: "Vineeth Pillai (Google)" To: Paolo Bonzini , kvm@vger.kernel.org Cc: Vineeth Pillai , linux-kernel@vger.kernel.org, Steven Rostedt , Joel Fernandes Subject: [PATCH] KVM: debugfs: expose pid of vcpu threads Date: Mon, 23 May 2022 15:03:27 -0400 Message-Id: <20220523190327.2658-1-vineeth@bitbyteword.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vineeth Pillai Add a new debugfs file to expose the pid of each vcpu threads. This is very helpful for userland tools to get the vcpu pids without worrying about thread naming conventions of the VMM. Signed-off-by: Vineeth Pillai (Google) --- include/linux/kvm_host.h | 2 ++ virt/kvm/kvm_main.c | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 34eed5f85ed6..c2c86fce761c 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1434,6 +1434,8 @@ int kvm_arch_pm_notifier(struct kvm *kvm, unsigned long state); #ifdef __KVM_HAVE_ARCH_VCPU_DEBUGFS void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry); +#else +static inline void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu) {} #endif int kvm_arch_hardware_enable(void); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 5ab12214e18d..9bb1dbf51c90 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3723,9 +3723,18 @@ static int create_vcpu_fd(struct kvm_vcpu *vcpu) return anon_inode_getfd(name, &kvm_vcpu_fops, vcpu, O_RDWR | O_CLOEXEC); } +#ifdef __KVM_HAVE_ARCH_VCPU_DEBUGFS +static int vcpu_get_pid(void *data, u64 *val) +{ + struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data; + *val = pid_nr(rcu_access_pointer(vcpu->pid)); + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(vcpu_get_pid_fops, vcpu_get_pid, NULL, "%llu\n"); + static void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu) { -#ifdef __KVM_HAVE_ARCH_VCPU_DEBUGFS struct dentry *debugfs_dentry; char dir_name[ITOA_MAX_LEN * 2]; @@ -3735,10 +3744,12 @@ static void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu) snprintf(dir_name, sizeof(dir_name), "vcpu%d", vcpu->vcpu_id); debugfs_dentry = debugfs_create_dir(dir_name, vcpu->kvm->debugfs_dentry); + debugfs_create_file("pid", 0444, debugfs_dentry, vcpu, + &vcpu_get_pid_fops); kvm_arch_create_vcpu_debugfs(vcpu, debugfs_dentry); -#endif } +#endif /* * Creates some virtual cpus. Good luck creating more than one. -- 2.34.1