Skip to content

Static local reworks#1054

Merged
yhcote merged 6 commits into
dynup:masterfrom
julien-thierry:static-local-reworks
Apr 4, 2020
Merged

Static local reworks#1054
yhcote merged 6 commits into
dynup:masterfrom
julien-thierry:static-local-reworks

Conversation

@julien-thierry

Copy link
Copy Markdown
Contributor

This fixes the error on RHEL8.0 test gcc-static-local-var-5:

ERROR: audit.o: reference to static local variable lock.65414 in audit_log_end was removed
/root/kpatch/kpatch-build/create-diff-object: unreconcilable difference

Mentioned in PR #993 .

Comment thread kpatch-build/create-diff-object.c
}
#endif

static bool kpatch_changed_child_needs_parent_profiling(struct symbol *sym)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be helpful to add a comment somewhere explaining that .cold children don't have fentry but that .part children often do.

BTW, the terms 'parent' and 'child' in this context have always bothered me because they're so ambigious. What do you think? Any ideas for better naming? Superfunction/subfunction?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add the comment.

Superfunction sounds a bit odd. But subfunction definitely sounds better than child.
Maybe Top function?
Otherwise I actually like the "part" terminology (without being a direct references to the .part. in the name of the symbol). So I would suggest e.g. "function_parts" and "part_of" .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about function_parts/part_of. Maybe parent/child is ok.

Comment thread kpatch-build/create-diff-object.c
Comment thread kpatch-build/create-diff-object.c Outdated
Comment thread kpatch-build/create-diff-object.c Outdated
@jpoimboe

jpoimboe commented Nov 1, 2019

Copy link
Copy Markdown
Member

A unit test (or tests) for this PR would be good too.

julien-thierry pushed a commit to julien-thierry/kpatch-unit-test-objs that referenced this pull request Nov 4, 2019
This is a test for dynup/kpatch#1054. The following patch was used with
a RHEL-8.0 kernel:

diff --git a/kernel/audit.c b/kernel/audit.c
index e7478cb..ed2546a 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -325,6 +325,12 @@ void audit_panic(const char *message)
 	}
 }

+void kpatch_audit_foo(void)
+{
+	if (!jiffies)
+		printk("kpatch audit foo\n");
+}
+
 static inline int audit_rate_check(void)
 {
 	static unsigned long	last_check = 0;
@@ -335,6 +341,7 @@ static inline int audit_rate_check(void)
 	unsigned long		elapsed;
 	int			retval	   = 0;

+	kpatch_audit_foo();
 	if (!audit_rate_limit) return 1;

 	spin_lock_irqsave(&lock, flags);
@@ -354,6 +361,11 @@ static inline int audit_rate_check(void)
 	return retval;
 }

+noinline void kpatch_audit_check(void)
+{
+	audit_rate_check();
+}
+
 /**
  * audit_log_lost - conditionally log lost audit message event
  * @message: the message stating reason for lost audit message
@@ -400,6 +412,8 @@ static int audit_log_config_change(char *function_name, u32 new, u32 old,
 	struct audit_buffer *ab;
 	int rc = 0;

+	kpatch_audit_check();
+
 	ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE);
 	if (unlikely(!ab))
 		return rc;

Signed-off-by: Julien Thierry <jthierry@redhat.com>
julien-thierry pushed a commit to julien-thierry/kpatch-unit-test-objs that referenced this pull request Nov 22, 2019
This is a test for dynup/kpatch#1054. The following patch was used with
a RHEL-8.0 kernel:

diff --git a/kernel/audit.c b/kernel/audit.c
index e7478cb..ed2546a 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -325,6 +325,12 @@ void audit_panic(const char *message)
 	}
 }

+void kpatch_audit_foo(void)
+{
+	if (!jiffies)
+		printk("kpatch audit foo\n");
+}
+
 static inline int audit_rate_check(void)
 {
 	static unsigned long	last_check = 0;
@@ -335,6 +341,7 @@ static inline int audit_rate_check(void)
 	unsigned long		elapsed;
 	int			retval	   = 0;

+	kpatch_audit_foo();
 	if (!audit_rate_limit) return 1;

 	spin_lock_irqsave(&lock, flags);
@@ -354,6 +361,11 @@ static inline int audit_rate_check(void)
 	return retval;
 }

+noinline void kpatch_audit_check(void)
+{
+	audit_rate_check();
+}
+
 /**
  * audit_log_lost - conditionally log lost audit message event
  * @message: the message stating reason for lost audit message
@@ -400,6 +412,8 @@ static int audit_log_config_change(char *function_name, u32 new, u32 old,
 	struct audit_buffer *ab;
 	int rc = 0;

+	kpatch_audit_check();
+
 	ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE);
 	if (unlikely(!ab))
 		return rc;

Signed-off-by: Julien Thierry <jthierry@redhat.com>
sm00th added a commit to sm00th/kpatch that referenced this pull request Jan 20, 2020
This is supposedly fixed by dynup#1054 and should be reinabled once that is
merged.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
sm00th added a commit to sm00th/kpatch that referenced this pull request Jan 23, 2020
This is supposedly fixed by dynup#1054 and should be reinabled once that is
merged.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
sm00th added a commit to sm00th/kpatch that referenced this pull request Jan 24, 2020
This is supposedly fixed by dynup#1054 and should be reinabled once that is
merged.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
@joe-lawrence

Copy link
Copy Markdown
Contributor

/bump. According to the review comment conversation, @julien-thierry is waiting on @jpoimboe for a few follow ups to his suggestions? And that a unit test has been merged in the meantime.

@sm00th sm00th left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs a commit re-enabling gcc-static-local-var-5 tests across all distros.

Otherwise looks ok.

Comment thread kpatch-build/create-diff-object.c Outdated

/*
* Child functions with "*.cold" names don't have _fentry_ calls, but "*.part",
* often don't. In the later case, it is not necessary to include the parent

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* often don't. In the later case, it is not necessary to include the parent
* often do. In the later case, it is not necessary to include the parent

Julien Thierry added 6 commits March 30, 2020 14:14
When a child symbol has changed, the parent symbol is only needed
in the output object if the child symbol is unpatchable on its own.
This is the case when the child symbol does not have its own profiling
call.

Only include unchanged parent symbols if their child has changed and
the child does not have a function profiling call.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
A symbol associated to a function can be split into multiple
sub-functions. Currently, kpatch only supports one child per function.

Extend this to support an arbitrary number of sub-function per function.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
Consider symbols containing .part. in their names as sub-function
of the symbols they are derived from (if such symbol still exists in the
object file).

Signed-off-by: Julien Thierry <jthierry@redhat.com>
A symbol in the original object might get split in several sub-functions
in the patched object, which can themselves be bundled (and use a
separate rela section). References to local static variables from the
original function, might have been moved in one of the sub-functions
in the patched object.

Look for references to local static variables in the rela section
of child symbols in the patched object.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
Signed-off-by: Julien Thierry <jthierry@redhat.com>
Reenable previously failing test gcc-static-local-var-5.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
@julien-thierry

Copy link
Copy Markdown
Contributor Author

I've added the enablement of gcc-static-local-var-5.

@yhcote

yhcote commented Apr 2, 2020

Copy link
Copy Markdown
Contributor

Taking a look as well at the moment. Will merge later today if it's OK :-)

@yhcote yhcote merged commit e2c66d7 into dynup:master Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants