From patchwork Thu Oct 13 21:12:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 2377 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp483892wrs; Thu, 13 Oct 2022 14:14:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6IyPOGnvxV8PALR3NPOjHC+hcvTTHGrWWa30pJDzwdEyhdMKOfVm8CJgAG01Bp3HOLUynG X-Received: by 2002:a63:5f54:0:b0:462:1149:f3b3 with SMTP id t81-20020a635f54000000b004621149f3b3mr1579319pgb.445.1665695678530; Thu, 13 Oct 2022 14:14:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665695678; cv=none; d=google.com; s=arc-20160816; b=iyp7RUJdYZUI97dq8mGoHM/0k2p6ahauQZIKqHS3MPjVCcBcXxhPP0h8q9SYMEo6Z5 UvTG0zh+k0eyJceD8ahB/yFaxwl0/kRgh59exqpJfTkDHAbAMQbxhiy2KndJ/F8BKV3u izIcjEho0w5iMySSi7DmalVYnVHr9pShNa9BOhvRTSIk5dxURgkbaVfWPXcExvXlVDe8 CSQVlcOocPk2krT2VNZeQiU9eOPOBnuRKCAGg2CFqqfyMNinLONnQefxaxo7tmkB9OwJ 5HDo3sRBIhMa3ZbDVuzV13b47vUUIVJeSeaVvXLEEHhfTiLDwYovObjSjOf2D5Hjn00b /2XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=dWPjjwmCXdw1FoLWbTCqb8PkUleSoznDfVrorISf0Bs=; b=lksa5oo0HQpWqgBMKWoecSlkRaEjXhrKIz0RLcn5SNPeiuGpwMB7hDNbG+PKr9TbKz YHzkKH4OdJ1tp3o+gwX5hRh8Vk1+O27aD4z4CHp9wyHd4UMhrBmhKNx/qfWhWMOUSvU3 QN1/IL0rdurJdAFzmWBwY712wPGCGZ69EWz5JnlhWvFIMtmRh9K8fAgVzAsvCchSj76n rB2XDWD/N99NiENv3fYgB7c7IqSvY/wH3mYdBJWkcJVNdjgBZRlL0BxHbb/Zr1yyz1ma pzeVLXdWIn27vtmQmXfGAZ1FaLkm7H8G5g58xVOpcPJG83zw7mnZRIrjGxAaf7NnG6JB Cl6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Wl3SxD4R; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b27-20020a631b1b000000b0045a3e1d1a6csi508268pgb.712.2022.10.13.14.14.25; Thu, 13 Oct 2022 14:14:38 -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=20210112 header.b=Wl3SxD4R; 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 S230175AbiJMVNp (ORCPT + 99 others); Thu, 13 Oct 2022 17:13:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbiJMVNV (ORCPT ); Thu, 13 Oct 2022 17:13:21 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93EF4191D7A for ; Thu, 13 Oct 2022 14:13:05 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id y65-20020a25c844000000b006bb773548d5so2573887ybf.5 for ; Thu, 13 Oct 2022 14:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=dWPjjwmCXdw1FoLWbTCqb8PkUleSoznDfVrorISf0Bs=; b=Wl3SxD4RgiI8mdPWO8AkxLNNNuFvmx2TVKUslqBgYcFOtlxKo0PibzHbprgwD8PCQH oq2O2wmIg5XJC70e4y7GFFVrlusSXIq4WR8SveMxveZzg0/6WISqHpZ7OzBkjr01nnp7 C6uTtRPcGcj5EF+MFcNS3KIOsZAX3AR665gsokStcFaoOmibFpyvlUqT4tzvPCCyECxs lpfUQE8m3YQVfaZP6hMuCSAug86mpg81Q/U0VR/UF1XvD1AAX+FStgqMrwKT8N4FNF6y lcR5IGwRUJE7UaFfSWZucL1k1lLGHEBhkfck+fYHsFX0SS+sCTzjwGEKQ62XJ1/7pdsi UJ+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dWPjjwmCXdw1FoLWbTCqb8PkUleSoznDfVrorISf0Bs=; b=vFNojcWjMkE0q1CRiZMkmZA8bgIVvOyppbwYOb5N2A2jejWTdRSw91Lt0Y3M1lfUjU MUf+aClhJ0L7xHexF4cNVfcWZiH3hSuqgrluHNqotQlKg7GsPxyyuUpD3A8Bn2PTCFSy BH2hdiLCFfYKYSKuHFsmkJdlNJVThJNIRYZTVCPyhmz06UF3WaqqdY+r6nHnkOBINK/C 1IVlSaWcK3iyhGZlsKfoQaeAYkhzawdHHTJKF2LCpgF1mM3mf7I5bHJuZypTTkSY/l12 tFQ+v+tcr6v/3wGKOe8xn8yWdMGmmYTVYuzCDpllHXrBDlbyNa4/2QVv3lb+c4SViEzf 1tug== X-Gm-Message-State: ACrzQf26NvmPWEt0TtoOc1g7fPV044b924n+dX5Ye6gEgd6/wOK1yEwP JRdKzYIz731MjIBxUY1WOPZkVuEf4KU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:bc4b:0:b0:6bc:a469:468c with SMTP id d11-20020a25bc4b000000b006bca469468cmr1922360ybk.199.1665695564234; Thu, 13 Oct 2022 14:12:44 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 13 Oct 2022 21:12:21 +0000 In-Reply-To: <20221013211234.1318131-1-seanjc@google.com> Mime-Version: 1.0 References: <20221013211234.1318131-1-seanjc@google.com> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog Message-ID: <20221013211234.1318131-4-seanjc@google.com> Subject: [PATCH v2 03/16] KVM: x86: Always use non-compat vcpu_runstate_info size for gfn=>pfn cache From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Michal Luczaj , David Woodhouse 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,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746608512263343525?= X-GMAIL-MSGID: =?utf-8?q?1746608512263343525?= Always use the size of Xen's non-compat vcpu_runstate_info struct when checking that the GPA+size doesn't cross a page boundary. Conceptually, using the current mode is more correct, but KVM isn't consistent with itself as kvm_xen_vcpu_set_attr() unconditionally uses the "full" size when activating the cache. More importantly, prior to the introduction of the gfn_to_pfn_cache, KVM _always_ used the full size, i.e. allowing the guest (userspace?) to use a poorly aligned GPA in 32-bit mode but not 64-bit mode is more of a bug than a feature, and fixing the bug doesn't break KVM's historical ABI. Always using the non-compat size will allow for future gfn_to_pfn_cache clenups as this is (was) the only case where KVM uses a different size at check()+refresh() than at activate(). E.g. the length/size of the cache can be made immutable and dropped from check()+refresh(), which yields a cleaner set of APIs and avoids potential bugs that could occur if check() where invoked with a different size than refresh(). Fixes: a795cd43c5b5 ("KVM: x86/xen: Use gfn_to_pfn_cache for runstate area") Cc: David Woodhouse Signed-off-by: Sean Christopherson --- arch/x86/kvm/xen.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index b2be60c6efa4..9e79ef2cca99 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -212,10 +212,7 @@ void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, int state) if (!vx->runstate_cache.active) return; - if (IS_ENABLED(CONFIG_64BIT) && v->kvm->arch.xen.long_mode) - user_len = sizeof(struct vcpu_runstate_info); - else - user_len = sizeof(struct compat_vcpu_runstate_info); + user_len = sizeof(struct vcpu_runstate_info); read_lock_irqsave(&gpc->lock, flags); while (!kvm_gfn_to_pfn_cache_check(v->kvm, gpc, gpc->gpa,