Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3031266imj; Mon, 11 Feb 2019 12:37:04 -0800 (PST) X-Google-Smtp-Source: AHgI3IZq3E1/0CM38iEmmO0kuSeWX8DnhzqwSEPEDceZ1s+IXnilFH5msSk2B25jSCT2RDBiP6Gs X-Received: by 2002:a17:902:a411:: with SMTP id p17mr99367plq.292.1549917424770; Mon, 11 Feb 2019 12:37:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549917424; cv=none; d=google.com; s=arc-20160816; b=kh7VXd7hn8Z7Wt3raW0it/F0hELN35xVX+S3HIt580oF7NHn7V0jkK44Je+7sLcomL S6zXKtTOyvZIT3VgkzhJbXhU76Zk5P3AKhtWYmDrf04gp9qLJgkagEYoUpVjBsHKi07J BrVW7/0MD6CJzekMgH5HbxLH2TOGaw0Gy2a+9r/Vbyv/gliJKtXxNhfbx4WJI5RNBgEM CVuAq7lBr71AkZ1czCmuW3pRD25qsF6GRcjo6ufk5jKE6XfbADUPpmJvNN84FSheamTm 6ZTU/B+fPzCv11FI4wHTX6H5sZKPYwAhd/vRNAt3DzTIHvLYIv7KN7jatXI4BqNIawHe KE6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jAU/yKj0QXxla3Viu5M/6EOsL3HpGEo4vnhRjeap1u8=; b=JPcotBBQcKhsM8XsCAqQjh02z20Hmj4AUhQXJ/mX756pmeguf6AqgVdmHAnmTIFdPJ hfQdnzI9n7w6C51UICY5LHS+QZ9L9ylfmxisluylpfmaeYpuPVxN/3D8P56hjVqc1Iuo xb4N7S69Wbf7ToIu78VagW4JxBPv5GjU86lBp6rEmOMI+0WpsktDJtltP05YIp5mazXe /G2kTssh/SwOGeLj3nqDjLCyWgjaU8a3ohLsXHUs7pKw899NeJCuOn+AFzZZiw7WHG2D zFtSj8yuIMyFE2l857thL1l1Mn/w7uquOmJq4j3DozdxJaZgsk4KiwqhxRs2tFHmVEE1 5seg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uPdGaHbU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j11si11739569plb.253.2019.02.11.12.36.49; Mon, 11 Feb 2019 12:37:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uPdGaHbU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732124AbfBKSUb (ORCPT + 99 others); Mon, 11 Feb 2019 13:20:31 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:53618 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727007AbfBKSUb (ORCPT ); Mon, 11 Feb 2019 13:20:31 -0500 Received: by mail-it1-f194.google.com with SMTP id g85so541487ita.3 for ; Mon, 11 Feb 2019 10:20:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jAU/yKj0QXxla3Viu5M/6EOsL3HpGEo4vnhRjeap1u8=; b=uPdGaHbUYiBCbGY18wf0fx+V7qybX8JeB9WGfZQQ0XCiMwzq+Bq31QhkwDr+2OoWv3 hubaV5sIv8KVS37KeEnOPR46TZ21nEFtZFJvZhsnCSgbqUVVvABg54NRA1K8nXYcxIVW VLPjAr8qM9Z0A1J/cU9YcR/ls2tXkRgEUZ1t2kdGs3ogvJSNKVwUHWmvSt5B+C7c938J k2Tm7jrvj2vYsmOSHbMQrYJxZbPvoOmKRg9NMnnmlgt/1AneSgOOyRGMPdn0d1wgpGVN sspUngdTuvkUi3PiuuqNNtLXJ9jUdpgLOwtKkaJ65mzNujVhsXE3bTJ1D9nc0MlQLuem he1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jAU/yKj0QXxla3Viu5M/6EOsL3HpGEo4vnhRjeap1u8=; b=qalXIDNkFiRY/3TfSdMP9AWUxVlv0CjGrcySOw3OsbDtQvPVbmuwSfvNlFvZfMyQ/G fpq4UTacxPnzFGyq/lXh3vgV1EoM79nNrdNtbxijViHsBx+wB9E3f0DkVFo4kWU0lGZ6 af+Fl3cXSwCwuY5EE2VmrzQHq2Yhnq4VGvD9nBov+tErenGm1BLPqx+q58nvAyDpmqNG cELHMaPgs0L1eXkKKuBuPs0JUjdFZW1qRbHf4Y+cQnH1/6gmeqjm5noGMEhVhymwq/pR uhkaukdG0khFZ3eMtr37KTvjPoTJP0o0DjrmCqohuUJxtipUn8LOjKSiGq4jVG4/BYF4 YMRA== X-Gm-Message-State: AHQUAubGcD1Hv8cQu8zGyYgb7OEVKXzY/hqGk3A62XDq872z56DgbXGz mtCNQBhwBGofgzPEp3FZONLQ49uTGV4XqGJY/6OcIw== X-Received: by 2002:a24:4582:: with SMTP id c2mr544687itd.158.1549909230194; Mon, 11 Feb 2019 10:20:30 -0800 (PST) MIME-Version: 1.0 References: <20190209000840.11018-1-miguel.ojeda.sandonis@gmail.com> <47895935-0619-fb4a-e74e-a8b029ba8504@gmail.com> In-Reply-To: <47895935-0619-fb4a-e74e-a8b029ba8504@gmail.com> From: Ard Biesheuvel Date: Mon, 11 Feb 2019 19:20:17 +0100 Message-ID: Subject: Re: [PATCH 0/3] Clean the new GCC 9 -Wmissing-attributes warnings To: Martin Sebor Cc: Miguel Ojeda , Linux Kernel Mailing List , Laura Abbott , Arnd Bergmann , Martin Sebor , Herbert Xu , Krzysztof Kozlowski , Catalin Marinas , Nick Desaulniers , Luc Van Oostenryck , Andrey Konovalov , Kees Cook , Sean Christopherson , Jessica Yu , Masahiro Yamada , James Morris , Mathieu Desnoyers , Borislav Petkov , Matt Mullins , Vincent Whitchurch , WANG Chao Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 11 Feb 2019 at 17:21, Martin Sebor wrote: > > On 2/9/19 5:31 AM, Miguel Ojeda wrote: > > On Sat, Feb 9, 2019 at 12:26 PM Ard Biesheuvel > > wrote: > >> > >> On Sat, 9 Feb 2019 at 12:19, Miguel Ojeda > >> wrote: > >>> > >>> It also affects the optimizer in two different ways AFAIK: > >>> > >>> * For the function itself, it gets optimized for size instead of speed. > >>> * For callers, the paths that lead to the calls are treated as unlikely. > >>> > >> > >> That seems reasonable, but that still does not mean it is necessarily > >> a problem if you apply 'cold' to one but not the other. > > > > Indeed. As I said, it is likely that you missed the attribute, not a > > sure thing (i.e. that you didn't do it explicitly). > > > >>> So GCC reports it because you would be (likely) missing the > >>> optimizations you expected if you are using the alias instead of the > >>> target. > >>> > >> > >> I see how that could be reasonable for extern declarations that do not > >> match the definition, since in that case, it is assumed that there is > >> only one instance of the function. For function pointers, I don't > >> think this assumption is valid. > > > > It sounds reasonable to have another warning for > > declarations-definition attribute mismatches too. However, I don't see > > why you would warn differently. Even if you have one instance of the > > function, you may also be using the declaration to explicitly avoid > > the unlikely treatment. > > > > Now, whether the warning is worth or not or at which "level", it > > depends. I guess the rationale behind having it under -Wall is that > > they expect people to have missed copying the attributes, rather than > > they are using aliases specifically to avoid a cold/... attribute. > > > >>> In our case in patch 3, we do not want the optimization for callers, > >>> which is why we don't mark the extern declaration as __cold (see the > >>> commit message). > >>> > >> > >> You did not cc me on the whole set, so I don't have the patch. But in > >> any case, GCC 9 has not been released so we should still have time to > >> talk sense into the GCC guys. > > > > I only CC'd people on the relevant patches according to > > get_maintainers (but yeah, 2 & 3 are related, I could have merged > > those lists). Anyway, using the lore.kernel.org server makes it easy > > to see an entire series when you have already one: > > > > https://lore.kernel.org/lkml/20190209000840.11018-1-miguel.ojeda.sandonis@gmail.com/ > > > > As for GCC, Martin (the author of the features) is CC'd, so he can > > chime in (and I am sure he appreciates the feedback :-) > > I do very much, thank you. I think you've fielded all the GCC > questions here so I don't have much to add. Just a comment regarding > aliases with different sets of attributes than their targets: it is > possible to come up with use cases not just with attribute cold but > others as well, including mutually exclusive pairs such as const and > pure. But the uses cases that drove the design of the warning were > those where the set of attributes is meant to be the same, and we > are yet to to come across the others in practice. If it turns out > that there are others in common use we can tweak the warning logic. > > Regarding function pointers, attribute cold only applies to function > declarations (and labels) and is ignored on pointers, so calls to > a cold function through a pointer are not necessarily subject to > the same effects as direct calls to the cold function. (This is > inconsistent with other attributes such as const and pure which can > be applied to function pointers, so I wouldn't recommend relying on > cold not changing to match the others.) > Hello Martin, Thanks for clearing this up. I seemed to have confused myself into thinking that the slew of attribute 'cold' warnings I was seeing when building the kernel plus modules with GCC-9 were about function pointers, but in fact they were about symbol aliases, for which the warning makes perfect sense. Next time, I'll try talking some sense into myself first. Apologies for the noise. -- Ard.