Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1368071lqh; Mon, 6 May 2024 05:58:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU0cueKhVt2berEka/gUrrrtOd/Gbuwik28JNN95FO41IHvqW0nQdkA9K6iJcJUD6+oaX0foCxzjj4ggnq5MNGLaLWLrYGqngz6Zc3+hg== X-Google-Smtp-Source: AGHT+IHBVTjPFvqqNuvQd5ymiRh8WDTEaQjBZJ/BRnY7xIvCiPOrjejTwHPwKn0mzJ2fmxGA1hg1 X-Received: by 2002:a50:9e47:0:b0:56e:2abd:d00f with SMTP id z65-20020a509e47000000b0056e2abdd00fmr7027367ede.18.1715000292226; Mon, 06 May 2024 05:58:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715000292; cv=pass; d=google.com; s=arc-20160816; b=xqXXnFTQDcNLjcvL75EfTiGDIY5RpO8RCmxTKrEzeadvl5jRLyYo9K+gcDhOPK3xiC oycP1WlxMNZ7Mc0i8qGc5aLPC7VyQJeVyEh+lAdgcyfQNp9WQYo2wo3jnfeLcTBBTB2m i4ZzoYySLTXSBWiSvmo95Vqm3bf371iJ44Ef1h979SkirsTxv6g/egT0S1I3sPxSGdEK jKJ6eeuvPZ1/YvdFuWcp011y8nvkO4AvjPPxPEG0iYPdo5Vijhqk3+cEhK7QZ8aOfydN U62jgp2UmCeZrKSP7wzN1NaUqFX0FYI756MwOiyygqxOo/srqEOYgSOUuF8NnDFw5vV0 VL3A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=nMciShd0EGYC7XDcTrn2YNrkROd7Rswy9QEQRWNAjUM=; fh=ubNy2YSY+/mEfuu0lj0Lld0/Px7h/IPggJvZPxZlptk=; b=W+4LXqbV2NCB2onPQjZMBi/ioCNfoVPtzSu8y1pAOcLxRYhkxVFA4rMJyofzv1+b/t 4jotA0JLePWXd9li5//kvnKkBp2i4yyJ8jwq6PaQUesa9PlaiJAK/z47UZ73pybyCtX+ bYoE6M/TM1Vra0Ya8LFKRlAEWemCKTuxWgGZYYmVYzr+GliuHZuNMLCfqBi/E1GXCBG9 3CIbkHdSDG5uTd4mf/KtZazMhvT/FGnfPFjJWEE049T0SnUms/ceilKxV6//OxyyK7sc kTDdvKD8uuq75xv3ADNJhxtl0EW3huL+AV5OcB7r5ps+9bZ2juNnE80uobhvEu7HxjCF 6yAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=NVCEXrDK; arc=pass (i=1 spf=pass spfdomain=kernel.dk dkim=pass dkdomain=kernel-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-169855-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169855-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f10-20020a056402160a00b00572b900fb4asi4955874edv.391.2024.05.06.05.58.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 05:58:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169855-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=NVCEXrDK; arc=pass (i=1 spf=pass spfdomain=kernel.dk dkim=pass dkdomain=kernel-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-169855-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169855-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 6A47D1F24425 for ; Mon, 6 May 2024 12:57:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 011146D1BB; Mon, 6 May 2024 12:57:51 +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="NVCEXrDK" Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (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 7DEF943687 for ; Mon, 6 May 2024 12:57:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715000270; cv=none; b=nr4RxG5W/9G7pmdZZB5rFQIJeg6k4/9PaBHPzcFNgsYhG78/7hbyKGKC9KNta52jha/tlYiom7RvTOMV6wmuTKwcQjrV0F37XVORsnDHJi86SPTRIxpVXuS3Wq9K6KEBpnvT4HApCMzELxqQuJq7VmOA8cx8sv/CRXTVPgsBLGI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715000270; c=relaxed/simple; bh=UsBddcet5Sd4zyP9X920l8bRMzFSxcgmySjLBhYkM0c=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=qnLeAc9yhNlTgX1XmcWmcykH68tJ11o+AqLnqoxbPJPY3dfD3LOHIVMHFOEFJQtBhm+MAtheAmlNlg4AGmrTfKz8xyt4qQTwIq51sh0pvcsehycW4+mxFAH+SO4UcOqryWOjBbNUKIA4VZjeRiz9FoRz3ucgvPdimbLXJfBYDcM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=NVCEXrDK; arc=none smtp.client-ip=209.85.161.49 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-oo1-f49.google.com with SMTP id 006d021491bc7-5acdbfa7a45so646577eaf.2 for ; Mon, 06 May 2024 05:57:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1715000266; x=1715605066; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=nMciShd0EGYC7XDcTrn2YNrkROd7Rswy9QEQRWNAjUM=; b=NVCEXrDKTUkIuOCgrmgGGD5CuP2Eij/BIo8wwbA8G+VlhtrKjkxwVdUDVYCvRmrvfN w1dCBueomJ0PoqYxgtVto0zW2tnbPWTOdVQpTxOHrditzFV9CuWfUPbO6l5cgIdvqcb/ KXNoYBV6zpS+iGOjfiN7RDZzyG9EmJM6I1hejS1/1GMttki27x2lGCVOFEj0I29KZ6r8 bGJNLSOC2mqzTe5Kb2zWiYZMRi7Ws9F7QEcEcrue7OiKy5aQXUzGqdgIUHY2s2Ty8RWC cxJJn6IGDHN3RRfuw0uxrKx5yEag9uhFxmAUk896yoXkXONtz7ns4xxN2QPcys89co+8 vZ8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715000266; x=1715605066; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nMciShd0EGYC7XDcTrn2YNrkROd7Rswy9QEQRWNAjUM=; b=ShUdslRJ113qToIF6ZCux6rBSubiqYa5A9eqxZNRJtZiqF8zCjG7VofsGgnt1JiAu2 yF1C0TivuN9qQHlCTpHZwxX3rTT8TmaSl1BAB1W9pXeTms3Fi8bIxz+bLouJrqnAJZSw CSp3WhuN2hJDLtu5ALp4BnxswomZriTUnARVdnFhNSEL5YvbpIwbDZi2KDdsQiFvVzJ8 UxJWqnfAQ3J5eyMSuowVw1R+fN1IrUvFinyvyfN6ZMCryD1XNM57ZBxKbNJkZKOKmWyn geFBLdyl5upHG3t7/lulBX7Qs4KwvqhYPSlc3jsg9PMdqxjkxoctta7hGKN+8BoyfjER 9X+w== X-Forwarded-Encrypted: i=1; AJvYcCUgEfOT0cpYdAHS731dypEB5BBSxF2/WD51O0XKeK+gBGiysCqghbUFI4RogkHGAI8qaJKiT0QVYPSPnMmYKwyOyZMNItSy1oO8eFfg X-Gm-Message-State: AOJu0Yz1qhWNnBb3bpr84jYUnM9R0AIG7mjUSsM+H2ON+liuvIuqc77z FwaldwzDagGg2iYNTtTuPHGwsL8lECyRfPKNB1cI8fmn/qt7QT3+vfPRXKdOl5M= X-Received: by 2002:a05:6870:b4a7:b0:23c:9036:1f61 with SMTP id y39-20020a056870b4a700b0023c90361f61mr12457322oap.1.1715000266357; Mon, 06 May 2024 05:57:46 -0700 (PDT) Received: from [192.168.1.150] ([198.8.77.194]) by smtp.gmail.com with ESMTPSA id g9-20020aa79dc9000000b006eae2d9298esm7596322pfq.194.2024.05.06.05.57.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 May 2024 05:57:45 -0700 (PDT) Message-ID: <71c1f01f-f740-43b0-9962-afcf08cab686@kernel.dk> Date: Mon, 6 May 2024 06:57:44 -0600 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] io_uring/rsrc: Add support for multi-folio buffer coalescing To: Chenliang Li , asml.silence@gmail.com Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, peiwei.li@samsung.com, joshi.k@samsung.com, kundan.kumar@samsung.com, gost.dev@samsung.com References: <20240506075303.25630-1-cliang01.li@samsung.com> Content-Language: en-US From: Jens Axboe In-Reply-To: <20240506075303.25630-1-cliang01.li@samsung.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 5/6/24 1:53 AM, Chenliang Li wrote: > Currently fixed buffers consisting of pages in one same folio(huge page) > can be coalesced into a single bvec entry at registration. > This patch expands it to support coalescing fixed buffers > with multiple folios, by: > 1. Add a helper function and a helper struct to do the coalescing work > at buffer registration; > 2. Add the bvec setup procedure of the coalsced path; coalesced > 3. store page_mask and page_shift into io_mapped_ubuf for > later use in io_import_fixed. Can you add some justification to this commit message? A good commit message should basically be the WHY of why this commit exists in the first place. Your commit message just explains what the patch does, which I can just read the code to see for myself. As it stands, it's not clear to me or anyone casually reading this commit message why the change is being done in the first place. Outside of that, you probably want to split this into two parts - one that adds the helper for the existing code, then one that modifies it for your change. We need this to be as simple as possible to review, as we've had a security issue with page coalescing in this code in the past. Minor comments below, will wait with a full review until this is split to be more easily reviewable. > +/* > + * For coalesce to work, a buffer must be one or multiple > + * folios, all the folios except the first and last one > + * should be of the same size. > + */ > +static bool io_sqe_buffer_try_coalesce(struct page **pages, > + unsigned int nr_pages, > + struct io_imu_folio_stats *stats) > +{ > + struct folio *folio = NULL, *first_folio = NULL; > + unsigned int page_cnt; > + int i, j; Please don't make up your own style, follow the style that's already in the file to begin with. > diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h > index c032ca3436ca..4c655e446150 100644 > --- a/io_uring/rsrc.h > +++ b/io_uring/rsrc.h > @@ -47,9 +47,18 @@ struct io_mapped_ubuf { > u64 ubuf_end; > unsigned int nr_bvecs; > unsigned long acct_pages; > + unsigned int page_shift; > + unsigned long page_mask; > struct bio_vec bvec[] __counted_by(nr_bvecs); > }; When adding members to a struct, please be cognizant of how it packs. I'd suggest making the above: u64 ubuf_end; unsigned int nr_bvecs; unsigned int page_shift; unsigned long page_mask; unsigned long acct_pages; struct bio_vec bvec[] __counted_by(nr_bvecs); which should pack much nicer and actually save memory. -- Jens Axboe