From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DA9E41B362 for ; Fri, 27 Feb 2026 14:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772200849; cv=none; b=OPVrBQEYpVrS+b8Qem820qrQB5JxuvAoPfBbLL9zZa2o0AnJSXWRNMCyA5DXaeq2Yi5R7QVMeRDmJEkmQknarwopLa0tjxruD4ERSVbVAg+WGsglrbiB9PdHkCViJUat+3HBVUsTBjN6C5n7gZFnNBbrIAeaXjMh1MdfAHnPPEY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772200849; c=relaxed/simple; bh=8lwXSRo7NPacbIIvhFTzxJbwX+KIp/2i2qGE2QKcudM=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:Cc:To:From: References:In-Reply-To; b=Dx3GgE/6LLHuSdLD3/6EYQgzZ5yh8F67LjdhsbC1UfNOE45PobWSSbE0e5PkieD6t8uyheO+KA6bf4XMzikF2t46gbriQNeERpo7EKarTjk+ujs0cBLMUBB4+p9FjWqIf96ziTYkuWrdZaMyG0EINstRES/TAR98EB7XOiZJE6U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=n/sz1jEk; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=GuFhh7Ge; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="n/sz1jEk"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="GuFhh7Ge" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61RACP1D3761438 for ; Fri, 27 Feb 2026 14:00:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= jlqb7BDCgmRJ1hZWQTjrCQIUXtq6dQQDj7TPdTyfFFg=; b=n/sz1jEkHInV5jOy e0RKqa6YVl9I9NKH7WAjGgq03/1uT4zvXCxSH0qdl/Eje6caKVQKnSjJmdfaTuwM hwmUs15YKtaF9kuyXp2eNKTNES+zCsx0vAjmrEqQh/4uKY+aJs4IBRxLtWjofxqz Rp0BZFdRAQbXvtg9qwNdlLTLqaxRALAAxaLe358mssyJ5hjJIRmQGh6y7OYbBtwj J8H4wRfEcT56CiwfOhVDxL3JPaw+XdlQEXfnvhHneRTvw7kh7G5BBkImDMo9oy92 BBCiiykbg+2MHbGPTHF/gNvbWSHWcatu1rKqoYkGZwd58i8UJBhzZDI0IiZ7wPtC g5bWtw== Received: from mail-vs1-f72.google.com (mail-vs1-f72.google.com [209.85.217.72]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4cjt7ybtqw-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 27 Feb 2026 14:00:47 +0000 (GMT) Received: by mail-vs1-f72.google.com with SMTP id ada2fe7eead31-5fde66571c7so19906711137.0 for ; Fri, 27 Feb 2026 06:00:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1772200846; x=1772805646; darn=vger.kernel.org; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=jlqb7BDCgmRJ1hZWQTjrCQIUXtq6dQQDj7TPdTyfFFg=; b=GuFhh7GeXzrHU/0mzzmVmHYXQX3JZprfOiru62awrzYvqzRRBf70QPxp90SECy+8fK DnbAtPmb2RYKZQ0cYD4YcZvR17gPx7i3q4hhRtIjpQ6qvq32cSPdbzhIRoNj0pA/i/WB qR5Buj2B9Rd2i02gvuSF3+VEGPkKtP/4Vzy7YGTI51q0NEGLEwM+oInU7MCYnlHv0Tic hQPfQVfZeeAE+/h16srEq19WFztAodk5Iod9sE2mn2k+x66RE2T0l+TROQK9FUMHL5KS 04MV/sXAMpxBt01AzeSpXXbO/ekhFSkp8AVx6plUxMtEREt72qY41+0SjhvDXCfeMRrd YRgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772200846; x=1772805646; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jlqb7BDCgmRJ1hZWQTjrCQIUXtq6dQQDj7TPdTyfFFg=; b=fdJBdU4pke1KAAY7j6KFgqkhn87qNvey8azH/suZ9r3uq4bd44nD3rtMzbhUBS4VDw rDWoa+jJXfsyqMFjN18XbxJHtXXR2IuMfViS3CX8Xwy0uPDWN8/A8t6TP0Q4zSVgxmSM DAX4WboG7mNb1VuBmz4EMkZ3hTn/aQZ5sZPsq+f1aLfWb86MkKjUQ9jSwcn6qk8L8DfM oF0xMIHhtj9bzJpklt5y2vBjqqaL9p3FQ6L7h93JrWBL0ksoDPmYOoJw8oclBQFfkqx0 8dhd6tt+C3TtnF7P6KbFMqekpNXJmkmKZN5ISlIQwlFVNMNtJzMYASr8Yddr5I1W9jAe qeUg== X-Forwarded-Encrypted: i=1; AJvYcCXm70s9pjhCnBZR91HhjGC7H0QgK6xWMkFOu9BnN2/Xy4ZFkIG6Hhv6Ty+LUPAYJoECqCj4CoOrxHD9qYc=@vger.kernel.org X-Gm-Message-State: AOJu0Ywn999HfGwykLmWS774cm0X7IU0UD3eqx83+gMXhnvo2t2pkYpe +CjTVRcSQc9nvn0/5/VEeDfZkfMunGxNNfdk9yT9KOhQdktLPSuw7cN9RXDxsiwKvcVs9mnZStP sH4A2HRvf/vfZT4fwiK7Hjqq1py5a4jJXTx168/HSnt3+pCLE85eoZE35T7ENvtUR4jE= X-Gm-Gg: ATEYQzw6wYi2TEBpzF7tIjRP/qVjmJACBkq6YjVtflD9nm4XFDkdApIqvKC39f5RFiN ulYxGkwj/ehRHFVtC0rNlI09mrFNKz8dO6ROlhiM3X340iJTl1WUT08ubWC3xVgTF49eY8n7LJh uoq9Nu/iEtgA7nVjwIkJ6iLN2xr8MDpUFFMnsbwKRHOlJwXSE4KI/a1tNWoQpr7I/BJiorInUyj BIWGNJ41V9cDWtSZ7YO2Bu6JAnOEwe6psokIlwFKZc+3nBGm3EhwbSVZB0NqqoIQA55Mkc8CkhC kwxLfRXbbI/HZjpfmiNOJP0FOLo2+bc++SoEcoP3NgELydsESpRWLKNugpPsjDC7VH+7w0Z5sR9 rg8zl/rH2oYOoAYLb2DbZetMWHbahw1fkPF7xwx6Z3PN9PuFqFLY1qGKp2YlC X-Received: by 2002:a05:6102:945:b0:5fd:b46b:d5a6 with SMTP id ada2fe7eead31-5ff1cf4a2edmr3779352137.12.1772200846098; Fri, 27 Feb 2026 06:00:46 -0800 (PST) X-Received: by 2002:a05:6102:945:b0:5fd:b46b:d5a6 with SMTP id ada2fe7eead31-5ff1cf4a2edmr3779295137.12.1772200845537; Fri, 27 Feb 2026 06:00:45 -0800 (PST) Received: from localhost (ip-86-49-242-13.bb.vodafone.cz. [86.49.242.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b935aeee867sm149340066b.66.2026.02.27.06.00.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Feb 2026 06:00:44 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 27 Feb 2026 14:00:43 +0000 Message-Id: Subject: Re: [PATCH v7] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core Cc: , , , To: "Jinyu Tang" , "Anup Patel" , "Atish Patra" , "Andrew Jones" , "Conor Dooley" , "Yong-Xuan Wang" , "Nutty Liu" , "Paul Walmsley" , "Paul Walmsley" , "Palmer Dabbelt" , "Albert Ou" , "Alexandre Ghiti" From: =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= References: <20260227121008.442241-1-tjytimi@163.com> In-Reply-To: <20260227121008.442241-1-tjytimi@163.com> X-Proofpoint-ORIG-GUID: DXsEClIu2Nxh5eFRH6gHfwDf14K5cpCr X-Authority-Analysis: v=2.4 cv=N7Mk1m9B c=1 sm=1 tr=0 ts=69a1a38f cx=c_pps a=DUEm7b3gzWu7BqY5nP7+9g==:117 a=9tUHzIdeCh+UoOnba06Qjw==:17 a=IkcTkHD0fZMA:10 a=HzLeVaNsDn8A:10 a=M51BFTxLslgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=Byx-y9mGAAAA:8 a=EUspDBNiAAAA:8 a=p71xfkkELbvJglz7_8IA:9 a=QEXdDO2ut3YA:10 a=-aSRE8QhW-JAV6biHavz:22 X-Proofpoint-GUID: DXsEClIu2Nxh5eFRH6gHfwDf14K5cpCr X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjI3MDEyNCBTYWx0ZWRfXwCMgGnXyAzFk bjvWV8OiQ/LddpcQejSQCJhPQr5PCXk0dLNLZIJyMVVs11IrsrkRd8OoUCc1B5GTO8SoPAJV6i7 qRYTR2BRqni2Gy51wN/2/1/cOShKFxTt4Br00W03AmQ+14qrNVjNxpMXuoI73anSh3rrQjjsNHA Cz6kULgn/w9it/ZNA55UdWD5Wy5l8qMy5Jg7N//ZMzIw3gdTZPHJiEnSDs82vpPIarNcC/QspN6 +uSdpj3h5Uhtl9fI0og1PqKGlWwDByMO+jW1tqyx5/t7byO6mEWwuHeubsYvuS2JQSQhmSYs0dW 9nWzdjKHgeTSEQpG1oLxX5D2FyRYFO4IPWguavtbzfXsBooJUskzbgLs3Ivq7B9FGRFONVoyFx5 pZscvySh1jeM6DOXjAc2pxzzT0SQA1JYZ4WCYxddIfZrEfy9j4aM7zi/vR96dVJhCGfF6TOVstO yBGIsBLcuHseAG2f5hw== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-27_02,2026-02-27_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 clxscore=1015 suspectscore=0 spamscore=0 adultscore=0 bulkscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2602270124 2026-02-27T20:10:08+08:00, Jinyu Tang : > Currently, kvm_arch_vcpu_load() unconditionally restores guest CSRs, > HGATP, and AIA state. However, when a VCPU is loaded back on the same > physical CPU, and no other KVM VCPU has run on this CPU since it was > last put, the hardware CSRs and AIA registers are still valid. > > This patch optimizes the vcpu_load path by skipping the expensive CSR > and AIA writes if all the following conditions are met: > 1. It is being reloaded on the same CPU (vcpu->arch.last_exit_cpu =3D=3D = cpu). > 2. The CSRs are not dirty (!vcpu->arch.csr_dirty). > 3. No other VCPU used this CPU (vcpu =3D=3D __this_cpu_read(kvm_former_vc= pu)). > > To ensure this fast-path doesn't break corner cases: > - Live migration and VCPU reset are naturally safe. KVM initializes > last_exit_cpu to -1, which guarantees the fast-path won't trigger. > - The 'csr_dirty' flag tracks runtime userspace interventions. If > userspace modifies guest configurations (e.g., hedeleg via > KVM_SET_GUEST_DEBUG, or CSRs including AIA via KVM_SET_ONE_REG), > the flag is set to skip the fast path. > > With the 'csr_dirty' safeguard proven effective, it is safe to > include kvm_riscv_vcpu_aia_load() inside the skip logic now. > > Signed-off-by: Jinyu Tang > --- > v6 -> v7: > - Moved kvm_riscv_vcpu_aia_load() into the fast-path skip logic, as > suggested by Radim Kr=C4=8Dm=C3=A1=C5=99. > - Verified the fix for the IMSIC instability issue reported in v3. > Testing was conducted on QEMU 10.0.2 with explicitly enabled AIA > (`-machine virt,aia=3Daplic-imsic`). The guest boots successfully=20 > using virtio-mmio devices like virtio-blk and virtio-net. Reviewed-by: Radim Kr=C4=8Dm=C3=A1=C5=99 Thanks.