From patchwork Fri Sep 8 22:28:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anish Moorthy X-Patchwork-Id: 13377863 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFF34EEB571 for ; Fri, 8 Sep 2023 22:29:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343788AbjIHWaA (ORCPT ); Fri, 8 Sep 2023 18:30:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343762AbjIHW36 (ORCPT ); Fri, 8 Sep 2023 18:29:58 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC20B1FCA for ; Fri, 8 Sep 2023 15:29:54 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-58e4d2b7d16so30133467b3.0 for ; Fri, 08 Sep 2023 15:29:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1694212194; x=1694816994; 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=LzMBBO3+QOcCxytQD9gvt8PFFPzKUty4hf8hE8hWFnE=; b=x9/DqsqR6rkAIzq/iuYA2jvTxSmcvPBIFgdA6yYOXjZi3m/Woq3Bm8y23LHlGXgndn cnqjzmarxy0pJupyULFIqB9HOeNnNMB64VkYa5QlQOFg0A+W8ATfopIP8ZF33hpdgNNr ygXQK7WSMeaTNza5N/M5nRmIi/Bg8W0FnFWGbkpITP+DBdUwp+ClnmgmOhZJaatdL2VE O5uewL8fNkPpE8vBfs02jCXd53NQDR4aHonCTiXdr06+TKYaD6q1n1O7vHSqu3B+rJxu eKlknLOrsCpun4Mxdp8CuM59wE+AOaCyX+5RWZM5PPbNk/Wh1EXDFuHWAYZRDMvzINAv OPRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694212194; x=1694816994; 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=LzMBBO3+QOcCxytQD9gvt8PFFPzKUty4hf8hE8hWFnE=; b=gZTDI017bwzepodjIPRYb3dwbvex5cFCTlLknwUXQ1lFIFJ2uZYi+nMrNHxX7hHPxT nVXEma+gDNSg7WjdiBC5jBvRH2ZDqITXkvoqS/PRG6lxyw9WDojmThd+djMXYWKWbVvO agxmBNa9AmT8jHH3ifUW3jGN6hJj/4U8XpU0jmp8kLUznJGQKNyEyn46Hy3qcP5tKMMs 0EYSD1jhBSPc7plM+mm2I4sJsqWFkVJTjKNTIsJVCoJJm0VqtwCSewJAkS56GpY9q2Tl KIr/zfA/nPUKfRWKzoMJCf0LAC5PKJ5Xup+XPVK3TLgJt4uLC02sZyd/cxL4DRnFeKDk 1tHQ== X-Gm-Message-State: AOJu0Yy5yT2UV8z63wxjpse6hr3bAFUnv5V/If0ns2/LdSvEL9Kif2kU xcLasuYdkmsKZHfeAuSjm2JI0YHN7mes5g== X-Google-Smtp-Source: AGHT+IGgQ6+xByO+HkT24hG/yB9NqyYPbYWpx7ZIjBxm/QZKjr8AwVFmzf4mP+1g9/qAE5XNiwUyfp/6A4SM3Q== X-Received: from laogai.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:2c9]) (user=amoorthy job=sendgmr) by 2002:a05:6902:168b:b0:d80:cf4:7e80 with SMTP id bx11-20020a056902168b00b00d800cf47e80mr72394ybb.7.1694212194254; Fri, 08 Sep 2023 15:29:54 -0700 (PDT) Date: Fri, 8 Sep 2023 22:28:53 +0000 In-Reply-To: <20230908222905.1321305-1-amoorthy@google.com> Mime-Version: 1.0 References: <20230908222905.1321305-1-amoorthy@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230908222905.1321305-7-amoorthy@google.com> Subject: [PATCH v5 06/17] KVM: x86: Annotate -EFAULTs from kvm_handle_error_pfn() From: Anish Moorthy To: seanjc@google.com, oliver.upton@linux.dev, kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: pbonzini@redhat.com, maz@kernel.org, robert.hoo.linux@gmail.com, jthoughton@google.com, amoorthy@google.com, ricarkol@google.com, axelrasmussen@google.com, peterx@redhat.com, nadav.amit@gmail.com, isaku.yamahata@gmail.com, kconsul@linux.vnet.ibm.com Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Implement KVM_CAP_MEMORY_FAULT_INFO for efaults generated by kvm_handle_error_pfn(). Signed-off-by: Anish Moorthy --- arch/x86/kvm/mmu/mmu.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index e1d011c67cc6..deae8ac74d9a 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -3267,6 +3267,8 @@ static void kvm_send_hwpoison_signal(struct kvm_memory_slot *slot, gfn_t gfn) static int kvm_handle_error_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) { + u64 fault_flags; + if (is_sigpending_pfn(fault->pfn)) { kvm_handle_signal_exit(vcpu); return -EINTR; @@ -3285,6 +3287,17 @@ static int kvm_handle_error_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fa return RET_PF_RETRY; } + WARN_ON_ONCE(fault->goal_level != PG_LEVEL_4K); + + fault_flags = 0; + if (fault->write) + fault_flags = KVM_MEMORY_FAULT_FLAG_WRITE; + else if (fault->exec) + fault_flags = KVM_MEMORY_FAULT_FLAG_EXEC; + else + fault_flags = KVM_MEMORY_FAULT_FLAG_READ; + kvm_handle_guest_uaccess_fault(vcpu, gfn_to_gpa(fault->gfn), PAGE_SIZE, + fault_flags); return -EFAULT; }