Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3670381imu; Fri, 30 Nov 2018 04:17:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vu2doOq3O+UtREb98fZImkq7bmdVtFRVlmQwC+lFayhdC+GM8YmFfK3lL28T1POWA8umFc X-Received: by 2002:a63:b4c:: with SMTP id a12mr4730351pgl.131.1543580253903; Fri, 30 Nov 2018 04:17:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543580253; cv=none; d=google.com; s=arc-20160816; b=NaQzpJk+Trp+khCEmD6+RHA0xd5fZxjB9zh8/xOv21qKjBEhyaIVeh7lorXyr1asUj 1JZTFphlO3XcfDgj66Wcre1xRS7kKdGw4fg3xaLsYW7MvHvPhLOAdOYbsSxoXgXA8cbx /K1XgdX/QIOxD85IWO8ii+/QC0PwKo6Ei6lihR+b//2OZo6iN9Ox3eba7zzE8NstKgei dGkP+fm8MlORy0Rpz0fPpA7DNRIbwwhjh9U6Cvs3BVi4GDWo+oMgEjyuyiJSo3aCDGOy Po2byaaS3GGOy+f9CbcdI9K7IZGgw8YNjhsvUle/RI//PsSPKsEeOBq4D0M2i6cMvoDx KreA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=hH1isLiPGaZbFvTmYc+oBYMK6apRW7EAWIPKq6jaBTc=; b=efM4eJvVxVvijjB0eQfXIvf2nvO1zHatenxTvxNMYn55OGQhy3ehv8Xv4O3uDxYsk7 E7XVseGP7ykR1sV9f5C1PYmdYgY9Y5q4tCvB/+XME9QarbXdgeeKaPmzDVvzImN0akvS gebYrkG9BOH5gpmHHHoFpKl5MSvtP7wmiCtvdYh1FXZ2Ktu9Gff+jSmbjR664oINTjD5 zbh31PM/pbRaVLm6vEAX0TC/j4J2uQYAuTGMwsnhv2EcT7RBZEHXC7jb52igXWkuL1cb ipL6XsgJv1lx/hMvthIdJncBreyr5VTTishpdp8uE1OEblsqqdPW3Whfqq2THK/PHY+g yyFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u21si4712004pgm.21.2018.11.30.04.17.11; Fri, 30 Nov 2018 04:17:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726776AbeK3XYW (ORCPT + 99 others); Fri, 30 Nov 2018 18:24:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26864 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726512AbeK3XYW (ORCPT ); Fri, 30 Nov 2018 18:24:22 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58B60C050009; Fri, 30 Nov 2018 12:15:16 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DA8F17DCC; Fri, 30 Nov 2018 12:15:13 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , linux-kernel@vger.kernel.org, Roman Kagan , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , x86@kernel.org, "Michael Kelley (EOSG)" , Nadav Amit , Thomas Gleixner Subject: [PATCH] x86/hyper-v: define structures from TLFS as packed Date: Fri, 30 Nov 2018 13:15:11 +0100 Message-Id: <20181130121511.12331-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 30 Nov 2018 12:15:16 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Without 'packed' compiler is free to add optimization paddings and re-order structure fields for randomization/optimization. And structures from hyperv-tlfs.h are used for hypervisor-guest communication, we need to ultimately forbid such practices. Suggested-by: Nadav Amit Signed-off-by: Vitaly Kuznetsov --- - This is a follow-up to my "[PATCH v2 0/4] x86/kvm/hyper-v: Implement Direct Mode for synthetic timers" series, as suggested by Thomas I'm routing it to KVM tree to avoid merge conflicts. --- arch/x86/include/asm/hyperv-tlfs.h | 50 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index ebfed56976d2..6a60fa17f6f2 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -271,7 +271,7 @@ union hv_x64_msr_hypercall_contents { u64 enable:1; u64 reserved:11; u64 guest_physical_address:52; - }; + } __packed; }; /* @@ -283,7 +283,7 @@ struct ms_hyperv_tsc_page { volatile u64 tsc_scale; volatile s64 tsc_offset; u64 reserved2[509]; -}; +} __packed; /* * The guest OS needs to register the guest ID with the hypervisor. @@ -324,7 +324,7 @@ struct hv_reenlightenment_control { __u64 enabled:1; __u64 reserved2:15; __u64 target_vp:32; -}; +} __packed; #define HV_X64_MSR_TSC_EMULATION_CONTROL 0x40000107 #define HV_X64_MSR_TSC_EMULATION_STATUS 0x40000108 @@ -332,12 +332,12 @@ struct hv_reenlightenment_control { struct hv_tsc_emulation_control { __u64 enabled:1; __u64 reserved:63; -}; +} __packed; struct hv_tsc_emulation_status { __u64 inprogress:1; __u64 reserved:63; -}; +} __packed; #define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001 #define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12 @@ -409,7 +409,7 @@ typedef struct _HV_REFERENCE_TSC_PAGE { __u32 res1; __u64 tsc_scale; __s64 tsc_offset; -} HV_REFERENCE_TSC_PAGE, *PHV_REFERENCE_TSC_PAGE; +} __packed HV_REFERENCE_TSC_PAGE, *PHV_REFERENCE_TSC_PAGE; /* Define the number of synthetic interrupt sources. */ #define HV_SYNIC_SINT_COUNT (16) @@ -466,7 +466,7 @@ union hv_message_flags { struct { __u8 msg_pending:1; __u8 reserved:7; - }; + } __packed; }; /* Define port identifier type. */ @@ -488,7 +488,7 @@ struct hv_message_header { __u64 sender; union hv_port_id port; }; -}; +} __packed; /* Define synthetic interrupt controller message format. */ struct hv_message { @@ -496,12 +496,12 @@ struct hv_message { union { __u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; } u; -}; +} __packed; /* Define the synthetic interrupt message page layout. */ struct hv_message_page { struct hv_message sint_message[HV_SYNIC_SINT_COUNT]; -}; +} __packed; /* Define timer message payload structure. */ struct hv_timer_message_payload { @@ -509,7 +509,7 @@ struct hv_timer_message_payload { __u32 reserved; __u64 expiration_time; /* When the timer expired */ __u64 delivery_time; /* When the message was delivered */ -}; +} __packed; /* Define virtual processor assist page structure. */ struct hv_vp_assist_page { @@ -519,7 +519,7 @@ struct hv_vp_assist_page { __u64 nested_enlightenments_control[2]; __u32 enlighten_vmentry; __u64 current_nested_vmcs; -}; +} __packed; struct hv_enlightened_vmcs { u32 revision_id; @@ -693,7 +693,7 @@ struct hv_enlightened_vmcs { u32 nested_flush_hypercall:1; u32 msr_bitmap:1; u32 reserved:30; - } hv_enlightenments_control; + } __packed hv_enlightenments_control; u32 hv_vp_id; u64 hv_vm_id; @@ -703,7 +703,7 @@ struct hv_enlightened_vmcs { u64 padding64_5[7]; u64 xss_exit_bitmap; u64 padding64_6[7]; -}; +} __packed; #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE 0 #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_IO_BITMAP BIT(0) @@ -744,7 +744,7 @@ union hv_stimer_config { u64 reserved_z0:3; u64 sintx:4; u64 reserved_z1:44; - }; + } __packed; }; @@ -759,7 +759,7 @@ union hv_synic_scontrol { struct { u64 enable:1; u64 reserved:63; - }; + } __packed; }; /* Define synthetic interrupt source. */ @@ -771,7 +771,7 @@ union hv_synic_sint { u64 masked:1; u64 auto_eoi:1; u64 reserved2:46; - }; + } __packed; }; /* Define the format of the SIMP register */ @@ -781,7 +781,7 @@ union hv_synic_simp { u64 simp_enabled:1; u64 preserved:11; u64 base_simp_gpa:52; - }; + } __packed; }; /* Define the format of the SIEFP register */ @@ -791,34 +791,34 @@ union hv_synic_siefp { u64 siefp_enabled:1; u64 preserved:11; u64 base_siefp_gpa:52; - }; + } __packed; }; struct hv_vpset { u64 format; u64 valid_bank_mask; u64 bank_contents[]; -}; +} __packed; /* HvCallSendSyntheticClusterIpi hypercall */ struct hv_send_ipi { u32 vector; u32 reserved; u64 cpu_mask; -}; +} __packed; /* HvCallSendSyntheticClusterIpiEx hypercall */ struct hv_send_ipi_ex { u32 vector; u32 reserved; struct hv_vpset vp_set; -}; +} __packed; /* HvFlushGuestPhysicalAddressSpace hypercalls */ struct hv_guest_mapping_flush { u64 address_space; u64 flags; -}; +} __packed; /* HvFlushVirtualAddressSpace, HvFlushVirtualAddressList hypercalls */ struct hv_tlb_flush { @@ -826,7 +826,7 @@ struct hv_tlb_flush { u64 flags; u64 processor_mask; u64 gva_list[]; -}; +} __packed; /* HvFlushVirtualAddressSpaceEx, HvFlushVirtualAddressListEx hypercalls */ struct hv_tlb_flush_ex { @@ -834,6 +834,6 @@ struct hv_tlb_flush_ex { u64 flags; struct hv_vpset hv_vp_set; u64 gva_list[]; -}; +} __packed; #endif -- 2.19.2