From patchwork Thu Oct 10 18:23:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13831162 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 F0B19D2444F for ; Thu, 10 Oct 2024 21:16:52 +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-Transfer-Encoding:Content-Type:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=w3u38MFKj4Hgu0NiviVwRjtFpk/ioMNBGBDQlt4DAgY=; b=KQhpwrgpGQYmdx O3+2TRO33td14LQoMMIJZVB42ilxAcpHSWh132C61yDGwlUx3BvPE5PVshtAtKGoiLOIrsf8Qy6Uq 2g3lWQC5QIhLu3gtIPIesmf4r2tIzh7lsPZX1zZ9dwXu4wJDEEzL4qCo63LxxTIC4YF5kd6rfoVI+ xOQti6ES3ke7o1hBPwSslZ3zPKWiPxV6WDGomp+BHyKQ/fPNFdaxTcR3+tF3dV4mx77OGFjXjHfMS Rtg2Tq4gprSzpO8PDp+ZOpLX55enRXktpKfNuo2kiaCbnBu4Bu4KPF24gSeoMwiYIbsPG7bFKPd0T 2RZDbYIibDKGlkPLjc/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sz0WU-0000000ENfu-336v; Thu, 10 Oct 2024 21:16:38 +0000 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syxrQ-0000000DqX4-2CxM for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 18:26:07 +0000 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-71e00c8adf9so1318776b3a.1 for ; Thu, 10 Oct 2024 11:26:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728584763; x=1729189563; darn=lists.infradead.org; h=content-transfer-encoding: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=w3u38MFKj4Hgu0NiviVwRjtFpk/ioMNBGBDQlt4DAgY=; b=wwsVmKdK+SipFg1qIF50TrdP6Oo7jO28ReLYz/VDjQtbPUYfeyWnk0GVNrM0uvKMns yzO1p2PHSyt6/6J6LjJccz4eC9X33n2N2DFqSywzlwGAsAWPs0+b7iefqw5tZpUARPQu 9OG64S1K6L+hc8UcCB61w0V2JL630JzshC0mLEAVFvK8USjgHGCuqzpy7gkmEW0tty66 NRob1YtQ6GGUHdVw6r2QY0qsQ4+DlBD5nwBCrRtcLzLwX9krXorOWvD+nF58Mr7YwjaH LDcNdo4BOKyAvdYIXqY2QFZaKTbi1CdYfH/QTc06gv+b8kc00QbcJRcZEUai+QUcejZU 3v4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728584763; x=1729189563; h=content-transfer-encoding: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=w3u38MFKj4Hgu0NiviVwRjtFpk/ioMNBGBDQlt4DAgY=; b=jNqk27E4X21ji96C1SPbLJusfoFLtFNcV4bMA77rovDSUHP0l13Tqs6XybdflZQyK7 N7SOmPc4CKbjDyRbZaZ+LkEPagdrlh+dAJj+QBYsjm3eeFfWHLY+gl6rgofM84frlugn Di5/HbqW9xL/yVHkX6aJoqMeoMKZyJd/VwNanJ34vSWx6S7pMD6XHHkCWqSdjZfjzQyB ZdBl7gTZTy/X0gdoRK6kXKBBiSJRkKSBhD9U8/Sjyv3MYvLfrYdUXPnkCBiDLVcYQ6bF AJLbNChbgn0hmXcgLuzAetNcQsILlr3gLyhzjz7t4m4iEdLeZ5L40i2Z8kXHHhwfsXOu eFvA== X-Forwarded-Encrypted: i=1; AJvYcCWtmx6CFSS/AqX0K5PqcsP8gG5/W9BaHcbSPvpwi22xd0hfI45joFKOGTdbmEYm6azpF7iVbE9MMRZwhw9R5ILQ@lists.infradead.org X-Gm-Message-State: AOJu0YzP/Sd5/hb5w+YmfZXawO9VGtUkG4jO7tqGVMtKeWr7lCk1UD3u F54gHczrSE+1VsdisZrB0IxyuAzRSd1QyhRrtslOa7XOV6ka13dXnjUBsyYjZISrSx9Pm8hYnIo mCA== X-Google-Smtp-Source: AGHT+IHthU1bxxWE76UmRU/cmSB/2b+tJYVulTyd1SGmZGLYBHQFEbukUNmDJAlwNs2CFth+SfvGFADhDCI= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a05:6a00:2f51:b0:71e:dd:8f9b with SMTP id d2e1a72fcca58-71e1dbe8750mr6976b3a.5.1728584762866; Thu, 10 Oct 2024 11:26:02 -0700 (PDT) Date: Thu, 10 Oct 2024 11:23:36 -0700 In-Reply-To: <20241010182427.1434605-1-seanjc@google.com> Mime-Version: 1.0 References: <20241010182427.1434605-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241010182427.1434605-35-seanjc@google.com> Subject: [PATCH v13 34/85] 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, " =?utf-8?q?Alex_Benn=C3=A9e?= " , Yan Zhao , David Matlack , David Stevens , Andrew Jones X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241010_112604_691212_69C9CFF9 X-CRM114-Status: GOOD ( 11.93 ) 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. Tested-by: Alex Bennée 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 080740f65061..b845e9252633 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3122,7 +3122,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, };