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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 29528C5475B for ; Fri, 1 Mar 2024 11:43:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.687617.1071291 (Exim 4.92) (envelope-from ) id 1rg1IX-0007fJ-2G; Fri, 01 Mar 2024 11:43:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 687617.1071291; Fri, 01 Mar 2024 11:43:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rg1IW-0007fC-VE; Fri, 01 Mar 2024 11:43:28 +0000 Received: by outflank-mailman (input) for mailman id 687617; Fri, 01 Mar 2024 11:43:27 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rg1IV-0007f6-7r for xen-devel@lists.xenproject.org; Fri, 01 Mar 2024 11:43:27 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ea135df9-d7c0-11ee-afd8-a90da7624cb6; Fri, 01 Mar 2024 12:43:25 +0100 (CET) Received: from support.bugseng.com (support.bugseng.com [162.55.131.47]) by support.bugseng.com (Postfix) with ESMTPA id 5FD894EE0737; Fri, 1 Mar 2024 12:43:25 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ea135df9-d7c0-11ee-afd8-a90da7624cb6 MIME-Version: 1.0 Date: Fri, 01 Mar 2024 12:43:25 +0100 From: Nicola Vetrini To: Xen Devel Cc: Andrew Cooper3 , George Dunlap , Stefano Stabellini , Jbeulich , Julien Grall , Wei Liu , Roger Pau , Consulting Subject: Violations of MISRA C Rule 20.7 in xen/arch/x86/include/asm/hvm/trace.h Message-ID: X-Sender: nicola.vetrini@bugseng.com Organization: BUGSENG s.r.l. Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Reporting the discussion that took place on Matrix on the matter, so that it can carry on here with all interested parties: > Hi everyone. I was looking at MISRA violations for Rule 20.7 > ("Expressions resulting from the expansion of macro parameters shall be > enclosed in parentheses") generated by > > #define TRC_PAR_LONG(par) ((uint32_t)(par)), ((par) >> 32) > > The thing here is this: the simplest fix is > > -#define TRC_PAR_LONG(par) ((uint32_t)(par)), ((par) >> 32) > +#define TRC_PAR_LO(par) ((uint32_t)(par)) > +#define TRC_PAR_HI(par) ((par) >> 32) > > and then replace all call sites accordingly. However, in certain places > (e.g., svm.c:1445), this causes a build error: > > arch/x86/hvm/svm/svm.c: In function ‘svm_inject_event’: > arch/x86/hvm/svm/svm.c:1445:1: error: macro "HVMTRACE_3D" requires > 4 arguments, but only 3 given > 1445 | TRC_PAR_LO(_event.cr2), TRC_PAR_HI(_event.cr2)); > | ^ > In file included from arch/x86/hvm/svm/svm.c:31: > > this is due to the somewhat strange definition of HVMTRACE_3D which > works with the previous form of the macro, but not the current one, as > the macro argument in HVMTRACE_LONG_2D is now split (_LO is d2 and _HI > is variadic), and therefore it's not passed to HVMTRACE_3D anymore as > two arguments. > I have a proposal: introduce a d3 argument to HVMTRACE_LONG_2D to > supply the additional argument and/or make HVMTRACE_LONG_2D > non-variadic. This would of course apply to the similarly named macros > in xen/arch/x86/include/asm/hvm/trace.h Andrew Cooper: > sigh - I'm half way through deleting all of that > guess I ought to finish Andrew Cooper: > @Nicola Vetrini: > https://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen.git;a=shortlog;h=refs/heads/xen-trace > On second thoughts I'm not sure it fixes the problem > just changes it. The problem is the use of macros to split a 64bit > quantity across two 32bit fields Nicola Vetrini: > It seems so, yes. But afaict this can be fixed by splitting the macro > definition in two, as done above, which wouldn't incur in the > compilation error on the new API Andrew Cooper: > given the users of TRACE_PARAM64() by the end, I'd prefer to do that > with real structs rather than perpetuating the macro mess George Dunlap: > It's been a long time since I looked at all this, but FWIW I inherited > all the weird macro stuff, never liked it, and myself used structs for > all new traces. So without having looked at the code at all, I'm > predisposed to agree w/ Andy's assessment that we should just rip out > the offending macros and replace them with structs. @gwd: I believe the file that I was concerned about does not fall under the XENTRACE entry in MAINTAINERS; you may want to rectify that. -- Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)