From owner-freebsd-net@freebsd.org Sat Sep 28 15:11:38 2019 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 C307D1298B3 for ; Sat, 28 Sep 2019 15:11:38 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-io1-f52.google.com (mail-io1-f52.google.com [209.85.166.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) 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 46gXF561K5z4KMp for ; Sat, 28 Sep 2019 15:11:37 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-io1-f52.google.com with SMTP id a1so25548039ioc.6 for ; Sat, 28 Sep 2019 08:11:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:from:date:message-id :subject:to; bh=T26NRsXQ7D/YXFRKMLUA35xFtymK+Jbh1mXAtD9lc70=; b=PmIOZ5jU/21diPW1vsjGHfSDSDGtdP6CPRUy8uTRPczo5E9OlqVP78a0Qp3ExOwxQQ B0ZUJ3zjGoWN1bBMjkbVNULFUDACj6+wCk7p8PXTFwIfNXYUVHb0DamfWO3RbLRvUg6A d+UTjy3OsBtWiyMZRBJiWvx5LEGPgiYcHWq2tbTBUg3zIs0SYYJBRINDpZow2S0uaFKa hK6tnIVvnVAf0ike009D04I6HXfLXLXOVdu5V0lJ45A3GpX77vvKele+AEwR3CDRild0 MIcTL7ztUPc2Moh63ukYRQUOV90PI43me6JknoH/qXWhgnmiJBmVHFwN7MAxdN6VGM1K 4WfQ== X-Gm-Message-State: APjAAAX3DKoG8/CrHMK3DgekUEG0bS9pgcdVTdoWfOtRvJwxMNHghhyM V/XQUU1KOynG5KQNZlbGCazEvVVh X-Google-Smtp-Source: APXvYqzd7YMaGo8UYod1D4Z3nhlERhR80WNj55fynjvcjeREBha7Ek3l2JmYnJmziQV8Vbza1vgm0g== X-Received: by 2002:a6b:b414:: with SMTP id d20mr13672214iof.162.1569683496312; Sat, 28 Sep 2019 08:11:36 -0700 (PDT) Received: from mail-io1-f44.google.com (mail-io1-f44.google.com. [209.85.166.44]) by smtp.gmail.com with ESMTPSA id h4sm1664087iom.17.2019.09.28.08.11.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 28 Sep 2019 08:11:36 -0700 (PDT) Received: by mail-io1-f44.google.com with SMTP id q10so25602962iop.2 for ; Sat, 28 Sep 2019 08:11:36 -0700 (PDT) X-Received: by 2002:a05:6638:3d4:: with SMTP id r20mr13328397jaq.104.1569683495435; Sat, 28 Sep 2019 08:11:35 -0700 (PDT) MIME-Version: 1.0 Reply-To: cem@freebsd.org From: Conrad Meyer Date: Sat, 28 Sep 2019 08:11:24 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Dropping the type argument from the mtod macro To: "freebsd-arch@freebsd.org" Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 46gXF561K5z4KMp X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of csecem@gmail.com designates 209.85.166.52 as permitted sender) smtp.mailfrom=csecem@gmail.com X-Spamd-Result: default: False [-4.08 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; HAS_REPLYTO(0.00)[cem@freebsd.org]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17:c]; REPLYTO_ADDR_EQ_FROM(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; FORGED_SENDER(0.30)[cem@freebsd.org,csecem@gmail.com]; MIME_TRACE(0.00)[0:+]; R_DKIM_NA(0.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; TAGGED_FROM(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; FORGED_RECIPIENTS(0.00)[freebsd-arch@freebsd.org,freebsd-net@freebsd.org]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; TO_DOM_EQ_FROM_DOM(0.00)[]; FROM_NEQ_ENVFROM(0.00)[cem@freebsd.org,csecem@gmail.com]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; IP_SCORE(-2.08)[ip: (-4.89), ipnet: 209.85.128.0/17(-3.29), asn: 15169(-2.17), country: US(-0.05)]; RCVD_IN_DNSWL_NONE(0.00)[52.166.85.209.list.dnswl.org : 127.0.5.0]; TO_DN_EQ_ADDR_ALL(0.00)[]; RWL_MAILSPIKE_POSSIBLE(0.00)[52.166.85.209.rep.mailspike.net : 127.0.0.17]; RCVD_TLS_ALL(0.00)[] X-Mailman-Approved-At: Sat, 12 Oct 2019 23:48:15 +0000 X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Sep 2019 15:11:38 -0000 Hi all, (net@ is BCC'd to keep discussion on arch@.) In the past we've moved away from macros with explicit types as parameters, in favor of casting void* results as needed (e.g., MALLOC()). I'd like to do the same with mtod. The refactoring is easy enough to do safely with a Coccinelle semantic patch. The semantic patch converts instances of "mtod(m, t)" to "(t)mtod(m)". markj@ and rrs@ both point out that the network stack uses the type argument as a visual tool in large functions where the declaration of the lvariable isn't necessarily nearby its use. I think the "(t)mtod(m)" preserves that utility as a visual tool; I may be mistaken. Currently, the semantic patch drops the explicit "(t)" in two limited cases: "t" is "void *", or the "mtod()" invocation is used during initial variable declaration and assignment. The reasoning is that in both cases, the "t" isn't giving you any additional information. Neither of these exceptions is core to the idea, and either could be removed. What do you think? A rough draft of the proposal is sketched out here: https://reviews.freebsd.org/D21669 Best, Conrad P.S., On an earlier version of this revision, markj@ and emaste@ both expressed concern for downstream consumers. There are two aspects of the current differential that should smooth that experience. First, a backwards-compatible two-argument mtod(m, t) is retained using an ugly macro hack. (Existing code compiles without modification.) Second, the coccinelle semantic patch will be checked in to the tree somewhere for use by downstream consumers that want to convert their code.