Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8863ybl; Tue, 7 Jan 2020 13:04:21 -0800 (PST) X-Google-Smtp-Source: APXvYqwrT1RxVkF5sdpAs3REt7TwsNaHi/8O9IZCpl19Qh0uKhSliq9CMLXV9LDjEn947cIsuz65 X-Received: by 2002:aca:c507:: with SMTP id v7mr291741oif.157.1578431061040; Tue, 07 Jan 2020 13:04:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578431061; cv=none; d=google.com; s=arc-20160816; b=rE4PCJibseda/5/WJ822mY1NSiN8pxhMAVAny6GCifiOzbh2GmNeg/lqO3odGoyTUd dWUsoA4MeLbvz4mVImo8mJT9vM2hj9FEzYyFrgH0NfSsKtDWOhgEcfPpg234aRYhqWDI O3SdeCD+FDuZxmBd8mXWcuEes+PASSMs5jIvPS8RsJeRgPsUvDZ+QnzkNWJn7NF8DQ/W 3DpmertuK/RRvPbAMn4fzk3IWJ+7Rp4yNmiK5/AJy5IrmwYa9HO9essooUeiSphlhgVp PkT+teizO2FblosNoHmXGqboZUf1E9N7APstAvuia7CwnnQOSgKKJyaz4GG6Q+ZuaKZi z7uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MCoYloJtKFoNdjdu8BH2bUmNz5bhQ8RfMaA0I7QqG9U=; b=B4uZNGlNc1elzcqlzOttX/BQsu29MNodJOid8Dk5l3eQyhs9ohEuTQRLAuGRZnY9EA MQ6H0xBG/GezqsUeg0tsG2gex2wdDZ98qjm5eBm+4scz+RBEXd4oRbMPrvohFbCiyhQx 4CjhXLjwhiv40XbTBcjLxOOGvWCnJZK75vKydITnr84CvFQkVA8sH0oDddIxtxSjUjJd G8r1g+42E4Ch55hrVhOYryej3CagJ7908iZYGQlU1k4My93V0zl3GxdZsP45BAIMh/AN 1dmzt18z1rJsSHlPkDtefS5G/8NpsLP63qbjpKytJKSgD1wXxRB8k0ffDFJDPTx8W+5k nvXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=As++hsus; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u21si578872oic.263.2020.01.07.13.04.08; Tue, 07 Jan 2020 13:04:21 -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=@kernel.org header.s=default header.b=As++hsus; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728632AbgAGVDU (ORCPT + 99 others); Tue, 7 Jan 2020 16:03:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:44928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727991AbgAGVDT (ORCPT ); Tue, 7 Jan 2020 16:03:19 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F108520678; Tue, 7 Jan 2020 21:03:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578430998; bh=FFnxewB0PxNjiHj9jmXU04m/t7uLXJ/DPQUka9Y/FR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=As++hsusyxHxXyYEke51G8YxWH0OFY6Ly/M9NGGi3YifGc6SZ9pNUh6D1T+Sbgc9O u2sFGDkEschVAePo5CYo4Ozt1tVMHVvGg37ccNZRkRb853+oMOVXMH4nOGtG6bHt0n NuPIZ6LepoQAVO/cdSj/yheSVvKGvmx1Yrh7W75M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Woodhouse , Maximilian Heyne , Paul Durrant , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , SeongJae Park , Jens Axboe , Sasha Levin Subject: [PATCH 5.4 183/191] xen/blkback: Avoid unmapping unmapped grant pages Date: Tue, 7 Jan 2020 21:55:03 +0100 Message-Id: <20200107205342.786178756@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200107205332.984228665@linuxfoundation.org> References: <20200107205332.984228665@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park [ Upstream commit f9bd84a8a845d82f9b5a081a7ae68c98a11d2e84 ] 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") Reviewed-by: David Woodhouse Reviewed-by: Maximilian Heyne Reviewed-by: Paul Durrant Reviewed-by: Roger Pau Monné Signed-off-by: SeongJae Park Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- 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 @@ next: 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.20.1