Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-10]: src/sys/arch/x86 Pull up following revision(s) (requested by...



details:   https://anonhg.NetBSD.org/src/rev/8dfd53f00e6f
branches:  netbsd-10
changeset: 374105:8dfd53f00e6f
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Apr 01 15:11:00 2023 +0000

description:
Pull up following revision(s) (requested by riastradh in ticket #136):

        sys/arch/x86/x86/intr.c: revision 1.164
        sys/arch/x86/isa/clock.c: revision 1.41
        sys/arch/x86/include/intr_private.h: revision 1.1

x86/intr: Work around sleazy clockintr with a secret frame argument.
PR kern/57197

diffstat:

 sys/arch/x86/include/intr_private.h |  39 +++++++++++++++++++++++++++++++++++++
 sys/arch/x86/isa/clock.c            |  18 ++++++++++------
 sys/arch/x86/x86/intr.c             |  20 +++++++++++++++---
 3 files changed, 66 insertions(+), 11 deletions(-)

diffs (156 lines):

diff -r a5a22adaa991 -r 8dfd53f00e6f sys/arch/x86/include/intr_private.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/x86/include/intr_private.h       Sat Apr 01 15:11:00 2023 +0000
@@ -0,0 +1,39 @@
+/*     $NetBSD: intr_private.h,v 1.1.2.2 2023/04/01 15:11:00 martin Exp $      */
+
+/*-
+ * Copyright (c) 2023 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef        _X86_INTR_PRIVATE_H_
+#define        _X86_INTR_PRIVATE_H_
+
+/*
+ * XXX This is a horrible kludge to let intr_establish_xname detect
+ * when it needs to handle a sleazy extra argument to the interrupt
+ * handler that's not part of the normal interrupt handler signature.
+ */
+int i8254_clockintr(void *, struct intrframe *);
+
+#endif /* _X86_INTR_PRIVATE_H_ */
diff -r a5a22adaa991 -r 8dfd53f00e6f sys/arch/x86/isa/clock.c
--- a/sys/arch/x86/isa/clock.c  Sat Apr 01 10:36:04 2023 +0000
+++ b/sys/arch/x86/isa/clock.c  Sat Apr 01 15:11:00 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clock.c,v 1.39 2020/05/29 12:30:41 rin Exp $   */
+/*     $NetBSD: clock.c,v 1.39.20.1 2023/04/01 15:11:00 martin Exp $   */
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -121,7 +121,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFT
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.39 2020/05/29 12:30:41 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.39.20.1 2023/04/01 15:11:00 martin Exp $");
 
 /* #define CLOCKDEBUG */
 /* #define CLOCK_PARANOIA */
@@ -152,6 +152,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFT
 #include <x86/lock.h>
 #include <machine/specialreg.h> 
 #include <x86/rtc.h>
+#include <x86/intr_private.h>
 
 #ifndef __x86_64__
 #include "mca.h"
@@ -188,8 +189,6 @@ void (*x86_delay)(unsigned int) = i8254_
 void           sysbeep(int, int);
 static void     tickle_tc(void);
 
-static int     clockintr(void *, struct intrframe *);
-
 int            sysbeepdetach(device_t, int);
 
 static unsigned int    gettick_broken_latch(void);
@@ -371,8 +370,8 @@ tickle_tc(void)
 
 }
 
-static int
-clockintr(void *arg, struct intrframe *frame)
+int
+i8254_clockintr(void *arg, struct intrframe *frame)
 {
        tickle_tc();
 
@@ -555,9 +554,14 @@ i8254_initclocks(void)
        /*
         * XXX If you're doing strange things with multiple clocks, you might
         * want to keep track of clock handlers.
+        *
+        * XXX This is an abuse of the interrupt handler signature with
+        * __FPTRCAST which requires a special case for IPL_CLOCK in
+        * intr_establish_xname.  Please fix this nonsense!  See also
+        * the comments about i8254_clockintr in x86/x86/intr.c.
         */
        (void)isa_intr_establish(NULL, 0, IST_PULSE, IPL_CLOCK,
-           __FPTRCAST(int (*)(void *), clockintr), 0);
+           __FPTRCAST(int (*)(void *), i8254_clockintr), 0);
 }
 
 void
diff -r a5a22adaa991 -r 8dfd53f00e6f sys/arch/x86/x86/intr.c
--- a/sys/arch/x86/x86/intr.c   Sat Apr 01 10:36:04 2023 +0000
+++ b/sys/arch/x86/x86/intr.c   Sat Apr 01 15:11:00 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.c,v 1.163 2022/10/29 13:59:04 riastradh Exp $     */
+/*     $NetBSD: intr.c,v 1.163.2.1 2023/04/01 15:11:00 martin Exp $    */
 
 /*
  * Copyright (c) 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.163 2022/10/29 13:59:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.163.2.1 2023/04/01 15:11:00 martin Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -162,6 +162,8 @@
 #include <machine/i8259.h>
 #include <machine/pio.h>
 
+#include <x86/intr_private.h>
+
 #include "ioapic.h"
 #include "lapic.h"
 #include "pci.h"
@@ -944,11 +946,21 @@ intr_establish_xname(int legacy_irq, str
        ih->ih_slot = slot;
        strlcpy(ih->ih_xname, xname, sizeof(ih->ih_xname));
 #ifdef KDTRACE_HOOKS
-       ih->ih_fun = intr_kdtrace_wrapper;
-       ih->ih_arg = ih;
+       /*
+        * XXX i8254_clockintr is special -- takes a magic extra
+        * argument.  This should be fixed properly in some way that
+        * doesn't involve sketchy function pointer casts.  See also
+        * the comments in x86/isa/clock.c.
+        */
+       if (handler != __FPTRCAST(int (*)(void *), i8254_clockintr)) {
+               ih->ih_fun = intr_kdtrace_wrapper;
+               ih->ih_arg = ih;
+       }
 #endif
 #ifdef MULTIPROCESSOR
        if (!mpsafe) {
+               KASSERT(handler !=                      /* XXX */
+                   __FPTRCAST(int (*)(void *), i8254_clockintr));
                ih->ih_fun = intr_biglock_wrapper;
                ih->ih_arg = ih;
        }



Home | Main Index | Thread Index | Old Index