From nobody Tue Nov 12 15:05:43 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 4XnqVM4xRdz5cfTL; Tue, 12 Nov 2024 15:05:47 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) (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 4XnqVL75MWz4QwC; Tue, 12 Nov 2024 15:05:46 +0000 (UTC) (envelope-from markjdb@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-qk1-x732.google.com with SMTP id af79cd13be357-7b13bf566c0so342409185a.3; Tue, 12 Nov 2024 07:05:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731423946; x=1732028746; darn=freebsd.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=qEAcFMlBhiS6EFchhHhQXMFiDVZ8LxwyYas3DWHa0Ys=; b=SWsRK2dUqh8RqJkVgPfktDrpBnbXRFq3BA+gFCKxxtAKdevOT/APnnMlKGxv3RvSO9 esM7VC4M0CZWs0BH3Wy+uQkXIQ48tP5AEhB5+VEqXEnajMBdeuWOrysTymkjMe+zVpWJ AiBR5iRZqKglTePAxajZ+xD6LZmcVsKX6qvr4qNQgy1tH9B80Qt5ulK9v/GAH/gYuaUE LnKnOUWAdcsZkHaoj4Vy7wAb+T4Ju7pGa7G01rig4CHJpGfPs1F6DH4lrfsy+DHzIejz bsj6qvsMuJpgwl8zl5S8v0qCe8a4MUHv/IiTk905zOoWqVAm4kkuLh96QJwxUr1Xcvde l0aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731423946; x=1732028746; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qEAcFMlBhiS6EFchhHhQXMFiDVZ8LxwyYas3DWHa0Ys=; b=IBTEY8QRjKDRWU2iYaZp8TYT1DfBtxdtuPwFlWhSmGQYYes+yuIVc6rqd1AlhpNnZt ozwLtLt2S86kE1DcaxCgh/nZGC7VtMxeg+nMkOMksFziwx1LwnW9ctztHtF3X5lsW6Yz HaXNs6+NjGMibbKWqnefkaUF+EcuWP0OqqmGlUoh4rlfUEDYWEyhsUMhCWQ7CpPqeZwk IDYZ+/h6MvPr4CgL7BfQz41CVFKvMeVaHrPDVSuP2/7TQWcp96q6+JlyEaVrWdvqoDck OclDP5n+JmdZBYzK1pUAPh99nYZxaJO9jWAvqrYnVtKvKa8lxLxLFwMqM62jO1IMLl/g WSmg== X-Forwarded-Encrypted: i=1; AJvYcCWHiJV9kEd3fiMWFtkxSzB/t5j4KYCS7fog7wrLeEuRzJum9MbGEc3YxqS3oKRmeX2wkxuXNU6WDWoN3gq36kni5FyY@freebsd.org, AJvYcCXXeEkWyN2pfz5TiR1R3R4rcVbnExMB4HReh47ZtbM4d0CC3Z9PzVFrixvYECOdSOwkI3d1acbrdf57uM47ZXMVzeE9azo=@freebsd.org X-Gm-Message-State: AOJu0YxAK6YOgRA/zpEA5f5qhRiynn8WpPXT2us+4IPGNTz4NTS2gEPG pFw11MBfeJyyOgbTDAwjPaSPEn/O4ceEQH+TM9lAOifjQnAYWzXDGUtxiw== X-Google-Smtp-Source: AGHT+IGI1OWlHYumFlF8n5RMLwqOYl9a+XMieCyMfiRVaV31H5CO0pzDCssk6tYFx5h+GL25rdCW0w== X-Received: by 2002:a05:620a:4712:b0:7b1:45be:2e89 with SMTP id af79cd13be357-7b34bb175c5mr318985185a.17.1731423945787; Tue, 12 Nov 2024 07:05:45 -0800 (PST) Received: from nuc (192-0-220-237.cpe.teksavvy.com. [192.0.220.237]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32acf6c46sm597892885a.127.2024.11.12.07.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 07:05:45 -0800 (PST) Date: Tue, 12 Nov 2024 10:05:43 -0500 From: Mark Johnston To: Jose Luis Duran Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 1fa6daaafd74 - main - ipfilter: Avoid stopping with a lock held Message-ID: References: <202411120347.4AC3lPOA015167@gitrepo.freebsd.org> 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202411120347.4AC3lPOA015167@gitrepo.freebsd.org> 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:2607:f8b0::/32, country:US] X-Rspamd-Queue-Id: 4XnqVL75MWz4QwC X-Spamd-Bar: ---- On Tue, Nov 12, 2024 at 03:47:25AM +0000, Jose Luis Duran wrote: > The branch main has been updated by jlduran: > > URL: https://cgit.FreeBSD.org/src/commit/?id=1fa6daaafd74c1a457dcfe26e0a5943b5441dc9d > > 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 held when > detaching by initializing callout_init_rw() with CALLOUT_SHAREDLOCK. > > It avoids the following WITNESS warning when stopping the service: > > # service ipfilter stop > calling _callout_stop_safe with the following non-sleepable locks held: > shared rw ipf filter load/unload mutex (ipf filter load/unload mutex) r = 0 (0xffff0000417c7530) locked @ /usr/src/sys/netpfil/ipfilter/netinet/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/sys/netpfil/ipfilter/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 = timeout(ipf_timer_func, softc, hz/2); > #endif > - callout_init(&softc->ipf_slow_ch, 1); > + callout_init_rw(&softc->ipf_slow_ch, &softc->ipf_global.ipf_lk, CALLOUT_SHAREDLOCK); I didn't notice this before, but it's unnecessary to reinitialize the callout each time the timeout function fires. The initialization only needs to be done once. > 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 = timeout(ipf_timer_func, softc, > (hz / IPF_HZ_DIVIDE) * IPF_HZ_MULT); > #endif > - callout_init(&softc->ipf_slow_ch, 1); > + callout_init_rw(&softc->ipf_slow_ch, &softc->ipf_global.ipf_lk, CALLOUT_SHAREDLOCK); > callout_reset(&softc->ipf_slow_ch, (hz / IPF_HZ_DIVIDE) * IPF_HZ_MULT, > ipf_timer_func, softc); > return (0); I think part of this diff is missing. The timeout function still tries to acquire this rwlock, and now it'll deadlock since the callout framework will have already acquired it as a result of this change.