From patchwork Tue Apr 2 02:27:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kachhap X-Patchwork-Id: 161592 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp1192750jan; Mon, 1 Apr 2019 19:27:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzdK3Kl6KIRFJo/s4XUIN3TgarMEU7FfFjP3SUWJvsCKm071zzwhbdQkBWpWCKYorARvWoH X-Received: by 2002:aa7:8212:: with SMTP id k18mr10617412pfi.50.1554172066949; Mon, 01 Apr 2019 19:27:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554172066; cv=none; d=google.com; s=arc-20160816; b=eae8Z4bzDHhq/jy2ESM/dMwHvH7q8M0lQuKJxWSvp+qctYmgHBdYZDetivc7lmT5Te h4ClJxFchAd0ZBPmzTSfOuh6XKy6Y9qQydHMBqQIsJ4q8vX/EnhnapyXFcfm9qjRl7hc IecXu82WQ4/f0gyF9XIFK3zY+tLEu8IKx3HoPDbR+3N7czPpPke9ndwmi5vF/mid/Xo0 8jx4vzX9Iee/bRnkKReD2MwyshycqRj0msL9WC/OMu3p3q3mdCLyNBq9Nnj9H660UF2c 58BAro+upoTufhEaS3U8XrNT/RUy+vCZjg/MqJx2Ko0MVF52ulY6LRIaulyRQSuj8/MO N2lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=80oEx7EXOWYe9lNm8FtZEQLWb//Yg1syvNwrmVCjoq8=; b=l8lUhWFaAjADT8eWFSuOA8uYDxtXBQEhy0KGKvYXCl86pvJyjgNWWWwa9XPKCI5qHq 5jLEJioLLZ9FViw9OyL2+SrVpXMABKONKLujPNtZVWGr/z1wBk9HwfKCBuOFsoadOXDC P++YIV5zrthRcYLHrbf+Pnvx/hz9JTkfZQGibOmO4YCDN9/FWodEQq9wj8q55LZZbIH2 s0MMCu4KrP3L09QLtgNHGAzWQcA2LEk1SU5SEfxEfkdp0Fbdp0Y3OlmKD/Pk/8ZBZPJd vdco71j+WgKnEvWeQSRG7ZST5AHyBlCeeN43bY+ZBs4y+yUeKTrBY9JsVvYapNVeQm5y LF/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p2si6902970plr.69.2019.04.01.19.27.46; Mon, 01 Apr 2019 19:27:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728823AbfDBC1k (ORCPT + 31 others); Mon, 1 Apr 2019 22:27:40 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:43480 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726269AbfDBC1k (ORCPT ); Mon, 1 Apr 2019 22:27:40 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A335980D; Mon, 1 Apr 2019 19:27:39 -0700 (PDT) Received: from a075553-lin.blr.arm.com (a075553-lin.blr.arm.com [10.162.0.144]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E76863F59C; Mon, 1 Apr 2019 19:27:34 -0700 (PDT) From: Amit Daniel Kachhap To: linux-arm-kernel@lists.infradead.org Cc: Christoffer Dall , Marc Zyngier , Catalin Marinas , Will Deacon , Andrew Jones , Dave Martin , Ramana Radhakrishnan , kvmarm@lists.cs.columbia.edu, Kristina Martsenko , linux-kernel@vger.kernel.org, Amit Daniel Kachhap , Mark Rutland , James Morse , Julien Thierry Subject: [PATCH v8 1/9] KVM: arm64: Propagate vcpu into read_id_reg() Date: Tue, 2 Apr 2019 07:57:09 +0530 Message-Id: <1554172037-4516-2-git-send-email-amit.kachhap@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1554172037-4516-1-git-send-email-amit.kachhap@arm.com> References: <1554172037-4516-1-git-send-email-amit.kachhap@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Martin Architecture features that are conditionally visible to the guest will require run-time checks in the ID register accessor functions. In particular, read_id_reg() will need to perform checks in order to generate the correct emulated value for certain ID register fields such as ID_AA64PFR0_EL1.SVE for example. This patch propagates vcpu into read_id_reg() so that future patches can add run-time checks on the guest configuration here. For now, there is no functional change. Signed-off-by: Dave Martin Reviewed-by: Alex Bennee --- arch/arm64/kvm/sys_regs.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) -- 2.7.4 diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 539feec..a5d14b5 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1044,7 +1044,8 @@ static bool access_arch_timer(struct kvm_vcpu *vcpu, } /* Read a sanitised cpufeature ID register by sys_reg_desc */ -static u64 read_id_reg(struct sys_reg_desc const *r, bool raz) +static u64 read_id_reg(const struct kvm_vcpu *vcpu, + struct sys_reg_desc const *r, bool raz) { u32 id = sys_reg((u32)r->Op0, (u32)r->Op1, (u32)r->CRn, (u32)r->CRm, (u32)r->Op2); @@ -1078,7 +1079,7 @@ static bool __access_id_reg(struct kvm_vcpu *vcpu, if (p->is_write) return write_to_read_only(vcpu, p, r); - p->regval = read_id_reg(r, raz); + p->regval = read_id_reg(vcpu, r, raz); return true; } @@ -1107,16 +1108,18 @@ static u64 sys_reg_to_index(const struct sys_reg_desc *reg); * are stored, and for set_id_reg() we don't allow the effective value * to be changed. */ -static int __get_id_reg(const struct sys_reg_desc *rd, void __user *uaddr, +static int __get_id_reg(const struct kvm_vcpu *vcpu, + const struct sys_reg_desc *rd, void __user *uaddr, bool raz) { const u64 id = sys_reg_to_index(rd); - const u64 val = read_id_reg(rd, raz); + const u64 val = read_id_reg(vcpu, rd, raz); return reg_to_user(uaddr, &val, id); } -static int __set_id_reg(const struct sys_reg_desc *rd, void __user *uaddr, +static int __set_id_reg(const struct kvm_vcpu *vcpu, + const struct sys_reg_desc *rd, void __user *uaddr, bool raz) { const u64 id = sys_reg_to_index(rd); @@ -1128,7 +1131,7 @@ static int __set_id_reg(const struct sys_reg_desc *rd, void __user *uaddr, return err; /* This is what we mean by invariant: you can't change it. */ - if (val != read_id_reg(rd, raz)) + if (val != read_id_reg(vcpu, rd, raz)) return -EINVAL; return 0; @@ -1137,25 +1140,25 @@ static int __set_id_reg(const struct sys_reg_desc *rd, void __user *uaddr, static int get_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr) { - return __get_id_reg(rd, uaddr, false); + return __get_id_reg(vcpu, rd, uaddr, false); } static int set_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr) { - return __set_id_reg(rd, uaddr, false); + return __set_id_reg(vcpu, rd, uaddr, false); } static int get_raz_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr) { - return __get_id_reg(rd, uaddr, true); + return __get_id_reg(vcpu, rd, uaddr, true); } static int set_raz_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr) { - return __set_id_reg(rd, uaddr, true); + return __set_id_reg(vcpu, rd, uaddr, true); } static bool access_ctr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,