From nobody Fri Jan 19 11:10:47 2024 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TGcNr2XFQz2tqhv; Fri, 19 Jan 2024 11:10:52 +0000 (UTC) (envelope-from rozhuk.im@gmail.com) Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TGcNq2TdXz4cbv; Fri, 19 Jan 2024 11:10:51 +0000 (UTC) (envelope-from rozhuk.im@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20230601 header.b=mQtbMyum; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of rozhuk.im@gmail.com designates 2a00:1450:4864:20::42d as permitted sender) smtp.mailfrom=rozhuk.im@gmail.com Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-33921b8988fso318699f8f.3; Fri, 19 Jan 2024 03:10:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705662649; x=1706267449; darn=freebsd.org; h=content-transfer-encoding:mime-version:message-id:subject:cc:to :date:from:from:to:cc:subject:date:message-id:reply-to; bh=f74U4ZW/gRhjC5Kr5GZaLWL1OfKxzRZp7MIJDnCDrHQ=; b=mQtbMyumo+rwEmupSQmcuNKFcEbQ9JbqT6uTNb+sk/PlcW0fxUXxp8HCkkIlawKI+J LW7Q+YaSPyS+2U001wQZSBplKqUaExLJK7JAOM3tjYnpdN586JksFjJerKjBvJboQ1C4 bg6quhcwnyFDJZxkrqB5k9RPcCxAH3Zs8lm+MzJnES10dhkcPybXxIQiqPjN9qgdVz72 ZCmBBXtdC8g86nPsRexuolmnub2oY/pckmCUCwFW0H/gqvrBnIKV0wQsXjvoxJgJNe6l K+OSHS7RV9PE3dnHOcXfqaGzpd7oM999wU4f8QDuLQjTT70WXRdoj9l58a2swJfpGXgw oNuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705662649; x=1706267449; h=content-transfer-encoding:mime-version:message-id:subject:cc:to :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=f74U4ZW/gRhjC5Kr5GZaLWL1OfKxzRZp7MIJDnCDrHQ=; b=KMoEjkxRI8he6swjm48np4+iKchoGKAZ4LpoZJ5P4/ZeAdnhTFCCW4XFvOkLF7HCd3 45BM3O9rY9bIzVFIPZqPCSw4mlCBFc4MR42hp5lBYPxmJdFWgibAw6B8GbRyzp5lVGop t8yxOqnQZjU1RMkTa4VYm/4C4XW/P8nhJD+UAOQ3HCu+cGYjkDsD3bgFXZf0wJMn6HJn npSLGHVp5+RSa8oW2221yi93tU3bwdtNSQoICHxdO8ym8/coy2RkAto6K1Ftdy5Zj9bH 1BlK/DKEO/Y+pYJkgYxxel+oNl6KCI8kCldIMrX+o8U+W1NfsIqTjigEY+rglpQQ/2IK kT6w== X-Gm-Message-State: AOJu0YzVqTkPVlxz2t4ZnS/0MHBaklDavM0MNznoNSbJRb1tBAwvf7rY +3rWkHRplGfKmbrrTxNkyhffyA9Nt6+suvNHL+2hGGvf6NT6zLcpLsZZ1tN1/Sc= X-Google-Smtp-Source: AGHT+IGKKyzp1IMrhXnyTln7RLrMHZ5KqTiOfjNfp2DY2TYQWRfS5z2omJXkWgBI6Q21YPk99zYyBA== X-Received: by 2002:adf:f645:0:b0:337:c654:c822 with SMTP id x5-20020adff645000000b00337c654c822mr1486738wrp.127.1705662649375; Fri, 19 Jan 2024 03:10:49 -0800 (PST) Received: from rimwks.local ([2001:470:1f15:3d8:80e3:6e27:b43a:1e50]) by smtp.gmail.com with ESMTPSA id a1-20020a5d5081000000b00337d9b772c6sm1753180wrt.37.2024.01.19.03.10.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 03:10:49 -0800 (PST) From: Rozhuk Ivan X-Google-Original-From: Rozhuk Ivan Date: Fri, 19 Jan 2024 13:10:47 +0200 To: FreeBSD Hackers Cc: rozhuk.im@gmail.com, FreeBSD Mailing List Subject: kcmp implementation for mesa Message-ID: <20240119131047.6975f574@rimwks.local> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; amd64-portbld-freebsd14.0) List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spamd-Bar: --- X-Spamd-Result: default: False [-4.00 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36:c]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20230601]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; TAGGED_FROM(0.00)[]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[gmail.com,freebsd.org]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FREEMAIL_ENVFROM(0.00)[gmail.com]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org,freebsd-ports@freebsd.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; TAGGED_RCPT(0.00)[]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::42d:from] X-Rspamd-Queue-Id: 4TGcNq2TdXz4cbv Hi! graphics/mesa-* uses SYS_kcmp [1] to compare two fds: int os_same_file_description(int fd1, int fd2) { pid_t pid = getpid(); /* Same file descriptor trivially implies same file description */ if (fd1 == fd2) return 0; return syscall(SYS_kcmp, pid, pid, KCMP_FILE, fd1, fd2); } FreeBSD does not implemet this and we got in terminal: "amdgpu: os_same_file_description couldn't determine if two DRM fds reference the same file description." Mesa say: /* DRM file descriptors, file descriptions and buffer sharing. * * amdgpu_device_initialize first argument is a file descriptor (fd) * representing a specific GPU. * If a fd is duplicated using os_dupfd_cloexec, * the file description will remain the same (os_same_file_description will * return 0). * But if the same device is re-opened, the fd and the file description will * be different. * * amdgpu_screen_winsys's fd tracks the file description which was * given to amdgpu_winsys_create. This is the fd used by the application * using the driver and may be used in other ioctl (eg: drmModeAddFB) * * amdgpu_winsys's fd is the file description used to initialize the * device handle in libdrm_amdgpu. * * The 2 fds can be different, even in systems with a single GPU, eg: if * radv is initialized before radeonsi. * * This fd tracking is useful for buffer sharing because KMS/GEM handles are * specific to a DRM file description, i.e. the same handle value may refer * to different underlying BOs in different DRM file descriptions. * As an example, if an app wants to use drmModeAddFB it'll need a KMS handle * valid for its fd (== amdgpu_screen_winsys::fd). * If both fds are identical, there's nothing to do: bo->u.real.kms_handle * can be used directly (see amdgpu_bo_get_handle). * If they're different, the BO has to be exported from the device fd as * a dma-buf, then imported from the app fd as a KMS handle. */ I do few checks with dup() and os_dupfd_cloexec() and code show that fd equal. Does this implementation will do that mesa expects? #include #include int os_same_file_description(int fd1, int fd2) { struct kinfo_file kif1, kif2; /* Same file descriptor trivially implies same file description */ if (fd1 == fd2) return (0); kif1.kf_structsize = sizeof(kif1); kif2.kf_structsize = sizeof(kif2); if (-1 == fcntl(fd1, F_KINFO, &kif1) || -1 == fcntl(fd2, F_KINFO, &kif2)) return (-1); if (kif1.kf_type != kif2.kf_type || 0 != memcmp(&kif1.kf_path, &kif2.kf_path, sizeof(kif1.kf_path))) return (3); switch (kif1.kf_type) { case KF_TYPE_VNODE: if (0 == memcmp(&kif1.kf_un.kf_file, &kif2.kf_un.kf_file, sizeof(kif1.kf_un.kf_file))) return (0); return (3); case KF_TYPE_SOCKET: if (0 == memcmp(&kif1.kf_un.kf_sock, &kif2.kf_un.kf_sock, sizeof(kif1.kf_un.kf_sock))) return (0); return (3); case KF_TYPE_PIPE: if (0 == memcmp(&kif1.kf_un.kf_pipe, &kif2.kf_un.kf_pipe, sizeof(kif1.kf_un.kf_pipe))) return (0); return (3); //case KF_TYPE_FIFO: case KF_TYPE_KQUEUE: if (0 == memcmp(&kif1.kf_un.kf_kqueue, &kif2.kf_un.kf_kqueue, sizeof(kif1.kf_un.kf_kqueue))) return (0); return (3); //case KF_TYPE_MQUEUE: //case KF_TYPE_SHM: case KF_TYPE_SEM: if (0 == memcmp(&kif1.kf_un.kf_sem, &kif2.kf_un.kf_sem, sizeof(kif1.kf_un.kf_sem))) return (0); return (3); case KF_TYPE_PTS: if (0 == memcmp(&kif1.kf_un.kf_pts, &kif2.kf_un.kf_pts, sizeof(kif1.kf_un.kf_pts))) return (0); return (3); case KF_TYPE_PROCDESC: if (0 == memcmp(&kif1.kf_un.kf_proc, &kif2.kf_un.kf_proc, sizeof(kif1.kf_un.kf_proc))) return (0); return (3); //case KF_TYPE_DEV: case KF_TYPE_EVENTFD: if (0 == memcmp(&kif1.kf_un.kf_eventfd, &kif2.kf_un.kf_eventfd, sizeof(kif1.kf_un.kf_eventfd))) return (0); return (3); case KF_TYPE_TIMERFD: if (0 == memcmp(&kif1.kf_un.kf_timerfd, &kif2.kf_un.kf_timerfd, sizeof(kif1.kf_un.kf_timerfd))) return (0); return (3); } /* Otherwise we can't tell */ return (-1); } Refs: 1. https://man7.org/linux/man-pages/man2/kcmp.2.html