Skip to content

Commit

Permalink
Code improvement and bug fixes for QAT support
Browse files Browse the repository at this point in the history
1. Support QAT when ZFS is root file-system:
   When ZFS module is loaded before QAT started, the QAT can
   be started again in post-process, e.g.:
   echo 0 > /sys/module/zfs/parameters/zfs_qat_compress_disable
   echo 0 > /sys/module/zfs/parameters/zfs_qat_encrypt_disable
   echo 0 > /sys/module/zfs/parameters/zfs_qat_checksum_disable
2. Verify alder checksum of the de-compress result
3. Allocate Digest, IV and AAD buffer in physical contiguous
   memory by QAT_PHYS_CONTIG_ALLOC.
4. Update the documentation for zfs_qat_compress_disable,
   zfs_qat_checksum_disable, zfs_qat_encrypt_disable.

Reviewed-by: Tom Caputi <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Weigang Li <[email protected]>
Signed-off-by: Chengfeix Zhu <[email protected]>
Closes openzfs#8323 
Closes openzfs#8610
  • Loading branch information
cfzhux authored and behlendorf committed Apr 16, 2019
1 parent 59f6594 commit 5090f72
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 51 deletions.
52 changes: 39 additions & 13 deletions man/man5/zfs-module-parameters.5
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,45 @@ can't hurt performance.
Use \fB1\fR for yes and \fB0\fR for no (default).
.RE

.sp
.ne 2
.na
\fBzfs_qat_checksum_disable\fR (int)
.ad
.RS 12n
This tunable disables qat hardware acceleration for sha256 checksums. It
may be set after the zfs modules have been loaded to initialize the qat
hardware as long as support is compiled in and the qat driver is present.
.sp
Use \fB1\fR for yes and \fB0\fR for no (default).
.RE

.sp
.ne 2
.na
\fBzfs_qat_compress_disable\fR (int)
.ad
.RS 12n
This tunable disables qat hardware acceleration for gzip compression. It
may be set after the zfs modules have been loaded to initialize the qat
hardware as long as support is compiled in and the qat driver is present.
.sp
Use \fB1\fR for yes and \fB0\fR for no (default).
.RE

.sp
.ne 2
.na
\fBzfs_qat_encrypt_disable\fR (int)
.ad
.RS 12n
This tunable disables qat hardware acceleration for AES-GCM encryption. It
may be set after the zfs modules have been loaded to initialize the qat
hardware as long as support is compiled in and the qat driver is present.
.sp
Use \fB1\fR for yes and \fB0\fR for no (default).
.RE

.sp
.ne 2
.na
Expand Down Expand Up @@ -2961,19 +3000,6 @@ Valid values are \fB1\fR (full), \fB2\fR (dev) and \fB3\fR (none).
Default value: \fB1\fR.
.RE

.sp
.ne 2
.na
\fBzfs_qat_disable\fR (int)
.ad
.RS 12n
This tunable disables qat hardware acceleration for gzip compression and.
AES-GCM encryption. It is available only if qat acceleration is compiled in
and the qat driver is present.
.sp
Use \fB1\fR for yes and \fB0\fR for no (default).
.RE

.SH ZFS I/O SCHEDULER
ZFS issues I/O operations to leaf vdevs to satisfy and complete I/Os.
The I/O scheduler determines when and in what order those operations are
Expand Down
27 changes: 14 additions & 13 deletions module/zfs/qat.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,6 @@ qat_mem_free_contig(void **pp_mem_addr)
int
qat_init(void)
{
int ret;

ret = qat_dc_init();
if (ret != 0)
return (ret);

ret = qat_crypt_init();
if (ret != 0) {
qat_dc_fini();
return (ret);
}

qat_ksp = kstat_create("zfs", 0, "qat", "misc",
KSTAT_TYPE_NAMED, sizeof (qat_stats) / sizeof (kstat_named_t),
KSTAT_FLAG_VIRTUAL);
Expand All @@ -86,6 +74,19 @@ qat_init(void)
kstat_install(qat_ksp);
}

/*
* Just set the disable flag when qat init failed, qat can be
* turned on again in post-process after zfs module is loaded, e.g.:
* echo 0 > /sys/module/zfs/parameters/zfs_qat_compress_disable
*/
if (qat_dc_init() != 0)
zfs_qat_compress_disable = 1;

if (qat_cy_init() != 0) {
zfs_qat_checksum_disable = 1;
zfs_qat_encrypt_disable = 1;
}

return (0);
}

Expand All @@ -97,7 +98,7 @@ qat_fini(void)
qat_ksp = NULL;
}

qat_crypt_fini();
qat_cy_fini();
qat_dc_fini();
}

Expand Down
7 changes: 5 additions & 2 deletions module/zfs/qat.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ typedef struct qat_stats {
QAT_STAT_INCR(stat, 1)

extern qat_stats_t qat_stats;
extern int zfs_qat_compress_disable;
extern int zfs_qat_checksum_disable;
extern int zfs_qat_encrypt_disable;

/* inlined for performance */
static inline struct page *
Expand All @@ -167,8 +170,8 @@ void qat_mem_free_contig(void **pp_mem_addr);

extern int qat_dc_init(void);
extern void qat_dc_fini(void);
extern int qat_crypt_init(void);
extern void qat_crypt_fini(void);
extern int qat_cy_init(void);
extern void qat_cy_fini(void);
extern int qat_init(void);
extern void qat_fini(void);

Expand Down
39 changes: 37 additions & 2 deletions module/zfs/qat_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#include <linux/vmalloc.h>
#include <linux/pagemap.h>
#include <linux/completion.h>
#include <linux/mod_compat.h>
#include <sys/zfs_context.h>
#include <sys/byteorder.h>
#include <sys/zio.h>
#include "qat.h"

Expand Down Expand Up @@ -111,6 +113,9 @@ qat_dc_init(void)
Cpa32U buff_meta_size = 0;
CpaDcSessionSetupData sd = {0};

if (qat_dc_init_done)
return (0);

status = cpaDcGetNumInstances(&num_inst);
if (status != CPA_STATUS_SUCCESS)
return (-1);
Expand Down Expand Up @@ -252,6 +257,7 @@ qat_compress_impl(qat_compress_dir_t dir, char *src, int src_len,
Cpa32U num_add_buf = (add_len >> PAGE_SHIFT) + 2;
Cpa32U bytes_left;
Cpa32U dst_pages = 0;
Cpa32U adler32 = 0;
char *data;
struct page *page;
struct page **in_pages = NULL;
Expand Down Expand Up @@ -468,6 +474,12 @@ qat_compress_impl(qat_compress_dir_t dir, char *src, int src_len,
goto fail;
}

/* verify adler checksum */
adler32 = *(Cpa32U *)(src + dc_results.consumed + ZLIB_HEAD_SZ);
if (adler32 != BSWAP_32(dc_results.checksum)) {
status = CPA_STATUS_FAIL;
goto fail;
}
*c_len = dc_results.produced;
QAT_STAT_INCR(decomp_total_out_bytes, *c_len);
}
Expand Down Expand Up @@ -534,7 +546,30 @@ qat_compress(qat_compress_dir_t dir, char *src, int src_len,
return (ret);
}

module_param(zfs_qat_compress_disable, int, 0644);
MODULE_PARM_DESC(zfs_qat_compress_disable, "Disable QAT compression");
static int
param_set_qat_compress(const char *val, struct kernel_param *kp)
{
int ret;
int *pvalue = kp->arg;
ret = param_set_int(val, kp);
if (ret)
return (ret);
/*
* zfs_qat_compress_disable = 0: enable qat compress
* try to initialize qat instance if it has not been done
*/
if (*pvalue == 0 && !qat_dc_init_done) {
ret = qat_dc_init();
if (ret != 0) {
zfs_qat_compress_disable = 1;
return (ret);
}
}
return (ret);
}

module_param_call(zfs_qat_compress_disable, param_set_qat_compress,
param_get_int, &zfs_qat_compress_disable, 0644);
MODULE_PARM_DESC(zfs_qat_compress_disable, "Enable/Disable QAT compression");

#endif
Loading

0 comments on commit 5090f72

Please sign in to comment.