From patchwork Mon Dec 28 12:50:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 7925951 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 933969F387 for ; Mon, 28 Dec 2015 12:50:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A3BB920259 for ; Mon, 28 Dec 2015 12:50:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9EA6420256 for ; Mon, 28 Dec 2015 12:50:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752125AbbL1MuV (ORCPT ); Mon, 28 Dec 2015 07:50:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51461 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752049AbbL1MuU (ORCPT ); Mon, 28 Dec 2015 07:50:20 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id DC335C027326; Mon, 28 Dec 2015 12:50:19 +0000 (UTC) Received: from redhat.com (vpn1-6-250.ams2.redhat.com [10.36.6.250]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id tBSCoFbJ015571; Mon, 28 Dec 2015 07:50:16 -0500 Date: Mon, 28 Dec 2015 14:50:15 +0200 From: "Michael S. Tsirkin" To: Xiao Guangrong Cc: pbonzini@redhat.com, imammedo@redhat.com, gleb@kernel.org, mtosatti@redhat.com, stefanha@redhat.com, rth@twiddle.net, ehabkost@redhat.com, dan.j.williams@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, Laszlo Ersek Subject: Re: How to reserve guest physical region for ACPI Message-ID: <20151228141917-mutt-send-email-mst@redhat.com> References: <1449040860-19040-1-git-send-email-guangrong.xiao@linux.intel.com> <5680A0C8.6040505@linux.intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5680A0C8.6040505@linux.intel.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Dec 28, 2015 at 10:39:04AM +0800, Xiao Guangrong wrote: > > Hi Michael, Paolo, > > Now it is the time to return to the challenge that how to reserve guest > physical region internally used by ACPI. > > Igor suggested that: > | An alternative place to allocate reserve from could be high memory. > | For pc we have "reserved-memory-end" which currently makes sure > | that hotpluggable memory range isn't used by firmware > (https://lists.nongnu.org/archive/html/qemu-devel/2015-11/msg00926.html) I don't want to tie things to reserved-memory-end because this does not scale: next time we need to reserve memory, we'll need to find yet another way to figure out what is where. I would like ./hw/acpi/bios-linker-loader.c interface to be extended to support 64 bit RAM instead (and maybe a way to allocate and zero-initialize buffer without loading it through fwcfg), this way bios does the allocation, and addresses can be patched into acpi. See patch at the bottom that might be handy. > he also innovated a way to use 64-bit address in DSDT/SSDT.rev = 1: > | when writing ASL one shall make sure that only XP supported > | features are in global scope, which is evaluated when tables > | are loaded and features of rev2 and higher are inside methods. > | That way XP doesn't crash as far as it doesn't evaluate unsupported > | opcode and one can guard those opcodes checking _REV object if neccesary. > (https://lists.nongnu.org/archive/html/qemu-devel/2015-11/msg01010.html) Yes, this technique works. An alternative is to add an XSDT, XP ignores that. XSDT at the moment breaks OVMF (because it loads both the RSDT and the XSDT, which is wrong), but I think Laszlo was working on a fix for that. > Michael, Paolo, what do you think about these ideas? > > Thanks! So using a patch below, we can add Name(PQRS, 0x0) at the top of the SSDT (or bottom, or add a separate SSDT just for that). It returns the current offset so we can add that to the linker. Won't work if you append the Name to the Aml structure (these can be nested to arbitrary depth using aml_append), so using plain GArray for this API makes sense to me. ---> acpi: add build_append_named_dword, returning an offset in buffer This is a very limited form of support for runtime patching - similar in functionality to what we can do with ACPI_EXTRACT macros in python, but implemented in C. This is to allow ACPI code direct access to data tables - which is exactly what DataTableRegion is there for, except no known windows release so far implements DataTableRegion. Signed-off-by: Michael S. Tsirkin --- -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 1b632dc..f8998ea 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -286,4 +286,7 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre); void build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets); +int +build_append_named_dword(GArray *array, const char *name_format, ...); + #endif diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 0d4b324..7f9fa65 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -262,6 +262,32 @@ static void build_append_int(GArray *table, uint64_t value) } } +/* Build NAME(XXXX, 0x0) where 0x0 is encoded as a qword, + * and return the offset to 0x0 for runtime patching. + * + * Warning: runtime patching is best avoided. Only use this as + * a replacement for DataTableRegion (for guests that don't + * support it). + */ +int +build_append_named_qword(GArray *array, const char *name_format, ...) +{ + int offset; + va_list ap; + + va_start(ap, name_format); + build_append_namestringv(array, name_format, ap); + va_end(ap); + + build_append_byte(array, 0x0E); /* QWordPrefix */ + + offset = array->len; + build_append_int_noprefix(array, 0x0, 8); + assert(array->len == offset + 8); + + return offset; +} + static GPtrArray *alloc_list; static Aml *aml_alloc(void)