From patchwork Tue Apr 1 16:18:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 14035132 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C67C20E70F for ; Tue, 1 Apr 2025 16:18:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743524290; cv=none; b=n5IryaAbFLKQAF36DGl4UHN1hy9sAlUsfDjPE2dir0HLLY7mDCVz7FDDNSyi959o8c1/EDnUHF9Fxvura7hlj5UI3xGnge1OfiOhTBwtdEg/Go8m+CHv2FCM6xXydQaGY2Z6cqpxpJUnhLUAF9w4lNMVm4j6h+cr6uH61ndGO6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743524290; c=relaxed/simple; bh=fWIBQmUTb72aiRc41495d8ZZdXdCbxu4pWmWZnHxDTI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=c3UAdqTX4elfROuUtYzAs1WYEKXQT+Wfl8fHqD8wYRj4aMTKmZeNtT+zpkkKgImlClrDJBh6EDp2G3n5lFz/LtEHoYSpRikMDmsTmYwOgmOuX9iymDcRMCPfZmq7WYR2UIz2lfAkcdi7PvZuWCmH6w5y3buASJ9trBNxLp7KJy4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Ww4OEtH6; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ww4OEtH6" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2241ae15dcbso133802405ad.0 for ; Tue, 01 Apr 2025 09:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743524288; x=1744129088; darn=vger.kernel.org; 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=i3CvVTiTohY/MD7XlD1mUCUkTV809OhWBxe9COdH9yw=; b=Ww4OEtH6tuLU/NSLZstG5erzVN/7+B0EIZapBgN3R2x3xqT464z72ozfZ5LmHgBCXv gXkomsRveJK+KlUqZk8iBHnbevFYuI1KWwtk9XJdcC5A2bM7R3nmpthidlosdcXvEpTY ivXCqQApfj0GEkl5rl46UBzFMEu0i/16zz4rS2rw6Iz8h9GH23QkjAFi+aAlU4knkZq8 6/Ps525KhbQjgP7IpiinqardQu566IpZCAUllUO4c9q2rjRh/wIk/hBLDPgLRdeTOMj6 NyPpb0oEE3/9csHvoeUqqTZg7e6qzcfyU4YRHrmqSxPqUw1ALROE93MbZfinv3WhHu/E 5C2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743524288; x=1744129088; 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=i3CvVTiTohY/MD7XlD1mUCUkTV809OhWBxe9COdH9yw=; b=Akan+KezyMBLvaUrlsfGHxnR57JrsPdLWpG4SlcB80Cw3Ygcrs1b1XW/RgXRi9ewC4 1fTMUu3q0HflLeu7fPpBIg5aEYAMc7j2lryYGNaPOqbe1q5KtE9Y4feFvjEh7kG8DmXk VmXobpU3rXcWChCtIcVfr+iIt1CnaUTKCloGUw9b+o/eEQb89wG6kHuGjfK1rm7W2cmS nXWfuDP2qPkrJ5jTE+7OPj8rRke8XPF5Fke6dEyxf2Ec91r6gPQnjw8/b47PyEeWG92L xPbewwka6x2F0noiAmCe3RjSG6qagGWg85KzmhRA47sypkB8Kgzqb4mbbgkEm+fTXW1O UoBw== X-Gm-Message-State: AOJu0Yx/cn/PFPIFn8J5NmX7RWVcqo2r0f3ggeZ+pichc5jHZNtQk0HT MWorvmBovatd3cIhUYdwyom2aCtkFXw3XZjAdAxEU/E/7qjH1BcbjC9Qd8Ub83tu1K8Z/U+a365 uLg== X-Google-Smtp-Source: AGHT+IGYMlELE54qVypHagndgMfq83OicwY6JnNyZsP/+GL6myxIy23X8uMt9Qym6qCfe654bpzCkDka+5E= X-Received: from pfhh22.prod.google.com ([2002:a05:6a00:2316:b0:730:5761:84af]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e88f:b0:223:5c33:56a8 with SMTP id d9443c01a7336-2292f9e51f9mr223551505ad.35.1743524287794; Tue, 01 Apr 2025 09:18:07 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 1 Apr 2025 09:18:02 -0700 In-Reply-To: <20250401161804.842968-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250401161804.842968-1-seanjc@google.com> X-Mailer: git-send-email 2.49.0.472.ge94155a9ec-goog Message-ID: <20250401161804.842968-2-seanjc@google.com> Subject: [PATCH v3 1/3] KVM: VMX: Don't send UNBLOCK when starting device assignment without APICv From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed , Jim Mattson When starting device assignment, i.e. potential IRQ bypass, don't blast KVM_REQ_UNBLOCK if APICv is disabled/unsupported. There is no need to wake vCPUs if they can never use VT-d posted IRQs (sending UNBLOCK guards against races being vCPUs blocking and devices starting IRQ bypass). Opportunistically use kvm_arch_has_irq_bypass() for all relevant checks in the VMX Posted Interrupt code so that all checks in KVM x86 incorporate the same information (once AMD/AVIC is given similar treatment). Cc: Yosry Ahmed Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/posted_intr.c | 7 +++---- arch/x86/kvm/x86.c | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c index ec08fa3caf43..16121d29dfd9 100644 --- a/arch/x86/kvm/vmx/posted_intr.c +++ b/arch/x86/kvm/vmx/posted_intr.c @@ -134,9 +134,8 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) static bool vmx_can_use_vtd_pi(struct kvm *kvm) { - return irqchip_in_kernel(kvm) && enable_apicv && - kvm_arch_has_assigned_device(kvm) && - irq_remapping_cap(IRQ_POSTING_CAP); + return irqchip_in_kernel(kvm) && kvm_arch_has_irq_bypass() && + kvm_arch_has_assigned_device(kvm); } /* @@ -254,7 +253,7 @@ bool pi_has_pending_interrupt(struct kvm_vcpu *vcpu) */ void vmx_pi_start_assignment(struct kvm *kvm) { - if (!irq_remapping_cap(IRQ_POSTING_CAP)) + if (!kvm_arch_has_irq_bypass()) return; kvm_make_all_cpus_request(kvm, KVM_REQ_UNBLOCK); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c841817a914a..a5ea4b4c7036 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -13556,6 +13556,7 @@ bool kvm_arch_has_irq_bypass(void) { return enable_apicv && irq_remapping_cap(IRQ_POSTING_CAP); } +EXPORT_SYMBOL_GPL(kvm_arch_has_irq_bypass); int kvm_arch_irq_bypass_add_producer(struct irq_bypass_consumer *cons, struct irq_bypass_producer *prod) From patchwork Tue Apr 1 16:18:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 14035133 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 366EB21CA0E for ; Tue, 1 Apr 2025 16:18:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743524291; cv=none; b=SGBN62OW91TE78EJQi3p78qNwOqepD81rx+adgyWj6joyF4P4FXb6Ib720BPddPiJ6bbJ07nPY0eOPfW5ZYqIOkzQHXDJf+7A5Lxj5lFZbCRwDvfuLCa51zKgxVrdg3V6juv8l/gqZTHm0vpAH7WaKwXRVx3K/Z24bLoDPpbRDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743524291; c=relaxed/simple; bh=ZlxjQIsKWBnCn4azAPaeZp9DWgj/64K0rqQe0dmeggs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oH7mhormAKveFidttrdUNtIgjBecqWl95Mk/15Jvh6DYDdvtjIB5Z/F+WwO7POnsEC8/f5Gb9EmpuFM1HjI5uJu7Sn+mwTaafZZjI4JYU8abrzJupZKP+xkvGn9r58/BeYApmoblTemBL8Z5eRXSgfxGQ9ZBRcZiAg/lk/UOnqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ecIcKzhu; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ecIcKzhu" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2262051205aso82978175ad.3 for ; Tue, 01 Apr 2025 09:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743524289; x=1744129089; darn=vger.kernel.org; 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=bqWYbif5v+Yux+dM7N5z+opj8vbiyTpqkOl2VaFaASM=; b=ecIcKzhuHkx8Y8993aWfZyVZeVHbR5WfCSOWJWb2Tj2Qw+sAu3TDQQJmSH3bSZsO+T lq4SF+cFmcvZwoDZ/CllHj+uLyPytkesMLm0+fT8A2QhMOax0olEG/0lApy8ypWsDPWb JpQqc7Q5TSUCeTne3PwnUk8kphlivvrQvGAe83pOwn0drMkOI6Dz5zbVs5MTvaCXyCQU jZWs1qQuTHtwCpdbK5t3cEUbkxoICEMa6GUZ865oNbKkjARyJb62Ji+OpyGV8WNMtmEz fA/+cYVEY2Ia3erb93znXH3Ppr+aWBo+otq54+WMaLDkiaGXfNkjCAAzfgsSYcttNIjN Ur9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743524289; x=1744129089; 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=bqWYbif5v+Yux+dM7N5z+opj8vbiyTpqkOl2VaFaASM=; b=ZS9u79g7OHIZ0E7nu6hpM0+jNVkzl+xm7hX64++jQ4Zsb8kU4Zdyli3kgMRDekYHN/ p3hngpRFNedhgHlCbk1ifRyh+HwgihV6Zt/fOsKeEmC5hNYCZToQ8uxyvDcNAL/vpDIT S82DvKPX4v7JC/sAXdy77XiZLADnIM0NH64i6JXlqOQHAG/i+GPZ+q/CGr7pZKIPvQhr l9DOp0ayvO9t6LEWU12W88e9hLNkMJCpPLtuLCkN/PlzynvPRbXeoisa8v+DEuSjGPdy 6fNEndAoBhMlU6W1Q/MLLQ0a6SwfhS1xnc6SYRxOhWz/J28mylLB5bdb0v8GZh/ZWmcv YRTQ== X-Gm-Message-State: AOJu0YxXqyXDay9oawK8kywRpLKdBZSuYs6n+xqM1jntBUFMXNFCcMj5 PyJQGcmVtTwC91QZDFODFBYhfbsnGgM3PkMj5tL/M8R199xs6WYKnS/ueS1AwQBSMsYHJpMKdCV EpA== X-Google-Smtp-Source: AGHT+IFBjQl9T5sWawUBkQ+04s8CWsMBMWzhJzaFZdNq/LILgQj/lKKMYLjUW8g9R/4M43HyO/qeuo/exXs= X-Received: from pfgt25.prod.google.com ([2002:a05:6a00:1399:b0:736:4ad6:1803]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:4609:b0:736:46b4:beef with SMTP id d2e1a72fcca58-73980350385mr18816589b3a.3.1743524289597; Tue, 01 Apr 2025 09:18:09 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 1 Apr 2025 09:18:03 -0700 In-Reply-To: <20250401161804.842968-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250401161804.842968-1-seanjc@google.com> X-Mailer: git-send-email 2.49.0.472.ge94155a9ec-goog Message-ID: <20250401161804.842968-3-seanjc@google.com> Subject: [PATCH v3 2/3] KVM: SVM: Don't update IRTEs if APICv/AVIC is disabled From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed , Jim Mattson Skip IRTE updates if AVIC is disabled/unsupported, as forcing the IRTE into remapped mode (kvm_vcpu_apicv_active() will never be true) is unnecessary and wasteful. The IOMMU driver is responsible for putting IRTEs into remapped mode when an IRQ is allocated by a device, long before that device is assigned to a VM. I.e. the kernel as a whole has major issues if the IRTE isn't already in remapped mode. Opportunsitically kvm_arch_has_irq_bypass() to query for APICv/AVIC, so so that all checks in KVM x86 incorporate the same information. Cc: Yosry Ahmed Cc: Jim Mattson Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/avic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 65fd245a9953..901d8d2dc169 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -898,8 +898,7 @@ int avic_pi_update_irte(struct kvm *kvm, unsigned int host_irq, struct kvm_irq_routing_table *irq_rt; int idx, ret = 0; - if (!kvm_arch_has_assigned_device(kvm) || - !irq_remapping_cap(IRQ_POSTING_CAP)) + if (!kvm_arch_has_assigned_device(kvm) || !kvm_arch_has_irq_bypass()) return 0; pr_debug("SVM: %s: host_irq=%#x, guest_irq=%#x, set=%#x\n", From patchwork Tue Apr 1 16:18:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 14035134 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E267E20E70F for ; Tue, 1 Apr 2025 16:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743524293; cv=none; b=cNpsaCc+Od53W1WBw0UhVuJEN71MrG9CCdxsVI1XgWFHYlD0hkA6qAhmiVnOmuS9FvQeYgrgDWzfV/V5Oozn6kcOCc/6ZAMfkJ7Qf9+7sSK+dfpl3Pjof53nVHnI5i06Z6nb9idU9zckKbWnztxiAJGvoaim2O0of61Y8+YbTnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743524293; c=relaxed/simple; bh=mLQbx1jisqBwOfc+NQxn9P1UAtUaAxPUhi+tPamI/f0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FhWkE5SM6HOLmeKQ0/UDBgrAJw+erT90To6IMnJwSZn7hEarzKrhCVsbTPDpnyjlbIpiNKI+Fh77ZJ9BTiNAp1R5UMGe3c8CiDIyUPnQt9KdXDf2Ft3UgmJgjE1FPO7B9K/41LSbCWj0D7CUtpyO8B8nLq4K9zQ7LKnRPhVX+jw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Z7ALBBfb; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Z7ALBBfb" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ff6167e9ccso627570a91.1 for ; Tue, 01 Apr 2025 09:18:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743524291; x=1744129091; darn=vger.kernel.org; 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=AkBWo9dnQGpjZuqJnrYPda5jwQq6BFGndRJc124YDKs=; b=Z7ALBBfb6StDn1ZNvZEWH60T2KoZSvE4cfgpHEs+dmuAb/dvtyKXYPhShtp6RPzWAc ynBMXa45BdNaEJJR7lHG9k6uQg5wtYzFJVfMI50q1SUDKHQbIgn8a5QFgv1+f1XisogV vTpCwADBxAbgEH7MMD7HsxVHe8vAVhXkaJ2hOSct/OvNPn1q+wQRvc6yvKR3DeX6rJo0 CZ2xn50Esf8waJz1N2wI/driyiYbFP6qbp41rpYSwtoJQ1Hjhoj6mqoGO/mWCB3TmxDK OQWxOIvOqCn2Ep0CBLDSGuITVrOpcknSRq1KXZMGPk3Xq4DGNpEntctxFXWCYKmLY+hn UZ9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743524291; x=1744129091; 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=AkBWo9dnQGpjZuqJnrYPda5jwQq6BFGndRJc124YDKs=; b=KdwzIRlWLXoVrD6CQWVg6MQ8shmLQceh2hv+ah6USMEe/kPXoyzRC1jhbnLTV2KSYi dP7u6r9uvijMSlm4cprwDfhh4o8S9+9E65s5cbCUhdQPthpLvbcWQ5hZtUdb/CtwX7Cu AH6l3ebxn1/u5R2tKYzAf7eXmUh4RK9NRiO237R2YRCwI+g0KEZKjCr3uS3M62M4gFpW q/7rb3bTWcDVneALTfVPmUKDCgr7sAxSnHnwVEhAASwAV9PnVAwi1U8W5OHtqzg/nTCJ /+k9tuLNU+e8V6OlPC4hwb1deXx5u0biHpd78jzT7yeYuQl0ZzvCQf03ybWWdXaXN8me QFYA== X-Gm-Message-State: AOJu0YzPAmyjT1eFx0eDRotPjSQqvIFQdI+nC2X90puSJgm/ENUWoQdr KOjkH6JntD9BJz6ic4ji02BXbp4tHDDsgzW2vrE7GQamQ550bdGN1YoSkTWDu2tDFSSHg8iL+MD 03g== X-Google-Smtp-Source: AGHT+IEQY+S+Rgi5OwC0yzzxYa5wSGw6iWHC3K9elsEqqknoTddyn8IHbybmZm5I3XA/J0Eutqh8BKIlg2I= X-Received: from pfbdu10.prod.google.com ([2002:a05:6a00:2b4a:b0:736:ae72:7543]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3950:b0:1f5:7eee:bb10 with SMTP id adf61e73a8af0-2009f5ba6c0mr21757247637.8.1743524291266; Tue, 01 Apr 2025 09:18:11 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 1 Apr 2025 09:18:04 -0700 In-Reply-To: <20250401161804.842968-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250401161804.842968-1-seanjc@google.com> X-Mailer: git-send-email 2.49.0.472.ge94155a9ec-goog Message-ID: <20250401161804.842968-4-seanjc@google.com> Subject: [PATCH v3 3/3] KVM: x86: Add module param to control and enumerate device posted IRQs From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed , Jim Mattson Add a module param to each KVM vendor module to allow disabling device posted interrupts without having to sacrifice all of APICv/AVIC, and to also effectively enumerate to userspace whether or not KVM may be utilizing device posted IRQs. Disabling device posted interrupts is very desirable for testing, and can even be desirable for production environments, e.g. if the host kernel wants to interpose on device interrupts. Put the module param in kvm-{amd,intel}.ko instead of kvm.ko to match the overall APICv/AVIC controls, and to avoid complications with said controls. E.g. if the param is in kvm.ko, KVM needs to be snapshot the original user-defined value to play nice with a vendor module being reloaded with different enable_apicv settings. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm/svm.c | 2 ++ arch/x86/kvm/vmx/vmx.c | 2 ++ arch/x86/kvm/x86.c | 8 +++++++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index a884ab544335..6e8be274c089 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1923,6 +1923,7 @@ struct kvm_arch_async_pf { extern u32 __read_mostly kvm_nr_uret_msrs; extern bool __read_mostly allow_smaller_maxphyaddr; extern bool __read_mostly enable_apicv; +extern bool __read_mostly enable_device_posted_irqs; extern struct kvm_x86_ops kvm_x86_ops; #define kvm_x86_call(func) static_call(kvm_x86_##func) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 8abeab91d329..def76e63562d 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -231,6 +231,8 @@ module_param(tsc_scaling, int, 0444); static bool avic; module_param(avic, bool, 0444); +module_param(enable_device_posted_irqs, bool, 0444); + bool __read_mostly dump_invalid_vmcb; module_param(dump_invalid_vmcb, bool, 0644); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b70ed72c1783..ac7f1df612e8 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -115,6 +115,8 @@ module_param(enable_apicv, bool, 0444); bool __read_mostly enable_ipiv = true; module_param(enable_ipiv, bool, 0444); +module_param(enable_device_posted_irqs, bool, 0444); + /* * If nested=1, nested virtualization is supported, i.e., guests may use * VMX and be a hypervisor for its own guests. If nested=0, guests may not diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index a5ea4b4c7036..9211344b20ae 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -227,6 +227,9 @@ EXPORT_SYMBOL_GPL(allow_smaller_maxphyaddr); bool __read_mostly enable_apicv = true; EXPORT_SYMBOL_GPL(enable_apicv); +bool __read_mostly enable_device_posted_irqs = true; +EXPORT_SYMBOL_GPL(enable_device_posted_irqs); + const struct _kvm_stats_desc kvm_vm_stats_desc[] = { KVM_GENERIC_VM_STATS(), STATS_DESC_COUNTER(VM, mmu_shadow_zapped), @@ -9784,6 +9787,9 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) if (r != 0) goto out_mmu_exit; + enable_device_posted_irqs &= enable_apicv && + irq_remapping_cap(IRQ_POSTING_CAP); + kvm_ops_update(ops); for_each_online_cpu(cpu) { @@ -13554,7 +13560,7 @@ EXPORT_SYMBOL_GPL(kvm_arch_has_noncoherent_dma); bool kvm_arch_has_irq_bypass(void) { - return enable_apicv && irq_remapping_cap(IRQ_POSTING_CAP); + return enable_device_posted_irqs; } EXPORT_SYMBOL_GPL(kvm_arch_has_irq_bypass);