Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp2081917rwb; Fri, 5 Aug 2022 12:56:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR5CTQ2exx/hI8PenQo9kfflDs5PMplTMVd9bF0dFMeaLF2JP1/NslmeMzCKNn+dKrJ1M9lp X-Received: by 2002:a05:6402:48:b0:43a:caa8:756b with SMTP id f8-20020a056402004800b0043acaa8756bmr7742161edu.112.1659729365098; Fri, 05 Aug 2022 12:56:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659729365; cv=none; d=google.com; s=arc-20160816; b=CFl6P+jvxw79MeZV1sEEwt+XsqavJXSk2Bz+n/s9PtYqda8Pd/embqQA/yNzUaS6fG fp03AdTYjJxjlILq3jCNPiEKqvWJP7Ix644xmhWeDJTQ3e5ZPzvTkosf0I2PQJal3wrl uEpY5O2bv5P4tfTvGeq7kVShyOvIostNfmxh0ij1BJ/b+CjAXDqteCwB0Y4x6xDLlKHR ZatH5Jdmw8Zmazznc5EvhocqQ7bR5DYcmzs4/g3RF+EVO+D6lys/5ZcreqFODuj/c1QJ fiFoPWTbaY4fzqHaXyNYU7niENNq6PUcllslEodTPwMsXqJbome5TEm7XlDVR6opHcNW +ZLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0bqeAVxOv1cvt506AIyaShQcLeSdfwwBjFLTn7gNzK4=; b=UUonDoYzaDqB4NpGqU7IIgBPCc0USvf5zwpsIS5849nd7zBEx2ezgZyslgXQUZ1xRd 4Tm5fMfQ22IxdKpXfoBq+XbdXWfyqRz4zkOyAQuSQmRoh6bYaYXw+uGvyo4V/SMWKCVG NCRZ4lw2+zCjf9zFcWO4jn3A+enDfERfmYqO+j8E3lwQZ1Tn4RXPiwRohUafVg5oxKYa zjbgc5GwMR+3zw8HwCCSbThv72zfUcZtA1sPCtvVRlxVJLQQIIPFyly2gNjLlNnOlLTZ PNdJVUDortTr2o5jz93cY1ldgJrIog7t7Tcb8PvRXh6LDjQ2mYDaS3ierx1BsYky+tYc vK/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=f+F1IOVI; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv9-20020a170906b1c900b00726c7fc61dfsi4009727ejb.103.2022.08.05.12.55.39; Fri, 05 Aug 2022 12:56:05 -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=@semihalf.com header.s=google header.b=f+F1IOVI; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241253AbiHETk6 (ORCPT + 99 others); Fri, 5 Aug 2022 15:40:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241443AbiHETky (ORCPT ); Fri, 5 Aug 2022 15:40:54 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E86311805 for ; Fri, 5 Aug 2022 12:40:53 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id c17so4775160lfb.3 for ; Fri, 05 Aug 2022 12:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=0bqeAVxOv1cvt506AIyaShQcLeSdfwwBjFLTn7gNzK4=; b=f+F1IOVIZjUPQzuXQjLojG+pXD/2sSikKxH++DYAxDArMLZIaUoZP8lbDkzAlcjMUE 3W1VS4h7HTzzTgV8Rsi/LHB//SqzkqQmMnYRFk+p6ziWmHaNhHKVonZ9XA3/AE4MwK9I RajpOltnDRXaQ71wGyWRXMWHkU3GeLbwsqgBIKwzfTf41/bYJGWldMdHFUc2Pj1ml54W Ct6J49rpys0VfRvRk2Y6jZ95BcFSOOONBGH9pE/h/2FpmdEh6vH3BckAFsVmkP8CT4mB VfTaB4xrqr7TKe5Zv+rWY706d7g9ZLpEJL6Q7hBB2/gtLGPEpL+GsgEkfiIjln+JgsL9 dsIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=0bqeAVxOv1cvt506AIyaShQcLeSdfwwBjFLTn7gNzK4=; b=WSjXRtT1DT6pEWms0Aqki9VuXBRmJ6Q23fL4rTtiqFss/HanzqRfDFv+Y+a5ogR+J6 yU2KG8boY4UyaEfjy9En98hvYMazoKEGLt+/8PATF5DTfM69S8rVottCPmVNOGrWEY7z LTWTz7zflU0i/NVFzLc6fgn9xsbVhmEhErvSlFeTvj8Cz3TBdxcoldLoR4kwOdK2o91a GFK6P1ECgIgn0WdOKsSounPKYmMwcIEcMAGw+/sKjpuCJVSyE2yyVNEYvnHU8yF34aWa 3eY6ZwvEaGw10F+8vwQSHrZTSu3Y41LY1gbU36Az6WRFiMjxSZ/Qz5CFyqbRYnN/JW2u JmVQ== X-Gm-Message-State: ACgBeo2Sk2pmcL88lPg4rRmzzNFP/5USRG9a8nx88EbqJrYbDFWJ0ln1 S2wkPPQm159nzdI6rJukgwevdA== X-Received: by 2002:a05:6512:1283:b0:48b:9817:ce2b with SMTP id u3-20020a056512128300b0048b9817ce2bmr206194lfs.417.1659728451592; Fri, 05 Aug 2022 12:40:51 -0700 (PDT) Received: from dmaluka.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id o4-20020a056512230400b0048a407f41bbsm560079lfu.238.2022.08.05.12.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 12:40:51 -0700 (PDT) From: Dmytro Maluka To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Eric Auger , Alex Williamson , Rong L Liu , Zhenyu Wang , Tomasz Nowicki , Grzegorz Jaszczyk , upstream@semihalf.com, Dmitry Torokhov , Dmytro Maluka Subject: [PATCH v2 1/5] KVM: x86: Move irq mask notifiers from x86 to generic KVM Date: Fri, 5 Aug 2022 21:39:15 +0200 Message-Id: <20220805193919.1470653-2-dmy@semihalf.com> X-Mailer: git-send-email 2.37.1.559.g78731f0fdb-goog In-Reply-To: <20220805193919.1470653-1-dmy@semihalf.com> References: <20220805193919.1470653-1-dmy@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Currently irq mask notifiers are used only internally in the x86 code for PIT emulation. However they are not really arch specific. We are going to use them in the generic irqfd code, for postponing resampler irqfd notification until the interrupt is unmasked. So move the implementation of mask notifiers to the generic code, to allow irqfd to register its mask notifiers. Note that calling mask notifiers via calling kvm_fire_mask_notifiers() is still implemented for x86 only, so registering mask notifiers on other architectures will have no effect for now. Signed-off-by: Dmytro Maluka --- arch/x86/include/asm/kvm_host.h | 16 ---------------- arch/x86/kvm/irq_comm.c | 33 --------------------------------- arch/x86/kvm/x86.c | 1 - include/linux/kvm_host.h | 15 +++++++++++++++ virt/kvm/eventfd.c | 33 +++++++++++++++++++++++++++++++++ virt/kvm/kvm_main.c | 1 + 6 files changed, 49 insertions(+), 50 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 9217bd6cf0d1..dc76617f11c1 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1198,9 +1198,6 @@ struct kvm_arch { struct kvm_xen_hvm_config xen_hvm_config; - /* reads protected by irq_srcu, writes by irq_lock */ - struct hlist_head mask_notifier_list; - struct kvm_hv hyperv; struct kvm_xen xen; @@ -1688,19 +1685,6 @@ int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3); int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa, const void *val, int bytes); -struct kvm_irq_mask_notifier { - void (*func)(struct kvm_irq_mask_notifier *kimn, bool masked); - int irq; - struct hlist_node link; -}; - -void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq, - struct kvm_irq_mask_notifier *kimn); -void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq, - struct kvm_irq_mask_notifier *kimn); -void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin, - bool mask); - extern bool tdp_enabled; u64 vcpu_tsc_khz(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c index 0687162c4f22..f27e4c9c403e 100644 --- a/arch/x86/kvm/irq_comm.c +++ b/arch/x86/kvm/irq_comm.c @@ -234,39 +234,6 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id) mutex_unlock(&kvm->irq_lock); } -void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq, - struct kvm_irq_mask_notifier *kimn) -{ - mutex_lock(&kvm->irq_lock); - kimn->irq = irq; - hlist_add_head_rcu(&kimn->link, &kvm->arch.mask_notifier_list); - mutex_unlock(&kvm->irq_lock); -} - -void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq, - struct kvm_irq_mask_notifier *kimn) -{ - mutex_lock(&kvm->irq_lock); - hlist_del_rcu(&kimn->link); - mutex_unlock(&kvm->irq_lock); - synchronize_srcu(&kvm->irq_srcu); -} - -void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin, - bool mask) -{ - struct kvm_irq_mask_notifier *kimn; - int idx, gsi; - - idx = srcu_read_lock(&kvm->irq_srcu); - gsi = kvm_irq_map_chip_pin(kvm, irqchip, pin); - if (gsi != -1) - hlist_for_each_entry_rcu(kimn, &kvm->arch.mask_notifier_list, link) - if (kimn->irq == gsi) - kimn->func(kimn, mask); - srcu_read_unlock(&kvm->irq_srcu, idx); -} - bool kvm_arch_can_set_irq_routing(struct kvm *kvm) { return irqchip_in_kernel(kvm); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index e5fa335a4ea7..a0a776f5c42f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11818,7 +11818,6 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) if (ret) goto out_page_track; - INIT_HLIST_HEAD(&kvm->arch.mask_notifier_list); INIT_LIST_HEAD(&kvm->arch.assigned_dev_head); atomic_set(&kvm->arch.noncoherent_dma_count, 0); diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 90a45ef7203b..dd5f14e31996 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -760,7 +760,10 @@ struct kvm { struct kvm_irq_routing_table __rcu *irq_routing; #endif #ifdef CONFIG_HAVE_KVM_IRQFD + /* reads protected by irq_srcu, writes by irq_lock */ struct hlist_head irq_ack_notifier_list; + /* reads protected by irq_srcu, writes by irq_lock */ + struct hlist_head irq_mask_notifier_list; #endif #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) @@ -1581,6 +1584,12 @@ struct kvm_irq_ack_notifier { void (*irq_acked)(struct kvm_irq_ack_notifier *kian); }; +struct kvm_irq_mask_notifier { + void (*func)(struct kvm_irq_mask_notifier *kimn, bool masked); + int irq; + struct hlist_node link; +}; + int kvm_irq_map_gsi(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *entries, int gsi); int kvm_irq_map_chip_pin(struct kvm *kvm, unsigned irqchip, unsigned pin); @@ -1599,6 +1608,12 @@ void kvm_register_irq_ack_notifier(struct kvm *kvm, struct kvm_irq_ack_notifier *kian); void kvm_unregister_irq_ack_notifier(struct kvm *kvm, struct kvm_irq_ack_notifier *kian); +void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq, + struct kvm_irq_mask_notifier *kimn); +void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq, + struct kvm_irq_mask_notifier *kimn); +void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin, + bool mask); int kvm_request_irq_source_id(struct kvm *kvm); void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id); bool kvm_arch_irqfd_allowed(struct kvm *kvm, struct kvm_irqfd *args); diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index 2a3ed401ce46..39403d9fbdcc 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -518,6 +518,39 @@ void kvm_unregister_irq_ack_notifier(struct kvm *kvm, synchronize_srcu(&kvm->irq_srcu); kvm_arch_post_irq_ack_notifier_list_update(kvm); } + +void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq, + struct kvm_irq_mask_notifier *kimn) +{ + mutex_lock(&kvm->irq_lock); + kimn->irq = irq; + hlist_add_head_rcu(&kimn->link, &kvm->irq_mask_notifier_list); + mutex_unlock(&kvm->irq_lock); +} + +void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq, + struct kvm_irq_mask_notifier *kimn) +{ + mutex_lock(&kvm->irq_lock); + hlist_del_rcu(&kimn->link); + mutex_unlock(&kvm->irq_lock); + synchronize_srcu(&kvm->irq_srcu); +} + +void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin, + bool mask) +{ + struct kvm_irq_mask_notifier *kimn; + int idx, gsi; + + idx = srcu_read_lock(&kvm->irq_srcu); + gsi = kvm_irq_map_chip_pin(kvm, irqchip, pin); + if (gsi != -1) + hlist_for_each_entry_rcu(kimn, &kvm->irq_mask_notifier_list, link) + if (kimn->irq == gsi) + kimn->func(kimn, mask); + srcu_read_unlock(&kvm->irq_srcu, idx); +} #endif void diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index a49df8988cd6..5ca7fb0b8257 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1144,6 +1144,7 @@ static struct kvm *kvm_create_vm(unsigned long type) #ifdef CONFIG_HAVE_KVM_IRQFD INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list); + INIT_HLIST_HEAD(&kvm->irq_mask_notifier_list); #endif r = kvm_init_mmu_notifier(kvm); -- 2.37.1.559.g78731f0fdb-goog