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 B5BADC25B10 for ; Fri, 10 May 2024 15:59:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 146606B00FA; Fri, 10 May 2024 11:59:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F7D06B00FB; Fri, 10 May 2024 11:59:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED9066B00FC; Fri, 10 May 2024 11:59:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D02A26B00FA for ; Fri, 10 May 2024 11:59:13 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8572816180D for ; Fri, 10 May 2024 15:59:13 +0000 (UTC) X-FDA: 82102945386.16.AAF138F Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf13.hostedemail.com (Postfix) with ESMTP id BA91020008 for ; Fri, 10 May 2024 15:59:11 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=IcqVK3XV; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3TkQ-ZgYKCAk1njwslpxxpun.lxvurw36-vvt4jlt.x0p@flex--seanjc.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3TkQ-ZgYKCAk1njwslpxxpun.lxvurw36-vvt4jlt.x0p@flex--seanjc.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715356751; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=u5ISVPYL6PmEyuY/FQRwjKLZdHccDsXxGbSGsjEmQJk=; b=ZjHFIODngKdM93I8ayMqdBOJnVXV3AWjewTYt+zi+ClKFrf4UPX3tSxjh9wyjuP7GN2SoO VfuJCCbO7BkD12TsV0OIfcnaQKpVXujwkhU3HQMyAxJVk2PcG39q68kKg+QR4Qk3osOxUw XLlvCDvl+llihHto6T8uULl6EQXRDQo= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=IcqVK3XV; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3TkQ-ZgYKCAk1njwslpxxpun.lxvurw36-vvt4jlt.x0p@flex--seanjc.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3TkQ-ZgYKCAk1njwslpxxpun.lxvurw36-vvt4jlt.x0p@flex--seanjc.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715356751; a=rsa-sha256; cv=none; b=K9kz/3gAi/rdzqWBK/+c8+pe6rYworrF2j4KltfCHwjK73xta5Rd1XBr9I1O3YjYvSostr GdqgHseMhwYxzTsirFhEKOwMMj49RKz9tMTzctT7vBfXfU5YiNOUxzbHdlWtQw8TT8nsnE NMn2zJtmufgAjEkaVPv1BGvok7nwfXg= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcc0bcf9256so3406354276.3 for ; Fri, 10 May 2024 08:59:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715356751; x=1715961551; darn=kvack.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=u5ISVPYL6PmEyuY/FQRwjKLZdHccDsXxGbSGsjEmQJk=; b=IcqVK3XVLkzKmif+aATetqIBsBCKYXmVoYIk+ZsLTwXdY0rcGgjkk7yJ4312VAqoz7 kl6YT2wxioIgdLwT5UFwexDQq+bq3jhUscFL9bUmA4IU9smmynzA4tmFqRpmb8Bxf7so 9+/BwzljPJhdpU3EnT42KAne4ihFHI7UyqcgTD7B78I+6CF3sd5LfId+vpJiO0edIVcs eowRMOWUtYFQ0dSdZdv5G/jt11z8uwAHM/tC3t1avtiEQ2Quu7YKPPyP2RJ+smvxRSE8 y22244aVgQuLXqIsDPtdxX4EdQdqaJ+h7dXKa+RiCFFa26yL/qoNQy7Vbm9ZPPkKp9p2 By2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715356751; x=1715961551; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=u5ISVPYL6PmEyuY/FQRwjKLZdHccDsXxGbSGsjEmQJk=; b=ZAyaaH3pAUrTEi8RQitkq0JpYTwrt1Iqcm1fAjCaYSOBKWhYr2zZWoiy1Qv5p5QZEr 4DvKFd+SExbxJZxWMRO1h/NeZTjqepeEnyRbxP625Oxse2kaIlLwKxRcFRBo8Vvw+BX+ hCLSaZmcn1BJeP4StpnAuPCYVzvY1SH1cnNuI/doQUGSccCD5Ln8k1OYeOuND32RivcU OvIIfNQqeJA8K8TLX8KxOgBvVeXQYsIgfQ2xDROywDoFmTGBeiC1uW9MdPLWXMw2H2h/ CoOlMSZ8eZvl05mmwpjaGhCDCcqhQtKmYrmMhbxIRs9K8RzhtV/GFI3lm0BTcWbp2Szl Nzrw== X-Forwarded-Encrypted: i=1; AJvYcCVsFjhDw9Zf8WfUaxRnLJwbGeYBQ+AG8zHJHqwswHNuFntB/C0odJ0AYCcQU//jcsMdefNwVZ++UdpzgJa+sD2Q7Nk= X-Gm-Message-State: AOJu0YxpNEkNKyRMl6T9J0U5EcUUMoHmyJHeeuY+l92wyNtm2RQz83+W SQ2HE7LRsO4wJuNGX0Oaunk13mjHevKz88PuAsF3Tund9xsBMldbtvMWEAV5PzvygYo5N/e2FHq mSA== X-Google-Smtp-Source: AGHT+IEX/OuQG0ZhfJrRj7k8BAEO/RM7nxjVnIQb2HXfQAss9M//0E1w+F9Y0UfoI1zSWZuVX2x+Zkq5Z94= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1006:b0:dc6:c94e:fb85 with SMTP id 3f1490d57ef6-dee4f1b1019mr242036276.2.1715356750717; Fri, 10 May 2024 08:59:10 -0700 (PDT) Date: Fri, 10 May 2024 08:59:09 -0700 In-Reply-To: <20240510152744.ejdy4jqawc2zd2dt@amd.com> Mime-Version: 1.0 References: <20240501085210.2213060-1-michael.roth@amd.com> <20240510015822.503071-1-michael.roth@amd.com> <20240510152744.ejdy4jqawc2zd2dt@amd.com> Message-ID: Subject: Re: [PATCH v15 21/23] KVM: MMU: Disable fast path for private memslots From: Sean Christopherson To: Michael Roth Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, jroedel@suse.de, thomas.lendacky@amd.com, hpa@zytor.com, ardb@kernel.org, vkuznets@redhat.com, jmattson@google.com, luto@kernel.org, dave.hansen@linux.intel.com, slp@redhat.com, pgonda@google.com, peterz@infradead.org, srinivas.pandruvada@linux.intel.com, rientjes@google.com, dovmurik@linux.ibm.com, tobin@ibm.com, bp@alien8.de, vbabka@suse.cz, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, jarkko@kernel.org, ashish.kalra@amd.com, nikunj.dadhania@amd.com, pankaj.gupta@amd.com, liam.merwick@oracle.com, papaluri@amd.com, Isaku Yamahata Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: BA91020008 X-Stat-Signature: bfhxo4pg97o6dzh7xfbi6q3csr3t9sco X-HE-Tag: 1715356751-11645 X-HE-Meta: U2FsdGVkX18mDjhjh/n/ysb84beG1GN4sqGYOHxkzHjiGcViygjJHPSt0mmHoQgwn8LAOHmbj71KUe286aEcyQPSrC2UJyh8YFGvQER83UVeuIBA5rvM3OKJAKOxEXo9Ql9AKXU4hkdx7qlDD7bggilpelOyHXVU7yOj6C4BarPRZhyICU+FOVeIN1tfH4KlYEMGfWUoXKRDDC1pDua8nwr2rdOW7jxLSxJ/u7bpjb93hr2KTacPeKRY0JanLw15tao9LwrFtKI6Acu/Eid78NTs3oLRTOzLbIW4NHie4gasfs+OHBrz8L9G3joGy5B8UxPm4tFZgXkcq4TfIdBX1rTAK1UO1zyVmgnVSND9vRDE2jFEQRbdTcRNNRk4b4qCHLk1YfclxWOGx6hU6SnJGp9htyLH/mdbKS51+xBFaMiUJ6LnBdcWQ9SMnK2Jp9P0olxAGoMi6O8bO5l8Q97pzPivtdIJ9cyJQdQ0iGz4tF8LE+akCSsq0tDUfhw+KjTSJfYq8XHGQor7BlakwWFuQupf/x9ms3i7v43B8+gYiuKSbuhorjr/nFPMmk8VaaNIEHqiwJjs3jKDsWPeKOgBDl+llg+uzOSolB+UcBOTXnZ+fvOka8WF+nweyjZpEM/n+o+eGhLOtVrg1CzpR0iuISs3kbNgaeJSVx/Am2Qg0Ih/XFYPAph8MKKxgEU6im4glghuD12nYlAulEJ2JhdFPdOp4ChBlDREWXKpqJexV9pwumgElQNsQpRVQGfTsDs7MtWf/fgkU5VKjkJA3wOvSTIO9hOnfY2pl5EmreHi6C4BvfO6eQSBM4EjZ4ESQ26Qssh9W+hD0sm4JdZe/jDdvkoU+YqlwYCjOZJZwfsZTtcrRarjoO3Aw8wIsXlbZnkBbGVDaIXcczmJ3vnBC+emRueNDLN9sEIg84rSqqFfkFf1CuNBTgK+umbQabYC+iYS+mCQ/cHYefgJ33/Jeec 6NbCXYhL GBMLDC6qFbWiDv0rSVjN74WKIkt+58VzSSuVyGxdM3dFjzGRlvDNdjZJdi3Aoc836jYEphuq506zLWsSWSVgU9/nV1dhQ9lfI0d7/72qZWPLA2AbG1Bsc91UcMz2EtDp5ZhlOifQ+pnAJMEMOcZHycIXVjyYrMC499SVSjFcrSoPsh+9gvBxS6f4Wmr7KuVVjQlhy5jJ57Db7yNikJTxAvrxCpUxQZ0LoTRKcSfWeLKxddibwnPaD6wbxdqJESc9KZhwDQk1nfZQnp6qvyddc7CHrf7RMxQZ/efg0rUwy5/9EJwqNBgW1Uk27GdV9Ghne1WNvlRQIey+10RqG6lG7/u67bYM4b3u1x/VFB1DgiiodESzHjxq9tNAYz2lmeUkgn480xm6iNtAOC2cmDvKc0kKk43X3tfh17yZquO3QrN/9VTuu/pK9/yUw5I02EpgCy1b4zh24oI8bMsyjlr7h8J4iMc2pkDhjCOgxmdrGYAuAcdpcPIAA5i+hlwdT8boMOVx85v6H1cpo0QRj8TcJ7yCTXvPwWAwe20gU6dSITLFkhT4Jmq2PhENcml4oM/JHxikBziSja6EFC2drjuydnIYrAsh8gfGBvwvALKTj2YyI7uOG04nO3icQswk2eHXuo0ePtWRmHG4emyyBi3cVrvwif/NFUgWRI8OE1O+PbIBjCQEV+R8z43kyGA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.004110, 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 Fri, May 10, 2024, Michael Roth wrote: > On Fri, May 10, 2024 at 03:50:26PM +0200, Paolo Bonzini wrote: > > On Fri, May 10, 2024 at 3:47=E2=80=AFPM Sean Christopherson wrote: > > > > > > > + * Since software-protected VMs don't have a notion of a shar= ed vs. > > > > + * private that's separate from what KVM is tracking, the abo= ve > > > > + * KVM_EXIT_MEMORY_FAULT condition wouldn't occur, so avoid t= he > > > > + * special handling for that case for now. > > > > > > Very technically, it can occur if userspace _just_ modified the attri= butes. And > > > as I've said multiple times, at least for now, I want to avoid specia= l casing > > > SW-protected VMs unless it is *absolutely* necessary, because their s= ole purpose > > > is to allow testing flows that are impossible to excercise without SN= P/TDX hardware. > >=20 > > Yep, it is not like they have to be optimized. >=20 > Ok, I thought there were maybe some future plans to use sw-protected VMs > to get some added protections from userspace. But even then there'd > probably still be extra considerations for how to handle access tracking > so white-listing them probably isn't right anyway. >=20 > I was also partly tempted to take this route because it would cover this > TDX patch as well: >=20 > https://lore.kernel.org/lkml/91c797997b57056224571e22362321a23947172f.1= 705965635.git.isaku.yamahata@intel.com/ Hmm, I'm pretty sure that patch is trying to fix the exact same issue you a= re fixing, just in a less precise way. S-EPT entries only support RWX=3D0 and= RWX=3D111b, i.e. it should be impossible to have a write-fault to a present S-EPT entry= . And if TDX is running afoul of this code: if (!fault->present) return !kvm_ad_enabled(); then KVM should do the sane thing and require A/D support be enabled for TD= X. And if it's something else entirely, that changelog has some explaining to = do. > and avoid any weirdness about checking kvm_mem_is_private() without > checking mmu_invalidate_seq, but I think those cases all end up > resolving themselves eventually and added some comments around that. Yep, checking state that is protected by mmu_invalidate_seq outside of mmu_= lock is definitely allowed, e.g. the entire fast page fault path operates outsid= e of mmu_lock and thus outside of mmu_invalidate_seq's purview. It's a-ok because the SPTE are done with an atomic CMPXCHG, and so KVM only= needs to ensure its page tables aren't outright _freed_. If the zap triggered by= the attributes change "wins", then the fast #PF path will fail the CMPXCHG and = be an expensive NOP. If the fast #PF wins, the zap will pave over the fast #PF f= ix, and the IPI+flush that is needed for all zaps, to ensure vCPUs don't have s= tale references, does the rest. And if there's an attributes race that causes the fast #PF to bail early, t= he vCPU will see the correct state on the next page fault.