Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp819891rwi; Thu, 27 Oct 2022 07:59:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6THcB50aQHK7d6WnuUN+juXuiuPq72LwDOtB68hjihIYuMVZzmKAMwSuWBALDyV0M4k/mI X-Received: by 2002:a05:6402:448b:b0:43b:5ec6:8863 with SMTP id er11-20020a056402448b00b0043b5ec68863mr45445134edb.377.1666882767434; Thu, 27 Oct 2022 07:59:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666882767; cv=none; d=google.com; s=arc-20160816; b=ir5SU29x+T0DCv62uOFlMJemkKuM5W0e1mjSwJ0NUNjKJJu6RgaKfmuoc4BK4rghpt MgqZKOa3vOlMCS3/NI/WtTdcSatlyIu+RBWRWKbqP75cqX20xHrg5qwM94cBU05Czb3r CIiVexXkZW3GEnoaS3IEK6ZFBz8F+1fekzFbOknu5Fk+PRl+dZe3qqYeUXp/NiduR1NR 662T5hnJh4tsv2wcWwCZl5AxgJKAcQo1+dcM9kg9vJRNFAECXZRN5HqmkQwr+oSLO/2r ep1pSyQfV5z/J3yVAKoHioe7LpRTvbzSqpsrXGa0uN6TeUfXOhqdI6H5Zmr+OCQbnC0j dSsg== 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=UwTsZJHpAarkVCfMmsk/OcucFJNCKaSnInJ8QxuSXZU=; b=ffcs3KzKyANWifUND0URkx/SbkFlFt879oXGeZO3P1Ml+ZzFCz3qa+sBBy62KAG86B td7aK0ug7w6tusqpdUCI26CfxPywgNxlcLZ5kCaLoiPeIvcNT9yIfLkqj35pBR6O6n9N 4s11XJon0VHDqakMTVFqHlHAy+T2ulm6wE2r04FNfWbVgegqEsgukrQprBrU4ysnPjaS v8eIB195Gzwi5zII1ut0eisjONBS+b9SlQoNWnqRoDF8+N7s5EUkZrwXnniB33zs768P I2b1Op/G1sD6gZTVKnJ0W13VF8gPKMVmTo1ShgVNbf3OmXBiyP3Wx2Sa0Xh5jynxG7bQ cjYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="sK/ZCJil"; 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 cw19-20020a170906479300b007316ac034acsi1888600ejc.834.2022.10.27.07.59.00; Thu, 27 Oct 2022 07:59:27 -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="sK/ZCJil"; 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 S235688AbiJ0Opj (ORCPT + 99 others); Thu, 27 Oct 2022 10:45:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235765AbiJ0OpU (ORCPT ); Thu, 27 Oct 2022 10:45:20 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74C35915D2 for ; Thu, 27 Oct 2022 07:45:03 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id c2so1699184plz.11 for ; Thu, 27 Oct 2022 07:45:03 -0700 (PDT) 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=UwTsZJHpAarkVCfMmsk/OcucFJNCKaSnInJ8QxuSXZU=; b=sK/ZCJilVFiHN1C0llpajbcmWUhuBQurlUT399lNJzCA0S5H5AVjT9UEHO3rZJ6QnD XHmXOoBts3sIQ077Efrq2L+3+g2e2zApUrPZMO/CqimWYKvcZ76QrOLwmpHo8UEtV3aP 4u/64rq6qi3zm/WP4EB2sGC8AAgZ144Bes9/ryGoUrzIL6wvWV2fl5+GiHG1/1Nxxi59 T222EcV2+nJo/5p20aqajWU1WHXIJ5H2OjYXx/qq3fTcc3rWdLGsSlh7ud0zN5GQqT9K 3bMw79j+IX73Cwwauwy+3N/n/a2HM3TPVbQ1Rw++8ZJbqNzOn4Vm8j/fEPLiQbhaSsHL HACQ== 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=UwTsZJHpAarkVCfMmsk/OcucFJNCKaSnInJ8QxuSXZU=; b=EQ+rFu4jQi7ixjXINhwe1I/FzhrfVrTd+KlkyXoF1yFUt/1N+8mp/XtnZ+NOf8QfQS ujA4Ul9PBGen/c5rTDwVo4gUcPUq+XXDINOBBfDzQU33ESqX7H9NTWWq6BuPqeu3Pgcb 0wJ/oMHqES+eHcKQNY6lc8qW0cgEjQpGqg/b4MYi4+USzBmmWg6Jz4yGsNJLLFjd288g Z8aFLirp5CBKXpweNaaRcAqp+wRWhnpHmdXH7ay9sKVUjnyY2dF9P6W8+f4T/PaTq+8H MEmeDp/MHruUETATDMaZPvBWB96EzxKf3fn3PXSWYlzq7dNL/1czYtovusrQPz38VWMq c/Vg== X-Gm-Message-State: ACrzQf01R189PvkzSqk4a/QXMR69KNIypxfmpHgowFgSCD0eVTrwpKI1 2OB+ZlHhcJYUoSeJjrDqfghZVg== X-Received: by 2002:a17:902:bc88:b0:185:4421:250 with SMTP id bb8-20020a170902bc8800b0018544210250mr48418471plb.29.1666881902856; Thu, 27 Oct 2022 07:45:02 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id t2-20020a170902e84200b00176dc67df44sm1316925plg.132.2022.10.27.07.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 07:45:02 -0700 (PDT) Date: Thu, 27 Oct 2022 14:44:58 +0000 From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Michal Luczaj , David Woodhouse Subject: Re: [PATCH v2 03/16] KVM: x86: Always use non-compat vcpu_runstate_info size for gfn=>pfn cache Message-ID: References: <20221013211234.1318131-1-seanjc@google.com> <20221013211234.1318131-4-seanjc@google.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=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 On Thu, Oct 27, 2022, Paolo Bonzini wrote: > On 10/13/22 23:12, Sean Christopherson wrote: > > 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. > > I'd rather not introduce additional restrictions in KVM, But KVM already has this restriction. "struct vcpu_info" is always checked for the non-compat size, and as above, "struct vcpu_runstate_info" is checked for the non-compat size during its initialization. > actually easy to avoid this patch by instead enforcing that attributes are > set in a sensible order: I don't care about fixing XEN support, I care about forcing "length" to be immutable in order to simplify the gfn_to_pfn_cache implementation. Avoiding this patch prevents doing that later in this series. > - long mode cannot be changed after the shared info page is enabled (which > makes sense because the shared info page also has a compat version) How is this not introducing an additional restriction? This seems way more onerous than what is effectively a revert. > - the caches must be activated after the shared info page (which enforces > that the vCPU attributes are set after the VM attributes) > > This is technically a userspace API break, but nobody is really using this > API outside Amazon so... Patches coming after I finish testing. It's not just userspace break, it affects the guest ABI as well. arch.xen.long_mode isn't set just by userspace, it's also snapshot when the guest changes the hypercall page. Maybe there's something in the XEN ABI that says the hypercall page can never be changed, but barring that I don't see how to prevent ending up with a misaligned cache due to the guest enabling long mode. int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data) { struct kvm *kvm = vcpu->kvm; u32 page_num = data & ~PAGE_MASK; u64 page_addr = data & PAGE_MASK; bool lm = is_long_mode(vcpu); /* Latch long_mode for shared_info pages etc. */ vcpu->kvm->arch.xen.long_mode = lm;