From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF4FEC36008 for ; Wed, 26 Mar 2025 18:52:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E7F002800A0; Wed, 26 Mar 2025 14:52:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E06EE28008D; Wed, 26 Mar 2025 14:52:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA7E52800A0; Wed, 26 Mar 2025 14:52:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A788B28008D for ; Wed, 26 Mar 2025 14:52:36 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7F4E91A0555 for ; Wed, 26 Mar 2025 18:52:37 +0000 (UTC) X-FDA: 83264598354.24.6D1E141 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) by imf19.hostedemail.com (Postfix) with ESMTP id A2A931A0009 for ; Wed, 26 Mar 2025 18:52:35 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=LShVKNPZ; spf=pass (imf19.hostedemail.com: domain of oliver.upton@linux.dev designates 95.215.58.170 as permitted sender) smtp.mailfrom=oliver.upton@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743015156; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FSshJQs9r4m1RulgZtk+BVpimPAXm4vtzmVudgOOHPM=; b=DEqt95sNhia7zqp9m3xWg53dOZBFjNzfIzRZQKKQteSrNqf/hLv4NZRMH8t8mPXniinOeK A5TTDz6jSXUtCcZesgD+2SKFY0X4S0nzCtV6tQgr7x5oDCtavuEchwBinudYkTqTc5XCy4 1ZjOmASp7rOkxVpG7p9+EY+1JDbKdSI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=LShVKNPZ; spf=pass (imf19.hostedemail.com: domain of oliver.upton@linux.dev designates 95.215.58.170 as permitted sender) smtp.mailfrom=oliver.upton@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743015156; a=rsa-sha256; cv=none; b=KUgjtv9NMBP5PV18cUh8IebNd+patzLc4WJRMTtzrrEFRDC+2N5iFU67tBCbY8jurkrLxR 4p5641NF9jq0opGAhwFKEdNb+LeeThVErDTBYWgdu7p3pcrnFSvroRiGF7P505Yi0J7aTt heO7nPg+L2J2q9iN9UTnGwz6e1J9sBw= Date: Wed, 26 Mar 2025 11:51:57 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1743015153; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FSshJQs9r4m1RulgZtk+BVpimPAXm4vtzmVudgOOHPM=; b=LShVKNPZ6tCQ+oRaWLBf37sMD9m9kLZ1yV8CQVogM0OEPbYG6Zx/v0bZJqxgtmr5Tfs8lv GXloeObhq8Mw9QPkel4lZfRvub7HRjUx/bgqZ08AFXisEvRmgzxz2ZRuxTRd0Ac8ppKgZq o9ote564OApjCSKkwU5wEfzbIGHon1M= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Sean Christopherson Cc: Marc Zyngier , Ankit Agrawal , Catalin Marinas , Jason Gunthorpe , "joey.gouly@arm.com" , "suzuki.poulose@arm.com" , "yuzenghui@huawei.com" , "will@kernel.org" , "ryan.roberts@arm.com" , "shahuang@redhat.com" , "lpieralisi@kernel.org" , "david@redhat.com" , Aniket Agashe , Neo Jia , Kirti Wankhede , "Tarun Gupta (SW-GPU)" , Vikram Sethi , Andy Currid , Alistair Popple , John Hubbard , Dan Williams , Zhi Wang , Matt Ochs , Uday Dhoke , Dheeraj Nigam , Krishnakant Jaju , "alex.williamson@redhat.com" , "sebastianene@google.com" , "coltonlewis@google.com" , "kevin.tian@intel.com" , "yi.l.liu@intel.com" , "ardb@kernel.org" , "akpm@linux-foundation.org" , "gshan@redhat.com" , "linux-mm@kvack.org" , "ddutile@redhat.com" , "tabba@google.com" , "qperret@google.com" , "kvmarm@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" Subject: Re: [PATCH v3 1/1] KVM: arm64: Allow cacheable stage 2 mapping using VMA flags Message-ID: References: <20250319170429.GK9311@nvidia.com> <20250319192246.GQ9311@nvidia.com> <86y0wrlrxt.wl-maz@kernel.org> <86wmcbllg2.wl-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: A2A931A0009 X-Rspamd-Server: rspam05 X-Rspam-User: X-Stat-Signature: 38k84h1bizo7kmdcncu9r3n6qmh3yd1w X-HE-Tag: 1743015155-181950 X-HE-Meta: U2FsdGVkX1+jxdDMMpopEC5RixZQkLNnj7jgwgflxkhlDDR56ClXx5mKE/YPH5RgsxNqxLSK8XE26+TjJk3Jw2xqBnmeQgteVIVFyvMuA44drDJwFfaH1dIqFLPmyKPekC4+VRa2tzg+an3kUzMirsCk2KCN1ZBjayIAQ4HcOqyGvFuDDvN+9ib0TZSkioNF51epjFHv97vZ8E2A5r6/O1PlzvOmmMui+rC8MkUqNMFnyVqcD2Ulc8MaFU6x/tQTdRqG5cifY5PQelztn6CKOfHbCEcLIHjTP7w0OKcF5y9F0hyk1Y3h8kZdBwjEITS70e/vTNsurkqoRTywUXkhvxq5rXVp8YQWVW6YobL67RRB3qmC03EKzAFTGAnqmXG0n7fkx75uFrl7bErax7ra3CfAVVTFAUOA7ODXWNZXfVgS/DLtwJlOlIGAxsxnqT+khJaXPVmC0KfHtdSz/Vt1FNhdT1m0vnPYEuDoPE4tRn6dW/HuOnb3Dib72UbFfJnuuX3CJH0ZteY9HledHrRT6QVBw+Pa6dGTOiuzwC2QkfkFX6bf3Jiw2phkLS302st5K3rMX75E07yoynsIdFGxyZIzBwi0X9vbuGpZHffDZz/MazB5kg8bjE1heBJvzFfcd+fFPIMxzTijtVTBNcNt3WS7N47DUIE8mo1nYF9NfzxjksAjrbvvySQ80l1/LXtgCslsUR7IAL3MNlQqv20t1VlYs0Vi5GrOApf4MVYHb6Kyz1tYMHxmCygsHqYYBZcZpjlD5WWMQsycOfUvIflx3tY/nSoOZcXRuX7mL1p8FcXRdjkvPHYLjYH7C5mcQofVGQmvR1by4ZmPoepA0LdxoOt7np4mQ9VvuWQmLJ/NNwc2j+l11GMpfr+KJgzqatO3Zps0Vwq8jEjMEaSxQ4Hd48+MQdqVptqa X-Bogosity: Ham, tests=bogofilter, spamicity=0.000391, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Mar 26, 2025 at 11:24:32AM -0700, Sean Christopherson wrote: > > > But I thought the whole problem is that mapping this fancy memory as device is > > > unsafe on non-FWB hosts? If it's safe, then why does KVM needs to reject anything > > > in the first place? > > > > I don't know where you got that idea. This is all about what memory > > type is exposed to a guest: > > > > - with FWB, no need for CMOs, so cacheable memory is allowed if the > > device supports it (i.e. it actually exposes memory), and device > > otherwise. > > > > - without FWB, CMOs are required, and we don't have a host mapping for > > these pages. As a fallback, the mapping is device only, as this > > doesn't require any CMO by definition. > > > > There is no notion of "safety" here. > > Ah, the safety I'm talking about is the CMO requirement. IIUC, not doing CMOs > if the memory is cacheable could result in data corruption, i.e. would be a safety > issue for the host. But I missed that you were proposing that the !FWB behavior > would be to force device mappings. To Jason's earlier point, you wind up with a security issue the other way around. Supposing the host is using a cacheable mapping to, say, zero the $THING at the other end of the mapping. Without a way to CMO the $THING we cannot make the zeroing visible to a guest with a stage-2 Device-* mapping. Marc, I understand that your proposed fallback is aligned to what we do today, but I'm actually unconvinced that it provides any reliable/correct behavior. We should then wind up with stage-2 memory attribute rules like so: 1) If struct page memory, use a cacheable mapping. CMO for non-FWB. 2) If cacheable PFNMAP: a) With FWB, use a cacheable mapping b) Without FWB, fail. 3) If VM_ALLOW_ANY_UNCACHED, use Normal Non-Cacheable mapping 4) Otherwise, Device-nGnRE I understand 2b breaks ABI, but the 'typical' VFIO usages fall into (3) and (4). > > > > Importantly, it is *userspace* that is in charge of deciding how the > > > > device is mapped at S2. And the memslot flag is the correct > > > > abstraction for that. > > > > > > I strongly disagree. Whatever owns the underlying physical memory is in charge, > > > not userspace. For memory that's backed by a VMA, userspace can influence the > > > behavior through mmap(), mprotect(), etc., but ultimately KVM needs to pull state > > > from mm/, via the VMA. Or in the guest_memfd case, from guest_memfd. > > > > I don't buy that. Userspace needs to know the semantics of the memory > > it gives to the guest. Or at least discover that the same device > > plugged into to different hosts will have different behaviours. Just > > letting things rip is not an acceptable outcome. > > Agreed, but that doesn't require a memslot flag. A capability to enumerate that > KVM can do cacheable mappings for PFNMAP memory would suffice. And if we want to > have KVM reject memslots that are cachaeable in the VMA, but would get device in > stage-2, then we can provide that functionality through the capability, i.e. let > userspace decide if it wants "fallback to device" vs. "error on creation" on a > per-VM basis. > > What I object to is adding a memslot flag. A capability that says "I can force cacheable things to be cacheable" is useful beyond even PFNMAP stuff. A pedantic but correct live migration / snapshotting implementation on non-FWB would need to do CMOs in case the VM used a non-WB mapping for memory. Thanks, Oliver