From patchwork Wed Sep 20 14:02:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankit Agrawal X-Patchwork-Id: 13392838 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72425CE79CE for ; Wed, 20 Sep 2023 14:04:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DA426B0177; Wed, 20 Sep 2023 10:04:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08AEF6B0178; Wed, 20 Sep 2023 10:04:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E94956B0179; Wed, 20 Sep 2023 10:04:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D8EB06B0177 for ; Wed, 20 Sep 2023 10:04:15 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 85A8B40D7C for ; Wed, 20 Sep 2023 14:04:15 +0000 (UTC) X-FDA: 81257145270.26.0EC9066 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2089.outbound.protection.outlook.com [40.107.102.89]) by imf09.hostedemail.com (Postfix) with ESMTP id 8574F14030E for ; Wed, 20 Sep 2023 14:02:35 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=De1iAOeQ; spf=pass (imf09.hostedemail.com: domain of ankita@nvidia.com designates 40.107.102.89 as permitted sender) smtp.mailfrom=ankita@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695218556; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=YZ9WR5mTfWIaAoV3mw5WTI527fuGHb8ijeoqJ8wZ8Pg=; b=b5njbjvyrFpGpf+5kG02hJP79W/SEpZ5+GlHhm2ojn3B2MipY6uMnuL31qqmkh2TYxqItI D7RGLghoZv+cJmMbcikfPfevCRG0N5oxK7+ftJWkFgdFgCjdFqXCxDXCAhMdMmPFqsx9U1 znYwldKTzBehORabQ3ViUhdoUL6I6yY= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1695218556; a=rsa-sha256; cv=pass; b=AmBgVUzRERzobE3wUhnHht3WMJKSqVcaVcdZzx4XCMUfhHDVwiPw37dLEqWxFFI0pjA13z 7UGqHJ9B+8mw27S9GhIMAQyibwoUUaurrROC5TWk/xtSVL/n91SdfO29b8DP7ohGi77ez0 /fykaU0Rb72KrZvYT77PF4V9k26Aer8= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=De1iAOeQ; spf=pass (imf09.hostedemail.com: domain of ankita@nvidia.com designates 40.107.102.89 as permitted sender) smtp.mailfrom=ankita@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ksjWE2TLN1v3TlwzaqJge9305wB8WvlRrg5oMxyGQGwWByACloakePookXH5k2B7Y9Mb7oFDjVt0Sx8igPRdVQon3cc+XsxKHmJ90gj2kRoGAnYrj5mLkiMQ4ZF6Z/XzS5qABRmkOcRaLn90Sorgb2SAIFjeCbEzxRgIY+OxnMci2XR+dfyc2uefzIsVV8VQAcNcdmbqs4c5Mt8aowuVbSJQlToPWjPHAsHnj+gLWcUjs+4TK/4kmaZ3PjVM9HhTYXiRZPw0qQtW90ax0xVYraFUoBOMEs505bm5JyppHCt2AEtjjr+mICUlVaf0+ggCRHdx35W8jE8mvFPQHU4XSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YZ9WR5mTfWIaAoV3mw5WTI527fuGHb8ijeoqJ8wZ8Pg=; b=jtO0AX2CwqhzQ2FSTPHXLOUDPqM5qRCS0Xi13VAkQUtlNgKgnrtmdIghfBeQdVgG+OVFp1+BAlyds6TpcGK/PUdTRaTlsqwA/RBpaW65xrzt/RGGSjI7OYkIqqn7MwVCHBx4FOm7n4mIxyh7ExrozUYwrjaQWrXIU2gM9CRJfqduWNYmP0RBw5xo/sJTNoAVNRkMOoaZfrCmdLDZfgBrzbMJh60G8wW5tVgP8cOGm1K9x7VrZNJXYlMgjQ2UDiTuR4KwJrqPFsV8YF0ETEWzDXKqZeQkYqVgeUE6DXbdzu4CeuZS8zgYooeBt4acCKndfs+FYVQGFx39sZaRFp1KJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kvack.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YZ9WR5mTfWIaAoV3mw5WTI527fuGHb8ijeoqJ8wZ8Pg=; b=De1iAOeQOsvMkcUnNanT2AoEnFnhaoZNi0xDTb/+d7zykHAFz/wYh9771OQxue1H94rJp7NRlOqUIg0Kkm9AmYlo4QLVIpEins1yQ8vhWgBd4TOnIjGrootAbQ+SLL7aNncuh7z3QwxwyFmZg6qfnHUw+iZjgEJPwrFcZRIp3NDS7AuQ/cNQtAUR5rZ0DSpzjkJoZ+62qmoXxVTO9ksDQLQ8POAVnpoGhhqy8vIlHApF+vs8m6/fqynxWKSD5ny9f3//W/KvIaznN/jmci9SHx3hgMiPkkm5Zuru1JNtfLjx1oegtd/rR9ptN+GLqojKFvJX3F1iLvWgZ+IBcRNhxQ== Received: from DM6PR06CA0059.namprd06.prod.outlook.com (2603:10b6:5:54::36) by DS7PR12MB6094.namprd12.prod.outlook.com (2603:10b6:8:9d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.28; Wed, 20 Sep 2023 14:02:32 +0000 Received: from DS1PEPF0001708F.namprd03.prod.outlook.com (2603:10b6:5:54:cafe::31) by DM6PR06CA0059.outlook.office365.com (2603:10b6:5:54::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.29 via Frontend Transport; Wed, 20 Sep 2023 14:02:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by DS1PEPF0001708F.mail.protection.outlook.com (10.167.17.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.20 via Frontend Transport; Wed, 20 Sep 2023 14:02:32 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Wed, 20 Sep 2023 07:02:18 -0700 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Wed, 20 Sep 2023 07:02:18 -0700 Received: from sgarnayak-dt.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41 via Frontend Transport; Wed, 20 Sep 2023 07:02:13 -0700 From: To: , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v1 0/4] mm: Implement ECC handling for pfn with no struct page Date: Wed, 20 Sep 2023 19:32:06 +0530 Message-ID: <20230920140210.12663-1-ankita@nvidia.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001708F:EE_|DS7PR12MB6094:EE_ X-MS-Office365-Filtering-Correlation-Id: b2d279b5-c173-4101-6432-08dbb9e23be8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 825oSOByUb/cBTlj9EfyOhnC16MF1cATirVI7plUrtb+FME3kaV9KcCSvp89ZPsof1Liagu5Fc7bnLxgdg6sHar/XMT7GXpevvqlyiYjnhG5vmRUxVZszjt9u4Tpsh+sJSFL/APdl48cNi93vph/1w53GTXi+RamjfNuzBptKPsxTiQrjIakhQdv+WmeA5qdiKIqHwztpmF0IkdTvCuCLW4UrV05h54iofOg7nucR/lGNowdYk60LRB0rqkvHwBM8ldfNv5QcDy/Umqi564KfQefH0G5VYrUewUMlH7t0JyEFKPzoe0CDFz1D6iZE6oV5Be3nHmuwu1g0I/gRBs/b/9Lz+oFMtVfoJYjOSBo1DgHhTXfs+qlGwey2hiANf953YSm0SmXuRktF+j6gRkKgRJvd5LkGq+lP6ApVyXR7mRda3HBEXfYzeprxRJRxoDwlu5plXZBZtwE0ntXlzLvMS3yZnQN7hdFsJQzcw3fDILpzKTbDO6948uohwbrhaDV4cCVp7NGeKW42jSQofS7CskqLspYq3Qf/KyyhhmuKJ2HbC4yssFPIwKClMB8+E2pv21Qj6E7/TgQOp8j+rl8TyLXYin6V/CNaL3xvgOJG/MOb5Q8yKGGekniFJ/6ahmIQrQd8ku/77kQYWAOqVsNVl1LXHN2QbyGJYAIPm3YLtGdlS3fenv2uI4QczX8E466Vlf0dJdjKdC1SXb7MugnNzhteCqFB5qMaCAveeLkQuRjI/J6auYx8J1w7UGjfwTjXM1qrOmB5ngBNCDoqzN3zKHdufhLpsDoXbZh747mHKU= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(136003)(376002)(346002)(396003)(82310400011)(186009)(451199024)(1800799009)(40470700004)(46966006)(36840700001)(7696005)(6666004)(966005)(83380400001)(478600001)(47076005)(26005)(336012)(426003)(2906002)(2876002)(2616005)(70206006)(70586007)(54906003)(8676002)(110136005)(4326008)(5660300002)(41300700001)(8936002)(316002)(7416002)(356005)(40460700003)(36860700001)(1076003)(86362001)(36756003)(7636003)(82740400003)(40480700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2023 14:02:32.0484 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2d279b5-c173-4101-6432-08dbb9e23be8 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0001708F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6094 X-Rspamd-Queue-Id: 8574F14030E X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ffisbrms1ktyqioiqk8rzp19kb637so8 X-HE-Tag: 1695218555-130940 X-HE-Meta: U2FsdGVkX18TnEfNoUAWzTbfFS3lQv2jtSEiOeEKLBuOd2rcZeH6Ki/Fwu32emB2Ex36POJ8hwonXQpJI3ZZrcnSkzzi33nY7Yo2f/zJUKBUv5Uket0vWbZ9m0LCLc8XlL60wkbPHhgFklQby+LRXc+F4HLp6TpAB00UgObgz8Ah7PICZ+d31dpgXHEAEiu7ZCzuS+yhcBhkPsy58oJYL3KLleREnQYytyl6uaj3A+nuCiOVmYU+19paxDgvH7WEd1VTooh9IGqldrA9JLFfcA4E81d6OP+0uWLNwaShQn/pWcD6m1Rzw+4jEEvnrSI8WUavCzkt+CMF1KoWDH50aQJv+UlZTg2jllSicCbM7ZPzGjgPFXqAzZszH3GR9jZ8OiT1jc6z6De0xJRe+EU+oL6lEPONMgSt9A8S1wxgibCJBBSeUe4uwqk0t8dR/j/GzsjFoHwF+IuG+5Hd9Z1wj075dqobGBOG0cgs9gp/cFb646UAXAOjOVJ1Y+5JshhS7viwJOgIMSwFd33CFQIzMctibiAhX1O2TasoJw0eEno7s9fCR7iOOp3n3P8t09FL3HqrZd00z2ICtk0OeKB/OWcDZn7EpL93CTFSX2QQuSF+uhBqWCtC7jnCjUZiwrrqANydJyNd2aOdP1871SRbP5QgrIrOiwG2KO5T2gb8LwI9/AsDQQU7Ni7YgiUQrXmn9DTPhhIbQjqUmmA+AKUVSMySfV9FarnNn4lYUnzu7JxW2WTS707e8eR4IsCj9dWWh0g79to1DqNOS3cQx3MPjIjAiM9IW9fNOhq7EuanXyEcM5XR/iyjIcb+WnD8g/lzsPWit9tjb3NOuJagmmRq+4jUqLqqGnHU0DwJqJB1qyFucKgLPtCPEfp4Og0wW56muRIZv3LAAHuCHX6zF9MbGFd8U37EivMRDPTw+QrGCOYuH9nHAsAQU53bqwcHfuDcfDLtVU60cqwBvqpYaYv 47WymZnh NXPoQuLPovRi5k9njqTxgJLzgWwoNeRoPbyu1Cy7IKAQvTmnikwmb5jVDW1zWhqVrZd0m/km1MmiccMK0LV0jtmRzIZ9Kxen0L5w6gWlKLEe1ySGHgisZe9EIisYazam6HoT4EMCrw7YeJXNkmRNkJe9KMZhiiqH98L8Ke4d26hFj0S7FIn4hOblSWG+/p3MYk3i/qHWxTqrzRuPUQHrudeeoFYuh+FbQP4TKh/IvGKO0ZFq06NmHung5FEbgZI/rTXyLY4wyTVnNgmXeqODsrBmSVSKNw7Yw9V4C X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Ankit Agrawal The kernel MM currently handles ECC errors / poison only on memory page backed by struct page. As part of [1], the nvgrace-gpu-vfio-pci module maps the device memory to user VA (Qemu) using remap_pfn_range without being added to the kernel. These pages are not backed by struct page. Implement a new ECC handling for memory without struct pages. Kernel MM expose registration APIs to allow modules that are managing the device to register its memory region and a callback function. MM then tracks such regions using interval tree. The mechanism is largely similar to that of ECC on pfn with struct pages. If there is an ECC error on a pfn, MM uses the registered memory failure callback function to notify the module of the faulty PFN, so that the module may take any required action. The pfn is then unmapped in Stage-2. When the VM tries to access the page, it gets trapped in KVM, which calls the vm ops fault function. If the module fault function returns VM_FAULT_HWPOISON, KVM sends a BUS_MCEERR_AR to the usermode (Qemu) mapped to the poisoned page. Lastly, nvgrace-gpu-vfio-pci module make use of the new mechanism to get poison handling support on the device memory. Patch generated over v6.6-rc2 and with [1] applied. [1] is currently under review. [1] https://lore.kernel.org/all/20230915025415.6762-1-ankita@nvidia.com/ Ankit Agrawal (4): mm: handle poisoning of pfn without struct pages mm: Add poison error check in fixup_user_fault() for mapped pfn mm: Change ghes code to allow poison of non-struct pfn vfio/nvgpu: register device memory for poison handling drivers/acpi/apei/ghes.c | 12 +-- drivers/vfio/pci/nvgrace-gpu/main.c | 107 +++++++++++++++++++++- drivers/vfio/vfio.h | 11 --- drivers/vfio/vfio_main.c | 3 +- include/linux/memory-failure.h | 22 +++++ include/linux/mm.h | 1 + include/linux/vfio.h | 15 ++++ include/ras/ras_event.h | 1 + mm/Kconfig | 1 + mm/gup.c | 2 +- mm/memory-failure.c | 135 +++++++++++++++++++++++----- virt/kvm/kvm_main.c | 6 ++ 12 files changed, 270 insertions(+), 46 deletions(-) create mode 100644 include/linux/memory-failure.h