From patchwork Wed Nov 8 11:17:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Saenz Julienne X-Patchwork-Id: 162970 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp843298vqo; Wed, 8 Nov 2023 03:22:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IHeqTYKV31Sgh0ed4dV4e+YUbBq7jiHYpW6QF4FFS02A6uWqI71F1eFsEYny9RRch9Ug3Ex X-Received: by 2002:a05:6808:23cb:b0:3b2:e0f0:e53d with SMTP id bq11-20020a05680823cb00b003b2e0f0e53dmr2055596oib.37.1699442564669; Wed, 08 Nov 2023 03:22:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699442564; cv=none; d=google.com; s=arc-20160816; b=HEDf17bjwGjwOrZDM6MIOhl5/fRUpH/uGmvwq0ZJd7VR6CA6Mu8G0uh7JcNVxB8PRy 1PTHVj0YN0zRYiWYj96Bzwcb4bWBmhi1mKIQ9kfiyixYVOqwoAasCQEOl1DIS3hFxYcm awLPB9/SGxMcssk5N7NWcC6H1Z4VrGlm8t0WD2nl1GUR3PmAwHQxENu0qmdLec1s4YaD nowlPgXh+d4tbAqevVRLH1COykJiQrTIHsYhRK16xmBZ3yHAR/nSGz3/L7pz1QffjUoo g++u0RuwFTfajPnth9t4Bs1yxZTHU+99aaRO1vcaf3ldAagk0kt47U7M+lkh6QVGjEXc cRpw== 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=oGmQSWddAE8KqMq8lmVDTRLTnkN/hdaUFRsiDOi+ttg=; fh=Qdq7NqGm5JR9LpctBpXjoRI38Lb2mCk6xy26GEDp1Bg=; b=nR1bUOjmU7EpNR6R3/kj+CoQGSbWETkeZDDJ5UulvM5jm+f7c91+sUWdjy+2306Y6C RlX51U/+nAm7g5ZZ+NiyWSAz0Gytz8aHDDCn5XmGSE6J4aZN8UsciGy9qZzARJG7kprO qbp+kBCtDiGVfHKJy/zWVw6mji3CRbLli+62qHaT6d3rBdQanJruOkvb5rW9LVKr6f4C MSsUMT4VoGQPqj/+30ePYwX/yRywVLjgPwCwCVjuCVr2PoOHDf8gpqoSLRygMouhhza5 /dq7JqALe6O/0vyu6xPtbZQkPptu7zRI8ZdRzMvAkaOQYvTMVABNkKBJd3ruqA6tgl+j uJrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=R0A3p8uD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id j2-20020a056a00130200b0069100d1fc37si12848937pfu.49.2023.11.08.03.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:22:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=R0A3p8uD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id A3D1680615CE; Wed, 8 Nov 2023 03:22:41 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344807AbjKHLWJ (ORCPT + 32 others); Wed, 8 Nov 2023 06:22:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344686AbjKHLVy (ORCPT ); Wed, 8 Nov 2023 06:21:54 -0500 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79FD91BF3; Wed, 8 Nov 2023 03:21:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1699442512; x=1730978512; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oGmQSWddAE8KqMq8lmVDTRLTnkN/hdaUFRsiDOi+ttg=; b=R0A3p8uD3LsJkr+hknwGV/eFTPcdmhtskkROAvqShaRGrh3/7kuIY6J5 E1ayrjy8yPpJDtg5MnX8hQfU94cr+Tn/JzSv3TLHJKJPtXnt4Vb6yc0uE RlmSPbWY/jS/ePgDiCUEHdcPNwDldtVccxL7H3IWSVm+B6ChCt736aqRr 8=; X-IronPort-AV: E=Sophos;i="6.03,286,1694736000"; d="scan'208";a="361603061" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1a-m6i4x-54a853e6.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2023 11:21:50 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1a-m6i4x-54a853e6.us-east-1.amazon.com (Postfix) with ESMTPS id 9FEC448ED2; Wed, 8 Nov 2023 11:21:46 +0000 (UTC) Received: from EX19MTAEUC001.ant.amazon.com [10.0.10.100:61983] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.4.34:2525] with esmtp (Farcaster) id 93cbfb2a-c5dc-4a75-bf0d-dbebc073ea77; Wed, 8 Nov 2023 11:21:45 +0000 (UTC) X-Farcaster-Flow-ID: 93cbfb2a-c5dc-4a75-bf0d-dbebc073ea77 Received: from EX19D004EUC001.ant.amazon.com (10.252.51.190) by EX19MTAEUC001.ant.amazon.com (10.252.51.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Wed, 8 Nov 2023 11:21:39 +0000 Received: from dev-dsk-nsaenz-1b-189b39ae.eu-west-1.amazon.com (10.13.235.138) by EX19D004EUC001.ant.amazon.com (10.252.51.190) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Wed, 8 Nov 2023 11:21:34 +0000 From: Nicolas Saenz Julienne To: CC: , , , , , , , , , , , , , , , Nicolas Saenz Julienne Subject: [RFC 16/33] KVM: x86/mmu: Expose R/W/X flags during memory fault exits Date: Wed, 8 Nov 2023 11:17:49 +0000 Message-ID: <20231108111806.92604-17-nsaenz@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231108111806.92604-1-nsaenz@amazon.com> References: <20231108111806.92604-1-nsaenz@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.13.235.138] X-ClientProxiedBy: EX19D043UWA003.ant.amazon.com (10.13.139.31) To EX19D004EUC001.ant.amazon.com (10.252.51.190) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 08 Nov 2023 03:22:41 -0800 (PST) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781994686707577523 X-GMAIL-MSGID: 1781994686707577523 Include the fault's read, write and execute status when exiting to user-space. Signed-off-by: Nicolas Saenz Julienne --- arch/x86/kvm/mmu/mmu.c | 4 ++-- include/linux/kvm_host.h | 9 +++++++-- include/uapi/linux/kvm.h | 6 ++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 4e02d506cc25..feca077c0210 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4300,8 +4300,8 @@ static inline u8 kvm_max_level_for_order(int order) static void kvm_mmu_prepare_memory_fault_exit(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) { - kvm_prepare_memory_fault_exit(vcpu, fault->gfn << PAGE_SHIFT, - PAGE_SIZE, fault->write, fault->exec, + kvm_prepare_memory_fault_exit(vcpu, fault->gfn << PAGE_SHIFT, PAGE_SIZE, + fault->write, fault->exec, fault->user, fault->is_private); } diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 71e1e8cf8936..631fd532c97a 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2367,14 +2367,19 @@ static inline void kvm_account_pgtable_pages(void *virt, int nr) static inline void kvm_prepare_memory_fault_exit(struct kvm_vcpu *vcpu, gpa_t gpa, gpa_t size, bool is_write, bool is_exec, - bool is_private) + bool is_read, bool is_private) { vcpu->run->exit_reason = KVM_EXIT_MEMORY_FAULT; vcpu->run->memory_fault.gpa = gpa; vcpu->run->memory_fault.size = size; - /* RWX flags are not (yet) defined or communicated to userspace. */ vcpu->run->memory_fault.flags = 0; + if (is_read) + vcpu->run->memory_fault.flags |= KVM_MEMORY_EXIT_FLAG_READ; + if (is_write) + vcpu->run->memory_fault.flags |= KVM_MEMORY_EXIT_FLAG_WRITE; + if (is_exec) + vcpu->run->memory_fault.flags |= KVM_MEMORY_EXIT_FLAG_EXECUTE; if (is_private) vcpu->run->memory_fault.flags |= KVM_MEMORY_EXIT_FLAG_PRIVATE; } diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 03f5c08fd7aa..0ddffb8b0c99 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -533,7 +533,13 @@ struct kvm_run { } notify; /* KVM_EXIT_MEMORY_FAULT */ struct { +#define KVM_MEMORY_EXIT_FLAG_READ (1ULL << 0) +#define KVM_MEMORY_EXIT_FLAG_WRITE (1ULL << 1) +#define KVM_MEMORY_EXIT_FLAG_EXECUTE (1ULL << 2) #define KVM_MEMORY_EXIT_FLAG_PRIVATE (1ULL << 3) +#define KVM_MEMORY_EXIT_NO_ACCESS \ + (KVM_MEMORY_EXIT_FLAG_NR | KVM_MEMORY_EXIT_FLAG_NW | \ + KVM_MEMORY_EXIT_FLAG_NX) __u64 flags; __u64 gpa; __u64 size;