From owner-freebsd-current@freebsd.org Fri Oct 23 16:32:29 2020 Return-Path: Delivered-To: freebsd-current@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 6AD6144A5CC; Fri, 23 Oct 2020 16:32:29 +0000 (UTC) (envelope-from melounmichal@gmail.com) Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) (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 4CHqWw1K5Cz4LC2; Fri, 23 Oct 2020 16:32:28 +0000 (UTC) (envelope-from melounmichal@gmail.com) Received: by mail-wm1-x32b.google.com with SMTP id c16so2422422wmd.2; Fri, 23 Oct 2020 09:32:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:reply-to:subject:to:cc:references :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=LSOUjr7+2UhBbH5lMeRHhjAn/gqy5kvPoW84yNGTZAA=; b=oojZWDiTuSiA72HfTbyeQvfzdtKdWK/UGgFms7+c1cvRhBCSSnWdSRsTBqdg6h+inO J2Nm8hOxVnZN59Us7ys/O+BtEyMpRhpDEoLZBcRIxs6kDq1wvPFuuoAL3EO+mSPqVXdN 51VBt3n1J7Jxrara9eY16qq8knQ3yFz8RJGaIkTGVeQVKJcnIfMXJWpyGdLmqkYkS5K7 PCmhFIaDak1hQYI3wSJ8l8WgvKNAkY3uYj3eCuLGtBDcpj5nIW/AjncOfOju9ZCEh+tv GZHuTCT2mtVN9/X4+B7iH7RHvmckYVVNbPgO3ZfTwJSL6owkNKdH2/9JhGWR5AYJR6Ku D3Uw== X-Gm-Message-State: AOAM530t2ok5VYMNuo+9NUze7iEKo6dM0kK3iHyqFZw52FGJMeSbKjUa zUxvMVOGVxW7excNyb4UhDR8mpsRILY= X-Google-Smtp-Source: ABdhPJz2oGzdzc88aTvyy51uChxw46YxZAdpTt8eOt+SYv9OB/9wUlxfhZuHVZFleFXhFAcCdULuug== X-Received: by 2002:a7b:c114:: with SMTP id w20mr57783wmi.105.1603470746483; Fri, 23 Oct 2020 09:32:26 -0700 (PDT) Received: from [88.208.79.100] (halouny.humusoft.cz. [88.208.79.100]) by smtp.gmail.com with ESMTPSA id x1sm3961916wrl.41.2020.10.23.09.32.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Oct 2020 09:32:25 -0700 (PDT) Sender: Michal Meloun From: Michal Meloun X-Google-Original-From: Michal Meloun Reply-To: mmel@freebsd.org Subject: Re: panic: non-current pmap 0xffffa00020eab8f0 on Rpi3 To: Mark Johnston Cc: bob prohaska , freebsd-current@freebsd.org, freebsd-arm@freebsd.org References: <20201006021029.GA13260@www.zefox.net> <20201006133743.GA96285@raichu> <20201019203954.GC46122@raichu> Message-ID: <454e1e9f-e839-8961-2ae1-9ddd86f1cefd@freebsd.org> Date: Fri, 23 Oct 2020 18:32:25 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <20201019203954.GC46122@raichu> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4CHqWw1K5Cz4LC2 X-Spamd-Bar: -- X-Spamd-Result: default: False [-2.43 / 15.00]; HAS_REPLYTO(0.00)[mmel@freebsd.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; NEURAL_HAM_SHORT(-0.46)[-0.459]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; TAGGED_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.99)[-0.994]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; NEURAL_HAM_LONG(-0.98)[-0.976]; MIME_GOOD(-0.10)[text/plain]; REPLYTO_DOM_NEQ_FROM_DOM(0.00)[]; MID_RHS_MATCH_TO(1.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::32b:from]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[freebsd-arm,freebsd-current] X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.33 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, 23 Oct 2020 16:32:29 -0000 On 19.10.2020 22:39, Mark Johnston wrote: > On Fri, Oct 16, 2020 at 11:53:56AM +0200, Michal Meloun wrote: >> >> >> On 06.10.2020 15:37, Mark Johnston wrote: >>> On Mon, Oct 05, 2020 at 07:10:29PM -0700, bob prohaska wrote: >>>> Still seeing non-current pmap panics on the Pi3, this time a B+ running >>>> 13.0-CURRENT (GENERIC-MMCCAM) #0 71e02448ffb-c271826(master) >>>> during a -j4 buildworld. The backtrace reports >>>> >>>> panic: non-current pmap 0xffffa00020eab8f0 >>> >>> Could you show the output of "show procvm" from the debugger? >> >> I see same panic too, in my case its very rare - typical scenario is >> rebuild of kf5 ports (~250, 2 days of full load). Any idea how to debug >> this? >> Michal > > I suspect that there is some race involving the pmap switching in > vmspace_exit(), but I can't see it. In the example below, presumably > process 22604 on CPU 0 is also exiting? Could you show the backtrace?> > It would also be useful to see the value of PCPU_GET(curpmap) at the > time of the panic. I'm not sure if there's a way to get that from DDB, > but I suspect it should be equal to &vmspace0->vm_pmap. Mark, I think that I found problem. The PCPU_GET() is not (and is not supposed to be) an atomic operation, it expects that thread is at least pinned. This is not true for pmap_remove_pages() - so I think that the KASSERT is racy and shoud be removed (or at least covered by sched_pin()/sched_unpin() pair). What do you think? > > I think vmspace_exit() should issue a release fence with the cmpset and > an acquire fence when handling the refcnt == 1 case, Yep, true, fully agree. Michal but I don't see why > that would make a difference here. So, if you can test a debug patch, > this one will yield a bit more debug info. If you can provide access to > a vmcore and kernel debug symbols, that'd be even better. > > diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c > index 284f00b3cc0d..3c53ae3b4c1e 100644 > --- a/sys/arm64/arm64/pmap.c > +++ b/sys/arm64/arm64/pmap.c > @@ -4838,7 +4838,8 @@ pmap_remove_pages(pmap_t pmap) > int allfree, field, freed, idx, lvl; > vm_paddr_t pa; > > - KASSERT(pmap == PCPU_GET(curpmap), ("non-current pmap %p", pmap)); > + KASSERT(pmap == PCPU_GET(curpmap), > + ("non-current pmap %p %p", pmap, PCPU_GET(curpmap))); > > lock = NULL; > > diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c > index c20005ae64cf..0ad415e3b88c 100644 > --- a/sys/vm/vm_map.c > +++ b/sys/vm/vm_map.c > @@ -358,7 +358,10 @@ vmspace_exit(struct thread *td) > p = td->td_proc; > vm = p->p_vmspace; > atomic_add_int(&vmspace0.vm_refcnt, 1); > - refcnt = vm->vm_refcnt; > + refcnt = atomic_load_int(&vm->vm_refcnt); > + > + KASSERT(vmspace_pmap(vm) == PCPU_GET(curpmap), > + ("non-current pmap %p %p", pmap, PCPU_GET(curpmap))); > do { > if (refcnt > 1 && p->p_vmspace != &vmspace0) { > /* Switch now since other proc might free vmspace */ >