From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (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 1A52B19DFAB for ; Thu, 28 Aug 2025 00:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756339331; cv=none; b=Gyq0Tr79xBDtyiFsARlLo0CMUFKchliCE/szuxu1HZ8pV/NgCY5pLccpEfUfkBkG7m997+sajPWOnxNPe0DXWXJmhomp2HO1qMRCWNfNpUErGh40jf0J4h+L/29L/6v/27L+WjHuAgvSAtyfH3X/kFsPYwCFnR1HO603m7xawXs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756339331; c=relaxed/simple; bh=TvCX+8FkP7MFHYKfg/0KhAOHMZdZcfiHEdWLUolI1Zo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pj1BKlBv+x3aTPwN9ufiiQXCKeixn1JW8fT1GteHsU9ffk867Gboi4+U4Y4O9QTvCzp/9l3gs900wHSIbKRnZ/h/h+g7SuGhAc5fDJXhTo93bwGnnP+FBxxE74d9QtIBwG0J1R7nnNOr1jrlcHK5zi/uXHRCtWR/1PBsGwAF1lM= 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=FwGjinL6; arc=none smtp.client-ip=209.85.210.201 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="FwGjinL6" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-771e1451631so757000b3a.1 for ; Wed, 27 Aug 2025 17:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1756339327; x=1756944127; 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=vhbQgqknyAyVeKaXs8kP6grJ1hrwQUkSmJiE25IRpuQ=; b=FwGjinL6djn0iX+mCxZgJ6VgeV7qBbQopg+f1tDftimoOdpxj0PE1cGZiTSMRRw8Z4 bsRWFdiReGjHjjopEPvTo+25kWh2mZ4u6aFcZYEGcC+Nmhtxko3ZIGCaMf/iqh0FuS9Z 7RlAjao2y4po8a6a/DfbW38NOdniScT5kUdoRmDH/UVwTTLM0PmaKTNDlZGs9inTQbU7 82iOF6OVv73twgxpHgP6raLu6kw2J8MpCQui73xwaIj9RxdWX1OTBMLwP2tBizWnQpY4 zmdvSDiF/+ZLqrCr+oqyRDYlp47T7+7/i0/sfonud1ThTK1460RajvcywdvQbvTPl596 +cYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756339327; x=1756944127; 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=vhbQgqknyAyVeKaXs8kP6grJ1hrwQUkSmJiE25IRpuQ=; b=otTRFIjyJWDHiP1KcvNUTgC0by6v4lNUDTKIm7Gg/8ptAXPo1krgbm3Z7GdOPHnVXW JbuHqIl3enbsAVmH01zBz1S1evtGLDb8LaI7ZKdcMyEg4bJe0RNExunlETWK7aJmOpVK h5zgnNo/pN0P3LsbOl8kJ/KTxmSjverloK0k+YJ/K/1+bCiZf4NDiW0ngLDE9KFSNP2u 5JC+FdvtGLvh20CTAjFaLAbCXcSMg3b4QsaT4LWShB/oP7InAvoOz2ymC4QWuMmPG+VW pSdh9f4nS6nu1Aukp0YWauu74mAFfqxgY/jROEzN/Z7XtO5LKzRenlT260YMq3YoWT5h uB2A== X-Forwarded-Encrypted: i=1; AJvYcCUfE6MnUK8qVZTeIZ2vtXwiPmcuROo1MG9TnqEXU+E/SeChL5RzeACZCDB3Q6Xu4pC/Z/U=@vger.kernel.org X-Gm-Message-State: AOJu0YzQfNnzH/ftXLLPGMbeRT+6yNXjJBuNcoUlaojnd36PJ1/6RBjB ke793c4AvCkVLweiKTBne/42uIyJKDi6neitgycYk4Ctz7Ln1TKzu/AsENQ71YplVxdNL3iS62U PY3PYGA== X-Google-Smtp-Source: AGHT+IFSTSPK462uYm9CJ0EAHOKjQ8TiWstiYBGpgePwdPA6VvAffLDDZpu/ZHt6d1MsFofssMNf6pVc4TI= X-Received: from pfbdr10.prod.google.com ([2002:a05:6a00:4a8a:b0:772:a5a:298b]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:4b46:b0:76e:885a:c1c9 with SMTP id d2e1a72fcca58-7702fc24f39mr26347774b3a.27.1756339327187; Wed, 27 Aug 2025 17:02:07 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 27 Aug 2025 17:01:52 -0700 In-Reply-To: <20250828000156.23389-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250828000156.23389-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.268.g9569e192d0-goog Message-ID: <20250828000156.23389-4-seanjc@google.com> Subject: [PATCH v2 3/7] Drivers: hv: Disable IRQs only after handling pending work before VTL return From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Catalin Marinas , Will Deacon , Tianrui Zhao , Bibo Mao , Huacai Chen , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Peter Zijlstra , Andy Lutomirski , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-hyperv@vger.kernel.org, rcu@vger.kernel.org, Nuno Das Neves , Mukesh R Content-Type: text/plain; charset="UTF-8" Swap the order of checking for TIF-based work and cancellation, and disable IRQs only after checking and processing TIF-based work; checking TIF with IRQs enabled is a-ok, e.g. IRQs and preemption _must_ be enabled before handling the pending work. Signed-off-by: Sean Christopherson --- drivers/hv/mshv_vtl_main.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/hv/mshv_vtl_main.c b/drivers/hv/mshv_vtl_main.c index aa09a76f0eff..4ca13c54c0a0 100644 --- a/drivers/hv/mshv_vtl_main.c +++ b/drivers/hv/mshv_vtl_main.c @@ -735,16 +735,8 @@ static int mshv_vtl_ioctl_return_to_lower_vtl(void) struct hv_vp_assist_page *hvp; int ret; - local_irq_save(irq_flags); - if (READ_ONCE(mshv_vtl_this_run()->cancel)) { - local_irq_restore(irq_flags); - preempt_enable(); - return -EINTR; - } - ti_work = READ_ONCE(current_thread_info()->flags); if (unlikely(ti_work & VTL0_WORK)) { - local_irq_restore(irq_flags); preempt_enable(); ret = mshv_do_pre_guest_mode_work(ti_work); if (ret) @@ -753,6 +745,13 @@ static int mshv_vtl_ioctl_return_to_lower_vtl(void) continue; } + local_irq_save(irq_flags); + if (READ_ONCE(mshv_vtl_this_run()->cancel)) { + local_irq_restore(irq_flags); + preempt_enable(); + return -EINTR; + } + mshv_vtl_return(&mshv_vtl_this_run()->cpu_context); local_irq_restore(irq_flags); -- 2.51.0.268.g9569e192d0-goog