From owner-freebsd-current@freebsd.org Fri Feb 5 18:34:04 2016 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D1283A761FE for ; Fri, 5 Feb 2016 18:34:04 +0000 (UTC) (envelope-from oliver.pinter@hardenedbsd.org) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id B2DD7983 for ; Fri, 5 Feb 2016 18:34:04 +0000 (UTC) (envelope-from oliver.pinter@hardenedbsd.org) Received: by mailman.ysv.freebsd.org (Postfix) id B28DFA761FD; Fri, 5 Feb 2016 18:34:04 +0000 (UTC) Delivered-To: current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B2209A761FC for ; Fri, 5 Feb 2016 18:34:04 +0000 (UTC) (envelope-from oliver.pinter@hardenedbsd.org) Received: from mail-wm0-x22f.google.com (mail-wm0-x22f.google.com [IPv6:2a00:1450:400c:c09::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D10A97F for ; Fri, 5 Feb 2016 18:34:04 +0000 (UTC) (envelope-from oliver.pinter@hardenedbsd.org) Received: by mail-wm0-x22f.google.com with SMTP id r129so38842536wmr.0 for ; Fri, 05 Feb 2016 10:34:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hardenedbsd-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Md4mDO2hb+8K9jbVQllxBqYMSOm0Tj8blYnRinkTeaA=; b=xqBa4m3Nr1/tJzV7rPGMXKU5dt47S0Tvpiydzh7TK+aL+d7ogAHnAEm4jlDbJKVMC0 0R2ySDEpUysXz0YDnZv0Anfs8W3P4DwJn2uYMAJ8owGCipdLlSb+4CUHvZA4ZsfzxZA9 BtEPq2O1Z/rRnxrITOpv/fcjTFjac1DA/gT+GVnOcVDqzec4ljrj0KZoXOLBSUPq7+gz RzO8wHQex4mlRvY2TgaHW4FMvVPr12j2BdZISKIe6LkkFSm/LUYhhSaIopQuFF1a/IGL 1eC4Ne09e3njcBR2TwR+d9viO+VNr7GkZxBzRTdbao0H9a/9CJUqeajw3e8d6QA3VLer pNzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=Md4mDO2hb+8K9jbVQllxBqYMSOm0Tj8blYnRinkTeaA=; b=TjFmjjsDczc2FIX4NxTzsOed/4Uz4rJwCwPW1HNwO25vC9b/fyKsaV4q+zfgToI6rn XvvGRHPg5WgAJMfnqcpmEQ1EfJeaQGMJCdQa4s7vS601dLOtjjAM9Et3TYl9f7aukiR3 C2g8SBbmMr2F9j8ZqvP7BiPGgQ2w70r7OPweArzrYdSybpgplGTaspXfrEejRMon/AQG F7zOlm0J8hNU3F4LQZnvsLy1SoGcro6dR/XYFDcQ3yLXhqoprqUMg4u+lGddFJ5nVFCt q/LlxHyNuoID3BwHM5BAkMSRhk3YT1oaYloKykQyT2Fbt2So3ivX7cvceqeyL3RMo9vb HwiA== X-Gm-Message-State: AG10YOSd1lHolgRJd5fjYMmKQM436zkcVE67ScIEyOrwRczM5rGJmw1mir3G7Icf1TJKuJ3LnWBTH5cvy+vtUb81 MIME-Version: 1.0 X-Received: by 10.28.184.78 with SMTP id i75mr18484933wmf.22.1454697242703; Fri, 05 Feb 2016 10:34:02 -0800 (PST) Received: by 10.194.82.6 with HTTP; Fri, 5 Feb 2016 10:34:02 -0800 (PST) In-Reply-To: References: Date: Fri, 5 Feb 2016 19:34:02 +0100 Message-ID: Subject: Re: Broken suspend-resume (suspend to RAM) with enabled INVARIANTS on 11-CURRENT - with workaround From: Oliver Pinter To: current Cc: Konstantin Belousov Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Feb 2016 18:34:05 -0000 On 2/5/16, Oliver Pinter wrote: > Hi all! > > I used this gdb macro, to traverse the proc list, and print out the > relevant p_flag's flags: > > set $curr_proc=0 > def next_proc > if $curr_proc == 0 > set $curr_proc = allproc.lh_first > else > set $curr_proc = $curr_proc.p_list.le_next > end > set $curr_p_flag = $curr_proc->p_flag > set $curr_name = $curr_proc->p_comm > p $curr_name > p/x $curr_p_flag > if ($curr_p_flag & 0x00004) != 0 > printf "is P_KTHREAD\n" > else > printf "isn't P_KTHREAD\n" > end > if ($curr_p_flag & 0x00200) != 0 > printf "is P_SYSTEM\n" > else > printf "isn't P_SYSTEM\n" > end > end > > And seems like the "kernel" process don't have the P_KTHREAD flag, > which fires the KASSERT in sys/kern/kern_proc.c's stop_all_proc(void) > function. > > The relevant part of the code is: > 2986 void > 2987 stop_all_proc(void) > 2988 { > 2989 struct proc *cp, *p; > 2990 int r, gen; > 2991 bool restart, seen_stopped, seen_exiting, stopped_some; > 2992 > 2993 cp = curproc; > 2994 /* > 2995 * stop_all_proc() assumes that all process which have > 2996 * usermode must be stopped, except current process, for > 2997 * obvious reasons. Since other threads in the process > 2998 * establishing global stop could unstop something, disable > 2999 * calls from multithreaded processes as precaution. The > 3000 * service must not be user-callable anyway. > 3001 */ > *3002 KASSERT((cp->p_flag & P_HADTHREADS) == 0 || > *3003 (cp->p_flag & P_KTHREAD) != 0, ("mt stop_all_proc")); > 3004 > 3005 allproc_loop: > > If I comment out this KASSERT or just whitelist the "kernel" process, > then I get a completely working suspend to ram and resume on my laptop > (which is a HP 430G1) with one additional small tweak > (hw.acpi.reset_video=1). > > So the question is that the KASSERT is bogus or too strict, or the > P_KTHREAD flags is missing from "kernel" process? > > The gdb macros output is: > [...] > (kgdb) > $139 = 0xfffff800029773c8 "rand_harvestq" > $140 = 0x10000204 > is P_KTHREAD > is P_SYSTEM > (kgdb) > $141 = 0xfffff80002977940 "init" > $142 = 0x10004200 > isn't P_KTHREAD > is P_SYSTEM > (kgdb) > $143 = 0xfffff800029783c8 "audit" > $144 = 0x10000204 > is P_KTHREAD > is P_SYSTEM > (kgdb) > $145 = 0xffffffff80f1b4d0 "kernel" > $146 = 0x10000280 > isn't P_KTHREAD > is P_SYSTEM > > I've CC-ed Konstantin to this discussion, because he added this > functionality to the kernel. > > Additional info: > If I try to trigger the KASSERT with the debug.stop_all_proc=1 sysctl, > then it's never fires, but when I try to put my machine to S3 with > ctrl+alt+space then it fires. > Not yet tested, but possible fix: diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index cb952da..25bae84 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -482,7 +482,7 @@ proc0_init(void *dummy __unused) session0.s_leader = p; p->p_sysent = &null_sysvec; - p->p_flag = P_SYSTEM | P_INMEM; + p->p_flag = P_SYSTEM | P_INMEM | P_KTHREAD; p->p_flag2 = 0; p->p_state = PRS_NORMAL; #ifdef PAX