lkml.org 
[lkml]   [2022]   [Aug]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v5 15/22] x86/virt/tdx: Allocate and set up PAMTs for TDMRs
Date
On Wed, 2022-08-17 at 15:46 -0700, Sagi Shahar wrote:
> > +/*
> > + * Calculate PAMT size given a TDMR and a page size.  The returned
> > + * PAMT size is always aligned up to 4K page boundary.
> > + */
> > +static unsigned long tdmr_get_pamt_sz(struct tdmr_info *tdmr,
> > +                                     enum tdx_page_sz pgsz)
> > +{
> > +       unsigned long pamt_sz;
> > +       int pamt_entry_nr;
>             ^
> This should be an 'unsigned long'. Otherwise you get an integer
> overflow for large memory machines.

Agreed. Thanks.

>
> > +
> > +       switch (pgsz) {
> > +       case TDX_PG_4K:
> > +               pamt_entry_nr = tdmr->size >> PAGE_SHIFT;
> > +               break;
> > +       case TDX_PG_2M:
> > +               pamt_entry_nr = tdmr->size >> PMD_SHIFT;
> > +               break;
> > +       case TDX_PG_1G:
> > +               pamt_entry_nr = tdmr->size >> PUD_SHIFT;
> > +               break;
> > +       default:
> > +               WARN_ON_ONCE(1);
> > +               return 0;
> > +       }
> > +
> > +       pamt_sz = pamt_entry_nr * tdx_sysinfo.pamt_entry_size;
> > +       /* TDX requires PAMT size must be 4K aligned */
> > +       pamt_sz = ALIGN(pamt_sz, PAGE_SIZE);
> > +
> > +       return pamt_sz;
> > +}
> > +

\
 
 \ /
  Last update: 2022-08-18 01:44    [W:0.223 / U:2.460 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site