From patchwork Thu Jan 5 16:05:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13090124 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 158BDC3DA7A for ; Thu, 5 Jan 2023 16:06:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.472036.732129 (Exim 4.92) (envelope-from ) id 1pDSko-0005MP-8Y; Thu, 05 Jan 2023 16:06:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 472036.732129; Thu, 05 Jan 2023 16:06:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pDSko-0005MI-5k; Thu, 05 Jan 2023 16:06:06 +0000 Received: by outflank-mailman (input) for mailman id 472036; Thu, 05 Jan 2023 16:06:04 +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 1pDSkm-0005LZ-Ad for xen-devel@lists.xenproject.org; Thu, 05 Jan 2023 16:06:04 +0000 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2068.outbound.protection.outlook.com [40.107.241.68]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d9cb5a9d-8d12-11ed-b8d0-410ff93cb8f0; Thu, 05 Jan 2023 17:06:02 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by PA4PR04MB8046.eurprd04.prod.outlook.com (2603:10a6:102:ba::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Thu, 5 Jan 2023 16:06:00 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389%7]) with mapi id 15.20.5944.019; Thu, 5 Jan 2023 16:06:00 +0000 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: d9cb5a9d-8d12-11ed-b8d0-410ff93cb8f0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JK0twxZG6alBtmSSizwcYEyh563fpdxnpgziu3kcb+CZZ8IDa3K+w4U1anaG+W5B10VvmEUVzSq2++WzJjigo0XK4vSOicrqj0v7/FMvfiD/mtB4i+4DroFTkkLtV6kwzHTpAg1q61qYzpZinpL1gKcmbwwq6Hfcn5fasTL+8vpHh3MfmK8DkW5E9LdCmFpbgcmPIJa0m5wFw5cWxwgfkR/fG+0Y+p+jAyzm3fngBE/6TGSnp24Z07B2mgE0DvT47/AbpyVEmyQYoJFFdR7fy3/V5EyLlbboWGEUM2LwcndOzE4oVF0zW4lmyV72gemtGWqdkNl/uYstkh85iSql1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=tp/xRy5VT94YqOsqdM3hhLWnXJKhH74obPOAkyaCA0Q=; b=clxZolyFyrRJJ2KxqPgWzTGcPFh0Ka8PidOk5WXeoMN+a3lbNJxVedKEhiMtnQTLzaVNXZbt+L/sXRhqvk5rAD00BJvW4k7n+aeUbwZ8nuqjHJcgbfcazVtxF0Gy2AcYkZF7btAfAsAiyu2+xM6kFVtHvPVjz6V3MZSDfOIcItJE+15VvOCeDYJzJqu8GF5BYLnb+RAcQ3EHydRgnlw4GaAtzgJEEmtZ4VkSWJ+tqL05jcRr4TDgrx8RfuNmBQROOe4CW5pd77vgdVerYIVJCAcQpfjWtF8H6MN3V3UmMOPJZ3zDx2Qg+khE6ioIXnA6jKJy8DuG4OGx5SOEETi0dQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tp/xRy5VT94YqOsqdM3hhLWnXJKhH74obPOAkyaCA0Q=; b=wY3IacouTb28PDk+gWcXEamSJDS2A134FGrYIL0baydIR6X0TvXOQWNCUKq4VtvoPY7DyuwI2t5+r1u/qmEAasK5h8iT2n1epbzlR/A3Y+9FjykMmxCbpc9X7tbVEXMc4qJnof0BAzJfpWjngIkpmPNFamKGPP+EGFe6lzReulrfoGsIgylPajpULKo9SV5pTcZkCg5WOUmMq4KCyl17pNCey9xjj4iOa04hYI4lutWYL7nite7OBEjqP1XF7nUy3Q1xqvTEwErOCqRIP7md4JhplgA58MnyoHRFufh+SEjrI1P7mYzILrckaew0fm2lAGEp7JJ0knKkXTQbYIu+nw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Thu, 5 Jan 2023 17:05:59 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH 08/11] x86/shadow: reduce effort of hash calculation Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Tim Deegan , George Dunlap References: <074dc3bb-6057-4f61-d516-d0fe3551165c@suse.com> In-Reply-To: <074dc3bb-6057-4f61-d516-d0fe3551165c@suse.com> X-ClientProxiedBy: FR3P281CA0006.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1d::16) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|PA4PR04MB8046:EE_ X-MS-Office365-Filtering-Correlation-Id: 64ff1aa6-ab3e-4d85-38af-08daef36bd2f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KhmN35WnVVCHX3NTS8nYQ8roJdSOC+NdLb/oE7FghutaIbMflusxce+Qa2o9/ePhdtP7fSb6npkm70rH99J+SroCKqom1lPPQjYAfCDw6n+J3CWh9OqPXXVEWbXQXqufrAZgBxf+wsbDWwLKQ+LHED6bps0cPQUO2Eb/+ng16H16KmMfu4R0hchihMPwb5y40M13/q2CunrtLxoKEmRL1B5BSqBlcRJ/Mtk+bPpjAZ+hdk+FhbFx51UeE0aF1SzpEcTHCHFgh6xL1AfOFl9u1FMhGqy1b1tDC8B+9zAKk99PfFXhuaDTmJ6ZBkbe12qZTxy06z4XFEH3kc81Lkd2pFFLxo7tPnPLjiJRyaPvww0f6hXlfKtJ40Xe83tN1fdsT3AmCRemmZYB2JUx5s/uHhPEYe2OyewMpFa6JJb94QEdWnbbgusXidQUpWAjmOGT7agQ2lEHdSIlhPtuG0oN+4ckDMXZwCKUkH8swTLm00SMQcfp+ruSjmfDQuJhv7LJ3PSzF/6IilnfmXe0yqk6iXPMWwc9giR1VRZ1EltKQjqokrj5yLkvGzjHAXwgOC93A1m5iFvDSQXvU3dSPxG447K7lg7HCPw0tSztI203dMbIkWjAfAVMAkf/lE8RQDukxX0Vco2gdODinfQ9UnSUJ4RSA1gO7zk4Gslb3D5EX2KeR/0qDaKfx6bUzjWqyn7EcYLaCbkkM1/9UWsjO62XKFsw/rrtRLnlhadZEOPpJSo= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(136003)(376002)(396003)(346002)(366004)(39860400002)(451199015)(38100700002)(6506007)(316002)(31696002)(4326008)(86362001)(66476007)(66946007)(5660300002)(8676002)(2906002)(66556008)(41300700001)(8936002)(6512007)(26005)(186003)(2616005)(6916009)(54906003)(478600001)(6486002)(31686004)(36756003)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?k56qlp1rdnkTXR/yXnm5ckSm++P0?= =?utf-8?q?WEyT5DKDt1TlTghKou7X2RsPlKvW76VtPGpxKP6IjpmzAEkaY1agAGukxO2aDDSJO?= =?utf-8?q?aQ7lLjMzlcl3O8j/cCY2s+ObNQxNlBg7Bk86NmCionhB28owyhMwygY8Sym2tdtbM?= =?utf-8?q?lcTy181vn8mypY2wyZ6sQB/tN+cXR2bqOpNf2Qkt01bxbazgw8I/hTbPquUzzsQAq?= =?utf-8?q?Jiz4HPge4F41Fq+tzkupKNJNE1AhxQjD9PvMqJdLWlN7QhTUYhSu9JYAAGWe+BdXc?= =?utf-8?q?+CaQjA1qvd7wnHPRyrvRUFtutvEFRO9Dt00dmzwpqFW5edebCXvas2FEaqmkms9lL?= =?utf-8?q?O7g7MDpIGJ43raIxb4hDQD5LWxK0QY764M4xJBVR1+PXFK5mBaz6UgAi0BYbQxv1S?= =?utf-8?q?EHFqXPR7Zg8Z2uhp8BAt5wmb8LQr7Hmm3NQCq96eLwldN3e40OBc4ij5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utf-8?q?yen4YFIwBhxhsFiEgf4kqxBYuZBtqGW9zVVsXdxK/HSAIJDDXsIu1ufUC0olR4H4T?= =?utf-8?q?CuvyUqnqpzA6SsPgYsAE6v8KZbEB1jb7mgp05D89bmBRHL6NPQVmmvLzmYjTgPIXg?= =?utf-8?q?34OfPS+5rrFQzXsoxWH+YTnQOBNBSR0S324myD1eSWBrm5y2xrTLlzHrdtOdMLwiW?= =?utf-8?q?mMoK4pJtWXEE?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 64ff1aa6-ab3e-4d85-38af-08daef36bd2f X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2023 16:06:00.8857 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LaQDgsNlFjFJCocMBEUkxOUjT0qwE/voMbSmTu3fAN7wtJpxx0dgCsa2Y6wWK7xICqEttpvbeczQIWvQT6NEbg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB8046 The "n" input is a GFN value and hence bounded by the physical address bits in use on a system. The hash quality won't improve by also including the upper always-zero bits in the calculation. To keep things as compile-time-constant as they were before, use PADDR_BITS (not paddr_bits) for loop bounding. This reduces loop iterations from 8 to 5. While there also drop the unnecessary cast to u32. Signed-off-by: Jan Beulich --- I was tempted to also change the types of "p" (pointer to const) and "i" (unsigned) right here (and perhaps even the "byte" in the comment ahead of the function), but then thought this might be going too far ... --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -1400,7 +1400,11 @@ static inline key_t sh_hash(unsigned lon unsigned char *p = (unsigned char *)&n; key_t k = t; int i; - for ( i = 0; i < sizeof(n) ; i++ ) k = (u32)p[i] + (k<<6) + (k<<16) - k; + + BUILD_BUG_ON(PADDR_BITS > BITS_PER_LONG + PAGE_SHIFT); + for ( i = 0; i < (PADDR_BITS - PAGE_SHIFT + 7) / 8; i++ ) + k = p[i] + (k << 6) + (k << 16) - k; + return k % SHADOW_HASH_BUCKETS; }