From patchwork Tue Nov 16 20:40:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixuan Wang X-Patchwork-Id: 12623171 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D628FC433F5 for ; Tue, 16 Nov 2021 20:40:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C28B961BBD for ; Tue, 16 Nov 2021 20:40:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230488AbhKPUnz (ORCPT ); Tue, 16 Nov 2021 15:43:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229614AbhKPUny (ORCPT ); Tue, 16 Nov 2021 15:43:54 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2A14C061570 for ; Tue, 16 Nov 2021 12:40:57 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id gx15-20020a17090b124f00b001a695f3734aso525172pjb.0 for ; Tue, 16 Nov 2021 12:40:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NWDKpsQFk5mN1jQnrTsnd6C8/vgl4oVD+4bLDzSVTA4=; b=BUZriuUCZaEqLELZx01yp5T528kyEBFfOP+m/pnCa/gr0Nr+jVhJmBN4gksVKnllpa rIGvPF/5jY2pXHksacZGehBOvYhZafRVp2bhwGcA1Ir66VCruLifsvFlWptWo0KsBcVe QbUC/24ylEw6N2YOmxh9zlieOOj0pwu766x8L+LKoSiOBnAgTf4QmctxfssXX6MhgTN6 hVWL1Ds5h0TGIYJyFZ7M2PbhxTKUI+42G2Y/0nbsXRehvSiMDoe0+IldRAaBqgUJiMn3 O0tqP5YaZ3O0yCyz7goVHAdNOEYaKn8bwuyS5rS2T6PBJ52LFJSwiRcX+8yEzqfCUzsA 9xkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NWDKpsQFk5mN1jQnrTsnd6C8/vgl4oVD+4bLDzSVTA4=; b=enZVrE75DEujYhnWwXvkYe1MnttZgDiUaJDJ9YyjVqcqfQI8DFvxgsT3vCT5i1FOQF TtSL4swbq+z1LGemWvjli/V+OoGeEdFUrG8GLyEOmK0clQ2HzjYgARU4LcsU7wVsu0hn br/uQFFQVZ87eOFMUOfGjTmRykrhXmCz0ZlI10XQCWIuqiAv91cg8lOkGgO6uNRqzkU+ bqAcx/TpBUfidxSB9luQomjJXG/GTAvDFvvtJAOr1jpOzo44FyRcyESszqOoS5U358Xn X3YAHap3+YXZ0Umz6kx7V8ykvlrruqjxxG/WohXym+qUTDEoRL8REg86bikMokIEjglU CZGg== X-Gm-Message-State: AOAM533Mo0L4bRUJZYsZjAsHct73MTVXG6n01UM2tEjRbps0O53cs1H3 evkfuMvfTDUwYMF9Vo6F5UVdPpI9SXLz1g== X-Google-Smtp-Source: ABdhPJy6X9K6G80bB94GZKjfhaB/vdpu+jgjhSeT0EWqHRb2f71kUduH2YIVKw9vcqtPI7kjk4zPgw== X-Received: by 2002:a17:90a:e7d1:: with SMTP id kb17mr2368408pjb.124.1637095256668; Tue, 16 Nov 2021 12:40:56 -0800 (PST) Received: from localhost.localdomain (netadmin.ucsd.edu. [137.110.160.224]) by smtp.gmail.com with ESMTPSA id lp12sm3652359pjb.24.2021.11.16.12.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 12:40:56 -0800 (PST) From: Zixuan Wang To: kvm@vger.kernel.org, pbonzini@redhat.com, drjones@redhat.com Cc: marcorr@google.com, erdemaktas@google.com, rientjes@google.com, seanjc@google.com, brijesh.singh@amd.com, Thomas.Lendacky@amd.com, varad.gautam@suse.com, jroedel@suse.de, bp@suse.de Subject: [kvm-unit-tests PATCH v2 01/10] x86 UEFI: Remove mixed_mode Date: Tue, 16 Nov 2021 12:40:44 -0800 Message-Id: <20211116204053.220523-2-zxwang42@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211116204053.220523-1-zxwang42@gmail.com> References: <20211116204053.220523-1-zxwang42@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Zixuan Wang Remove the mixed_mode code from efi.h as we are not supporting i386 UEFI for now. Signed-off-by: Zixuan Wang --- lib/linux/efi.h | 317 +++++++++++++++--------------------------------- 1 file changed, 100 insertions(+), 217 deletions(-) diff --git a/lib/linux/efi.h b/lib/linux/efi.h index 7ac1082..455625a 100644 --- a/lib/linux/efi.h +++ b/lib/linux/efi.h @@ -62,15 +62,7 @@ typedef guid_t efi_guid_t; typedef struct { efi_guid_t guid; - u32 table; -} efi_config_table_32_t; - -typedef union { - struct { - efi_guid_t guid; - void *table; - }; - efi_config_table_32_t mixed_mode; + void *table; } efi_config_table_t; /* @@ -251,127 +243,76 @@ typedef struct efi_generic_dev_path efi_device_path_protocol_t; /* * EFI Boot Services table */ -union efi_boot_services { - struct { - efi_table_hdr_t hdr; - void *raise_tpl; - void *restore_tpl; - efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long, - efi_physical_addr_t *); - efi_status_t (__efiapi *free_pages)(efi_physical_addr_t, - unsigned long); - efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *, - unsigned long *, - unsigned long *, u32 *); - efi_status_t (__efiapi *allocate_pool)(int, unsigned long, - void **); - efi_status_t (__efiapi *free_pool)(void *); - efi_status_t (__efiapi *create_event)(u32, unsigned long, - efi_event_notify_t, void *, - efi_event_t *); - efi_status_t (__efiapi *set_timer)(efi_event_t, - EFI_TIMER_DELAY, u64); - efi_status_t (__efiapi *wait_for_event)(unsigned long, - efi_event_t *, - unsigned long *); - void *signal_event; - efi_status_t (__efiapi *close_event)(efi_event_t); - void *check_event; - void *install_protocol_interface; - void *reinstall_protocol_interface; - void *uninstall_protocol_interface; - efi_status_t (__efiapi *handle_protocol)(efi_handle_t, - efi_guid_t *, void **); - void *__reserved; - void *register_protocol_notify; - efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *, - void *, unsigned long *, - efi_handle_t *); - efi_status_t (__efiapi *locate_device_path)(efi_guid_t *, - efi_device_path_protocol_t **, - efi_handle_t *); - efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *, - void *); - void *load_image; - void *start_image; - efi_status_t (__efiapi *exit)(efi_handle_t, - efi_status_t, - unsigned long, - efi_char16_t *); - void *unload_image; - efi_status_t (__efiapi *exit_boot_services)(efi_handle_t, - unsigned long); - void *get_next_monotonic_count; - efi_status_t (__efiapi *stall)(unsigned long); - void *set_watchdog_timer; - void *connect_controller; - efi_status_t (__efiapi *disconnect_controller)(efi_handle_t, - efi_handle_t, - efi_handle_t); - void *open_protocol; - void *close_protocol; - void *open_protocol_information; - void *protocols_per_handle; - void *locate_handle_buffer; - efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *, - void **); - void *install_multiple_protocol_interfaces; - void *uninstall_multiple_protocol_interfaces; - void *calculate_crc32; - void *copy_mem; - void *set_mem; - void *create_event_ex; - }; - struct { - efi_table_hdr_t hdr; - u32 raise_tpl; - u32 restore_tpl; - u32 allocate_pages; - u32 free_pages; - u32 get_memory_map; - u32 allocate_pool; - u32 free_pool; - u32 create_event; - u32 set_timer; - u32 wait_for_event; - u32 signal_event; - u32 close_event; - u32 check_event; - u32 install_protocol_interface; - u32 reinstall_protocol_interface; - u32 uninstall_protocol_interface; - u32 handle_protocol; - u32 __reserved; - u32 register_protocol_notify; - u32 locate_handle; - u32 locate_device_path; - u32 install_configuration_table; - u32 load_image; - u32 start_image; - u32 exit; - u32 unload_image; - u32 exit_boot_services; - u32 get_next_monotonic_count; - u32 stall; - u32 set_watchdog_timer; - u32 connect_controller; - u32 disconnect_controller; - u32 open_protocol; - u32 close_protocol; - u32 open_protocol_information; - u32 protocols_per_handle; - u32 locate_handle_buffer; - u32 locate_protocol; - u32 install_multiple_protocol_interfaces; - u32 uninstall_multiple_protocol_interfaces; - u32 calculate_crc32; - u32 copy_mem; - u32 set_mem; - u32 create_event_ex; - } mixed_mode; -}; - -typedef union efi_boot_services efi_boot_services_t; +typedef struct { + efi_table_hdr_t hdr; + void *raise_tpl; + void *restore_tpl; + efi_status_t(__efiapi *allocate_pages)(int, int, unsigned long, + efi_physical_addr_t *); + efi_status_t(__efiapi *free_pages)(efi_physical_addr_t, + unsigned long); + efi_status_t(__efiapi *get_memory_map)(unsigned long *, void *, + unsigned long *, + unsigned long *, u32 *); + efi_status_t(__efiapi *allocate_pool)(int, unsigned long, + void **); + efi_status_t(__efiapi *free_pool)(void *); + efi_status_t(__efiapi *create_event)(u32, unsigned long, + efi_event_notify_t, void *, + efi_event_t *); + efi_status_t(__efiapi *set_timer)(efi_event_t, + EFI_TIMER_DELAY, u64); + efi_status_t(__efiapi *wait_for_event)(unsigned long, + efi_event_t *, + unsigned long *); + void *signal_event; + efi_status_t(__efiapi *close_event)(efi_event_t); + void *check_event; + void *install_protocol_interface; + void *reinstall_protocol_interface; + void *uninstall_protocol_interface; + efi_status_t(__efiapi *handle_protocol)(efi_handle_t, + efi_guid_t *, void **); + void *__reserved; + void *register_protocol_notify; + efi_status_t(__efiapi *locate_handle)(int, efi_guid_t *, + void *, unsigned long *, + efi_handle_t *); + efi_status_t(__efiapi *locate_device_path)(efi_guid_t *, + efi_device_path_protocol_t **, + efi_handle_t *); + efi_status_t(__efiapi *install_configuration_table)(efi_guid_t *, + void *); + void *load_image; + void *start_image; + efi_status_t(__efiapi *exit)(efi_handle_t, + efi_status_t, + unsigned long, + efi_char16_t *); + void *unload_image; + efi_status_t(__efiapi *exit_boot_services)(efi_handle_t, + unsigned long); + void *get_next_monotonic_count; + efi_status_t(__efiapi *stall)(unsigned long); + void *set_watchdog_timer; + void *connect_controller; + efi_status_t(__efiapi *disconnect_controller)(efi_handle_t, + efi_handle_t, + efi_handle_t); + void *open_protocol; + void *close_protocol; + void *open_protocol_information; + void *protocols_per_handle; + void *locate_handle_buffer; + efi_status_t(__efiapi *locate_protocol)(efi_guid_t *, void *, + void **); + void *install_multiple_protocol_interfaces; + void *uninstall_multiple_protocol_interfaces; + void *calculate_crc32; + void *copy_mem; + void *set_mem; + void *create_event_ex; +} efi_boot_services_t; /* * Types and defines for EFI ResetSystem @@ -386,24 +327,6 @@ typedef union efi_boot_services efi_boot_services_t; #define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL) #define EFI_RUNTIME_SERVICES_REVISION 0x00010000 -typedef struct { - efi_table_hdr_t hdr; - u32 get_time; - u32 set_time; - u32 get_wakeup_time; - u32 set_wakeup_time; - u32 set_virtual_address_map; - u32 convert_pointer; - u32 get_variable; - u32 get_next_variable; - u32 set_variable; - u32 get_next_high_mono_count; - u32 reset_system; - u32 update_capsule; - u32 query_capsule_caps; - u32 query_variable_info; -} efi_runtime_services_32_t; - typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc); typedef efi_status_t efi_set_time_t (efi_time_t *tm); typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending, @@ -438,25 +361,22 @@ typedef efi_status_t efi_query_variable_store_t(u32 attributes, unsigned long size, bool nonblocking); -typedef union { - struct { - efi_table_hdr_t hdr; - efi_get_time_t __efiapi *get_time; - efi_set_time_t __efiapi *set_time; - efi_get_wakeup_time_t __efiapi *get_wakeup_time; - efi_set_wakeup_time_t __efiapi *set_wakeup_time; - efi_set_virtual_address_map_t __efiapi *set_virtual_address_map; - void *convert_pointer; - efi_get_variable_t __efiapi *get_variable; - efi_get_next_variable_t __efiapi *get_next_variable; - efi_set_variable_t __efiapi *set_variable; - efi_get_next_high_mono_count_t __efiapi *get_next_high_mono_count; - efi_reset_system_t __efiapi *reset_system; - efi_update_capsule_t __efiapi *update_capsule; - efi_query_capsule_caps_t __efiapi *query_capsule_caps; - efi_query_variable_info_t __efiapi *query_variable_info; - }; - efi_runtime_services_32_t mixed_mode; +typedef struct { + efi_table_hdr_t hdr; + efi_get_time_t __efiapi *get_time; + efi_set_time_t __efiapi *set_time; + efi_get_wakeup_time_t __efiapi *get_wakeup_time; + efi_set_wakeup_time_t __efiapi *set_wakeup_time; + efi_set_virtual_address_map_t __efiapi *set_virtual_address_map; + void *convert_pointer; + efi_get_variable_t __efiapi *get_variable; + efi_get_next_variable_t __efiapi *get_next_variable; + efi_set_variable_t __efiapi *set_variable; + efi_get_next_high_mono_count_t __efiapi *get_next_high_mono_count; + efi_reset_system_t __efiapi *reset_system; + efi_update_capsule_t __efiapi *update_capsule; + efi_query_capsule_caps_t __efiapi *query_capsule_caps; + efi_query_variable_info_t __efiapi *query_variable_info; } efi_runtime_services_t; #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL) @@ -468,60 +388,23 @@ typedef union { #define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | (10)) #define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | (02)) -typedef struct { - efi_table_hdr_t hdr; - u64 fw_vendor; /* physical addr of CHAR16 vendor string */ - u32 fw_revision; - u32 __pad1; - u64 con_in_handle; - u64 con_in; - u64 con_out_handle; - u64 con_out; - u64 stderr_handle; - u64 stderr; - u64 runtime; - u64 boottime; - u32 nr_tables; - u32 __pad2; - u64 tables; -} efi_system_table_64_t; +typedef union efi_simple_text_input_protocol efi_simple_text_input_protocol_t; +typedef union efi_simple_text_output_protocol efi_simple_text_output_protocol_t; typedef struct { efi_table_hdr_t hdr; - u32 fw_vendor; /* physical addr of CHAR16 vendor string */ + unsigned long fw_vendor; /* physical addr of CHAR16 vendor string */ u32 fw_revision; - u32 con_in_handle; - u32 con_in; - u32 con_out_handle; - u32 con_out; - u32 stderr_handle; - u32 stderr; - u32 runtime; - u32 boottime; - u32 nr_tables; - u32 tables; -} efi_system_table_32_t; - -typedef union efi_simple_text_input_protocol efi_simple_text_input_protocol_t; -typedef union efi_simple_text_output_protocol efi_simple_text_output_protocol_t; - -typedef union { - struct { - efi_table_hdr_t hdr; - unsigned long fw_vendor; /* physical addr of CHAR16 vendor string */ - u32 fw_revision; - unsigned long con_in_handle; - efi_simple_text_input_protocol_t *con_in; - unsigned long con_out_handle; - efi_simple_text_output_protocol_t *con_out; - unsigned long stderr_handle; - unsigned long stderr; - efi_runtime_services_t *runtime; - efi_boot_services_t *boottime; - unsigned long nr_tables; - unsigned long tables; - }; - efi_system_table_32_t mixed_mode; + unsigned long con_in_handle; + efi_simple_text_input_protocol_t *con_in; + unsigned long con_out_handle; + efi_simple_text_output_protocol_t *con_out; + unsigned long stderr_handle; + unsigned long stderr; + efi_runtime_services_t *runtime; + efi_boot_services_t *boottime; + unsigned long nr_tables; + unsigned long tables; } efi_system_table_t; struct efi_boot_memmap { From patchwork Tue Nov 16 20:40:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixuan Wang X-Patchwork-Id: 12623173 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88493C433EF for ; Tue, 16 Nov 2021 20:41:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67E1861BBD for ; Tue, 16 Nov 2021 20:41:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230493AbhKPUn4 (ORCPT ); Tue, 16 Nov 2021 15:43:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229614AbhKPUn4 (ORCPT ); Tue, 16 Nov 2021 15:43:56 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1883C061570 for ; Tue, 16 Nov 2021 12:40:58 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id iq11so420497pjb.3 for ; Tue, 16 Nov 2021 12:40:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EkWXUimwz4xAip6Df8riMGQc04C7loo3bf7EoovJCi8=; b=aL+iwW+JpCBgZ14qGGjKIsNGxkLH/yzJXR2KnU5ge0uJhQFC6DotZXPC9WlEUYBzMO mRiWivV/87wsz/T+wNi1DNCDji6N1x+NYs9zq5s7ilivDK+GfsADa8upxk5ghgE/TZKf VvFANJzeTxa/Lij4RiXW7sr/I4AfZSXnVMXpAYw36qABo+y+85utCJLBBHLUtY+KQ8Sa 10bT6LwT8JokiUix5ZjwRfzaaQ1oy99bllfjwzxshpbFoWmohcQgtKQ1cP08KVFAPvLT vu7H6pqXptvglQhbRsMlsCwm5JOLxP7BhffNO4k4SeaeK+bO/4Uh7WNXGgOAT36XrO5a dsZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EkWXUimwz4xAip6Df8riMGQc04C7loo3bf7EoovJCi8=; b=xaRUaQQroEi8DfH0i4CPEa9Yx6oGKPgYhQRYQCaQx3EeaRJ3sP3k/eYSu2KxIiCb3a EKrNGKZ3xti8ezjnCtZ0+y0STpTM3XC8e2OewqbaOdsi38KOJf/fYBeCdvXWKPqKOBld ZN954YqE6QFNl6yJZ3UgFUOrI0eVMcebHKYS50j+2+VKevaCXr99jtEl0ia0j8pfEcLR +vdSwXSpgqz9umfbNVcu0e1AgxO3vVhDNrAOmWX/E7kJFitlC12pKuxGWHNRSSde2+FU SsElrfRQGu8ONOL9A8CS2RKzNy8mEooaeFMJUt6UtmIFk7w9dt1NCWfOfEqUXs2uc5bj yh3Q== X-Gm-Message-State: AOAM531Qlx5GeCs3T0/uFjK+/nqqlLBV5LlUxh4dRpjz8W6WLaVf5C6r p1Ks3CnGUCF7MkS3Vi4vtJK3bNg6f4bs8w== X-Google-Smtp-Source: ABdhPJz/H6NvkreKLfgqYbz4t1O9mpUNSnaH2QrEXcmW941D/Pb7WsiJ4OFy45AkovL82LX189lfgA== X-Received: by 2002:a17:902:7c88:b0:142:5f2f:182a with SMTP id y8-20020a1709027c8800b001425f2f182amr49082932pll.72.1637095258002; Tue, 16 Nov 2021 12:40:58 -0800 (PST) Received: from localhost.localdomain (netadmin.ucsd.edu. [137.110.160.224]) by smtp.gmail.com with ESMTPSA id lp12sm3652359pjb.24.2021.11.16.12.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 12:40:57 -0800 (PST) From: Zixuan Wang To: kvm@vger.kernel.org, pbonzini@redhat.com, drjones@redhat.com Cc: marcorr@google.com, erdemaktas@google.com, rientjes@google.com, seanjc@google.com, brijesh.singh@amd.com, Thomas.Lendacky@amd.com, varad.gautam@suse.com, jroedel@suse.de, bp@suse.de Subject: [kvm-unit-tests PATCH v2 02/10] x86 UEFI: Refactor set up process Date: Tue, 16 Nov 2021 12:40:45 -0800 Message-Id: <20211116204053.220523-3-zxwang42@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211116204053.220523-1-zxwang42@gmail.com> References: <20211116204053.220523-1-zxwang42@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Zixuan Wang Refactor the EFI set up process. The previous set up process calls multiple arch-specific functions, now it's simplified to call only one arch-specific function: 1. (Arch neutral ) Extract EFI data structures, e.g., memory maps 2. (Arch neutral ) Exit EFI boot services 3. (Arch specific) Parse EFI data structures and set up arch-specific resources 4. (Arch neutral ) Run test cases' main functions Signed-off-by: Zixuan Wang --- lib/efi.c | 50 ++++++++++++--- lib/efi.h | 19 ++++-- lib/x86/acpi.c | 36 ++++++----- lib/x86/acpi.h | 5 +- lib/x86/asm/setup.h | 16 +---- lib/x86/setup.c | 150 ++++++++++++++++++++------------------------ 6 files changed, 146 insertions(+), 130 deletions(-) diff --git a/lib/efi.c b/lib/efi.c index 9506830..99eb00c 100644 --- a/lib/efi.c +++ b/lib/efi.c @@ -65,9 +65,9 @@ out: return status; } -efi_status_t efi_exit_boot_services(void *handle, unsigned long mapkey) +efi_status_t efi_exit_boot_services(void *handle, struct efi_boot_memmap *map) { - return efi_bs_call(exit_boot_services, handle, mapkey); + return efi_bs_call(exit_boot_services, handle, *map->key_ptr); } efi_status_t efi_get_system_config_table(efi_guid_t table_guid, void **table) @@ -88,31 +88,61 @@ efi_status_t efi_get_system_config_table(efi_guid_t table_guid, void **table) efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) { int ret; - unsigned long mapkey = 0; efi_status_t status; efi_bootinfo_t efi_bootinfo; efi_system_table = sys_tab; - setup_efi_bootinfo(&efi_bootinfo); - status = setup_efi_pre_boot(&mapkey, &efi_bootinfo); + /* Memory map struct values */ + efi_memory_desc_t *map = NULL; + unsigned long map_size = 0, desc_size = 0, key = 0, buff_size = 0; + u32 desc_ver; + + /* Set up efi_bootinfo */ + efi_bootinfo.mem_map.map = ↦ + efi_bootinfo.mem_map.map_size = &map_size; + efi_bootinfo.mem_map.desc_size = &desc_size; + efi_bootinfo.mem_map.desc_ver = &desc_ver; + efi_bootinfo.mem_map.key_ptr = &key; + efi_bootinfo.mem_map.buff_size = &buff_size; + + /* Get EFI memory map */ + status = efi_get_memory_map(&efi_bootinfo.mem_map); if (status != EFI_SUCCESS) { - printf("Failed to set up before ExitBootServices, exiting.\n"); - return status; + printf("Failed to get memory map\n"); + goto efi_main_error; } - status = efi_exit_boot_services(handle, mapkey); + /* + * Exit EFI boot services, let kvm-unit-tests take full control of the + * guest + */ + status = efi_exit_boot_services(handle, &efi_bootinfo.mem_map); if (status != EFI_SUCCESS) { printf("Failed to exit boot services\n"); - return status; + goto efi_main_error; } - setup_efi(&efi_bootinfo); + /* Set up arch-specific resources */ + status = setup_efi(&efi_bootinfo); + if (status != EFI_SUCCESS) { + printf("Failed to set up arch-specific resources\n"); + goto efi_main_error; + } + + /* Run the test case */ ret = main(__argc, __argv, __environ); /* Shutdown the guest VM */ efi_rs_call(reset_system, EFI_RESET_SHUTDOWN, ret, 0, NULL); + /* Unreachable */ + return EFI_UNSUPPORTED; + +efi_main_error: + /* Shutdown the guest with error EFI status */ + efi_rs_call(reset_system, EFI_RESET_SHUTDOWN, status, 0, NULL); + /* Unreachable */ return EFI_UNSUPPORTED; } diff --git a/lib/efi.h b/lib/efi.h index 1b3abd0..ce8b74d 100644 --- a/lib/efi.h +++ b/lib/efi.h @@ -2,9 +2,7 @@ #define _EFI_H_ /* - * EFI-related functions in . This file's name "efi.h" is in - * conflict with GNU-EFI library's "efi.h", but does not include - * GNU-EFI headers or links against GNU-EFI. + * EFI-related functions. * * Copyright (c) 2021, Google Inc, Zixuan Wang * @@ -13,9 +11,20 @@ #include "linux/efi.h" #include -efi_status_t _relocate(long ldbase, Elf64_Dyn *dyn, efi_handle_t handle, efi_system_table_t *sys_tab); +/* + * efi_bootinfo_t: stores EFI-related machine info retrieved before exiting EFI + * boot services, and is then used by setup_efi(). setup_efi() cannot retrieve + * this info as it is called after ExitBootServices and thus some EFI resources + * and functions are not available. + */ +typedef struct { + struct efi_boot_memmap mem_map; +} efi_bootinfo_t; + +efi_status_t _relocate(long ldbase, Elf64_Dyn *dyn, efi_handle_t handle, + efi_system_table_t *sys_tab); efi_status_t efi_get_memory_map(struct efi_boot_memmap *map); -efi_status_t efi_exit_boot_services(void *handle, unsigned long mapkey); +efi_status_t efi_exit_boot_services(void *handle, struct efi_boot_memmap *map); efi_status_t efi_get_system_config_table(efi_guid_t table_guid, void **table); efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab); diff --git a/lib/x86/acpi.c b/lib/x86/acpi.c index 0f75d79..c523dac 100644 --- a/lib/x86/acpi.c +++ b/lib/x86/acpi.c @@ -4,29 +4,35 @@ #ifdef TARGET_EFI struct rsdp_descriptor *efi_rsdp = NULL; -void setup_efi_rsdp(struct rsdp_descriptor *rsdp) { +void set_efi_rsdp(struct rsdp_descriptor *rsdp) +{ efi_rsdp = rsdp; } -static struct rsdp_descriptor *get_rsdp(void) { +static struct rsdp_descriptor *get_rsdp(void) +{ if (efi_rsdp == NULL) { - printf("Can't find RSDP from UEFI, maybe setup_efi_rsdp() was not called\n"); + printf("Can't find RSDP from UEFI, maybe set_efi_rsdp() was not called\n"); } return efi_rsdp; } #else -static struct rsdp_descriptor *get_rsdp(void) { - struct rsdp_descriptor *rsdp; - unsigned long addr; - for(addr = 0xf0000; addr < 0x100000; addr += 16) { - rsdp = (void*)addr; - if (rsdp->signature == RSDP_SIGNATURE_8BYTE) - break; - } - if (addr == 0x100000) { - return NULL; - } - return rsdp; +static struct rsdp_descriptor *get_rsdp(void) +{ + struct rsdp_descriptor *rsdp; + unsigned long addr; + + for (addr = 0xf0000; addr < 0x100000; addr += 16) { + rsdp = (void *)addr; + if (rsdp->signature == RSDP_SIGNATURE_8BYTE) + break; + } + + if (addr == 0x100000) { + return NULL; + } + + return rsdp; } #endif /* TARGET_EFI */ diff --git a/lib/x86/acpi.h b/lib/x86/acpi.h index db8ee56..67ba389 100644 --- a/lib/x86/acpi.h +++ b/lib/x86/acpi.h @@ -106,10 +106,7 @@ struct facs_descriptor_rev1 u8 reserved3 [40]; /* Reserved - must be zero */ }; +void set_efi_rsdp(struct rsdp_descriptor *rsdp); void* find_acpi_table_addr(u32 sig); -#ifdef TARGET_EFI -void setup_efi_rsdp(struct rsdp_descriptor *rsdp); -#endif /* TARGET_EFI */ - #endif diff --git a/lib/x86/asm/setup.h b/lib/x86/asm/setup.h index 73ff4a3..dbfb2a2 100644 --- a/lib/x86/asm/setup.h +++ b/lib/x86/asm/setup.h @@ -12,21 +12,7 @@ unsigned long setup_tss(u8 *stacktop); #include "efi.h" #include "x86/amd_sev.h" -/* - * efi_bootinfo_t: stores EFI-related machine info retrieved by - * setup_efi_pre_boot(), and is then used by setup_efi(). setup_efi() cannot - * retrieve this info as it is called after ExitBootServices and thus some EFI - * resources are not available. - */ -typedef struct { - phys_addr_t free_mem_start; - phys_addr_t free_mem_size; - struct rsdp_descriptor *rsdp; -} efi_bootinfo_t; - -void setup_efi_bootinfo(efi_bootinfo_t *efi_bootinfo); -void setup_efi(efi_bootinfo_t *efi_bootinfo); -efi_status_t setup_efi_pre_boot(unsigned long *mapkey, efi_bootinfo_t *efi_bootinfo); +efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo); void setup_5level_page_table(void); #endif /* TARGET_EFI */ diff --git a/lib/x86/setup.c b/lib/x86/setup.c index 24fe74e..86ff400 100644 --- a/lib/x86/setup.c +++ b/lib/x86/setup.c @@ -173,34 +173,14 @@ void setup_multiboot(struct mbi_bootinfo *bi) extern void load_idt(void); extern void load_gdt_tss(size_t tss_offset); -void setup_efi_bootinfo(efi_bootinfo_t *efi_bootinfo) -{ - efi_bootinfo->free_mem_size = 0; - efi_bootinfo->free_mem_start = 0; - efi_bootinfo->rsdp = NULL; -} - -static efi_status_t setup_pre_boot_memory(unsigned long *mapkey, efi_bootinfo_t *efi_bootinfo) +static efi_status_t setup_memory_allocator(efi_bootinfo_t *efi_bootinfo) { int i; - unsigned long free_mem_total_pages; - efi_status_t status; - struct efi_boot_memmap map; - efi_memory_desc_t *buffer, *d; - unsigned long map_size, desc_size, buff_size; - u32 desc_ver; - - map.map = &buffer; - map.map_size = &map_size; - map.desc_size = &desc_size; - map.desc_ver = &desc_ver; - map.buff_size = &buff_size; - map.key_ptr = mapkey; - - status = efi_get_memory_map(&map); - if (status != EFI_SUCCESS) { - return status; - } + unsigned long free_mem_pages = 0; + unsigned long free_mem_start = 0; + struct efi_boot_memmap *map = &(efi_bootinfo->mem_map); + efi_memory_desc_t *buffer = *map->map; + efi_memory_desc_t *d = NULL; /* * The 'buffer' contains multiple descriptors that describe memory @@ -209,77 +189,42 @@ static efi_status_t setup_pre_boot_memory(unsigned long *mapkey, efi_bootinfo_t * memory allocator, so that the memory allocator can work in the * largest free continuous memory region. */ - free_mem_total_pages = 0; - for (i = 0; i < map_size; i += desc_size) { + for (i = 0; i < *(map->map_size); i += *(map->desc_size)) { d = (efi_memory_desc_t *)(&((u8 *)buffer)[i]); if (d->type == EFI_CONVENTIONAL_MEMORY) { - if (free_mem_total_pages < d->num_pages) { - free_mem_total_pages = d->num_pages; - efi_bootinfo->free_mem_size = free_mem_total_pages << EFI_PAGE_SHIFT; - efi_bootinfo->free_mem_start = d->phys_addr; + if (free_mem_pages < d->num_pages) { + free_mem_pages = d->num_pages; + free_mem_start = d->phys_addr; } } } - if (efi_bootinfo->free_mem_size == 0) { + if (free_mem_pages == 0) { return EFI_OUT_OF_RESOURCES; } - return EFI_SUCCESS; -} + phys_alloc_init(free_mem_start, free_mem_pages << EFI_PAGE_SHIFT); -static efi_status_t setup_pre_boot_rsdp(efi_bootinfo_t *efi_bootinfo) -{ - return efi_get_system_config_table(ACPI_TABLE_GUID, (void **)&efi_bootinfo->rsdp); + return EFI_SUCCESS; } -efi_status_t setup_efi_pre_boot(unsigned long *mapkey, efi_bootinfo_t *efi_bootinfo) +static efi_status_t setup_rsdp(efi_bootinfo_t *efi_bootinfo) { efi_status_t status; + struct rsdp_descriptor *rsdp; - status = setup_pre_boot_memory(mapkey, efi_bootinfo); - if (status != EFI_SUCCESS) { - printf("setup_pre_boot_memory() failed: "); - switch (status) { - case EFI_OUT_OF_RESOURCES: - printf("No free memory region\n"); - break; - default: - printf("Unknown error\n"); - break; - } - return status; - } - - status = setup_pre_boot_rsdp(efi_bootinfo); + /* + * RSDP resides in an EFI_ACPI_RECLAIM_MEMORY region, which is not used + * by kvm-unit-tests x86's memory allocator. So it is not necessary to + * copy the data structure to another memory region to prevent + * unintentional overwrite. + */ + status = efi_get_system_config_table(ACPI_TABLE_GUID, (void **)&rsdp); if (status != EFI_SUCCESS) { - printf("Cannot find RSDP in EFI system table\n"); return status; } - status = setup_amd_sev(); - if (status != EFI_SUCCESS) { - switch (status) { - case EFI_UNSUPPORTED: - /* Continue if AMD SEV is not supported */ - break; - default: - printf("Set up AMD SEV failed\n"); - return status; - } - } - - status = setup_amd_sev_es(); - if (status != EFI_SUCCESS) { - switch (status) { - case EFI_UNSUPPORTED: - /* Continue if AMD SEV-ES is not supported */ - break; - default: - printf("Set up AMD SEV-ES failed\n"); - return status; - } - } + set_efi_rsdp(rsdp); return EFI_SUCCESS; } @@ -333,8 +278,51 @@ static void setup_gdt_tss(void) load_gdt_tss(tss_offset); } -void setup_efi(efi_bootinfo_t *efi_bootinfo) +efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo) { + efi_status_t status; + + status = setup_memory_allocator(efi_bootinfo); + if (status != EFI_SUCCESS) { + printf("Memory allocator setup failed: "); + if (status == EFI_OUT_OF_RESOURCES) { + printf("No free memory region\n"); + } else { + printf("error = 0x%lx\n", status); + } + return status; + } + + status = setup_rsdp(efi_bootinfo); + if (status != EFI_SUCCESS) { + printf("Cannot find RSDP in EFI system table\n"); + return status; + } + + status = setup_amd_sev(); + if (status != EFI_SUCCESS) { + switch (status) { + case EFI_UNSUPPORTED: + /* Continue if AMD SEV is not supported */ + break; + default: + printf("Set up AMD SEV failed\n"); + return status; + } + } + + status = setup_amd_sev_es(); + if (status != EFI_SUCCESS) { + switch (status) { + case EFI_UNSUPPORTED: + /* Continue if AMD SEV-ES is not supported */ + break; + default: + printf("Set up AMD SEV-ES failed\n"); + return status; + } + } + reset_apic(); setup_gdt_tss(); setup_idt(); @@ -343,9 +331,9 @@ void setup_efi(efi_bootinfo_t *efi_bootinfo) enable_apic(); enable_x2apic(); smp_init(); - phys_alloc_init(efi_bootinfo->free_mem_start, efi_bootinfo->free_mem_size); - setup_efi_rsdp(efi_bootinfo->rsdp); setup_page_table(); + + return EFI_SUCCESS; } #endif /* TARGET_EFI */ From patchwork Tue Nov 16 20:40:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixuan Wang X-Patchwork-Id: 12623175 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA8BEC433F5 for ; Tue, 16 Nov 2021 20:41:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F9BD61BBD for ; Tue, 16 Nov 2021 20:41:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230513AbhKPUn6 (ORCPT ); Tue, 16 Nov 2021 15:43:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230494AbhKPUn5 (ORCPT ); Tue, 16 Nov 2021 15:43:57 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04A77C061764 for ; Tue, 16 Nov 2021 12:41:00 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id q12so218536pgh.5 for ; Tue, 16 Nov 2021 12:41:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZXu/eaACaGA7uvtwoJon0fQRTaY9vT6/mcPLe7D+atE=; b=QeE/llGvywprPHzB6mA/XolU81TJx3wVfDf9ZUlZ0jdcuGDs1ucwqoWeo5HGomfPfY d06ErHpn3ysHTvIDAIu6jme6g4NoCfvDb24JjGJRx68jsanoqax51XwQhZeNDLp04Fm4 MpK3xPlGr5QMvRHHrgYJxQ8Mk4b1eNTcleZjykVYg92VwuRnVbeODKr/r6oVZNhu/S9U +6LRbr/TRLmWU4BpodSbyt5mbKGYHGmhRIkHsuqcnbhTl06DhcpZ6zJwHO34CKpMUZ8T BAriopX6Z/VUFHg3E/fHpKUAnTAGUMoKJPY4nr7TsKxRltqA9YIAQvBDCxMnTWaP3cvH CcWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZXu/eaACaGA7uvtwoJon0fQRTaY9vT6/mcPLe7D+atE=; b=YQKhEssakx0XsP+f/Otw+2Nu4R6WbGyMlnYGwg1d/HdlhHHmDsYogenZizOl5jB0mb foCv0U0rRt9FaiC6H/2y68XBsqiMH5TTE1G8QD0XV/lDhI/bLAmBDu0UP8uHo5w1CEFZ W4Wby/abNFtc6fDYXZR/dmG+VoMWPjmD3UPvWPxoiqweZYyEnk5n3raSTIZrgl0zjXD+ k1nyRVjVaHDRD45ATqfVTStt29ALvQFkB+t1hY/COV9VTa9ZH6JFrPx1EEemg6VpdZ68 H9Jm8s76yuAnWq/vJ7KyRKFdE0WDUCUDp3+T0Izq6wGgQR01cVobHGmqjpXw/YsbWcPW 9XDg== X-Gm-Message-State: AOAM533Vv0cTIshwYah6oSgKYBCTEWUpCpZ4km+bVYRAHn143eOigcBj /+2++O7r7gcrTNWqIOsDtWU91559BS7DMA== X-Google-Smtp-Source: ABdhPJzscxv9e0xDIv8Ix4ntoQkJ9cMd/fb19sAlKsdjBWokqFhBF3HJBlwbmG8pPR6WVsU45PSv3A== X-Received: by 2002:aa7:83d6:0:b0:494:690e:e66b with SMTP id j22-20020aa783d6000000b00494690ee66bmr1899403pfn.53.1637095259217; Tue, 16 Nov 2021 12:40:59 -0800 (PST) Received: from localhost.localdomain (netadmin.ucsd.edu. [137.110.160.224]) by smtp.gmail.com with ESMTPSA id lp12sm3652359pjb.24.2021.11.16.12.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 12:40:58 -0800 (PST) From: Zixuan Wang To: kvm@vger.kernel.org, pbonzini@redhat.com, drjones@redhat.com Cc: marcorr@google.com, erdemaktas@google.com, rientjes@google.com, seanjc@google.com, brijesh.singh@amd.com, Thomas.Lendacky@amd.com, varad.gautam@suse.com, jroedel@suse.de, bp@suse.de Subject: [kvm-unit-tests PATCH v2 03/10] x86 AMD SEV: Skip SEV-ES if SEV is unsupported Date: Tue, 16 Nov 2021 12:40:46 -0800 Message-Id: <20211116204053.220523-4-zxwang42@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211116204053.220523-1-zxwang42@gmail.com> References: <20211116204053.220523-1-zxwang42@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Sean Christopherson Skip the SEV-ES setup if SEV is unsupported. Also update the printf to include error codes. Signed-off-by: Sean Christopherson --- lib/x86/setup.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/x86/setup.c b/lib/x86/setup.c index 86ff400..68ee74c 100644 --- a/lib/x86/setup.c +++ b/lib/x86/setup.c @@ -300,29 +300,24 @@ efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo) } status = setup_amd_sev(); + /* Continue if AMD SEV is not supported, but skip SEV-ES setup */ + if (status == EFI_UNSUPPORTED) { + goto continue_setup_after_sev; + } + if (status != EFI_SUCCESS) { - switch (status) { - case EFI_UNSUPPORTED: - /* Continue if AMD SEV is not supported */ - break; - default: - printf("Set up AMD SEV failed\n"); - return status; - } + printf("AMD SEV setup failed, error = 0x%lx\n", status); + return status; } status = setup_amd_sev_es(); - if (status != EFI_SUCCESS) { - switch (status) { - case EFI_UNSUPPORTED: - /* Continue if AMD SEV-ES is not supported */ - break; - default: - printf("Set up AMD SEV-ES failed\n"); - return status; - } + if (status != EFI_SUCCESS && status != EFI_UNSUPPORTED) { + printf("AMD SEV-ES setup failed, error = 0x%lx\n", status); + return status; } +continue_setup_after_sev: + reset_apic(); setup_gdt_tss(); setup_idt(); From patchwork Tue Nov 16 20:40:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixuan Wang X-Patchwork-Id: 12623177 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6383CC433EF for ; Tue, 16 Nov 2021 20:41:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43AFD61BBD for ; Tue, 16 Nov 2021 20:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230506AbhKPUn7 (ORCPT ); Tue, 16 Nov 2021 15:43:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbhKPUn6 (ORCPT ); Tue, 16 Nov 2021 15:43:58 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CCD7C061570 for ; Tue, 16 Nov 2021 12:41:01 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id p18so181727plf.13 for ; Tue, 16 Nov 2021 12:41:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MWmwqGIl7Mu5e/wgA79g1QL5VHJzKW1OzNicN+6imL4=; b=CGBAkPA8pk9pE+Ha+7FoBdQHmsq9YW0d490I4iMBb9xg4+kNlZs3hgc1dHTzlsUGtF +kXAbzGxNDLGCWGDtXom4OuROXSNxwUHygqsIxq0rjCK2Gg38cIOUAHkORugXZtCDR0O CShZyhDwpVIeerm+OSYxwRsuy2G7Hi3z4cEE1xBelJwnYGoGVfAp8KbDKlw2l5wOlX/1 6E6WizLQmTtiZ58z2gtGoyCqw5T4wh3vrRNbiLPRLJXbVVPvFsMWyB15FgEfCclVkPZg 2KWhJVTYoXvA4+vSvNtoUnuL7wWIRsUEhBbwGyONgogNCWJPsjSsHlYGJRDJYyPZJnfv +75A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MWmwqGIl7Mu5e/wgA79g1QL5VHJzKW1OzNicN+6imL4=; b=K+WndeKThTzB2KmtxdjUFA4aQbgVufcWez5Ijh+ld1Jgn22/AV1+js/+KuDMeq55zq 67We4Q7zeJLs2mRaxXnkgbca/lFUu/QkY8rGIWJWMjdhzBd8VMNt9BDRq6sh5UUTFI6c xsyHHEuqR6yWe6qIB8UkdHMmFPffBws6L5hJTyWJ6zg6WFpS+wKHItliwjsEJ3UNRVdL zVxA1y5n0xk4GHeT1G9Er9Gq9tVJp2kHd9vv0YmqSYj4zxyzZGqMS41hdg1pskvzr/Hp phiB2YeTB4HHPIVHwLDLDM76+Of7GK2vPO30KqA1fZt4ufTw1AQaObE2GCkFeWbxWCQk HSsg== X-Gm-Message-State: AOAM531BiFkT18heorlveA7jrul0BkZtr1HRFWUGxvXxYiiJZwCYTsBw RVyyRm3YpLcfG2WzuD2ZmXNrNSeqexTCYQ== X-Google-Smtp-Source: ABdhPJyTzQzgiNlWgxGW/qMpwDtaf9MgVqXvQyGo0ctGW2gsKTixN1oqrZpq6dPwYdKZjkc0uNjtLg== X-Received: by 2002:a17:90a:6b44:: with SMTP id x4mr2372328pjl.27.1637095260443; Tue, 16 Nov 2021 12:41:00 -0800 (PST) Received: from localhost.localdomain (netadmin.ucsd.edu. [137.110.160.224]) by smtp.gmail.com with ESMTPSA id lp12sm3652359pjb.24.2021.11.16.12.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 12:40:59 -0800 (PST) From: Zixuan Wang To: kvm@vger.kernel.org, pbonzini@redhat.com, drjones@redhat.com Cc: marcorr@google.com, erdemaktas@google.com, rientjes@google.com, seanjc@google.com, brijesh.singh@amd.com, Thomas.Lendacky@amd.com, varad.gautam@suse.com, jroedel@suse.de, bp@suse.de Subject: [kvm-unit-tests PATCH v2 04/10] x86 UEFI: Convert x86 test cases to PIC Date: Tue, 16 Nov 2021 12:40:47 -0800 Message-Id: <20211116204053.220523-5-zxwang42@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211116204053.220523-1-zxwang42@gmail.com> References: <20211116204053.220523-1-zxwang42@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Zixuan Wang UEFI loads EFI applications to dynamic runtime addresses, so it requires all applications to be compiled as PIC (position independent code). PIC does not allow the usage of compile time absolute address. This commit converts multiple x86 test cases to PIC so they can compile and run in UEFI: - x86/cet.efi - x86/emulator.c: x86/emulator.c depends on lib/x86/usermode.c. But usermode.c contains non-PIC inline assembly code. This commit converts lib/x86/usermode.c and x86/emulator.c to PIC, so x86/emulator.c can compile and run in UEFI. - x86/vmware_backdoors.c: it depends on lib/x86/usermode.c and now works without modifications. - x86/eventinj.c - x86/smap.c - x86/access.c: it runs fine without '-cpu max', which disables the SMEP-related tests. But with '-cpu max', it crashes in the middle, so it is left disabled in this commit. - x86/umip.c: convert to PIC and fix a bug: In summary, in the following line, %[sp0] can be compiled as a %r8-based offset address: x86/umip.c:127 "mov %%" R "sp, %[sp0]\n\t" /* kernel sp for exception handlers */ %r8 is then modified in function calls without saving/restoring, thus making the following line using the wrong address. x86/umip.c:148 "mov %[sp0], %%" R "sp\n\t" This register is selected by the compiler, it's not guaranteed to be %r8 so we cannot just push/pop %r8 before/after the function call. A simple fix is to save the %rsp to %rbx. %rbx is a callee-saved register, so its value is not modified by function calls. Signed-off-by: Zixuan Wang --- lib/x86/usermode.c | 3 ++- x86/Makefile.common | 10 +++++----- x86/Makefile.x86_64 | 7 ++++--- x86/access.c | 9 +++++---- x86/cet.c | 8 +++++--- x86/emulator.c | 5 +++-- x86/eventinj.c | 8 ++++++++ x86/smap.c | 13 +++++++++---- x86/umip.c | 26 +++++++++++++++++++++++--- 9 files changed, 64 insertions(+), 25 deletions(-) diff --git a/lib/x86/usermode.c b/lib/x86/usermode.c index 2e77831..5b657fd 100644 --- a/lib/x86/usermode.c +++ b/lib/x86/usermode.c @@ -58,7 +58,8 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector, "pushq %[user_stack_top]\n\t" "pushfq\n\t" "pushq %[user_cs]\n\t" - "pushq $user_mode\n\t" + "lea user_mode(%%rip), %%rdx\n\t" + "pushq %%rdx\n\t" "iretq\n" "user_mode:\n\t" diff --git a/x86/Makefile.common b/x86/Makefile.common index deaa386..2b39dd5 100644 --- a/x86/Makefile.common +++ b/x86/Makefile.common @@ -81,16 +81,16 @@ tests-common = $(TEST_DIR)/vmexit.$(exe) $(TEST_DIR)/tsc.$(exe) \ $(TEST_DIR)/init.$(exe) \ $(TEST_DIR)/hyperv_synic.$(exe) $(TEST_DIR)/hyperv_stimer.$(exe) \ $(TEST_DIR)/hyperv_connections.$(exe) \ - $(TEST_DIR)/tsx-ctrl.$(exe) + $(TEST_DIR)/tsx-ctrl.$(exe) \ + $(TEST_DIR)/eventinj.$(exe) \ + $(TEST_DIR)/smap.$(exe) \ + $(TEST_DIR)/umip.$(exe) # The following test cases are disabled when building EFI tests because they # use absolute addresses in their inline assembly code, which cannot compile # with the '-fPIC' flag ifneq ($(TARGET_EFI),y) -tests-common += $(TEST_DIR)/eventinj.$(exe) \ - $(TEST_DIR)/smap.$(exe) \ - $(TEST_DIR)/realmode.$(exe) \ - $(TEST_DIR)/umip.$(exe) +tests-common += $(TEST_DIR)/realmode.$(exe) endif test_cases: $(tests-common) $(tests) diff --git a/x86/Makefile.x86_64 b/x86/Makefile.x86_64 index fe6457c..3963840 100644 --- a/x86/Makefile.x86_64 +++ b/x86/Makefile.x86_64 @@ -30,6 +30,8 @@ tests += $(TEST_DIR)/intel-iommu.$(exe) tests += $(TEST_DIR)/rdpru.$(exe) tests += $(TEST_DIR)/pks.$(exe) tests += $(TEST_DIR)/pmu_lbr.$(exe) +tests += $(TEST_DIR)/emulator.$(exe) +tests += $(TEST_DIR)/vmware_backdoors.$(exe) ifeq ($(TARGET_EFI),y) tests += $(TEST_DIR)/amd_sev.$(exe) @@ -40,14 +42,13 @@ endif # with the '-fPIC' flag ifneq ($(TARGET_EFI),y) tests += $(TEST_DIR)/access.$(exe) -tests += $(TEST_DIR)/emulator.$(exe) tests += $(TEST_DIR)/svm.$(exe) tests += $(TEST_DIR)/vmx.$(exe) -tests += $(TEST_DIR)/vmware_backdoors.$(exe) +endif + ifneq ($(fcf_protection_full),) tests += $(TEST_DIR)/cet.$(exe) endif -endif include $(SRCDIR)/$(TEST_DIR)/Makefile.common diff --git a/x86/access.c b/x86/access.c index 911f0e3..a2ec049 100644 --- a/x86/access.c +++ b/x86/access.c @@ -700,7 +700,7 @@ static int ac_test_do_access(ac_test_t *at) if (F(AC_ACCESS_TWICE)) { asm volatile ( - "mov $fixed2, %%rsi \n\t" + "lea fixed2(%%rip), %%rsi \n\t" "mov (%[addr]), %[reg] \n\t" "fixed2:" : [reg]"=r"(r), [fault]"=a"(fault), "=b"(e) @@ -710,7 +710,7 @@ static int ac_test_do_access(ac_test_t *at) fault = 0; } - asm volatile ("mov $fixed1, %%rsi \n\t" + asm volatile ("lea fixed1(%%rip), %%rsi \n\t" "mov %%rsp, %[rsp0] \n\t" "cmp $0, %[user] \n\t" "jz do_access \n\t" @@ -719,7 +719,8 @@ static int ac_test_do_access(ac_test_t *at) "pushq %[user_stack_top] \n\t" "pushfq \n\t" "pushq %[user_cs] \n\t" - "pushq $do_access \n\t" + "lea do_access(%%rip), %%r8\n\t" + "pushq %%r8\n\t" "iretq \n" "do_access: \n\t" "cmp $0, %[fetch] \n\t" @@ -750,7 +751,7 @@ static int ac_test_do_access(ac_test_t *at) [user_cs]"i"(USER_CS), [user_stack_top]"r"(user_stack + sizeof user_stack), [kernel_entry_vector]"i"(0x20) - : "rsi"); + : "rsi", "r8"); asm volatile (".section .text.pf \n\t" "page_fault: \n\t" diff --git a/x86/cet.c b/x86/cet.c index a21577a..a4b79cb 100644 --- a/x86/cet.c +++ b/x86/cet.c @@ -52,7 +52,7 @@ static u64 cet_ibt_func(void) printf("No endbr64 instruction at jmp target, this triggers #CP...\n"); asm volatile ("movq $2, %rcx\n" "dec %rcx\n" - "leaq 2f, %rax\n" + "leaq 2f(%rip), %rax\n" "jmp *%rax \n" "2:\n" "dec %rcx\n"); @@ -67,7 +67,8 @@ void test_func(void) { "pushq %[user_stack_top]\n\t" "pushfq\n\t" "pushq %[user_cs]\n\t" - "pushq $user_mode\n\t" + "lea user_mode(%%rip), %%rax\n\t" + "pushq %%rax\n\t" "iretq\n" "user_mode:\n\t" @@ -77,7 +78,8 @@ void test_func(void) { [user_ds]"i"(USER_DS), [user_cs]"i"(USER_CS), [user_stack_top]"r"(user_stack + - sizeof(user_stack))); + sizeof(user_stack)) + : "rax"); } #define SAVE_REGS() \ diff --git a/x86/emulator.c b/x86/emulator.c index c5f584a..22a518f 100644 --- a/x86/emulator.c +++ b/x86/emulator.c @@ -262,12 +262,13 @@ static void test_pop(void *mem) asm volatile("mov %%rsp, %[tmp] \n\t" "mov %[stack_top], %%rsp \n\t" - "push $1f \n\t" + "lea 1f(%%rip), %%rax \n\t" + "push %%rax \n\t" "ret \n\t" "2: jmp 2b \n\t" "1: mov %[tmp], %%rsp" : [tmp]"=&r"(tmp) : [stack_top]"r"(stack_top) - : "memory"); + : "memory", "rax"); report_pass("ret"); stack_top[-1] = 0x778899; diff --git a/x86/eventinj.c b/x86/eventinj.c index 46593c9..3c0db56 100644 --- a/x86/eventinj.c +++ b/x86/eventinj.c @@ -155,9 +155,17 @@ asm("do_iret:" "pushf"W" \n\t" "mov %cs, %ecx \n\t" "push"W" %"R "cx \n\t" +#ifndef __x86_64__ "push"W" $2f \n\t" "cmpb $0, no_test_device\n\t" // see if need to flush +#else + "leaq 2f(%rip), %rbx \n\t" + "pushq %rbx \n\t" + + "mov no_test_device(%rip), %bl \n\t" + "cmpb $0, %bl\n\t" // see if need to flush +#endif "jnz 1f\n\t" "outl %eax, $0xe4 \n\t" // flush page "1: \n\t" diff --git a/x86/smap.c b/x86/smap.c index c6ddf38..0994c29 100644 --- a/x86/smap.c +++ b/x86/smap.c @@ -159,12 +159,17 @@ int main(int ac, char **av) init_test(i); stac(); test = -1; +#ifndef __x86_64__ + #define TEST "test" +#else + #define TEST "test(%rip)" +#endif asm("or $(" xstr(USER_BASE) "), %"R "sp \n" "push $44 \n " - "decl test\n" + "decl " TEST "\n" "and $~(" xstr(USER_BASE) "), %"R "sp \n" "pop %"R "ax\n" - "movl %eax, test"); + "movl %eax, " TEST "\n"); report(pf_count == 0 && test == 44, "write to user stack with AC=1"); @@ -173,10 +178,10 @@ int main(int ac, char **av) test = -1; asm("or $(" xstr(USER_BASE) "), %"R "sp \n" "push $45 \n " - "decl test\n" + "decl " TEST "\n" "and $~(" xstr(USER_BASE) "), %"R "sp \n" "pop %"R "ax\n" - "movl %eax, test"); + "movl %eax, " TEST "\n"); report(pf_count == 1 && test == 45 && save == -1, "write to user stack with AC=0"); diff --git a/x86/umip.c b/x86/umip.c index af8db59..fccdedc 100644 --- a/x86/umip.c +++ b/x86/umip.c @@ -20,10 +20,20 @@ static void gp_handler(struct ex_regs *regs) } } +#ifndef __x86_64__ +#define GP_ASM_MOVE_TO_RIP \ + "mov" W " $1f, %[expected_rip]\n\t" +#else +#define GP_ASM_MOVE_TO_RIP \ + "pushq %%rax\n\t" \ + "lea 1f(%%rip), %%rax\n\t" \ + "mov %%rax, %[expected_rip]\n\t" \ + "popq %%rax\n\t" +#endif #define GP_ASM(stmt, in, clobber) \ asm volatile ( \ - "mov" W " $1f, %[expected_rip]\n\t" \ + GP_ASM_MOVE_TO_RIP \ "movl $2f-1f, %[skip_count]\n\t" \ "1: " stmt "\n\t" \ "2: " \ @@ -125,12 +135,18 @@ static noinline int do_ring3(void (*fn)(const char *), const char *arg) "mov %%dx, %%fs\n\t" "mov %%dx, %%gs\n\t" "mov %%" R "sp, %[sp0]\n\t" /* kernel sp for exception handlers */ + "mov %[sp0], %%" R "bx\n\t" /* ebx/rbx is preserved before and after 'call' instruction */ "push" W " %%" R "dx \n\t" "lea %[user_stack_top], %%" R "dx \n\t" "push" W " %%" R "dx \n\t" "pushf" W "\n\t" "push" W " %[user_cs] \n\t" +#ifndef __x86_64__ "push" W " $1f \n\t" +#else + "lea 1f(%%rip), %%rdx \n\t" + "pushq %%rdx \n\t" +#endif "iret" W "\n" "1: \n\t" #ifndef __x86_64__ @@ -140,12 +156,16 @@ static noinline int do_ring3(void (*fn)(const char *), const char *arg) #ifndef __x86_64__ "pop %%ecx\n\t" #endif +#ifndef __x86_64__ "mov $1f, %%" R "dx\n\t" +#else + "lea 1f(%%" R "ip), %%" R "dx\n\t" +#endif "int %[kernel_entry_vector]\n\t" ".section .text.entry \n\t" "kernel_entry: \n\t" #ifdef __x86_64__ - "mov %[sp0], %%" R "sp\n\t" + "mov %%rbx, %%rsp\n\t" #else "add $(5 * " S "), %%esp\n\t" #endif @@ -171,7 +191,7 @@ static noinline int do_ring3(void (*fn)(const char *), const char *arg) [arg]"D"(arg), [kernel_ds]"i"(KERNEL_DS), [kernel_entry_vector]"i"(0x20) - : "rcx", "rdx"); + : "rcx", "rdx", "rbx"); return ret; } From patchwork Tue Nov 16 20:40:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixuan Wang X-Patchwork-Id: 12623181 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8439BC4332F for ; Tue, 16 Nov 2021 20:41:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67A59615E2 for ; Tue, 16 Nov 2021 20:41:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230525AbhKPUoA (ORCPT ); Tue, 16 Nov 2021 15:44:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230494AbhKPUn7 (ORCPT ); Tue, 16 Nov 2021 15:43:59 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F88EC061570 for ; Tue, 16 Nov 2021 12:41:02 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id g18so502865pfk.5 for ; Tue, 16 Nov 2021 12:41:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1AE+HQrLi6BxdLK3n3GfzMpS9PYJGXdqFTYhG0I5PN4=; b=CQNFR7NOP7hkZb7c0hL0VBiZNje2CdB/E2DvYx6r9Jn2i8RZ0BVM+KlK2PK1hkMglY AjFvlfEl9D0dRuBXG7y8mUfAG2SsEFzI+na8Xl80FGNnvGQ/15cJB/S09Exrv0nGOIgS 90UV9LhfgtYVtxmFub5q+YnEZrmgXvUSIGUMJlPnT21ESJtV17L+KWn7u/VDk2sW/ZVX dOjyu4LVfdvQIglSeK+Jx0lUE2gEN6+UFkC+gqHGbLDhMh36wvdrzi++XrT/h46o2dhZ CzxwZz6Nn1wQhDfr0KMdPsOoUnjYhAGnVhcLzTwDun9rwULs8jMWmp43b7idj0uB5SFU t7vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1AE+HQrLi6BxdLK3n3GfzMpS9PYJGXdqFTYhG0I5PN4=; b=iBDUXa+veB8Hz8PJMdGpGo0UphIu0YKOTCtWN2zB1Cf+hoBS3cSdtvMgkfu7n1k4HE FPI8YiSJeQyfBH6CCMacntHLBM6iBXc85dKNtyDMVxxTa6+kPI0DzBJBgHakX/EYViZ3 TnydyDKaFkUyx5FRtnGDH4mM3G6r5Hwq6yZhn/pI2MmsYdKb2yJuaITWMmSoO1PfTbPm /Ga9rblL6q4tNnJCXDsKjs+oCGY7b3OzbRdeXU/AkxQZwx7lR+q030FBTWHiplBBVCde nmrTFPfwoXP5rpTzmL3p6GOsD70Mlg9Y36nKSxfsLRf+mMZJkWUIbPvUfcLwvdtMoH/N nMtg== X-Gm-Message-State: AOAM532FL2J+c6YGwgxthGUEktKewsY6oI0lbn67tbZVVnraFw6WWF4b VwuyK4kl2D15L6g0IkBzai2E/CTBTWy6fw== X-Google-Smtp-Source: ABdhPJwE8Dsms2V2K60CmGEakBLb7kONv0fZsLxvGQPl51bmBvzafVbOxLWw16Rh7PVypS3lUCeyPg== X-Received: by 2002:a05:6a00:847:b0:49f:9d3c:9b4b with SMTP id q7-20020a056a00084700b0049f9d3c9b4bmr2025839pfk.16.1637095261623; Tue, 16 Nov 2021 12:41:01 -0800 (PST) Received: from localhost.localdomain (netadmin.ucsd.edu. [137.110.160.224]) by smtp.gmail.com with ESMTPSA id lp12sm3652359pjb.24.2021.11.16.12.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 12:41:01 -0800 (PST) From: Zixuan Wang To: kvm@vger.kernel.org, pbonzini@redhat.com, drjones@redhat.com Cc: marcorr@google.com, erdemaktas@google.com, rientjes@google.com, seanjc@google.com, brijesh.singh@amd.com, Thomas.Lendacky@amd.com, varad.gautam@suse.com, jroedel@suse.de, bp@suse.de Subject: [kvm-unit-tests PATCH v2 05/10] x86 UEFI: Set UEFI OVMF as readonly Date: Tue, 16 Nov 2021 12:40:48 -0800 Message-Id: <20211116204053.220523-6-zxwang42@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211116204053.220523-1-zxwang42@gmail.com> References: <20211116204053.220523-1-zxwang42@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Zixuan Wang Set readonly for UEFI OVMF image. Signed-off-by: Zixuan Wang --- x86/efi/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x86/efi/run b/x86/efi/run index a47c0d5..922b266 100755 --- a/x86/efi/run +++ b/x86/efi/run @@ -54,7 +54,7 @@ popd || exit 2 # UEFI's largest allocatable memory region is large enough. EFI_RUN=y \ "$TEST_DIR/run" \ - -drive file="$EFI_UEFI",format=raw,if=pflash \ + -drive file="$EFI_UEFI",format=raw,if=pflash,readonly=on \ -drive file.dir="$EFI_TEST/$EFI_CASE/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \ -net none \ -nographic \ From patchwork Tue Nov 16 20:40:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixuan Wang X-Patchwork-Id: 12623179 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63783C433FE for ; Tue, 16 Nov 2021 20:41:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4EAAB615E2 for ; Tue, 16 Nov 2021 20:41:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231138AbhKPUoC (ORCPT ); Tue, 16 Nov 2021 15:44:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231127AbhKPUoA (ORCPT ); Tue, 16 Nov 2021 15:44:00 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6AB0C061746 for ; Tue, 16 Nov 2021 12:41:03 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id u11so224806plf.3 for ; Tue, 16 Nov 2021 12:41:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2/AVP8Zq6uyC9VI9QdGVIbCSITCn5Jm+/LDPwBstTZI=; b=WX160uVdk/xuIB9uLy0b0H+DyP+zM7foNxBbH0AYRv55ROUdDBHzx8KxrfwtAmlfCi eKsCiSE0fkhz1qnBxuKl21+K2ep8AEI7jmIuRRFHRsdIc+1LConDtXZEBTx2LYCX012+ RmzH5yJOSKE6TaziOHSm+KHrXBcc6lKhf2dSnv4mTBNHTsoY9qf0HDxYFwwUkgnbiC68 e6Y0JzNRt94gnsPl26QYiqxVlpVMYmGZJ/aEZGLP9ivLU2JCrdVf2idkys3gpK5zpkVc 7+nV3272PweDftZO3Mj/1ed3jddNYY/5Z1MZysx2ZPnn+rEmsO2vPbdIwL2UK8M+4A2g tNrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2/AVP8Zq6uyC9VI9QdGVIbCSITCn5Jm+/LDPwBstTZI=; b=2mVwnGV9ei2I1uXMKB3AzyErMeBAgcKX1MQLykR0byxSnUEe0Ah9ZJY8uwHg1SfZZU wvYQnK/rw8qKUfA+OzJ/jZvCnd2IPiE1b4ZgTgeHHIWH3EuAuIsLYqhGOz7ZDZPEbpkg hU8iu2uNFrHMnD8KDNyCna/Amo19VcBAvfKWNZ5kM9D6EMGhh6EpvsM7g6p44k31/tlS YPj+SUprBVYp/Jizhs1+9aVW67dIfjJ4wAQ/147LT4ibSEfV4Ftl0O5MR58wAipoTCwr j+yjEOk28XjtX13pYuPHNZytUsJPoMF2ABLSIo0nAwoarSYLgASquzYbdRfsxHhzyOXy OZlQ== X-Gm-Message-State: AOAM531mp6XVoMl6iNDrO31rdhHiSv1t2ZsSb2G3igJ4uYtfUPh+71MA gROELhmF2QDt/CDvGbrno0Wu2Z9Foms0fA== X-Google-Smtp-Source: ABdhPJwAyHMKvuHqedpYzwySrVsT8yYr2QixIEc8+/ADken5WbWK16XVLouVPGo5nKmW3wgKzPudYg== X-Received: by 2002:a17:90a:fa18:: with SMTP id cm24mr2295112pjb.241.1637095262855; Tue, 16 Nov 2021 12:41:02 -0800 (PST) Received: from localhost.localdomain (netadmin.ucsd.edu. [137.110.160.224]) by smtp.gmail.com with ESMTPSA id lp12sm3652359pjb.24.2021.11.16.12.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 12:41:02 -0800 (PST) From: Zixuan Wang To: kvm@vger.kernel.org, pbonzini@redhat.com, drjones@redhat.com Cc: marcorr@google.com, erdemaktas@google.com, rientjes@google.com, seanjc@google.com, brijesh.singh@amd.com, Thomas.Lendacky@amd.com, varad.gautam@suse.com, jroedel@suse.de, bp@suse.de Subject: [kvm-unit-tests PATCH v2 06/10] x86 UEFI: Exit QEMU with return code Date: Tue, 16 Nov 2021 12:40:49 -0800 Message-Id: <20211116204053.220523-7-zxwang42@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211116204053.220523-1-zxwang42@gmail.com> References: <20211116204053.220523-1-zxwang42@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Zixuan Wang kvm-unit-tests runner scripts parse QEMU exit code to determine if a test case runs successfully. But the UEFI 'reset_system' function always exits QEMU with code 0, even if the test case returns a non-zero code. This commit fixes this issue by calling 'exit' function to exit QEMU with the correct code. Signed-off-by: Zixuan Wang --- lib/efi.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/efi.c b/lib/efi.c index 99eb00c..64cc978 100644 --- a/lib/efi.c +++ b/lib/efi.c @@ -85,6 +85,17 @@ efi_status_t efi_get_system_config_table(efi_guid_t table_guid, void **table) return EFI_NOT_FOUND; } +static void efi_exit(efi_status_t code) +{ + exit(code); + + /* + * Fallback to UEFI reset_system() service, in case testdev is + * missing and exit() does not properly exit. + */ + efi_rs_call(reset_system, EFI_RESET_SHUTDOWN, code, 0, NULL); +} + efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) { int ret; @@ -134,14 +145,14 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) ret = main(__argc, __argv, __environ); /* Shutdown the guest VM */ - efi_rs_call(reset_system, EFI_RESET_SHUTDOWN, ret, 0, NULL); + efi_exit(ret); /* Unreachable */ return EFI_UNSUPPORTED; efi_main_error: /* Shutdown the guest with error EFI status */ - efi_rs_call(reset_system, EFI_RESET_SHUTDOWN, status, 0, NULL); + efi_exit(status); /* Unreachable */ return EFI_UNSUPPORTED; From patchwork Tue Nov 16 20:40:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixuan Wang X-Patchwork-Id: 12623183 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 583BEC433F5 for ; Tue, 16 Nov 2021 20:41:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B94363214 for ; Tue, 16 Nov 2021 20:41:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231157AbhKPUoC (ORCPT ); Tue, 16 Nov 2021 15:44:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231150AbhKPUoC (ORCPT ); Tue, 16 Nov 2021 15:44:02 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAB2BC061570 for ; Tue, 16 Nov 2021 12:41:04 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id b4so193901pgh.10 for ; Tue, 16 Nov 2021 12:41:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a+5g09lFkE7HG3OL5MbNwxLwI2lhjZlEhMNfRa6rR90=; b=foH2/f9qBcdGHgMbRa/PKHwAkNC6qE+wOAUjeIqmF8pJ4ub6CavbwiM2f8y3irrwoV qKur+j3KlwCBqw4KcfiJ0AqZ9yxvG9xh7ihS63yYqpkrM5KaqjoIis00heRjobDP1oZa 3EpcduUv4JO7T5mCsMkL+tx5mL5ySoQJ9xKV9aSI8npyrANBOnugDqSJ76PHHN6cJ9xf 2c+1CLOAdGdeXqck6tsRyL/IPhArnzvRz5HsLtjOt/r3xLFj6eKazQQOw1hDS66aco6i vQ5yfFztzPw2vbAODRoctdmIkwe4YBBJ0YiyHtQYX0/cTW7ZeR9S5AHfNtTgRSsSrahz Q+WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a+5g09lFkE7HG3OL5MbNwxLwI2lhjZlEhMNfRa6rR90=; b=HI4JoRMEUSxobhlnw5wadzCC+rFItrEmFXaHZ574tsCFW43qBomxK+Kn3LmilDtLjr HDsr/6DQAoBzdUokxQPMni+k4ldOCrnoJEvmWVoIU8G6Cr3thHbywcE7bAflChJXypp0 3C6WeFBvDEOt1jNKX9DgiX1fZsxsxPdVtb2Y99oDMCmbLgrjlV1vlX6/HjvpJ/GVRzbd 7zvCwLwX3YRPespsVzHHdzGzy35ma5208DgHlmo1MiyWUelVMIiDqHYMRdNyQcdRh9FI iHHZ8QCcvsglsjlPpF4w/SqS2eRdijoLIJQRvuKaIcg8eXvh8EnroYSZmOjfypE8R7i1 Sw5g== X-Gm-Message-State: AOAM530TbbsrrZK4n4S/97Z/J12/E3ywvL32mg1rMJs/Q8gHDCSj0Ncu TO/Ob+rZidQ7DynEy4zktzWZUWgFn7BSJw== X-Google-Smtp-Source: ABdhPJxp4Xm0o+TthRFTM+eHvPVAt3kycG9CIWYGaRSXMgfZOknvD1NfD/IpwcAYlxxwsfzUMnTYHA== X-Received: by 2002:a63:5816:: with SMTP id m22mr1329391pgb.98.1637095264005; Tue, 16 Nov 2021 12:41:04 -0800 (PST) Received: from localhost.localdomain (netadmin.ucsd.edu. [137.110.160.224]) by smtp.gmail.com with ESMTPSA id lp12sm3652359pjb.24.2021.11.16.12.41.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 12:41:03 -0800 (PST) From: Zixuan Wang To: kvm@vger.kernel.org, pbonzini@redhat.com, drjones@redhat.com Cc: marcorr@google.com, erdemaktas@google.com, rientjes@google.com, seanjc@google.com, brijesh.singh@amd.com, Thomas.Lendacky@amd.com, varad.gautam@suse.com, jroedel@suse.de, bp@suse.de Subject: [kvm-unit-tests PATCH v2 07/10] scripts: Generalize EFI check Date: Tue, 16 Nov 2021 12:40:50 -0800 Message-Id: <20211116204053.220523-8-zxwang42@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211116204053.220523-1-zxwang42@gmail.com> References: <20211116204053.220523-1-zxwang42@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Marc Orr Previously, the scripts distinguish between seabios and UEFI via a hard-coded env var in the EFI run script, `arch/x86/efi/run`. Furthermore, this var is passed to the x86 run script, `arch/x86/run`, and then not available in other scripts (or to other architectures). Replace the previous approach with a common variable TARGET_EFI to check whether the repo has been configured to run under EFI. This variable is extracted from the `config.mak` file generated by `configure`. Signed-off-by: Marc Orr --- x86/efi/run | 1 - x86/run | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/x86/efi/run b/x86/efi/run index 922b266..aacc691 100755 --- a/x86/efi/run +++ b/x86/efi/run @@ -52,7 +52,6 @@ popd || exit 2 # run in UEFI, some test cases, e.g. `x86/pmu.c`, require more free memory. A # simple fix is to increase the QEMU default memory size to 256MiB so that # UEFI's largest allocatable memory region is large enough. -EFI_RUN=y \ "$TEST_DIR/run" \ -drive file="$EFI_UEFI",format=raw,if=pflash,readonly=on \ -drive file.dir="$EFI_TEST/$EFI_CASE/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \ diff --git a/x86/run b/x86/run index 4eba2b9..9e18464 100755 --- a/x86/run +++ b/x86/run @@ -1,5 +1,7 @@ #!/usr/bin/env bash +source scripts/common.bash + if [ -z "$STANDALONE" ]; then if [ ! -f config.mak ]; then echo "run ./configure && make first. See ./configure -h" @@ -39,12 +41,12 @@ fi command="${qemu} --no-reboot -nodefaults $pc_testdev -vnc none -serial stdio $pci_testdev" command+=" -machine accel=$ACCEL" -if ! [ "$EFI_RUN" ]; then +if [ "${TARGET_EFI}" != "y" ]; then command+=" -kernel" fi command="$(timeout_cmd) $command" -if [ "$EFI_RUN" ]; then +if [ "${TARGET_EFI}" == "y" ]; then # Set ENVIRON_DEFAULT=n to remove '-initrd' flag for QEMU (see # 'scripts/arch-run.bash' for more details). This is because when using # UEFI, the test case binaries are passed to QEMU through the disk From patchwork Tue Nov 16 20:40:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixuan Wang X-Patchwork-Id: 12623185 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CAF2C433EF for ; Tue, 16 Nov 2021 20:41:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 296F061BBD for ; Tue, 16 Nov 2021 20:41:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231181AbhKPUoD (ORCPT ); Tue, 16 Nov 2021 15:44:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231175AbhKPUoD (ORCPT ); Tue, 16 Nov 2021 15:44:03 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01B37C061746 for ; Tue, 16 Nov 2021 12:41:06 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id np3so417031pjb.4 for ; Tue, 16 Nov 2021 12:41:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CZSv2V270ivGkUHWP211rK4YqDvBcOoVBaR6NUvkFKw=; b=KAXZ5frOmF6X9a2i4U6lAVxmeG6YCqG/g/9QOqiHjAP0aZiv0jwBdEzeya6NB2YLKU KOegrHDW06FCaRbFnWzrEGS+qHqFfr++tONXapwNwn3IWtaWGbI/KpjOCTMXMzfw+Fgq FTWU2Hi3YxwmGcW97hasS+fn1PVYyVFv6vIDqxQDgGvaIdoCCOZ0XdVWXM+XL1FtNJDY eaF4iPSWjG/0mU5nnSNliAoSyvE5b745TJETuKys3e1Ljou3NfcEJrh81NLsQ9wwjkRe AvyNQZZlYd9c3CTpqIkiG60HF8+r5tohD8H4FcxX2GCOzhYJnXM4p7XQN4a0LmyON8kP u9lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CZSv2V270ivGkUHWP211rK4YqDvBcOoVBaR6NUvkFKw=; b=W8PQPZO682oW6Kk2KnQB5De1L/pDlfrPBiV6/XlzOGGKhxoY25HKWlJJwx7rFfUxn2 gkSuLHKvFNSF9EQ9X70UYx3V1sXvFtOkmMWRmnAzWh3QdwuIok8k1xD9dEvkNlppoVbn lp3p4rPsPUnNhDsjf81B17szHqwUwIiwwWGz1CrCuHZRnwO30kBRxpHbfu6EmU6QPjnA PSxwPnoYl/AuYTslMzHtE5KV+bpMr5NSbmQlC5gSwqnm2I0/uZSDT83DipSkQCFqPQPt sGCmuYLy9iJrLA9oDzVnQ7CeTP2PuJN1cSw2eY3AL4A4nDOzdlwtDy+fJLprblXBeeGq EOBw== X-Gm-Message-State: AOAM531+JG/j0IkxkgAjRG+2H7KQ0wqruWOC/ABKxiweNQHcfgPpUiDm OaRgfqH2TTT3t2bjorNUMcuKlGC8jOt6MQ== X-Google-Smtp-Source: ABdhPJwy+j2ItvqeIxNm+I0DHkuIP700MO2sumnTv7tnxWFmQlRTMC72mfYhJ6fAukGCDocxUi6Rdw== X-Received: by 2002:a17:90b:1d09:: with SMTP id on9mr2277126pjb.191.1637095265172; Tue, 16 Nov 2021 12:41:05 -0800 (PST) Received: from localhost.localdomain (netadmin.ucsd.edu. [137.110.160.224]) by smtp.gmail.com with ESMTPSA id lp12sm3652359pjb.24.2021.11.16.12.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 12:41:04 -0800 (PST) From: Zixuan Wang To: kvm@vger.kernel.org, pbonzini@redhat.com, drjones@redhat.com Cc: marcorr@google.com, erdemaktas@google.com, rientjes@google.com, seanjc@google.com, brijesh.singh@amd.com, Thomas.Lendacky@amd.com, varad.gautam@suse.com, jroedel@suse.de, bp@suse.de Subject: [kvm-unit-tests PATCH v2 08/10] x86 UEFI: Make run_tests.sh (mostly) work under UEFI Date: Tue, 16 Nov 2021 12:40:51 -0800 Message-Id: <20211116204053.220523-9-zxwang42@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211116204053.220523-1-zxwang42@gmail.com> References: <20211116204053.220523-1-zxwang42@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Marc Orr Make several fixes so that run_tests.sh can run the test cases when the repo is configured to run under UEFI. Specifically: 1. The scripts are enlighted to run the .efi test cases rather than the .flat test cases. 2. The scripts are enlighted to run an empty file, _NO_FILE_4Uhere_, which is used to sanity check QEMU and QEMU flags. 3. The scripts are updated to always run with `-smp 1`, since SMP is not yet supported under UEFI. Notably, QEMU's `-append` flag still does not work. This will need to be fixed in future commits. For now, test cases that use `-append` are marked `SKIP`. Signed-off-by: Marc Orr --- scripts/runtime.bash | 14 ++++++++++++-- x86/efi/run | 24 ++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/scripts/runtime.bash b/scripts/runtime.bash index 132389c..228a207 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -82,6 +82,10 @@ function run() local accel="$8" local timeout="${9:-$TIMEOUT}" # unittests.cfg overrides the default + if [ "${TARGET_EFI}" == "y" ]; then + kernel=$(basename $kernel .flat) + fi + if [ -z "$testname" ]; then return fi @@ -127,8 +131,14 @@ function run() fi last_line=$(premature_failure > >(tail -1)) && { - print_result "SKIP" $testname "" "$last_line" - return 77 + skip=true + if [ "${TARGET_EFI}" == "y" ] && [[ "${last_line}" =~ "Reset" ]]; then + skip=false + fi + if [ ${skip} == true ]; then + print_result "SKIP" $testname "" "$last_line" + return 77 + fi } cmdline=$(get_cmdline $kernel) diff --git a/x86/efi/run b/x86/efi/run index aacc691..e6486ed 100755 --- a/x86/efi/run +++ b/x86/efi/run @@ -34,16 +34,27 @@ shift 1 # This host dir will be loaded by QEMU as a FAT32 image # - Make UEFI startup script that runs the .efi on boot mkdir -p "$EFI_TEST/$EFI_CASE/" -cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_TEST/$EFI_CASE/" +if [ $EFI_CASE != "_NO_FILE_4Uhere_" ]; then + cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_TEST/$EFI_CASE/" +else + touch "$EFI_TEST/$EFI_CASE/$EFI_CASE.efi" +fi pushd "$EFI_TEST/$EFI_CASE" || exit 2 # 'startup.nsh' is the default script executed by UEFI on boot # Use this script to run the test binary automatically -cat << EOF >startup.nsh +if [ $EFI_CASE != "_NO_FILE_4Uhere_" ]; then + cat << EOF >startup.nsh @echo -off fs0: "$EFI_CASE.efi" EOF +else + cat << EOF >startup.nsh +@echo -off +reset -s +EOF +fi popd || exit 2 # Run test case with 256MiB QEMU memory. QEMU default memory size is 128MiB. @@ -52,11 +63,16 @@ popd || exit 2 # run in UEFI, some test cases, e.g. `x86/pmu.c`, require more free memory. A # simple fix is to increase the QEMU default memory size to 256MiB so that # UEFI's largest allocatable memory region is large enough. +# +# Also, pass in an EFI-specific smp count (i.e., `-smp 1`) as the last argument +# to x86/run. This `smp` flag overrides any previous `smp` flags (e.g., +# `-smp 4`). This is necessary because KVM-Unit-Tests do not currently support +# SMP under UEFI. This last flag should be removed when this issue is resolved. "$TEST_DIR/run" \ -drive file="$EFI_UEFI",format=raw,if=pflash,readonly=on \ -drive file.dir="$EFI_TEST/$EFI_CASE/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \ -net none \ -nographic \ - -smp "$EFI_SMP" \ -m 256 \ - "$@" + "$@" \ + -smp "$EFI_SMP" From patchwork Tue Nov 16 20:40:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixuan Wang X-Patchwork-Id: 12623187 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64B58C433F5 for ; Tue, 16 Nov 2021 20:41:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46987615E2 for ; Tue, 16 Nov 2021 20:41:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231180AbhKPUoF (ORCPT ); Tue, 16 Nov 2021 15:44:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231168AbhKPUoE (ORCPT ); Tue, 16 Nov 2021 15:44:04 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B34CC061570 for ; Tue, 16 Nov 2021 12:41:07 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id v23so414730pjr.5 for ; Tue, 16 Nov 2021 12:41:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eT2uK5iWzmGTlr1p6wJHz1YbA/c4PXLTlOcjdQGarGM=; b=ERsUxkOJItxISuNgJpljb5OyMJcVfeJNmO1ku13/OEjhV9RHcZvg0EtE40+YsA2FSJ vMLCdLWnKS2k1Fg25Sm1U/A3aD3+ux+bATGl9Kf/STLT2p18Ii4RHTtGJKTYEhmFi/jA KX8Ivt/yLBja04Ho603Yh0MZYi9TeEJscy2yaXcuWJePL0T3F3Z0Ihwd5UgS1Vlk6aGS B7ELPntiU+b1mRw2RCt6XgtiFr6HLrfwvKjprrxx//mOmsaqCYMjo61E23k1PCDkz5zY fRHwUSsgot3D9W51zjCUJKMy2hO7kAWDZ8XgUJaEu7WMSqBieTI/mM28Bd1gEIBYtC2D e9Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eT2uK5iWzmGTlr1p6wJHz1YbA/c4PXLTlOcjdQGarGM=; b=EAw0xrUzFZXpDs+STCL+8tb7th42w/uZp4lDgBPuY0riRdqr2VBfUAHKU0si0pd1fD jJ4Oitt4s382kxITt8924Pk+jOKMKzH1axS/+edzjCqP1yz2RvKoNpQxtTsSLJ1Xfyp+ W0ShYhQxRf0w/IEZWlu3i8oZwlwsCYnm7aG+mJD0mQq0CvSjPhc2+R/HSp/uWtAI6iAS Y7MiXe+pZoBI7K9Jvy1JrPDVsI26wUtU0vt5Fo84ylL7IZM62Jcs44H5nQoKCB1k+aTD n0NtDhgNT1XiVBbu3ZV8u2EO65dwtEBs7dTQmLLv/dmjsWsUa0p4yDCYMQF+k1FgoG/L Sk+g== X-Gm-Message-State: AOAM532KkiLfLBoFodFtMaBEsAQsFkULqk4mqHPFyyEsykr/ZCSi3JjA UpG73PmMFxq/v2ePj3xigZCx2A1QJYoA1A== X-Google-Smtp-Source: ABdhPJxVc2vhvI5h0FO/JeDgCmWg4vTZznYegG1YHfJHRgl8ND5qhMbHsLzo3nSQKZ8yBbqGa2/Vjg== X-Received: by 2002:a17:90a:d684:: with SMTP id x4mr2581720pju.244.1637095266325; Tue, 16 Nov 2021 12:41:06 -0800 (PST) Received: from localhost.localdomain (netadmin.ucsd.edu. [137.110.160.224]) by smtp.gmail.com with ESMTPSA id lp12sm3652359pjb.24.2021.11.16.12.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 12:41:05 -0800 (PST) From: Zixuan Wang To: kvm@vger.kernel.org, pbonzini@redhat.com, drjones@redhat.com Cc: marcorr@google.com, erdemaktas@google.com, rientjes@google.com, seanjc@google.com, brijesh.singh@amd.com, Thomas.Lendacky@amd.com, varad.gautam@suse.com, jroedel@suse.de, bp@suse.de Subject: [kvm-unit-tests PATCH v2 09/10] x86 UEFI: Improve Boot Speed Date: Tue, 16 Nov 2021 12:40:52 -0800 Message-Id: <20211116204053.220523-10-zxwang42@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211116204053.220523-1-zxwang42@gmail.com> References: <20211116204053.220523-1-zxwang42@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Zixuan Wang The previous runner script uses `startup.nsh` to specify the EFI binaries. When a UEFI firmware sees this script, it waits 5 seconds for user input before executing the script. To remove this 5-second waiting, this commit drops the `startup.nsh` script, and renames test case binaries as UEFI's default binary filename `EFI/BOOT/BOOTX64.EFI`. This does not trigger the 5-second waiting. This commit only fix the boot speed for x86/efi/run script. The run-tests.sh will be fixed by the follow-up patch. Signed-off-by: Zixuan Wang --- x86/efi/run | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/x86/efi/run b/x86/efi/run index e6486ed..a888979 100755 --- a/x86/efi/run +++ b/x86/efi/run @@ -30,32 +30,16 @@ fi shift 1 # Prepare EFI boot file system -# - Copy .efi file to host dir $EFI_TEST/$EFI_CASE/ +# - Copy .efi file to host dir $EFI_TEST/$EFI_CASE/EFI/BOOT/BOOTX64.EFI # This host dir will be loaded by QEMU as a FAT32 image -# - Make UEFI startup script that runs the .efi on boot -mkdir -p "$EFI_TEST/$EFI_CASE/" -if [ $EFI_CASE != "_NO_FILE_4Uhere_" ]; then - cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_TEST/$EFI_CASE/" -else - touch "$EFI_TEST/$EFI_CASE/$EFI_CASE.efi" -fi +# - UEFI firmware by default loads the file EFI/BOOT/BOOTX64.EFI +: "${EFI_CASE_DIR:="$EFI_TEST/$EFI_CASE/EFI/BOOT"}" +: "${EFI_CASE_BINARY:="$EFI_CASE_DIR/BOOTX64.EFI"}" -pushd "$EFI_TEST/$EFI_CASE" || exit 2 -# 'startup.nsh' is the default script executed by UEFI on boot -# Use this script to run the test binary automatically -if [ $EFI_CASE != "_NO_FILE_4Uhere_" ]; then - cat << EOF >startup.nsh -@echo -off -fs0: -"$EFI_CASE.efi" -EOF -else - cat << EOF >startup.nsh -@echo -off -reset -s -EOF +mkdir -p "$EFI_CASE_DIR" +if [ "$EFI_CASE" != "_NO_FILE_4Uhere_" ]; then + cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_CASE_BINARY" fi -popd || exit 2 # Run test case with 256MiB QEMU memory. QEMU default memory size is 128MiB. # After UEFI boot up and we call `LibMemoryMap()`, the largest consecutive From patchwork Tue Nov 16 20:40:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zixuan Wang X-Patchwork-Id: 12623189 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7432C433EF for ; Tue, 16 Nov 2021 20:41:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AABDD61BBD for ; Tue, 16 Nov 2021 20:41:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231185AbhKPUoG (ORCPT ); Tue, 16 Nov 2021 15:44:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231168AbhKPUoF (ORCPT ); Tue, 16 Nov 2021 15:44:05 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B72EC061767 for ; Tue, 16 Nov 2021 12:41:08 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id n15-20020a17090a160f00b001a75089daa3so3300687pja.1 for ; Tue, 16 Nov 2021 12:41:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cLHNLQQhiR0+HDVMn8nTLasPvOuAmrrT3cWHezBkp04=; b=nH5FQ0odZRZ+CJYhCL8GzOogZssH+vnCc2HC/8oI8qb7/nGa1pWp/7YZqDLb5dKpgC hSzg4n2un5i1ZbZIW6z0/2takLDkIn6prIhRUeFGO36PFHu/Df/eEkKlfm1IiIgtQXFJ 85bsU5ECmrnvHDjLG2MkPXG4CT76XVcAszOdBkJwULv7bl1mw5A5CpPg/nDjNFPPwm4i 67ZeY4PCWxABCO/X24R66VApCFE+SqNncAkrKA1hq74420xS2LgVLXYJsrjLwDKoEuUl XIBkrScKKOJLdeFwgIr13JDogsIdEeokgBZ5jU5UUYBGEfYsAos8kHFYG4ZZtFaRsBxn r6PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cLHNLQQhiR0+HDVMn8nTLasPvOuAmrrT3cWHezBkp04=; b=RZlLZJ4gBTl0psKgSif5PYGvIJkJ/ymRQm+Kb3bJJc8HV14ThP1a8HZMVx6a0GNADk YjbF+kXAc99H4teMvZQ+QEJJtOIHl+1rkBZIKi3ap81mWc7Xhx4cFG1o87HOF8VBM7uo 7TwOmOAW8D8yWzPER5LxXQABvjdlJG0Gid3HMQP9ExVpwyxCTug5BnD/fdb6W6SkjuEf 3ixcpSYGNvY1oywuaB7Wk2gf9b/cJAp8NltdPLufNy15SqGmNkCrailI7C69J8eoMd54 VH+bNy8ep5glqKs2CxJAAzO4NnTQyqwyvigTPTADrYf2QnFAdMoKFlUpasbNdgGb3u6t /L8A== X-Gm-Message-State: AOAM530qSNNMkIAcWyIiTjU6DRis2llmJk/pn1OmKN+c4Hu0EsmCq1ty 3vN2lANHuVAq6zEDnauCU6AshOQup2zRXg== X-Google-Smtp-Source: ABdhPJxGGwApjCXYg0BikzKNPf/3WrivKzO0fMInBKGNCUoHEA9Q6MJLpQ2TMBrS48xSSeFBYy9TZQ== X-Received: by 2002:a17:903:410b:b0:142:497b:7209 with SMTP id r11-20020a170903410b00b00142497b7209mr49191732pld.9.1637095267548; Tue, 16 Nov 2021 12:41:07 -0800 (PST) Received: from localhost.localdomain (netadmin.ucsd.edu. [137.110.160.224]) by smtp.gmail.com with ESMTPSA id lp12sm3652359pjb.24.2021.11.16.12.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 12:41:07 -0800 (PST) From: Zixuan Wang To: kvm@vger.kernel.org, pbonzini@redhat.com, drjones@redhat.com Cc: marcorr@google.com, erdemaktas@google.com, rientjes@google.com, seanjc@google.com, brijesh.singh@amd.com, Thomas.Lendacky@amd.com, varad.gautam@suse.com, jroedel@suse.de, bp@suse.de Subject: [kvm-unit-tests PATCH v2 10/10] x86 UEFI: Make _NO_FILE_4Uhere_ work w/ BOOTX64.EFI Date: Tue, 16 Nov 2021 12:40:53 -0800 Message-Id: <20211116204053.220523-11-zxwang42@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211116204053.220523-1-zxwang42@gmail.com> References: <20211116204053.220523-1-zxwang42@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Marc Orr The `_NO_FILE_4Uhere_` test case is used by the runner scripts to verify QEMU's configuration. Make it work with EFI/BOOT/BOOTX64.EFI by compling a minimal EFI binary, called dummy.c that returns immediately. Signed-off-by: Marc Orr --- scripts/runtime.bash | 2 +- x86/efi/run | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/runtime.bash b/scripts/runtime.bash index 228a207..bb89a53 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -132,7 +132,7 @@ function run() last_line=$(premature_failure > >(tail -1)) && { skip=true - if [ "${TARGET_EFI}" == "y" ] && [[ "${last_line}" =~ "Reset" ]]; then + if [ "${TARGET_EFI}" == "y" ] && [[ "${last_line}" =~ "enabling apic" ]]; then skip=false fi if [ ${skip} == true ]; then diff --git a/x86/efi/run b/x86/efi/run index a888979..834cd90 100755 --- a/x86/efi/run +++ b/x86/efi/run @@ -39,6 +39,18 @@ shift 1 mkdir -p "$EFI_CASE_DIR" if [ "$EFI_CASE" != "_NO_FILE_4Uhere_" ]; then cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_CASE_BINARY" +else + if ! [ -f "$EFI_CASE_BINARY" ]; then + cat <$EFI_SRC/efi/dummy.c +int main(int argc, char **argv) +{ + return 0; +} +EOF + make "$EFI_SRC/efi/dummy.efi" + cp "$EFI_SRC/efi/dummy.efi" "$EFI_CASE_BINARY" + rm -f $EFI_SRC/efi/dummy* + fi fi # Run test case with 256MiB QEMU memory. QEMU default memory size is 128MiB.