From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AAD723EA90 for ; Mon, 9 Mar 2026 19:27:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773084476; cv=none; b=WmBysRUE/BXRjUCN4/Uu3hpgC0gzztmplRTDWIKKeihN09WLosrhw9LKWU7ReYo3CQq7o9490d8mg5mH3oGokvFtm1L7dRglZo2xy9VoGnDYqYV2k9Quc572sd6eU+YDtYyc88IH8Xsr6/okF9pE5ty5oqJoqZ3OK1ttU8hab2M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773084476; c=relaxed/simple; bh=mDnIlWt5S6ZYGX9wYtM4TlzRPCybD/Bxq0jFAVwaScE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nOEkJ/8+15ou7/JWvak4Fd46BJrE5U/TveAWSv9L6g6KyftgQR0reREYl+2KzQ5ORgbW7NCfDKtbxQ7yM9yKPXy4JUqwCG69//ZnQVjsDBjwRxkx3SsaD5QhqtsBJr9ehYlsatHoKGOJ3YMMJwen0KpRBUWzmjtdkxJGo4jVFoM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HH6kr/x1; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HH6kr/x1" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2ae4b40999bso1695ad.1 for ; Mon, 09 Mar 2026 12:27:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773084475; x=1773689275; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=+5+N+QS7JaZPLj+uCtT6Y1yacnGRCT6luuIZGAnMNOM=; b=HH6kr/x1pVeM9tsVVf2aG71BPUUjvh3qWnKiTEVcn5AMBjBvmFpvSqRpCQ1KQqeGCS 7S3cl8iJPjXP6dIAmuVubCIZiDQN9uYap/gN0qd1xCoN/LZdePKpkWq2ljXrLUW0mbx4 sejRYFYs28Oh1k7pUniwY0V9fZH8t9DHLfla367AzDuH45s0pHcoCR2TC4cCVzofj6cZ QCQ+aaW9i9SXPUqF5BNHeL0jnyhAwFLOObm9s3BmOTPVYsdWkvIsVnmuA1++RIatG5sW jmK+XrgEzSUgSsjPsQNhzRd0JV0krXpBl1yReH7+S3rzheK6HHVK2zqBaJ3kgsWlOveF XuYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773084475; x=1773689275; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+5+N+QS7JaZPLj+uCtT6Y1yacnGRCT6luuIZGAnMNOM=; b=XBbsswAFXzWH1MJNbrnL3lzZEoYn8VqRNwEE7nC9NQJv78mTjrpcH9qQXIAEBt8Vb8 /v/nocVK29asGAYJZ6F6gJb7Scp6dVYrjH5UZO8/Ng/o+kyZ9OLQ+K0nwQsxQYvCA2cc Ho7Mdx6+Fn4/DCFC3OCPjqDnYMyDT7vjxJjEgUY08mDvTtd7vOZrCwsAwcC8jcvu22Gm OrJf1u/77ea39B+GsSyg2Y8NovV4vn8ZImTps18roq/TBUPBJP5AxP0/TnBKwle+1083 ndNt0u0ub8FFbGbm6adDEq78C0UWlx3iFT/a7cXP23B6XfGsPV7SjPOmZTOJJr3XZcgq 5dzg== X-Forwarded-Encrypted: i=1; AJvYcCUlLSnGtxxppzoO2ds8XDNStDQx163ypXNNOnIrAZsiZ3W9jq4iONtZqD5FX7sfLUNt4cGnqv5KZ5lJqcQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4C9Y0lzJDbJHGIMmzIywuWs2ZnGrJZ1HIqH3XQAFRmqTB4SGJ ZAnfEJb470fNhXJqYgE5fEzQCghqBKZ1dvhRTQB1O1BOSAtjHxCgAiNy89mG3dBgjg== X-Gm-Gg: ATEYQzz5vkJSDBmeryWqIwR8og7KXTL7L3hCDL2LSVmKkLtgEUf1P/rXOG04NG+Fxlt ggeeROIDX79SXLKRZoLHl1n/tcnQspqMoTvW6AYL8HuNPOvJ6y2yHi1X2mz7sgJWgMSjety1yCa rQjK+pjgdY6Fjwl+7/wBRV90dVB9nKuZcrn2sGf14kP6tV9TfyrWEhDre+6GKFR+qZjvlp3Aue9 hwlBVgPIlxUedvSZag8C/qBpvETXigGRvkrs64WtqOCj51B5VsySp1ONJ75xVm4MWfZwRBdPDe2 5w9dO+9yNu7EY8dAeaTf32tbXG9s6rnLaRRBky9TNY8dnxH5zX6rCT86bDbkhHkYReyTPSUp3en oGbB/J10AjjHEo8KrBpTP3oASjF5KTqhwajQc6sTk4HNJw0dxsZL2nkNNbHVnCPJWBR+xYUXYIw WXVM0BGOcqgseZ80hjIQKrn8afv7Nj/9ULY7Gnr/KSlFq5tl3gXrtY3iF0xyQ/+LBG3PpiXkVr X-Received: by 2002:a17:902:ce0c:b0:2a7:87c2:fcde with SMTP id d9443c01a7336-2aea3258530mr529395ad.15.1773084474262; Mon, 09 Mar 2026 12:27:54 -0700 (PDT) Received: from google.com (154.52.125.34.bc.googleusercontent.com. [34.125.52.154]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c739e16cebbsm9655626a12.16.2026.03.09.12.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 12:27:53 -0700 (PDT) Date: Mon, 9 Mar 2026 19:27:49 +0000 From: Carlos Llamas To: Kees Cook Cc: Peter Zijlstra , Sami Tolvanen , Sean Christopherson , LKML , linux-arm-kernel , kvmarm , kvm@vger.kernel.org, Will McVicker Subject: Re: [PATCH v4 09/17] perf/core: Use static_call to optimize perf_guest_info_callbacks Message-ID: References: <20211111020738.2512932-1-seanjc@google.com> <20211111020738.2512932-10-seanjc@google.com> <202202061011.A255DE55B@keescook> <202202061854.B5B11282@keescook> 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: <202202061854.B5B11282@keescook> On Sun, Feb 06, 2022 at 06:55:56PM -0800, Kees Cook wrote: > On Sun, Feb 06, 2022 at 09:28:52PM +0100, Peter Zijlstra wrote: > > On Sun, Feb 06, 2022 at 10:45:15AM -0800, Kees Cook wrote: > > > > > I'm digging through the macros to sort this out, but IIUC, an example of > > > the problem is: > > > > > > > > so the caller is expecting "unsigned int (*)(void)" but the prototype > > > of __static_call_return0 is "long (*)(void)": > > > > > > long __static_call_return0(void); > > > > > > Could we simply declare a type-matched ret0 trampoline too? > > > > That'll work for this case, but the next case the function will have > > arguments we'll need even more nonsense... > > Shouldn't the typeof() work there too, though? I.e. as long as the > return value can hold a "0", it'd work. I gave this a shot but then hit a wall with the arguments indeed: typedef int (perf_snapshot_branch_stack_t)(struct perf_branch_entry *entries, unsigned int cnt); [...] DEFINE_STATIC_CALL_RET0(perf_snapshot_branch_stack, perf_snapshot_branch_stack_t); I can generate a stub with the matching return type using typeof() but the arguments have to be fixed e.g. to (void): #define DEFINE_STATIC_CALL_RET0(name, _func) \ static inline typeof(((typeof(_func)*)0)()) \ __static_call_ret0_##name(void) { return 0; } \ __DEFINE_STATIC_CALL(name, _func, __static_call_ret0_##name) I believe this would work for most perf callbacks cases except the one above because the arguments would generate a different hash for CFI. > > > And as stated in that other email, there's tb_stub_func() having the > > exact same problem as well. > > Yeah, I'd need to go look at that again. Is this testing for "_func == __static_call_return0" in static_call()? Ok, but I don't understand how to handle the arguments here either. The call sites do "static_call(name)(...)", and I don't see a way to handle this using macro magic. > > > The x86_64 CFI patches had a work-around for this, that could trivially > > be lifted I suppose. > > Yeah, I think it'd be similar. I haven't had a chance to go look at that > again... > What is this work-around for x86? Downstream I had to resolve this my providing individual stubs for each DEFINE_STATIC_CALL_RET0() :( If you care to see my hack: https://android-review.googlesource.com/c/kernel/common/+/3980171 I don't have a clue on how to fix this properly though. Any ideas? -- Carlos Llamas