From nobody Mon Mar 07 16:45:02 2022 X-Original-To: freebsd-arm@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 8A3E31A051E3; Mon, 7 Mar 2022 16:45:18 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) (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 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KC47x4SgQz4j3s; Mon, 7 Mar 2022 16:45:17 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by mail-qt1-x832.google.com with SMTP id 11so13716589qtt.9; Mon, 07 Mar 2022 08:45:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=5UYaPmaTEqBJoZRQrb8hIFwZZsI3StJpQcF7a5ffnfk=; b=IUstT1RgGaFjTpv9oNTVMo1dYUCStoh3nxph2gw4dwsis6vbIOGlGWPlVWAstKDebr acR6FfELyFpfuz6HielHo7OC62fd8tdEimZ85ZSVRmrcKm2w2NlRvhFUlLZJzPhgx3UD BJW2XvkIOysMA72JUnidH8VmMBwZONz0K13vC2W3TOpffCfekoK9d7WewwfJa1TLproh jZr1r/fxA8buyNSNFATRH/9CdYjZ/5bUZ12wYeNjwS7gE2qlR375pgQGV3JZx5RNp+4x 1KBf4d7BlC9e2eYSaSFiMCPkuoG9jiR3sw0KBlssdXvgk2X4B94RNLFDDGhX/3Na9thJ n4pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=5UYaPmaTEqBJoZRQrb8hIFwZZsI3StJpQcF7a5ffnfk=; b=xsKBbnhS7/xUTi4pItNkI5W4Gtug28BlrRC9LuOsx3YMeDkwIfWkG6OaTgzLlySNpE FDApXEz8M/JjaPdAdi/KQ9PCEqDcymTm+z1KiIbIDUhdAsMBopSZuI8kdhXeffy28D25 zA1zXCHGML4x3kdJpzl/6qkE5PtjsbnGQ0a495QH9+fbbHTPeQViz6AXw9KIQFbygGJg xj0bHq2IypDQQNzWwRkfVpgf9SLMWFmDgTfhLeawlUKkFetfLZ5x1iLS/Jrcq98qYi/3 wYf4WCJ6jtLmTK/V0muHrwqNfnA3wcHBSDXbpaBKqR7NH3K4vS3tE8vD2XfYLHUXfTsv ZN9g== X-Gm-Message-State: AOAM530uvVmimp3lSx1/E3lblh6r1PjRY9bWhkcLoxBGgXl7hjdkzEgl y/g4L0+Ek+eCdBV12FJ3jdY= X-Google-Smtp-Source: ABdhPJzlc0Zggspr8Cto8dM8HsXuYqdkHYszZmwu09XKCJ89gVohiVxquCEfHtkVH4aSHYXG1GX8xQ== X-Received: by 2002:ac8:5c4e:0:b0:2de:7191:7480 with SMTP id j14-20020ac85c4e000000b002de71917480mr10169763qtj.489.1646671511395; Mon, 07 Mar 2022 08:45:11 -0800 (PST) Received: from nuc (198-84-189-58.cpe.teksavvy.com. [198.84.189.58]) by smtp.gmail.com with ESMTPSA id 15-20020ac8570f000000b002e05a1f990dsm4841181qtw.65.2022.03.07.08.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 08:45:10 -0800 (PST) Date: Mon, 7 Mar 2022 11:45:02 -0500 From: Mark Johnston To: Andrew Turner Cc: Ronald Klop , bob prohaska , Mark Millard , freebsd-arm@freebsd.org, freebsd-current Subject: Re: panic: data abort in critical section or under mutex (was: Re: panic: Unknown kernel exception 0 esr_el1 2000000 (on 14-CURRENT/aarch64 Feb 28)) Message-ID: References: <1800459695.1.1646649539521@mailrelay> <132978150.92.1646660769467@mailrelay> <3374E0F8-D712-4ED0-A62B-B6924FC8A5E2@fubar.geek.nz> List-Id: Porting FreeBSD to ARM processors List-Archive: https://lists.freebsd.org/archives/freebsd-arm List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-arm@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3374E0F8-D712-4ED0-A62B-B6924FC8A5E2@fubar.geek.nz> X-Rspamd-Queue-Id: 4KC47x4SgQz4j3s X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=IUstT1Rg; dmarc=none; spf=pass (mx1.freebsd.org: domain of markjdb@gmail.com designates 2607:f8b0:4864:20::832 as permitted sender) smtp.mailfrom=markjdb@gmail.com X-Spamd-Result: default: False [-0.70 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; RCPT_COUNT_FIVE(0.00)[6]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[gmail.com:+]; FORGED_SENDER(0.30)[markj@freebsd.org,markjdb@gmail.com]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[markj@freebsd.org,markjdb@gmail.com]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20210112]; FROM_HAS_DN(0.00)[]; NEURAL_SPAM_SHORT(1.00)[1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::832:from]; MLMMJ_DEST(0.00)[freebsd-arm,freebsd-current]; MID_RHS_NOT_FQDN(0.50)[]; FREEMAIL_CC(0.00)[klop.ws,www.zefox.net,yahoo.com,freebsd.org]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N On Mon, Mar 07, 2022 at 04:25:22PM +0000, Andrew Turner wrote: > > > On 7 Mar 2022, at 15:13, Mark Johnston wrote: > > ... > > A (the?) problem is that the compiler is treating "pc" as an alias > > for x18, but the rmlock code assumes that the pcpu pointer is loaded > > once, as it dereferences "pc" outside of the critical section. On > > arm64, if a context switch occurs between the store at _rm_rlock+144 and > > the load at +152, and the thread is migrated to another CPU, then we'll > > end up using the wrong CPU ID in the rm->rm_writecpus test. > > > > I suspect the problem is unique to arm64 as its get_pcpu() > > implementation is different from the others in that it doesn't use > > volatile-qualified inline assembly. This has been the case since > > https://cgit.freebsd.org/src/commit/?id=63c858a04d56529eddbddf85ad04fc8e99e73762 > > . > > > > I haven't been able to reproduce any crashes running poudriere in an > > arm64 AWS instance, though. Could you please try the patch below and > > confirm whether it fixes your panics? I verified that the apparent > > problem described above is gone with the patch. > > Alternatively (or additionally) we could do something like the following. There are only a few MI users of get_pcpu with the main place being in rm locks. > > diff --git a/sys/arm64/include/pcpu.h b/sys/arm64/include/pcpu.h > index 09f6361c651c..59b890e5c2ea 100644 > --- a/sys/arm64/include/pcpu.h > +++ b/sys/arm64/include/pcpu.h > @@ -58,7 +58,14 @@ struct pcpu; > > register struct pcpu *pcpup __asm ("x18"); > > -#define get_pcpu() pcpup > +static inline struct pcpu * > +get_pcpu(void) > +{ > + struct pcpu *pcpu; > + > + __asm __volatile("mov %0, x18" : "=&r"(pcpu)); > + return (pcpu); > +} > > static inline struct thread * > get_curthread(void) Indeed, I think this is probably the best solution.