Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp114030pxj; Wed, 26 May 2021 17:50:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUia3g2oocbNZAKxWFiTOUVfWApdEsbPY5hw8wSGWEhXyR7+bn9r4RvtOvPOHaVcT1FrFT X-Received: by 2002:a50:afa3:: with SMTP id h32mr1073361edd.202.1622076611838; Wed, 26 May 2021 17:50:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622076611; cv=none; d=google.com; s=arc-20160816; b=nPegkjTsXsVcV1ajkJBJ12htl8fX86XTczt02PNRuWP1MV6DQai8VVRD2UpIzDaGcI K3+TYOrnMxTzpNyCoSBuKPP8SVyXYD3518hFcJgX9CnyADavorwBLWspZwvvUCCmhzSj rCk177Z38YydHzoiasizb4k6hWSh0qvYMXph/ypTA0rhQ3t5SJi+Qf3TSdtn/RedH9yg 1al2DdCnazXBoAyaE5B5d1fvFb1PeAYGprNJi/EQGtjgWA1j/OzsdINl00DwaavWccab puq4QmSPz+K2X9aSv1t+RsqgvZKJXpe3nQbWcdI8nnTfx3Q+TzfhUeBhm3QOTQJiGC5S wMag== 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=f/rbjKviRvFVX0Te8u4k8bqeiTictapTyzo3WDV9mhs=; b=qN+/oAP0yUg0ASmqzQYIcQaJUKP1oH3fpIUxSwEW6hFuvm4Fjsc1nzyd67AE+rTiRd lGfjyAqHh3Ef9op2e7EoHJXpsj1LOVZ9eUJ1tkj2+JzlVT8mU/YDmv6/mxT4orI7Kg3Q oKIf0upcfIOsYNO5EgqpXPwAupJJmHXiXsaaHTRYU13iuPhRpq3W7fNKu2jPeiLhdAMP Tg4/ikd1Jb5CLYHIJ6i707rvokjZAEmqIofAQ4Dhp4luME6VzISmUa10q+oTjGTFq6fS IfPQAJWPsGwZ5qSIfxmGmnoIUSw4LoQ1pp2JqAFeFWLJsSMm0ILfmTzGOw30p/4rNp4Q y2jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Memse1iJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c4si478236edr.432.2021.05.26.17.49.24; Wed, 26 May 2021 17:50:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Memse1iJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S233333AbhEZVMa (ORCPT + 99 others); Wed, 26 May 2021 17:12:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230499AbhEZVMZ (ORCPT ); Wed, 26 May 2021 17:12:25 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1E30C061574 for ; Wed, 26 May 2021 14:10:52 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id e17so1933621pfl.5 for ; Wed, 26 May 2021 14:10:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=f/rbjKviRvFVX0Te8u4k8bqeiTictapTyzo3WDV9mhs=; b=Memse1iJsMVqDZS5ISUSOn2BjkDNVbGZ2ReD6ANclbxOAXOX3XbY10C31X5O97HFbe D2z7fgKGs44dEuKE+PB4kGr6DjpUXnajPR0vdWaTZiW87hEYN0Y+XZyb2KGUA/Hiy3hX AWWoBXvpL22VtsdZ1z4Dvn0bWZp+48g7MsGEyuVdGdSTvb4vZN3JUb4V0fm5It7dFlHp IlRlVf5JaL5yXltVC48qFKg5rgvIZ/Yob9p2R8j36IW6PvI2A7kCqhKxhQebVfrMSu/+ nSZ1Ppqy7V6fkzjvXCfj1aSgTtOLlufuXsdJ0TFgC+Vfu7PLdQd+ch5HBc1fdteiB+z2 /Z5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=f/rbjKviRvFVX0Te8u4k8bqeiTictapTyzo3WDV9mhs=; b=J0kEHdl2EKw7AIPB/x5G7/503IJ/a0X8IF5T17++Em/32m2/xpQrlv6eNmHcUljgjs 12LZyos9nH38n9zZ0bOVlKq37GF81J17z+A6G/u2uvCzgidtMFsRCY739I7mFDMxclIo CzvdR0Kvb1/iEWmjKsRm5mxq+wwXP5rpjzdgTEDE7iA3adX3eUPmAIyIu/twSM4D5mPR gQXVr7jfvpELw2MAs8bishWq0cnLVMsoNtxsCKQ4t2oPbT01TK26pwS1CI1+eOBUsxMe czZo/39h6JuTKLoxo/wVYGgk/25qqfNPd2XkLqmIs8TBP9KD1elQFqjTGfDvRCH8+wvp HedQ== X-Gm-Message-State: AOAM5315brg/+acEwS2eL10rT3Ggt9M4o9Aj+Qdomh22E9tvmWhJUOJC 1boFKE+WamvNEXozNYjHAgGQkQ== X-Received: by 2002:a65:6a52:: with SMTP id o18mr392699pgu.177.1622063452156; Wed, 26 May 2021 14:10:52 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id o7sm9219pgs.45.2021.05.26.14.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 14:10:51 -0700 (PDT) Date: Wed, 26 May 2021 21:10:47 +0000 From: Sean Christopherson To: Isaku Yamahata Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , isaku.yamahata@gmail.com Subject: Re: [RFC PATCH 00/10] KVM: x86/mmu: simplify argument to kvm page fault handler Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 20, 2021, Isaku Yamahata wrote: > This is a preliminary clean up for TDX which complicates KVM page fault > execution path. Ooh, a series to complicate the page fault path! ;-) Grammatical snarkiness aside, I'm all in favor of adding a struct to collect the page fault collateral. Overarching feedback: - Have kvm_mmu_do_page_fault() handle initialization of the struct. That will allow making most of the fields const, and will avoid the rather painful kvm_page_fault_init(). - Pass @vcpu separately. Yes, it's associated with the fault, but literally the first line in every consumer is "struct kvm_vcpu *vcpu = kpf->vcpu;". - Use "fault" instead of "kpf", mostly because it reads better for people that aren't intimately familiar with the code, but also to avoid having to refactor a huge amount of code if we decide to rename kvm_page_fault, e.g. if we decide to use that name to return fault information to userspace. - Snapshot anything that is computed in multiple places, even if it is derivative of existing info. E.g. it probably makes sense to grab write/fetch (or exec). E.g. I'm thinking something like struct kvm_page_fault { const gpa_t cr2_or_gpa; const u32 error_code; const bool write; const bool read; const bool fetch; const bool prefault; const bool is_tdp; gfn_t gfn; hva_t hva; int max_level; kvm_pfn_t pfn; bool map_writable; }; int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault); static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u32 err, bool prefault) { struct kvm_page_fault fault = { .cr2_or_gpa = cr2_or_gpa, .error_code = err, .write = err & PFERR_WRITE_MASK, .fetch = err & PFERR_FETCH_MASK, .perm = ... .rsvd = err & PFERR_RSVD_MASK, .is_tdp = vcpu->arch.mmu->page_fault == kvm_tdp_page_fault, ... }; #ifdef CONFIG_RETPOLINE if (likely(fault.is_tdp)) return kvm_tdp_page_fault(vcpu, &fault); #endif return vcpu->arch.mmu->page_fault(vcpu, &fault); }