Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3109728pxm; Mon, 28 Feb 2022 12:12:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxIvrQNUv9RhNCY5Y+B8qKQ+SLU2GHib5KuqrtUJLUGCGDwW9+1meYgjaL52N6Seq1+AaE3 X-Received: by 2002:a17:902:8d87:b0:14f:7ad8:65c3 with SMTP id v7-20020a1709028d8700b0014f7ad865c3mr21815116plo.32.1646079142541; Mon, 28 Feb 2022 12:12:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646079142; cv=none; d=google.com; s=arc-20160816; b=GW9quBIgqtm5UoACS4UrTD24ZlyAOFGapnNqRFYn+hIX2mASNz1l4WmcBZvpwDzLrc iXOYYuHPpCInleEbDCB8/clg5qGnkDan/+aSnbC3cpGx9Giy59eMFoNR/6IK87PCEQYS lObfSNxxrXyZLqafC9rDSFg50B9r18QZxoJ5gAIiJQ4+3jy/IjV464ccrYNec9SdQOqx VtB08gYrXxEhCsbmbPq9RwD6OMMDnChnnpkNc8YvDnAVmyDjYtemqxXLbEJGDVndcvag qAcgrebeKRLNT2yXa+sfKjqT5bvqQFGQXbKur/Twb9Mrk9LqK+81igjvuNh63cTpw+yQ 4/DQ== 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=naoamjAtaAQKAV9+BChIUh5U6HL3I0og2dSH4YgO1O0=; b=xSV1GvtNu111zgsyhrJV8B2K5zN1C2Ke+kEjemIDrDCdcg3DOWpofaQHGLLCLQnYQ8 Y54822kHwGhurmhmHDXPT8OTAsWgMvLJSiWgeVxv0J8tSn0djSHZC83zES2aaF02bGYl T2Nw36dMA4MyczcEYRRljLMpjQKblaQthDGsKVvjnB9Gd11tUcBU/kEJm+gyYIP1Ueq7 kqi1FF+MEzBDlNGzu/06UcpURCt1d1jKNgqSjexlZNjJpY+mrsb5iIk2GrPb+NYqOvY/ N5U4HIn0j7+ZUeMinPVQqE4Wk5S3vwUFCNLTc/1hBDINEM2yG8Mo6H9RGSm/U5XTcyQg M/7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XSZKlrRn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s34-20020a63ff62000000b0036327224371si10076636pgk.10.2022.02.28.12.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:12:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XSZKlrRn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 95603158EA5; Mon, 28 Feb 2022 11:35:33 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239493AbiB1SAb (ORCPT + 99 others); Mon, 28 Feb 2022 13:00:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240785AbiB1Ryp (ORCPT ); Mon, 28 Feb 2022 12:54:45 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00F6B532C6; Mon, 28 Feb 2022 09:43:25 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 915C960180; Mon, 28 Feb 2022 17:43:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99CB6C340E7; Mon, 28 Feb 2022 17:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646070205; bh=8seL92Jujnzxe9kcZe3hncaHsIPde+ilak9Z5aBPr0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XSZKlrRnN4PODrfSLExwF00Pp8Ehw5wwRVkGyXGqkAR3yxP5jKxS9Nr4i2ikkwwjR 1RJ9ashgK79B9e9PIIvAXyytF4egfvomDQQ0+R1eRQrXPh2lz617QmTV3sARv2/9n/ xxGSqw7AI9mU2Xnymx/1IOUBvlnIz7bZLNrQbwcQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bob Chen , Jens Axboe Subject: [PATCH 5.16 008/164] io_uring: dont convert to jiffies for waiting on timeouts Date: Mon, 28 Feb 2022 18:22:50 +0100 Message-Id: <20220228172400.500203076@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220228172359.567256961@linuxfoundation.org> References: <20220228172359.567256961@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jens Axboe commit 228339662b398a59b3560cd571deb8b25b253c7e upstream. If an application calls io_uring_enter(2) with a timespec passed in, convert that timespec to ktime_t rather than jiffies. The latter does not provide the granularity the application may expect, and may in fact provided different granularity on different systems, depending on what the HZ value is configured at. Turn the timespec into an absolute ktime_t, and use that with schedule_hrtimeout() instead. Link: https://github.com/axboe/liburing/issues/531 Cc: stable@vger.kernel.org Reported-by: Bob Chen Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7633,7 +7633,7 @@ static int io_run_task_work_sig(void) /* when returns >0, the caller should retry */ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx, struct io_wait_queue *iowq, - signed long *timeout) + ktime_t timeout) { int ret; @@ -7645,8 +7645,9 @@ static inline int io_cqring_wait_schedul if (test_bit(0, &ctx->check_cq_overflow)) return 1; - *timeout = schedule_timeout(*timeout); - return !*timeout ? -ETIME : 1; + if (!schedule_hrtimeout(&timeout, HRTIMER_MODE_ABS)) + return -ETIME; + return 1; } /* @@ -7659,7 +7660,7 @@ static int io_cqring_wait(struct io_ring { struct io_wait_queue iowq; struct io_rings *rings = ctx->rings; - signed long timeout = MAX_SCHEDULE_TIMEOUT; + ktime_t timeout = KTIME_MAX; int ret; do { @@ -7675,7 +7676,7 @@ static int io_cqring_wait(struct io_ring if (get_timespec64(&ts, uts)) return -EFAULT; - timeout = timespec64_to_jiffies(&ts); + timeout = ktime_add_ns(timespec64_to_ktime(ts), ktime_get_ns()); } if (sig) { @@ -7707,7 +7708,7 @@ static int io_cqring_wait(struct io_ring } prepare_to_wait_exclusive(&ctx->cq_wait, &iowq.wq, TASK_INTERRUPTIBLE); - ret = io_cqring_wait_schedule(ctx, &iowq, &timeout); + ret = io_cqring_wait_schedule(ctx, &iowq, timeout); finish_wait(&ctx->cq_wait, &iowq.wq); cond_resched(); } while (ret > 0);