Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp24409pxb; Tue, 12 Jan 2021 18:51:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWAGAqFn8z2C28vnrhenNDSNFIj3g0AkEEdYtEjaGcVtjnh7uKGpQWAVsex8d6T9ywEbwY X-Received: by 2002:a17:906:6a45:: with SMTP id n5mr1331061ejs.514.1610506280340; Tue, 12 Jan 2021 18:51:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610506280; cv=none; d=google.com; s=arc-20160816; b=qNLDKKkAsMkl4RwDk0JWmfm4ijLuXBzsJDg8ebjUvddQpqUPwM91mDeD9pDGg37bca 1Gc/1DlfSNCYpM3SlTgGJ6vyaBplEMUv9CMC2HWJjxhsZf891hsqOevjxEudPOIIIrjI ShmC2QzhDuoZ7d4MU1gT1wZSt8nHmJ5SwaIhgc4HOB+qBpnCE6TbtBN1OuswwfSMCLQg nyK07rybA9kDBXhS3XmAoNv5fFLjm2M22CHQKVj6AJdjRhuhek263ieMUpLl6W0UwCSn LPOK53QPiuQbXEDgyOmCwywWzOWtO+uXrXVivW3oIrFL/wjpfsUVHXZqAbxWn2Fj0D8n c4Ew== 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=olxCUvxpcXL3R2GLrBwENG3ouQB8ZYtp3GhVSnmKZuM=; b=Q90JGE2Vu0ht1PJVgV69PIoKXClHSLZZZS2ulV6/31Qcn3hJTS2gJ5vm/Ur42S0jZ8 pIFcujd4aml8GimpVGyG4XonSBN6J9gxx+keJsTUkQ/ulhXA1f3S7U87KjcbIMqBl/9P YCpbOv+r9GdZCkC/NRsmJ0THdTcTf2YFkudDVQfJQYpwvsuprepzuhGETbFBdGqbv0oq mHjErkRqgTzfFyeeyDaKZIAlIf3RCrRHg46t7SB6nj/hPLWcZZxYC5LBBT5RPASi+O/z MhnpWiEXQC2mYpXbrHWdQHF4vkns4MP9G1PtV5L6oKyJQ+j7NUrir8yiwgxx3NCYcx36 8vRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dGJqu63Q; 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 x59si301239edc.544.2021.01.12.18.50.56; Tue, 12 Jan 2021 18:51:20 -0800 (PST) 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=20161025 header.b=dGJqu63Q; 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 S2390693AbhALVy3 (ORCPT + 99 others); Tue, 12 Jan 2021 16:54:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728571AbhALVyX (ORCPT ); Tue, 12 Jan 2021 16:54:23 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EAC9C061575 for ; Tue, 12 Jan 2021 13:53:42 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id h10so2218124pfo.9 for ; Tue, 12 Jan 2021 13:53:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=olxCUvxpcXL3R2GLrBwENG3ouQB8ZYtp3GhVSnmKZuM=; b=dGJqu63Q0ptoAgat6qwOgZD/Q2sZqyW2KSQRD4lnZ9JqupU/ioxwsfD3sRrRl0vEMU N06qMEAwo5jbV8aZcz68fUKiYeFxBwKGsZHcm8V1wVbe5sqniVcue6n3wIZkG7YTm7YB GGxVVgW1n2/LqKLtn9syy711cKx/2mqBGUoqFbPIe+OQM2U/xnAJHTB1bo+T9jx3N2cr s7qkUZ39pEkaScorHtIFO7znCq2lXZKbdTunwd5z6m562Gy2LpYQ4Vv9U89HnuMvl5H5 HPmEqBkC/qqb1YBXP4C39fRmZaBMWou7gop+ve1NG8w85U/y8h/qugKhJE6dgTICANr8 U+kA== 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=olxCUvxpcXL3R2GLrBwENG3ouQB8ZYtp3GhVSnmKZuM=; b=OZw8la+eN3dmaXt/41PyedwDtBpiBI9n74PfDovKwb7NeJm+Iw8nu01wbU6uJXVunf Zb4GCE6AayiEmSsc/pp6fHl9FenXxi1jjmUG6u7Vnc+WlH0Xd6n+g/HOj/5Nr6ST+eMj qUTA9IC4Xehk/G6P790xjpX9zY2ov65pUH1L/4htWQDGdrvvuLJZmEJiBb6i7hU5ZMf5 HbvlTqBgQszD72HGK+L+QOd2xqHJ3taV74kWINgXvMiSax08rlBsKXP9zq0xXo7SzPC/ nLuq/oOJi5BiWOgtlspal31VqFhHrm8Ydn7VedvgcY7JOV/LwDRwjHxw/1xwbGJWLDgQ tLfg== X-Gm-Message-State: AOAM533owd3IsHONvGw6QcOtnJzYyRw6yv8uqPUMghiiBl7lC9lVEOB2 LAQhs3hFmjpZAq+WTiN8ThwlWbbBB+TRcgc/ss/ltA== X-Received: by 2002:a05:6a00:796:b029:1ad:6394:432d with SMTP id g22-20020a056a000796b02901ad6394432dmr1280433pfu.36.1610488421716; Tue, 12 Jan 2021 13:53:41 -0800 (PST) MIME-Version: 1.0 References: <20210112205542.1375847-1-natechancellor@gmail.com> <20210112213703.GA1376568@ubuntu-m3-large-x86> In-Reply-To: <20210112213703.GA1376568@ubuntu-m3-large-x86> From: Nick Desaulniers Date: Tue, 12 Jan 2021 13:53:30 -0800 Message-ID: Subject: Re: [PATCH] ubsan: Implement __ubsan_handle_alignment_assumption To: Nathan Chancellor Cc: Kees Cook , Andrew Morton , LKML , clang-built-linux Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 12, 2021 at 1:37 PM Nathan Chancellor wrote: > > > if real_ptr is an unsigned long, do we want to use `__ffs(real_ptr) + > > 1` here rather than ffs which takes an int? It seems the kernel is > > missing a definition of ffsl. :( > > Why the + 1? I think if we use __ffs (which it seems like we should), I > think that needs to become This came up recently in an internal code review; ffs and __ffs differ in output by one. See also the definition of ffs for alpha in arch/alpha/include/asm/bitops.h. Also, I just confirmed that: ``` #include // include/asm-generic/bitops/ffs.h static inline int ffs(int x) { int r = 1; if (!x) return 0; if (!(x & 0xffff)) { x >>= 16; r += 16; } if (!(x & 0xff)) { x >>= 8; r += 8; } if (!(x & 0xf)) { x >>= 4; r += 4; } if (!(x & 3)) { x >>= 2; r += 2; } if (!(x & 1)) { x >>= 1; r += 1; } return r; } // include/asm-generic/bitops/__ffs.h static __always_inline unsigned long __ffs(unsigned long word) { int num = 0; if ((word & 0xffffffff) == 0) { num += 32; word >>= 32; } if ((word & 0xffff) == 0) { num += 16; word >>= 16; } if ((word & 0xff) == 0) { num += 8; word >>= 8; } if ((word & 0xf) == 0) { num += 4; word >>= 4; } if ((word & 0x3) == 0) { num += 2; word >>= 2; } if ((word & 0x1) == 0) num += 1; return num; } int main() { int x = 3; unsigned long y = 3; printf("%d\n%lu\n", ffs(x), __ffs(y)); return 0; } ``` will print: 1 0 -- Thanks, ~Nick Desaulniers