From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 9014D287263 for ; Mon, 9 Mar 2026 22:32:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773095526; cv=none; b=daCl9sh1mJPXPaHwPrZSIhnrCWImXx275Glq/y7KRf4/KuofYkIZx+N1cGZM+l0Q/H/wuh/+jcvLcI3VMhIxJC1ZYjImV55z+/2T4Cw1KjT5HvRzVZA1zMXT1F8Poh4cw+7AIPj3zuvrciEcYFlKRx2VWOzG2PFSWSFOiokF3Ts= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773095526; c=relaxed/simple; bh=Ka0jVISzipJAqHRkCGQhv2ocUOj57W+L55ihA8NY06k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=O7heGCbaqQvdbPM/wO9wK2caS9WjFAiCzN1jU4QXadFwDlt1Ycv2w3dSW6A5EqK5p4C1nwc//pq0M+Dxr6zhR/3O5l0+C/fOM3XGmZKlubS/WMScqnsDoBmofUcCoelhnlDyaLEMYlD+AdL4ynhqEpfEmHxpvCpYZzekIZQa2zE= 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=DrCZceSZ; arc=none smtp.client-ip=209.85.214.175 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="DrCZceSZ" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2aea4ebb048so5585ad.1 for ; Mon, 09 Mar 2026 15:32:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773095525; x=1773700325; 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=IBkcZ4vNzPnscp2wv/tDrm8if6LphvMnNawG/F/pvx8=; b=DrCZceSZargkLUVKGz53iBEIsfokL3DKF8MEcIHoWQo8g1C+7SPJZrQHYbY4QarKBp Y1r/0A7aq/Tw5zbsr91k0BbkncsWtPC5YGxrDpgBqtkzE6VvISUoN9NpO2muYEcxq1Xs 073AOb2kWznabLjkl14HVSZ2hQLfjZEWpG7nwFUwelcZ3/0r5QAQFj1XR6Xe4y9OhCtV RcF6a2bGZUVv0hWalXgW/iccqjwrhgNdfoi1MDFCYF3cqYnaRuQeJ3RToSL//drD24zJ fEw+OhJKmK6dOMfHuXhIrfoIlIvSCSBFHRpuXIRpy+XJRqJfVpRW11qaIQOHus3lM4zP htRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773095525; x=1773700325; 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=IBkcZ4vNzPnscp2wv/tDrm8if6LphvMnNawG/F/pvx8=; b=Mol98r0dOd7P4SvuI8391meieMaTmxJRUh3v5TUKJohPom3PCRteVIevHPWVj3kenl dw3eDvWlRvJwTtYCEstg97oD5zJDMt/jNj7qu+Ca1a2GI9pBdjW9g0OXYtzmmtfvQu0C LDeVEjKy3T4YMp4V8MvKsrLaslFRcfnshRZrXb5qHZdPittjIwHunwte3kUcURvo7bSm 6/tXCUyt9PHBtbzkJw1MgotKIn7g6nQlEFKehmfHIUR5H0aSylL3u6/UoJcim4NisouV hShURF+HDwY1URKbeNf8rGwD6875EHMfgFJlYt2y3XCy4IteTvZUuNTdkOOSXopr+w9b umgQ== X-Forwarded-Encrypted: i=1; AJvYcCV+9ZrIGKA4FCMI6SDon0IoJcEd9f6sD9xBU0A6gKqHKeCUSJy3GfxAsFP5uPdb/6lKQ6Prn/gCDJHGFgI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2OH7EwJ9NfQdRK1B8107mVtDWf3ZAaxKSAB+nT8Slm6bw3DMl N0Oesc93uz/agNj/ALV3uK2pC0bAHmnTlnn7n/Yr66JwaDLa3N4kBGqUBCxISEyE2A== X-Gm-Gg: ATEYQzwuY/RY39Q0ZIAmLFd7IS3LGnjTFHemNozcX/5Aggkxrg1D6kfMU3dL3IHnKhl N3pcUoJVqKbWH+9n8ke7oYCVy0SEdc2xQc4HlumW9WkqcEsxR9JqLzTvdqaQNr7tBnEEz0RAymW cyCLZE3qYdLcdILWAbNue7B4Ov1jw4AxXUiKkQANmhf3VIAcsNz9o3144fBgWSc95DR+QAJnzTk y7rhW/bgKIWw2Wb/k9gTZXRKJnZgs4cWxOIo1MRV3pnTzB3TNjgxZZz35i7aokQFezZbY1tTBVR x6L20c4OyS154amSSY5bq2QRyOwB5J4nFOUPZOmA2ghStJR8+hoL2gQUSm97ZA/Ymo5bB2/Vo8E 3NYLkkEzfRyRy0FOm7H6n3UEXpBJlbjwZDNP5bSjcksZCuCyenfoMlgJTzqhY8xIUPt/7K+dd1l PfJu0QnQwyXh7BEI6gHX7yao7rriymBXDINIIcQop3Lf5LiXqYegkTbCfeyvU6x7n7azPuY3vke Cmj6A== X-Received: by 2002:a17:903:46c7:b0:2a7:5652:50b2 with SMTP id d9443c01a7336-2aea456730emr562725ad.9.1773095524481; Mon, 09 Mar 2026 15:32:04 -0700 (PDT) Received: from google.com (197.23.125.34.bc.googleusercontent.com. [34.125.23.197]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-829a4867e54sm11494132b3a.35.2026.03.09.15.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 15:32:02 -0700 (PDT) Date: Mon, 9 Mar 2026 22:31:56 +0000 From: Sami Tolvanen To: Carlos Llamas Cc: Kees Cook , Peter Zijlstra , 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: <20260309223156.GA73501@google.com> 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: Hi Carlos, On Mon, Mar 09, 2026 at 07:27:49PM +0000, Carlos Llamas wrote: > 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. If you need a stub with a matching CFI type for an arbitrary function, perhaps you can do something like this (arm64, untested): #define DEFINE_TYPED_STUB_RET0(name, reffunc) \ typeof(reffunc) name; \ __ADDRESSABLE(name); \ asm( \ " " __ALIGN_STR " \n" \ " .4byte __kcfi_typeid_" #name " \n" \ #name ": \n" \ " bti c \n" \ " mov x0, xzr \n" \ " ret " \ ) For the !CONFIG_CFI case, or architectures that implement static calls, you can probably just point the stub to __static_call_return0: #define DEFINE_TYPED_STUB_RET0(name, reffunc) \ typeof(reffunc) name __asm__("__static_call_return0") Sami