From patchwork Thu Nov 16 13:46:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13457919 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 89874C54FB9 for ; Thu, 16 Nov 2023 13:46:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.634230.989610 (Exim 4.92) (envelope-from ) id 1r3chC-0003f7-9w; Thu, 16 Nov 2023 13:46:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 634230.989610; Thu, 16 Nov 2023 13:46:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r3chC-0003f0-6p; Thu, 16 Nov 2023 13:46:14 +0000 Received: by outflank-mailman (input) for mailman id 634230; Thu, 16 Nov 2023 13:46:13 +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 1r3chB-0003dG-4t for xen-devel@lists.xenproject.org; Thu, 16 Nov 2023 13:46:13 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on20615.outbound.protection.outlook.com [2a01:111:f400:7d00::615]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 804fbd85-8486-11ee-9b0e-b553b5be7939; Thu, 16 Nov 2023 14:46:11 +0100 (CET) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by PAXPR04MB8973.eurprd04.prod.outlook.com (2603:10a6:102:20c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.8; Thu, 16 Nov 2023 13:46:09 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44%3]) with mapi id 15.20.7002.019; Thu, 16 Nov 2023 13:46:09 +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: 804fbd85-8486-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pe27FRw9NVn0wSXmJ/J0iW4hOvotUrHXE+bruOKDZJi+4um16Zm2uTUqknyTuXHhjVfcOmBKIJPsZDJTtfUWswr1Eqd7fbGY2PlogxhcK82x8V8eMXcO/F2i9eMnE+p+2nxD2qrIHgoItkwtGQJOFIkqQSZIwlqzF+Z8gWXzrx0AL6Ncor480xmP3KqAnm4zZkrS2Qlj6wyrxyBtadE2WeNO0/EAf9bMHUURLPM1QD/a+zAR1kvv+lnZCZ0NgweTrZt2uKSJ4xpI5P6e6im4i48sM07np2IeCuv8TVmL47YaBPgLgY8TY+W0m0mcux3oyYtBdAUd6UNOsyE0Ua0ZyQ== 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=aQ35HW5/VXYEY1+3qai12wgann+ykzB/YgLcoRE3Z2A=; b=YypLyMtfSSZ4h0Zz3m6zbEXGUzmMLYLkPfhoqjzkBlckupHDxMs8uXWheBcD9kE/lbQ95J8vQlPKvgL51tdRdvJFD9uZxfrfWyHAmJimf40mJKbeOx0LtBOIUEbodnc7Wg34kdGQG0Bsts8gnd3gY/SSGOW+gaupX7Qnhg4N8IOFLUbLLPRH5cwhl43EthEooiijv6p49Aoz9mcwPQ3T7m2+LEhXT/hWLFruu0ofnPn+3JQFfuZix+0zuj7uHMT/mdMP1NNDTC0EmZ7lH7NQOAzdQmx2vL7qPOxLsKWPo2XTFFh9ghqr+F6Lqp6W2Fh0cqgm24Hu4XG8/g3rXDkjvQ== 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=aQ35HW5/VXYEY1+3qai12wgann+ykzB/YgLcoRE3Z2A=; b=IO8YaVec+JU9yP0oH//oSZXa7qvx5K258qvw9kHRHREby520ITh0t5NCQS6XZbgpf5ny3n4j3DSlww8LFpVwwTRsJTy1aF0M4qYo/tF7U76hy8lokC1CZbegIGPHje2Ga3XhOTmqHUVFa7QJzhFgqrZC/nSJY+cSyPtvyf9J7QamxqdvzQrFNCslOQdAovrneJwpNHl7LpsOTJBAfLauDIEHA86k/9S/FYhcCpf0rXMfYH5rdYyGmATwts+TVHjEkVz0i7q5j1oAhvafmqgEiaLpL4wQinUFeuxmVVhDUsJINZ/n6Fut7fdwLV854WYDL5BF9n+2s8fgMXeWt9q5fg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <9810305d-4b36-4e23-b807-a7a00f0ba6b6@suse.com> Date: Thu, 16 Nov 2023 14:46:08 +0100 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 1/5] x86/HVM: introduce hvm_point_entry() 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?= References: <08e0708c-17e2-4a5e-aaf7-5f60a40f76db@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <08e0708c-17e2-4a5e-aaf7-5f60a40f76db@suse.com> X-ClientProxiedBy: FR0P281CA0011.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:15::16) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|PAXPR04MB8973:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ff9fc7b-6111-4301-79a2-08dbe6aa6379 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e3qhI7JW26AfM8ghP3Z1xB1gCDj/zdp3mD67d+QxFX0ee1OY4ykwXeRontvX03ZX8QGSTV2EHRY1k3VznjkKZUGopAZa73+CE2OpQYiduc5wcMmBOYbytl/FGz+wVlbwAksrM3F4uYlSfoF2UFjdkqm3ZZDW5QJ1Jelufgw5m9gtBhOnpxlMGNK1S+P0RmE7ubkk5LdLl3G6JjVo07OWYTubmm5I8fJqolgKkwp9PlgHkJNdHljZu9kVaZty2vKRf/a6keciaumqTl2p0SasPVuS4ABJJZDx/NjaEnglAo0NBbgRN1OUYO9IVA5j8w7N2AfQs9GemunI695CCiSFAnhyUwMsseDgkhaIpJerfZ+CGDfBCyYKdVtzsGxE4lpJR6NFNqhYmZ/nlCWUHNzWRhornI6AK4XuOL0qwuQBwuyGrtfWjtNsdVyuyKNkuvVtH6t4RClycPY47B85W3H+8sSiagteW5I2U6ia2xfs2GMIiGE7BPmd8+q2pkAqDPCAz9YjajFLMiXUEtIYJIM1dmOGvYwLR3E9PxvQaNiYnxS4UAsqlEFrWnUIaB6LUAkVSa+KFVHG8l9VcXulJKUur34PikzpPIzhzhFNN4CfHXtIcdj1CqOmZB0kzy26XLcS08kXO2m/DKymyMh89qKlhg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(136003)(346002)(39860400002)(366004)(396003)(376002)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(38100700002)(5660300002)(2906002)(31696002)(8676002)(4326008)(86362001)(8936002)(41300700001)(31686004)(6916009)(2616005)(316002)(54906003)(66556008)(66946007)(66476007)(478600001)(83380400001)(26005)(6486002)(36756003)(6506007)(6512007)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?1CkBcZxVXdEQQvTzTcM/IPBE8WkI?= =?utf-8?q?alxFqKOvUxVqyLIvQTeZr908uYham60kYtgbLQxhotcDPNliLTJXmGDpAyLYhmOr3?= =?utf-8?q?Gxp+O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ETNFcww7VFEDPxwhgr4PNxCx6KCuPvQAF3O3/zvkWjUZIXd7iO59tyPfD?= =?utf-8?q?GDoeT6a8LTXsrpJpEA5o16Qi3vkL+uOL9JJHijMAUikO5CmAI/sI0Mb4ejM07eCeP?= =?utf-8?q?TVz74nQ1YcyHUnca39jOORHcfYPbf19sDNfeaxYVMFppGe+Osn2Dc0jCwx0rhj6aM?= =?utf-8?q?aJSEwhRcO2wHi3ZsIKNqIm/5rCvWHUlBRGOsnu7S7+S1XQQL1ONUA6du7txhb5RvH?= =?utf-8?q?j7mQ9Qzy02nVGkDob2JWvSULVcsinzCXPZEC3c3zLmyOqSr6p558sbSalG+3xx2Db?= =?utf-8?q?ARk7/fYPRYYkqNTq8hJ9RWq041Dxe1CY1ZNRvkqohHu4jNa8n1Wd5VhwskaWHw2fO?= =?utf-8?q?7wavzxFescJfqsIDNP49BFeawI+r/aLLSybqOiD1xrziDGJTVkI1BYqhE3IrE+H4I?= =?utf-8?q?e2xNKD5VVddbSIoGck2mTry6obIyi0WGsh7gIOG3NDNczChM3yLg8QZdFucDDezvO?= =?utf-8?q?HtKNt/2JVftQdgjRMnDJoobDrYgvXeJdNUJHRpXoX82yUAbeDlLVNO5hWHHnTHPgY?= =?utf-8?q?rlb+OZdAPivY?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6ff9fc7b-6111-4301-79a2-08dbe6aa6379 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2023 13:46:09.1947 (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: n7I8HxJx4gzryg0W7r+C64KZIp/4AhK/xKE8bMgOZPYK+gIv/ZTCBaZeQ6vooXXLSmdxzPgRzmD0eq/DeRUeLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8973 ... to accompany hvm_read_entry() when actual copying isn't desirable. This allows to remove open-coded stream accesses from hpet_load(), along with using the helper in hvm_load() itself. Since arch_hvm_load()'s declaration would need changing, and since the function is not used from elsewhere, purge the declaration. With that it makes little sense to keep arch_hvm_save()'s around; convert that function to static then at the same time. In hpet_load() simplify the specific case of error return that's in context anyway: There's no need to hold the lock when only updating a local variable. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- v2: New. --- a/xen/arch/x86/hvm/hpet.c +++ b/xen/arch/x86/hvm/hpet.c @@ -637,7 +637,7 @@ static int cf_check hpet_save(struct vcp static int cf_check hpet_load(struct domain *d, hvm_domain_context_t *h) { HPETState *hp = domain_vhpet(d); - struct hvm_hw_hpet *rec; + const struct hvm_hw_hpet *rec; uint64_t cmp; uint64_t guest_time; int i; @@ -645,17 +645,12 @@ static int cf_check hpet_load(struct dom if ( !has_vhpet(d) ) return -ENODEV; - write_lock(&hp->lock); - /* Reload the HPET registers */ - if ( _hvm_check_entry(h, HVM_SAVE_CODE(HPET), HVM_SAVE_LENGTH(HPET), 1) ) - { - write_unlock(&hp->lock); + rec = hvm_point_entry(HPET, h); + if ( !rec ) return -EINVAL; - } - rec = (struct hvm_hw_hpet *)&h->data[h->cur]; - h->cur += HVM_SAVE_LENGTH(HPET); + write_lock(&hp->lock); #define C(x) hp->hpet.x = rec->x C(capability); --- a/xen/arch/x86/hvm/save.c +++ b/xen/arch/x86/hvm/save.c @@ -15,7 +15,7 @@ #include -void arch_hvm_save(struct domain *d, struct hvm_save_header *hdr) +static void arch_hvm_save(struct domain *d, struct hvm_save_header *hdr) { uint32_t eax, ebx, ecx, edx; @@ -30,7 +30,7 @@ void arch_hvm_save(struct domain *d, str d->arch.hvm.sync_tsc = rdtsc(); } -int arch_hvm_load(struct domain *d, struct hvm_save_header *hdr) +static int arch_hvm_load(struct domain *d, const struct hvm_save_header *hdr) { uint32_t eax, ebx, ecx, edx; @@ -277,7 +277,7 @@ int hvm_save(struct domain *d, hvm_domai int hvm_load(struct domain *d, hvm_domain_context_t *h) { - struct hvm_save_header hdr; + const struct hvm_save_header *hdr; struct hvm_save_descriptor *desc; hvm_load_handler handler; struct vcpu *v; @@ -286,11 +286,12 @@ int hvm_load(struct domain *d, hvm_domai if ( d->is_dying ) return -EINVAL; - /* Read the save header, which must be first */ - if ( hvm_load_entry(HEADER, h, &hdr) != 0 ) + /* Get at the save header, which must be first */ + hdr = hvm_point_entry(HEADER, h); + if ( !hdr ) return -ENODATA; - rc = arch_hvm_load(d, &hdr); + rc = arch_hvm_load(d, hdr); if ( rc ) return rc; --- a/xen/arch/x86/include/asm/hvm/save.h +++ b/xen/arch/x86/include/asm/hvm/save.h @@ -39,6 +39,21 @@ void _hvm_write_entry(struct hvm_domain_ int _hvm_check_entry(struct hvm_domain_context *h, uint16_t type, uint32_t len, bool strict_length); +/* + * Unmarshalling: check, then return pointer. Evaluates to non-NULL on success. + * This macro requires the save entry to be the same size as the dest structure. + */ +#define hvm_point_entry(x, h) ({ \ + const void *ptr = NULL; \ + BUILD_BUG_ON(HVM_SAVE_HAS_COMPAT(x)); \ + if ( _hvm_check_entry(h, HVM_SAVE_CODE(x), \ + HVM_SAVE_LENGTH(x), true) == 0 ) \ + { \ + ptr = &(h)->data[(h)->cur]; \ + h->cur += HVM_SAVE_LENGTH(x); \ + } \ + ptr; }) + /* Unmarshalling: copy the contents in a type-safe way */ void _hvm_read_entry(struct hvm_domain_context *h, void *dest, uint32_t dest_len); @@ -127,9 +142,4 @@ int hvm_save_one(struct domain *d, unsig XEN_GUEST_HANDLE_64(uint8) handle, uint64_t *bufsz); int hvm_load(struct domain *d, hvm_domain_context_t *h); -/* Arch-specific definitions. */ -struct hvm_save_header; -void arch_hvm_save(struct domain *d, struct hvm_save_header *hdr); -int arch_hvm_load(struct domain *d, struct hvm_save_header *hdr); - #endif /* __XEN_HVM_SAVE_H__ */ From patchwork Thu Nov 16 13:46:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13457920 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 5A522C197A0 for ; Thu, 16 Nov 2023 13:46:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.634232.989619 (Exim 4.92) (envelope-from ) id 1r3chg-0004G4-Hr; Thu, 16 Nov 2023 13:46:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 634232.989619; Thu, 16 Nov 2023 13:46:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r3chg-0004Fx-Ep; Thu, 16 Nov 2023 13:46:44 +0000 Received: by outflank-mailman (input) for mailman id 634232; Thu, 16 Nov 2023 13:46:42 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r3che-0004DG-Qg for xen-devel@lists.xenproject.org; Thu, 16 Nov 2023 13:46:42 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0607.outbound.protection.outlook.com [2a01:111:f400:fe0e::607]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 92a08bdf-8486-11ee-98db-6d05b1d4d9a1; Thu, 16 Nov 2023 14:46:41 +0100 (CET) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by VI1PR04MB7181.eurprd04.prod.outlook.com (2603:10a6:800:12a::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.7; Thu, 16 Nov 2023 13:46:38 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44%3]) with mapi id 15.20.7002.019; Thu, 16 Nov 2023 13:46:38 +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: 92a08bdf-8486-11ee-98db-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AGYX+/Qdu73ErPenOXphgWjKQUE4DrqCX6kaEgc5KOrX5bz7BqhsRDuRg1VPadxCJUjYy5CVM9t/v9VNnrVEA11aVlfmW09ctJdei6xi08iV6jx1qkkHqcTq+QF0lF7RYsO/pww7LcVR0LeD/TQgfNXy//wWwvDc9W8CJFDdaG9h+if75lC56jLKFqpxQSQ1Fg37jqiCofjiGnDyVezbwFHQfqo45ZtdljTEREbie+4yvwXEWB3VufO//UGhfP1SGGrRykL24Vlw9zvbfPpyqmvBY1ihAucN7Qgi42DmqEygSlZHPT6Dp6lsoU+j6NHt91CQYx7mEuv41EvHPAaCEA== 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=lMSbuMzFk476bXS0hFnUWgnN47n36WdfLn6n8LRD3+0=; b=fTpGHzIg6Sf/naHm+oDh22w726uo9LnHvxqC34/pxFxKWH7isWmGiGzY+OwRAnL+CHN8mc1jHKuIa5Hbc0wOzpylq397khBnUcZtvqd4ioRHwZSZBmDzCTkHnhOA+ZIrgtf/rb7YgHQcXtNtGp+bB6EzVaFQ63jdJqguo8n/q7Be2wG8zYn9/s60eLpNlAC7e2u2qUQH/pZLYYrBQwA/W3vEIGu2kRkhxhTrbjbI+DizitIQDW0js9g5bU2TZR/IenDrDlL2EQNTLbIg8uzdrm1eN4EZGGpb9C5+bXsAIWWDL9DKskemd+CH0TI0Qb05hOXyjzTJI/DnTN7Vm4cPDw== 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=lMSbuMzFk476bXS0hFnUWgnN47n36WdfLn6n8LRD3+0=; b=RqyzQX8/3tDlg4mUVircMf9Z/ACsE8tRwaru/GrmvW2luSkh67XR7gHh6bbw92G/CnbQTs4Vor3rviKBel1nzZII145UQTo+XTyoeki3h8Hn9iAa/rHUScBj89O9+CJkqs7rFRhnMNePvi77+l0jF8AIErW0+HoIjlr6lH/Q1cYr8YPx/cWBpl0fPE+GRAbkB4+DWDlY9wVK9izfwrOi8LkYsv9n4w4Rc9Q02PrGUPsRB4Cp9dhjR8G3Xpe6V2Iwc2/HV9OQqVqgvz+OhUoSO8GNkSByDI9T8xazlOJgug/Vb3+O4jpVF5b/bYa5vJ38FrelVanP2TfGMixSn+roeg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <822a6328-36d3-43e9-9fc4-36d01a6b9ef2@suse.com> Date: Thu, 16 Nov 2023 14:46:37 +0100 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 2/5] x86/HVM: split restore state checking from state loading 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?= References: <08e0708c-17e2-4a5e-aaf7-5f60a40f76db@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <08e0708c-17e2-4a5e-aaf7-5f60a40f76db@suse.com> X-ClientProxiedBy: FR0P281CA0011.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:15::16) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|VI1PR04MB7181:EE_ X-MS-Office365-Filtering-Correlation-Id: 6db19afd-6e97-4056-e6a2-08dbe6aa74b6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l7b2L41tkC0WthIIlKGQPUBN9XXJEnHOPuiRqlmhPrwnb3MYMvXT7N5/RXgR5p6Te645tmT3ql5Ezrjv9gDmGNqKxeIs+ABF243+1lM9fAo5RdbirCEqMpTzK5GHdpf4jOC6J/5sya4lRiJzG7mOad1mrzCyNKAHPQ0NqdeyAU2kmbxNJxxmVOTeLZfax6TYREJBVyErflJGKvaks3ujhN2+c4xv9M2F0pU2pINFzs03OLX9yjxakFZAZgFVTfg1eSjdLgzdVcehQiOzkeZUZgBQBfi8f5dQco4Mo8DZA9QIAm3BxZplfxpK9+PAgaA1+aNGbKfcyCFdeyILB9Gd+FbE9k+wjv5RTCskwh90aG+R/d2r0t3wmMlQMz/dW8kHvdPR8N6y8eBNIF7iQijcdZLsI/iAqIX4/6N1lo+upUOs3PQw36xfGmafsVaLYopcvpNONbrG/NC+7PWPs8PVKXj2jTRgfHFD55grF/Ute+XzHMqc1dj2zXJT31PCvTpZBCrcHQeI8/ZQJZsbPNImUo69sUAgOdJdSf0A/j8k6aZzL0hM/dRZ9NYprngYXWprhi96aPr9ieb1TVHIejzpQqNF03FmdnJg+3Ncwyebay9mM9EbyZyta8Z1usGJKQCAriGbM+AXpo0jABfngN0/fA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(136003)(366004)(346002)(396003)(230922051799003)(64100799003)(1800799009)(186009)(451199024)(31696002)(36756003)(86362001)(8676002)(2906002)(8936002)(4326008)(5660300002)(66476007)(66556008)(54906003)(316002)(66946007)(6916009)(478600001)(6486002)(38100700002)(31686004)(6506007)(26005)(2616005)(41300700001)(83380400001)(6512007)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?UL0Nd3VWZPm1k8IyzyYNZkZ5dHrQ?= =?utf-8?q?tfBVzyjzX0qWFtHkyqf2cRZ4THtO6KSHvSTdjA9tDSGYbjpxgwqj32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h?= =?utf-8?q?sOLf5PcXowpuE2NrY0tFakrySltS5UYXbCjP/IwzxuTA4AXckpYWvJUQrBd9jgQuL?= =?utf-8?q?ZXaCX6WyIBkiwdUa86mofMxD7tIdbti35Q6UCIPdJ4Ov5sKgqJEPEumyFJuOs2s/l?= =?utf-8?q?rgbdafKjOyVW8rROLjUjKDPzMDO2jmnGrd1ApdgTa68gB994ObRT7/b5QrRzOK/wu?= =?utf-8?q?XHy2L0eaxmYRL+HyipE+z+t8Vk5564TXtfud1Qdb6twVRM8aaVHReaNZZBlfdvJIo?= =?utf-8?q?Tzp20ZGmYnqRjRBIzKmXLNzZ72CbNVkkNK8zWAmHMRheLEKWYRlP26P/aluOMLn1P?= =?utf-8?q?zMQAbf5qr1XfpG1kvLRYNC9LoTb/h1EUg7J4/jpdj8SItzRQ1psMnEZSKn3iDfuxS?= =?utf-8?q?09Vn4Ta/Hji2EIS88Hu4NVb+/Jq64hxSnJAaoIDOiNpk5VRtMYNaOlFttZ/ciWuCD?= =?utf-8?q?K6LNFoLB3VA2HvMLPTFbhFQFLJW3bz7PUFUPEJZdaJXKVg41z79k+JHTzNJS5CS7f?= =?utf-8?q?+c+z5ulVtt6ItTSSqFGfQ3hh2VK27d7yzocwqE1ETCKJzVVzRF3syz51vHLdxvfcG?= =?utf-8?q?wIblOLZFPm5y?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6db19afd-6e97-4056-e6a2-08dbe6aa74b6 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2023 13:46:38.1094 (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: J5nkrMY1KAV+nTaTMkYCPyeqlg9qSy9zKpxEWeQaCxn7ptUs7AZNZpyhdYDNanlCV47IQb2RIamy1RlnzuZ7EQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7181 ..., at least as reasonably feasible without making a check hook mandatory (in particular strict vs relaxed/zero-extend length checking can't be done early this way). Note that only one of the two uses of hvm_load() is accompanied with hvm_check(). The other directly consumes hvm_save() output, which ought to be well-formed. This means that while input data related checks don't need repeating in the "load" function when already done by the "check" one (albeit assertions to this effect may be desirable), domain state related checks (e.g. has_xyz(d)) will be required in both places. Suggested-by: Roger Pau Monné Signed-off-by: Jan Beulich --- Do we really need all the copying involved in use of _hvm_read_entry() (backing hvm_load_entry()? Zero-extending loads are likely easier to handle that way, but for strict loads all we gain is a reduced risk of unaligned accesses (compared to simply pointing into h->data[]). Would the hvm_sr_handlers[] better use array_access_nospec()? --- v2: New. --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -379,6 +379,10 @@ long arch_do_domctl( if ( copy_from_guest(c.data, domctl->u.hvmcontext.buffer, c.size) != 0 ) goto sethvmcontext_out; + ret = hvm_check(d, &c); + if ( ret ) + goto sethvmcontext_out; + domain_pause(d); ret = hvm_load(d, &c); domain_unpause(d); --- a/xen/arch/x86/hvm/save.c +++ b/xen/arch/x86/hvm/save.c @@ -30,7 +30,8 @@ static void arch_hvm_save(struct domain d->arch.hvm.sync_tsc = rdtsc(); } -static int arch_hvm_load(struct domain *d, const struct hvm_save_header *hdr) +static int arch_hvm_check(const struct domain *d, + const struct hvm_save_header *hdr) { uint32_t eax, ebx, ecx, edx; @@ -55,6 +56,11 @@ static int arch_hvm_load(struct domain * "(%#"PRIx32") and restored on another (%#"PRIx32").\n", d->domain_id, hdr->cpuid, eax); + return 0; +} + +static void arch_hvm_load(struct domain *d, const struct hvm_save_header *hdr) +{ /* Restore guest's preferred TSC frequency. */ if ( hdr->gtsc_khz ) d->arch.tsc_khz = hdr->gtsc_khz; @@ -66,13 +72,12 @@ static int arch_hvm_load(struct domain * /* VGA state is not saved/restored, so we nobble the cache. */ d->arch.hvm.stdvga.cache = STDVGA_CACHE_DISABLED; - - return 0; } /* List of handlers for various HVM save and restore types */ static struct { hvm_save_handler save; + hvm_check_handler check; hvm_load_handler load; const char *name; size_t size; @@ -88,6 +93,7 @@ void __init hvm_register_savevm(uint16_t { ASSERT(typecode <= HVM_SAVE_CODE_MAX); ASSERT(hvm_sr_handlers[typecode].save == NULL); + ASSERT(hvm_sr_handlers[typecode].check == NULL); ASSERT(hvm_sr_handlers[typecode].load == NULL); hvm_sr_handlers[typecode].save = save_state; hvm_sr_handlers[typecode].load = load_state; @@ -275,6 +281,78 @@ int hvm_save(struct domain *d, hvm_domai return 0; } +int hvm_check(const struct domain *d, hvm_domain_context_t *h) +{ + const struct hvm_save_header *hdr; + int rc; + + if ( d->is_dying ) + return -EINVAL; + + /* Get at the save header, which must be first */ + hdr = hvm_point_entry(HEADER, h); + if ( !hdr ) + return -ENODATA; + + rc = arch_hvm_check(d, hdr); + if ( rc ) + return rc; + + for ( ; ; ) + { + const struct hvm_save_descriptor *desc; + hvm_check_handler handler; + + if ( h->size - h->cur < sizeof(*desc) ) + { + /* Run out of data */ + printk(XENLOG_G_ERR + "HVM restore %pd: save did not end with a null entry\n", + d); + return -ENODATA; + } + + /* Read the typecode of the next entry and check for the end-marker */ + desc = (const void *)&h->data[h->cur]; + if ( desc->typecode == HVM_SAVE_CODE(END) ) + { + /* Reset cursor for hvm_load(). */ + h->cur = 0; + return 0; + } + + /* Find the handler for this entry */ + if ( desc->typecode >= ARRAY_SIZE(hvm_sr_handlers) || + !hvm_sr_handlers[desc->typecode].name || + !hvm_sr_handlers[desc->typecode].load ) + { + printk(XENLOG_G_ERR "HVM restore %pd: unknown entry typecode %u\n", + d, desc->typecode); + return -EINVAL; + } + + /* Check the entry */ + handler = hvm_sr_handlers[desc->typecode].check; + if ( !handler ) + { + if ( desc->length > h->size - h->cur - sizeof(*desc) ) + return -ENODATA; + h->cur += sizeof(*desc) + desc->length; + } + else if ( (rc = handler(d, h)) ) + { + printk(XENLOG_G_ERR + "HVM restore %pd: failed to check %s:%u rc %d\n", + d, hvm_sr_handlers[desc->typecode].name, desc->instance, rc); + return rc; + } + + process_pending_softirqs(); + } + + /* Not reached */ +} + int hvm_load(struct domain *d, hvm_domain_context_t *h) { const struct hvm_save_header *hdr; @@ -291,9 +369,8 @@ int hvm_load(struct domain *d, hvm_domai if ( !hdr ) return -ENODATA; - rc = arch_hvm_load(d, hdr); - if ( rc ) - return rc; + ASSERT(!arch_hvm_check(d, hdr)); + arch_hvm_load(d, hdr); /* Down all the vcpus: we only re-enable the ones that had state saved. */ for_each_vcpu(d, v) @@ -304,10 +381,7 @@ int hvm_load(struct domain *d, hvm_domai { if ( h->size - h->cur < sizeof(struct hvm_save_descriptor) ) { - /* Run out of data */ - printk(XENLOG_G_ERR - "HVM%d restore: save did not end with a null entry\n", - d->domain_id); + ASSERT_UNREACHABLE(); return -ENODATA; } @@ -320,8 +394,7 @@ int hvm_load(struct domain *d, hvm_domai if ( (desc->typecode > HVM_SAVE_CODE_MAX) || ((handler = hvm_sr_handlers[desc->typecode].load) == NULL) ) { - printk(XENLOG_G_ERR "HVM%d restore: unknown entry typecode %u\n", - d->domain_id, desc->typecode); + ASSERT_UNREACHABLE(); return -EINVAL; } --- a/xen/arch/x86/include/asm/hvm/save.h +++ b/xen/arch/x86/include/asm/hvm/save.h @@ -103,6 +103,8 @@ static inline unsigned int hvm_load_inst * restoring. Both return non-zero on error. */ typedef int (*hvm_save_handler) (struct vcpu *v, hvm_domain_context_t *h); +typedef int (*hvm_check_handler)(const struct domain *d, + hvm_domain_context_t *h); typedef int (*hvm_load_handler) (struct domain *d, hvm_domain_context_t *h); @@ -140,6 +142,7 @@ size_t hvm_save_size(struct domain *d); int hvm_save(struct domain *d, hvm_domain_context_t *h); int hvm_save_one(struct domain *d, unsigned int typecode, unsigned int instance, XEN_GUEST_HANDLE_64(uint8) handle, uint64_t *bufsz); +int hvm_check(const struct domain *d, hvm_domain_context_t *h); int hvm_load(struct domain *d, hvm_domain_context_t *h); #endif /* __XEN_HVM_SAVE_H__ */ From patchwork Thu Nov 16 13:47:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13457921 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 C0B45C197A0 for ; Thu, 16 Nov 2023 13:47:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.634235.989630 (Exim 4.92) (envelope-from ) id 1r3ciN-0004zI-0z; Thu, 16 Nov 2023 13:47:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 634235.989630; Thu, 16 Nov 2023 13:47:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r3ciM-0004zB-Sl; Thu, 16 Nov 2023 13:47:26 +0000 Received: by outflank-mailman (input) for mailman id 634235; Thu, 16 Nov 2023 13:47:25 +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 1r3ciL-0003dG-Gx for xen-devel@lists.xenproject.org; Thu, 16 Nov 2023 13:47:25 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2062a.outbound.protection.outlook.com [2a01:111:f400:7d00::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ab7b8ffb-8486-11ee-9b0e-b553b5be7939; Thu, 16 Nov 2023 14:47:23 +0100 (CET) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by PAXPR04MB8973.eurprd04.prod.outlook.com (2603:10a6:102:20c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.8; Thu, 16 Nov 2023 13:47:21 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44%3]) with mapi id 15.20.7002.019; Thu, 16 Nov 2023 13:47:21 +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: ab7b8ffb-8486-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mlL7ooIk5ib95FfX26jrAzpYs36aAGNR4MCLh++NE1TaQlPdFyPir1bPSxTY//xKfWpgLVvjv9PIvokEeQ+WnYNwEqRUn9QdOsYzVxw+RO4zHzs9i3e40C11FuQHgw+bjL6KgNfTAeopBx4q3h9K3otjBEQQ+SUtaRMZiKuib6SvYJj2Fn7MCu2N/dAndgZgR3TtVMDH7aHhR5gHO+6EwTPY+K4qYWT96P6d3e8VM18Jj9Phq3GkeBk2hgN/yBR58GZ92cBkHJV57HjwfoV8PWrZ0PIzQDrW35xOutsxGSYglbgC40ESnAk8SawsjXbPfW7lz4vu769Tj3xF80VBdg== 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=21bfP1a8vc58vTNWpsCvgoeAH47g9WRPqWztSSvlClg=; b=cB93LPZb03gkfHKLJk0u3l6Vi8LDMxuwqldYDrH+HgGzxvVjmQzJAaJf88RnXF6UmfBZPothStPV+S8sTnfPvCdeqqIf5hwgELAXy1VrBVjVMPfK5Uf5Dnk8b0Whdn7MjzsZE30kiqBJk/WoZ213d8MlhL1mQ/+uxSdQQHP76peBplq0vb+0rk9tmbuXrF3YS53HfF8wh/93maHVrzelglUd8/cS+dvfwqQvyISX/kBfIPHH7xae6Y5tmcCRnaIwlkzUciJbCf6bhMUI6xTH5Nb3mZ/o9Otd5xMitjGCI+g7oeo+ZCm88sWZuDD46mxBo2rMs6W6KS1Bo9XqnBILDg== 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=21bfP1a8vc58vTNWpsCvgoeAH47g9WRPqWztSSvlClg=; b=zVSSsoZ7e9YJrxHMsP/C5vYxLjEfAy+ZYZL3xwOtavOTaI/2xdM1mpfVCfcEpMpPCT9BwbP/WV+tujNskyD0kf/2VZtdwY21hbOJBspeU+9/pgAA7f/7QJL275uAPrN7bI6JqKib/hHy5NkXgBAVmRdj7numDoZNeMczr9V/XEazTm0R7iXgP38PWP8+Jassx6KKcqp7LK/Ju7dRTi9A13QfEGyuBpxL2VDfiFl4RkMCSKna/MTsNSmbdsBG5O2ca1MBqdBYsTK1iQJVauEGpoxyM+POGFmp5Xn1C3eeOl+iN3jrkHkIDxCjgdgnoNyZWgqkEMenLZMLYjlAUqjWrw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <3627a561-939c-472e-840c-6925f4774631@suse.com> Date: Thu, 16 Nov 2023 14:47:20 +0100 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 3/5] x86/HVM: adjust save/restore hook registration for optional check handler 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?= , Paul Durrant References: <08e0708c-17e2-4a5e-aaf7-5f60a40f76db@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <08e0708c-17e2-4a5e-aaf7-5f60a40f76db@suse.com> X-ClientProxiedBy: FR0P281CA0011.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:15::16) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|PAXPR04MB8973:EE_ X-MS-Office365-Filtering-Correlation-Id: a2a40075-5414-4073-5175-08dbe6aa8e4a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aY6fdQwETr0hc4YDiJStX+xqq0Y3qgPPieN1csxbDu5AOsFihnf/3QGEttdQvc6dMP4BlaxVXSDQk9cVjvXVhZwBg9r4MDPQwgtDdIRFPCHXrfTh1A0Kxl4yzP+oaTyQyf051WzUTGmH0cfIlw81d0mvVOMoPJ2WEu1AQds/u2KUtQwqUlinQip06bbozx5IkYJj5AJ8pcdfvd255D5LNiFybWNZSSGuRxq9WKrsnDD3NlL7LQY+ClI9kHcBCu/PLf+hEPNxR5IDf+KHUENf4sHVHaKYOW17L19f7/ul7jwbmZ9heVLpdNB/aDDSYhynJRLoi6fdRsRtXs6jHSE5vGsfp8VVeEMJTlLTwCz1m9UgBCWHdgEtIpK3Xyf8o46D9TQR0q9oPX3hYcfFNfQD/bx6OFg75issf8iqGSOpe5JY6DOJOMPPHtwke5MlMcpHQY3oAz13On3BRd+uTq7sCWeJ4ddGTC/duC3K4Fvc4qBN2D3qZYC5Bnn1Tuj8XQosZsXE9e52AH0K14DVnL6WG2VKmRe/uhYThEIwjyzVSvF/qktJeiJG+CJTMGq2/T+Xibs8asBV/ZS7qOwqVWu5BM/KSSSoxPkq3xTEsRvkS1pNTLt7iP5VuGTKCFgRs9RXKl+KlCCtB9y4Yt1PQwMYjw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(136003)(346002)(39860400002)(366004)(396003)(376002)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(38100700002)(5660300002)(2906002)(31696002)(8676002)(4326008)(86362001)(8936002)(41300700001)(31686004)(6916009)(2616005)(316002)(54906003)(66556008)(66946007)(66476007)(478600001)(83380400001)(26005)(6486002)(36756003)(6506007)(6512007)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?pm5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6MG4AR4Pl7aaOKelg1xcP?= =?utf-8?q?eAXya8/TfI7R1p6fe4I+MYVaBRW2ZD3qAlSLRwObZcQyCvyP+CmmcFKMVMT1JLWNq?= =?utf-8?q?0dBXCZ6J/1fgXUSrFABtQIQzLSPeRGaGSxYMCdeNHPRAzx+PV2aGQJKny8bzkuKUw?= =?utf-8?q?Bdv7/d3ySmURdRL2De3oIpsJ1ikqRdjI8h3pdtN0Um0I0JVvqIjRSajVuFEAhab1z?= =?utf-8?q?4c31XaQEVU8MWIdG7ByXy3jHQoXRPgIKnDARKKlpDEhjybK9CYFT24FWHLTY3Syfq?= =?utf-8?q?JC3sQRc7zmx+fO/QsnpJ+fPChSoaeMvle4xbjPt4yPYyGtcImO7LAZ2a6O7T8JTaz?= =?utf-8?q?vlTsHKS3FqTwWzLybO5aIY8a7sSxjD3JUQsaCnFhDMfQDEy5dkf8x/tYQ6/UwFSb0?= =?utf-8?q?mqZMppcRwVhtyZBhHw0Iu95yOV9LkGQLACYjV7NnZ4dC9NwXTLgZ9yvTvJcpd0wyO?= =?utf-8?q?UBy/Ok99FhNSyBFioVbgXfMjxkAcvyv5a9J/RUFMeB69nyx/dFAsLCdPRB8v2/UCm?= =?utf-8?q?NxrvkJx9X41HXsbEo2yDMIqFzNjgr8ovwyY6CLi0v+mVVXK9wM+7U5uJE4vhrcM0j?= =?utf-8?q?OL7hbXhZ5VNSWKhJyHmdQDDcmJbg8BFrEUfK4F83j4oiPvqPr054fzcb1pkeCG9m8?= =?utf-8?q?q3Gqcn6qGs7c?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: a2a40075-5414-4073-5175-08dbe6aa8e4a X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2023 13:47:21.0241 (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: lqzTESIq3euSh3HS+7CIMuJmtLbYQSB5N9SeyUgOBilGg7LN393vR2DRQfjKxA4mpwmFSK8hSTG3ElfbgoYgWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8973 Register NULL uniformly as a first step. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- v2: New. --- a/xen/arch/x86/cpu/mcheck/vmce.c +++ b/xen/arch/x86/cpu/mcheck/vmce.c @@ -374,7 +374,7 @@ static int cf_check vmce_load_vcpu_ctxt( return err ?: vmce_restore_vcpu(v, &ctxt); } -HVM_REGISTER_SAVE_RESTORE(VMCE_VCPU, vmce_save_vcpu_ctxt, +HVM_REGISTER_SAVE_RESTORE(VMCE_VCPU, vmce_save_vcpu_ctxt, NULL, vmce_load_vcpu_ctxt, 1, HVMSR_PER_VCPU); #endif --- a/xen/arch/x86/emul-i8254.c +++ b/xen/arch/x86/emul-i8254.c @@ -458,7 +458,7 @@ static int cf_check pit_load(struct doma return rc; } -HVM_REGISTER_SAVE_RESTORE(PIT, pit_save, pit_load, 1, HVMSR_PER_DOM); +HVM_REGISTER_SAVE_RESTORE(PIT, pit_save, NULL, pit_load, 1, HVMSR_PER_DOM); #endif /* The intercept action for PIT DM retval: 0--not handled; 1--handled. */ --- a/xen/arch/x86/hvm/hpet.c +++ b/xen/arch/x86/hvm/hpet.c @@ -692,7 +692,7 @@ static int cf_check hpet_load(struct dom return 0; } -HVM_REGISTER_SAVE_RESTORE(HPET, hpet_save, hpet_load, 1, HVMSR_PER_DOM); +HVM_REGISTER_SAVE_RESTORE(HPET, hpet_save, NULL, hpet_load, 1, HVMSR_PER_DOM); static void hpet_set(HPETState *h) { --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -793,7 +793,7 @@ static int cf_check hvm_load_tsc_adjust( return 0; } -HVM_REGISTER_SAVE_RESTORE(TSC_ADJUST, hvm_save_tsc_adjust, +HVM_REGISTER_SAVE_RESTORE(TSC_ADJUST, hvm_save_tsc_adjust, NULL, hvm_load_tsc_adjust, 1, HVMSR_PER_VCPU); static int cf_check hvm_save_cpu_ctxt(struct vcpu *v, hvm_domain_context_t *h) @@ -1189,7 +1189,7 @@ static int cf_check hvm_load_cpu_ctxt(st return 0; } -HVM_REGISTER_SAVE_RESTORE(CPU, hvm_save_cpu_ctxt, hvm_load_cpu_ctxt, 1, +HVM_REGISTER_SAVE_RESTORE(CPU, hvm_save_cpu_ctxt, NULL, hvm_load_cpu_ctxt, 1, HVMSR_PER_VCPU); #define HVM_CPU_XSAVE_SIZE(xcr0) (offsetof(struct hvm_hw_cpu_xsave, \ @@ -1538,6 +1538,7 @@ static int __init cf_check hvm_register_ hvm_register_savevm(CPU_XSAVE_CODE, "CPU_XSAVE", hvm_save_cpu_xsave_states, + NULL, hvm_load_cpu_xsave_states, HVM_CPU_XSAVE_SIZE(xfeature_mask) + sizeof(struct hvm_save_descriptor), @@ -1546,6 +1547,7 @@ static int __init cf_check hvm_register_ hvm_register_savevm(CPU_MSR_CODE, "CPU_MSR", hvm_save_cpu_msrs, + NULL, hvm_load_cpu_msrs, HVM_CPU_MSR_SIZE(ARRAY_SIZE(msrs_to_send)) + sizeof(struct hvm_save_descriptor), --- a/xen/arch/x86/hvm/irq.c +++ b/xen/arch/x86/hvm/irq.c @@ -784,9 +784,9 @@ static int cf_check irq_load_link(struct return 0; } -HVM_REGISTER_SAVE_RESTORE(PCI_IRQ, irq_save_pci, irq_load_pci, +HVM_REGISTER_SAVE_RESTORE(PCI_IRQ, irq_save_pci, NULL, irq_load_pci, 1, HVMSR_PER_DOM); -HVM_REGISTER_SAVE_RESTORE(ISA_IRQ, irq_save_isa, irq_load_isa, +HVM_REGISTER_SAVE_RESTORE(ISA_IRQ, irq_save_isa, NULL, irq_load_isa, 1, HVMSR_PER_DOM); -HVM_REGISTER_SAVE_RESTORE(PCI_LINK, irq_save_link, irq_load_link, +HVM_REGISTER_SAVE_RESTORE(PCI_LINK, irq_save_link, NULL, irq_load_link, 1, HVMSR_PER_DOM); --- a/xen/arch/x86/hvm/mtrr.c +++ b/xen/arch/x86/hvm/mtrr.c @@ -773,7 +773,7 @@ static int cf_check hvm_load_mtrr_msr(st return 0; } -HVM_REGISTER_SAVE_RESTORE(MTRR, hvm_save_mtrr_msr, hvm_load_mtrr_msr, 1, +HVM_REGISTER_SAVE_RESTORE(MTRR, hvm_save_mtrr_msr, NULL, hvm_load_mtrr_msr, 1, HVMSR_PER_VCPU); void memory_type_changed(struct domain *d) --- a/xen/arch/x86/hvm/pmtimer.c +++ b/xen/arch/x86/hvm/pmtimer.c @@ -300,7 +300,7 @@ static int cf_check acpi_load(struct dom return 0; } -HVM_REGISTER_SAVE_RESTORE(PMTIMER, acpi_save, acpi_load, +HVM_REGISTER_SAVE_RESTORE(PMTIMER, acpi_save, NULL, acpi_load, 1, HVMSR_PER_DOM); int pmtimer_change_ioport(struct domain *d, uint64_t version) --- a/xen/arch/x86/hvm/rtc.c +++ b/xen/arch/x86/hvm/rtc.c @@ -797,7 +797,7 @@ static int cf_check rtc_load(struct doma return 0; } -HVM_REGISTER_SAVE_RESTORE(RTC, rtc_save, rtc_load, 1, HVMSR_PER_DOM); +HVM_REGISTER_SAVE_RESTORE(RTC, rtc_save, NULL, rtc_load, 1, HVMSR_PER_DOM); void rtc_reset(struct domain *d) { --- a/xen/arch/x86/hvm/vioapic.c +++ b/xen/arch/x86/hvm/vioapic.c @@ -631,7 +631,8 @@ static int cf_check ioapic_load(struct d return 0; } -HVM_REGISTER_SAVE_RESTORE(IOAPIC, ioapic_save, ioapic_load, 1, HVMSR_PER_DOM); +HVM_REGISTER_SAVE_RESTORE(IOAPIC, ioapic_save, NULL, ioapic_load, 1, + HVMSR_PER_DOM); void vioapic_reset(struct domain *d) { --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -1145,7 +1145,7 @@ static int cf_check viridian_load_domain return 0; } -HVM_REGISTER_SAVE_RESTORE(VIRIDIAN_DOMAIN, viridian_save_domain_ctxt, +HVM_REGISTER_SAVE_RESTORE(VIRIDIAN_DOMAIN, viridian_save_domain_ctxt, NULL, viridian_load_domain_ctxt, 1, HVMSR_PER_DOM); static int cf_check viridian_save_vcpu_ctxt( @@ -1188,7 +1188,7 @@ static int cf_check viridian_load_vcpu_c return 0; } -HVM_REGISTER_SAVE_RESTORE(VIRIDIAN_VCPU, viridian_save_vcpu_ctxt, +HVM_REGISTER_SAVE_RESTORE(VIRIDIAN_VCPU, viridian_save_vcpu_ctxt, NULL, viridian_load_vcpu_ctxt, 1, HVMSR_PER_VCPU); static int __init cf_check parse_viridian_version(const char *arg) --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -1591,9 +1591,9 @@ static int cf_check lapic_load_regs(stru return 0; } -HVM_REGISTER_SAVE_RESTORE(LAPIC, lapic_save_hidden, +HVM_REGISTER_SAVE_RESTORE(LAPIC, lapic_save_hidden, NULL, lapic_load_hidden, 1, HVMSR_PER_VCPU); -HVM_REGISTER_SAVE_RESTORE(LAPIC_REGS, lapic_save_regs, +HVM_REGISTER_SAVE_RESTORE(LAPIC_REGS, lapic_save_regs, NULL, lapic_load_regs, 1, HVMSR_PER_VCPU); int vlapic_init(struct vcpu *v) --- a/xen/arch/x86/hvm/vpic.c +++ b/xen/arch/x86/hvm/vpic.c @@ -449,7 +449,7 @@ static int cf_check vpic_load(struct dom return 0; } -HVM_REGISTER_SAVE_RESTORE(PIC, vpic_save, vpic_load, 2, HVMSR_PER_DOM); +HVM_REGISTER_SAVE_RESTORE(PIC, vpic_save, NULL, vpic_load, 2, HVMSR_PER_DOM); void vpic_reset(struct domain *d) { --- a/xen/arch/x86/include/asm/hvm/save.h +++ b/xen/arch/x86/include/asm/hvm/save.h @@ -113,6 +113,7 @@ typedef int (*hvm_load_handler) (struct void hvm_register_savevm(uint16_t typecode, const char *name, hvm_save_handler save_state, + hvm_check_handler check_state, hvm_load_handler load_state, size_t size, int kind); @@ -122,12 +123,13 @@ void hvm_register_savevm(uint16_t typeco /* Syntactic sugar around that function: specify the max number of * saves, and this calculates the size of buffer needed */ -#define HVM_REGISTER_SAVE_RESTORE(_x, _save, _load, _num, _k) \ +#define HVM_REGISTER_SAVE_RESTORE(_x, _save, check, _load, _num, _k) \ static int __init cf_check __hvm_register_##_x##_save_and_restore(void) \ { \ hvm_register_savevm(HVM_SAVE_CODE(_x), \ #_x, \ &_save, \ + check, \ &_load, \ (_num) * (HVM_SAVE_LENGTH(_x) \ + sizeof (struct hvm_save_descriptor)), \ --- a/xen/arch/x86/hvm/save.c +++ b/xen/arch/x86/hvm/save.c @@ -88,6 +88,7 @@ static struct { void __init hvm_register_savevm(uint16_t typecode, const char *name, hvm_save_handler save_state, + hvm_check_handler check_state, hvm_load_handler load_state, size_t size, int kind) { @@ -96,6 +97,7 @@ void __init hvm_register_savevm(uint16_t ASSERT(hvm_sr_handlers[typecode].check == NULL); ASSERT(hvm_sr_handlers[typecode].load == NULL); hvm_sr_handlers[typecode].save = save_state; + hvm_sr_handlers[typecode].check = check_state; hvm_sr_handlers[typecode].load = load_state; hvm_sr_handlers[typecode].name = name; hvm_sr_handlers[typecode].size = size; From patchwork Thu Nov 16 13:47:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13457922 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 768BFC54FB9 for ; Thu, 16 Nov 2023 13:47:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.634236.989640 (Exim 4.92) (envelope-from ) id 1r3cig-0005SQ-7t; Thu, 16 Nov 2023 13:47:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 634236.989640; Thu, 16 Nov 2023 13:47:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r3cig-0005SJ-4k; Thu, 16 Nov 2023 13:47:46 +0000 Received: by outflank-mailman (input) for mailman id 634236; Thu, 16 Nov 2023 13:47:44 +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 1r3cie-0003dG-EJ for xen-devel@lists.xenproject.org; Thu, 16 Nov 2023 13:47:44 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on062c.outbound.protection.outlook.com [2a01:111:f400:fe0e::62c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b6f67cc8-8486-11ee-9b0e-b553b5be7939; Thu, 16 Nov 2023 14:47:42 +0100 (CET) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by VI1PR04MB7181.eurprd04.prod.outlook.com (2603:10a6:800:12a::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.7; Thu, 16 Nov 2023 13:47:41 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44%3]) with mapi id 15.20.7002.019; Thu, 16 Nov 2023 13:47:40 +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: b6f67cc8-8486-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dkH7Qef6wZuvUH5Z/H+VX7O2ES6Wapzdx9D1Ki2hR3wD5xZ5uUlI55mqMewxYAzF4EziuORLdA+tAVwkuhxbsSb8lNsKsPTBKSNVff89SsO61+TMPa+bkRjASt+haLB8AKuLNcs5Q/Syx6zT/Vgk239/RaH5AI67YUeoCXhR6V8nw6ViqCtN6xKJJ4AL8kfhkimuHpol2eO4mt9E/WVtTS4+WqJyo643Ld3S2Dd/H/3HNYizUwHJJnelpjkYSwTtYilYh6vJdqZrbxtehZ4J76psAbpnpuXW9BqwzZLvbuskI8kpA2jkb17LUieJ3vqhuzY2kZj+rBOjmjv8bNPXpA== 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=VFoksZlHmjUHcpacPzoQIHgByDW8pTeI436EQErY+x8=; b=I2UwZ7ojL9hWVeVkbyeCZGB5JAv1ghskKnIu4Mw2YaAj/HZ7Z+mgIQSmTRa9JsHPn7eDS8jd65toNo3cZ9AU5aUHPY/gSSPwrdm/GA+0mm3gxfWC01G5SGNPPTH4r3c+Aj0yMLpHVxno7boPNrPiQ9wXuYZS1+ssHLH9ptJbi2VfgrGs7/DS5N3x7R3NdF3GI0ut2nD+rDtSxNonfIddml+tKJDYC/0FPcrPBuK0wN1FBCVzgSs1i4XUvxdFiQWwcz6LApgoG8yZ7DgVe32NMUrS/DE908et7+qOx2Ov/IrRgEbHxVf1l8gvi6/zTVkyD9tBtO1UzMD59DDp5jdrXg== 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=VFoksZlHmjUHcpacPzoQIHgByDW8pTeI436EQErY+x8=; b=iyX3xRRkhYaqiJ4lMOHmoCTzpgmkCee7L10fUDtu3WSRhvAff6stRAh+3Oz3jWuF+ePY0+KdMXusyjyK3OMhlW8s2iSBoLN+4JsWoZAsiOdfiDpqrZE3t9WUl63TSxk4A5Yl+PPITTMH1KUHME+bfutPGGIFI1h6v4UUIyVMPFMUaPrVZqV7J8tkiBeWIeRh6TRMiWoBekj80YOZnVRwC4tMHpJLoi3acFnT7Ygu8z2cxxXG9wVHaNzKa5svXyaw4jxLKzXI8V1+NWe6ol+lWTun5JJYEGG+gmw9BGJEyBDmkyKQwKv7oug/XXtuPU022DaRxnX2uZin5BWp9v9YyQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <584f566f-a0c9-49b5-b592-89ac4f1ecd05@suse.com> Date: Thu, 16 Nov 2023 14:47:39 +0100 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 4/5] x86/vPIT: check values loaded from state save record 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?= References: <08e0708c-17e2-4a5e-aaf7-5f60a40f76db@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9Jj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0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <08e0708c-17e2-4a5e-aaf7-5f60a40f76db@suse.com> X-ClientProxiedBy: FR0P281CA0011.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:15::16) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|VI1PR04MB7181:EE_ X-MS-Office365-Filtering-Correlation-Id: 97ded0cd-c276-4366-97a1-08dbe6aa9a25 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yet2sjyEsyIQNpVZ0tinFxYlZaLLfG8BRPThH8G5O5aSeVa/RzzgR9wO+55vUjhz9exBkjV2jJN+/fgXrL1LoKRY0jxQJTJcCiPcZELvy/l/zzRb8kr19NXbs4PfT6MjGpNUNP0LC6B3uUVp4QorsQCTaX4HiXUcQdLZ52J578qeHBsVpEQj24UE87LKo1VduD1VP7liFNyd0mRVeFfWwWiWez4dbAXz7CPbF/RoAEwb7IIfyVJm2sdKDUbuTkzsrQHa9SmNeLgIGr84GBcCSvxjWcdhzfJaBvhVK6aSsmjeNKETO01fRtmtA962izR57Z9Eu/zW+5Ll9/uV+tMVAymkwnShP+9KY8VYKdgZL33AR+oRSYE6V5a+fimc9gu5ybnrvogW4tKrR9a+rG9G8SaoeGPeypDW1XlA2SkkC3JHGPF9QBNhHkolBuMPnujIGUDaZxwcgoi33bPTlUcCMFGxvg5grZLCjnmDTmaXkAK0QdAU0FcfW6G4gT/oToO9rXrO2tkKIO2NzUqMmdWGqPKB1Mp+GFCkclNxTwecIJ2UAO2nZwup+v/ujoWhTOqTBOTNOrJ0XVjWX5sE06iOxZcFQsoHYMuLLKx55BbpQjRHI8Te4TNnVoJD+kSVh7LbNY8BSlIUQLcqEIGpWH8TAw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(136003)(366004)(346002)(396003)(230922051799003)(64100799003)(1800799009)(186009)(451199024)(31696002)(36756003)(86362001)(8676002)(2906002)(8936002)(4326008)(5660300002)(66476007)(66556008)(54906003)(316002)(66946007)(6916009)(478600001)(6486002)(38100700002)(31686004)(6506007)(26005)(2616005)(41300700001)(83380400001)(6512007)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?v01YjUJy1wVARVsqqvb4XD6jxiJr?= =?utf-8?q?dZU9QaVmoLSGPF4ReD36QeIl6t1AjKwT7VfBEPGNJvkyFf3l2Rqxm6qeg1NBb4O1z?= =?utf-8?q?nPCGPn9FMj8f8k1Pt4dQAXG1sjxqKdl2f/d+4Gl9uJW10zkDQIj5tLwirHPoh6Ded?= =?utf-8?q?ARCKy6TtVYuRaZHjkHSdec8mQOT4RtaYAG7Wrt1cK9NTaNcD5O6dBVNA9hhOX15oO?= =?utf-8?q?+uklXKoJd6Hi5sCtDlPvTrJlo1u90h4gMYQNWAJu1/nYvkVG2GeBfg4xtO2oEi8y2?= =?utf-8?q?TftH5RdTB1evhb1V9I2B456pxp49hGxB2sy0RuHxPH5/t2TPXXH5i7i6JEkF+O50/?= =?utf-8?q?nPX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ep0HO5egID3hYEXJuCEQXtf1H0onycoHWMFCQIvIjsm4KleaOas+KYs1?= =?utf-8?q?g9K/1XVki0DDJqOcyRVnvy6mIiP14ZM9zv6bjtLSrQsNeT5XQ2C6QXS3qq7Q8/pkd?= =?utf-8?q?ETjUmC3XHWSsZA3w4Pa2QG6Y1idIL4vCRSk/I2Yhg9TUJAPRqDJ5mLrTiIbUPL5vA?= =?utf-8?q?XGF0CAnikS0jV7UPwKeLItxKWk18Ily+2LQQWrmheswC73XNK1j9+WLKQKd4KX30z?= =?utf-8?q?guynpAsjt6B5Vji30DXmVDiVUSes1I3UY+fQwgMv5szQWDLRhIks17GsIN6Piimoe?= =?utf-8?q?QLM/Haqiiy4A?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97ded0cd-c276-4366-97a1-08dbe6aa9a25 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2023 13:47:40.9218 (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: yVafaRlbeitlIjNt+2eThCm0qhnm81BZKTSryPaVR6gaIgf1tzqpd3PJCWdEFSR1xOrrlpqd/DjBLs00div52w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7181 In particular pit_latch_status() and speaker_ioport_read() perform calculations which assume in-bounds values. Several of the state save record fields can hold wider ranges, though. Refuse to load values which cannot result from normal operation, except mode, the init state of which (see also below) cannot otherwise be reached. Note that ->gate should only be possible to be zero for channel 2; enforce that as well. Adjust pit_reset()'s writing of ->mode as well, to not unduly affect the value pit_latch_status() may calculate. The chosen mode of 7 is still one which cannot be established by writing the control word. Note that with or without this adjustment effectively all switch() statements using mode as the control expression aren't quite right when the PIT is still in that init state; there is an apparent assumption that before these can sensibly be invoked, the guest would init the PIT (i.e. in particular set the mode). Signed-off-by: Jan Beulich --- For mode we could refuse to load values in the [0x08,0xfe] range; I'm not certain that's going to be overly helpful. For count I was considering to clip the saved value to 16 bits (i.e. to convert the internally used 0x10000 back to the architectural 0x0000), but pit_save() doesn't easily lend itself to such a "fixup". If desired perhaps better a separate change anyway. --- v2: Introduce separate checking function; switch to refusing to load bogus values. Re-base. --- a/xen/arch/x86/emul-i8254.c +++ b/xen/arch/x86/emul-i8254.c @@ -47,6 +47,7 @@ #define RW_STATE_MSB 2 #define RW_STATE_WORD0 3 #define RW_STATE_WORD1 4 +#define RW_STATE_NUM 5 #define get_guest_time(v) \ (is_hvm_vcpu(v) ? hvm_get_guest_time(v) : (u64)get_s_time()) @@ -427,6 +428,47 @@ static int cf_check pit_save(struct vcpu return rc; } +static int cf_check pit_check(const struct domain *d, hvm_domain_context_t *h) +{ + const struct hvm_hw_pit *hw; + unsigned int i; + + if ( !has_vpit(d) ) + return -ENODEV; + + hw = hvm_point_entry(PIT, h); + if ( !hw ) + return -ENODATA; + + /* + * Check to-be-loaded values are within valid range, for them to represent + * actually reachable state. Uses of some of the values elsewhere assume + * this is the case. Note that the channels' mode fields aren't checked; + * older Xen might save them as 0xff. + */ + if ( hw->speaker_data_on > 1 || hw->pad0 ) + return -EDOM; + + for ( i = 0; i < ARRAY_SIZE(hw->channels); ++i ) + { + const struct hvm_hw_pit_channel *ch = &hw->channels[i]; + + if ( ch->count > 0x10000 || + ch->count_latched >= RW_STATE_NUM || + ch->read_state >= RW_STATE_NUM || + ch->write_state >= RW_STATE_NUM || + ch->rw_mode > RW_STATE_WORD0 || + ch->gate > 1 || + ch->bcd > 1 ) + return -EDOM; + + if ( i != 2 && !ch->gate ) + return -EINVAL; + } + + return 0; +} + static int cf_check pit_load(struct domain *d, hvm_domain_context_t *h) { PITState *pit = domain_vpit(d); @@ -443,6 +485,14 @@ static int cf_check pit_load(struct doma goto out; } + for ( i = 0; i < ARRAY_SIZE(pit->hw.channels); ++i ) + { + struct hvm_hw_pit_channel *ch = &pit->hw.channels[i]; + + if ( (ch->mode &= 7) > 5 ) + ch->mode -= 4; + } + /* * Recreate platform timers from hardware state. There will be some * time jitter here, but the wall-clock will have jumped massively, so @@ -458,7 +508,7 @@ static int cf_check pit_load(struct doma return rc; } -HVM_REGISTER_SAVE_RESTORE(PIT, pit_save, NULL, pit_load, 1, HVMSR_PER_DOM); +HVM_REGISTER_SAVE_RESTORE(PIT, pit_save, pit_check, pit_load, 1, HVMSR_PER_DOM); #endif /* The intercept action for PIT DM retval: 0--not handled; 1--handled. */ @@ -575,7 +625,7 @@ void pit_reset(struct domain *d) for ( i = 0; i < 3; i++ ) { s = &pit->hw.channels[i]; - s->mode = 0xff; /* the init mode */ + s->mode = 7; /* the init mode */ s->gate = (i != 2); pit_load_count(pit, i, 0); } From patchwork Thu Nov 16 13:48:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13457923 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 192A4C54FB9 for ; Thu, 16 Nov 2023 13:48:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.634240.989650 (Exim 4.92) (envelope-from ) id 1r3cj5-0006Eb-MB; Thu, 16 Nov 2023 13:48:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 634240.989650; Thu, 16 Nov 2023 13:48:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r3cj5-0006EQ-JP; Thu, 16 Nov 2023 13:48:11 +0000 Received: by outflank-mailman (input) for mailman id 634240; Thu, 16 Nov 2023 13:48:10 +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 1r3cj4-0003dG-Jr for xen-devel@lists.xenproject.org; Thu, 16 Nov 2023 13:48:10 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on20619.outbound.protection.outlook.com [2a01:111:f400:7e1a::619]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c68b3322-8486-11ee-9b0e-b553b5be7939; Thu, 16 Nov 2023 14:48:09 +0100 (CET) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by DU0PR04MB9443.eurprd04.prod.outlook.com (2603:10a6:10:35b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.17; Thu, 16 Nov 2023 13:48:06 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44%3]) with mapi id 15.20.7002.019; Thu, 16 Nov 2023 13:48:06 +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: c68b3322-8486-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jkBTUVfpTRISbuIuUJoH31KBkXyTRnzgUA4Zi8K/KE0uYAF9PDH7I0VQYV6mUb22xPp9DTSA60pBZx3mnLBBFRVmi9JkEWqvyjKqHVQLRKYJxVGshJku5nKNLWTXXHFrDAfBs+HtEYc64ypSEc5emWgwnwJBWRtwpDzmf3sXSZeiQ2M9Ut1099VKNKcnjrh7UmT3ingOjFMOGAXCpVU5m2quhEP0lpwo8kRnu2slhX4uCXiOUBzx/59C+vKV90Y/SMVjti9QdJ5F9ZPRU/GNZhqC3OHpkCVw51a78N41EOHlvKFP7fn3QCUaAPDQuMs69dW26WvVtYP8tJOerB0Vjg== 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=bqohVIbaW1GFFTMipf5Ri+LEksZYdjyITV1mQl/ILng=; b=YUkj1lnk5ZOi0gmRVrP2GgKm0XxHrYmEHjsP30EEPWPrOyl1lGVA281XA0tI3odWkvGtQRNODRY2SejVLgyhnFzFMmkgz9dX5P6VLn8bzPLuuKxo/68z5I4/m/0pwr4Wjy+NT+d+m517MwZ4fJOA0LlEIwYb2S+1O4Vu0UDkMD68LMxusgJQcxx1t2dzMHluESDhFLxuSU+mB90BmvZr+PmJs5wNfZlEkXGDKpN5ign5Ru0VyNwzuBwADV0pZTUtG2CVa+PdfQdpHiBlozHH5YZNRvYXBoxdyU/6vXu4ockts6reCHw6KKfN4tkhZYeVys4DySLciF7BSFC5pjx50A== 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=bqohVIbaW1GFFTMipf5Ri+LEksZYdjyITV1mQl/ILng=; b=cG6Pat/5x8/3vo2xLiXp9eES4245OLJNP5oX1yUqXTG9ohZFYxfHi68veYmDNjBTAZjDHU1RHtFlE1lbPw8L7B1LASdGx0SmvD+1pXijfcWkSLkw5cG8/beS+MxmCe9AWHxf61MxC6Ol2cLL2yj5eMBjuvgJD5lIt6COcnzFwiZuq0JZWkMx/B9P5gRBqYi8cMIwwz8nQqryPWBmWrd7S1BhlLdtL8HdWU+cQlS0FmdtSVaW6GtnT5AjUCXM0iNx+6QX7/cCGZAPO8zL2TuNL5zp7Ocvz1WQG0ku18UOjH9d/mBHOTr34z62+37vK5mfol+DbLgkUFUcXRY6xR5JNQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <976532e6-9514-4a46-8ca1-edf66f22659b@suse.com> Date: Thu, 16 Nov 2023 14:48:05 +0100 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 5/5] x86/vPIC: check values loaded from state save record 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?= References: <08e0708c-17e2-4a5e-aaf7-5f60a40f76db@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8r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WpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <08e0708c-17e2-4a5e-aaf7-5f60a40f76db@suse.com> X-ClientProxiedBy: FR0P281CA0011.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:15::16) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|DU0PR04MB9443:EE_ X-MS-Office365-Filtering-Correlation-Id: 22841434-97af-4b03-00d4-08dbe6aaa941 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bMlNPW734KhZ90doakKgfjLrH2A0Q3G/o5kULoHNAiUxOV9SAVeY0ssYwiOijxjOlZvMWe0IXqZRw87hOtla5m9lVr4DBajfXd8144EmCQu6lLMpVtVdoepxUjfIJSF/+yeDyvbWP7k7kvxXU4RRJGcpvEURnsdkZdcYQaLm6ows4JPCCxvj7jvwIkK2wQ6pK4xqp93I8w2jIKZlBka1GeyshqfdFeMwqX+j9mxqzHdUquXLZVBJwp29lvMhTuEYtqrcteuf4sX0D5Th9pYxqmFCIhKpcp+eaKlrRabPAGoUkdCHBbpcxheApRzJ16XO08ZCLKVFWcqKmxDO/Pe54gxs4zjGPLAjrLpv653QYa0eXKWPXMzSqrocA+EI+xVMFUAFRaRIultXAT4r8xGwGo/imN6t3jkFengPa0qSQPUxx+csLrUEOoNqMkZM32yemqJI2nFJ8pxfdRKhQLBBW4RC13nAZmC2lmQIIzi0ZuyqtYWFz6INpnQNXoksD5GbuEZz1hYZ77EAybFa8Q5J925jzPEC8RyO4AwApz8PBBVGI75vHm3wHz3ATpqyKs7ixQ9g7otwrRifpRsJcJmZuyyuEsCOUaMpoiNCCTdQi2reiowTsAQ4kE2MuPAe99mhDekb2OxJOECy9Ixztaiwbw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(376002)(39860400002)(136003)(346002)(230922051799003)(186009)(64100799003)(1800799009)(451199024)(316002)(8676002)(66946007)(8936002)(6486002)(66556008)(54906003)(66476007)(38100700002)(6506007)(478600001)(26005)(5660300002)(83380400001)(4326008)(6512007)(6916009)(2616005)(31696002)(36756003)(41300700001)(2906002)(86362001)(31686004)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?vxFaVeCpXTsMXH2jZ+qiWNR+1/1y?= =?utf-8?q?KkhoYJOsR5hdKPeAVCESsb5KNkocAxNdyo9KrGIZcSsTTcvS+q+hDIBJZ78tJvli3?= =?utf-8?q?NbySOLbvtj1JQLxL4jn0gOGIkDm/FGW3QgXjnsM9cKhl27dY/bnuaSbliFvWA1yH5?= =?utf-8?q?Bf8HMsLQ52FnxMl5g/2PGUDA0RchDKtQfPP4o2KYLjmG0/u7D448Xipd9zK4cDhi/?= =?utf-8?q?HrJ0qbSdkq78g+mAFEfCiuDjoxoKTI/yS3Rtg04jXLPOkUlvzDKKTVlUbKp7jCr1Y?= =?utf-8?q?Wht6tBKXKmjJvUTvNfUTtlABvOSMbTSr5ugR3TuQe32woyli0WsrbCmt3ob2hLzLm?= =?utf-8?q?RBLZhdocX7azv96wiW7wNfH09ILxjwAD0YGXBDr+94D9Oy8y1D5twfh2AsceZ+Ol1?= =?utf-8?q?zvHm41OuFusl8QPOomIgPWJmYpTJljcFoXTHsAUv8an1hR4xPibdZi3jxqK/0YZlR?= =?utf-8?q?Ja/cr3SRuH7SsCmoc3yBBqOgN4pRbfbHFlbeltf0NutXL3ZGj/wafSKC0xrfvr5T7?= =?utf-8?q?XFJ9KGJfDPw9iQTMnfP/R0kdVAnxLyPFjFm/dzs6y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CtGkmIqgwEbDgiq5Ril?= =?utf-8?q?tuBshQxeHuhR3i1WE1vqCHyet1ROJRd+Fxoe5beN9Oa+SNEeqhJgkrxCA2SLcbxCw?= =?utf-8?q?g7pZhc5h1Mme?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22841434-97af-4b03-00d4-08dbe6aaa941 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2023 13:48:06.2568 (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: KDddFW0K5sSwq200kGt9Re+w/qHBJQObuUPLHfeiXYxHto/TRkX41nNFVZRTRrrYkytFl1H8eotUYY9UDwty3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR04MB9443 Loading is_master from the state save record can lead to out-of-bounds accesses via at least the two container_of() uses by vpic_domain() and __vpic_lock(). Make sure the value is consistent with the instance being loaded. For ->int_output (which for whatever reason isn't a 1-bit bitfield), besides bounds checking also take ->init_state into account. For ELCR follow what vpic_intercept_elcr_io()'s write path and vpic_reset() do, i.e. don't insist on the internal view of the value to be saved. Adjust vpic_elcr_mask() to allow using it easily for the new case, but still also especially in the 2nd of the uses by vpic_intercept_elcr_io()). Move the instance range check as well, leaving just an assertion in the load handler. While there also correct vpic_domain() itself, to use its parameter in both places. Signed-off-by: Jan Beulich --- v2: Introduce separate checking function; switch to refusing to load bogus values. Re-base. --- a/xen/arch/x86/hvm/vpic.c +++ b/xen/arch/x86/hvm/vpic.c @@ -35,13 +35,13 @@ #include #define vpic_domain(v) (container_of((v), struct domain, \ - arch.hvm.vpic[!vpic->is_master])) + arch.hvm.vpic[!(v)->is_master])) #define __vpic_lock(v) &container_of((v), struct hvm_domain, \ vpic[!(v)->is_master])->irq_lock #define vpic_lock(v) spin_lock(__vpic_lock(v)) #define vpic_unlock(v) spin_unlock(__vpic_lock(v)) #define vpic_is_locked(v) spin_is_locked(__vpic_lock(v)) -#define vpic_elcr_mask(v) ((v)->is_master ? 0xf8 : 0xde) +#define vpic_elcr_mask(v, mb2) ((v)->is_master ? 0xf8 | ((mb2) << 2) : 0xde) /* Return the highest priority found in mask. Return 8 if none. */ #define VPIC_PRIO_NONE 8 @@ -387,7 +387,7 @@ static int cf_check vpic_intercept_elcr_ if ( dir == IOREQ_WRITE ) { /* Some IRs are always edge trig. Slave IR is always level trig. */ - data = (*val >> shift) & vpic_elcr_mask(vpic); + data = (*val >> shift) & vpic_elcr_mask(vpic, 1); if ( vpic->is_master ) data |= 1 << 2; vpic->elcr = data; @@ -395,7 +395,7 @@ static int cf_check vpic_intercept_elcr_ else { /* Reader should not see hardcoded level-triggered slave IR. */ - data = vpic->elcr & vpic_elcr_mask(vpic); + data = vpic->elcr & vpic_elcr_mask(vpic, 0); if ( !shift ) *val = data; else @@ -429,6 +429,38 @@ static int cf_check vpic_save(struct vcp return 0; } +static int cf_check vpic_check(const struct domain *d, hvm_domain_context_t *h) +{ + unsigned int inst = hvm_load_instance(h); + const struct hvm_hw_vpic *s; + + if ( !has_vpic(d) ) + return -ENODEV; + + /* Which PIC is this? */ + if ( inst >= ARRAY_SIZE(d->arch.hvm.vpic) ) + return -ENOENT; + + s = hvm_point_entry(PIC, h); + if ( !s ) + return -ENODATA; + + /* + * Check to-be-loaded values are within valid range, for them to represent + * actually reachable state. Uses of some of the values elsewhere assume + * this is the case. + */ + if ( s->int_output > 1 ) + return -EDOM; + + if ( s->is_master != !inst || + (s->int_output && s->init_state) || + (s->elcr & ~vpic_elcr_mask(s, 1)) ) + return -EINVAL; + + return 0; +} + static int cf_check vpic_load(struct domain *d, hvm_domain_context_t *h) { struct hvm_hw_vpic *s; @@ -438,18 +470,21 @@ static int cf_check vpic_load(struct dom return -ENODEV; /* Which PIC is this? */ - if ( inst > 1 ) - return -ENOENT; + ASSERT(inst < ARRAY_SIZE(d->arch.hvm.vpic)); s = &d->arch.hvm.vpic[inst]; /* Load the state */ if ( hvm_load_entry(PIC, h, s) != 0 ) return -EINVAL; + if ( s->is_master ) + s->elcr |= 1 << 2; + return 0; } -HVM_REGISTER_SAVE_RESTORE(PIC, vpic_save, NULL, vpic_load, 2, HVMSR_PER_DOM); +HVM_REGISTER_SAVE_RESTORE(PIC, vpic_save, vpic_check, vpic_load, 2, + HVMSR_PER_DOM); void vpic_reset(struct domain *d) {