From patchwork Mon Nov 23 14:06:06 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 62178 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nANEBoTO018662 for ; Mon, 23 Nov 2009 14:11:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753853AbZKWOJx (ORCPT ); Mon, 23 Nov 2009 09:09:53 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754629AbZKWOJw (ORCPT ); Mon, 23 Nov 2009 09:09:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48288 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754474AbZKWOJs (ORCPT ); Mon, 23 Nov 2009 09:09:48 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nANE9Bmg003047 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 23 Nov 2009 09:09:12 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nANE7saJ031601; Mon, 23 Nov 2009 09:09:11 -0500 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 564A018D476; Mon, 23 Nov 2009 16:06:08 +0200 (IST) From: Gleb Natapov To: kvm@vger.kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, avi@redhat.com, mingo@elte.hu, a.p.zijlstra@chello.nl, tglx@linutronix.de, hpa@zytor.com, riel@redhat.com Subject: [PATCH v2 11/12] Handle async PF in non preemptable context. Date: Mon, 23 Nov 2009 16:06:06 +0200 Message-Id: <1258985167-29178-12-git-send-email-gleb@redhat.com> In-Reply-To: <1258985167-29178-1-git-send-email-gleb@redhat.com> References: <1258985167-29178-1-git-send-email-gleb@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 09444c9..0836d9a 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -63,6 +63,7 @@ struct kvm_task_sleep_node { struct hlist_node link; wait_queue_head_t wq; u32 token; + int cpu; }; static struct kvm_task_sleep_head { @@ -91,6 +92,11 @@ static void apf_task_wait(struct task_struct *tsk, u32 token) struct kvm_task_sleep_head *b = &async_pf_sleepers[key]; struct kvm_task_sleep_node n, *e; DEFINE_WAIT(wait); + int cpu, idle; + + cpu = get_cpu(); + idle = idle_cpu(cpu); + put_cpu(); spin_lock(&b->lock); e = _find_apf_task(b, token); @@ -105,15 +111,30 @@ static void apf_task_wait(struct task_struct *tsk, u32 token) n.token = token; init_waitqueue_head(&n.wq); hlist_add_head(&n.link, &b->list); + if (idle || preempt_count() > 1) + n.cpu = smp_processor_id(); + else + n.cpu = -1; spin_unlock(&b->lock); for (;;) { - prepare_to_wait(&n.wq, &wait, TASK_UNINTERRUPTIBLE); + if (n.cpu < 0) + prepare_to_wait(&n.wq, &wait, TASK_UNINTERRUPTIBLE); if (hlist_unhashed(&n.link)) break; - schedule(); + + if (n.cpu < 0) { + schedule(); + } else { + /* + * We cannot reschedule. So halt. + */ + native_safe_halt(); + local_irq_disable(); + } } - finish_wait(&n.wq, &wait); + if (n.cpu < 0) + finish_wait(&n.wq, &wait); return; } @@ -146,7 +167,9 @@ again: hlist_add_head(&n->link, &b->list); } else { hlist_del_init(&n->link); - if (waitqueue_active(&n->wq)) + if (n->cpu >= 0) + smp_send_reschedule(n->cpu); + else if (waitqueue_active(&n->wq)) wake_up(&n->wq); } spin_unlock(&b->lock);