Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2423612rda; Wed, 25 Oct 2023 02:11:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/w32QBRdL/7iw/c7C72K6IRd60NBwd1UfGjhgyHDbU3Wz7rUOOeNVVMo4hJRVq0k1xKAc X-Received: by 2002:a05:622a:148c:b0:412:2ff3:50b2 with SMTP id t12-20020a05622a148c00b004122ff350b2mr18431931qtx.35.1698225098854; Wed, 25 Oct 2023 02:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698225098; cv=none; d=google.com; s=arc-20160816; b=eMP6KrVoAe7Oydbr9/lIKNJj/UJJ0cnTqTgFQOspRWgYHPmv4CDtcUpBQjxcTrkNOu X/AdQLDMSsZDxFo+bb+2vlRXwCPn6hCyvny6O4tqcTfaS9qIWS3Gsoe3xDYi2dZXGrWm nE374tX/4nhFgFABBBAMlegAyXYPdQNuNs/8Em4JzuhdZ8Qz+IRXTl+oxZ4h/FygDmxX lB4nJ+5vd7aP+CeOZogoJOrZIk+7YwleEqNbxQq7oOXgmvOml4wwd1WXMkxDFhdmrj+E uiz84jcM+93kzklcNF4vTfpQ96U2PfBZEe4DZsfkkOXaTqL9SDo4ie9U8iZUCXSz2KLQ QUIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=/FytEg3M9eI+HiGC4+Q1c4/7OpeWyHjtYgtZUMsVmeo=; fh=zXY/rQ4rpgxJvtzkp5dKF1OFYHzTHKs3+bpVzaC87EU=; b=YmNNB0UaQpNZpjwl7fT5ke1yn/ldGMbXQf5AjT50WwqETRRSJANf8SZAIVNatdRy1k zkt+PbV/6dJueoamdImdHcK1aWfcfKyp77lJjA8/xgzfyPQgoPZtg8qVQURdiYe+WRGD bccQONjyTqBOuVsR91q0R8kAN3YAT99fuaaKomPW2gOTbyVDC5dFd0mM2BXf7wu1DnZj pETbLl56EpVvoIFcVuPTpZKHf/Bqf1nXLHzLKDcD8zFaw9VZ5rQKfTO2PNrNYyysJfdE lWythyC4R4wuIv6tYFNmB3VnFWmW8XBmS3neJ7SUAyd+ifLiw6BdWkn0Exlq1aphlZU4 3IwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TpOnb6y2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id j18-20020a819212000000b0059f54066709si10328279ywg.108.2023.10.25.02.11.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 02:11:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TpOnb6y2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 9914C80384F5; Wed, 25 Oct 2023 02:11:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232503AbjJYJLZ (ORCPT + 99 others); Wed, 25 Oct 2023 05:11:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231648AbjJYJLW (ORCPT ); Wed, 25 Oct 2023 05:11:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA2FE138 for ; Wed, 25 Oct 2023 02:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698225037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/FytEg3M9eI+HiGC4+Q1c4/7OpeWyHjtYgtZUMsVmeo=; b=TpOnb6y28M84LFyaJE5iRFSGaiphlp+ik72dF51Y57YBZSUlDvVZ/LRRRtVnSCFkBL5l9v l+j7IJ2GfAP8ahvavjaLkBJ4MRVb5vdvpgcz5z9xk9ziFHtmroO5dWNBKeiZhHAXa0EAgY uZX8dYnbODmzH7CIhqqfijjddsXAki8= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-6flSrF0MMJWKE47u615DNw-1; Wed, 25 Oct 2023 05:10:35 -0400 X-MC-Unique: 6flSrF0MMJWKE47u615DNw-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-533d8a785a5so3744563a12.3 for ; Wed, 25 Oct 2023 02:10:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698225034; x=1698829834; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/FytEg3M9eI+HiGC4+Q1c4/7OpeWyHjtYgtZUMsVmeo=; b=SHCZd5YFPMuRSkxWAiBqD9Ipmc/Kptemv/JiDzKVHIkNgVL6XNKbSwAXYx6tg38Nor PNk7a9YbtTVzGK+EDGombO9Jg4utRLlsdnxtProTMGXExR+3pksa+A1oL56QjICF+PpC EcAkcpB8/zWPxzPL4riyWty6fexkLPFtE1iDL9kQmWHdleAN3ApMoN4LHn2S3eyxvE4s s9F0PNPgmZXxh+9IcbLtdNcWwo4S+bCY9Zz+mTLxOgHA/A9fInE6P+z3tnQexasTGC4+ W91szo5df0tirD3edAXDS3zTw1MJ75DmVP847Kd/rjrGQ2zboXIrwdnaLM9trsKjlBuF 3DsQ== X-Gm-Message-State: AOJu0Yzz/n1tlxHYgxgfFWX7F8PnJor1ZF4xgbhoF4/SoTaqYRynhcUV 7GgGQUxlF7RO40AwcH5yBCUboukLm85R02A24lkDjDXraqPMASZTf5cVLljBJJb+I/eGOLnrsty KpYmvHkuwkGHjQv2cG2H57Jpvnxe65P85 X-Received: by 2002:a05:6402:5202:b0:53e:21f6:d784 with SMTP id s2-20020a056402520200b0053e21f6d784mr14486022edd.8.1698225034067; Wed, 25 Oct 2023 02:10:34 -0700 (PDT) X-Received: by 2002:a05:6402:5202:b0:53e:21f6:d784 with SMTP id s2-20020a056402520200b0053e21f6d784mr14485999edd.8.1698225033756; Wed, 25 Oct 2023 02:10:33 -0700 (PDT) Received: from fedora (g2.ign.cz. [91.219.240.8]) by smtp.gmail.com with ESMTPSA id d8-20020a05640208c800b0053e5a1bf77dsm9103868edz.88.2023.10.25.02.10.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 02:10:33 -0700 (PDT) From: Vitaly Kuznetsov To: Xiaoyao Li , Paolo Bonzini , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Cc: Jonathan Corbet , Wanpeng Li , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xiaoyao Li Subject: Re: [PATCH v2 1/2] x86/kvm/async_pf: Use separate percpu variable to track the enabling of asyncpf In-Reply-To: <20231025055914.1201792-2-xiaoyao.li@intel.com> References: <20231025055914.1201792-1-xiaoyao.li@intel.com> <20231025055914.1201792-2-xiaoyao.li@intel.com> Date: Wed, 25 Oct 2023 11:10:32 +0200 Message-ID: <87a5s73w53.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 25 Oct 2023 02:11:34 -0700 (PDT) Xiaoyao Li writes: > Refer to commit fd10cde9294f ("KVM paravirt: Add async PF initialization > to PV guest") and commit 344d9588a9df ("KVM: Add PV MSR to enable > asynchronous page faults delivery"). It turns out that at the time when > asyncpf was introduced, the purpose was defining the shared PV data 'struct > kvm_vcpu_pv_apf_data' with the size of 64 bytes. However, it made a mistake > and defined the size to 68 bytes, which failed to make fit in a cache line > and made the code inconsistent with the documentation. Oh, I actually though it was done on purpose :-) 'enabled' is not accessed by the host, it's only purpose is to cache MSR_KVM_ASYNC_PF_EN. > > Below justification quoted from Sean[*] > > KVM (the host side) has *never* read kvm_vcpu_pv_apf_data.enabled, and > the documentation clearly states that enabling is based solely on the > bit in the synthetic MSR. > > So rather than update the documentation, fix the goof by removing the > enabled filed and use the separate percpu variable instread. > KVM-as-a-host obviously doesn't enforce anything or consume the size, > and changing the header will only affect guests that are rebuilt against > the new header, so there's no chance of ABI breakage between KVM and its > guests. The only possible breakage is if some other hypervisor is > emulating KVM's async #PF (LOL) and relies on the guest to set > kvm_vcpu_pv_apf_data.enabled. But (a) I highly doubt such a hypervisor > exists, (b) that would arguably be a violation of KVM's "spec", and > (c) the worst case scenario is that the guest would simply lose async > #PF functionality. > > [*] https://lore.kernel.org/all/ZS7ERnnRqs8Fl0ZF@google.com/T/#u > > Suggested-by: Sean Christopherson > Signed-off-by: Xiaoyao Li > --- > Documentation/virt/kvm/x86/msr.rst | 1 - > arch/x86/include/uapi/asm/kvm_para.h | 1 - > arch/x86/kernel/kvm.c | 11 ++++++----- > 3 files changed, 6 insertions(+), 7 deletions(-) > > diff --git a/Documentation/virt/kvm/x86/msr.rst b/Documentation/virt/kvm/x86/msr.rst > index 9315fc385fb0..f6d70f99a1a7 100644 > --- a/Documentation/virt/kvm/x86/msr.rst > +++ b/Documentation/virt/kvm/x86/msr.rst > @@ -204,7 +204,6 @@ data: > __u32 token; > > __u8 pad[56]; > - __u32 enabled; > }; > > Bits 5-4 of the MSR are reserved and should be zero. Bit 0 is set to 1 > diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h > index 6e64b27b2c1e..605899594ebb 100644 > --- a/arch/x86/include/uapi/asm/kvm_para.h > +++ b/arch/x86/include/uapi/asm/kvm_para.h > @@ -142,7 +142,6 @@ struct kvm_vcpu_pv_apf_data { > __u32 token; > > __u8 pad[56]; > - __u32 enabled; > }; > > #define KVM_PV_EOI_BIT 0 > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c > index b8ab9ee5896c..388a3fdd3cad 100644 > --- a/arch/x86/kernel/kvm.c > +++ b/arch/x86/kernel/kvm.c > @@ -65,6 +65,7 @@ static int __init parse_no_stealacc(char *arg) > > early_param("no-steal-acc", parse_no_stealacc); > > +static DEFINE_PER_CPU_READ_MOSTLY(bool, async_pf_enabled); Would it make a difference is we replace this with a cpumask? I realize that we need to access it on all CPUs from hotpaths but this mask will rarely change so maybe there's no real perfomance hit? > static DEFINE_PER_CPU_DECRYPTED(struct kvm_vcpu_pv_apf_data, apf_reason) __aligned(64); > DEFINE_PER_CPU_DECRYPTED(struct kvm_steal_time, steal_time) __aligned(64) __visible; > static int has_steal_clock = 0; > @@ -244,7 +245,7 @@ noinstr u32 kvm_read_and_reset_apf_flags(void) > { > u32 flags = 0; > > - if (__this_cpu_read(apf_reason.enabled)) { > + if (__this_cpu_read(async_pf_enabled)) { > flags = __this_cpu_read(apf_reason.flags); > __this_cpu_write(apf_reason.flags, 0); > } > @@ -295,7 +296,7 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_kvm_asyncpf_interrupt) > > inc_irq_stat(irq_hv_callback_count); > > - if (__this_cpu_read(apf_reason.enabled)) { > + if (__this_cpu_read(async_pf_enabled)) { > token = __this_cpu_read(apf_reason.token); > kvm_async_pf_task_wake(token); > __this_cpu_write(apf_reason.token, 0); > @@ -362,7 +363,7 @@ static void kvm_guest_cpu_init(void) > wrmsrl(MSR_KVM_ASYNC_PF_INT, HYPERVISOR_CALLBACK_VECTOR); > > wrmsrl(MSR_KVM_ASYNC_PF_EN, pa); > - __this_cpu_write(apf_reason.enabled, 1); > + __this_cpu_write(async_pf_enabled, 1); As 'async_pf_enabled' is bool, it would probably be more natural to write __this_cpu_write(async_pf_enabled, true); > pr_debug("setup async PF for cpu %d\n", smp_processor_id()); > } > > @@ -383,11 +384,11 @@ static void kvm_guest_cpu_init(void) > > static void kvm_pv_disable_apf(void) > { > - if (!__this_cpu_read(apf_reason.enabled)) > + if (!__this_cpu_read(async_pf_enabled)) > return; > > wrmsrl(MSR_KVM_ASYNC_PF_EN, 0); > - __this_cpu_write(apf_reason.enabled, 0); > + __this_cpu_write(async_pf_enabled, 0); ... and 'false' here. > > pr_debug("disable async PF for cpu %d\n", smp_processor_id()); > } -- Vitaly