[PATCH 3.2 23/70] xen-blkback: only read request operation from shared ring once

Ben Hutchings
2016-01-18T03:24:56Z

From: Roger Pau Monné <roger.pau@citrix.com>

commit 1f13d75ccb806260079e0679d55d9253e370ec8a upstream.

A compiler may load a switch statement value multiple times, which could
be bad when the value is in memory shared with the frontend.

When converting a non-native request to a native one, ensure that
src->operation is only loaded once by using READ_ONCE().

This is part of XSA155.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
[bwh: Backported to 3.2:
- s/READ_ONCE/ACCESS_ONCE/
- Adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
drivers/block/xen-blkback/common.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

--- a/drivers/block/xen-blkback/common.h
+++ b/drivers/block/xen-blkback/common.h
@@ -238,11 +238,11 @@ static inline void blkif_get_x86_32_req(
struct blkif_x86_32_request *src)
{
int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST;
- dst->operation = src->operation;
+ dst->operation = ACCESS_ONCE(src->operation);
dst->nr_segments = src->nr_segments;
dst->handle = src->handle;
dst->id = src->id;
- switch (src->operation) {
+ switch (dst->operation) {
case BLKIF_OP_READ:
case BLKIF_OP_WRITE:
case BLKIF_OP_WRITE_BARRIER:
@@ -267,11 +267,11 @@ static inline void blkif_get_x86_64_req(
struct blkif_x86_64_request *src)
{
int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST;
- dst->operation = src->operation;
+ dst->operation = ACCESS_ONCE(src->operation);
dst->nr_segments = src->nr_segments;
dst->handle = src->handle;
dst->id = src->id;
- switch (src->operation) {
+ switch (dst->operation) {