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: 10090383 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 4203860329 for ; Mon, 4 Dec 2017 14:06:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A85D2842D for ; Mon, 4 Dec 2017 14:06:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E0452877F; Mon, 4 Dec 2017 14:06:41 +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.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED, URIBL_DBL_ABUSE_SPAM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 913492842D for ; Mon, 4 Dec 2017 14:06:40 +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=gdUDMT0FQcEVS2OqIbBfB0i0wvUnYRMA9acwa363MFI=; b=lIXzAC/WaxikMYwykSI8ewzReW IVWbykZK/FKbmPuDXs3/9QG0o2tqUglSZkLfeAd9vnWYKC6Ae0RPxPRaD8oxDsnF1S9esoCJEjEDD Z+AgVLv9fiql9vK48rWd7+YK8bJ9af7IgHmQyjwjSElT5ceqtRNDxqMu8w8hESf3g1S+twz23BgWM s6UDXn/1A1Nr5p8i/MmS1JA/t2NaV5vTdDq6+Yb7EnWodmpNod4DIU3C/dNWSecT1nQrRHjNR16Ib VNSuVlLgxny0Ui/R+6qAW9Ijn02aZiLt8iucpTx2a8kt++6UnM+eySjrZNgS5UdhAww2+x3CZQDqu H9smBDyw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eLrOJ-000675-C5; Mon, 04 Dec 2017 14:06:39 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eLrM1-0002O3-Ir for linux-arm-kernel@lists.infradead.org; Mon, 04 Dec 2017 14:04:30 +0000 Received: by mail-wr0-x243.google.com with SMTP id x49so17406608wrb.13 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=mi6yDCugeKnKkfX4U2+RuXTym0BusPt31qwJH4viKBTqGG1CUSNV7rVhOecZE2Lz7K Af1SDrmf6PiiUFs+GVVLP+M4w12HQgwpxhOwwWzvXeZb5+Otz29GL+GICXRhtymBLRFK E3ZZsvx8kcuKlVTKF6Urp0p0l+9kzSJ4WrYbcWpltXUQGpnpZdcyzAVr8rko4dTri0BX wsjffsg0q5ZbB0ODZeRwNqLFn9Mu7XZg01xkkHLm8DT+DK2bbqHmiAAacbYRsnipkTyp 37VPHAjTW8aK6laG9k/mzZia5iYg6cbhM5RHZYR3HXB4oCF1cdaQY57/SalQjBqzMF/d VTag== X-Gm-Message-State: AJaThX6cr6csZce3kaUZbTHMcto2ejTt7187qzqbfariv8GegDQVwmXW JUE4NLeDfLaTcYi+qlDInf/YpQ== 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?= 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171204_060417_856643_880F6F20 X-CRM114-Status: GOOD ( 10.21 ) 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: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Marc Zyngier , stable@vger.kernel.org, Kristina Martsenko , Christoffer Dall 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 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)