From owner-svn-src-all@freebsd.org Sat Aug 29 07:09:12 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0350C3D0025; Sat, 29 Aug 2020 07:09:12 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BdndM3V0Jz43ZC; Sat, 29 Aug 2020 07:09:11 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-wr1-x443.google.com with SMTP id f7so1141165wrw.1; Sat, 29 Aug 2020 00:09:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=fr+XgDr1LRxwO6sKj9p+ER5WnSKmqsBFFhMYokA0lCg=; b=j2G9mEy2Ys3HVj9M7A+B4FBbacg78q9ke1IOH7KpctooeWeOuXk2Inedir7j1VDpRM 4lkkiRbiFbgMfe8cl6dRaLq6FvtLH/9iIUJl3KlGAYkJIMlub+WRZy4QYAqpG6/wPdpg W1SkMw+XG9XlxzZSNbPJIFwOwD9tmzjGXcKDtE7Iv/caGZrkNJDNsJuIxuUJoONvfPLm hCySIhSkNtkCgVW/WP9niCZVjfoR/anjEFy4fXZ/vKnl028weVRGj88pDAVOnXOggxUv 3G3i+nuB2fQbdosH7nWqbL3l67p7fYB+fuk4Q32lAt2/BV882YeTmZEVL4udFUyP+QBh LoYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=fr+XgDr1LRxwO6sKj9p+ER5WnSKmqsBFFhMYokA0lCg=; b=ihw2k5HeQL5cpxSYGIpaJPI7x30XtIJz3Qa1doudWMLHdtdY9okKRxvnhnCF7w8tgV S27dS7ztFiUsl2nJtUaWDKVxbA+V1I/DRUBzcsck0AcqcAwF7IokgnDX5YBR7LRV3S0r xxfCNKqzl6cHSseCEqSPqig+gsNXayYdYvgeccymqC6NVdudkKHfnDO5QMGGJ9h+OJMd xQYzRzAKx2nsVG4aFynAlQHeLWmVx2OwzVdmcbL0yHrK2cUsL71vRU+fNfHADN4x1m87 3DWQ2YFpE0TNl3ETBitcphCNVaZh16nlM8UroMMA/JwxGmbG8Hr9m5ZstHYEyDIFqCni 97+w== X-Gm-Message-State: AOAM532Fw6mCvSWaPoM8ZEq88POWIrvnHjim8dGqAxjoU5mZKGc53jL5 IK3My+ARxKwavnTKTE8kyeWzwKEjHppDiN6R2ssS1lKp X-Google-Smtp-Source: ABdhPJyit1/adjopwey0inVvO4+M/reOOyi8UllS2fiq8G7YXxkmKbXkaHnbnQe6BWL7h5AkY+cA/OOLyCvY+heBA0w= X-Received: by 2002:adf:f8d0:: with SMTP id f16mr2549616wrq.66.1598684949249; Sat, 29 Aug 2020 00:09:09 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a5d:5347:0:0:0:0:0 with HTTP; Sat, 29 Aug 2020 00:09:08 -0700 (PDT) In-Reply-To: <202008290430.07T4UCM4007928@repo.freebsd.org> References: <202008290430.07T4UCM4007928@repo.freebsd.org> From: Mateusz Guzik Date: Sat, 29 Aug 2020 09:09:08 +0200 Message-ID: Subject: Re: svn commit: r364946 - head/sys/kern To: Warner Losh Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 4BdndM3V0Jz43ZC X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; REPLY(-4.00)[] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Aug 2020 07:09:12 -0000 This crashes on boot for me: atal trap 12: page fault while in kernel mode cpuid = 0; apic id = 00 fault virtual address = 0x0 fault code = supervisor read data, page not present instruction pointer = 0x20:0xffffffff805b0a7f stack pointer = 0x28:0xfffffe002366a7f0 frame pointer = 0x28:0xfffffe002366a7f0 code segment = base 0x0, limit 0xfffff, type 0x1b = DPL 0, pres 1, long 1, def32 0, gran 1 processor eflags = interrupt enabled, resume, IOPL = 0 current process = 89 (devmatch) trap number = 12 panic: page fault cpuid = 0 time = 1598692135 KDB: stack backtrace: db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe002366a4a0 vpanic() at vpanic+0x182/frame 0xfffffe002366a4f0 panic() at panic+0x43/frame 0xfffffe002366a550 trap_fatal() at trap_fatal+0x387/frame 0xfffffe002366a5b0 trap_pfault() at trap_pfault+0x4f/frame 0xfffffe002366a610 trap() at trap+0x27d/frame 0xfffffe002366a720 calltrap() at calltrap+0x8/frame 0xfffffe002366a720 --- trap 0xc, rip = 0xffffffff805b0a7f, rsp = 0xfffffe002366a7f0, rbp = 0xfffffe002366a7f0 --- strlen() at strlen+0x1f/frame 0xfffffe002366a7f0 sbuf_cat() at sbuf_cat+0x15/frame 0xfffffe002366a810 sysctl_devices() at sysctl_devices+0x104/frame 0xfffffe002366a8a0 sysctl_root_handler_locked() at sysctl_root_handler_locked+0x91/frame 0xfffffe002366a8f0 sysctl_root() at sysctl_root+0x249/frame 0xfffffe002366a970 userland_sysctl() at userland_sysctl+0x170/frame 0xfffffe002366aa20 sys___sysctl() at sys___sysctl+0x5f/frame 0xfffffe002366aad0 amd64_syscall() at amd64_syscall+0x10c/frame 0xfffffe002366abf0 fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe002366abf0 --- syscall (202, FreeBSD ELF64, sys___sysctl), rip = 0x80041c0ea, rsp = 0x7fffffffda78, rbp = 0x7fffffffdab0 --- KDB: enter: panic [ thread pid 89 tid 100067 ] Stopped at kdb_enter+0x37: movq $0,0x7e2616(%rip) On 8/29/20, Warner Losh wrote: > Author: imp > Date: Sat Aug 29 04:30:12 2020 > New Revision: 364946 > URL: https://svnweb.freebsd.org/changeset/base/364946 > > Log: > Move to using sbuf for some sysctl in newbus > > Convert two different sysctl to using sbuf. First, for all the default > sysctls we implement for each device driver that's attached. This is a > pure sbuf conversion. > > Second, convert sysctl_devices to fill its buffer with sbuf rather > than a hand-rolled crappy thing I wrote years ago. > > Reviewed by: cem, markj > Differential Revision: https://reviews.freebsd.org/D26206 > > Modified: > head/sys/kern/subr_bus.c > > Modified: head/sys/kern/subr_bus.c > ============================================================================== > --- head/sys/kern/subr_bus.c Sat Aug 29 04:30:06 2020 (r364945) > +++ head/sys/kern/subr_bus.c Sat Aug 29 04:30:12 2020 (r364946) > @@ -260,36 +260,33 @@ enum { > static int > device_sysctl_handler(SYSCTL_HANDLER_ARGS) > { > + struct sbuf sb; > device_t dev = (device_t)arg1; > - const char *value; > - char *buf; > int error; > > - buf = NULL; > + sbuf_new_for_sysctl(&sb, NULL, 1024, req); > switch (arg2) { > case DEVICE_SYSCTL_DESC: > - value = dev->desc ? dev->desc : ""; > + sbuf_cpy(&sb, dev->desc ? dev->desc : ""); > break; > case DEVICE_SYSCTL_DRIVER: > - value = dev->driver ? dev->driver->name : ""; > + sbuf_cpy(&sb, dev->driver ? dev->driver->name : ""); > break; > case DEVICE_SYSCTL_LOCATION: > - value = buf = malloc(1024, M_BUS, M_WAITOK | M_ZERO); > - bus_child_location_str(dev, buf, 1024); > + bus_child_location_sb(dev, &sb); > break; > case DEVICE_SYSCTL_PNPINFO: > - value = buf = malloc(1024, M_BUS, M_WAITOK | M_ZERO); > - bus_child_pnpinfo_str(dev, buf, 1024); > + bus_child_pnpinfo_sb(dev, &sb); > break; > case DEVICE_SYSCTL_PARENT: > - value = dev->parent ? dev->parent->nameunit : ""; > + sbuf_cpy(&sb, dev->parent ? dev->parent->nameunit : ""); > break; > default: > + sbuf_delete(&sb); > return (EINVAL); > } > - error = SYSCTL_OUT_STR(req, value); > - if (buf != NULL) > - free(buf, M_BUS); > + error = sbuf_finish(&sb); > + sbuf_delete(&sb); > return (error); > } > > @@ -5464,13 +5461,13 @@ SYSCTL_PROC(_hw_bus, OID_AUTO, info, CTLTYPE_STRUCT > | > static int > sysctl_devices(SYSCTL_HANDLER_ARGS) > { > + struct sbuf sb; > int *name = (int *)arg1; > u_int namelen = arg2; > int index; > device_t dev; > struct u_device *udev; > int error; > - char *walker, *ep; > > if (namelen != 2) > return (EINVAL); > @@ -5501,34 +5498,21 @@ sysctl_devices(SYSCTL_HANDLER_ARGS) > udev->dv_devflags = dev->devflags; > udev->dv_flags = dev->flags; > udev->dv_state = dev->state; > - walker = udev->dv_fields; > - ep = walker + sizeof(udev->dv_fields); > -#define CP(src) \ > - if ((src) == NULL) \ > - *walker++ = '\0'; \ > - else { \ > - strlcpy(walker, (src), ep - walker); \ > - walker += strlen(walker) + 1; \ > - } \ > - if (walker >= ep) \ > - break; > - > - do { > - CP(dev->nameunit); > - CP(dev->desc); > - CP(dev->driver != NULL ? dev->driver->name : NULL); > - bus_child_pnpinfo_str(dev, walker, ep - walker); > - walker += strlen(walker) + 1; > - if (walker >= ep) > - break; > - bus_child_location_str(dev, walker, ep - walker); > - walker += strlen(walker) + 1; > - if (walker >= ep) > - break; > - *walker++ = '\0'; > - } while (0); > -#undef CP > - error = SYSCTL_OUT(req, udev, sizeof(*udev)); > + sbuf_new(&sb, udev->dv_fields, sizeof(udev->dv_fields), SBUF_FIXEDLEN); > + sbuf_cat(&sb, dev->nameunit); > + sbuf_putc(&sb, '\0'); > + sbuf_cat(&sb, dev->desc); > + sbuf_putc(&sb, '\0'); > + sbuf_cat(&sb, dev->driver != NULL ? dev->driver->name : '\0'); > + sbuf_putc(&sb, '\0'); > + bus_child_pnpinfo_sb(dev, &sb); > + sbuf_putc(&sb, '\0'); > + bus_child_location_sb(dev, &sb); > + sbuf_putc(&sb, '\0'); > + error = sbuf_finish(&sb); > + if (error == 0) > + error = SYSCTL_OUT(req, udev, sizeof(*udev)); > + sbuf_delete(&sb); > free(udev, M_BUS); > return (error); > } > -- Mateusz Guzik