From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Fri, 23 Aug 2019 07:53:43 -0700 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87A123090FC1; Fri, 23 Aug 2019 14:53:42 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-117-39.ams2.redhat.com [10.36.117.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77A796CE79; Fri, 23 Aug 2019 14:53:33 +0000 (UTC) Subject: Re: [edk2-rfc] [edk2-devel] CPU hotplug using SMM with QEMU+OVMF To: Paolo Bonzini , "Kinney, Michael D" , "rfc@edk2.groups.io" , "Yao, Jiewen" Cc: Alex Williamson , "devel@edk2.groups.io" , qemu devel list , Igor Mammedov , "Chen, Yingwen" , "Nakajima, Jun" , Boris Ostrovsky , Joao Marcal Lemos Martins , Phillip Goerl References: <8091f6e8-b1ec-f017-1430-00b0255729f4@redhat.com> <74D8A39837DF1E4DA445A8C0B3885C503F75FAD3@shsmsx102.ccr.corp.intel.com> <7cb458ea-956e-c1df-33f7-025e4f0f22df@redhat.com> <74D8A39837DF1E4DA445A8C0B3885C503F7600B9@shsmsx102.ccr.corp.intel.com> <20190816161933.7d30a881@x1.home> <74D8A39837DF1E4DA445A8C0B3885C503F761B96@shsmsx102.ccr.corp.intel.com> <35396800-32d2-c25f-b0d0-2d7cd8438687@redhat.com> <772d64f7-e153-e9e6-dd69-9f34de5bb577@redhat.com> <3ca65433-8aed-57d4-7f18-a2a2718a6ffe@redhat.com> From: "Laszlo Ersek" Message-ID: <88721a95-a31a-5302-3614-17440c7eb508@redhat.com> Date: Fri, 23 Aug 2019 16:53:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 23 Aug 2019 14:53:42 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 08/22/19 20:51, Paolo Bonzini wrote: > On 22/08/19 20:29, Laszlo Ersek wrote: >> On 08/22/19 08:18, Paolo Bonzini wrote: >>> On 21/08/19 22:17, Kinney, Michael D wrote: >>>> DMA protection of memory ranges is a chipset feature. For the current >>>> QEMU implementation, what ranges of memory are guaranteed to be >>>> protected from DMA? Is it only A/B seg and TSEG? >>> >>> Yes. >> >> This thread (esp. Jiewen's and Mike's messages) are the first time that >> I've heard about the *existence* of such RAM ranges / the chipset >> feature. :) >> >> Out of interest (independently of virtualization), how is a general >> purpose OS informed by the firmware, "never try to set up DMA to this >> RAM area"? Is this communicated through ACPI _CRS perhaps? >> >> ... Ah, almost: ACPI 6.2 specifies _DMA, in "6.2.4 _DMA (Direct Memory >> Access)". It writes, >> >> For example, if a platform implements a PCI bus that cannot access >> all of physical memory, it has a _DMA object under that PCI bus that >> describes the ranges of physical memory that can be accessed by >> devices on that bus. >> >> Sorry about the digression, and also about being late to this thread, >> continually -- I'm primarily following and learning. > > It's much simpler: these ranges are not in e820, for example > > kernel: BIOS-e820: [mem 0x0000000000059000-0x000000000008bfff] usable > kernel: BIOS-e820: [mem 0x000000000008c000-0x00000000000fffff] reserved (1) Sorry, my _DMA quote was a detour from QEMU -- I wondered how a physical machine with actual RAM at 0x30000, and also chipset level protection against DMA to/from that RAM range, would expose the fact to the OS (so that the OS not innocently try to set up DMA there). (2) In case of QEMU+OVMF, "e820" is not defined at the firmware level. While - QEMU exports an "e820 map" (and OVMF does utilize that), - and Linux parses the UEFI memmap into an "e820 map" (so that dependent logic only need to deal with e820), in edk2 the concepts are "GCD memory space map" and "UEFI memmap". So what OVMF does is, it reserves the TSEG area in the UEFI memmap: https://github.com/tianocore/edk2/commit/b09c1c6f2569a (This was later de-constified for the extended TSEG size, in commit 23bfb5c0aab6, "OvmfPkg/PlatformPei: prepare for PcdQ35TsegMbytes becoming dynamic", 2017-07-05). This is just to say that with OVMF, TSEG is not absent from the UEFI memmap, it is reserved instead. (Apologies if I misunderstood and you didn't actually claim otherwise.) > The ranges are not special-cased in any way by QEMU. Simply, AB-segs > and TSEG RAM are not part of the address space except when in SMM. (or when TSEG is not locked, and open; but:) yes, this matches my understanding. > Therefore, DMA to those ranges ends up respectively to low VGA RAM[1] > and to the bit bucket. When AB-segs are open, for example, DMA to that > area becomes possible. Which seems to imply that, if we alias 0x30000 to the AB-segs, and rely on the AB-segs for CPU hotplug, OVMF should close and lock down the AB-segs at first boot. Correct? (Because OVMF doesn't do anything about AB at the moment.) Thanks Laszlo > > Paolo > > [1] old timers may remember DEF SEG=&HB800: BLOAD "foo.img",0. It still > works with some disk device models. >