From patchwork Wed Jul 19 08:33:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 122473 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2309845vqt; Wed, 19 Jul 2023 02:26:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlGNLlPDAd4Kx3G12pm67TZ/LtZaYTK+V+A4u7y7uqH2LFg/HcdU6JjwsKVBBS7S7T4x0rxy X-Received: by 2002:a17:90b:4003:b0:262:db8a:318a with SMTP id ie3-20020a17090b400300b00262db8a318amr15299194pjb.30.1689758785307; Wed, 19 Jul 2023 02:26:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689758785; cv=none; d=google.com; s=arc-20160816; b=KM+5wF+gV/T3xT6D0fLfAonq8aW0ejNFoLlbv2PEHZAWB72/4WBF2Dwxg95/nQDmF2 XczG+4ufHeSBjB9zosTzKrQ5ElWfjRCJVSk+C+WhKg8C1vu+1tlCePOJT7wyPbp04SUQ hG9VVQylERSYFgsa/oqO08ft9thw1RnspYLp6fnYjm1emW/FxBp7V5GkS/5/lKSmBY4z MTnAvCEOGf1yp8sNDkJU1V47FKevg3wMv0SjUkaFk9tdX/KHQAgEBy3f8c86rS3OxEek 8HI4l6S2FSdNYPTMDmNITSCWM1fgbWY3clEG8pYT/dPivTl1pU0qcOOX2jpJRHBE5sYu J9bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=u6vY+tGd7gKeprypgLwq7ldr1B6lfjWwDPl4SksR3QU=; fh=EPInOf6TfVyiSSRVKPXACBXMF1VmttgXrcIqBwES350=; b=Jtdoo151IyJR6esjC+uaGxK99tc9zMtyb2GvwymkURqGnehtQUkiDAOZTeG2qUuU5n Edmjo4ZQvcyq+/K1Ex2oviFfU+uqq3Zb0cPS8JJ73NTlCxj3hF/2e8f6uca4mP285bc1 s4rD6XRubtjA0ZtB1SBpfR5/ryvs9SrBDf2O24aeO9wFHUIiGPJsod90HdY++7S6NVSi 0kKDrsBApXOxOy1JqYvnMaFg4qW2AIGK3fVW5tu3wCkOFWTONO3s9XzUhPPPwwF+V86p 11wU48FrTyeoac1dqk4yHASaZ7UzoMlWZ+HlpDblWTPfY1QrDwUjvLtB7xNFTdYSTnoi SuGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ceF1wHvX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ft22-20020a17090b0f9600b00263e8027e64si1068239pjb.138.2023.07.19.02.26.12; Wed, 19 Jul 2023 02:26:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ceF1wHvX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231134AbjGSJA6 (ORCPT + 99 others); Wed, 19 Jul 2023 05:00:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231124AbjGSJAv (ORCPT ); Wed, 19 Jul 2023 05:00:51 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E71A19B1; Wed, 19 Jul 2023 02:00:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689757250; x=1721293250; h=from:to:cc:subject:date:message-id; bh=nF9H3bO49HKidU+fzoDygP2E0naSyQmKuj1/sp95mHk=; b=ceF1wHvXKPyPsoMJq+dbXFsZvPHK5oHMfE06ocWnxTNHr49LeHXFYyob A29H8gBobX/LL6n32li3tMjXwh2V06+SrFKfWle1vT7YBEQd6uXYwt0lb 4KzFKuqyXRIbhGpuwW1V2X1CUi/0pkjy7dsBzaJDY8uzDMsMpJCN3Mwpt xicxCCKPKGZnvOr4OUety8KEn84qs5xY7CqL1YwyX0Q11Ds+Z1h2brGBW bvVq8HwqQAwLVkG7tITRPEkgoBhC9FR9xTaoJGN8t8cg8vqKi3I0RatBv wHA3nuyUuMi1SlR0KIdy6NTW403SnaXgFqL95BSkXPYdMcrimnBEk6p6G g==; X-IronPort-AV: E=McAfee;i="6600,9927,10775"; a="397263959" X-IronPort-AV: E=Sophos;i="6.01,216,1684825200"; d="scan'208";a="397263959" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jul 2023 02:00:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10775"; a="701227029" X-IronPort-AV: E=Sophos;i="6.01,216,1684825200"; d="scan'208";a="701227029" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jul 2023 02:00:48 -0700 From: Yan Zhao To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, seanjc@google.com, stevensd@chromium.org, Yan Zhao Subject: [PATCH] KVM: allow mapping of compound tail pages for IO or PFNMAP mapping Date: Wed, 19 Jul 2023 16:33:32 +0800 Message-Id: <20230719083332.4584-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771840507779734218 X-GMAIL-MSGID: 1771840507779734218 Allow mapping of tail pages of compound pages for IO or PFNMAP mapping by trying and getting ref count of its head page. For IO or PFNMAP mapping, sometimes it's backed by compound pages. KVM will just return error on mapping of tail pages of the compound pages, as ref count of the tail pages are always 0. So, rather than check and add ref count of a tail page, check and add ref count of its folio (head page) to allow mapping of the compound tail pages. This will not break the origial intention to disallow mapping of tail pages of non-compound higher order allocations as the folio of a non-compound tail page is the same as the page itself. On the other side, put_page() has already converted page to folio before putting page ref. Signed-off-by: Yan Zhao --- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) base-commit: 24ff4c08e5bbdd7399d45f940f10fed030dfadda diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 138292a86174..6f2b51ef20f7 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2551,7 +2551,7 @@ static int kvm_try_get_pfn(kvm_pfn_t pfn) if (!page) return 1; - return get_page_unless_zero(page); + return folio_try_get(page_folio(page)); } static int hva_to_pfn_remapped(struct vm_area_struct *vma,