[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220616011926.hjmogvbzo6e4d5cj@black.fi.intel.com>
Date: Thu, 16 Jun 2022 04:19:26 +0300
From: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
To: Dave Hansen <dave.hansen@...el.com>
Cc: tglx@...utronix.de, mingo@...hat.com, bp@...en8.de,
luto@...nel.org, peterz@...radead.org, ak@...ux.intel.com,
dan.j.williams@...el.com, david@...hat.com, hpa@...or.com,
linux-kernel@...r.kernel.org,
sathyanarayanan.kuppuswamy@...ux.intel.com, seanjc@...gle.com,
thomas.lendacky@....com, x86@...nel.org
Subject: Re: [PATCHv4 3/3] x86/tdx: Handle load_unaligned_zeropad()
page-cross to a shared page
On Wed, Jun 15, 2022 at 04:34:48PM -0700, Dave Hansen wrote:
> On 6/15/22 15:52, Kirill A. Shutemov wrote:
> >> + vaddr = (unsigned long)insn_get_addr_ref(&insn, regs);
> >> + if (vaddr / PAGE_SIZE != (vaddr + size) / PAGE_SIZE)
> > Oops. I just realized it has off-by-one. It supposed to be:
> >
> > if (vaddr / PAGE_SIZE != (vaddr + size - 1) / PAGE_SIZE)
>
> That was bugging me. Glad you caught this.
>
> Wouldn't this be more obviously correct?
>
> if (ALIGN_DOWN(vaddr, PAGE_SIZE) !=
> ALIGN_DOWN(vaddr + size, PAGE_SIZE))
> ...
I don't think it fixes anything.
Consider the case when vaddr is 4092 and size is 4. This is legitimate
access -- aligned and not page crosser.
The left side of the check will be evaluated to 0 and the right will be 1
which is wrong and will get us -EFAULT.
I cannot think of a helper that would fit the need.
--
Kirill A. Shutemov
Powered by blists - more mailing lists