From patchwork Thu Mar 14 23:26:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13592945 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C0D5C54E6A for ; Fri, 15 Mar 2024 00:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8L5WrB2/z6TOo0agpjkGCMKiutfLS6g6otExlVSKWz4=; b=el56O/OEmix2OG EOoYhmZ4ma9WgLo9reh3wtKI5DSYcnZ5FMRAQLSbd7a6OihZ498M2DHABv8n5ByhZ3e+M1boVJTO4 7UVMDe9Gh7a00EKLH1SJG8buiZmsSP9jT76WEuqMELyj46Zb4yt0m3A8BOAjXJ1Dd+B7l7IHmHee+ 7YpYeWQTlXZJjeL3Z6fgKBdyOc7I0H7OM/MSXovkvVxdciUCUJNBrRX4of+VbNLTrCsSKB0Yecq91 QwZ3zKK3L9RwTKpY6W+vw6wcOQN/cC40FeD4K77xXJTA7cVkB1BJmGlwz5F5i7nYkhT/s/2G1Ur6D cXb2DVaVx2D3aGZKL4uw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkvUQ-0000000GAn8-1wpL; Fri, 15 Mar 2024 00:32:02 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkuTR-0000000G013-0E5o for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2024 23:27:05 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-dcc0bcf9256so2013251276.3 for ; Thu, 14 Mar 2024 16:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710458813; x=1711063613; darn=lists.infradead.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=bGD1oHLzIwlI71Um3uWf9rz8YDkt0fT9aZFmZxidv5s=; b=PAUzV/vSfJRkljJvJJVdoBy+eFTx3Mo8vYwMHSjW4oBFmGYiSPZ/mN6KL43WekCIWj BBAPZuoiekVIEhGl4cVktgdly9h0Az7rvg1hbYPsjyZZ+Ja9I9DARa9DTnLnanVfD7Xu gfoLjyjpk9Ic9B5lR5sofpb6gdE2XtgqL2GveyQTNtrcrcr4KiUPZMt5SxZVm2w4TmM0 BwLr/aCi2flTlHHUxEx/6pGeW4RdIJwjGlmfRs3vZ3jrvzi1wwKjtYFE1lVZc5Di1I0m 4QgP6fHLPsky4uiOTm6K0Be0WRANahL3Ol/VssVJZtWQVhCGay0vOCB/4geliE1nAZZW DjHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710458813; x=1711063613; 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=bGD1oHLzIwlI71Um3uWf9rz8YDkt0fT9aZFmZxidv5s=; b=uPpS2MPvlMIv48K3Ezei/vuFVIOaYDAurHvKO9WTaTrsGMnM7LdIwn9/AQYm/FY6li 6R/6qI27/C9VVehLkQvkfiA1Wm/dNZ9JPpslOFk0bfOaLi2Y+CXXUZ3Nws/hgm6Mx3Q7 MOG7Bvb5uewzFWB0sc3XQUYTA75ENOm8744SSvyjCrFfiMbOldVUQa+fNkVhVcQMnNuG yCxzVulEKw2d+x/eu4xKKpFuEumhyERVtb3wugMFEjRFODbhx5Y1CXm0NONqFrrsXMUa wGL92RE5RW6gtC5zJJvYG2rQXf4KzbXhVmRHAHb6C/2uo/KPXXj6SoBpTiwZ2xM5f3e4 Y6FA== X-Gm-Message-State: AOJu0YyDAxs3pv5R0toOa2kluCTMn1U+ZrBndu70lInQzkUVsJT9QuN4 2zSYyIbvUv9HKcPo/TOAV/PCfL6t8rallcBqHJubUICngoRlQ2mtjpDS7C4bbyYGb55WLDe47WW pFA== X-Google-Smtp-Source: AGHT+IEf2SHyoW7Ci/nXvsu/vvl6dD716Be1qw4xm14NPqmYsKQJNpbDJU6sbwjkwsuGTYDcc+4TPOzUy5A= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1b85:b0:dbe:30cd:8fcb with SMTP id ei5-20020a0569021b8500b00dbe30cd8fcbmr188618ybb.0.1710458812732; Thu, 14 Mar 2024 16:26:52 -0700 (PDT) Date: Thu, 14 Mar 2024 16:26:26 -0700 In-Reply-To: <20240314232637.2538648-1-seanjc@google.com> Mime-Version: 1.0 References: <20240314232637.2538648-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog Message-ID: <20240314232637.2538648-8-seanjc@google.com> Subject: [PATCH 07/18] KVM: selftests: Explicitly clobber the IDT in the "delete memslot" testcase From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Paolo Bonzini , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Ackerley Tng X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240314_162657_773322_54695713 X-CRM114-Status: GOOD ( 13.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Explicitly clobber the guest IDT in the "delete memslot" test, which expects the deleted memslot to result in either a KVM emulation error, or a triple fault shutdown. A future change to the core selftests library will configuring the guest IDT and exception handlers by default, i.e. will install a guest #PF handler and put the guest into an infinite #NPF loop (the guest hits a !PRESENT SPTE when trying to vector a #PF, and KVM reinjects the #PF without fixing the #NPF, because there is no memslot). Note, it's not clear whether or not KVM's behavior is reasonable in this case, e.g. arguably KVM should try (and fail) to emulate in response to the #NPF. But barring a goofy/broken userspace, this scenario will likely never happen in practice. Punt the KVM investigation to the future. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/set_memory_region_test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/testing/selftests/kvm/set_memory_region_test.c index 06b43ed23580..9b814ea16eb4 100644 --- a/tools/testing/selftests/kvm/set_memory_region_test.c +++ b/tools/testing/selftests/kvm/set_memory_region_test.c @@ -221,8 +221,20 @@ static void test_move_memory_region(void) static void guest_code_delete_memory_region(void) { + struct desc_ptr idt; uint64_t val; + /* + * Clobber the IDT so that a #PF due to the memory region being deleted + * escalates to triple-fault shutdown. Because the memory region is + * deleted, there will be no valid mappings. As a result, KVM will + * repeatedly intercepts the state-2 page fault that occurs when trying + * to vector the guest's #PF. I.e. trying to actually handle the #PF + * in the guest will never succeed, and so isn't an option. + */ + memset(&idt, 0, sizeof(idt)); + __asm__ __volatile__("lidt %0" :: "m"(idt)); + GUEST_SYNC(0); /* Spin until the memory region is deleted. */