From patchwork Fri Apr 28 12:03:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikos Nikoleris X-Patchwork-Id: 13226306 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 279F6C77B60 for ; Fri, 28 Apr 2023 12:05:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345937AbjD1MFF (ORCPT ); Fri, 28 Apr 2023 08:05:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345860AbjD1ME4 (ORCPT ); Fri, 28 Apr 2023 08:04:56 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CFE2E2108 for ; Fri, 28 Apr 2023 05:04:55 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C5F4D1480; Fri, 28 Apr 2023 05:05:39 -0700 (PDT) Received: from godel.lab.cambridge.arm.com (godel.lab.cambridge.arm.com [10.7.66.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D41D93F5A1; Fri, 28 Apr 2023 05:04:54 -0700 (PDT) From: Nikos Nikoleris To: kvm@vger.kernel.org, kvmarm@lists.linux.dev, andrew.jones@linux.dev Cc: pbonzini@redhat.com, alexandru.elisei@arm.com, ricarkol@google.com Subject: [kvm-unit-tests PATCH v5 06/29] x86: Avoid references to fields of ACPI tables Date: Fri, 28 Apr 2023 13:03:42 +0100 Message-Id: <20230428120405.3770496-7-nikos.nikoleris@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230428120405.3770496-1-nikos.nikoleris@arm.com> References: <20230428120405.3770496-1-nikos.nikoleris@arm.com> MIME-Version: 1.0 X-ARM-No-Footer: FoSSMail Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org ACPI table definitions in have to be packed. However, once we do that, direct references to members of the packed struct might result in unaligned pointers and gcc complains about them. This change modifies the code to avoid such references in preparation for making the APCI table definitions packed. Signed-off-by: Nikos Nikoleris --- x86/s3.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/x86/s3.c b/x86/s3.c index 96db728c..910c57fb 100644 --- a/x86/s3.c +++ b/x86/s3.c @@ -2,15 +2,6 @@ #include "acpi.h" #include "asm/io.h" -static u32* find_resume_vector_addr(void) -{ - struct acpi_table_facs_rev1 *facs = find_acpi_table_addr(FACS_SIGNATURE); - if (!facs) - return 0; - printf("FACS is at %p\n", facs); - return &facs->firmware_waking_vector; -} - #define RTC_SECONDS_ALARM 1 #define RTC_MINUTES_ALARM 3 #define RTC_HOURS_ALARM 5 @@ -40,12 +31,14 @@ extern char resume_start, resume_end; int main(int argc, char **argv) { struct acpi_table_fadt_rev1 *fadt = find_acpi_table_addr(FACP_SIGNATURE); - volatile u32 *resume_vector_ptr = find_resume_vector_addr(); + struct acpi_table_facs_rev1 *facs = find_acpi_table_addr(FACS_SIGNATURE); char *addr, *resume_vec = (void*)0x1000; - *resume_vector_ptr = (u32)(ulong)resume_vec; + assert(facs); + facs->firmware_waking_vector = (u32)(ulong)resume_vec; - printf("resume vector addr is %p\n", resume_vector_ptr); + printf("FACS is at %p\n", facs); + printf("resume vector addr is %p\n", &facs->firmware_waking_vector); for (addr = &resume_start; addr < &resume_end; addr++) *resume_vec++ = *addr; printf("copy resume code from %p\n", &resume_start);