From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CB84C4646B for ; Fri, 21 Jun 2019 09:40:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0DAF521537 for ; Fri, 21 Jun 2019 09:40:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726766AbfFUJkF (ORCPT ); Fri, 21 Jun 2019 05:40:05 -0400 Received: from foss.arm.com ([217.140.110.172]:54142 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726566AbfFUJkF (ORCPT ); Fri, 21 Jun 2019 05:40:05 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3C3B3147A; Fri, 21 Jun 2019 02:40:04 -0700 (PDT) Received: from filthy-habits.cambridge.arm.com (filthy-habits.cambridge.arm.com [10.1.197.61]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DB53A3F246; Fri, 21 Jun 2019 02:40:02 -0700 (PDT) From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: Andre Przywara , Christoffer Dall , Dave Martin , Jintack Lim , Julien Thierry , James Morse , Suzuki K Poulose Subject: [PATCH 33/59] KVM: arm64: nv: Pretend we only support larger-than-host page sizes Date: Fri, 21 Jun 2019 10:38:17 +0100 Message-Id: <20190621093843.220980-34-marc.zyngier@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190621093843.220980-1-marc.zyngier@arm.com> References: <20190621093843.220980-1-marc.zyngier@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Jintack Lim Exposing memory management support to the virtual EL2 as is exposed to the host hypervisor would make the implementation too complex and inefficient. Therefore expose limited memory management support for the following two cases. We expose same or larger page granules than the one host uses. We can theoretically support a guest hypervisor having smaller-than-host granularities but it is not worth it since it makes the implementation complicated and it would waste memory. We expose 40 bits of physical address range to the virtual EL2, because we only support a 40bit IPA for the guest. Eventually, this will change. [ This was only trapping on the 32-bit encoding, also using the current target register value as a base for the sanitisation. Use as the handler for the 64-bit sysreg as well, also load the sanitised version of the sysreg before clearing and setting bits. -- Andre Przywara ] Signed-off-by: Jintack Lim Signed-off-by: Andre Przywara Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 50 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index ec34b81da936..cc994ec3c121 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1710,6 +1710,54 @@ static bool access_spsr_el2(struct kvm_vcpu *vcpu, return true; } +static bool access_id_aa64mmfr0_el1(struct kvm_vcpu *v, + struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + u64 val; + + if (p->is_write) + return write_to_read_only(v, p, r); + + val = read_id_reg(v, r, false); + + if (!nested_virt_in_use(v)) + goto out; + + /* + * Don't expose granules smaller than the host's granule to the guest. + * We can theoretically support a guest hypervisor having + * smaller-than-host granularities but it is not worth it since it + * makes the implementation complicated and it would waste memory. + */ + switch (PAGE_SIZE) { + case SZ_64K: + /* 16KB granule not supported */ + val &= ~(0xf << ID_AA64MMFR0_TGRAN16_SHIFT); + val |= (ID_AA64MMFR0_TGRAN16_NI << ID_AA64MMFR0_TGRAN16_SHIFT); + /* fall through */ + case SZ_16K: + /* 4KB granule not supported */ + val &= ~(0xf << ID_AA64MMFR0_TGRAN4_SHIFT); + val |= (ID_AA64MMFR0_TGRAN4_NI << ID_AA64MMFR0_TGRAN4_SHIFT); + break; + case SZ_4K: + /* All granule sizes are supported */ + break; + default: + unreachable(); + } + + /* Expose only 40 bits physical address range to the guest hypervisor */ + val &= ~(0xf << ID_AA64MMFR0_PARANGE_SHIFT); + val |= (0x2 << ID_AA64MMFR0_PARANGE_SHIFT); /* 40 bits */ + +out: + p->regval = val; + + return true; +} + static bool access_id_aa64pfr0_el1(struct kvm_vcpu *v, struct sys_reg_params *p, const struct sys_reg_desc *r) @@ -1846,7 +1894,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { ID_UNALLOCATED(6,7), /* CRm=7 */ - ID_SANITISED(ID_AA64MMFR0_EL1), + ID_SANITISED_FN(ID_AA64MMFR0_EL1, access_id_aa64mmfr0_el1), ID_SANITISED(ID_AA64MMFR1_EL1), ID_SANITISED(ID_AA64MMFR2_EL1), ID_UNALLOCATED(7,3), -- 2.20.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B7E9C48BE5 for ; Fri, 21 Jun 2019 09:40:12 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id C2CBC21530 for ; Fri, 21 Jun 2019 09:40:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C2CBC21530 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 76A854A4CA; Fri, 21 Jun 2019 05:40:11 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KmOxpK7QUFcs; Fri, 21 Jun 2019 05:40:10 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 2F7DF4A331; Fri, 21 Jun 2019 05:40:10 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 63B184A52C for ; Fri, 21 Jun 2019 05:40:08 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id b8OlkINokOK3 for ; Fri, 21 Jun 2019 05:40:07 -0400 (EDT) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 6BA544A4E1 for ; Fri, 21 Jun 2019 05:40:04 -0400 (EDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3C3B3147A; Fri, 21 Jun 2019 02:40:04 -0700 (PDT) Received: from filthy-habits.cambridge.arm.com (filthy-habits.cambridge.arm.com [10.1.197.61]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DB53A3F246; Fri, 21 Jun 2019 02:40:02 -0700 (PDT) From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [PATCH 33/59] KVM: arm64: nv: Pretend we only support larger-than-host page sizes Date: Fri, 21 Jun 2019 10:38:17 +0100 Message-Id: <20190621093843.220980-34-marc.zyngier@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190621093843.220980-1-marc.zyngier@arm.com> References: <20190621093843.220980-1-marc.zyngier@arm.com> MIME-Version: 1.0 Cc: Andre Przywara , Dave Martin X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu From: Jintack Lim Exposing memory management support to the virtual EL2 as is exposed to the host hypervisor would make the implementation too complex and inefficient. Therefore expose limited memory management support for the following two cases. We expose same or larger page granules than the one host uses. We can theoretically support a guest hypervisor having smaller-than-host granularities but it is not worth it since it makes the implementation complicated and it would waste memory. We expose 40 bits of physical address range to the virtual EL2, because we only support a 40bit IPA for the guest. Eventually, this will change. [ This was only trapping on the 32-bit encoding, also using the current target register value as a base for the sanitisation. Use as the handler for the 64-bit sysreg as well, also load the sanitised version of the sysreg before clearing and setting bits. -- Andre Przywara ] Signed-off-by: Jintack Lim Signed-off-by: Andre Przywara Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 50 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index ec34b81da936..cc994ec3c121 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1710,6 +1710,54 @@ static bool access_spsr_el2(struct kvm_vcpu *vcpu, return true; } +static bool access_id_aa64mmfr0_el1(struct kvm_vcpu *v, + struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + u64 val; + + if (p->is_write) + return write_to_read_only(v, p, r); + + val = read_id_reg(v, r, false); + + if (!nested_virt_in_use(v)) + goto out; + + /* + * Don't expose granules smaller than the host's granule to the guest. + * We can theoretically support a guest hypervisor having + * smaller-than-host granularities but it is not worth it since it + * makes the implementation complicated and it would waste memory. + */ + switch (PAGE_SIZE) { + case SZ_64K: + /* 16KB granule not supported */ + val &= ~(0xf << ID_AA64MMFR0_TGRAN16_SHIFT); + val |= (ID_AA64MMFR0_TGRAN16_NI << ID_AA64MMFR0_TGRAN16_SHIFT); + /* fall through */ + case SZ_16K: + /* 4KB granule not supported */ + val &= ~(0xf << ID_AA64MMFR0_TGRAN4_SHIFT); + val |= (ID_AA64MMFR0_TGRAN4_NI << ID_AA64MMFR0_TGRAN4_SHIFT); + break; + case SZ_4K: + /* All granule sizes are supported */ + break; + default: + unreachable(); + } + + /* Expose only 40 bits physical address range to the guest hypervisor */ + val &= ~(0xf << ID_AA64MMFR0_PARANGE_SHIFT); + val |= (0x2 << ID_AA64MMFR0_PARANGE_SHIFT); /* 40 bits */ + +out: + p->regval = val; + + return true; +} + static bool access_id_aa64pfr0_el1(struct kvm_vcpu *v, struct sys_reg_params *p, const struct sys_reg_desc *r) @@ -1846,7 +1894,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { ID_UNALLOCATED(6,7), /* CRm=7 */ - ID_SANITISED(ID_AA64MMFR0_EL1), + ID_SANITISED_FN(ID_AA64MMFR0_EL1, access_id_aa64mmfr0_el1), ID_SANITISED(ID_AA64MMFR1_EL1), ID_SANITISED(ID_AA64MMFR2_EL1), ID_UNALLOCATED(7,3), -- 2.20.1 _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C746EC43613 for ; Fri, 21 Jun 2019 10:04:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9956B21530 for ; Fri, 21 Jun 2019 10:04:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GqPGJEO4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9956B21530 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=5p7s/QQcpcjyuE58zY7kmtAvEShNVZENjmomeqPRQ5I=; b=GqPGJEO4jJ7E/4 ssAxK+UcgmVjnFkfnsqzrEtodPNGrMQ9whHPAj//90rEAr348C5kzJaOrrZoGgmYt3MKOfbyCnplW ke1NsNwUgQoJzTsIEj8qsgZoe/8PySOg3zA+mhbOtS30ZgXmwKcjelUP7SK0T8YdkZkhOMPvwxzNF S4OFRtoD75m9MNKg3H8q0cC7oSlrOygtJlWzRas0uEOh6hX3ZUyv3oivOCgtWe6L6Nyb3rPuRRdDY Hm0tT49sp+/cwsR2/TinRRwYJ+70/tJixHhTqSzLld0k7bE+Sf7Viv6vcwMcg6HC43ZXuzhYvj117 vs0TYkyYY2FXu9hX7yhA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1heGPc-0007gg-2c; Fri, 21 Jun 2019 10:04:52 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1heG1d-0007mT-FL for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2019 09:40:10 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3C3B3147A; Fri, 21 Jun 2019 02:40:04 -0700 (PDT) Received: from filthy-habits.cambridge.arm.com (filthy-habits.cambridge.arm.com [10.1.197.61]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DB53A3F246; Fri, 21 Jun 2019 02:40:02 -0700 (PDT) From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [PATCH 33/59] KVM: arm64: nv: Pretend we only support larger-than-host page sizes Date: Fri, 21 Jun 2019 10:38:17 +0100 Message-Id: <20190621093843.220980-34-marc.zyngier@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190621093843.220980-1-marc.zyngier@arm.com> References: <20190621093843.220980-1-marc.zyngier@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190621_024005_652478_D1A5757F X-CRM114-Status: GOOD ( 14.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Julien Thierry , Andre Przywara , Suzuki K Poulose , Christoffer Dall , Dave Martin , James Morse , Jintack Lim Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jintack Lim Exposing memory management support to the virtual EL2 as is exposed to the host hypervisor would make the implementation too complex and inefficient. Therefore expose limited memory management support for the following two cases. We expose same or larger page granules than the one host uses. We can theoretically support a guest hypervisor having smaller-than-host granularities but it is not worth it since it makes the implementation complicated and it would waste memory. We expose 40 bits of physical address range to the virtual EL2, because we only support a 40bit IPA for the guest. Eventually, this will change. [ This was only trapping on the 32-bit encoding, also using the current target register value as a base for the sanitisation. Use as the handler for the 64-bit sysreg as well, also load the sanitised version of the sysreg before clearing and setting bits. -- Andre Przywara ] Signed-off-by: Jintack Lim Signed-off-by: Andre Przywara Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 50 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index ec34b81da936..cc994ec3c121 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1710,6 +1710,54 @@ static bool access_spsr_el2(struct kvm_vcpu *vcpu, return true; } +static bool access_id_aa64mmfr0_el1(struct kvm_vcpu *v, + struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + u64 val; + + if (p->is_write) + return write_to_read_only(v, p, r); + + val = read_id_reg(v, r, false); + + if (!nested_virt_in_use(v)) + goto out; + + /* + * Don't expose granules smaller than the host's granule to the guest. + * We can theoretically support a guest hypervisor having + * smaller-than-host granularities but it is not worth it since it + * makes the implementation complicated and it would waste memory. + */ + switch (PAGE_SIZE) { + case SZ_64K: + /* 16KB granule not supported */ + val &= ~(0xf << ID_AA64MMFR0_TGRAN16_SHIFT); + val |= (ID_AA64MMFR0_TGRAN16_NI << ID_AA64MMFR0_TGRAN16_SHIFT); + /* fall through */ + case SZ_16K: + /* 4KB granule not supported */ + val &= ~(0xf << ID_AA64MMFR0_TGRAN4_SHIFT); + val |= (ID_AA64MMFR0_TGRAN4_NI << ID_AA64MMFR0_TGRAN4_SHIFT); + break; + case SZ_4K: + /* All granule sizes are supported */ + break; + default: + unreachable(); + } + + /* Expose only 40 bits physical address range to the guest hypervisor */ + val &= ~(0xf << ID_AA64MMFR0_PARANGE_SHIFT); + val |= (0x2 << ID_AA64MMFR0_PARANGE_SHIFT); /* 40 bits */ + +out: + p->regval = val; + + return true; +} + static bool access_id_aa64pfr0_el1(struct kvm_vcpu *v, struct sys_reg_params *p, const struct sys_reg_desc *r) @@ -1846,7 +1894,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { ID_UNALLOCATED(6,7), /* CRm=7 */ - ID_SANITISED(ID_AA64MMFR0_EL1), + ID_SANITISED_FN(ID_AA64MMFR0_EL1, access_id_aa64mmfr0_el1), ID_SANITISED(ID_AA64MMFR1_EL1), ID_SANITISED(ID_AA64MMFR2_EL1), ID_UNALLOCATED(7,3), -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel