Skip to content

Commit 6e514a7

Browse files
committed
Add capability to log debug to a file.
Change-Id: I6486a678712f88d52cc1b90faaf16ffcdd40db42 Signed-off-by: Steve Linsell <stevenx.linsell@intel.com>
1 parent cdd4d84 commit 6e514a7

14 files changed

Lines changed: 632 additions & 403 deletions

.tools/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ CFLAGS = $(cflags) $(cflags_cc_opt) $(cflags_enable_upstream_driver) \
9696
$(enable_qat_small_pkt_offload) \
9797
$(enable_qat_lenstra_protection) \
9898
$(enable_qat_debug) $(enable_qat_warnings) \
99-
$(enable_qat_mem_debug) $(enable_qat_mem_warnings)
99+
$(enable_qat_mem_debug) $(enable_qat_mem_warnings) \
100+
$(cflags_qat_debug_file)
100101

101102
libqat_la_LDFLAGS = $(QAT_SHARED_LIB_DEPS_LD) \
102103
$(QAT_SHARED_LIB_DEPS_UPSTREAM_DRIVER) \

.tools/Makefile.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ CFLAGS = $(cflags) $(cflags_cc_opt) $(cflags_enable_upstream_driver) \
155155
$(enable_qat_small_pkt_offload) \
156156
$(enable_qat_lenstra_protection) \
157157
$(enable_qat_debug) $(enable_qat_warnings) \
158-
$(enable_qat_mem_debug) $(enable_qat_mem_warnings)
158+
$(enable_qat_mem_debug) $(enable_qat_mem_warnings) \
159+
$(cflags_qat_debug_file)
159160

160161
CPP = @CPP@
161162
CPPFLAGS = @CPPFLAGS@
@@ -244,6 +245,7 @@ cflags_enable_upstream_driver = @cflags_enable_upstream_driver@
244245
cflags_enable_usdm = @cflags_enable_usdm@
245246
cflags_mux = @cflags_mux@
246247
cflags_qat_contig_mem = @cflags_qat_contig_mem@
248+
cflags_qat_debug_file = @cflags_qat_debug_file@
247249
datadir = @datadir@
248250
datarootdir = @datarootdir@
249251
docdir = @docdir@
@@ -309,6 +311,7 @@ with_cc_opt = @with_cc_opt@
309311
with_ld_opt = @with_ld_opt@
310312
with_openssl_dir = @with_openssl_dir@
311313
with_openssl_install_dir = @with_openssl_install_dir@
314+
with_qat_debug_file = @with_qat_debug_file@
312315
with_qat_dir = @with_qat_dir@
313316
with_qat_install_dir = @with_qat_install_dir@
314317
with_usdm_dir = @with_usdm_dir@

.tools/configure

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ QAT_MULTI_THREAD_FALSE
643643
QAT_MULTI_THREAD_TRUE
644644
QAT_CONTIG_MEM_FALSE
645645
QAT_CONTIG_MEM_TRUE
646+
cflags_qat_debug_file
646647
include_enable_usdm
647648
cflags_enable_usdm
648649
cflags_enable_multi_thread
@@ -658,6 +659,7 @@ enable_qat_mux
658659
enable_multi_thread
659660
with_ld_opt
660661
with_cc_opt
662+
with_qat_debug_file
661663
with_usdm_dir
662664
enable_usdm
663665
enable_upstream_driver
@@ -814,6 +816,7 @@ with_qat_install_dir
814816
enable_upstream_driver
815817
enable_usdm
816818
with_usdm_dir
819+
with_qat_debug_file
817820
with_cc_opt
818821
with_ld_opt
819822
enable_multi_thread
@@ -829,6 +832,7 @@ with_cflags_qat_contig_mem
829832
with_cflags_enable_multi_thread
830833
with_cflags_enable_usdm
831834
with_includes_enable_usdm
835+
with_cflags_qat_debug_file
832836
with_ICP_API_DIR
833837
with_ICP_SAL_API_DIR
834838
with_ICP_LAC_API_DIR
@@ -1540,6 +1544,9 @@ Optional Packages:
15401544
be used to specify a path other than the standard
15411545
default path within the Upstream Intel Quickassist
15421546
Technology Driver source code
1547+
--with-qat_debug_file Path and filename to log debug output to. Combine
1548+
with other flags that enable the debug and warning
1549+
output
15431550
--with-cc_opt Sets additional parameters that will be added to the
15441551
CFLAGS
15451552
--with-ld_opt Sets additional parameters that will be used during
@@ -11566,6 +11573,14 @@ fi
1156611573

1156711574

1156811575

11576+
# Check whether --with-qat_debug_file was given.
11577+
if test "${with_qat_debug_file+set}" = set; then :
11578+
withval=$with_qat_debug_file;
11579+
fi
11580+
11581+
11582+
11583+
1156911584
# Check whether --with-cc_opt was given.
1157011585
if test "${with_cc_opt+set}" = set; then :
1157111586
withval=$with_cc_opt;
@@ -11907,6 +11922,22 @@ fi
1190711922
fi
1190811923
fi
1190911924

11925+
if test "x$with_qat_debug_file" != "x"
11926+
then
11927+
11928+
# Check whether --with-cflags_qat_debug_file was given.
11929+
if test "${with_cflags_qat_debug_file+set}" = set; then :
11930+
withval=$with_cflags_qat_debug_file;
11931+
else
11932+
cflags_qat_debug_file="-DQAT_DEBUG_FILE_PATH=\$(with_qat_debug_file)"
11933+
fi
11934+
11935+
11936+
{ $as_echo "$as_me:${as_lineno-$LINENO}: Enabling writing debug to file" >&5
11937+
$as_echo "$as_me: Enabling writing debug to file" >&6;}
11938+
fi
11939+
11940+
1191011941
if test "x$enable_usdm" != "xyes" -a "x$enable_multi_thread" != "xyes"; then
1191111942
QAT_CONTIG_MEM_TRUE=
1191211943
QAT_CONTIG_MEM_FALSE='#'

.tools/configure.ac

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ AC_ARG_WITH(usdm_dir,
126126
[Path to the USDM Component source code. This should be used to specify a path other than the standard default path within the Upstream Intel Quickassist Technology Driver source code]))
127127
AC_SUBST(with_usdm_dir)
128128

129+
AC_ARG_WITH(qat_debug_file,
130+
AS_HELP_STRING([--with-qat_debug_file],
131+
[Path and filename to log debug output to. Combine with other flags that enable the debug and warning output]))
132+
AC_SUBST(with_qat_debug_file)
133+
129134
AC_ARG_WITH(cc_opt,
130135
AS_HELP_STRING([--with-cc_opt],
131136
[Sets additional parameters that will be added to the CFLAGS]))
@@ -366,6 +371,14 @@ fi
366371
fi
367372
fi
368373

374+
if test "x$with_qat_debug_file" != "x"
375+
then
376+
AC_ARG_WITH(cflags_qat_debug_file, AS_HELP_STRING(), , cflags_qat_debug_file="-DQAT_DEBUG_FILE_PATH=\$(with_qat_debug_file)")
377+
AC_SUBST(cflags_qat_debug_file)
378+
AC_MSG_NOTICE([Enabling writing debug to file])
379+
fi
380+
381+
369382
AM_CONDITIONAL([QAT_CONTIG_MEM], [test "x$enable_usdm" != "xyes" -a "x$enable_multi_thread" != "xyes"])
370383
AM_CONDITIONAL([QAT_MULTI_THREAD], [test "x$enable_usdm" != "xyes" -a "x$enable_multi_thread" = "xyes"])
371384
AM_CONDITIONAL([QAE_MEM], [test "x$enable_usdm" = "xyes"])

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,23 @@ Optional
840840
console/logs and may also introduce side channel timing attack
841841
vulnerabilities (disabled by default).
842842
843+
--with-qat_debug_file=/file/and/path/to/log/qat/debug/to
844+
This option turns on logging to a file instead of to stderr. It works with
845+
any combination of the following flags:
846+
--enable-qat_warnings
847+
--enable-qat_debug
848+
--enable-qat_mem_warnings
849+
--enable-qat_mem_debug
850+
The option should specify the full absolute path and filename that you would
851+
like to log to. The directory needs to be writable by the user the process
852+
is running as, and the log file can get very big, very quickly.
853+
The existing log file will be replaced rather than appended to on each run
854+
of the application. If the file cannot be opened for writing then the
855+
logging will default to output to stderr.
856+
As with the other logging options this option should never be enabled in a
857+
production environment as private key information and plaintext data will
858+
be logged to the file (logging to file is disabled by default).
859+
843860
--disable-multi_thread/--enable-multi_thread
844861
Disable/Enable an alternative way of managing within userspace the pinned
845862
contiguous memory allocated by the qat_contig_mem driver. This alternative

cmn_mem_drv_inf.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,33 @@
5151
# include <pthread.h>
5252
# include "cpa.h"
5353

54+
extern FILE* qatDebugLogFile;
5455

5556
#ifdef QAT_MEM_DEBUG
56-
# define MEM_DEBUG(fmt_str, ...) \
57-
fprintf(stderr, "[MEM_DEBUG][%s:%d:%s()] "fmt_str, __FILE__, __LINE__, \
58-
__func__, ##__VA_ARGS__)
57+
# define MEM_DEBUG(fmt_str, ..) \
58+
do { \
59+
fprintf(qatDebugLogFile,"[MEM_DEBUG][%s:%d:%s()] "fmt_str, \
60+
__FILE__, __LINE__, __func__, ##__VA_ARGS__); \
61+
fflush(qatDebugLogFile); \
62+
} while(0)
5963
#else
6064
# define MEM_DEBUG(...)
6165
#endif
6266

63-
# define MEM_ERROR(fmt_str, ...) \
64-
fprintf(stderr, "[MEM_ERROR][%s:%d:%s()] "fmt_str, __FILE__, __LINE__, \
65-
__func__, ##__VA_ARGS__)
67+
# define MEM_ERROR(fmt_str, ...) \
68+
do { \
69+
fprintf(qatDebugLogFile,"[MEM_ERROR][%s:%d:%s()] "fmt_str, \
70+
__FILE__, __LINE__, __func__, ##__VA_ARGS__); \
71+
fflush(qatDebugLogFile); \
72+
} while(0)
6673

6774
#if defined(QAT_MEM_WARN) || defined(QAT_MEM_DEBUG)
68-
# define MEM_WARN(fmt_str, ...) \
69-
fprintf(stderr, "[MEM_WARN][%s:%d:%s()] "fmt_str, __FILE__, __LINE__, \
70-
__func__, ##__VA_ARGS__)
75+
# define MEM_WARN(fmt_str, ...) \
76+
do { \
77+
fprintf(qatDebugLogFile,"[MEM_WARN][%s:%d:%s()] "fmt_str, \
78+
__FILE__, __LINE__, __func__, ##__VA_ARGS__); \
79+
fflush(qatDebugLogFile); \
80+
} while(0)
7181
#else
7282
# define MEM_WARN(...)
7383
#endif

configure

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ QAT_MULTI_THREAD_FALSE
643643
QAT_MULTI_THREAD_TRUE
644644
QAT_CONTIG_MEM_FALSE
645645
QAT_CONTIG_MEM_TRUE
646+
cflags_qat_debug_file
646647
include_enable_usdm
647648
cflags_enable_usdm
648649
cflags_enable_multi_thread
@@ -658,6 +659,7 @@ enable_qat_mux
658659
enable_multi_thread
659660
with_ld_opt
660661
with_cc_opt
662+
with_qat_debug_file
661663
with_usdm_dir
662664
enable_usdm
663665
enable_upstream_driver
@@ -814,6 +816,7 @@ with_qat_install_dir
814816
enable_upstream_driver
815817
enable_usdm
816818
with_usdm_dir
819+
with_qat_debug_file
817820
with_cc_opt
818821
with_ld_opt
819822
enable_multi_thread
@@ -829,6 +832,7 @@ with_cflags_qat_contig_mem
829832
with_cflags_enable_multi_thread
830833
with_cflags_enable_usdm
831834
with_includes_enable_usdm
835+
with_cflags_qat_debug_file
832836
with_ICP_API_DIR
833837
with_ICP_SAL_API_DIR
834838
with_ICP_LAC_API_DIR
@@ -1540,6 +1544,9 @@ Optional Packages:
15401544
be used to specify a path other than the standard
15411545
default path within the Upstream Intel Quickassist
15421546
Technology Driver source code
1547+
--with-qat_debug_file Path and filename to log debug output to. Combine
1548+
with other flags that enable the debug and warning
1549+
output
15431550
--with-cc_opt Sets additional parameters that will be added to the
15441551
CFLAGS
15451552
--with-ld_opt Sets additional parameters that will be used during
@@ -11566,6 +11573,14 @@ fi
1156611573

1156711574

1156811575

11576+
# Check whether --with-qat_debug_file was given.
11577+
if test "${with_qat_debug_file+set}" = set; then :
11578+
withval=$with_qat_debug_file;
11579+
fi
11580+
11581+
11582+
11583+
1156911584
# Check whether --with-cc_opt was given.
1157011585
if test "${with_cc_opt+set}" = set; then :
1157111586
withval=$with_cc_opt;
@@ -11907,6 +11922,22 @@ fi
1190711922
fi
1190811923
fi
1190911924

11925+
if test "x$with_qat_debug_file" != "x"
11926+
then
11927+
11928+
# Check whether --with-cflags_qat_debug_file was given.
11929+
if test "${with_cflags_qat_debug_file+set}" = set; then :
11930+
withval=$with_cflags_qat_debug_file;
11931+
else
11932+
cflags_qat_debug_file="-DQAT_DEBUG_FILE_PATH=\$(with_qat_debug_file)"
11933+
fi
11934+
11935+
11936+
{ $as_echo "$as_me:${as_lineno-$LINENO}: Enabling writing debug to file" >&5
11937+
$as_echo "$as_me: Enabling writing debug to file" >&6;}
11938+
fi
11939+
11940+
1191011941
if test "x$enable_usdm" != "xyes" -a "x$enable_multi_thread" != "xyes"; then
1191111942
QAT_CONTIG_MEM_TRUE=
1191211943
QAT_CONTIG_MEM_FALSE='#'

e_qat.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ static int qat_engine_destroy(ENGINE *e)
803803
qat_free_DH_methods();
804804
qat_free_DSA_methods();
805805
qat_free_RSA_methods();
806+
QAT_DEBUG_LOG_CLOSE();
806807
ERR_unload_QAT_strings();
807808
return 1;
808809
}
@@ -826,6 +827,8 @@ static int bind_qat(ENGINE *e, const char *id)
826827
unsigned int devmasks[] = { 0, 0, 0, 0, 0 };
827828
#endif
828829

830+
QAT_DEBUG_LOG_INIT();
831+
829832
WARN("QAT Warnings enabled.\n");
830833
DEBUG("QAT Debug enabled.\n");
831834
DEBUG("id=%s\n", id);
@@ -956,12 +959,14 @@ static ENGINE *engine_qat(void)
956959

957960
void ENGINE_load_qat(void)
958961
{
959-
ENGINE *toadd = engine_qat();
962+
ENGINE *toadd;
960963
int error = 0;
961964
char error_string[QAT_MAX_ERROR_STRING] = { 0 };
962965

966+
QAT_DEBUG_LOG_INIT();
963967
DEBUG("- Starting\n");
964968

969+
toadd = engine_qat();
965970
if (toadd == NULL) {
966971
error = ERR_peek_error();
967972
ERR_error_string_n(error, error_string, QAT_MAX_ERROR_STRING);

e_qat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
# include <openssl/engine.h>
5050
# include <sys/types.h>
5151
# include <unistd.h>
52+
# include <string.h>
5253

5354
# include "cpa.h"
5455
# include "cpa_types.h"
@@ -65,6 +66,9 @@
6566
#define likely(x) __builtin_expect (!!(x), 1)
6667
#define unlikely(x) __builtin_expect (!!(x), 0)
6768

69+
#define XSTR(x) #x
70+
#define STR(x) XSTR(x)
71+
6872
/* Macro used to handle errors in qat_engine_ctrl() */
6973
#define BREAK_IF(cond, mesg) \
7074
if(unlikely(cond)) { retVal = 0; WARN(mesg); break; }

qae_mem_utils.h

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,33 @@
6161

6262
# define QAE_BYTE_ALIGNMENT 0x0040/* 64 bytes */
6363

64+
extern FILE* qatDebugLogFile;
65+
6466
#ifdef QAT_MEM_DEBUG
65-
# define MEM_DEBUG(fmt_str, ...) \
66-
fprintf(stderr, "[MEM_DEBUG][%s:%d:%s()] "fmt_str, __FILE__, __LINE__, \
67-
__func__, ##__VA_ARGS__)
67+
# define MEM_DEBUG(fmt_str, ...) \
68+
do { \
69+
fprintf(qatDebugLogFile,"[MEM_DEBUG][%s:%d:%s()] "fmt_str, \
70+
__FILE__, __LINE__, __func__, ##__VA_ARGS__); \
71+
fflush(qatDebugLogFile); \
72+
} while(0)
6873
#else
6974
# define MEM_DEBUG(...)
7075
#endif
7176

72-
# define MEM_ERROR(fmt_str, ...) \
73-
fprintf(stderr, "[MEM_ERROR][%s:%d:%s()] "fmt_str, __FILE__, __LINE__, \
74-
__func__, ##__VA_ARGS__)
77+
# define MEM_ERROR(fmt_str, ...) \
78+
do { \
79+
fprintf(qatDebugLogFile,"[MEM_ERROR][%s:%d:%s()] "fmt_str, \
80+
__FILE__, __LINE__, __func__, ##__VA_ARGS__); \
81+
fflush(qatDebugLogFile); \
82+
} while(0)
7583

7684
#if defined(QAT_MEM_WARN) || defined(QAT_MEM_DEBUG)
77-
# define MEM_WARN(fmt_str, ...) \
78-
fprintf(stderr, "[MEM_WARN][%s:%d:%s()] "fmt_str, __FILE__, __LINE__, \
79-
__func__, ##__VA_ARGS__)
85+
# define MEM_WARN(fmt_str, ...) \
86+
do { \
87+
fprintf(qatDebugLogFile,"[MEM_WARN][%s:%d:%s()] "fmt_str, \
88+
__FILE__, __LINE__, __func__, ##__VA_ARGS__); \
89+
fflush(qatDebugLogFile); \
90+
} while(0)
8091
#else
8192
# define MEM_WARN(...)
8293
#endif

0 commit comments

Comments
 (0)