From patchwork Tue Aug 19 12:01:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 35586 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D5A5D2136C for ; Tue, 19 Aug 2014 12:05:20 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id w7sf20051091qcr.3 for ; Tue, 19 Aug 2014 05:05:20 -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=UgoVAUv6TviTPgLb7VLeYddUZWvUzdMuModY4jkxLog=; b=NXnErPhaVmFkwlRHOMh6egqDraTZZgtFLP+AKx0+jRBimyttDEjX2hY01NCtMAGM1V P8LX4vXONf4dqpblsi5iZhZpaybd/q0feo0IhLN6RdXdWEMjEyoNozOveni8xM9dRVTk VJHYWk2/oq4BkVyG1re+lsXkqhffFzznlhcIUdUt62dsC9/z4YaiLLpucaA1a4wQJGL0 /p/z2iPlv74SUpAWjActI24BaI+paoH3UFS/rNrQgHX+qKLR25hcMFCOpetWZCkHfyJP O+T07uOI2A3UohqYYcZqqSk5Vw/cQTi6JUMBCQHRquurq47Xe/5lIsNRMnzAMY+fyygn x90g== X-Gm-Message-State: ALoCoQmPuJ/o1LZrnaiV3Cc+NlLo9nNGaBLD6iEpE15lMXGwJQ5SzD+yXjda2xMmUHJWUSIrqemA X-Received: by 10.236.16.165 with SMTP id h25mr9624713yhh.30.1408449920335; Tue, 19 Aug 2014 05:05:20 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.105.247 with SMTP id c110ls979004qgf.5.gmail; Tue, 19 Aug 2014 05:05:20 -0700 (PDT) X-Received: by 10.220.105.201 with SMTP id u9mr29928995vco.11.1408449920208; Tue, 19 Aug 2014 05:05:20 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id ji10si8504971vdb.3.2014.08.19.05.05.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Aug 2014 05:05:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ij19so7317435vcb.11 for ; Tue, 19 Aug 2014 05:05:20 -0700 (PDT) X-Received: by 10.221.5.137 with SMTP id og9mr29933318vcb.18.1408449920058; Tue, 19 Aug 2014 05:05:20 -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.37.5 with SMTP id tc5csp232845vcb; Tue, 19 Aug 2014 05:05:19 -0700 (PDT) X-Received: by 10.70.96.165 with SMTP id dt5mr50195710pdb.71.1408449918964; Tue, 19 Aug 2014 05:05:18 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id dz6si25000808pab.107.2014.08.19.05.05.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Aug 2014 05:05:13 -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 1XJi7H-0006gf-I5; Tue, 19 Aug 2014 12:02:19 +0000 Received: from mail-lb0-f180.google.com ([209.85.217.180]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XJi72-0006VF-ED for linux-arm-kernel@lists.infradead.org; Tue, 19 Aug 2014 12:02:05 +0000 Received: by mail-lb0-f180.google.com with SMTP id v6so5280450lbi.25 for ; Tue, 19 Aug 2014 05:01:41 -0700 (PDT) X-Received: by 10.112.56.206 with SMTP id c14mr32741240lbq.27.1408449700358; Tue, 19 Aug 2014 05:01:40 -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 kv3sm31833801lbc.37.2014.08.19.05.01.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Aug 2014 05:01:39 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Subject: [PATCH 1/2] KVM: Introduce gfn_to_hva_memslow_prot Date: Tue, 19 Aug 2014 14:01:51 +0200 Message-Id: <1408449712-14903-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-20140819_050204_660546_F6A7DFB0 X-CRM114-Status: GOOD ( 11.66 ) 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.217.180 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.217.180 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -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.180 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 --- 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);