From patchwork Tue Sep 10 09:07:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Roche X-Patchwork-Id: 13798147 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 306CFECE58B for ; Tue, 10 Sep 2024 09:08:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snwr2-00069G-Ax; Tue, 10 Sep 2024 05:08:08 -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 1snwr0-00067a-Ql for qemu-devel@nongnu.org; Tue, 10 Sep 2024 05:08:06 -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 1snwqs-0004HY-Vk for qemu-devel@nongnu.org; Tue, 10 Sep 2024 05:08:01 -0400 Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48A8tb0E031012 for ; Tue, 10 Sep 2024 09:07:55 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-11-20; bh=nvKn/wDBAxD1e10wUSGS3PLbmwSD8bBz13dZQCFyI20=; b= C452c+3DsxTE4O2lLdSjUrwmcVbt2xoa/1cpjsjy3B75D2NGu7W2g9yXga9pqLIb 4a3WPyuZ1Y46U3FNqj8KBNvAd8iqAmT4j1PJpXfIMAC6jkOehqNAyEOEL+kDaU3b REjmRDpSOL4a2lpglAjGa+7/epJE2ttb3SCN0KVsT+nn/iNcOun0vAUzj8Y+BLpg iw+TyL9fyvZlO3bLN5dZ0nrWBE74kYh7AAaXpNdiM1Mixo+Z6MKfty+KqulXgzqF HqrnQaS2LgzNumETvJcG3t/wNlPHKE1hyownfR+9NlDWmKaJECJf1PTcIZSkQ0WY VO7ey2DGrXPVhGhfbHxS8g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41gdrb51s6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Sep 2024 09:07:54 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48A886Qw034160 for ; Tue, 10 Sep 2024 09:07:54 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2176.outbound.protection.outlook.com [104.47.56.176]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41gd98s0dy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Sep 2024 09:07:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YSXVX1Pl5+F2LKfnhI/MZ/YOK77Y/7WDxpiIZYzxO7a+a9+DfiQS1ceJqIC/B++ljACfwD1kRkViezH2WW/xJq6hDL0zMbI8IEV0YJzEgyIVoXdWsPe9cka0KzoRQMrkaOX8nOmvNXMjXtaIdZZOOCnNN3PBhe4PSZ0/fip8r0P9ocGQpoL1kWGWeqN2oHld90LzBmdnsOcGEldGTOcapmZyRkUl5W1PK5GtpbJmI68lhXUcu+VQAWzwhHyjxxjZMgvHh8fTLQzMEbiemSeqvJLFo6rT9AgVPHX/vUpMy7Sk5sgfytq0+UUiv1V935+d7s4KoJo282lTyDv8I38lDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=nvKn/wDBAxD1e10wUSGS3PLbmwSD8bBz13dZQCFyI20=; b=OBcobv4ZpZSDMs4o3JpvF7g0tOdK2ADTjNcXHsX+pQJcif5FlONAehk3QkUCvLm7aChQna8IICXjjPqoqZQ/kL8FRlhVkSQ28qoK8YUKHH3a+ACk5uJpVn5aBvU4NJIaGFo4ahfoiogYrKYZOfR3vFlfysOYM+Q1epGSECCkBi6tbM9zqiG7LQUMd2sWnXIrudOGfYOgDk2ZXm6Etsx6AIvv7s5W4lGuxmHrba59HJKz3VjPYn3F19i18OR6Ch8IkAYY/WcZ71LwAnSOZte7obLfyncqecJRokziDcWmfl2BdkXEKNlFI2cEX6my7PA8L7ZlxaqsjuEJMGhebsg5MQ== 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=nvKn/wDBAxD1e10wUSGS3PLbmwSD8bBz13dZQCFyI20=; b=SqYaLN7AcxKIUG52V53iqgt4r9a1XEeTgyHbuR1NevY/3TWoN1I4Qwv+AEWcfixzxI+DL6M2/zCeX9H6wFLSzNk1uuhc3lkxXc6cms6AyAJhVnpBGrGiIYD23UOnvwRZhaip+1AJ84psm662owB/T541zv/bIyon83FsRvB/sa8= Received: from CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) by CH3PR10MB7163.namprd10.prod.outlook.com (2603:10b6:610:127::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.16; Tue, 10 Sep 2024 09:07:52 +0000 Received: from CH3PR10MB7329.namprd10.prod.outlook.com ([fe80::f238:6143:104c:da23]) by CH3PR10MB7329.namprd10.prod.outlook.com ([fe80::f238:6143:104c:da23%5]) with mapi id 15.20.7939.010; Tue, 10 Sep 2024 09:07:52 +0000 From: =?utf-8?q?=E2=80=9CWilliam_Roche?= To: qemu-devel@nongnu.org Cc: william.roche@oracle.com, joao.m.martins@oracle.com Subject: [RFC 1/6] accel/kvm: SIGBUS handler should also deal with si_addr_lsb Date: Tue, 10 Sep 2024 09:07:42 +0000 Message-ID: <20240910090747.2741475-2-william.roche@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910090747.2741475-1-william.roche@oracle.com> References: <20240910090747.2741475-1-william.roche@oracle.com> X-ClientProxiedBy: SJ0PR03CA0002.namprd03.prod.outlook.com (2603:10b6:a03:33a::7) To CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB7329:EE_|CH3PR10MB7163:EE_ X-MS-Office365-Filtering-Correlation-Id: 9fcf6905-33c7-414d-8c43-08dcd1780cc9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: R6CbSpa39ZZTQ82PokK60i2yCbZkBpK6ZDXAz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H2yO2/4T2Cgqi1e1Ed8w0xzw9Fvre/0nhN5uRu92HDIxELklUh4E7AqJrNJJMVFdEFtXXkbT+5oZffMfUeZsQEBH1TgRgQkTB1/FvzPiZILB0UTYtFqTyEDalhF+VpzMMT1ZfUvIN1pnwyvjs8+b+J6jHKk6IXEFKb8DWXh0zwjEwUeP4KhTvR6eBvAPvPOl/V0/fVBzzl8aO68/3jO7JVM59fopaolA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH3PR10MB7329.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: W8FRydjQzJXd+ufc5qD8A985h1SioqZmEQ3Plyc1uVATBXVfaXMyPX59QuuPTo+WqildX/cYXORDjgXEu4/6NdD4tkTGwQJfglUeO8syAsRtWwZuh5t9GKxWuYHUiszg2PjmmgAc6Ex+zPbCDzpzWlMbhxG/atBzEZwMPlw8u5IY2lRsMEYhy0EhHpoU8q3qvncvL4jEZ7tZBOcbA78DBB2w2/M6BSRxH88WJzHhOF6ZQKBrrtWMVMbncoKxAmLieaLWqthlYEKXN9ExdoS6gFixkHf1fVUx1rvqpQXBBevbS/nA+0UsvTkhwyWjbLBUjw4IIHUi5nKQhmWAf3MkGfgQOrB8dgOFtqpEIDKDvfV0+V2hSskUYr2HfLJkvpkdW507OvwSo+6tkXi7JsbZ6G58gj3CQ/HAjHUxNgz9oTtVvoHm6oAKjFY0waGtO13RYKxkbW4yzEM5iHRmEvpGQBLEDcF0C7yPf0Ck3BEUkBvkzzbCiLXrylBalEvoe4Jn6LtPJcSCARTJPHOcobRFdiTaWhWIVNmfuygjhtGHAJAKVBEEFPlS+Uye/2R7FeYzKQ/dLJ4bMGjviNormq9nKyRJCixi83THfpqtce0BvMRiLvcPumMVikfSNR/q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H5NUUtjnJJKWW5KpURzKAkH7kUgiTAKOkDim7X3CIe8iHoU0HQGdMuQZjANVIoUdKpkP/O8H4twiEacTJ/9R1kQEbNh3UtRdYFD9558VwvHTJggQfN6JHbaqYVl+n/TNF2KdHSoBiXdeK3RcMfWEgD4n+9Vt3VBZovYNOus4CUD/7+noSDXJZN6WjC3cymEbygzQG8qw6E6MHVpwrsHbjkLS8rq/KTZQvTkEqfwIIIXVO1gcWBQsrqBIuCfAco1IgFYhwUZfoD40u26Y8ll5XtPgXA88S4V+2sXWVW9/0naIPncO3ezzm+rue/jG4IK3z++wvOw/mK6CBYE8mfXXu6tQ/IbbUbVI7ZqTXUaLzAlkVsaNX9eNq3Svyvyj7id/ZFBhCPNhKXnLORt7BB7BYup1KvNd2iZI+d9lbjaclQmzI3CDWsfoyQVbSqY7g69xlGXlIhwtqvE9ve5Zpl+BfEoHHN4vYSJplZEoefcZF6eCVOAxLUVzFd4mevwXYgsT382RDrnjzdQYtMcyBQPqUpMhRHxQeATvzlNNLV2QjWVcqqIFmImPmwBBYH1jOoo5qUz0TrlKqaIVQHIQK/A= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9fcf6905-33c7-414d-8c43-08dcd1780cc9 X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB7329.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 09:07:52.2326 (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: yqcM0bF43BxkR2UWgQpLZd039vDlqSxgbtIzYNWdXC7ZJINMehWmVk/eR5dItQb06zEpYcUnc/mpwAW4nrx+GPPti3EvD1ZNhXfGm64NGOg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR10MB7163 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-10_01,2024-09-09_02,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 phishscore=0 mlxscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409100068 X-Proofpoint-ORIG-GUID: c8xcuTEOVAU27wWlkckkBijY8atiXZn_ X-Proofpoint-GUID: c8xcuTEOVAU27wWlkckkBijY8atiXZn_ Received-SPF: pass client-ip=205.220.165.32; envelope-from=william.roche@oracle.com; helo=mx0a-00069f02.pphosted.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, RCVD_IN_MSPIKE_H3=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 The SIGBUS signal siginfo reporting a HW memory error provides a si_addr_lsb fields with an indication of the impacted memory page size. This information should be used to track the hwpoisoned page sizes. Signed-off-by: William Roche --- accel/kvm/kvm-all.c | 6 ++++-- accel/stubs/kvm-stub.c | 4 ++-- include/qemu/osdep.h | 5 +++-- include/sysemu/kvm.h | 4 ++-- system/cpus.c | 6 ++++-- util/oslib-posix.c | 3 +++ 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 75d11a07b2..409c5d3ce6 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2836,6 +2836,7 @@ void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu) #ifdef KVM_HAVE_MCE_INJECTION static __thread void *pending_sigbus_addr; static __thread int pending_sigbus_code; +static __thread short pending_sigbus_addr_lsb; static __thread bool have_sigbus_pending; #endif @@ -3542,7 +3543,7 @@ void kvm_init_cpu_signals(CPUState *cpu) } /* Called asynchronously in VCPU thread. */ -int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr) +int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr, short addr_lsb) { #ifdef KVM_HAVE_MCE_INJECTION if (have_sigbus_pending) { @@ -3551,6 +3552,7 @@ int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr) have_sigbus_pending = true; pending_sigbus_addr = addr; pending_sigbus_code = code; + pending_sigbus_addr_lsb = addr_lsb; qatomic_set(&cpu->exit_request, 1); return 0; #else @@ -3559,7 +3561,7 @@ int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr) } /* Called synchronously (via signalfd) in main thread. */ -int kvm_on_sigbus(int code, void *addr) +int kvm_on_sigbus(int code, void *addr, short addr_lsb) { #ifdef KVM_HAVE_MCE_INJECTION /* Action required MCE kills the process if SIGBUS is blocked. Because diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index 8e0eb22e61..80780433d8 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -38,12 +38,12 @@ bool kvm_has_sync_mmu(void) return false; } -int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr) +int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr, short addr_lsb) { return 1; } -int kvm_on_sigbus(int code, void *addr) +int kvm_on_sigbus(int code, void *addr, short addr_lsb) { return 1; } diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index fe7c3c5f67..838271c4b8 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -585,8 +585,9 @@ struct qemu_signalfd_siginfo { uint64_t ssi_stime; /* System CPU time consumed (SIGCHLD) */ uint64_t ssi_addr; /* Address that generated signal (for hardware-generated signals) */ - uint8_t pad[48]; /* Pad size to 128 bytes (allow for - additional fields in the future) */ + uint16_t ssi_addr_lsb;/* Least significant bit of address (SIGBUS) */ + uint8_t pad[46]; /* Pad size to 128 bytes (allow for */ + /* additional fields in the future) */ }; int qemu_signalfd(const sigset_t *mask); diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 9cf14ca3d5..21262eb970 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -207,8 +207,8 @@ int kvm_has_gsi_routing(void); bool kvm_arm_supports_user_irq(void); -int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr); -int kvm_on_sigbus(int code, void *addr); +int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr, short addr_lsb); +int kvm_on_sigbus(int code, void *addr, short addr_lsb); #ifdef COMPILING_PER_TARGET #include "cpu.h" diff --git a/system/cpus.c b/system/cpus.c index 1c818ff682..12e630f760 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -376,12 +376,14 @@ static void sigbus_handler(int n, siginfo_t *siginfo, void *ctx) if (current_cpu) { /* Called asynchronously in VCPU thread. */ - if (kvm_on_sigbus_vcpu(current_cpu, siginfo->si_code, siginfo->si_addr)) { + if (kvm_on_sigbus_vcpu(current_cpu, siginfo->si_code, + siginfo->si_addr, siginfo->si_addr_lsb)) { sigbus_reraise(); } } else { /* Called synchronously (via signalfd) in main thread. */ - if (kvm_on_sigbus(siginfo->si_code, siginfo->si_addr)) { + if (kvm_on_sigbus(siginfo->si_code, + siginfo->si_addr, siginfo->si_addr_lsb)) { sigbus_reraise(); } } diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 11b35e48fb..64517d1e40 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -767,6 +767,9 @@ void sigaction_invoke(struct sigaction *action, } else if (info->ssi_signo == SIGILL || info->ssi_signo == SIGFPE || info->ssi_signo == SIGSEGV || info->ssi_signo == SIGBUS) { si.si_addr = (void *)(uintptr_t)info->ssi_addr; + if (info->ssi_signo == SIGBUS) { + si.si_addr_lsb = (short int)info->ssi_addr_lsb; + } } else if (info->ssi_signo == SIGCHLD) { si.si_pid = info->ssi_pid; si.si_status = info->ssi_status; From patchwork Tue Sep 10 09:07:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Roche X-Patchwork-Id: 13798146 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 6A112ECE582 for ; Tue, 10 Sep 2024 09:08:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snwrC-0006OO-Ba; Tue, 10 Sep 2024 05:08:19 -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 1snwr0-00067b-Qw for qemu-devel@nongnu.org; Tue, 10 Sep 2024 05:08:06 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snwqt-0004Hf-6i for qemu-devel@nongnu.org; Tue, 10 Sep 2024 05:08:02 -0400 Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48A8uEWS003988 for ; Tue, 10 Sep 2024 09:07:57 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-11-20; bh=lTEL6i972hm0brpxKiBCC5Jh/AaomVcIwAnTkmwuThc=; b= LY2kmDN8nLq7iyA0nwMbX2jxE7pGFV7vOw033IcKjQg9B22wJqn8vWTRC98ysNmd hYReeMGVaKnOWYhVueD8Y2mu30SA4HrZ9FGxIAgUcGOou0FBjem1QUOvOH1Sygci NJ9aseSezDYPGtGSvMVnyjXYkPzWVbbxbWEJFgdM1D4gy54qJpamBLE8nQF03EIU u7lL8l/SoeTmZPhviaBrK29wzYyuT+vtddU01IGT/6Zm8rvNxp0WwinTP5k62P2r YZ2fhFj0ZLJ/e+yuVzWtynYQ1Gj6mragYcpkwWg+/FiQ3juuFB9/oevw91pJCm5T MwG15K0Cco4ZBnH0TI1aOg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41gevcn1b9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Sep 2024 09:07:57 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48A7giFs019825 for ; Tue, 10 Sep 2024 09:07:57 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2175.outbound.protection.outlook.com [104.47.56.175]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41gd9esdc1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Sep 2024 09:07:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ER0bIrNJNLZoyRP+J6XAScN35mdL6+DWMgCqwKOM1emzv9agwikwTnQWI/YuGoffY8Gc2nyQJuURy9Yjwazv7Ifl5AkgD31sjzSdE1zfS/yz35bz8clxKmwHs0g/5Un88Q9CtM3Vx7uINLjdwWFIWUqO51mfAqNAIrdSgqAHQRCBqPBBym1kFWkhaqQiXEcvLW0ApANDoHGdX4KxKJf7h+Jvfrnd9EotvI6ZBOWXDkgN8qaFK0Y/YUlxS+mn3Kp8k05SAPMSZ7if8xpsYghhoq0sx/mAXM2PUlWl6nnexPyTilUXJppN6v9yqh1sRTFkeqVFta+rnsPdGXXJSfKPkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=lTEL6i972hm0brpxKiBCC5Jh/AaomVcIwAnTkmwuThc=; b=sOYtN7tOU617TrCsWgV8J0JcsbdvMjzokAVop12/r5eeqoAtbExqwhUD3LJaZognEyH2lRywVfEo3A7vE/4J49ecCO/+WTYlXbwG/qP0ogqztqk0UrAlvjqMFlX0ns0Awl+I1hxV7w98YGbegzZc0EzpBbhen6woOXjdDJe0+P0Di0BjAmpdcpBYecnWAHD8P+ztQxHBXeNPNJZPoMjpMFVgIh7StvD3QgGKmUIU8GRGTeMhZkjekuEZB9joyXWVk1x6O6RDUlKDngAR0lD/CgwdTFt2luoSleatDMaWWPz4AFFdMrCBm2bX68QLTqHl7Rhbh10BWBHAujm9KkGszA== 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=lTEL6i972hm0brpxKiBCC5Jh/AaomVcIwAnTkmwuThc=; b=yU696/foQWjpkiYBz68Hn0ggIfpYJo/lwOareuG4nnwUrm+0MQAcjKXQoyd/qF5clX6rTR9g+0BfR+MBn2nkpfEgHMkxgc3J2Ln6THJescllrEuF4LJzJeTypF2wkE0SkKpN5u0ga4UTeMvNZ4Y2mOpQPZQbJ+hcGHiz256kFRM= Received: from CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) by CH3PR10MB7163.namprd10.prod.outlook.com (2603:10b6:610:127::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.16; Tue, 10 Sep 2024 09:07:54 +0000 Received: from CH3PR10MB7329.namprd10.prod.outlook.com ([fe80::f238:6143:104c:da23]) by CH3PR10MB7329.namprd10.prod.outlook.com ([fe80::f238:6143:104c:da23%5]) with mapi id 15.20.7939.010; Tue, 10 Sep 2024 09:07:54 +0000 From: =?utf-8?q?=E2=80=9CWilliam_Roche?= To: qemu-devel@nongnu.org Cc: william.roche@oracle.com, joao.m.martins@oracle.com Subject: [RFC 2/6] accel/kvm: Keep track of the HWPoisonPage sizes Date: Tue, 10 Sep 2024 09:07:43 +0000 Message-ID: <20240910090747.2741475-3-william.roche@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910090747.2741475-1-william.roche@oracle.com> References: <20240910090747.2741475-1-william.roche@oracle.com> X-ClientProxiedBy: BY1P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:59d::17) To CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB7329:EE_|CH3PR10MB7163:EE_ X-MS-Office365-Filtering-Correlation-Id: 4caa6945-3fc0-44f6-bff4-08dcd1780e26 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: DXpgbSNdZGSBudWcq2XfMht25kCCnJxCpTQk3Uhv6vkSNRHXiQtKKJ3MCP7T5C4G+PltlDFsAgz8gSLU52+6q8tiMuSASeOa+89nz5oJR4HEYNkAwN1+Gr304ob5RaJEM5YBh1wlA5NpjkLy9Jn5ovMtihXHINYj/WNkFb3gAxfq2kwpzQf/YaZsOwHmTTB7zR/LoVwwH6diHjjgDDwxXicj4WlXUEgh9abZyb2NXgwM/mjrvk4P3fEjUhw6lfITAKVQ4GybyNH4S2ezSnm5DlE6I9QitvZ9vwourYYunIFbPZxAU3P0HMeN1zTlnc9lH7seRpHloreFUA0OwJF3RcrKyMSt+Sg1Is5VXslvBt8vAKfyhSHKPahiNbkcz4m68qOKEWXsdmC6RetYsQUeDDZdX34yPpJA5pzTh9ygFv+MhWOv0ES8Ib2yoCeGFNCRZ1xhx4IU/zfGmg8R06As4zUegl4WvfcKasCJk74vCy3amLri94Eski55o2I2I2d8Rs1UDbQT4oy9DsnwSYaajFnEtz75p6rwN/oIxQbHln9e74+oWFEVlhLMPd6FsNfMJ2vz/x5N8PgqVE/fy+U28euH+bfcvKgN1lfOqZ4iKVmFNT0ojpumFB75bypPsJ9kmAYNxZK9dxMFlEJaTlf73vi5FIuIWMrwndphc3WsgAYY9DiVLNAFDaGIuvQ6H1Ipw2+ecxmdUOeUhBJP+M5hQHzQQUCMHcQP2Jms1b1FIVcoCyerQvgO0JTrgX96SWUqH4We4ciGtxkPig86o+nZmy+mPCtlqr4Bv8bU7w1ZzX7QxI561oxBXEJJUUGA/FK3wuO7qrbpNlycsdm/I/fii6o/2KJtbsEILXZDImUDODtSd9kNVBOa04p0wRSGE8Hu2h1+TkLP4Ib7NcVD6X0nbW0WNDrYt5cSr7WJHGE3iaNXv14lXvXklqUdIy48n6Lx0pcnWJHmumHB7JThkHO52Hv9F6iqb7HM9yBHNoMkAnvksEPtGUGWaLpDkt7GPMdY6wYLkB7BNd/sMmGn+4AoXWmdedVb53BqqJc87llkrQQjjTVMnZ2Baq5uGbJ3S5oJOXFRRF8szHw82o2UM0ED0jN0xUxsT2t9GYGRCdqmTHgkb502+2WzC/FfUw7QmDjWNuG/AKXfCk/CcQhV4fY17nMV56wKdjjpCHzgqcUGZdmJG9oo5uY5QNPcF4/ksMcjAfNn/jBGCPj4DZp0lCLi622Vg9b3WB0fhCrccwAdo8MSAc6Jm1lUuXDa4riU+oQbRvA7iSZnzHHTMBvJjKHZLu034KAZmrppzFJSd/P/E08PRuvQPd5UMMk5GINkKUTOswXbiQZQsff6V/iB/Z8nlA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH3PR10MB7329.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Aqhq+R/HFnig7EFL+HH0f5mBZBdHfFcTO1D465jHhbwOkCz0WlrTvHGwMmDCMDI0DaCy8EE6OiYTu3C6ahcUi3aRMhTWgtJeBJ67A9OeNGlOmR9zk7CCEYuun1IWwKSwyEFO/yD6iIIFPIU523wlwEd5KfyO3l4TvbaTfw187vsJWw2gr8ooGkBTvcDP3D+RMCXzobzN+8SyQT9+Y3KvOd9Ogo+UdHpLQejSEgCTVwK5jtV+7eYxavbLiXFEAB9rFt3R0nUlDM2HKA8T7fDN+soZ5SqdXRLWBlIi6VOcSihloV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Y0CFIWjU4Yx8wcrLIp4Hzi0D2VKN6BDdP0SKLmxmP3aQaT7RxEsVTk/zs7ELJu677uYCDzSoN+pg+6OzCZJer8iX/tWS38ZLQ/IcioqbrTup+cWhYjiZnoCFUP97eG/Bz9AkYXWEwKalDl/SiIs54hLLR1MsTP8r2nbCJ3BdtNZoCVKI5kDEHnhsF6UCEd3sNPUU06dXnZ244f2njCLhod6OyEkK/imJNjBq/nTUWXZlnDewiajytvslzSsTkVp92kzb/MQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: O7ADp0MI2I4COvJahpyOnp2brwXlooHs3CGRCaGWZf3IuzLNh4l5Ag/FNHiSusalHYzhaLI7A9XDsK+dqhrWOWr4XzanJNeKrwPKFTPEf7XSnlWl7Gn9MPw+yHSxFelqJBS0uH+RQ4jUmtmPkfJ+Sm+bt2PfJHAIuqfevAdxRrgp5pW3tQzn3m8n3ivZWGCTqulu0y+wXyVt6vU3visom687dH/92qqFSG8/rT/YDRIEIQxguGtFA3KCpUPFRNaXvXLdETQzz/cK3huI3Vr+TiANqEwMiL/VpMYYOVX2XYx+JqGTfDIH90Yi/qGOWntAMzP3OsCwiJ7CRsJfnOgE87HOO9skEiajYt/FGJQsWm+0/rbKAlbdOir9n99L2+/latW2/QCrmWGY7si4VS0NaVgtTZmImtZjasFJR/f9hAtIEz/ZAo3Q/yh3raDPJKT3Yd3dtKlu6QLv7BTSLHNkgtI6bs7yImV8VvN9S7UycqmhWWPEv077Bz8lYYxaOoGVUogutvu/vo41rP2PQWSmjzI8sqA+nKQ25QQUqcwYzi8g8nGewfPpGjj4KfDJcoH/CZu705/ZWtfxAyDshedPRpVOUIolDPejx3WPVdb5kpo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4caa6945-3fc0-44f6-bff4-08dcd1780e26 X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB7329.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 09:07:54.5060 (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: GOSZQ8UfLlR5Q6QZvjMPJILjrGvLebHVdk9kLkvbAG9I8wqB6j62uYWpx1i7ODJh4JVd3BoJ/aexwZCkmnJZv8iWB69oMAj9FEyTJ+2hLC4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR10MB7163 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-10_01,2024-09-09_02,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409100068 X-Proofpoint-ORIG-GUID: 5NHfYzZ4zghzv3FwKEz2bQOv-tfE2E95 X-Proofpoint-GUID: 5NHfYzZ4zghzv3FwKEz2bQOv-tfE2E95 Received-SPF: pass client-ip=205.220.177.32; envelope-from=william.roche@oracle.com; helo=mx0b-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_H4=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 Add the page size information to the hwpoison_page_list elements. Signed-off-by: William Roche --- accel/kvm/kvm-all.c | 11 +++++++---- include/sysemu/kvm.h | 3 ++- include/sysemu/kvm_int.h | 3 ++- target/arm/kvm.c | 5 +++-- target/i386/kvm/kvm.c | 5 +++-- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 409c5d3ce6..bcccf80bd7 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1200,6 +1200,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; @@ -1212,12 +1213,12 @@ 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); g_free(page); } } -void kvm_hwpoison_page_add(ram_addr_t ram_addr) +void kvm_hwpoison_page_add(ram_addr_t ram_addr, size_t sz) { HWPoisonPage *page; @@ -1228,6 +1229,7 @@ void kvm_hwpoison_page_add(ram_addr_t ram_addr) } page = g_new(HWPoisonPage, 1); page->ram_addr = ram_addr; + page->page_size = sz; QLIST_INSERT_HEAD(&hwpoison_page_list, page, list); } @@ -3031,7 +3033,8 @@ int kvm_cpu_exec(CPUState *cpu) if (unlikely(have_sigbus_pending)) { bql_lock(); kvm_arch_on_sigbus_vcpu(cpu, pending_sigbus_code, - pending_sigbus_addr); + pending_sigbus_addr, + pending_sigbus_addr_lsb); have_sigbus_pending = false; bql_unlock(); } @@ -3569,7 +3572,7 @@ int kvm_on_sigbus(int code, void *addr, short addr_lsb) * we can only get action optional here. */ assert(code != BUS_MCEERR_AR); - kvm_arch_on_sigbus_vcpu(first_cpu, code, addr); + kvm_arch_on_sigbus_vcpu(first_cpu, code, addr, addr_lsb); return 0; #else return 1; diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 21262eb970..c8c0d52bed 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -383,7 +383,8 @@ bool kvm_vcpu_id_is_valid(int vcpu_id); unsigned long kvm_arch_vcpu_id(CPUState *cpu); #ifdef KVM_HAVE_MCE_INJECTION -void kvm_arch_on_sigbus_vcpu(CPUState *cpu, int code, void *addr); +void kvm_arch_on_sigbus_vcpu(CPUState *cpu, int code, void *addr, + short addr_lsb); #endif void kvm_arch_init_irq_routing(KVMState *s); diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index 1d8fb1473b..753e4bc6ef 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -168,10 +168,11 @@ void kvm_set_max_memslot_size(hwaddr max_slot_size); * * Parameters: * @ram_addr: the address in the RAM for the poisoned page + * @sz: size of the poison page as reported by the 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, size_t sz); #endif diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 849e2e21b3..f62e53e423 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -2348,10 +2348,11 @@ int kvm_arch_get_registers(CPUState *cs) return ret; } -void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr) +void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr, short addr_lsb) { ram_addr_t ram_addr; hwaddr paddr; + size_t sz = (addr_lsb > 0) ? (1 << addr_lsb) : TARGET_PAGE_SIZE; assert(code == BUS_MCEERR_AR || code == BUS_MCEERR_AO); @@ -2359,7 +2360,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, sz); /* * If this is a BUS_MCEERR_AR, we know we have been called * synchronously from the vCPU thread, so we can easily diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 2fa88ef1e3..99b87140cc 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -714,12 +714,13 @@ static void hardware_memory_error(void *host_addr) exit(1); } -void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr) +void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr, short addr_lsb) { X86CPU *cpu = X86_CPU(c); CPUX86State *env = &cpu->env; ram_addr_t ram_addr; hwaddr paddr; + size_t sz = (addr_lsb > 0) ? (1 << addr_lsb) : TARGET_PAGE_SIZE; /* If we get an action required MCE, it has been injected by KVM * while the VM was running. An action optional MCE instead should @@ -732,7 +733,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, sz); kvm_mce_inject(cpu, paddr, code); /* From patchwork Tue Sep 10 09:07:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Roche X-Patchwork-Id: 13798149 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 985C7ECE564 for ; Tue, 10 Sep 2024 09:08:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snwr9-0006Mn-FS; Tue, 10 Sep 2024 05:08: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 1snwr2-000690-1L for qemu-devel@nongnu.org; Tue, 10 Sep 2024 05:08:08 -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 1snwr0-0004Hu-CB for qemu-devel@nongnu.org; Tue, 10 Sep 2024 05:08:07 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48A8tZNe002423 for ; Tue, 10 Sep 2024 09:08:00 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-11-20; bh=iUpJfFkmzvcResM42CgeM3OXvVIAkS6DqN2a6mWjScg=; b= FMbE3HIOMm8HBhWuhhfHzAj53rFgU30ytjYemz29q9Xx8+x4lxskKQnzzfry9ah+ U9H4soCC/yOHVkCz8RwJu+kNfWuukAmYK5WUS8TDxmH61nbxAgN/fJZP5YGL4rWf 2ksUr6HqxQ9jlaKGGTzx9yfigOyrIuzCQ7RKUj+iKwmCRbChING088i/jJvQ200L aQwHT3dWajpJQ/nW1qiz3sU5uk7iPe2nhIkoTL1eNZT6aF5sOk2BU6S70KC7yNZo O1ha3/bZmSmMn40Y2C3P+akvTjp16ENvXLNuwWVFhJ+2LWbyLZ0idRZSIJuRTThQ Llcc/SuyBC48MmI4yf6piw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41gfctd0n4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Sep 2024 09:08:00 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48A8j1T5006205 for ; Tue, 10 Sep 2024 09:07:58 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 41gd9898dk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Sep 2024 09:07:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ljuja7oc5Ezh3JCGAq27UPv1l7HS3feANmX5Gk1PDwMA/jLu50MPIdy8Y8dJ9cIjqkd399Ef4YhstL05/M1HzrKOEwB4JQM5fx6r6QxhqB1Fuyn1Kr3J1yLQSvkwQWMlDUDyXaiewH9T1lRA2O+V5awp9gQRu8rOx6UtLNFH6ifZIFGZIY629Pw52eHEw8HlcsxYGPr0J6E+UI0hgIa/nl3UvgrgmCnB0XqOkrh6I/ufkMAxFx1dhYUrUVYcZvJGS38Cm3ENkRDzAA3mU+e/TcRqNcosfqDQ1j0uSme8XQUivuNBvQYiurMAQZ3e7tHmATA/20ZPi29iPPhmEUwnJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=iUpJfFkmzvcResM42CgeM3OXvVIAkS6DqN2a6mWjScg=; b=MqaqikAQYywd3E7Wmd25p4EWt/f92Ufc0Nq/cdIPk7ObUlYrAI9FlwEpEFG6Qg+36b8stHXeyyk/apMeOF1+N9MsSnUFpc9JzCH9ImlQ+WJFgcQYT8rFRsMipccylTwHs/kVYmvrw9F8UZaR2C6c4/P0LDnhKyYr0U3lG5Q+AaiNwPnCuD1JFWsh1WKzSC0MJBmcBZaYwnwbroJVESR1/iv4InAyXYM5tFmX9+OXwJnBf5+0Q6aN4dSR0j+WQSJKhUFKeZYIMdtqjWUaJ8r+0pigbxlCgaTvkUCFTafX0kuMr7UsX9ZTUEW8jBRUx4VJz2S+Z3+0kFvntP8y9sCeUA== 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=iUpJfFkmzvcResM42CgeM3OXvVIAkS6DqN2a6mWjScg=; b=zX1fKwNu4hDWFpQO9j1g+qK4eTFvJz/gP4gYPQaiALxKB9wuEr3rHC8HiTPNi0ok9ABrwiAYVllSFc1suewXSBPxSJ1FBOg+nnlOf3He5DmBxGFdwrAsVDhUUN/xVA8fkPISB/SqIt3GFUyiGqDQXC/v8buhp5jBCIgwo8RNVIk= Received: from CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) by CH3PR10MB7163.namprd10.prod.outlook.com (2603:10b6:610:127::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.16; Tue, 10 Sep 2024 09:07:56 +0000 Received: from CH3PR10MB7329.namprd10.prod.outlook.com ([fe80::f238:6143:104c:da23]) by CH3PR10MB7329.namprd10.prod.outlook.com ([fe80::f238:6143:104c:da23%5]) with mapi id 15.20.7939.010; Tue, 10 Sep 2024 09:07:56 +0000 From: =?utf-8?q?=E2=80=9CWilliam_Roche?= To: qemu-devel@nongnu.org Cc: william.roche@oracle.com, joao.m.martins@oracle.com Subject: [RFC 3/6] system/physmem: Remap memory pages on reset based on the page size Date: Tue, 10 Sep 2024 09:07:44 +0000 Message-ID: <20240910090747.2741475-4-william.roche@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910090747.2741475-1-william.roche@oracle.com> References: <20240910090747.2741475-1-william.roche@oracle.com> X-ClientProxiedBy: SJ0PR03CA0009.namprd03.prod.outlook.com (2603:10b6:a03:33a::14) To CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB7329:EE_|CH3PR10MB7163:EE_ X-MS-Office365-Filtering-Correlation-Id: 258c3698-79e9-4cee-36cf-08dcd1780f70 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: Eg8FkcKCsLL8jMmOd7zUdDVAU0lSLAGJGH999dLg1H4BG9TZkHlGSUWzhelW8D0xspavkqiIkCnqenLSV7kbJWCTGw+WZGLGaQYpeQ7nHbWnuvaSsFvLBMoVtgkkbAuWjdf7HecBvRNoB3dkV01o+afk3h13ZzKSlMXHfMpG2cdESIArQnpre3IvojpCOKd/7Bzz6ukfGvttQoCQKb7CZI8109Xy84SYkUm6F4n3K1z62GZzaweUzNAhya54SvQyHpfOrQl6Eg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gi8Qe4nSEuBnTw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH3PR10MB7329.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8ainwrLeFVwJGN/fWTwraYnFKtUm0+/BB8NG/h/0GYwTEMLon+3vv1quhFq9/Q4F2UW7+y23+XgyKlztcespG7ez1cBUiSTNPy+HZCW6zbf6ckHpP9dWI8WPrUxcdkJjMPKrftD09k8G5Qsib8KvXerIrAjHfR0X325P3ta7BffuhaAvIo26l1MG8PyQx7yZhkb8AaRKa7RDuy/Q8RfGIRPUUmd4h+KBb6YAX0oF57cmQydTy15+bP+Rtm8yJ2bcoPQX1vzRjqBU2RrWWjBIqeK16n9t5efxKKBX61iByf2naVdxsn2kGqh9u6dMNCWWoRV3eZ4bbpRZQ6NHDEq6D8K0gZ/LlybT5o9CBMU8sz1i9+RNk8HYkyrh8Kx7JLliw9AQT14H3HgOyLasD98K/uQsfCXp5+1vPAaPQKh9QR6lH+ReK2uZJKae6ekMVRl4NNPviGYk8VLdLN2ESTiuA5HPyfDhIW8Bk7m9J6JkK5HIRD0Lra2lfotlRv+U3D31XtBjdar7UZdKqJ01LC+ZbTGH+e6arGwgZax1N1P+O8BdBTquC2HDXyWP+0/QG0yhirDTAPJZXJ2hg/PTN/YkYREztxCesSXYsEUg4gLi6TAyW8+gxIYnxN2eprS22Rw7BA9/YHd1N6iET4qJKZe1fjVM63GjEkp8yJFrE3VWv6L1rGmqNwTcg5co7JCWmY/Gc6qSi/AaT3WR13ck44YT0gojNfZKNa08aIwEwcvfFSGsUQ1Mr+BSDof6KsRye6s0kcMu5Xc+T/9MDmhGd37e79v6fFWPhuNAa5O/dfektywOgihhbcfiBysiMdzXZKxLyKGxswaH+ESWZX4YM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XTyh1kzC45RZL8ZS2faOEJhp+jeKIZ7mq5/jqOVfw9kdQWsw+2P+g6g4RTvHu5NZEO/wDe01a7mtJ7Vb2jaN5NUez7l1zyuAAoDpPvUqu7E1VIKTZX6WFREztlI71uh2i63oORl0rWc9bgLlsaBqvHHcIFhkKicjUwEFTIx2uk9AaYQyd08AsnoVHonL9GNmn7vIIZD0T/5aaARpbFAYaB9AF0zvh7kNwaUu08PXlJ/9cU7n0oLozveVY6iRipnmcd3DvRwxKCrRDYUYIFE0mjUS18HW5ADh+YTepoSdl0GD+SRrbDu5NM2slctd/fcOJFb6p9E7AxYAbKA5F2dVLoE7J9T3+CBjYBILy9U7imH+cQJ+4MgEQzUrCyz7JNN+ajo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 258c3698-79e9-4cee-36cf-08dcd1780f70 X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB7329.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 09:07:56.6808 (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: wqQxxgEBcSx4MjavdReb9lj3voFqoXsKVf6HSkQv6SvQku4lmcki1r6pnLH9d1tBGzYFLWQnFrOGOVvL2RZ3yC44Q6SeKH2o3g6hfzdTxmw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR10MB7163 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-10_01,2024-09-09_02,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 adultscore=0 phishscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409100068 X-Proofpoint-GUID: NncZa5EChgctiqQ09YiMqhw5G_r9Dbti X-Proofpoint-ORIG-GUID: NncZa5EChgctiqQ09YiMqhw5G_r9Dbti Received-SPF: pass client-ip=205.220.165.32; envelope-from=william.roche@oracle.com; helo=mx0a-00069f02.pphosted.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, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TVD_PH_BODY_ACCOUNTS_PRE=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 When the VM reboots, a memory reset is performed calling qemu_ram_remap() on all hwpoisoned pages. We take into account the recorded page size to adjust the size and location of the memory hole. In case of a largepage used, we also need to punch a hole in the backend file to regenerate a usable memory, cleaning the HW poisoned section. Signed-off-by: William Roche --- system/physmem.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/system/physmem.c b/system/physmem.c index 94600a33ec..5c176146c0 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2195,6 +2195,11 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) RAMBLOCK_FOREACH(block) { offset = addr - block->offset; if (offset < block->max_length) { + /* addr could be a subpage of a former large page */ + if (length < block->page_size) { + offset = ROUND_DOWN(offset, block->page_size); + length = block->page_size; + } vaddr = ramblock_ptr(block, offset); if (block->flags & RAM_PREALLOC) { ; @@ -2208,6 +2213,14 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) prot = PROT_READ; prot |= block->flags & RAM_READONLY ? 0 : PROT_WRITE; if (block->fd >= 0) { + if (length > TARGET_PAGE_SIZE && fallocate(block->fd, + FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, + offset + block->fd_offset, length) != 0) { + error_report("Could not recreate the file hole for " + "addr: " RAM_ADDR_FMT "@" RAM_ADDR_FMT "", + length, addr); + exit(1); + } area = mmap(vaddr, length, prot, flags, block->fd, offset + block->fd_offset); } else { From patchwork Tue Sep 10 09:07:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Roche X-Patchwork-Id: 13798150 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 3BE13ECE582 for ; Tue, 10 Sep 2024 09:09:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snws2-0000Xj-2c; Tue, 10 Sep 2024 05:09:14 -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 1snwrX-00082T-Io for qemu-devel@nongnu.org; Tue, 10 Sep 2024 05:08:46 -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 1snwrS-0004J2-Tl for qemu-devel@nongnu.org; Tue, 10 Sep 2024 05:08:39 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48A8tX3p008899 for ; Tue, 10 Sep 2024 09:08:30 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-11-20; bh=liLEVMlOxr9MKo9jga2VkXBGye4xwDKxHC6nl8W5hQ0=; b= dCzVGeWOOerQi+3d9Xljw+CMcd0A2yD+cBrA5emaqmgQ49bd6v6dLgn12hi7AHnU 6+McOcYHUwbN8csKI/W1xuDiJm6hc7wJUEXzFVT89NnSdVOpmLmOjg+lslRjHPUp R2z+GQz5WqNgT36TAvtmtJDycGaP8I866uo89wFINFxOxuTalPsAwZ0jrGG6r6ZH cnHwSjqiOg9d+mm574aqFZ4HsofYl49t71HWe/aH25Yr53UWEDfkGhNqhqX+Vako /Y7T/uLVTYV2DPSb87Y1uMvIY5gdXOR4W4+pDzLDgQNCPBFkGmpf9/7ZJkib1tvj +Gxqg5kce5kYlty9aCdwqA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41geq9n07s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Sep 2024 09:08:29 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48A8ao8Q005070 for ; Tue, 10 Sep 2024 09:08:28 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 41gd9898f7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Sep 2024 09:08:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FkYeC7kzX6T824Ydx/cBoQWe+xy6T/SIgzrmxxji64fdoaJLA78HE50i3XFzoZn6YIGZeD/UDXw5nSNY6df2K/8gFh+dXxlOeuX6WRDRICbR2gC3hJA2jNVOADH0D/iTHaoLu+YKs2gMfliu7QmNlyVB8mN5bdXaDDp9+x63P6BUAJoBTeR3M2cwTuB54zjCWtOqFmxvNzrYxTX88iDzYgaZNBZhS+VEKZ1yAtRAT/Duuk22duJOu8K1WRi9tluydq1bEKpkO9PcYR7wTLdHWGMoVKD5s4jzlV2g7KbxB9UNEg3NKppc1BeI/lxJRK4FVoueSJUcxXEWVxj3AqfLEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=liLEVMlOxr9MKo9jga2VkXBGye4xwDKxHC6nl8W5hQ0=; b=eB+VvMTODSEIbC2OSj8St9lVrrMhX239nXCRK7qTK7Zq1Zgq4AAVsh8+o6OA4d6KBMD4aTHV/qfVwVlJGPsUJK57l0MSgZ/+h/uXiUUM4Qr7Xoo+j+uuPI7RJnSrjyiC3gkoFpz49RuCBqmeUPSPqwldah6zBHgWIBG6IZLSEX0FLKytz33phWjyVlVoVLBlc5VXo6oTApBXxakvZE7doNghmmqbajeg68tXoaDfa0ZqpBW2XRkbahMjhCr15q6w8i1eN8pBrd2qxcC1396czrJNlcHm6f5UcXL3AzrS/vqWHPNh+jKjszoOD8w0dllqOc5WZZZ15YyEIW+MOHgP8w== 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=liLEVMlOxr9MKo9jga2VkXBGye4xwDKxHC6nl8W5hQ0=; b=N12FsnwJi0G8G0vqj67W2bloEVXZuXRwCVxGpb0B1KTBIHsYXwTnABSQ4l9k6gR0+S83CjI2MN19JI/s1hU77/sJZcIFUhDa1zajE+6CvBC2erNLGU/lM1ILNFcWQ35EJCn6UaQEzth643eY0KRhLOyLqaWyoHCwlK+b9bRC57o= Received: from CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) by CH3PR10MB7163.namprd10.prod.outlook.com (2603:10b6:610:127::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.16; Tue, 10 Sep 2024 09:07:59 +0000 Received: from CH3PR10MB7329.namprd10.prod.outlook.com ([fe80::f238:6143:104c:da23]) by CH3PR10MB7329.namprd10.prod.outlook.com ([fe80::f238:6143:104c:da23%5]) with mapi id 15.20.7939.010; Tue, 10 Sep 2024 09:07:59 +0000 From: =?utf-8?q?=E2=80=9CWilliam_Roche?= To: qemu-devel@nongnu.org Cc: william.roche@oracle.com, joao.m.martins@oracle.com Subject: [RFC 4/6] system: Introducing hugetlbfs largepage RAS feature Date: Tue, 10 Sep 2024 09:07:45 +0000 Message-ID: <20240910090747.2741475-5-william.roche@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910090747.2741475-1-william.roche@oracle.com> References: <20240910090747.2741475-1-william.roche@oracle.com> X-ClientProxiedBy: SJ0PR13CA0090.namprd13.prod.outlook.com (2603:10b6:a03:2c4::35) To CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB7329:EE_|CH3PR10MB7163:EE_ X-MS-Office365-Filtering-Correlation-Id: 5413426b-1433-4693-3529-08dcd17810e0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: Sjv7ZSEn/PK9i3s08k/qiIw0d1M2nEIoJ9Ynl3vjaD8LZBW0etIboOcwVdPSjSMPgapmP8Oe80nLJ61/azuu9iteOW3KCDIXO8TMBxwu80rVzpXASCAehbpaO1Na85Vc14fsnrH8TRYE0XiKUiILRtb7IJMmPIi7Y9/3lrYJayKWMzCUOtAs3gOT6mZuf4j2mgB6lM+fGX/l0VuQ13q6lYFct786pwjXZF/X37gD95Drx5F95K0rPvZxWRZEle0uvmX9kbtRTWFBPn3hkwECiZxvGROlAHdCRFK0L0knlciWOsam5cog7ECwSWId+pSJOvp/l0tJXyfLLhgnP8Qw53p1jLajAgNtGcsIJcKVSfUGe96BZ6bzQl6nj1t7nvaEZNh0m2gj6bLbRUvsF+i9mQ0ywocTCSZl289dYfmT/1FHlXEh7c5/euuUyjEJDaOMGWp54unWDVd16tbLSnj8ymTvHkf8n/94QS8pXok3S95MqxtFNXfKd6lQJ9KQ8siiWQYO0PbdtNIeW9LpZ2IBll+rUHFEwxbZ2fWOjsNoKBJkII3LWpUBiWg+NnrzCYA/Pfl+e47RIVuySx3QEUIpZoiY4+e9YEyAelvkxMxSEEslSfNAdCxKI5Qi309BLLjQhcRV2bmYCu7avlKy2CcjJgt4gvw4K9MbGU0I+jvxFxxKKZ0R3H2GcHd85uH/+1aYG33Za0yoN8kOHfL2TwM0uB4HlRjUBrucdTl6kIyZ94a9gTMX8xD2hXyTCFm6Icg/rNkvP/FYsvIxpYARWz07n5s+U0HQrnxQttmb6e9KNgvk2ySW6JuCVTH2foajKptIqXtykfgmWpqsCi+GD/b5eHS6y/MxpXLUfkV68Kp0ginKfQ4nZvOg/KMF1jx1cnwotwoKz6MnFq0zOl05FitA5Vu1Ga40SZiwc7i41t+ZynFo9GSE26HksdxtOTbsGcP1Vt8zvK76ALolkWJVN/2N0FlHa2rdXcdKlAOLIRkUM/w24LCInEjZQCsKMNuzzq2o4H5LcYpPL5CGWVa5y3sMrWJ/9f61lEisPJC/InhxMFqClmHA+1c9u995ghlxaYi3NLcfuTPaFcnbiLLB55O0qX6g6MldC0vc321hytNt2Wq63XzdORni1BFWzeUtO0nBtoCgUs/yBJO+/4RMJxvX0YSQvaUVriIK4pN+kE355EfY60AutyEB8QkaY5aR9cAMZ9jzslZY/SNbYPGNqzB13B92FdJUaYwKmq0oljKlxPGeAF60tpyBtpBHDmhyh1mW+MZWEjHcR6NmuEyNnoj5nlpqDfrAS7dHPMtj/wVVgcMk1r5iEW8GvRYvRbL5V7dM3Zb5CXph/2qmtbv058VEIQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH3PR10MB7329.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oHFk7eC56sHQU3MhEsV8HTFICi2QPVDJPppZjqiSEI+SkRjxFWB8TfNPU4ZkKcneXkDTZGSz6veXuwIIEQTfHRw/LP8V0z2RtGeCNCYyV8miWDkzLKlm8uzVkIXzVhfiMitBVPMNIKQAWD6ylDvP+cP+ZcJOPzUISs4fDkfyjFVm14ffDPGhwRpIRj3BpLXKpUM/Bh9O+dh1MGDTEIFPOjHW0oq7ZibWtNcEsGooBhMixA5uC+5FKTrjqwD16drHYJl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dll5IjetYnhTTbjYGIvUF2lfMOYlYJ8czcyqG0NcaeaI5Xu+Kp4RKAghpCWlpyl6R9c951KOAywHTlj137I33HhIydZpt3EGt4hkURJ0ADCzSTD6aQ/FQ1mBok+tk58uolEglyL8rXsp5iIew50LZMrZRHcNr7TEseAsFJH4S2NTN1mg6UOZZUr4Cr6ClZdklI+e1uJHAPznsm5P6NEIzI4JQcJgcT5voHovdygApIB9Dsh4C9/DdIU6kjH53UfayV7EH7Gx/pXq23QQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: a6EnIIEQdC52tj5b5h95jcqafrzhusY8twKge3tKO0id+olJNi/WaCf5QsikmxF1PFvbpvmQXykUxpda/JQoQRetxn3tYAjjQVVCKCi/Nj0tio2WoOXCYhI5RZGTNUIajRxP0RUvbQait4M8lFezu610v/aZUrXJl5tqblEjCXhv6X3+Rbdzpr0C53Ovf05cCkwdFdnd0zjruhK4XJAVR1xId0U3+uv5bgRRzC8oKc5C/RmvtrPlP6Hxrc+eSUSFJDJHjIDzukocbAiYl0qtMquxfd7b3DBQBf3ALHcTiiU7MYZWmKPli2y9RGYLRy/MNoXa57hzuetrR/M0U/9zXI8xkX1uniCF0lLPZtm25eeZjLzQRDyePzlJsmwzZIozKcr87w5I7g/bmrVfoSOiuokdtTgsFPprH6qNt/EETZPfnpEcgv1LQpHAHVtJb7r6L/DNE8JEPsMFu6iES2JFJv6tnsaLQyOG0AP5oOseZFQslexFs1zBIXP9sLQyJ7fLQws1/eRVPSX6P8xGZDyTx8plNeTOwC2E2HP7HqMQoWf+izZvMsewVAHQiSn1TaaQp75gZxrqkYobCYX2njXLUHq91i61DM3yygiwUauVgtg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5413426b-1433-4693-3529-08dcd17810e0 X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB7329.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 09:07:59.1141 (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: Fw253IoQYyN9ib2J1IVej/qkFkbTmnNXQgp1CAyonrnb1PKQ0JnQmsLodr0k9WSLZzt4m5py8ozHYSCI+OLNy8byHVvWHi8qxVlf+3lc0gE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR10MB7163 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-10_01,2024-09-09_02,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 adultscore=0 phishscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409100069 X-Proofpoint-ORIG-GUID: esnLY6orywVAZ2wcO01N3OUYV4kDZQ3N X-Proofpoint-GUID: esnLY6orywVAZ2wcO01N3OUYV4kDZQ3N Received-SPF: pass client-ip=205.220.165.32; envelope-from=william.roche@oracle.com; helo=mx0a-00069f02.pphosted.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, RCVD_IN_MSPIKE_H3=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 We need to deal with hugetlbfs memory large pages facing HW errors, to increase the probability to survive a memory poisoning. When an error is detected, the platform kernel marks the entire hugetlbfs large page as "poisoned" and reports the event to all potential users using SIGBUS. This change introduces 2 aspects: . trying to recover not HWPOISON data from the error impacted large page . splitting this large page into standard sized pages When Qemu receives this SIGBUS, it will try to recover as much data as possible from the hugepage backend file (which has to be a MAP_SHARED mapping) with the help of the following kernel feature: linux commit 38c1ddbde6c6 ("hugetlbfs: improve read HWPOISON hugepage") The impacted hugetlbfs large page is replaced by a set of standard pages populated with the content of the recovered area or a poison for the unrecoverable locations, reading the backend file. Any error reading this file results in the corresponding standard sized page to be poisoned. And if this file mapping is not set with "share=on", the entire replacing set of pages is poisoned. We pause the VM to perfom the memory replacement. To do so we have to get out of the SIGBUS handler(s). But the signal will be reraised on VM resume. The platform kernel may report the beginning of the error impacted large page in the SIGBUS siginfo data, so we may have to adjust this poison address information to point to the finer grain actual poison location based on the replacing standard sized pages. Aiming at a more precise poison information reported to the VM gives the possibility to better react to this situation, improving the overall RAS of hugetlbfs VMs. Signed-off-by: William Roche --- accel/kvm/kvm-all.c | 7 + meson.build | 2 + system/hugetlbfs_ras.c | 546 +++++++++++++++++++++++++++++++++++++++++ system/hugetlbfs_ras.h | 3 + system/meson.build | 1 + system/physmem.c | 17 ++ target/arm/kvm.c | 10 + target/i386/kvm/kvm.c | 10 + 8 files changed, 596 insertions(+) create mode 100644 system/hugetlbfs_ras.c create mode 100644 system/hugetlbfs_ras.h diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index bcccf80bd7..6c6841f935 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -57,6 +57,10 @@ #include #endif +#ifdef CONFIG_HUGETLBFS_RAS +#include "system/hugetlbfs_ras.h" +#endif + /* KVM uses PAGE_SIZE in its definition of KVM_COALESCED_MMIO_MAX. We * need to use the real host PAGE_SIZE, as that's what KVM will use. */ @@ -1211,6 +1215,9 @@ static void kvm_unpoison_all(void *param) { HWPoisonPage *page, *next_page; +#ifdef CONFIG_HUGETLBFS_RAS + hugetlbfs_ras_empty(); +#endif QLIST_FOREACH_SAFE(page, &hwpoison_page_list, list, next_page) { QLIST_REMOVE(page, list); qemu_ram_remap(page->ram_addr, page->page_size); diff --git a/meson.build b/meson.build index fbda17c987..03214586c4 100644 --- a/meson.build +++ b/meson.build @@ -3029,6 +3029,8 @@ if host_os == 'windows' endif endif +config_host_data.set('CONFIG_HUGETLBFS_RAS', host_os == 'linux') + ######################## # Target configuration # ######################## diff --git a/system/hugetlbfs_ras.c b/system/hugetlbfs_ras.c new file mode 100644 index 0000000000..2f7e550f56 --- /dev/null +++ b/system/hugetlbfs_ras.c @@ -0,0 +1,546 @@ +/* + * Deal with memory hugetlbfs largepage errors in userland. + * + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. + */ + +#include "qemu/osdep.h" +#include +#include +#include +#include +#include +#include + +#include "exec/address-spaces.h" +#include "exec/memory.h" +#include "exec/ramblock.h" +#include "qemu/thread.h" +#include "qemu/queue.h" +#include "qemu/error-report.h" +#include "block/thread-pool.h" +#include "sysemu/runstate.h" +#include "sysemu/kvm.h" +#include "qemu/main-loop.h" +#include "block/aio-wait.h" + +#include "hugetlbfs_ras.h" + +/* #define DEBUG_HUGETLBFS_RAS */ + +#ifdef DEBUG_HUGETLBFS_RAS +#define DPRINTF(fmt, ...) \ + do { fprintf(stderr, "lpg_ras[%s]: " fmt, __func__, ## __VA_ARGS__); \ + } while (0) +#else +#define DPRINTF(fmt, ...) do {} while (0) +#endif + +/* + * We track the Large Poisoned Pages to be able to: + * - Identify if a faulting page is already under replacement + * - Trigger a replacement for new pages + * - Inform the suspended signal handlers that they can continue + */ +typedef enum LPP_state { + LPP_SUBMITTED = 1, + LPP_PREPARING, + LPP_DONE, + LPP_FAILED, +} LPP_state; + +typedef struct LargeHWPoisonPage { + void *page_addr; /* hva of the poisoned large page */ + size_t page_size; + LPP_state page_state; + void *first_poison; /* location of the first poison found */ + struct timespec creation_time; + QLIST_ENTRY(LargeHWPoisonPage) list; +} LargeHWPoisonPage; + +static QLIST_HEAD(, LargeHWPoisonPage) large_hwpoison_page_list = + QLIST_HEAD_INITIALIZER(large_hwpoison_page_list); +static int large_hwpoison_vm_stop; /* indicate that VM is stopping */ +static QemuCond large_hwpoison_cv; +static QemuCond large_hwpoison_new; +static QemuCond large_hwpoison_vm_running; +static QemuMutex large_hwpoison_mtx; +static QemuThread thread; +static void *hugetlbfs_ras_listener(void *arg); +static int vm_running; +static bool hugetlbfs_ras_initialized; +static int _PAGE_SIZE = 4096; +static int _PAGE_SHIFT = 12; + +/* size should be a power of 2 */ +static int +shift(int sz) +{ + int e, s = 0; + + for (e = 0; (s < sz) && (e < 31); e++) { + s = (1 << e); + if (s == sz) { + return e; + } + } + return -1; +} + +static int +hugetlbfs_ras_init(void) +{ + _PAGE_SIZE = qemu_real_host_page_size(); + _PAGE_SHIFT = shift(_PAGE_SIZE); + if (_PAGE_SHIFT < 0) { + warn_report("No support for hugetlbfs largepage errors: " + "Bad page size (%d)", _PAGE_SIZE); + return -EIO; + } + qemu_cond_init(&large_hwpoison_cv); + qemu_cond_init(&large_hwpoison_new); + qemu_cond_init(&large_hwpoison_vm_running); + qemu_mutex_init(&large_hwpoison_mtx); + + qemu_thread_create(&thread, "hugetlbfs_error", hugetlbfs_ras_listener, + NULL, QEMU_THREAD_DETACHED); + + hugetlbfs_ras_initialized = true; + return 0; +} + +bool +hugetlbfs_ras_use(void) +{ + static bool answered; + + if (answered) { + return hugetlbfs_ras_initialized; + } + + /* XXX we could verify if ras feature should be used or not (on ARM) */ + + /* CAP_SYS_ADMIN capability needed for madvise(MADV_HWPOISON) */ + if (getuid() != 0) { + warn_report("Priviledges needed to deal with hugetlbfs memory poison"); + } else { + hugetlbfs_ras_init(); + } + + answered = true; + return hugetlbfs_ras_initialized; +} + +/* return the backend real page size used for the given address */ +static size_t +hugetlbfs_ras_backend_sz(void *addr) +{ + ram_addr_t offset; + RAMBlock *rb; + + rb = qemu_ram_block_from_host(addr, false, &offset); + if (!rb) { + warn_report("No associated RAMBlock to addr: %p", addr); + return _PAGE_SIZE; + } + return rb->page_size; +} + +/* + * Report if this std page address of the given faulted large page should be + * retried or if the current signal handler should continue to deal with it. + * Once the mapping is replaced, we retry the errors appeared before the + * 'page struct' creation, to deal with previous errors that haven't been + * taken into account yet. + * But the 4k pages of the mapping can also experience HW errors in their + * lifetime. + */ +static int +hugetlbfs_ras_retry(void *addr, LargeHWPoisonPage *page, + struct timespec *entry_time) +{ + if (addr == page->first_poison) { + return 0; + } + if (entry_time->tv_sec < page->creation_time.tv_sec) { + return 1; + } + if ((entry_time->tv_sec == page->creation_time.tv_sec) && + (entry_time->tv_nsec <= page->creation_time.tv_nsec)) { + return 1; + } + return 0; +} + +/* + * If the given address is a large page, we try to replace it + * with a set of standard sized pages where we copy what remains + * valid from the failed large page. + * We reset the two values pointed by paddr and psz to point + * to the first poisoned page in the new set, and the size + * of this poisoned page. + * Return True when it's done. The handler continues with the + * possibly corrected values. + * Returning False means that there is no signal handler further + * action to be taken, the handler should exit. + */ +bool +hugetlbfs_ras_correct(void **paddr, size_t *psz, int code) +{ + void *p, *reported_addr; + size_t reported_sz, real_sz; + LargeHWPoisonPage *page; + int found = 0; + struct timespec et; + + assert(psz != NULL && paddr != NULL); + + DPRINTF("SIGBUS (%s) at %p (size: %lu)\n", + (code == BUS_MCEERR_AR ? "AR" : "AO"), *paddr, *psz); + + if (!hugetlbfs_ras_initialized) { + return true; + } + + /* + * XXX kernel provided size is not reliable... + * As kvm_send_hwpoison_signal() uses a hard-coded PAGE_SHIFT + * signal value on hwpoison signal. + * So in the case of a std page size, we must identify the actual + * size to consider (from the mapping block size, or if we + * already reduced the page to 4k chunks) + */ + reported_sz = *psz; + + p = *paddr; + reported_addr = p; + + if (clock_gettime(CLOCK_MONOTONIC, &et) != 0) { + et.tv_sec = 0; + et.tv_nsec = 1; + } + qemu_mutex_lock(&large_hwpoison_mtx); + + if (large_hwpoison_vm_stop) { + qemu_mutex_unlock(&large_hwpoison_mtx); + return false; + } + + QLIST_FOREACH(page, &large_hwpoison_page_list, list) { + if (page->page_addr <= p && + page->page_addr + page->page_size > p) { + found = 1; + break; + } + } + + if (!found) { + if (reported_sz > _PAGE_SIZE) { + /* we trust the kernel in this case */ + real_sz = reported_sz; + } else { + real_sz = hugetlbfs_ras_backend_sz(p); + if (real_sz <= _PAGE_SIZE) { + /* not part of a large page */ + qemu_mutex_unlock(&large_hwpoison_mtx); + return true; + } + } + page = g_new0(LargeHWPoisonPage, 1); + p = (void *)ROUND_DOWN((unsigned long long)p, real_sz); + page->page_addr = p; + page->page_size = real_sz; + page->page_state = LPP_SUBMITTED; + QLIST_INSERT_HEAD(&large_hwpoison_page_list, page, list); + qemu_cond_signal(&large_hwpoison_new); + } else { + if ((code == BUS_MCEERR_AR) && (reported_sz <= _PAGE_SIZE) && + hugetlbfs_ras_retry(p, page, &et)) { + *paddr = NULL; + } + } + + while (page->page_state < LPP_DONE && !large_hwpoison_vm_stop) { + qemu_cond_wait(&large_hwpoison_cv, &large_hwpoison_mtx); + } + + if (large_hwpoison_vm_stop) { + DPRINTF("Handler exit requested as on page %p\n", page->page_addr); + *paddr = NULL; + } + qemu_mutex_unlock(&large_hwpoison_mtx); + + if (page->page_state == LPP_FAILED) { + warn_report("Failed recovery for page: %p (error at %p)", + page->page_addr, reported_addr); + return (*paddr == NULL ? false : true); + } + + *psz = (size_t)_PAGE_SIZE; + + DPRINTF("SIGBUS (%s) corrected from %p to %p (size %ld to %ld)\n", + (code == BUS_MCEERR_AR ? "AR" : "AO"), + reported_addr, *paddr, reported_sz, *psz); + + return (*paddr == NULL ? false : true); +} + +/* + * Sequentially read the valid data from the failed large page (shared) backend + * file and copy that into our set of standard sized pages. + * Any error reading this file (not only EIO) means that we don't retrieve + * valid data for the read location, so it results in the corresponding + * standard page to be marked as poisoned. + * And if this file mapping is not set with "share=on", we can't rely on the + * content on the backend file, so the entire replacing set of pages + * is poisoned in this case. + */ +static int take_valid_data_lpg(LargeHWPoisonPage *page, const char **err) +{ + int fd, i, ps = _PAGE_SIZE, slot_num, poison_count = 0; + ram_addr_t offset; + RAMBlock *rb; + uint64_t fd_offset; + ssize_t count, retrieved; + + /* find the backend to get the associated fd and offset */ + rb = qemu_ram_block_from_host(page->page_addr, false, &offset); + if (!rb) { + if (err) { + *err = "No associated RAMBlock"; + } + return -1; + } + fd = qemu_ram_get_fd(rb); + fd_offset = rb->fd_offset; + offset += fd_offset; + assert(page->page_size == qemu_ram_pagesize(rb)); + slot_num = page->page_size / ps; + + if (!qemu_ram_is_shared(rb)) { /* we can't use the backend file */ + if (madvise(page->page_addr, page->page_size, MADV_HWPOISON) == 0) { + page->first_poison = page->page_addr; + warn_report("Large memory error, unrecoverable section " + "(unshared hugetlbfs): start:%p length: %ld", + page->page_addr, page->page_size); + return 0; + } else { + if (err) { + *err = "large poison injection failed"; + } + return -1; + } + } + + for (i = 0; i < slot_num; i++) { + retrieved = 0; + while (retrieved < ps) { + count = pread(fd, page->page_addr + i * ps + retrieved, + ps - retrieved, offset + i * ps + retrieved); + if (count == 0) { + DPRINTF("read reach end of the file\n"); + break; + } else if (count < 0) { + DPRINTF("read backend failed: %s\n", strerror(errno)); + break; + } + retrieved += count; + } + if (retrieved < ps) { /* consider this page as poisoned */ + if (madvise(page->page_addr + i * ps, ps, MADV_HWPOISON)) { + if (err) { + *err = "poison injection failed"; + } + return -1; + } + if (page->first_poison == NULL) { + page->first_poison = page->page_addr + i * ps; + } + poison_count++; + DPRINTF("Found a poison at index %d = addr %p\n", + i, page->page_addr + i * ps); + } + } + + /* + * A large page without at least a 4k poison will not have an + * entry into hwpoison_page_list, so won't be correctly replaced + * with a new large page on VM reset with qemu_ram_remap(). + * Any new error on this area will fail to be handled. + */ + if (poison_count == 0) { + if (err) { + *err = "No Poison found"; + } + return -1; + } + + DPRINTF("Num poison for page %p : %d / %d\n", + page->page_addr, poison_count, i); + return 0; +} + +/* + * Empty the large_hwpoison_page_list -- to be called on address space + * poison cleanup outside of concurrent memory access. + */ +void hugetlbfs_ras_empty(void) +{ + LargeHWPoisonPage *page, *next_page; + + if (!hugetlbfs_ras_initialized) { + return; + } + qemu_mutex_lock(&large_hwpoison_mtx); + QLIST_FOREACH_SAFE(page, &large_hwpoison_page_list, list, next_page) { + QLIST_REMOVE(page, list); + g_free(page); + } + qemu_mutex_unlock(&large_hwpoison_mtx); +} + +/* + * Deal with the given page, initializing its data. + */ +static void +hugetlbfs_ras_transform_page(LargeHWPoisonPage *page, const char **err_info) +{ + const char *err_msg; + int fd; + ram_addr_t offset; + RAMBlock *rb; + + /* find the backend to get the associated fd and offset */ + rb = qemu_ram_block_from_host(page->page_addr, false, &offset); + if (!rb) { + DPRINTF("No associated RAMBlock to %p\n", page->page_addr); + err_msg = "qemu_ram_block_from_host error"; + goto err; + } + fd = qemu_ram_get_fd(rb); + + if (sync_file_range(fd, offset, page->page_size, + SYNC_FILE_RANGE_WAIT_AFTER) != 0) { + err_msg = "sync_file_range error on the backend"; + perror("sync_file_range"); + goto err; + } + if (fsync(fd) != 0) { + err_msg = "fsync error on the backend"; + perror("fsync"); + goto err; + } + if (msync(page->page_addr, page->page_size, MS_SYNC) != 0) { + err_msg = "msync error on the backend"; + perror("msync"); + goto err; + } + page->page_state = LPP_PREPARING; + + if (munmap(page->page_addr, page->page_size) != 0) { + err_msg = "Failed to unmap"; + perror("munmap"); + goto err; + } + + /* replace the large page with standard pages */ + if (mmap(page->page_addr, page->page_size, PROT_READ | PROT_WRITE, + MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0) + == MAP_FAILED) { + err_msg = "Failed to map std page"; + perror("mmap"); + goto err; + } + + /* take a copy of still valid data and mark the failed pages as poisoned */ + if (take_valid_data_lpg(page, &err_msg) != 0) { + goto err; + } + + if (clock_gettime(CLOCK_MONOTONIC, &page->creation_time) != 0) { + err_msg = "Failed to set creation time"; + perror("clock_gettime"); + goto err; + } + + page->page_state = LPP_DONE; + return; + +err: + if (err_info) { + *err_info = err_msg; + } + page->page_state = LPP_FAILED; +} + +/* attempt to vm_stop the entire VM in the IOthread */ +static void coroutine_hugetlbfs_ras_vmstop_bh(void *opaque) +{ + vm_stop(RUN_STATE_PAUSED); + DPRINTF("VM STOPPED\n"); + qemu_mutex_lock(&large_hwpoison_mtx); + vm_running = 0; + qemu_cond_signal(&large_hwpoison_vm_running); + qemu_mutex_unlock(&large_hwpoison_mtx); +} + +static void coroutine_hugetlbfs_ras_vmstart_bh(void *opaque) +{ + vm_start(); +} + +static void * +hugetlbfs_ras_listener(void *arg) +{ + LargeHWPoisonPage *page; + int new; + const char *err; + + /* monitor any newly submitted element in the list */ + qemu_mutex_lock(&large_hwpoison_mtx); + while (1) { + new = 0; + QLIST_FOREACH(page, &large_hwpoison_page_list, list) { + if (page->page_state == LPP_SUBMITTED) { + new++; + vm_running = 1; + DPRINTF("Stopping the VM\n"); + aio_bh_schedule_oneshot(qemu_get_aio_context(), + coroutine_hugetlbfs_ras_vmstop_bh, NULL); + /* inform all SIGBUS threads that they have to return */ + large_hwpoison_vm_stop++; + qemu_cond_broadcast(&large_hwpoison_cv); + + /* wait until VM is stopped */ + while (vm_running) { + DPRINTF("waiting for vm to stop\n"); + qemu_cond_wait(&large_hwpoison_vm_running, + &large_hwpoison_mtx); + } + + hugetlbfs_ras_transform_page(page, &err); + if (page->page_state == LPP_FAILED) { + error_report("fatal: unrecoverable hugepage memory error" + " at %p (%s)", page->page_addr, err); + exit(1); + } + + large_hwpoison_vm_stop--; + + DPRINTF("Restarting the VM\n"); + aio_bh_schedule_oneshot(qemu_get_aio_context(), + coroutine_hugetlbfs_ras_vmstart_bh, NULL); + } + } + if (new) { + qemu_cond_broadcast(&large_hwpoison_cv); + } + + qemu_cond_wait(&large_hwpoison_new, &large_hwpoison_mtx); + } + qemu_mutex_unlock(&large_hwpoison_mtx); + return NULL; +} diff --git a/system/hugetlbfs_ras.h b/system/hugetlbfs_ras.h new file mode 100644 index 0000000000..324228bda3 --- /dev/null +++ b/system/hugetlbfs_ras.h @@ -0,0 +1,3 @@ +bool hugetlbfs_ras_use(void); +bool hugetlbfs_ras_correct(void **paddr, size_t *psz, int code); +void hugetlbfs_ras_empty(void); diff --git a/system/meson.build b/system/meson.build index a296270cb0..eda92f55a9 100644 --- a/system/meson.build +++ b/system/meson.build @@ -37,4 +37,5 @@ system_ss.add(when: 'CONFIG_DEVICE_TREE', if_false: files('device_tree-stub.c')) if host_os == 'linux' system_ss.add(files('async-teardown.c')) + system_ss.add(files('hugetlbfs_ras.c')) endif diff --git a/system/physmem.c b/system/physmem.c index 5c176146c0..78de507bd0 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -82,6 +82,10 @@ #include #endif +#ifdef CONFIG_HUGETLBFS_RAS +#include "system/hugetlbfs_ras.h" +#endif + //#define DEBUG_SUBPAGE /* ram_list is read under rcu_read_lock()/rcu_read_unlock(). Writes @@ -2061,6 +2065,19 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, return NULL; } +#ifdef CONFIG_HUGETLBFS_RAS + { + QemuFsType ftyp = qemu_fd_getfs(fd); + + if (ftyp == QEMU_FS_TYPE_HUGETLBFS) { + if (hugetlbfs_ras_use() && !(ram_flags & RAM_SHARED)) { + warn_report("'share=on' option must be set to support " + "hugetlbfs memory error handling"); + } + } + } +#endif + block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, offset, errp); if (!block) { if (created) { diff --git a/target/arm/kvm.c b/target/arm/kvm.c index f62e53e423..6215d1acb5 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -40,6 +40,10 @@ #include "hw/acpi/ghes.h" #include "target/arm/gtimer.h" +#ifdef CONFIG_HUGETLBFS_RAS +#include "system/hugetlbfs_ras.h" +#endif + const KVMCapabilityInfo kvm_arch_required_capabilities[] = { KVM_CAP_LAST_INFO }; @@ -2356,6 +2360,12 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr, short addr_lsb) assert(code == BUS_MCEERR_AR || code == BUS_MCEERR_AO); +#ifdef CONFIG_HUGETLBFS_RAS + if (!hugetlbfs_ras_correct(&addr, &sz, code)) { + return; + } +#endif + if (acpi_ghes_present() && addr) { ram_addr = qemu_ram_addr_from_host(addr); if (ram_addr != RAM_ADDR_INVALID && diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 99b87140cc..c99095cb1f 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -69,6 +69,10 @@ #include "exec/memattrs.h" #include "trace.h" +#ifdef CONFIG_HUGETLBFS_RAS +#include "system/hugetlbfs_ras.h" +#endif + #include CONFIG_DEVICES //#define DEBUG_KVM @@ -729,6 +733,12 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr, short addr_lsb) */ assert(code == BUS_MCEERR_AR || code == BUS_MCEERR_AO); +#ifdef CONFIG_HUGETLBFS_RAS + if (!hugetlbfs_ras_correct(&addr, &sz, code)) { + return; + } +#endif + if ((env->mcg_cap & MCG_SER_P) && addr) { ram_addr = qemu_ram_addr_from_host(addr); if (ram_addr != RAM_ADDR_INVALID && From patchwork Tue Sep 10 09:07:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Roche X-Patchwork-Id: 13798152 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 5942FECE564 for ; Tue, 10 Sep 2024 09:10:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snwsE-0001I8-IT; Tue, 10 Sep 2024 05:09:23 -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 1snwrW-0007tn-2v for qemu-devel@nongnu.org; Tue, 10 Sep 2024 05:08:45 -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 1snwrS-0004J6-SB for qemu-devel@nongnu.org; Tue, 10 Sep 2024 05:08:36 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48A8tZZc008924 for ; Tue, 10 Sep 2024 09:08:30 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-11-20; bh=q0iQvauBKftLkn5wPQYkulRxXA4ngQtig5Bo3welgzw=; b= LyiXyyVpqkW8uEAY+WsyiOALwnxc/YQBCHddAkXv/1hnoknSpB/EfEo/UKSFGymR gOh81K4/LlUUH8llyS/kNVG/R+ZpJaepgf+zofhDbAqVM+9k77dMMm3vpUatBbNc xS+kucp4u02SuIGWDSn5iRFBu00ox+lPmdJqg5z6dYjMIZ6S5nBJ/iKUmOihi2Tv qlnDK3xSZ8UEqtawLvS9JwXE3OZh3ZLaGCSGZkOvEKvw/8dT2z9/dWiNezQmmtw+ UmDoEJHq+cUUb0cOJGHlNn7Ndk8nywb/1ZaA8i3EQ0NCxHBzlGsOxGwyxHS27Dr2 zbef0cFtHixqCDE9lud3DA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41geq9n07t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Sep 2024 09:08:30 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48A8ao8R005070 for ; Tue, 10 Sep 2024 09:08:28 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 41gd9898f7-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Sep 2024 09:08:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KiVEkCkR5hKZlqiQU75FNykR8/8p7IA/ODBeC2o7nlVUNpTrSIMrdvJNRBkTAPkWsjaqa/+z3ovPgeWjwr8wsutXQLzoZfoMtjv+Gnsp7D6GGDHCjO6jM05RdNED2iF0TqOCyhi/CLp1FUAHS43+bawgziaQusGfyDqVNuCo+Jo2CXkp2FJEmHBA2RfAUEW2XzgeoLuHjTdYDjCzEt9OrzagR+c9NGGrEv2nFHowZ3NwxHdT6Tsm+ZQ6OUHh+jP0mZWWqczn0QsRzsQ7sgfMf7Xemjo0HK6lgxAsl2k3ZmfqenUQcj6edUEdMUbY/Tucx6USFYrMfi8gRA9MYr1HcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=q0iQvauBKftLkn5wPQYkulRxXA4ngQtig5Bo3welgzw=; b=f0yg0j5CO/4NBemRyzkCAjWLJ/T5SCwEbZZ8+HZymtJ644cRLj6qE87uzqaKu5hqBuHAfA4ZE59ndcjaLHqX/RaldqUSXvwdGokGRW7HIKF/j9L8j3DGvwAVGAvaVuiTqxW31jF7dLwhoxPj1IQcUdAKmCQ1Ye78YUJUzNciE8mO0Aqleu0zf0da3NHlyZiWpyRvMsZcaYTtn5xvL4KcPeuuGHQSKuwJGfPFM1cey/tUlm2f1lJx40WyhTZ2OOXLj6gMLSLqGGNh6y5cybO72FwKgF8LAKfhFeJSRTIpgSAz/2jb05BDqt9GrB8/+Z7KeJlbjzAEV1FK7SmLPEYMBg== 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=q0iQvauBKftLkn5wPQYkulRxXA4ngQtig5Bo3welgzw=; b=mmuMckIFeXpcpDLW7Vunks/1pEfzkLfrcbGtHtYuj1l9oT1lbgxg0vyIiMSfFt16Tzip5Qhzx+gvua6JEvKYLdUpEhuO0DeuGVeDmHChMWpeiitGZ4WuXu64EZsvoQJs3X2AD9hBjz5nsoNNgCzKT27D7o2gr6beRiF0KX61sHs= Received: from CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) by CH3PR10MB7163.namprd10.prod.outlook.com (2603:10b6:610:127::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.16; Tue, 10 Sep 2024 09:08:01 +0000 Received: from CH3PR10MB7329.namprd10.prod.outlook.com ([fe80::f238:6143:104c:da23]) by CH3PR10MB7329.namprd10.prod.outlook.com ([fe80::f238:6143:104c:da23%5]) with mapi id 15.20.7939.010; Tue, 10 Sep 2024 09:08:01 +0000 From: =?utf-8?q?=E2=80=9CWilliam_Roche?= To: qemu-devel@nongnu.org Cc: william.roche@oracle.com, joao.m.martins@oracle.com Subject: [RFC 5/6] system/hugetlb_ras: Handle madvise SIGBUS signal on listener Date: Tue, 10 Sep 2024 09:07:46 +0000 Message-ID: <20240910090747.2741475-6-william.roche@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910090747.2741475-1-william.roche@oracle.com> References: <20240910090747.2741475-1-william.roche@oracle.com> X-ClientProxiedBy: SJ0PR13CA0074.namprd13.prod.outlook.com (2603:10b6:a03:2c4::19) To CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB7329:EE_|CH3PR10MB7163:EE_ X-MS-Office365-Filtering-Correlation-Id: dfc37579-713f-4073-a76e-08dcd178124f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: 4aC0e332yH5bykxnoYaZ0ENvAwfsePqd+xKkHQGDzlmc18xq4UJpplx/OT6iePfoiz94EtcWLOyMf1UtWCAFlZ/DO1HuAgEdwiN3CyIsHXoVWXj1xrn45U1gyCue4V9xkaYOYbaq4OyhNqU7cTnSew1RuovmtxuGAAN3/Pd8xpVN9NgNmBmzeL2T17jOu5R/S46D3spsPxlfwkPOH2aD5N21KG/utUXttzJ4p1cH3uWwmilR0EGbdBkiNtD5Z19qHoCYAOGRpoeC1/w8pDPxTo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A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH3PR10MB7329.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7Hfwcb35aQsBKMLbCaSlam7wKmfYbYhxA0jpeBMnUKvmJxQUOvtEJpZeP8emoytZlN7uecC1micYyEzG4vAxek15jVGBzO1CNwD9o78snnquCbdxBaSH4KNmM8HfaYkvXlee/JXgPfKZ79MqZRQJB8VUcHfAwoVzSmFG5GXNRWFetzXXnsDTZkTpcp40k5kjIZVxeOh65kalyelbuAIZkgHwv7/63dX9Q0T9ICH85VgZmqPUfVHq8WQa972hBLc39Sxe+5Kj3XaH6mP5ngdwSUS/WgwNBsRm6z3kS5VYgdbuaX9KTGrjf8FL2c3t1qYoIR8Rw7+1knezpjwUrojljJ5aPp9IxK9pWX9Pe8LMI1XYm63n352mtWit5l2R3ERvRT6l/3qZiWsTOEj+wBWSX+Y/LOjWFHwBZxqZYzs0DyeOZ7Bp9Unf6Yqw3y0v5RqylxVSH+a2KCq+FQlLgPJIbUxYWZbmswUzhnj8fNCNVYziIJXRhydECwcqJiwG2KKi/s/U+6rJ4lPyRE4dxiHc4vq9/lhL8/7E6zJACEVZnbO84EuTp0HzAJt75CMDaDrNSWVAa5UEbAF6JEJT7apPtA/mPRB54d9kOt4p3+zJtrqnURLSKRbPNCsYnJjUWQw3znA6AbwThTypChJ6QraIGL9sCChRX+iQM30daEbewKPdq2aS/Zr/R7W3zTKr7/CFz2mkHl3HtZrjbGGQX7LngFHSyD0d4mOAjXejPhr5KcdD61GrOXdF8db/WSgi3jQ7VjDsQVCY5PSkJqBOqNa3/lLWHi0s5hEKjP45mkr1Qt2XoESRWuokhEZRlLWzEdf/BQWF2U846yz3Tig49cZwgsAgvhyfns5BTq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M70dJ+p1ucPPiu0dUUh/u19Slc4LRIi6YYevH49YiL+TFgycBqJ8Chlo4RT6BZfuUYozXB+axsItEObJ8VebTu/iDpTKrKZXQ9uWeut3Yiz5x5Fo0B4Wjcsfh7/tSYSaLb6gFQ5ZjazOLM5cAYTjn0+b1qEFhjIhHfIJTco4KmLAHUPtmq/Kbl/309NE473PdNdbgkH/k1aY++3F6n7lExIa2PsXtYNBjCLayHIT0/qACNFboeLrJnnycQWdvbGanY5QzQruwkwui1FfMyqOQOEvzyRG6V39mUQdLMANJ9gW9UIW9yJS2wAmOBB5+V2xxt1gQc3+2LlPcZbFluhaXltNJmLeV3vWQZdUsuEGqJOKdAE879MU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: dfc37579-713f-4073-a76e-08dcd178124f X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB7329.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 09:08:01.4935 (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: 23FVuucykByfGD2BhHoEqrfMgNlRcx7vnab+NIob8RInmdVd/CEPDh8sS1L24NoZCwSSumdrgtjADKjgnYsuZvoH1Ef0FN+nIh8vNaqbye0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR10MB7163 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-10_01,2024-09-09_02,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 adultscore=0 phishscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409100069 X-Proofpoint-ORIG-GUID: Dd-MVO7QG7l2cATmoJ_eteIDhZuHQn55 X-Proofpoint-GUID: Dd-MVO7QG7l2cATmoJ_eteIDhZuHQn55 Received-SPF: pass client-ip=205.220.165.32; envelope-from=william.roche@oracle.com; helo=mx0a-00069f02.pphosted.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, RCVD_IN_MSPIKE_H3=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 madvise MADV_HWPOISON can generate a SIGBUS when called, so the listener thread (the caller) needs to deal with this signal. The signal handler recognizes a thread specific variable allowing it to directly exit when generated from this thread. Signed-off-by: William Roche --- system/cpus.c | 9 +++++++++ system/hugetlbfs_ras.c | 43 ++++++++++++++++++++++++++++++++++++++++-- system/hugetlbfs_ras.h | 1 + 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/system/cpus.c b/system/cpus.c index 12e630f760..642055f729 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -47,6 +47,10 @@ #include "hw/hw.h" #include "trace.h" +#ifdef CONFIG_HUGETLBFS_RAS +#include "system/hugetlbfs_ras.h" +#endif + #ifdef CONFIG_LINUX #include @@ -374,6 +378,11 @@ static void sigbus_handler(int n, siginfo_t *siginfo, void *ctx) sigbus_reraise(); } +#ifdef CONFIG_HUGETLBFS_RAS + /* skip error on the listener thread - does not return in this case */ + hugetlbfs_ras_signal_from_listener(); +#endif + if (current_cpu) { /* Called asynchronously in VCPU thread. */ if (kvm_on_sigbus_vcpu(current_cpu, siginfo->si_code, diff --git a/system/hugetlbfs_ras.c b/system/hugetlbfs_ras.c index 2f7e550f56..90e399bbad 100644 --- a/system/hugetlbfs_ras.c +++ b/system/hugetlbfs_ras.c @@ -70,6 +70,8 @@ static QemuCond large_hwpoison_vm_running; static QemuMutex large_hwpoison_mtx; static QemuThread thread; static void *hugetlbfs_ras_listener(void *arg); +static pthread_key_t id_key; +static sigjmp_buf listener_jmp_buf; static int vm_running; static bool hugetlbfs_ras_initialized; static int _PAGE_SIZE = 4096; @@ -105,6 +107,10 @@ hugetlbfs_ras_init(void) qemu_cond_init(&large_hwpoison_vm_running); qemu_mutex_init(&large_hwpoison_mtx); + if (pthread_key_create(&id_key, NULL) != 0) { + warn_report("No support for hugetlbfs largepage errors - no id_key"); + return -EIO; + } qemu_thread_create(&thread, "hugetlbfs_error", hugetlbfs_ras_listener, NULL, QEMU_THREAD_DETACHED); @@ -288,6 +294,19 @@ hugetlbfs_ras_correct(void **paddr, size_t *psz, int code) return (*paddr == NULL ? false : true); } +/* this madvise can generate a SIGBUS, use the jump buffer to deal with it */ +static bool poison_location(void *addr, int size) +{ + if (sigsetjmp(listener_jmp_buf, 1) == 0) { + if (madvise(addr, size, MADV_HWPOISON)) { + DPRINTF("poison injection failed: %s (addr:%p sz:%d)\n", + strerror(errno), addr, size); + return false; + } + } + return true; +} + /* * Sequentially read the valid data from the failed large page (shared) backend * file and copy that into our set of standard sized pages. @@ -321,7 +340,7 @@ static int take_valid_data_lpg(LargeHWPoisonPage *page, const char **err) slot_num = page->page_size / ps; if (!qemu_ram_is_shared(rb)) { /* we can't use the backend file */ - if (madvise(page->page_addr, page->page_size, MADV_HWPOISON) == 0) { + if (poison_location(page->page_addr, page->page_size)) { page->first_poison = page->page_addr; warn_report("Large memory error, unrecoverable section " "(unshared hugetlbfs): start:%p length: %ld", @@ -350,7 +369,7 @@ static int take_valid_data_lpg(LargeHWPoisonPage *page, const char **err) retrieved += count; } if (retrieved < ps) { /* consider this page as poisoned */ - if (madvise(page->page_addr + i * ps, ps, MADV_HWPOISON)) { + if (!poison_location(page->page_addr + i * ps, ps)) { if (err) { *err = "poison injection failed"; } @@ -402,6 +421,19 @@ void hugetlbfs_ras_empty(void) qemu_mutex_unlock(&large_hwpoison_mtx); } +/* + * Check if the signal is taken from the listener thread, + * in this thread we don't return as we jump after the madvise call. + */ +void +hugetlbfs_ras_signal_from_listener(void) +{ + /* check if we take the SIGBUS in the listener */ + if (pthread_getspecific(id_key) != NULL) { + siglongjmp(listener_jmp_buf, 1); + } +} + /* * Deal with the given page, initializing its data. */ @@ -498,6 +530,13 @@ hugetlbfs_ras_listener(void *arg) LargeHWPoisonPage *page; int new; const char *err; + sigset_t set; + + pthread_setspecific(id_key, (void *)1); + /* unblock SIGBUS */ + sigemptyset(&set); + sigaddset(&set, SIGBUS); + pthread_sigmask(SIG_UNBLOCK, &set, NULL); /* monitor any newly submitted element in the list */ qemu_mutex_lock(&large_hwpoison_mtx); diff --git a/system/hugetlbfs_ras.h b/system/hugetlbfs_ras.h index 324228bda3..9c2a6e49a1 100644 --- a/system/hugetlbfs_ras.h +++ b/system/hugetlbfs_ras.h @@ -1,3 +1,4 @@ bool hugetlbfs_ras_use(void); bool hugetlbfs_ras_correct(void **paddr, size_t *psz, int code); void hugetlbfs_ras_empty(void); +void hugetlbfs_ras_signal_from_listener(void); From patchwork Tue Sep 10 09:07:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Roche X-Patchwork-Id: 13798151 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 3E708ECE564 for ; Tue, 10 Sep 2024 09:09:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snwrq-00006t-15; Tue, 10 Sep 2024 05:09:01 -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 1snwrW-0007to-0m for qemu-devel@nongnu.org; Tue, 10 Sep 2024 05:08:45 -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 1snwrS-0004J8-SE for qemu-devel@nongnu.org; Tue, 10 Sep 2024 05:08:36 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48A8tZZd008924 for ; Tue, 10 Sep 2024 09:08:31 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-11-20; bh=6zRKVP0wxYzEad+yxt0t268SLIx2OcpPGkov/2Pn12M=; b= J+eu4MyxSGPSsKyWxa0N9XO9Goge9HlAdkuzVFMXYT++hGQQkBpT7EOAkTYeDi3Z GAWEKZdmVPfMGHy/B7SHEYTi4zoKZVURxTJ1j5kWw9i/SYIxWa0hjgNH2poq5ECF mcPG0Y5EwcxKyab05XFKnAmbXMi3EhNKJMdNZgR7Z17KjARypg2ohoSuxJ7XKILx 61pdygwFceS868AtiRc3IyVE5r8dwjZlwu/9ZzsdyE38/NAE+GCBjBwpriQFBtFO KPrE48eIDffNAEmplk901ya8+jdP6h/84ZBzjWTE2WSlzpKQTXZgdKGINNgmPfel LfhiPI7akl9BU8AOKst2sA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41geq9n07u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Sep 2024 09:08:30 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48A8ao8S005070 for ; Tue, 10 Sep 2024 09:08:29 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 41gd9898f7-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Sep 2024 09:08:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eYBVtjY4xfdtG+fdZLCNlOHTdZ30UNRcwOT4Nqj3eYG7YJSZleYpT+/TNt7pmrNWiaGTKrPbuZwn8BFycNnOlC9NrgdlOkMwQkEGpByUdn6ARAjR95VX5GLx06myVQobCXFZDExkXBIe1lqqHpngavTPwijysw3fukvcPjn2DqN0PVc+7d0SXxqZzjq/1jRIT/YkdLdbTHpV1CigkIZW0bPIBoYMf/gvPg4XmQ+bpAud9wTj3wr0PGPtW65NYHWYjpt74t4YMkI0t2FENDlXgNDCqlR6u0f0HzHhcPICSgQE/JjcKrDSv8ohjW5d5SIR2IagjcooE2Y0vR0whJSJug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=6zRKVP0wxYzEad+yxt0t268SLIx2OcpPGkov/2Pn12M=; b=flSU+nL7PbJlk50SthsdbLb4Cs57mcbHboFKkJgX/02PWEWp73QOJV0yX7mZt54BzfW8wnHaeVpPcsmPK3K54KJbko7lsqqGZ+20BcMNeT0ulaFc2bbYFbBiUSjKu1WULrNXLxCDdTxPBnX5IGBRuKGw/r6o5z6F+qG5pvF8dGrWYjvekebpreY9TO06P6T+AUahGY65HfAb5jWpBHDFyc2thBJ9ZXdI9lCDCdKpUzJnrrImLm6L0VqmVlgSLJrNfsu5JyBRl5eZBuNMc5+zuxDrpx3GDH1I7u1zFTzr6t1N/gQADhCCgw4aRM2BYmcQD4F8XC79d4BENnf0s1AYqw== 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=6zRKVP0wxYzEad+yxt0t268SLIx2OcpPGkov/2Pn12M=; b=yZ53M1QSnzc6uGfhb3lsovdFq9CvIN8HDpXnoYXk1ckQhNiuXPW6cTAQ3E7l84SB31nLD8zvWz0sH/NZDGA01xID/ziTG+V9li0bwhnSc2shvG3FSUmPqAmqSExPsVoG31A+NQksBAbscdMmWUMT3Lqa5LlFm9b5TEhyQOAiAYo= Received: from CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) by CH3PR10MB7163.namprd10.prod.outlook.com (2603:10b6:610:127::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.16; Tue, 10 Sep 2024 09:08:03 +0000 Received: from CH3PR10MB7329.namprd10.prod.outlook.com ([fe80::f238:6143:104c:da23]) by CH3PR10MB7329.namprd10.prod.outlook.com ([fe80::f238:6143:104c:da23%5]) with mapi id 15.20.7939.010; Tue, 10 Sep 2024 09:08:03 +0000 From: =?utf-8?q?=E2=80=9CWilliam_Roche?= To: qemu-devel@nongnu.org Cc: william.roche@oracle.com, joao.m.martins@oracle.com Subject: [RFC 6/6] system/hugetlb_ras: Replay lost BUS_MCEERR_AO signals on VM resume Date: Tue, 10 Sep 2024 09:07:47 +0000 Message-ID: <20240910090747.2741475-7-william.roche@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910090747.2741475-1-william.roche@oracle.com> References: <20240910090747.2741475-1-william.roche@oracle.com> X-ClientProxiedBy: SJ0PR03CA0077.namprd03.prod.outlook.com (2603:10b6:a03:331::22) To CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB7329:EE_|CH3PR10MB7163:EE_ X-MS-Office365-Filtering-Correlation-Id: 688e1f75-be63-4cf4-1aaa-08dcd17813a3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: P9fMdBl8LiogQHjdVms+rCv6hqM2mQfvOyTdpMWQJq6RzIFrylHmi3jy7CfZLHyCu5n/fgtSu0VFk2LjhA/ageAXdtJSHF/Xj8ggYiOgKIt95vYfUsgNaMzJGaUkIvhblWQ+v3mOTZ/phZQ1CKkcGtbxpjfqk45AMgjLgV5VF0renMCo3pPcntjNdLk6QVvzN5R07aOPSsv0y46CA/xK9zpsNwS0nhn0zibgcwouLd0IwQpKiIw/8LRQEiOWX0m3qEWrQQbZ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JI+SVKZwlHEUgZ6VUdufZ0wujo9Ck9cxA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH3PR10MB7329.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VQeIBgPrtpIEGgH7dXpjIG5aQnQTLbTzc1aq9tAYWohHKxHYuVzi/HwsPJN2gld3tfjviUzhmQOkHmBN8DaSkYDPyddm9nLmc8/SqueN/A/hLu9wURd9+XKYaAtCAFXeDp1wqv7596N5miVQOJAepIm/R9n379tfBlxi/fP85AlRgd9CefBhju9qCWEb09+dG96sgIaNU2XGY/q6NQt7D/xIIMSCWaSUmFCVK/lQme3Pxzi8fd+gu5c0TXNpQBUWVLoKNceBkXem6QxChgqG9hpLFj+tGJ0Cg+yh7te1SlU5iuCQQa5YT1NwybLHA5IDhG6KpHqdJaRnwhxL/R4foORD457PU8kCT0fs1da0SJEZR+yoMv7LFvgLn4H1dDyIZorohjmvycCW593OrwoybZG5POrrXfac7AculOA3SML/albUc/6W5GvUwjJ8S2mb/kDVjuHIteCYqMo1/XMUAqqsNI2xRpAjoogMqn+q7tv2VLzS71kArjDEjSnMm1mRDrFugLMoQ4Urmkv5GZSS6tMTBfCwM3YpS9iDMuQ4lhVd2u6YGoPBnarl3h5xcKZgik21QJSFx/WV7gh/7Uh+UWST7kq2WJbJOHAh0BKSox2BcB4RoWPl0FAn5kZfwNshqCXbvE+2Auu8yV5NE036wks61kcEb0NfqYUoCJK3pGjhWl0xfEyrAr85+DbldfIKvGvnV6xTYJ0SRp/uuu7cujhBhu6+4rw3k9NrFnCI2KC29XkcH+rdhui5Iu4SteAOiLQTw4x3CCA3qWRviLSJrCs7+jUVehU/K8567drAb0glFmVkOI8r0dtQBNwkwqGZm2oTnsWb0AbbGooK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g4HXStLxnuy2y8nz52KpRWIb0rXXx6G+01lAWUZGpgCNU3fU5um3qOKAnq9jLU/ukBOC26GOb7acOIJHZK1qmRBZ8i8i3NFv6BCbjyyxLXEZ2LkJ4lwx4U3WYU070iUtzaqdbDPd4SYQYiDuebaGroJkbjE3gwi3mY/faWLekDzaEVmekgjrZIjmoHLyvXh7srOIec2THtuEKCWJ0VA9DcwAQG5LZIpf6AffNEY+TbCMCevWaeNkmY4QfcaIQZ8J1xjCJ/Q3xXjwhA81TgKUZKH8Cpm4omaawVP99YeFl3R8lTK/g9x/a2rnZ5OKCAuNxSuV9pgxKruaZ6cH2Px5RklZv/HixhxUbp2/LpTWLtB//gCEhZYQH4Dw8/61Sj8ggq27TmpA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 688e1f75-be63-4cf4-1aaa-08dcd17813a3 X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB7329.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 09:08:03.6984 (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: YTUme79k+Z87R7F1dcoNYO1GAdfiY9AYvKvo+lXYBC8RTyb2OfKbifQjChWoSHTIJZSzpJIRJ470xyOLFwhazIpsCs7seqlZ6aLOVRibEzo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR10MB7163 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-10_01,2024-09-09_02,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 adultscore=0 phishscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409100069 X-Proofpoint-ORIG-GUID: eeTNbU0ywurDNPkBxXGxFsXOKpMMuoEN X-Proofpoint-GUID: eeTNbU0ywurDNPkBxXGxFsXOKpMMuoEN Received-SPF: pass client-ip=205.220.165.32; envelope-from=william.roche@oracle.com; helo=mx0a-00069f02.pphosted.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, RCVD_IN_MSPIKE_H3=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 In case the SIGBUS handler is triggered by a BUS_MCEERR_AO signal and this handler needs to exit to let the VM pause during the memory mapping change, this SIGBUS won't be regenerated when the VM resumes. In this case we take note of this signal before exiting the handler to replay it when the VM resumes. Signed-off-by: William Roche --- system/hugetlbfs_ras.c | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/system/hugetlbfs_ras.c b/system/hugetlbfs_ras.c index 90e399bbad..50f810f836 100644 --- a/system/hugetlbfs_ras.c +++ b/system/hugetlbfs_ras.c @@ -155,6 +155,56 @@ hugetlbfs_ras_backend_sz(void *addr) return rb->page_size; } + +/* + * List of BUS_MCEERR_AO signals received before replaying. + * Addition is serialized under large_hwpoison_mtx, but replay is + * asynchronous. + */ +typedef struct LargeHWPoisonAO { + void *addr; + QLIST_ENTRY(LargeHWPoisonAO) list; +} LargeHWPoisonAO; + +static QLIST_HEAD(, LargeHWPoisonAO) large_hwpoison_ao = + QLIST_HEAD_INITIALIZER(large_hwpoison_ao); + +static void +large_hwpoison_ao_record(void *addr) +{ + LargeHWPoisonAO *cel; + + cel = g_new(LargeHWPoisonAO, 1); + cel->addr = addr; + QLIST_INSERT_HEAD(&large_hwpoison_ao, cel, list); +} + +/* replay the possible BUS_MCEERR_AO recorded signal(s) */ +static void +hugetlbfs_ras_ao_replay_bh(void) +{ + LargeHWPoisonAO *cel, *next; + QLIST_HEAD(, LargeHWPoisonAO) local_list = + QLIST_HEAD_INITIALIZER(local_list); + + /* + * Copy to a local list to avoid holding large_hwpoison_mtx + * when calling kvm_on_sigbus(). + */ + qemu_mutex_lock(&large_hwpoison_mtx); + QLIST_FOREACH_SAFE(cel, &large_hwpoison_ao, list, next) { + QLIST_REMOVE(cel, list); + QLIST_INSERT_HEAD(&local_list, cel, list); + } + qemu_mutex_unlock(&large_hwpoison_mtx); + + QLIST_FOREACH_SAFE(cel, &local_list, list, next) { + DPRINTF("AO on %p\n", cel->addr); + kvm_on_sigbus(BUS_MCEERR_AO, cel->addr, _PAGE_SHIFT); + g_free(cel); + } +} + /* * Report if this std page address of the given faulted large page should be * retried or if the current signal handler should continue to deal with it. @@ -276,6 +326,15 @@ hugetlbfs_ras_correct(void **paddr, size_t *psz, int code) if (large_hwpoison_vm_stop) { DPRINTF("Handler exit requested as on page %p\n", page->page_addr); *paddr = NULL; + /* + * BUS_MCEERR_AO specific case: this signal is not regenerated, + * we keep it to replay when the VM is ready to take it. + */ + if (code == BUS_MCEERR_AO) { + large_hwpoison_ao_record(page->first_poison ? page->first_poison : + reported_addr); + } + } qemu_mutex_unlock(&large_hwpoison_mtx); @@ -522,6 +581,7 @@ static void coroutine_hugetlbfs_ras_vmstop_bh(void *opaque) static void coroutine_hugetlbfs_ras_vmstart_bh(void *opaque) { vm_start(); + hugetlbfs_ras_ao_replay_bh(); } static void *