From patchwork Fri Sep 28 13:39:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 10620029 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C90BE913 for ; Fri, 28 Sep 2018 14:03:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8FF828BA8 for ; Fri, 28 Sep 2018 14:03:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B684E28C03; Fri, 28 Sep 2018 14:03:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 303B328B9A for ; Fri, 28 Sep 2018 14:03:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=FRDlf13zZ2p4HMWYHVyxvVLU5AvNyT7smRvquwdzdr8=; b=ZOY4Egvx4oQs8ZRuhTTe1CfYtM ASIqm3l1S822nYc3jGyapqV0yd7F9GMseEZ0nEI8bsQuEWuS/94ABhMPnIdWOlyufjRruoo6sYU4s OYYnemu+XytaD33oVwGIeppquGJBW9zfAG7rrIiE3/RamoOwOjIBjKSTFSF0ZSxdoAfbpqIMXf96a FlKFdnyrzYpWH4zK/3JceGv0bcmo8R6EV4vdEzyIiohRn94RYp+JyUfflgYoUD5EFqeht98vI3bk6 QCeZ5JqFGmCG/arZttx5agGp/epjbPe9JOt2VMies3sWzvJDkiFa5URTsz4rCvu+0hTx5NRDdDRZ1 LYd2WKQg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5tME-0005AI-SB; Fri, 28 Sep 2018 14:03:02 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5tCz-0006t9-CO for linux-arm-kernel@bombadil.infradead.org; Fri, 28 Sep 2018 13:53:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=+17KV63jv04CW2S5JW33SvTZ6zft5YynrmyIKPkzvO8=; b=r6NAXzotnWu8cEvWZLzonKLLW p2rWh3aReTTfKU6LavGRFF01Z9ap3W/4M2IgmVapc8hl9otnPvGUo3DRQ9eyYidc7iHUkySYFxTss SohAIxauYpEun0UdzbBRaflVnXzl/O8/lMJ4tp2m6gzpv/xbDPyfO7NYeDa0GBDTvpl0Nr/+Kxv9J 03XfnbgsJms84ckRLDl8NsRYIwt/S8kDxv0E8og6QCPpvKkf6cd8wQB0gLraGJV4thoRgKlYw1F+T 8M4RyrUPh3LJkmioXHOCHEXFRwAQhklB8d47asDupErXQjj86u9jfFA1dDY7oy754ieUvqbGYkw7g ajypnd6Og==; Received: from foss.arm.com ([217.140.101.70]) by casper.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5t0h-0005nG-8i for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 13:40:48 +0000 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 019FA15B2; Fri, 28 Sep 2018 06:40:37 -0700 (PDT) Received: from e103592.Emea.Arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 49C853F5B7; Fri, 28 Sep 2018 06:40:35 -0700 (PDT) From: Dave Martin To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH v2 11/23] KVM: arm64: Support runtime sysreg filtering for KVM_GET_REG_LIST Date: Fri, 28 Sep 2018 14:39:15 +0100 Message-Id: <1538141967-15375-12-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1538141967-15375-1-git-send-email-Dave.Martin@arm.com> References: <1538141967-15375-1-git-send-email-Dave.Martin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180928_144047_582509_7B31A740 X-CRM114-Status: GOOD ( 17.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Okamoto Takayuki , Christoffer Dall , Ard Biesheuvel , Marc Zyngier , Catalin Marinas , Will Deacon , =?utf-8?q?Alex_Benn=C3=A9e?= , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP KVM_GET_REG_LIST should only enumerate registers that are actually accessible, so it is necessary to filter out any register that is not exposed to the guest. For features that are configured at runtime, this will require a dynamic check. For example, ZCR_EL1 and ID_AA64ZFR0_EL1 would need to be hidden if SVE is not enabled for the guest. Special-casing walk_one_sys_reg() for specific registers will make the code unnecessarily messy, so this patch adds a new sysreg method check_present() that, if defined, indicates whether the sysreg should be enumerated. If the guest runtime configuration may require a particular system register to be hidden, check_present should point to a function that returns true or false to enable or disable enumeration of that register respectively. Currently check_present() is not used for any other purpose, but it may be a useful foundation for abstracting other parts of the code to handle conditionally-present sysregs, if required. Signed-off-by: Dave Martin --- arch/arm64/kvm/sys_regs.c | 10 +++++++--- arch/arm64/kvm/sys_regs.h | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 0dfd064..adb6cbd 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -2437,7 +2437,8 @@ static bool copy_reg_to_user(const struct sys_reg_desc *reg, u64 __user **uind) return true; } -static int walk_one_sys_reg(const struct sys_reg_desc *rd, +static int walk_one_sys_reg(const struct kvm_vcpu *vcpu, + const struct sys_reg_desc *rd, u64 __user **uind, unsigned int *total) { @@ -2448,6 +2449,9 @@ static int walk_one_sys_reg(const struct sys_reg_desc *rd, if (!(rd->reg || rd->get_user)) return 0; + if (rd->check_present && !rd->check_present(vcpu, rd)) + return 0; + if (!copy_reg_to_user(rd, uind)) return -EFAULT; @@ -2476,9 +2480,9 @@ static int walk_sys_regs(struct kvm_vcpu *vcpu, u64 __user *uind) int cmp = cmp_sys_reg(i1, i2); /* target-specific overrides generic entry. */ if (cmp <= 0) - err = walk_one_sys_reg(i1, &uind, &total); + err = walk_one_sys_reg(vcpu, i1, &uind, &total); else - err = walk_one_sys_reg(i2, &uind, &total); + err = walk_one_sys_reg(vcpu, i2, &uind, &total); if (err) return err; diff --git a/arch/arm64/kvm/sys_regs.h b/arch/arm64/kvm/sys_regs.h index 24bac06..cffb31e 100644 --- a/arch/arm64/kvm/sys_regs.h +++ b/arch/arm64/kvm/sys_regs.h @@ -61,6 +61,10 @@ struct sys_reg_desc { const struct kvm_one_reg *reg, void __user *uaddr); int (*set_user)(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr); + + /* Return true iff the register exists; assume present if NULL */ + bool (*check_present)(const struct kvm_vcpu *vcpu, + const struct sys_reg_desc *rd); }; static inline void print_sys_reg_instr(const struct sys_reg_params *p)