Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3480158rdb; Wed, 13 Sep 2023 13:23:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGblzr/9KNFKQ/B3avJjGuXA2K/875jJMgslpgTSU3IAOIZIbbydh4BtW7RgmtPfkfIUXNq X-Received: by 2002:a17:90a:4903:b0:273:f848:e3c4 with SMTP id c3-20020a17090a490300b00273f848e3c4mr3372257pjh.17.1694636610182; Wed, 13 Sep 2023 13:23:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694636610; cv=none; d=google.com; s=arc-20160816; b=agyMczXWyLeBbnf1Vi5mQD5+eiUADT1wH9qcSLwRCkpC5A9OeknkCVDcsqPGKLhNKd yILCIakZN0v2G12ODFOGeYxBLXwZ+gRL1ke1pf3uLC+ydhP5EE6rO++n9KI12Aq25P1N BuG2Qv3o/RL3Qu2Vr7gpBOI7GFAP8f20ZVSzJdLHAniZMTHoalKlqRNRktShKXDEXY+S anB9oIKSieulLdH6bNgatouULI6pkhvxiBxuSSu+WtPFcidUIioG6nNTSZUpyq034DpL qyEfN6j7+U3ra7YqOxsflNnrNzTrnepj3LiqCdU1xZYYaVvJl+5Ng/oHPX+5cNNE2Kb7 zOwA== 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=0XzR5I7KJku7F7SWC+84xSwy53eURsqp6mziMgKZea8=; fh=ANS6iRpdj3ntKSmwSzT4LEHUH9ZAudCj9zvP8/EeThQ=; b=T7oGhzSD5JqwylJ4tnFG/eFoHdGh5FLURQay7+WxqIOVLT1b/p33ODHGO0bExNYHHa EEPE6pz+x/Scqk2xRMqtk8Tg1BlOGE9QuDCxVCZ27EEkPsE55ETim2AxBC/llhymfZXB r6EE5petIA2FmVW/fnwTXpT0bWT43F5xhbmz7DOPMQBd0RcqG9cU7Zs+ZlWQdCyzwWPQ jcRWF3beVktr0uiyN8zTV6uDM+M7HTdaB8UVPyFK4UkSc66BOFzeogvEVtLNaLLaftfr HHURVqL4H10PlDfGiHvrXmyowxbBpGjDv1hRtUv8DlGpnZTBh/PRwqK8HFEALESIEKkF DXQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=K6LDdGpn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id k9-20020a17090a910900b002639acf55c7si2217372pjo.7.2023.09.13.13.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 13:23:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=K6LDdGpn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 76E76812670C; Wed, 13 Sep 2023 03:49:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239743AbjIMKtT (ORCPT + 99 others); Wed, 13 Sep 2023 06:49:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233278AbjIMKtQ (ORCPT ); Wed, 13 Sep 2023 06:49:16 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C3A9CA; Wed, 13 Sep 2023 03:49:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694602152; x=1726138152; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vjzCCiYbRI2Udp8b7ZaBhaYrlSTbrUefC/7glJvCx6s=; b=K6LDdGpny2yjMmpjfIe3OR9AX2x/V4j3oASc8y6R83KI4hLiblVMl8fh eSJD/e8pT5HA73SW4pLuayTqrGoJAUSQ708Y7ZEVjlwdPaRdCTBEcl87q jWgGJtIjUpC4fe37czQiGVWeP4JyyV21bLptJr0FcbSRG3hfpd/xd3IoM Fjq+k1/gKRjw1LR2dpe0edBAMS8TU0Kahw3KUqknTRcF2SAE5/nP89ZCv JVcr1/EGd0u2T7xERBYmz6KTssAFhLRBgXBl5gpSB8yPUVjOeKU85BipD SEGkmD+wqCob8z52aGIvOcwG+g4iO/pGNcB/2cpZEgDUSjGkFH/VQ2Omq g==; X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="377537874" X-IronPort-AV: E=Sophos;i="6.02,143,1688454000"; d="scan'208";a="377537874" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 03:49:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="809635584" X-IronPort-AV: E=Sophos;i="6.02,143,1688454000"; d="scan'208";a="809635584" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 03:49:11 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Michael Roth , Paolo Bonzini , Sean Christopherson , erdemaktas@google.com, Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, linux-coco@lists.linux.dev, Chao Peng , Ackerley Tng , Vishal Annapurve , Yuan Yao , Jarkko Sakkinen , Xu Yilun , Quentin Perret , wei.w.wang@intel.com, Fuad Tabba Subject: [RFC PATCH 2/6] KVM: guestmem_fd: Make error_remove_page callback to unmap guest memory Date: Wed, 13 Sep 2023 03:48:51 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, 13 Sep 2023 03:49:23 -0700 (PDT) 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email From: Isaku Yamahata Implement error_remove_page inode method for KVM gmem. Update struct kvm_gfn_range to indicate unmapping gufs because page is poisoned. Signed-off-by: Isaku Yamahata --- include/linux/kvm_host.h | 2 ++ virt/kvm/guest_mem.c | 47 +++++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 091bc89ae805..e81a7123c84f 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -266,8 +266,10 @@ struct kvm_gfn_range { pte_t pte; unsigned long attributes; u64 raw; + struct page *page; } arg; bool may_block; + bool memory_error; }; bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range); bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range); diff --git a/virt/kvm/guest_mem.c b/virt/kvm/guest_mem.c index 35d8f03e7937..746e683df589 100644 --- a/virt/kvm/guest_mem.c +++ b/virt/kvm/guest_mem.c @@ -305,7 +305,7 @@ static int kvm_gmem_error_page(struct address_space *mapping, struct page *page) struct kvm_gmem *gmem; unsigned long index; pgoff_t start, end; - gfn_t gfn; + bool flush; if (!IS_ENABLED(CONFIG_HAVE_GENERIC_PRIVATE_MEM_HANDLE_ERROR)) return MF_IGNORED; @@ -316,26 +316,43 @@ static int kvm_gmem_error_page(struct address_space *mapping, struct page *page) end = start + thp_nr_pages(page); list_for_each_entry(gmem, gmem_list, entry) { + struct kvm *kvm = gmem->kvm; + + KVM_MMU_LOCK(kvm); + kvm_mmu_invalidate_begin(kvm); + KVM_MMU_UNLOCK(kvm); + + flush = false; xa_for_each_range(&gmem->bindings, index, slot, start, end - 1) { - for (gfn = start; gfn < end; gfn++) { - if (WARN_ON_ONCE(gfn < slot->base_gfn || - gfn >= slot->base_gfn + slot->npages)) - continue; - - /* - * FIXME: Tell userspace that the *private* - * memory encountered an error. - */ - send_sig_mceerr(BUS_MCEERR_AR, - (void __user *)gfn_to_hva_memslot(slot, gfn), - PAGE_SHIFT, current); - } + pgoff_t pgoff; + + if (WARN_ON_ONCE(end < slot->base_gfn || + start >= slot->base_gfn + slot->npages)) + continue; + + pgoff = slot->gmem.pgoff; + struct kvm_gfn_range gfn_range = { + .slot = slot, + .start = slot->base_gfn + max(pgoff, start) - pgoff, + .end = slot->base_gfn + min(pgoff + slot->npages, end) - pgoff, + .arg.page = page, + .may_block = true, + .memory_error = true, + }; + + flush |= kvm_mmu_unmap_gfn_range(kvm, &gfn_range); } + if (flush) + kvm_flush_remote_tlbs(kvm); + + KVM_MMU_LOCK(kvm); + kvm_mmu_invalidate_end(kvm); + KVM_MMU_UNLOCK(kvm); } filemap_invalidate_unlock_shared(mapping); - return 0; + return MF_DELAYED; } static const struct address_space_operations kvm_gmem_aops = { -- 2.25.1