Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp20946134rwd; Thu, 29 Jun 2023 08:58:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlGGJnkfFwl/xgdT3Ju3yg8A9y19aGLTYb7JUIiAL0ABxG8o2mGwSPj5xsI6vx4F92F/5X8q X-Received: by 2002:a05:6a00:cc3:b0:679:c1c9:1d34 with SMTP id b3-20020a056a000cc300b00679c1c91d34mr429267pfv.18.1688054317440; Thu, 29 Jun 2023 08:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688054317; cv=none; d=google.com; s=arc-20160816; b=rCIRW0Gf+T6OXj4WE9b5xioL8nFSDHT6P9ibuhJpK0xAIOw+SydPv22bntpClvK9P3 Lq7swa2S1DIyKVy1fuHB9bMFAKkHIXuycwtA7dFc8TUa3rTm+661hlvP+th4/9I++0ds OlL+wLuYVbkgUJScXs92crK9dSOJzNf/EMIQbQj1M3Ikx2rI33MV23azXlsBCQGDLZHy 40YXpEGx3+up2CM919CqVenMmjT8wCENm91S8gC/uYMmC7882oxbsFmDn9KZ2afTwAXy wnrrW4SpsRsP/8cnxR9k3JrqHc3Xim5O6B4kbahTpneK4xuYOVSn6sny9oaMqP5YDLEt YMFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:dkim-signature; bh=7TGC0VGQH5Yr0gxepslsru//MnVacowxczeMG+0ih5U=; fh=CYEGVF1+lfXmckMmhg7oJXL9+RRgoDHyMSQ9SyWHjGY=; b=plrrVn3NBn50aY8m5lhk6jCW+8L2sfwRVycsxzEFwXUF+7ZOGIvRBqUTvCoPrWVtxD uzIQxrVNnSPhP/9hrZwK+JjEnMbJjNhGM45YIArNNVs24WzorqNGZYJJcKrEdh8K3SlM jwLh3E/hPWLFRAFsPYcS9aGWzqqx9wnBUKoXS2oDK10tek5neIOYId2/SMj8Zo/V9V5T hg4Nn3Ang8Fi8UKYbtEvN8CpOrUQaBvnw3hjNYv7qzA4Tg376A1rFE1d7eoPx57EBgiR NpPW9NR0mZgglcU5RB6phpHbhadriiADsRNA3ARAD5HKEEeTUBaGhqeuI0XJELh4s2jv cHvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=uIFm08lW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c22-20020a056a00249600b00666b0317ecasi11224704pfv.60.2023.06.29.08.58.22; Thu, 29 Jun 2023 08:58:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=20221208 header.b=uIFm08lW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232541AbjF2PQw (ORCPT + 99 others); Thu, 29 Jun 2023 11:16:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232209AbjF2PQr (ORCPT ); Thu, 29 Jun 2023 11:16:47 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A4DE1BD1 for ; Thu, 29 Jun 2023 08:16:45 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-c0d62f4487cso652196276.0 for ; Thu, 29 Jun 2023 08:16:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688051805; x=1690643805; 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=7TGC0VGQH5Yr0gxepslsru//MnVacowxczeMG+0ih5U=; b=uIFm08lWh354I3Yb9tpSwcd/lD37ejiz/aCL5wO1kFc5Ja7IMAEB1ZSZGhggEMCr+t XPlBhlePXtWobpv6scIZE66hOihfqD98wraX24uBzW6weu93/0bGUFdNcHOg/9Hr+kB7 tJIO8EPiuQ25OtnSTaoJRFsQ6K7zxFJcROu18Vkqmd7NCCkHYpV25twRhFFuKh321+oc e6oAvwWKRR2wyrvtxH5+AVlLxrBMrNkdSdU1SfcSaGPNN9rbOo9oAsEhxC734AqnKxBc JT7oUS5wf4a4xrsxvVjIHWcyYCNMVoP5UbsfA2yOC4M5ti1xsgf2SHYvJzKDcMCMpih7 /Fvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688051805; x=1690643805; 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=7TGC0VGQH5Yr0gxepslsru//MnVacowxczeMG+0ih5U=; b=eKH76K/ob/LlXTwDXVZQNsqUXOsllBPy+8WGtdWypym47pYLEMwT6OKNng8lrQXqJG i0YYdiIbgR0zul23deqILFRZ5ONQzaxd4p5xgkPoBOXh11UZJ1EMTsnthgrAAm1rXf5l dlijiZkPiI8SSaMiNnbBUEqdAhjvpbNHaRCCFXIMFJYYoGRHKsmkQ+xyJORM6Kt5uYBa aAXad81AwZL0AMJemNRn9Pc97G3KyXyKajVRfawKZOHr4iscKYCxSD2yBdxVjc00n2CD UeX4Dthk6Gvf4QZbxA9h3EZc7DixF6GuCaIohwseYR9NJB6IAYFYYs68EBwR6IljINfm xVlQ== X-Gm-Message-State: ABy/qLaGTaciDrbxq8azlgSCGWZzbibrduiopgbjGAZJ3EHEAE6v5MkQ yeNQhH8lsErdCHk4SOdAXSdZsbjkX/I= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:3610:0:b0:c15:cbd1:60d6 with SMTP id d16-20020a253610000000b00c15cbd160d6mr1647yba.5.1688051804809; Thu, 29 Jun 2023 08:16:44 -0700 (PDT) Date: Thu, 29 Jun 2023 08:16:43 -0700 In-Reply-To: Mime-Version: 1.0 References: <20230606091842.13123-1-binbin.wu@linux.intel.com> <20230606091842.13123-5-binbin.wu@linux.intel.com> Message-ID: Subject: Re: [PATCH v9 4/6] KVM: x86: Introduce untag_addr() in kvm_x86_ops From: Sean Christopherson To: Binbin Wu Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, chao.gao@intel.com, kai.huang@intel.com, David.Laight@aculab.com, robert.hu@linux.intel.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_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-kernel@vger.kernel.org On Thu, Jun 29, 2023, Binbin Wu wrote: > On 6/28/2023 8:15 AM, Sean Christopherson wrote: > > On Tue, Jun 06, 2023, Binbin Wu wrote: > > Use the perfectly good helper added earlier in the series: > >=20 > > cr3_lam =3D kvm_get_active_lam_bits(); > Good suggestion. Thanks. >=20 > >=20 > > That has the added bonus of avoiding a VMREAD of CR3 when LAM is disabl= ed in CR4. > Why? I don't get the point. Sorry, typo on my end. When LAM is disabled in guest CPUID, not CR4. > > > +void vmx_untag_addr(struct kvm_vcpu *vcpu, gva_t *gva, u32 flags) > > Rather than modify the pointer, return the untagged address. That's mo= re flexible > > as it allows using the result in if-statements and whatnot. That might= not ever > > come into play, but there's no good reason to use an in/out param in a = void > > function. > In earlier version, it did return the untagged address. > In this version, I changed it as an in/out param to make the interface > conditional and avoid to add a dummy one in SVM. > Is it can be a reason? Hmm, no. You can achieve the same by doing: struct kvm_vcpu *vcpu =3D emul_to_vcpu(ctxt); if (!kvm_x86_ops.get_untagged_addr) return addr; return static_call(kvm_x86_get_untagged_addr)(vcpu, addr, flags); > > gva_t vmx_get_untagged_addr(struct kvm_vcpu *vcpu, gva_t gva, > > unsigned int flags) > > { > > unsigned long cr3_bits, cr4_bits; > > int lam_bit; > >=20 > > if (flags & (X86EMUL_F_FETCH | X86EMUL_F_BRANCH_INVLPG | X86EMUL_F_IMP= LICIT)) > Thanks for the suggestion. Overall, it looks good to me. >=20 > Suppose "X86EMUL_F_BRANCH_INVLPG "=C2=A0 should be two flags for branch a= nd > invlpg, right=EF=BC=9F Yeah, typo again. Should just be X86EMUL_F_INVLPG, because unlike LASS, LA= M ignores all FETCH types. > And for LAM, X86EMUL_F_IMPLICIT will not be used because in the implicit > access to memory management registers or descriptors, > the linear base addresses still need to be canonical and no hooks will be > added to untag the addresses in these pathes. > So I probably will remove the check for X86EMUL_F_IMPLICIT here. No, please keep it, e.g. so that changes in the emulator don't lead to brea= kage, and to document that they are exempt. If you want, you could do WARN_ON_ONCE() for the IMPLICIT case, but I don't= know that that's worthwhile, e.g. nothing will go wrong if KVM tries to untag an implicit access, and deliberately avoiding the call make make it annoying t= o consolidate code in the future.