Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2123005rdf; Mon, 6 Nov 2023 05:31:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IF65eaV4eq3qQPTzLyyAyqzE5cQBM0brVV3LHDu476JVpIpYCSJO27qyxAxqtg3hYpl7bSv X-Received: by 2002:a05:6a20:3d03:b0:14e:b4d5:782d with SMTP id y3-20020a056a203d0300b0014eb4d5782dmr28730736pzi.2.1699277473271; Mon, 06 Nov 2023 05:31:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699277473; cv=none; d=google.com; s=arc-20160816; b=O1RCXu89gF93kH6EueyCpUJTVKfi3JtmjW7d8QQ7xxwemlMJFJFAj2p9/kRn5LBz7r vfRY4ehRlvPdI69xKxISVe0fi0vEz++njU05bWAMtfr5w5uyigTTr0cnS1/ehDQpQx3+ 2FV1STCq5hOdHIveJxMkOwAVCWp++Me2BkkBbMRJXvQyODHS4N6EKzMu6bOWn/yy7Sbj d+bN6LbxzgaUud14hKvXpBdXGFQCl7E8pfDoXRzsnJVvKfrYIVEy/2piXikoUDgWWCRO YLf6fSSgqCD6qAQkWzW03+Z4gRXpzZkU6BQcYONsmt4jGxuxQTilCL56ehp1qIWFO5xI T0cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=sKN9wen/tm7cB97ghnIhNBCP5XfRBMi4Tg5ZYI9TW8s=; fh=40T7eROG8cMX7AgR0nYbDhAs71YhHrArMF/A8tRYCr8=; b=Le0hJcnyVbccwFRQnE+LPC9FbMwL68zcSo53+0+FODRK+Za9vyiMmtdfCHKMyt8ZGg 1r1n5DhIg2QstDkv56ZVaaj9358gc2uX2j1jWAdM/Zciza1XbcAGKmHB86DJr5nIJHQ/ vmSXcXWjVhDHnt8oU+64iGRT9DdoGiWd27QqhkYY4ZBBxmtjJSnf74fNRoSPDjUjrGR0 OhlW5t7gTSi6cZSufaJjlXl9txoAAWVMx5WdaIg01enR60bdM25esiQPSM6v6lx1/MLA Jl7LxOPvmRZTYilVnQYgx1DzgN++J6O4Jn3rCvU9l7PGm0N6LJFCMFU3SZrXFHhgWFiL aibQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tkp5vxJU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id t3-20020a17090340c300b001c73d73f163si8619579pld.505.2023.11.06.05.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 05:31:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tkp5vxJU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id E956080A5F2D; Mon, 6 Nov 2023 05:31:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232713AbjKFNa6 (ORCPT + 99 others); Mon, 6 Nov 2023 08:30:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232718AbjKFNa4 (ORCPT ); Mon, 6 Nov 2023 08:30:56 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 838D210A; Mon, 6 Nov 2023 05:30:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699277453; x=1730813453; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=GcPOwqKIRcSDpD/XkGdZ5KVAeJljJ23LDoDjt600Qfg=; b=Tkp5vxJUJyXrBZ2wV/laQ+hredbTr6MbNtHiMB6j8I6jylMIhHh9BmJt DjKHAN/ZeHXFLI1RWWe5kdPeXU7C4fwsv5dhDJ+a1q2WxKn4XhaakZVP/ X8GtrTjBbryVH1/1/Bjz6R7wkgXsiR8X05WcKkRYbWZhrcfyC7u+xnPXM zx/TbCqECwCSaRbytAnB5sfKcbHqgnRoLynCR9cyc0YcxoxhrSgMxfwdA TZIxf9+V0zQioMRzOtTF3CFWnFBTzfsccD90L1D8RDilDvxABse8Ug6Di ZTXdPEITWBSk4tp4mkEokSc7s0sBmq0J5nfLAc2ksFK7fL002AUA3szAy w==; X-IronPort-AV: E=McAfee;i="6600,9927,10885"; a="2263458" X-IronPort-AV: E=Sophos;i="6.03,281,1694761200"; d="scan'208";a="2263458" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2023 05:30:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10885"; a="755855766" X-IronPort-AV: E=Sophos;i="6.03,281,1694761200"; d="scan'208";a="755855766" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.159.165]) by orsmga007.jf.intel.com with ESMTP; 06 Nov 2023 05:30:42 -0800 Date: Mon, 6 Nov 2023 21:29:10 +0800 From: Xu Yilun To: Paolo Bonzini Cc: Sean Christopherson , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Xu Yilun , Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Subject: Re: [PATCH v13 20/35] KVM: x86/mmu: Handle page fault for private memory Message-ID: References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-21-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Mon, 06 Nov 2023 05:31:10 -0800 (PST) On Sun, Nov 05, 2023 at 05:19:36PM +0100, Paolo Bonzini wrote: > On Sun, Nov 5, 2023 at 2:04 PM Xu Yilun wrote: > > > > > +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, > > > + fault->is_private); > > > +} > > > + > > > +static int kvm_faultin_pfn_private(struct kvm_vcpu *vcpu, > > > + struct kvm_page_fault *fault) > > > +{ > > > + int max_order, r; > > > + > > > + if (!kvm_slot_can_be_private(fault->slot)) { > > > + kvm_mmu_prepare_memory_fault_exit(vcpu, fault); > > > + return -EFAULT; > > > + } > > > + > > > + r = kvm_gmem_get_pfn(vcpu->kvm, fault->slot, fault->gfn, &fault->pfn, > > > + &max_order); > > > + if (r) { > > > + kvm_mmu_prepare_memory_fault_exit(vcpu, fault); > > > + return r; > > > > Why report KVM_EXIT_MEMORY_FAULT here? even with a ret != -EFAULT? > > The cases are EFAULT, EHWPOISON (which can report > KVM_EXIT_MEMORY_FAULT) and ENOMEM. I think it's fine > that even -ENOMEM can return KVM_EXIT_MEMORY_FAULT, > and it doesn't violate the documentation. The docs tell you "what > can you do if error if EFAULT or EHWPOISON?"; they don't > exclude that other errnos result in KVM_EXIT_MEMORY_FAULT, > it's just that you're not supposed to look at it Thanks, it's OK for ENOMEM + KVM_EXIT_MEMORY_FAULT. Another concern is, now 3 places to report EFAULT + KVM_EXIT_MEMORY_FAULT: if (!kvm_slot_can_be_private(fault->slot)) { kvm_mmu_prepare_memory_fault_exit(vcpu, fault); return -EFAULT; } file = kvm_gmem_get_file(slot); if (!file) return -EFAULT; if (fault->is_private != kvm_mem_is_private(vcpu->kvm, fault->gfn)) { kvm_mmu_prepare_memory_fault_exit(vcpu, fault); return -EFAULT; } They are different cases, and seems userspace should handle them differently, but not enough information to distinguish them. Thanks, Yilun > > Paolo > >