Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp29811pxb; Tue, 12 Jan 2021 19:03:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhoX8K5GC6ELAaGOnqAYdgGKx2DY8JSGkmzoBe/nbQqsoaGBDSocI6nfi/Gn3VzV/48nio X-Received: by 2002:aa7:d154:: with SMTP id r20mr89786edo.258.1610506992740; Tue, 12 Jan 2021 19:03:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610506992; cv=none; d=google.com; s=arc-20160816; b=RE8ckvvkz+wREmw23sRAJgT3HuJMoQNrGD5B4fT2ttfSHraavmsI5CqTt2wnE88ud5 ovEaWXB2nnHZ83RCTigNOfhRBkcVI6OU8gCr7u4uQxidS0m/N+PdNLuOeGRPGr/M7VEy If9fjdPfWd5dd8avVeLSQ4gI6wMX66vNdZNXyvtSC5H8RDc597vDk/x1p9B/vImZuU9P uRBTPW4zL3htnVHDzzYTP6utGRo9Ut0v3vfofGD5EA6kq/PbjA4n8a2Y6bkh49XSk7NU brKfaiMutiGVA9QsFvEFh3AEquZSAwR9RgNXrHStCSgoHABDoPlJYsoLY7AqlmwwVdEQ 1TKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=PAaIIToNfkh2YDvfiyNmhQxep4I10YuTfP4xkCJeuVc=; b=0hbtgWiRbgIafF4a2lSJrDbH2rQQTqB9LnAzgPYZyohK6QbXKd1jv5OKhPV754gCBI hWVXg6CzcCYUt+8l9i49LYE+uiN/+VIfX9cH05Pep8OhyKKsQvMYMpUQOjH+O0b0q0yB Y7BLvFmftS52IQ9Qr4j/Gvxr9CHnycnr3eRPbyCrw3VGkJvixA7e9MFOcpman9rN8xN2 rFjXktmcFrBUzA4SPy+BSwA25aEhxk4JlWirb0eg9tRbIcWBYlBVMRIvQutaRYwCFb/H g+QnPhvby6oQy5YUU0baxiqnewrlKP5sbdvLDIce6G1L2hM4e7zeI05nVTOiMpkrBdgV +S4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C6CHTBNX; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b11si290447ede.511.2021.01.12.19.02.49; Tue, 12 Jan 2021 19:03:12 -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=@gmail.com header.s=20161025 header.b=C6CHTBNX; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394292AbhALWHT (ORCPT + 99 others); Tue, 12 Jan 2021 17:07:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393915AbhALWHS (ORCPT ); Tue, 12 Jan 2021 17:07:18 -0500 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F19C9C061794 for ; Tue, 12 Jan 2021 14:06:37 -0800 (PST) Received: by mail-io1-xd29.google.com with SMTP id w18so9313iot.0 for ; Tue, 12 Jan 2021 14:06:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=PAaIIToNfkh2YDvfiyNmhQxep4I10YuTfP4xkCJeuVc=; b=C6CHTBNXsozuvr5a6+hpZhybdguepzIRKjP2oHIzMIh7j6RCVItoLzalNl9Ty097J5 ieCEb5FvuayKlDhw+Qf5wqiXWcZmln7OhWN1O2vFfc+7dzruCxHTILIXZMwfARSkumdP 85wPwBLkbPGqUAd5R9X+28bc8mp/s9Hlq13ybr4zbZIqVWc1L/MQbH6LDF3vPTw8lxtU dSphNL8YTuoc/MgNhTYXV968o6t7eYzTNF9fxKbAKR7rv1eDmm/HoeNLR0OtFf7wbFxG D//qivkUGF425jrEDzEpyZKhtgbYJP/NP5ucYuJ8IcvP3bSBr7CGCi/a/vSxuKPhqUgn J+wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=PAaIIToNfkh2YDvfiyNmhQxep4I10YuTfP4xkCJeuVc=; b=XDR05H56zJOHl6w/9JeDZeoiGSYnKUg73vXT/PskXX/pHgpCXRgTTuYDFSHUURzQ5s QHwy9RMIM1h4DpJZ9jIfpsEUxSF4JpQuWcHS2W6fCF+hibGdYIqg+CXknF1pNJX9ZQX1 /4YbD0x40xaib5y2YdkuG1587FVITYbq+2MRfm/RPZMW71lYuxNaRXAYMmwpZ3C6DWUr 2UzOrYvlmfVSWuF9r91jSYbcCjijMM3LdOFsz9v3usa5DNSEY20crf+Ev6XfpAl26Jsg IE5HCiQMRkihECQwu9R/6occEBux7tQIHkXPxFJ+TM0y6k2rDlQE0VKxpHuxaJDblWrl f3vQ== X-Gm-Message-State: AOAM530MVUZPCXUltLP+wyjx3HmmCtbOPFd7Kg15PDy3qDogekbiGIrC DgJxtrZjaZm++fseaL+g6OQ= X-Received: by 2002:a6b:dd13:: with SMTP id f19mr1004530ioc.74.1610489197305; Tue, 12 Jan 2021 14:06:37 -0800 (PST) Received: from ubuntu-m3-large-x86 ([2604:1380:45f1:1d00::1]) by smtp.gmail.com with ESMTPSA id a17sm33570ilc.77.2021.01.12.14.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 14:06:36 -0800 (PST) Date: Tue, 12 Jan 2021 15:06:34 -0700 From: Nathan Chancellor To: Nick Desaulniers Cc: Kees Cook , Andrew Morton , LKML , clang-built-linux Subject: Re: [PATCH] ubsan: Implement __ubsan_handle_alignment_assumption Message-ID: <20210112220634.GA1377517@ubuntu-m3-large-x86> References: <20210112205542.1375847-1-natechancellor@gmail.com> <20210112213703.GA1376568@ubuntu-m3-large-x86> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 12, 2021 at 01:53:30PM -0800, Nick Desaulniers wrote: > 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. Interesting, thanks for bringing it up! Looks like ffs returns 1-32 and __ffs returns 0-31. I think that we want __ffs here because we are shifting (1UL << 32 overflows on 32-bit architectures) and the code in LLVM appears to agree. LeastSignificantSetBitIndex evaluates to __builtin_ctzl, which is the asm-generic implementation of __ffs. Cheers, NAthan