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 59034C4332F for ; Tue, 31 Oct 2023 19:10:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxu80-0008E8-NN; Tue, 31 Oct 2023 15:10:16 -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 1qxu7z-0008Ah-Pn for qemu-devel@nongnu.org; Tue, 31 Oct 2023 15:10:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxu7u-00089c-CK for qemu-devel@nongnu.org; Tue, 31 Oct 2023 15:10:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698779408; 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: in-reply-to:in-reply-to:references:references; bh=mUWpt9yw9KRqs+DA1PXjT9+U4zq/exq81q09+dacIGg=; b=VE4oNR/9ZyhbcAGbsd7vJvb5tqAiX7m3iHUoxivuOEKp5XtT2JvSz4cFYFX/iXQ0z/dt1D IrI/4OPpZ0YlGaj/iDjXax5zWNQMQei8v5l5vuJ9Mwi4bfx8nzQrLFxNVhG5NcXa4HOpYc z98UADTih8IRdrRaxHweg87CjgfaYLE= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-aM7SOxX5OX6xKbZwKBp9vA-1; Tue, 31 Oct 2023 15:10:01 -0400 X-MC-Unique: aM7SOxX5OX6xKbZwKBp9vA-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-66d48cfd295so21609196d6.0 for ; Tue, 31 Oct 2023 12:10:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698779400; x=1699384200; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mUWpt9yw9KRqs+DA1PXjT9+U4zq/exq81q09+dacIGg=; b=U2buR/LJpZHpFClUVu3M1kO3Lw93VOAVMCxpHAVWWWH9dWaP++iTOen+OCGTUMj1Vx OjZk+2fnI1wviq/oObupqh7kg5Mavp426Q8Eu5a3DF2HcJO9pZEze6Zzb9vWRyiMsg5e gg44XVcYOAorSCojOLeFdg1PJPAo2Bw8lVTTg5FS2b5fFe/h9diVM7az+m5z9BYAWFwO ZnfZsRTxOjjJn3Udl/+bA/en/UqdRX4a2vHScPuEZVC+juGSPFHLxOpYFHjPRJdRZ/vJ 01ljt+rMY5zYd0Nk8dGUQu9WPTmQBLllmaZ0YYDKzT0OsZBlrFMXIadQqS0Q+p0c3q0l 8ppA== X-Gm-Message-State: AOJu0YwsqtMYjZsGaWrjhWm9Ju2de5VcTAqTUdZw8KZUAkuOO1t1vNCo +xEcVfMDBDG0/KYv5xMqZgneM9IGQQKyHj+8ydyIIjYS67uDBo1Ckvr4VTAQRV6gjz2v8Lxtmmz YwMFUD3FZH9PW1dA= X-Received: by 2002:a05:6214:2b98:b0:65d:486:25c6 with SMTP id kr24-20020a0562142b9800b0065d048625c6mr14272918qvb.3.1698779400720; Tue, 31 Oct 2023 12:10:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQa4NlknX7vTN6SE4iEw+7yBTOgshIE57WxdxhHWQqVIzInJ/qMpYZ53rX6MBLYtmLwy876Q== X-Received: by 2002:a05:6214:2b98:b0:65d:486:25c6 with SMTP id kr24-20020a0562142b9800b0065d048625c6mr14272897qvb.3.1698779400208; Tue, 31 Oct 2023 12:10:00 -0700 (PDT) Received: from x1n (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id g14-20020a0cd7ce000000b00647386a3234sm772918qvj.85.2023.10.31.12.09.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 12:09:59 -0700 (PDT) Date: Tue, 31 Oct 2023 15:09:57 -0400 From: Peter Xu To: Fabiano Rosas Cc: qemu-devel@nongnu.org, berrange@redhat.com, armbru@redhat.com, Juan Quintela , Leonardo Bras , Claudio Fontana , Nikolay Borisov Subject: Re: [PATCH v2 16/29] migration/ram: Add support for 'fixed-ram' migration restore Message-ID: References: <20231023203608.26370-1-farosas@suse.de> <20231023203608.26370-17-farosas@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231023203608.26370-17-farosas@suse.de> Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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 Mon, Oct 23, 2023 at 05:35:55PM -0300, Fabiano Rosas wrote: > From: Nikolay Borisov > > Add the necessary code to parse the format changes for the 'fixed-ram' > capability. > > One of the more notable changes in behavior is that in the 'fixed-ram' > case ram pages are restored in one go rather than constantly looping > through the migration stream. > > Signed-off-by: Nikolay Borisov > Signed-off-by: Fabiano Rosas > --- > (farosas) reused more of the common code by making the fixed-ram > function take only one ramblock and calling it from inside > parse_ramblock. > --- > migration/ram.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 93 insertions(+) > > diff --git a/migration/ram.c b/migration/ram.c > index 152a03604f..cea6971ab2 100644 > --- a/migration/ram.c > +++ b/migration/ram.c > @@ -3032,6 +3032,32 @@ static void fixed_ram_insert_header(QEMUFile *file, RAMBlock *block) > qemu_put_buffer(file, (uint8_t *) header, header_size); > } > > +static int fixed_ram_read_header(QEMUFile *file, struct FixedRamHeader *header) > +{ > + size_t ret, header_size = sizeof(struct FixedRamHeader); > + > + ret = qemu_get_buffer(file, (uint8_t *)header, header_size); > + if (ret != header_size) { > + return -1; > + } > + > + /* migration stream is big-endian */ > + be32_to_cpus(&header->version); > + > + if (header->version > FIXED_RAM_HDR_VERSION) { > + error_report("Migration fixed-ram capability version mismatch (expected %d, got %d)", > + FIXED_RAM_HDR_VERSION, header->version); I know it doesn't matter a lot for now, but it'll be good to start using Error** in new codes? > + return -1; > + } > + > + be64_to_cpus(&header->page_size); > + be64_to_cpus(&header->bitmap_offset); > + be64_to_cpus(&header->pages_offset); > + > + > + return 0; > +} > + > /* > * Each of ram_save_setup, ram_save_iterate and ram_save_complete has > * long-running RCU critical section. When rcu-reclaims in the code > @@ -3932,6 +3958,68 @@ void colo_flush_ram_cache(void) > trace_colo_flush_ram_cache_end(); > } > > +static void read_ramblock_fixed_ram(QEMUFile *f, RAMBlock *block, > + long num_pages, unsigned long *bitmap) > +{ > + unsigned long set_bit_idx, clear_bit_idx; > + unsigned long len; > + ram_addr_t offset; > + void *host; > + size_t read, completed, read_len; > + > + for (set_bit_idx = find_first_bit(bitmap, num_pages); > + set_bit_idx < num_pages; > + set_bit_idx = find_next_bit(bitmap, num_pages, clear_bit_idx + 1)) { > + > + clear_bit_idx = find_next_zero_bit(bitmap, num_pages, set_bit_idx + 1); > + > + len = TARGET_PAGE_SIZE * (clear_bit_idx - set_bit_idx); > + offset = set_bit_idx << TARGET_PAGE_BITS; > + > + for (read = 0, completed = 0; completed < len; offset += read) { > + host = host_from_ram_block_offset(block, offset); > + read_len = MIN(len, TARGET_PAGE_SIZE); Why MIN()? I didn't read qemu_get_buffer_at() yet, but shouldn't len always be multiple of target page size or zero? > + > + read = qemu_get_buffer_at(f, host, read_len, > + block->pages_offset + offset); > + completed += read; > + } > + } > +} > + > +static int parse_ramblock_fixed_ram(QEMUFile *f, RAMBlock *block, ram_addr_t length) > +{ > + g_autofree unsigned long *bitmap = NULL; > + struct FixedRamHeader header; > + size_t bitmap_size; > + long num_pages; > + int ret = 0; > + > + ret = fixed_ram_read_header(f, &header); > + if (ret < 0) { > + error_report("Error reading fixed-ram header"); Same here on error handling; suggest to use Error** from the start. > + return -EINVAL; > + } > + > + block->pages_offset = header.pages_offset; > + num_pages = length / header.page_size; > + bitmap_size = BITS_TO_LONGS(num_pages) * sizeof(unsigned long); > + > + bitmap = g_malloc0(bitmap_size); > + if (qemu_get_buffer_at(f, (uint8_t *)bitmap, bitmap_size, > + header.bitmap_offset) != bitmap_size) { > + error_report("Error parsing dirty bitmap"); > + return -EINVAL; > + } > + > + read_ramblock_fixed_ram(f, block, num_pages, bitmap); > + > + /* Skip pages array */ > + qemu_set_offset(f, block->pages_offset + length, SEEK_SET); > + > + return ret; > +} > + > static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length) > { > int ret = 0; > @@ -3940,6 +4028,10 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length) > > assert(block); > > + if (migrate_fixed_ram()) { > + return parse_ramblock_fixed_ram(f, block, length); > + } > + > if (!qemu_ram_is_migratable(block)) { > error_report("block %s should not be migrated !", block->idstr); > return -EINVAL; > @@ -4142,6 +4234,7 @@ static int ram_load_precopy(QEMUFile *f) > migrate_multifd_flush_after_each_section()) { > multifd_recv_sync_main(); > } > + > break; > case RAM_SAVE_FLAG_HOOK: > ret = rdma_registration_handle(f); > -- > 2.35.3 > -- Peter Xu