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

Re: [PATCH v3 4/6] xen: Switch to byteswap


  • To: Julien Grall <julien@xxxxxxx>, Lin Liu (刘林) <lin.liu@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • Date: Wed, 11 May 2022 09:56:11 +0000
  • Accept-language: en-GB, en-US
  • 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=arcselector9901; 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=i0NjmKknu847jEBZ5WoR2pyMVM8i3R0MuYh7Er4DYlU=; b=aPNub8s0rTXggKQO7tarUiXyHrTHnKIc0q6OhxICTF1V7ASJ2GjZHyskSguPHnvMYChAuCxTP5NaYOKkm8wbP6AZOeRyPQW2Yz4ApAGZSNFQFwVm/bugXL2TVMXQZmYJb2L4Nw8OG67o9LQju9cBybh4dnWDDQ5Vkh95IrWxx3rQPG/9jiUfqWzWVctZbrwwM2wc3f62HasauFOy/KegMvcPKnX10byIJQlMVYovTdVS81mrmothilWSqLiNh0zPH/OxudjFNJjuQ86W/TmafHGG7x4FUDN9Ge0S4eKb0tH5Uj8LeCsyAViAVL/trWPmnQcbtsyMSs4nHGNhLRM4kA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SK4AEoYApWZw1vt+IPtD0dURVEK+mVucUKH1OOzKkXL8M61l8Niilh7S3aeL+yrcgVdA3LP2kkg0TWVHZLG2mgJgbRPkO49ngPZzV1uhqp5yVqjQUFA3goqO55TLOed+vzzwFcMTcWjMNJbB+DHDFeohGIEkoPNk84H6tp8ujtFk8PX4lQzO0kSyURIw1edKkLw3bYDsrK8PaM+NE2C56FuAc0Gf5gTCkSk4z7HDvz8o9vcqjmXb95rTvgEArHwl2ZrwbJ3cN6x1+rGY47wefQxvo/IySkkGjyESW/8U2kzNyBTGM2a0D63AeV01cI1YbuBp1DU5uXGYrPK26F9GTw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, George Dunlap <George.Dunlap@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Wei Liu <wl@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Delivery-date: Wed, 11 May 2022 09:56:27 +0000
  • Ironport-data: A9a23:FeDHTqxRWzaDPVPuGGp6t+cKxyrEfRIJ4+MujC+fZmUNrF6WrkUPx mFNXGCOOq7cY2ugLt1yao+z/RsBucXUmNI2SgBrqSAxQypGp/SeCIXCJC8cHc8zwu4v7q5Dx 59DAjUVBJlsFhcwnj/0bv656yMUOZigHtIQMsadUsxKbVIiGX5JZS5LwbZj2NY12IHhWmthh PupyyHhEA79s9JLGjp8B5Kr8HuDa9yr5Vv0FnRnDRx6lAe2e0s9VfrzFonoR5fMeaFGH/bSe gr25OrRElU1XfsaIojNfr7TKiXmS1NJVOSEoiI+t6OK2nCuqsGuu0qS2TV1hUp/0l20c95NJ NplhZ+gYws3Oq72ocMGdz1TGgxfHO5n0eqSSZS/mZT7I0zuVVLJmq0rIGRoeIoS96BwHH1E8 uEeJHYVdBefiumqwbW9DO5xmsAkK8qtN4Qa0p1i5WiBUbB6HtaeE+OTvY4wMDQY36iiGd73Y cYDZCUpRxPHexBVYX8cCY4knffujX76G9FdgA3M+fdosjaLpOB3+IfLKtH7YeaxfMlukUaEl zqY8nXTLR5PYbRzzhLAqBpAnNTnnz7/WY8UPK218LhtmlL77nweDlgaWEW2pdG9i1WiQJRPJ koM4C0soKMuskuxQbHVRAakqXSJuhodXdt4EOAg7gyJjK3O7G6xBGIJUzpAY9wOr9ItSHoh0 Vrht8ztLSxitvuSU3313p2Zty+oMC4Za0oLfzYZTBAt6sPm5oo0i3ryos1LFae0ipj5HG/2y jXT9Cwm3exL3IgMyrmx+k3Bj3S0vJ/VQwUp5wLRGGW48gd+Y43jbIutgbTG0ct9wE+iZgHpl BA5dwK2tYji0bnlePSxfdgw
  • Ironport-hdrordr: A9a23:FfFfXKDYjWJf/2jlHej1sseALOsnbusQ8zAXPh9KJCC9I/bzqy nxpp8mPEfP+U0ssHFJo6HiBEEZKUmsuaKdkrNhR4tKOzOW91dATbsSoLcKpgeNJ8SQzJ876U 4NSclD4ZjLfCBHZKXBkUeF+rQbsb+6GcmT7I+woUuFDzsaEp2IhD0JaDpzZ3cGIDWucqBJca Z0iPAmmxOQPVAsKuirDHgMWObO4/fRkoj9XBIADxk7rCGTkDKB8tfBYlil9yZbdwkK7aYp8G DDnQC8zL6kqeuHxhjV0HKWx4hKmeHm1sBICKW3+4sow3TX+0SVjbZaKvm/VQMO0aaSAZER4Z /xSiIbToFOArXqDziISFXWqlHdOX0VmgLfIBej8AfeSIrCNXMH4oN69PxkmlGy0TtegPhslK 1MxG6XrJxREFfJmzn8/cHBU1VwmlOzumdKq59as5Vza/ppVFZql/1XwKqVKuZzIAvqrIQ8VO V+BsDV4/hbNVuccnDCp2FqhNihRG46EBuKSlUL/pX96UkdoFlpi08DgMAPlHYJ85wwD5FC+u TfK6xt0LVDVNUfY65xDPoIBcG3FmvOSxTRN3/6GyWtKIgXf3bW75Ln6rQ84++nPJQO0ZspgZ zEFEhVsGYjEniefvFmHKc7hiwlbF/NLQgFkPsulqSRkoeMN4bDIGmEVE0kldemrrEWHtDbMs zDTa5rPw==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHYZFbw3mG1/klQJUepEAoxYdrkNK0X7v0AgAAFDwCAAAI1AIAABM2AgAADuQCAAXM6gA==
  • Thread-topic: [PATCH v3 4/6] xen: Switch to byteswap

On 10/05/2022 12:47, Julien Grall wrote:
> Hi,
>
> On 10/05/2022 12:34, Andrew Cooper wrote:
>> On 10/05/2022 12:17, Julien Grall wrote:
>>>>
>>>>>
>>>>>> diff --git a/xen/include/xen/unaligned.h
>>>>>> b/xen/include/xen/unaligned.h
>>>>>> index 0a2b16d05d..16b2e6f5f0 100644
>>>>>> --- a/xen/include/xen/unaligned.h
>>>>>> +++ b/xen/include/xen/unaligned.h
>>>>>> @@ -20,62 +20,62 @@
>>>>>>       static inline uint16_t get_unaligned_be16(const void *p)
>>>>>>     {
>>>>>> -    return be16_to_cpup(p);
>>>>>> +    return be16_to_cpu(*(const uint16_t *)p)
>>>>>
>>>>> I haven't checked the existing implementation of be16_to_cpup().
>>>>
>>>> It's a plain dereference, just like this.  AFAICT, it wasn't unaligned
>>>> safe before, either.
>>>
>>> Well, technically an architecture could provide an override for the
>>> copy. I agree that arm32 is already bogus but...
>>>
>>>>
>>>> It should be reasonably easy to fix in a followup patch.  Just
>>>> memcpy()
>>>> to/from the void pointer to a stack variable of the appropriate type.
>>> ... I disagree that it should be fixed in a follow-up patch. It should
>>> be fixed now as this is where the badness is spread to any
>>> architecture.
>>
>> No.  That is an inappropriate request to make.
>>
>> Lin's patch does not alter the broken-ness of unaligned on arm32, and
>> does improve the aspect of the hypervisor that it pertains to.  It
>> therefore stands on its own merit.
> I am not sure sure why switching from *cpup* improves things... and as
> usual you haven't answered to the clarification questions.

Adjust your tone back to something appropriate to the conversation.

The p helpers hide a unsafe typecast&dereference which will erroneously
compile both of these:

void foo(void *ptr)
{
    blah_p(ptr);
}

void bar(baz *ptr)
{
    blah_p(ptr);
}

and potentially malfunction as a consequence, not to mention that it's
sufficient obfuscation to trick a maintainer into believe an unrelated
area of code was safe when it wasn't.

Deleting the p helpers is a specific objective of the work, because it
forces the author to resolve to an integral type, and have the deference
chain visible in a single location which improves code clarity.

On a hunch, I checked the MISRA spec, and it turns out there is a rule
against the p helpers (specifically the type safety aspect), so this
series is removing a whole load of DIR 4.9 violations from the codebase.

~Andrew

 


Rackspace

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