public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Valentin Schneider <vschneid@redhat.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	linux-arch@vger.kernel.org, Josh Poimboeuf <jpoimboe@kernel.org>,
	Daniel Wagner <dwagner@suse.de>,
	Sean Christopherson <seanjc@google.com>,
	Juergen Gross <jgross@suse.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Rik van Riel <riel@fb.com>
Subject: x86 RAR implementation
Date: Fri, 2 May 2025 09:36:13 -0700	[thread overview]
Message-ID: <1eefc8a3-a54f-44e7-ae60-739047230ac4@intel.com> (raw)
In-Reply-To: <20250502152002.GX4439@noisy.programming.kicks-ass.net>

Trimming down the cc list (and oh, what a cc list it was!!!) to x86 folks.

On 5/2/25 08:20, Peter Zijlstra wrote:
> So where IPI is:
> 
>  - IPI all CPUs
>  - local invalidate
>  - wait for completion

To drill down on this a bit, the IPI is actually something like

	for_each_cpu(IPI_cpumask)
		per_cpu_ptr(cpu)->csd = 1;
	send_ipi(IPI_cpumask)
	// local invalidate
	// wait for completion

... and the send_ipi() can be a for loop too if it's in clustered mode.
So there is at least _a_ for loop in this case in practice because each
CPU has a per-cpu structure to tell it what to do in the IPI.

> This then becomes:
> 
>  for ()
>    - RAR some CPUs
>    - wait for completion

Were you thinking that the "some CPUs" was limited to 64 because of the
size of the payload table and action vectors? Maybe I was thinking of
arranging the data structures differently.

I was figuring that we could use one entry in the payload table per IPI
operation, *not* one per CPU. Something like:

	e = alloc_payload_entry();
	payload_table[e] = payload;
	for_each_cpu(RAR_cpumask)
		per_cpu_ptr(cpu)->action_vector[e] = RAR_PENDING;
	send_ipi(RAR_cpumask)
	// local invalidate
	// wait for completion
	free_table_entry(e);

In that silly scheme, the allocation can fail. But in that case it's
easy to just fall back to IPIs. I _think_ that works, but it's all in my
head and maybe I'm missing something silly.

I think the mechanism you were thinking of was something like this
(diff'd from what I had above):

-	e = alloc_payload_entry();
+	e = smp_processor_id();
	payload_table[e] = payload;
	for_each_cpu(RAR_cpumask)
		per_cpu_ptr(cpu)->action_vector[e] = RAR_PENDING;
	send_ipi(RAR_cpumask)
	// local invalidate
	// wait for completion
-	free_table_entry(e);

That beats my scheme because it doesn't have any allocation, free or
locking overhead and can't fail to allocate. But it would be limited to
<=64 CPUs because the payload table and action vector are only 64
entries long.



      reply	other threads:[~2025-05-02 16:36 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-29 11:32 [PATCH v5 00/25] context_tracking,x86: Defer some IPIs until a user->kernel transition Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 01/25] objtool: Make validate_call() recognize indirect calls to pv_ops[] Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 02/25] objtool: Flesh out warning related to pv_ops[] calls Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 03/25] rcu: Add a small-width RCU watching counter debug option Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 04/25] rcutorture: Make TREE04 use CONFIG_RCU_DYNTICKS_TORTURE Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 05/25] jump_label: Add annotations for validating noinstr usage Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 06/25] static_call: Add read-only-after-init static calls Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 07/25] x86/paravirt: Mark pv_sched_clock static call as __ro_after_init Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 08/25] x86/idle: Mark x86_idle " Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 09/25] x86/paravirt: Mark pv_steal_clock " Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 10/25] riscv/paravirt: " Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 11/25] loongarch/paravirt: " Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 12/25] arm64/paravirt: " Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 13/25] arm/paravirt: " Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 14/25] perf/x86/amd: Mark perf_lopwr_cb " Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 15/25] sched/clock: Mark sched_clock_running key " Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 16/25] KVM: VMX: Mark __kvm_is_using_evmcs static " Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 17/25] x86/speculation/mds: Mark mds_idle_clear key as allowed in .noinstr Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 18/25] sched/clock, x86: Mark __sched_clock_stable " Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 19/25] KVM: VMX: Mark vmx_l1d_should flush and vmx_l1d_flush_cond keys " Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 20/25] stackleack: Mark stack_erasing_bypass key " Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 21/25] objtool: Add noinstr validation for static branches/calls Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 22/25] module: Remove outdated comment about text_size Valentin Schneider
2025-05-05 14:27   ` Petr Pavlu
2025-04-29 11:32 ` [PATCH v5 23/25] module: Add MOD_NOINSTR_TEXT mem_type Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 24/25] context-tracking: Introduce work deferral infrastructure Valentin Schneider
2025-04-29 11:32 ` [PATCH v5 25/25] context_tracking,x86: Defer kernel text patching IPIs Valentin Schneider
2025-04-29 16:11 ` [PATCH v5 00/25] context_tracking,x86: Defer some IPIs until a user->kernel transition Dave Hansen
2025-04-30 17:20   ` Steven Rostedt
2025-04-30 18:07     ` Dave Hansen
2025-04-30 19:42       ` Steven Rostedt
2025-04-30 20:00         ` Dave Hansen
2025-05-02  9:55           ` Valentin Schneider
2025-05-02 13:53             ` Dave Hansen
2025-05-02 16:38               ` Valentin Schneider
2025-05-02 17:57                 ` Dave Hansen
2025-05-05 15:45                   ` Valentin Schneider
2025-05-02 11:22       ` Peter Zijlstra
2025-05-02 14:33         ` Dave Hansen
2025-05-02 15:20           ` Peter Zijlstra
2025-05-02 16:36             ` Dave Hansen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1eefc8a3-a54f-44e7-ae60-739047230ac4@intel.com \
    --to=dave.hansen@intel.com \
    --cc=bp@alien8.de \
    --cc=dwagner@suse.de \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=jpoimboe@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=riel@fb.com \
    --cc=rostedt@goodmis.org \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=vschneid@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox