From patchwork Tue Jul 11 20:43:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 118713 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp737767vqm; Tue, 11 Jul 2023 13:58:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlGoA3WXZywaRnki16XBzcDYjzySvZdZPP/kkw/GmsLygqy5378Wom8aCqB6gPnzfxR7FlTx X-Received: by 2002:a17:903:191:b0:1b8:95a1:847c with SMTP id z17-20020a170903019100b001b895a1847cmr16903168plg.40.1689109123703; Tue, 11 Jul 2023 13:58:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689109123; cv=none; d=google.com; s=arc-20160816; b=bxEJ80mJIIHE7TpivjxiwrUdGmwmNBtxPTov5cnEntxzq3slJl7Ft4IZXpJl9iXghk s5X3OZ4jwXbhrwvgWPfZu1/H0vHIaY5TKmgBlkUBVEpvPZZb9bCUUAlBrPKj5NYWtiwK zDQRbUP7ejSiJj0+wQg9LmuwWAoYhZbPmCYsOyFjtE2pWDMtY3f501oCZQzgPnEz+4RN t49Akbz/1B5ljRDhY2F7kWMqtbIxJF86XKb03io24ZraMAukmDV1o0jWeGU/NM5o6owS yRJVq3M+L2XrTckR5V48rDGp3TMt9wY6n+xliFyo/fqdakthmuT0B9JNuTXg5pZRxyEt 3HRw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RhnrJF2dPLoBWUU12VjDOt5vBH0HKwmnbELH9GE6Oiw=; fh=p+wOSmeLusTVqUKR8aQc56XBO9QP4vSQ6AXDIQF3284=; b=N51zFgnu7ELPVgskZQ3gsEGJRn5zD4j8o30oLocNJWxDihyGiOiPMs1j4wGv/3htR5 uPt8QyN/b5kPpNgeb3YBsEQDmXeRW3ury9t0GPQnsyR8eal9f0nMLCqN13dUYnI+TOfE 1twDMzHWMDtG4jzCc/s+q+i7Iro4Kshi/1lSBTqknrJUW9FQZ09t9YmPeOTCrZKkjuo9 G5UO/BwXMJJYkoken38pzlu1uxfCsH7kI9RapJBDXHnjsPN5jSQrCM8XbLXr09wgc56b l7VnR2Iyrx5vk4u+z9khQMsTC6b2Fj/2iqrAUijY586NRDUFRkapHxczCFYp5gV1o+n5 aLvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=3aCbceAw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id km8-20020a17090327c800b001b694ecf48fsi1987311plb.71.2023.07.11.13.58.29; Tue, 11 Jul 2023 13:58:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=3aCbceAw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229911AbjGKUoC (ORCPT + 99 others); Tue, 11 Jul 2023 16:44:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbjGKUoB (ORCPT ); Tue, 11 Jul 2023 16:44:01 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87DB7195 for ; Tue, 11 Jul 2023 13:44:00 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-682eef7d752so842153b3a.0 for ; Tue, 11 Jul 2023 13:44:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1689108240; x=1689713040; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RhnrJF2dPLoBWUU12VjDOt5vBH0HKwmnbELH9GE6Oiw=; b=3aCbceAwkgWqnj5/9VsREWCy67MDdUmA90tFIDvfByUxgd6lufiCgfQow5eLzCwAOr OLtIvB7uwtRtb1XARNCwQorqqwefVLZdlTcfKN4W86BdzonS5yVEStw9AymGna+7pgvL TW5QaH09WQy3ojKNx1oXs/4Tj++BorYbtHoiKFrbgHToLx4dBRJmLxmu5IfK8DhLkKws pGjaec3mdL5+FLZmFB+eXR80DAWnROaRF3etC8mAR080NZ+HMp0JC6RU9y0Du2/33ouz 3/DF3L9z0Xd6uO6G3gnuOKchAW5UcCnwcSByavl1FZ6JGnOqI2jahJ8OTMPQSutH2mXP IZDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689108240; x=1689713040; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RhnrJF2dPLoBWUU12VjDOt5vBH0HKwmnbELH9GE6Oiw=; b=NjkxesJFyCy08RCo6Y8Uv1R5cFAGDg9sG6PMq0CaTNiBJhPk6kpZJMpUIWqwtUyPM4 M5ULTIHg1WIZfpPSSjQB/LLszUfeo71HJWv5RUekmNTQsa5Gg5sGEKknmku8B5VuQMnO J4MdA/E1silDA2+hqnnWBf93KOplMJRr1mf8MKOJ0u0SLUgC3bwMf7fmGU052uof7r+G NEq+6g/c+kX/XZ0JiB2BNO+DRNxontiiAxou+6Uk4HTnffZTqdq7hoZFnnYKzYa4enWq ++4Qf/wlDGzlRyhVOljurUQCoz+wgxwJiDBhKnbBLofXb0aqS8ngebtBF+5c9Tj6VrSp V7lA== X-Gm-Message-State: ABy/qLaNLhjnb/FQYsfKH+0Wvu9P6Jh0yOBozu4jRnUbaFKjdnUn0KKP Pw73wSN0EHrA8/LGd4FxRDooyA== X-Received: by 2002:a05:6a00:39a1:b0:67f:8ef5:2643 with SMTP id fi33-20020a056a0039a100b0067f8ef52643mr18904466pfb.2.1689108240070; Tue, 11 Jul 2023 13:44:00 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id f7-20020aa78b07000000b00640ddad2e0dsm2124461pfd.47.2023.07.11.13.43.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 13:43:59 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Cc: brauner@kernel.org, arnd@arndb.de, Jens Axboe Subject: [PATCH 1/5] exit: abtract out should_wake helper for child_wait_callback() Date: Tue, 11 Jul 2023 14:43:48 -0600 Message-Id: <20230711204352.214086-2-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230711204352.214086-1-axboe@kernel.dk> References: <20230711204352.214086-1-axboe@kernel.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771159288810574020 X-GMAIL-MSGID: 1771159288810574020 Abstract out the helper that decides if we should wake up following a wake_up() callback on our internal waitqueue. No functional changes intended in this patch. Signed-off-by: Jens Axboe Acked-by: Christian Brauner --- kernel/exit.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index edb50b4c9972..2809dad69492 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -1520,6 +1520,17 @@ static int ptrace_do_wait(struct wait_opts *wo, struct task_struct *tsk) return 0; } +static bool pid_child_should_wake(struct wait_opts *wo, struct task_struct *p) +{ + if (!eligible_pid(wo, p)) + return false; + + if ((wo->wo_flags & __WNOTHREAD) && wo->child_wait.private != p->parent) + return false; + + return true; +} + static int child_wait_callback(wait_queue_entry_t *wait, unsigned mode, int sync, void *key) { @@ -1527,13 +1538,10 @@ static int child_wait_callback(wait_queue_entry_t *wait, unsigned mode, child_wait); struct task_struct *p = key; - if (!eligible_pid(wo, p)) - return 0; + if (pid_child_should_wake(wo, p)) + return default_wake_function(wait, mode, sync, key); - if ((wo->wo_flags & __WNOTHREAD) && wait->private != p->parent) - return 0; - - return default_wake_function(wait, mode, sync, key); + return 0; } void __wake_up_parent(struct task_struct *p, struct task_struct *parent) From patchwork Tue Jul 11 20:43:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 118712 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp736660vqm; Tue, 11 Jul 2023 13:55:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlGIcAASd0Xi/loNf9WQdJL4tPCrjFViLJuTnCkxfjEetKdBP+1oWJEE1cKTCvsBumck4w7h X-Received: by 2002:a50:fe93:0:b0:51b:c714:a2a1 with SMTP id d19-20020a50fe93000000b0051bc714a2a1mr12727002edt.7.1689108911971; Tue, 11 Jul 2023 13:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689108911; cv=none; d=google.com; s=arc-20160816; b=vV7jfER5WmKnXiXDXpb8KXTNquft819GqcZFLFg1LeFCVav20nKZuDiQk3/7C/MqID HRwkkXKRtj6StFF5bN8FQTecQcwQZ7B/kKWjM4LAcSIMPFWIMKkvHwjHC0PK6E7+WlQw v6uIq2B2omDKMPAaA5vN9a8jzjfcoTrjiclxVmnqnRVRqeH0ugZ8Y9kKo1TNxBjaO3N+ LgQmImp3hjOFLEBN+qAczWtzXGwlk6jSg+3mMfN98HoDS9AVYwwPQLBrQS85rNK+MGJI qcAeT2T9CJ6Q1e5vv9QL34yuOoErMLweRWerlKCln2DWCul9IJeIsofCCvmmDw84sVAO 3gxw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KZsZ8f6snXSrxb5rxjwdGIt7zdNvfSU6bnPqicjdHws=; fh=p+wOSmeLusTVqUKR8aQc56XBO9QP4vSQ6AXDIQF3284=; b=n1uSnxGDvj1JBp3TrXf2xsYW/tR6k6jKoi4h5+QvRVSQwiMOKLWm4OrWjEVxRhyiWx AnPa4GmQv30F65HeVzfL4pnZ1jMV+CMYnkRef4UsRz4uOn6X/bOcUhEyCdfAhid8dH/Q 7FrVDJrAdfL0MMPN3AvrDa8NIO1hHIAnDDS+nVSzew+tvWAieb0OOOq/E5zGvA9fv+xy JNEcfIkNn6DRYudapexFt/bcd2QCKSunoYZZY+0yww6TSko9XVUtE0EwW7jokHCapfEO lHcwrjse0xNaS+NszzemhkSLf6iP8Rp2D0SwbSsGZjQEsoKW1EsyGYHoL6ZbIOcgUS6T /7CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=3N0SJijD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t20-20020a05640203d400b0051de4ebaa2fsi2833786edw.35.2023.07.11.13.54.48; Tue, 11 Jul 2023 13:55:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=3N0SJijD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229573AbjGKUoI (ORCPT + 99 others); Tue, 11 Jul 2023 16:44:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229964AbjGKUoD (ORCPT ); Tue, 11 Jul 2023 16:44:03 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24847195 for ; Tue, 11 Jul 2023 13:44:02 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-682ae5d4184so1334063b3a.1 for ; Tue, 11 Jul 2023 13:44:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1689108241; x=1691700241; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KZsZ8f6snXSrxb5rxjwdGIt7zdNvfSU6bnPqicjdHws=; b=3N0SJijDU79cAiD9z1CvyfDS/0x4aovQkXowXuC+Qe1dNPjhu6fJB7n6LWQMnowsAe gKjPDzKnsWBD/lwJgTSNQfJjXo2iY3sW1mTttU10WMNXtDzZA5helUetsfpokXL0VIeR qTBoIj6i6NslICeWocfhD5cpKS6rzMp1yweglA3MTbo83yNW33FIAEGIjHXn/SoQ10R4 0c/62G9XNASoHReTCnZT5a8jQggpIPw0IrSNebcBBMmqmZz7Kd4c97bpfncwLb3pvQHf XqIU1WdKzQ6bf48mwEaIVRV4aVQharmr6OAiPZ2Cbz6Rzaluuo4ZPzmSvUnzWVUfmKsQ GYhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689108241; x=1691700241; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KZsZ8f6snXSrxb5rxjwdGIt7zdNvfSU6bnPqicjdHws=; b=kJfk7nyzezqncYn3LZtvd2FeIzNB95KSpJmNWRVuucGhWFfQJpvq8WlKOEsVW14x3a IrEfLwUVgzOlk91ucnYDRNNYxafWz400yhuaLBnZ4W6NcOfMFYGxW6WrOiadN2Qs/BjY 1wVNFEmbmlExu+apJnNpMh/0IYQo1lfrCLX0Sb5YCYJl9Hx/AuSTIFGGpZ0h42ZOd31c dT110eOpC3jbF1kxEuxGMgLwPHMnk8gfomfHxsWGBvgIoetargLX83osBLAQkES+AnHL eDrHNFims2ioAsQlJUd5sMdgoHt9EobaEBkoK1Zvr2uBpBnLXDXAL/F4WRAhdsMWIKET kU7Q== X-Gm-Message-State: ABy/qLa5iJM/4Pax5OnPTEjzfWsjFahYgLoY55aRXSTgbxZF2EkjQT9H 1JaaZBPg9eNZNY3re27191/H0g== X-Received: by 2002:a05:6a20:3d0d:b0:123:149b:a34f with SMTP id y13-20020a056a203d0d00b00123149ba34fmr22664283pzi.1.1689108241461; Tue, 11 Jul 2023 13:44:01 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id f7-20020aa78b07000000b00640ddad2e0dsm2124461pfd.47.2023.07.11.13.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 13:44:00 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Cc: brauner@kernel.org, arnd@arndb.de, Jens Axboe Subject: [PATCH 2/5] exit: move core of do_wait() into helper Date: Tue, 11 Jul 2023 14:43:49 -0600 Message-Id: <20230711204352.214086-3-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230711204352.214086-1-axboe@kernel.dk> References: <20230711204352.214086-1-axboe@kernel.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771159066413879068 X-GMAIL-MSGID: 1771159066413879068 Rather than have a maze of gotos, put the actual logic in __do_wait() and have do_wait() loop deal with waitqueue setup/teardown and whether to call __do_wait() again. No functional changes intended in this patch. Signed-off-by: Jens Axboe Acked-by: Christian Brauner --- kernel/exit.c | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index 2809dad69492..d8fb124cc038 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -1590,16 +1590,10 @@ static int do_wait_pid(struct wait_opts *wo) return 0; } -static long do_wait(struct wait_opts *wo) +static long __do_wait(struct wait_opts *wo) { - int retval; - - trace_sched_process_wait(wo->wo_pid); + long retval; - init_waitqueue_func_entry(&wo->child_wait, child_wait_callback); - wo->child_wait.private = current; - add_wait_queue(¤t->signal->wait_chldexit, &wo->child_wait); -repeat: /* * If there is nothing that can match our criteria, just get out. * We will clear ->notask_error to zero if we see any child that @@ -1617,18 +1611,18 @@ static long do_wait(struct wait_opts *wo) if (wo->wo_type == PIDTYPE_PID) { retval = do_wait_pid(wo); if (retval) - goto end; + return retval; } else { struct task_struct *tsk = current; do { retval = do_wait_thread(wo, tsk); if (retval) - goto end; + return retval; retval = ptrace_do_wait(wo, tsk); if (retval) - goto end; + return retval; if (wo->wo_flags & __WNOTHREAD) break; @@ -1638,14 +1632,31 @@ static long do_wait(struct wait_opts *wo) notask: retval = wo->notask_error; - if (!retval && !(wo->wo_flags & WNOHANG)) { - retval = -ERESTARTSYS; - if (!signal_pending(current)) { - schedule(); - goto repeat; - } - } -end: + if (!retval && !(wo->wo_flags & WNOHANG)) + return -ERESTARTSYS; + + return retval; +} + +static long do_wait(struct wait_opts *wo) +{ + int retval; + + trace_sched_process_wait(wo->wo_pid); + + init_waitqueue_func_entry(&wo->child_wait, child_wait_callback); + wo->child_wait.private = current; + add_wait_queue(¤t->signal->wait_chldexit, &wo->child_wait); + + do { + retval = __do_wait(wo); + if (retval != -ERESTARTSYS) + break; + if (signal_pending(current)) + break; + schedule(); + } while (1); + __set_current_state(TASK_RUNNING); remove_wait_queue(¤t->signal->wait_chldexit, &wo->child_wait); return retval; From patchwork Tue Jul 11 20:43:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 118709 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp732994vqm; Tue, 11 Jul 2023 13:45:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlEsbA22WpXK8Qv+gKRWR7vEYwInP+tON0jw9a8NdWe2Vvv4JuBAzF6pnz1NyKPvkRVG3mEc X-Received: by 2002:a05:6a20:9187:b0:12c:28f4:1ca0 with SMTP id v7-20020a056a20918700b0012c28f41ca0mr16591164pzd.38.1689108314646; Tue, 11 Jul 2023 13:45:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689108314; cv=none; d=google.com; s=arc-20160816; b=VQbsuVr7io2W9wIXGmxJUmm/p9DetjSc530AA3o1DKM/Qrprb6qTwqZspqjwUBg216 cVaWiwHUBok05eNRwjR7Nb0laKhuG/u7sMi7wbn2PxqNL5SNXXuFR0KZrpdE3CSQO+RD dZgGtIG/COhz/+TbI/WLXk9Pui4kbJINrrtfRsTK7ZH3disoZJaF/e0l8E7jEy7r5vSY /6Gbt/RDYX0rvoE5Hrt+YJ94nmg0Un0izarWHgI8C7sftMpe5HvePXXesH9j2Aw44+bW LmxH3jIH1fli2/SYX4r4u3VIQ7NGB9P0miViGIXd1LkPOL9y2UyUIqj0mgjImUhW3S1w Juvw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WYDIyeoAajuf9ZWE7uQTqbgmYwdh8IUMjMetvGRNy4k=; fh=p+wOSmeLusTVqUKR8aQc56XBO9QP4vSQ6AXDIQF3284=; b=l/DqWbRH3dYnG15UUa+HaayoX3TJJLbGy3EqTMN+s6o0qT+PCudzqzoTbKEVd06Wmg Yj2x0UGSUhNvhtGkikiV4Lu86oZORNbkrX3P9mm+CsGt6rh8eAwr2yuFkmj0U9eZX1JN vMfxDC3JG3IJ/BsCWQvepHGsD0aI22Hf2OMQT/PIJeYtSTu2tUGYRcBNoDriszWVxJdr NeQnGZwIuyOlOXCMEwmRH8gJPBfp1QPzLqFE91pKsCSzWuJnzxbC7FegezhfhDGCftGm BQiYDJKRDAWVdEaaI1Be+HGBdcdSF/7zltP8WAGmOH28lT2Z9zWzlkgAc/pPLcAAxTqQ P9sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=Kw7OJtlI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s18-20020aa78d52000000b00665c24182bcsi1880964pfe.219.2023.07.11.13.45.00; Tue, 11 Jul 2023 13:45:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=Kw7OJtlI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230393AbjGKUoL (ORCPT + 99 others); Tue, 11 Jul 2023 16:44:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbjGKUoE (ORCPT ); Tue, 11 Jul 2023 16:44:04 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 173F810E3 for ; Tue, 11 Jul 2023 13:44:03 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-682ae5d4184so1334067b3a.1 for ; Tue, 11 Jul 2023 13:44:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1689108242; x=1691700242; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WYDIyeoAajuf9ZWE7uQTqbgmYwdh8IUMjMetvGRNy4k=; b=Kw7OJtlIsWYqkTdCePYJ6j0sZ/wo/9SVbH1Crr+PV4T3hXRLT6ogGGfyIuciZw49Gj cI5oawLufTg1VdoXxqFJTj96IZ9LHiViG8qs9gqHj9oPq4Y+91EB96UEMZsm7r77wu8P Yn5JRCM0rusYPLf30cag4PsOv2r3sDrVrBlFj8C8ONp/aX3iV8zqm3noaS84jfGYo3ha sfPT2yzhH/vVULPlCdqjag8UkzdvJZMrmv6e93tXoG7wSen83LRi+nKcGRZYT5lteNac JU7032+kC7Es/v+DINgPt+3jH99AVZJHNmV2oujw+iOFWZ8fWulhdp34w6aNdBogxLb2 x++g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689108242; x=1691700242; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WYDIyeoAajuf9ZWE7uQTqbgmYwdh8IUMjMetvGRNy4k=; b=KEj+NlNZSKDbESphy3bXJ8sum1Xq1l8vQz8iZ5yxHjICxUC2sFn/WZY4UNKPa0nrOe 1E3ZiPVlihJ38zPUiEo9udcRlXttyw7aXcisDFHHnpjyzxLgjP7bZM4cML7RwMnqitT4 ssahtHjScQEkcVw4TlTfvM7Ozc9MD1p+Nt0frrauIXZ29c7W/YYqL4Re1IhpaVP1Xlrs 8DvqVUHLhwBlt2EIsQALkjoFsFUNhA01qYELLk9Gqov+M31g9lIyRQmRq9CcRFJ477JP /nNjyWtAizVHo3zeQiBEflwXYa+YitcrVZIBlXBoTa+SfHtvWiql2u/RggXf/I9dcD0j KEnQ== X-Gm-Message-State: ABy/qLbi32jY6jV9rx2dcZuJhqkFboJzr2BITTM2aXhLPVVWDO8SLvD6 IrXrECxPE5tv5ZjYgS5m4zkBew== X-Received: by 2002:a05:6a20:a128:b0:132:8daa:23eb with SMTP id q40-20020a056a20a12800b001328daa23ebmr2053712pzk.4.1689108242624; Tue, 11 Jul 2023 13:44:02 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id f7-20020aa78b07000000b00640ddad2e0dsm2124461pfd.47.2023.07.11.13.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 13:44:02 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Cc: brauner@kernel.org, arnd@arndb.de, Jens Axboe Subject: [PATCH 3/5] exit: add kernel_waitid_prepare() helper Date: Tue, 11 Jul 2023 14:43:50 -0600 Message-Id: <20230711204352.214086-4-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230711204352.214086-1-axboe@kernel.dk> References: <20230711204352.214086-1-axboe@kernel.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771158440280925176 X-GMAIL-MSGID: 1771158440280925176 Move the setup logic out of kernel_waitid(), and into a separate helper. No functional changes intended in this patch. Signed-off-by: Jens Axboe --- kernel/exit.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index d8fb124cc038..8934c91a9fe1 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -1662,14 +1662,12 @@ static long do_wait(struct wait_opts *wo) return retval; } -static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop, - int options, struct rusage *ru) +static int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid, + struct waitid_info *infop, int options, + struct rusage *ru, unsigned int *f_flags) { - struct wait_opts wo; struct pid *pid = NULL; enum pid_type type; - long ret; - unsigned int f_flags = 0; if (options & ~(WNOHANG|WNOWAIT|WEXITED|WSTOPPED|WCONTINUED| __WNOTHREAD|__WCLONE|__WALL)) @@ -1703,7 +1701,7 @@ static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop, if (upid < 0) return -EINVAL; - pid = pidfd_get_pid(upid, &f_flags); + pid = pidfd_get_pid(upid, f_flags); if (IS_ERR(pid)) return PTR_ERR(pid); @@ -1712,19 +1710,34 @@ static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop, return -EINVAL; } - wo.wo_type = type; - wo.wo_pid = pid; - wo.wo_flags = options; - wo.wo_info = infop; - wo.wo_rusage = ru; - if (f_flags & O_NONBLOCK) - wo.wo_flags |= WNOHANG; + wo->wo_type = type; + wo->wo_pid = pid; + wo->wo_flags = options; + wo->wo_info = infop; + wo->wo_rusage = ru; + if (*f_flags & O_NONBLOCK) + wo->wo_flags |= WNOHANG; + + return 0; +} + +static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop, + int options, struct rusage *ru) +{ + struct wait_opts wo; + long ret; + unsigned int f_flags = 0; + + ret = kernel_waitid_prepare(&wo, which, upid, infop, options, ru, + &f_flags); + if (ret) + return ret; ret = do_wait(&wo); if (!ret && !(options & WNOHANG) && (f_flags & O_NONBLOCK)) ret = -EAGAIN; - put_pid(pid); + put_pid(wo.wo_pid); return ret; } From patchwork Tue Jul 11 20:43:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 118711 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp735569vqm; Tue, 11 Jul 2023 13:51:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlE/o3HD7pfewgu6BtElROIZf9qjRIhje9IxdMazylwazaxB9NiXdJq9i00vs7Rmv9wP8tVA X-Received: by 2002:aa7:d658:0:b0:51e:2282:e1fc with SMTP id v24-20020aa7d658000000b0051e2282e1fcmr15967579edr.6.1689108719338; Tue, 11 Jul 2023 13:51:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689108719; cv=none; d=google.com; s=arc-20160816; b=CzA1zjmMd2zYDr9Tu0lahTKO5Kx6MuAhw4DzDBRjLWhBuOUG09AaGcz0R0BX0vXkFU fI9PwwGCitHV8KQnFLL4Js0r+VEPRqoIKZbz2dUuqlUJ349vw4gLuq9oU8exkYOSJsMm lY/DLpEmrWXNSfBRxIKGlw/jtE+DXIP3vyhMAmCBBks16oJVrIdM1JVS9giX46LPZHph AGhgGVrAE4sRDTeLYFNqGL0Mw49IdNYfmbkq+FAerms7YPBwjU4066t9NYCrZ0XeW7Sf ZfZILDZSc1HdUVOWXdbTkidPTNgKIdZlxS5u0ke9Wp4MloGeoXyj4lguMYRl7kWhmCTk nMpQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=C9zc53z+/V9/ECV3tKzh/T4s2rLLXca0QnmcU/Zn8AM=; fh=p+wOSmeLusTVqUKR8aQc56XBO9QP4vSQ6AXDIQF3284=; b=SBNvf0wGJTmaxpDGBrc8F+lNIMH7WNrFQoZTkkuSHZZPoDI14b/pMAoeBrdtzlvwYu pm5559G0RhbsG+0Jol3hbQrRq7MdwgopxwyMRGP553BUEhU24W+ibbvJa44rsk0vj5f+ TgT6huUhaopywfYNhCcZAqcqXRBImUJo21pjsqU2uz75+zwvWy7iBBqkDVd8aqcFGY8E Pcuv6C1JHBJ5c0da/fZ6xY7QrD1ljyql/3Q9kIK3e6/boO/3c+BfUflDTsK5SQt9OmNh eSFLJajoTO4gc5x/yjQ3C5ZPiipw/+8Tq4zGrO2TipmZg3yl386wIbHyFZnalFwIVgdY Gz0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=4stpGtuZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v10-20020aa7d9ca000000b0051e16ff03f5si3043737eds.319.2023.07.11.13.51.35; Tue, 11 Jul 2023 13:51:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=4stpGtuZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230258AbjGKUoO (ORCPT + 99 others); Tue, 11 Jul 2023 16:44:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230059AbjGKUoH (ORCPT ); Tue, 11 Jul 2023 16:44:07 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F0C81710 for ; Tue, 11 Jul 2023 13:44:04 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6748a616e17so1602713b3a.1 for ; Tue, 11 Jul 2023 13:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1689108244; x=1689713044; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C9zc53z+/V9/ECV3tKzh/T4s2rLLXca0QnmcU/Zn8AM=; b=4stpGtuZn7oMLOlDScS37tR4LbmPlFNAC023tmFK1/0CFyIBw0w4A5dau++EKDbUcT ujMsJ7PJofZSUz6kakzpmFt4T3MOOWrdKDgumuKIa0qo29UaJCdMBPCqUKMjBbnuPbMy 1kUratjfGG5pFsUfdUNIUKYG0s/yyYkSr1sIOWjZ0usCzVaBaf4/jXnyrtb0n7dxfUU2 LdnpD/cMhpPlEsp23nUsqMDSNEkkHz5GFPnKGCvwaZFOT31WMZaXOykDMf5keT6EtMF6 FYA59OuZmBp8EN/8e6xd0w747SZ4CksKsINtcvUbHcnrAG7m2vKKPcWbhPBOVhFbxq09 e3zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689108244; x=1689713044; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C9zc53z+/V9/ECV3tKzh/T4s2rLLXca0QnmcU/Zn8AM=; b=bSpBybGUT/r2NP25qTDp+fRHN8zUrBOtPBO2Dbg/XRSZRXbB6W4p1VDeFo0e+/aXUI 06tf1y0Rl3PYD3BW3MpNLml+gpVTCoNckydI7xSAgQFTULvnlGwZjh7mwn9DxrIR1Gys Yvi8rY57MIZ6J4jIIWXH0aJA48Turx6HpaErsCo0Oz0p/SmQDDhlaPPGde72Cpg5qWEk 9Q6+yf1NZ6wvJUlVBeqNRXH6EWnqeDbtStnEe2cRb5YmeERFqRfxQv23r8MXxcghFDWL 9lXAfXkA/JFeC7wsg0rKh60/mOeKXQs152nx90Apig9ZcQGydk0d15reKbS+wTwdsXgZ 8BPg== X-Gm-Message-State: ABy/qLbJ4pqLFZXxo0JEQIn4GITBqungwNH6K2Pk8QFMExa/szDnwXPY 29OHBhgwpUL4aD5q9tPoKUhUSg== X-Received: by 2002:aa7:91c9:0:b0:668:834d:4bd with SMTP id z9-20020aa791c9000000b00668834d04bdmr17735349pfa.0.1689108243811; Tue, 11 Jul 2023 13:44:03 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id f7-20020aa78b07000000b00640ddad2e0dsm2124461pfd.47.2023.07.11.13.44.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 13:44:03 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Cc: brauner@kernel.org, arnd@arndb.de, Jens Axboe Subject: [PATCH 4/5] exit: add internal include file with helpers Date: Tue, 11 Jul 2023 14:43:51 -0600 Message-Id: <20230711204352.214086-5-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230711204352.214086-1-axboe@kernel.dk> References: <20230711204352.214086-1-axboe@kernel.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771158864305075407 X-GMAIL-MSGID: 1771158864305075407 Move struct wait_opts and waitid_info into kernel/exit.h, and include function declarations for the recently added helpers. Make them non-static as well. This is in preparation for adding a waitid operation through io_uring. With the abtracted helpers, this is now possible. Signed-off-by: Jens Axboe --- kernel/exit.c | 32 +++++++------------------------- kernel/exit.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 kernel/exit.h diff --git a/kernel/exit.c b/kernel/exit.c index 8934c91a9fe1..1c9d1cbadcd0 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -74,6 +74,8 @@ #include #include +#include "exit.h" + /* * The default value should be high enough to not crash a system that randomly * crashes its kernel from time to time, but low enough to at least not permit @@ -1037,26 +1039,6 @@ SYSCALL_DEFINE1(exit_group, int, error_code) return 0; } -struct waitid_info { - pid_t pid; - uid_t uid; - int status; - int cause; -}; - -struct wait_opts { - enum pid_type wo_type; - int wo_flags; - struct pid *wo_pid; - - struct waitid_info *wo_info; - int wo_stat; - struct rusage *wo_rusage; - - wait_queue_entry_t child_wait; - int notask_error; -}; - static int eligible_pid(struct wait_opts *wo, struct task_struct *p) { return wo->wo_type == PIDTYPE_MAX || @@ -1520,7 +1502,7 @@ static int ptrace_do_wait(struct wait_opts *wo, struct task_struct *tsk) return 0; } -static bool pid_child_should_wake(struct wait_opts *wo, struct task_struct *p) +bool pid_child_should_wake(struct wait_opts *wo, struct task_struct *p) { if (!eligible_pid(wo, p)) return false; @@ -1590,7 +1572,7 @@ static int do_wait_pid(struct wait_opts *wo) return 0; } -static long __do_wait(struct wait_opts *wo) +long __do_wait(struct wait_opts *wo) { long retval; @@ -1662,9 +1644,9 @@ static long do_wait(struct wait_opts *wo) return retval; } -static int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid, - struct waitid_info *infop, int options, - struct rusage *ru, unsigned int *f_flags) +int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid, + struct waitid_info *infop, int options, + struct rusage *ru, unsigned int *f_flags) { struct pid *pid = NULL; enum pid_type type; diff --git a/kernel/exit.h b/kernel/exit.h new file mode 100644 index 000000000000..f10207ba1341 --- /dev/null +++ b/kernel/exit.h @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-only +#ifndef LINUX_WAITID_H +#define LINUX_WAITID_H + +struct waitid_info { + pid_t pid; + uid_t uid; + int status; + int cause; +}; + +struct wait_opts { + enum pid_type wo_type; + int wo_flags; + struct pid *wo_pid; + + struct waitid_info *wo_info; + int wo_stat; + struct rusage *wo_rusage; + + wait_queue_entry_t child_wait; + int notask_error; +}; + +bool pid_child_should_wake(struct wait_opts *wo, struct task_struct *p); +long __do_wait(struct wait_opts *wo); +int kernel_waitid_prepare(struct wait_opts *wo, int which, pid_t upid, + struct waitid_info *infop, int options, + struct rusage *ru, unsigned int *f_flags); +#endif From patchwork Tue Jul 11 20:43:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 118710 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp735080vqm; Tue, 11 Jul 2023 13:50:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlFYssthc09fGJ0DpdsA3lQplJfVdi4IMjTSg4JPQ8I4cGBtIDqGeHn5ROejG52/VSWEWUzP X-Received: by 2002:a17:906:c7c3:b0:992:c774:9415 with SMTP id dc3-20020a170906c7c300b00992c7749415mr15225352ejb.63.1689108639845; Tue, 11 Jul 2023 13:50:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689108639; cv=none; d=google.com; s=arc-20160816; b=MwQyqNbhzFHv6JlmKeZIsCWThXBrdoK7ZfyHigAF7ZqaWcfx9zbujWMY154/6ExGIJ N8dgC2bqfbT40qkgqg5B9CveEDocyhU3jJD2R7p7MDQ2IQ1Cv8z5DtOuFN5LW2pWrEBA 1jgDavCcTeI/s02fUEHmtIpTDRdYLB1GdEJZuQsMMsx3EjoGg1KAIuX8WN4JPsHrjDnt QXAcINIrso0IzzocZmZzvyr+MuNT1dNQg4RjH6aULSXWv+nlLRcHt7EYR2TU7lSypqOm SPRYmk42yMcCvoagYvp0lWUjvumWgg6LnBkZvr97SKqjOSKdrpG/iK4wGmDmhh+Xif0C bbYQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4n2XJYve3gudseqRv7072PVt+VBZ9vLHlAyLPSwsN/I=; fh=p+wOSmeLusTVqUKR8aQc56XBO9QP4vSQ6AXDIQF3284=; b=vDutyp6YUxUTfHbP+GQdJSwr+qwQU9lmzZRJpgJY1bv2T6hp2Mhx4PgbnZMOQN4ho9 buxvVphA/WpsnCdiAOhFrHjVmvnxdZE8JAej+3uRXswwP2BO7P4HeAO6XF3t7vYWcUu/ 3MBRH4YF5oyBWQvp6IZNFa3b3qCYsS0AO20VmiioAwkJvM7Kq+SZVv9L1lK7lOdmTC5t eQ+va98WONLntOJDBxVzgZ5saEJZXW64A7HLVsCbUQrGtkfu3m7773L4lMQyXgTD3AXP JzoTK0LF5Wgl3ohn4OBaqx5pghcKeO2CDLizdPaPdvvoTs7pLpo7pqH64xHh5d9sCotJ RS5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=hoqlSJMX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gl25-20020a170906e0d900b00989004c1498si2799139ejb.589.2023.07.11.13.50.16; Tue, 11 Jul 2023 13:50:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=hoqlSJMX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229548AbjGKUoR (ORCPT + 99 others); Tue, 11 Jul 2023 16:44:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230038AbjGKUoI (ORCPT ); Tue, 11 Jul 2023 16:44:08 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F60D171E for ; Tue, 11 Jul 2023 13:44:06 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-66d6a9851f3so980765b3a.0 for ; Tue, 11 Jul 2023 13:44:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1689108245; x=1691700245; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4n2XJYve3gudseqRv7072PVt+VBZ9vLHlAyLPSwsN/I=; b=hoqlSJMXDZRjzpvMprCZFtEPTuYFxntpTMkogVqVpJuYzu8Z7VT4qsPYmgexTPgYf1 91L7Ks/8w2OrPNdC+VctUI+jIEDikGki82svmKpbv0WvfqCR40J5LPHMc0hYj3FhTEbb 0WbF5XbluoHDZ6RqEFwHA1YMcxM8rbapIIi5iHBiGXT3oDIQ6T7UiftevGB9Z2TpRc8J WsAjaSeSY1+pF0GoZ3YtIy75LmKD+WnbbObBSPPXWaFNUnTbe8uZRapkkvgsagApRp6l m67C1BAzGlrmly7Vbjjw8uKBLGPdCoLxB9Gufo+KD4ODCfLxziMEo+K+pVMsFaLScI7/ /kUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689108245; x=1691700245; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4n2XJYve3gudseqRv7072PVt+VBZ9vLHlAyLPSwsN/I=; b=RBA1sIlEeyridH+lKp/dj4jxDM0z6tlm2K8VzfJCeXAzH+YuwniGn4PfaKX/VpbNQ3 yp8OtWiuPppca4cmKWVpidfcaiFEzETFj8SCyNV9NMR4VNh7fFmU+Xp9GGV57aCTf41R IKr2dcdOjC4Cu7EpBRKi2NFQOEqJLRHumVxl43v7dqCLg7VDHKgoXeMWSWY+KfKheHTv pG35MUmLyAOxJBkxQrRksp+Hus8dRBR3lHlIKsvuZPTo6d4Z3SUwxeIDg38Dvs5PJWWc 3TcWkHAtIoSYs0EUyCcJnsjxpqF/Bk5ApWPFLJ68fPVC0pWQCeWoFijhhmdCkBtCMWxu cWUg== X-Gm-Message-State: ABy/qLY9qWHfUHnDNy6s1AN8nvTgNDx5c1BPNqFakJ/oUKcCYoXF3JJa Aa8zCmB8X4AGL0WwwN5JE5AGxg== X-Received: by 2002:a05:6a00:308f:b0:677:bb4c:c321 with SMTP id bh15-20020a056a00308f00b00677bb4cc321mr16851831pfb.0.1689108245363; Tue, 11 Jul 2023 13:44:05 -0700 (PDT) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id f7-20020aa78b07000000b00640ddad2e0dsm2124461pfd.47.2023.07.11.13.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 13:44:04 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Cc: brauner@kernel.org, arnd@arndb.de, Jens Axboe Subject: [PATCH 5/5] io_uring: add IORING_OP_WAITID support Date: Tue, 11 Jul 2023 14:43:52 -0600 Message-Id: <20230711204352.214086-6-axboe@kernel.dk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230711204352.214086-1-axboe@kernel.dk> References: <20230711204352.214086-1-axboe@kernel.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771158781095932925 X-GMAIL-MSGID: 1771158781095932925 This adds support for an async version of waitid(2), in a fully async version. If an event isn't immediately available, wait for a callback to trigger a retry. The format of the sqe is as follows: sqe->len The 'which', the idtype being queried/waited for. sqe->fd The 'pid' (or id) being waited for. sqe->file_index The 'options' being set. sqe->addr2 A pointer to siginfo_t, if any, being filled in. buf_index, add3, and waitid_flags are reserved/unused for now. waitid_flags will be used for options for this request type. One interesting use case may be to add multi-shot support, so that the request stays armed and posts a notification every time a monitored process state change occurs. Note that this does not support rusage, on Arnd's recommendation. See the waitid(2) man page for details on the arguments. Signed-off-by: Jens Axboe --- include/linux/io_uring_types.h | 2 + include/uapi/linux/io_uring.h | 2 + io_uring/Makefile | 2 +- io_uring/cancel.c | 5 + io_uring/io_uring.c | 3 + io_uring/opdef.c | 9 ++ io_uring/waitid.c | 271 +++++++++++++++++++++++++++++++++ io_uring/waitid.h | 15 ++ 8 files changed, 308 insertions(+), 1 deletion(-) create mode 100644 io_uring/waitid.c create mode 100644 io_uring/waitid.h diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index a7f03d8d879f..598553877fc2 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -276,6 +276,8 @@ struct io_ring_ctx { struct hlist_head futex_list; struct io_alloc_cache futex_cache; + struct hlist_head waitid_list; + const struct cred *sq_creds; /* cred used for __io_sq_thread() */ struct io_sq_data *sq_data; /* if using sq thread polling */ diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 420f38675769..8fca2cffc343 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -66,6 +66,7 @@ struct io_uring_sqe { __u32 msg_ring_flags; __u32 uring_cmd_flags; __u32 futex_flags; + __u32 waitid_flags; }; __u64 user_data; /* data to be passed back at completion time */ /* pack this to avoid bogus arm OABI complaints */ @@ -239,6 +240,7 @@ enum io_uring_op { IORING_OP_FUTEX_WAIT, IORING_OP_FUTEX_WAKE, IORING_OP_FUTEX_WAITV, + IORING_OP_WAITID, /* this goes last, obviously */ IORING_OP_LAST, diff --git a/io_uring/Makefile b/io_uring/Makefile index 2e4779bc550c..e5be47e4fc3b 100644 --- a/io_uring/Makefile +++ b/io_uring/Makefile @@ -8,6 +8,6 @@ obj-$(CONFIG_IO_URING) += io_uring.o xattr.o nop.o fs.o splice.o \ statx.o net.o msg_ring.o timeout.o \ sqpoll.o fdinfo.o tctx.o poll.o \ cancel.o kbuf.o rsrc.o rw.o opdef.o \ - notif.o + notif.o waitid.o obj-$(CONFIG_IO_WQ) += io-wq.o obj-$(CONFIG_FUTEX) += futex.o diff --git a/io_uring/cancel.c b/io_uring/cancel.c index 3dba8ccb1cd8..a01f3f41012b 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -16,6 +16,7 @@ #include "poll.h" #include "timeout.h" #include "futex.h" +#include "waitid.h" #include "cancel.h" struct io_cancel { @@ -124,6 +125,10 @@ int io_try_cancel(struct io_uring_task *tctx, struct io_cancel_data *cd, if (ret != -ENOENT) return ret; + ret = io_waitid_cancel(ctx, cd, issue_flags); + if (ret != -ENOENT) + return ret; + spin_lock(&ctx->completion_lock); if (!(cd->flags & IORING_ASYNC_CANCEL_FD)) ret = io_timeout_cancel(ctx, cd); diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 67ff148bc394..6d99d51b84e6 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -93,6 +93,7 @@ #include "net.h" #include "notif.h" #include "futex.h" +#include "waitid.h" #include "timeout.h" #include "poll.h" @@ -336,6 +337,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p) ctx->submit_state.free_list.next = NULL; INIT_WQ_LIST(&ctx->locked_free_list); INIT_HLIST_HEAD(&ctx->futex_list); + INIT_HLIST_HEAD(&ctx->waitid_list); INIT_DELAYED_WORK(&ctx->fallback_work, io_fallback_req_func); INIT_WQ_LIST(&ctx->submit_state.compl_reqs); return ctx; @@ -3259,6 +3261,7 @@ static __cold bool io_uring_try_cancel_requests(struct io_ring_ctx *ctx, mutex_lock(&ctx->uring_lock); ret |= io_poll_remove_all(ctx, task, cancel_all); ret |= io_futex_remove_all(ctx, task, cancel_all); + ret |= io_waitid_remove_all(ctx, task, cancel_all); mutex_unlock(&ctx->uring_lock); ret |= io_kill_timeouts(ctx, task, cancel_all); if (task) diff --git a/io_uring/opdef.c b/io_uring/opdef.c index 2034acfe10d0..2fbdf6a6c24a 100644 --- a/io_uring/opdef.c +++ b/io_uring/opdef.c @@ -34,6 +34,7 @@ #include "cancel.h" #include "rw.h" #include "futex.h" +#include "waitid.h" static int io_no_issue(struct io_kiocb *req, unsigned int issue_flags) { @@ -453,6 +454,10 @@ const struct io_issue_def io_issue_defs[] = { .prep = io_eopnotsupp_prep, #endif }, + [IORING_OP_WAITID] = { + .prep = io_waitid_prep, + .issue = io_waitid, + }, }; const struct io_cold_def io_cold_defs[] = { @@ -681,6 +686,10 @@ const struct io_cold_def io_cold_defs[] = { [IORING_OP_FUTEX_WAITV] = { .name = "FUTEX_WAITV", }, + [IORING_OP_WAITID] = { + .name = "WAITID", + .async_size = sizeof(struct io_waitid_async), + }, }; const char *io_uring_get_opcode(u8 opcode) diff --git a/io_uring/waitid.c b/io_uring/waitid.c new file mode 100644 index 000000000000..8d6ac22113dd --- /dev/null +++ b/io_uring/waitid.c @@ -0,0 +1,271 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Support for async notification of waitid + */ +#include +#include +#include +#include +#include + +#include + +#include "io_uring.h" +#include "cancel.h" +#include "waitid.h" +#include "../kernel/exit.h" + +struct io_waitid { + struct file *file; + int which; + pid_t upid; + int options; + struct wait_queue_head *head; + struct siginfo __user *infop; + struct waitid_info info; +}; + +static void io_waitid_free(struct io_kiocb *req) +{ + struct io_waitid_async *iwa = req->async_data; + + put_pid(iwa->wo.wo_pid); + kfree(req->async_data); + req->async_data = NULL; + req->flags &= ~REQ_F_ASYNC_DATA; +} + +static int io_waitid_finish(struct io_kiocb *req, int ret) +{ + struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid); + int signo = 0; + + if (ret > 0) { + signo = SIGCHLD; + ret = 0; + } + if (!iw->infop) + goto done; + + if (!user_write_access_begin(iw->infop, sizeof(*iw->infop))) { + ret = -EFAULT; + goto done; + } + + unsafe_put_user(signo, &iw->infop->si_signo, Efault); + unsafe_put_user(0, &iw->infop->si_errno, Efault); + unsafe_put_user(iw->info.cause, &iw->infop->si_code, Efault); + unsafe_put_user(iw->info.pid, &iw->infop->si_pid, Efault); + unsafe_put_user(iw->info.uid, &iw->infop->si_uid, Efault); + unsafe_put_user(iw->info.status, &iw->infop->si_status, Efault); +done: + user_write_access_end(); + io_waitid_free(req); + return ret; +Efault: + ret = -EFAULT; + goto done; +} + +static void io_waitid_complete(struct io_kiocb *req, int ret) +{ + struct io_tw_state ts = { .locked = true }; + + lockdep_assert_held(&req->ctx->uring_lock); + + /* + * Did cancel find it meanwhile? + */ + if (hlist_unhashed(&req->hash_node)) + return; + + hlist_del_init(&req->hash_node); + + ret = io_waitid_finish(req, ret); + if (ret < 0) + req_set_fail(req); + io_req_set_res(req, ret, 0); + io_req_task_complete(req, &ts); +} + +static bool __io_waitid_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req) +{ + struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid); + struct wait_queue_head *head; + + head = READ_ONCE(iw->head); + if (head) { + struct io_waitid_async *iwa = req->async_data; + + spin_lock_irq(&head->lock); + list_del_init(&iwa->wo.child_wait.entry); + iw->head = NULL; + spin_unlock_irq(&head->lock); + io_waitid_complete(req, -ECANCELED); + return true; + } + + return false; +} + +int io_waitid_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd, + unsigned int issue_flags) +{ + struct hlist_node *tmp; + struct io_kiocb *req; + int nr = 0; + + if (cd->flags & (IORING_ASYNC_CANCEL_FD|IORING_ASYNC_CANCEL_FD_FIXED)) + return -ENOENT; + + io_ring_submit_lock(ctx, issue_flags); + hlist_for_each_entry_safe(req, tmp, &ctx->waitid_list, hash_node) { + if (req->cqe.user_data != cd->data && + !(cd->flags & IORING_ASYNC_CANCEL_ANY)) + continue; + if (__io_waitid_cancel(ctx, req)) + nr++; + if (!(cd->flags & IORING_ASYNC_CANCEL_ALL)) + break; + } + io_ring_submit_unlock(ctx, issue_flags); + + if (nr) + return nr; + + return -ENOENT; +} + +bool io_waitid_remove_all(struct io_ring_ctx *ctx, struct task_struct *task, + bool cancel_all) +{ + struct hlist_node *tmp; + struct io_kiocb *req; + bool found = false; + + lockdep_assert_held(&ctx->uring_lock); + + hlist_for_each_entry_safe(req, tmp, &ctx->waitid_list, hash_node) { + if (!io_match_task_safe(req, task, cancel_all)) + continue; + __io_waitid_cancel(ctx, req); + found = true; + } + + return found; +} + +static void io_waitid_cb(struct io_kiocb *req, struct io_tw_state *ts) +{ + struct io_waitid_async *iwa = req->async_data; + struct io_ring_ctx *ctx = req->ctx; + int ret; + + /* + * If we get -ERESTARTSYS here, we need to re-arm and check again + * to ensure we get another callback. If the retry works, then we can + * just remove ourselves from the waitqueue again and finish the + * request. + */ + ret = __do_wait(&iwa->wo); + if (unlikely(ret == -ERESTARTSYS)) { + struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid); + + io_tw_lock(ctx, ts); + iw->head = ¤t->signal->wait_chldexit; + add_wait_queue(iw->head, &iwa->wo.child_wait); + ret = __do_wait(&iwa->wo); + if (ret == -ERESTARTSYS) + return; + + remove_wait_queue(iw->head, &iwa->wo.child_wait); + iw->head = NULL; + } + + io_tw_lock(ctx, ts); + io_waitid_complete(req, ret); +} + +static int io_waitid_wait(struct wait_queue_entry *wait, unsigned mode, + int sync, void *key) +{ + struct wait_opts *wo = container_of(wait, struct wait_opts, child_wait); + struct io_waitid_async *iwa = container_of(wo, struct io_waitid_async, wo); + struct io_kiocb *req = iwa->req; + struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid); + struct task_struct *p = key; + + if (!pid_child_should_wake(wo, p)) + return 0; + + req->io_task_work.func = io_waitid_cb; + io_req_task_work_add(req); + iw->head = NULL; + list_del_init(&wait->entry); + return 1; +} + +int io_waitid_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) +{ + struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid); + + if (sqe->addr || sqe->buf_index || sqe->addr3 || sqe->waitid_flags) + return -EINVAL; + + iw->which = READ_ONCE(sqe->len); + iw->options = READ_ONCE(sqe->file_index); + iw->upid = READ_ONCE(sqe->fd); + iw->infop = u64_to_user_ptr(READ_ONCE(sqe->addr2)); + iw->head = NULL; + return 0; +} + +int io_waitid(struct io_kiocb *req, unsigned int issue_flags) +{ + struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid); + struct io_ring_ctx *ctx = req->ctx; + struct io_waitid_async *iwa; + unsigned int f_flags = 0; + int ret; + + if (io_alloc_async_data(req)) + return -ENOMEM; + + iwa = req->async_data; + iwa->req = req; + + ret = kernel_waitid_prepare(&iwa->wo, iw->which, iw->upid, &iw->info, + iw->options, NULL, &f_flags); + if (ret) + goto done; + + /* + * Arm our callback and add us to the waitqueue, in case no events + * are available. + */ + init_waitqueue_func_entry(&iwa->wo.child_wait, io_waitid_wait); + iwa->wo.child_wait.private = req->task; + iw->head = ¤t->signal->wait_chldexit; + add_wait_queue(iw->head, &iwa->wo.child_wait); + + io_ring_submit_lock(ctx, issue_flags); + hlist_add_head(&req->hash_node, &ctx->waitid_list); + + ret = __do_wait(&iwa->wo); + if (ret == -ERESTARTSYS) { + io_ring_submit_unlock(ctx, issue_flags); + return IOU_ISSUE_SKIP_COMPLETE; + } + + hlist_del_init(&req->hash_node); + remove_wait_queue(iw->head, &iwa->wo.child_wait); + iw->head = NULL; + ret = io_waitid_finish(req, ret); + + io_ring_submit_unlock(ctx, issue_flags); +done: + if (ret < 0) + req_set_fail(req); + io_req_set_res(req, ret, 0); + return IOU_OK; +} diff --git a/io_uring/waitid.h b/io_uring/waitid.h new file mode 100644 index 000000000000..956a8adafe8c --- /dev/null +++ b/io_uring/waitid.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "../kernel/exit.h" + +struct io_waitid_async { + struct io_kiocb *req; + struct wait_opts wo; +}; + +int io_waitid_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); +int io_waitid(struct io_kiocb *req, unsigned int issue_flags); +int io_waitid_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd, + unsigned int issue_flags); +bool io_waitid_remove_all(struct io_ring_ctx *ctx, struct task_struct *task, + bool cancel_all);