Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1985240pxx; Sat, 31 Oct 2020 04:52:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygIsny1oxYJah0bA9w7eTHOGg/iu1J5GrQxG37Vd0NG1eO8ZHjMF8IVFHI69mYrTJImlPo X-Received: by 2002:a17:906:3689:: with SMTP id a9mr6757009ejc.403.1604145167856; Sat, 31 Oct 2020 04:52:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604145167; cv=none; d=google.com; s=arc-20160816; b=db9iWCZPAo8QRYhyV43d+SAb1GC/KM2FoYPGlsumSvA8fbSyuPuL+GkHrwRq4Zz6Ar 1VOBVbXFLDBIxMc/GYFCaBBEdum0JYSEcZnaiWJJDQDTCoHSoVHLI2mle3R+bZY1ix3y bi2Ybg0GQx+WVQa6EX66aBYSNxk48JBYMyco3RIjDdkxTmVZche0QCQcsOmqVCIqOW75 PTxoADmjwlMs3ito54EvFSLtRXnJGfZLnZh2c/Q2RUTmWmO5FRqYCUzW7I6/X1u/UA25 //cpWWkqpx3AyNlxcFHq3E2Fpu2vbIrrPJEzk0NhulXUnrMzQZbRzB09Y6RvfSMDSAWT CiSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Iasjwj5/SxCrX4AtcNLx1YIaT3s3m0k4N8PvHBAgJrU=; b=pT0Llok7ReId+PnLZMNtyQ6Bw7xVkmSo8Uv/z81uxZy3zCDcGrW1mtL2wGtPJ+ce8K A0WP44EhjCJ1mNnUw2i8Z+U9IzRUAuq0iTMjZoB5lur8mYJC0Nj/58XF7GkxoFk8vCTZ 6GWSf75XXOBlUkm2SidI1AaB2gJNqCON9pMmDoGWwdRgp2aSHitEY0cBPxs80UcOcg9a dQPTtQ4XjiLvjVMPU+17iUMnZn2Ady4G7Kv9WXDgV7R1kBo43wcXV+WoYtbmO430mfjn ApjyCegqbfZtE2Bo6HdANGPQOZ6jLST26vAqOOf9fP5ovHN6fftJHHfId49+AWKeTxWi kZ2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O7DuFU9e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d8si6896690edz.107.2020.10.31.04.52.25; Sat, 31 Oct 2020 04:52:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O7DuFU9e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727179AbgJaLka (ORCPT + 99 others); Sat, 31 Oct 2020 07:40:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:39070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727353AbgJaLk1 (ORCPT ); Sat, 31 Oct 2020 07:40:27 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 DA37620731; Sat, 31 Oct 2020 11:40:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604144426; bh=Csmu/aoph/I1G8huV9ayhGWzcyNnZ3WOSLX47x3dAH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O7DuFU9eoOduceZ5+P7GT9I0SdLGR3sMbkFBPz+OR5snPULTfqZueF1aliVkKvw9Q eCFVK+M5YxoczsyNz8eNs/4WSXTXrCknqg6l4GOuxp9hxFbp8QNzCf9fpjDGcy8jyw Tu2XTfmtv1VH9gZ9iqPgrc51wnRbzXn1Y2bhej2Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+27c12725d8ff0bfe1a13@syzkaller.appspotmail.com, "Matthew Wilcox (Oracle)" , Jens Axboe Subject: [PATCH 5.8 14/70] io_uring: Fix use of XArray in __io_uring_files_cancel Date: Sat, 31 Oct 2020 12:35:46 +0100 Message-Id: <20201031113500.188798721@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201031113459.481803250@linuxfoundation.org> References: <20201031113459.481803250@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Matthew Wilcox (Oracle)" commit ce765372bc443573d1d339a2bf4995de385dea3a upstream. We have to drop the lock during each iteration, so there's no advantage to using the advanced API. Convert this to a standard xa_for_each() loop. Reported-by: syzbot+27c12725d8ff0bfe1a13@syzkaller.appspotmail.com Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -8008,28 +8008,19 @@ static void io_uring_attempt_task_drop(s void __io_uring_files_cancel(struct files_struct *files) { struct io_uring_task *tctx = current->io_uring; - XA_STATE(xas, &tctx->xa, 0); + struct file *file; + unsigned long index; /* make sure overflow events are dropped */ tctx->in_idle = true; - do { - struct io_ring_ctx *ctx; - struct file *file; - - xas_lock(&xas); - file = xas_next_entry(&xas, ULONG_MAX); - xas_unlock(&xas); - - if (!file) - break; - - ctx = file->private_data; + xa_for_each(&tctx->xa, index, file) { + struct io_ring_ctx *ctx = file->private_data; io_uring_cancel_task_requests(ctx, files); if (files) io_uring_del_task_file(file); - } while (1); + } } static inline bool io_uring_task_idle(struct io_uring_task *tctx)