Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp60300lqo; Tue, 7 May 2024 12:06:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU5EF5DEhR81Oa3jmNMpPGCelpkhScF0vGMO1EKTMFQLXtCUsy7Yv/6uwQLAuG5XIUJhyud+EDP+MIYETkjdVIsgeBzkXPDrJ3nFujFBw== X-Google-Smtp-Source: AGHT+IHUl58rkNLE95/wlOtsY6YmLSjPfegNyZp60x4kaZZY4Chw2An0Tu2cl4UE09bY8m2SAewb X-Received: by 2002:a05:6a20:f393:b0:1ad:7e82:c091 with SMTP id adf61e73a8af0-1afc8d1b048mr570366637.10.1715108790974; Tue, 07 May 2024 12:06:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715108790; cv=pass; d=google.com; s=arc-20160816; b=GyqO5BX5CE9LQT2jPb5WFNXXGQ6AjJ1+m5jG5Daz4nfvIpDBOESDEpsbYRQcdjmrQo NurbVKDqN/YyOPTCNBso+4OxWqJMQnwkEqdngjD2k8XHH+FetAmv8JQkNS66mRWXKxG2 T1BWJ2aquyH2lhMc7Tj6tvz/gvRZe90cHH4BOnpiLp/ctyBKBAiQzX+plmnryYYjr3a6 IvOtZcCccwfMbxp9R9Z4sgvNOUN3XYt0d2X9NhaVOpLQkp//y6r1AoWSEGLESjjA/40F Gw8OQyUGJNNJy1Nl3r42cTHBRJfn27D/lDb91xwManoMgkBO+beAAfvw5AGKWvltoMy0 EM1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=YmWheXdPpQuPLWl1RiMEbt0Eg1z181/dlD8IMNrkg1o=; fh=cwg5IJvkleuLlumxH+mNFvxGF8D4VKYB6FqvfvrnrG8=; b=sl4sZnrI1PLty0R2v6ERXw/GgI4ZjKFuEjSnThV/nWoY9H0iXVLqQICZTSd8BgamF9 iHhq4mgAkLv22RU89Va9PvZlPRJ1+hR50J6XkaUWR1buq1jWvkl934Zhjre+PEoNRmGE mEU81JmEGv6Q79Ue4y6j0DiJP7Ylo+CiFmSuDBGh6N4X8z3Vg6iAhJ/DrWt3X6yoAuX6 dBYNSGPKq6VhhGxY7v/2rqDtqBYmvQTe+gjnbUX/5Bbu674+vv7xmg3m3PPyF2qzZdj0 1mtrXgTGCszzMnQjnoWPWm8bf2w82+savwr7UotfSGYznL/ymVexqk9RRondmJSA2ltK W4Vg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=eo+YnCWO; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-171946-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171946-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id bx20-20020a056a02051400b00621a6cc8918si7028874pgb.615.2024.05.07.12.06.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 12:06:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171946-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=eo+YnCWO; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-171946-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171946-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id AC142B22AD5 for ; Tue, 7 May 2024 18:04:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 074DC16D325; Tue, 7 May 2024 18:04:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="eo+YnCWO" Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (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 CB307748F for ; Tue, 7 May 2024 18:04:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105067; cv=none; b=aP0VybpRMdPv8Bol0VZ9ipKI09tVL7XFt62zB2K0+H1YJfwLHhAf5JBqoaLEj/H0OkxmchiOVcY50kr2cKNCSZllheQ/cDl37lwxh5AqpLwHWU7wpU7kwOsBH7jKecgOHbNVm3pyv3TG3eWSw03GyjDWoZkdHYu59Bg6ytP93sE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105067; c=relaxed/simple; bh=bAeC75xvNb+JauaCbjaxHSxSCPq7tnqY5BqL0SZHYRw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Id/ecTtLnkDdg46VDhv1Lo/LSKQeHEeT97kFV5aty8G0kvSfmQRe1m1/8XYWJI8zTuu4UiX9QQAb7EGdxkRIf5M2vjhhFwVHGST1nBlFKE44UgAteCOv9m3cRrpAqHB0ONy5sOh7h8LF2zvlVcd5aher6SpqUn7L1OWsLERhzpQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch; spf=none smtp.mailfrom=ffwll.ch; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b=eo+YnCWO; arc=none smtp.client-ip=209.85.167.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ffwll.ch Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3c6febc1506so88490b6e.1 for ; Tue, 07 May 2024 11:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1715105065; x=1715709865; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YmWheXdPpQuPLWl1RiMEbt0Eg1z181/dlD8IMNrkg1o=; b=eo+YnCWOylpYuKvM7GG0ZejU8v4QEDQ1r73vBdA99OHLl2GcaygX80XSd9UDYeJfvk 3sDUd7+rkuhuYRoyrZ7S9Gw/e7g3GEgmha28eVvySJRUQiF3GIXqcuEPD2tknRAKTjIV YAuGOVeB9P/q7P5b3e00HC/xqHRlFGb2HMO08= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715105065; x=1715709865; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YmWheXdPpQuPLWl1RiMEbt0Eg1z181/dlD8IMNrkg1o=; b=ofpDU4GpyCs10tUscRa74QrGyTz+B5lkLN2VDMiVSLZtA8sQ3kJ2Teylhqt4E3vztQ xaF4D+/d0FlWy2SqaFLS9MsXImHLiOQfV4YInRoanaEfCrBGMqCXku8swl2a8n8VNU6+ pQUDHlt4tXkknT5vZKn5Y2ekiXTuU2AAGcCWi2do+xMxReREtcoLBGkPJuFH61PfykPJ PwBztwsY/9jk5aDIA1aJZvxzGH5ZHiBHKltqxNbUG6NhVO4Bxzy1JtXRHbQTwFjXX6v9 hl11b2Qsm429HLmdtMwINhEdi6c4OSwzgg2Le88o84L4znxaVA5JGICp3tSE1L/qSLmY NFMQ== X-Forwarded-Encrypted: i=1; AJvYcCVCQXGyt35GhDFEEfguBn59j/fkBxmOQ05XXRfnjjKxzTHQaKlUvmcIOidyRW+0ep+lQwBhmiUeDHO6WVAdTFGzRycFxLV1OBiFFhOI X-Gm-Message-State: AOJu0YwYAYXvQdqqV8UkjlCirgnM/8ZndzBFzLE6l5kpy9ziEoDCY4/m ZpS3uP9SmRa1o2n1uQTLK4QvImUJ+MJr6RwtaG3Z1zDK0s5yGlxyuDP4n2XGWDkD0Xp2wxxzdy7 /43K6jeUrArSy1nduvKbBWFC26ayS8+kfN6ocxw== X-Received: by 2002:a05:6870:239a:b0:22e:dfbc:4aae with SMTP id 586e51a60fabf-240980ba70cmr376610fac.2.1715105064951; Tue, 07 May 2024 11:04:24 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <202405031110.6F47982593@keescook> <20240503211129.679762-2-torvalds@linux-foundation.org> <20240503212428.GY2118490@ZenIV> <20240504-wohngebiet-restwert-6c3c94fddbdd@brauner> In-Reply-To: From: Daniel Vetter Date: Tue, 7 May 2024 20:04:13 +0200 Message-ID: Subject: Re: [Linaro-mm-sig] Re: [PATCH] epoll: try to be a _bit_ better about file lifetimes To: Linus Torvalds , Simon Ser , Pekka Paalanen Cc: =?UTF-8?Q?Christian_K=C3=B6nig?= , Christian Brauner , Al Viro , keescook@chromium.org, axboe@kernel.dk, christian.koenig@amd.com, dri-devel@lists.freedesktop.org, io-uring@vger.kernel.org, jack@suse.cz, laura@labbott.name, linaro-mm-sig@lists.linaro.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, minhquangbui99@gmail.com, sumit.semwal@linaro.org, syzbot+045b454ab35fd82a35fb@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" On Tue, May 07, 2024 at 09:46:31AM -0700, Linus Torvalds wrote: > On Tue, 7 May 2024 at 04:03, Daniel Vetter wrote: > > > > It's really annoying that on some distros/builds we don't have that, and > > for gpu driver stack reasons we _really_ need to know whether a fd is the > > same as another, due to some messy uniqueness requirements on buffer > > objects various drivers have. > > It's sad that such a simple thing would require two other horrid > models (EPOLL or KCMP). > > There'[s a reason that KCMP is a config option - *some* of that is > horrible code - but the "compare file descriptors for equality" is not > that reason. > > Note that KCMP really is a broken mess. It's also a potential security > hole, even for the simple things, because of how it ends up comparing > kernel pointers (ie it doesn't just say "same file descriptor", it > gives an ordering of them, so you can use KCMP to sort things in > kernel space). > > And yes, it orders them after obfuscating the pointer, but it's still > not something I would consider sane as a baseline interface. It was > designed for checkpoint-restore, it's the wrong thing to use for some > "are these file descriptors the same". > > The same argument goes for using EPOLL for that. Disgusting hack. > > Just what are the requirements for the GPU stack? Is one of the file > descriptors "trusted", IOW, you know what kind it is? > > Because dammit, it's *so* easy to do. You could just add a core DRM > ioctl for it. Literally just > > struct fd f1 = fdget(fd1); > struct fd f2 = fdget(fd2); > int same; > > same = f1.file && f1.file == f2.file; > fdput(fd1); > fdput(fd2); > return same; > > where the only question is if you also woudl want to deal with O_PATH > fd's, in which case the "fdget()" would be "fdget_raw()". > > Honestly, adding some DRM ioctl for this sounds hacky, but it sounds > less hacky than relying on EPOLL or KCMP. Well, in slightly more code (because it's part of the "import this dma-buf/dma-fence/whatever fd into a driver object" ioctl) this is what we do. The issue is that there's generic userspace (like compositors) that sees these things fly by and would also like to know whether the other side they receive them from is doing nasty stuff/buggy/evil. And they don't have access to the device drm fd (since those are a handful of layers away behind the opengl/vulkan userspace drivers even if the compositor could get at them, and in some cases not even that). So if we do this in drm we'd essentially have to create a special drm_compare_files chardev, put the ioctl there and then tell everyone to make that thing world-accessible. Which is just too close to a real syscall that it's offensive, and hey kcmp does what we want already (but unfortunately also way more). So we rejected adding that to drm. But we did think about it. > I'd be perfectly ok with adding a generic "FISAME" VFS level ioctl > too, if this is possibly a more common thing. and not just DRM wants > it. > > Would something like that work for you? Yes. Adding Simon and Pekka as two of the usual suspects for this kind of stuff. Also example code (the int return value is just so that callers know when kcmp isn't available, they all only care about equality): https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/util/os_file.c#L239 -Sima -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch