From patchwork Fri Jul 26 23:51:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743471 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3740EC3DA49 for ; Sat, 27 Jul 2024 00:06:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To: From:Subject:Message-ID:References:Mime-Version:In-Reply-To:Date: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bC28fbRseb42Ch2zMqBFWEix5TOk22ZdgToO+ip0K/0=; b=tqJ9kBi+go5kCavMAeXEQKg8u0 vRGIO18dChypRIglYme6Fgs7COiqtfVu/VxI20BN1xOIXlGmnPncVsC4v57cGfyOB1MYhHONqYDiT rCxkboSNj49zDddbkUW8w1DzwS5s2hBqXI5mF+VqksEFfi9Blgq3ud+JnMAkvZZTSw2RoalB8ccOU b75PKUKLirYCmyfhO8y8Mz1W1cPURXZ4IxPNd/S9Z4ZleUUpbFuHIKbDsj1SuKDbw3PQ07Jiezecr 1zqZ6InR3LlyEWOikGxSfGYL/Mb657icDvWDVq144QM0FmkrqMZyVZTalCmDU4OFiz1aQMunitP4P XJgOLuLw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUwu-00000005X3J-31Q9; Sat, 27 Jul 2024 00:06:12 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUkr-00000005Q0p-1pbd for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:53:47 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e0879957a99so416342276.1 for ; Fri, 26 Jul 2024 16:53:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038024; x=1722642824; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=bC28fbRseb42Ch2zMqBFWEix5TOk22ZdgToO+ip0K/0=; b=wlhR9UHWbRCcQsCk7Qyniuas+4OWywK1BeSXLA4zE78tE6GChzNJdviYi1HSoc6ax+ d5InN80QZ7NVPje2u+/kGiRgzLMjqD1/uw3IT/pVfIDbPxxubwiIuaMwhEzhhZ1gm5ME ADd7f7qw747nrFDjEnX4nRrpHj9GwWm6YegJe/3i7siQiydGWbUr1LRCjrix/y5dpmYP WcS/UQHpztxSTruAEyOiyrTIxz6BGeITkWO/cPIRYxpTWSdAryT+ZkD81tYpAxlpUnN9 IxV6UFPt8AYBHzjxmOkSwTHuE2YVus3/UZPegFqoW6Y7Jmw4lERsEdBZXSVQDm5CTnyg lkIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038024; x=1722642824; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bC28fbRseb42Ch2zMqBFWEix5TOk22ZdgToO+ip0K/0=; b=h3GjkL2RJ+MfT5pOKRTeTJRfVlWhZW2cgSorq+c0QyDw3//4doo+CEQc1butS2QZxg PpE7p2SS/hTlBqmTv1yMF9PNFQTJSeerv7MfcF+8PhtiRc+qhFvjncX+YhiD3chcAGf0 a4wuLzg6aW9jTmLoo4F+sqqou9qXSH+rIPWuevcItKg69UNfEJ4b21hhjYgHP+ttScG4 S88iMvr4fOoM0DVTvwT8f1RG/LONcuizqIpRkELgPG0TMu3EGoLfiIAMOrffDouGgYqw QPYyZnjrtqqSMM5X8ELfkNokZGE8u5ubWv7DTmfcwD0/A8R3YnH1pPysoCsZ6B1GAY3t 8xyw== X-Forwarded-Encrypted: i=1; AJvYcCWlvXd7fHfDyHMibBbbK1DvZferYBXC+FnYmZHb27QA3pJHH0zdkPikQRv/09+YYOzFMY3+XTllpRpg5MIOkYkNE8ZC421EZJHrKemElZ0ZiaF5wgA= X-Gm-Message-State: AOJu0Yy4xqHq8PMs6YBbKNOjRjVtMSxNQCNcss3gWz7ScIvnfHzN29zq 7gAFTHg/F6/rpBU8Rxr/LEzWnFS/FpVJmBeQ04lO0fFyUnPnjFMaF/N581Vh2Rk9DyEnzAQ0fo2 +6g== X-Google-Smtp-Source: AGHT+IFe6CawsiHghHJz6goDA5MI5OiaYSIvtgnV/oY+y/tLOOW/H4O66kyosfEcqs3UQ2nQeG3uHH/jimU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:181d:b0:e03:5144:1d48 with SMTP id 3f1490d57ef6-e0b5452490amr2050276.11.1722038023813; Fri, 26 Jul 2024 16:53:43 -0700 (PDT) Date: Fri, 26 Jul 2024 16:51:41 -0700 In-Reply-To: <20240726235234.228822-1-seanjc@google.com> Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240726235234.228822-33-seanjc@google.com> Subject: [PATCH v12 32/84] KVM: Get writable mapping for __kvm_vcpu_map() only when necessary From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , David Stevens X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_165345_686176_76CB8149 X-CRM114-Status: GOOD ( 12.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When creating a memory map for read, don't request a writable pfn from the primary MMU. While creating read-only mappings can be theoretically slower, as they don't play nice with fast GUP due to the need to break CoW before mapping the underlying PFN, practically speaking, creating a mapping isn't a super hot path, and getting a writable mapping for reading is weird and confusing. Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index a46c7bf1f902..a28479629488 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3142,7 +3142,7 @@ int __kvm_vcpu_map(struct kvm_vcpu *vcpu, gfn_t gfn, struct kvm_host_map *map, struct kvm_follow_pfn kfp = { .slot = gfn_to_memslot(vcpu->kvm, gfn), .gfn = gfn, - .flags = FOLL_WRITE, + .flags = writable ? FOLL_WRITE : 0, .refcounted_page = &map->pinned_page, .pin = true, };