From owner-freebsd-net@freebsd.org Fri Jul 17 10:03:23 2020 Return-Path: Delivered-To: freebsd-net@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 43E853603BF for ; Fri, 17 Jul 2020 10:03:23 +0000 (UTC) (envelope-from zec@fer.hr) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60079.outbound.protection.outlook.com [40.107.6.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mail.protection.outlook.com", Issuer "GlobalSign Organization Validation CA - SHA256 - G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4B7RX96rN2z3bqy for ; Fri, 17 Jul 2020 10:03:21 +0000 (UTC) (envelope-from zec@fer.hr) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fCnl1oHo4A2+qHLbnND/J9dFCbXHSqk2wHiRov3JmURok05ZXUmEM1S5Kgv6lpve6LKAZqe1v/6nRYR0wFulUDa/B8sjw5P/Pd2UqjoEY5WBTvfZVl4YvtP5kX/FzmgkB6dAliKJBacIXqX8j5HFWdXsoxpFEcxQ5oqlazRfwEPpupCI5LvwLLsmo/ZjR6SO75vhrGjjAlmCrXbFc12NS62xzL0sJHSUPuj6oG/oOt9oShcvqhRHQo41+LpON340FZKP/xpXOUzcu3qLXi/Cg2X87ew2i+9CUkdPMwmX38Gl2IY4WEzt1oz3LtoV3sKhvczv97KNujchVJQywGn2UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EVwRhj8mHTJ6XjvU4itwsSO/7mG3n3h2BS9q9+FQiRY=; b=EAt2J2/ZaNF5qKlIKpereys21O1wOj3iNerglnrQVA/4L/zdBYeF+qDc+SeHR7gmC/ze3Mo+yklvCOcnvDjHrvbEtH87hoibH/Fn8VlTSuwCgpOkbRxvgW/Q5WTKAsZkaHA78gMUJaGYayTGGAwUtSWqqIw37VNNVT5UXVS+stzauxbAw7UeUjNTaq+S+zMQvyQVovuknZF4J9fE5SabSav2ceNC2iouRRZNP0R0qu7Ro5Phm5B+kZYL1wHdG0cLU1/Jm32zl0LXbgtVSaRYUib+A3bkqvmAS3TQv6q/pwONcLW6gwwP0ba3hoTq+Kq/5aOLkFaJMi0r9n2GQ6MgTg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fer.hr; dmarc=pass action=none header.from=fer.hr; dkim=pass header.d=fer.hr; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ferhr.onmicrosoft.com; s=selector2-ferhr-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EVwRhj8mHTJ6XjvU4itwsSO/7mG3n3h2BS9q9+FQiRY=; b=c3XGAC7jByg2DctnnVrkb9jMLgzlW1r7S9sn6rxbHZSvoAhKYngSY5S0AbH3E81VsZJZlGFvMStaX+BG4QUPf521F3nwKfaLck2d4piI8QrUQBi3O6jBjcwiuyiXd7f5BkUACKDmv7uw5Lso4voJ73zmAjH0IhBQPyo7QelHp/w= Received: from VE1PR08MB4783.eurprd08.prod.outlook.com (2603:10a6:802:a9::16) by VI1PR08MB3984.eurprd08.prod.outlook.com (2603:10a6:803:e9::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Fri, 17 Jul 2020 10:03:19 +0000 Received: from VE1PR08MB4783.eurprd08.prod.outlook.com ([fe80::c8e:e335:c7:319b]) by VE1PR08MB4783.eurprd08.prod.outlook.com ([fe80::c8e:e335:c7:319b%3]) with mapi id 15.20.3195.022; Fri, 17 Jul 2020 10:03:19 +0000 Date: Fri, 17 Jul 2020 12:03:11 +0200 From: Marko Zec To: John-Mark Gurney Cc: freebsd-net@FreeBSD.org Subject: Re: IF_DRV_PREPEND unlocked? Message-ID: <20200717120311.59377e0d@x23> In-Reply-To: <20200716185629.GT4213@funkthat.com> References: <20200715232624.GR4213@funkthat.com> <20200716072622.5fa35ba2@x23> <20200716074917.04445daa@x23> <20200716185629.GT4213@funkthat.com> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; amd64-portbld-freebsd11.3) Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-ClientProxiedBy: ZRAP278CA0011.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::21) To VE1PR08MB4783.eurprd08.prod.outlook.com (2603:10a6:802:a9::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from x23 (161.53.19.9) by ZRAP278CA0011.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Fri, 17 Jul 2020 10:03:19 +0000 X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; amd64-portbld-freebsd11.3) X-Originating-IP: [161.53.19.9] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1cf4f0e4-f0cf-41bb-da03-08d82a38a1d9 X-MS-TrafficTypeDiagnostic: VI1PR08MB3984: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kW1ve77t0FPKRuaxhaBZyu25HnBOQbRmhDcRxk+4NvagQw6lRkibJJbYwkaTJM+lQC7llMbHKTOkm/IwXeU/BUjtHU4DW0q07iZugAYzX4gQ/q3vTIuHVrvSWkKihJLYE/D+7Uk/w9K9O/fyJ0Bvtj63x1oPwouZXsxyWS1kqcl6Qa2UUcKZGpsCicpqNkOYCMuaFQUOFNcPtrndFR9tXPU8IV9xlcZolJMI/euM5+GHwnBiz0kg5jfvhYViRK8n6GsdZMl8HWU55mTrGa4Cxr7HUIyy7zsMIscfH1fYPuiqT+J4IU7QM8ceLdaa84XKjdFcG8DwvwlX+pvxTMvDgQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR08MB4783.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(346002)(396003)(376002)(39850400004)(366004)(136003)(6496006)(66946007)(86362001)(66476007)(26005)(956004)(55016002)(9686003)(316002)(786003)(83380400001)(52116002)(16526019)(1076003)(33716001)(186003)(9576002)(7116003)(6916009)(2906002)(8676002)(66556008)(478600001)(4326008)(5660300002)(8936002)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: /xVsiyQFHnMrHUEH0MKFvfA5zu1a+Gm3p+EQ58KzVCpGZPVL+dSRI6pkJM2bCJkwlPOivqkCHsyNeWjgO6D80S/ZOODITYyfIJ0phX7bbH0jrgd5T4TH6IEqfBw+ZdG1Wzj1cOhV7NBpXX65yM+GMo5Ji/syej4H+MZjTYHzH7jW1wpJBGAXOqRBmeW7AAA+YiA1zeMJby2fCpZY6CJF/dBpuJgbfpFYbeo/pyNroShmKiVqVFC0mvb3oSmCtjdkFjCX0RKHrlDbqtdAVu2ewq6/XGdX3DUZrNz/ql4dpTyWHcCpURuDrXm2fQAOZl3xwJBXRaBSMrM6u8rOXgRxsgPI6FNj6pwlSMFcqeGyHtfqAB2003jhiT3sjk7kZ8rOZ61OtFbSUGqKFq+lnGbbtVIWV0p6zLIrlUFG6Ry3CWNdjNVIqWyTgvxJXvUeVmEQdi3gpqdvk7NiP9AGSuZO3Dk7ZaOGktWkP3SzywsdgnM= X-OriginatorOrg: fer.hr X-MS-Exchange-CrossTenant-Network-Message-Id: 1cf4f0e4-f0cf-41bb-da03-08d82a38a1d9 X-MS-Exchange-CrossTenant-AuthSource: VE1PR08MB4783.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2020 10:03:19.5908 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: ca71eddc-cc7b-4e5b-95bd-55b658e696be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nMrjzaFUijIS5xdlZ40g8bPWtkw872J2tAhfJlpByPpU10DhP3OIPR99qGuaGYnA X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3984 X-Rspamd-Queue-Id: 4B7RX96rN2z3bqy X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=ferhr.onmicrosoft.com header.s=selector2-ferhr-onmicrosoft-com header.b=c3XGAC7j; dmarc=none; spf=pass (mx1.freebsd.org: domain of zec@fer.hr designates 40.107.6.79 as permitted sender) smtp.mailfrom=zec@fer.hr X-Spamd-Result: default: False [-3.27 / 15.00]; MID_RHS_NOT_FQDN(0.50)[]; NEURAL_HAM_MEDIUM(-0.99)[-0.988]; R_DKIM_ALLOW(-0.20)[ferhr.onmicrosoft.com:s=selector2-ferhr-onmicrosoft-com]; HAS_XOIP(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:40.107.0.0/16]; NEURAL_HAM_LONG(-1.02)[-1.022]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[fer.hr]; ARC_ALLOW(-1.00)[microsoft.com:s=arcselector9901:i=1]; RCVD_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[ferhr.onmicrosoft.com:+]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_HAM_SHORT(-1.16)[-1.156]; RWL_MAILSPIKE_POSSIBLE(0.00)[40.107.6.79:from]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; SUBJECT_ENDS_QUESTION(1.00)[]; ASN(0.00)[asn:8075, ipnet:40.104.0.0/14, country:US]; RCVD_TLS_LAST(0.00)[]; RCVD_IN_DNSWL_LOW(-0.10)[40.107.6.79:from] X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jul 2020 10:03:23 -0000 On Thu, 16 Jul 2020 11:56:29 -0700 John-Mark Gurney wrote: > Marko Zec wrote this message on Thu, Jul 16, 2020 at 07:49 +0200: > > On Thu, 16 Jul 2020 07:26:22 +0200 > > Marko Zec wrote: > > > > > On Wed, 15 Jul 2020 16:26:25 -0700 > > > John-Mark Gurney wrote: > > > > > > > I happen to be looking at the implementation of > > > > IFQ_DRV_PREPEND, and unlike IFQ_DRV_DEQUEUE, it doesn't obtain > > > > the lock when manipulating the ifq. I took a brief look at a > > > > few drivers, and it looks like some of them expect that > > > > _PREPEND lock the Q like _DEQUEUE does. > > > > > > > > This is likely not an issue often, since it's an error path that > > > > likely rarely happens, but we should fix it. > > > > > > > > Should we just add the IFQ_LOCK/_UNLOCK to the macro? > > > > > > > > Comments or thoughts? > > > > > > I also have a hard time understanding the semantics of IFQ_DRV_* > > > macros: per altq(9) they appear to be variants of their IFQ_ > > > counterparts which are intended to be protected by some other > > > mechanism rather than IFQ_LOCK, but in some instances this isn't > > > the case, as they do grab the IFQ_LOCK. > > > > Hmm it's not that unclear after looking better: ifq_drv_* parts of > > struct ifaltq should be protected by some external mechanisms when > > using IFQ_DRV_ macros, and ifq_ parts are still protected by > > ifq_mtx. So it doesn't look like IFQ_LOCK/_UNLOCK should be added to > > IFQ_DRV_PREPEND()... > > Ahh, I was miss reading the macros on what was protected. Yes, it > does look like the ifq_drv_* fields are supposed to be protected by > another lock... We were both too fast to conclude that all IFQ_DRV_* are OK, but now I'm not sure any more: #define IFQ_DRV_IS_EMPTY(ifq) \ (((ifq)->ifq_drv_len == 0) && ((ifq)->ifq_len == 0)) So, if per altq(9) the contract is that with IFQ_DRV_* the ifq_drv_* fields should be protected by some caller-provided mechanism, while the other ifq_* fields will be implictly protected by ifq_mtx, how can accessing ifw_len without holding ifq_mtx in the above example be safe? Marko > > I just now found that altq(9) documents this interface... I had > assumed it as undocumented after man IFQ_DRV_DEQUEUE didn't return > results.. > > Looks like I REALLY do need to complete my script to make sure that > ALL Nm's and related pages have MLINKs. ALTQ.9 is missing 16 links > to the functions it documents... > > Just as a reminder to people who write docs, please, make sure you > link ALL of the function in your docs... Otherwise your docs won't > be as easy to find.. >