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

Re: [PATCH] x86/string: correct memmove()'s forwarding to memcpy()


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Wed, 3 Feb 2021 15:36:33 +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=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FX6FwoNVhsfj7C4kPKB0/qKC8cFRTtjcevGezhqt2Hc=; b=Hpy1iAc1wqLdfolBdK3iGn1noCj4Wl9y2J7gIfUVSC/46/krs1uzlFppYHUXXUbE7uAaiMMxBhs1MzcWIVM0wNTVOz6Nkb1ajPVWgiZHUKPHseKEbR12S7LKuOgpEzKY0T7ZCmMRJghzTrCbm9g7QQicG5MZOh2twbfcR+dZcPOfqXzUQ6pz2ckDgHJwDiMmVOeRp3aaSZdCf6wJOrmW/UrrR7ecjsOrwJiFvhaCcxhG1fEw4hvK8Wn8Hs8xwcbcKXUp5koYVJbW0n2AKI1uoUygb3IvJ+1qBndeVum7p3Eug4WWYwSDGlMlOVOiGIIpW+AWfqp+AqBbRNG5rbTB7Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RbTSkS8p7a3x6aIMa6q9zCGaZNfT7UK0YZkEijCUI2tFpx/M1TZuMeoyPM8RxeSVxpfrNv0FYqc5NVjmu24ZjpjDrjnpZXl/pPr5BYLRdeKKjaeQbEChxhdR8Qo+LF949h0uwLq8gHMmEoNrYzKVi5NoSnfABuhHh7Uv5bDcLs9waR7GQdyRgU7g0ABUGnMAGSWbdGNjc8AJ34ktXIFNYfn3uPu/KJ6D5LdOnS527GFpceNI9yEEvxagkO6TDgwYC/6a/0jN6DiW84ajcxJY5k3657o7YwD+RpO8RyVOpNXAT4guyZALdUeKtxDEShIcUtO+CHdQZcYys50KbuJISg==
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 03 Feb 2021 15:37:02 +0000
  • Ironport-sdr: ZolqkgHUWX0jB/D7M9wWi4VoA0dBkR7wd0TFtTlkrsgXXDWTekACBG68hDYis1efwPNCEc96wg d4Oxq7loGDiu36OPc4/DXVPFImgpoeKg2J0cpezQKK2BK8brHWSjZH/9F+hWmpMsQcGw74HHOP DiQemBEP4AUk7P9gYLvHmq0BV7ZX3e5VcoKFMqsWqkgXp8Z7IQLD3l8EaufevenfdNQowHRWGq O7YYWrCvJNq5UXZGuJh3f1cpBZpIuTxWnr/EYPDjyM8Azt5DZxTYcvuS4LO/y8wqH4sQcZXbRZ s94=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 03/02/2021 15:31, Jan Beulich wrote:
> On 03.02.2021 16:01, Andrew Cooper wrote:
>> On 03/02/2021 14:22, Jan Beulich wrote:
>>> With memcpy() expanding to the compiler builtin, we may not hand it
>>> overlapping source and destination. We strictly mean to forward to our
>>> own implementation (a few lines up in the same source file).
>>>
>>> Fixes: 78825e1c60fa ("x86/string: Clean up x86/string.h")
>>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
>> I agree that the current logic is buggy, but I'm not sure this is an
>> improvement.
>>
>> You've switched from relying on GCC's builtin to operate forwards, to
>> relying on Xen's implementation operating forwards.
> Is there such a guarantee for the compiler builtin? If so - no
> need for this patch indeed. But I couldn't find any doc saying
> so.

I've never seen it emit anything which isn't a forwards operation (i.e.
I think the compiled result tended to be safe in practice), but C's
flexibility does explicitly permit a backwards implementation.

>
>> At the very least, can we get a code comment stating something like
>> "depends on Xen's implementation operating forwards" ?
> No problem at all.

In which case Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> to
avoid a round trip.

>
>>> ---
>>> An alternative would be to "#undef memcpy" near the top of the file. But
>>> I think the way it's done now is more explicit to the reader. An #undef
>>> would be the only way if the macro was an object-like one.
>> I chose not to use undef's to avoid impacting the optimisation of other
>> functions in this file.  I can't remember if this made a difference in
>> practice.
>>
>>> At least with gcc10 this does alter generated code: The builtin gets
>>> expanded into a tail call, while after this change our memcpy() gets
>>> inlined into memmove(). This would change again once we separate the 3
>>> functions here into their own CUs for placing them in an archive.
>> As (perhaps) a tangent, how do we plan to provide x86-optimised versions
>> in combination with the library work?
> By specifying the per-arch lib.a first.

Ok - good to hear.

>>   We're long overdue needing to
>> refresh our fast-strings support to include fast rep-mov/stosb.
> That's pretty much orthogonal to the code movement though.

Yes, but it does need doing.  We're perpetually playing catchup, and
there are meaningful improvements to be had for logic such as
clear_page() which is fairly poor, optimisation wise atm.

~Andrew



 


Rackspace

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