[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] vPCI: resolve MISRA R10.1 boolean arithmetic type violation


  • To: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Wed, 27 May 2026 16:34:04 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=H9L2Mu1KrNMAjehP1E37RfcDrG3fxTSBlXRii7MMts4=; b=lU8HHWSivaHcO/0+wW3nRTLF3j0eX0R7VK2NJ7C+R1T3w+8DNmcThxiXnmyckqMR+Le2Hxu0lsIIZz/T7Ol7CXHrBebKRFGCKCTdAwrdXzAIAiq5EhDcUkfz0FBdjBKZg5zoD9NG7t/W66/ShXkY0nX2ZBKzIF1oG0WAtpazqRkEWSjsYdWMA6+1rtjeP619nk9NY19x5VZPN3eNoYbh5DEosTI6Q+HJGId54CjrHlSQnfSSljSHMy7F9jNtli1rJ97Vd1CMg62exeACTx6XwJ2s+6fz33yv3Wr5z2Qvxe9IhbRiv/CZuNmesT7r+MGBCUqkQKodvbcjmpCOoPGXkg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jbThJ/OfMKL1NYAKBsQ8tRRhgH+VnFAwUVEYdH1vf9jpxwIPpkpKf86wlf6HfbsQ4e26lhosGYvXegbc5yZs0PPinakHbyqZJhhndaHbhII60H7CYyHzKwcCyaUMxIfaeywtWHnIRGaL8wNVS4cZohUilrcDnV3FXZWj+Uepa6kdKDj1XgJxUkkjnYXR61mPKXK8seTWIYwmcX8unpihyuulJ4VvogeUCL5t7ZCM8tToWwZcM8wlQrKZDL7csRgARdGONpVG2V/LutqzLbp93AJwu3wJXdZMb+GTvIXQPZy2ztZCjSFzWnVuYx75+JD8zmv6mEnAowAnwVM4snWsIg==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Stewart Hildebrand <stewart.hildebrand@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 27 May 2026 14:34:35 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, May 26, 2026 at 03:12:23PM -0700, Stefano Stabellini wrote:
> On Fri, 22 May 2026, Jan Beulich wrote:
> > (extending Cc list)
> > 
> > On 22.05.2026 08:13, Dmytro Prokopchuk1 wrote:
> > > --- a/xen/drivers/vpci/header.c
> > > +++ b/xen/drivers/vpci/header.c
> > > @@ -586,7 +586,7 @@ static void cf_check bar_write(
> > >          if ( val != (uint32_t)(bar->addr >> (hi ? 32 : 0)) )
> > >              gprintk(XENLOG_WARNING,
> > >                      "%pp: ignored BAR %zu write while mapped\n",
> > > -                    &pdev->sbdf, bar - pdev->vpci->header.bars + hi);
> > > +                    &pdev->sbdf, bar - pdev->vpci->header.bars + (hi ? 1 
> > > : 0));
> > >          return;
> > >      }
> > >  
> > > @@ -647,7 +647,7 @@ static void cf_check guest_mem_bar_write(const struct 
> > > pci_dev *pdev,
> > >          if ( guest_addr != bar->guest_addr )
> > >              gprintk(XENLOG_WARNING,
> > >                      "%pp: ignored guest BAR %zu write while mapped\n",
> > > -                    &pdev->sbdf, bar - pdev->vpci->header.bars + hi);
> > > +                    &pdev->sbdf, bar - pdev->vpci->header.bars + (hi ? 1 
> > > : 0));
> > >          return;
> > >      }
> > >      bar->guest_addr = guest_addr;
> > 
> > Well. If I'm not mistaken we had discussed situations like this (long ago).
> > Imo the added verbosity gets in the way of readability. If we absolutely
> > cannot or don't want to deviate such constructs (of which I expect we have
> > more), then we ought to consider alternatives (like changing the variables'
> > types in the case here).
> > 
> > As to deviating: rules.rst, according to my reading, says that &, |, ^, or
> > shifts would be okay to use with a bool operand. What's wrong with also
> > permitting this for other operators?
> 
> In my opinion, if we are going to treat bool as its own type, it makes
> sense not to silently mix bools into arithmetic with int types. I also
> do not find this patch less readable -- I actually find it more
> readable, since it makes it more obvious that hi is a bool.

Another possibly less controversial option is doing the arithmetic
based on the register value directly: (reg - PCI_BASE_ADDRESS_0) / 4.

TBH that's likely faster than the dereferences done to get the base
address of the bars array.

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.