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=-12.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 5A72EC433EB for ; Tue, 28 Jul 2020 13:47:01 +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 2475420663 for ; Tue, 28 Jul 2020 13:47:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="gMzFarRK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2475420663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.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 1k0Pw2-0000re-HR; Tue, 28 Jul 2020 13:46:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k0Pw1-0000rZ-MJ for xen-devel@lists.xenproject.org; Tue, 28 Jul 2020 13:46:25 +0000 X-Inumbo-ID: b98830a3-d0d8-11ea-8b54-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b98830a3-d0d8-11ea-8b54-bc764e2007e4; Tue, 28 Jul 2020 13:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1595943984; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=YhoL7kY+bwriu01woWNcAHyzh1F/hQ8bxdDZSr+kIVk=; b=gMzFarRKKobk+EXxdCVHDHPkxfxtROcdyzmizfwRpdD+Fkh0nFa4Bs// 5eDZA4mbj/WQi1QUWFAuvyRhbKgeaxgzCD5pnhVgIfHjzBXrJQ5IiF8S+ x+W+S2LBs2BSOmLgUaW5VMYfvU7HIENnhWmNRyMv49EynZ2aZGPeqwxHe M=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: Hz2AnqTPk3jwtY+eH1yLKDlvxEPfmviLDPbxLMBzHQX9tYoaxKKsr0bpFaE/CnK/ak/W91Xotx ZPKZPG+ya6vDuLJu0tuZgX/B4jOY9NHpsNjaXHMskmttgm6CaOASt0yhMFgFF9ja5kNTwV1aQs fd6+5m8xNygCAJeQ9rO594NLdkafoCOKd5xzVOYLccQHI00JW7EoOBq5SOufoFAeKdgOjc+MsW 5hAq/8z3NxzRyUcdEAh91howVCp6ywTtcLttCqb9d1kW8LYxDO4MdnfWpVHX4NiYNZmhtI0MsW XxQ= X-SBRS: 2.7 X-MesageID: 23684190 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.75,406,1589256000"; d="scan'208";a="23684190" Subject: Re: [PATCH] x86/vhpet: Fix type size in timer_int_route_valid To: Eslam Elnikety , References: <20200728083357.77999-1-elnikety@amazon.com> <09b2f75d-13d7-8f53-54a1-6f10ecd7b6e2@amazon.com> From: Andrew Cooper Message-ID: Date: Tue, 28 Jul 2020 14:46:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <09b2f75d-13d7-8f53-54a1-6f10ecd7b6e2@amazon.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Content-Language: en-GB X-ClientProxiedBy: AMSPEX02CAS01.citrite.net (10.69.22.112) To AMSPEX02CL02.citrite.net (10.69.22.126) 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: Paul Durrant , Jan Beulich , Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On 28/07/2020 12:09, Eslam Elnikety wrote: > On 28.07.20 11:26, Andrew Cooper wrote: >> On 28/07/2020 09:33, Eslam Elnikety wrote: >>> The macro timer_int_route_cap evalutes to a 64 bit value. Extend the >>> size of left side of timer_int_route_valid to match. >>> >>> This bug was discovered and resolved using Coverity Static Analysis >>> Security Testing (SAST) by Synopsys, Inc. >>> >>> Signed-off-by: Eslam Elnikety >>> --- >>>   xen/arch/x86/hvm/hpet.c | 2 +- >>>   1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c >>> index ca94e8b453..9afe6e6760 100644 >>> --- a/xen/arch/x86/hvm/hpet.c >>> +++ b/xen/arch/x86/hvm/hpet.c >>> @@ -66,7 +66,7 @@ >>>       MASK_EXTR(timer_config(h, n), HPET_TN_INT_ROUTE_CAP) >>>     #define timer_int_route_valid(h, n) \ >>> -    ((1u << timer_int_route(h, n)) & timer_int_route_cap(h, n)) >>> +    ((1ULL << timer_int_route(h, n)) & timer_int_route_cap(h, n)) >>>     static inline uint64_t hpet_read_maincounter(HPETState *h, >>> uint64_t guest_time) >>>   { >> >> Does this work? > > Yes! This is better than my fix (and I like that it clarifies the > route part of the config. Will you sign-off and send a patch? Any chance I can persuade you, or someone else to do this?  Loads of the macros can be removed by filling in proper bitfield names in place of '_', resulting in rather better code. ~Andrew > >> >> diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c >> index ca94e8b453..638f6174de 100644 >> --- a/xen/arch/x86/hvm/hpet.c >> +++ b/xen/arch/x86/hvm/hpet.c >> @@ -62,8 +62,7 @@ >>     #define timer_int_route(h, n)    MASK_EXTR(timer_config(h, n), >> HPET_TN_ROUTE) >>   -#define timer_int_route_cap(h, n) \ >> -    MASK_EXTR(timer_config(h, n), HPET_TN_INT_ROUTE_CAP) >> +#define timer_int_route_cap(h, n) (h)->hpet.timers[(n)].route >>     #define timer_int_route_valid(h, n) \ >>       ((1u << timer_int_route(h, n)) & timer_int_route_cap(h, n)) >> diff --git a/xen/include/asm-x86/hvm/vpt.h >> b/xen/include/asm-x86/hvm/vpt.h >> index f0e0eaec83..a41fc443cc 100644 >> --- a/xen/include/asm-x86/hvm/vpt.h >> +++ b/xen/include/asm-x86/hvm/vpt.h >> @@ -73,7 +73,13 @@ struct hpet_registers { >>       uint64_t isr;               /* interrupt status reg */ >>       uint64_t mc64;              /* main counter */ >>       struct {                    /* timers */ >> -        uint64_t config;        /* configuration/cap */ >> +        union { >> +            uint64_t config;    /* configuration/cap */ >> +            struct { >> +                uint32_t _; >> +                uint32_t route; >> +            }; >> +        }; >>           uint64_t cmp;           /* comparator */ >>           uint64_t fsb;           /* FSB route, not supported now */ >>       } timers[HPET_TIMER_NUM]; >> >> >