Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4398365ybc; Tue, 26 Nov 2019 08:20:17 -0800 (PST) X-Google-Smtp-Source: APXvYqzMo3meFWndHYcgK2E0w7D+E7kn6ObHR9lfnSfgzMxVcuwNzGMy5dc+9H8EQsu4NIxkfKbw X-Received: by 2002:a17:906:2444:: with SMTP id a4mr44247306ejb.134.1574785217543; Tue, 26 Nov 2019 08:20:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574785217; cv=none; d=google.com; s=arc-20160816; b=BZdGKD32CGhLhoUO3726UEOLoaxKvs8qEo6bi8gYlbDD+n1ct8694LzXS5uBZ3yRXt g4uqmySSvlfZzIfWqqtIrHSdh+tTGMbCqjUuIO7HQBwL8jYQI2WbvCIfq58sdgoHzGkA U0Kcy3jLQeUGafkBfbaj+lH3+tNkDnNPHQe0Ek8MbUkNrJmhrYY83d6xfYnVDOdTqKey A3JToViAJcffWn+LfdjTte7xUHCroS8s0kUWGoE/tx+fCFt9+eIy7ZDpLSBMq1vANQno gcDHTalNXAle784BCB6fEA4rBCGaEp0whWAAFtGZZYTBDtftjluCFm924A3l/b1E1Fbu /ydw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:ironport-sdr:dkim-signature; bh=W6LVx4gxON2oRR7lI5LBc6xbhhFYl7QITbdcuRcSicE=; b=AFte8gfWaq7EtwDY80e8oXuAQiakrpqzSdp1IchhX84msoLBzYK6gcVQ0Wt9eUiLo0 Qan7lEfd4zfCyNXBy8o92lHiJCJ9A3UMavxy8+AICzGkXKQijwuI/5IND/XurH99q2vw 6qTObnK0P1BhItB8gb9+m+cdOFFoyFcM30Dy2dpXToPi5Pi3acDLyIWrmPSW1NoCmPMi GEixpFSQemqCCGioL7E9ThrrS7hUzGqDrZHtQlwFewZbseFO05mo7SpxeBgUG9/VN3Uo ZxNjQk5WX6u262iVUlfC91HLCkrh6x89PV2hFbZebHEorISy/9Hcy5ucYa+TbhSKkLMw m6pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=niBqkuT4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a8si1130568edv.432.2019.11.26.08.19.52; Tue, 26 Nov 2019 08:20:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=niBqkuT4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728515AbfKZPgn (ORCPT + 99 others); Tue, 26 Nov 2019 10:36:43 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:59253 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727028AbfKZPgn (ORCPT ); Tue, 26 Nov 2019 10:36:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1574782603; x=1606318603; h=from:to:cc:subject:date:message-id:mime-version; bh=W6LVx4gxON2oRR7lI5LBc6xbhhFYl7QITbdcuRcSicE=; b=niBqkuT43EgB73IVQQNzJjyAT7TlaocwzwoFyN1NApU1UtlCFUsKxQH8 CY9rpOEKdDfFnUNH28rQRdIRaXqXMX2h262wHBcVf3k9x1mGu0WmITXxu fIW2YCsrrqEdj8V90l6e62zpNrox/dadcHV3lHUzm7i422q3V/a2skQV/ M=; IronPort-SDR: 5wWL59AZwO67yqNc5aqVtgEaOhBYBWfL588jw3WwrStdgwZROFHQEOELUJ+fRTE7kLc4lyCuRz a7XRWura312g== X-IronPort-AV: E=Sophos;i="5.69,246,1571702400"; d="scan'208";a="9989878" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 26 Nov 2019 15:36:33 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com (Postfix) with ESMTPS id AC79CA2499; Tue, 26 Nov 2019 15:36:31 +0000 (UTC) Received: from EX13D31EUA001.ant.amazon.com (10.43.165.15) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 26 Nov 2019 15:36:31 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.54) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 26 Nov 2019 15:36:27 +0000 From: SeongJae Park To: , CC: , , , , SeongJae Park Subject: [PATCH] xen/blkback: Avoid unmapping unmapped grant pages Date: Tue, 26 Nov 2019 16:36:05 +0100 Message-ID: <20191126153605.27564-1-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.54] X-ClientProxiedBy: EX13D01UWB003.ant.amazon.com (10.43.161.94) To EX13D31EUA001.ant.amazon.com (10.43.165.15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park For each I/O request, blkback first maps the foreign pages for the request to its local pages. If an allocation of a local page for the mapping fails, it should unmap every mapping already made for the request. However, blkback's handling mechanism for the allocation failure does not mark the remaining foreign pages as unmapped. Therefore, the unmap function merely tries to unmap every valid grant page for the request, including the pages not mapped due to the allocation failure. On a system that fails the allocation frequently, this problem leads to following kernel crash. [ 372.012538] BUG: unable to handle kernel NULL pointer dereference at 0000000000000001 [ 372.012546] IP: [] gnttab_unmap_refs.part.7+0x1c/0x40 [ 372.012557] PGD 16f3e9067 PUD 16426e067 PMD 0 [ 372.012562] Oops: 0002 [#1] SMP [ 372.012566] Modules linked in: act_police sch_ingress cls_u32 ... [ 372.012746] Call Trace: [ 372.012752] [] gnttab_unmap_refs+0x34/0x40 [ 372.012759] [] xen_blkbk_unmap+0x83/0x150 [xen_blkback] ... [ 372.012802] [] dispatch_rw_block_io+0x970/0x980 [xen_blkback] ... Decompressing Linux... Parsing ELF... done. Booting the kernel. [ 0.000000] Initializing cgroup subsys cpuset This commit fixes this problem by marking the grant pages of the given request that didn't mapped due to the allocation failure as invalid. Fixes: c6cc142dac52 ("xen-blkback: use balloon pages for all mappings") Signed-off-by: SeongJae Park Reviewed-by: David Woodhouse Reviewed-by: Maximilian Heyne Reviewed-by: Paul Durrant --- drivers/block/xen-blkback/blkback.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index fd1e19f1a49f..3666afa639d1 100644 --- a/drivers/block/xen-blkback/blkback.c +++ b/drivers/block/xen-blkback/blkback.c @@ -936,6 +936,8 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, out_of_memory: pr_alert("%s: out of memory\n", __func__); put_free_pages(ring, pages_to_gnt, segs_to_map); + for (i = last_map; i < num; i++) + pages[i]->handle = BLKBACK_INVALID_HANDLE; return -ENOMEM; } -- 2.17.1