* [PATCH 0/2] trace-cmd: Still work without memfd_create()
@ 2022-04-28 17:49 Steven Rostedt
2022-04-28 17:49 ` [PATCH 1/2] trace-cmd Makefile: Change test-build to link as well Steven Rostedt
2022-04-28 17:49 ` [PATCH 2/2] trace-cmd agent: Test if memfd_create() is available Steven Rostedt
0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-04-28 17:49 UTC (permalink / raw)
To: linux-trace-devel; +Cc: Joel Fernandes, Steven Rostedt (Google)
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
As some systems do not implement memfd_create() be able to fallback to the
tempfile method.
Depends on: https://lore.kernel.org/r/20220405192204.1551283-1-joel@joelfernandes.org
https://patchwork.kernel.org/project/linux-trace-devel/patch/20220405192204.1551283-1-joel@joelfernandes.org/
Steven Rostedt (Google) (2):
trace-cmd Makefile: Change test-build to link as well
trace-cmd agent: Test if memfd_create() is available
Makefile | 13 +++++++++++--
lib/trace-cmd/include/private/trace-cmd-private.h | 5 +++++
lib/trace-cmd/trace-msg.c | 8 ++++++++
3 files changed, 24 insertions(+), 2 deletions(-)
--
2.35.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] trace-cmd Makefile: Change test-build to link as well
2022-04-28 17:49 [PATCH 0/2] trace-cmd: Still work without memfd_create() Steven Rostedt
@ 2022-04-28 17:49 ` Steven Rostedt
2022-04-28 17:49 ` [PATCH 2/2] trace-cmd agent: Test if memfd_create() is available Steven Rostedt
1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-04-28 17:49 UTC (permalink / raw)
To: linux-trace-devel; +Cc: Joel Fernandes, Steven Rostedt (Google)
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Remove the '-c' option from the test-build macro build. To test if a
function exists, it needs to go through the link phase, otherwise it can
pass with an undefined symbol.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 982514baad01..9fbc6de25d05 100644
--- a/Makefile
+++ b/Makefile
@@ -163,7 +163,7 @@ export NO_PYTHON
# $(call test-build, snippet, ret) -> ret if snippet compiles
# -> empty otherwise
test-build = $(if $(shell sh -c 'echo "$(1)" | \
- $(CC) -o /dev/null -c -x c - > /dev/null 2>&1 && echo y'), $2)
+ $(CC) -o /dev/null -x c - > /dev/null 2>&1 && echo y'), $2)
UDIS86_AVAILABLE := $(call test-build,\#include <udis86.h>, y)
ifneq ($(strip $(UDIS86_AVAILABLE)), y)
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] trace-cmd agent: Test if memfd_create() is available
2022-04-28 17:49 [PATCH 0/2] trace-cmd: Still work without memfd_create() Steven Rostedt
2022-04-28 17:49 ` [PATCH 1/2] trace-cmd Makefile: Change test-build to link as well Steven Rostedt
@ 2022-04-28 17:49 ` Steven Rostedt
1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-04-28 17:49 UTC (permalink / raw)
To: linux-trace-devel; +Cc: Joel Fernandes, Steven Rostedt (Google)
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Some systems do not have memfd_create() available and it is a regression
to require it. Fall back to tempfs if memfd_create() is not available at
build time.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
Makefile | 11 ++++++++++-
lib/trace-cmd/include/private/trace-cmd-private.h | 5 +++++
lib/trace-cmd/trace-msg.c | 8 ++++++++
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 9fbc6de25d05..abc4ac723db4 100644
--- a/Makefile
+++ b/Makefile
@@ -184,6 +184,15 @@ endef
# have flush/fua block layer instead of barriers?
blk-flags := $(call test-build,$(BLK_TC_FLUSH_SOURCE),-DHAVE_BLK_TC_FLUSH)
+define MEMFD_CREATE_SOURCE
+#define _GNU_SOURCE
+#include <sys/mman.h>
+int main(void) { return memfd_create(\"test\", 0); }
+endef
+
+# have memfd_create available
+memfd-flags := $(call test-build,$(MEMFD_CREATE_SOURCE),-DHAVE_MEMFD_CREATE)
+
ifeq ("$(origin O)", "command line")
saved-output := $(O)
@@ -363,7 +372,7 @@ endif
# Append required CFLAGS
override CFLAGS += $(INCLUDES) $(VAR_DIR)
override CFLAGS += $(PLUGIN_DIR_TRACECMD_SQ)
-override CFLAGS += $(udis86-flags) $(blk-flags)
+override CFLAGS += $(udis86-flags) $(blk-flags) $(memfd-flags)
override LDFLAGS += $(udis86-ldflags)
CMD_TARGETS = trace-cmd $(BUILD_PYTHON)
diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
index 0efc2a1c4850..3b84170f2258 100644
--- a/lib/trace-cmd/include/private/trace-cmd-private.h
+++ b/lib/trace-cmd/include/private/trace-cmd-private.h
@@ -380,6 +380,8 @@ enum tracecmd_msg_flags {
TRACECMD_MSG_FL_USE_VSOCK = 1 << 1,
};
+#define MSG_CACHE_FILE "/tmp/trace_msg_cacheXXXXXX"
+
/* for both client and server */
struct tracecmd_msg_handle {
int fd;
@@ -389,6 +391,9 @@ struct tracecmd_msg_handle {
bool done;
bool cache;
int cfd;
+#ifndef HAVE_MEMFD_CREATE
+ char cfile[sizeof(MSG_CACHE_FILE)];
+#endif
};
struct tracecmd_tsync_protos {
diff --git a/lib/trace-cmd/trace-msg.c b/lib/trace-cmd/trace-msg.c
index 5ba2eeb2d183..9899fa8796e2 100644
--- a/lib/trace-cmd/trace-msg.c
+++ b/lib/trace-cmd/trace-msg.c
@@ -591,9 +591,17 @@ tracecmd_msg_handle_alloc(int fd, unsigned long flags)
int tracecmd_msg_handle_cache(struct tracecmd_msg_handle *msg_handle)
{
if (msg_handle->cfd < 0) {
+#ifdef HAVE_MEMFD_CREATE
msg_handle->cfd = memfd_create("trace_msg_cache", 0);
if (msg_handle->cfd < 0)
return -1;
+#else
+ strcpy(msg_handle->cfile, MSG_CACHE_FILE);
+ msg_handle->cfd = mkstemp(msg_handle->cfile);
+ if (msg_handle->cfd < 0)
+ return -1;
+ unlink(msg_handle->cfile);
+#endif
}
msg_handle->cache = true;
return 0;
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-28 17:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-28 17:49 [PATCH 0/2] trace-cmd: Still work without memfd_create() Steven Rostedt
2022-04-28 17:49 ` [PATCH 1/2] trace-cmd Makefile: Change test-build to link as well Steven Rostedt
2022-04-28 17:49 ` [PATCH 2/2] trace-cmd agent: Test if memfd_create() is available Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).