Skip to content

Commit fe8822b

Browse files
committed
Ensure kfpu_begin()/end() are in same scope.
For the variabe defined inside kfpu_begin(). Use kfpu_begin_ctx() for the split init/fini functions. Signed-off-by: Jorgen Lundman <lundman@lundman.net>
1 parent 6b57fe1 commit fe8822b

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

include/os/windows/spl/sys/simd.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ extern uint32_t kfpu_state;
116116
if (NT_SUCCESS(saveStatus)) \
117117
KeRestoreExtendedProcessorState(&SaveState);
118118

119+
#define kfpu_begin_ctx(O) \
120+
(O)->saveStatus = \
121+
KeSaveExtendedProcessorState(kfpu_state, &(O)->SaveState);
122+
123+
#define kfpu_end_ctx(O) \
124+
if (NT_SUCCESS(((O)->saveStatus))) \
125+
KeRestoreExtendedProcessorState(&(O)->SaveState);
126+
119127
/*
120128
* CPUID feature tests for user-space. Linux kernel provides an interface for
121129
* CPU feature testing.

include/sys/zio_checksum.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ typedef struct zio_abd_checksum_data {
6969
fletcher_4_ctx_t *acd_ctx;
7070
zio_cksum_t *acd_zcp;
7171
void *acd_private;
72+
#if defined(_WIN32) && defined(_KERNEL)
73+
NTSTATUS saveStatus;
74+
XSTATE_SAVE SaveState;
75+
#endif
7276
} zio_abd_checksum_data_t;
7377

7478
typedef void zio_abd_checksum_init_t(zio_abd_checksum_data_t *);

module/zcommon/zfs_fletcher.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,14 @@ fletcher_4_native_impl(const void *buf, uint64_t size, zio_cksum_t *zcp)
461461

462462
if (ops->uses_fpu == B_TRUE) {
463463
kfpu_begin();
464-
}
465-
ops->init_native(&ctx);
466-
ops->compute_native(&ctx, buf, size);
467-
ops->fini_native(&ctx, zcp);
468-
if (ops->uses_fpu == B_TRUE) {
464+
ops->init_native(&ctx);
465+
ops->compute_native(&ctx, buf, size);
466+
ops->fini_native(&ctx, zcp);
469467
kfpu_end();
468+
} else {
469+
ops->init_native(&ctx);
470+
ops->compute_native(&ctx, buf, size);
471+
ops->fini_native(&ctx, zcp);
470472
}
471473
}
472474

@@ -509,12 +511,14 @@ fletcher_4_byteswap_impl(const void *buf, uint64_t size, zio_cksum_t *zcp)
509511

510512
if (ops->uses_fpu == B_TRUE) {
511513
kfpu_begin();
512-
}
513-
ops->init_byteswap(&ctx);
514-
ops->compute_byteswap(&ctx, buf, size);
515-
ops->fini_byteswap(&ctx, zcp);
516-
if (ops->uses_fpu == B_TRUE) {
514+
ops->init_byteswap(&ctx);
515+
ops->compute_byteswap(&ctx, buf, size);
516+
ops->fini_byteswap(&ctx, zcp);
517517
kfpu_end();
518+
} else {
519+
ops->init_byteswap(&ctx);
520+
ops->compute_byteswap(&ctx, buf, size);
521+
ops->fini_byteswap(&ctx, zcp);
518522
}
519523
}
520524

@@ -831,7 +835,11 @@ abd_fletcher_4_init(zio_abd_checksum_data_t *cdp)
831835
cdp->acd_private = (void *) ops;
832836

833837
if (ops->uses_fpu == B_TRUE) {
838+
#if defined(_WIN32) && defined(_KERNEL)
839+
kfpu_begin_ctx(cdp);
840+
#else
834841
kfpu_begin();
842+
#endif
835843
}
836844
if (cdp->acd_byteorder == ZIO_CHECKSUM_NATIVE)
837845
ops->init_native(cdp->acd_ctx);
@@ -853,7 +861,11 @@ abd_fletcher_4_fini(zio_abd_checksum_data_t *cdp)
853861
ops->fini_byteswap(cdp->acd_ctx, cdp->acd_zcp);
854862

855863
if (ops->uses_fpu == B_TRUE) {
864+
#if defined(_WIN32) && defined(_KERNEL)
865+
kfpu_end_ctx(cdp);
866+
#else
856867
kfpu_end();
868+
#endif
857869
}
858870
}
859871

0 commit comments

Comments
 (0)