From patchwork Wed Aug 20 09:13:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 35685 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f70.google.com (mail-qg0-f70.google.com [209.85.192.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0E48C20351 for ; Wed, 20 Aug 2014 09:16:54 +0000 (UTC) Received: by mail-qg0-f70.google.com with SMTP id i50sf14471956qgf.9 for ; Wed, 20 Aug 2014 02:16:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id:cc :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=4tcxUsd161Xav6kDEWGqRpJ84nWRMkdi+5hfsl2rGcw=; b=abmvQoV4IUz1t9UA/LNgCFSEBRZaxnAo/WVN+fjA8g0MluaIWFJXb+cJQqgQd+NtJr R8qMSApm29A8s/MEkswSXjoi8JWUG+yl+c+F7MsaNcNJKpcM9hptq4TMuTFQrLiFTmld SO0fys9xnttBN5OrFzzs1RLZ6ZotTUb9HfmMPCYCKOfHM7/Ic58DCaWAG/8i9vG9X1/R oxqCWRmCl2YxEMcdm8dLcPq4n2p528I6fR2dm7uud6YOIhm6705y9jH2hcfew5JvCGal mZvZ6gd7lL4soZ/ei9iGVG8C45aedKAv5TnHi7G/GkBF9Iwfgn1253Alx00mdIoyl0Vz O+tw== X-Gm-Message-State: ALoCoQkG6qRRH+zNMaLN2uLn78WFxia2oENd4OQ/4xaLVRUH4C3dguJBl6//56cYRnSgz9XEB1jH X-Received: by 10.236.150.110 with SMTP id y74mr23980106yhj.7.1408526213859; Wed, 20 Aug 2014 02:16:53 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.228 with SMTP id d91ls198991qge.41.gmail; Wed, 20 Aug 2014 02:16:53 -0700 (PDT) X-Received: by 10.52.243.10 with SMTP id wu10mr5100079vdc.45.1408526213751; Wed, 20 Aug 2014 02:16:53 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id rw10si10324028vcb.44.2014.08.20.02.16.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 20 Aug 2014 02:16:53 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id hy4so8637668vcb.22 for ; Wed, 20 Aug 2014 02:16:53 -0700 (PDT) X-Received: by 10.52.119.229 with SMTP id kx5mr203886vdb.40.1408526213686; Wed, 20 Aug 2014 02:16:53 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp37869vcb; Wed, 20 Aug 2014 02:16:53 -0700 (PDT) X-Received: by 10.224.1.196 with SMTP id 4mr74742157qag.99.1408526212297; Wed, 20 Aug 2014 02:16:52 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id u10si33073195qcc.6.2014.08.20.02.16.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Aug 2014 02:16:52 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XK1y4-0007fb-GH; Wed, 20 Aug 2014 09:14:08 +0000 Received: from mail-la0-f52.google.com ([209.85.215.52]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XK1y1-0007cu-CO for linux-arm-kernel@lists.infradead.org; Wed, 20 Aug 2014 09:14:05 +0000 Received: by mail-la0-f52.google.com with SMTP id b17so6811504lan.25 for ; Wed, 20 Aug 2014 02:13:42 -0700 (PDT) X-Received: by 10.152.5.102 with SMTP id r6mr40278219lar.81.1408526022227; Wed, 20 Aug 2014 02:13:42 -0700 (PDT) Received: from localhost.localdomain (188-178-240-98-static.dk.customer.tdc.net. [188.178.240.98]) by mx.google.com with ESMTPSA id a4sm1028470lae.1.2014.08.20.02.13.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Aug 2014 02:13:41 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Subject: [PATCH v2 1/2] KVM: Introduce gfn_to_hva_memslot_prot Date: Wed, 20 Aug 2014 11:13:35 +0200 Message-Id: <1408526016-4696-1-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.0.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140820_021405_602297_95A2D83E X-CRM114-Status: GOOD ( 11.30 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.215.52 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.215.52 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Peter Maydell , Alex Bennee , Christoffer Dall , Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: christoffer.dall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 To support read-only memory regions on arm and arm64, we have a need to resolve a gfn to an hva given a pointer to a memslot to avoid looping through the memslots twice and to reuse the hva error checking of gfn_to_hva_prot(), add a new gfn_to_hva_memslot_prot() function and refactor gfn_to_hva_prot() to use this function. Acked-by: Marc Zyngier Signed-off-by: Christoffer Dall --- Changelog[v2]: - Fix typo in patch title include/linux/kvm_host.h | 2 ++ virt/kvm/kvm_main.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index a4c33b3..85875e0 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -528,6 +528,8 @@ struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn); unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn); unsigned long gfn_to_hva_prot(struct kvm *kvm, gfn_t gfn, bool *writable); unsigned long gfn_to_hva_memslot(struct kvm_memory_slot *slot, gfn_t gfn); +unsigned long gfn_to_hva_memslot_prot(struct kvm_memory_slot *slot, gfn_t gfn, + bool *writable); void kvm_release_page_clean(struct page *page); void kvm_release_page_dirty(struct page *page); void kvm_set_page_accessed(struct page *page); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 33712fb..36b887d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1075,9 +1075,9 @@ EXPORT_SYMBOL_GPL(gfn_to_hva); * If writable is set to false, the hva returned by this function is only * allowed to be read. */ -unsigned long gfn_to_hva_prot(struct kvm *kvm, gfn_t gfn, bool *writable) +unsigned long gfn_to_hva_memslot_prot(struct kvm_memory_slot *slot, + gfn_t gfn, bool *writable) { - struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn); unsigned long hva = __gfn_to_hva_many(slot, gfn, NULL, false); if (!kvm_is_error_hva(hva) && writable) @@ -1086,6 +1086,13 @@ unsigned long gfn_to_hva_prot(struct kvm *kvm, gfn_t gfn, bool *writable) return hva; } +unsigned long gfn_to_hva_prot(struct kvm *kvm, gfn_t gfn, bool *writable) +{ + struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn); + + return gfn_to_hva_memslot_prot(slot, gfn, writable); +} + static int kvm_read_hva(void *data, void __user *hva, int len) { return __copy_from_user(data, hva, len);