From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-175.mta0.migadu.com (out-175.mta0.migadu.com [91.218.175.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80A7762171 for ; Wed, 5 Jun 2024 05:27:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717565249; cv=none; b=EDcNcA0X9TMcM9c+1G4n+UJh8CtL/mWuNL8dT0XL+a7o42AotmyDLXqRoiaDvpKmeXlGA2vPFJa979cOUGPxT9Y+COZYROCcYvFwQRr8GpAa/W9urgwx/xZY3c1UU3Yl54YfVza2Q9OEa2WHvLi7nqkpANL7xNmEIYxepGhsBU8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717565249; c=relaxed/simple; bh=lUdXT4EJDwyLEOyQQYwaIlJR/WnTCbQVQ6FitFIjdIk=; h=Content-Type:Message-ID:Date:MIME-Version:Subject:To:References: From:In-Reply-To; b=KSDuxOUyveMY9Akuwj+dzA3eVc5Lw3iNkb1i9XYMqkGKTdzLKMGamqLX9unUYnF+Qvpk8BSRXQN+/nfrDwb8Y2dGlRLfqMwxP+B16AqhEiuPdXYQTV3K9U7Q31oC1vFh4qrh/pk5rDK19oFfQbHoVvac/ZypeG458GH/dKhaMns= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=s.muenzel.net; spf=pass smtp.mailfrom=s.muenzel.net; dkim=pass (1024-bit key) header.d=s.muenzel.net header.i=@s.muenzel.net header.b=ceGhlh77; arc=none smtp.client-ip=91.218.175.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=s.muenzel.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=s.muenzel.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=s.muenzel.net header.i=@s.muenzel.net header.b="ceGhlh77" X-Envelope-To: axboe@kernel.dk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=s.muenzel.net; s=default; t=1717565241; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Fr2oooiX9HIo6N1auZF4belPhJceqqVdLR+t5eMXAV0=; b=ceGhlh77tsw5Awlr6x4WoSdKigvOHz6YDEIzfQF5henvbLBCs+5odExBRBZUyk3ui1eH/d 6jj5cUDs08gMS45Sep4E/rDEqEemJ+igcjXGqe3p3XBBYTUDBjUOLxqDx06vKPN5iBEIka 5vm5OSJeZbpdAqVYQn5jFF5fb3DGofQ= X-Envelope-To: io-uring@vger.kernel.org Content-Type: multipart/mixed; boundary="------------7VXEky8tSqLP2K0dHE4epZRr" Message-ID: <0817a90d-7c0b-4a70-85f0-06537dd8e54b@s.muenzel.net> Date: Wed, 5 Jun 2024 07:25:16 +0200 Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: madvise/fadvise 32-bit length To: Jens Axboe , io-uring@vger.kernel.org References: <2d4d3434-401c-42c2-b450-40dec4689797@kernel.dk> <8b08398d-a66d-42ad-a776-78b52d5231c4@s.muenzel.net> <70ac49de-f753-486f-b68e-60f08c652195@kernel.dk> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Stefan In-Reply-To: <70ac49de-f753-486f-b68e-60f08c652195@kernel.dk> X-Migadu-Flow: FLOW_OUT This is a multi-part message in MIME format. --------------7VXEky8tSqLP2K0dHE4epZRr Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/6/2024 16:49, Jens Axboe wrote: > On 6/2/24 2:58 AM, Stefan wrote: >> On 1/6/2024 20:33, Jens Axboe wrote: >>> On 6/1/24 9:51 AM, Stefan wrote: >>>> On 1/6/2024 17:35, Jens Axboe wrote: >>>>> On 6/1/24 9:22 AM, Stefan wrote: >>>>>> On 1/6/2024 17:05, Jens Axboe wrote: >>>>>>> On 6/1/24 8:19 AM, Jens Axboe wrote: >>>>>>>> On 6/1/24 3:43 AM, Stefan wrote: >>>>>>>>> io_uring uses the __u32 len field in order to pass the length to >>>>>>>>> madvise and fadvise, but these calls use an off_t, which is 64bit on >>>>>>>>> 64bit platforms. >>>>>>>>> >>>>>>>>> When using liburing, the length is silently truncated to 32bits (so >>>>>>>>> 8GB length would become zero, which has a different meaning of "until >>>>>>>>> the end of the file" for fadvise). >>>>>>>>> >>>>>>>>> If my understanding is correct, we could fix this by introducing new >>>>>>>>> operations MADVISE64 and FADVISE64, which use the addr3 field instead >>>>>>>>> of the length field for length. >>>>>>>> >>>>>>>> We probably just want to introduce a flag and ensure that older stable >>>>>>>> kernels check it, and then use a 64-bit field for it when the flag is >>>>>>>> set. >>>>>>> >>>>>>> I think this should do it on the kernel side, as we already check these >>>>>>> fields and return -EINVAL as needed. Should also be trivial to backport. >>>>>>> Totally untested... Might want a FEAT flag for this, or something where >>>>>>> it's detectable, to make the liburing change straight forward. >>>>>>> >>>>>>> >>>>>>> diff --git a/io_uring/advise.c b/io_uring/advise.c >>>>>>> index 7085804c513c..cb7b881665e5 100644 >>>>>>> --- a/io_uring/advise.c >>>>>>> +++ b/io_uring/advise.c >>>>>>> @@ -17,14 +17,14 @@ >>>>>>> struct io_fadvise { >>>>>>> struct file *file; >>>>>>> u64 offset; >>>>>>> - u32 len; >>>>>>> + u64 len; >>>>>>> u32 advice; >>>>>>> }; >>>>>>> struct io_madvise { >>>>>>> struct file *file; >>>>>>> u64 addr; >>>>>>> - u32 len; >>>>>>> + u64 len; >>>>>>> u32 advice; >>>>>>> }; >>>>>>> @@ -33,11 +33,13 @@ int io_madvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) >>>>>>> #if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU) >>>>>>> struct io_madvise *ma = io_kiocb_to_cmd(req, struct io_madvise); >>>>>>> - if (sqe->buf_index || sqe->off || sqe->splice_fd_in) >>>>>>> + if (sqe->buf_index || sqe->splice_fd_in) >>>>>>> return -EINVAL; >>>>>>> ma->addr = READ_ONCE(sqe->addr); >>>>>>> - ma->len = READ_ONCE(sqe->len); >>>>>>> + ma->len = READ_ONCE(sqe->off); >>>>>>> + if (!ma->len) >>>>>>> + ma->len = READ_ONCE(sqe->len); >>>>>>> ma->advice = READ_ONCE(sqe->fadvise_advice); >>>>>>> req->flags |= REQ_F_FORCE_ASYNC; >>>>>>> return 0; >>>>>>> @@ -78,11 +80,13 @@ int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) >>>>>>> { >>>>>>> struct io_fadvise *fa = io_kiocb_to_cmd(req, struct io_fadvise); >>>>>>> - if (sqe->buf_index || sqe->addr || sqe->splice_fd_in) >>>>>>> + if (sqe->buf_index || sqe->splice_fd_in) >>>>>>> return -EINVAL; >>>>>>> fa->offset = READ_ONCE(sqe->off); >>>>>>> - fa->len = READ_ONCE(sqe->len); >>>>>>> + fa->len = READ_ONCE(sqe->addr); >>>>>>> + if (!fa->len) >>>>>>> + fa->len = READ_ONCE(sqe->len); >>>>>>> fa->advice = READ_ONCE(sqe->fadvise_advice); >>>>>>> if (io_fadvise_force_async(fa)) >>>>>>> req->flags |= REQ_F_FORCE_ASYNC; >>>>>>> >>>>>> >>>>>> >>>>>> If we want to have the length in the same field in both *ADVISE >>>>>> operations, we can put a flag in splice_fd_in/optlen. >>>>> >>>>> I don't think that part matters that much. >>>>> >>>>>> Maybe the explicit flag is a bit clearer for users of the API >>>>>> compared to the implicit flag when setting sqe->len to zero? >>>>> >>>>> We could go either way. The unused fields returning -EINVAL if set right >>>>> now can serve as the flag field - if you have it set, then that is your >>>>> length. If not, then the old style is the length. That's the approach I >>>>> took, rather than add an explicit flag to it. Existing users that would >>>>> set the 64-bit length fields would get -EINVAL already. And since the >>>>> normal flags field is already used for advice flags, I'd prefer just >>>>> using the existing 64-bit zero fields for it rather than add a flag in >>>>> an odd location. Would also make for an easier backport to stable. >>>>> >>>>> But don't feel that strongly about that part. >>>>> >>>>> Attached kernel patch with FEAT added, and liburing patch with 64 >>>>> versions added. >>>>> >>>> >>>> Sounds good! >>>> Do we want to do anything about the current (32-bit) functions in >>>> liburing? They silently truncate the user's values, so either marking >>>> them deprecated or changing the type of length in the arguments to a >>>> __u32 could help. >>> >>> I like changing it to an __u32, and then we'll add a note to the man >>> page for them as well (with references to the 64-bit variants). >>> >>> I still need to write a test and actually test the patches, but I'll get >>> to that Monday. If you want to write a test case that checks the 64-bit >>> range, then please do! >>> >> >> Maybe something like the following for madvise? >> Create an 8GB file initialized with 0xaa, punch a (8GB - page_size) >> hole using MADV_REMOVE, and check the contents. It requires support >> for FALLOC_FL_PUNCH_HOLE in the filesystem. > > I think that looks very reasonable, and it's better than the DONTNEED > and timings, it was always a pretty shitty test. We just need to ensure > that we return T_EXIT_SKIP if the fs it's being run on doesn't support > punching holes. > > FWIW, I did put the liburing changes in an 'advise' branch, so you could > generate a patch against that. Once we're happy with it, it can get > pulled into master. > Here's the patch against your branch. --------------7VXEky8tSqLP2K0dHE4epZRr Content-Type: text/x-patch; charset=UTF-8; name="0001-Change-madvise-test-to-use-MADV_REMOVE.patch" Content-Disposition: attachment; filename="0001-Change-madvise-test-to-use-MADV_REMOVE.patch" Content-Transfer-Encoding: base64 RnJvbSAxNTcwY2ZkYzQ5NGM5ZjM4YmFjODRmN2ZjODM3ZjY5Zjk5ODg4YWMwIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBTdGVmYW4gTXVlbnplbCA8c291cmNlQHMubXVlbnpl bC5uZXQ+CkRhdGU6IE1vbiwgMyBKdW4gMjAyNCAxODo0MDoyNyArMDIwMApTdWJqZWN0OiBb UEFUQ0hdIENoYW5n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