Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4190955rdb; Thu, 14 Sep 2023 14:57:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFIYHGmlNWZ8XGcvOiK9v9Po+QyRuT/aToqe8aickZNmRKciMjaqHntJ4tGPYF5erL2ndB1 X-Received: by 2002:a05:6a20:3d0d:b0:13d:d5bd:758f with SMTP id y13-20020a056a203d0d00b0013dd5bd758fmr10533pzi.6.1694728649248; Thu, 14 Sep 2023 14:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694728649; cv=none; d=google.com; s=arc-20160816; b=w21Qsca2mP0tnCMfVG8VikE+d7hWsrptRdAx5NplV7dy2cKX3b2/6vh44OKzMhwZ9Z /YFZWFHgFwDvJluqG7Mw8BuSP9y/DnOrT4gQdNVLaWIauMllyKiLKSzw/5s53tA2BpL6 8hS7+utblEWm7+UgZ1KAg7Q7hkiNxCS37ArHVjlmqUaaLda0akoiKWZkpn1aj9SYieXb v8oYtlKh89br6EKOrjzlFC+YEqyIrlFY3txrqBAzoWRRJfhebJ9FeBFv1yf9wizLBE3P wix9KwuQYb2SAmSFhfBptUsUt3ihpD6XNE/IIlzuTJGcN9murzA+HWIsQC6Zo2FTYyfC odnw== 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=Q0osJNvhj0fiTzHIWQ+91ixq0PkbEOWYyIzEWBKpJpo=; fh=Pse6jmHBPG+eF2jySJBwZZsWpIPDhGOMIuoCFUtva9I=; b=PN4Lo5gN1t6DlSG9CN185+4Ln9q6sB2kvCsLPd6qfMUpoZ+VzZG01Yu2t8tJlcZiiI PyowPvzfYc3viYiu3N59V3JUTTRj7mjHTHpuTNXMdRBZ7xSXqUyl2HEtQ0t+UPCLoKIL 5OnrKOWGXUGXoRox57bS1JbPmFr+m4UgzKBRoOsJZtWwkd/NwfEqW2+J57QQd2mMU0bF bnI9TwG2AI5YzPWLGkg6SKgKVv7HPGZtqhj5ao3gClNgR9zfTrmAdOfMcSeUvOgHftFo MRsGLVRyozXAXor98ppgPhtdXLcEPfeqPbm1jk+/kfCd9hWuxsjusGXqkfKcRxdJGhy1 HXPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SSMnqBWN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id eb5-20020a056a004c8500b0068e23721457si2222103pfb.68.2023.09.14.14.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 14:57:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SSMnqBWN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id BC2FD801B31B; Thu, 14 Sep 2023 06:51:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239257AbjINNvy (ORCPT + 99 others); Thu, 14 Sep 2023 09:51:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239107AbjINNvx (ORCPT ); Thu, 14 Sep 2023 09:51:53 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A66461BE3; Thu, 14 Sep 2023 06:51:49 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0533C433C7; Thu, 14 Sep 2023 13:51:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694699509; bh=hMh7eQopqrtQZLsj75qHwGwk96M3LrHj3/pLM+3yCto=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SSMnqBWNIGvXAmtdsuQZYI+7yZYvTNV//weL23ZrRgBOiOazVE+4nkZ7h/wj8P1t3 sbbSVmK4oHzDxvBCPNwEyh0ubGnxWINbTa9rACgoVHp3Z+9rKKZvcmFMXuewTyRWCR lhRxPCHvNy/EGC/dj08TyHIs7cQJxLVpfsFbXRJnuxyjA1wMauYFFE0JzKVjew77bA ntnSxefW4fYC8jZFTJYrbwT61KZ4R1smXLkhF4DscH/K1VpWP13h1xZeVARF5td7jJ eBwC31IT8mp1fwmuRpn+VXqCBtc30VNt2Imb5j94W1KsJvqDqkRLVwC6UoTJ0qokVy lKBmzY9tht2Ug== Date: Thu, 14 Sep 2023 15:51:44 +0200 From: Josh Poimboeuf To: Kees Cook Cc: Randy Dunlap , Stephen Rothwell , Linux Next Mailing List , Linux Kernel Mailing List , Kent Overstreet , Peter Zijlstra Subject: Re: linux-next: Tree for Sep 12 (bcachefs, objtool) Message-ID: <20230914135144.udwf3lmhh5zael5e@treble> References: <20230912152645.0868a96a@canb.auug.org.au> <20230913210829.zkxv6qqlamymhatr@treble> <202309131758.208804F4@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <202309131758.208804F4@keescook> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Sep 2023 06:51:56 -0700 (PDT) On Wed, Sep 13, 2023 at 06:01:42PM -0700, Kees Cook wrote: > > +++ b/fs/bcachefs/buckets.h > > @@ -180,7 +180,7 @@ static inline u64 bch2_dev_buckets_reserved(struct bch_dev *ca, enum bch_waterma > > > > switch (watermark) { > > case BCH_WATERMARK_NR: > > - unreachable(); > > + BUG(); > > Linus gets really upset about new BUG() usage (takes out the entire > system): > https://docs.kernel.org/process/deprecated.html#bug-and-bug-on > > It'd be nicer to actually handle the impossible case. (WARN and return > 0?) Sure, see below. BTW, I'm about to go off grid for 1.5 weeks, so there will be no v3 coming from me anytime soon :-) ---8<--- From: Josh Poimboeuf Subject: [PATCH v2] bcachefs: Remove undefined behavior in bch2_dev_buckets_reserved() In general it's a good idea to avoid using bare unreachable() because it introduces undefined behavior in compiled code. In this case it even confuses GCC into emitting an empty unused bch2_dev_buckets_reserved.part.0() function. Use WARN_ON(1) instead, which is nice and defined. While in theory it should never trigger, if something were to go awry and the BCH_WATERMARK_NR case were to actually hit, the failure mode is more robust. Fixes the following warnings: vmlinux.o: warning: objtool: bch2_bucket_alloc_trans() falls through to next function bch2_reset_alloc_cursors() vmlinux.o: warning: objtool: bch2_dev_buckets_reserved.part.0() is missing an ELF size annotation Reported-by: Randy Dunlap Signed-off-by: Josh Poimboeuf --- fs/bcachefs/buckets.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/bcachefs/buckets.h b/fs/bcachefs/buckets.h index f192809f50cf..211f054bf83d 100644 --- a/fs/bcachefs/buckets.h +++ b/fs/bcachefs/buckets.h @@ -180,7 +180,8 @@ static inline u64 bch2_dev_buckets_reserved(struct bch_dev *ca, enum bch_waterma switch (watermark) { case BCH_WATERMARK_NR: - unreachable(); + WARN_ON(1); + break; case BCH_WATERMARK_stripe: reserved += ca->mi.nbuckets >> 6; fallthrough; -- 2.41.0