From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796568179; b=gtWSqvWz4KRqLIe+8U3Zogz6Ar9YRYpUZ8auLe/Kj1QueWCF6wGe6T/5HbLkpCloZ0kY 8Tlo+zqMMIAF262TuhgXF7e25JVqHj9vvyaKLGZRES+jWsiQtQtALuixyK+niFcZt3QB9 g25OjTs6H09KwUumD9QBD5yXPSDy4yI7VH6bgN8R1k5aKkhgOv7/KA1c00mMxLjLSoo4s QqAWg+F8XqQZz9DoSp7EZZiBMzMYaoejdF/8fdJoAAFVcj+DK5UbC753cPjp8x9MFncYw BJPThOEsvLQfC6fgonRq3QrAy+hvusE+vPhjbN4/Kh1T6zswz+uObSqvTjUq51sXFkA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796568179; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=mxLwDJsX8Cv35hazO9hCOa0Hi39neFfwc94weD/APPk=; b=rluOTxxSw8AA7dClMKrodfMiEupKNJARARNNmBE/s+H0XjdmrmmETY2YxIxbX6uecJBG 11H1WDA+ijxr6fCg0X16Rz05PYePk0ngFT40aulRZnNAFQ686U4lrdXStm6ztn/q6/uLo RHf+K6MOaAwzx3BvBa+oE4/9F022Tg1IZwjqgB3jL/KeSfB3KtlgN0IQFNvXBXsIbGrp3 EiaSQdTwWPOGPUgqxblJxygmug7UiVbWzpTu7u5pXLJbR4w9mMePWwsAC1qWfQ4DtvzPB iHy22fdyYTlvxiW49G9+JndMeAc2jq3hCw5gYI67Oa13Bgaa3vHTn821k2DkELc9y7g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=mGM5p6Cs; arc=none smtp.remote-ip=209.85.221.45 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 145B2606A31F for ; Sun, 6 Dec 2026 14:42:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 145B2606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=mGM5p6Cs Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-492fcbfaa88so1621667f8f.3 for ; Sun, 06 Dec 2026 06:42:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796568177; x=1797172977; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=mxLwDJsX8Cv35hazO9hCOa0Hi39neFfwc94weD/APPk=; b=mGM5p6CsP8n5qmzylqeAnQETcuX5htBUbdqBZvYRU4BBOOj5bLYa6Nx19sMjclLWhX bOIYLnDItJE9J3R1pldKbO/FBwUbvR4/vrdJur6OyEReZ5+SStBdKILtBPQQBAioyIzU pzgPQKS57JRxkz4VFeJPUtX6Ob8GFe2KlJM0e5ykGXUPfXSi0WssngmutMJtipQN578b xmlFZ6CAbvsndIz3KdoPAF/bMoyefdeHLX3S+OgXn29qUNzbvQkn9bb4LFwNzDi9NMPg zKdweVdaqD7J06CmX8+F//wBrKIftaflTfW8zf+lr9wEq6hIkuwL5C0gcO7TyBRuw9Un kfsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796568177; x=1797172977; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=mxLwDJsX8Cv35hazO9hCOa0Hi39neFfwc94weD/APPk=; b=yy04XOf2XGPi1QnxGR0GN8MSSYdHp/kq3TC4WrXbQEXK7UuFlItcT52yKUWTiKkQNo tfduA4eAZ2lY2nIK/OVs8uXXr48jytqKNlXS+uayMe4wMUHZR3MnGITaOyBe0UPtX+TS s/lKnZrvFKPMMddjEK+I31n0rIhFm9efxSe1oWowpPs2Y+ZUXdsQcw8NiBxCsRhKvQje CrnZkXkFPRViyD3DTvWfPQvCOOxEcPH7ZAHFUxIf35hRbAlJov/ZbnP9yBHnhJ/IpDrX t/9CpiMaK5zkbjlBEtg28jJ0w8NNi357RgriKVb1S8X+cUcS0pQxc+qFHB53K8ruhzX4 t+0w== X-Forwarded-Encrypted: i=1; AL+hErGUqG/oUwzz56Bqm1r1guA8nqWrQ00hPYwhyK0RUnLmQsLrS1utkYs3A3BSjFdM66rcqUPAqaLOLuFYdFs=@vger.kernel.org X-Gm-Message-State: AB4q+uGE5buCqgMtRw04AGx+FqmlWKUgWzNXG2aRKXCbR41VVjGbj98f z39/1hB/8VmktdzaQlKHmp+3/3NrVA8dkkFnXgfYWGp4k4VF19aQV64r X-Gm-Gg: AZFdTZd1DT7KgReM03XFc6BIasDnOM1g5FRo8/Lb3ttySRXTMZQvW3ZkgIJ8cQdwpW5 rJuPtpmf5Cp0lBavUldZKRn4tcIQH/14tMkJcoQvzKVkxScBg+Qq0GSOI/rPvoAEESWzkGkv3tj 5JkfrkGlpbYttBjKh9GY1fLHqQBiFXxtvHs8T5wj+OOjDVYWstSaHqtHtpvvUfuAV4jpqPifXnJ WGm8jgXJXJ544ZdwPIIjXTI9TRgEwkbnSVoCbHZxCAkefZ1WHGUoj3CMCcOHcvyl97CrhtXLCRg rhmqHZAxSoOkCYfzNlJrJy7mYRC14v87Un6BS813ZszHGK41VxKo3Kbbf8MtRvT4ZElUadvIfpe bU5p9fUw4XpFScZGuFDZpH1nK/mZe+po5CcezAvkbA+45znUvbnR8CWuqjHfptD3r4KZMOVLRBa tfe7h0ckDoQPY3yHc1yi3QWSeSGpVXjsWTNQ6YbMqisoszR0+H8vf0dsQR2ySdle7M/6iU7zqkw /qPJwuyRHPUVfKWIQ4bRGi2eyyyZzyZLUpOaWRuFvqgrAzsAr/JUYeQN+3MHagKeM1FnlBgur0Q FCWG6jMf/DhaVHANZaU8UkwyFYdujJPbJfkCi6P3WlGPn2VbQFHGeHfSDOO8j8Z9FOFXRmwFa02 VyenF1aUsEQ== X-Received: by 2002:a05:6000:40c9:b0:4a7:1428:13dd with SMTP id ffacd0b85a97d-4d1ea4b39bbmr16494211f8f.21.1796568177170; Sun, 06 Dec 2026 06:42:57 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d172e41d6asm17299365f8f.25.2026.12.06.06.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 06:42:56 -0800 (PST) Date: Sun, 6 Dec 2026 14:42:56 +0000 From: David Laight To: Thomas =?UTF-8?B?V2Vpw59zY2h1aA==?= Cc: Willy Tarreau , linux-kernel@vger.kernel.org, Danish Khateeb , hch@lst.de Subject: Re: [PATCH v2 3/4] tools/nolibc: add support for fcntl() Message-ID: <20261206144256.05bd50b1@pumpkin> In-Reply-To: <82fbde7b-8896-4909-88dc-c535abeba76b@message-id.t-8ch.de> References: <20261202-nolibc-fcntl-v2-0-651ff5781baa@weissschuh.net> <20261202-nolibc-fcntl-v2-3-651ff5781baa@weissschuh.net> <20261206130803.60d5f61d@pumpkin> <82fbde7b-8896-4909-88dc-c535abeba76b@message-id.t-8ch.de> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sun, 6 Dec 2026 14:42:30 +0100 Thomas Wei=C3=9Fschuh wrote: > Hi! >=20 > On 2026-12-06 13:08:03+0000, David Laight wrote: > > On Sat, 5 Dec 2026 15:25:36 +0100 > > Willy Tarreau wrote: =20 > > > On Wed, Dec 02, 2026 at 08:29:48AM +0100, Thomas Wei=C3=9Fschuh wrote= : =20 > > > > Add the fcntl() function. > > > >=20 > > > > Special handling is necessary for 'struct flock'. > > > > The definition from the UAPI headers is not large-file capable. > > > > Provide a custom definition which is compatible with 'struct flock6= 4' > > > > on 32-bit systems and 'struct flock' on 64-bit ones. > > > >=20 > > > > Signed-off-by: Thomas Wei=C3=9Fschuh =20 > > > (...) =20 > > > > --- a/tools/include/nolibc/types.h > > > > +++ b/tools/include/nolibc/types.h > > > > @@ -32,6 +32,21 @@ struct timeval { > > > > #include > > > > #undef timeval > > > > =20 > > > > +struct flock { > > > > + short l_type; > > > > + short l_whence; > > > > + __kernel_loff_t l_start; > > > > + __kernel_loff_t l_len; > > > > + __kernel_pid_t l_pid; > > > > +#if defined(__sparc__) > > > > + short __pad; > > > > +#endif > > > > +}; =20 > > >=20 > > > The commit message makes no mention of this pad and nothing here expl= ains > > > why it is necessary nor if other architectures might need it in the > > > future. I suspect it might be that __kernel_pid_t would be 16-bit the= re, > > > but I really don't know. I think a comment here in front of__pad to s= ay > > > why/when it's needed would help. =20 > >=20 > > My brain remembers something about sparc having an extra field. > > But I can't remember what it was used for, and it was __unused when the > > file was added to Linux for 1.3.44. > > The corresponding types.h has a 32bit pid_t - so it isn't just an > > explicit pad. > > (Although SunOS might have had a 16bit pid and made the pad reasonable.) > >=20 > > I think it also pointless, The size of the structure isn't passed into = the > > kernel (it would need and ioctl() that used IORW()) and the kernel does= n't > > seem to have ever cleared the user field. =20 >=20 > Because the size is not passed into the kernel it is important to have > the padding in the nolibc type. The kernel will read/write as many bytes > as its UAPI definition has. If we leave off the padding member the > kernel will read/write out of bounds. For some reason I was thinking the kernel would only read/write the fields it was going to look at. > This will work most of the time for fcntl(), as the bytes are written as > they were read just before. However it is racy and can break in > wonderous ways if the out of bounds access is in a different mapping. >=20 > We don't care about the MIPS padding/sysid as these are specific to > 32-bit 'struct flock' and there the nolibc 'struct flock' is really > 'struct flock64'. >=20 > I'll add some more explanations for this. >=20 > > It might be relevant if you were compiling against the Linux headers but > > expected to run on some other OS - but that just won't work. > > (SYSV sparc binaries would 'just about' run on SunOS - but it was large= ly > > theoretical and was responsible for some nasty bugs.) =20 >=20 > Nolibc only ever cares about running on Linux. I was thinking more widely and wondering why the pad/unused were added in the first place. David >=20 > > Rather more problematic is MIPS32, change 9f79b8b7 'simplified' the pad. > > But managed to move the l_sysid field the other side of l_pid. =20 >=20 > Indeed. >=20 > (...) >=20 >=20 > Thomas