From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 14E9B36A37A for ; Tue, 30 Jun 2026 09:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782813101; cv=none; b=VeO4pLRGchiLrAHImdfYjp6g5dBZzCbatVfGH87qFxyZS688+gygXAwBb8uXnPLdeODFnJMUH4ProNRy0yy2fvKLfWYF6Xhm02ByZIP4Mz7EdPEnJJumWpDGUM1VGhRqFChSW4iFCIfXWdCyAxTrvcT+WwimqlZ3gchx4j3M2tU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782813101; c=relaxed/simple; bh=yb90SNjFBocihj8fiYGJqdyII0fOUVjjiJzpoUx4P1E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=L7zoUQiRQY92gmToWeS/xZmOwpoCwvJRv4gZIapvx1P5sUPUXQI0J7DIEQiaz8d41e3+nd9aSmluvzgBEnWcYau52Y/B/XF8lyWTw2cOWh20L2BMNezpL7EpTjEnuAAhoKwByfPU/hAOJLNn6EnOIoljnYHoykGwDy/YKCkUrGE= 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=Nw5BUhMf; arc=none smtp.client-ip=209.85.128.42 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="Nw5BUhMf" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4926e5803e5so40645e9.0 for ; Tue, 30 Jun 2026 02:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782813098; x=1783417898; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=RtSqH+WqtZAB5cklSCb440iNsoDcg75bAXjvEoBq+ok=; b=Nw5BUhMfB8dN0UiLXKCi7sGwj/SnM+wDxMaojZ798fT2kzIdT81T7FTRHqmlc0M2B7 6EEwjeAgRTobzwR2I7fTK3fjAl+C9u14pa2heNFxU7v2z8nYkuqO7M4ieAb/WGJDwaEd KJ8oUNBQcFA3nACA3PUesA6popWa1Shx2o0sdnh/CkDL5f7qHymbXW+GW3FGkXaVyKVs gQURX5BydHK4Qwx1B3SSQAjmUHrGb1TpM0+aHWukxZSHUYLeO5OrdXdSnhZ2Om1IFbKB T/H04y9FXJ1JBAyHMzUbTEw0jDw4a4UsSwoMQYk6nfBTHviwjvBqGMhSGgwunYLCwMS0 36+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782813098; x=1783417898; h=in-reply-to:content-disposition:content-type: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 :content-type; bh=RtSqH+WqtZAB5cklSCb440iNsoDcg75bAXjvEoBq+ok=; b=Bfowk8HquWyYHeUSs2uEE8b7+Mmsi9HKjA1RJfLYbDBYaJahWL6AzY59kZmEBvAuH9 nYCAEXxds2aF3nPQ7l6qrX5KxmP6yoykmKKoHf0OI6albdeCXrN135JFzQM/4ytljniG zALLN7d/YFGZJOOeRSXBsI9oGUhez9kFCO3NX9fONcmJNyHuw83sxcJBgoLAAwohmIwh oqzfuuaprQq71N/JZt7duOVJ75f1sNFzh8mzA+oNlhzN4mWgfeDowHTeKkm3Q3GvwMd9 uD5/TEmM697BG9fkeoC2GGc7tD0sosNnGReX218xhncm+oU0Vf82e9sDu61AUMQI7/Sx 4ZyA== X-Forwarded-Encrypted: i=1; AFNElJ99hPrPMwwvjQykfVUejdvw2mu8MJCARHOUY+5GrS8A7LCHdAqiPok0hEz1NFAZNSUcc1TTixSaa0WUP38=@vger.kernel.org X-Gm-Message-State: AOJu0YyV+gTn7PhfuKEAzdVRiE6Y2s1bUlWdNikEPCPl+GpvXwWMAHQ1 Wkt0vxmMy6XsYKJlzr0PC8z4nXupWxzry3VZymbR6eL9ipIx8XimWP8o8pVXhMGT7A== X-Gm-Gg: AfdE7cnS3K6wjcIjgjOczqLH54S09zxlch1lvdyh1cJlYA7hdBQeS4WMCGfMUrYEAA2 ER9Mm47qa06Eo9ywX6lRkbXUFH72hukKGWY89YI7X18drA8+b7myPx/n9Vv6a6DhRecPV8+2tKl fug7MUslshnqIObsx+93oH9jQ5adHK8BR75snu01/zakUbkiry29uBZmEyk8V/IR8IHyAUr9aNR u60PdWpgPXuy2xSREjSJEe+zRRPBs8V54rJi0J4zh/FtFCe1q/F9WOTuhfde8QmCZMwuuDhpmjY icF7ZQFoFxSqSFxqf4QDJVYqRe5fJ47aHXu4KYK/qgF7guU2+qTRgAFXoQKAWCVCl/U/ofzWuve 180+/YT0HwCRtK9XC/IlYv4+furq2nVW2kg+on1fM0HOHCuiWmhXeftawlTewcngfCytFtJ5NRC YgHUJjoXf7LeOtdWlU+0dGnRa30w1ti+EZqoh+vhbVH1vbLU+oZytjBlO8/A0= X-Received: by 2002:a05:600c:58d0:b0:493:adf3:d892 with SMTP id 5b1f17b1804b1-493bd76f95emr1505e9.3.1782813096603; Tue, 30 Jun 2026 02:51:36 -0700 (PDT) Received: from google.com (143.11.148.146.bc.googleusercontent.com. [146.148.11.143]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493bb4f174esm22907135e9.2.2026.06.30.02.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2026 02:51:36 -0700 (PDT) Date: Tue, 30 Jun 2026 09:51:30 +0000 From: Sebastian Ene To: Vincent Donnefort Cc: catalin.marinas@arm.com, oupton@kernel.org, sudeep.holla@kernel.org, will@kernel.org, jens.wiklander@linaro.org, joey.gouly@arm.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, android-kvm@google.com, maz@kernel.org, mrigendra.chaubey@gmail.com, op-tee@lists.trustedfirmware.org, perlarsen@google.com, seiden@linux.ibm.com, smostafa@google.com, sumit.garg@kernel.org, suzuki.poulose@arm.com, yuzenghui@huawei.com Subject: Re: [PATCH v7 6/7] KVM: arm64: Ensure FFA ranges are page aligned Message-ID: References: <20260617145130.3729015-1-sebastianene@google.com> <20260617145130.3729015-7-sebastianene@google.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 Thu, Jun 18, 2026 at 06:09:11PM +0100, Vincent Donnefort wrote: > On Wed, Jun 17, 2026 at 02:51:29PM +0000, Sebastian Ene wrote: > > From: Mostafa Saleh > > > > At the moment we only check that the size of the range is page > > aligned, and truncate the address to the page boundary. > > This make an assumption that TZ will do the same. > > > > However, it might decide to use the extra offset of the neighbour > > page at the end, which is valid under FFA if NS is using larger > > page size. > Hey Vincent, > I failed to parse this > > But I see > > /* The base IPA of the constituent memory region, aligned to 4 kiB */ > > So it sounds fair to prevent oversharing when PAGE_SIZE > 4KiB > I think the problem is when you have a mismatch between FFA_PAGE_SIZE and the system PAGE_SIZE. We expect a fixed FFA_PAGE_SIZE of 4kb and this is enforced by : https://elixir.bootlin.com/linux/v7.1.2/source/arch/arm64/kvm/hyp/nvhe/ffa.c#L761 if FFA_PAGE_SIZE = 4kb and PAGE_SIZE = 16kb you can end up annotating more pages with FF-A then needed when the range->address is unaligned. It took me a while to understand this so I guess it is better to rephrase the commit msg. > > > > Harden this check by also checking that the base address is aligned > > and reject it otherwise. > > > > Fixes: 436090001776 ("KVM: arm64: Handle FFA_MEM_SHARE calls from the host") > > Signed-off-by: Mostafa Saleh > > Signed-off-by: Sebastian Ene > > Perhaps the commit description needs some improvement. > > The rest looks good. > > Reviewed-by: Vincent Donnefort > > > --- > > arch/arm64/kvm/hyp/nvhe/ffa.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c > > index 1a2abd0154c6..d7c5701d0584 100644 > > --- a/arch/arm64/kvm/hyp/nvhe/ffa.c > > +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c > > @@ -352,7 +352,7 @@ static u32 __ffa_host_share_ranges(struct ffa_mem_region_addr_range *ranges, > > u64 sz = (u64)range->pg_cnt * FFA_PAGE_SIZE; > > u64 pfn = hyp_phys_to_pfn(range->address); > > > > - if (!PAGE_ALIGNED(sz)) > > + if (!PAGE_ALIGNED(sz | range->address)) > > break; > > > > if (__pkvm_host_share_ffa(pfn, sz / PAGE_SIZE)) > > @@ -372,7 +372,7 @@ static u32 __ffa_host_unshare_ranges(struct ffa_mem_region_addr_range *ranges, > > u64 sz = (u64)range->pg_cnt * FFA_PAGE_SIZE; > > u64 pfn = hyp_phys_to_pfn(range->address); > > > > - if (!PAGE_ALIGNED(sz)) > > + if (!PAGE_ALIGNED(sz | range->address)) > > break; > > > > if (__pkvm_host_unshare_ffa(pfn, sz / PAGE_SIZE)) > > -- > > 2.54.0.1136.gdb2ca164c4-goog > > Thanks, Sebastian