From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 883B1367B60 for ; Tue, 30 Jun 2026 13:55:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782827704; cv=none; b=FvoCsTRPqfFP6iuMZKAJjBy8ZUuHbiQ0/9K6PKUMn90ILjGIQxzTxtX/xTCZJ6OBLLELru09kCdiP4msq+hqx+vyWoJ/N1eTONbaTG5AhfdsYSSysQhsttVf3T61cBKqGqo9wdA1FFdtl3TuErvZiDNCc9Ki5e5jgYzcrWgSnqU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782827704; c=relaxed/simple; bh=BZTIV6TqTeB7J+1Dtg4pF50uudgrKv7bFjkquNTPB7s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BCVwLvjwxRWeJnMAWfzmP1MOQBDASfZX206st5YLlrZWlJ56HfdG8OIBjaVJLL/j65nE8RuZ5XPW0Jgamga1Il4Qt28ttU3LYkl9kluDTxAIBSWNNOSDiGE71o7Va0v/OVCMWbEtJie0OOtvBu6vLvew09A/zZuw7iohPj3zrVk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=EtvvyWb/; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="EtvvyWb/" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=0qcJqCcklKVPAFlEqPl6j+3Jq7S/eKAGS4aOmQ/9Nqs=; b=EtvvyWb/LPBu5O2h86UY+qYwvz KB9pmGprDbh9o5O753xsWn30CoVqpaz7ScYZTF/3klj7YZ24P4tLYS+cIFy/xQsnUHEGmpzp47NdM d4oohvIdBvG9g506ejXJ9RLucWhY5EzO1QiK/OxwzlNOCYnI2VLMpoHNZqN3k4ZH/ybXOYMN7uQgn ALk3xJPt8gtfQIVnifFhQaOUl3uIGJBCrqlGBpR/yKD+ofk9QN0siBOxiwUNMRSr5GpP/TlL/SqwI UDQucyYOW4ABr5Sy1Qjtj3EoYZKPG2T9p44cFisTaDUQ+Rn4Col8N2SXRKq96TOb+BqNx6p0GADYs iU15qwUw==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.99.2 #2 (Red Hat Linux)) id 1weYvM-00000001wRo-1kBz; Tue, 30 Jun 2026 13:54:52 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 7EEE8300339; Tue, 30 Jun 2026 15:54:50 +0200 (CEST) Date: Tue, 30 Jun 2026 15:54:50 +0200 From: Peter Zijlstra To: Dmitry Antipov , glider@google.com, elver@google.com, dvyukov@google.com Cc: Josh Poimboeuf , Thomas Gleixner , linux-kernel@vger.kernel.org, nathan@kernel.org, nick.desaulniers+lkml@gmail.com, morbo@google.com, justinstitt@google.com Subject: Re: objtool: undefined stack state in folio_zero_user() Message-ID: <20260630135450.GA921102@noisy.programming.kicks-ass.net> References: <35822cf3c35fc6621621f858e94a2b0ce19abf88.camel@yandex.ru> <20260630104434.GC751831@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260630104434.GC751831@noisy.programming.kicks-ass.net> + KMSAN / clang folks On Tue, Jun 30, 2026 at 12:44:35PM +0200, Peter Zijlstra wrote: > On Mon, Jun 22, 2026 at 04:23:46PM +0300, Dmitry Antipov wrote: > > As of ef0c9f75a195 ("lib: Add stale 'raid6' directory to .gitignore file") > > with clang 22.1.8 and KMSAN enabled, objtool stucks in folio_zero_user(): > > > > $ ./tools/objtool/objtool --hacks=jump_label --hacks=noinstr \ > > --hacks=skylake --ibt --prefix=16 --orc --retpoline --rethunk \ > > --static-call --uaccess --no-unreachable --noinstr --unret --link \ > > vmlinux.o > > vmlinux.o: warning: objtool: folio_zero_user+0x947: undefined stack state > > vmlinux.o: error: objtool: folio_zero_user+0x947: unknown CFA base reg -1 > > > > Dmitry > > > 0000000001533940 : > > > 1534272: 48 89 e1 mov %rsp,%rcx > > 1534275: 48 85 ed test %rbp,%rbp > > 1534278: 8b 54 24 1c mov 0x1c(%rsp),%edx > > 153427c: 0f 85 c2 00 00 00 jne 1534344 > > 1534282: 31 c0 xor %eax,%eax > > 1534284: 48 89 cc mov %rcx,%rsp > > 1534287: 4c 89 f7 mov %r14,%rdi ;; HERE > > ... > > 1534327: 48 89 64 24 78 mov %rsp,0x78(%rsp) > ... > > 153433a: 48 8b 4c 24 78 mov 0x78(%rsp),%rcx > > 153433f: e9 31 ff ff ff jmp 1534275 > > > This is well insane codegen, and I cannot blame objtool for hating on it > -- in fact, I hate on it too. > > Let me try and figure out how best to fix this insane compiler output. This seems to 'work', but it is somewhat yuck. Josh, any better ideas? --- diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c index 1b387d5a195b..839c91d3c28c 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -391,7 +391,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec break; - case 0x89: + case 0x89: /* mov r16/32/64,r/m16/32/64 */ if (!rex_w) break; @@ -430,7 +430,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec } fallthrough; - case 0x88: + case 0x88: /* mov r8, r/m8 */ if (!rex_w) break; @@ -462,7 +462,7 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec break; - case 0x8b: + case 0x8b: /* mov r/m16/32/64, r16/32/64 */ if (!rex_w) break; @@ -494,6 +494,9 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec break; + case 0x8a: /* mov r/m8, r8 */ + break; + case 0x8d: if (mod_is_reg()) { WARN("invalid LEA encoding at %s:0x%lx", sec->name, offset); diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 10b18cf9c360..53a67b322856 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3149,8 +3149,25 @@ static int update_cfi_state(struct instruction *insn, /* drap: mov disp(%rbp), %reg */ restore_reg(cfi, op->dest.reg); + } else if (op->src.reg == CFI_SP && + regs[CFI_SP].base == CFI_CFA && + op->src.offset == regs[CFI_SP].offset + cfi->stack_size) { + + /* + * Clang RSP musical chains: + * + * mov %rsp, disp(%rsp) + * ... + * mov disp(%rsp), %reg [handled here] + * ... + * mov %reg, %rsp + */ + cfi->vals[op->dest.reg].base = CFI_CFA; + cfi->vals[op->dest.reg].offset = -cfi->stack_size; + restore_reg(cfi, CFI_SP); + } else if (op->src.reg == cfa->base && - op->src.offset == regs[op->dest.reg].offset + cfa->offset) { + op->src.offset == regs[op->dest.reg].offset + cfa->offset) { /* mov disp(%rbp), %reg */ /* mov disp(%rsp), %reg */ @@ -3233,6 +3250,12 @@ static int update_cfi_state(struct instruction *insn, } else if (op->dest.reg == cfa->base) { + /* mov %rsp, disp(%rsp) */ + if (op->src.reg == CFI_SP && cfi->regs[CFI_SP].base == CFI_UNDEFINED) { + cfi->regs[CFI_SP].base = CFI_CFA; + cfi->regs[CFI_SP].offset = op->dest.offset - cfi->stack_size; + } + /* mov reg, disp(%rbp) */ /* mov reg, disp(%rsp) */ save_reg(cfi, op->src.reg, CFI_CFA,