From patchwork Sat May 16 04:45:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhichao Huang X-Patchwork-Id: 48582 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0BDA42121F for ; Sat, 16 May 2015 04:49:26 +0000 (UTC) Received: by wgtl5 with SMTP id l5sf36231125wgt.1 for ; Fri, 15 May 2015 21:49:25 -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 :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=iZUBJnQG6F7NYbQ5FlKy2fYnas8wVT9jcrszkbC1FL0=; b=b9PIKSdxTKk7TI6e0SQOiXAbd6nUt9TSRvfI49x+6OP13AtAWEnPMA6CsfPlSZ1NmC xF1WL3UQ4YI5PN772IaryIDu5WvouuzQwn0iHrLmkUdU2df9VHVRSU0U1zBrSTVvpmHi G3FY1Vs8fBge83GkKLTeAZADzTgeFybEDLXCJ+eVleu4Y8Kwpsd9GW30Im89xFJr5hDA fcZ41aTgBjypWJ1pZaQkml/RInCApBmXWtnv0bqhW9e5v1tDJOgGcqmvv2Cs0OtRDu56 84V6IHy3VqkNSELpqSVyam4VQiSGodE4TYzazainAlytc1CEqBWcWoViVAzqLX9Kp3uX zfcg== X-Gm-Message-State: ALoCoQnPM520pSum+MjNGmtThRtOvw5SVuWQCBOaFCOkYSJU80uewe9C5SZar8Z/PqtVXbU4PNKg X-Received: by 10.180.88.226 with SMTP id bj2mr1563733wib.7.1431751765315; Fri, 15 May 2015 21:49:25 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.239.130 with SMTP id vs2ls503738lac.97.gmail; Fri, 15 May 2015 21:49:25 -0700 (PDT) X-Received: by 10.152.42.141 with SMTP id o13mr9642684lal.33.1431751765156; Fri, 15 May 2015 21:49:25 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id z6si2385981lae.16.2015.05.15.21.49.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 May 2015 21:49:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by lagv1 with SMTP id v1so149472890lag.3 for ; Fri, 15 May 2015 21:49:24 -0700 (PDT) X-Received: by 10.112.140.231 with SMTP id rj7mr9500162lbb.76.1431751764536; Fri, 15 May 2015 21:49:24 -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.112.108.230 with SMTP id hn6csp2472208lbb; Fri, 15 May 2015 21:49:23 -0700 (PDT) X-Received: by 10.70.92.34 with SMTP id cj2mr24777380pdb.116.1431751761714; Fri, 15 May 2015 21:49:21 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ns8si5574063pbc.246.2015.05.15.21.49.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 May 2015 21:49:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) 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 1YtU0V-0006tN-7T; Sat, 16 May 2015 04:47:27 +0000 Received: from mail-pd0-f169.google.com ([209.85.192.169]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YtTzs-0006a7-ON for linux-arm-kernel@lists.infradead.org; Sat, 16 May 2015 04:46:50 +0000 Received: by pdfh10 with SMTP id h10so46297380pdf.3 for ; Fri, 15 May 2015 21:46:27 -0700 (PDT) X-Received: by 10.66.244.16 with SMTP id xc16mr24282450pac.87.1431751587580; Fri, 15 May 2015 21:46:27 -0700 (PDT) Received: from localhost ([167.160.116.91]) by mx.google.com with ESMTPSA id vl9sm3357590pbc.73.2015.05.15.21.46.23 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 15 May 2015 21:46:26 -0700 (PDT) From: Zhichao Huang To: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com, alex.bennee@linaro.org Subject: [PATCH 04/10] KVM: arm: common infrastructure for handling AArch32 CP14/CP15 Date: Sat, 16 May 2015 12:45:45 +0800 Message-Id: <1431751551-4788-5-git-send-email-zhichao.huang@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1431751551-4788-1-git-send-email-zhichao.huang@linaro.org> References: <1431751551-4788-1-git-send-email-zhichao.huang@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150515_214648_898016_5BDCA732 X-CRM114-Status: GOOD ( 18.23 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.192.169 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.2 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.192.169 listed in wl.mailspike.net] Cc: huangzhichao@huawei.com, Zhichao Huang 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: zhichao.huang@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.215.50 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 As we're about to trap a bunch of CP14 registers, let's rework the CP15 handling so it can be generalized and work with multiple tables. Signed-off-by: Zhichao Huang --- arch/arm/kvm/coproc.c | 176 ++++++++++++++++++++++++++--------------- arch/arm/kvm/interrupts_head.S | 2 +- 2 files changed, 112 insertions(+), 66 deletions(-) diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c index 9d283d9..d23395b 100644 --- a/arch/arm/kvm/coproc.c +++ b/arch/arm/kvm/coproc.c @@ -375,6 +375,9 @@ static const struct coproc_reg cp15_regs[] = { { CRn(15), CRm( 0), Op1( 4), Op2( 0), is32, access_cbar}, }; +static const struct coproc_reg cp14_regs[] = { +}; + /* Target specific emulation tables */ static struct kvm_coproc_target_table *target_tables[KVM_ARM_NUM_TARGETS]; @@ -424,47 +427,75 @@ static const struct coproc_reg *find_reg(const struct coproc_params *params, return NULL; } -static int emulate_cp15(struct kvm_vcpu *vcpu, - const struct coproc_params *params) +/* + * emulate_cp -- tries to match a cp14/cp15 access in a handling table, + * and call the corresponding trap handler. + * + * @params: pointer to the descriptor of the access + * @table: array of trap descriptors + * @num: size of the trap descriptor array + * + * Return 0 if the access has been handled, and -1 if not. + */ +static int emulate_cp(struct kvm_vcpu *vcpu, + const struct coproc_params *params, + const struct coproc_reg *table, + size_t num) { - size_t num; - const struct coproc_reg *table, *r; - - trace_kvm_emulate_cp15_imp(params->Op1, params->Rt1, params->CRn, - params->CRm, params->Op2, params->is_write); + const struct coproc_reg *r; - table = get_target_table(vcpu->arch.target, &num); + if (!table) + return -1; /* Not handled */ - /* Search target-specific then generic table. */ r = find_reg(params, table, num); - if (!r) - r = find_reg(params, cp15_regs, ARRAY_SIZE(cp15_regs)); - if (likely(r)) { + if (r) { /* If we don't have an accessor, we should never get here! */ BUG_ON(!r->access); if (likely(r->access(vcpu, params, r))) { /* Skip instruction, since it was emulated */ kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); - return 1; } - /* If access function fails, it should complain. */ - } else { - kvm_err("Unsupported guest CP15 access at: %08lx\n", - *vcpu_pc(vcpu)); - print_cp_instr(params); + + /* Handled */ + return 0; } + + /* Not handled */ + return -1; +} + +static void unhandled_cp_access(struct kvm_vcpu *vcpu, + const struct coproc_params *params) +{ + u8 hsr_ec = kvm_vcpu_trap_get_class(vcpu); + int cp; + + switch (hsr_ec) { + case HSR_EC_CP15_32: + case HSR_EC_CP15_64: + cp = 15; + break; + case HSR_EC_CP14_MR: + case HSR_EC_CP14_64: + cp = 14; + break; + default: + WARN_ON((cp = -1)); + } + + kvm_err("Unsupported guest CP%d access at: %08lx\n", + cp, *vcpu_pc(vcpu)); + print_cp_instr(params); kvm_inject_undefined(vcpu); - return 1; } -/** - * kvm_handle_cp15_64 -- handles a mrrc/mcrr trap on a guest CP15 access - * @vcpu: The VCPU pointer - * @run: The kvm_run struct - */ -int kvm_handle_cp15_64(struct kvm_vcpu *vcpu, struct kvm_run *run) +int kvm_handle_cp_64(struct kvm_vcpu *vcpu, + const struct coproc_reg *global, + size_t nr_global, + const struct coproc_reg *target_specific, + size_t nr_specific) { struct coproc_params params; @@ -478,7 +509,13 @@ int kvm_handle_cp15_64(struct kvm_vcpu *vcpu, struct kvm_run *run) params.Rt2 = (kvm_vcpu_get_hsr(vcpu) >> 10) & 0xf; params.CRm = 0; - return emulate_cp15(vcpu, ¶ms); + if (!emulate_cp(vcpu, ¶ms, target_specific, nr_specific)) + return 1; + if (!emulate_cp(vcpu, ¶ms, global, nr_global)) + return 1; + + unhandled_cp_access(vcpu, ¶ms); + return 1; } static void reset_coproc_regs(struct kvm_vcpu *vcpu, @@ -491,12 +528,11 @@ static void reset_coproc_regs(struct kvm_vcpu *vcpu, table[i].reset(vcpu, &table[i]); } -/** - * kvm_handle_cp15_32 -- handles a mrc/mcr trap on a guest CP15 access - * @vcpu: The VCPU pointer - * @run: The kvm_run struct - */ -int kvm_handle_cp15_32(struct kvm_vcpu *vcpu, struct kvm_run *run) +int kvm_handle_cp_32(struct kvm_vcpu *vcpu, + const struct coproc_reg *global, + size_t nr_global, + const struct coproc_reg *target_specific, + size_t nr_specific) { struct coproc_params params; @@ -510,33 +546,57 @@ int kvm_handle_cp15_32(struct kvm_vcpu *vcpu, struct kvm_run *run) params.Op2 = (kvm_vcpu_get_hsr(vcpu) >> 17) & 0x7; params.Rt2 = 0; - return emulate_cp15(vcpu, ¶ms); + if (!emulate_cp(vcpu, ¶ms, target_specific, nr_specific)) + return 1; + if (!emulate_cp(vcpu, ¶ms, global, nr_global)) + return 1; + + unhandled_cp_access(vcpu, ¶ms); + return 1; } /** - * kvm_handle_cp14_64 -- handles a mrrc/mcrr trap on a guest CP14 access + * kvm_handle_cp15_64 -- handles a mrrc/mcrr trap on a guest CP15 access * @vcpu: The VCPU pointer * @run: The kvm_run struct */ -int kvm_handle_cp14_64(struct kvm_vcpu *vcpu, struct kvm_run *run) +int kvm_handle_cp15_64(struct kvm_vcpu *vcpu, struct kvm_run *run) { - struct coproc_params params; + const struct coproc_reg *target_specific; + size_t num; - params.CRn = (kvm_vcpu_get_hsr(vcpu) >> 1) & 0xf; - params.Rt1 = (kvm_vcpu_get_hsr(vcpu) >> 5) & 0xf; - params.is_write = ((kvm_vcpu_get_hsr(vcpu) & 1) == 0); - params.is_64bit = true; + target_specific = get_target_table(vcpu->arch.target, &num); + return kvm_handle_cp_64(vcpu, + cp15_regs, ARRAY_SIZE(cp15_regs), + target_specific, num); +} - params.Op1 = (kvm_vcpu_get_hsr(vcpu) >> 16) & 0xf; - params.Op2 = 0; - params.Rt2 = (kvm_vcpu_get_hsr(vcpu) >> 10) & 0xf; - params.CRm = 0; +/** + * kvm_handle_cp15_32 -- handles a mrc/mcr trap on a guest CP15 access + * @vcpu: The VCPU pointer + * @run: The kvm_run struct + */ +int kvm_handle_cp15_32(struct kvm_vcpu *vcpu, struct kvm_run *run) +{ + const struct coproc_reg *target_specific; + size_t num; - (void)trap_raz_wi(vcpu, ¶ms, NULL); + target_specific = get_target_table(vcpu->arch.target, &num); + return kvm_handle_cp_32(vcpu, + cp15_regs, ARRAY_SIZE(cp15_regs), + target_specific, num); +} - /* handled */ - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); - return 1; +/** + * kvm_handle_cp14_64 -- handles a mrrc/mcrr trap on a guest CP14 access + * @vcpu: The VCPU pointer + * @run: The kvm_run struct + */ +int kvm_handle_cp14_64(struct kvm_vcpu *vcpu, struct kvm_run *run) +{ + return kvm_handle_cp_64(vcpu, + cp14_regs, ARRAY_SIZE(cp14_regs), + NULL, 0); } /** @@ -546,23 +606,9 @@ int kvm_handle_cp14_64(struct kvm_vcpu *vcpu, struct kvm_run *run) */ int kvm_handle_cp14_32(struct kvm_vcpu *vcpu, struct kvm_run *run) { - struct coproc_params params; - - params.CRm = (kvm_vcpu_get_hsr(vcpu) >> 1) & 0xf; - params.Rt1 = (kvm_vcpu_get_hsr(vcpu) >> 5) & 0xf; - params.is_write = ((kvm_vcpu_get_hsr(vcpu) & 1) == 0); - params.is_64bit = false; - - params.CRn = (kvm_vcpu_get_hsr(vcpu) >> 10) & 0xf; - params.Op1 = (kvm_vcpu_get_hsr(vcpu) >> 14) & 0x7; - params.Op2 = (kvm_vcpu_get_hsr(vcpu) >> 17) & 0x7; - params.Rt2 = 0; - - (void)trap_raz_wi(vcpu, ¶ms, NULL); - - /* handled */ - kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); - return 1; + return kvm_handle_cp_32(vcpu, + cp14_regs, ARRAY_SIZE(cp14_regs), + NULL, 0); } /****************************************************************************** diff --git a/arch/arm/kvm/interrupts_head.S b/arch/arm/kvm/interrupts_head.S index a9f3a56..35e4a3a 100644 --- a/arch/arm/kvm/interrupts_head.S +++ b/arch/arm/kvm/interrupts_head.S @@ -607,7 +607,7 @@ ARM_BE8(rev r6, r6 ) * (hardware reset value is 0) */ .macro set_hdcr operation mrc p15, 4, r2, c1, c1, 1 - ldr r3, =(HDCR_TPM|HDCR_TPMCR|HDCR_TDRA|HDCR_TDOSA|HDCR_TDA) + ldr r3, =(HDCR_TPM|HDCR_TPMCR) .if \operation == vmentry orr r2, r2, r3 @ Trap some perfmon accesses .else