From mboxrd@z Thu Jan 1 00:00:00 1970 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 A6409D3399E for ; Mon, 28 Oct 2024 16:42:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t5Sou-0003KS-6K; Mon, 28 Oct 2024 12:42:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t5Sos-0003K8-NH for qemu-devel@nongnu.org; Mon, 28 Oct 2024 12:42:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t5Soq-0001V6-00 for qemu-devel@nongnu.org; Mon, 28 Oct 2024 12:42:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730133734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=T0UAX23+37ZRrHea98bsMhwQ80Lb1MZgJknkx7BqqeA=; b=aXUh+JZaPYkgO7in/M85tlp+SD6OKZ6tA72r22hjY63v0+oyn69HTQlUWUW4ny7G8BIYOz QzflzjIPyk+QeafLHh02W5p6bopuhPs5XFOT/FxUSKTYtHjRYFJSJ3h9xNwjE1r9URsKKC nbNGwZi+pFbOUM6tkoCrlmerc3/5b6k= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-383-cKd3ofIKMGCZ3fNFR5dQ6A-1; Mon, 28 Oct 2024 12:42:13 -0400 X-MC-Unique: cKd3ofIKMGCZ3fNFR5dQ6A-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4315afcae6cso25284575e9.0 for ; Mon, 28 Oct 2024 09:42:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730133732; x=1730738532; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=T0UAX23+37ZRrHea98bsMhwQ80Lb1MZgJknkx7BqqeA=; b=V/Du1nPWngtbihCiwX2zemL0JnTx9MjeL556rCiudwqSUUOCQFca5uzA21n2uEavI8 KW1i/S7HFksP8nYnROls1GiC5IAkMcE19f5OaHEfocKjM2wgqlzQnvrfQGN+/AWHtDDn m5UwwNQEK+ip8LnAvhoCVxnskIDyz6AJW201pG80PyVlVD7uV8o4AnipnKiwlcA01UEf mg9WBoGylwxN91KEqT1HckQ9IpVVaxJ4MxPqmxapDtdhIgIBShUxZXDlaeTlnwxgmZgg Obd6xRW3b0L2Vx3Y6XlEsDzULOKRveGZsu7f6+Vtzgs9u1nrDT9Syf37oUmGRvLljXRm 3eww== X-Forwarded-Encrypted: i=1; AJvYcCUeLLm2DOOfesgmRim9EiwUviQYxi2hRGicvUCdI9xlXwMmweKYoR6IZNd6pG+5e96TiZ6P+zwWdeS3@nongnu.org X-Gm-Message-State: AOJu0YzVz9ZUGlaVptndPwIhZ7CRpSuGiMVkO4gV52i/YLlhvwYLn2hx WJkoE5wCaKaJhFvw4EHRHBwjJFbgyjHmrPNmmK6/dIiOKlC2nyikGTQme4rhnrVblXLX027QQLB 7VB8KtM549gQZMQKjdEprXzV0/I14sFPH7ASaaQZs/rbQC+gUlhFZ X-Received: by 2002:a05:600c:450f:b0:431:7ccd:ff8a with SMTP id 5b1f17b1804b1-431b2f326c8mr2055625e9.14.1730133731986; Mon, 28 Oct 2024 09:42:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGBesCrSu0q4i2SZfeVQIYSHgqs3Pn9F5uTcLGHdCRZm3VZfc0mDe/6YB2p/qzRtKR5IbJeA== X-Received: by 2002:a05:600c:450f:b0:431:7ccd:ff8a with SMTP id 5b1f17b1804b1-431b2f326c8mr2055315e9.14.1730133731552; Mon, 28 Oct 2024 09:42:11 -0700 (PDT) Received: from ?IPV6:2003:cb:c722:3c00:70fc:90a8:2c65:79b4? (p200300cbc7223c0070fc90a82c6579b4.dip0.t-ipconnect.de. [2003:cb:c722:3c00:70fc:90a8:2c65:79b4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43193573551sm115340055e9.6.2024.10.28.09.42.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Oct 2024 09:42:11 -0700 (PDT) Message-ID: <9a49fc5f-bf9e-4e72-bd3e-13975d4913bd@redhat.com> Date: Mon, 28 Oct 2024 17:42:10 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 2/4] accel/kvm: Keep track of the HWPoisonPage page_size To: William Roche , kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org Cc: peterx@redhat.com, pbonzini@redhat.com, richard.henderson@linaro.org, philmd@linaro.org, peter.maydell@linaro.org, mtosatti@redhat.com, joao.m.martins@oracle.com References: <20241022213503.1189954-1-william.roche@oracle.com> <20241022213503.1189954-3-william.roche@oracle.com> <9b17600d-4473-4bb6-841f-00f93d86f720@oracle.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJ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o9Zu9w7Kv AxBQXWeXhJI9XQssfrf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <9b17600d-4473-4bb6-841f-00f93d86f720@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.373, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TVD_PH_BODY_ACCOUNTS_PRE=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On 26.10.24 01:27, William Roche wrote: > On 10/23/24 09:28, David Hildenbrand wrote: > >> On 22.10.24 23:35, “William Roche wrote: >>> From: William Roche >>> >>> Add the page size information to the hwpoison_page_list elements. >>> As the kernel doesn't always report the actual poisoned page size, >>> we adjust this size from the backend real page size. >>> We take into account the recorded page size to adjust the size >>> and location of the memory hole. >>> >>> Signed-off-by: William Roche >>> --- >>>   accel/kvm/kvm-all.c       | 14 ++++++++++---- >>>   include/exec/cpu-common.h |  1 + >>>   include/sysemu/kvm.h      |  3 ++- >>>   include/sysemu/kvm_int.h  |  3 ++- >>>   system/physmem.c          | 20 ++++++++++++++++++++ >>>   target/arm/kvm.c          |  8 ++++++-- >>>   target/i386/kvm/kvm.c     |  8 ++++++-- >>>   7 files changed, 47 insertions(+), 10 deletions(-) >>> >>> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c >>> index 2adc4d9c24..40117eefa7 100644 >>> --- a/accel/kvm/kvm-all.c >>> +++ b/accel/kvm/kvm-all.c >>> @@ -1266,6 +1266,7 @@ int kvm_vm_check_extension(KVMState *s, >>> unsigned int extension) >>>    */ >>>   typedef struct HWPoisonPage { >>>       ram_addr_t ram_addr; >>> +    size_t     page_size; >>>       QLIST_ENTRY(HWPoisonPage) list; >>>   } HWPoisonPage; >>>   @@ -1278,15 +1279,18 @@ static void kvm_unpoison_all(void *param) >>>         QLIST_FOREACH_SAFE(page, &hwpoison_page_list, list, next_page) { >>>           QLIST_REMOVE(page, list); >>> -        qemu_ram_remap(page->ram_addr, TARGET_PAGE_SIZE); >>> +        qemu_ram_remap(page->ram_addr, page->page_size); >> >> Can't we just use the page size from the RAMBlock in qemu_ram_remap? >> There we lookup the RAMBlock, and all pages in a RAMBlock have the >> same size. > > > Yes, we could use the page size from the RAMBlock in qemu_ram_remap() > that is called when the VM is resetting. I think that knowing the > information about the size of poisoned chunk of memory when the poison > is created is useful to give a trace of what is going on, before seeing > maybe other pages being reported as poisoned. That's the 4th patch goal > to give an information as soon as we get it. > It also helps to filter the new errors reported and only create an entry > in the hwpoison_page_list for new large pages. > Now we could delay the page size retrieval until we are resetting and > present the information (post mortem). I do think that having the > information earlier is better in this case. If it is not required for this patch, then please move the other stuff to patch #4. Here, we really only have to discard a large page, which we can derive from the QEMU RAMBlock page size. > > >> >> I'll note that qemu_ram_remap() is rather stupid and optimized only >> for private memory (not shmem etc). >> >> mmap(MAP_FIXED|MAP_SHARED, fd) will give you the same poisoned page >> from the pagecache; you'd have to punch a hole instead. >> >> It might be better to use ram_block_discard_range() in the long run. >> Memory preallocation + page pinning is tricky, but we could simply >> bail out in these cases (preallocation failing, ram discard being >> disabled). > > > I see that ram_block_discard_range() adds more control before discarding > the RAM region and can also call madvise() in addition to the fallocate > punch hole for standard sized memory pages. Now as the range is supposed > to be recreated, I'm not convinced that these madvise calls are necessary. They are the proper replacement for the mmap(MAP_FIXED) + fallocate. That function handles all cases of properly discarding guest RAM. > > But we can also notice that this function will report the following > warning in all cases of not shared file backends: > "ram_block_discard_range: Discarding RAM in private file mappings is > possibly dangerous, because it will modify the underlying file and will > affect other users of the file" Yes, because it's a clear warning sign that something weird is happening. You might be throwing away data that some other process might be relying on. How are you making QEMU consume hugetlbs? We could suppress these warnings, but let's first see how you are able to trigger it. > Which means that hugetlbfs configurations do see this new cryptic > warning message on reboot if it is impacted by a memory poisoning. > So I would prefer to leave the fallocate call in the qemu_ram_remap() > function. Or would you prefer to enhance ram_block_discard_range()code > to avoid the message in a reset situation (when called from qemu_ram_remap)? Please try reusing the mechanism to discard guest RAM instead of open-coding this. We still have to use mmap(MAP_FIXED) as a backup, but otherwise this function should mostly do+check what you need. (-warnings we might want to report differently / suppress) If you want, I can start a quick prototype of what it could look like when using ram_block_discard_range() + ram_block_discard_is_disabled() + fallback to existing mmap(MAP_FIXED). > > >> >> qemu_ram_remap() might be problematic with page pinning (vfio) as is >> in any way :( > > I agree. If qemu_ram_remap() fails, Qemu is ended either abort() or > exit(1). Do you say that memory pinning could be detected by > ram_block_discard_range() or maybe mmap call for the impacted region and > make one of them fail ? This would be an additional reason to call > ram_block_discard_range() from qemu_ram_remap().   Is it what you are > suggesting ? ram_block_discard_is_disabled() might be the right test. If discarding is disabled, then rebooting might create an inconsistency with e.g.,vfio, resulting in the issues we know from memory ballooning where the state vfio sees will be different from the state the guest kernel sees. It's tricky ... and we much rather quit the VM early instead of corrupting data later :/ -- Cheers, David / dhildenb