Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4306445rwi; Sat, 22 Oct 2022 08:05:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM69N+bdEGa0i72u4Xe38Atmpg8VfuAmvLHGcyftCzFzLZSgunWWpruZSVgF+e8tQnp6w8uX X-Received: by 2002:aa7:c302:0:b0:461:85d7:b82 with SMTP id l2-20020aa7c302000000b0046185d70b82mr2134227edq.354.1666451140602; Sat, 22 Oct 2022 08:05:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666451140; cv=none; d=google.com; s=arc-20160816; b=hnjBvPq1tmkj+/fS8OwT9ocdljbGH6OEaua1Ka/yzVYCWynWTTBA1EsW8sasNFDxGX 7EQYEAk3CdyZNqzlkeoZfSETUHlEDvTc3Dg+FB4s2s2Y5HSFPFFIrfkoFYFqj44qkt0o oWJdI/3zyyZgvsx9uo91Y8vwGSYeC0OLSLamtN096iTF+umI3dnaYNj9PNfKZ6IHhDWN EOlWv7DnhdDX74RXSkgnj79CuC4hiL5cPW1j/38e+q+YixTIEVtcynGVX+Ja6vlopPEd zMYzRRvm0dH/tWS4PzyhCTARPhu/jkOFlbNscmxXNyuIhLoMd/BMwVZX13cqvHWTJQbu Gpug== 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=LfDdHQU4IT/hl9I/5HNnFT18wMtiD3dXD2LsNJVhO5Y=; b=kak/WXeipYGfuhY/Ms55lD8+WySGINCAiyEO56g/Ipz1jsetvawHSekSoUMWOEmGfZ 6vt5F4yxrAtOF9WNuOPWT0sEGhDld8pqkeuTiPevgUOyOpyZOmS6KRraUZI0UVOgiv6V l4It4ml/as7lHb9+R07km3SV40NjHnphf+D6eYKFrDONXBW0QHOw4Y16end2QXSlBYQi ViF2fOdYQjMLkPru7A/m6EbFYtfd87WL+645EJS1GEslQ5zdEAGnCXw9nD12YdrjpnJO GLF1Ham9OIhPJhi7zHHwYCooLzXMaLYYGERUh/ahpk4m2IWkOvklwnnGlAZNNRC6KZ23 7CXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=dCyf9vlw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g22-20020a1709065d1600b0078277d265bcsi4251080ejt.204.2022.10.22.08.05.05; Sat, 22 Oct 2022 08:05:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=dCyf9vlw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229707AbiJVO5m (ORCPT + 99 others); Sat, 22 Oct 2022 10:57:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbiJVO5j (ORCPT ); Sat, 22 Oct 2022 10:57:39 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 843D4159949 for ; Sat, 22 Oct 2022 07:57:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=LfDdHQU4IT/hl9I/5HNnFT18wMtiD3dXD2LsNJVhO5Y=; b=dCyf9vlwvONBM4zSIsCL3Xkogn uhuZ7ki2qrs2doVxqulA1AE2JiYuCjEPz8IdtufwRps7O4skItg4W7b6DhivXsWUeYn06jdrezoRA cc7FhdHqiTTUJQZ/QiyFGxrzCbiOsWlEinzkbqP+vuySr6F7BFXavWD5WcH7D5AJ7DAQYWEyJ4Al6 cMkJduq0RcpDGmDYiho+MtfVYgU0GUYFB9bOtkbiV0CidzQmY7ghM3dDUCh0iNOYrx0syawZm2wHw ZbW9EWrjF8WGHfM82My18SxLd9yLHpd0t7+tJQnWYbJHrLeqsnHx+9WC9uCpPZRfwChIclGKOGh4Z nIO6WG2A==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1omFwD-00DzS4-Nz; Sat, 22 Oct 2022 14:57:25 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7C40E30035C; Sat, 22 Oct 2022 16:57:19 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 192882C30ED69; Sat, 22 Oct 2022 16:57:19 +0200 (CEST) Date: Sat, 22 Oct 2022 16:57:18 +0200 From: Peter Zijlstra To: Mark Rutland Cc: llvm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Fangrui Song , Joao Moreira , Josh Poimboeuf , Kees Cook , Nathan Chancellor , Nick Desaulniers , Sami Tolvanen Subject: Re: kCFI && patchable-function-entry=M,N Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 21, 2022 at 04:56:20PM +0100, Mark Rutland wrote: > Hi, > > For arm64, I'd like to use -fatchable-function-entry=M,N (where N > 0), for our > ftrace implementation, which instruments *some* but not all functions. > Unfortuntately, this doesn't play nicely with -fsanitize=kcfi, as instrumented > and non-instrumented functions don't agree on where the type hash should live > relative to the function entry point, making them incompatible with one another. > AFAICT, there's no mechanism today to get them to agree. > > Today we use -fatchable-function-entry=2, which happens to avoid this. > ... but I understand that for x86, folk want the pre-function NOPs to > fall-through into the body of the function. Yep. > Is there any mechanism today that we could use to solve this, or could we > extend clang to have some options to control this behaviour? So the main pain-point for you is differentiating between function with notrace and those without it, right? That is; suppose you (like x86) globally do: -fpatchable-function-entry=4,2 to get a consistent function signature, you're up a creek because you use the __patchable_function_entries section to drive ftrace and now every function will have it. So perhaps something like: -fpatchable-function-entry=N,M,sectionname would help, then you can have notrace be the same layout, except a different section. Eg. something like: #define notrace __attribute__((patchable_function_entry(4,2,__notrace_function_entries))) It does make the whole: CFLAGS_REMOVE_file.o = $(CC_FLAGS_FTRACE) a bit of a pain, but I've long favoured removing all that and having explitic notrace attributes on all relevant functions. Then again; perhaps it could be made to work by ensuring CFLAGS starts with: -fpatchable-function-entry=4,2,__notrace_function_entries and have CC_FLAGS_FTRACE include (and hence override with) -fpatchable-function-entry=4,2,__ftrace_function_entries assuming that with duplicate argument the last is effective.