[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: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 18 Nov 2026 09:19:11 +0100
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID"
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Community Manager <community.manager@xxxxxxxxxxxxxx>, Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 18 Nov 2026 08:19:21 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 17.11.2026 22:33, Andrew Cooper wrote:
> 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.

As there doesn't look to be any interest in widening the pattern (as you
say, there are many more fields where such protection would help), I
agree ...

> 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.

... there's no point having such special treatment just here. Hence ...

> 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.

... I then think no vote is going to be necessary (since aiui it's just
me you would want to outvote).

Jan



 


Rackspace

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