From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.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 008CA39B4BC for ; Mon, 13 Apr 2026 23:29:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776122946; cv=none; b=qJ44fjNa2MD4if+Xpo6vz1F0AL0u/Bos93W7aEDH1t1wq2Gn7F+Ur7PUFY+KFzEmFebQeIwi//e++zLwKooY6egt9DbNFAHfvUBIf0aQ0LtGfwPdBzFxRaDQ8PuDE8FRQAzHF5WfWwA/V+GfFCEYax0Puzl/wCnVFjXpH9D4tQg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776122946; c=relaxed/simple; bh=YWZAnDYf6y9BkmLDuysBkBolYs6f9pDJ3ZTZLEHRWpA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OnY/mFMzrBiyhqsaUkLKDR2Eb6xZwSYlt7IO4/x8QgV0FKM8kYc2tWsaFmj+O4pSNXICUmrTPHkperzgq95KIfP6kZ/UR7iZxwJxvbdp3C6D/mJqFnJ0xgVRZ53tnb6r6fqa1krgT/71rlpgQAGFKyh7j3PiaGe4jUV820uoDrE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=SEGie2VU; arc=none smtp.client-ip=74.125.82.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SEGie2VU" Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-1270f10a774so39777c88.1 for ; Mon, 13 Apr 2026 16:29:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776122944; x=1776727744; 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=YWZAnDYf6y9BkmLDuysBkBolYs6f9pDJ3ZTZLEHRWpA=; b=SEGie2VUKI1KUnlXjfJUT8nz3JXn6nD82oVOidiFLaffx4jypT/6hNAIw8k/LSOyQF ZOdmTLljCQFyWesvFaqi2V2IuDuG8NNdSjaK3zV1Od2hVnHjgXZB1fHiGwLd55LyBSHL rZ2Ce3VTOKygRB8oP1sFvitxAptdAZqtoXrrkUvjOV25XEkYdL3E0OWQc8wqKTYNQJs3 1kOJC68UZj+xKeWL0Wrr7jZungRTbbdjvBQkDPIj6/h2Tjpg5CqnHC7D5OVVq02wefF7 S98lkOrnvg4FRgHQwfMPlpPyo97/G/eoJHq6X/0FeDhkENwJYx6rcUB0iGw8SJCPIVA7 V/UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776122944; x=1776727744; 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=YWZAnDYf6y9BkmLDuysBkBolYs6f9pDJ3ZTZLEHRWpA=; b=p4Yi6ilEqW5kN/hkZ3U+mr9jI5Q4wKRB4aM3zhErqIDuC32h/lLSzKr0CZvYdwdeqJ FsUoiymKVtC8SCzH/QyFaF5/5Vjp8IBfrIH4o6aNwzOV9+JLCUl9p9YpghWV0tlSFWEI CygtVMFD2Ck1BaL21m3BWalyR30bdq65IEaUeE96PcObfsidoAheJXl8WpE7FP4iNOE8 M14vZVNBWVxw4q9KuMSI0u3i/JIdQGxNxFCxOfNYCQHFYoDYzpC1vAJjfPvQ1c+hjBeZ 83KH5HubqZLJOLZLf2fY3VM49kz+/uo0n2MIycekxzN6g0SvYsn/E/i5ocRPu1hSyUPu gJTA== X-Forwarded-Encrypted: i=1; AFNElJ9uT+SBH2lkAWlLEhlrgi2HRAcvwxwQwG79fCRKli2LkObbRCBNjswMxn7p05bFX7hfxGuSkSL6R4mrBQA=@vger.kernel.org X-Gm-Message-State: AOJu0YxRajBvlM6kMZh+ZRSRqkVd5qquDeNCTx8UZnJzmIlu9oFi7cql PAM+R4taFdF1tbhiWQHehMjFIOBeGMQMq4KJ1mMMBPsu5qHpd3M0NkGruJN59F7s1w== X-Gm-Gg: AeBDieuuvwzJKGTpQCnfelR6IvxBtoQe0knv5tp5I5Xo9+5VqjHLusgAJQ8azF79PfR wz+M7jobzQHd++U+/JyPp/1GlD7ac2uUQpdVEULjjssZdNdC7hXXjFOdtLU/cAjSPvIVdZcyxEk 6niRVLXBgFBOJUH50tb9gUGgVxVrhLX5+3m2OeajEpqHwC/P9wx/dn3JnPGsOruR+Rx/zF3Aoaz kGwpSaKRylGC3fcYwo7CJilHKfpulyJzsPQN4W8iEjIWe/tJS5jIm3LyWTooqubmYZ+ksK6WoSw sSiqeQ3UrQz03Ko9UxRoIOSj3t7hx6pY3AG8R8EE6Mco3n1OnqSR46ZJabGguNquM9391f8urH2 eUS1zF7IKoYaZ7iSvjpdwnxfSfx+UmA5hcvIc8txURtJnPx6+UGER1KkYvhnoK0FtQSFjAhSdOZ GP0248Gt9e9xpGNjlDJQzS0sOfHLfWVgg+YXoVyGuWPZMEqyp73LFYEfyMgWHxIRZjnWFTwhoJG O+4tpnRv9g= X-Received: by 2002:a05:7022:11f:b0:12b:ebc9:3da6 with SMTP id a92af1059eb24-12c29c1d268mr869915c88.7.1776122943207; Mon, 13 Apr 2026 16:29:03 -0700 (PDT) Received: from google.com (195.236.83.34.bc.googleusercontent.com. [34.83.236.195]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2d851e5bb3csm10730610eec.1.2026.04.13.16.29.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2026 16:29:02 -0700 (PDT) Date: Mon, 13 Apr 2026 23:28:57 +0000 From: Samiullah Khawaja To: Jason Gunthorpe Cc: Pranjal Shrivastava , David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Alex Williamson , Shuah Khan , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Saeed Mahameed , Adithya Jayachandran , Parav Pandit , Leon Romanovsky , William Tu , Pratyush Yadav , Pasha Tatashin , David Matlack , Andrew Morton , Chris Li , Vipin Sharma , YiFei Zhu Subject: Re: [PATCH 05/14] iommupt: Implement preserve/unpreserve/restore callbacks Message-ID: References: <20260203220948.2176157-1-skhawaja@google.com> <20260203220948.2176157-6-skhawaja@google.com> <20260410141652.GV2551565@ziepe.ca> <20260410231650.GD3694781@ziepe.ca> <20260413223318.GR3694781@ziepe.ca> 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; format=flowed Content-Disposition: inline In-Reply-To: <20260413223318.GR3694781@ziepe.ca> On Mon, Apr 13, 2026 at 07:33:18PM -0300, Jason Gunthorpe wrote: >On Mon, Apr 13, 2026 at 07:31:22PM +0000, Samiullah Khawaja wrote: >> Yes, we use the collect walker during KHO restore of the preserved pages >> and also during free. But if I understand correctly, the collect walker >> behaviour changes based on some FEAT_ flags (like SIGN_EXTEND). So we >> have to be careful if the previous kernel was using different FEAT flags >> that affect the collect walker. To handle this, we can just preserve the >> u32 features from struct pt_common and deduce everything using that. > >It is agressively not stable, and even new kernels might not support >the features old ones were using, so this is a bit dicy. Agreed. > >You probably need some, but I think I'd be very choosey about which >some I preserve and which come from the new driver. > >> Thinking about it more, we do preserve the top_level, so that could >> potentially be used to walk over the page tables of these free-only >> domains if we just set up the pts->index and pts->end_index properly by >> initializing the range based on the top_level. Are you thinking of a >> similar approach to walk these free-only domains? > >Hmm, even the free walker requires computing the end_index, and that >requires at least vasz. eg ARM will compute the number of items in the >top level based on vasz to support concatenated pages. Yes end_index setup using "derived vasz" is exactly what I was referring to earlier. Basically KHO stores the order of the folio, so we can look at the order of the top_table and that should give us an idea of vasz? Even if actual vasz is less than the one drived from the order of the page in next kernel, rest of the page should be filled with zeroes, so iterating through it should be fine? I think to keep the scope of this series limited and also to do it in the proper way, I can save the vasz. That should give us everything to free and restore in the next kernel without introducing too much complexity and ABI right now. We can put in more functionality with subsequent patch series to handle other usecases. WDYT? > >I don't think sign_extend is used in the free path though. I think it is used in the pt_all_range() during free to calculate the range to iterate over. Based on the sign_extend it decides the vasz and that affect last_va and that affects end_index. > >So if that is the only purpose then yes you can probably get away with >nothing, but you have to be very careful to contain the restored >domain to only execute free and nothing else by removing the >map/unmap/etc ops. > >And add some dedicated self tests (zero pt features and test free) to >simulate it. > >Jason