From patchwork Mon Jun 29 15:50:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11631201 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B184913 for ; Mon, 29 Jun 2020 15:51:59 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E4BD52545F for ; Mon, 29 Jun 2020 15:51:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E4BD52545F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jpw3j-0002tZ-Re; Mon, 29 Jun 2020 15:51:03 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jpw3i-0002tU-Qm for xen-devel@lists.xenproject.org; Mon, 29 Jun 2020 15:51:02 +0000 X-Inumbo-ID: 54e09cbc-ba20-11ea-8587-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 54e09cbc-ba20-11ea-8587-12813bfff9fa; Mon, 29 Jun 2020 15:51:01 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id F0241AD26; Mon, 29 Jun 2020 15:51:00 +0000 (UTC) To: "xen-devel@lists.xenproject.org" From: Jan Beulich Subject: [PATCH] x86: fix compat header generation Message-ID: <0e617191-d61f-08e2-eaa9-b324cd6501f0@suse.com> Date: Mon, 29 Jun 2020 17:50:59 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 Content-Language: en-US X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Paul Durrant , George Dunlap , Andrew Cooper , Ian Jackson , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" As was pointed out by "mm: fix public declaration of struct xen_mem_acquire_resource", we're not currently handling structs correctly that has uint64_aligned_t fields. #pragma pack(4) suppresses the necessary alignment even if the type did properly survive (which it also didn't) in the process of generating the headers. Overall, with the above mentioned change applied, there's only a latent issue here afaict, i.e. no other of our interface structs is currently affected. As a result it is clear that using #pragma pack(4) is not an option. Drop all uses from compat header generation. Make sure {,u}int64_aligned_t actually survives, such that explicitly aligned fields will remain aligned. Arrange for {,u}int64_t to be transformed into a type that's 64 bits wide and 4-byte aligned, by utilizing that in typedef-s the "aligned" attribute can be used to reduce alignment. Note that this changes alignment (but not size) of certain compat structures, when one or more of their fields use a non-translated struct as their type(s). This isn't correct, and hence applying alignof() to such fields requires care, but the prior situation was even worse. There's one change to generated code according to my observations: In arch_compat_vcpu_op() the runstate area "area" variable would previously have been put in a just 4-byte aligned stack slot (despite being 8 bytes in size), whereas now it gets put in an 8-byte aligned location. Signed-off-by: Jan Beulich --- a/xen/include/Makefile +++ b/xen/include/Makefile @@ -34,15 +34,6 @@ headers-$(CONFIG_XSM_FLASK) += compat/xs cppflags-y := -include public/xen-compat.h -DXEN_GENERATING_COMPAT_HEADERS cppflags-$(CONFIG_X86) += -m32 -# 8-byte types are 4-byte aligned on x86_32 ... -ifeq ($(CONFIG_CC_IS_CLANG),y) -prefix-$(CONFIG_X86) := \#pragma pack(push, 4) -suffix-$(CONFIG_X86) := \#pragma pack(pop) -else -prefix-$(CONFIG_X86) := \#pragma pack(4) -suffix-$(CONFIG_X86) := \#pragma pack() -endif - endif public-$(CONFIG_X86) := $(wildcard public/arch-x86/*.h public/arch-x86/*/*.h) @@ -57,16 +48,16 @@ compat/%.h: compat/%.i Makefile $(BASEDI echo "#define $$id" >>$@.new; \ echo "#include " >>$@.new; \ $(if $(filter-out compat/arch-%.h,$@),echo "#include <$(patsubst compat/%,public/%,$@)>" >>$@.new;) \ - $(if $(prefix-y),echo "$(prefix-y)" >>$@.new;) \ grep -v '^# [0-9]' $< | \ $(PYTHON) $(BASEDIR)/tools/compat-build-header.py | uniq >>$@.new; \ - $(if $(suffix-y),echo "$(suffix-y)" >>$@.new;) \ echo "#endif /* $$id */" >>$@.new mv -f $@.new $@ +.PRECIOUS: compat/%.i compat/%.i: compat/%.c Makefile $(CPP) $(filter-out -Wa$(comma)% -include %/include/xen/config.h,$(XEN_CFLAGS)) $(cppflags-y) -o $@ $< +.PRECIOUS: compat/%.c compat/%.c: public/%.h xlat.lst Makefile $(BASEDIR)/tools/compat-build-source.py mkdir -p $(@D) grep -v 'DEFINE_XEN_GUEST_HANDLE(long)' $< | \ --- a/xen/tools/compat-build-header.py +++ b/xen/tools/compat-build-header.py @@ -3,7 +3,7 @@ import re,sys pats = [ - [ r"__InClUdE__(.*)", r"#include\1\n#pragma pack(4)" ], + [ r"__InClUdE__(.*)", r"#include\1" ], [ r"__IfDeF__ (XEN_HAVE.*)", r"#ifdef \1" ], [ r"__ElSe__", r"#else" ], [ r"__EnDif__", r"#endif" ], @@ -13,7 +13,8 @@ pats = [ [ r"(struct|union|enum)\s+(xen_?)?(\w)", r"\1 compat_\3" ], [ r"@KeeP@", r"" ], [ r"_t([^\w]|$)", r"_compat_t\1" ], - [ r"(8|16|32|64)_compat_t([^\w]|$)", r"\1_t\2" ], + [ r"(8|16|32|64_aligned)_compat_t([^\w]|$)", r"\1_t\2" ], + [ r"(\su?int64(_compat)?)_T([^\w]|$)", r"\1_t\3" ], [ r"(^|[^\w])xen_?(\w*)_compat_t([^\w]|$$)", r"\1compat_\2_t\3" ], [ r"(^|[^\w])XEN_?", r"\1COMPAT_" ], [ r"(^|[^\w])Xen_?", r"\1Compat_" ], --- a/xen/tools/compat-build-source.py +++ b/xen/tools/compat-build-source.py @@ -9,6 +9,7 @@ pats = [ [ r"^\s*#\s*endif /\* (XEN_HAVE.*) \*/\s+", r"__EnDif__" ], [ r"^\s*#\s*define\s+([A-Z_]*_GUEST_HANDLE)", r"#define HIDE_\1" ], [ r"^\s*#\s*define\s+([a-z_]*_guest_handle)", r"#define hide_\1" ], + [ r"^\s*#\s*define\s+(u?int64)_aligned_t\s.*", r"typedef \1_T __attribute__((aligned(4))) \1_compat_T;" ], [ r"XEN_GUEST_HANDLE(_[0-9A-Fa-f]+)?", r"COMPAT_HANDLE" ], ];