public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: linux-kernel@vger.kernel.org, x86@kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"Kirill A. Shutemov" <kirill@shutemov.name>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Michael Roth <michael.roth@amd.com>,
	Joerg Roedel <jroedel@suse.de>,
	Dionna Glaze <dionnaglaze@google.com>,
	Andy Lutomirski <luto@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH 1/6] x86/sev: Fix calculation of end address based on number of pages
Date: Fri, 19 May 2023 11:31:52 -0500	[thread overview]
Message-ID: <0cce2c41-bd61-122c-05a9-89ed78fbdaaa@amd.com> (raw)
In-Reply-To: <b5671e1d6d7b1b9e6ed9f5bde15cdd06aca2671b.1684513457.git.thomas.lendacky@amd.com>

Hit send by mistake so I missed adding the cover letter and version 
update. Resending...

Thanks,
Tom

On 5/19/23 11:24, Tom Lendacky wrote:
> When calculating an end address based on an unsigned int number of pages,
> any value greater than or equal to 0x100000 that is shift PAGE_SHIFT bits
> results in a 0 value, resulting in an invalid end address. Change the
> number of pages variable in various routines from an unsigned int to an
> unsigned long to calculate the end address correctly.
> 
> Fixes: 5e5ccff60a29 ("x86/sev: Add helper for validating pages in early enc attribute changes")
> Fixes: dc3f3d2474b8 ("x86/mm: Validate memory when changing the C-bit")
> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
>   arch/x86/include/asm/sev.h | 16 ++++++++--------
>   arch/x86/kernel/sev.c      | 14 +++++++-------
>   2 files changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h
> index 13dc2a9d23c1..7ca5c9ec8b52 100644
> --- a/arch/x86/include/asm/sev.h
> +++ b/arch/x86/include/asm/sev.h
> @@ -192,12 +192,12 @@ struct snp_guest_request_ioctl;
>   
>   void setup_ghcb(void);
>   void __init early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
> -					 unsigned int npages);
> +					 unsigned long npages);
>   void __init early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr,
> -					unsigned int npages);
> +					unsigned long npages);
>   void __init snp_prep_memory(unsigned long paddr, unsigned int sz, enum psc_op op);
> -void snp_set_memory_shared(unsigned long vaddr, unsigned int npages);
> -void snp_set_memory_private(unsigned long vaddr, unsigned int npages);
> +void snp_set_memory_shared(unsigned long vaddr, unsigned long npages);
> +void snp_set_memory_private(unsigned long vaddr, unsigned long npages);
>   void snp_set_wakeup_secondary_cpu(void);
>   bool snp_init(struct boot_params *bp);
>   void __init __noreturn snp_abort(void);
> @@ -212,12 +212,12 @@ static inline int pvalidate(unsigned long vaddr, bool rmp_psize, bool validate)
>   static inline int rmpadjust(unsigned long vaddr, bool rmp_psize, unsigned long attrs) { return 0; }
>   static inline void setup_ghcb(void) { }
>   static inline void __init
> -early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr, unsigned int npages) { }
> +early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr, unsigned long npages) { }
>   static inline void __init
> -early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr, unsigned int npages) { }
> +early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr, unsigned long npages) { }
>   static inline void __init snp_prep_memory(unsigned long paddr, unsigned int sz, enum psc_op op) { }
> -static inline void snp_set_memory_shared(unsigned long vaddr, unsigned int npages) { }
> -static inline void snp_set_memory_private(unsigned long vaddr, unsigned int npages) { }
> +static inline void snp_set_memory_shared(unsigned long vaddr, unsigned long npages) { }
> +static inline void snp_set_memory_private(unsigned long vaddr, unsigned long npages) { }
>   static inline void snp_set_wakeup_secondary_cpu(void) { }
>   static inline bool snp_init(struct boot_params *bp) { return false; }
>   static inline void snp_abort(void) { }
> diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c
> index b031244d6d2d..108bbae59c35 100644
> --- a/arch/x86/kernel/sev.c
> +++ b/arch/x86/kernel/sev.c
> @@ -645,7 +645,7 @@ static u64 __init get_jump_table_addr(void)
>   	return ret;
>   }
>   
> -static void pvalidate_pages(unsigned long vaddr, unsigned int npages, bool validate)
> +static void pvalidate_pages(unsigned long vaddr, unsigned long npages, bool validate)
>   {
>   	unsigned long vaddr_end;
>   	int rc;
> @@ -662,7 +662,7 @@ static void pvalidate_pages(unsigned long vaddr, unsigned int npages, bool valid
>   	}
>   }
>   
> -static void __init early_set_pages_state(unsigned long paddr, unsigned int npages, enum psc_op op)
> +static void __init early_set_pages_state(unsigned long paddr, unsigned long npages, enum psc_op op)
>   {
>   	unsigned long paddr_end;
>   	u64 val;
> @@ -701,7 +701,7 @@ static void __init early_set_pages_state(unsigned long paddr, unsigned int npage
>   }
>   
>   void __init early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
> -					 unsigned int npages)
> +					 unsigned long npages)
>   {
>   	/*
>   	 * This can be invoked in early boot while running identity mapped, so
> @@ -723,7 +723,7 @@ void __init early_snp_set_memory_private(unsigned long vaddr, unsigned long padd
>   }
>   
>   void __init early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr,
> -					unsigned int npages)
> +					unsigned long npages)
>   {
>   	/*
>   	 * This can be invoked in early boot while running identity mapped, so
> @@ -879,7 +879,7 @@ static void __set_pages_state(struct snp_psc_desc *data, unsigned long vaddr,
>   		sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PSC);
>   }
>   
> -static void set_pages_state(unsigned long vaddr, unsigned int npages, int op)
> +static void set_pages_state(unsigned long vaddr, unsigned long npages, int op)
>   {
>   	unsigned long vaddr_end, next_vaddr;
>   	struct snp_psc_desc *desc;
> @@ -904,7 +904,7 @@ static void set_pages_state(unsigned long vaddr, unsigned int npages, int op)
>   	kfree(desc);
>   }
>   
> -void snp_set_memory_shared(unsigned long vaddr, unsigned int npages)
> +void snp_set_memory_shared(unsigned long vaddr, unsigned long npages)
>   {
>   	if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
>   		return;
> @@ -914,7 +914,7 @@ void snp_set_memory_shared(unsigned long vaddr, unsigned int npages)
>   	set_pages_state(vaddr, npages, SNP_PAGE_STATE_SHARED);
>   }
>   
> -void snp_set_memory_private(unsigned long vaddr, unsigned int npages)
> +void snp_set_memory_private(unsigned long vaddr, unsigned long npages)
>   {
>   	if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
>   		return;

  reply	other threads:[~2023-05-19 16:32 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-18 23:14 [PATCHv12 0/9] mm, x86/cc, efi: Implement support for unaccepted memory Kirill A. Shutemov
2023-05-18 23:14 ` [PATCHv12 1/9] mm: Add " Kirill A. Shutemov
2023-05-31 15:51   ` Borislav Petkov
2023-05-31 16:27     ` Kirill A. Shutemov
2023-05-31 17:50       ` Borislav Petkov
2023-05-31 18:10         ` [PATCHv12.1 " Kirill A. Shutemov
2023-05-18 23:14 ` [PATCHv12 2/9] efi/x86: Get full memory map in allocate_e820() Kirill A. Shutemov
2023-05-18 23:14 ` [PATCHv12 3/9] efi/libstub: Implement support for unaccepted memory Kirill A. Shutemov
2023-05-19 15:12   ` Tom Lendacky
2023-05-18 23:14 ` [PATCHv12 4/9] x86/boot/compressed: Handle " Kirill A. Shutemov
2023-05-19 10:16   ` Kirill A. Shutemov
2023-05-22 11:01     ` Kirill A. Shutemov
2023-05-22 11:08       ` Ard Biesheuvel
2023-05-18 23:14 ` [PATCHv12 5/9] efi: Add unaccepted memory support Kirill A. Shutemov
2023-05-18 23:14 ` [PATCHv12 6/9] efi/unaccepted: Avoid load_unaligned_zeropad() stepping into unaccepted memory Kirill A. Shutemov
2023-05-18 23:14 ` [PATCHv12 7/9] x86/tdx: Make _tdx_hypercall() and __tdx_module_call() available in boot stub Kirill A. Shutemov
2023-05-18 23:14 ` [PATCHv12 8/9] x86/tdx: Refactor try_accept_one() Kirill A. Shutemov
2023-05-18 23:14 ` [PATCHv12 9/9] x86/tdx: Add unaccepted memory support Kirill A. Shutemov
2023-05-31  0:58   ` Isaku Yamahata
2023-05-31 12:25     ` Kirill A. Shutemov
2023-05-19 16:24 ` [PATCH 1/6] x86/sev: Fix calculation of end address based on number of pages Tom Lendacky
2023-05-19 16:31   ` Tom Lendacky [this message]
2023-05-19 16:24 ` [PATCH 2/6] x86/sev: Put PSC struct on the stack in prep for unaccepted memory support Tom Lendacky
2023-05-19 16:24 ` [PATCH 3/6] x86/sev: Allow for use of the early boot GHCB for PSC requests Tom Lendacky
2023-05-19 16:24 ` [PATCH 4/6] x86/sev: Use large PSC requests if applicable Tom Lendacky
2023-05-19 16:24 ` [PATCH 5/6] x86/sev: Add SNP-specific unaccepted memory support Tom Lendacky
2023-05-19 16:24 ` [PATCH 6/6] x86/efi: Safely enable unaccepted memory in UEFI Tom Lendacky
2023-05-19 16:30 ` [RESEND PATCH v8 0/6] Provide SEV-SNP support for unaccepted memory Tom Lendacky
2023-05-19 16:30   ` [RESEND PATCH v8 1/6] x86/sev: Fix calculation of end address based on number of pages Tom Lendacky
2023-05-19 16:30   ` [RESEND PATCH v8 2/6] x86/sev: Put PSC struct on the stack in prep for unaccepted memory support Tom Lendacky
2023-05-19 16:30   ` [RESEND PATCH v8 3/6] x86/sev: Allow for use of the early boot GHCB for PSC requests Tom Lendacky
2023-05-19 16:30   ` [RESEND PATCH v8 4/6] x86/sev: Use large PSC requests if applicable Tom Lendacky
2023-06-06 10:46     ` Borislav Petkov
2023-05-19 16:30   ` [RESEND PATCH v8 5/6] x86/sev: Add SNP-specific unaccepted memory support Tom Lendacky
2023-05-19 16:30   ` [RESEND PATCH v8 6/6] x86/efi: Safely enable unaccepted memory in UEFI Tom Lendacky

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=0cce2c41-bd61-122c-05a9-89ed78fbdaaa@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dionnaglaze@google.com \
    --cc=hpa@zytor.com \
    --cc=jroedel@suse.de \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=michael.roth@amd.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox