Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp294677pxk; Thu, 17 Sep 2020 03:21:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqC6HheSZ+qW8JPgZeexUATzFTpycWSESq73LymJyjQNYo1Gg2+SuNRj40AeThCQEZqu9L X-Received: by 2002:a17:906:7489:: with SMTP id e9mr29413379ejl.154.1600338081974; Thu, 17 Sep 2020 03:21:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600338081; cv=none; d=google.com; s=arc-20160816; b=NrFTn2HfqDGuoik3KAiRYZ6C+OUDcIlPZdV1NpU/iL2PxKbbyCyLJBWJ6tq1mjYUdf nfmHBY4MeqPep4yU69MX/wU5yK9cAsPGyCzLAEcB8sN6Iv692boRdcGam8UBsxBMa9/q TNEuO7SvlwwNFuH+OC7zVTDkLRjRozKiNOK9hVD83/pxlQzqMSEi9wQBA+sTiOkWFlWL FML5Itcz2BqrfUcVJwBV6iT/4+bzzb9qKktzfxuE0RUkKm0tGLECoMqyChqVYWVJLs5f 1JZPQ69uflYseuywPX7X6YpzCo/IRMIxcimmZCWHQBePeGxpCr70Jg70TsiadTgnzn62 g5Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sYHG4V6fy3u/g4UVdawRvlE3KZPiniHhZvdOnhelAps=; b=paQcLhXm1y3rZWl2njr9GVLpRexUnduVZFrXq5dsPxGJXTG+DQl1RzYZ0pSlvnxNSX AK2HedftYQz8/FpTbqx/fRr3zOuovpyLW7nU4XHETmFsjWtBwt3z3b1KjoLeq/2X8/l+ lfi7bhajy4nlqCFGV5oaCd0Z2fUvcpOE+qbct73wFP/n4FqcEvVOIQMS4hXzufaYD4lR xQelCEXyBkR/ExjChIat2TUVSXIRU56G9ZH469BVHFCU7R15ohG566OhJthpM0bVOFP9 s02lbKjBwkl4XI1HUdPDuRyxasOoKJUdfHZNkQPNC4hl51JmZjtFgPcaeucHwEJHuKKC vTGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="R1AU/hLU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e22si13626465edv.198.2020.09.17.03.20.54; Thu, 17 Sep 2020 03:21:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="R1AU/hLU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726520AbgIQKRP (ORCPT + 99 others); Thu, 17 Sep 2020 06:17:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46026 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726180AbgIQKRL (ORCPT ); Thu, 17 Sep 2020 06:17:11 -0400 X-Greylist: delayed 368 seconds by postgrey-1.27 at vger.kernel.org; Thu, 17 Sep 2020 06:17:11 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600337830; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sYHG4V6fy3u/g4UVdawRvlE3KZPiniHhZvdOnhelAps=; b=R1AU/hLUDi/kfh3GEBE7ZcZ6Rb7ITaX04YczHJ4k7ijSHIPWU9Qje8om6YchP0pTsEZDUB MIX+Ca/ifAwf/Xw40vYNGiWHB9KaAJ3hGhh8ERS88p45MmpNeDrwVsrG7Ffy3TmoZo6b2/ FBWVDe33LMWzpi2zpZdLeet0YiTjxYU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-108-yqSV6GPdOoWRQpRVufXO1Q-1; Thu, 17 Sep 2020 06:10:59 -0400 X-MC-Unique: yqSV6GPdOoWRQpRVufXO1Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4937F801AAB; Thu, 17 Sep 2020 10:10:58 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4218101416F; Thu, 17 Sep 2020 10:10:54 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Sean Christopherson , Vitaly Kuznetsov , Ingo Molnar , Wanpeng Li , "H. Peter Anvin" , Borislav Petkov , Jim Mattson , Paolo Bonzini , Joerg Roedel , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-kernel@vger.kernel.org, Thomas Gleixner , Maxim Levitsky Subject: [PATCH v4 1/2] KVM: add request KVM_REQ_OUT_OF_MEMORY Date: Thu, 17 Sep 2020 13:10:47 +0300 Message-Id: <20200917101048.739691-2-mlevitsk@redhat.com> In-Reply-To: <20200917101048.739691-1-mlevitsk@redhat.com> References: <20200917101048.739691-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This request will be used in rare cases when emulation can't continue due to being out of memory, to kill the current VM. Currently only implemented for x86. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/x86.c | 7 +++++++ include/linux/kvm_host.h | 1 + 2 files changed, 8 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 17f4995e80a7e..ea1834dd807f9 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8471,6 +8471,13 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) kvm_vcpu_update_apicv(vcpu); if (kvm_check_request(KVM_REQ_APF_READY, vcpu)) kvm_check_async_pf_completion(vcpu); + + if (kvm_check_request(KVM_REQ_OUT_OF_MEMORY, vcpu)) { + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; + vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; + r = 0; + goto out; + } } if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win) { diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 05e3c2fb3ef78..487c8ed2e3f88 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -146,6 +146,7 @@ static inline bool is_error_page(struct page *page) #define KVM_REQ_MMU_RELOAD (1 | KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP) #define KVM_REQ_PENDING_TIMER 2 #define KVM_REQ_UNHALT 3 +#define KVM_REQ_OUT_OF_MEMORY 4 #define KVM_REQUEST_ARCH_BASE 8 #define KVM_ARCH_REQ_FLAGS(nr, flags) ({ \ -- 2.26.2