Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp50632lqi; Wed, 6 Mar 2024 09:45:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVCn2PxPvr30Wv+ocqo6sGTSfBYpPF9eMjS7Svka24my3XkrscyB4lVYe0MIGLLMqd9V/t8l4mEy9Mj+vYCPTD48+sfqhDB/0PnTGIZKg== X-Google-Smtp-Source: AGHT+IHl9Er95nDIYfD200WCxYNU2vH6Nb+wNiV9lJz8e3Fb7jxIgy6OK7Esc72Ch6rZBkokCTlf X-Received: by 2002:a05:6a20:7350:b0:1a1:22f1:5ae7 with SMTP id v16-20020a056a20735000b001a122f15ae7mr6706742pzc.30.1709747115885; Wed, 06 Mar 2024 09:45:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709747115; cv=pass; d=google.com; s=arc-20160816; b=LFrI7CSZPgL6bsBUiQZzZGJjgg02QUd1ncpOxt8YeKhPIh8j3h6tbKcVqlq5wdPlOI bTeQ9QyvrfX01oxHDp26fxjDIuixD87R02a5o7VXiLNEdVJrV89vzSDY5Y49UHfTTjJ8 kxGqxbc4p5Q3I2eA+XwdufURb7P4nZ1A2Rq55eO3KAccfi7uP2lodpbW4Bn/LCi+kCp7 y2RPxoZY38ZjsSWx969LUCJGSvM63Xg4QtXABldzGbXZ8i6fa+Z+i22BSlbZInlz0t66 s1enCCFPGra5fzX6m8PCs4qOs8xuHTbZzjadmsSooTSHFJnelDaU0kCESM+gS4pWAlN0 +IZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=FpyRbZ0RdQZQRjC0Rn2UI7ybSBSrjRoc3WCER4LofKQ=; fh=QzBmiPmfDiML0E2LJyGAUsWokAGPNMwj2bU5vNaYBBQ=; b=OEZZ1RLUsygFX/3Uhufl3uZacZNvPna/P20yPuD45lEUX+TjKeZPspZzUbdCkXDSiN HvQU6SDfeXgka00QMyADmzBh4d7F6Konu9yIU6A30i2irnQ+7Lpj+RnfJJlkl29jdEw+ Scww7Owe9tcMSoFSecQrsH1XeMQisDf1Gn+HnhzsjHxGN9JKCfn3hgr3jZ47n4eF5EiH R3/PDmrViVydnywDmJjTuufypsmzlJlG8Lw2KSdAwSq5Kr0mHFbtgil1Lze9rRFyMO1w fAuAG8blBS/X4om4SxtXtnyxonP9txZwghZRx7yqOw+ra+hfVXiFdyqJnSkAQ8Fm7454 0U6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=MzdXd8Lc; arc=pass (i=1 spf=pass spfdomain=ziepe.ca dkim=pass dkdomain=ziepe.ca); spf=pass (google.com: domain of linux-kernel+bounces-94344-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94344-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c10-20020a634e0a000000b005dc891520f0si12072761pgb.272.2024.03.06.09.45.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 09:45:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94344-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=MzdXd8Lc; arc=pass (i=1 spf=pass spfdomain=ziepe.ca dkim=pass dkdomain=ziepe.ca); spf=pass (google.com: domain of linux-kernel+bounces-94344-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94344-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 823C4280D22 for ; Wed, 6 Mar 2024 17:45:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A367C13C9EE; Wed, 6 Mar 2024 17:45:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="MzdXd8Lc" Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (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 01DA71426B for ; Wed, 6 Mar 2024 17:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709747100; cv=none; b=ANZ2H5M81vRUTlpWGbcRtAg4pCAVkHuKHrGD9+tyTuR1ZfwkMYcoYH7y2MDTaOANwNGsra2oZUwWHRGwberXXVV/E1Tyj1VmrDfH/bz5UmQkzaIsSnNbu2WVpdzHgmir0I9xqxpk2kwnuuD3k1pIn3QMJYMeXzcy+S2A4/aAC9I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709747100; c=relaxed/simple; bh=KgEC8zWw55+Acg7UImx7iG13lc0bEoNvPiGpELvl9iU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EbKTi7H4MjniBsT8srEb5AyJhCClfGX8v2wE5VeGo7MzBhgm1yscjF4lOnnJ24CTTAFhazuck/nLK9n+Tp0lPzsC01gYU7KYUSm8z5KpZkoosiu4m+V1xEtdmQuWpw/SyP9hGKM2n4sW0Bn7dBt3E2q9OCR9OKPVusL5Zl+H7Yc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=MzdXd8Lc; arc=none smtp.client-ip=209.85.219.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-69012259657so31255266d6.0 for ; Wed, 06 Mar 2024 09:44:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1709747098; x=1710351898; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=FpyRbZ0RdQZQRjC0Rn2UI7ybSBSrjRoc3WCER4LofKQ=; b=MzdXd8LcU01zr9pHMG00oFxvyTq5As1ywDlryOvXF5Skub+P2KTULXRPxMWl2G9ttK Amy8Ix4bPZpZKYozlIIU0pyBS65CgCMN2La54O1Balib3RVF+HMBWdz5Ss6L1QEGw93J Zef5kI9faBP5Lo53x38XQBXB/oV41Cbgq0l/JqoL1095Y+CnLzGPSvtSKAYsmDbDPpWR KNNxkzTfb4Rfic5BNNI8R8PQ06+v0dDNx/lSdIr0pEkz8dYF/8eA+ixANT3aJEAW5V0F RSsvriiGzNJIkKyxyyw76H3NxHYV6Xoe2gVaAUbvlGjro5t9NqURsx6RqRNbF5MAm+Mc nkJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709747098; x=1710351898; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FpyRbZ0RdQZQRjC0Rn2UI7ybSBSrjRoc3WCER4LofKQ=; b=VPuUicLGo1bkZQ5X96JyUVb8DF3myGDGtbEqx+/aLd3Gav/kWDccqn7bV5+qNvSRhn afb/o+r3mkJo84iK/905ybhHxUJ6omUFRU6TTlbMDc9ixRz4gWHwX0KH0nAzWeGFcDBV 1T0SbY1N1QSG3RxJRqOEQqM2aK9jFEoAMk8VgUdHH1lYVOmcIbwCppiQzaxOA3dPsfMY FcD/aUvJjOBIo2Rc83PL0+uYx3frqYu1E5/sbmJloPvhm7rjC/cC6XB6yUDcCgtI45ir 12B4gKdgJhOUkUmooIRhvYBdAR/L4wbZZW8pVRi/vSr0/3CPGaaDTJeYJ3z8mCgd9pKs ELCg== X-Forwarded-Encrypted: i=1; AJvYcCVg/OGTAbYVI8sqeiSWQ41lMDsUavUpXgqG82jpr5tUX0vJ/4BX5p9KK6aZplsGbtChKHVC0BSoOnwi6nW6fpfFaEKHs7+wswi/Xigk X-Gm-Message-State: AOJu0Yy7lNXKW46A1r0Yd2dffmo3BC6O56zcp24aMdVrn20+Qzv2O1Ih IJ24X4BCq3Bj+jBx7jOIei/l5M3kUjGQjP1hd5U6iLhSG2SEL65mrg2DgfN6WkP6NGK0uqoLJJS h X-Received: by 2002:a05:6214:11b1:b0:690:64e6:33d5 with SMTP id u17-20020a05621411b100b0069064e633d5mr5599360qvv.54.1709747097870; Wed, 06 Mar 2024 09:44:57 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-68-80-239.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.80.239]) by smtp.gmail.com with ESMTPSA id ol17-20020a0562143d1100b006904e2c9e36sm7228573qvb.116.2024.03.06.09.44.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 09:44:57 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1rhvK4-001uSz-88; Wed, 06 Mar 2024 13:44:56 -0400 Date: Wed, 6 Mar 2024 13:44:56 -0400 From: Jason Gunthorpe To: Christoph Hellwig Cc: Leon Romanovsky , Robin Murphy , Marek Szyprowski , Joerg Roedel , Will Deacon , Chaitanya Kulkarni , Jonathan Corbet , Jens Axboe , Keith Busch , Sagi Grimberg , Yishai Hadas , Shameer Kolothum , Kevin Tian , Alex Williamson , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Andrew Morton , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, linux-nvme@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, Bart Van Assche , Damien Le Moal , Amir Goldstein , "josef@toxicpanda.com" , "Martin K. Petersen" , "daniel@iogearbox.net" , Dan Williams , "jack@suse.com" , Zhu Yanjun Subject: Re: [RFC RESEND 00/16] Split IOMMU DMA mapping operation to two steps Message-ID: <20240306174456.GO9225@ziepe.ca> References: <47afacda-3023-4eb7-b227-5f725c3187c2@arm.com> <20240305122935.GB36868@unreal> <20240306144416.GB19711@lst.de> <20240306154328.GM9225@ziepe.ca> <20240306162022.GB28427@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240306162022.GB28427@lst.de> On Wed, Mar 06, 2024 at 05:20:22PM +0100, Christoph Hellwig wrote: > On Wed, Mar 06, 2024 at 11:43:28AM -0400, Jason Gunthorpe wrote: > > I don't think they are so fundamentally different, at least in our > > past conversations I never came out with the idea we should burden the > > driver with two different flows based on what kind of alignment the > > transfer happens to have. > > Then we talked past each other.. Well, we never talked to such detail > > > So if we want to efficiently be able to handle these cases we need > > > two APIs in the driver and a good framework to switch between them. > > > > But, what does the non-page-aligned version look like? Doesn't it > > still look basically like this? > > I'd just rather have the non-aligned case for those who really need > it be the loop over map single region that is needed for the direct > mapping anyway. There is a list of interesting cases this has to cover: 1. Direct map. No dma_addr_t at unmap, multiple HW SGLs 2. IOMMU aligned map, no P2P. Only IOVA range at unmap, single HW SGLs 3. IOMMU aligned map, P2P. Only IOVA range at unmap, multiple HW SGLs 4. swiotlb single range. Only IOVA range at unmap, single HW SGL 5. swiotlb multi-range. All dma_addr_t's at unmap, multiple HW SGLs. 6. Unaligned IOMMU. Only IOVA range at unmap, multiple HW SGLs I think we agree that 1 and 2 should be optimized highly as they are the common case. That mainly means no dma_addr_t storage in either 5 is the slowest and has the most overhead. 4 is basically the same as 2 from the driver's viewpoint 3 is quite similar to 1, but it has the IOVA range at unmap. 6 doesn't have to be optimal, from the driver perspective it can be like 5 That is three basic driver flows 1/3, 2/4 and 5/6 So are you thinking something more like a driver flow of: .. extent IO and get # aligned pages and know if there is P2P .. dma_init_io(state, num_pages, p2p_flag) if (dma_io_single_range(state)) { // #2, #4 for each io() dma_link_aligned_pages(state, io range) hw_sgl = (state->iova, state->len) } else { // #1, #3, #5, #6 hw_sgls = alloc_hw_sgls(num_ios) if (dma_io_needs_dma_addr_unmap(state)) dma_addr_storage = alloc_num_ios(); // #5 only for each io() hw_sgl[i] = dma_map_single(state, io range) if (dma_addr_storage) dma_addr_storage[i] = hw_sgl[i]; // #5 only } ? This is not quite what you said, we split the driver flow based on needing 1 HW SGL vs need many HW SGL. > > So are they really so different to want different APIs? That strikes > > me as a big driver cost. > > To not have to store a dma_address range per CPU range that doesn't > actually get used at all. Right, that is a nice optimization we should reach for. Jason