public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: devel@edk2.groups.io, Pawel Polawski <ppolawsk@redhat.com>,
	Jiewen Yao <jiewen.yao@intel.com>,
	Oliver Steffen <osteffen@redhat.com>,
	Jordan Justen <jordan.l.justen@intel.com>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>
Subject: Re: [PATCH v2 4/4] OvmfPkg/PlatformInitLib: Add PlatformReservationConflictCB
Date: Thu, 12 Jan 2023 11:36:03 +0100	[thread overview]
Message-ID: <bc9e6e79-24e6-5aca-010e-69af5f444c83@redhat.com> (raw)
In-Reply-To: <20230111082647.d3bg3er5ofjpszuc@sirius.home.kraxel.org>

On 1/11/23 09:26, Gerd Hoffmann wrote:
>   Hi,
> 
>>> +/**
>>> +  Check whenever the 64bit PCI MMIO window overlaps with a reservation
>>> +  from qemu.  If so move down the MMIO window to resolve the conflict.
>>> +
>>> +  This happens on (virtal) AMD machines with 1TB address space,
>>> +  because the AMD IOMMU uses an address window just below 1GB.
>>
>> (3) Same two typos, I think, as in the commit message.
> 
> Duplicated by the power of cut + paste.
> 
>>> +  NewBase = (PlatformInfoHob->PcdPciMmio64Base -
>>> +             PlatformInfoHob->PcdPciMmio64Size);
>>
>> (6) This appears a typo; we'll want
>>
>>   NewBase + PcdPciMmio64Size == E820Entry->BaseAddr
> 
> But then NewBase is not aligned.  The assignment above moves it down
> while maintaining the existing alignment.

Ah, good point. I totally missed the idea here.

The starting predicate is, apparently, that the base is aligned by size
("naturally aligned"), so by subtracting size from the aperture, we get
a new aperture that conforms to both properties below:

- still naturally aligned (original predicate preserved),

- empty intersection with the original aperture (because the new
aperture will end where the old one just started).

Now, here's one thought: just because the new (sunken) aperture does not
intersect the pre-move aperture, is it guaranteed to also steer clear of
the E820 Entry either?

I don't think that's certain. If the E820 Entry overlaps the bottom of
the original aperture, but goes "deeper" than that, then it will overlap
the top of the sunken aperture too.

So I think we might want to do a two step process here, in case the
original aperture overlaps the E820 Entry:

- push down the aperture (same size) so its exclusive end equal the
inclusive start of the E820 Entry

- align *down* (truncate) the base of the aperture, while keeping its
size unchanged.

Something like:

  NewBase = E820Entry->BaseAddr - PcdPciMmio64Size;

  ASSERT (PcdPciMmio64Size != 0);
  ASSERT ((PcdPciMmio64Size & (PcdPciMmio64Size - 1)) == 0);
  NewBase = NewBase & ~(PcdPciMmio64Size - 1);

> 
>> (9) Do we need any other checks or maybe assertions that we're only
>> conflicting with a reserved area, and/or that the subtraction for
>> NewBase does not underflow?
>>
>> I don't think we can "armor" this very well, I'm just pondering if there
>> are any egregious misunderstandings between QEMU and the firmware that
>> we might want to catch here. If not, that's OK of course.
> 
> Yes, it's hard to design something which can handle all reservations
> qemu might do in the future correctly.  And, yes, the code above works
> because we know the qemu reservation is smaller than the mmio window, so
> moving down to the next naturally aligned address actually solves the
> conflict.

Not only smaller, but also *not encompassing* the lower boundary of the
MMIO window.

Anyway, up to you -- if you want to stick with the logic shown in this
patch, I'm OK, but then please add some comments, or maybe even some
ASSERTs.

Thanks!
Laszlo


      reply	other threads:[~2023-01-12 10:36 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-10  8:21 [PATCH v2 0/4] OvmfPkg: check 64bit mmio window for resource conflicts Gerd Hoffmann
2023-01-10  8:21 ` [PATCH v2 1/4] OvmfPkg/PlatformInitLib: Add PlatformScanE820 and GetFirstNonAddressCB Gerd Hoffmann
2023-01-10 15:41   ` Laszlo Ersek
2023-01-10  8:21 ` [PATCH v2 2/4] OvmfPkg/PlatformInitLib: Add PlatformGetLowMemoryCB Gerd Hoffmann
2023-01-10 16:53   ` Laszlo Ersek
2023-01-11  7:29     ` Gerd Hoffmann
2023-01-11 13:56       ` Laszlo Ersek
2023-01-11 15:23         ` Gerd Hoffmann
2023-01-12 11:09           ` Laszlo Ersek
2023-01-12 14:03             ` Gerd Hoffmann
2023-01-12 15:44               ` Laszlo Ersek
2023-01-10  8:21 ` [PATCH v2 3/4] OvmfPkg/PlatformInitLib: Add PlatformAddHobCB Gerd Hoffmann
2023-01-10 17:42   ` Laszlo Ersek
2023-01-11  8:06     ` Gerd Hoffmann
2023-01-11 14:08       ` Laszlo Ersek
2023-01-10  8:21 ` [PATCH v2 4/4] OvmfPkg/PlatformInitLib: Add PlatformReservationConflictCB Gerd Hoffmann
2023-01-10 17:55   ` Laszlo Ersek
2023-01-11  8:26     ` Gerd Hoffmann
2023-01-12 10:36       ` Laszlo Ersek [this message]

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-list 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=bc9e6e79-24e6-5aca-010e-69af5f444c83@redhat.com \
    --to=devel@edk2.groups.io \
    /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