Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2335984ybi; Thu, 4 Jul 2019 09:05:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzaHDwb4LHme77X0sJitWJVB22APf62RvLJ/4f9NxVApjNurVyUXuQ8h8MSLSebiQsCvqS5 X-Received: by 2002:a63:3481:: with SMTP id b123mr44447283pga.358.1562256339270; Thu, 04 Jul 2019 09:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562256339; cv=none; d=google.com; s=arc-20160816; b=Y7lSCBk+Hb+ACTaguQ3m+yEBbVK2d61NFJu9PGRdEFoLUoxhduLqYkXh2mkGT4TMpG 0aZLNodGm1dK6ptrr0h4lrxQjikX+n3JDcPVjzgHcEnxvcPPgJHjicuivLoXHav+kAzs BybvvuBgesl/Pbamm+mt2nHU5zLKZqx1xwQVbcTSpIQPFttqqwV+MkVYrwdDGyOxsOzV sPH62Pff9msb0h0ovtNUvrvhU1yuemZCWPGUEj37UkxwirtexMQ6ng3yHmSqIpGj8K4t c6zzNVty1ZityIOSa9XH9lyEVXkwOPfMTQ5cFKhOUKb/stwUdjyRSNrvuxr0P0sb/vlk RdvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=fhQ0Se92Bm2BbYqIGhm1cI+ZAFO1eywerRnSPIIlkBw=; b=qWbSljDANhK4j7TRGGI06UZ2r41s11wqquXSmC5unjYN/IIIorRzxE6bX4FtEnHll7 L+ej5Vq/xCXcLz6dVJh8PPlW3CszKxJCocwqRNzZyNP54JeqJ5qSywfYXyh8oF5L9KWv oUmXjpYSbYGMEK7cr/tQVuj0Z1gEctfmEysoATESpglqszezpieQAmnuLeJw1w5dzpvC jQ0khJyXNGO8E7KgJYYgHyX6kwEVvHhSPZhcdTpFaqbZJCShHQrcY712ohCq2kT8lbhB VyZ/KcqCyURXL0UJRtGyUETzX8rIukiopPmDkdFYMMkarzphnlSArRLdOjfCAvisCVFk HqNQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z25si5374231pgv.418.2019.07.04.09.05.24; Thu, 04 Jul 2019 09:05:39 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727008AbfGDQDR (ORCPT + 99 others); Thu, 4 Jul 2019 12:03:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37608 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbfGDQDR (ORCPT ); Thu, 4 Jul 2019 12:03:17 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F49481F0D; Thu, 4 Jul 2019 16:03:05 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.136]) by smtp.corp.redhat.com (Postfix) with SMTP id A2240BA7D; Thu, 4 Jul 2019 16:03:02 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 4 Jul 2019 18:03:05 +0200 (CEST) Date: Thu, 4 Jul 2019 18:03:01 +0200 From: Oleg Nesterov To: Andrew Morton Cc: Qian Cai , axboe@kernel.dk, hch@lst.de, peterz@infradead.org, gkohli@codeaurora.org, mingo@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hugh Dickins Subject: [PATCH] swap_readpage: avoid blk_wake_io_task() if !synchronous Message-ID: <20190704160301.GA5956@redhat.com> References: <1559161526-618-1-git-send-email-cai@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1559161526-618-1-git-send-email-cai@lca.pw> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 04 Jul 2019 16:03:17 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org swap_readpage() sets waiter = bio->bi_private even if synchronous = F, this means that the caller can get the spurious wakeup after return. This can be fatal if blk_wake_io_task() does set_current_state(TASK_RUNNING) after the caller does set_special_state(), in the worst case the kernel can crash in do_task_dead(). Reported-by: Qian Cai Acked-by: Hugh Dickins Reviewed-by: Jens Axboe Signed-off-by: Oleg Nesterov --- mm/page_io.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index 2e8019d..3098895 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -140,8 +140,10 @@ static void end_swap_bio_read(struct bio *bio) unlock_page(page); WRITE_ONCE(bio->bi_private, NULL); bio_put(bio); - blk_wake_io_task(waiter); - put_task_struct(waiter); + if (waiter) { + blk_wake_io_task(waiter); + put_task_struct(waiter); + } } int generic_swapfile_activate(struct swap_info_struct *sis, @@ -398,11 +400,12 @@ int swap_readpage(struct page *page, bool synchronous) * Keep this task valid during swap readpage because the oom killer may * attempt to access it in the page fault retry time check. */ - get_task_struct(current); - bio->bi_private = current; bio_set_op_attrs(bio, REQ_OP_READ, 0); - if (synchronous) + if (synchronous) { bio->bi_opf |= REQ_HIPRI; + get_task_struct(current); + bio->bi_private = current; + } count_vm_event(PSWPIN); bio_get(bio); qc = submit_bio(bio); -- 2.5.0