Skip to content

Commit

Permalink
Add capability to log debug to a file.
Browse files Browse the repository at this point in the history
Change-Id: I6486a678712f88d52cc1b90faaf16ffcdd40db42
Signed-off-by: Steve Linsell <stevenx.linsell@intel.com>
  • Loading branch information
stevelinsell committed Aug 9, 2017
1 parent cdd4d84 commit 6e514a7
Show file tree
Hide file tree
Showing 14 changed files with 632 additions and 403 deletions.
3 changes: 2 additions & 1 deletion .tools/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ CFLAGS = $(cflags) $(cflags_cc_opt) $(cflags_enable_upstream_driver) \
$(enable_qat_small_pkt_offload) \
$(enable_qat_lenstra_protection) \
$(enable_qat_debug) $(enable_qat_warnings) \
$(enable_qat_mem_debug) $(enable_qat_mem_warnings)
$(enable_qat_mem_debug) $(enable_qat_mem_warnings) \
$(cflags_qat_debug_file)

libqat_la_LDFLAGS = $(QAT_SHARED_LIB_DEPS_LD) \
$(QAT_SHARED_LIB_DEPS_UPSTREAM_DRIVER) \
Expand Down
5 changes: 4 additions & 1 deletion .tools/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ CFLAGS = $(cflags) $(cflags_cc_opt) $(cflags_enable_upstream_driver) \
$(enable_qat_small_pkt_offload) \
$(enable_qat_lenstra_protection) \
$(enable_qat_debug) $(enable_qat_warnings) \
$(enable_qat_mem_debug) $(enable_qat_mem_warnings)
$(enable_qat_mem_debug) $(enable_qat_mem_warnings) \
$(cflags_qat_debug_file)

CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
Expand Down Expand Up @@ -244,6 +245,7 @@ cflags_enable_upstream_driver = @cflags_enable_upstream_driver@
cflags_enable_usdm = @cflags_enable_usdm@
cflags_mux = @cflags_mux@
cflags_qat_contig_mem = @cflags_qat_contig_mem@
cflags_qat_debug_file = @cflags_qat_debug_file@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
Expand Down Expand Up @@ -309,6 +311,7 @@ with_cc_opt = @with_cc_opt@
with_ld_opt = @with_ld_opt@
with_openssl_dir = @with_openssl_dir@
with_openssl_install_dir = @with_openssl_install_dir@
with_qat_debug_file = @with_qat_debug_file@
with_qat_dir = @with_qat_dir@
with_qat_install_dir = @with_qat_install_dir@
with_usdm_dir = @with_usdm_dir@
Expand Down
31 changes: 31 additions & 0 deletions .tools/configure
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ QAT_MULTI_THREAD_FALSE
QAT_MULTI_THREAD_TRUE
QAT_CONTIG_MEM_FALSE
QAT_CONTIG_MEM_TRUE
cflags_qat_debug_file
include_enable_usdm
cflags_enable_usdm
cflags_enable_multi_thread
Expand All @@ -658,6 +659,7 @@ enable_qat_mux
enable_multi_thread
with_ld_opt
with_cc_opt
with_qat_debug_file
with_usdm_dir
enable_usdm
enable_upstream_driver
Expand Down Expand Up @@ -814,6 +816,7 @@ with_qat_install_dir
enable_upstream_driver
enable_usdm
with_usdm_dir
with_qat_debug_file
with_cc_opt
with_ld_opt
enable_multi_thread
Expand All @@ -829,6 +832,7 @@ with_cflags_qat_contig_mem
with_cflags_enable_multi_thread
with_cflags_enable_usdm
with_includes_enable_usdm
with_cflags_qat_debug_file
with_ICP_API_DIR
with_ICP_SAL_API_DIR
with_ICP_LAC_API_DIR
Expand Down Expand Up @@ -1540,6 +1544,9 @@ Optional Packages:
be used to specify a path other than the standard
default path within the Upstream Intel Quickassist
Technology Driver source code
--with-qat_debug_file Path and filename to log debug output to. Combine
with other flags that enable the debug and warning
output
--with-cc_opt Sets additional parameters that will be added to the
CFLAGS
--with-ld_opt Sets additional parameters that will be used during
Expand Down Expand Up @@ -11566,6 +11573,14 @@ fi



# Check whether --with-qat_debug_file was given.
if test "${with_qat_debug_file+set}" = set; then :
withval=$with_qat_debug_file;
fi




# Check whether --with-cc_opt was given.
if test "${with_cc_opt+set}" = set; then :
withval=$with_cc_opt;
Expand Down Expand Up @@ -11907,6 +11922,22 @@ fi
fi
fi

if test "x$with_qat_debug_file" != "x"
then

# Check whether --with-cflags_qat_debug_file was given.
if test "${with_cflags_qat_debug_file+set}" = set; then :
withval=$with_cflags_qat_debug_file;
else
cflags_qat_debug_file="-DQAT_DEBUG_FILE_PATH=\$(with_qat_debug_file)"
fi


{ $as_echo "$as_me:${as_lineno-$LINENO}: Enabling writing debug to file" >&5
$as_echo "$as_me: Enabling writing debug to file" >&6;}
fi


if test "x$enable_usdm" != "xyes" -a "x$enable_multi_thread" != "xyes"; then
QAT_CONTIG_MEM_TRUE=
QAT_CONTIG_MEM_FALSE='#'
Expand Down
13 changes: 13 additions & 0 deletions .tools/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ AC_ARG_WITH(usdm_dir,
[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]))
AC_SUBST(with_usdm_dir)

AC_ARG_WITH(qat_debug_file,
AS_HELP_STRING([--with-qat_debug_file],
[Path and filename to log debug output to. Combine with other flags that enable the debug and warning output]))
AC_SUBST(with_qat_debug_file)

AC_ARG_WITH(cc_opt,
AS_HELP_STRING([--with-cc_opt],
[Sets additional parameters that will be added to the CFLAGS]))
Expand Down Expand Up @@ -366,6 +371,14 @@ fi
fi
fi

if test "x$with_qat_debug_file" != "x"
then
AC_ARG_WITH(cflags_qat_debug_file, AS_HELP_STRING(), , cflags_qat_debug_file="-DQAT_DEBUG_FILE_PATH=\$(with_qat_debug_file)")
AC_SUBST(cflags_qat_debug_file)
AC_MSG_NOTICE([Enabling writing debug to file])
fi


AM_CONDITIONAL([QAT_CONTIG_MEM], [test "x$enable_usdm" != "xyes" -a "x$enable_multi_thread" != "xyes"])
AM_CONDITIONAL([QAT_MULTI_THREAD], [test "x$enable_usdm" != "xyes" -a "x$enable_multi_thread" = "xyes"])
AM_CONDITIONAL([QAE_MEM], [test "x$enable_usdm" = "xyes"])
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,23 @@ Optional
console/logs and may also introduce side channel timing attack
vulnerabilities (disabled by default).
--with-qat_debug_file=/file/and/path/to/log/qat/debug/to
This option turns on logging to a file instead of to stderr. It works with
any combination of the following flags:
--enable-qat_warnings
--enable-qat_debug
--enable-qat_mem_warnings
--enable-qat_mem_debug
The option should specify the full absolute path and filename that you would
like to log to. The directory needs to be writable by the user the process
is running as, and the log file can get very big, very quickly.
The existing log file will be replaced rather than appended to on each run
of the application. If the file cannot be opened for writing then the
logging will default to output to stderr.
As with the other logging options this option should never be enabled in a
production environment as private key information and plaintext data will
be logged to the file (logging to file is disabled by default).
--disable-multi_thread/--enable-multi_thread
Disable/Enable an alternative way of managing within userspace the pinned
contiguous memory allocated by the qat_contig_mem driver. This alternative
Expand Down
28 changes: 19 additions & 9 deletions cmn_mem_drv_inf.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,33 @@
# include <pthread.h>
# include "cpa.h"

extern FILE* qatDebugLogFile;

#ifdef QAT_MEM_DEBUG
# define MEM_DEBUG(fmt_str, ...) \
fprintf(stderr, "[MEM_DEBUG][%s:%d:%s()] "fmt_str, __FILE__, __LINE__, \
__func__, ##__VA_ARGS__)
# define MEM_DEBUG(fmt_str, ..) \
do { \
fprintf(qatDebugLogFile,"[MEM_DEBUG][%s:%d:%s()] "fmt_str, \
__FILE__, __LINE__, __func__, ##__VA_ARGS__); \
fflush(qatDebugLogFile); \
} while(0)
#else
# define MEM_DEBUG(...)
#endif

# define MEM_ERROR(fmt_str, ...) \
fprintf(stderr, "[MEM_ERROR][%s:%d:%s()] "fmt_str, __FILE__, __LINE__, \
__func__, ##__VA_ARGS__)
# define MEM_ERROR(fmt_str, ...) \
do { \
fprintf(qatDebugLogFile,"[MEM_ERROR][%s:%d:%s()] "fmt_str, \
__FILE__, __LINE__, __func__, ##__VA_ARGS__); \
fflush(qatDebugLogFile); \
} while(0)

#if defined(QAT_MEM_WARN) || defined(QAT_MEM_DEBUG)
# define MEM_WARN(fmt_str, ...) \
fprintf(stderr, "[MEM_WARN][%s:%d:%s()] "fmt_str, __FILE__, __LINE__, \
__func__, ##__VA_ARGS__)
# define MEM_WARN(fmt_str, ...) \
do { \
fprintf(qatDebugLogFile,"[MEM_WARN][%s:%d:%s()] "fmt_str, \
__FILE__, __LINE__, __func__, ##__VA_ARGS__); \
fflush(qatDebugLogFile); \
} while(0)
#else
# define MEM_WARN(...)
#endif
Expand Down
31 changes: 31 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ QAT_MULTI_THREAD_FALSE
QAT_MULTI_THREAD_TRUE
QAT_CONTIG_MEM_FALSE
QAT_CONTIG_MEM_TRUE
cflags_qat_debug_file
include_enable_usdm
cflags_enable_usdm
cflags_enable_multi_thread
Expand All @@ -658,6 +659,7 @@ enable_qat_mux
enable_multi_thread
with_ld_opt
with_cc_opt
with_qat_debug_file
with_usdm_dir
enable_usdm
enable_upstream_driver
Expand Down Expand Up @@ -814,6 +816,7 @@ with_qat_install_dir
enable_upstream_driver
enable_usdm
with_usdm_dir
with_qat_debug_file
with_cc_opt
with_ld_opt
enable_multi_thread
Expand All @@ -829,6 +832,7 @@ with_cflags_qat_contig_mem
with_cflags_enable_multi_thread
with_cflags_enable_usdm
with_includes_enable_usdm
with_cflags_qat_debug_file
with_ICP_API_DIR
with_ICP_SAL_API_DIR
with_ICP_LAC_API_DIR
Expand Down Expand Up @@ -1540,6 +1544,9 @@ Optional Packages:
be used to specify a path other than the standard
default path within the Upstream Intel Quickassist
Technology Driver source code
--with-qat_debug_file Path and filename to log debug output to. Combine
with other flags that enable the debug and warning
output
--with-cc_opt Sets additional parameters that will be added to the
CFLAGS
--with-ld_opt Sets additional parameters that will be used during
Expand Down Expand Up @@ -11566,6 +11573,14 @@ fi



# Check whether --with-qat_debug_file was given.
if test "${with_qat_debug_file+set}" = set; then :
withval=$with_qat_debug_file;
fi




# Check whether --with-cc_opt was given.
if test "${with_cc_opt+set}" = set; then :
withval=$with_cc_opt;
Expand Down Expand Up @@ -11907,6 +11922,22 @@ fi
fi
fi

if test "x$with_qat_debug_file" != "x"
then

# Check whether --with-cflags_qat_debug_file was given.
if test "${with_cflags_qat_debug_file+set}" = set; then :
withval=$with_cflags_qat_debug_file;
else
cflags_qat_debug_file="-DQAT_DEBUG_FILE_PATH=\$(with_qat_debug_file)"
fi


{ $as_echo "$as_me:${as_lineno-$LINENO}: Enabling writing debug to file" >&5
$as_echo "$as_me: Enabling writing debug to file" >&6;}
fi


if test "x$enable_usdm" != "xyes" -a "x$enable_multi_thread" != "xyes"; then
QAT_CONTIG_MEM_TRUE=
QAT_CONTIG_MEM_FALSE='#'
Expand Down
7 changes: 6 additions & 1 deletion e_qat.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ static int qat_engine_destroy(ENGINE *e)
qat_free_DH_methods();
qat_free_DSA_methods();
qat_free_RSA_methods();
QAT_DEBUG_LOG_CLOSE();
ERR_unload_QAT_strings();
return 1;
}
Expand All @@ -826,6 +827,8 @@ static int bind_qat(ENGINE *e, const char *id)
unsigned int devmasks[] = { 0, 0, 0, 0, 0 };
#endif

QAT_DEBUG_LOG_INIT();

WARN("QAT Warnings enabled.\n");
DEBUG("QAT Debug enabled.\n");
DEBUG("id=%s\n", id);
Expand Down Expand Up @@ -956,12 +959,14 @@ static ENGINE *engine_qat(void)

void ENGINE_load_qat(void)
{
ENGINE *toadd = engine_qat();
ENGINE *toadd;
int error = 0;
char error_string[QAT_MAX_ERROR_STRING] = { 0 };

QAT_DEBUG_LOG_INIT();
DEBUG("- Starting\n");

toadd = engine_qat();
if (toadd == NULL) {
error = ERR_peek_error();
ERR_error_string_n(error, error_string, QAT_MAX_ERROR_STRING);
Expand Down
4 changes: 4 additions & 0 deletions e_qat.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
# include <openssl/engine.h>
# include <sys/types.h>
# include <unistd.h>
# include <string.h>

# include "cpa.h"
# include "cpa_types.h"
Expand All @@ -65,6 +66,9 @@
#define likely(x) __builtin_expect (!!(x), 1)
#define unlikely(x) __builtin_expect (!!(x), 0)

#define XSTR(x) #x
#define STR(x) XSTR(x)

/* Macro used to handle errors in qat_engine_ctrl() */
#define BREAK_IF(cond, mesg) \
if(unlikely(cond)) { retVal = 0; WARN(mesg); break; }
Expand Down
29 changes: 20 additions & 9 deletions qae_mem_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,33 @@

# define QAE_BYTE_ALIGNMENT 0x0040/* 64 bytes */

extern FILE* qatDebugLogFile;

#ifdef QAT_MEM_DEBUG
# define MEM_DEBUG(fmt_str, ...) \
fprintf(stderr, "[MEM_DEBUG][%s:%d:%s()] "fmt_str, __FILE__, __LINE__, \
__func__, ##__VA_ARGS__)
# define MEM_DEBUG(fmt_str, ...) \
do { \
fprintf(qatDebugLogFile,"[MEM_DEBUG][%s:%d:%s()] "fmt_str, \
__FILE__, __LINE__, __func__, ##__VA_ARGS__); \
fflush(qatDebugLogFile); \
} while(0)
#else
# define MEM_DEBUG(...)
#endif

# define MEM_ERROR(fmt_str, ...) \
fprintf(stderr, "[MEM_ERROR][%s:%d:%s()] "fmt_str, __FILE__, __LINE__, \
__func__, ##__VA_ARGS__)
# define MEM_ERROR(fmt_str, ...) \
do { \
fprintf(qatDebugLogFile,"[MEM_ERROR][%s:%d:%s()] "fmt_str, \
__FILE__, __LINE__, __func__, ##__VA_ARGS__); \
fflush(qatDebugLogFile); \
} while(0)

#if defined(QAT_MEM_WARN) || defined(QAT_MEM_DEBUG)
# define MEM_WARN(fmt_str, ...) \
fprintf(stderr, "[MEM_WARN][%s:%d:%s()] "fmt_str, __FILE__, __LINE__, \
__func__, ##__VA_ARGS__)
# define MEM_WARN(fmt_str, ...) \
do { \
fprintf(qatDebugLogFile,"[MEM_WARN][%s:%d:%s()] "fmt_str, \
__FILE__, __LINE__, __func__, ##__VA_ARGS__); \
fflush(qatDebugLogFile); \
} while(0)
#else
# define MEM_WARN(...)
#endif
Expand Down
Loading

0 comments on commit 6e514a7

Please sign in to comment.