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: 120541 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4472758qgn; Mon, 4 Dec 2017 06:04:11 -0800 (PST) X-Google-Smtp-Source: AGs4zMYz+hiTdIB2QIfsF4Wc5D7Tc3eeauYohmmLC5U+ADlSF2x6YR27nGyd34Wsmjz4zwUU+AgN X-Received: by 10.84.175.67 with SMTP id s61mr8910938plb.72.1512396251498; Mon, 04 Dec 2017 06:04:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512396251; cv=none; d=google.com; s=arc-20160816; b=ZShm0qsuwuzs2b8j3tScKy6CO+7ayxIHSWgG0VL/gTz+LBHjhm/hLbFll+LAzMbR2u 4Z3GRtfXk+HLyWtIvmoHhwAxHPV6WRQQzuapjwFiQipqQdSHDvO+AoNNWTe4oaunsDIy j+0BmI9oU0J4Brf2vBz6Jx9gvN0E7jAc5MXIcUBSia+MHyGbEYDDWRFb6xl+Ri/F/hHa pMFrxnfxx37q/S7b2tJ3rbomV6FZt6Jic7NW/rlJfcHT7gsFizvgvqeQhg8pbJO3q/tw ROojBmqwOAYCsfYhWXRpdTgQZ4ScS71B9P3lkNxuOaq5wx2uFc9Fb2PyxLk/VTtTGgI+ rwLQ== 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:dkim-signature:arc-authentication-results; bh=+CusPMXYVrjOVmHAylBHwzDxwi7kqn3PcS/X5orpTAs=; b=WJ2s5ypy05s7Iq2N453z/a7QKxrmuwf1jhKlg2/3J6ugeIYQUBCi62yIzP7Q44YCIu VTdUiGD/l0gNZPxPpcORJLbwrDG6qXISnFc4lbIVQua1nuHHDH2b0DO6BJ2NiymZXcW0 JtsY4UoVJEXURm0jk/TqTyZ6ZnuW6FDKAfKYpFGY8Ge/FYtwujg49xMs5AV9xdbW7+Gv x4uJwMTZ/b3m+0cjyEmvZ6/RpWT8MW/FXQ/WAvMPKa6SxrdGjAvg4ySvG43hV5g3PM5w qLEcS9ghnBX+ioPgspk1e5O+4uwa4q2KE6FmBV2WbfZzkGKXEnb2aVe6ZyJ76A2ZqG0A lZKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@christofferdall-dk.20150623.gappssmtp.com header.s=20150623 header.b=Dsjk1uz/; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 g31si5138782pld.67.2017.12.04.06.04.11; Mon, 04 Dec 2017 06:04:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@christofferdall-dk.20150623.gappssmtp.com header.s=20150623 header.b=Dsjk1uz/; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754464AbdLDOEI (ORCPT + 9 others); Mon, 4 Dec 2017 09:04:08 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:38627 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754380AbdLDOD7 (ORCPT ); Mon, 4 Dec 2017 09:03:59 -0500 Received: by mail-wr0-f194.google.com with SMTP id o2so17413034wro.5 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=PYYTLd4xDGiUTxHvizIkrm3iFsdAWNiYCZ48EI3BA0EF6I6/IRbU6Uu0aHCXjanUoN KlYbN1mqwju0EpGkVm0z3hvPsnbw+IsJySoEPTA8AxXZsHo3OmUruRJufVS2H9wAgZlv Xlf2k5uLVUql7gZ0kZ0aIponX8OJ2aUSmKn4WCAC0nRQpiP6MIxhxYkfoHl/7bEKc5x9 chjqzPXGxeMNQ5J6ytblmZ05KYP7Q9UFkFof/fZPm4ObIABAC8z5tBlQx7II56L0WwP+ skMigWEFET5UcAy8IQv21A9EvrgdBQHQ1MX1yj3+T5wd6skvSCDP6zMLAx72nedXhd8v 2qUA== X-Gm-Message-State: AJaThX6z/+XWKyPu32ndcbQtPBUTGg+RNhO/FGBhVgalqyvb71jHsDQP 0y270z1PeQv/Lyd8otYZC93bGw== 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?b?UmFkaW0gS3LEjW3DocWZ?= 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: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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(-) -- 2.14.2 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)