Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6208212rdb; Thu, 14 Dec 2023 11:07:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IFG92EL+uETP0wSLnUmV44a/vLdNgzPj7er2MrPsF7R8Zi97KwRlz9dRbQ5jK9mZbGDE4Hg X-Received: by 2002:a05:620a:6017:b0:77f:8c26:75d9 with SMTP id dw23-20020a05620a601700b0077f8c2675d9mr5553102qkb.108.1702580833598; Thu, 14 Dec 2023 11:07:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702580833; cv=none; d=google.com; s=arc-20160816; b=dFSs4sXDuR5PyTylC2D5BQpIZfAEY7ediRpdrJfctQRPz6fmiflz1EWsgt68BxtczH KMOBU4B4q4jperi0yvMAmciHk6eX17JW5fpl6UM7wuzyx8XVHEhpzgmkN34WB5RDjI+Z N8aOzz9j8ypSoE1uMj+2U+qqyE2AMhZaVe+ShuLkK9VJi7IiGYgK8svmY62eYqVCTIyQ JDeI6IxW5Wy6ujN52vmJRd8476xEsPPjswamMNexh5yLN/pwkV4fEVPetKU6b/VBXbG6 qzVhAg6QOR0DtVF5tiajKQLseXBXNO2miy1JniUcYr1cck7WKTNpIEV6+fErn4bnKUNk TTOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=qqOs0PUF8MGjM25NmW96fbAjdjE87kFFPmbKKuRqHvQ=; fh=g4dyzEFYnIDRScnGHiW7ajbcMWfhXHZiCVED7qPSh04=; b=Ik2TeG5Y1A8oDd6LhkNLrnd/MPyYIEtHukQHeI5vN/Wipi3Kzt64oR1AGrmgrH2Uub m49nebAO6NcR3KW12IK0r6P6zQKKSb7lHWQx6jiFW4jY7izwZnNu0lEoM8y8sWvyezGO jDy541rcWfReCvy80xnnc0V94V4+wZwkZjXvaBB/PtyICo1Okn31gFq6yBOgtgboio0w vEECSqmgipPd14Yxzjpe7F4oBO6uXeIS5s3F1lriNz+YicVfEeL3Kve7kaNUzV47OhML itv/BiE3hJg0B08AxGaB22qku8EXddQt0vr3QEOk+ibcpLNN7tHkHu3ae/ePDgcPS72Q ZEuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=bL4awJd2; spf=pass (google.com: domain of linux-kernel+bounces-1-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z10-20020a05620a08ca00b0077f0a9abdb6si14968314qkz.101.2023.12.14.11.07.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 11:07:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=bL4awJd2; spf=pass (google.com: domain of linux-kernel+bounces-1-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5C8161C20EDC for ; Thu, 14 Dec 2023 19:07:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C42C468E86; Thu, 14 Dec 2023 19:07:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="bL4awJd2" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-io1-f44.google.com (mail-io1-f44.google.com [209.85.166.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5122068E85 for ; Thu, 14 Dec 2023 19:07:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Received: by mail-io1-f44.google.com with SMTP id ca18e2360f4ac-7b709f8ba01so74420939f.1 for ; Thu, 14 Dec 2023 11:07:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1702580820; x=1703185620; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=qqOs0PUF8MGjM25NmW96fbAjdjE87kFFPmbKKuRqHvQ=; b=bL4awJd2dj3qHosM8eBvoUaKpIe1R+kn55itYPM3IVqAvSHqJw9d+91EGPeS7RKeYU vnx4DZHxVDHCcdHZPVLk0qcpmPAVpr3HMed/irDPnw3qZxQi9/NJXpDjJziweXtuh9Qu qtb9fTusD/I0ygf18zlLDFKT62D6vnx1cuk+RAfudjbnjNrskRZzfq/IznpAOvI4ZVJd 1Ygx6KHrmApvRgvJ/bSriDn8uQgLjfMFCVafQNsuzInCI2e2GtYNRhhq2UcoJMGtsuRl l+yCW/FxdjKwCN28crOix8XijxZpGk4dlgjofVDxXRP7w4SEKD546srkx3WCeB7UJ2hD xriA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702580820; x=1703185620; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qqOs0PUF8MGjM25NmW96fbAjdjE87kFFPmbKKuRqHvQ=; b=BeOyQG0anZ2OS8ECDpJXmkOFOu1PACSwJLsiZKBluO38BB9uYw5ZinILAODDHNoRTV pGKTYUiSMYmZic4bkHVMLP8FFXUzeiNm87jvBkXzo6jQFn6K53ZVd8jFkmNPiyh27J4m PKkCso3UbOjUuEbiThkd+ymv0i1othOlWkgtCDU4BezcTHf/+aQJsfKE4pAV+Zc0iGyL jCUY/T5nKYt3z53X5V8o+dNL+z/h2vxNIcI3IuziVvn3movSqx3BoUH+8oX93fH/OLtR OI1GhEmHuwgAnAjNYPkKpitkuZlkrwJa5MDymAe7IfyguJe0yjqF6uBX5ZwgNhxukQBv vRBg== X-Gm-Message-State: AOJu0YyT+CgXBJ06Uhrj/Xv9ACfFENOnSHuwDjbFWaIv1gn4NRyOLLb8 jAhaROHQD/Nv6DkuVxIAogTfXQ== X-Received: by 2002:a05:6e02:1c05:b0:35f:847c:1e5c with SMTP id l5-20020a056e021c0500b0035f847c1e5cmr1655231ilh.0.1702580820321; Thu, 14 Dec 2023 11:07:00 -0800 (PST) Received: from [192.168.1.116] ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id e6-20020a028606000000b00469010b6cc7sm3588131jai.114.2023.12.14.11.06.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Dec 2023 11:06:59 -0800 (PST) Message-ID: <500557ed-3967-455e-8a79-d64711045b70@kernel.dk> Date: Thu, 14 Dec 2023 12:06:57 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RERESEND 00/11] splice(file<>pipe) I/O on file as-if O_NONBLOCK Content-Language: en-US To: =?UTF-8?Q?Ahelenia_Ziemia=C5=84ska?= Cc: Christian Brauner , Alexander Viro , linux-fsdevel@vger.kernel.org, "D. Wythe" , "David S. Miller" , "Liam R. Howlett" , Alexander Mikhalitsyn , Andrew Morton , Boris Pismenny , Cong Wang , David Ahern , David Howells , Eric Dumazet , Gavrilov Ilia , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Jakub Kicinski , Jan Karcher , John Fastabend , Karsten Graul , Kirill Tkhai , Kuniyuki Iwashima , Li kunyu , linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Masami Hiramatsu , Miklos Szeredi , Paolo Abeni , Pengcheng Yang , Shigeru Yoshida , Steven Rostedt , Suren Baghdasaryan , Tony Lu , Wen Gu , Wenjia Zhang , Xu Panda , Zhang Zhengming References: <2cover.1697486714.git.nabijaczleweli@nabijaczleweli.xyz> From: Jens Axboe In-Reply-To: <2cover.1697486714.git.nabijaczleweli@nabijaczleweli.xyz> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/14/23 11:44 AM, Ahelenia Ziemia?ska wrote: > First: https://lore.kernel.org/lkml/cover.1697486714.git.nabijaczleweli@nabijaczleweli.xyz/t/#u > Resend: https://lore.kernel.org/lkml/1cover.1697486714.git.nabijaczleweli@nabijaczleweli.xyz/t/#u > Resending again per https://lore.kernel.org/lkml/20231214093859.01f6e2cd@kernel.org/t/#u > > Hi! > > As it stands, splice(file -> pipe): > 1. locks the pipe, > 2. does a read from the file, > 3. unlocks the pipe. > > For reading from regular files and blcokdevs this makes no difference. > But if the file is a tty or a socket, for example, this means that until > data appears, which it may never do, every process trying to read from > or open the pipe enters an uninterruptible sleep, > and will only exit it if the splicing process is killed. > > This trivially denies service to: > * any hypothetical pipe-based log collexion system > * all nullmailer installations > * me, personally, when I'm pasting stuff into qemu -serial chardev:pipe > > This follows: > 1. https://lore.kernel.org/linux-fsdevel/qk6hjuam54khlaikf2ssom6custxf5is2ekkaequf4hvode3ls@zgf7j5j4ubvw/t/#u > 2. a security@ thread rooted in > > 3. https://nabijaczleweli.xyz/content/blogn_t/011-linux-splice-exclusion.html > > Patches were posted and then discarded on principle or funxionality, > all in all terminating in Linus posting >> But it is possible that we need to just bite the bullet and say >> "copy_splice_read() needs to use a non-blocking kiocb for the IO". > > This does that, effectively making splice(file -> pipe) > request (and require) O_NONBLOCK on reads fron the file: > this doesn't affect splicing from regular files and blockdevs, > since they're always non-blocking > (and requesting the stronger "no kernel sleep" IOCB_NOWAIT is non-sensical), Not sure how you got the idea that regular files or block devices is always non-blocking, this is certainly not true without IOCB_NOWAIT. Without IOCB_NOWAIT, you can certainly be waiting for previous IO to complete. > but always returns -EINVAL for ttys. > Sockets behave as expected from O_NONBLOCK reads: > splice if there's data available else -EAGAIN. > > This should all pretty much behave as-expected. Should it? Seems like there's a very high risk of breaking existing use cases here. Have you at all looked into the approach of enabling splice to/from _without_ holding the pipe lock? That, to me, would seem like a much saner approach, with the caveat that I have not looked into that at all so there may indeed be reasons why this is not feasible. -- Jens Axboe