From patchwork Mon Dec 18 14:39:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13497055 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 31BC6C46CD3 for ; Mon, 18 Dec 2023 14:40:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.656062.1023993 (Exim 4.92) (envelope-from ) id 1rFEmn-0001hj-1b; Mon, 18 Dec 2023 14:40:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 656062.1023993; Mon, 18 Dec 2023 14:40:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFEmm-0001hc-UH; Mon, 18 Dec 2023 14:40:00 +0000 Received: by outflank-mailman (input) for mailman id 656062; Mon, 18 Dec 2023 14:39:59 +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 1rFEml-0001hV-BS for xen-devel@lists.xenproject.org; Mon, 18 Dec 2023 14:39:59 +0000 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [2a00:1450:4864:20::333]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 504a794c-9db3-11ee-9b0f-b553b5be7939; Mon, 18 Dec 2023 15:39:56 +0100 (CET) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40c580ba223so39062195e9.3 for ; Mon, 18 Dec 2023 06:39:56 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id v9-20020a05600c470900b0040c4acaa4bfsm31329915wmo.19.2023.12.18.06.39.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Dec 2023 06:39:55 -0800 (PST) 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: 504a794c-9db3-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1702910396; x=1703515196; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=Lh1hl9sCcsQ2pc/dsi+OGUNJGqlfdDZuQfx1cyY8ztI=; b=dJu4DqehkFmfTtyrrANOa130oxlVefZStc6cpJB7gW/bsepqkRijK6NqYLCaRHS9Wj B172F0A0qZLe01VqRUXTE0aT3w9dPqv1geNeps3AkUYZjzVPR6SopnlwxRqWx+6wi4ar AATC0oshXaO2Ll/0DeVe7ZoJNPQ6i5AWYpjD/Gm5ovGNfgR5kFYzL7K4cKv38Qugskoy MwaRWKmtmek4vfLXlAXgMlDp6IBz+G6j2PhI84O9aXI6Odzcv8y/Nh3XrZncZS0y9qA+ QElfHg903KOmRmPh23/Z4yraHkwkgMLOmfWAkCRbMRmbiK9x5EmXOcyyWp5txVjB4EV4 PwIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702910396; x=1703515196; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Lh1hl9sCcsQ2pc/dsi+OGUNJGqlfdDZuQfx1cyY8ztI=; b=ICTAfwYX148f0AV70D2hYWxgbjcfT6W43pLWWAYRl2fWtD2UYrbOJ6Su8HWm4JtdDq Vz70haLrYbCA4nYLkQ5LDomoptt4Rs2zz3jemUqr1lXvrmnMHKRCIP3bcjRx93uIcYHO /X+x1oBNnnsZsKtxgwHxnebQ8578C2F7hnXsdp8wNjjfguyqEv0R0vNsB1niU30tclB9 8th6Eibz+jRsgz+7Gd2r0KVSHvT+y8RB55dufaH5Aa6roXut6ur9A3VfNqc22XeVspva Yd8tovfO47ejD3ULPmMLo3jWl29ZrxQYyyIehGQfReUxRHkuvM04i2o2Ty/5cgqn3Sh/ P23A== X-Gm-Message-State: AOJu0YxEawBIPlrsLyV50zyWBn9vrpX8wYLEFOmvIfUFhVpo1euG/seD NaS/KseXzkPnp2wcHFXqXmaHJdDletrh0aIgu5ms X-Google-Smtp-Source: AGHT+IHVZs15/+OWblOreD2gWeNcEqRPITzOD3Nw9dnkYmZw3AoRm9ZBHpc1U0YnS53rESzeLQLXew== X-Received: by 2002:a05:600c:4f56:b0:40c:6a42:c60b with SMTP id m22-20020a05600c4f5600b0040c6a42c60bmr3386796wmq.187.1702910396284; Mon, 18 Dec 2023 06:39:56 -0800 (PST) Message-ID: <05e69eea-79cc-4b3c-861b-855fa67c878a@suse.com> Date: Mon, 18 Dec 2023 15:39:55 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 1/5] x86/HVM: split restore state checking from state loading From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= References: <1e855575-8c0f-4222-80ba-e64305ea714b@suse.com> Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/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8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <1e855575-8c0f-4222-80ba-e64305ea714b@suse.com> ..., 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 "real" hvm_load() is accompanied with a "checking" one. 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 --- Now that this re-arranges hvm_load() anyway, wouldn't it be better to down the vCPU-s ahead of calling arch_hvm_load() (which is now easy to arrange for)? 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[]). --- v4: Fold hvm_check() into hvm_load(). v2: New. --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -379,8 +379,12 @@ long arch_do_domctl( if ( copy_from_guest(c.data, domctl->u.hvmcontext.buffer, c.size) != 0 ) goto sethvmcontext_out; + ret = hvm_load(d, false, &c); + if ( ret ) + goto sethvmcontext_out; + domain_pause(d); - ret = hvm_load(d, &c); + ret = hvm_load(d, true, &c); domain_unpause(d); sethvmcontext_out: --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -5397,7 +5397,7 @@ int hvm_copy_context_and_params(struct d } c.cur = 0; - rc = hvm_load(dst, &c); + rc = hvm_load(dst, true, &c); out: vfree(c.data); --- 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,12 +281,10 @@ int hvm_save(struct domain *d, hvm_domai return 0; } -int hvm_load(struct domain *d, hvm_domain_context_t *h) +int hvm_load(struct domain *d, bool real, hvm_domain_context_t *h) { const struct hvm_save_header *hdr; struct hvm_save_descriptor *desc; - hvm_load_handler handler; - struct vcpu *v; int rc; if ( d->is_dying ) @@ -291,50 +295,91 @@ int hvm_load(struct domain *d, hvm_domai if ( !hdr ) return -ENODATA; - rc = arch_hvm_load(d, hdr); - if ( rc ) - return rc; + rc = arch_hvm_check(d, hdr); + if ( real ) + { + struct vcpu *v; + + ASSERT(!rc); + arch_hvm_load(d, hdr); - /* Down all the vcpus: we only re-enable the ones that had state saved. */ - for_each_vcpu(d, v) - if ( !test_and_set_bit(_VPF_down, &v->pause_flags) ) - vcpu_sleep_nosync(v); + /* + * Down all the vcpus: we only re-enable the ones that had state + * saved. + */ + for_each_vcpu(d, v) + if ( !test_and_set_bit(_VPF_down, &v->pause_flags) ) + vcpu_sleep_nosync(v); + } + else if ( rc ) + return rc; for ( ; ; ) { + const char *name; + hvm_load_handler load; + 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(!real); return -ENODATA; } /* Read the typecode of the next entry and check for the end-marker */ desc = (struct hvm_save_descriptor *)(&h->data[h->cur]); - if ( desc->typecode == 0 ) + if ( desc->typecode == HVM_SAVE_CODE(END) ) + { + /* Reset cursor for hvm_load(, true, ). */ + if ( !real ) + h->cur = 0; return 0; + } /* Find the handler for this entry */ - if ( (desc->typecode > HVM_SAVE_CODE_MAX) || - ((handler = hvm_sr_handlers[desc->typecode].load) == NULL) ) + if ( desc->typecode >= ARRAY_SIZE(hvm_sr_handlers) || + !(name = hvm_sr_handlers[desc->typecode].name) || + !(load = hvm_sr_handlers[desc->typecode].load) ) { printk(XENLOG_G_ERR "HVM%d restore: unknown entry typecode %u\n", d->domain_id, desc->typecode); + ASSERT(!real); return -EINVAL; } - /* Load the entry */ - printk(XENLOG_G_INFO "HVM%d restore: %s %"PRIu16"\n", d->domain_id, - hvm_sr_handlers[desc->typecode].name, desc->instance); - rc = handler(d, h); + if ( real ) + { + /* Load the entry */ + printk(XENLOG_G_INFO "HVM restore %pd: %s %"PRIu16"\n", d, + name, desc->instance); + rc = load(d, h); + } + else + { + /* Check the entry. */ + hvm_check_handler check = hvm_sr_handlers[desc->typecode].check; + + if ( !check ) + { + if ( desc->length > h->size - h->cur - sizeof(*desc) ) + return -ENODATA; + h->cur += sizeof(*desc) + desc->length; + rc = 0; + } + else + rc = check(d, h); + } + if ( rc ) { - printk(XENLOG_G_ERR "HVM%d restore: failed to load entry %u/%u rc %d\n", - d->domain_id, desc->typecode, desc->instance, rc); + printk(XENLOG_G_ERR "HVM restore %pd: failed to %s %s:%u rc %d\n", + d, real ? "load" : "check", name, desc->instance, rc); return rc; } + process_pending_softirqs(); } --- 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,6 @@ 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_load(struct domain *d, hvm_domain_context_t *h); +int hvm_load(struct domain *d, bool real, hvm_domain_context_t *h); #endif /* __XEN_HVM_SAVE_H__ */ From patchwork Mon Dec 18 14:40:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13497056 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 AB18FC35274 for ; Mon, 18 Dec 2023 14:40:31 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.656063.1024004 (Exim 4.92) (envelope-from ) id 1rFEn6-0002v3-Ay; Mon, 18 Dec 2023 14:40:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 656063.1024004; Mon, 18 Dec 2023 14:40:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFEn6-0002us-7X; Mon, 18 Dec 2023 14:40:20 +0000 Received: by outflank-mailman (input) for mailman id 656063; Mon, 18 Dec 2023 14:40:18 +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 1rFEn4-0001hV-Kv for xen-devel@lists.xenproject.org; Mon, 18 Dec 2023 14:40:18 +0000 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [2a00:1450:4864:20::335]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5bfc2054-9db3-11ee-9b0f-b553b5be7939; Mon, 18 Dec 2023 15:40:16 +0100 (CET) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40c31f18274so39447275e9.0 for ; Mon, 18 Dec 2023 06:40:16 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id v9-20020a05600c470900b0040c4acaa4bfsm31329915wmo.19.2023.12.18.06.40.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Dec 2023 06:40:15 -0800 (PST) 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: 5bfc2054-9db3-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1702910416; x=1703515216; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=4DiAqokvVXPd3MpiYleSixbq9Tt+MTQdnErWjsgoNBk=; b=Fy1I60LwA5NUhDj+BRYKoXo+Y1L6EeLzM57ehmrzrR5exZWfakOfuy2FDPVmuyamVh PCS3ZjH8DK6RLluIXVmefpTT2Y1GlbwtfVG654Z7AS+HHf4XPNOrTJyF35qa5ppsDel4 WHa8PfR2YCfw80EKJDkei6ud4rJ/YzGG1JyYou0o2Opt8bkX2GmKG3HgXol6QTKb8Eix KSlBi/4craO4PllucAkc+6h7IDM3k0cQSLktvpZXlJB4DIpsAojA5sM2NAwiD+QPUoEH /zYecECT1RBeN1Nz7vQE3hc1zl1MYt7Xmo/Y8ByaQTT9dM3YlGBqTlRiqN+fXl1MXaAg 0LWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702910416; x=1703515216; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4DiAqokvVXPd3MpiYleSixbq9Tt+MTQdnErWjsgoNBk=; b=Jti+uhj1QnWba+v1BV/ZsMQJ4ZLU5zVp9OB4b8OueEaIYRIIJ72jPW4vII/3GpvxIX 2x6M96bhQmal0h71op+lWn9AUhS/mBUZbLRQ8q7D3ur/82gAX/RkJFFy1t4Y/Qm+W6zO aZzWWgP4LDGP4l4H9bIya0LXot5eqpApKZQ4QkmuSnjGvDmucbRikQThWm3HuDK1g5p+ 81Q3iOM02uHTxBk6YoHaGLVB9rLi0zEUkJS3+SKIeMh9iG+ZjJPBx3bHUU472L5eyM/Z 8+7xDlznGwK34R1MwTcki7jOJWnj4i4aDYf1ywxmtyEPituayCCWcF08jH2p19UiFa9q M/2A== X-Gm-Message-State: AOJu0YwrDVtgNnZAshdwwAnATGjFqVL49r5zlcY8BR8HiBQgt1DiPvpj DNSCANX1IfeTRa8InCcs8DS09lQd0kj/9CKd8CVc X-Google-Smtp-Source: AGHT+IFMLpzKTNORPRPFLBDCtaO+CZBNJmfJ5d+xy3Kd9QX0KblH5lsAi7/62hsZEtGlNqIpHkMQng== X-Received: by 2002:a05:600c:4e8d:b0:401:b6f6:d90c with SMTP id f13-20020a05600c4e8d00b00401b6f6d90cmr7854855wmq.35.1702910415796; Mon, 18 Dec 2023 06:40:15 -0800 (PST) Message-ID: <4ed8bbd2-f893-4c12-b804-2df56d55209e@suse.com> Date: Mon, 18 Dec 2023 15:40:15 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 2/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?= References: <1e855575-8c0f-4222-80ba-e64305ea714b@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ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ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <1e855575-8c0f-4222-80ba-e64305ea714b@suse.com> 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 @@ -1617,9 +1617,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 Mon Dec 18 14:40:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13497057 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 B645EC35274 for ; Mon, 18 Dec 2023 14:40:46 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.656066.1024013 (Exim 4.92) (envelope-from ) id 1rFEnN-0003Sp-I1; Mon, 18 Dec 2023 14:40:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 656066.1024013; Mon, 18 Dec 2023 14:40:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFEnN-0003Si-F9; Mon, 18 Dec 2023 14:40:37 +0000 Received: by outflank-mailman (input) for mailman id 656066; Mon, 18 Dec 2023 14:40:36 +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 1rFEnM-0003LJ-Ek for xen-devel@lists.xenproject.org; Mon, 18 Dec 2023 14:40:36 +0000 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [2a00:1450:4864:20::329]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 67750d39-9db3-11ee-98eb-6d05b1d4d9a1; Mon, 18 Dec 2023 15:40:35 +0100 (CET) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40c256ffdbcso37433805e9.2 for ; Mon, 18 Dec 2023 06:40:35 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id v9-20020a05600c470900b0040c4acaa4bfsm31329915wmo.19.2023.12.18.06.40.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Dec 2023 06:40:34 -0800 (PST) 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: 67750d39-9db3-11ee-98eb-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1702910435; x=1703515235; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=ZlEogBHJ42bqKdVld3OnXFEdms3+g1R9Ku2xVNYGcew=; b=gZrgDnmAwawg3irOr18KAp9h+dD4j3JiSPgde5BxZI8h6dhs6I6Po1mtpOibzAQXKq bArCBImfhYBbkNatGuevwG2iFC15eEERp4xuTstRm5ufdqIXB6dYIb8Ro7ZHdpzbNGB3 BID3fgfU3XN4Qk8O3+AZKSWXHcZgSxJ9LYSTsrDUJ3xkdR335+0gENcm+MEKczPV/Q49 jpV4qPQ0y3353jHY0MrqMg4xo2W6pQKdOM0VMoFY5BPUb4lErITT3mUorAwZHmNkc7BY GK34vIKTkppuAzaMCEPs7SMPri6aHrxMUdAC9CVbq6M5IOdH2m1AhcScR0W5pBs8DGP/ T74Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702910435; x=1703515235; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZlEogBHJ42bqKdVld3OnXFEdms3+g1R9Ku2xVNYGcew=; b=QtNOOS46HVnzbpL9SKmtBggep4Kz7NUsMFlxaavj7VWEYSCLZOPrie3ILDxKIS/C3I 1i4/pjudPIQou96nA78kGKSuwXm3796xrWt5rzrZXvCFGwEoZxriVMVeh5i2udXZwIyj PhTU0fBDj8536ieLbVC8NpQKcqOtjshbqY262n6GP/FFrbDqClANTUprABaOvaKsYc2/ Ox2uvJ27miGcI2LZQd/3hL1qPhfLFVe/BmWFq71PS8swAfxrqsyFoH9bckd/jZHfP7jq +7OmdazR5ICV2sRPpj/ksjWRKYMI9Ppik8ZUt6eJmxshVTOH55z28QNSVhbzepVaWiTw t/fQ== X-Gm-Message-State: AOJu0Yw/uooAv+uTRATKbVVlhNHPg8Cl1QB8A3dUSti2niH0/wfGNIIH pAjtdtO+8thvyuEfsnChBu2KI2uG7YGuH0HtvnD2 X-Google-Smtp-Source: AGHT+IEhltKV7HXRK7qqDP6DCXQOLNvBF2soPdud5P371fCtyDZ4MAsc1yR8Nze4nLgdwVHGL3VMiQ== X-Received: by 2002:a05:600c:35d3:b0:40d:18ee:1d08 with SMTP id r19-20020a05600c35d300b0040d18ee1d08mr883863wmq.138.1702910434890; Mon, 18 Dec 2023 06:40:34 -0800 (PST) Message-ID: <160696b3-13ff-4b4e-99ec-3d926a3c0be8@suse.com> Date: Mon, 18 Dec 2023 15:40:34 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 3/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: <1e855575-8c0f-4222-80ba-e64305ea714b@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: <1e855575-8c0f-4222-80ba-e64305ea714b@suse.com> 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 Mon Dec 18 14:40:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13497058 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 B65BCC35274 for ; Mon, 18 Dec 2023 14:41:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.656068.1024023 (Exim 4.92) (envelope-from ) id 1rFEng-00049G-UR; Mon, 18 Dec 2023 14:40:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 656068.1024023; Mon, 18 Dec 2023 14:40:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFEng-000496-Rn; Mon, 18 Dec 2023 14:40:56 +0000 Received: by outflank-mailman (input) for mailman id 656068; Mon, 18 Dec 2023 14:40:55 +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 1rFEnf-00048G-8T for xen-devel@lists.xenproject.org; Mon, 18 Dec 2023 14:40:55 +0000 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [2a00:1450:4864:20::333]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 71c86c98-9db3-11ee-9b0f-b553b5be7939; Mon, 18 Dec 2023 15:40:53 +0100 (CET) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40c3fe6c1b5so34652435e9.2 for ; Mon, 18 Dec 2023 06:40:53 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id v9-20020a05600c470900b0040c4acaa4bfsm31329915wmo.19.2023.12.18.06.40.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Dec 2023 06:40:52 -0800 (PST) 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: 71c86c98-9db3-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1702910452; x=1703515252; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=ymXg0bpmFz+1mXkWwxvgqG3wuNIkNAkO2q/Jn5XmZJc=; b=ZCYQm2n0QmuJkA1KAHqAgTPpY9OfnV0NWGiRWFZvjmelZxG+Yn0bqX86wyqon5La4j JnEgc3idnjOCqHQbJPr5v0OdZc/I8mUxQT2Vjo/5FfJtcCCCmPE21g77DIahjM0zj1uq RATUnBYhX9UfLBMhxUTaUlA+PXoBwzdjTE/gWvpiEpjuhd/kAQkevD53po4/sgZHMf5k qyrUALjWBKwoQCVe0+8XV6RpyWZb4vgblgYnp41Jdl4yckqyfcREpUOwzcD2z31GoSSp 3TkezJIUh2DFrA01WPVdzu5r4XZlZkxHYR04M1HljKDQr5F97fxQ1AmYBmZ/KkCUrFYA EHxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702910452; x=1703515252; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ymXg0bpmFz+1mXkWwxvgqG3wuNIkNAkO2q/Jn5XmZJc=; b=UjT1rA1PA3HKuc7EUE7+KciYZiYkRqKQh6d+N0FwmhjRJM71JvuUIgQNPtWrU0/7eV zotmR7Ohg1gO12BVc9XfPr3Yn6+JF4fUrh2H6TZSgXVINhvchDgCAv/BsqTAUIzxMj9m sPpS6ZArL5udMdEnvRWNKW8ITIiiTAhVfdoYi0Mr3Jg2rDP3SVuiibxIGfoTvOSA6fxD /CTQua69f8BMHFsbqHykEoNf2c3p1blCk/Jm9BQKOVw1L3xpio1loPrcKMnpnfzMmYoF dpYbv5leGqgF4YmlQ7YZp0srMM/VuJCDdgpS13oUAdinj6hlltY/Sxt5fr1BZyZfykfz 0qNA== X-Gm-Message-State: AOJu0YyAAu9bp0q4GEpNiMJMSByMnNBSt+tneH3gSGVFWztSwFqHhA8u XaLvqCktyg/EKnQP7yGsUIYW9NyZ9hoYfUVh4Z4M X-Google-Smtp-Source: AGHT+IENCFbPhDWDJ3O0ULNCi2CFlhIgp2QC7so5i0AAfbe74adx52KuOILEZGhet3fdRhlvc10odA== X-Received: by 2002:a05:600c:1715:b0:40c:2bfa:fb03 with SMTP id c21-20020a05600c171500b0040c2bfafb03mr8060780wmn.72.1702910452441; Mon, 18 Dec 2023 06:40:52 -0800 (PST) Message-ID: <9ab115f2-04c6-443f-95f1-581b2889b08f@suse.com> Date: Mon, 18 Dec 2023 15:40:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 4/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: <1e855575-8c0f-4222-80ba-e64305ea714b@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s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1e855575-8c0f-4222-80ba-e64305ea714b@suse.com> 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) { From patchwork Mon Dec 18 14:41:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13497059 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 75C13C35274 for ; Mon, 18 Dec 2023 14:41:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.656072.1024033 (Exim 4.92) (envelope-from ) id 1rFEo2-0004qx-5j; Mon, 18 Dec 2023 14:41:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 656072.1024033; Mon, 18 Dec 2023 14:41:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFEo2-0004qq-2o; Mon, 18 Dec 2023 14:41:18 +0000 Received: by outflank-mailman (input) for mailman id 656072; Mon, 18 Dec 2023 14:41:16 +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 1rFEo0-0003LJ-8S for xen-devel@lists.xenproject.org; Mon, 18 Dec 2023 14:41:16 +0000 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [2a00:1450:4864:20::32c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7f5c899e-9db3-11ee-98eb-6d05b1d4d9a1; Mon, 18 Dec 2023 15:41:15 +0100 (CET) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-40b5155e154so39167485e9.3 for ; Mon, 18 Dec 2023 06:41:15 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id v9-20020a05600c470900b0040c4acaa4bfsm31329915wmo.19.2023.12.18.06.41.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Dec 2023 06:41:15 -0800 (PST) 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: 7f5c899e-9db3-11ee-98eb-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1702910475; x=1703515275; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=SA83WH/tVAa+8UrSlLg9fG17XrU318HxH5GSIudImvg=; b=S+0IbRap4/C1EFSlMJkMYUCyD+9KP7RY88e28IOhlK/wUI4EgE7AqyVDLq9AD1Vv5q n+kbVDKcd8la/QSzhEug/EMlt8PZhIBlvkwXieqV4AzZCUDQZqemFdIpl4lH8nyv//i8 UPTa+cZQn1PDFHgBnRSR4jQMHPLixGIbF7631cOrnkcHz48ugEVE6lU7aKt5VL6LtXlR oyy5jeFoNYDc/I3kjdsalnG0FVvR3s/OqdxI+hP31qpvtV4CjM54Xq8sThcsNb/JnKeF gzSssWTqP0NqIBm08m2eeM/UHgK3O9a+vpChy3vsr75r+eM9jt9wq3VVNxS3s21AUqpQ XEoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702910475; x=1703515275; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SA83WH/tVAa+8UrSlLg9fG17XrU318HxH5GSIudImvg=; b=s8lDsJC/XI4gmjuUZ3G+rvVJkEoRIkpf89S+jyX1dp+ouNtkDep51tCBE7TeaNIitf LulXkRh4Q1R1dI6O0BXCuMro40AK3/jfTTCVOgTj71LH1uk1Z7fem81x9aDV4xTyMueZ dMfpJe9VfDhuhhqNtRm9KUuWAa7RYGOxvuCQVw3m1zOuHsBIIIIqn0zFPiY75RKFhKCS nMIvPsM1DYFakiViNQwigoq5TB+KoNF3D/8v9YfZ7jIV2F8EW2N4Gz+A+gLCTmJCtB08 P3NqVLiiZL77Z7eo0ZqFlMzLl6htrSMTZFqVBIGdFpW/B7IRhxlClYEyc8I8IiyOgaBw UaTw== X-Gm-Message-State: AOJu0YxKaV1qPgRA/4RPkfu6B9gF2hShRWQ4SCUj4Iyg6HPQHpY6OjOR IO/+29PI8IOkIMPLiLVwx+nou2jGSA7ixDPFP57T X-Google-Smtp-Source: AGHT+IEealb4TeglQHiJMGnJmhQlZzJDKrMBnAgY1fG14D5192f8JWEwkO3UZFcej4VUE8t1+TV/wA== X-Received: by 2002:a05:600c:1c9d:b0:40c:837:f033 with SMTP id k29-20020a05600c1c9d00b0040c0837f033mr7923825wms.61.1702910475359; Mon, 18 Dec 2023 06:41:15 -0800 (PST) Message-ID: <3bd1a8b8-1ed5-4d3a-8f5a-e193fdab7e1d@suse.com> Date: Mon, 18 Dec 2023 15:41:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v4 5/5] x86/vIRQ: split PCI link load state checking from actual 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: <1e855575-8c0f-4222-80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wLstV30g80nkgZf/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: <1e855575-8c0f-4222-80ba-e64305ea714b@suse.com> Move the checking into a check hook, and add checking of the padding fields as well. Signed-off-by: Jan Beulich Reviewed-by: Roger Pau Monné --- v4: New. --- a/xen/arch/x86/hvm/irq.c +++ b/xen/arch/x86/hvm/irq.c @@ -749,6 +749,30 @@ static int cf_check irq_load_isa(struct return 0; } +static int cf_check irq_check_link(const struct domain *d, + hvm_domain_context_t *h) +{ + const struct hvm_hw_pci_link *pci_link = hvm_get_entry(PCI_LINK, h); + unsigned int link; + + if ( !pci_link ) + return -ENODATA; + + for ( link = 0; link < ARRAY_SIZE(pci_link->pad0); link++ ) + if ( pci_link->pad0[link] ) + return -EINVAL; + + for ( link = 0; link < ARRAY_SIZE(pci_link->route); link++ ) + if ( pci_link->route[link] > 15 ) + { + printk(XENLOG_G_ERR + "HVM restore: PCI-ISA link %u out of range (%u)\n", + link, pci_link->route[link]); + return -EINVAL; + } + + return 0; +} static int cf_check irq_load_link(struct domain *d, hvm_domain_context_t *h) { @@ -759,16 +783,6 @@ static int cf_check irq_load_link(struct if ( hvm_load_entry(PCI_LINK, h, &hvm_irq->pci_link) != 0 ) return -EINVAL; - /* Sanity check */ - for ( link = 0; link < 4; link++ ) - if ( hvm_irq->pci_link.route[link] > 15 ) - { - printk(XENLOG_G_ERR - "HVM restore: PCI-ISA link %u out of range (%u)\n", - link, hvm_irq->pci_link.route[link]); - return -EINVAL; - } - /* Adjust the GSI assert counts for the link outputs. * This relies on the PCI and ISA IRQ state being loaded first */ for ( link = 0; link < 4; link++ ) @@ -788,5 +802,5 @@ HVM_REGISTER_SAVE_RESTORE(PCI_IRQ, irq_s 1, HVMSR_PER_DOM); 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, NULL, irq_load_link, - 1, HVMSR_PER_DOM); +HVM_REGISTER_SAVE_RESTORE(PCI_LINK, irq_save_link, irq_check_link, + irq_load_link, 1, HVMSR_PER_DOM);