On 9/23/2021 4:52 PM, Thomas Gleixner wrote:
On Mon, Sep 13 2021 at 13:01, Sohil Mehta wrote:
+/* UPID Notification control status */
+#define UPID_ON 0x0 /* Outstanding notification */
+#define UPID_SN 0x1 /* Suppressed notification */
Come on. This are bits in upid.status, right? So why can't the comment
above these defines says so and why can't the names not reflect that?
I'll fix this.
+struct uintr_upid_ctx {
+ struct uintr_upid *upid;
+ refcount_t refs;
Please use tabular format for struct members.
Will do.
+};
+
+struct uintr_receiver {
+ struct uintr_upid_ctx *upid_ctx;
+};
So we need a struct to wrap a pointer to another struct. Why?
The struct will have more members added later. Should the wrapper be
created then?
I didn't want to add members that are not used in this patch.
+inline bool uintr_arch_enabled(void)
What's this arch_enabled indirection for? Is this used anywhere in
non-architecture code?
I'll remove this indirection.
It is a remnant of some older code that had uintr_fd managed outside of
the x86 code.
+{
+ return static_cpu_has(X86_FEATURE_UINTR);
+}
+
+static inline bool is_uintr_receiver(struct task_struct *t)
+{
+ return !!t->thread.ui_recv;
+}
+
+static inline u32 cpu_to_ndst(int cpu)
+{
+ u32 apicid = (u32)apic->cpu_present_to_apicid(cpu);
+
+ WARN_ON_ONCE(apicid == BAD_APICID);
Brilliant. If x2apic is not enabled then this case returns
I'll fix this.
+ if (!x2apic_enabled())
+ return (apicid << 8) & 0xFF00;
(BAD_APICID << 8) & 0xFF00 == 0xFF ....
+int do_uintr_unregister_handler(void)
+{
+ struct task_struct *t = current;
+ struct fpu *fpu = &t->thread.fpu;
+ struct uintr_receiver *ui_recv;
+ u64 msr64;
+
+ if (!is_uintr_receiver(t))
+ return -EINVAL;
+
+ pr_debug("recv: Unregister handler and clear MSRs for task=%d\n",
+ t->pid);
+
+ /*
+ * TODO: Evaluate usage of fpregs_lock() and get_xsave_addr(). Bugs
+ * have been reported recently for PASID and WRPKRU.
Again. Which bugs and why haven't they been evaluated before posting?
I apologize again. This comment is no longer valid.
+ * UPID and ui_recv will be referenced during context switch. Need to
+ * disable preemption while modifying the MSRs, UPID and ui_recv thread
+ * struct.
+ */
+ fpregs_lock();
And because you need to disable preemption you need to use
fpregs_lock(), right? That's not what fpregs_lock() is about.
Got it. I'll evaluate the use of fpregs_lock() at all places.
+ wrmsrl(MSR_IA32_UINTR_MISC, msr64);
+ wrmsrl(MSR_IA32_UINTR_PD, 0ULL);
+ wrmsrl(MSR_IA32_UINTR_RR, 0ULL);
+ wrmsrl(MSR_IA32_UINTR_STACKADJUST, 0ULL);
+ wrmsrl(MSR_IA32_UINTR_HANDLER, 0ULL);
+ } else {
+ struct uintr_state *p;
+
+ p = get_xsave_addr(&fpu->state.xsave, XFEATURE_UINTR);
+ if (p) {
+ p->handler = 0;
+ p->stack_adjust = 0;
+ p->upid_addr = 0;
+ p->uinv = 0;
+ p->uirr = 0;
+ }
So p == NULL is expected here?
I'll fix this and other usages of get_xsave_addr().
Thanks,
Sohil