Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1122781rwb; Fri, 13 Jan 2023 08:11:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXsMkuZvdKbvEFjdmHiUbgcOFZ1IBvy/HsBe08z3c5yk6PikTn5+QfmY+NksmMFiuIrE3tM4 X-Received: by 2002:a17:90b:344b:b0:229:3f14:8bdf with SMTP id lj11-20020a17090b344b00b002293f148bdfmr229580pjb.14.1673626267655; Fri, 13 Jan 2023 08:11:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673626267; cv=none; d=google.com; s=arc-20160816; b=seKBVzDH8wz/hcqrUgo6OoLNx0zZe550FM9JX6wPPQWXs2rPStL51kjMFxMXkC237W Klq5PVAEJSunjgrd5O8ectJumGTYq64BhFHJxp5jUKlCkN7z9uhrEqD5pDGjpfVZ69UC UKIIBNBToUmdu3Ki5mfaTGecOt6btqXs/ZSF2iyLPzN5cN7O1ZxwC5Iu37Pcf7+QFbJz v44zPWFqZ5aPUTGAtKjD+VkYsVT8uzM7baE6+/OUZb11cokq8DXSY9bvJ2cRMzovl7NH a2s01OqYAfrPLssGokJS8MoDZ3LDsItozKtMSL7QD438uB5SXXt7OtFZhL0f5mkVcyiO Jj3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wobIjMJNqTwtr3bYoELqDsKPAwD1PC9Q+itWmni1C6o=; b=1KWYMVipJm3s2bH6QuwTtYUCxQjEEvqCpIHwjDx0Gc+vECm+UkdE2L7iD2DDR/UG6X QAJrcKeiATGM1lTFj1x/5n9ykJ0BaTZrd4APj9ocQaAZRjoSgiJ/avP1CfIQgYZFdBo4 4ojSIl1fhpffhb+fnpqYg8Jyom2R7R++TH/U/jegMVDXZYD0a/Qi7ac4CtaAbgEa+x18 nUJgmVKafHvV0na6Ld0PDEktRUy/+4jyY0RiHNg0fgxuE0uvcavp/LFH9SyMLHDOV342 9Dh8jkyBxOjWHaRmWJuhQV9q3GMerLGS7lVnLD5oI7xwaxQgZT7RxuyO6+eZqsz+DkIs k4ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=b63RB6SU; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kk14-20020a17090b4a0e00b00213b2bb261asi22430232pjb.33.2023.01.13.08.10.43; Fri, 13 Jan 2023 08:11:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=b63RB6SU; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230177AbjAMP57 (ORCPT + 99 others); Fri, 13 Jan 2023 10:57:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230366AbjAMP5g (ORCPT ); Fri, 13 Jan 2023 10:57:36 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 578D690E54 for ; Fri, 13 Jan 2023 07:49:04 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id u1-20020a17090a450100b0022936a63a21so932863pjg.4 for ; Fri, 13 Jan 2023 07:49:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; 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=wobIjMJNqTwtr3bYoELqDsKPAwD1PC9Q+itWmni1C6o=; b=b63RB6SUcCzsN6y8LRPVghJm6iLrFxEo37MywBuf7UMlj+FVwXhZZe4YLNQobeby9f 5Y7aa0MQGskyI2wvFHZz+jDqS363pC0Dz1i7oI/i6JDA6Xndz8H2Uyj6ctnHzV51E6/E w792bLZupviwtara97i1v6aHHvJ6p1tQzOr0T7doUpDitcCzKuM5r010rVTnPFIm3Bog RLbnXBcBp5mJBlujcwZJ1eZjCw7yBPrDxzjHsG8vRZXjN1VQLLh9sN8DhDoY0Ki7pAkB 2wQNZMUUctFpcWq/t8PpsJAki9xOcJ8zX1OD7H8Ltkbbcch0m4LNTv2NTDyZ6IZqe46O RhDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=wobIjMJNqTwtr3bYoELqDsKPAwD1PC9Q+itWmni1C6o=; b=HEPiFXpQaeNJMmVrBQU+vEkhoqIz+GNtcMGR401I4AXnbLdp/VDgeyr5Mv5gxFjvcI txRivcI0tOjkqWL4t96dWl72tBoXiZid9YL6+NwL9+zalOrNN9WY+tWuxsG5ecTD5Rum qWOVUT5QEaepb/HbqDhLqprzONB58HgCQr55TVD/450ul/tX4GNa5QeQm5SiR17JhwKh R4mmj6mntiujXydAY4jGQWkfKIwHFvStbHCW71cBRYzn9nE2KAMYxQGio/Ld9JQJFFkN 6k+oLQ+EZe5B4pm7y/FKW1z23iJzk9LDB32diTr0tjP8jRsAsIgmNsiI5fPrV3pQzJsO 3nWQ== X-Gm-Message-State: AFqh2kqDFsF0UfBo+JzeHw7Rr1ycvR0WoanMpnyOep6m/Jskl+8mCwuy J9Trha1iObCtHYMkQGLjRc0DRg== X-Received: by 2002:a17:90a:fd12:b0:226:5758:a57f with SMTP id cv18-20020a17090afd1200b002265758a57fmr1478484pjb.2.1673624943743; Fri, 13 Jan 2023 07:49:03 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id nv7-20020a17090b1b4700b00212cf2fe8c3sm2732462pjb.1.2023.01.13.07.49.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 07:49:03 -0800 (PST) Date: Fri, 13 Jan 2023 15:48:59 +0000 From: Sean Christopherson To: Borislav Petkov Cc: Michael Roth , 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, wanpengli@tencent.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, vbabka@suse.cz, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, dgilbert@redhat.com, jarkko@kernel.org, ashish.kalra@amd.com, harald@profian.com Subject: Re: [PATCH RFC v7 04/64] KVM: x86: Add 'fault_is_private' x86 op Message-ID: References: <20221214194056.161492-1-michael.roth@amd.com> <20221214194056.161492-5-michael.roth@amd.com> <20230105024256.ptujtjgzcdmpakoa@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, Jan 13, 2023, Borislav Petkov wrote: > On Wed, Jan 04, 2023 at 08:42:56PM -0600, Michael Roth wrote: > > Obviously I need to add some proper documentation for this, but a 1 > > return basically means 'private_fault' pass-by-ref arg has been set > > with the appropriate value, whereas 0 means "there's no platform-specific > > handling for this, so if you have some generic way to determine this > > then use that instead". > > Still binary, tho, and can be bool, right? > > I.e., you can just as well do: > > if (static_call(kvm_x86_fault_is_private)(kvm, gpa, err, &private_fault)) > goto out; > > at the call site. Ya. Don't spend too much time trying to make this look super pretty though, there are subtle bugs inherited from the base UPM series that need to be sorted out and will impact this code. E.g. invoking kvm_mem_is_private() outside of the protection of mmu_invalidate_seq means changes to the attributes may not be reflected in the page tables. I'm also hoping we can avoid a callback entirely, though that may prove to be more pain than gain. I'm poking at the UPM and testing series right now, will circle back to this and TDX in a few weeks to see if there's a sane way to communicate shared vs. private without having to resort to a callback, and without having races between page faults, KVM_SET_MEMORY_ATTRIBUTES, and KVM_SET_USER_MEMORY_REGION2. > > This is mainly to handle CONFIG_HAVE_KVM_PRIVATE_MEM_TESTING, which > > just parrots whatever kvm_mem_is_private() returns to support running > > KVM selftests without needed hardware/platform support. If we don't > > take care to skip this check where the above fault_is_private() hook > > returns 1, then it ends up breaking SNP in cases where the kernel has > > been compiled with CONFIG_HAVE_KVM_PRIVATE_MEM_TESTING, since SNP > > relies on the page fault flags to make this determination, not > > kvm_mem_is_private(), which normally only tracks the memory attributes > > set by userspace via KVM_SET_MEMORY_ATTRIBUTES ioctl. > > Some of that explanation belongs into the commit message, which is a bit > lacking... I'll circle back to this too when I give this series (and TDX) a proper look, there's got too be a better way to handle this.