public: add RING_COPY_RESPONSE()
authorMarek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Tue, 30 Mar 2021 12:37:38 +0000 (14:37 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 30 Mar 2021 12:37:38 +0000 (14:37 +0200)
commit60081862a8272fb021d4f4b85ee83eafe048f8f0
tree5725cf542e178e794812541904e699de8f4f21cd
parenteaecd329a56ccbc8158a20a75dcb486d07a412d6
public: add RING_COPY_RESPONSE()

Using RING_GET_RESPONSE() on a shared ring is easy to use incorrectly
(i.e., by not considering that the other end may alter the data in the
shared ring while it is being inspected). Safe usage of a response
generally requires taking a local copy.

Provide a RING_COPY_RESPONSE() macro to use instead of
RING_GET_RESPONSE() and an open-coded memcpy().  This takes care of
ensuring that the copy is done correctly regardless of any possible
compiler optimizations.

Use a volatile source to prevent the compiler from reordering or
omitting the copy.

This generalizes similar RING_COPY_REQUEST() macro added in 3f20b8def0.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
xen/include/public/io/ring.h