From patchwork Wed Jan 11 13:56:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13096709 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 A5632C5479D for ; Wed, 11 Jan 2023 13:56:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.475373.737055 (Exim 4.92) (envelope-from ) id 1pFban-0007nf-LO; Wed, 11 Jan 2023 13:56:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 475373.737055; Wed, 11 Jan 2023 13:56:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pFban-0007nY-IS; Wed, 11 Jan 2023 13:56:37 +0000 Received: by outflank-mailman (input) for mailman id 475373; Wed, 11 Jan 2023 13:56:36 +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 1pFbam-0007nL-CY for xen-devel@lists.xenproject.org; Wed, 11 Jan 2023 13:56:36 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2079.outbound.protection.outlook.com [40.107.6.79]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c1f28ee2-91b7-11ed-b8d0-410ff93cb8f0; Wed, 11 Jan 2023 14:56:34 +0100 (CET) Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by DU2PR04MB9116.eurprd04.prod.outlook.com (2603:10a6:10:2f7::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Wed, 11 Jan 2023 13:56:33 +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.6002.012; Wed, 11 Jan 2023 13:56:33 +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: c1f28ee2-91b7-11ed-b8d0-410ff93cb8f0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z953bz3nFFFaQ8kRRDXismk0G7je/7A7feBoknxMk94W9dqBDDOXX4mEzejOYUSw3B7Gm2NMmgpZukW2t5lpVPYGUkCSlCelD7rN6bMJjHwC0llDL8OBOh1OQnYWbEJYX3kTM82iRHqLLv27sjzLtwosLtL7qO688g9QjzxwGDIgHN+uqUP6cJqF8Dr9iDGYliahGOBv/59fat9luHaLFVVhkqBiClnw5Nk+OmtbAfPTLo32/WmnTN02h8x/k6NUmfa1zGvMXUY3G2Q/hwdd8zYVJQS6pWwR5dq9jDVtYOJRPC98z9xfdZWiXLrAP4BJZLkQ8h8PAmtbxeylI0Gqaw== 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=dOlBxwttZ7/+xseKnKOuiqz4kR/3+d88oza4XKWQx5c=; b=Q1F0GUfzbx8Z7UvU8AP+nNyj1rjYDxJ1ByQvE6awNcYfvdXADwXV1/RYwBNikqX8XWKMepjsSwsLiFqbPKOa+ulf5x5FLjtUjYC3gDHMSzCcmmAOSE1RwugoCnXY+pzcc1ekm1JZFeDYQMqHLCEgGaP2XheeW0HbSL0GfS4P7XmOzUVv6viabhuHXXtXQR+gW+8YmCLLB4lmW6lwGdLqxBrdopLfKRTW4DEonhELpNlONWyca/sU8ZJvHVkzUWjpWEK8GWQ8VCSNrg817ewABmRVY4ivcr6e2fI6JSgyqF+jT715XW8F/2sHT5eChtkneZu7tJXAUPi/qxbzW1D19g== 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=dOlBxwttZ7/+xseKnKOuiqz4kR/3+d88oza4XKWQx5c=; b=zoh4veZ5PfqSLe389B4cbTUw2GjeL30lAIp39GgmDuMjqPaDGQwXQ3n6Mya3x+aZe8aKg2gEIrmsKi+DI0EFlcUwDuEotmelba3NFWnbj/DyGovZyCBm3aw4Bip+8VOsGS5vyaUNZxKyplNQmNKsUOnL16yVwDIhGcTY0+r+tFoRcHygdPQ3+qQ67U3XCKuPLElbHZODMf6PuVaZWVx0FuzLmLwP1fHQZXqg0sqHt4my+ptl4fs1vOzAzJpD937p/TexMbUCXPb7NQY76kZNRK/5l769OhKspd8VFjEoeUZkYmDd3RTaBuWLeBVPnFWlCLSdOomfw/VLhOmTbuxeIw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <4785b34b-2672-e3a8-8096-df1365b6b7b8@suse.com> Date: Wed, 11 Jan 2023 14:56:30 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v2 7/9] 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: In-Reply-To: X-ClientProxiedBy: FR2P281CA0018.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::28) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|DU2PR04MB9116:EE_ X-MS-Office365-Filtering-Correlation-Id: 91fef956-0412-4031-5c15-08daf3dba5a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5D8H1G5oecUJkQHviGT+zZZ6KmsDOeRgaOgDikazts7wgSrYXYRltyRh9cP9HxiWIYeayePzRP0CpZgDpExaPme0fTXXW1HpPT6LUJEiIuh7MlrmbRh64+QUeaDKZdeFUDAgBcRWVLK0IOmOajbGy0nbxleD84HcoVq24l0R8s8WhbrnU+QCNAJvYh6bUDWt9PH3wfXJBHklpmNTqSA9/ZRnnYAgaZgo3cWlQ92MzUuVoxqQ3gwsIan2omIxKU+8SycGAAtT/zJ1o4I8NqMZyfRgFcW6qN+3vMuLSvTh8c0Nl6Oj8UipEL4Yu8IR24id1bWMECkSdRBIZMg4JA+x8eOvIUWNDFwl36paZftkxmQryqtCVcRNHMmWLMz6ZNaBh/M2Pvcbw5iq7GBKidkhh/PZcR28PJXqwk5O42yeCdE2O7AG3N5qmdhbkBYMWLN8N/PewCioNlfPTIAlOoTBgwH/z/Ure7Plg8FcWj7uTx0M6RYuV8Tp3OvJ9JzR3QMX45SEfgVTN/k660eAvAjO1WlNrS20lJ6100fED/3se3k8ShIcbmA57eOdkoQpHX3h9oIUE7jJj/cMML4kGQmvLS7B3ULSQBkRpHSviY5EWPKXapIvvJf3vMP9Yn2FVK83mCUfhQJ7f1qFJK3RycR+Hz/0z3B6CGKFPhhIPpMfgG7+j+6kwMBo71I8afZOm5sVmo9DXmzDZlQq8PYg3Wtu57JY1P0Rn6t3ugCWc00aM0g= 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)(346002)(39860400002)(366004)(376002)(396003)(451199015)(8676002)(66946007)(31686004)(41300700001)(2906002)(8936002)(5660300002)(36756003)(6916009)(66476007)(316002)(6512007)(66556008)(54906003)(478600001)(6486002)(6506007)(4326008)(26005)(186003)(2616005)(31696002)(86362001)(38100700002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?LWfzM6LLXkhx7jDQqMknnMbAWlex?= =?utf-8?q?PPDtcEbMr9uJck2A+OcNjtRmlwCpm/HM+UdVWgzbSaJaK67zmp8YzJ+x0lfXcysgQ?= =?utf-8?q?Jq5WAYiXMqGaOeu5S/qaJ98AualM6LFxxBVFMUIAdAtgOeYMlUFQl7xchY043bnG/?= =?utf-8?q?Oh2FQeT9vgIfL18Ylg52eajhuXfWUG4MW2w9bdHCPaJTtxIN3+jML4QMNuSUdrSMT?= =?utf-8?q?HZA1rbcn051S06oqB6uy9oUijc9EnY2qqvd9ybgbLABUHhQVxgHepmITQbL+o0qHr?= =?utf-8?q?s5tklQI4ps1AMEjzQxbsDqKZvaZa7HUyh+gU8S3lWAJNWjm83qRdbI7WJ48nJg0X3?= =?utf-8?q?GSQ3VkewPJnNe34roZNHaojo9f8twsnKXFZHDrqUF1fjyCFSfl5lVaRpW2YbBMddT?= =?utf-8?q?elQZxHt+qx7qaDh8OnTBhWv1+AuCEd2Jw8t7PKJolPqXzu+w0oB20lnB8xE5AOD1k?= =?utf-8?q?ZnzYK3f8YaWMqnhjLQFs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j9esTDdqk46jXFFqzjWVTs3IMbQRa5R?= =?utf-8?q?7HF9okeWhven+Jf7HP28FcrEsc/fZMU6qI1nMKSxwDeNMmcXGA0Q0Tyr3afeN1fMw?= =?utf-8?q?HDY++6cqQDjdZoUi8cv+COvFCg6kHiOSOv6tFsa3tsBN1mGggKBvpAkakPTD2PBzy?= =?utf-8?q?j1aXfaRBETlv?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91fef956-0412-4031-5c15-08daf3dba5a0 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2023 13:56:32.9577 (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: tHszxTT8ffrBZ8Z8eMdO5NeCQq5truvEfqlaFWhfwO2foFKWTbPB/zn+tpAyS9Sk9fDjwYbs/fR/TedndyqQ/w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB9116 The "n" input is a GFN/MFN 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 conversion to an array of unsigned char, moving the value off the stack altogether (at least with optimization enabled). Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper --- I was tempted to also change the type "i" (unsigned) right here, but then thought this might be going too far ... --- v2: Also eliminate the unsigned char * alias of "n". --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -1397,10 +1397,13 @@ static unsigned int shadow_get_allocatio typedef u32 key_t; static inline key_t sh_hash(unsigned long n, unsigned int t) { - 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++, n >>= 8 ) + k = (uint8_t)n + (k << 6) + (k << 16) - k; + return k % SHADOW_HASH_BUCKETS; }