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

Re: [PATCH] PCI: deviate MISRA R11.8 for the one-time SBDF initialization


  • To: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Tue, 17 Nov 2026 21:33:42 +0000
  • 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=Hxac6VCxWRPyHSpfVyfkx+JZW1yPapP4FV+Nsp2xFHY=; b=k3hmjBF8N6He9w3aVVB2Ac8YDvtREhxOQIb8IuXBGW3mx85B6SBCzTzrn0//GrjXAUh8xFCqM/9RF3Y4bfBmGNSP1xEy/s+jCdEGLNZVhissLgSdorF+wAKL7Fz9JZEQ9hmxhlWxt5flRr0HteXG085SCGcnNuhZp3yXhxsnDmmw0vr84W5kU6aGWGefrnLn7hMSnkj6D9J/jQlVHRESkh72nZBEeFxrX3Peaj6DtBq8JpPIrJUrMt1aPiMzR5vFYM3R1iHAXxbQKXLtl4+I/ic0uGUIddtHRNdNcnqrhuWwyH12qONiTavOI0fWWdAa4/LAwvttxW3KdYzISzFqBg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sjuBcpTk1WCM7T5seWzDq+6NTz92bmnuDMTMDvrvLwRGhE6AOgEnMrGirlgda4WaWtc7KBNaW3RaGop++MKHr6m04h+cZvvcAKAy2hVABWI86Z6CIUB/g6MJCf/N4VUvy24uLGZpaTMmwgIUOyi/BA6EKbesnts0Pov5/qvuMpi9nNzQY2QtVbxOoXyitVQPIQ1rWPmWXyelmlmBJG9oci232+jQLnH30qslYEnPWfBN7IyoOGP8b0A6XLoB20o1GXEXZt3z0TAJwv0BPiCyXrNt/FFIg9UEnpA6/3rDSRPwdiAGgwkTXwaf08DvMyijbmMLCH8kiIeOC3VthgOsLg==
  • 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: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Autocrypt: addr=andrew.cooper3@xxxxxxxxxx; keydata= xsFNBFLhNn8BEADVhE+Hb8i0GV6mihnnr/uiQQdPF8kUoFzCOPXkf7jQ5sLYeJa0cQi6Penp VtiFYznTairnVsN5J+ujSTIb+OlMSJUWV4opS7WVNnxHbFTPYZVQ3erv7NKc2iVizCRZ2Kxn srM1oPXWRic8BIAdYOKOloF2300SL/bIpeD+x7h3w9B/qez7nOin5NzkxgFoaUeIal12pXSR Q354FKFoy6Vh96gc4VRqte3jw8mPuJQpfws+Pb+swvSf/i1q1+1I4jsRQQh2m6OTADHIqg2E ofTYAEh7R5HfPx0EXoEDMdRjOeKn8+vvkAwhviWXTHlG3R1QkbE5M/oywnZ83udJmi+lxjJ5 YhQ5IzomvJ16H0Bq+TLyVLO/VRksp1VR9HxCzItLNCS8PdpYYz5TC204ViycobYU65WMpzWe LFAGn8jSS25XIpqv0Y9k87dLbctKKA14Ifw2kq5OIVu2FuX+3i446JOa2vpCI9GcjCzi3oHV e00bzYiHMIl0FICrNJU0Kjho8pdo0m2uxkn6SYEpogAy9pnatUlO+erL4LqFUO7GXSdBRbw5 gNt25XTLdSFuZtMxkY3tq8MFss5QnjhehCVPEpE6y9ZjI4XB8ad1G4oBHVGK5LMsv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bZrI0U9tJ B8WrhBLXDiYlyJT6zOV2yZFuW47VrLsjYnHwn27hmxTC/7tvG3euCklmkn9Sl9IAKFu29RSo d5bD8kMSCYsTqtTfT6W4A3qHGvIDta3ptLYpIAOD2sY3GYq2nf3Bbzx81wZK14JdDDHUX2Rs 6+ahAA==
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Community Manager <community.manager@xxxxxxxxxxxxxx>
  • Delivery-date: Tue, 17 Nov 2026 21:33:52 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 17/11/2026 8:55 pm, Dmytro Prokopchuk1 wrote:
> MISRA C Rule 11.8 states: "A cast shall not remove any const or volatile
> qualification from the type pointed to by a pointer".
>
> alloc_pdev() writes the device identity once. seg, bus and devfn are
> members of a const union, so that write goes through a cast that removes
> const. Three such casts performed the same initialization.
>
> Store the whole sbdf in one assignment and document that cast with
> one-line SAF-15-safe comment.
>
> No functional changes.
>
> Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
> ---
> Test CI pipeline:
> https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/3081067362
> ---
>  docs/misra/safe.json          | 8 ++++++++
>  xen/drivers/passthrough/pci.c | 5 ++---
>  2 files changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/docs/misra/safe.json b/docs/misra/safe.json
> index 3584cb90c6..3503d2e808 100644
> --- a/docs/misra/safe.json
> +++ b/docs/misra/safe.json
> @@ -124,6 +124,14 @@
>          },
>          {
>              "id": "SAF-15-safe",
> +            "analyser": {
> +                "eclair": "MC3A2.R11.8"
> +            },
> +            "name": "Rule 11.8: one-time init of a const PCI identity",
> +            "text": "The cast removes const only to initialize the const 
> pci_dev identity fields (seg, bus, devfn). The const qualification prevents 
> any later assignment, and this is the only write, performed before the device 
> is published on alldevs_list."
> +        },
> +        {
> +            "id": "SAF-16-safe",
>              "analyser": {},
>              "name": "Sentinel",
>              "text": "Next ID to be used"
> diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
> index 578472d068..14d59b1293 100644
> --- a/xen/drivers/passthrough/pci.c
> +++ b/xen/drivers/passthrough/pci.c
> @@ -329,9 +329,8 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg, 
> u8 bus, u8 devfn)
>      if ( !pdev )
>          return NULL;
>  
> -    *(u16*) &pdev->seg = pseg->nr;
> -    *((u8*) &pdev->bus) = bus;
> -    *((u8*) &pdev->devfn) = devfn;
> +    /* SAF-15-safe R11.8 one-time init of the const PCI identity */
> +    *(pci_sbdf_t *)&pdev->sbdf = PCI_SBDF(pseg->nr, bus, devfn);
>      pdev->domain = NULL;
>  
>      INIT_LIST_HEAD(&pdev->vf_list);

I'm sorry you're in the middle of a fight between the maintainers, but
this too is absurd.

There is nothing about pdev->sbdf worthy of an exception like this.  We
have loads of other structures with identifiers that **if and only if we
were writing C++** would be const members.  From a practical standpoint
d->domain_id or v->vcpu_id would be far more worthy than pdev->sbdf of
special casing in this way.

But, Xen is written in C.

I accept that this isn't creating a class of undefined behaviour, but
it's bogus-looking code try to try and use a C++-ism.  In the modern
world of AI's, we're at much greater risk of an LLM seeing this and
deciding it's an acceptable code pattern in Xen.


Please just delete the const and make a plain SBDF assignment to drop
the current casts.

If I need to call a formal governance vote to put an end to the
maintainer infighting, I will.  It has gone on far too long, and is
continuing to waste time we simply don't have.

~Andrew



 


Rackspace

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