From patchwork Fri Oct 13 15:08:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Roche X-Patchwork-Id: 13420992 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 67692C41513 for ; Fri, 13 Oct 2023 15:10:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qrJnI-00072U-K7; Fri, 13 Oct 2023 11:09:40 -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 1qrJn9-0006zD-CW for qemu-devel@nongnu.org; Fri, 13 Oct 2023 11:09:33 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qrJn2-0006zo-ED for qemu-devel@nongnu.org; Fri, 13 Oct 2023 11:09:30 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39DE0nFC019270; Fri, 13 Oct 2023 15:09:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=W2UWonwhJLUiL/DU8SA7D1JKPkE/ypyvs/ozde+ZdS8=; b=Gm2v5zdX3deSrxysrRD2/g+8/y5FD1awrJCyVAwSAis5mAZUJEsFe8XzW4nyXlPLOubX VCS7pcCRvfWrJr+j4N2AUlXQHyBtXiwuk7HWg0T+aAEfKgVMx9gtKntNpI34/Ibip0Pt eCmfWPiApPd2ZUdW30iWeDwCpBnhnfUJCa9CoIJ5/fcxs4v9COBZLJ45KgRbnEmnlp4N 6fiDnkvSkZlMc7TZeHsH6kMLSV+gQ3YGsTBEpM/JWQjQ1lawQNc6rTlPCdawvJwcIGtN P+bA9RxVTvAW4hyfmufqtyZhcWFhMRRY5FzFE1AxWr9Y+0z7NDnU52TUMSTS9O8NCzbd Ng== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tmh912j3d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:09:20 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39DF8vME021322; Fri, 13 Oct 2023 15:09:00 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2168.outbound.protection.outlook.com [104.47.56.168]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3tptasfv4p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Oct 2023 15:09:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KIrB11APN2mr0uKEMhT0KKandDhnsPD8XqkfstR7BPadeJGbFUBoMYyTmBa/SuAflya6Bb8kigfDSD3rCFM6tRJWYSKPBpQMRFOQqoTQUe3vvX5dEQ91StEt673wWI3sL2F3+O5B83X9FZFYlqaMFZIycIyTgkraoqtj12C2N0NKqkVs8i+IIMzP23Y8yilB5xY1tiFFECvYP3m55uyN0FpVuAaYeBEWDMJ6n0LOzKvwpy26IiU94rrLH0aATDniJJc1wYo+MRM9Es4ThjwLzKk0gc3XYJyoRHVve3ByMf4VJIwx1+wrJuBPMXBpAHKpGNZmxA8nOicbaZllQZkGwg== 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=W2UWonwhJLUiL/DU8SA7D1JKPkE/ypyvs/ozde+ZdS8=; b=NnShCQeF3iLlsjafJAGPrwuW4rsTEbfHoASWpZor4PLFxChiMjP63HL84L2iKFxQJmPvVAsh7H2VGHd6OMRbA+BY6T08atDsTDfeGxuIQRxRhwl1a7SanRUWm5Sm4TBryvby3D4cq6LuVMqyGdjh6fVWIhw5RDVt2kJZeWS+rm4CFfoO3sKBT5b9zNuIJZsTX6Z+3YOypucI5wggmAWzW/SIoJ45caSRi/40eAapQsx6Drc7ux/tPa6rv89SmWkS87dQ7pyvKCEtKF09WvHhk6oSPrls9oWuhlKejhtTxUbVg04SishSxfy22R48KTlr/qlUazGSO3xhGJtmr1mJIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=W2UWonwhJLUiL/DU8SA7D1JKPkE/ypyvs/ozde+ZdS8=; b=PWyJRZbW5cgqihWCqT4tGRCf4Xig1Q1tYQI+v/HGhPZIqxHpdXfabQG99N/rFe7OycAsBvUq+ZvRymtMz6QfPx5dsINnSphPxrHybEWDftEdbW8VNDjl6WpbaZV0GBWLrDlxAqMGUNoVKpEL23oOpCAVZDY9iMdzEYOBVDstsEE= Received: from PH0PR10MB5481.namprd10.prod.outlook.com (2603:10b6:510:ea::5) by CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.37; Fri, 13 Oct 2023 15:08:58 +0000 Received: from PH0PR10MB5481.namprd10.prod.outlook.com ([fe80::487d:5c37:8928:9885]) by PH0PR10MB5481.namprd10.prod.outlook.com ([fe80::487d:5c37:8928:9885%4]) with mapi id 15.20.6863.043; Fri, 13 Oct 2023 15:08:58 +0000 From: =?utf-8?q?=E2=80=9CWilliam_Roche?= To: qemu-devel@nongnu.org, peterx@redhat.com Cc: lizhijian@fujitsu.com, pbonzini@redhat.com, quintela@redhat.com, leobras@redhat.com, joao.m.martins@oracle.com, lidongchen@tencent.com, william.roche@oracle.com Subject: [PATCH v4 2/2] migration: prevent migration when a poisoned page is unknown from the VM Date: Fri, 13 Oct 2023 15:08:39 +0000 Message-Id: <20231013150839.867164-3-william.roche@oracle.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231013150839.867164-1-william.roche@oracle.com> References: <20230920235301.1622672-1-william.roche@oracle.com> <20231013150839.867164-1-william.roche@oracle.com> X-ClientProxiedBy: BL0PR0102CA0006.prod.exchangelabs.com (2603:10b6:207:18::19) To PH0PR10MB5481.namprd10.prod.outlook.com (2603:10b6:510:ea::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR10MB5481:EE_|CH2PR10MB4166:EE_ X-MS-Office365-Filtering-Correlation-Id: b319961b-c0b2-4f93-8fd7-08dbcbfe52ff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yvUCcGURtAaGmPJj5876gcrk8JeKbzlG3mMkJQ5h5vvTWEB/nEoZTvQlQqGSZYpd84jTV1BNRgh7R4CSDCXIkypz+39CV0qqNT8B0jrp75mSFuiq3dx5sJtRZzPl9Wr+BY77x9A0xGztholH3H8uTa7droYiIA6nyINF4l5/sEX3c9cNx+fjNE8MQ+xaFuVUlJjg+qx77qxrlNSM7wkF5xM9TysJ1lkQue2yxpkAuFXUUndFWDGIbNw4V2o36R6vPUkACAs73Jz8gbD9Le/QgDe6MABb3U3xUySMLm53pgt6Nm8okIVReloawfY84zp6gyt97A3yGXBp83pdIhuV8UMFWoQIOtiXu2QbXuYBcE9BHfdaMWHALiG3Z2RMB/DQdhxVVZ1hWHTWVGmRmFmwHj+9eZdrvLXvqwu9HRGPiQLEZkyNVV1qtlC74aY/p6uDfLZJtsX3y0jX8XZpNs36NrgiYRC6dD7aATgtpkQ27rPWauN1CF2ErwAtTXK/ZIOb3LVboYJbe+x1Dd/q/tt6SooTKbP2TEMKv6bYEdfQ4fdZFBgjds79WM1KAe32Bcwe X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR10MB5481.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(39860400002)(366004)(136003)(396003)(376002)(346002)(230922051799003)(1800799009)(451199024)(186009)(64100799003)(86362001)(38100700002)(36756003)(5660300002)(41300700001)(66946007)(66476007)(6666004)(2906002)(8676002)(478600001)(8936002)(6486002)(6512007)(4326008)(6506007)(83380400001)(1076003)(2616005)(107886003)(66556008)(316002)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Gp4IMu+sEYRfudpcu+11K9Goqe7qbZpccDZnLb+AFXop2ZB1/QQ99pXVPAvJZdEZL4G7Zc/NBSRPois0iqrc/AhFdRifLZn9jKtzI3EPl6r7BWASB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TY/wlXgXXUI/YsgxYtrKO17GuceQI+PT7qMmhN7r0AzjThWOzLA+HAzopW5P5htwdAuN1aIvtu/Pzw4P80Ms2MnM5ycEHtF3ii2PLyMlMvSmSCu5p1TYLGOTNF4FVHUrA+zF0ZtqWcqFl52mZOlsHm4QecXsJx8Vs3o/ZbFnUu1dFbVahs1y4diMuw7ancEWl9Ewdjg++PgoG0HvUp3g5Te1nr68CzGTs/RDZzXBA2oumtIArWwFk9NRtdM4E7RubxNTar4h6SKHMaJ8V3D/7Z56x7EhL6G/Etfg+tdlLZBZOrCqhNm3tQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b319961b-c0b2-4f93-8fd7-08dbcbfe52ff X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB5481.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2023 15:08:57.9081 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3EXphpY9A69QmJlSbwnzioZ5+i9e5Ybj9Q/gwl+qmpO4ny5ElUH5tT1F9KaSOd3gKiF2H/9f0Xk7jXDDYGBXxQQAcz8uBPC90BiG0nyK4eQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4166 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-13_06,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 bulkscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310130128 X-Proofpoint-GUID: gDOL9R2c_BemUkTAtmt4v0KpeGVB8iSC X-Proofpoint-ORIG-GUID: gDOL9R2c_BemUkTAtmt4v0KpeGVB8iSC Received-SPF: pass client-ip=205.220.165.32; envelope-from=william.roche@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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 From: William Roche Migrating a poisoned page as a zero-page can only be done when the running guest kernel knows about this poison, so that it marks this page as unaccessible and any access in the VM would fail. But if a poison information is not relayed to the VM, the kernel does not prevent its access. In this case, transforming a poisoned page into a zero-page could create a case of silent data corruption. So we have to keep track of poisons not injected into the guest, like the ARM VM emulation ignoring BUS_MCEERR_AO errors. When such a page exists, the migration has to be blocked. Signed-off-by: William Roche --- accel/kvm/kvm-all.c | 27 ++++++++++++++++++++++++++- accel/stubs/kvm-stub.c | 5 +++++ include/sysemu/kvm.h | 6 ++++++ include/sysemu/kvm_int.h | 3 ++- migration/migration.c | 6 ++++++ target/arm/kvm64.c | 6 +++++- target/i386/kvm/kvm.c | 2 +- 7 files changed, 51 insertions(+), 4 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 850577ea0e..2829b6372a 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1133,8 +1133,17 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension) return ret; } +/* + * We track the poisoned pages to be able to: + * - replace them on VM reset + * - skip them when migrating + * - block a migration for a VM where a poisoned page is ignored + * as this VM kernel (not knowing about the error) could + * incorrectly access the page. + */ typedef struct HWPoisonPage { ram_addr_t ram_addr; + bool vm_known; QLIST_ENTRY(HWPoisonPage) list; } HWPoisonPage; @@ -1166,20 +1175,36 @@ bool kvm_hwpoisoned_page(RAMBlock *block, void *offset) return false; } -void kvm_hwpoison_page_add(ram_addr_t ram_addr) +void kvm_hwpoison_page_add(ram_addr_t ram_addr, bool known) { HWPoisonPage *page; QLIST_FOREACH(page, &hwpoison_page_list, list) { if (page->ram_addr == ram_addr) { + if (known && !page->vm_known) { + page->vm_known = true; + } return; } } page = g_new(HWPoisonPage, 1); page->ram_addr = ram_addr; + page->vm_known = known; QLIST_INSERT_HEAD(&hwpoison_page_list, page, list); } +bool kvm_hwpoisoned_unknown(void) +{ + HWPoisonPage *pg; + + QLIST_FOREACH(pg, &hwpoison_page_list, list) { + if (!pg->vm_known) { + return true; + } + } + return false; +} + static uint32_t adjust_ioeventfd_endianness(uint32_t val, uint32_t size) { #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index c0a31611df..c43de44263 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -138,3 +138,8 @@ bool kvm_hwpoisoned_page(RAMBlock *block, void *ram_addr) { return false; } + +bool kvm_hwpoisoned_unknown(void) +{ + return false; +} diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 858688227a..37c8316ce4 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -580,4 +580,10 @@ uint32_t kvm_dirty_ring_size(void); * false: page not yet poisoned */ bool kvm_hwpoisoned_page(RAMBlock *block, void *ram_addr); + +/** + * kvm_hwpoisoned_unknown - indicate if a qemu reported memory error + * is still unknown to (hasn't been injected into) the VM kernel. + */ +bool kvm_hwpoisoned_unknown(void); #endif diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index a5b9122cb8..2dfde40690 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -136,10 +136,11 @@ void kvm_set_max_memslot_size(hwaddr max_slot_size); * * Parameters: * @ram_addr: the address in the RAM for the poisoned page + * @known: indicate if the error is injected to the VM kernel * * Add a poisoned page to the list * * Return: None. */ -void kvm_hwpoison_page_add(ram_addr_t ram_addr); +void kvm_hwpoison_page_add(ram_addr_t ram_addr, bool known); #endif diff --git a/migration/migration.c b/migration/migration.c index 1c6c81ad49..27e9571aaf 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -66,6 +66,7 @@ #include "sysemu/qtest.h" #include "options.h" #include "sysemu/dirtylimit.h" +#include "sysemu/kvm.h" static NotifierList migration_state_notifiers = NOTIFIER_LIST_INITIALIZER(migration_state_notifiers); @@ -1646,6 +1647,11 @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc, return false; } + if (kvm_hwpoisoned_unknown()) { + error_setg(errp, "Can't migrate this vm with ignored poisoned page"); + return false; + } + if (migration_is_blocked(errp)) { return false; } diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index 5e95c496bb..e8db6380c1 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -1158,7 +1158,6 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr) ram_addr = qemu_ram_addr_from_host(addr); if (ram_addr != RAM_ADDR_INVALID && kvm_physical_memory_addr_from_host(c->kvm_state, addr, &paddr)) { - kvm_hwpoison_page_add(ram_addr); /* * If this is a BUS_MCEERR_AR, we know we have been called * synchronously from the vCPU thread, so we can easily @@ -1169,7 +1168,12 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr) * called synchronously from the vCPU thread, or a bit * later from the main thread, so doing the injection of * the error would be more complicated. + * In this case, BUS_MCEERR_AO errors are unknown from the + * guest, and we will prevent migration as long as this + * poisoned page hasn't generated a BUS_MCEERR_AR error + * that the guest takes into account. */ + kvm_hwpoison_page_add(ram_addr, (code == BUS_MCEERR_AR)); if (code == BUS_MCEERR_AR) { kvm_cpu_synchronize_state(c); if (!acpi_ghes_record_errors(ACPI_HEST_SRC_ID_SEA, paddr)) { diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index f6c7f7e268..f9365b4457 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -649,7 +649,7 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr) ram_addr = qemu_ram_addr_from_host(addr); if (ram_addr != RAM_ADDR_INVALID && kvm_physical_memory_addr_from_host(c->kvm_state, addr, &paddr)) { - kvm_hwpoison_page_add(ram_addr); + kvm_hwpoison_page_add(ram_addr, true); kvm_mce_inject(cpu, paddr, code); /*