Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp244356pxb; Mon, 13 Sep 2021 18:11:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSiOvZY6QapmTHmdv3cJ7okEvIiRxdHsPSyWseW67tQgzJWMZadxMBVksZa0Bd+L4Vm9Ft X-Received: by 2002:a02:a46:: with SMTP id 67mr10198942jaw.142.1631581915685; Mon, 13 Sep 2021 18:11:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631581915; cv=none; d=google.com; s=arc-20160816; b=M+YxNEGZmcjjl3rnwYqJhe/aA5fXqe9tmP3m/wo2/6WTw5DJZ/uoYldTk1MEVF7RfN sFmTxsMT6I/UIbEe34yE/e8ZTDVzkdhc0gpPU1Nl/jKs92KfQNSMsZKNtJiibfnoQiXx zjrqbOYYx5K/TGoumj4Hk83B1NeFsshrwQDX6loZIr5iYqQ4JaeoRjp8vH7Z0njysgY9 nE+91euzRA7IxXo/pwbtkFdI5UZfUo3marWDiCoadvRUHV7gclxWCVHQSHGmGEzc4iWZ E/juw+JejyQ07hQEJQZB3kbRjFcIZz2uZEMjR/syNPqj/jY0JEBRHAUZv5hWnSGjxVq+ HVRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=h6laIf/b4mPqz9ieIo0BoLxfadBv/pBLzz57FwMCWS8=; b=h37WvDsBCVmhrGHgKXjvEL8fo/LOiXeh80uVPZ7Hk1Va9fpeUmbLMcaSm91B5Afpbr qL26iovMaQh+fiotTY7Oa9WI77nJQxipfBopesunlE6LbSJuFUA1TtazLgmFf+04uuba TOvvP6cezTbqwKbMngB1eS8t8mVykP566Xh6GWU/mvRfTk9db9Tj5cRjtVxczfpGZrph MDDUNrNa8CJ9xPx/sZJ6L3e0OTUSMa7ugkclLkTUSthFEL6UreGQxkwdgJnG2Ii9r3fP lf+iwKQIyzruDoSTZ7TbRV7+EKkQDdLQ0Q6wpE65Rvz9SmdRa65K3oHoZQpRqAp6FESf z9EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SEu7xaZS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b9si8837234ion.34.2021.09.13.18.11.45; Mon, 13 Sep 2021 18:11:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SEu7xaZS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348128AbhIMVP0 (ORCPT + 99 others); Mon, 13 Sep 2021 17:15:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348122AbhIMVP0 (ORCPT ); Mon, 13 Sep 2021 17:15:26 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D234C061574 for ; Mon, 13 Sep 2021 14:14:09 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id x27so23908931lfu.5 for ; Mon, 13 Sep 2021 14:14:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=h6laIf/b4mPqz9ieIo0BoLxfadBv/pBLzz57FwMCWS8=; b=SEu7xaZSAjVMKNw5hjypkoLJ+5JYwWZcOY2BABqYuBro/CZPK17EczUQuLCrutTPGL 16Qz1HYIlWBLiIz9fuIN+11uBldPo/W5AePdN6GsQEA+SUtc8P+uASAYS6tS0ldHx07E 2lonLGUWd9SBbHuElL3JERelxOI/WCQiYZQMZ+cnIB22lorehJTp1jfpHpUXPGwAVLsr iug/4lH2iw/Q756RGmEMyqecg2b3vt+REqwODu74njL+3uIRYmD7FhCYQoWZA7S/e7X4 zbL4RRw54fmrJ/xhPMXQuEF33NXAg8H1490G0IrDnCzFSwlQt8KLs4uiBLXAehRStlz0 T9Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=h6laIf/b4mPqz9ieIo0BoLxfadBv/pBLzz57FwMCWS8=; b=PEuuGytSKjDRSlubMOXxwZWT5JNldQ1gOgFdPw1vuE3p/lWF0kkt6bfgZrVPlnohAv 442iK592v9A9cLQuKBwW6KsuC9Hfd9oLBOP3gNO3O5905BsKFbh7yXV2TwfMfaPBBLTE mcg1+3S7iqUsELut3c3GeXqJl2H//FODSGz6dD2KvZZg1bCx+o1/yWlVSntDo0zbVCSx MbenR0+W3FvQgr0BKQ4p1d42ObHvb0YQpdZAhzky2i9ZlK88kX3H3UPKbbdrO9DzJxuu 9NvbHqrCm8Jikw272EijUkypxu+zYeZ/dh7OPBQmgnLOINIFBX29XFDmG1ek9w/Mh4A6 3uaQ== X-Gm-Message-State: AOAM533HQPzr3oXTkVr5mVHBfxp1xcp/Ldz6yFo2hCJnywLcXIL9WgEe B+YRG/ivfnbpXb7B44xAVI28eqB/jDbio0q0IksuvQ== X-Received: by 2002:a05:6512:3b9e:: with SMTP id g30mr10188187lfv.651.1631567647760; Mon, 13 Sep 2021 14:14:07 -0700 (PDT) MIME-Version: 1.0 References: <20210913131113.390368911@linuxfoundation.org> <20210913131114.028340332@linuxfoundation.org> In-Reply-To: From: Nick Desaulniers Date: Mon, 13 Sep 2021 14:13:56 -0700 Message-ID: Subject: Re: [PATCH 5.14 018/334] nbd: add the check to prevent overflow in __nbd_ioctl() To: Linus Torvalds Cc: Arnd Bergmann , Sedat Dilek , Greg Kroah-Hartman , Naresh Kamboju , Nathan Chancellor , Baokun Li , open list , linux-stable , Hulk Robot , Josef Bacik , Jens Axboe , Sasha Levin , clang-built-linux , lkft-triage@lists.linaro.org, llvm@lists.linux.dev, Kees Cook Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 13, 2021 at 1:50 PM Nick Desaulniers wrote: > > On Mon, Sep 13, 2021 at 1:42 PM Linus Torvalds > wrote: > > > > On Mon, Sep 13, 2021 at 1:16 PM Nick Desaulniers > > wrote: > > > > > > Do we have access to _Generic in GCC 4.9? > > > > We've ended up using it unconditionally since last year, so yes. > > Sorry, grepping would have taken < 1s. I'm very lazy. > http://threevirtues.com/ > > > > > In fact, the compiler version tests got removed when we raised the gcc > > version requirement to 4.9 in commit 6ec4476ac825 ("Raise gcc version > > requirement to 4.9"): > > > > "In particular, raising the minimum to 4.9 means that we can now just > > assume _Generic() exists, which is likely the much better replacement > > for a lot of very convoluted built-time magic with conditionals on > > sizeof and/or __builtin_choose_expr() with same_type() etc" > > > > but we haven't used it much since. > > > > The "seqprop" code for picking the right lock for seqlock is perhaps > > the main example, and staring at that code will make you go blind, so > > look away. > > Looking at my patch: > https://lore.kernel.org/stable/20210913203201.1844253-1-ndesaulniers@google.com/ > I don't think _Generic helps us in the case of dispatching based on > the result of is_signed_type() (the operands could undergo type > promotion, so we'd need lots of cases that are more concisely covered > by is_signed_type()). It could replace the nested checks in div_64 > with nested _Generics, I think. Not sure it's a huge win for > readability. Maybe cut the number of expansions of the parameters in > half though. Let me give it a try just to see what it looks like. Is this more readable? Same line count. I'm not sure if there's such a thing as "fallthrough" between the "cases" of _Generic to minimize duplication, or whether this could be factored further. Needs lots more () around macro param use and tab'ed out line endings... diff --git a/include/linux/math64.h b/include/linux/math64.h index 8652a8a35d70..8fc4d56a45b9 100644 --- a/include/linux/math64.h +++ b/include/linux/math64.h @@ -162,17 +162,17 @@ static inline s64 div_s64(s64 dividend, s32 divisor) div_u64(dividend, divisor)); \ }) -#define __div_64(dividend) _Generic((divisor), \ - s64: div64_x64, \ - u64: div64_x64, \ - default: div_x64) +#define __div_64(dividend, divisor) _Generic((divisor), \ + s64: div64_x64(dividend, divisor), \ + u64: div64_x64(dividend, divisor), \ + default: div_x64(dividend, divisor)) #define div_64(dividend, divisor) ({ \ BUILD_BUG_ON_MSG(sizeof(dividend) > sizeof(u64), \ "128b div unsupported"); \ _Generic((dividend), \ - s64: __div_64(dividend)(dividend, divisor), \ - u64: __div_64(dividend)(dividend, divisor), \ + s64: __div_64(dividend, divisor), \ + u64: __div_64(dividend, divisor), \ default: dividend / divisor); \ }) -- Thanks, ~Nick Desaulniers