lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKwvOdna5NZ0ZTv0pXVVz15=4FLkw7pfFgr6KsRtXRmi2o1uEw@mail.gmail.com>
Date:   Tue, 7 Mar 2023 13:16:17 -0800
From:   Nick Desaulniers <ndesaulniers@...gle.com>
To:     "Luck, Tony" <tony.luck@...el.com>,
        "Torvalds, Linus" <torvalds@...ux-foundation.org>
Cc:     Jakub Jelinek <jakub@...hat.com>,
        Segher Boessenkool <segher@...nel.crashing.org>,
        Peter Zijlstra <peterz@...radead.org>,
        "Eranian, Stephane" <eranian@...gle.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "Chatre, Reinette" <reinette.chatre@...el.com>,
        "Yu, Fenghua" <fenghua.yu@...el.com>,
        "peternewman@...gle.com" <peternewman@...gle.com>,
        "james.morse@....com" <james.morse@....com>,
        "babu.moger@....com" <babu.moger@....com>,
        "ananth.narayan@....com" <ananth.narayan@....com>,
        "vschneid@...hat.com" <vschneid@...hat.com>,
        Nathan Chancellor <nathan@...nel.org>,
        clang-built-linux <llvm@...ts.linux.dev>,
        Borislav Petkov <bp@...en8.de>,
        "H. Peter Anvin" <hpa@...or.com>,
        "linux-toolchains@...r.kernel.org" <linux-toolchains@...r.kernel.org>
Subject: Re: [PATCH] x86/resctrl: avoid compiler optimization in __resctrl_sched_in

On Tue, Mar 7, 2023 at 1:11 PM Luck, Tony <tony.luck@...el.com> wrote:
>
> > (a) it shouldn't define and declare a static function in a header file
> >
> >  (b) the resctrl_sched_in() inline function is midesigned to begin with
>
> Fixing "b" would seem to be to just pass "next_p" to the function to
> use instead of "current".

```
diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h
index 52788f79786f..f46c0b97334d 100644
--- a/arch/x86/include/asm/resctrl.h
+++ b/arch/x86/include/asm/resctrl.h
@@ -49,7 +49,7 @@ DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key);
  *   simple as possible.
  * Must be called with preemption disabled.
  */
-static void __resctrl_sched_in(void)
+static void __resctrl_sched_in(struct task_struct *next)
 {
  struct resctrl_pqr_state *state = this_cpu_ptr(&pqr_state);
  u32 closid = state->default_closid;
@@ -61,13 +61,13 @@ static void __resctrl_sched_in(void)
  * Else use the closid/rmid assigned to this cpu.
  */
  if (static_branch_likely(&rdt_alloc_enable_key)) {
- tmp = READ_ONCE(current->closid);
+ tmp = READ_ONCE(next->closid);
  if (tmp)
  closid = tmp;
  }

  if (static_branch_likely(&rdt_mon_enable_key)) {
- tmp = READ_ONCE(current->rmid);
+ tmp = READ_ONCE(next->rmid);
  if (tmp)
  rmid = tmp;
  }
@@ -88,17 +88,17 @@ static inline unsigned int
resctrl_arch_round_mon_val(unsigned int val)
  return val * scale;
 }

-static inline void resctrl_sched_in(void)
+static inline void resctrl_sched_in(struct task_struct *next)
 {
  if (static_branch_likely(&rdt_enable_key))
- __resctrl_sched_in();
+ __resctrl_sched_in(next);
 }

 void resctrl_cpu_detect(struct cpuinfo_x86 *c);

 #else

-static inline void resctrl_sched_in(void) {}
+static inline void resctrl_sched_in(struct task_struct *next) {}
 static inline void resctrl_cpu_detect(struct cpuinfo_x86 *c) {}

 #endif /* CONFIG_X86_CPU_RESCTRL */
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index e2c1599d1b37..d970347838a4 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -314,7 +314,7 @@ static void update_cpu_closid_rmid(void *info)
  * executing task might have its own closid selected. Just reuse
  * the context switch code.
  */
- resctrl_sched_in();
+ resctrl_sched_in(current);
 }

 /*
@@ -530,7 +530,7 @@ static void _update_task_closid_rmid(void *task)
  * Otherwise, the MSR is updated when the task is scheduled in.
  */
  if (task == current)
- resctrl_sched_in();
+ resctrl_sched_in(current);
 }

 static void update_task_closid_rmid(struct task_struct *t)
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index 470c128759ea..708c87b88cc1 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -212,7 +212,7 @@ __switch_to(struct task_struct *prev_p, struct
task_struct *next_p)
  switch_fpu_finish();

  /* Load the Intel cache allocation PQR MSR. */
- resctrl_sched_in();
+ resctrl_sched_in(next_p);

  return prev_p;
 }
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index 4e34b3b68ebd..bb65a68b4b49 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -656,7 +656,7 @@ __switch_to(struct task_struct *prev_p, struct
task_struct *next_p)
  }

  /* Load the Intel cache allocation PQR MSR. */
- resctrl_sched_in();
+ resctrl_sched_in(next_p);

  return prev_p;
 }

```
?

>
> Can you expand about part "a" ... Linux has zillions of static inline functions
> in header files to handle CONFIG options. One version is the real McCoy
> while the other is just a stub for the CONFIG=n case.

Right, I had the same question.

Perhaps it's more so that no one calls __resctrl_sched_in, only
resctrl_sched_in, therefor they should be folded into one function?

>
> What's different about this one?
>
> -Tony



-- 
Thanks,
~Nick Desaulniers

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ