From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 EC20613341A for ; Thu, 7 Mar 2024 18:24:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709835886; cv=none; b=TvE4JMJA+j5WftfRqqy9hY4qa6ZgjnH5xpeBABBPi+1HpkiMf+9FwNlAMeYBm0ky9XLmYCQwlNDvCLpdmUUaeuiLS0mUnnIedQgyv71EQnd3U6WRlusrMlnRXzIl7BGOSJp1U9YdE0UX38U/2UaA8EtOaZ9Augs1soQdr9KwHxA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709835886; c=relaxed/simple; bh=o5cNRugZZzIdyCSXKjEvmt2jqbDFCbmVxFG4IAatR2s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iEsXY1pxxpb9yaJiMeSaFb6PtAs5ZrSvwmTtrPVjXK4onG7/L0mHuTTevfqVAmsIb8x5qZgnt84wfwI/ZjOp2m+7mNvzWdK0nqqqg7wpJMdI18kIisfZz3W/0hFl64yMCfBP+jDYWtalkNNGTOk/1l9v+G9fKqqHBiBJ+Gg7dN8= 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=Zq8Wt8St; arc=none smtp.client-ip=209.85.219.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="Zq8Wt8St" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbf618042daso1891187276.0 for ; Thu, 07 Mar 2024 10:24:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709835884; x=1710440684; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tmf20qquXCm5BgDJjOs0QNTSjGXizLhNZTJUFBFz11s=; b=Zq8Wt8St+xF2cyam9YwfVwe4x3CobSKF5I5wtvcErbEU3ZZrx5ribcXs44RHRfOyt6 YU1wPDXuxJyPDnJTbgDixUsEDPUSYv4aUAJZilMZBXhnWcivw3dbMjLZx7rnv+2nX5jK YZ2fDP1cUT0xjj/iyDRMFd/Rb5k9DvMZhg7+wiRHkjla7vK2sr8hdvtP/Nz7P0P3aHqN f84Nv+xT5HBtb239pRslSoCSdyUAriMrgQ28nsPTNfHkRKgKGz9HGTqeHLBbit1Wf3Uq 2UKytWYkJVbkOpmCTzCvH2jBC4dysn6yw6WiPek/BRkSTlqytIQGunXtCAx7B9MAvxue i0uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709835884; x=1710440684; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tmf20qquXCm5BgDJjOs0QNTSjGXizLhNZTJUFBFz11s=; b=RKT8WDPVZJsC6lbpHsXiKzA6nbsw1ox+Tkl/TmTaSBwoyVbZES4UKj+VLGYyHLLQ0G Uf30BcKU/ZbOYpjA5lSgid5cS+o/DZjbdJ6CVY5vTGrs1Hu+jdv8GFV7ZwKIOS/WK1Qz TP973gT0LhmfeqAVnqBqQaaD9S/XiqLQXQxODOR8/MdvZH3p5aQxL8DuTNDgJ6DFSMOY T6zzbvcbs7zCmjvRSZqUf6KAptX0oGQEFFqvtyQ/mc8715wOWqcGIfGi1+b6bXVbo4Wd f5P7DtzWAFDrdFdob02rUBkEohWZ9T6q4u8Bfn848M03dyR45zyVjOGP+drUArpzD49V Btww== X-Gm-Message-State: AOJu0YwWq+jL6dNu/8qAbvw2ziGboPvlClsEFtm7vutm4H5HTeJ6ZWHm yT+diiRR7nQEsoidVkv/8d6B1Ka4BL2ENWiXFOIYtRlaWqfhYA+IVavfIl1uld8we+YfoterOHb xVA== X-Google-Smtp-Source: AGHT+IGBNywGbWe053DjXxN00I9scAq0pLzYUHamC39E63b0Ie62RJr8RSL5xpW1+UKIKkf9I0pzPARRwWU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:18d3:b0:dc7:865b:22c6 with SMTP id ck19-20020a05690218d300b00dc7865b22c6mr771085ybb.8.1709835883899; Thu, 07 Mar 2024 10:24:43 -0800 (PST) Date: Thu, 7 Mar 2024 10:24:42 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240307054623.13632-1-manali.shukla@amd.com> <20240307054623.13632-6-manali.shukla@amd.com> Message-ID: Subject: Re: [PATCH v1 5/5] selftests: KVM: SVM: Add Idle HLT intercept test From: Sean Christopherson To: Manali Shukla Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, pbonzini@redhat.com, shuah@kernel.org, nikunj@amd.com, thomas.lendacky@amd.com, vkuznets@redhat.com, bp@alien8.de Content-Type: text/plain; charset="us-ascii" On Thu, Mar 07, 2024, Sean Christopherson wrote: > On Thu, Mar 07, 2024, Manali Shukla wrote: From: Manali Shukla > > + xapic_enable(); > > + > > + icr_val = (APIC_DEST_SELF | APIC_INT_ASSERT | VINTR_VECTOR); > > + > > + for (i = 0; i < NUM_ITERATIONS; i++) { > > + xapic_write_reg(APIC_ICR, icr_val); > > + asm volatile("sti; hlt; cli"); > > Please add safe_halt() and cli() helpers in processor.h. And then do: Doh, saw something shiny and forgot to finish my though. For safe_halt(), copy the thing verbatim from KVM-Unit-Tests, as not everyone is familiar with the sti=>hlt trick. /* * Execute HLT in an STI interrupt shadow to ensure that a pending IRQ that's * intended to be a wake event arrives *after* HLT is executed. Modern CPUs, * except for a few oddballs that KVM is unlikely to run on, block IRQs for one * instruction after STI, *if* RFLAGS.IF=0 before STI. Note, Intel CPUs may * block other events beyond regular IRQs, e.g. may block NMIs and SMIs too. */ static inline void safe_halt(void) { asm volatile("sti; hlt"); }