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 20F4FC4345F for ; Thu, 25 Apr 2024 22:13:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8134B6B0087; Thu, 25 Apr 2024 18:13:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79B896B0092; Thu, 25 Apr 2024 18:13:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6162E6B0093; Thu, 25 Apr 2024 18:13:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 41C146B0087 for ; Thu, 25 Apr 2024 18:13:45 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A7ADF161368 for ; Thu, 25 Apr 2024 22:13:44 +0000 (UTC) X-FDA: 82049457168.12.9A88AE5 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf09.hostedemail.com (Postfix) with ESMTP id CCA9E140023 for ; Thu, 25 Apr 2024 22:13:42 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=WP+YZm5d; spf=pass (imf09.hostedemail.com: domain of 3ldUqZgYKCCQSEANJCGOOGLE.COMLINUX-MMKVACK.ORG@flex--seanjc.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3ldUqZgYKCCQSEANJCGOOGLE.COMLINUX-MMKVACK.ORG@flex--seanjc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714083222; a=rsa-sha256; cv=none; b=j1Ar5pBAZZK9BqoZIcbIlebZm1FZ/mxbuj0l2tXAbj7UgWG7dEsuslhNW3Ajkru725zP+a z3wdkb6NxNFIQDXVVaq63U9sVEpDJfDrh4dgtc6Di/M33yZwxjG8kpSQicqZet9aU/AC1j s5VqVb4fluZPO37VmW9WRYRPMCdWynA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=WP+YZm5d; spf=pass (imf09.hostedemail.com: domain of 3ldUqZgYKCCQSEANJCGOOGLE.COMLINUX-MMKVACK.ORG@flex--seanjc.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3ldUqZgYKCCQSEANJCGOOGLE.COMLINUX-MMKVACK.ORG@flex--seanjc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714083222; 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=VlD1vrF3NmiYyeEP9cJyDUHce3FgvPJuIrigqLvvs0A=; b=G3AtvbFu9u5btDjnqYc2uQhwf8g3h/ebYVebU9DAko6DghO0VzdDMf5hZil7qs/rcU3jQ0 FmrePOpXolgUsm0oj54Ul6KldIRJA4WO5eRKqtcHERdAfZDyOn0rtDQip+pyMKopjxvwwc uVou/1IBFALKyfTtVifozZTq6Fup4DI= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61b330409b7so28673007b3.0 for ; Thu, 25 Apr 2024 15:13:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714083222; x=1714688022; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VlD1vrF3NmiYyeEP9cJyDUHce3FgvPJuIrigqLvvs0A=; b=WP+YZm5ddc1Acz9djrJhsncZwSabAM/UNsWgmuelJeL+9qAl2iw5WFOHCqoQ43DKAo +3t0Lyw4NTD+7XfulUWGJvjTy8c6T3tx4j3GqUvoeKF7uoIpl7Wx8VSj294PL82Ld0m9 tyhGxEVQm4Uj0LxBhDKhIBxA9hms6zgVZlhc3Qlgzjx+d3CJUUY8dQUvX4UWvXnr2HKk /KituWV+T6rMkMDFerD5qmaCg9lp+ssN+NV0p80+hV3UnhCvMUT0LqADqQ74po5rNIjZ Qg7qbdFesRQWQIIgxBg8zcrgvqPTx8u+6GPqdBHs/u9BbcosMGK0Ygg0W0deYI1MGDfi Lypg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714083222; x=1714688022; h=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=VlD1vrF3NmiYyeEP9cJyDUHce3FgvPJuIrigqLvvs0A=; b=EetgfGdjRV68TvjwlVA+7B8zOQsSvVYbj5deKtrnMfrZp4eb3U0YYEQd+U4HddFgJ3 cc6ut+GvNhoveKnDf/ywVk9c3CuqB/M6gk4Kkz9Qg0nSCIgCqt2+jWFWt2+Jz9Oj8SKv TkILLCx86tT31O3+0F1Qj8YT4PBcQJjq9EWfpk3DWb1adxJT/dN4H8NRVx2m1oj2gqyQ xNDs3XCbx5zaiC1FrSzdcEMK5a7bf1Y0rns98ROd9SFK9PwzxUGdVJdpNaeY+eOd7h7s /pyRG6cOw73iKNFaAhtb6isHtenT7r5scKpLEutCGTFZkjyVUe+JVhz09r3yxfz333v8 FbMg== X-Forwarded-Encrypted: i=1; AJvYcCUUN2BhRkmtIGZSAZ5HySU/o/A66Ynl+hlDJpJ6ob5o48tCCVN+IOP34PVaM9Tu4y0LDaI6wlXF3H8O79cbERDgIxc= X-Gm-Message-State: AOJu0YzwSJelyEmqjzFqA0bPnIK2ktCq3jmwh694UBln4FcThc+c4ODO du9U1vBp27spDLCHf8AlmjO60qRBuDL59M05P5kL6wRZu9fNBVFJZzpVlBGWb9AOqN9HVyF5E42 w+A== X-Google-Smtp-Source: AGHT+IHzHjxcfIPYRO/0ZR+/PU18iR8U2AlUK3bDXYPmThs8oWF6MVloZCgQa8+8/V5cYRymgqjaTVn5F6o= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:a097:0:b0:61a:b41a:2ef5 with SMTP id x145-20020a81a097000000b0061ab41a2ef5mr194759ywg.10.1714083221862; Thu, 25 Apr 2024 15:13:41 -0700 (PDT) Date: Thu, 25 Apr 2024 15:13:40 -0700 In-Reply-To: <20240425220008.boxnurujlxbx62pg@amd.com> Mime-Version: 1.0 References: <20240421180122.1650812-1-michael.roth@amd.com> <20240421180122.1650812-10-michael.roth@amd.com> <20240425220008.boxnurujlxbx62pg@amd.com> Message-ID: Subject: Re: [PATCH v14 09/22] KVM: SEV: Add support to handle MSR based Page State Change VMGEXIT From: Sean Christopherson To: Michael Roth Cc: 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, pbonzini@redhat.com, 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, Brijesh Singh Content-Type: text/plain; charset="us-ascii" X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: CCA9E140023 X-Stat-Signature: r3ehuw17exjdkbcdq3s6xqifbh3iihfx X-Rspam-User: X-HE-Tag: 1714083222-760837 X-HE-Meta: U2FsdGVkX1/F1+elLFLCjfIMnTjaIAm+U+SJVGCsTcBPslGsVK3LroAWJysPkGo2ZsDzGBRzd9hdO5Hx1Sdwj89+VXFZnM6w8eydSdtJJ84e+dBHjLvTqa9GIPlYvRUa4BYiBSikuv38lPjI9j+DdrvG6F08bmWlTXWa8intMoje7ZWPnc45OMKV8vp40/IVH7Zb5ZtU1CIy320QTHbbNCL5VgjHdDe8mNLC4N448oQXsaLw9yaWEHX1W4OOLo0PNNnzLUjeUtlyCInQq7n2hMB1Nlho31OOZx7CKFQ16axdpcTx1tpLQIJzhlT5ehFybGcWBD09jpcjNrZ/voBj6k6VbTcw3nzVdMFW1ZL9dLNtUkTcvPPf3g7XaOw1F9bRht0fufuCX5/Y2kdskjJr9diShJsu3EVUyUM46fbpQ7JH2TZF5pN4wcS8ypEW196Qrvp/54ifQ+i7f17Y0wl7u+vnijy1kH1itNTbv+UJpiLSpTequPOTyXWEPeu2bMRbzDNEkHQN02xOS69h3iSNsrcBD7ZXZvG5k7TUeLfk0/eBHkZWF6F/XNL+ky2G0GW0l/pW3tPlhCZUFlNuRUEopsCzRzKFZDGbjORCtaFiTd8D1BIAtVO6TlmY8zpG6f8ED6BGQG4ExMt0bbSwMD+14CKc9bUDOF2fJLQOR7/w/bk7DktknJZeEl0SL7cyQz7SP8/HlXeB+3mtb4Wg01nUxOIdomS4zpfVeWMUeeHxYV+EVZp3fEo+ZqXfsH0eIFxIqvpyT6YN+V0F/Fps2wBnu/TddDY8RPG++Bx1x0MZfhIeR48/H8bgtFWijl5ll8251kZJ9nYiOLG5JhBPbgmn5xyV5tl8aCvHXlYkykVf31Cj97aJOpSjxVJJIckrcJ/DvBfYpfTpq8BHIenJrlk8xW/RqgB+a0AWlK+90th/W8XiG2NKk1T+CE1s2Ee1ANLrfFwy4CxtAzlKsWb6uAS Mq4l17sq Vnm3ZPfG1ZBrY2XbyoLKkgguh6J2ib5qQmJUsNM1Q2FIQYIO3Imv0sUF1IkElYcct0AK8luYeFi1hrcCX7k2u2dUxLsIZLrIgIYu0YCshrQmxjSzYRPtp6gNd6W71MnHxBr9XfRbhun5K09XfUPuwZafzixceC26hWWoclNZVUTl8/RQ6FRm7d23O+afWnLTB6rdm6g+0pqPaPLD2KFoT1GOdM+u2xgHKFuV6o8r/00CxB0mBUaPH597DNEiuLrW17/uLknuPKXhddcf/wGYkWJ/M/41b6UkHWh6LvTIons5c5vDUCMJLObCR/0CTj1LS+Ss/kj9QlPtlj/kTLblAgNQimEEBcjLRPIwSI3YJYFLE7NDNLqtm1ONV5S2FrWDkm+QDm9+RpLhPsutCbCOJk4Q5VUoNOZc0Oi37iE52yOFvxoy7nlE1YWG7sd5mOsCkLABMhlhODk80sq9Rb3ZWgipU8BqFQVmRl3HLSgDv7bQwzyT0xTYcjNo0B/Ao1MiabTqxN+ZopExGYs5ubmH/Dkq7DtDkOqWQBHVfQtEzT1tbpf+oAjLba6Es15pXXoqZsdF3/fhhXP8FZj/1G0k5xBBrUw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.007398, 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 Thu, Apr 25, 2024, Michael Roth wrote: > On Wed, Apr 24, 2024 at 01:59:48PM -0700, Sean Christopherson wrote: > > On Sun, Apr 21, 2024, Michael Roth wrote: > > > +static int snp_begin_psc_msr(struct kvm_vcpu *vcpu, u64 ghcb_msr) > > > +{ > > > + u64 gpa = gfn_to_gpa(GHCB_MSR_PSC_REQ_TO_GFN(ghcb_msr)); > > > + u8 op = GHCB_MSR_PSC_REQ_TO_OP(ghcb_msr); > > > + struct vcpu_svm *svm = to_svm(vcpu); > > > + > > > + if (op != SNP_PAGE_STATE_PRIVATE && op != SNP_PAGE_STATE_SHARED) { > > > + set_ghcb_msr(svm, GHCB_MSR_PSC_RESP_ERROR); > > > + return 1; /* resume guest */ > > > + } > > > + > > > + vcpu->run->exit_reason = KVM_EXIT_VMGEXIT; > > > + vcpu->run->vmgexit.type = KVM_USER_VMGEXIT_PSC_MSR; > > > + vcpu->run->vmgexit.psc_msr.gpa = gpa; > > > + vcpu->run->vmgexit.psc_msr.op = op; > > > > Argh, no. > > > > This is the same crud that TDX tried to push[*]. Use KVM's existing user exits, > > and extend as *needed*. There is no good reason page state change requests need > > *two* exit reasons. The *only* thing KVM supports right now is private<=>shared > > conversions, and that can be handled with either KVM_HC_MAP_GPA_RANGE or > > KVM_EXIT_MEMORY_FAULT. > > > > The non-MSR flavor can batch requests, but I'm willing to bet that the overwhelming > > majority of requests are contiguous, i.e. can be combined into a range by KVM, > > and that handling any outliers by performing multiple exits to userspace will > > provide sufficient performance. > > That does tend to be the case. We won't have as much granularity with > the per-entry error codes, but KVM_SET_MEMORY_ATTRIBUTES would be > expected to be for the entire range anyway, and if that fails for > whatever reason then we KVM_BUG_ON() anyway. We do have to have handling > for cases where the entries aren't contiguous however, which would > involve multiple KVM_EXIT_HYPERCALLs until everything is satisfied. But > not a huge deal since it doesn't seem to be a common case. If it was less complex overall, I wouldn't be opposed to KVM marshalling everything into a buffer, but I suspect it will be simpler to just have KVM loop until the PSC request is complete. > KVM_HC_MAP_GPA_RANGE seems like a nice option because we'd also have the > flexibility to just issue that directly within a guest rather than > relying on SNP/TDX specific hcalls. I don't know if that approach is > practical for a real guest, but it could be useful for having re-usable > guest code in KVM selftests that "just works" for all variants of > SNP/TDX/sw-protected. (though we'd still want stuff that exercises > SNP/TDX->KVM_HC_MAP_GPA_RANGE translation). > > I think we'd there is some potential baggage there with the previous SEV > live migration use cases. There's some potential that existing guest kernels > will use it once it gets advertised and issue them alongside GHCB-based > page-state changes. It might make sense to use one of the reserved bits > to denote this flavor of KVM_HC_MAP_GPA_RANGE as being for > hardware/software-protected VMs and not interchangeable with calls that > were used for SEV live migration stuff. I don't think I follow, what exactly wouldn't be interchangeable, and why? > If this seems reasonable I'll give it a go and see what it looks like. > > > > > And the non-MSR version that comes in later patch is a complete mess. It kicks > > the PSC out to userspace without *any* validation. As I complained in the TDX > > thread, that will create an unmaintable ABI for KVM. > > > > KVM needs to have its own, well-defined ABI. Splitting functionality between > > KVM and userspace at seemingly random points is not maintainable. > > > > E.g. if/when KVM supports UNSMASH, upgrading to the KVM would arguably break > > userspace as PSC requests that previously exited would suddenly be handled by > > KVM. Maybe. It's impossible to review this because there's no KVM ABI, KVM is > > little more than a dumb pipe parroting information to userspace. > > It leans on the GHCB spec to avoid re-inventing structs/documentation > for things like Page State Change buffers, but do have some control > as we want over how much we farm out versus lock into the KVM ABI. For > instance the accompanying Documentation/ update mentions we only send a > subset of GHCB requests that need to be handled by userspace, so we > could handle SMASH/UNSMASH in KVM without breaking expectations (or if > SMASH/UNSMASH were intermixed with PSCs, documentation that only PSC > opcodes could be updated by userspace). > > But I'm certainly not arguing it wouldn't be better to have a > guest-agnostic alternative if we can reach an agreement on that, and > KVM_HC_MAP_GPA_RANGE seems like it could work. Yeah, I want to at least _try_ to achieve common ground, because the basic functionality of all this stuff is the exact same.