From nobody Tue Nov 12 18:45:44 2024 X-Original-To: dev-commits-src-main@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 4XnwNQ17Hdz5cwby; Tue, 12 Nov 2024 18:45:58 +0000 (UTC) (envelope-from jlduran@gmail.com) Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) (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 "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XnwNP4sZFz3wqX; Tue, 12 Nov 2024 18:45:57 +0000 (UTC) (envelope-from jlduran@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-e2905d083d5so334473276.0; Tue, 12 Nov 2024 10:45:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731437156; x=1732041956; h=content-transfer-encoding:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=XC+KEMdEsMFRNsiyy07hPHLKxrQ1gtwma7srQQ5/vcg=; b=ZO990jbsP15axC+wdaGXp3HSmrYNN4xwaVNHEVhPqUdldCC998ca6IkuFj4tR75pcX JIK7UPAB3jOGR9prGbbVxHOakTV4TH21DGawMAu3gkBowj6uJb9ZbyY6+M2I3Up8BZz4 q188tlqwEW516rom3HK4vDUBrZz8aQgUUbW/UqQHg/bOCLSpNTlpI2mSVxv0t4jYdqKH HBo19ShSe0d782pKnXVBSxRSFnWgdqD6pnL74ON2wxr1M4UoMPoBwTMllqec1O64i/M2 k2Rt73YA7E4HgkJhJOOTeGh3IRz3HP469MCcGLZJDwO7xXFnM8qgN4ggEsVjOgwf+lI1 AZvw== X-Forwarded-Encrypted: i=1; AJvYcCUl2DtFrUDmb5I4uDBrrouY8RHOn18ZgPEQFJKHp+f/8ZQncyUHp3nabzVScOOxbV1/XVq3CUcdz6K4Y+BB/PBQtx/sLkk=@freebsd.org, AJvYcCVtUba896dNCn4YmTiblsBBFyPqn8v/u+va4rBT2hl62Wflb5cA2SNlPLL6x3Y4A19JUrkSGWZ9ONZDOOgvLpY=@freebsd.org, AJvYcCWlNOvHsMm+wMZwcWuUJDmInQqB3kx6qyFddtKLsRHT4mKXqPlKyxN9B1wUeoBWg2lx2eL81I6HNR4k7eC+5HBORPRa@freebsd.org X-Gm-Message-State: AOJu0YxWOjzCbmY8VlqiVLOEoP7DaURTi3JLKWOb5Vp9KfnIjkucDkUr pi8wOIpelKuBEYam4I++XyBAezwAwAs/kLhgtkuftwCVK/iyiow+63B2gFDPSVU= X-Google-Smtp-Source: AGHT+IENYGOSYub5gZWwJKohHg31d65SZ+XcJKkTrJAnk5yD7MxgzCQ7WIP/u73wImCqUiTyxKZfXg== X-Received: by 2002:a05:690c:3506:b0:6ea:4d3f:df8c with SMTP id 00721157ae682-6eaddd73a18mr62819567b3.1.1731437156206; Tue, 12 Nov 2024 10:45:56 -0800 (PST) Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com. [209.85.219.169]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb656aasm26677357b3.83.2024.11.12.10.45.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Nov 2024 10:45:55 -0800 (PST) Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e2905d083d5so334468276.0; Tue, 12 Nov 2024 10:45:55 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUv6okY70ewGJueImII2pjRNFeJbeU058WN40hkum2Y+0oPztF+54cEev9Le6QbOZ7dfJxEbFE4RFkK+QpSOkk3x5mt/lc=@freebsd.org, AJvYcCVDR+RlbmODAbDRz0Dktt9Lnaa7N8vZJY4OSJ1QSNZFCJOZBxyteYiIJ7OEnf3cILGGj8AR6het+/NAQjTiv2lN/Jc3@freebsd.org, AJvYcCVPCy8ipdH7Xent7r40IzmCIP2dpkROc26o2eGdIchgvLZN1/cdRrMQFfXUqdoWh+/Yk2WxrLkn0OF5c6mzuMw=@freebsd.org X-Received: by 2002:a05:6902:2847:b0:e2b:dc86:c45d with SMTP id 3f1490d57ef6-e337f86b07bmr5956417276.3.1731437155610; Tue, 12 Nov 2024 10:45:55 -0800 (PST) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 References: <202411120347.4AC3lPOA015167@gitrepo.freebsd.org> <09923ad3-4065-4a31-b35f-74f84e09cff1@FreeBSD.org> <20241112155219.2E15A2DF@slippy.cwsent.com> <20241112160243.B372532F@slippy.cwsent.com> <20241112184111.2CCA53C2@slippy.cwsent.com> In-Reply-To: <20241112184111.2CCA53C2@slippy.cwsent.com> Reply-To: jlduran@freebsd.org From: Jose Luis Duran Date: Tue, 12 Nov 2024 15:45:44 -0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: git: 1fa6daaafd74 - main - ipfilter: Avoid stopping with a lock held To: Cy Schubert Cc: John Baldwin , src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US] X-Rspamd-Queue-Id: 4XnwNP4sZFz3wqX X-Spamd-Bar: ---- On Tue, Nov 12, 2024 at 3:41=E2=80=AFPM Cy Schubert wrote: > > I'm building a test patch on my sandbox machine. The patches in my git re= po > will, > > a) remove another #if 0 from 2013, > b) revert this commit, > c) fix the "stopping with lock held" bug > > Testing on the sandbox is needed before I submit a review. > > You can revert this if you want, or I can push my three commits when my > testing is complete. I'll revert the commit, I feel better with this approach, thank you! > > > -- > Cheers, > Cy Schubert > FreeBSD UNIX: Web: https://FreeBSD.org > NTP: Web: https://nwtime.org > > e^(i*pi)+1=3D0 > > > In message om> > , Jose Luis Duran writes: > > What would be the recommended approach in this case? > > Revert, and commit with the fixes, or just fix the problematic code. > > > > At any rate, I have created https://reviews.freebsd.org/D47530. Feel > > free to commandeer it, as my testing is limited to what's currently in > > the "Test Plan". I was not able to recreate the deadlock described > > here, but it definitely makes sense. > > > > On Tue, Nov 12, 2024 at 1:02=3DE2=3D80=3DAFPM Cy Schubert > com> wrote: > > > > > > In message <20241112155219.2E15A2DF@slippy.cwsent.com>, Cy Schubert w= rite=3D > > s: > > > > In message <09923ad3-4065-4a31-b35f-74f84e09cff1@FreeBSD.org>, John= Bal=3D > > dwin > > > > wri > > > > tes: > > > > > On 11/11/24 19:47, Jose Luis Duran wrote: > > > > > > The branch main has been updated by jlduran: > > > > > > > > > > > > URL: https://cgit.FreeBSD.org/src/commit/?id=3D3D1fa6daaafd74c1= a457dc=3D > > fe26e0a5 > > > > 94 > > > > > 3b5441dc9d > > > > > > > > > > > > commit 1fa6daaafd74c1a457dcfe26e0a5943b5441dc9d > > > > > > Author: Jose Luis Duran > > > > > > AuthorDate: 2024-11-02 17:58:59 +0000 > > > > > > Commit: Jose Luis Duran > > > > > > CommitDate: 2024-11-12 03:46:15 +0000 > > > > > > > > > > > > ipfilter: Avoid stopping with a lock held > > > > > > > > > > > > Avoid calling _callout_stop_safe with a non-sleepable lock= hel=3D > > d when > > > > > > detaching by initializing callout_init_rw() with CALLOUT_S= HARE=3D > > DLOCK. > > > > > > > > > > > > It avoids the following WITNESS warning when stopping the = serv=3D > > ice: > > > > > > > > > > > > # service ipfilter stop > > > > > > calling _callout_stop_safe with the following non-slee= pabl=3D > > e lock > > > > s > > > > > held: > > > > > > shared rw ipf filter load/unload mutex (ipf filter loa= d/un=3D > > load m > > > > ut > > > > > ex) r =3D3D 0 (0xffff0000417c7530) locked @ /usr/src/sys/netpfil/= ipfilt=3D > > er/netin > > > > et > > > > > /fil.c:7926 > > > > > > stack backtrace: > > > > > > #0 0xffff00000052d394 at witness_debugger+0x60 > > > > > > #1 0xffff00000052e620 at witness_warn+0x404 > > > > > > #2 0xffff0000004d4ffc at _callout_stop_safe+0x8c > > > > > > #3 0xffff0000f7236674 at ipfdetach+0x3c > > > > > > #4 0xffff0000f723fa4c at ipf_ipf_ioctl+0x788 > > > > > > #5 0xffff0000f72367e0 at ipfioctl+0x144 > > > > > > #6 0xffff00000034abd8 at devfs_ioctl+0x100 > > > > > > #7 0xffff0000005c66a0 at vn_ioctl+0xbc > > > > > > #8 0xffff00000034b2cc at devfs_ioctl_f+0x24 > > > > > > #9 0xffff0000005331ec at kern_ioctl+0x2e0 > > > > > > #10 0xffff000000532eb4 at sys_ioctl+0x140 > > > > > > #11 0xffff000000880480 at do_el0_sync+0x604 > > > > > > #12 0xffff0000008579ac at handle_el0_sync+0x4c > > > > > > > > > > > > PR: 282478 > > > > > > Suggested by: markj > > > > > > Reviewed by: cy > > > > > > Approved by: emaste (mentor) > > > > > > MFC after: 1 week > > > > > > --- > > > > > > sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c | 4 ++-- > > > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > > > > > > > diff --git a/sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c b/sy= s/ne=3D > > tpfil/ > > > > ip > > > > > filter/netinet/ip_fil_freebsd.c > > > > > > index bcde0d2c7323..b3dea40c3d8c 100644 > > > > > > --- a/sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c > > > > > > +++ b/sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c > > > > > > @@ -181,7 +181,7 @@ ipf_timer_func(void *arg) > > > > > > #if 0 > > > > > > softc->ipf_slow_ch =3D3D timeout(ipf_timer_fu= nc, so=3D > > ftc, hz/ > > > > 2); > > > > > > #endif > > > > > > - callout_init(&softc->ipf_slow_ch, 1); > > > > > > + callout_init_rw(&softc->ipf_slow_ch, &softc->ipf_glob= al.i=3D > > pf_lk, > > > > > CALLOUT_SHAREDLOCK); > > > > > > callout_reset(&softc->ipf_slow_ch, > > > > > > (hz / IPF_HZ_DIVIDE) * IPF_HZ_MULT, > > > > > > ipf_timer_func, softc); > > > > > > @@ -221,7 +221,7 @@ ipfattach(ipf_main_softc_t *softc) > > > > > > softc->ipf_slow_ch =3D3D timeout(ipf_timer_func, soft= c, > > > > > > (hz / IPF_HZ_DIVIDE) * I= PF_H=3D > > Z_MULT > > > > ); > > > > > > #endif > > > > > > - callout_init(&softc->ipf_slow_ch, 1); > > > > > > + callout_init_rw(&softc->ipf_slow_ch, &softc->ipf_global.ipf_l= k, C=3D > > ALLOUT > > > > > _SHAREDLOCK); > > > > > > callout_reset(&softc->ipf_slow_ch, (hz / IPF_HZ_DIVID= E) *=3D > > IPF_H > > > > Z_MULT, > > > > > > ipf_timer_func, softc); > > > > > > return (0); > > > > > > > > > > But this means the callout is now called with the lock held, and = I do=3D > > n't se > > > > e > > > > > any changes > > > > > to ipf_timer_func. Hmm, so you now recurse on the lock? You nee= d to=3D > > take > > > > ou > > > > > t the locking > > > > > in ipf_timer_func I think as it is now spurious. You can also ax= e th=3D > > e #if > > > > 0' > > > > > d code around > > > > > timeout() while you are at it. > > > > > > > > Reviewing all the #if 0's in ipfilter, discovering why they are the= re, =3D > > and > > > > either removing them or implementing what Darren had initially inte= nded=3D > > is > > > > in my queue. The upstream git log isn't helpful for reasons I preac= h ab=3D > > out > > > > proper commit logs. > > > > > > > > Given that this one is in ip_fil_freebsd.c (specific to FreeBSD), i= t ca=3D > > n be > > > > removed. Others require more grokking. > > > > > > It can go. It was #if 0'd by ea3022cbbd3f5, IIRC in discussion with y= ou a=3D > > t > > > the time (2013). > > > > > > ea3022cbbd3f5 converted timeout(9) to callout(9). This code remained = as a=3D > > n > > > artifact of the conversion. It was sent by you to me following the ip= filt=3D > > er > > > upgrade from 4.1.28 to 5.1.2 earlier that year. > > > > > > > > > -- > > > Cheers, > > > Cy Schubert > > > FreeBSD UNIX: Web: https://FreeBSD.org > > > NTP: Web: https://nwtime.org > > > > > > e^(i*pi)+1=3D3D0 > > > > > > > > > > > > > > > > > > > > > --=3D20 > > Jose Luis Duran > > --=20 Jose Luis Duran