From patchwork Tue Aug 26 11:43:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 35997 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3CA2B20551 for ; Tue, 26 Aug 2014 11:52:15 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id eu11sf122324729pac.3 for ; Tue, 26 Aug 2014 04:52:14 -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=8XqvupPUfjEvPDQLmwNC6GPESfoYI20zO7aQiKnejHw=; b=NvCeCLn4eDHCkx3oHPDDYcJuI0ajkVr7hhX15z0PL0TXkoBpIl+v8nkYEip4wzTTZs N9TWXPSbYhAi/G63SAuZUqonhUiDcY5pKjvti+lRa0FpqbGcB7+8gbedJbMI/FnxnhVj tQTdIfYinjtTvHIv1mu/h/V6w0WD1T5CsBx4+y14k01/dgcDWwmU+c/hz6GPbJohrgZB az+jZNZogilagQFFxk9CdsEH1deGxo3+vVlv5b2ydxinHlG00bvkqVjDI3ILIDu0Thoz PRMUPMS0ykXJ5lqPi2z1KvH9nHCWp2QllauBKEefhMJBZZqA4j68ckfFlzaBy+M3gasc lx0Q== X-Gm-Message-State: ALoCoQmPp/zqNe6hohZ+iUW2UsGmCJgpEimu+CjcEMWQ2IY9O4li8I/wBa9bXJa/vsZ4MND5dAfu X-Received: by 10.66.157.41 with SMTP id wj9mr18048097pab.26.1409053934556; Tue, 26 Aug 2014 04:52:14 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.39.231 with SMTP id v94ls1522998qgv.16.gmail; Tue, 26 Aug 2014 04:52:14 -0700 (PDT) X-Received: by 10.220.7.131 with SMTP id d3mr407013vcd.49.1409053934457; Tue, 26 Aug 2014 04:52:14 -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 xb5si1219224vdc.94.2014.08.26.04.52.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 26 Aug 2014 04:52:14 -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 hy4so16337999vcb.22 for ; Tue, 26 Aug 2014 04:52:14 -0700 (PDT) X-Received: by 10.220.247.3 with SMTP id ma3mr11463213vcb.29.1409053934393; Tue, 26 Aug 2014 04:52:14 -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 uj3csp191969vcb; Tue, 26 Aug 2014 04:52:13 -0700 (PDT) X-Received: by 10.70.90.3 with SMTP id bs3mr36545242pdb.42.1409053933563; Tue, 26 Aug 2014 04:52:13 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id o1si4217849pde.6.2014.08.26.04.52.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Aug 2014 04:52:12 -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 1XMFGy-0005mN-AQ; Tue, 26 Aug 2014 11:50:48 +0000 Received: from mail-la0-f51.google.com ([209.85.215.51]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XMFGv-0005UH-Kt for linux-arm-kernel@lists.infradead.org; Tue, 26 Aug 2014 11:50:46 +0000 Received: by mail-la0-f51.google.com with SMTP id pn19so14608682lab.38 for ; Tue, 26 Aug 2014 04:50:18 -0700 (PDT) X-Received: by 10.152.28.230 with SMTP id e6mr27436419lah.62.1409053405670; Tue, 26 Aug 2014 04:43:25 -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 yx5sm4770556lbb.35.2014.08.26.04.43.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Aug 2014 04:43:24 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Subject: [PATCH v3 1/2] KVM: Introduce gfn_to_hva_memslot_prot Date: Tue, 26 Aug 2014 13:43:12 +0200 Message-Id: <1409053393-13768-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-20140826_045045_862315_CA72C9D7 X-CRM114-Status: GOOD ( 11.20 ) 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.51 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.215.51 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Marc Zyngier , Peter Maydell , 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. Cc: Ard Biesheuvel Acked-by: Marc Zyngier Signed-off-by: Christoffer Dall --- Changelog[v3]: - None 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 ebd7236..6d8a658 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 5a0817e..76c92a7 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1076,9 +1076,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) @@ -1087,6 +1087,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);