OSDN Git Service

arm64/sve: Avoid dereference of dead task_struct in KVM guest entry
authorDave Martin <Dave.Martin@arm.com>
Wed, 6 Dec 2017 16:45:47 +0000 (16:45 +0000)
committerWill Deacon <will.deacon@arm.com>
Wed, 6 Dec 2017 19:08:05 +0000 (19:08 +0000)
commitcb968afc789821cdf9e17e79ef08ab90e5bae0f2
treebfebdce5e2dd33cc1c05aa9dbd574bd8cc933b6b
parentd96cc49bff5a7735576cc6f6f111f875d101cec8
arm64/sve: Avoid dereference of dead task_struct in KVM guest entry

When deciding whether to invalidate FPSIMD state cached in the cpu,
the backend function sve_flush_cpu_state() attempts to dereference
__this_cpu_read(fpsimd_last_state).  However, this is not safe:
there is no guarantee that this task_struct pointer is still valid,
because the task could have exited in the meantime.

This means that we need another means to get the appropriate value
of TIF_SVE for the associated task.

This patch solves this issue by adding a cached copy of the TIF_SVE
flag in fpsimd_last_state, which we can check without dereferencing
the task pointer.

In particular, although this patch is not a KVM fix per se, this
means that this check is now done safely in the KVM world switch
path (which is currently the only user of this code).

Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Christoffer Dall <christoffer.dall@linaro.org>
Cc: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
arch/arm64/kernel/fpsimd.c