Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1287934lqz; Mon, 1 Apr 2024 00:56:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV0KW/KwTSq+/38tNNfNDS/gvJPfE1NNa6UuJfFqkON+vUJvNhVcpLgX0gBD+6u/ZW6L/iy7G6t4GUlg5IY9az0HnDh59oJI8z/EATBKg== X-Google-Smtp-Source: AGHT+IF02A8lz/3g2PjRNxqP9J8hzrk6nZiGeIT95MXhydWulfnKxF9uem9lWxK0Gf4cLFRpiZuR X-Received: by 2002:a50:a6dc:0:b0:56c:59d4:6c5e with SMTP id f28-20020a50a6dc000000b0056c59d46c5emr5850441edc.7.1711958187262; Mon, 01 Apr 2024 00:56:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711958187; cv=pass; d=google.com; s=arc-20160816; b=07auu8xeuNWOWi4IFlrFkLYrxDIW/1ZUTt3XiydaWczXrymtdjojEwCpJA1b/upU/U E2UspBPzqvvKhsLA+zsyLKPwAav8/sUYVReYqDNocPRO4vL7mzb8qWg+zwk+3eJG8e1s UlrcF+CR4jc3vNBOtxBHb7+OQUXVwMc/avHef1ZcDQg1+9KR10CpjTUEc2HRGxt8dpE5 nHj5fKq4qOq0uUtfw92yQl41QC8+i7gQ6933YZ6TQskSCLXG8ATL+MpYwGEsrj6O9jTd QxFhsFN1olajuQIPP9+JrEeKoCmoeY4eOV26GG+EGxmGBovtABzltH0YqvZJTaHFRXNy tkag== 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=3/bmRW0RZrolxTvrm8LcMiQ+wRa4Ya61rnM0CmvyhhU=; fh=jnJ7RmQ8pe8wy5TECryzV8Aj4OuahZwKbxsvmnHevMk=; b=mAdnAkFll1Vek6o/gTh68xj58cGMKe+aAg0YBeN7gI/up9F9YEAroMeASm0WhDGs/d 9MbBLiPrCd/gR+ky/VfRd4GKXYAuOh8idAeFlSjwZsSeGA04Xc+YZzStRoD2KtsmlSEM hqvQI8dOr3Kz7glvi1wP5/W4Bga106Gvv6do2hKpFjnPwZuky3DFEcT0m7I09xvrdC3h A8KSmAuRdfkTPTLu4cFz4MPuTCcNdl4zlqAFw1RgS3V2v7PsVQETcnKsgXTljA15JNIJ foV42nzMPcEH67t6rRYQKeRK3+nffQGYXfPUs5IAsDU+pqpE71c49D1ts/o4sj8ki7HH oLKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@atmark-techno.com header.s=google header.b=awqdFPRm; arc=pass (i=1 spf=pass spfdomain=atmark-techno.com dkim=pass dkdomain=atmark-techno.com dmarc=pass fromdomain=atmark-techno.com); spf=pass (google.com: domain of linux-kernel+bounces-126504-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-126504-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=atmark-techno.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 17-20020a508e51000000b00567e266a464si4333213edx.605.2024.04.01.00.56.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 00:56:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-126504-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@atmark-techno.com header.s=google header.b=awqdFPRm; arc=pass (i=1 spf=pass spfdomain=atmark-techno.com dkim=pass dkdomain=atmark-techno.com dmarc=pass fromdomain=atmark-techno.com); spf=pass (google.com: domain of linux-kernel+bounces-126504-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-126504-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=atmark-techno.com 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 CC65D1F215ED for ; Mon, 1 Apr 2024 07:56:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70B29BE49; Mon, 1 Apr 2024 07:56:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=atmark-techno.com header.i=@atmark-techno.com header.b="awqdFPRm" Received: from gw2.atmark-techno.com (gw2.atmark-techno.com [35.74.137.57]) (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 ED9398F6E for ; Mon, 1 Apr 2024 07:56:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.74.137.57 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711958177; cv=none; b=M8xH0tvvDcUomApLdL5iePvDPS/7XXlu9pDeVVvMaHWFkR5gBm6mREyOdmCg9qkjnQZ6Cf7KkwK403S1uCzb51lbcF4caEbR/Dyj2GXWpBQevSi2g3cp4+6SQ2eJpChtM27M58Pn/Ox7NaXJby9LgBGaJEaBqHGJDj3Z5F/BwOQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711958177; c=relaxed/simple; bh=cgdtpYyjvErlX+/utjCkRaIwVeHPHbXHGies5CxxI0o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eXK4Yr5Kx+XxSLi5CYutWtSMkHmC8SXJ6VqqS4WJ8hemr7xCkxJN82C7hl2JIhfzdu90NVcc5Rpjr1CzVmRcwh/GdSzDIerUbhUawPsVGvo+oUDR3jYJoi+UOOdOFLFU/4TOftKsQ0o30gtyu9eLaUNHrVT18ijujCPQZ25G9Og= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=atmark-techno.com; spf=pass smtp.mailfrom=atmark-techno.com; dkim=pass (2048-bit key) header.d=atmark-techno.com header.i=@atmark-techno.com header.b=awqdFPRm; arc=none smtp.client-ip=35.74.137.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=atmark-techno.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=atmark-techno.com Authentication-Results: gw2.atmark-techno.com; dkim=pass (2048-bit key; unprotected) header.d=atmark-techno.com header.i=@atmark-techno.com header.a=rsa-sha256 header.s=google header.b=awqdFPRm; dkim-atps=neutral Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by gw2.atmark-techno.com (Postfix) with ESMTPS id E36E8276 for ; Mon, 1 Apr 2024 16:56:08 +0900 (JST) Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-29e06733018so2921446a91.0 for ; Mon, 01 Apr 2024 00:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atmark-techno.com; s=google; t=1711958168; x=1712562968; 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=3/bmRW0RZrolxTvrm8LcMiQ+wRa4Ya61rnM0CmvyhhU=; b=awqdFPRmjnk/7pZsDYheI/wAwmIlIku6xWWT6OweYbwOWfz/DJPm9Pjttl7M/H4FIB mPMAtocOtu5+jWv4j6Qo0hZKV9ipugOch+Av7NJZr3WqGErAqYS0Bsd41JPIsNmk59Gz LBbDdmTtJLFmU9KE3GB1Sh8SzToK9E2zT0fUYv30ZG4qKtLKuKRaR1mC0t+8eQMBKico OAFWLA++VPztpYUU0X7m6LeqLCXKM8vLpFZCyROz7jFqXcGCpoBtD1nKAWpw7mSGJTye gzFbwqIKDwZBxgeFXTLV6qL+7sV94QJ6eEgLPyDbnIaM/YJLPQa4ESOOm8kHamd5WVRk 2ieA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711958168; x=1712562968; 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=3/bmRW0RZrolxTvrm8LcMiQ+wRa4Ya61rnM0CmvyhhU=; b=w+BiQ2nnCNQvUXvkW9dMC81m8qRqMX4MeEmFavuumIQ+tW1dQXrVJr8pgJQPypQS+w /JBkj0y24+CHJRmUm/kJAdh/6JI4qWr0SSSkG2/1EGYtyYDctJfX0S+qeSQFrk4thXgZ FNCEoejaAOdIsVxFJv2IeJLIh+H8afBjUi/Bgm+sFEQJSRfzhJQ5xtAEVYGBIUzMerva BcnbaX1fZP5EVq1B1GoOpAfeKqJ4Fer9WIka2Wzd8wZpK3ppHrfPUDoIvQCXA8hnpo5U tI7gxWsxj61hSXdExMjRa+ffA2U35uVJjBxaC9FG7KKi8qsPHKhleRzOCrF/5R7WtD3W 5fBA== X-Forwarded-Encrypted: i=1; AJvYcCWk5iOWktS+65Opru238leQjPIb59AQY292PcJFiFse+x5hGpoY3FGkUkkjFY/AA2PE6alXvCtYUofwhKr0jQMxVpTDgur8xWNNKKkP X-Gm-Message-State: AOJu0Yz9JXM6AGuYcAsJo+aTOwhb1FA6aD7+gXG6BhWdcL06Z8vHCbkf 90lvFT++tbzUOK6wFytsRCM6bAP9l2dADa8uPquuhTivp09LxKmrMoQ4hfnZ9JJbIH+B/C09VCF eGfqmLJiTT5VMSGgQEFCUFHDP8wU8+Aziji+nw6XW87CSJGpjuISj4D4R0qnBj/M= X-Received: by 2002:a17:90b:4c05:b0:2a2:434a:e644 with SMTP id na5-20020a17090b4c0500b002a2434ae644mr739028pjb.25.1711958167648; Mon, 01 Apr 2024 00:56:07 -0700 (PDT) X-Received: by 2002:a17:90b:4c05:b0:2a2:434a:e644 with SMTP id na5-20020a17090b4c0500b002a2434ae644mr739009pjb.25.1711958167223; Mon, 01 Apr 2024 00:56:07 -0700 (PDT) Received: from pc-0182.atmarktech (35.112.198.104.bc.googleusercontent.com. [104.198.112.35]) by smtp.gmail.com with ESMTPSA id ev9-20020a17090aeac900b002a03d13fef5sm9414600pjb.7.2024.04.01.00.56.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Apr 2024 00:56:06 -0700 (PDT) Received: from martinet by pc-0182.atmarktech with local (Exim 4.96) (envelope-from ) id 1rrCWT-00D2zY-1h; Mon, 01 Apr 2024 16:56:05 +0900 Date: Mon, 1 Apr 2024 16:55:55 +0900 From: Dominique Martinet To: Michael Kelley Cc: "hch@lst.de" , "m.szyprowski@samsung.com" , "robin.murphy@arm.com" , "konrad.wilk@oracle.com" , "bumyong.lee@samsung.com" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "will@kernel.org" , "petr@tesarici.cz" , "roberto.sassu@huaweicloud.com" , "lukas@mntmn.com" Subject: Re: [PATCH 1/1] swiotlb: Fix swiotlb_bounce() to do partial sync's correctly Message-ID: References: <20240327034548.1959-1-mhklinux@outlook.com> 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=utf-8 Content-Disposition: inline In-Reply-To: Michael Kelley wrote on Sat, Mar 30, 2024 at 04:16:30AM +0000: > From: Dominique Martinet Sent: Friday, March 29, 2024 7:56 PM > > There are two things I don't understand here: > > 1/ Why orig_addr would come from slot[1] ? > > > > We have index = (tlb_addr - mem->start) >> IO_TLB_SHIFT, > > so index = (33 - 7) >> 5 = 26 >> 5 = 0 > > > > As such, orig_addr = mem->slots[0].orig_addr and we'd need the offset to > > be 30, not -2 ? > > mem->start is the physical address of the global pool of > memory allocated for swiotlb buffers. Argh. Okay, that clears up a misunderstanding I've had since day one... I should have done a little more reading there. I've re-checked now and indeed mem->start comes from the pool init, and corresponds to the reserved memory base. (I'm not actually 100% sure reserved memory has to be aligned, but at the very least I've never seen any that isn't on my hardware so I'll pretend it must be without checking) That makes much more sense with your fix, I agree offset must be negative in that case, and it'll work out. > > Well, either work - if we fix index to point to the next slot in the > > negative case that's also acceptable if we're sure it's valid, but I'm > > worried it might not be in cases there was only one slot e.g. mapping > > [7; 34] and calling with 33 size 2 would try to access slot 1 with a > > negative offset in your example, but slot[0] is the last valid slot. > > Right, but there wouldn't be one slot mapping [7; 34] if the > alignment rules are followed when the global swiotlb memory > pool is originally created. The low order IO_TLB_SHIFT bits > of slot physical addresses must be zero for the arithmetic > using shifts to work, so [7; 34] will cross a slot boundary and > two slots are needed. Yes, since the mem->start/slots belongs to the pool and not the mapping this didn't make sense either; there's no problem here. > > 2/ Why is orig_addr 37 the correct address to use for memcpy, and not > > 33? I'd think it's off by a "minimum alignment page", for me this > > computation only works if the dma_get_min_align size is bigger than io > > tlb size. > > The swiotlb mapping operation establishes a pair-wise mapping between > an orig_addr and tlb_addr, with the mapping extending for a specified > number of bytes. Your example started with orig_addr = 7, and I > posited that the mapping extends for 40 bytes. Sure. > I further posited that the tlb_addr returned by > swiotlb_tbl_map_single() would be 3 to meet the min alignment > requirement (which again only works if mem->start is 0). Okay that's where I'm lost. 1/ I agree that swiotlb_bounce() called from swiotlb_tbl_map_single() cannot be called with a tlb_addr past a single segment (which I'm not sure is acceptable in itself, taking the real value of 2KB for io tlb "pages", if the device requires 512 bytes alignment you won't be able to access [512-2048[ ?) 2/ swiotlb_bounce() can be called from swiotlb_sync_single_for_device() or swiotlb_sync_single_for_cpu() with no alignment check on tlb_addr, we're just trusting that they only ever pass address within the same constraint ? If you assume tlb addr can only go from the start of a slot to as far as the min alignment allows then I agree there's no more problem, but I don't understand where that comes from. Either way, that's not a new problem, and the old checks aren't making this any better so as far as I'm concerned this patch is Progress: Reviewed-by: Dominique Martinet Thanks for taking me by the hand here; if you want to keep discussing this I'll be happy to give it a little bit more time but I might be a little bit slower. -- Dominique