From patchwork Mon Dec 4 14:03:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10090341 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D882F60329 for ; Mon, 4 Dec 2017 14:04:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C04042899A for ; Mon, 4 Dec 2017 14:04:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4DD728D1D; Mon, 4 Dec 2017 14:04:17 +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=-4.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,URIBL_DBL_ABUSE_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B03C92899A for ; Mon, 4 Dec 2017 14:04:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754296AbdLDOEP (ORCPT ); Mon, 4 Dec 2017 09:04:15 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:37870 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754440AbdLDOD7 (ORCPT ); Mon, 4 Dec 2017 09:03:59 -0500 Received: by mail-wr0-f193.google.com with SMTP id k61so17412547wrc.4 for ; Mon, 04 Dec 2017 06:03:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+CusPMXYVrjOVmHAylBHwzDxwi7kqn3PcS/X5orpTAs=; b=Dsjk1uz/W2mdSpCVwtyW/UJhod70IDC63LoU+ksX2Ex1GIT9OXsWepLkG5wRBXNWXG R+nMYmRFJRosM0oj2KDLM8ZRzqCuwHkOxrKOtczxAj8+I1XuMO0BYbbiBAxM7lu6DQHF bzOqLfxm8szjcGW8WJSbIj/zA6i/BVx55CFCEl3qJJWOOSg/sOyGpYXQvZP+BcKSOxlk uAivV7a44BoyVOW8SZw3fRho1mMGR1jxvW/k4Av+G0KYGKKTNjRbm3CvzOhn5+PlVc3l SlFohQNIhXuRqU1PyA+kW9dPcgCyELJd3a6s/mk1nhcBHTMiL4FcZtPH6uFBWQMohq1I mSsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=+CusPMXYVrjOVmHAylBHwzDxwi7kqn3PcS/X5orpTAs=; b=nrZlez+VP5a/L0GWxXy8Sv41ODc5fzVrtTwyXE4drD1lsmVsFKg3KheokF595U4Yzc K32M06gEW+qby1t+/GTyWPFkUO81oUXFFprk8mqjJIAQDR/1Ugqsw6DcR270gQsBz+t5 x5OzT4cIvkZ4KNtXFiPlaxwdhQR7FVJ0+dNakE5XjdRMoTbNVw4IMZxNPgvU+8mqUFa6 rI1wnU//bHZYHaFUtUjrpG5/OXhrJOD9FIiObkzTWAHw91SwBqC6Fm++NkVV+TWoiO/j e2fBkW9+yZ49HrRDdobIRCkZ9Zp0aGVJILr/bJz4dkFCU2Q0z3cDyWofffL/rkSvDw1A qubQ== X-Gm-Message-State: AJaThX4dgNe8f/WzSl51EaxF8GeZ4ryW6ewbXiiUlQYTbyIJigJN/YIR xcvEK9K0pLuCZGF2iSSSi24ljg== X-Google-Smtp-Source: AGs4zMbsy8U7sDzr6A61JSgaS9YfzT1dzTsn2mBWtwHLFEMIWHrhkIByMM6cjh/Rem4efZGdBPlApA== X-Received: by 10.223.174.147 with SMTP id y19mr12538334wrc.97.1512396238361; Mon, 04 Dec 2017 06:03:58 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id g7sm22794279wra.38.2017.12.04.06.03.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Dec 2017 06:03:57 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Marc Zyngier , Kristina Martsenko , stable@vger.kernel.org, Christoffer Dall Subject: [PULL 08/19] arm64: KVM: fix VTTBR_BADDR_MASK BUG_ON off-by-one Date: Mon, 4 Dec 2017 15:03:37 +0100 Message-Id: <20171204140348.21965-6-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171204135637.21620-1-cdall@kernel.org> References: <20171204135637.21620-1-cdall@kernel.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Kristina Martsenko VTTBR_BADDR_MASK is used to sanity check the size and alignment of the VTTBR address. It seems to currently be off by one, thereby only allowing up to 47-bit addresses (instead of 48-bit) and also insufficiently checking the alignment. This patch fixes it. As an example, with 4k pages, before this patch we have: PHYS_MASK_SHIFT = 48 VTTBR_X = 37 - 24 = 13 VTTBR_BADDR_SHIFT = 13 - 1 = 12 VTTBR_BADDR_MASK = ((1 << 35) - 1) << 12 = 0x00007ffffffff000 Which is wrong, because the mask doesn't allow bit 47 of the VTTBR address to be set, and only requires the address to be 12-bit (4k) aligned, while it actually needs to be 13-bit (8k) aligned because we concatenate two 4k tables. With this patch, the mask becomes 0x0000ffffffffe000, which is what we want. Fixes: 0369f6a34b9f ("arm64: KVM: EL2 register definitions") Cc: # 3.11.x Reviewed-by: Suzuki K Poulose Reviewed-by: Christoffer Dall Signed-off-by: Kristina Martsenko Signed-off-by: Marc Zyngier Signed-off-by: Christoffer Dall --- arch/arm64/include/asm/kvm_arm.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index 7f069ff37f06..715d395ef45b 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -170,8 +170,7 @@ #define VTCR_EL2_FLAGS (VTCR_EL2_COMMON_BITS | VTCR_EL2_TGRAN_FLAGS) #define VTTBR_X (VTTBR_X_TGRAN_MAGIC - VTCR_EL2_T0SZ_IPA) -#define VTTBR_BADDR_SHIFT (VTTBR_X - 1) -#define VTTBR_BADDR_MASK (((UL(1) << (PHYS_MASK_SHIFT - VTTBR_X)) - 1) << VTTBR_BADDR_SHIFT) +#define VTTBR_BADDR_MASK (((UL(1) << (PHYS_MASK_SHIFT - VTTBR_X)) - 1) << VTTBR_X) #define VTTBR_VMID_SHIFT (UL(48)) #define VTTBR_VMID_MASK(size) (_AT(u64, (1 << size) - 1) << VTTBR_VMID_SHIFT)