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: 13743376 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF5F617F4EC for ; Fri, 26 Jul 2024 23:53:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722038026; cv=none; b=XDO2Yqf6GfeZa9DBqtJT2LBSiZLGN9P1PC8EUJhwGjYx7WOkkIMXED/tQmajvP3nCM+JcroofYM5giEkMXIx+4h58UWVairFENTzk9fKCzRUub/JvOvKBJLzD/d4vt1r0WBkmFbavOsjPEczb9Jox2itpLI9/uTdzxdOkZXmxYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722038026; c=relaxed/simple; bh=uf9ms+u2NfXkgc6o314wQs4yJxndrotou5MTD6pjg7g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GfBEXzX0mnZoamSjVJwQFeet6WDHE2OPHDhU97io2/M5hozJ0kICmUG9Rn6/KNMeu4AY3/t11p07XUXgmouDveLe+5sSKgtHNAJC/h42910Ck4PfBdOnpb6cMEqaW+jLG8fvtyQwg8ayC0+5u7XD5jntpw5aZY8SJst6RdqSJjA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gyMRMEom; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gyMRMEom" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e03a694ba5aso407993276.3 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=vger.kernel.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=gyMRMEom/TNpb2Aguqkw3Kr+W8GXK/pp4oC/n2rU2H6jg8xkOLsImfx1d2KBq1W/KA hDRhilSwXDaHxn+hxc0K8RfRSgTrAwYu25j3kBEGHEJXpPkCo109wlhRLMgkAgFEgVtC TRb6k+tcTcw30j9t3AGJv2rze6oZbgLTo9Yy+Dx2utk0ZLVArHJQ6PLYJWjXaOjRHfHC LaciJesXaFtuZDdXBmzHeP3HdYu6uu6XPV3NInXni1dBocS2VkvLEvf+4mChUxdqSYs7 7O7bx5/M4cBWhyOc8ePFQR8EAcLoQibQXydg4n/QO63ZJMZylzLXzMbPyQS1pxOsqNdj qt8w== 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=ko9aigxP0dZ+UpCV1i2YwUtX9/hd/q4S2F7HcXYTuiXt3Uc411E+549nvpM4jof/LN aQRhaivVnRyYfwvzUDrNh1ouI9EUbt8v72qDktZogCLn5ku85j9+J7CDRRTLNECzRKGr jTKSVRcXRB6DdoeuKH6+lPTq3HEd357czdHvA4s2Ud6uA8+6/Rmt5RYlUvW1zsCcHMPL +BzShLDn3MFYu0Susk7pLQ8poo0Ix5DzKxtFnJEjv4/Hlr4+8QQJOhUoU5+c/BrjLTRd ay6kjlb7gqOElDdRe935c1+ZBbUnuj8tDMXojwnKZvFFlzFXrBk3LRMfWhIXIJhu1ltD lFSA== X-Gm-Message-State: AOJu0YxuZckSWtGlXlCHEf2fwln+opRLINLG9IgXEycTDPhMB8gMHubl TjeHf7OGjxkzoz3PjlOcPikGo4TW7Ol9c5DX7npYiFZSNKPxL4sJKkPijSijEExJkSf9GSp2l15 Y5w== 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) Reply-To: Sean Christopherson Date: Fri, 26 Jul 2024 16:51:41 -0700 In-Reply-To: <20240726235234.228822-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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, };