Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3353541ybc; Thu, 14 Nov 2019 07:53:25 -0800 (PST) X-Google-Smtp-Source: APXvYqy8G5lfJvcncIr8Z85ulBCxgh6WAr0550lqeJBjdZG7C3xy7LS5JLP8rc7wtYDkOLPP6TtM X-Received: by 2002:aa7:c942:: with SMTP id h2mr2147467edt.238.1573746805016; Thu, 14 Nov 2019 07:53:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573746805; cv=none; d=google.com; s=arc-20160816; b=izcot2xpDJbuuugra4Jwkl48RZ1dwJSRTdGkqNeY6Ma41PCiYUBlre0m3HnogMfUgQ 571RozV7IK98/EAQTt9vZl8Hod5KIsRvR4glEfTu5YDV0T/bbX/dbUyODFlVk2B4EYDm vnzTfHi+rOsGE8cyxUikmYdOi7+RR/Le1L10z9g0yh9F/1/SZ60QtOMNjaL7OoVSYH9F ds9N9vgDtFI4hWbyyxPPmJmsC7FBiYok5QDsrJwMTG8orhzMFmWpkX8fL8LDpiNeAz4P EMGDhpjsvVSrv8MWMZiyAltTus9AD9WLvVJQcec92/81iISsz5B7VBG37/XZxPGBqOzU odNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:dkim-signature; bh=+RprlYzhSDEqjzZjpfI3XGa25r7ZTr5XLWPzcC7ZwH0=; b=pE36u+8j95mK4xqcLc86uL4yqBk3wjSLULpvyPgvR8626fxsW+5APqOH2GvdZigBaT iG0gsZe4vE2km6YgJPNdaKGNAfcIrtoEIOnPt1RBkAJRqzhBURcnRaJ/nMaPj5GX8a9u 9Mm/Qw9HQM98oaeCibb1dhMjFcNn9khjYeo5Jd8iO3RWt0eNp+M7GcKBFtV35wGDmxXK NwZhgaVYtqwvCfIaBy1CJynGCON9dHJysaJloWK4MoqhUrh9JBmv8njXvG5RGn0SrFCU ixYVZfkNhKftV4MbWq13RMGBjEGNmu7yd2v1WiHwg/dvKxKwqmWRwURkkc8LmxOBPCGz QMIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=cteXF1eM; 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 bi3si4460869edb.331.2019.11.14.07.52.59; Thu, 14 Nov 2019 07:53:25 -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; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=cteXF1eM; 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 S1726995AbfKNPvL (ORCPT + 99 others); Thu, 14 Nov 2019 10:51:11 -0500 Received: from mail-io1-f66.google.com ([209.85.166.66]:33136 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726443AbfKNPvK (ORCPT ); Thu, 14 Nov 2019 10:51:10 -0500 Received: by mail-io1-f66.google.com with SMTP id j13so7354846ioe.0 for ; Thu, 14 Nov 2019 07:51:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=+RprlYzhSDEqjzZjpfI3XGa25r7ZTr5XLWPzcC7ZwH0=; b=cteXF1eMCEYr0oXOfcP1lDv1V3S5fzBjYUjSfH0IIN9GvX9xSomMJJnxLA8dQE7b7C TcgraWfimEC/gCZ8OT3NOTaAYpwTRdbo8kvdF39A/2jqo5bWAf78QHTpw7ZevshLYbxh ayiBs9Zsa7IvzmfUHJVPwHgS3p+53zDbAQ68EIOBw63WnqvMbViZ/ctH8v7t+qQlSH5t hnODKvP9lBhLsQKgjNosMu6fQtgZGrzQypGYLVF5hlen9z2WXVG2W94xg+bQQiFbTS5i jeJMtrw3pu4ebbifrprAi53C+mmFefphATmFiYaCTYSa6XGuUE6rtIasK6NjvIMmg+8f IwTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=+RprlYzhSDEqjzZjpfI3XGa25r7ZTr5XLWPzcC7ZwH0=; b=pPY2aEc16b3JORZ0HvbfgeCuVuI81nSz83Colz2Qj/LWOwfSsHMwcyUMzcKY4jZVE4 IBjvokHY4//LnPK4jsqXYImKCqXEBiYMNrBK5bN+u+QAQp/SQ8J9Y6LnVrA/SMRf6tBc SCmJo5nWyeeV/JDonDo7iTeHqxltJlE3/d5gyKECq5dizevjd7aVBEX9z7qR/OUq/zLn 4HBr9MBxVKnEJhoUuh0hPauIFOP4JsL7lk1Ymk492YJUNvGcJi25Gc6+ehvbACq4+o33 7t3gbHJh77n1MBoT9AmiSsUDrqwKxtev85xzODawDkLZ/2plDvoSp433l7yW9VpAj9A/ nlaA== X-Gm-Message-State: APjAAAV7MczI31XPpzgZ3BrP94g/d5imXY2BzbG1AizH/uBruRLZA/j9 shh+HJvbyZO/qqSKP5P+ScwhZQ== X-Received: by 2002:a5d:8b85:: with SMTP id p5mr9482626iol.9.1573746667749; Thu, 14 Nov 2019 07:51:07 -0800 (PST) Received: from [192.168.1.159] ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id g11sm827035ilq.39.2019.11.14.07.51.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Nov 2019 07:51:06 -0800 (PST) Subject: Re: [PATCH RFC] io_uring: make signalfd work with io_uring (and aio) POLL From: Jens Axboe To: Rasmus Villemoes , Jann Horn Cc: io-uring@vger.kernel.org, "linux-kernel@vger.kernel.org" , Alexander Viro , Andrew Morton , linux-fsdevel , Christoph Hellwig References: <58059c9c-adf9-1683-99f5-7e45280aea87@kernel.dk> <58246851-fa45-a72d-2c42-7e56461ec04e@kernel.dk> <0f74341f-76fa-93ee-c03e-554d02707053@rasmusvillemoes.dk> <6243eb59-3340-deb5-d4b8-08501be01f34@kernel.dk> <85e8e954-d09c-f0b4-0944-598208098c8c@kernel.dk> Message-ID: <1a5b156a-fde5-507b-d5cf-f42ba3eacf1a@kernel.dk> Date: Thu, 14 Nov 2019 08:51:05 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <85e8e954-d09c-f0b4-0944-598208098c8c@kernel.dk> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/14/19 8:27 AM, Jens Axboe wrote: > On 11/14/19 8:20 AM, Jens Axboe wrote: >> On 11/14/19 8:19 AM, Rasmus Villemoes wrote: >>> On 14/11/2019 16.09, Jens Axboe wrote: >>>> On 11/14/19 7:12 AM, Rasmus Villemoes wrote: >>> >>>>> So, I can't really think of anybody that might be relying on inheriting >>>>> a signalfd instead of just setting it up in the child, but changing the >>>>> semantics of it now seems rather dangerous. Also, I _can_ imagine >>>>> threads in a process sharing a signalfd (initial thread sets it up and >>>>> blocks the signals, all threads subsequently use that same fd), and for >>>>> that case it would be wrong for one thread to dequeue signals directed >>>>> at the initial thread. Plus the lifetime problems. >>>> >>>> What if we just made it specific SFD_CLOEXEC? >>> >>> O_CLOEXEC can be set and removed afterwards. Sure, we're far into >>> "nobody does that" land, but having signalfd() have wildly different >>> semantics based on whether it was initially created with O_CLOEXEC seems >>> rather dubious. >>> >>> I don't want to break >>>> existing applications, even if the use case is nonsensical, but it is >>>> important to allow signalfd to be properly used with use cases that are >>>> already in the kernel (aio with IOCB_CMD_POLL, io_uring with >>>> IORING_OP_POLL_ADD). Alternatively, if need be, we could add a specific >>>> SFD_ flag for this. >>> >>> Yeah, if you want another signalfd flavour, adding it via a new SFD_ >>> flag seems the way to go. Though I can't imagine the resulting code >>> would be very pretty. >> >> Well, it's currently _broken_ for the listed in-kernel use cases, so >> I think making it work is the first priority here. > > How about something like this, then? Not tested. Tested, works for me. Here's the test case I used. We setup a signalfd with SIGALRM, and arm a timer for 100msec. Then we queue a poll for the signalfd, and wait for that to complete with a timeout of 1 second. If we time out waiting for the completion, we failed. If we do get a completion but we don't have POLLIN set, we failed. #include #include #include #include #include #include #include #include #define SFD_TASK 00000001 int main(int argc, char *argv[]) { struct __kernel_timespec ts; struct io_uring_sqe *sqe; struct io_uring_cqe *cqe; struct io_uring ring; struct itimerval itv; sigset_t mask; int sfd, ret; sigemptyset(&mask); sigaddset(&mask, SIGALRM); sigprocmask(SIG_BLOCK, &mask, NULL); sfd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC | SFD_TASK); if (sfd < 0) { if (errno == EINVAL) { printf("Not supported\n"); return 0; } perror("signalfd"); return 1; } memset(&itv, 0, sizeof(itv)); itv.it_value.tv_sec = 0; itv.it_value.tv_usec = 100000; setitimer(ITIMER_REAL, &itv, NULL); io_uring_queue_init(32, &ring, 0); sqe = io_uring_get_sqe(&ring); io_uring_prep_poll_add(sqe, sfd, POLLIN); io_uring_submit(&ring); ts.tv_sec = 1; ts.tv_nsec = 0; ret = io_uring_wait_cqe_timeout(&ring, &cqe, &ts); if (ret < 0) { fprintf(stderr, "Timed out waiting for cqe\n"); ret = 1; } else { if (cqe->res < 0) { fprintf(stderr, "cqe failed with %d\n", cqe->res); ret = 1; } else if (!(cqe->res & POLLIN)) { fprintf(stderr, "POLLIN not set in result mask?\n"); ret = 1; } else { ret = 0; } } io_uring_cqe_seen(&ring, cqe); io_uring_queue_exit(&ring); close(sfd); return ret; } -- Jens Axboe