All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoffer Dall <cdall@linaro.org>
To: Kristina Martsenko <kristina.martsenko@arm.com>
Cc: Christoffer Dall <christoffer.dall@linaro.org>,
	Marc Zyngier <marc.zyngier@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will.deacon@arm.com>,
	linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu, stable@vger.kernel.org
Subject: Re: [PATCH] arm64: KVM: fix VTTBR_BADDR_MASK BUG_ON off-by-one
Date: Mon, 20 Nov 2017 14:12:32 +0100	[thread overview]
Message-ID: <20171120131232.GH28855@cbox> (raw)
In-Reply-To: <1510670263-13092-1-git-send-email-kristina.martsenko@arm.com>

On Tue, Nov 14, 2017 at 02:37:43PM +0000, Kristina Martsenko wrote:
> 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: <stable@vger.kernel.org> # 3.11.x
> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> Signed-off-by: Kristina Martsenko <kristina.martsenko@arm.com>
> ---
>  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 61d694c2eae5..555d463c0eaa 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)
>  
> -- 
> 2.1.4
> 

Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>

WARNING: multiple messages have this Message-ID (diff)
From: cdall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] arm64: KVM: fix VTTBR_BADDR_MASK BUG_ON off-by-one
Date: Mon, 20 Nov 2017 14:12:32 +0100	[thread overview]
Message-ID: <20171120131232.GH28855@cbox> (raw)
In-Reply-To: <1510670263-13092-1-git-send-email-kristina.martsenko@arm.com>

On Tue, Nov 14, 2017 at 02:37:43PM +0000, Kristina Martsenko wrote:
> 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: <stable@vger.kernel.org> # 3.11.x
> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> Signed-off-by: Kristina Martsenko <kristina.martsenko@arm.com>
> ---
>  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 61d694c2eae5..555d463c0eaa 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)
>  
> -- 
> 2.1.4
> 

Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>

  reply	other threads:[~2017-11-20 13:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-14 14:37 [PATCH] arm64: KVM: fix VTTBR_BADDR_MASK BUG_ON off-by-one Kristina Martsenko
2017-11-14 14:37 ` Kristina Martsenko
2017-11-14 14:37 ` Kristina Martsenko
2017-11-20 13:12 ` Christoffer Dall [this message]
2017-11-20 13:12   ` Christoffer Dall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171120131232.GH28855@cbox \
    --to=cdall@linaro.org \
    --cc=catalin.marinas@arm.com \
    --cc=christoffer.dall@linaro.org \
    --cc=kristina.martsenko@arm.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=marc.zyngier@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.