Re: [kvm-unit-tests PATCH 07/14] vm/page: provide PGDIR_OFFSET() macro

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 14, 2016 at 08:40:45PM +0800, Peter Xu wrote:
> This can be used in further patches.
> 
> Signed-off-by: Peter Xu <peterx@xxxxxxxxxx>
> ---
>  lib/x86/asm/page.h | 3 +++
>  lib/x86/vm.c       | 4 ++--
>  2 files changed, 5 insertions(+), 2 deletions(-)

Reviewed-by: Andrew Jones <drjones@xxxxxxxxxx>

> 
> diff --git a/lib/x86/asm/page.h b/lib/x86/asm/page.h
> index 5044a49..c43bab2 100644
> --- a/lib/x86/asm/page.h
> +++ b/lib/x86/asm/page.h
> @@ -41,5 +41,8 @@
>  #define	PGDIR_MASK	1023
>  #endif
>  
> +#define PGDIR_BITS(lvl)        (((lvl) - 1) * PGDIR_WIDTH + PAGE_SHIFT)
> +#define PGDIR_OFFSET(va, lvl)  (((va) >> PGDIR_BITS(lvl)) & PGDIR_MASK)
> +
>  #endif /* !__ASSEMBLY__ */
>  #endif
> diff --git a/lib/x86/vm.c b/lib/x86/vm.c
> index 9771bd7..f97d1e5 100644
> --- a/lib/x86/vm.c
> +++ b/lib/x86/vm.c
> @@ -48,7 +48,7 @@ unsigned long *install_pte(unsigned long *cr3,
>      unsigned offset;
>  
>      for (level = PAGE_LEVEL; level > pte_level; --level) {
> -	offset = ((unsigned long)virt >> ((level-1) * PGDIR_WIDTH + 12)) & PGDIR_MASK;
> +	offset = PGDIR_OFFSET((unsigned long)virt, level);
>  	if (!(pt[offset] & PT_PRESENT_MASK)) {
>  	    unsigned long *new_pt = pt_page;
>              if (!new_pt)
> @@ -60,7 +60,7 @@ unsigned long *install_pte(unsigned long *cr3,
>  	}
>  	pt = phys_to_virt(pt[offset] & PT_ADDR_MASK);
>      }
> -    offset = ((unsigned long)virt >> ((level-1) * PGDIR_WIDTH + 12)) & PGDIR_MASK;
> +    offset = PGDIR_OFFSET((unsigned long)virt, level);
>      pt[offset] = pte;
>      return &pt[offset];
>  }
> -- 
> 2.7.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux