From patchwork Tue Jun 13 09:38:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 691969 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d91:0:0:0:0:0 with SMTP id b17csp361581wru; Tue, 13 Jun 2023 04:29:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4I6ZJh7cjpynUUJfV0l4rB9KPnSN+VDdmqLPvKF+/bY9dzkze+yt2n/dadtBfDPeAPbWyO X-Received: by 2002:ac8:5f14:0:b0:3f8:67d7:e99a with SMTP id x20-20020ac85f14000000b003f867d7e99amr13305017qta.11.1686655785616; Tue, 13 Jun 2023 04:29:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686655785; cv=none; d=google.com; s=arc-20160816; b=gDAVaHXi3lVRljr0p6D2/bTnBsb+Wmrj1zscbihWh5pimnJEP/Gu3E8nW/FC9bcPiI 45Z9GP2q5Y3HfqX90dpqI3+tPcECcjXOlbrIW4NDGCRg2kb9HHPGyGynr4WpGQA334Ns hAPW+q6P2a7WvLhYDSocWdONYWqN9W8XE8WlAuH2sDc96VcAklsabbs2YHYLZ046rGCs 9SRtlyeNF+wW+zv6PnMEKnyJAKANZzXU2yU+RxCBMUFxdlC9yiiFvYz7JO3hTx4S245H KLYg3y+bal9qpRaE04YPbXPqQxRiXlVXbewP3QcF2Ne/XzmpJH6BA63gys5hrW/7Jxdc R36A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tn6UViqugu1iPM5CBgyVG1U7YWBaY3WOqVleP4qvVWg=; b=YuJiy+AN751FZ7OOjmknF/k1SR9PFvBKP2NGwEsSnJtw7kRiQqKLzGWe7s1IB4StK6 tIsONXqM0Oevo5PHs9E1YPpH9tJGfvaklvcs9yiucMI2OzD4sda4GKhadbZuc3/UolK/ 1qlW9Q8vaVDw2/XvdLLQktxOSutThKkA1n5Qm7q9Eaj8zbH95eh9iMvm3fR60ll7OCyg gpX52WaW0NYz2m6pyseTCM0NNboLLNqX0xUx0nf7wtkZOK1C4Fy4dEZafxRO5xgSs34O 9lzlbXuxFF+0Q3ZPuBwxuv754oT2HG7i0oZPpDb7PcrkaVSxjqL5tT2wB0AmzvuS6q1G /qZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R0zb4M9R; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i18-20020ac85c12000000b003ea3e861b40si7184968qti.399.2023.06.13.04.29.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Jun 2023 04:29:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R0zb4M9R; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q90VO-0005oB-9V; Tue, 13 Jun 2023 05:40:02 -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 1q90VF-0005lY-Ah for qemu-devel@nongnu.org; Tue, 13 Jun 2023 05:39:55 -0400 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q90V6-0005hT-7w for qemu-devel@nongnu.org; Tue, 13 Jun 2023 05:39:53 -0400 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5183101690cso5400457a12.0 for ; Tue, 13 Jun 2023 02:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686649182; x=1689241182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tn6UViqugu1iPM5CBgyVG1U7YWBaY3WOqVleP4qvVWg=; b=R0zb4M9RAEzXPO7CQcnjo+h9pA3mCXQsgY4HVYTWp9uenStcAbDsJL0rhChV09HK6c mSe9xV5k6iQ3ldd/Ra103M5Gloi4fMWnW8TWEa0I2n81LJINDg8EdIpxK46bEY1EJikK BbYw848lKam6Sbw9Byw9JRmlfcpR6Da2rnLAiZpbq8ndAxKpL/nxBjrVHeGzlJcI/ai8 TqfL8YQhoBDCNGeteVj8asmCATFxJW1ERdRbCgv+IB1YNRO5A4XOJjPvfiLZtu0Afx2I AM13GAhWf1SfRQdc5PRSHwRaY/3uw52EXBzKMwEOVchBQTzGkgJGQ3jLayOfHJPFdiba jCcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686649182; x=1689241182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tn6UViqugu1iPM5CBgyVG1U7YWBaY3WOqVleP4qvVWg=; b=bfdCkoiL+CL5kVEmvVUTDZwYoI101W3qsJidSYZwlcyn9YBji7e1cGqkomAWG2DiRT 17OUUuFm9aPWrq/GJy82sNdtXh0HJOjPRqbKq4Soa8KVV+YSM42o9beiU+/1FzIIkymW LT4Rdm8qtNP+S19QOrRjix+/0xIzHUjBP74RIqzyFDOpf2BZhgonbrn5lVzTA0LcHA9f 754JeciSvpu6oCfD2GYH6iRWglKaaHdhDivRyV6U5gTVHXOCMkvPseqLkd6OddSJeqly b3rkYZ70AEGeTn3FLPdd+fSESgVlY4KA2xxd+zzeLucIiVsaU6EI4IWDECTQGysdeTIL wkMA== X-Gm-Message-State: AC+VfDz2Fd7AdIra3+cKXVMnscs9RpPaxIAktBfUmYp2izAkzRr0AqDN wKqkqfPvyCMuf2LzTR1Pnx1dyJghJau4h9vJIYmunQ== X-Received: by 2002:a17:906:5d09:b0:978:af9d:c004 with SMTP id g9-20020a1709065d0900b00978af9dc004mr10809240ejt.4.1686649182368; Tue, 13 Jun 2023 02:39:42 -0700 (PDT) Received: from localhost.localdomain ([185.140.244.249]) by smtp.gmail.com with ESMTPSA id ks9-20020a170906f84900b009786c83d5d6sm6384144ejb.25.2023.06.13.02.39.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 13 Jun 2023 02:39:42 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Steve Sistare , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 17/17] exec/memory: Introduce RAM_NAMED_FILE flag Date: Tue, 13 Jun 2023 11:38:22 +0200 Message-Id: <20230613093822.63750-18-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230613093822.63750-1-philmd@linaro.org> References: <20230613093822.63750-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52b; envelope-from=philmd@linaro.org; helo=mail-ed1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Steve Sistare migrate_ignore_shared() is an optimization that avoids copying memory that is visible and can be mapped on the target. However, a memory-backend-ram or a memory-backend-memfd block with the RAM_SHARED flag set is not migrated when migrate_ignore_shared() is true. This is wrong, because the block has no named backing store, and its contents will be lost. To fix, ignore shared memory iff it is a named file. Define a new flag RAM_NAMED_FILE to distinguish this case. Signed-off-by: Steve Sistare Reviewed-by: Peter Xu Message-Id: <1686151116-253260-1-git-send-email-steven.sistare@oracle.com> Signed-off-by: Philippe Mathieu-Daudé --- qapi/migration.json | 4 ++-- include/exec/cpu-common.h | 1 + include/exec/memory.h | 3 +++ backends/hostmem-file.c | 1 + migration/ram.c | 3 ++- softmmu/physmem.c | 7 ++++++- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 179af0c4d8..5bb5ab82a0 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -465,8 +465,8 @@ # block devices (and thus take locks) immediately at the end of # migration. (since 3.0) # -# @x-ignore-shared: If enabled, QEMU will not migrate shared memory -# (since 4.0) +# @x-ignore-shared: If enabled, QEMU will not migrate shared memory that is +# accessible on the destination machine. (since 4.0) # # @validate-uuid: Send the UUID of the source to allow the destination # to ensure it is the same. (since 4.2) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index e5a55ede5f..87dc9a752c 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -93,6 +93,7 @@ void qemu_ram_set_uf_zeroable(RAMBlock *rb); bool qemu_ram_is_migratable(RAMBlock *rb); void qemu_ram_set_migratable(RAMBlock *rb); void qemu_ram_unset_migratable(RAMBlock *rb); +bool qemu_ram_is_named_file(RAMBlock *rb); int qemu_ram_get_fd(RAMBlock *rb); size_t qemu_ram_pagesize(RAMBlock *block); diff --git a/include/exec/memory.h b/include/exec/memory.h index c3661b2276..47c2e0221c 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -232,6 +232,9 @@ typedef struct IOMMUTLBEvent { /* RAM that isn't accessible through normal means. */ #define RAM_PROTECTED (1 << 8) +/* RAM is an mmap-ed named file */ +#define RAM_NAMED_FILE (1 << 9) + static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, IOMMUNotifierFlag flags, hwaddr start, hwaddr end, diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 38ea65bec5..b4335a80e6 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -57,6 +57,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) ram_flags = backend->share ? RAM_SHARED : 0; ram_flags |= backend->reserve ? 0 : RAM_NORESERVE; ram_flags |= fb->is_pmem ? RAM_PMEM : 0; + ram_flags |= RAM_NAMED_FILE; memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), name, backend->size, fb->align, ram_flags, fb->mem_path, fb->offset, fb->readonly, diff --git a/migration/ram.c b/migration/ram.c index 88a6c82e63..5283a75f02 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -197,7 +197,8 @@ static bool postcopy_preempt_active(void) bool ramblock_is_ignored(RAMBlock *block) { return !qemu_ram_is_migratable(block) || - (migrate_ignore_shared() && qemu_ram_is_shared(block)); + (migrate_ignore_shared() && qemu_ram_is_shared(block) + && qemu_ram_is_named_file(block)); } #undef RAMBLOCK_FOREACH diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 588d0d166b..6bdd944fe8 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -1570,6 +1570,11 @@ void qemu_ram_unset_migratable(RAMBlock *rb) rb->flags &= ~RAM_MIGRATABLE; } +bool qemu_ram_is_named_file(RAMBlock *rb) +{ + return rb->flags & RAM_NAMED_FILE; +} + int qemu_ram_get_fd(RAMBlock *rb) { return rb->fd; @@ -1880,7 +1885,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, /* Just support these ram flags by now. */ assert((ram_flags & ~(RAM_SHARED | RAM_PMEM | RAM_NORESERVE | - RAM_PROTECTED)) == 0); + RAM_PROTECTED | RAM_NAMED_FILE)) == 0); if (xen_enabled()) { error_setg(errp, "-mem-path not supported with Xen");