From mboxrd@z Thu Jan 1 00:00:00 1970 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 F07FBC71136 for ; Fri, 13 Jun 2025 22:29:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=9udbEXIZcMjpAZHBAsY7p7z0gaqc2l0MRePZYLkkUtc=; b=4aCsvJecNyMydR6cBzBBXNW8Zw u4iuPiPNKJUYIPa4kxSHibadMlK1SMdFEoT8bqGeUeYY2gzk3x4YMw+/l5VzpPpmGz3s9dt7RGLJz k3pAWWznO/oTp0Px5A92ypxScycY4BAHo+fqlvy2vcAEeS3e+BgXHtXdsPPpO1L5HINQBVNPu2O67 UyEZ0FhFDDI8Lu2cRvqNC2GomypBiLqDGJJ+d6FOuUe2OWmXM2KTo4/Imt3myUKlxK5UzYoxnd4Tk A0nquz/BSbDPCphOeR1howDePO8ZYURSfylyMQjcUskGFdzU/nfrCn1C+jSjVdXawaMsBIGcEdGwY 9/y2ZrFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uQCto-00000000E8c-2vpf; Fri, 13 Jun 2025 22:29:24 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uQCtm-00000000E7k-0uJD for linux-riscv@lists.infradead.org; Fri, 13 Jun 2025 22:29:23 +0000 Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-31366819969so2067236a91.0 for ; Fri, 13 Jun 2025 15:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749853760; x=1750458560; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ntrF63Vv2zoH9u2B2bhtc6n4yroInyt7sGzPvAgo8Rk=; b=Qcryn+P0jOOemVLGMmX/IXmB/PAJlvHgd0oTFRO82mNDdlgw1WFLBnPt80BBptC+Zj yVTg8Rb6AZeg9zNzybB3qjLNVcG92ryyehS36FSyNOxjLySL9tm7fGgpxDD3UXR947Kv EYv6BPqYew1jjM6qgPLVqRvzsdNOHr8jDQalYYpNEKKdMBoIzv8/ZwHilxbJ5+pJs1N+ 2VTptHIlRHSkyWNemVMMgBSZJCey8KJWuJSMA+TTdtjBkYOvVgW5qzp57hlpz2DCashg zyrk05E90bqlaQdCggFLMKaV0r7pHOJPJ/atfJkLfb8oQqWvwDnULJIrDFQCR23qAnAv +SJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749853760; x=1750458560; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ntrF63Vv2zoH9u2B2bhtc6n4yroInyt7sGzPvAgo8Rk=; b=ZFPf1Trab3VFRaSdnnErYZBI2wlU6ZWOEk5zZKt0ltdZAEp0IAkdv1YptNlqhH88u+ fc2vpOI2qH0rFsZ9lxC7q7pcTHDslQVCru+ePmkAwMAAp8AiL+Wyh7XkiM/MNSWJzL/A mpUH0KXEs2QKd5Vj9nUZ3Dj9wgrphMXETD8MdZam3s6VdGL5IRuEleBIQpaInt744dCw K0KCNZM+q2p7+Myrdp5MTxmTrCCkSUMdHQBTjU4XGtEj2JN5Oum8pPKNsTbb7FmDj4PN ZcTjMjNqwqR3PFxLUStY6y5ZtlO1TjB6x8r+89Oo0yAF28g+I70e+IcEnrz7LHUKTS8S r8pw== X-Forwarded-Encrypted: i=1; AJvYcCXDObB34Q3D1Nd5u18jMvOIQsbtVJrgp1BAtt8dupdv6dC2Pqjjs7g4jqoggDi1n1WW1rJfiocO19ci7A==@lists.infradead.org X-Gm-Message-State: AOJu0YwpzqG79B39K5wrR7CtsH/MVZx3DHLlxrEFWz/4OhwjTD5Sv0J0 wRIyXM7jJgdYtL+FzwW59FtSyg+It4Avba1EEO5pVQKTtSPWuMlsm1PGtHtR/yujAWsydXN/U02 pjTvc+g== X-Google-Smtp-Source: AGHT+IGywTlpl0dHWnufpJSJlj4XpNlHL6UkXqc9RZbcriTQyKRR+zlmrTb17NJPljis76xDw4xc0g5PFgU= X-Received: from pjbsr4.prod.google.com ([2002:a17:90b:4e84:b0:313:2ad9:17ec]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2dd2:b0:312:f88d:25f9 with SMTP id 98e67ed59e1d1-313f1c7dacfmr2043479a91.7.1749853760694; Fri, 13 Jun 2025 15:29:20 -0700 (PDT) Date: Fri, 13 Jun 2025 15:29:19 -0700 In-Reply-To: <20250612-70c2e573983d05c4fbc41102@orel> Mime-Version: 1.0 References: <50989f0a02790f9d7dc804c2ade6387c4e7fbdbc.1749634392.git.zhouquan@iscas.ac.cn> <20250611-352bef23df9a4ec55fe5cb68@orel> <20250612-70c2e573983d05c4fbc41102@orel> Message-ID: Subject: Re: [PATCH] RISC-V: KVM: Avoid re-acquiring memslot in kvm_riscv_gstage_map() From: Sean Christopherson To: Andrew Jones Cc: zhouquan@iscas.ac.cn, anup@brainfault.org, atishp@atishpatra.org, paul.walmsley@sifive.com, palmer@dabbelt.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250613_152922_247488_64C4E6CD X-CRM114-Status: GOOD ( 12.03 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Thu, Jun 12, 2025, Andrew Jones wrote: > On Wed, Jun 11, 2025 at 09:17:36AM -0700, Sean Christopherson wrote: > > Looks like y'all also have a bug where an -EEXIST will be returned to userspace, > > and will generate what's probably a spurious kvm_err() message. > > On 32-bit riscv, due to losing the upper bits of the physical address? Or > is there yet another thing to fix? Another bug, I think. gstage_set_pte() returns -EEXIST if a PTE exists, and I _assume_ that's supposed to be benign? But this code returns it blindly: if (writable) { mark_page_dirty(kvm, gfn); ret = gstage_map_page(kvm, pcache, gpa, hfn << PAGE_SHIFT, vma_pagesize, false, true); } else { ret = gstage_map_page(kvm, pcache, gpa, hfn << PAGE_SHIFT, vma_pagesize, true, true); } if (ret) kvm_err("Failed to map in G-stage\n"); out_unlock: kvm_release_faultin_page(kvm, page, ret && ret != -EEXIST, writable); spin_unlock(&kvm->mmu_lock); return ret; and gstage_page_fault() forwards negative return codes: ret = kvm_riscv_gstage_map(vcpu, memslot, fault_addr, hva, (trap->scause == EXC_STORE_GUEST_PAGE_FAULT) ? true : false); if (ret < 0) return ret; and so eventually -EEXIST will propagate to userspace. I haven't looked too closely at the RISC-V MMU, but I would be surprised if encountering what ends up being a spurious fault is completely impossible. > The diff looks good to me, should I test and post it for you? If you test it, I'll happily write changelogs and post patches. _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv