Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp733928imm; Sat, 1 Sep 2018 19:23:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaM0kIn6UJaXhD3auW5ccfpyYk3BNCGD9JgiAYdh0bPe97H7yiJXsIHgs4+gIQYnx5TY0wA X-Received: by 2002:a17:902:8bc4:: with SMTP id r4-v6mr21547417plo.124.1535854992653; Sat, 01 Sep 2018 19:23:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535854992; cv=none; d=google.com; s=arc-20160816; b=E65bW9FohAly/1YdpY7bCP2ablJhd270P+wZPK36HyudpZPu+mUbrnjFLO/7xD0j2G hIqpaBigLS8lfg8araViLDB6yFqFzMCcwvyMwmYf2uTJ76cbvUqauy6/dTtB0HF7P+/e 1QDLY9CwUrQDxVPi9jsaDYhIw8u8GW7BCk7z5UTT0u/g7/eR1GCzLbQam5x9PC6xFWw+ mqOghHqQ4erOjXNKGIOGtCH4vT5782rGQebemzTH6hNfmZ/hcaKjnvjdIec8zj4rp8tM E1QzXhYo+h9oibkoPTNWoq+w0V4rbDLmDSA9kBYceLY+3vq4/K3oP8prDlrhi+MEWdTm VY1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:lines:content-disposition:mime-version :references:subject:cc:cc:cc:cc:cc:cc:cc:cc:cc:to:from:date :user-agent:message-id:arc-authentication-results; bh=egbTjjM1xgoMT7s6K9WQMwtm1Lb83qyQoJhWtdvDkhc=; b=etlVCIPcntYud5K6CHjmkyZdByoqfDBf7AmHjBq/7LJWA63lsWiPiI7LVDbr4/dmS3 Vq08vk/sUcC20apZ0MosgEVC/xmvYDKZQJhYUc67ORzokVpEpLvPW4ecLwmR+g1imGjl iaicK8qfQO/F7K/3A+uznaH/T0iWVudCYoebqENuovWSrNDg3xXrhY4dq3xG9MsJ5Tmx suF94ZjIkHfqGDxJs+5pp14be1G/CYmzyGvVKoc6cWSHF9ScrWOwE4SrlvNCUEJpVHP4 spqyanibPgUZYUxIq6ck1kQKzW9HqOHG/wgrPr3rM8Mxomri/M5iW2Oz7W1kYIXSHMrE LYJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k6-v6si12773309pls.426.2018.09.01.19.22.58; Sat, 01 Sep 2018 19:23:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727053AbeIBGfJ (ORCPT + 99 others); Sun, 2 Sep 2018 02:35:09 -0400 Received: from mga18.intel.com ([134.134.136.126]:13094 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725941AbeIBGfJ (ORCPT ); Sun, 2 Sep 2018 02:35:09 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Sep 2018 19:21:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,318,1531810800"; d="scan'208";a="80211544" Received: from dbxu-mobl.ccr.corp.intel.com (HELO wfg-t570.sh.intel.com) ([10.254.212.218]) by orsmga003.jf.intel.com with ESMTP; 01 Sep 2018 19:20:58 -0700 Received: from wfg by wfg-t570.sh.intel.com with local (Exim 4.89) (envelope-from ) id 1fwI0X-0003Za-5R; Sun, 02 Sep 2018 10:20:57 +0800 Message-Id: <20180901124811.469883138@intel.com> User-Agent: quilt/0.63-1 Date: Sat, 01 Sep 2018 19:28:19 +0800 From: Fengguang Wu To: Andrew Morton cc: Linux Memory Management List , Fengguang Wu cc: Peng DongX cc: Liu Jingqi cc: Dong Eddie CC: Dave Hansen cc: Huang Ying CC: Brendan Gregg cc: kvm@vger.kernel.org Cc: LKML Subject: [RFC][PATCH 1/5] [PATCH 1/5] kvm: register in task_struct References: <20180901112818.126790961@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=0001-kvm-register-in-task_struct.patch Content-Length: 1975 Lines: 64 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The added pointer will be used by the /proc/PID/idle_bitmap code to quickly identify QEMU task and walk EPT/NPT accordingly. For virtual machines, the A bits will be set in guest page tables and EPT/NPT, rather than the QEMU task page table. This costs 8 bytes in task_struct which could be wasteful for the majority normal tasks. The alternative is to add a flag only, and let it find the corresponding VM in kvm vm_list. Signed-off-by: Fengguang Wu --- include/linux/sched.h | 10 ++++++++++ virt/kvm/kvm_main.c | 1 + 2 files changed, 11 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index 43731fe51c97..26c8549bbc28 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -38,6 +38,7 @@ struct cfs_rq; struct fs_struct; struct futex_pi_state; struct io_context; +struct kvm; struct mempolicy; struct nameidata; struct nsproxy; @@ -1179,6 +1180,9 @@ struct task_struct { /* Used by LSM modules for access restriction: */ void *security; #endif +#if IS_ENABLED(CONFIG_KVM) + struct kvm *kvm; +#endif /* * New fields for task_struct should be added above here, so that @@ -1898,4 +1902,10 @@ static inline void rseq_syscall(struct pt_regs *regs) #endif +#if IS_ENABLED(CONFIG_KVM) +static inline struct kvm *task_kvm(struct task_struct *t) { return t->kvm; } +#else +static inline struct kvm *task_kvm(struct task_struct *t) { return NULL; } +#endif + #endif diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 8b47507faab5..0c483720de8d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3892,6 +3892,7 @@ static void kvm_uevent_notify_change(unsigned int type, struct kvm *kvm) if (type == KVM_EVENT_CREATE_VM) { add_uevent_var(env, "EVENT=create"); kvm->userspace_pid = task_pid_nr(current); + current->kvm = kvm; } else if (type == KVM_EVENT_DESTROY_VM) { add_uevent_var(env, "EVENT=destroy"); } -- 2.15.0