Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1231576rdb; Wed, 24 Jan 2024 08:34:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnE3T+IoViX4jPrygaQCMGtrQQPZ9ypDX8N1cKNbDVPShQZDpIMdAfUK/vVb0qzOw8mXfI X-Received: by 2002:a17:902:fc46:b0:1d4:b60f:1de5 with SMTP id me6-20020a170902fc4600b001d4b60f1de5mr1076384plb.26.1706114062994; Wed, 24 Jan 2024 08:34:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706114062; cv=pass; d=google.com; s=arc-20160816; b=isQpShYTzvqONCRj2lsttiYP5EKLbMoJBN6M8txU98wU99D45NYBJvwP/jVexDjy02 tGque+C5WQRzmSt+wGg+NlcRNFtMLhymR65EYaOB0vEZLudYHWbg9Pw+C+2+egV/ZsNd nTIaApvujuapDtduAAkaUKTu2vTlDl1aC+USwFaJ5re16ptJ6MwQnM9ZuqEyZ0uSL0f+ I5aGS7BaYVz5MUz575N11tDUKLMVyHshzMdhBQpKjiiQe3kkoR42mb1dAe2Bk6Vzy3Fn tBHMEiQxmfGwgEVi4hVgMWUUxREEycg/LxlwszkTmw+9bzCAb68DaLH+9xe+W/+knPlS N4nQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=JX7fJkqmjqtzDmgdDOKfImoORSlASa5dCAfyrxQaPEo=; fh=sQyIbIZh/rI1BPvZtL4XeizNqmvRnpFzZrnnHOcLq70=; b=gjbWT83Y6XnCeRuoDAaP8/PVOWtwIttr/y/VzKr/Jpyqn2La+pLf7+E+wIFgax0c78 ASn6/u3+7lm2dR6h6wfa7TrSOI1ilrm6JuWPh2fFnu8hcn3++0B7sw+KLu5j2jAwO2oS uA1wqPXFSKAqWqMrXD0y3aSdjSvSn1eVZha+QF0ZSfLQnd5ONinT0r6uJrKFgIIJp1V8 kD/lw7z5LO5OeAiteSNXThrZoDC/vXMZCnPuBRcl9vOhpOdk3SGXsQBJdysRKJhFtcId ntYWcXe4mvs+SpKCguS8GC1SVeSed82Oza8WdMG5LRelZdr5oU8gdBGHymNbtuF++OKp wxSw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OqqLbO+H; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-37297-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37297-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b5-20020a170902d50500b001d6e9ff365esi6290866plg.580.2024.01.24.08.34.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 08:34:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37297-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OqqLbO+H; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-37297-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37297-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2DA13B263EE for ; Wed, 24 Jan 2024 16:04:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E30DD7CF1A; Wed, 24 Jan 2024 16:04:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OqqLbO+H" Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 CDBC57C097; Wed, 24 Jan 2024 16:04:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112252; cv=none; b=DWrdmnGvxDZwbzRdl5o2dZmv4Dq1PxkwDVLCa0/sjtZDSDStZPIJhvQslTl6NasZTeeI+VPQ5o1b7vWiXMza4/hr7wKkW2PycS6DzRcwqdT13UagxDqa4HIdhbSdQci57LiAeWmU+bdCrXclbELKYN19uJl7/tLtu4XSpk8SUVE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706112252; c=relaxed/simple; bh=8xVTevAapGS1MQ5rJveUXc7iD2ZRnvv/yXE6rpElJw4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Fl6dzRPRtqXNDaVeXr5lxTu0t88F4eXfJubmKSwaBUNF4WwFy+bnbFh45TrCDoxwn8vkg36m4Uy1gSw6pejWD+YrhBHn84Cex6s8ni8tcSEXeJbWsuMWKXsxwmxAgVR7H3Zsj6JUeyrFbTzRQGzM6joa+7afwIHvkJ1QUzHruX4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OqqLbO+H; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6ddc162d8d5so263719b3a.1; Wed, 24 Jan 2024 08:04:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706112250; x=1706717050; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JX7fJkqmjqtzDmgdDOKfImoORSlASa5dCAfyrxQaPEo=; b=OqqLbO+HUNisj1pJ5cVGc1uoQuxCKe8z9//k6+rJJuTP7why/qI8TEhVxveAtHeLGM /8kcIr5RG4uUv2o0Sz9uyS3VCbQoydaWGhOJ+W+gpirQX3mlUh5QzSjtqqA5AWkc86xc WYenXdTBV7OYExMWvZ1lieYKy6zP9E/TLGoVw5DOeQY12V/HyQ4PIz9Lu1Ct3TuLjxYZ 3XFgB9FHcD6b6BJu4TQoVB1o3I7JP0KJHDzyymYSEvMon99RE0HxpOYwuX3J4nGc98KH qmmh16pOW9T+8IBQp/RVUi+x6WMITDyWQcgFmSlqdfl0ckXNO1cL6pH0iTL/VfAdchEB mT2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706112250; x=1706717050; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JX7fJkqmjqtzDmgdDOKfImoORSlASa5dCAfyrxQaPEo=; b=ih32MIUBpF8Wltxwo55ATuUljoihkUpUGjQ/0WboocLJGlBDw4VUEPDLhqimewyome SywofOMyH1y4/Ez4doArRfjUeC6SzlsbSkl31BfLLGV5CrqiPUjBnPmWCWSfb+FUCWD+ 3aByl42K8P9c1cZgpzLsHdYdl7imGwwJiZZZ9WG4UHDtJ2WiHeoTVILCTRLXrIx5v5bw HFSW3ANiqxVPmd5g8rdfPEKLiCiS9HSzlE8GUSMC3myyD97juEgYFIX+8bj8WLPi4QZF 9JGqkBze0xVHv6f3qA/66SjN4PhM/wu+3Y/6MsTHEUtIfS6uWgVDFWMk/lb9btka0PgN Gp7g== X-Gm-Message-State: AOJu0Yz8mi4YaegBcIO1fPUj0qltBGLzN6JFh/EZyi7VpqIuoRQbOx6P YaAsCkqSJbe2BlcY7+3w6HeOi1iu9cYXFwnn6wWDromcPHWkLht7 X-Received: by 2002:a05:6a00:a1e:b0:6da:938c:f77f with SMTP id p30-20020a056a000a1e00b006da938cf77fmr5939769pfh.52.1706112250067; Wed, 24 Jan 2024 08:04:10 -0800 (PST) Received: from localhost.localdomain ([43.129.189.221]) by smtp.gmail.com with ESMTPSA id n16-20020aa78a50000000b006cecaff9e29sm13973014pfa.128.2024.01.24.08.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 08:04:09 -0800 (PST) From: Brilliant Hanabi To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: Brilliant Hanabi , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] KVM: x86: Check irqchip mode before create PIT Date: Thu, 25 Jan 2024 00:02:48 +0800 Message-Id: <20240124160248.3077-1-moehanabichan@gmail.com> X-Mailer: git-send-email 2.39.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit As the kvm api(https://docs.kernel.org/virt/kvm/api.html) reads, KVM_CREATE_PIT2 call is only valid after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. Without this check, I can create PIT first and enable irqchip-split then, which may cause the PIT invalid because of lacking of in-kernel PIC to inject the interrupt. Signed-off-by: Brilliant Hanabi --- arch/x86/kvm/x86.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 27e23714e960..3edc8478310f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7016,6 +7016,8 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) r = -EEXIST; if (kvm->arch.vpit) goto create_pit_unlock; + if (!pic_in_kernel(kvm)) + goto create_pit_unlock; r = -ENOMEM; kvm->arch.vpit = kvm_create_pit(kvm, u.pit_config.flags); if (kvm->arch.vpit) -- 2.39.3