From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D330AEE3698 for ; Thu, 12 Feb 2026 15:29:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1229297.1535260 (Exim 4.92) (envelope-from ) id 1vqYdJ-0006b6-6F; Thu, 12 Feb 2026 15:29:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1229297.1535260; Thu, 12 Feb 2026 15:29:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vqYdJ-0006az-2c; Thu, 12 Feb 2026 15:29:33 +0000 Received: by outflank-mailman (input) for mailman id 1229297; Thu, 12 Feb 2026 15:29:32 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vqYdI-0006at-7o for xen-devel@lists.xenproject.org; Thu, 12 Feb 2026 15:29:32 +0000 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azlp170100001.outbound.protection.outlook.com [2a01:111:f403:c110::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9d6cc0d1-0827-11f1-9ccf-f158ae23cfc8; Thu, 12 Feb 2026 16:29:26 +0100 (CET) Received: from BN9PR03CA0776.namprd03.prod.outlook.com (2603:10b6:408:13a::31) by MW6PR12MB7072.namprd12.prod.outlook.com (2603:10b6:303:238::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9611.11; Thu, 12 Feb 2026 15:29:19 +0000 Received: from BN3PEPF0000B077.namprd04.prod.outlook.com (2603:10b6:408:13a:cafe::9e) by BN9PR03CA0776.outlook.office365.com (2603:10b6:408:13a::31) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9611.11 via Frontend Transport; Thu, 12 Feb 2026 15:29:04 +0000 Received: from satlexmb07.amd.com (165.204.84.17) by BN3PEPF0000B077.mail.protection.outlook.com (10.167.243.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9611.8 via Frontend Transport; Thu, 12 Feb 2026 15:29:19 +0000 Received: from localhost (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 12 Feb 2026 09:29:18 -0600 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9d6cc0d1-0827-11f1-9ccf-f158ae23cfc8 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BlKJxYAWr5ed9D7SsyImVkeODMJOIHB6yxRG2OC2wpy9vNr/9fXqoDu/uOuleu1KoJm3q4ZqkWFMNErp5RzwH0qO5yOVzE8wauebAmWBQ0X/czGaK/GmTZs3YsSXv6xqw5H7sW0dmPawV2gKW0YmthwOXhLb4hkiFLd8ClT2zcI/0lLFBu8i2TXz5b/0JtlXm/JRjzLGqy7jdwnjUWgAt2VysuNtRSJ4Uz9zILOgHB0UMc0MtnPBn4VS3aSdgw8x9TUlzC6jX/ssPXOYyHwf5tDeQjIrxBd/vJZdg9D3pkD1zmXuciO3m88eYHCveZ9ANAH0jmcybQUlynihSVIJuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sw5ygoxVKiT+AAE2mVV5SNuh5d1fTHTcz39e3luENq4=; b=X6uBbkixlnVaPCeNMY0qM+JREe4u/0CLlUk95U1/e8gPjRh6a/K/uTEa/jy+gEXW5w/NTBv895p6SyFIk9JxfBiLIbhGnSFB16XfTVioRn7kj8kS9tb5VDlf7Nz+NCo+6ejaej1zbBVpvaBvObINYiJGqOmc30RhSwlpwHR8T11qFYeOofX8nj4IEHr2DQ6NUgWKFFQSYPMW/ZFaU8xYtbHRNANI5Up8/z2AEjcFIQ2B2NTPRUAsbnnbdJk8/dkLcvF/OlTNgoDnLX40OBnUwIKM3p4czdK3R/oqHApI7CPg0x+5dn/njzc/bxXYVpIAuIu9J6LYKh7zp5DJQQPw4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sw5ygoxVKiT+AAE2mVV5SNuh5d1fTHTcz39e3luENq4=; b=gFza4miggg2wCbKT8XOr97VqSvyiVyppqDF3NbxMGqdRJHzFNoX509i6hyIS0FtAnyzfUSuIkoJp5cUjezIuUhWa1gDpVOL9BEiKFZ8JhCbTTJnMR83K6qk5vlQ7Rm/L0SueQA6f8J7JW0l5J3ef98X3tRYTmoOVWWJxwTNa940= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Date: Thu, 12 Feb 2026 16:29:16 +0100 Message-ID: To: Jan Beulich CC: Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Jason Andryuk , Subject: Re: [PATCH 07/12] x86: Have x86_emulate/ implement the single-vendor optimisation From: Alejandro Vallejo X-Mailer: aerc 0.20.1 References: <20260206161539.209922-1-alejandro.garciavallejo@amd.com> <20260206161539.209922-8-alejandro.garciavallejo@amd.com> <100f63bf-cc79-43c3-a0f6-147d2dff080d@suse.com> In-Reply-To: <100f63bf-cc79-43c3-a0f6-147d2dff080d@suse.com> X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B077:EE_|MW6PR12MB7072:EE_ X-MS-Office365-Filtering-Correlation-Id: 900b0578-414d-4fd2-a787-08de6a4b7d8e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?B?amlyRWVNRFlpci84TGlEdnNIWG5UczFPdEJpZ2xROGVOSEo1NGl6YlhpRUN6?= =?utf-8?B?QVVLRlQyMU9qWVE4TUdjWkZyRTBXWEExcW5VaW9aTzFjNXVFUnMyUjRORlFF?= =?utf-8?B?azcvbHhyV0dzeDNqbXZubEJhMjF5TEdtNlVBUjUwcytFdkJnWlg3elpraEtH?= =?utf-8?B?TVVUSHNCR3pGOENtNjVxVmlqVjhWMGh6dWN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ekVU?= =?utf-8?B?cmxXVEhsWU1NYnRxV3VPbm5scTRmQVNybVFKRXpLZDZQelRELzdZaldsZW5K?= =?utf-8?B?ZmtDcksvUUViSkV0MVcvNGFEeTNON3pQR0VQWi9Nd0dlMENHcFRybk4xNG4z?= =?utf-8?B?a0EyNUx5WG9oYW05SXpNVGlITUVKSnBETDNnM040Q2JDWHFkalVDZVZTRWNC?= =?utf-8?B?cnVpbkJXMmttOGlDR1hySHFsVE1WNWRyc2k3ZlQrdmppZ203T3lQb1hMWGpC?= =?utf-8?B?aDFqQW1NWTZkbm96VXI3bU9ERTNnPT0=?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(376014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 68g1ex/LTSr/oMJeRY/iBmY9CEzYmUUT3lX9TvsKeOQWpZxuv4sz5mlDEvOc3BnJozCw3y2BMxoThqNz3dnRtC4wN7ixi/fRnkMGgT9N7vQ/4AI2OYXUHcox3aBP6iBJT97HoDQKGqm1F4XYY57Ter5b9jttoEnhV97SNaVNjKZflptsz1/7x0xiaEkT6+VeXEv7vMtXUQPPJfmqnr6khQu8JnHMJinEYtSFgc7zN2WStDPVIUbPRyyyoOt6b5k4k/ipW6A7tQ6xUeamD1VnSSU83bxlnF2brYHcQAgMkShHKttgAznM9xAe+T1GzOCrqt+E2N1Fg0Xs81aZSGyvn6MefyVujmzuetvLcCm+FSGiopazzHre8TUTGwaPvdIYtDvM3E2p9Yy2rbJSRz4lZWz7eiTFfcDZ5HS1duXdX76QZk1cBUn9FjoKAWbWtZLI X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2026 15:29:19.4349 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 900b0578-414d-4fd2-a787-08de6a4b7d8e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B077.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB7072 On Thu Feb 12, 2026 at 12:26 PM CET, Jan Beulich wrote: > On 06.02.2026 17:15, Alejandro Vallejo wrote: >> Open code the vendor check through the policy as a one-off. The emulator >> embeds amd_like() in macros and is called in MANY places. Using a >> local variable (cp->x86_vendor) makes it a lot smaller (300-400 bytes >> smaller). So treat this as the exception it is and let it use the policy >> rather than boot_cpu_data. > > As elsewhere you mainly discuss benefits for the single-vendor case, is t= he > above about the opposite situation? Else why would codegen suffer this mu= ch > here? In single-vendor it doesn't matter. A constant is a constant. It matters in multivendor. And it matters for 2 reasons. 1. The x86_emulate() function is HUGE. 2. The x86_emulate() function has LOTS of amd_like() invocations. When amd_like() uses the policy it has an advantage over using the global. Namely, the policy is already cached in a register, so codegen simply has t= o pull the vendor from an offset into a register. When we go for a global var= iable we need to reach out and pull the variable from its 64bit address (because = we compile with model=3Dlarge). It normally evens out with the codegen reducti= ons cpu_vendor() encourages you to have, but in here it just doesn't. There's w= ay too many accesses to global state and .text suffers. The fix for this is caching the vendor somewhere else. A "bool amd_like" in= a local variable would shrink code substantially (by having rsp-relative acce= ss to the solution of the question amd_like() asks, and by avoiding the masking).= This optimisation is worth doing with or without this patch in place. Alas, I didn't test that, because this series was sufficiently complicated as-is. > > Using cp also is preferable for test and fuzzing harnesses, which don't > even know boot_cpu_data. They don't now, which is why I made the x86emul_cpu() macro. New subsystems added to a userlevel testing ground could simply have a boot_cpu_data with = the desired policy as part of their harness' global state. > >> @@ -30,8 +31,15 @@ void BUG(void); >> # define X86EMUL_NO_SIMD >> # endif >> =20 >> +/* intentionally avoid cpu_vendor(), as it produces much worse codegen = */ > > Nit (style): Capital letter wanted at the start. > >> +# define x86emul_cpu(cp) ((X86_ENABLED_VENDORS =3D=3D \ >> + ISOLATE_LSB(X86_ENABLED_VENDORS)) \ >> + ? X86_ENABLED_VENDORS \ >> + : ((cp)->x86_vendor & X86_ENABLED_VENDOR= S)) > > Nit: Indentation. The ? and : want to align with the controlling expressi= on. sure. > > Further, is this a good name, without "vendor" in it? x86emul_cpu_vendor() is fine with me too. > > And then I'm of two minds here as to the use of the macro parameter: On o= ne > hand we can be pretty certain what is passed in won't have side effects. > Otoh in a hypothetical odd case (seeing that this lives in a header file, > not local to an isolated piece of code) where there would be one, the > argument being evaluated unreliably could cause an unpleasant surprise. > The more ... > >> #else /* !__XEN__ */ >> # include "x86-emulate.h" >> +# define x86emul_cpu(cp) ((cp)->x86_vendor) > > ... that the same wouldn't be observable in the fuzzing or test harnesses= . I can turn this into a static inline to avoid such worries. Cheers, Alejandro