From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) (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 A5BC63E8C40 for ; Thu, 8 Jan 2026 14:38:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767883088; cv=none; b=GfWxOFMXXPkjWdIwwO7f+LTE0W99iaLe/LTaBHNZhrUuLP7TnrdBVkwxnL1YXENtEA8dTWjiBfC7TU/7q5owq5U/eDJG9vND5y1BcPB5Rj5ASXXouv/ioW+R3xqLJJcJrBKAx6+cGRajYRTyjx1i8EGEIlRnX59RJ/fhJ+hIrQY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767883088; c=relaxed/simple; bh=GmpQwcX3AomhyK8IzIdam8W2T3co9C63wzdOxRK0XH0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Y0hH8R9QW8IMZyUI5nP05TO6kUxafVg2m+dPYACkTot/sWEQ3wZWpXaAmWJu9ZBV0u3v1AHotnrlYnHGi+yWD01x0ZKsKt+m4t/ley9TQ1NUtVIMghmbo/Mbo9D/x/TDpp5oeBYRWsBveW/aX7g0sT6MtKHdD2LngL6zSBrRKSI= 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=LBpMoTH+; arc=none smtp.client-ip=209.85.160.178 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="LBpMoTH+" Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-4ffc5f35b54so5023951cf.0 for ; Thu, 08 Jan 2026 06:38:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1767883085; x=1768487885; 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=9UkPzHJqtD9VgrmurNOGQIfU0hw+eIOkm7oGShw0jyU=; b=LBpMoTH+XOSJw1NjVMYwpajJWEpQvvAdGRG7o7YXDk9HDcdrYV8aIUzLB7XU3V2fxj tRTMKOXbs3pn5Yt4POCi7lY2H19XxxV5nCZRNzi1PUzACFILaLNPaFOPgo+quhz/jO3G QLaLcMwXcuUDj6W1aweV3rVWs+hoICwfEeSI8qOGy1MFIZG0dCfvvFWTmDonJo7IBMni Hi0yer+FzRZi4Je5mEAvVUkanQul1IPHPkvmvNRGGw9DY82MZubkDrhJBK3mikZgNr44 5WIRtboYJUBYCF9jtQrErISdvUxtk2R3KSVjsueAwfq9I5MdR2AowXm1l0PLqaZUWxRt Umxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767883085; x=1768487885; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9UkPzHJqtD9VgrmurNOGQIfU0hw+eIOkm7oGShw0jyU=; b=up0KbAQn7kd8WTjtvaw56syp3eCAVhd7F/asyRvoSCT9151ksFVr+dezz022p4T9uw 2C6zjSccwUEe6/cFpSm8llCM250glfPD37CYqOfbIW1KPZgLd9ryQYPM5Gj1VuNqwgxg bpulM6ZE7y0evJbwJhaA8CJLcsCUi+HR702ofaNQA9N9kH+NADA3B2RZ0p8EfYbSj3Lx 2haaDdjth2GXlvm9WSEiSOW/fPVlrDndvHUmjlaVjdqTY9XObH9CAMmgarRL2FY2AvN9 IThRVta/JftPJpKGa4i5rlC83vu+ydXgTT8sxeiOPbaCLeKgpcHrcdcBqVRURju08dGM 5kFw== X-Forwarded-Encrypted: i=1; AJvYcCUgsRL0Tun3Lp5/v3hybqfaIAvfDJSvc1RipL3nbxjkUnMvlxlVdRnFufp+0t56FVMtD46wOafY9hI91Ys=@vger.kernel.org X-Gm-Message-State: AOJu0YwLPj2KISzE5UfLP6k7mVlEzPUFT3lgih9SkR1ntmS+ojP54uOL TqFSdO+39LkiPcNNSC594TyWyTOiCJlNZA0t14bF8lZcQWHHRcPbppBeaAV7vRWhAaE= X-Gm-Gg: AY/fxX7aaflu83+IJsfhtAUMQ9sjDlNk6Iop+aSqm/fHI/EEzLHGzJ7GSfxnwmDcbgB FohNgb2ZJKjMnXLhQARDJQLxDYwDPZEMYCGu1eDi8EUHhCXLI6aZoOgjcQ4KRUGAEQIRMIhtuG7 uCsFBrdoZZhTxoyHyZDin0DWQ1fmHgiSYmqCQkErkq9Je6r9p+Vy7yPECUoAbXtuPWbbWGdnFDe HSHlSS+HwWS3SMLDf7LKBilDHDyUPrk8gZtNoQE8uiekWr+FOSdNiEvzV/IDxgO/FqdY2ppV+MH 9HXNaNgXg+plrM7aS63fCI4kUrqdOd2dJuoKhOnihAPX9r8kgHENvLiij8eCk0m5jcZIszvp4+l ew0bKxFtHxB2NNNJSrrLyrFC3wvGOpNs8HCFG5Vr8FFmdyJeHsdrKGoifQfAxqL3oA/FUYTUHit cU42na56Jm2+U6eRNkNszfv/DnQVlde5xy6koWf7SJFyuJHRlBRxg+t1CQoTG6EdnpInY= X-Google-Smtp-Source: AGHT+IH8++VROd0tcHeXvIN5iIXsNvVoQ9NVpIio+cuElHEEIvpqUWXZewjuHPXTe96KfUV3OyLsqQ== X-Received: by 2002:a05:622a:1a98:b0:4f1:b9fc:eeda with SMTP id d75a77b69052e-4ffb4920c69mr75280691cf.37.1767883085548; Thu, 08 Jan 2026 06:38:05 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-162-112-119.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.112.119]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4ffa8c00acesm50442131cf.0.2026.01.08.06.38.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jan 2026 06:38:04 -0800 (PST) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1vdr9I-00000002M9N-1rBb; Thu, 08 Jan 2026 10:38:04 -0400 Date: Thu, 8 Jan 2026 10:38:04 -0400 From: Jason Gunthorpe To: Alex Mastro Cc: David Matlack , Alex Williamson , Shuah Khan , Peter Xu , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH] vfio: selftests: Add vfio_dma_mapping_mmio_test Message-ID: <20260108143804.GD545276@ziepe.ca> References: <20260107-scratch-amastro-vfio-dma-mapping-mmio-test-v1-1-0cec5e9ec89b@fb.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=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Jan 07, 2026 at 07:36:44PM -0800, Alex Mastro wrote: > This was inspired by QEMU's hw/vfio/region.c which also does this rounding up > of size to the next power of two [1]. > > I'm now realizing that's only necessary for regions with > VFIO_REGION_INFO_CAP_SPARSE_MMAP where there are multiple mmaps per region, and > each mmap's size is less than the size of the BAR. Here, since we're mapping the > entire BAR which must be pow2, it shouldn't be necessary. You only need to do this dance if you care about having large PTEs under the VMAs, which is probably something worth testing both scenarios. > The intent of QEMU's mmap alignment code is imperfect in the SPARE_MMAP case? > After a hole, the next mmap'able range could be some arbitrary page-aligned > offset into the region. It's not helpful mmap some region offset which is > maximally 4K-aligned at a 1G-aligned vaddr. > > I think to be optimal, QEMU should be attempting to align the vaddr for bar > mmaps such that > > vaddr % {2M,1G} == region_offset % {2M,1G} > > Would love someone to sanity check me on this. Kind of a diversion. What you write is correct. Ankit recently discovered this bug in qemu. It happens not just with SPARSE_MMAP but also when mmmaping around the MSI-X hole.. I also advocated for what you write here that qemu should ensure: vaddr % region_size == region_offset % region_size Until VFIO learns to align its VMAs on its own via Peter's work. Jason