From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: unit tests and get_user_pages_ptes_fast() Date: Mon, 04 Oct 2010 11:35:28 +0200 Message-ID: <4CA99FE0.7070709@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: Andrea Arcangeli To: KVM list Return-path: Received: from mx1.redhat.com ([209.132.183.28]:20505 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753961Ab0JDJfc (ORCPT ); Mon, 4 Oct 2010 05:35:32 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o949ZWjU022941 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 4 Oct 2010 05:35:32 -0400 Sender: kvm-owner@vger.kernel.org List-ID: During the last kvm forum, I described a unit test framework that can help test the kvm APIs. Briefly, it starts a process in host userspace, which sets up a memory slot mapping gpa 0:3G to hva 0:3G. It then sets up guest registers for unpaged protected mode (or paged protected mode with 1:1 mapping). The effect is that we have a 1:1 gva->hva translation, and can use KVM_RUN to run host code in guest mode. There is a snag however. kvm calls get_user_pages_fast(.write = 1), and the host process maps its code pages read-only. The way I'd like to work around this is to map read-only accesses to read-only pages as read-only. This also prevents ksm cow pages from being broken by read accesses. It can also be used to get the page size for transparent huge pages (and later hugetlbfs too). So, for a read fault we do: pte_t pte; get_user_pages_ptes_fast(..., page, &pte, 1, .write = 0) ... if (pte_transhuge(pte)) // or however it's called ... ... if (pte_write(pte)) map writeable else map readonly Any snags? or alternatives? -- error compiling committee.c: too many arguments to function