From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C67F4C433DF for ; Tue, 30 Jun 2020 10:53:18 +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 9BEFD2073E for ; Tue, 30 Jun 2020 10:53:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BEFD2073E 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 1jqDsc-0007rn-So; Tue, 30 Jun 2020 10:52:46 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jqDsc-0007rf-3y for xen-devel@lists.xenproject.org; Tue, 30 Jun 2020 10:52:46 +0000 X-Inumbo-ID: d1fcdaea-babf-11ea-bca7-bc764e2007e4 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d1fcdaea-babf-11ea-bca7-bc764e2007e4; Tue, 30 Jun 2020 10:52:41 +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 D9ACDACE1; Tue, 30 Jun 2020 10:52:40 +0000 (UTC) Subject: Re: [PATCH] x86: fix compat header generation To: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= References: <0e617191-d61f-08e2-eaa9-b324cd6501f0@suse.com> <20200630095239.GK735@Air-de-Roger> From: Jan Beulich Message-ID: <7d991541-84df-b18c-acde-449d3edae384@suse.com> Date: Tue, 30 Jun 2020 12:52:41 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200630095239.GK735@Air-de-Roger> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit 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 , "xen-devel@lists.xenproject.org" Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On 30.06.2020 11:52, Roger Pau Monné wrote: > On Mon, Jun 29, 2020 at 05:50:59PM +0200, Jan Beulich wrote: >> 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. > > Just to clarify my understanding, this means that struct fields that > are also structs will need special alignment? (because we no longer have > the 4byte packaging). They may need in principle, but right now there's no instance of such as per my comparing of the generated binaries. > I see from the generated headers that uint64_compat_t is already > aligned to 4 bytes, and I assume something similar will be needed for > all 8byte types? If there are native types that get re-used (rather than re-created as compat version in the compat headers, which would then necessarily derive from {u,}int64_t directly or indirectly, as there's no other non-derived 8-byte type that's legitimate to use in public headers - e.g. "unsigned long long" is not legitimate to be used, and all "unsigned long" instances [if there are any left] get converted to "unsigned int"), yes. >> 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. > > Is there someway that we could spot such changes, maybe building a > version of the plain structures with -m32 and comparing against their > compat versions? Depends on what "comparing" here means. Yes, something could presumably be invented. But it may also be that we'd be better of doing away with the re-use of native structs. But of course doing so will have significant fallout, which right now I have no good idea how to deal with. > I know we have some compat checking infrastructure, so I wonder if we > could use it to avoid issues like the one we had with > xen_mem_acquire_resource, as it seems like something that could be > programmatically detected. Yes, having this properly checked would definitely be nice. It's just the "how" that's unclear to me here. >> @@ -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 > > Not sure if it's worth mentioning that the .i and .c files are now > kept. Ouch - these weren't supposed to be left in. They were just for my debugging. Thanks for noticing. Jan