From patchwork Tue Nov 28 10:33:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13470948 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 44A10C4167B for ; Tue, 28 Nov 2023 10:34:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.642938.1002757 (Exim 4.92) (envelope-from ) id 1r7vPS-0000K6-Dp; Tue, 28 Nov 2023 10:33:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 642938.1002757; Tue, 28 Nov 2023 10:33:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r7vPS-0000Jz-Az; Tue, 28 Nov 2023 10:33:42 +0000 Received: by outflank-mailman (input) for mailman id 642938; Tue, 28 Nov 2023 10:33:41 +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 1r7vPR-0000IL-El for xen-devel@lists.xenproject.org; Tue, 28 Nov 2023 10:33:41 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0612.outbound.protection.outlook.com [2a01:111:f400:fe0e::612]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 97bf8e0d-8dd9-11ee-9b0e-b553b5be7939; Tue, 28 Nov 2023 11:33:39 +0100 (CET) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AM9PR04MB8844.eurprd04.prod.outlook.com (2603:10a6:20b:40b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.22; Tue, 28 Nov 2023 10:33:36 +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.7046.015; Tue, 28 Nov 2023 10:33:36 +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: 97bf8e0d-8dd9-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GisvrSPD0mju/nxXhRJpMFezXoI8D3iAoyEooZmR7NhoNpShHAoEkWP7+PJ8PFAeJlCQa1L6KLDmDgBsct/CKL3c4kVGe8hDLp+MDjo2n2HAHUSC3moxyseGmm8kgIszYzudnN4tP4cGFJWHgSU61FiyGe6WF45LwOylUcyjxaEVyTgU2LXedbzNazBtZSwGylqw0xKsVx6H1XdJHDg74uj0ECs/vid/wGJcLeGQEMXlwst4YPINDosxAthMlUG7+4ItwzHld1MobPPjOm6d6d4MziJ5hW5M9mH7w1foEk7q+6GdETqTl1AH9STjCAl8yb8rTU5abO/wfY+l9LiZ+A== 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=ZprIUxrlQ9pKLtqLP+Mf4qwZU5HLEL5NJRnyyEOBfjE=; b=AjIJ0ZLenNC6VLgDmyydWCNFbj4LGF7aEg1vdZB73Sxccof7TzUqDFkUzaABQ548qz61Q2kiLDpEhlM9oGoYCJZ8u3srnji+/BIcKs5kjBZDrW8YURKrJP32adfodUf6wxpzXIEPj8buuGTD7TrYkXel72eT6BD9l+8yj2is7UPtPFNoSB1pZjt80ysIp6R6D2yM2mhgsGtjp4dAysCx2w/3ruJkJqwsvpsc/5vOyXOXfiX6HLINrzNjvGSYQlbN9qx6ZbF2zjyEZjEr5gY4TgY8vDlp0lcbAit+YPljz7zp4GIy+6+BUZmer9pRkogAPAjaO56P3ljmw2To1EPnww== 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=ZprIUxrlQ9pKLtqLP+Mf4qwZU5HLEL5NJRnyyEOBfjE=; b=geq83vgh25rZJ+2teVQ060OPqtI4NnpAoiLygEkaRCVpZegeW/csa5t2+tnhQJqoVcRRua2VSJN6x5P1suFMYOugtNJ8Zkou9s+1bah9RKFmafk63ppKcX2ASVUNP9g+HkIgSz+Z0MbvH7+T2vv41O0UldoDfmv8Yz6b5PUA/46Lt8+f5hCQfgd2OLyavMQ4APTcmpE69ys/jDi1izb+XeAjs4fZFY9w4ud+hWor+J0SAQjGI80qPIiotc6vui+5egJmxGl4uSYSvKl1P6lNc6DDB/yEUgVzxiloU0S9EkW+LyP/2S6qpkK1f/hthXqloRiLML1mAlZt/5HhUYgV5A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Tue, 28 Nov 2023 11:33:35 +0100 User-Agent: Mozilla Thunderbird Subject: [PATCH v3 1/6] x86/HVM: introduce hvm_get_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: <49a17ffa-c873-4b0f-81ed-9587053ca159@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: <49a17ffa-c873-4b0f-81ed-9587053ca159@suse.com> X-ClientProxiedBy: FR4P281CA0444.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:c6::6) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AM9PR04MB8844:EE_ X-MS-Office365-Filtering-Correlation-Id: 24254803-e8db-42be-4afa-08dbeffd7a67 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2uYHqOTsBhL/xGq8wD+FDCxY7sl8jnoDJeU4z+KBhGrY7Zc/GOyQoFLjEetHue0GDFW82L+a2jTMWEIGKkqpCUPB/f+88p1JoWaMDaKDPhMxtDEAkqFjLgiUC900/WVtG8ymHk21yAunMN/yTY/AnBg9jNzbKmmuWt585wLB5MlDKw6EkJ4zmBNi4Sze3c98T5uiwnVxulOyDt/B+U8dl2cmkRKC45L6eft2N/o4zH4NaPCRUSxIKLrIEY5P+RnphPyDYez43dyDnfuJ5TZ8oFWYoNTmnQAq6ag6cxiE/FcEC1oWN3lJ4S0xKYri2XXjPzprXGQiusp3WuJ0P5xKBv6ObbyzmJRntC/9r5kOXf3VqiLPJsPZRRAhjQ6DijU7AijTPRhZmcjiezdU7OXqDAtRge4NxRu0d8Cl6WiWsYw1KH5sH5ALgI3D9Uzb3TH9FByTqm2wpuH6anK9rQOiA71K0r7fshAcZB5+T4nXUQ5r0110qhSfjB5kThhAWBiDRopA3sTUVZK4/0NA+UKXAzgCfG1Pu6jRfUdHCpm6T6ccM4YoAmyGIDN+iTfkb10ivVQ3DVN/fo0kqZpA8MnlwQ6eS99JBbf7F3nzRFkeNBb9KPhCO0EqUVHmB8X7uRl5sKECA0+PrNY+jb0Pam/jGw== 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)(39860400002)(366004)(136003)(346002)(396003)(376002)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(31696002)(86362001)(2906002)(5660300002)(6512007)(31686004)(6506007)(8676002)(4326008)(41300700001)(8936002)(83380400001)(316002)(54906003)(38100700002)(36756003)(2616005)(478600001)(6486002)(66476007)(66946007)(6916009)(26005)(66556008)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?AeO/XONcwBLMfJnMGTdTc934OHNv?= =?utf-8?q?aA8dRlazWC8bk0n7N0gBBZOefrZMMNjEWvNs7c++Z6ME2pMz9D2TXN4Ep7YJmmoaV?= =?utf-8?q?ZTgQGYQg0SOTnocDT6/6YatxaqpCfTTVGRNX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qxowypCuLNiGEv4dM/oIh5uVOIuJbo?= =?utf-8?q?Gdghb/9lm23f/wnA9kbgBGzqXb7rW3Q0985/XoSuNlE1XDGVFE03P8Xv0Bn1+EOuT?= =?utf-8?q?NssiXugBkQlpDojlX5ZgJM6ckVossbO+0IwQ5jlFcHHCFxYzPoTkU5iuMEFCOSsfZ?= =?utf-8?q?ILkt0jPSR3jgNLi+fdEpGoamJK5x01zH4mDxqwZoef7LBjyU/peW0qDtNbas0SQm4?= =?utf-8?q?4AbN6WDMq5Gr2wfsgLmqRlNEulHE4T8NJOL9fjd3pJ+t4bmyv0TPYGLx0sGhd9XSQ?= =?utf-8?q?gG6/4DCpo5iklhPwgkCUEW6E9Z0HvEt1c25E5c++pcFhq4PnjgNa410HeCrjUHq0I?= =?utf-8?q?e3lN85HTx59HHOrJJZodyPfo6rplV5X4fmVQ2GpJeUPyWd3hTA45iiscvzM+o88Gx?= =?utf-8?q?49SjTb3W+w8w+LMf3As1KHkwHso4Rzda5U+OAFWR0jzrO0NleTeGUSAJi34gZStCy?= =?utf-8?q?AVmkcSKFxdM9u/psua3qWEphM0T/EiCP3CS5/nRDbeF1Vw92R0ywpp+pEBQvziO4S?= =?utf-8?q?BKeOah+KWFA9?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 24254803-e8db-42be-4afa-08dbeffd7a67 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2023 10:33:36.3445 (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: PSomdg0tBYMx8qmPP3mXeTooeqQhQ7z/vKVjA6z1LXguqHVbsf0Tg7WfUJJfGQDJzhtrwTAMY4wW5nsosd/Jzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8844 ... 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 --- v3: Rename to hvm_get_entry(). 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_get_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_get_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_get_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 Tue Nov 28 10:34:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13470949 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 8BC88C4167B for ; Tue, 28 Nov 2023 10:34:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.642941.1002767 (Exim 4.92) (envelope-from ) id 1r7vPt-0000rB-Qz; Tue, 28 Nov 2023 10:34:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 642941.1002767; Tue, 28 Nov 2023 10:34:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r7vPt-0000r2-O4; Tue, 28 Nov 2023 10:34:09 +0000 Received: by outflank-mailman (input) for mailman id 642941; Tue, 28 Nov 2023 10:34:07 +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 1r7vPr-0000oV-Pm for xen-devel@lists.xenproject.org; Tue, 28 Nov 2023 10:34:07 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0618.outbound.protection.outlook.com [2a01:111:f400:fe0e::618]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a8242fa7-8dd9-11ee-98e3-6d05b1d4d9a1; Tue, 28 Nov 2023 11:34:06 +0100 (CET) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AM9PR04MB8844.eurprd04.prod.outlook.com (2603:10a6:20b:40b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.22; Tue, 28 Nov 2023 10:34:05 +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.7046.015; Tue, 28 Nov 2023 10:34:05 +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: a8242fa7-8dd9-11ee-98e3-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BMjN5Scs99xapyXXAGIeI9utqvVMF0N0q17VVdJuVJOdLQh2bvp8FEiHpFx9p8Hu6n0ervmZC0lxxT3RMpZol+6VYclu9K9zNRu+CBt4i46wE+2h9hbnASnUHp6Qsv4AsTI5uvri5KGtVIwKv7qNTXmveWCO8hsXHOuY3JUtM7MGeCc153EiuB67qZR7XDbXdZ0kvyAQQ2o6DUR75kA2olhL9hSLdi30lp/886iQzaZ2EetlBnipSVEFMQ70fTIEoU4AQevgZXO6UMUNQil+EGzgEYYCyawwwrUNjNbSuhPewGhnA8nCWvaWs3vvxdYtlQoaSoooAieQfaU0OGuiAQ== 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=HV5NvHCW8qUyTXV7C3qR2W+ZkaZGrmcXrHSxDmLp0YE=; b=YgofCn80b0RxRRNS4uOcsbsoNlYCaYa7eNcOCOEtthbHuDRg8wYiL7gdsh8SBxHbedCStO5XKAfh4k9f1rcvmi+cyYYKtUTtUYE85a9uVncu/aEk1V/xAHHHFgGOaYo7WaGr7VAx5PYOpPKOkx9ls5skCEfkCyJiiINt+4P7cOOat8apjnpIYQZCzmhLTD9G4vbov3G/Y9ELfQ4OmR9TDi6i84QtxMezVDW18wBqv1UYXKQp1lOxMV5wMPTHXeSHfNVmyqNBGM17933HL8TtCGG1gb8GlLKUU5nXVufJr6YpT0bYq5V+YjM0REWgfxCGbij37915ChkfIrOPUYGs6w== 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=HV5NvHCW8qUyTXV7C3qR2W+ZkaZGrmcXrHSxDmLp0YE=; b=B7WL+hpJDrm5sQPKS+PKjKyAAKtGVS3yngbopK+Da61vh+Wuc6hN+ZnGkoKr4tR+RBuhbhroz5R6MSnx5vNb7gPq0G3ysoPqk1ogje4aPKhooSE4AqxSiT4d8EnfrAHheTLfGghFYKPfd6pzt9hNQQqhrsiRQ/y89uqFgM8tq75Cpeb22w1Sg7HSO+XpsG1/DUF+Ay54aKS+HZZ3wwPiatcJHMf4I2DVSDVElFjdyWBeoHVWCHjpAy3dB43bbeb8MUtG7flKnMkcWTMe2TVY8NxnNA8x9l8mOitNxbq0ZH2qySRnESmIjp4g3rCemFxH2C3R6lwCuE+/R0PfoHglNQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Tue, 28 Nov 2023 11:34:04 +0100 User-Agent: Mozilla Thunderbird Subject: [PATCH v3 2/6] 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: <49a17ffa-c873-4b0f-81ed-9587053ca159@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: <49a17ffa-c873-4b0f-81ed-9587053ca159@suse.com> X-ClientProxiedBy: FR4P281CA0444.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:c6::6) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AM9PR04MB8844:EE_ X-MS-Office365-Filtering-Correlation-Id: 623c4868-8194-46da-36bc-08dbeffd8b8a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: knB3XGgztw8Q6IXSzcov6Htl0Fc/g7a8VEoSEqWaO3WqFEq22fyeYXq+1Y+lHNYhHey673U7EqYGglZoZId0c09/CCyS7zE8Kff3tONmuU83TC7p3GtzpXDBCjiAwias3feGuFFerLAyhlmAaHgb7VpNCoGovDtaWgbI7ldWCDmAEh70pvhX3pL6cwa3d4ov0ecaK8SbytHCxGB+QK7ljLdDVsh1L+Qy29STHMH3Dkzhuu4pLkgb8wyGHwSRbbcmw/Cel7g7zlyD0ZY25h0Q+UOyNTnixctnkWk16P8sXn0zXRYphYMNgUlRP6hiUKzjur+UzDbyljCc6/oKxOnQMnS8V9OEiQLM53q7uXq/T/G3yqNQomLw5W2i/tnhoSHPlBCccNtochQW0st9blZpD5qmvJS4/Vq1RqCDNOzfPfIekdTzl9VWAAHoW1xJ7dpB1E+//wNhMhTJnj6aEWOVp/KrKbVEYNuMNPCuIGatUhmdBaelVRkDyfr/ElNYaBHYCifl4YK+McrtJ51MMp+j51S7WjT36xO+6EcY9zRLfDOtegOzsEQr8Q3wbh4/5i44K3Ny2p0z2Di+dAC6cj9NRz8A4GJUDTDzw7l4XGbZxxOVtaL4sJRsOe42JHULoEv/EIdCd2ovLvPz+IXU/xx8hA== 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)(39860400002)(366004)(136003)(346002)(396003)(376002)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(31696002)(86362001)(2906002)(5660300002)(6512007)(31686004)(6506007)(8676002)(4326008)(41300700001)(8936002)(83380400001)(316002)(54906003)(38100700002)(36756003)(2616005)(478600001)(6486002)(66476007)(66946007)(6916009)(26005)(66556008)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?fFCG6vFQpeCIdAusAP6gmAmXIUZQ?= =?utf-8?q?yke/VLR06SOJhVkm5zM7B432EnZ2LmyK/SCgCWX814kLUMRZ33iiSRL7Vnboc3hEr?= =?utf-8?q?WlYlP2B/S6vVKVO0t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/lp6VhkIbuRDFw1z6KxFTFRFUOH1vwf40YjTBCcgouU+yiEj?= =?utf-8?q?wkXitKU4Z74MgkW9pKRzWtg+eez52QmYqZzUPbwa/E8ZQ2aHNSqG6WmcNpPVPtZaO?= =?utf-8?q?Bg42l7rCPTpM1aiwK/4IvjBpzBTp2HERNiRqENog46xozeB9UMKRogNkvz9hDKScj?= =?utf-8?q?/B489EvyY2UZ2qyYw+uVI1b3rMtCRG52P1a+b6rrvmEwVHXAAlmowhkVTeQmD8qcg?= =?utf-8?q?tiPmHVIMDmmDhS8fWjKhvHCbvOhWOIKejQzMIBCCcbRPxJq2ea7tKAj3pl80scVh+?= =?utf-8?q?5iC8MD+FiHRZSx4mNu4QoJy8ftKvKjsTRgmjGt1ZFyBdVSw8n73XfOjThxjNRK2Ld?= =?utf-8?q?ztdyeE5zFhj9huqYIiENwO8gTL8durD89l7vQ/xe0pUFGNWQd08OpO+g/qWwb3HQX?= =?utf-8?q?1CF2gb/8oLTNcOlcpyuQQ3GZgRoXxDREMayFgkSEfUQIaMbbz3pPCBPV+JWKA+/uR?= =?utf-8?q?s0Rt7YYTDpml8a8aN+oyVWvmHWP9l3b2WZCUZtWY0bpdws2GgwTckvGbS0x0UvXt/?= =?utf-8?q?+l7QFdaai9x4?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 623c4868-8194-46da-36bc-08dbeffd8b8a X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2023 10:34:05.1092 (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: Fla6ULWxSMiMgcLLqikFOQ0bLgTcMhOjYFl4WfxG4WSMSXbu/lsyrZVYwLIC8IWmDKD2zmQbNQNuf0S0lg72mg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8844 ..., 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_get_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 Tue Nov 28 10:34:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13470950 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 9BD9EC4167B for ; Tue, 28 Nov 2023 10:35:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.642945.1002776 (Exim 4.92) (envelope-from ) id 1r7vQl-0001ex-4I; Tue, 28 Nov 2023 10:35:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 642945.1002776; Tue, 28 Nov 2023 10:35:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r7vQl-0001eo-1Z; Tue, 28 Nov 2023 10:35:03 +0000 Received: by outflank-mailman (input) for mailman id 642945; Tue, 28 Nov 2023 10:35:01 +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 1r7vQi-0001eS-Ua for xen-devel@lists.xenproject.org; Tue, 28 Nov 2023 10:35:01 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0606.outbound.protection.outlook.com [2a01:111:f400:fe0e::606]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c7410ee2-8dd9-11ee-9b0e-b553b5be7939; Tue, 28 Nov 2023 11:34:58 +0100 (CET) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AM9PR04MB8844.eurprd04.prod.outlook.com (2603:10a6:20b:40b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.22; Tue, 28 Nov 2023 10:34:57 +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.7046.015; Tue, 28 Nov 2023 10:34:57 +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: c7410ee2-8dd9-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I/GB5xavGsit3C5KGxn6FretSoyY3qBHzDsYC4aRpAKcz96SqU7UZCK+qS3OtP/IlTrPdMo3+9i2OF6cM9z2oC10oq0E0s2VxqRlL32jZPYMHY99BI4kkmrrlFgx+jMumjFI54UavzUhTQBB/iec+5BHIRBW5QzSXfq3+GPum6hjpi5XbynBoTKs5D6ZxMfA2q44nIEjvEA0b0zFx+fWGl90ciRRoopuyRiTqF7u5PZwW7i/Ciq15nzRmnBjhwe29J9eu08KR08oPCdIJWc56i5xO0tGEfvUYg+nsMRIHO2Zaw7iAbxcakMA4IhebcCr5LILihiVbYSSTJz+x7i+ZQ== 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=VPblwhZxXKXmmMEQwPYJhq3BZo9HkDC2DOK95SX8Bhw=; b=RSAn5rkq266bpDOt1vQKrRrRiCn7+nGs1Oo6HtHLJNt0DDqQNaEYA6KJuX8Be/D6alhb6FlD9TGNDm6FGKghxOAs7lGmdxfykul0lq4K7o8fSb9sH0VLa5hy9Ae9rbjK8I4b1FASrcTOD1M5jKDPpRw+Zncjyy4p0vgyE1mvgtFRPyo3FaGO5ffzbgVnks5BsW+2AOKHkrhV9LHl89bpJ28vYn5J4eKX69PcCZP8P/e6xZyJ42cnuZ/ykvw7Ye46T1jhVko0T31bGuIBYwZQUtCwU6bOb12UUCveLCNZNLrxeK5rcKL/ruKYYENZW32q1878e0okb7YBou50FHtoNQ== 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=VPblwhZxXKXmmMEQwPYJhq3BZo9HkDC2DOK95SX8Bhw=; b=u/oIFidpg4oE+dJb26v59hPJZANIgUReV3AsOa0yr5Ne/36uykVexqapAWn/JPwwE8q8378sxMtaGJiG+wgk0MegoKI74wE4HQhvhSf18RGzPeWjCBCwSMNy4bPtw8MmVGWmsJH8JlCU/XJfmGI5INJWjuaEdWjdkQVN/HGYJ4bZrSSIAEr+fDquGZgApseN3GfiiO16sgMaY/Q/SAvQjmodsPMNs/GNPVEcQAZvw0CxFWsLJlC9XSbwPLsGQupp+Zn4c3IO6mwv2oDWW9dxMGR7EuHEr7WxAe9ekqMnH2Hsbm1IqReujh0lndStkVXarCwcHmqxW3wv44LhWdEx5A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Tue, 28 Nov 2023 11:34:57 +0100 User-Agent: Mozilla Thunderbird Subject: [PATCH v3 3/6] 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: <49a17ffa-c873-4b0f-81ed-9587053ca159@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: <49a17ffa-c873-4b0f-81ed-9587053ca159@suse.com> X-ClientProxiedBy: FR4P281CA0444.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:c6::6) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AM9PR04MB8844:EE_ X-MS-Office365-Filtering-Correlation-Id: 09482840-8f91-4fc5-9f63-08dbeffdaac5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: t2dPqKkbG8YOGiziGkBRGMxX++Fib838ObmeL+AiDZoIth8pQEAMQh5Fr8b89jpyEtYEIJhIOBk/jOoao5puvJggO+xa9G7Fp+JVLnbm8CCK//ZmOwzjUWYHdQujDqdPTY2LhjDCyDYaM92SO4EqZQtamo5+JtN2vZ8ZLyo3BPp4gfNB+x/2lQevImkymdmO5rfvkV56LbEU+9o35w/qNNo8MoS6tWh9XtIFo4tDLwgKsU0mfX74rmFL1cijxFRY3LkFQcN1Rpk2DM9cv9jColhqsRM2TjIQHXGWRTlUz6ajiKv6i3qCxYU0w5rFKnWKHi5a0pfqXesfMr9e4bRR3svoX5sU79OVKNXnCt0aphkhCRa8vAnOaBqkjGOhfjECQAZDKgoRVMFFlvbmZ+8lW7xroJc1/fV0lkFMWHWU8ILs9fZKZXfGUGzpTyQbhl7exmYvq43gwV+kI0DYw73fJGA7XSXai/8fcfPbKE8K0H2H2QlEhiAORBRtFyYcMEN221w43U4l9S4ZZtHh/SLwh99oyv0ZcFDgYF9hP+HrnWnBZtRLKC70s1IdZa0Da+J27KmuuUlae+Rrr1Tv8BwDq+WIjn7oxLn5EEwtQLWL4Ag8bF7G4TzQAz+MbDWyhfWME+PFFyzI87sCdZRsCHJ4lw== 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)(39860400002)(366004)(136003)(346002)(396003)(376002)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(31696002)(86362001)(2906002)(5660300002)(6512007)(31686004)(6506007)(8676002)(4326008)(41300700001)(8936002)(83380400001)(316002)(54906003)(38100700002)(36756003)(2616005)(478600001)(6486002)(66476007)(66946007)(6916009)(26005)(66556008)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?dyE9FrPsEJ57B7MaZRjYS2gPJig2?= =?utf-8?q?O716SHa4dva8xOT0LPkKYEoy23aHjxifQqrf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Nz2QA38oE?= =?utf-8?q?BCwZZ8mtWft3qojZ7RtKc1J0tTlndgxla60nQbxQOqDSW+onGDZEDrVF1LpuDqGpk?= =?utf-8?q?pfR7rLCPJKXRJ6tAkSYIl94LMZjW5rlCm6NjBu6GA6NBblzHD97TQgugiFfGSd92M?= =?utf-8?q?/lT7WLcoHKnKv695aiixvzKWDn5upifi1f2NEVnSNuZy4kmP7ZNTsb7ubvvNpmuSk?= =?utf-8?q?oIgxXXPK3xEuAeuBeS5CA2X0TkW4nG/cQT/B/9in02TUavcAnBLboUYugPq1k7zBo?= =?utf-8?q?zM+JLQLxJPPH1JPdngx3tDczC0F5U1jjjOIufcpx7MO2smsrFF74AZCYpBiKR1gLb?= =?utf-8?q?kONLHAY6HvXq/4ypApLmA6r5iz7NkHXPukj6Gc1W9eXaiBIP7EE12LBZjZNuT3GuO?= =?utf-8?q?hHu4bgwKExObLt4jDGsywBVIkysEv4qeJjSB4Zy3rLmZdgrptykdI5qIsecH2z5Vw?= =?utf-8?q?5vm2q/CySc9ByhfCecNvGwJhfIG6CYpM3QdIDX6glPJDNMbH8LO0M1v4p8gWhWLKQ?= =?utf-8?q?f0paja0gNNfeu5ZAGHXlRycp057ZT4fsIj1y0qM3OWS6nCYJr+EPcp7RZIU6UUUgr?= =?utf-8?q?eVh9JTbBsb2m?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 09482840-8f91-4fc5-9f63-08dbeffdaac5 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2023 10:34:57.4683 (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: MO8lOy9zTZFWNXZUsmBa7A1ByF1CmiIAWUIBNtR8vITWKmwHb38zEP8cCE7JL+nRPhrSgQdClVzon1dgfAHfpQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8844 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/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; --- 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)), \ From patchwork Tue Nov 28 10:35:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13470951 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 8F7F5C4167B for ; Tue, 28 Nov 2023 10:35:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.642949.1002786 (Exim 4.92) (envelope-from ) id 1r7vRW-0002Hg-G7; Tue, 28 Nov 2023 10:35:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 642949.1002786; Tue, 28 Nov 2023 10:35:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r7vRW-0002HZ-DG; Tue, 28 Nov 2023 10:35:50 +0000 Received: by outflank-mailman (input) for mailman id 642949; Tue, 28 Nov 2023 10:35:49 +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 1r7vRV-0002HL-NJ for xen-devel@lists.xenproject.org; Tue, 28 Nov 2023 10:35:49 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2043.outbound.protection.outlook.com [40.107.7.43]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e511a115-8dd9-11ee-98e3-6d05b1d4d9a1; Tue, 28 Nov 2023 11:35:48 +0100 (CET) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AM9PR04MB8844.eurprd04.prod.outlook.com (2603:10a6:20b:40b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.22; Tue, 28 Nov 2023 10:35:19 +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.7046.015; Tue, 28 Nov 2023 10:35:19 +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: e511a115-8dd9-11ee-98e3-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nTY9VZ3FtFfNLLNf1tLwN6lFg/c1KOZELtmNav7n5bPB8zNgj43QoZN4oN4Ow0R52tG3Jmx2bCti4I3KmsO2JpmSciChaKNkbgqG1UwfYInDLVlt5XpE8B99r1Jw0DZU/auGqkLQ9Wsv/PrPDu8zJ2lvYBpZDN0OtCc6HoENnh8X7Pyu8KC8zs46eRSfUPxSASWapxWMxYyzDEYXTcTVe28ZHSs4rqRGU6Qj53FsIoJ0BNS4B1zP1qtaoGp9ScB+EZLhf2xtIf6E3WVh5BX4c2zgK26rS3PlF02xTlCoG80/+J9Vq8agkZlCAWP8LcYtmidqf3FV7zQIUArRsMDbAg== 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=a9/1l+ViIg+Ju3Vw0L1eHHvCH642HR7HZCOl2I/vlGY=; b=VyfwxxaoXlvKdU8n4BLRHyB6yvZkVY3i4bykJutSp/1Bs5aOylONNKN/H784IDk0jM00w2HlfWpXCt/OyYB2kE9S8AyeZCVH9lf7ARhImP2LEGnBQDaASVG7yv/QNohSjmB2ccbIAWrChNFfW6xqGynUMIDwtpyo5ds1FN4lTND3bZHy6K9VeKqQDtpqGoZF7sUufQrTOiiL2sZ+Z5wtdwioQClq27gDUPLRq6k9TVnzEVzJJvwC3Lz+d0+slPkXpa+nIXJZYSTsfYxdpS3D4SQ3JI8uiXmwFDKnPCzQEoY5iDfMqAaDvESy4uK0vq1qGtb1tLIwM4r+Ct5EhwGs8w== 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=a9/1l+ViIg+Ju3Vw0L1eHHvCH642HR7HZCOl2I/vlGY=; b=HQXjIyfaMYcgjy66AqnuSRACYplrEefhMlDjdjyAcUJdJ0CVu01mb9znvb9F+1F40N5mU5MmeA+sWxyxpc66nFrgRDSRpf8wFjMoKUsgMvNpl7gkrzLUGs3VInmxKJkH13/lvE6iMAhSrArHsrpcgxSdNwcHMxGEuNwqorPpuiOReNKvp2KiWc8MOReF2NzMUP62RrkYL61AQQZ6c1J9NHxqc8RGXS7rU6bo1jCxzuLJdBJsGomj8aufxKYjNU3PHQcPa+ocZJudLLzPRBFBF5++PP/LS4aRTQQg05fSCdoDwGEPU0QvSEhjncmBgVlTpBYp4+D9GvTUK7LWPdR6ug== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Tue, 28 Nov 2023 11:35:18 +0100 User-Agent: Mozilla Thunderbird Subject: [PATCH v3 4/6] 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: <49a17ffa-c873-4b0f-81ed-9587053ca159@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO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JuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <49a17ffa-c873-4b0f-81ed-9587053ca159@suse.com> X-ClientProxiedBy: FR4P281CA0444.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:c6::6) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AM9PR04MB8844:EE_ X-MS-Office365-Filtering-Correlation-Id: 4da09ffa-6143-47c3-4b43-08dbeffdb7be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iXNWD1FmDPjz0f923BEYB20iueGRpWcff9PlMURHPL2qBDeqNXU9ApeWDsirgWjHbIu7fDnXSK2BD/I2fGHR3/7YQFps9j1FpG5nG7zQ26mSlR+OKZDTah2uxC47IhUmt73qo6pZVPBqbwyMxxd6ghnHwLNPkG0tNj/v5I/qjM35t5/5irT75abEAqDYqDesCejxb4RsG+DIhsFrAwlkTjVkUITiGL/znAwqDGTBOOUVMFGTRtxfIR1RAXz4CJ6uIe7rCz5I7SMKa1uvpo7N8xzO0ucm3aX6SEkePLI0HfdUcUVwE89UeTIMnOo9NIyiOGtdH3wAceg/c3IT52tBG+8Q5ve/RculWIKeQSeXebWSLatWHNAF4+jHp2E6mgQMb9XGtAIZsJOiaN95O2f5RjSbZDszexolEX4G+CedBASTKcZU3eqjFkpMwlMWHI96uQfBkLdKVL0deyFqHZBI9NDDQg4BgjLC0EKaKl/Oox5n6OptwQlIJQ5sldfVH8j9cpt38vurOser4+3lKh1QW2vFvzLnu1qvw+8PonIOFHZwiezBoGRXKK0Tkf5Cwxg8EkpsDl1svzogP2jjJ3H3Fe3q0Bc5TscKtk5BX6bunOIowU39eNmKTUH2Q162+gWuSGhC3XcRQswqJ1yxsAsuOg== 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)(39860400002)(366004)(136003)(346002)(396003)(376002)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(31696002)(86362001)(2906002)(5660300002)(6512007)(31686004)(6506007)(8676002)(4326008)(41300700001)(8936002)(83380400001)(316002)(54906003)(38100700002)(36756003)(2616005)(478600001)(6486002)(66476007)(66946007)(6916009)(26005)(66556008)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?2rELOujsDiZM28r3J6siKLkebBEP?= =?utf-8?q?tUdT/VEM9zmE0iafYUJeSMwik8z1/8ez8fEUcZ5dXGergssVPi11gL5sJncZb/C75?= =?utf-8?q?RIGMgeygxNYEWI6QVvnGjt+ZElwDPvVM+guUoHY0TrNNs5wuFd7969ayS4+NfuwAL?= =?utf-8?q?SGahj3yq/9mMzqoPVHoTpDYhqQkNw03TIf/1C9RKELUwrflYSQ1sxIRkicUm1rnnh?= =?utf-8?q?n5kgynRDha0pKY70yrflYjVAinoYiHudddqB4+7cQvpvV19SEF9GK/ln9GB2Yqpks?= =?utf-8?q?qNDC/VGCxab6wbKUoFYGaXMiS7qyS8bhG2ifPixLhXiAy3l/2/CfgB6/Ls5i0sIXg?= =?utf-8?q?66KJD0s0zuorf8Txu09q8XiULcJqYBEWuPBJOhCffRQ0VtyFqq7rDIE+JYcxtYrIh?= =?utf-8?q?NqpOcXh2iQ815geNzuw6t77r8zf8r/82m13zTmstfVkEVReiDO/w1jmdRi0vTMh77?= =?utf-8?q?WPJCJ/Fmdj+Ub7vdEsIkT/IWNySW8cULVBL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YrwA+z6eHFyD7miwoC26dL37?= =?utf-8?q?rDMQe2vKfxv8d6ijeHO80nQEwmmDN31E6jT2K7CFX3pQQdMkIpdxeP/Y6+twIT64o?= =?utf-8?q?G0Ewe3EWvMXs2Aj9y9VovNRoJ1586UTJv8xFvxDgGmhEgvrciY8zF6ktacHrOJG/M?= =?utf-8?q?mlgQC5vy10m0?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4da09ffa-6143-47c3-4b43-08dbeffdb7be X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2023 10:35:19.2332 (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: D9dMEiegVL26VEHoGUtEuntx9NjLCoeimn1EkVE05YZZpP76j+78Lozx9QBQQRQZYtH6tvdnLpmfZ+Z2piXfqQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8844 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 Reviewed-by: Roger Pau Monné --- 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. --- v3: Slightly adjust two comments. Re-base over rename in earlier patch. 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_get_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; + * Xen prior to 4.19 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; /* unreachable sentinel */ s->gate = (i != 2); pit_load_count(pit, i, 0); } From patchwork Tue Nov 28 10:35:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13470952 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 83DF6C4167B for ; Tue, 28 Nov 2023 10:36:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.642950.1002797 (Exim 4.92) (envelope-from ) id 1r7vRY-0002dt-Ol; Tue, 28 Nov 2023 10:35:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 642950.1002797; Tue, 28 Nov 2023 10:35:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r7vRY-0002dm-LM; Tue, 28 Nov 2023 10:35:52 +0000 Received: by outflank-mailman (input) for mailman id 642950; Tue, 28 Nov 2023 10:35:51 +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 1r7vRX-0001eS-RM for xen-devel@lists.xenproject.org; Tue, 28 Nov 2023 10:35:51 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on20625.outbound.protection.outlook.com [2a01:111:f400:7d00::625]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e5e7f392-8dd9-11ee-9b0e-b553b5be7939; Tue, 28 Nov 2023 11:35:50 +0100 (CET) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AS8PR04MB7542.eurprd04.prod.outlook.com (2603:10a6:20b:299::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.21; Tue, 28 Nov 2023 10:35:47 +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.7046.015; Tue, 28 Nov 2023 10:35:47 +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: e5e7f392-8dd9-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FGeFkQQbLFFdgMdSho8eUSUNigoSxg9ObsTNc1LQ1RCbgSvaTD5L9x2Jm4JZt6Dw8aOqFWYXB92L0Hp3lRbEQjVsHdcw4G4z3XZkgwMhS10XXDng2PssWdbRng4MwOeq3aOUShuPXYR1jRS8CA6pSwxWiY3lEv9eH8tjmcjdf07MouPE5rqJVrQYJeaWcWDyoksdJFE8iL1/VN5Fr6ptdJDe+fvXy3ARO8xcFjO4IL6XE2M3WrwFDAoY5UriYqc+eDDPr1//8GzDGWYPVBxQp6/sCAEc66bRj6NVoHJbQyNcvE3NR2MKiXmIGZQtGhAYwbV3oLqrD+OCSi6hyLL5TQ== 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=oBwVLYxteBvFvzJ5zFgWT14OipIYNoUnky/Sn7smcA8=; b=ktWX6Ce66aMMDt5vKF+rO+byyM/9oe2B4gZKRQCMr3Zmn3/dZSsbXt6xBUvQTm2P1Jc7XiD3gK00w7uuUiPGEPLA2Qk2aGnA8WahZXWz/BfuK48hvsV3fjJ/dCti9X+iIb69IOT8hp8A1OVx7aXvpkdgUoXkr/QlOMcPr3eHf1y8q2fXg1IRi+dx2DmXwDazj1oa3XslHWtCxgtcEcrbblDkucHDT62xGVyXLzJ0GnbIY37+884qPq5YomRBBph4KDMEkeYEK3dj8YvOmmu/8HyIgAE47/lXgfl/GvQZg3dhewTkBK9kdjAua3g5U+YnYteWa7qqHFxEMSQQLiH9oQ== 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=oBwVLYxteBvFvzJ5zFgWT14OipIYNoUnky/Sn7smcA8=; b=VCVfNlkJqQSkL6IvZ5UrznDioBxMTzT5YwsJpomNi4SU2d8YTHSItW9FqccxnEn2FIuA3Zb6pjtBx7PY5k38La43GVZ1/paJH6DIqdW5H7O3jT0PZveJJ1X0k2YGfHFaWG1hJfss1hNWr8paHjaqac1mthhYNZHwUi+voqtJ9/N1JxquGe7T6a8fOwgICm695xCKoH08tTJZz228dumS21D1nPyRKYwAmbwPKtw2ZqxiEAN5wqJq771v0ppI4U3iRGmq+MgzE1suvBj9NQsyS2YsCsNP7jO/Ku2YEhSwgLI2x+YFPbezdZ1o8DG1wEwSLYbriojFsM7d47Vjkk2GBQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <09fc4c14-07e8-4e59-a23e-bb295125f25a@suse.com> Date: Tue, 28 Nov 2023 11:35:46 +0100 User-Agent: Mozilla Thunderbird Subject: [PATCH v3 5/6] x86/vPIC: vpic_elcr_mask() master bit 2 control 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: <49a17ffa-c873-4b0f-81ed-9587053ca159@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/8PTowm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UTLOOK.COM (2603:10a6:d10:c6::6) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AS8PR04MB7542:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f3085dd-4f66-4b88-8f68-08dbeffdc876 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GcPMZ77MdVEpY8j0NVIXvuz/ILe3um0x9FYqKLuKhpGnhvOvvHAtj6zakUK87qqHEIYH3mxn23OnpdBtWF8FLc3CdUu4gskSiCFtBg4S+pVWTOveAxr+1RKguiXXjBIjlk6WgivOZm3IFzUQ8T6zNwyHNbwgH4QHYy9uO5M2eZAAeITiZc3iyu+OCZknc2oFk0qN188gyY6PRLM4SmmWY11tYLowvA7L7fnNflVeJRYSg2nlTDCdBEqIrOWtNVhGqlG9dc65mRgBYt1I9Nh8hPVPxRLmpD7thg40QCkkSSAu8QPFhvMCd0y+Gouk7nMZoAo81oNzch8VZ2qNvYHuzKqryHL9DQAQg1zT/auPtB120mKCkdZ2scu17cgCJja4NjhAov0Z/KxtqWBx2wojSmZS2bXlTzGdDbPxfl49U3tW94tNDYV40+bSYGUUR5hdOh8Csv2BXIh7H2Wv5jAngqcsnlsAfMSWUZ3rsYbkFQmrHLn64ohp7FmoL0MgO975JWRtvdrCO1LxfJkjaWcUPtc3qFoNTcFQuK7/lsmhA70gWLflFHJnJq5f8hkFTapEn6me4RqRQ3kcImw8+k/bxLF+2a069nFt3ntYcaUusAJvyBoV6rr8VBxXDglFbZK7mvKphCvKVfNW1ha8Z+c3WQ== 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)(346002)(376002)(39860400002)(366004)(136003)(396003)(230922051799003)(1800799012)(451199024)(64100799003)(186009)(31696002)(86362001)(83380400001)(6506007)(26005)(6512007)(2616005)(31686004)(36756003)(38100700002)(316002)(54906003)(4326008)(6916009)(66476007)(66556008)(66946007)(478600001)(6486002)(5660300002)(2906002)(8936002)(41300700001)(8676002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?e74vv8j9uHTtvy7TWb6loFSeWf+V?= =?utf-8?q?a3Szdls5daf00VzLO6rPUSKQN5sQZ/6SnbU18ztqmxSpv7IJe2v6l65J6WE5juR4X?= =?utf-8?q?YeEOB7XeZ+vPsPXTmPtrTQcwarR4j2C9qho8G2BmbLRbPX/0+Mbb9OXiLfZlZbwkG?= =?utf-8?q?Szg53EaOIruYF0+vp8iVks2WY2/ecCcyZYvq5qUSk7Vvctpq5t0yqd9XgOoW3ZFs0?= =?utf-8?q?KVEki2vNiUNlKEDETccs/MZ7XhuPeCt/YRpGnpZEv5s1e4/Xfvy3Ugcs7LpNXbDrZ?= =?utf-8?q?BHsvV6QPggpLN9T0S5Xp0JM+ajenc06yrr88Ibw3ePAt5DJ0ivLQD6Xtu5f8vkPVm?= =?utf-8?q?KPOtWyzKx2Ce+IOztKfmP3ZjsO6Ezh9ntBRdKWoh/9alLIpSOrpmRisgp8iJXBIyZ?= =?utf-8?q?QkuH+jM4aLIxZIhbS4H6MPpqzVC5nzXVUq37MCropqtuLSC9NnLp7aOR98bhMXmEL?= =?utf-8?q?h4R8Ol4EvQwP0guil3DREHsXE9UMer99r0KKZH+MBQyD+6QDf3WssR0yVb9Yog0LZ?= =?utf-8?q?P3gRZct3cyUnE+Jav6m6D2wwMuWp/601JCYJU91jx6XNLcvvdzUHn1Z8MdKgz8kDr?= =?utf-8?q?wxyAB7m6ipDNl2x/0KpG37pViHreRxxcoCDD4GFDbEhozJ4XCRf8x/as/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4znpCr/2?= =?utf-8?q?LER4DFbZP1TG?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1f3085dd-4f66-4b88-8f68-08dbeffdc876 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2023 10:35:47.3135 (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: rjF7BD+Ezlv/OduflxeWaBcQrP+fLq1nI2B9/zfvPLjiHCMBMcJmWWGo6/nf8Fvu3l8/SqgmlNDWdkkbOI8Y0w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7542 Master bit 2 is treated specially: We force it set, but we don't expose the bit being set to the guest. While right now the read and write handling can easily use the fixed mask, the restore input checking that is about to be put in place wants to use the inverted mask to prove that no bits are unduly set. That will require master bit 2 to be set. Otoh the read path requires the bit to be clear (the bit can have either value for the use on the write path). Hence allow use sites control over that bit. Signed-off-by: Jan Beulich Reviewed-by: Roger Pau Monné --- v3: New, split from larger patch. --- I'm certainly open to naming suggestions for the new macro parameter. "mb2" can certainly be misleading as to Multiboot 2. Yet "master_bit_2" it too long for my taste, not the least because of the macro then needing to be split across lines. --- a/xen/arch/x86/hvm/vpic.c +++ b/xen/arch/x86/hvm/vpic.c @@ -41,7 +41,7 @@ #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 From patchwork Tue Nov 28 10:36:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13470953 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 37475C07E98 for ; Tue, 28 Nov 2023 10:36:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.642954.1002807 (Exim 4.92) (envelope-from ) id 1r7vSR-0003pA-1S; Tue, 28 Nov 2023 10:36:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 642954.1002807; Tue, 28 Nov 2023 10:36:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r7vSQ-0003p1-V0; Tue, 28 Nov 2023 10:36:46 +0000 Received: by outflank-mailman (input) for mailman id 642954; Tue, 28 Nov 2023 10:36:45 +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 1r7vSP-0003ol-SY for xen-devel@lists.xenproject.org; Tue, 28 Nov 2023 10:36:45 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20610.outbound.protection.outlook.com [2a01:111:f400:7e1b::610]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 05fdd8b3-8dda-11ee-9b0e-b553b5be7939; Tue, 28 Nov 2023 11:36:44 +0100 (CET) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AM8PR04MB7892.eurprd04.prod.outlook.com (2603:10a6:20b:235::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.21; Tue, 28 Nov 2023 10:36: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.7046.015; Tue, 28 Nov 2023 10:36:41 +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: 05fdd8b3-8dda-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cT615HDANPn3mdWsUtz3g1EaauoOW+DPjRwzVYNhnaWXIHbAImkYdoZjoTsa2XhNfddQd515nc0Q96UH38vuj3SIuyo6zH2a0o21+8X5hgE/v3yrx/EW4QGPUfTt7kOsy/igzr2BOWFRwmhe1J6Qpk+KhawkcPs5n8f7OIwxnPzYueWYuYdNpJn/mhIve5Gy3AhGXDw+TG2i7+17yTCk2tuUwKw4S4BO1u1NrpGLz+ffQP+s1md6MTBDwzH0x5tgw6JiBjKGAoHN1pXxxlo/b23VfAvmaHPc0Qa5QvNVK0jdWsCPH24VYm8W5c25SM0FyhRWQW9zIinZE0D77TIGSQ== 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=ZxXDsWRhWG5TXSiUXqk5nLYM1a+YTnq7opN/8DGS2lo=; b=A0P8peg6bUhEtZykludjwbjmslSWYv0xMyXiQoUvuU4yJRMctDecgKKNxcbW5oupA/rwaWifbTm0PvzpAlpQtuP6NIS9U8/vf6vqBUf75SZSpnFroFelSEGERjGjhTXMFtZlSK2BMG3BVOQdo5HMydpiFncbD+TEarlDAIpFgTjbJ7nmCmLUEHvNJ1varFICmtS1ErjFyNP+RUG1tHsyceOWEo4AwzFE9lrtaQWZIAPMw5hOj780AddWTVGUzPxsqmHlICj7gAbqTFGDs91959td0zPUPRRZz9V8IWndHD0KtlHZ/iT/7oiTTZpgYYsGC2/EAv11B7B+n9TayUF0jQ== 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=ZxXDsWRhWG5TXSiUXqk5nLYM1a+YTnq7opN/8DGS2lo=; b=ALGj4jRuLzq9w3KcVOMqAy3jGMS2xmRKELBXyciDCo31KS/ozS4peQsK/SeSwQIeprhJS+RemJQUjmFM6PnRuTAH5Fi1FOdr1IklQypzxCXibVPvdZach4umMt/dJmPsvQMvEcnkZGn1ArRMMLmAgXn2yAbyAhL4BwBjaviDLHsY8ztHeGQtNW3+3yItr6LZdiQzMhURMmOOviekNXMKd4c0Tb4Nyb53k+19aGCofkbgbH+Tr0mrQOb/FpN4Uk5bt0H6ovW1o9DTSntNVF3HWdLXnhKAIQnv8Y8st/eXBRs0sNHnngoRgRjCY5E7eh8M/0UMEcWqYoOxMJKQ0JyoGA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: Date: Tue, 28 Nov 2023 11:36:40 +0100 User-Agent: Mozilla Thunderbird Subject: [PATCH v3 6/6] 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: <49a17ffa-c873-4b0f-81ed-9587053ca159@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: <49a17ffa-c873-4b0f-81ed-9587053ca159@suse.com> X-ClientProxiedBy: FR4P281CA0444.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:c6::6) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AM8PR04MB7892:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e40b020-7622-4de2-c072-08dbeffde84f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fs0WfHSwTMpyNTTumCgBL7cXvsG5OSBRWxqeYD9+8cUvBpP7RPRUr7Y7tgykRUNaJaHxyUwNvaTVZTK4zfK2matm3zJCkbe8rudej8j4Jbb2nRyrxbZwQ7Pjsm6brM0KNmjuHRrE/FHhvmltCEf2VXz8Y7Ni1+vJ1eamItPp5OMO0SkEnthTGAEmIdmTC2Su6ccHw0te3WDu/vAs0ZM/wwOnIgIoEH4KW05Av/wdruWgzTAEbDVn4sAhtjbJTYU1oxamIg0xPxtrE7K6OabBYHyz/dYeSe4gowbVUtfhJX0UHqDFBFWLY9RR95+zDNo2KTGIfG0+nYJCoGjHDc0Zi3ifjBZJ0p7/w0w1i8QNz/ZktdUsyBxgw12XsgR+GEU7C5fh1VPJBDuWJ73ub3d1hNKofNxsKJ54TwaH0DooQC2nut7EhiG2fJRcsnIwuW0zzspyfZIrLsPhdAV+z2VNvDFCUWOGGyuOa8M0FBWM1ajOpJ+owHty2Q8Zjj+PjSvhnBUWiGdCWsj9dMlS1MeyryWvmrM3LAfT9SKZbBXDcio2y9lLICz+m5dK1iM0STqaeWa4WGC5P3as6N4A86Jv0K0nvQc0Sxv0hNHICHQOI9rsqN/Bn1mbiPd76yetviBrmhBgUknvN3coGUxwyw5HjA== 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)(376002)(346002)(396003)(39860400002)(366004)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(26005)(83380400001)(38100700002)(31686004)(6512007)(6506007)(8936002)(66946007)(4326008)(6916009)(316002)(66556008)(54906003)(66476007)(5660300002)(31696002)(478600001)(8676002)(6486002)(86362001)(2906002)(41300700001)(36756003)(2616005)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?bDaX3H7VbIWOrNkpPj1QJv0JL/4n?= =?utf-8?q?6dMl0X27vi2quzGTGoiHnyQEC+wCZao/ZJLPgSSUx9p1qA5kMf4fe4WEnu9jD84jM?= =?utf-8?q?WVz+pHGHwAEKpvF3kKL1AaPgXcpCx1ZrqKFwVUczTcZ+c0zYZD/iCGoENyzRk2snq?= =?utf-8?q?ADI76deaTnLxEEEaLmvuVmYMersNl4yvCtSlTYQycUC6DSfb5atgrc3MTdicE3zUW?= =?utf-8?q?zich3EiPS8ceWdpkO/j3EhjUTTbITC+HEsM4y0NOU8R7daowWS9xx8a9cZgfrihYr?= =?utf-8?q?uYI+CxdxOWlVLAikYkJRFJH7ZKAoCIiCz8M9x8r+DHx2OqnI8SbWbcKPRW/EDGcVG?= =?utf-8?q?8BuSgNJ7EXACdoHIyoyXmmpH3EtJCNvNHAEkPOreGbBg0K5dI0drxTmUS2P3BBRRU?= =?utf-8?q?ebLotVDystWzlE2XApJyO35443+XM0vwlWBYPR6UafG7RYGzPuIYtulXZFjoYWmor?= =?utf-8?q?RW4RiALRiDZVmspM64M/BE9gCxHou1DdkIMTW3yu+gWhLg/WLqIUFVJybvaduegiN?= =?utf-8?q?i11mxcEPLrv3fiyaAx4yPu330oKNcn4tG990hflrZv6nmNVYTKGKR5n/IG0XKZoaA?= =?utf-8?q?AM6xiJOKD+A+H6orQjHoUlQShqVnBYt9uttpH1ri7DoYVK7Rdc3pQn2GTj2eLISWs?= =?utf-8?q?6WYbgEMsuizQ5lXFlGoCKE4uF8Os0PtgWKQ/xl6I/kUEuNVYnb1JDpLi5ed5eQ6uD?= =?utf-8?q?X9sv2OSQtM4jCEXGAxOac7i4lxOCf8MIOuLPKvjlGaJJmZmhM40veuMOsJS+4j0w+?= =?utf-8?q?U63BkOjpV7Smy+O/54irkDwZfT0m7+TkYa1sHn3EiRg/sxpDFNKfaEW5nrYW2okIs?= =?utf-8?q?3Dy+sV4ysgMz3MvQFVHXIp6PubRvOrTKOPvv2uLGBw6UU0dphYCGsGOFxYK5f9RI9?= =?utf-8?q?ukv7K8Mlb/hMuekbu972O/ib+JtL658nv8iE4o5WNiBd1fwPF/y0b35VPK0R3C1CX?= =?utf-8?q?8H0XSrjNg0dgOvl8/qMBbdT+i+T62Ijp7FvmbuUUPRBxwVWgxEpiPTf9dWGpiEPOd?= =?utf-8?q?akzlPy20q5H9fwS6GK2Jemnu2rSqivld7fdA5HIbmIsO+UDH3TWBPF4TaQQpd0Tnq?= =?utf-8?q?IgDolJRDsq1ueXXzSeZT3zFTs+u9bGg8AymT/TEsmmmp1B9GO+siOxqifbf263v7X?= =?utf-8?q?DmC4oiXt4UpNH6HSiJui1Y3iVjfSZDRU4g52AruwNzteQpJA3kqeUV/VKw0wSaMj1?= =?utf-8?q?fl9HRA/QzOd3KmbPM2in5wRDuj7izqOOpdxZc5igDgFmC/vzTV4gXXRCZ7C7H+iXF?= =?utf-8?q?ZXIoKju9ieULuSz6V/lVHbT1wsd43UTj+nQ2BBA1H9Hx7/BOTGFUUFO6Gz4pIfc4R?= =?utf-8?q?O23cUkxgSmoAagkvE+Bq9oC4/tTi/Mb2pOTAZ/UbEhWNZP3rn7T+L/n2IxoDpljOk?= =?utf-8?q?hloyPCgExd95T98HOQV7v/DRJLzSc50u/SAjibrO+QZN4kCHkihuQe+V2FkKQqi7l?= =?utf-8?q?N+G559BnaNbs5KO+TUViRa+SvMOcNUButGMlzerJdEYvJWupOfbrWjypeHebOLKB4?= =?utf-8?q?MvdzrTEDUYHi?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e40b020-7622-4de2-c072-08dbeffde84f X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2023 10:36:40.7588 (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: L5EnIh3MsUZSSz/L8/eIWH0EyG147F93wT+I8bqmdoWUcsW99fSjWEl61hU1cz3LOboppz7hy5BW6s7Kb+BdUQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7892 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. Move the instance range check as well, leaving just an assertion in the load handler. Signed-off-by: Jan Beulich Reviewed-by: Roger Pau Monné --- v3: vpic_domain() fix and vpic_elcr_mask() adjustment split out. Re-base over rename in earlier patch. 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 @@ -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_get_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) {