From patchwork Tue Sep 10 10:02:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=E2=80=9CWilliam_Roche?= X-Patchwork-Id: 13798237 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C856718C025 for ; Tue, 10 Sep 2024 10:02:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962554; cv=fail; b=tjJ3pvU1q7AiwlY9N67vJDu5HIO7lwiwHQmN3pe4mVkG2h1mUtNX2v85BDlfQOY+xT2FCYQuKQyq9ZjLPyplcc2X9hcd3JOvkWWpMVechvd7emnYzKAoMmV6M6O+zLdmN4ymvA5/Yrrk2hT7KqXdDPiJSXCPSOxUeuWt8mkPhiw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962554; c=relaxed/simple; bh=9u7rMKVGObTv6Fhcv0QKxRjyUxyFdmKKhPI3DDzS1X0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=jIRd9ZreUbruqYcD6P2/eIkrM485ga8VkTgu8mFPVla8vD7NZYJ3gNiblACTU/X6rAy8FDEm91IRKc0UpHkBvwL0ArdhDYU5pB+/z+XeYbl3Us+o85qLGorRXt3WfW/xSh50AEJqQ7z2zbcncE1xNJi8b/7FqaQPbC2S0rkwRwo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=HBvYrk95; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=PRdRWNga; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="HBvYrk95"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="PRdRWNga" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48A9QcbN027686; Tue, 10 Sep 2024 10:02:24 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= HBvYrk95oApy1gmE8K8yh27gqz2yp1Gc+UiRIhs802MbSCoeGZ2a6xyM5BKxSzfM gG3Nm0BFEdbakSSHEEBb3P+4gl7jMy2ODD9Ggvx+2DM9cW9KYgFvnMdrnAGTrGCv 4QxKDeRJhyNnqyzDDMuZVNUhqd2/c09CM2WBOqDQl4OiGJmdyMpTzFBWLuXaurLO J9AoGfeA7evW9KWPABQd9F5snGhnwpfDyBZ+ncpI3FvLLZcH6jKrB/F7YTMmsEff YQaaBQFGGc1zN3rMzYJlAvc+yLjt4PkW/Bh0RfHS7W1a7zwupIm45Sm8iEFSBMLM JR67LvWMMwqOsWkFxH2kgg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41gjbumwjv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2024 10:02:24 +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 48A8eqsK019973; Tue, 10 Sep 2024 10:02:23 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2171.outbound.protection.outlook.com [104.47.57.171]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41gd9eug8w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2024 10:02:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XKJyUkTemIwwKG+naajRSpf93StjK9dfZZh7fa+qJqurU2dTLX8zPtgwVcfz9NEVejSISYB3TZ1QQyVslwmT5b4/pVeqGEqgTg+EkSSOEBtUjOQ9zuYDAP7A2URi4xbJM9opN7G9RdpjZChqwA0p9+htqedXXMCnzaFp60IgVUttPuDVDxYVVoGpugG738raeEkN04pv6S6tYLJj4R85OxlhWS/cyAjpLutWFGJ7lZXg6UaUoNj4UfkZWa+V6NOwcJDGV9FrsBBeoBgIHnPc2hlUSNxarB/ZiBRz+Is1SndjIBa+LuY9v32H6eHKF9tevaNZrfRo/LI5+aJC+ZZ51Q== 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=N603uvIplnBOeuKmkIYEaRgbQCfrp6Zp0w91T6+LvaVX2KydP3FbDSrHEfj7a3X6c4TErpzG48iMKs9SUwzs3/xhDHU6PtQYU1M5Nd5kEpoPStbaw1On5ux2GNdcl+7yXBiJ4s9yMv3oBf2bApzAWXGy6UxDWJAtq7s4s16zfjn97LdpukxnkBQ2n6ISh63ogC8BdX6VhCMoN70ju5E6H2Gzn3Jp8OcTVUqYdvheBflZwQvhYvUVyh4F66xuFRGZzbab3Vm94Ze/GWhpi06Js2QudrXyleyDGGdp+3gGaXh6IaGLjXo6FHzh7ajoiVsXAQThN2Pud+RMrLNBThAjWg== 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=PRdRWNga1VB+LSK8160G+FEXvPXmoXConbzxk3Scrr5ScJEL0x/NRCKARqNEAsszq9+MfOBJ9cRp4BWiKuH1kFSBxANMlgbI72XqrZfW+uO7IViorfR0Pl9WsTIQhW7QMfed1+HSNYEDCbNqSABKdtOYbh6Xe/XH7UmCsW2Qt2o= Received: from CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) by PH0PR10MB5894.namprd10.prod.outlook.com (2603:10b6:510:14b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.10; Tue, 10 Sep 2024 10:02:21 +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 10:02:21 +0000 From: =?utf-8?q?=E2=80=9CWilliam_Roche?= To: pbonzini@redhat.com, peterx@redhat.com, david@redhat.com, philmd@linaro.org, marcandre.lureau@redhat.com, berrange@redhat.com, thuth@redhat.com, richard.henderson@linaro.org, peter.maydell@linaro.org, mtosatti@redhat.com, qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, qemu-arm@nongnu.org, william.roche@oracle.com, joao.m.martins@oracle.com Subject: [RFC RESEND 1/6] accel/kvm: SIGBUS handler should also deal with si_addr_lsb Date: Tue, 10 Sep 2024 10:02:11 +0000 Message-ID: <20240910100216.2744078-2-william.roche@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100216.2744078-1-william.roche@oracle.com> References: <20240910090747.2741475-1-william.roche@oracle.com> <20240910100216.2744078-1-william.roche@oracle.com> X-ClientProxiedBy: BYAPR07CA0108.namprd07.prod.outlook.com (2603:10b6:a03:12b::49) To CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB7329:EE_|PH0PR10MB5894:EE_ X-MS-Office365-Filtering-Correlation-Id: 5609caa5-8222-409e-d851-08dcd17fa930 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016|921020; X-Microsoft-Antispam-Message-Info: /IBpHQ0pqJyvoeFp49lMc4uq03h33XpBC1rAad9wUwUbf/mKOPeEOOuSlwwCvfBO1nVrc+tC9edJaotiv2j/We4BPDAqPMplkRgpxSqN6jDA6gfrKp5Okz6EEoZhU7ItQEjJZC5f1D2vPZnGvPwiXr5ffg2m8zHMoETxFBU4wJ+mzpTWLf7oNpGnimS993Dxh4fUhhUZs3otv9Mn+87gPucuLFrZ/ay5/spIKcPdlDCTkGONhzXnt+UJE/61cRNWngr/AzpNzeLQvTml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QWMX/zd8SMv3d4fN05xTmrfDhAgpF6mDdpfOiBngyjFt8cddSjoCZxKttBx+ 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)(7416014)(376014)(1800799024)(366016)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Tr16Z+TRXfXvEuWNnZWe5IHx0eSMwKuiZOks93V6usDJ0HpfiCDL9Lbsuwse+fLnAqqLtu5cpvi76FPbytAABcdf5DrvTISKH5fj6aYmvQaStv68Ew4pK9woNjALQAWM8EqsnIyDCvGqfDgAsxCeJOMW//kW73F2Bv8a2e/T0XDU/C3Stsyu6PnFedMsDxGloFvq4x1OmgABl6bknfXQDH/bUPhVpORjMqL8SZr5/5wRZDn9x/bDLK+2ZmnMTEbOHZxpSNn38yLx0XqAZnBMhqcriVzjlGJqdaReiXnPobYod9xw9/pXoQDmzTrHxlqDdbreMO4RcNrdfbjVYn/Uo2WHi2Pw51Ms6fQafn7hH1sc/U5io61B+3aSyFVU053E75NmYZDm4QT5bXl8cIjqUkGbe2St6gDBNxX+uHnz9IdbAgC12nSY3uAxNzKOo3w3dQwDPRMgPsLjJx7wQREe1y2CHC/uakkLPS2kRPHXLahKkj5f5Xf96++bda+Nh9dgtrAyXzDWgCI7THKf8b1Bewv1RuKhyuA1y4YYd4R0+SGSN9zuAzNnCEuPx+9vMXuC/mXzPYAAXUBt5L3+AxDchOTXd/GSoKXohlOE0Bh8rH4TcAtJQqui60tHrS7FmPFWHcd+C1n6r0oDI8i5oC5Na4jtxw2UyPDQsMkIeaYIj9gblfF7GRIdwJu9EZjczcubYZhYBjVe+EEA/cCRM64SB9Ysh+rzY5gMLeNEdrXO4KO6HDHAaTFndnJC1BDo4Fq4ptM9npUHfNAh8gmijLTwhzI0dpL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AqEUU48ikUaQ9HOQu3p9cOuCtL0bE4zOoGUlSlr5oAgoRz+6LISBO65U8ELKqZ9ob/pmlW6wrW+TKfKVehSDyUxemEm3tAfvslBzbEAM9IlnMvdALZxG/7iqhsKsU6FHz8CiNmpqZMcu5x6kxUWjAf3doOxXV89uqNSGXbRVCI4933cB1DVCiWvxg7yjFZlGlChaDem82hkst3z4Sd2EapDZyCYcTnpKaeIVy+rAhFvEKoklfcpah/+kTkyA30I35nys9i0aizo3o7QaHIgy0uKJ7gOAT9RWAzwDxsXuGagKRMQ0eNokmcM01CDp07lSqbw8lxRFA3yeEQOGLqlLDFqwYsNeGOVKUXbYV/tVwJx0wOEjJN1hBi2fPQIVlUAf5ZDqXVM7EN7RAgpcvHR3RDShA++UT605ABhzoSJIwe4PZn5NBiY1wAPw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5609caa5-8222-409e-d851-08dcd17fa930 X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB7329.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 10:02:21.0960 (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: /ofartDzhNs47galelG/JsFonuGVl4NiVCxPhV/0nKD8j2mSKgJmKa4MY387mTe9petQqk4kGMMevc9WV+lFj4Y14d9n7IuDWmmsx/uLZ80= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB5894 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_02,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-2409100075 X-Proofpoint-GUID: yU4BdGaw02dXTyhXbxRwlRlIzvOXD40n X-Proofpoint-ORIG-GUID: yU4BdGaw02dXTyhXbxRwlRlIzvOXD40n 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 10:02:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=E2=80=9CWilliam_Roche?= X-Patchwork-Id: 13798238 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCDC018C325 for ; Tue, 10 Sep 2024 10:02:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962555; cv=fail; b=G7RI0j3Cz6u4RYuA1ibOeHqPTIW3FRlBfDgvqS338aOtmRNhYPEVAnCldtRM/UIaPKKEZ6DGbatiDABVC76pDlDwjX7ObW5xi08P8sGuVpndNYMVWKpWFG3CLnNaXNXlGnyMBBXt13GD0sjqHE5g3xjbRIJy67FaQ3xQUT0iBjE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962555; c=relaxed/simple; bh=xUfJTO5PWmK7Tj2vzJTODuRexjeywIkwmYGAPU4aBd4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Uizg5z2PeDK2x+z3UGPOEK6y7cjK02IRHdLayFsmLiUA4D7SAv2+Q4wCbiLIJf6AZ8BgBF0R0HWtrC589oGgwQmXqWSyhSmGk1WtUYaD6ASEBS95/ZAumvIT0S1Ki0GcIgIQX0VtLGpJC5SdiYAXKr6lC5remfrGMHUgkOP5acw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=h5jTwveO; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=CKy6czpe; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="h5jTwveO"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="CKy6czpe" 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 48A9QnDn024802; Tue, 10 Sep 2024 10:02:26 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= h5jTwveO8V5SUyzI5wwUJgAZGFDkQ2ORqLXPbxuSeJSHQtFRjvPNQbJVONaG76/8 iqlyvVm0b+TURu+7Bd3/krCXRGS+lEZJ7FAP/iuF9u1Qk5rpIPCnBLUhepZ+HvsA cDsa7YKczjtsbcwJNY9pTa/WYMZeIy3TLccJHxo2WJ1yYzNyyfzkPEkcevOjc+UT E7asMADCJILln90SHC67msBktYvkXXuSsH33bVsWOXQm32YB1Qi5Pt9RQKy8pA2l zxAlgc3iunbjsmLoAJzMDD/dpSPHauB+Bkkx8sGiRqRaUlLQcYPDe1axzRPH4eiC wg1eapkuFzyOH00W1uABvA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41gevcn4cs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2024 10:02:26 +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 48A8jrVF006304; Tue, 10 Sep 2024 10:02:26 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2174.outbound.protection.outlook.com [104.47.57.174]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41gd98ba8k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2024 10:02:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=s6vQv/KdvSdP22n5b7T0YdXIPaqBNfYtrTyFplKbRA2rPEMPdJWut5py3JKzOKzQaiuB9NiHSJWCZaN102WO8abIu6Sjcm1MpplPUxixEqCWgIKSiYFl99WDH/uMpFjWIw2qXRMi6uaRVtmBhvxYwEniL4rTfIAGhhgUwxWvvyMWQxsYik8oqu1BW7zwmOiup3gGTwq5Kilyj1KvjIybCh/JPNzk0tlxDx8BU7KeNviQMnfsDFRxzacfa0jQp/PkDCIzFTgup5ICVB/iR6emgAeCwdPJz2ORW82kU4ezFi9tCwu0GrwQdbZ5vF6auudctuPn+ZaLAt0qG2iQDxmzZw== 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=XxkqVcMxeVx5+DEudTMEZt6mGO3V4xnwf8mRR2pqWjw8NDGhqSwEsRRzoFnO5xef4YX1Op0MlLR4OrTzdVSL+WMNoKN76FNo0WGeGvnke0qzqlJuR9L5i216AG5Pz6JfJxTQhg2jVeF1csVKFkeGnjd1ZTLgntuU7pBrYz06gYu7NbQ7KEx3d1isceOPgJ+NyqUdaOY/jJBdkIhafpH54vsjUTuYSyjEKi6P6ahBJk2pBSXNtfvA0lSZxo9U2q6yQN/Io+LrFFs89JKLfkJwdmERVb5jG48HegpJD5krOYWb6tq5G0uMElPmhEzwo4j3OdDJC9zRzGkh3xDVCEM10Q== 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=CKy6czpejbytM9dTSyhWMy5w1vm/XB5Jb6Hth+U5zF+LOiQJzHUGWQTri23hodZ/3j9wShhvKIS7aH9Gk+W0JdWlG7xTjBUScn/uUfV/klgzDng6wEq95rFKyCZX3FWvgxRaTbzVhse6IO7Nccw360p6+QmQFvhPbM9xgrjbKCw= Received: from CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) by PH0PR10MB5894.namprd10.prod.outlook.com (2603:10b6:510:14b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.10; Tue, 10 Sep 2024 10:02:23 +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 10:02:23 +0000 From: =?utf-8?q?=E2=80=9CWilliam_Roche?= To: pbonzini@redhat.com, peterx@redhat.com, david@redhat.com, philmd@linaro.org, marcandre.lureau@redhat.com, berrange@redhat.com, thuth@redhat.com, richard.henderson@linaro.org, peter.maydell@linaro.org, mtosatti@redhat.com, qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, qemu-arm@nongnu.org, william.roche@oracle.com, joao.m.martins@oracle.com Subject: [RFC RESEND 2/6] accel/kvm: Keep track of the HWPoisonPage sizes Date: Tue, 10 Sep 2024 10:02:12 +0000 Message-ID: <20240910100216.2744078-3-william.roche@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100216.2744078-1-william.roche@oracle.com> References: <20240910090747.2741475-1-william.roche@oracle.com> <20240910100216.2744078-1-william.roche@oracle.com> X-ClientProxiedBy: BY1P220CA0001.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:59d::14) To CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB7329:EE_|PH0PR10MB5894:EE_ X-MS-Office365-Filtering-Correlation-Id: da1e888c-2ac1-4ec0-a7ee-08dcd17faa80 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016|921020; X-Microsoft-Antispam-Message-Info: NT9waOgBSNseEpv7xU8F/FZ3jDam3pnjwlMod4jrIEA60HgNrP+d/AHrQ8Ma5AKZpB2gr3ozLcj1d8uorvAn2UpHGFi+DT+sgHWyrRpqeF9Bn4Rph1CtDqS35vFmfjAIgDJIUIgGDV/ocAv2jg3SlF/8oxn+ehRzbZ63nEpMGXB69ATbccZgxGZupqs8QZOnY2WgK5iukcBC2V/yCde61ckoQGuiOrcp3JNRk2HlUrZlvjreREeUxDwh23M8EFQ4AT9kWRl6CcaXY+h0kxSiulDDgXOiUSQw1HxedrLFKJuXaGOOY30lQNpGLu89aOExeWFQDeMwtWcrR7wg0ytqPkwzEbxjjonAKlJMxpjgp+NvY8GfrN/29S0lAWP70VV7wb9eU+X21twBMoACBRdMVfYyc+5JH+C1yZPUepnTSGhj1zcT/tKD1/VGpHDO7LWYxwwO16dqJ1KG0qV9PJ6nK1PnzHfa+Zr41iHsrkxiM1G1bKdIKU3W9LJDDuCPEGbjqFnjFllo8TOJF+SD2PN62GgFN1T5Nd0B2RCdeJEJphJSnj3WjGw35EUnbHT4qnIqgjMYIStCDvkxT+SAclgjN+heCW++MwiSvtjSpRWaXlV0+mGVS350K2d8yYPXwwitNUNO3ufyn8ABp37vS3ONICsP/f+kCoKk56U9Vz7fPrmteBKAdwneF4Y2g3ZblZHBRbRSBjmTjx+tQ+ImGcyJvJI2oia+sykmktqW7Aiaj4FMgxe79iQZF0f6ZtYtLLvXzzOZa3QMoyW4geyItyndwQfeZlMKUk6XzP/jjNHDQMBxnOHaHb3qUNDf3hJsW+ol+vuSuGEnnd7mM0znRX0mJPetCfDalyt6+zjavy1hyy358I1+h2ZTYtSzapnM3TeJrLKMIFmBv1GgZVNmkFN+CW2qi+/AT6kwTvIn+Swokas1KFBmnunI2BqRGLShRO8JQ6guoXZa4LKOQuGEgi6JmeKA+mRjiSlrjz/mEmawrxdhb6jGcltenwUD4iVKEwhbAxbgYq9rm4P6gsfGm3C6kcsoTGczmI8dBuHxS4lXDmT8jhVX215zTfmqKjBx81Xz31xp79Kjt46NMCZJJfObqzmKCeuC/v6H+TaK0ht0aZmYKqIONepEhnX8XpKZBKuc39qZLbPBifdkYrreFfV0N6cqept/ev0foOajsMaCiPZ2TqBSP06sRfQqPzogCcOaNJzPEKzYafhkJ6xG/UghdF8K1R+MBDEQwBekv9BEp3gvydoj+McnNZE7BDMAqIcHKPxYoM0E4Z4ASy7RsPtonnu9QfWhrCtl6Cp9hWRJCCObDqbZP7zO5CxJ35RwLeMGh3cDQwH60dMJQ4MWZbb2N7PjxHBqodGxZT9jjMFZ+A+lYtQDgUHDfYW0zG8ARKb0 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)(7416014)(376014)(1800799024)(366016)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1/F8jMERj0t2eWXh6pRJm9RI+hd+Oiq/cezG0gDzo5kmgWhIi9wVgSDtLTUuSm53RtWjjKUj6u3Q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je7C6QLYcaTT3K/6G8RUvcpeMWvjfqCg7ce16fq8WUKVvH7vTNDihf0SnNGJWc0e25UJp1sFsRzUezjaczctZerCl/bmXDO8wfeSw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: da1e888c-2ac1-4ec0-a7ee-08dcd17faa80 X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB7329.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 10:02:23.3072 (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: 24ixVMRJ6ZGPZ5oTOrjWzTvmg1jvNB3ZX5kSl9enMmR+oMnUQG+O2RPmgu2eCkf4VIGPIZutRuz9bMbmTD9tKRVGE1bPFn8Y/Zm1WSeuRlQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB5894 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_02,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-2409100075 X-Proofpoint-ORIG-GUID: nOW8GYwFTndQ6XtbnFeOHta8a2f5iM_u X-Proofpoint-GUID: nOW8GYwFTndQ6XtbnFeOHta8a2f5iM_u 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 10:02:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=E2=80=9CWilliam_Roche?= X-Patchwork-Id: 13798239 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CECF19004B for ; Tue, 10 Sep 2024 10:02:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962557; cv=fail; b=LT9clW+o3hGFoNC3rM9WAX+y0GZ+SD361knIyGMxhi+3Y7Ru4kBuVwjIGPPfMo0RXulnmyLHWCCVt18qbN/KBqHeOacOg7NE/HbcTHsl8/ef6I72cCnysxehhQkPKg3GXmLpUgdY+GYev5vVkyR6Re/oNX659DjHJ3e/04S65So= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962557; c=relaxed/simple; bh=TtsbbNbldI+v4iDtvc9GqclQeKAjszb6HAcVSuKRTpI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=jnizpneM63G9ip+F8HwZAbEBQrMS57l5zCqtndCa0qJmkib4NRYLxa6Ml3pZYtxtapVnUReFvEktevcb/VlTPke+fg+P5DkqvPImUUoloJ12ArbgOeQIWaT8CKUD0uoY4EVQdrFw8xt38Es5/JWLlf2ZyHVyHpnNbspaIfqdQnM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=Uu13LZMv; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=DClR3H3I; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Uu13LZMv"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="DClR3H3I" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48A9QdQO026829; Tue, 10 Sep 2024 10:02:29 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= Uu13LZMvKHtaK3nzsvEDgu0yPOV13cFrxkFFtSyqUDE820if5UdPew2eMf8IZ8LN ndUh0C5ndzTGkB8li3EF0X2KRJEcuLsCYaQ4d9mPX+sEIBGuxHfKExY4FXWK+xGW nkfysFm1xN/hg0c0mmVqAncbjprvQkTTpF4DmlcXsNU49PHJSLA3s3AGO59Ol0C0 Cl1o6bPsLiNkbcXOpcfUhSBNLVVoW+wBYv6G50/U8d9UFF61H5B26HW7AKboudok /MS9sS7c9P7HXLRU/XXzo/X6+C+k+S8+Zxl3JVklfuT3x9gWzbmBigLTK+DxfnYb 2kaXJz1/VYod9uQ4Ieb1Yg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41gd8cw2sr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2024 10:02:28 +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 48A81g0Q004160; Tue, 10 Sep 2024 10:02:28 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2176.outbound.protection.outlook.com [104.47.57.176]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41gd98baar-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2024 10:02:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MetVgO9suJylxZ+gMPpG/8Cgdyv61L6YzWCJXPob+pI/CNTsSU8o4XmcOjt7qGC76ZOen+SMjVuzJhIdo3KG21jWsUmULqgAtt1KUTW7KziQACTdM3+pIyouUlW1ZgWLyDcqoghqA7dIr0/xSNkQFw5Ltpp87giFq5LiKMmSlWQOfHILcddjgjgGJaimqADQr8DieIU/f2iJSCPityaTHiwXMF+YZ5BzR9QLmigXz8Rd4gZ/b1IyUWK0y5ITDzUSCC7QjdmR10KLalMfPHYkRdEN3I6aIGuUFABa9N9QRMfLkFJAiGY2QWyN275UTmeWvsk3UWki3D8shn1LlGFnuw== 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=SxK0OA+OGOF5dKmgYC/robj+K4FMtCfl75qgIOAYbgnbaGItLSP4APQgte0yt6RiROZyZFOUAzdZbmc36FNM3wWPJFuCUCzX9rJxQpJBIoQPSwOBko7qeqcIrq2Z/g/xWptECS53AqXAV3YD7QiVVsarVPbnQ05mX51mQrTvaVXyd2J8FdVSEDFwUEeIxqUbW1R9wvDTdIPxjQgg+GPqGdtl4xEotEygNZ/JAv+eEGrVZBM4foyU/+yVo9TXZafxQsvMVpJlcalwGUrbw6i8oHLzIygdaF7MALCWxrMPbJAMH3NPVCV9klU040cRkTupxtsf86hsv0la82kazVJ0pg== 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=DClR3H3IfrAupamFBrGTF8+n42woFonEJaywJGbPDImF2RF1wULqETJpe3hF8IQ8YLg7fsXLQfr4OafFJuR/4ixxr2XOnTdWcgHtpbrsOkHQoDH3rcgeqrE3CGfNmaVyyD87DA8dQgBG9Qaw+qFspn4hkzgkay3QBow88yILgR0= Received: from CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) by PH0PR10MB5894.namprd10.prod.outlook.com (2603:10b6:510:14b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.10; Tue, 10 Sep 2024 10:02:25 +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 10:02:25 +0000 From: =?utf-8?q?=E2=80=9CWilliam_Roche?= To: pbonzini@redhat.com, peterx@redhat.com, david@redhat.com, philmd@linaro.org, marcandre.lureau@redhat.com, berrange@redhat.com, thuth@redhat.com, richard.henderson@linaro.org, peter.maydell@linaro.org, mtosatti@redhat.com, qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, qemu-arm@nongnu.org, william.roche@oracle.com, joao.m.martins@oracle.com Subject: [RFC RESEND 3/6] system/physmem: Remap memory pages on reset based on the page size Date: Tue, 10 Sep 2024 10:02:13 +0000 Message-ID: <20240910100216.2744078-4-william.roche@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100216.2744078-1-william.roche@oracle.com> References: <20240910090747.2741475-1-william.roche@oracle.com> <20240910100216.2744078-1-william.roche@oracle.com> X-ClientProxiedBy: BY5PR16CA0015.namprd16.prod.outlook.com (2603:10b6:a03:1a0::28) To CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB7329:EE_|PH0PR10MB5894:EE_ X-MS-Office365-Filtering-Correlation-Id: 0681714c-bd8d-4489-2358-08dcd17fabfe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016|921020; X-Microsoft-Antispam-Message-Info: Eok5j0TODBnwoIMXf9qhAuTqtVbQLy/E3CC4pjf/PtHAymu/CfV2hsCNYZ5qSBygs0mfl03C/aQFfZGFr22+YHh80D1FoqCnxUO8zuHE56EBSO3fE6UvJrYFzHHSyVfEXaKuVNQ635aK+U9WxjmnuogTRXWuKTbylQ+P2+cEUnzY90yCruduE39qC8D6ycLe11fIwueRBt3cbs/hzV96tBfSZ3MHYm6c/2pl61gCXW+ZyUuSap7XxnWGds3GQkXzeAFr8o5w28YwkT1f2wpPZ3vE+cXWlhSek8AJfoyV7WmMsfsmVn1Fdckk0wynmY/hW/AC4iMubPyssO4cLRNQfqvQKks389QwJSWJQuksh9Tj9C96DVABNc0+9OMg2z8IjbpopLhOB6dKAhsbx3vlGgc6VtTNEGUNZ/BL2M4zApPecQhvfZrAAsJBubAu3VhUPdrh1q1sY9gNjEFjyr8IuVPPvFWJBvIh/u7uauerxSQ7Ce0d8FPWZJiNmOYt1lCZvZdV6WdFoUPBp1naqzPCAykv23bo67J3iCEq264xgT+ZA/Jwn4jbvClo4vyRNYmWKRfz9TBjIujfcgun7hMxSZNjlxN91849qHv86hpFU71OY2wmb2v4neakQygWYVV/UQ3qtcWFfS7bCnOg8JIYFGo9Mr3IM0ahxlpdskma2q3noy8glzYOwLYM+oP+gNWztH1NY94EbxXr8s2szuX1A7GHtAdu1eaiHkvQLUg3oERmhh5hfw+CmADPqwYQb/VtfYxhXfXsVV05pMI0QelyLy4M2VvsOhfmIxkyzs1u+FxVhigFMKYoU0Rf6H6zoevakX/gmMldxsYBso169QYcXxo6PfTM1GW5j5K+AO85igqy/PfczUxYPB5cpjUcxW5MAwPnse6eTUYFtZvhYkfyGn4tmYkau6ojfuy6ebeGCfHaieFdLScGD6YW/Ue/RhkJ+JD+2B1kidANWAPX4pQnJUi4jyH5QGFVQJqNoeeVRTwFIce2TY6uhtRs/CLzVJOjNzcr8qy06HhykNE9mGRkfGrTEptP+7t7UxpGMY5g8MHySCgtCiCvUO9HT2ixL7sNixlxotm67Qzzmwa2GC//L/WdGpDkTFnNsk7spyO5ezzQlOIGs2GRw5BbokYCIlBIfwQQWhLx8fKyLcACvsmZWNDAoOTlk/UeUOfeaC2/bpujmpMGSVkouSl8+gEZsVtkc3lwOxvqR8BZuSaWtdrvHEferq5d+hS3uYiisUDxYyC1HcADBDGTPwBRcAFcZA8yyGfGXUjTu/ikMagjfXvT0gC6xcTCivpSczd8PpwQ5EI5GhitM6GsdEiDg4Ba9X43TEJo2EZH4KWvDcf8ic8KEqCEcMzsM2wFXdLW9odxx23InQLqoqQ6kgnqsmF89Ca6 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)(7416014)(376014)(1800799024)(366016)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4ahHWp/WiwzMSBSTMzHoV4XMooKu9wal1N6uXBZp6KMhCbkBDujwM/KKhJGAHHR/hV4nn5JO99iOVouNy4xWI87RcTqV25srLLCS16NQlWtEhkgnlAqyHU6WDh1IULeWnRsziYpdQCQqQ+V2GHNuCFee5/XRxeP+i/2yxm6JyGeg/JQwioEOiNCKetsi8Ot2l8u56sgUbIrVLavy8/I8qGEhzJXhoG79SAzzUxWqjkMCRRjkf9mF8z7NircPxPUVkz3K9j0MyjtwgpIOmW8hvQEJTEcW9/RvNzKzJ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q6n8vCIw4T5FRWnlSR7MwZi93LmfPu1kL+yD2GYkgmsMV7AG8LzxGq0LKMZK5M9G0pe2/iMYkbBDDffmGg1YAeLz9mW4VlvF/5nHVVk1FDh0E36peJ+EaJYpiS/mhHnlZCVwP8oruLGN1xGfGEJpbe1DJ6XL7KPM4VThxysoKiGq05ZhUs3o04bFrvYHuWb9/38P7WocmWyBcdIUBSur9o14vOgjK3Em2yTlzMMK+vBmKno/326FQ5NSwyOq4kg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: xa8bd83GwAEdQLAyoEt4bd2WrzMtDzjIDnzXBZRyuWa7p1BD25oj3bNiF6df+3bXiBNjHH8rEjyJ4I4EWsBRAY42mJQjWrx7qE+q4xEe7Z/ysi7xVDDLo2qz1SvIzf3ZgyPdzkoK+H5CAFTdefNliYk8jrLpwwPsLFOLDRpSy+4heHxZUPQcKiIIXlCBawYwmAsBuVVejnErGYFapxk8PLyB1etkukvqpNGh/Lsr8EFkuLu8gvtOajdmCLxiolqDigNZnq8R7hSzT00NMdZY5gx9fsphYPEh+UnAFEmt8i6Rm+AUSSUPaCREdqwRPq5+nGUc07754IV4otr6MGoeMXNn70piV9r7+zSz0F4BX/ruFp6m0avQRYsqYN4WQ9XjUBbpcsGHKIpfe2WkqscytWlh9o8OTHv5ZMi1fSh3mOOHM2Mw3G4G1B5RAhtlJGYqEnhSIO68sTPKgAgNXmekrjQwP0M4+YBYhqYd70Xui/TwrrJPsvoWXmn59hV9hM4HgZv2Ziepy6mVlIfKvT3ryJ9FrmfBaRnFOs+VTwV/fVJYRfc9i/qob58/yeoPDfz9mtqV/9OY8oMQwCMSC0dWXqBi+91B85yuH7+eCMdncVU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0681714c-bd8d-4489-2358-08dcd17fabfe X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB7329.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 10:02:25.7993 (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: Nc1FS/YsiEZzQqsWZur8GveaszjgeC3LebMAzQfkCcmKywG28g5aW4Zkfp8GDrW6hhUDxc6TbGLGMTwVFH9OwxUzeoP9TiDW8+KJAnZa8Bs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB5894 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_02,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-2409100075 X-Proofpoint-ORIG-GUID: rnmyGKondh9D7gNtCMS5PnbJJkCmYxPM X-Proofpoint-GUID: rnmyGKondh9D7gNtCMS5PnbJJkCmYxPM 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 10:02:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=E2=80=9CWilliam_Roche?= X-Patchwork-Id: 13798240 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8B191922EA for ; Tue, 10 Sep 2024 10:02:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962561; cv=fail; b=CKXD/4dxMBAUOWfJEsGFaXEw2hrY/+sMeZkZR4xtCOeXWrdSj6c5NqOIVhmy0LKSBs1oVPFqYqRF2Z8sgsww9I56bs3soVAaGHGR/zjEDiRUbE5zigSf6696d7HjUcxcpsVUbapgigDCEMpuLbsLprv/ffr0XVWuFz04vJWV/58= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962561; c=relaxed/simple; bh=EzZ95p62oQvM24yrcHqIPrcWlldWTuoJQMuQZr9WfuQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=L3lkY90occ9o5CKcTj9TLelJM/W1SVUzde2kfqRVmHZYmyyF/9GVbpIERp+noB8B2ZPKWQPUdhTmZAYraXuX2Lb4jngFDk4mjV+dda5Xy2s1+Ca5O2LGS26k19OZ8XIbSZufR0LckzIqoDE3IezBP3Ki4Mx0GRFd2s/V1c3SN4c= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=ndo0yJt2; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=edu1U8S+; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ndo0yJt2"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="edu1U8S+" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48A9QXx6026793; Tue, 10 Sep 2024 10:02: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=liLEVMlOxr9MKo9jga2VkXBGye4xwDKxHC6nl8W5hQ0=; b= ndo0yJt26OPaqlUENhTaTW5adrueFssrnSwzVOfmu6lyWI/DLeN5IfoLXZlNhgNu jYNrQs66M544h7kvGzGmtl96SaGqVQvlIAck44J++wfxu4aVY7UHAQ4rZsg+a7WQ awx6gu5jnlZNFXeObMaeax3cEpWUWD1pgKIEe9jrnUVJwT2toJBnh9OkS/Dzmd3x 33uOBmAmCYxJDB0DzHlByR8LQLiBbhO3VQv1HMvvMBnjYQnPtHBEBIHaivrEcaPX RGxfkHeTrL/jH5swdFFuUbFpoEn1qtvLwKBrz0yz4gTf3GfI8nDgVBqM5nvzAv6G 8NrKRqqkV2nx42E+49K8fg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41gd8cw2su-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2024 10:02:31 +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 48A8RhKn004165; Tue, 10 Sep 2024 10:02:30 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2177.outbound.protection.outlook.com [104.47.57.177]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41gd98bact-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2024 10:02:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UpO4YV/Q9rJTLJzFx6nmE8s2XEYGTqpyENN5wjn9iNjnXgSW31tB1xGrOEQ6rBPueqCm7ZdWH8K4OrTrILb8SBQyZ8mZ9pwdNag1Rc7xCwTbcG8pI5C+SYXNnHXI5IHzyjPnqyUtAQFlQdbeqhzwj2Rg32WMi2pd18f5SedGyuDY3g64r4Sir9UBLB57WKr84eZW5BxbZM+Y49pBz7YtBwpLvv3VpvpkbBhZC/w6VI0akUK6aLmWDiutPwI3vEhd+4rLt3kbXa3qtexsSTlZpVW1SaK7ryD8T+9f6NAWIbaDzTSW4d8qLBBYj+BGRgH4Mwlby+lWU1HZlpjuaqFrkg== 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=twASUZ3TgCWQgrdS+CvE6M85OM11OlH0JEzKmh9qNojKKrfGVlbl94riK5ReWTgyKgFVwkYgJjB0BTrt5Uv1LY2j9s6fYBDZmhltutnFqgJFjiOteuovocz/S+0r0e7t3uld2xkKmfJeqX9k1x/pkyiNNZ0vHAkchb1hFtOWo/LgWMpo7Qdv3OBI7gfiC3Nl9yQx+q0qRZyGhMZTpoFnEHoxaUZNdEXu0WkUibrnbkm8oW2bEJAztCCCl0XInR5+mytoktNLHFAh1L+0BtBHp+VoJUpvQoSe2a+wi3O2SNxA1vWhGtGypmGwTomrXHKJrL+yZyW2lPNwAmji//+PLw== 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=edu1U8S+kGKXBBXu1QJTatnCopGUTeim6ehbyd/7eL2kJRlmdhEnSEilDnJLbMqwV1aGW3U49qpRyijLbxrtkTHnS6GfFwgkCraQRQL+oK7iGWOh4YjIfcwhc+3zPu7USEgraDd3Xq1iUFsF4ejZnEAQhPe/XnIAECXd8FF9EYA= Received: from CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) by PH0PR10MB5894.namprd10.prod.outlook.com (2603:10b6:510:14b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.10; Tue, 10 Sep 2024 10:02:28 +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 10:02:28 +0000 From: =?utf-8?q?=E2=80=9CWilliam_Roche?= To: pbonzini@redhat.com, peterx@redhat.com, david@redhat.com, philmd@linaro.org, marcandre.lureau@redhat.com, berrange@redhat.com, thuth@redhat.com, richard.henderson@linaro.org, peter.maydell@linaro.org, mtosatti@redhat.com, qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, qemu-arm@nongnu.org, william.roche@oracle.com, joao.m.martins@oracle.com Subject: [RFC RESEND 4/6] system: Introducing hugetlbfs largepage RAS feature Date: Tue, 10 Sep 2024 10:02:14 +0000 Message-ID: <20240910100216.2744078-5-william.roche@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100216.2744078-1-william.roche@oracle.com> References: <20240910090747.2741475-1-william.roche@oracle.com> <20240910100216.2744078-1-william.roche@oracle.com> X-ClientProxiedBy: BY5PR16CA0016.namprd16.prod.outlook.com (2603:10b6:a03:1a0::29) To CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB7329:EE_|PH0PR10MB5894:EE_ X-MS-Office365-Filtering-Correlation-Id: a0d7f173-04fa-4eca-d0ac-08dcd17fad39 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016|921020; X-Microsoft-Antispam-Message-Info: /elB657P2ZLYKNaQBzs7dv+IVk25jZlxujp0KIdsZXHNDJE6Wjxk46XO/wgd4e+uSvScQXIRZAPthLFBY8+mb+IhEH1rtNF1/qT+qrOgF90e2oOVh/fwWDtLJt80SQGpTx6dTG/zmPiYwhvtCTL3oSNJfYG0uZdVZQQzklB/jQcdF3okru1MWGMmbL2xA7np7F9osZDHNgvgGSUNlZAZgym+kvMzFa7cT0fx62ikWV/PMYFso4UOepGNAXEF8ZRtuFrp2GAiIpvkHUihjZQyLMlyGKK/46lXTPphw/hnt+jyKbbuTuBC1q+goBvq8dkcuCPIBdOUrWiR/nn73KyuUdyURAEPWHV2w+5eqK7vNe3vZpB1M7c5WmKqX8Jvbl00/o0RfxjRhXuntTIV6jJsnwcTrTyY0tXXM0mx6JQ3GBJjW3hZmuAd+aRGzs4233tK0LM1XeqAe1dMi4j4tj18O6UHJQU0z/Tr/vX9PbPWL4K7w2H5t51ixM/5W82U5nYNVybxxKBvTXSOvXTvGMxk2GVrlSEdXQFm1152lkHjWs06uC4zmbDO1qwcQxHiZZrAYkAn/NxWpVLQqq+0LV7w2SHxLRubZfJpLoHM1JOaCXvxoTFp0XdS2azVvQuoMNys7qYZFcGMMUSxsjXfgQTdK4UoZlRmqHZHcM+3wpfSs4jnzQgd4VQf9rHJY5bPoek83fYyMMLeD0E2beBNxBnkZ4ILepex1FHo3LOw1SWVdZx6IehebIHFtqkEictagbG8gOaV2EPAl+1l+zvZddP5F0XE5uV3wIxUnEIJM9IaSB46RCF0uDzrGqbD6EskOK+QzgeMpDAXAotJHi0lvuHwpCTn71XPf4yxiks4M/MRORevBZzutw4ynD9tvkEDtFZStG4lOmsk3V/8XOCB45Wg5biLpGu9dtzhLuHsr2dhXVMsH6VZUgqEH8FIOXNaRPealC1qGtU5OCVThnOojxzOAqPyLbv7bSMxbeQvN13zkmSkB/L3/Yy1Bzd+tf2unhPekbezRI5k7vFqzmHfFppen/g/GWhWyFgataIh+C3RC+nkjNbIxcztA6+hG8pdNX/UccH/e7BWI6rFQtFob85JoUXdOSxAfl1nrHd5VhZhUW+gvU3o9QOCj7aSyUlSXZslJ2J6DAzr1yZz6qLI5KGxsckRtAjLWhePHAk5aijzITN+zt/W4sJ2Ek0sZE0usdqaRDG44mvAsqRGH1iKpz7+dhwiixRa9TcEgg4dGREGE99TvXL/U9Biw0PRkV9hVlx1BBU7ErYtEYWXs1tXR8X/VUlWzF4vLNBo9FasMI+VSjk3/Z0I7/962ePYP9gbqP0vHYAMrvhIR+UWmaOyLcul/Q70s85YNJfSnwgQmGe9EoHFMEc1fUZbLrGyulj2nB6r 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)(7416014)(376014)(1800799024)(366016)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jSNRRAZxOr1GtRaSVgarwXfTQb8O1R3lckrkmi/Wcspye0Yvvhl42gy1imvyLrjYcba6rYpAhpq6K084q4zSywmVoNleiLUSKy8dMZrvgyx/qCD/aB5SMJpAuR545Z61Xtr//a3DOf6IWdpCAtQNjqPciek8WHhsQ6ykbuZdb7i9Yf6Y3G8fbDah+f7aqL//eRlB8ALVwmX9/uXkbxqi57glVPF+OPw7KMRZoIs3GyyVscPwMvk1vTo9aW04e+CkyLUZPblqswgLdOzzHVUWSClF/FkdMeGsgnmb95AwEXYjRnfomETQyGO3n+PsZMf9gorLYcrk/b4w53SUWAY3vDzXi72QMnVM75nw3BpReAEzaubmSL6IORAz1Calq4DzMy8kwpfc0vlRqr0t7zcNgoB6o1yfDil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r5m26pwSmi8XOAFKwYLwDQfDOimJqPzMlTrj4ogRZ/jnQa/EMoWxCf3Xy45/1AzLAFeM/K8iW8tonpgr8sJ7+Ssrnrz0PnTYzNDRRXJEgavHvhaRFHrkYkZVQfmG0aKQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: CcIj5Updvgi+gsgArbjR/yrewvr4UcI/NQZXw/Nw6ryuPYz221szVc+2cZRIcHHNmUPILLi66Ph10x/EFBO5RfvmrUtWV+Nfb/KcuJJuH27s2TCmF/F4b3CglWTaSMKug0xfMxRF2rMhvZjOlRqjlsdYCxZjfiFBouF7srPO9EIIF416gs+/lD2Y+ZxHcxQ6QXxb62YxLVcnS3TlalcKB/T3Id6iYvVIQSySxEUcVhsj560YnZB8r9E8PJw5lSX7C21tnJCIYPC8xYE9Q9bmRn9IfrVg6k4nqAVBTaqXM1dFc5GOeip/NEcGAnhl/+Oq++AmgNAvX0aPMSOcdJDYlw7HSbUwaNYl3nO1uNV0rsFz3LUeZpQ5DBt0uC0eAbbGMrYBNr7cwE4czx/PnIJHIAObt3g2LxfZkNCQH2fA9rAJjA6y/xzyvRBznIN4dQE/+pQMiOLCq8vud33kSA0S9MeLehs3NsZ+pdkgzP0Ccc+P3pb+rmMbZie/lm3mELnl2ylTpq4bTZYMPAd3Q/Ms/Zgza+TGpUHKcvv3L+C6ZPCTSibNiz5OFpTH2Xgl/65/ZmcJ2X+yHfT+L6jDTbUE7aITeHqCjuFjIrjfvVB2uPY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a0d7f173-04fa-4eca-d0ac-08dcd17fad39 X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB7329.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 10:02:27.9947 (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: lkxj8+aTEy17vf2pi9Z3nkw2rVCeIuL+GxvZch8K1iuFxS0W5w61Qbza3jq7o6i4BCEW9oNt5mGGMsostSf+AtyVtFgw2BOhog0o9B7uffM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB5894 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_02,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-2409100075 X-Proofpoint-ORIG-GUID: pGlFbq6NfxZNuSAK7nIVGqCa3T834aqd X-Proofpoint-GUID: pGlFbq6NfxZNuSAK7nIVGqCa3T834aqd 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 10:02:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=E2=80=9CWilliam_Roche?= X-Patchwork-Id: 13798241 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0F4819049D for ; Tue, 10 Sep 2024 10:02:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962561; cv=fail; b=lo5se9FULWcxLBSepSjJd0PekIvkWBYGx80lpTcDq+xr7fAI+cJc24ia+ToaM9Hi3EvvwJr/U4jc5PwAk8kCPiw8EfNFzVk1CxgTDlkMBb5reZ+maVdTtOC7gszeU3Kozp9cLkS0ucD56mr5DRyeivX8IvxP4Xr4OAyNNlHTA1U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962561; c=relaxed/simple; bh=Eu/0qcIr/eI4L/hb+/cSd8PtoLkiNdf76GVXAT3PGf8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=dwEK+6WLNJG7bHXWYWRFJep+yoAe3VxsHTZ58ARypggDnNR5b26xOK3DyUpJ5oEB+DgZDgIuVFT8HJf5IbGnxUHfOtLQ5fVcjEJjG3icewAA8e6LBxZontdmLY1ebNqiqMa20RGYiwZ8GW49Bkn6IM/yf6hjBxsG4xHntDi210Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=iMZGZsiI; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=hSQ3n8OE; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="iMZGZsiI"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="hSQ3n8OE" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48A9QV6t027615; Tue, 10 Sep 2024 10:02:34 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= iMZGZsiI7NapdkgKri/lyAeJnnhqZJKeDqUW7/xckH3XkYubnfMhnvsHIyowgvzJ Gyl8sMHb2AWR0XTlsJ+Pt0PArYStx9IWaXDBYMJ+tkzKbY5P4HmJbYfmkZ938QZi ilxwWZZrm6F7Z9oHxFGBeTPdMYPnvd+7UaV2D2a1OMgLC9UGruhN8TYort5Fr2nW UeEFFroodYXnJ4vA6BIiI9mstac2gsXh2KNMbjJZVmuchYskDWa6d8OAvDhxYAEH jOChk/+LE1Ro19docfHbq1glznanYXJLZW3IUoCvsnSFVc8N8YwGrT77KAc/F2fn 0mEZjxac8t8/HvaVUCSzwg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41gjbumwkc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2024 10:02:34 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48A8C1Hl033550; Tue, 10 Sep 2024 10:02:33 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2173.outbound.protection.outlook.com [104.47.57.173]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41gd98bs0y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2024 10:02:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KnOC13hYghUl+f+BMW1CoqxSf3e0ndaAwCLnCF024+3nTznj465hLj71Siivcw6DJOHi6XhWVcZw8++Aq3c0J3S5Y09HgkNgjxoPp66j3tuooV4FSF1d8i69cYP7v4aUKvTe3X54wWvJ+ETrKg2yEKTRUBb/S6BFAa1JagxfuokKp8/C12lIdHxCh/Uf+3GwVKWxkKcikg9g9R8DPDdKUm5RgIy73eBgIPPPltD0DdOdEsjMUgRh6yZzlsXBlnLVgMOGyFo7hOiaQidwTdpuFsAIi1pi/+xzJYEgrPI7pXBxKGxbMdO5pLeYsxW54irMRqxDKavCJ0+sfa2w6ryJwQ== 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=ZMJB+zj+3mrfxRFqvHQzAL5UKopx8uTqzPAQ9gAsn1UzG6tlfgYEBaAksQv5MukTf+gX0qCHHUom9OsSrkLVRgM8B+zmhflt6gKuQmnb5UerE0a0IUXvlemZ4pGrKIn4wJoNS/6oCrMXc3t6IuEnRtdLH6RdUTXnWw8vG7DZ91x0Aal7TgzDWBv+9QqKD70iNkW9iXglZvZWZ4owKjcYUBwVPoZqcrhBsfpjR8KJo3WAl3itEJ88/Gnrt4mhX5VnMLZZPcmbASz9/hUTIKULlH55InsL+tMFsu27ErohvoKjzwTlD/AQa7ToI+IvtBocfcAxhfg80OdC9rQ6yrc5BQ== 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=hSQ3n8OEysTratlYABDGG+y6SJ1sd+x0rQTPA4SYOgxfBphcq+koANfemhSEw8woZxbSI35JGAAp+F3iSd4MLoz/HLryOFtODvriCZ8QOFdfN9OGaHp1FIcgtEsD+5S85+Ko5DHiFDD9M7RFfPhVRxAvobhFkvNBDSM4UzePqIE= Received: from CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) by PH0PR10MB5894.namprd10.prod.outlook.com (2603:10b6:510:14b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.10; Tue, 10 Sep 2024 10:02:30 +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 10:02:30 +0000 From: =?utf-8?q?=E2=80=9CWilliam_Roche?= To: pbonzini@redhat.com, peterx@redhat.com, david@redhat.com, philmd@linaro.org, marcandre.lureau@redhat.com, berrange@redhat.com, thuth@redhat.com, richard.henderson@linaro.org, peter.maydell@linaro.org, mtosatti@redhat.com, qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, qemu-arm@nongnu.org, william.roche@oracle.com, joao.m.martins@oracle.com Subject: [RFC RESEND 5/6] system/hugetlb_ras: Handle madvise SIGBUS signal on listener Date: Tue, 10 Sep 2024 10:02:15 +0000 Message-ID: <20240910100216.2744078-6-william.roche@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100216.2744078-1-william.roche@oracle.com> References: <20240910090747.2741475-1-william.roche@oracle.com> <20240910100216.2744078-1-william.roche@oracle.com> X-ClientProxiedBy: SJ0PR13CA0071.namprd13.prod.outlook.com (2603:10b6:a03:2c4::16) To CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB7329:EE_|PH0PR10MB5894:EE_ X-MS-Office365-Filtering-Correlation-Id: f9f31a53-56f5-4e4d-b37b-08dcd17faea4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016|921020; X-Microsoft-Antispam-Message-Info: z8svcxqUkpXhwhPSdttr7t3dwEYmR+0qCE73OUXB8Uo14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Cm3Q34cAzZ5BJWgaSagVK602FebTygveOLz6So/WVikfGpfPjRckdU109G9NRv9O3Y9dBCek1PPpFgWCUXvxMk/u9FK+4F8R6muouTCKA3bcj8O0yxDKhVqvCCQ2ZdllbnfLfyyR/WURNB+2pG63fCBvMc5qdOrXK8DjJFIngf0SOYWnkYg7Du5xK3h9EsSAqBnD9sWxryv1EoMxR11/DobFM3gRtb9ka0WhZeW6+Y4BR6EtTIrYcwsiVzn+otpekhl54Eij1lsqB2RV0hxR/w9ImXFB/yNq0aM 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)(7416014)(376014)(1800799024)(366016)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pqTei94JI2EucWBZwbTW49Ghm/i1wAAxWj3gqODofQFbCma1tEKPxVWJxyIcx6qEhaeV/YvXRJQzSkcjHV0YEwQth4Eoht/Ajqcfk25LTVbjXwZKta56FgrDeCPX2mSmQRYS1BkW8k12urW4OTiitMdSk/7g+cJ8Dc2ohpZ1cU/WkCHKtdmJ9mAXVoa0PPt/ibKO1DChW16OgyO6Fj0duI0lGMaV1sMQdjLOAiko/OZqYPw8xloD0T5gtkYG4qQSiErT+Tk4CLDvdPFlSTLawFiOf1WYA8Q+vPfmFQzatVA73vRGkMIgTSyfn7RHRBHlLWr5Z73HGuDrEhHMgD5eLQSws0JFB20SfkLaDX/q/06mDTp89R8DF5839k2uPlmaX0u1MmY7jrlRQeAhWJeSel6kfwNDxkm+eZEOpdG3KIHe4N+I95jmmcVxrNnxTm3N0iqgdej5s+XqrQjVZlDMttP/aeWJoB50mhC/zgqtO2kmobTeLnt+96i1U0absd9gTgb5f9uVtBJeUX51SBl3jkGFT9ltSw7x+kJxid8VJqwTLtQ0LM3E35g8PwNIY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kCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 8W1niBl+CmOVxW2ZVUvoR+AlEU4bgyqzttw4W7HoVXZMlz4xd40DVo71dGhWesxUs9gDtHt/UaZIhGz2Ubsxp7c3tRCjQn/XoExxSKL2a7Uo9oovPEKtYCr6CMAOx9mevBfTAEtXCxzc2CmfxtmQYJAy/EKFELCPQLcRjJRQ9IgZLkg6hhJgEugBnbyHLpph2D6MooUs6qk0Uf5THeu4QjwMBSsd1EICpjQF5cEXU6kP7JWY8UaotH0w5HKKuygeu82luME2HuN26sHhzuHoDekd7Qkmvh+7rTcxlMsVtJKMFWGw4KGH2etAKfOCOocUMvvISnBHXLn2whR/eTXlwM+e8s4YM63v6IgzqFAHKOaokhsEVZ2OxcctI0/GnwyCG+ArLsGtI5cWE7rY1DsOVWWjA4Q6tvcAUKq2LJy7iNxBO6rzZ86X7Gh098M2oSsBH1o0N3ok67/oMeFZIfvlwsRyD982URtKSiaCEIYawo3C/DQaMBcfNyjISHxRDAgOdh21gl4y6AAhcj9/CeIxgn2tQLYjyOhPdu06WfnCa7Lfdu5vFufW8Z6uMoVKNn9QRVs03ipg7RImWXG8CKkOFJyW2m9DW1iwhC1hzWBfpYE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f9f31a53-56f5-4e4d-b37b-08dcd17faea4 X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB7329.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 10:02:30.2914 (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: AkJ0cV1j/2jousaO/Tgm2VY4y1m9n3jhdDK9PuAkTSducDfnjhS0b2fIkfOe5EHrp2Hy3eM9oxspu4XkfONAKF/lWUKGKSV/4hkwegnavyw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB5894 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_02,2024-09-09_02,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 phishscore=0 spamscore=0 malwarescore=0 adultscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409100075 X-Proofpoint-GUID: gsE44U6I7-Iqo4XMil3OPa1l_RjgpF29 X-Proofpoint-ORIG-GUID: gsE44U6I7-Iqo4XMil3OPa1l_RjgpF29 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 10:02:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=E2=80=9CWilliam_Roche?= X-Patchwork-Id: 13798242 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D764018C32B for ; Tue, 10 Sep 2024 10:02:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962572; cv=fail; b=FVaAJzqxBVk5inIlMKNLsZQFuE4Z3w+SLHCARRDpft+1PaGL5065/08pZAGb8fmym3T+50F/tBL8/xv4eTJK7AljboXGHzb4XYwyeZA4nPbwlJC4lZ65HHZmXdXpv+qpYFXg0wDEzVVwODaYXcEnmangw23oRO60wO59e4e7F/4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962572; c=relaxed/simple; bh=Scdh7OiEj4mxTZznQMCy9eALQT+A6VPKk7YaemlYF3A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=eoU0LIcdozaJzHOWGxcQpepJafKqI6izlQXDsh5ESh87HER+kMro3rdBP7kVsb2zV9UcOQ07aSXRa8zS3vYp+FuvXGaXj3KEKQxVvBQDs7BxfLCObh4vIDNHUEsjL2l3s8FVpKNuVkMMpHzpoVpmGrakHtCzttvxlEn+kqLUTas= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=RlYYAb8U; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=hULaZaKT; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="RlYYAb8U"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="hULaZaKT" 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 48A9QVcH022346; Tue, 10 Sep 2024 10:02:37 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= RlYYAb8UTzBVLAXWf57TivquzOqiFxRn9Ntq+xg28dbfqmCJ081JlM0r6qMwjwO9 +K5tPT+36Up+qOAeR6ZilRxV9MoxSGu4ulguMo7laFJWAI3Ijte/nwSa5oVnyZBA QYSrkiBxn2lq9HK8Pi9ubH+/083JGW2I4UAZWMMzvA7J+zGFFliSPXo+QaibydTD vZ9tPNJrSyg9hwWIvUVFDXI9pyPnKiz+gyrsZA47guOLxOQMHOrOwXA6OSVKGF3a DXkchcHgth8sMhZd6bd0O6KaO52WH8EvHChiMiMIH3PeDbJ2I0ErN+u/B4FT79vo TFr2ViXH+/s2EZN+5B9mKg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41gfctd3yx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2024 10:02:36 +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 48AA0tjB019798; Tue, 10 Sep 2024 10:02:35 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 41gd9eugka-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Sep 2024 10:02:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FtxAO6WQbt4Vq3kGGRMt7+b5z58r4cMIeyKf3y6ks1z68J2HHETEUTq45l1DBt1WMy/uEaqhwBJTRfXWOv06a5W0q2Ys2hs99bI7XLW7XuaWLXI8lKbcGeoVw2DJ8M0TDSnqvFdBf0/NakzeFMwZlxCtvzMUpMttO1p5sToSq+I7zrPXcJKAxy4pLy2uCexlB6jXrVAR9Vn7SF/BZ4+ajUYa9+bHoDneaksJeKm+T3v3WUr9al4NbD4/+6j3kzChg+d2gyhFU1f1BEQKj1SRsGngwUk5gUK/ALvGqCf7bsfxNG0MrJslz9n4ifZfFdrk1f90ai26yptvV20rA2NDMw== 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=BZHWQXtMYeziAeWtszGtHREKR2M2aXwy75FTkGl9AOrZH7OjnNO0mgL5vbTWQWUKJaDmO8ykXWo8Z04RJD/pZGqn2F30fBx4ITLYrwg64Z6X7BWo4p5xymsmbvDq+vsm19v3DkxcSpSg6ANLiB9oft2I1cQ9E5dwaA0LVl+aathQg7zImpvLs0d2nb+9BHA02P2lyGJSvIRIqRm2an8UUOEAP/9XD3CGh9rjppZpHQIScUjlY2kiOMuEhTCatG6S7tCrCtHtJQ0MKUqomaoZXKviCft8izwx346qQtQFO2hqZsIkRBjmvJnn7tXbYNe9Gi1QJyBoYFNOkLxM6/vnPQ== 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=hULaZaKTHXdhSWHzg120OgDUjvbWoXWDDfXdOfEOcNy1hXtvgdVfrYLgGRwNlAaILrem1MAxV7+isY2iaRs7XOWxK0HbTphaYK2ruRZJ8ZUme35LCp4RJvEqHgQPWizixatUtHzgmx8d4RMniI8R5hQIWy6HAODIYBV151FNL3Y= Received: from CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) by PH0PR10MB5894.namprd10.prod.outlook.com (2603:10b6:510:14b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.10; Tue, 10 Sep 2024 10:02:32 +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 10:02:32 +0000 From: =?utf-8?q?=E2=80=9CWilliam_Roche?= To: pbonzini@redhat.com, peterx@redhat.com, david@redhat.com, philmd@linaro.org, marcandre.lureau@redhat.com, berrange@redhat.com, thuth@redhat.com, richard.henderson@linaro.org, peter.maydell@linaro.org, mtosatti@redhat.com, qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, qemu-arm@nongnu.org, william.roche@oracle.com, joao.m.martins@oracle.com Subject: [RFC RESEND 6/6] system/hugetlb_ras: Replay lost BUS_MCEERR_AO signals on VM resume Date: Tue, 10 Sep 2024 10:02:16 +0000 Message-ID: <20240910100216.2744078-7-william.roche@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240910100216.2744078-1-william.roche@oracle.com> References: <20240910090747.2741475-1-william.roche@oracle.com> <20240910100216.2744078-1-william.roche@oracle.com> X-ClientProxiedBy: BY5PR04CA0006.namprd04.prod.outlook.com (2603:10b6:a03:1d0::16) To CH3PR10MB7329.namprd10.prod.outlook.com (2603:10b6:610:12c::16) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB7329:EE_|PH0PR10MB5894:EE_ X-MS-Office365-Filtering-Correlation-Id: 03215d93-5641-49b8-edbe-08dcd17fb019 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016|921020; X-Microsoft-Antispam-Message-Info: EsSO2UGLVZdpUvM0EhBCbsiYew0Fe/viWSjhQxTaupscQyDTmA6fuUm5h2wX3Iws5bC6bt64YFZRzr48lOYY8z2rlpQ+4okLdZCf6JQiOG1PM5iYnM159gR5P97pDvERvwU4qbH51fo2EjO0dmO2tO/jF6prj4Ofn3nHlLBkAuIRX0mf7vwFZDuYfk68QIKDez7A/CasO8qWW2i6iqCWv4Nw9ea09thyUpFWTYwNskT6llvO6JD0eQR2v3IVkXfpAPWSul5/lvhaZ5fU9HtU8+BwFpVaG3GDjtI1CmVPVhZQOQi/A1ZLHYy7Ohx7gqrkpurkojwbZn7rofyx+I0nNSOkFSvjTDO6u1zeW4NRIySs/FYoiM4rtK3SYl07EpNG97H81E6xeJyYkTFVsxHpYD3R0X757yNh1x9aYCsg9N0XmY4+0Xsp3yHxNSY+2BPpisw484htcL9p0eIQ8YE6FQBSk6qSs6am80DfSbPybTyjzsJnCB7725LXcrK2txwTY0DmMECRrP/9tOJhylwoK4WWuPjtTkxHILqPqj84qcVleObJsVcQpVTBXS2vSOeeQrnnNLHeiR/FLYQXKFz/hO+7JS5HvJb9AunBjU4xVP+mgPhu/YbeKoXjKtjH4yuDjWSNFcGLb6YFDVPWYD+NBoMFpa3mD3wcnjefxo6dX2RbN2BqhgDrlRdQRhJWEYI4pUU0cXfphlZKbT9FrL+VSAS/e42lcyTPA5zZAD0mkMhn3JD0nvZrPHbjV04CqXBfLT9tR2BhFLZjekap5orU8M2u/a8e0EWFuhMUH78oCGKAmIA81BD3Qwpo7nv9/Xleh0nBEdbyzxj9JJ41uFpWcanX4eyrHlk1d6VdizU4lT7F7TfYqYk8ewspVLcm3TbryxDwbpVL8y+Vs6Zkxtj/6KYD7VQ9rF5FZvKw5AAT7hZxtD0fSLc9PcN9dWq/tJiFMSi97AzRUqwvFyjY96bnEsbviQ3/NU/yAoLPFLODFJAOg52zFRdekWO8vg6iWf1Gj/dh7ZU1h0DcbdIh9LCE1JxGRHfC/uIINR9TcKwb9rDYF/CRUD+Iw+LkPsARHnxMxAY7/dG1dNy1ZIdazt6SrsZEqV5gm2aHQBWhDbiiFDtaBalSnE1kz5ZlFqZB+guAcWusnv+/WBAk2zeTZdwdDTVkGCmVS9gEObtHJ+a3G7CXFGtmUtJhmucA7tYexh3NGkORQXqKY4ShXIq4S2AvbJQsDXrzovXfwqhJ6xoHd4gH8AOt5My1r5nN45+bTa5x05TQoncrtkPFsURDagig3Gb0WNWnj3pptmSVmck4dOl/s5Jg3k2gN1anMMbil21fTHucICTEyVTb8b3gD9iLdyutfWLAxWvGeVWSgsEr/QL2csqzUjYVlifqVZVNZ2oH 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)(7416014)(376014)(1800799024)(366016)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uDvYovXieU1cDOFAZeolMNhp+W0IxmtcoujbL117EpApkc0T/2zaEZ9VbrygnhrKGYx9XyVn/yIDZXhLgCc5BLmC5n0vY9e30BtWkci2yQR82xuC+077MrKrNB7uLPu8DgifZcoS60BNFqSOvzfG7mpGt/WQy42d5QUsahh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riginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03215d93-5641-49b8-edbe-08dcd17fb019 X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB7329.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 10:02:32.7074 (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: 02jud2HlQfU4J1fx52HZD02l9EV8z8KX6zDz2aJq0VYi/HCGB9JbtI+SiWnhD9HuGJdepsx+z6DklSAamLcgD7774eDeUglgMCd1HJsOwGo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB5894 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_02,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-2409100075 X-Proofpoint-GUID: gc52CITwLG83E-NazIeIKq_AI3ziclBh X-Proofpoint-ORIG-GUID: gc52CITwLG83E-NazIeIKq_AI3ziclBh 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 *