Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3327716imu; Sun, 11 Nov 2018 12:28:07 -0800 (PST) X-Google-Smtp-Source: AJdET5d97czvcH3vI41ckQWpvQbrY5kOZ3vAEfQHaaQtZ3t9TZcKfsEh5LmgV9yW37HNrVQvvvhE X-Received: by 2002:a17:902:6a8b:: with SMTP id n11-v6mr17607789plk.311.1541968087815; Sun, 11 Nov 2018 12:28:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541968087; cv=none; d=google.com; s=arc-20160816; b=vQB6G6H/Rb8lxWecf7lsdkoMz3F9Wg5ap2VewJOlOrlFQz4B+6GwelNs0GTFOoFp2m K4mbNryQBBZ+aI1iMNJyX68UdesqurOMUiCpwv+Q3holYjxjYi+VJypWFRxC+x02W0dL 1p7wjR49vBOrLsF9h6R/3Zi9svI+zpA9SAevWKMhJjTq43BnqnwtnpOq/9OhU5IT0XeN /G7swKxnQ1cuUSTgaPtMD49SNTTDWh9fGaxOTDIoErjzx9i3swXRHfSPoai9ZhjdkEOv +Enuyk6FmLDKdTBWxf+8VYlr0gD3yWXHx9vD/1jf9fC3tI2/rvrTF3/w7mDS8zXBEdHT YC2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=bzWB6JgEg72zntJsmY2xJHWAvnknmW7XseWPY+QLQIQ=; b=bAPqNR0ZAfxDq0uyZFhZ0FP03nJpryiAzs0g/pfF3aGwbgHKE4gSX5P/XPD340WuLd XK1VSDf2MgSs2V4RWZE5IMxtnPi1WN5ac+wxvD5OBBaCrm+tir9lYdSRKyZxFrMlzd7C k70Pfma9DvIJ3yTuCuipZueFj4I/dHIVXKUfRfOpQy0f66UMI2JKsxoUR2SeKpiQpoJB 9Gcll0PCJm7jCSudNl7qDxgkM7SLWATt7eUeRcErCOqkBGEozqkllPg+L+TkECnXfjf0 FgfFwO1fWfENIEDBkM2ymzBVPGNufp07bXVBYIq6LVx0P1H66vHpmPdyujfJrmjuYP54 UF3A== ARC-Authentication-Results: i=1; mx.google.com; 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 i127-v6si16920191pfc.148.2018.11.11.12.27.53; Sun, 11 Nov 2018 12:28:07 -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; 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 S1731639AbeKLGQ5 (ORCPT + 99 others); Mon, 12 Nov 2018 01:16:57 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:50798 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730595AbeKLFs0 (ORCPT ); Mon, 12 Nov 2018 00:48:26 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsk-0000oN-Ie; Sun, 11 Nov 2018 19:58:54 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsY-0001nj-PD; Sun, 11 Nov 2018 19:58:42 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Jiang Biao" , "Huang Chong" , "Michael S. Tsirkin" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 303/366] virtio_balloon: fix another race between migration and ballooning In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Jiang Biao commit 89da619bc18d79bca5304724c11d4ba3b67ce2c6 upstream. Kernel panic when with high memory pressure, calltrace looks like, PID: 21439 TASK: ffff881be3afedd0 CPU: 16 COMMAND: "java" #0 [ffff881ec7ed7630] machine_kexec at ffffffff81059beb #1 [ffff881ec7ed7690] __crash_kexec at ffffffff81105942 #2 [ffff881ec7ed7760] crash_kexec at ffffffff81105a30 #3 [ffff881ec7ed7778] oops_end at ffffffff816902c8 #4 [ffff881ec7ed77a0] no_context at ffffffff8167ff46 #5 [ffff881ec7ed77f0] __bad_area_nosemaphore at ffffffff8167ffdc #6 [ffff881ec7ed7838] __node_set at ffffffff81680300 #7 [ffff881ec7ed7860] __do_page_fault at ffffffff8169320f #8 [ffff881ec7ed78c0] do_page_fault at ffffffff816932b5 #9 [ffff881ec7ed78f0] page_fault at ffffffff8168f4c8 [exception RIP: _raw_spin_lock_irqsave+47] RIP: ffffffff8168edef RSP: ffff881ec7ed79a8 RFLAGS: 00010046 RAX: 0000000000000246 RBX: ffffea0019740d00 RCX: ffff881ec7ed7fd8 RDX: 0000000000020000 RSI: 0000000000000016 RDI: 0000000000000008 RBP: ffff881ec7ed79a8 R8: 0000000000000246 R9: 000000000001a098 R10: ffff88107ffda000 R11: 0000000000000000 R12: 0000000000000000 R13: 0000000000000008 R14: ffff881ec7ed7a80 R15: ffff881be3afedd0 ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018 It happens in the pagefault and results in double pagefault during compacting pages when memory allocation fails. Analysed the vmcore, the page leads to second pagefault is corrupted with _mapcount=-256, but private=0. It's caused by the race between migration and ballooning, and lock missing in virtballoon_migratepage() of virtio_balloon driver. This patch fix the bug. Fixes: e22504296d4f64f ("virtio_balloon: introduce migration primitives to balloon pages") Signed-off-by: Jiang Biao Signed-off-by: Huang Chong Signed-off-by: Michael S. Tsirkin Signed-off-by: Ben Hutchings --- drivers/virtio/virtio_balloon.c | 2 ++ 1 file changed, 2 insertions(+) --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -413,7 +413,9 @@ static int virtballoon_migratepage(struc tell_host(vb, vb->inflate_vq); /* balloon's page migration 2nd step -- deflate "page" */ + spin_lock_irqsave(&vb_dev_info->pages_lock, flags); balloon_page_delete(page); + spin_unlock_irqrestore(&vb_dev_info->pages_lock, flags); vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE; set_page_pfns(vb->pfns, page); tell_host(vb, vb->deflate_vq);